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 matches the API expected
by hydra-works (< 2.0.0).
  • Loading branch information
mark-dce committed Mar 21, 2023
1 parent d49465f commit e34579c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
30 changes: 30 additions & 0 deletions spec/lib/clamby_scanner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 }

before do
# Stub Clamby to return true if filename includes "virus"
# in environments without ClamAV installed - e.g. CircleCI
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

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
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 e34579c

Please sign in to comment.