Skip to content

Commit

Permalink
Add more scan_files specs
Browse files Browse the repository at this point in the history
  • Loading branch information
sammo1235 committed Oct 7, 2024
1 parent 985bdbf commit cdefed2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
1 change: 0 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ DEVISE_SECRET_KEY=DEVISE_SECRET_KEY
SENTRY_DSN=SENTRY_DSN
AUTHY_API_KEY=AUTHY_API_KEY
AUTHY_API_URL=https://api.authy.com
DISABLE_VIRUS_SCANNER=false
PROFILE_MODE=false
LOG_LEVEL=info
ASSET_HOST=
Expand Down
60 changes: 58 additions & 2 deletions spec/models/concerns/scan_files_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "rails_helper"

RSpec.describe ScanFiles do
describe "callbacks" do
let(:record) { create(:form_answer_attachment) }
let(:record) { create(:form_answer_attachment) }

describe "callbacks" do
describe "#set_scan_results_to_pending" do
it "defines the method" do
record.save
Expand Down Expand Up @@ -43,4 +43,60 @@
end
end
end

describe ".scan_for_viruses" do
it "defines methods for scanning and cleaning per given attribute" do
# assumes [scan_for_viruses :file] stated in model
expect(record.respond_to?(:scan_file!)).to be_truthy
expect(record.respond_to?(:on_scan_file)).to be_truthy
expect(record.respond_to?(:clean?)).to be_truthy
expect(record.respond_to?(:pending_or_scanning?)).to be_truthy
expect(record.respond_to?(:infected?)).to be_truthy
expect(record.respond_to?(:set_scan_results_to_pending)).to be_truthy
end
end

describe ".scan_[attr_name]" do
context "when ENV['DISABLE_VIRUS_SCANNER'] == 'true'" do
before do
ENV["DISABLE_VIRUS_SCANNER"] = "true"
allow(record).to receive(:move_to_clean_bucket)
end

after do
ENV["DISABLE_VIRUS_SCANNER"] = "false"
end

it "updates [attr_name]_scan_results to clean" do
record.scan_file!

expect(record.reload.file_scan_results).to eq "clean"
end

it "calls the move_to_clean_bucket method" do
expect(record).to receive(:move_to_clean_bucket).with(:file)

record.scan_file!
end
end

context "when ENV['DISABLE_VIRUS_SCANNER'] == 'false'" do
it "enqueues a FileScanJob and updates [attr_name]_scan_results to scanning" do
expect(FileScanJob).to receive(:perform_later).with(
{
model: "FormAnswerAttachment",
column: :file,
id: record.id,
}.to_json,
"FormAnswerAttachment",
record.id,
"file",
)

record.scan_file!

expect(record.reload.file_scan_results).to eq "scanning"
end
end
end
end

0 comments on commit cdefed2

Please sign in to comment.