Skip to content

Commit

Permalink
Merge pull request #372 from samvera/clamby-dev-con
Browse files Browse the repository at this point in the history
Deprecate clamav gem in favor of Clamby
  • Loading branch information
escowles authored Oct 22, 2019
2 parents 442e533 + 5829bea commit 7422781
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
name: 'samvera/ruby_fcrepo_solr'
ruby_version: << parameters.ruby_version >>
steps:
- run: 'sudo apt-get update && sudo apt-get install clamav'
- run: 'sudo freshclam'
- samvera/cached_checkout
- samvera/bundle_for_gem:
ruby_version: << parameters.ruby_version >>
Expand Down
1 change: 1 addition & 0 deletions .solr_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 7.7.2
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ group :development, :test do
gem 'rubocop-rspec', '~> 1.13.0', require: false
gem 'pry' unless ENV['CI']
gem 'pry-byebug' unless ENV['CI']
gem 'clamby'
end

if ENV['RAILS_VERSION']
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,19 @@ Behaviors included in the model include:
* Virus checking of original files
* Full-text extraction from original files

Check out the [Hydra::Derivatives README](https://github.com/samvera/hydra-derivatives#dependencies) for additional dependencies.
## Dependencies

Check out the [Hydra::Derivatives README](https://github.com/samvera/hydra-derivatives#dependencies) for dependencies.

## Additional dependencies required for specs

#### ClamAV
* Mac installation
```
$ brew install clamav
$ cp /usr/local/etc/clamav/freshclam.conf.sample /usr/local/etc/clamav/freshclam.conf
$ freshclam
```

## Installation

Expand Down Expand Up @@ -93,9 +105,11 @@ page.save

## Virus Detection

To turn on virus detection, install clamav on your system and add the `clamav` gem to your Gemfile
To turn on virus detection, install [ClamAV](https://www.clamav.net/documents/installing-clamav) on your system and add the `clamby` gem to your Gemfile

gem 'clamav'
```ruby
gem 'clamby'
```

Then include the `VirusCheck` module in your `FileSet` class:

Expand Down
4 changes: 4 additions & 0 deletions hydra-works.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'solr_wrapper', '~> 2.0'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'rspec_junit_formatter'

### Pinned dependencies
# Pin sprockets to < 4 since it requires ruby 2.5+
spec.add_dependency 'sprockets', '< 4'
end
18 changes: 17 additions & 1 deletion lib/hydra/works/virus_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,32 @@ def initialize(file)
# Override this method to use your own virus checking software
# @return [Boolean]
def infected?
defined?(ClamAV) ? clam_av_scanner : null_scanner
if defined?(Clamby)
clamby_scanner
elsif defined?(ClamAV)
clam_av_scanner
else
null_scanner
end
end

def clam_av_scanner
Deprecation.warn(self, "The ClamAV has been replaced by Clamby " \
"as the supported virus scanner for hydra-works. " \
"ClamAV support will be removed in hydra-works 2.0 ")
scan_result = ClamAV.instance.method(:scanfile).call(file)
return false if scan_result == 0
warning "A virus was found in #{file}: #{scan_result}"
true
end

# @return [Boolean]
def clamby_scanner
scan_result = Clamby.virus?(file)
warning("A virus was found in #{file}") if scan_result
scan_result
end

# Always return zero if there's nothing available to check for viruses. This means that
# we assume all files have no viruses because we can't conclusively say if they have or not.
def null_scanner
Expand Down
2 changes: 1 addition & 1 deletion spec/hydra/works/services/characterization_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Persist our file with some content and reload
file.content = "junk"
expect(file.save).to be true
expect(file.reload).to eq({})
expect(file.reload).to be_empty
# Re-check property values
expect(file.file_size).to eq(["7618"])
expect(file.file_title).to eq(["sample-file"])
Expand Down
31 changes: 31 additions & 0 deletions spec/hydra/works/virus_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

context 'when ClamAV is defined' do
before do
hide_const('Clamby')

class ClamAV
def self.instance
@instance ||= ClamAV.new
Expand All @@ -20,16 +22,19 @@ def scanfile(path)
end
end
end

after do
Object.send(:remove_const, :ClamAV)
end

context 'with a clean file' do
before { allow(ClamAV.instance).to receive(:scanfile).with('/tmp/path').and_return(0) }
it 'returns false with no warning' do
expect(ActiveFedora::Base.logger).not_to receive(:warn)
is_expected.not_to be_infected
end
end

context 'with an infected file' do
before { allow(ClamAV.instance).to receive(:scanfile).with('/tmp/path').and_return(1) }
it 'returns true with a warning' do
Expand All @@ -40,9 +45,35 @@ def scanfile(path)
end

context 'when ClamAV is not defined' do
before do
hide_const('Clamby')
end

it 'returns false with a warning' do
expect(ActiveFedora::Base.logger).to receive(:warn).with(kind_of(String))
is_expected.not_to be_infected
end
end

context 'Clamby integration tests' do
before do
require 'clamby'
end

context "when it's infected" do
let(:file) { File.join(fixture_path, 'eicar.txt') }

it 'finds a virus' do
is_expected.to be_infected
end
end

context "when it's clean" do
let(:file) { File.join(fixture_path, 'piano_note.wav') }

it 'finds no virus' do
is_expected.not_to be_infected
end
end
end
end

0 comments on commit 7422781

Please sign in to comment.