Skip to content

Commit

Permalink
Add tests for ClambyScanner
Browse files Browse the repository at this point in the history
Tests the configuration of ClamAV in environments where it's installed;
otherwise, stubs Clamby to ensure ClambyScanner returns values expected
by the hydra-works API.
  • Loading branch information
mark-dce committed Mar 21, 2023
1 parent 1e72df9 commit 3792891
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
36 changes: 36 additions & 0 deletions spec/lib/clamby_scanner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'rails_helper'
require 'clamby_scanner'

RSpec.describe ClambyScanner do
let(:infected_file) { Rails.root.join('spec', 'fixtures', 'virus_checking', 'virus_check.txt').to_s }
let(:clean_file) { Rails.root.join('spec', 'fixtures', 'miranda', 'miranda_thesis.pdf').to_s }

describe "Clamby" do
before do
# Stub Clamby to return true if filename includes "virus"
# in environments without ClamAV installed - e.g. CircleCI
Clamby.configure(error_clamscan_missing: false, output_level: 'off')
unless Clamby.scanner_exists?
class_double("Clamby").as_stubbed_const
allow(Clamby).to receive(:virus?) { |args| args.match?(/virus/i) }
end
end

it 'detects viruses' do
expect(described_class.infected?(infected_file)).to be true
end

it 'passes clean files' do
expect(described_class.infected?(clean_file)).to be false
end
end

describe "functionality" do
# ClambyScanner can be removed once we're running a more recent version of hydra-works
it 'is handled natively in hydra-works >= 2.0.0' do
pending 'hydra-works >= v2.0.0'
native = Gem::Version.new(Hydra::Works::VERSION) >= Gem::Version.new('2.0.0')
expect(native).to be true
end
end
end
5 changes: 0 additions & 5 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@
# ActiveFedora::Cleaner.clean!
# end

config.before do
class_double("Clamby").as_stubbed_const
allow(Clamby).to receive(:virus?).and_return(false)
end

config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::IntegrationHelpers, type: :request
config.include Warden::Test::Helpers, type: :system
Expand Down

0 comments on commit 3792891

Please sign in to comment.