Sha256: 0fb84a41239f15747e7fa684a32f6bb8bb388d9580399f57783ddcb3af5e2e52

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe Hydra::Works::VirusScanner do
  let(:file)   { '/tmp/path' }
  let(:logger) { Logger.new(nil) }

  before { allow(ActiveFedora::Base).to receive(:logger).and_return(logger) }

  subject { described_class.new(file) }

  context 'when ClamAV is defined' do
    before do
      class ClamAV
        def self.instance
          @instance ||= ClamAV.new
        end

        def scanfile(path)
          puts "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
        expect(ActiveFedora::Base.logger).to receive(:warn).with(kind_of(String))
        is_expected.to be_infected
      end
    end
  end

  context 'when ClamAV is not defined' do
    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
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hydra-works-1.2.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-1.1.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-1.0.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.17.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.16.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.15.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.12.1 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.14.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.13.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.12.0 spec/hydra/works/virus_scanner_spec.rb
hydra-works-0.11.0 spec/hydra/works/virus_scanner_spec.rb