Merge branch 'clamav' into develop

This commit is contained in:
Xavier J 2016-04-15 15:55:49 +02:00
commit 1da9ab7632
8 changed files with 49 additions and 9 deletions

View file

@ -53,6 +53,8 @@ gem 'openid_connect'
gem 'rest-client'
gem 'clamav-client', require: 'clamav/client'
gem 'carrierwave'
gem 'pg'

View file

@ -100,6 +100,7 @@ GEM
chartkick (1.3.2)
childprocess (0.5.5)
ffi (~> 1.0, >= 1.0.11)
clamav-client (3.0.0)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.1.0)
@ -489,6 +490,7 @@ DEPENDENCIES
capybara
carrierwave
chartkick
clamav-client
coffee-rails (~> 4.1.0)
css_splitter
database_cleaner

View file

@ -13,8 +13,8 @@ task :deploy do
end
task :deploy_test do
domains = %w(test_sgmap)
branch = 'master'
domains = %w(192.168.0.116)
branch = 'clamav'
domains.each do |domain|
sh "mina deploy domain=#{domain} branch=#{branch}"
end

View file

@ -56,7 +56,7 @@ class Users::DescriptionController < UsersController
end
unless (errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params)).empty?
flash.alert = errors_upload.full_messages.joins('<br>').html_safe
flash.alert = errors_upload.html_safe
return render 'show'
end

View file

@ -0,0 +1,12 @@
class ClamavService
def self.safe_file? path_file
FileUtils.chmod 0666, path_file
client = ClamAV::Client.new
response = client.execute(ClamAV::Commands::ScanCommand.new(path_file))
return false if response.first.class == ClamAV::VirusResponse
true
end
end

View file

@ -5,13 +5,17 @@ class PiecesJustificativesService
dossier.types_de_piece_justificative.each do |type_de_pieces_justificatives|
unless params["piece_justificative_#{type_de_pieces_justificatives.id}"].nil?
piece_justificative = PieceJustificative.new(content: params["piece_justificative_#{type_de_pieces_justificatives.id}"],
dossier: dossier,
type_de_piece_justificative: type_de_pieces_justificatives,
user: user)
if ClamavService.safe_file? params["piece_justificative_#{type_de_pieces_justificatives.id}"].path
piece_justificative = PieceJustificative.new(content: params["piece_justificative_#{type_de_pieces_justificatives.id}"],
dossier: dossier,
type_de_piece_justificative: type_de_pieces_justificatives,
user: user)
unless piece_justificative.save
errors << piece_justificative.errors.messages[:content][0]+" (#{piece_justificative.libelle})"+"<br>"
unless piece_justificative.save
errors << piece_justificative.errors.messages[:content][0]+" (#{piece_justificative.libelle})"+"<br>"
end
else
errors << params["piece_justificative_#{type_de_pieces_justificatives.id}"].original_filename+": <b>Virus détecté !!</b>"+"<br>"
end
end
end

View file

@ -18,6 +18,8 @@ describe Users::DescriptionController, type: :controller do
let(:piece_justificative_1) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_1}", 'application/pdf') }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
sign_in dossier.user
end
@ -221,6 +223,20 @@ describe Users::DescriptionController, type: :controller do
dossier.reload
end
describe 'clamav anti-virus presence' do
it 'ClamavService safe_file? is call' do
expect(ClamavService).to receive(:safe_file?).twice
post :create, {dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
end
end
context 'for piece 0' do
subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s }
it { expect(subject.content).not_to be_nil }

View file

@ -3,7 +3,10 @@ require 'spec_helper'
feature 'user is on description page' do
let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, cerfa_flag: true) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure) }
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
visit users_dossier_description_path dossier
within('#new_user') do
@ -13,6 +16,7 @@ feature 'user is on description page' do
end
end
it { expect(page).to have_css('#description_page') }
context 'he fill description fields' do