feat(ClamAV): add config to disable clamav usage
This commit is contained in:
parent
628625366b
commit
97feca6305
4 changed files with 54 additions and 21 deletions
|
@ -4,25 +4,51 @@ describe ClamavService do
|
|||
|
||||
subject { ClamavService.safe_file?(path_file) }
|
||||
|
||||
before do
|
||||
client = double("ClamAV::Client", execute: [response])
|
||||
allow(ClamAV::Client).to receive(:new).and_return(client)
|
||||
allow(FileUtils).to receive(:chmod).with(0666, path_file).and_return(true)
|
||||
context "when ClamAV is enabled" do
|
||||
before do
|
||||
@saved_clamav = Rails.configuration.x.clamav.enabled
|
||||
Rails.configuration.x.clamav.enabled = true
|
||||
|
||||
client = double("ClamAV::Client", execute: [response])
|
||||
allow(ClamAV::Client).to receive(:new).and_return(client)
|
||||
allow(FileUtils).to receive(:chmod).with(0666, path_file).and_return(true)
|
||||
end
|
||||
|
||||
after do
|
||||
Rails.configuration.x.clamav.enabled = @saved_clamav
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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") }
|
||||
end
|
||||
end
|
||||
|
||||
context 'When response type is ClamAV::SuccessResponse' do
|
||||
let(:response) { ClamAV::SuccessResponse.new("OK") }
|
||||
it { expect(subject).to eq(true) }
|
||||
end
|
||||
context "when ClamAV is disabled" do
|
||||
before do
|
||||
@saved_clamav = Rails.configuration.x.clamav.enabled
|
||||
Rails.configuration.x.clamav.enabled = false
|
||||
end
|
||||
|
||||
context 'When response type is ClamAV::VirusResponse' do
|
||||
let(:response) { ClamAV::VirusResponse.new("KO", "VirusN4ame") }
|
||||
it { expect(subject).to eq(false) }
|
||||
end
|
||||
after do
|
||||
Rails.configuration.x.clamav.enabled = @saved_clamav
|
||||
end
|
||||
|
||||
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") }
|
||||
it do
|
||||
expect(ClamAV::Client).not_to receive(:new)
|
||||
expect(FileUtils).not_to receive(:chmod)
|
||||
expect(subject).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue