2016-12-16 09:12:16 +01:00
|
|
|
describe ClamavService do
|
|
|
|
describe '.safe_file?' do
|
|
|
|
let(:path_file) { '/tmp/plop.txt' }
|
|
|
|
|
2019-02-05 14:23:43 +01:00
|
|
|
subject { ClamavService.safe_file?(path_file) }
|
2016-12-16 09:12:16 +01:00
|
|
|
|
|
|
|
before do
|
2019-02-05 14:23:43 +01:00
|
|
|
client = double("ClamAV::Client", execute: [response])
|
2017-08-21 15:23:01 +02:00
|
|
|
allow(ClamAV::Client).to receive(:new).and_return(client)
|
2019-02-05 14:23:43 +01:00
|
|
|
allow(FileUtils).to receive(:chmod).with(0666, path_file).and_return(true)
|
2016-12-16 09:12:16 +01:00
|
|
|
end
|
|
|
|
|
2019-02-05 14:23:43 +01:00
|
|
|
context 'When response type is ClamAV::SuccessResponse' do
|
|
|
|
let(:response) { ClamAV::SuccessResponse.new("OK") }
|
|
|
|
it { expect(subject).to eq(true) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'When response type is ClamAV::VirusResponse' do
|
|
|
|
let(:response) { ClamAV::VirusResponse.new("KO", "VirusN4ame") }
|
|
|
|
it { expect(subject).to eq(false) }
|
|
|
|
end
|
2016-12-16 09:12:16 +01:00
|
|
|
|
2019-02-05 14:23:43 +01:00
|
|
|
context 'When response type is ClamAV::ErrorResponse' do
|
|
|
|
let(:response) { ClamAV::ErrorResponse.new("File not found") }
|
|
|
|
it { expect { subject }.to raise_error("ClamAV ErrorResponse : File not found") }
|
2016-12-16 09:12:16 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|