tests
This commit is contained in:
parent
9ee9389ba1
commit
1b27ab5aff
1 changed files with 49 additions and 39 deletions
|
@ -7,57 +7,67 @@ describe VirusScannerJob, type: :job do
|
||||||
VirusScannerJob.perform_now(blob)
|
VirusScannerJob.perform_now(blob)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the blob is not analyzed yet" do
|
context "when the virus scan launch before rails analyze" do
|
||||||
it "retries the job later" do
|
before do
|
||||||
expect { subject }.to have_enqueued_job(VirusScannerJob)
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
||||||
|
subject
|
||||||
|
blob.analyze
|
||||||
|
end
|
||||||
|
it { expect(blob.virus_scanner.safe?).to be_truthy }
|
||||||
|
it { expect(blob.analyzed?).to be_truthy }
|
||||||
|
it { expect(blob.lock_version).to eq(2) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "should raise ActiveRecord::StaleObjectError" do
|
||||||
|
let(:blob_2) { ActiveStorage::Blob.find(blob.id) }
|
||||||
|
before do
|
||||||
|
blob_2.metadata[:virus_scan_result] = "infected"
|
||||||
|
blob.metadata[:virus_scan_result] = "safe"
|
||||||
|
blob.save
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect { blob_2.save }.to raise_error(ActiveRecord::StaleObjectError) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when there is an integrity error" do
|
||||||
|
before do
|
||||||
|
blob.update_column('checksum', 'integrity error')
|
||||||
|
|
||||||
|
assert_performed_jobs(5) do
|
||||||
|
VirusScannerJob.perform_later(blob)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it do
|
||||||
|
expect(blob.reload.virus_scanner.corrupt?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the blob has been analyzed" do
|
context "when no virus is found" do
|
||||||
before do
|
before do
|
||||||
blob.analyze
|
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
||||||
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an integrity error" do
|
it { expect(blob.virus_scanner.safe?).to be_truthy }
|
||||||
before do
|
end
|
||||||
blob.update_column('checksum', 'integrity error')
|
|
||||||
|
|
||||||
assert_performed_jobs(5) do
|
context "when a virus is found" do
|
||||||
VirusScannerJob.perform_later(blob)
|
before do
|
||||||
end
|
allow(ClamavService).to receive(:safe_file?).and_return(false)
|
||||||
end
|
subject
|
||||||
|
|
||||||
it do
|
|
||||||
expect(blob.reload.virus_scanner.corrupt?).to be_truthy
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when no virus is found" do
|
it { expect(blob.virus_scanner.infected?).to be_truthy }
|
||||||
before do
|
end
|
||||||
allow(ClamavService).to receive(:safe_file?).and_return(true)
|
|
||||||
subject
|
|
||||||
end
|
|
||||||
|
|
||||||
it { expect(blob.virus_scanner.safe?).to be_truthy }
|
context "when the blob has been deleted" do
|
||||||
|
before do
|
||||||
|
ActiveStorage::Blob.find(blob.id).purge
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a virus is found" do
|
it "ignores the error" do
|
||||||
before do
|
expect { subject }.not_to raise_error
|
||||||
allow(ClamavService).to receive(:safe_file?).and_return(false)
|
|
||||||
subject
|
|
||||||
end
|
|
||||||
|
|
||||||
it { expect(blob.virus_scanner.infected?).to be_truthy }
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the blob has been deleted" do
|
|
||||||
before do
|
|
||||||
ActiveStorage::Blob.find(blob.id).purge
|
|
||||||
end
|
|
||||||
|
|
||||||
it "ignores the error" do
|
|
||||||
expect { subject }.not_to raise_error
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue