diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb
index 18eb0aa61..fb6ecb930 100644
--- a/app/controllers/users/description_controller.rb
+++ b/app/controllers/users/description_controller.rb
@@ -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('
').html_safe
+ flash.alert = errors_upload.html_safe
return render 'show'
end
diff --git a/app/services/clamav_service.rb b/app/services/clamav_service.rb
index 03605b487..f34c32c76 100644
--- a/app/services/clamav_service.rb
+++ b/app/services/clamav_service.rb
@@ -1,9 +1,12 @@
class ClamavService
- def self.safe_io_data? path_file
- client = ClamAV::Client.new
+ def self.safe_file? path_file
+ FileUtils.chmod 0666, path_file
+
+ client = ClamAV::Client.new
response = client.execute(ClamAV::Commands::ScanCommand.new(path_file))
- puts response
+ return false if response.first.class == ClamAV::VirusResponse
+ true
end
end
\ No newline at end of file
diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb
index da424a1e3..c19a7ddc8 100644
--- a/app/services/pieces_justificatives_service.rb
+++ b/app/services/pieces_justificatives_service.rb
@@ -5,20 +5,18 @@ class PiecesJustificativesService
dossier.types_de_piece_justificative.each do |type_de_pieces_justificatives|
unless params["piece_justificative_#{type_de_pieces_justificatives.id}"].nil?
- # unless ClamavService.safe_io_data? params["piece_justificative_#{type_de_pieces_justificatives.id}"].path
- #
- # end
+ 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)
- 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})"+"
"
+ unless piece_justificative.save
+ errors << piece_justificative.errors.messages[:content][0]+" (#{piece_justificative.libelle})"+"
"
+ end
+ else
+ errors << params["piece_justificative_#{type_de_pieces_justificatives.id}"].original_filename+": Virus détecté !!"+"
"
end
-
-
end
end
errors
diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb
index e148830e2..6c9b50600 100644
--- a/spec/controllers/users/description_controller_spec.rb
+++ b/spec/controllers/users/description_controller_spec.rb
@@ -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 }
diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb
index 468fd4415..3ea348592 100644
--- a/spec/features/description_page/upload_piece_justificative_spec.rb
+++ b/spec/features/description_page/upload_piece_justificative_spec.rb
@@ -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