ddr-antivirus 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b9df155d09e46c53818f01062bb81c7edc064ce
4
- data.tar.gz: f01c25fe5043058b97fbf6d058e75f36e6d0c0af
3
+ metadata.gz: 1e2dc2816bc43d784563002fecfa27809184e0e7
4
+ data.tar.gz: f662098335165f8b839dde9af1540901fbcb412e
5
5
  SHA512:
6
- metadata.gz: b9881f3a0b1e46b82a3e179a361277ae9fc15032e97923daa94d02713fcbf32dc0522aed47f71f6af34eca8b68390adf43d2f46fb83bc085c290abca9090fa41
7
- data.tar.gz: 00ca141a41c649d4b004d354014fb390c004dbaf7c99f3090dcf325ae41357e1af4687ba65f15dcbd03a21e01519c6ef7073c36d8ad8f214044b7593d3a7d78f
6
+ metadata.gz: 296903f26f411e4638f61a27782b5a6f2fd5c4d654d0c5edec1bfab8de6846c8fdd0156efdd5d302bd85135d31c7f097fd9c679bcc706e394ee740460f3812cd
7
+ data.tar.gz: d88a0465de7c6d7de55827de7b8264ba808ca3e1d1ec9ad5f28e5b728de9a2771d19b706ce5945d0084f0a989f3c84893d27786c35e422b3996cdefc51815eb2
@@ -1,8 +1,12 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.1
5
- - 2.2
3
+ - 2.1.5
6
4
  cache:
7
5
  - bundler
8
-
6
+ - apt
7
+ before_install:
8
+ - sudo apt-get update -qq
9
+ - sudo apt-get install -y clamav-daemon
10
+ before_script:
11
+ - sudo freshclam -v
12
+ - sudo /etc/init.d/clamav-daemon start
@@ -1,4 +1,3 @@
1
- require "open3"
2
1
  require "fileutils"
3
2
  require "shellwords"
4
3
 
@@ -9,11 +8,14 @@ module Ddr::Antivirus
9
8
  class ClamdScannerAdapter < ScannerAdapter
10
9
 
11
10
  SCANNER = "clamdscan".freeze
11
+ CONFIG = "clamconf".freeze
12
+
13
+ MAX_FILE_SIZE_RE = Regexp.new('^MaxFileSize = "(\d+)"')
12
14
 
13
15
  def scan(path)
14
- output, status = clamdscan(path)
16
+ output, exitcode = clamdscan(path)
15
17
  result = ScanResult.new(path, output, version: version, scanned_at: Time.now.utc)
16
- case status.exitstatus
18
+ case exitcode
17
19
  when 0
18
20
  result
19
21
  when 1
@@ -24,21 +26,31 @@ module Ddr::Antivirus
24
26
  end
25
27
 
26
28
  def clamdscan(path)
27
- make_readable(path) do
28
- command(path)
29
+ output = make_readable(path) do
30
+ command "--fdpass", safe_path(path)
29
31
  end
32
+ [ output, $?.exitstatus ]
30
33
  end
31
34
 
32
35
  def version
33
- out, err, status = Open3.capture3(SCANNER, "-V")
34
- out.strip
36
+ @version ||= command("-V").strip
37
+ end
38
+
39
+ def config
40
+ @config ||= `#{CONFIG}`
41
+ end
42
+
43
+ def max_file_size
44
+ if m = MAX_FILE_SIZE_RE.match(config)
45
+ m[1]
46
+ end
35
47
  end
36
48
 
37
49
  private
38
50
 
39
- def command(path)
40
- safe_path = Shellwords.shellescape(path)
41
- Open3.capture2e(SCANNER, safe_path)
51
+ def command(*args)
52
+ cmd = args.dup.unshift(SCANNER).join(" ")
53
+ `#{cmd}`
42
54
  end
43
55
 
44
56
  def make_readable(path)
@@ -46,38 +58,18 @@ module Ddr::Antivirus
46
58
  original = File.stat(path).mode # raises Errno::ENOENT
47
59
  if !File.world_readable?(path)
48
60
  changed = FileUtils.chmod("a+r", path)
49
- logger.info "File #{path} made world-readable for virus scanning."
61
+ logger.debug "#{self.class} - File \"#{path}\" made world-readable."
50
62
  end
51
63
  result = yield
52
64
  if changed
53
65
  FileUtils.chmod(original, path)
54
- logger.info "Mode reset to original #{original} on file #{path}."
66
+ logger.debug "#{self.class} - Mode on file \"#{path}\" reset to original: #{original}."
55
67
  end
56
68
  result
57
69
  end
58
70
 
59
- end
60
-
61
- # Result of a scan with the ClamdScannerAdapter
62
- # @api private
63
- class ClamdScanResult < ScanResult
64
-
65
- def virus_found
66
- if m = /: ([^\s]+) FOUND$/.match(output)
67
- m[1]
68
- end
69
- end
70
-
71
- def ok?
72
- status.exitstatus == 0
73
- end
74
-
75
- def has_virus?
76
- status.exitstatus == 1
77
- end
78
-
79
- def error?
80
- status.exitstatus == 2
71
+ def safe_path(path)
72
+ Shellwords.shellescape(path)
81
73
  end
82
74
 
83
75
  end
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Antivirus
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ I'm clean!
@@ -0,0 +1,20 @@
1
+ RSpec.describe "ClamAV support using clamd" do
2
+
3
+ let(:clean_file) { File.expand_path(File.join("..", "..", "fixtures", "clean.txt"), __FILE__) }
4
+
5
+ before do
6
+ @adapter = Ddr::Antivirus.scanner_adapter
7
+ Ddr::Antivirus.scanner_adapter = :clamd
8
+ end
9
+
10
+ after do
11
+ Ddr::Antivirus.scanner_adapter = @adapter
12
+ end
13
+
14
+ describe "on the clean file" do
15
+ it "doesn't raise an error" do
16
+ expect { Ddr::Antivirus.scan(clean_file) }.not_to raise_error
17
+ end
18
+ end
19
+
20
+ end
@@ -1,11 +1,10 @@
1
1
  require "tempfile"
2
+ require "fileutils"
2
3
  require "ddr/antivirus/adapters/clamd_scanner_adapter"
3
4
 
4
5
  module Ddr::Antivirus
5
6
  RSpec.describe ClamdScannerAdapter do
6
7
 
7
- let(:path) { File.expand_path(File.join("..", "..", "fixtures", "blue-devil.png"), __FILE__) }
8
-
9
8
  before do
10
9
  allow(subject).to receive(:version) { "version" }
11
10
  end
@@ -15,57 +14,48 @@ module Ddr::Antivirus
15
14
  @file = Tempfile.new("test")
16
15
  @file.write("Scan me!")
17
16
  @file.close
18
- allow(subject).to receive(:command).with(@file.path) { ["#{@file.path}: OK", double(exitstatus: 0)] }
17
+ FileUtils.chmod(0000, @file.path)
19
18
  end
20
19
  after { @file.unlink }
21
- describe "when the file is not world readable" do
22
- it "should temporarily change the permissions" do
23
- FileUtils.chmod("a-r", @file.path)
24
- original_mode = File.stat(@file.path).mode
25
- expect(FileUtils).to receive(:chmod).with("a+r", @file.path)
26
- subject.scan(@file.path)
27
- expect(File.stat(@file.path).mode).to eq(original_mode)
20
+ describe "when the file is not readable" do
21
+ it "scans the file" do
22
+ expect { subject.scan(@file.path) }.not_to raise_error
28
23
  end
29
- end
30
- describe "when the file is world readable" do
31
- before { FileUtils.chmod("a+r", @file.path) }
32
- it "should not change the permissions" do
33
- original_mode = File.stat(@file.path).mode
34
- expect(FileUtils).not_to receive(:chmod)
35
- subject.scan(@file.path)
36
- expect(File.stat(@file.path).mode).to eq(original_mode)
24
+ it "resets the original permissions" do
25
+ expect { subject.scan(@file.path) }.not_to change { File.stat(@file.path).mode }
37
26
  end
38
27
  end
39
28
  end
40
29
 
41
30
  describe "result" do
31
+ let(:path) { File.expand_path(File.join("..", "..", "fixtures", "blue-devil.png"), __FILE__) }
42
32
  before do
43
- allow(subject).to receive(:command).with(path) { ["output", status] }
33
+ allow(subject).to receive(:clamdscan).with(path) { ["output", exitcode] }
44
34
  end
45
35
  describe "when a virus is found" do
46
- let(:status) { double(exitstatus: 1) }
36
+ let(:exitcode) { 1 }
47
37
  it "should raise a VirusFoundError" do
48
38
  expect { subject.scan(path) }.to raise_error(VirusFoundError)
49
39
  end
50
40
  end
51
41
  describe "when there is an error" do
52
- let(:status) { double(exitstatus: 2) }
53
- it "should raise a ScannerError" do
42
+ let(:exitcode) { 2 }
43
+ it "raises a ScannerError" do
54
44
  expect { subject.scan(path) }.to raise_error(ScannerError)
55
45
  end
56
46
  end
57
47
  describe "success" do
58
- let(:status) { double(exitstatus: 0) }
59
- it "should have output" do
48
+ let(:exitcode) { 0 }
49
+ it "has output" do
60
50
  expect(subject.scan(path).output).to eq("output")
61
51
  end
62
- it "should have a scanned_at time" do
52
+ it "has a scanned_at time" do
63
53
  expect(subject.scan(path).scanned_at).to be_a(Time)
64
54
  end
65
- it "should have a version" do
55
+ it "has a version" do
66
56
  expect(subject.scan(path).version).to eq("version")
67
57
  end
68
- it "should have the file_path" do
58
+ it "has the file_path" do
69
59
  expect(subject.scan(path).file_path).to eq(path)
70
60
  end
71
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-antivirus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,8 @@ files:
76
76
  - lib/ddr/antivirus/scanner_adapter.rb
77
77
  - lib/ddr/antivirus/version.rb
78
78
  - spec/fixtures/blue-devil.png
79
+ - spec/fixtures/clean.txt
80
+ - spec/integration/clamd_spec.rb
79
81
  - spec/spec_helper.rb
80
82
  - spec/unit/clamd_scanner_adapter_spec.rb
81
83
  homepage: https://github.com/duke-libraries/ddr-antivirus
@@ -104,5 +106,7 @@ specification_version: 4
104
106
  summary: Pluggable antivirus scanning service.
105
107
  test_files:
106
108
  - spec/fixtures/blue-devil.png
109
+ - spec/fixtures/clean.txt
110
+ - spec/integration/clamd_spec.rb
107
111
  - spec/spec_helper.rb
108
112
  - spec/unit/clamd_scanner_adapter_spec.rb