clamby 1.3.2 → 1.4.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
  SHA256:
3
- metadata.gz: e11cf21ff5f74654f10a44017053c0b883f382ab423e38c6fe0a46af9ce314ac
4
- data.tar.gz: 233cc4ea434c05f575885336aebbba53884b019317d507855b0688179546d116
3
+ metadata.gz: d8a7e48c2bd0285d60fe7ece07fd72bca337e33fefb86d5304b6278132047d44
4
+ data.tar.gz: d2489bc3655ecf95667fa41f9aa39e104404fb9d0eccbbf5447dd6cd9e78b307
5
5
  SHA512:
6
- metadata.gz: eee15a0059ebd4bf338cfda8ae30428ed0160b8bf14a2d10296bccccf41bb17bab07aea2f4de3ebd8bbb85664131fb050a5a8b64786be107c1d25c689867dab1
7
- data.tar.gz: '092f0f57aee3984ab4085cf84960686cce96033095d41bd1c0ff61cb5b5ab7bafcaeec6d1563e1167b6641917d4bf95a3a80cc456553b7c36b3dbcdc1de211e6'
6
+ metadata.gz: 1a505ca85b244f599a0270a9e94e46305b1230fb2502eebbffbc441e86e78d7e668ab534fb39a2f086eb14a330c68706bd15104a387aec2e518108e9e4f912e3
7
+ data.tar.gz: 2401278d0d3721113268156994ed39eed440619b90f1e25dd42b62db99681eeeaa3aa23c9d5d7c7c59477ccd1875f93192f052a350ea9d83d3836517ec5ff724
@@ -1,3 +1,6 @@
1
+ # v1.4.0
2
+ - [emilong](https://github.com/kobaltz/clamby/commits/master?author=emilong) added `:error_clamscan_client_error => false` option to prevent error from missing running daemon or clamscan.
3
+
1
4
  # v1.3.2
2
5
  - [emilong](https://github.com/kobaltz/clamby/commits/master?author=emilong) added `stream` option
3
6
 
@@ -1,3 +1,4 @@
1
+ require "English"
1
2
  require "clamby/version"
2
3
  require "clamby/exception"
3
4
  module Clamby
@@ -5,6 +6,7 @@ module Clamby
5
6
  :check => true,
6
7
  :daemonize => false,
7
8
  :error_clamscan_missing => true,
9
+ :error_clamscan_client_error => false,
8
10
  :error_file_missing => true,
9
11
  :error_file_virus => false,
10
12
  :fdpass => false,
@@ -21,7 +23,7 @@ module Clamby
21
23
  end
22
24
 
23
25
  def self.safe?(path)
24
- value = virus?(path)
26
+ value = virus?(path)
25
27
  return nil if value.nil?
26
28
  ! value
27
29
  end
@@ -44,12 +46,24 @@ module Clamby
44
46
  def self.virus?(path)
45
47
  return nil unless scanner_exists?
46
48
  return nil unless file_exists?(path)
47
- scanner = system(*system_command(path))
49
+ system(*system_command(path))
48
50
 
49
- return false if scanner
50
- return true unless @config[:error_file_virus]
51
+ case $CHILD_STATUS.exitstatus
52
+ when 0
53
+ return false
54
+ when 2
55
+ # clamdscan returns 2 whenever error other than a detection happens
56
+ if @config[:error_clamscan_client_error] && @config[:daemonize]
57
+ raise Exceptions::ClamscanClientError.new("Clamscan client error")
58
+ end
59
+
60
+ # returns true to maintain legacy behavior
61
+ return true
62
+ else
63
+ return true unless @config[:error_file_virus]
51
64
 
52
- raise Exceptions::VirusDetected.new("VIRUS DETECTED on #{Time.now}: #{path}")
65
+ raise Exceptions::VirusDetected.new("VIRUS DETECTED on #{Time.now}: #{path}")
66
+ end
53
67
  end
54
68
 
55
69
  def self.scanner_exists?
@@ -2,5 +2,6 @@ module Exceptions
2
2
  class Error < StandardError; end
3
3
  class VirusDetected < Error; end
4
4
  class ClamscanMissing < Error; end
5
+ class ClamscanClientError < Error; end
5
6
  class FileNotFound < Error; end
6
- end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Clamby
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -97,4 +97,46 @@ describe Clamby do
97
97
  expect(Clamby.system_command(good_path)).to eq ["clamdscan", "--stream", good_path, "--no-summary"]
98
98
  end
99
99
  end
100
+
101
+ context 'error_clamscan_client_error option' do
102
+ it 'is false by default' do
103
+ expect(Clamby.config[:error_clamscan_client_error]).to eq false
104
+ end
105
+ it 'accepts an error_clamscan_client_error option in the config' do
106
+ Clamby.configure(error_clamscan_client_error: true)
107
+ expect(Clamby.config[:error_clamscan_client_error]).to eq true
108
+ end
109
+
110
+ before {
111
+ Clamby.configure(check: false)
112
+ allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(2)
113
+ allow(Clamby).to receive(:system)
114
+ }
115
+
116
+ context 'when false' do
117
+ before { Clamby.configure(error_clamscan_client_error: false) }
118
+
119
+ it 'virus? returns true when the daemonized client exits with status 2' do
120
+ Clamby.configure(daemonize: true)
121
+ expect(Clamby.virus?(good_path)).to eq true
122
+ end
123
+ it 'returns true when the client exits with status 2' do
124
+ Clamby.configure(daemonize: false)
125
+ expect(Clamby.virus?(good_path)).to eq true
126
+ end
127
+ end
128
+
129
+ context 'when true' do
130
+ before { Clamby.configure(error_clamscan_client_error: true) }
131
+
132
+ it 'virus? raises when the daemonized client exits with status 2' do
133
+ Clamby.configure(daemonize: true)
134
+ expect { Clamby.virus?(good_path) }.to raise_error(Exceptions::ClamscanClientError)
135
+ end
136
+ it 'returns true when the client exits with status 2' do
137
+ Clamby.configure(daemonize: false)
138
+ expect(Clamby.virus?(good_path)).to eq true
139
+ end
140
+ end
141
+ end
100
142
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kobaltz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-22 00:00:00.000000000 Z
11
+ date: 2018-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler