clamav-client 1.0.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.
@@ -0,0 +1,30 @@
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
+ module ClamAV
18
+ class Response
19
+ def initialize(file)
20
+ @file = file
21
+ end
22
+
23
+ def ==(other)
24
+ @file == other.file
25
+ end
26
+
27
+ protected
28
+ attr_reader :file
29
+ end
30
+ end
@@ -0,0 +1,21 @@
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 'clamav/responses'
18
+ module ClamAV
19
+ class ErrorResponse < Response
20
+ end
21
+ end
@@ -0,0 +1,21 @@
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 'clamav/responses'
18
+ module ClamAV
19
+ class SuccessResponse < Response
20
+ end
21
+ end
@@ -0,0 +1,21 @@
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 'clamav/responses'
18
+ module ClamAV
19
+ class VirusResponse < Response
20
+ end
21
+ end
@@ -0,0 +1,32 @@
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
+ module ClamAV
18
+ module Util
19
+ UnknownPathException = Class.new(RuntimeError)
20
+
21
+ def Util.path_to_files(path)
22
+ if Dir.exist?(path)
23
+ Dir.glob(path + '/*')
24
+ elsif File.exist?(path)
25
+ [path]
26
+ else
27
+ message =" (path = #{path})"
28
+ raise UnknownPathException.new("#{__FILE__}:#{__LINE__} path_to_files : path argument neither a file nor a directory. Aborting. #{message}")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
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
+ module ClamAV
18
+ class Wrapper
19
+ def wrap_request(request); raise NotImplementedError; end
20
+ def unwrap_response(response); raise NotImplementedError; end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
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 'clamav/wrapper'
18
+
19
+ module ClamAV
20
+ module Wrappers
21
+ class NewLineWrapper < ::ClamAV::Wrapper
22
+ def wrap_request(request)
23
+ "n#{request}\n"
24
+ end
25
+
26
+ def read_response(socket)
27
+ buff = ""
28
+ while (char = socket.getc) != "\n"
29
+ buff << char
30
+ end
31
+ buff
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
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 'clamav/wrapper'
18
+
19
+ module ClamAV
20
+ module Wrappers
21
+ class NullTerminationWrapper < ::ClamAV::Wrapper
22
+ def wrap_request(request)
23
+ "z#{request}\0"
24
+ end
25
+
26
+ def read_response(socket)
27
+ buff = ""
28
+ while (char = socket.getc) != "\0"
29
+ buff << char
30
+ end
31
+ buff
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ $CEliacmaTrESTuScikgsn$FREE-TEST-SIGNATURE$EEEEE$
@@ -0,0 +1 @@
1
+ Innocent!
@@ -0,0 +1,57 @@
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::Client Integration Tests" do
20
+ describe "default new line delimiter" do
21
+ let(:client) { ClamAV::Client.new }
22
+
23
+ describe "any callable" do
24
+ it "can be used" do
25
+ assert client.execute(lambda { |conn| true })
26
+ end
27
+ end
28
+
29
+ describe "ping" do
30
+ let(:ping_command) { ClamAV::Commands::PingCommand.new }
31
+
32
+ it "can be sent" do
33
+ assert client.execute(ping_command)
34
+ end
35
+
36
+ it "can be sent multiple times" do
37
+ assert client.execute(ping_command)
38
+ assert client.execute(ping_command)
39
+ end
40
+ end
41
+
42
+ describe "scan" do
43
+ it "can be started" do
44
+ dir = File.expand_path('../../../../test/fixtures', __FILE__)
45
+ results = client.execute(ClamAV::Commands::ScanCommand.new(dir))
46
+
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
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,34 @@
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
+ describe "ClamAV::Client Integration Tests" do
19
+ describe "Util" do
20
+ describe "absolute_path" do
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__)
23
+ end
24
+
25
+ it "transforms a directory to an array of N element" do
26
+ 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__))
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
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 'minitest/autorun'
18
+
19
+ require 'clamav/client'
@@ -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 "ClamAV::Client" do
20
+ describe "its instantiation" do
21
+
22
+ let(:conn) { Minitest::Mock.new }
23
+
24
+ it "can have its connection injected" do
25
+ # Given
26
+ conn.expect(:establish_connection, nil, [])
27
+
28
+ # When
29
+ ClamAV::Client.new(conn)
30
+
31
+ # Then
32
+ conn.verify
33
+ end
34
+
35
+ end
36
+ 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