op-clamav-client 3.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ # clamav-client - ClamAV client
2
+ # Copyright (C) 2014 Franck Verrot <franck@verrot.fr>
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test_helper'
18
+
19
+ describe "INSTREAM command" do
20
+ before do
21
+ @conn = Minitest::Mock.new
22
+ @io = ::StringIO.new('hello')
23
+ end
24
+
25
+ after do
26
+ @conn.verify
27
+ end
28
+
29
+ it "can process an IO object" do
30
+ @conn.expect(:write_request, nil, ["INSTREAM"])
31
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x05hello"])
32
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x00"])
33
+ @conn.expect(:read_response, '1: stream: OK', [])
34
+
35
+ assert ClamAV::Commands::InstreamCommand.new(@io).call(@conn)
36
+ end
37
+
38
+ it "can specify the size of read chunks" do
39
+ chunk_size = 1
40
+
41
+ @conn.expect(:write_request, nil, ["INSTREAM"])
42
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x01h"])
43
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x01e"])
44
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x01l"])
45
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x01l"])
46
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x01o"])
47
+ @conn.expect(:raw_write, nil, ["\x00\x00\x00\x00"])
48
+ @conn.expect(:read_response, '1: stream: OK', [])
49
+
50
+ assert ClamAV::Commands::InstreamCommand.
51
+ new(@io, chunk_size).call(@conn)
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ # clamav-client - ClamAV client
2
+ # Copyright (C) 2014 Franck Verrot <franck@verrot.fr>
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test_helper'
18
+
19
+ describe "PingCommand" do
20
+ before do
21
+ @conn = Minitest::Mock.new
22
+ end
23
+
24
+ after do
25
+ @conn.verify
26
+ end
27
+
28
+ it "can be called" do
29
+ @conn.expect(:send_request, '42: PONG', ["PING"])
30
+
31
+ assert ClamAV::Commands::PingCommand.new.call(@conn)
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ # clamav-client - ClamAV client
2
+ # Copyright (C) 2014 Franck Verrot <franck@verrot.fr>
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test_helper'
18
+
19
+ describe "ScanCommand" do
20
+ before do
21
+ @conn = Minitest::Mock.new
22
+ @path = 'some path'
23
+ end
24
+
25
+ after do
26
+ @conn.verify
27
+ end
28
+
29
+ it "can recognize a sane file" do
30
+ @conn.expect(:send_request, "1: #{@path}: OK", ["SCAN #{@path}"])
31
+
32
+ ClamAV::Util.stub :path_to_files, [@path] do
33
+ assert ClamAV::Commands::ScanCommand.new(@path).call(@conn)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,46 @@
1
+ # clamav-client - ClamAV client
2
+ # Copyright (C) 2014 Franck Verrot <franck@verrot.fr>
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test_helper'
18
+
19
+ describe "ClamAV::Connection" do
20
+ let(:client) { ClamAV::Client.new }
21
+ let(:wrapper) { ClamAV::Wrappers::NewLineWrapper.new }
22
+ let(:socket_mock) do
23
+ mock = Minitest::Mock.new
24
+ mock.expect(:!, false)
25
+ end
26
+
27
+ it "requires a client, a socket and a wrapper" do
28
+ assert_raises(ArgumentError) { ClamAV::Connection.new }
29
+ assert_raises(ArgumentError) { ClamAV::Connection.new(socket: socket_mock, wrapper: wrapper) }
30
+ assert_raises(ArgumentError) { ClamAV::Connection.new(client: client, wrapper: wrapper) }
31
+ assert_raises(ArgumentError) { ClamAV::Connection.new(client: client, socket: socket_mock) }
32
+ end
33
+
34
+ it "can be constructed with a client, a socket and wrapper class" do
35
+ ClamAV::Connection.new(client: client, socket: socket_mock, wrapper: wrapper)
36
+ end
37
+
38
+ it "support raw writes" do
39
+ socket_mock.expect(:write, nil, ["foo"])
40
+
41
+ conn = ClamAV::Connection.new(client: client, socket: socket_mock, wrapper: wrapper)
42
+ conn.raw_write("foo")
43
+
44
+ socket_mock.verify
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ # clamav-client - ClamAV client
2
+ # Copyright (C) 2014 Franck Verrot <franck@verrot.fr>
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test_helper'
18
+
19
+ describe "NewLineWrapper" do
20
+ let(:wrapper) { ClamAV::Wrappers::NewLineWrapper.new }
21
+
22
+ it "wraps requests" do
23
+ wrapper.wrap_request("foo").must_equal "nfoo\n"
24
+ end
25
+
26
+ it "read responses" do
27
+ # Mock an IO object
28
+ socket_mock = Class.new do
29
+ def getc
30
+ @val ||= "hello\n"
31
+ @val.slice!(0)
32
+ end
33
+ end.new
34
+
35
+ wrapper.read_response(socket_mock).must_equal "hello"
36
+ end
37
+
38
+ end
@@ -0,0 +1,38 @@
1
+ # clamav-client - ClamAV client
2
+ # Copyright (C) 2014 Franck Verrot <franck@verrot.fr>
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ require 'test_helper'
18
+
19
+ describe "NullTerminationWrapper" do
20
+ let(:wrapper) { ClamAV::Wrappers::NullTerminationWrapper.new }
21
+
22
+ it "wraps requests" do
23
+ wrapper.wrap_request("foo").must_equal "zfoo\0"
24
+ end
25
+
26
+ it "read responses" do
27
+ # Mock an IO object
28
+ socket_mock = Class.new do
29
+ def getc
30
+ @val ||= "hello\0"
31
+ @val.slice!(0)
32
+ end
33
+ end.new
34
+
35
+ wrapper.read_response(socket_mock).must_equal "hello"
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: op-clamav-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.4.2
5
+ platform: ruby
6
+ authors:
7
+ - Franck Verrot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ClamAV::Client connects to a Clam Anti-Virus clam daemon and send commands.
70
+ email:
71
+ - franck@verrot.fr
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ChangeLog.md
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - clamav-client.gemspec
82
+ - lib/clamav.rb
83
+ - lib/clamav/client.rb
84
+ - lib/clamav/commands/command.rb
85
+ - lib/clamav/commands/instream_command.rb
86
+ - lib/clamav/commands/ping_command.rb
87
+ - lib/clamav/commands/quit_command.rb
88
+ - lib/clamav/commands/scan_command.rb
89
+ - lib/clamav/connection.rb
90
+ - lib/clamav/response.rb
91
+ - lib/clamav/responses/error_response.rb
92
+ - lib/clamav/responses/success_response.rb
93
+ - lib/clamav/responses/virus_response.rb
94
+ - lib/clamav/util.rb
95
+ - lib/clamav/wrapper.rb
96
+ - lib/clamav/wrappers/new_line_wrapper.rb
97
+ - lib/clamav/wrappers/null_termination_wrapper.rb
98
+ - test/Dockerfile
99
+ - test/integration/clamav/client_test.rb
100
+ - test/integration/clamav/util_test.rb
101
+ - test/test_helper.rb
102
+ - test/unit/clamav/client_test.rb
103
+ - test/unit/clamav/commands/instream_command_test.rb
104
+ - test/unit/clamav/commands/ping_command_test.rb
105
+ - test/unit/clamav/commands/scan_command_test.rb
106
+ - test/unit/clamav/connection_test.rb
107
+ - test/unit/clamav/wrappers/new_line_wrapper_test.rb
108
+ - test/unit/clamav/wrappers/null_termination_wrapper_test.rb
109
+ homepage: https://github.com/franckverrot/clamav-client
110
+ licenses:
111
+ - GPL-v3
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '2.5'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.4.22
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: ClamAV::Client connects to a Clam Anti-Virus clam daemon and send commands.
132
+ test_files:
133
+ - test/Dockerfile
134
+ - test/integration/clamav/client_test.rb
135
+ - test/integration/clamav/util_test.rb
136
+ - test/test_helper.rb
137
+ - test/unit/clamav/client_test.rb
138
+ - test/unit/clamav/commands/instream_command_test.rb
139
+ - test/unit/clamav/commands/ping_command_test.rb
140
+ - test/unit/clamav/commands/scan_command_test.rb
141
+ - test/unit/clamav/connection_test.rb
142
+ - test/unit/clamav/wrappers/new_line_wrapper_test.rb
143
+ - test/unit/clamav/wrappers/null_termination_wrapper_test.rb