ddr-antivirus 1.1.0 → 1.2.0
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 +4 -4
- data/README.md +12 -10
- data/lib/ddr/antivirus/adapters/clamav_scanner_adapter.rb +15 -1
- data/lib/ddr/antivirus/adapters/null_scanner_adapter.rb +1 -4
- data/lib/ddr/antivirus/scan_result.rb +6 -23
- data/lib/ddr/antivirus/scanner.rb +1 -1
- data/lib/ddr/antivirus/version.rb +1 -1
- data/spec/shared_examples_for_scan_results.rb +0 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cbe6bb3732e0dd194bee771110acbd331359f91
|
4
|
+
data.tar.gz: a5cd603f3e9a56244179ece7d93890c26f873910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
##
|
22
|
+
## How It Works
|
23
23
|
|
24
|
-
Ddr::Antivirus does *not*
|
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
|
-
|
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
|
-
|
30
|
+
The auto-selection process may be overridden by configuration:
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
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
|
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.
|
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
|
-
|
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
|
49
|
-
|
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
|
-
"
|
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
|
|
@@ -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.
|
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-
|
11
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|