clamav-client 2.0.1 → 3.0.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: 0e16bf843318d1ae3aec44e522c278143affc3d2
4
- data.tar.gz: 100e606c288e5a6a3a46a0537e4d4f6f0d989b9c
3
+ metadata.gz: 11dfc16043cb078ca8546e7d1c6a8b3a8566998d
4
+ data.tar.gz: 36153ccbb6af07644a62fe8bc3bed19a45bb0c65
5
5
  SHA512:
6
- metadata.gz: 06d3e9d069ff7875b6f499c78adfbdaae9a29a030fd38f68435393e322cfa3c407c0d53a72d4067550cfa0b09c3da73858c4d944b8ce46f31c95ccb4d3484a0e
7
- data.tar.gz: 141d5420ccd5fc6a90332b77184b5c1c593d2b27ce297a2b498677cc7b176a87aa3dffdd86f13173492912f47ed2906faba88daa17280407fbffb092d11df4a4
6
+ metadata.gz: 412d152f55ad56fd5dc93845a2e2706550248324462f752de4e2f0c3c709830d5285dbbb66d6282f9d2d4da37d5c4ee6a1e21481800440891164218da97fbd6c
7
+ data.tar.gz: c73336041272d4f4608dc649b5d82c1e4ce9f2c06cb582e870754b9b5ad912e0f87447c88a08872d9259b6678497763c172b9a69eca5dcbdf4573684fb7f0023
@@ -8,4 +8,7 @@ rvm:
8
8
  - jruby-19mode
9
9
  - jruby-head
10
10
  - rbx
11
- script: rake unit_tests
11
+ before_install: "sudo ./test/ci-setup.sh"
12
+ env:
13
+ - CLAMD_UNIX_SOCKET=/var/run/clamav/clamd.ctl
14
+ script: rake
@@ -0,0 +1,34 @@
1
+ # Unreleased (3.0.0)
2
+
3
+ * README: Added instructions to install ClamAV on Ubuntu, RedHat and CentOS
4
+ * INSTREAM: fixed a problem parsing the "FOUND" response
5
+ * VirusReponse: The virus file name is now held by the VirusReponse object
6
+
7
+
8
+ # 2.0.1
9
+
10
+ * README.md : ClamAV's setup notes
11
+ * clamav-client.gemspec : Upgrade gem after yanking it on RG
12
+
13
+ # 2.0.0
14
+
15
+ * lib/clamav/commands/instream_command: Support of INSTREAM
16
+ * lib/clamav/responses.rb : Change insufficient comparison
17
+ * README.md: Now backward-compatible back to Ruby 1.9.2
18
+ * lib/clamav/client.rb : Configure with constants
19
+ * CLAMD_UNIX_SOCKET
20
+ * CLAMD_TCP_HOST
21
+ * CLAMD_TCP_PORT
22
+ * clamav-client.gemspec : Add the minitest gem for older Rubies
23
+ * .travis.yml : New test script. Add support for more Rubies
24
+ * lib/clamav/connection : remove keyword arguments
25
+ * travis.yml : Add basic configuration
26
+ * lib/clamav/wrapper.rb : Host common code
27
+ * lib/clamav/commands/command : Remove dead code
28
+ * Code format consistency.
29
+ * Explicit #call() to better document usage.
30
+ * Code typos; Ruby highlighting; wording.
31
+
32
+ # 1.0.0
33
+
34
+ * Initial release
data/README.md CHANGED
@@ -20,6 +20,29 @@ Alternatively, you can spawn a `pry` console right away by just running:
20
20
 
21
21
  $ rake console
22
22
 
23
+ ### Installing ClamAV's daemon
24
+
25
+ #### On OSX
26
+
27
+ If you are using brew, just run
28
+
29
+ ```shell
30
+ brew install clamav
31
+ ```
32
+ #### On Linux (Ubuntu)
33
+ ```shell
34
+ sudo apt-get install clamav-daemon clamav-freshclam clamav-unofficial-sigs
35
+ sudo freshclam
36
+ sudo service clamav-daemon start
37
+ ```
38
+ #### On Linux (RedHat, CentOS)
39
+ ```shell
40
+ sudo yum install clamd clamav clamav-db
41
+ sudo freshclam
42
+ sudo service clamd start
43
+ ```
44
+ Under RedHat/CentOS the UNIX Socket, located at `/var/run/clamav/clamd.sock`
45
+
23
46
  ## Requirements
24
47
 
25
48
  * Ruby >= 1.9.2
@@ -157,6 +180,12 @@ over the `CLAMD_UNIX_SOCKET`.
157
180
 
158
181
  Sets the socket path of the ClamAV daemon.
159
182
 
183
+ Under RedHat/CentOS this can either be set via an environment variable (above) or in the ClamAV::Connection call
184
+ ```
185
+ connection = ClamAV::Connection.new(socket: ::UNIXSocket.new('/var/run/clamav/clamd.sock'), wrapper: ::ClamAV::Wrappers::NewLineWrapper.new)
186
+ client = ClamAV::Client.new(connection)
187
+ ```
188
+
160
189
  #### CLAMD_TCP_HOST and CLAMD_TCP_PORT
161
190
 
162
191
  Sets the host and port of the ClamAV daemon.
@@ -3,7 +3,7 @@ $:<< 'lib'
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "clamav-client"
6
- spec.version = "2.0.1"
6
+ spec.version = "3.0.0"
7
7
  spec.authors = ["Franck Verrot"]
8
8
  spec.email = ["franck@verrot.fr"]
9
9
  spec.summary = %q{ClamAV::Client connects to a Clam Anti-Virus clam daemon and send commands.}
@@ -21,23 +21,19 @@ require 'clamav/responses/virus_response'
21
21
  module ClamAV
22
22
  module Commands
23
23
  class Command
24
- Statuses = {
25
- 'OK' => ClamAV::SuccessResponse,
26
- 'ERROR' => ClamAV::ErrorResponse,
27
- 'ClamAV-Test-Signature FOUND' => ClamAV::VirusResponse
28
- }
29
24
 
30
25
  def call; raise NotImplementedError.new; end
31
26
 
32
27
  protected
33
28
 
29
+ # OK response looks like "1: stream: OK" or "1: /tmp/NOT_A_VIRUS.TXT: OK"
30
+ # FOUND response looks like "1: stream: Eicar-Test-Signature FOUND" or "1: /tmp/EICAR.COM: Eicar-Test-Signature FOUND"
34
31
  def get_status_from_response(str)
35
- case str
36
- when 'Error processing command. ERROR'
37
- ErrorResponse.new(str)
38
- else
39
- /(?<id>\d+): (?<filepath>.*): (?<status>.*)/ =~ str
40
- Statuses[status].new(filepath)
32
+ /^(?<id>\d+): (?<filepath>.*): (?<virus_name>.*)\s?(?<status>(OK|FOUND))$/ =~ str
33
+ case status
34
+ when 'OK' then ClamAV::SuccessResponse.new(filepath)
35
+ when 'FOUND' then ClamAV::VirusResponse.new(filepath, virus_name.strip)
36
+ else ClamAV::ErrorResponse.new(str)
41
37
  end
42
38
  end
43
39
 
@@ -16,17 +16,13 @@
16
16
 
17
17
  module ClamAV
18
18
  class Response
19
- def initialize(file)
20
- @file = file
21
- end
22
19
 
20
+ attr_reader :file, :virus_name, :error_str
21
+
22
+ # Not sure if this is still required?
23
23
  def ==(other)
24
24
  @file == other.file && self.class == other.class
25
25
  end
26
26
 
27
- protected
28
-
29
- attr_reader :file
30
-
31
27
  end
32
28
  end
@@ -18,5 +18,10 @@ require 'clamav/responses'
18
18
 
19
19
  module ClamAV
20
20
  class ErrorResponse < Response
21
+
22
+ def initialize(error_str)
23
+ @error_str = error_str
24
+ end
25
+
21
26
  end
22
27
  end
@@ -18,5 +18,10 @@ require 'clamav/responses'
18
18
 
19
19
  module ClamAV
20
20
  class SuccessResponse < Response
21
+
22
+ def initialize(file)
23
+ @file = file
24
+ end
25
+
21
26
  end
22
27
  end
@@ -18,5 +18,11 @@ require 'clamav/responses'
18
18
 
19
19
  module ClamAV
20
20
  class VirusResponse < Response
21
+
22
+ def initialize(file, virus_name)
23
+ @file = file
24
+ @virus_name = virus_name
25
+ end
26
+
21
27
  end
22
28
  end
@@ -0,0 +1,7 @@
1
+ # Update Ubuntu and install ClamAV
2
+ apt-get update
3
+ apt-get install clamav-daemon clamav-freshclam clamav-unofficial-sigs
4
+
5
+ # Update the signature database and start the daemon
6
+ freshclam
7
+ service clamav-daemon start
@@ -40,32 +40,42 @@ describe "ClamAV::Client Integration Tests" do
40
40
  end
41
41
 
42
42
  describe "scan" do
43
+ let(:base_path) { File.expand_path('../../../../', __FILE__) }
44
+
43
45
  it "can be started" do
44
- dir = File.expand_path('../../../../test/fixtures', __FILE__)
46
+ dir = File.join(base_path, 'test/fixtures')
45
47
  results = client.execute(ClamAV::Commands::ScanCommand.new(dir))
46
48
 
47
- expected_results = [
48
- ClamAV::VirusResponse.new("/Users/cesario/Development/clamav-client/test/fixtures/clamavtest.gz"),
49
- ClamAV::VirusResponse.new("/Users/cesario/Development/clamav-client/test/fixtures/clamavtest.txt"),
50
- ClamAV::VirusResponse.new("/Users/cesario/Development/clamav-client/test/fixtures/clamavtest.zip"),
51
- ClamAV::SuccessResponse.new("/Users/cesario/Development/clamav-client/test/fixtures/innocent.txt")
52
- ]
53
- assert_equal expected_results, results
49
+ expected_results = {
50
+ "#{base_path}/test/fixtures/clamavtest.gz" => ClamAV::VirusResponse,
51
+ "#{base_path}/test/fixtures/clamavtest.txt" => ClamAV::VirusResponse,
52
+ "#{base_path}/test/fixtures/clamavtest.zip" => ClamAV::VirusResponse,
53
+ "#{base_path}/test/fixtures/innocent.txt" => ClamAV::SuccessResponse
54
+ }
55
+
56
+ results.each do |result|
57
+ expected_result = expected_results[result.file]
58
+ assert_equal expected_result, result.class
59
+ end
54
60
  end
55
61
  end
56
62
 
57
63
  describe "instream" do
58
- it "can be started" do
59
- dir = File.expand_path('../../../../test/fixtures', __FILE__)
60
-
61
- [
62
- ['clamavtest.txt', ClamAV::VirusResponse],
63
- ['innocent.txt', ClamAV::SuccessResponse]
64
- ].each do |file, response_class|
65
- io = File.open(File.join(dir, file))
66
- command = ClamAV::Commands::InstreamCommand.new(io)
67
- client.execute(command).must_equal response_class.new("stream")
68
- end
64
+ let(:dir) { File.expand_path('../../../../test/fixtures', __FILE__) }
65
+
66
+ it "can recognize a sane file" do
67
+ command = build_command_for_file('innocent.txt')
68
+ client.execute(command).must_equal ClamAV::SuccessResponse.new("stream")
69
+ end
70
+
71
+ it "can recognize an infected file" do
72
+ command = build_command_for_file('clamavtest.txt')
73
+ client.execute(command).must_equal ClamAV::VirusResponse.new("stream", "ClamAV-Test-Signature")
74
+ end
75
+
76
+ def build_command_for_file(file)
77
+ io = File.open(File.join(dir, file))
78
+ ClamAV::Commands::InstreamCommand.new(io)
69
79
  end
70
80
  end
71
81
  end
@@ -19,15 +19,22 @@ describe "ClamAV::Client Integration Tests" do
19
19
  describe "Util" do
20
20
  describe "absolute_path" do
21
21
  it "transforms a single file to an array of one element" do
22
- assert_equal [File.absolute_path(__FILE__)], ClamAV::Util.path_to_files(__FILE__)
22
+ expected_path = File.absolute_path(__FILE__)
23
+ actual_path = ClamAV::Util.path_to_files(__FILE__).first
24
+ assert_equal expected_path, actual_path
23
25
  end
24
26
 
25
27
  it "transforms a directory to an array of N element" do
26
28
  files = %w(
27
- /Users/cesario/Development/clamav-client/test/integration/clamav/client_test.rb
28
- /Users/cesario/Development/clamav-client/test/integration/clamav/util_test.rb
29
- )
30
- assert_equal files, ClamAV::Util.path_to_files(File.dirname(__FILE__))
29
+ clamav-client/test/integration/clamav/client_test.rb
30
+ clamav-client/test/integration/clamav/util_test.rb
31
+ ).sort
32
+ actual_files = ClamAV::Util.path_to_files(File.dirname(__FILE__)).sort
33
+
34
+ files.each_with_index do |file, index|
35
+ path = Regexp.new(".*/#{file}")
36
+ assert path.match(actual_files[index])
37
+ end
31
38
  end
32
39
  end
33
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamav-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck Verrot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-22 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - ChangeLog.md
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md
@@ -95,6 +96,7 @@ files:
95
96
  - lib/clamav/wrapper.rb
96
97
  - lib/clamav/wrappers/new_line_wrapper.rb
97
98
  - lib/clamav/wrappers/null_termination_wrapper.rb
99
+ - test/ci-setup.sh
98
100
  - test/fixtures/clamavtest.gz
99
101
  - test/fixtures/clamavtest.txt
100
102
  - test/fixtures/clamavtest.zip
@@ -134,6 +136,7 @@ signing_key:
134
136
  specification_version: 4
135
137
  summary: ClamAV::Client connects to a Clam Anti-Virus clam daemon and send commands.
136
138
  test_files:
139
+ - test/ci-setup.sh
137
140
  - test/fixtures/clamavtest.gz
138
141
  - test/fixtures/clamavtest.txt
139
142
  - test/fixtures/clamavtest.zip