Final implement of clamav gem

This commit is contained in:
Xavier J 2016-04-15 15:32:15 +02:00
parent 4099efd326
commit 900b377ae2
5 changed files with 37 additions and 16 deletions

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

@ -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

View file

@ -5,10 +5,7 @@ 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,
@ -17,8 +14,9 @@ class PiecesJustificativesService
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
errors

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