ddr-antivirus 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9424fb9fcce9fd87db0354060b80873112d923bb
4
- data.tar.gz: 4e190d50edeba08eec311c2ed6e38189fec3eb29
3
+ metadata.gz: 0cbe6bb3732e0dd194bee771110acbd331359f91
4
+ data.tar.gz: a5cd603f3e9a56244179ece7d93890c26f873910
5
5
  SHA512:
6
- metadata.gz: 6f2dc02d2c56c5f5e4d0d2669517578b6905b6e300ca6b9afef71243c44540f89cdd630549e386ed15d9b7911a53d05d9030a2801c11503e2b5dd549de02fc84
7
- data.tar.gz: b32e01dc33aba340e8ac87f7030c431518d24d387992fc42addbe1131c5355c8eef8e35e2ac38b67ef2b223686647bceb09fca26d0a47fbb5c38e5b382d69b76
6
+ metadata.gz: 6ba1025ded7e40dea5ace207906ee6e0b5dbff5076d2c6d39880a2bb323eb27c147391ea3b17e09a9b61a70e7d9c6fb4088d9103b21fa08c960d26a2a642a518
7
+ data.tar.gz: dbc106f548fc2c4369cf1fc3d74292f62ed77d11780858f6660bb7f740fda02430bed699f2060b7f67403cadc2895a128b9794264543f9383df6d1a33dc02632
data/README.md CHANGED
@@ -19,19 +19,21 @@ Or install it yourself as:
19
19
 
20
20
  $ gem install ddr-antivirus
21
21
 
22
- ## ClamAV
22
+ ## How It Works
23
23
 
24
- Ddr::Antivirus does *not* include the `clamav` gem as a runtime dependency. Add to your application's Gemfile:
24
+ Ddr::Antivirus does *not* provide a virus scanning engine as a runtime dependency. Instead, it will select a scanner adapter class for the software it finds in your environment following this procedure:
25
25
 
26
- gem 'clamav'
26
+ - If the [clamav](https://github.com/eagleas/clamav) gem is available, it will select the `ClamavScannerAdapter`.
27
+ - If the ClamAV Daemon client `clamdscan` is on the user's path, it will select the `ClamdScannerAdapter`.
28
+ - Otherwise, it will select the [`NullScannerAdapter`](#the-nullscanneradapter).
27
29
 
28
- For system dependencies, see https://github.com/eagleas/clamav.
30
+ The auto-selection process may be overridden by configuration:
29
31
 
30
- Ddr::Antivirus will automatically use an adapter class for ClamAV if the Ruby gem is installed.
31
-
32
- ## ClamAV Daemon Client (clamdscan)
33
-
34
- Ddr::Antivirus will automatically use an adapter class for `clamdscan` if the executable is on the user's path.
32
+ ```ruby
33
+ Ddr::Antivirus.configure do |config|
34
+ config.scanner_adapter = :clamd # or :clamav, or :null
35
+ end
36
+ ```
35
37
 
36
38
  ## Usage
37
39
 
@@ -51,7 +53,7 @@ Ddr::Antivirus::Scanner.new do |scanner|
51
53
  end
52
54
  ```
53
55
 
54
- The scanner raises an exception (Ddr::Antivirus::VirusFoundError) if a virus is found.
56
+ The scanner raises a `Ddr::Antivirus::VirusFoundError` exception if a virus is found.
55
57
 
56
58
  ### Results
57
59
 
@@ -34,13 +34,27 @@ module Ddr
34
34
  class ClamavScanResult < Ddr::Antivirus::ScanResult
35
35
 
36
36
  def virus_found
37
- raw if raw.is_a?(String)
37
+ raw if has_virus?
38
+ end
39
+
40
+ def has_virus?
41
+ ![0, 1].include?(raw)
38
42
  end
39
43
 
40
44
  def error?
41
45
  raw == 1
42
46
  end
43
47
 
48
+ def status
49
+ return "FOUND #{virus_found}" if has_virus?
50
+ return "ERROR" if error?
51
+ "OK"
52
+ end
53
+
54
+ def to_s
55
+ "#{file_path}: #{status} (#{version})"
56
+ end
57
+
44
58
  def default_version
45
59
  # Engine and database versions
46
60
  # E.g., ClamAV 0.98.3/19010/Tue May 20 21:46:01 2014
@@ -6,11 +6,8 @@ module Ddr
6
6
  #
7
7
  class NullScannerAdapter < ScannerAdapter
8
8
 
9
- RESULT = "File not scanned -- using :null scanner adapter."
10
-
11
9
  def scan(path)
12
- Ddr::Antivirus.logger.warn(RESULT)
13
- Ddr::Antivirus::ScanResult.new(RESULT, path)
10
+ Ddr::Antivirus::ScanResult.new("#{path}: NOT SCANNED - using :null scanner adapter.", path)
14
11
  end
15
12
 
16
13
  end
@@ -23,42 +23,25 @@ module Ddr
23
23
  end
24
24
 
25
25
  # Subclasses may override to provide description of virus found.
26
- # Should return nil if no virus found.
27
26
  def virus_found; end
28
27
 
28
+ # Subclasses should override
29
29
  def has_virus?
30
30
  !virus_found.nil?
31
31
  end
32
32
 
33
- def status
34
- return status_found if has_virus?
35
- return status_error if error?
36
- status_ok
37
- end
38
-
39
- def ok?
40
- !(has_virus? || error?)
41
- end
42
-
43
- # Subclasses may implement to indicate an error condition (not necessarily an exception).
33
+ # Subclasses may override to indicate an error condition (not necessarily an exception).
44
34
  def error?
45
35
  false
46
36
  end
47
37
 
48
- def status_error
49
- "ERROR"
50
- end
51
-
52
- def status_ok
53
- "OK"
54
- end
55
-
56
- def status_found
57
- "FOUND #{virus_found}"
38
+ def ok?
39
+ !(has_virus? || error?)
58
40
  end
59
41
 
42
+ # Subclasses may override
60
43
  def to_s
61
- "Virus scan: #{status} - #{file_path} (#{version})"
44
+ "#{raw} (#{version})"
62
45
  end
63
46
 
64
47
  end
@@ -20,7 +20,7 @@ module Ddr
20
20
  result = adapter.scan(path)
21
21
  raise Ddr::Antivirus::VirusFoundError, result if result.has_virus?
22
22
  logger.error("Antivirus scanner error (#{result.version})") if result.error?
23
- logger.info(result)
23
+ logger.info(result.to_s)
24
24
  result
25
25
  end
26
26
 
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Antivirus
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -24,15 +24,9 @@ shared_examples "a successful scan result" do
24
24
  it "should be ok" do
25
25
  expect(subject).to be_ok
26
26
  end
27
- it "should have OK status" do
28
- expect(subject.status).to eq "OK"
29
- end
30
27
  end
31
28
 
32
29
  shared_examples "an error scan result" do
33
- it "should have ERROR status" do
34
- expect(subject.status).to eq("ERROR")
35
- end
36
30
  it "should have an error" do
37
31
  expect(subject).to be_error
38
32
  end
@@ -46,9 +40,6 @@ shared_examples "an error scan result" do
46
40
  end
47
41
 
48
42
  shared_examples "a virus scan result" do
49
- it "should have FOUND status" do
50
- expect(subject.status).to match(/^FOUND/)
51
- end
52
43
  it "shoud have a virus" do
53
44
  expect(subject.virus_found).not_to be_nil
54
45
  expect(subject).to have_virus
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: 1.1.0
4
+ version: 1.2.0
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: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport