smart_proxy_openscap 0.6.10 → 0.6.11
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/bin/smart-proxy-arf-json +1 -1
- data/lib/smart_proxy_openscap/arf_json.rb +4 -1
- data/lib/smart_proxy_openscap/arf_parser.rb +5 -1
- data/lib/smart_proxy_openscap/spool_forwarder.rb +1 -1
- data/lib/smart_proxy_openscap/storage_fs.rb +2 -2
- data/lib/smart_proxy_openscap/version.rb +1 -1
- data/test/script_class_test.rb +4 -2
- data/test/spool_forwarder_test.rb +11 -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: 6076ca39518813d5f4ac1dbf16a0f741200c8d66
|
4
|
+
data.tar.gz: 0045badb98b310b25bed8fd61faae944856dfcf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2acd7a57974547171d678219a32ac804a6606f5508ff20bcfbe07bc348c8ef5c1d7802618ee69fa79590898748a6d2f3724bcf2354c271d27dcdef95deeb2f17
|
7
|
+
data.tar.gz: 54fd17a312559d449bbbcf0a7d5d6826e9c1149d6d55503f80575c2087302ff687ee9beed33c927343aad234c4978e2c9ea64f9640a7178012de8c2c92575e5a
|
data/bin/smart-proxy-arf-json
CHANGED
@@ -12,7 +12,7 @@ require 'digest'
|
|
12
12
|
module Proxy
|
13
13
|
module OpenSCAP
|
14
14
|
class ArfJson
|
15
|
-
def as_json(file_in, file_out)
|
15
|
+
def as_json(file_in, file_out, proxy_name, proxy_url)
|
16
16
|
::OpenSCAP.oscap_init
|
17
17
|
arf_digest = Digest::SHA256.hexdigest(File.read(file_in))
|
18
18
|
|
@@ -26,6 +26,9 @@ module Proxy
|
|
26
26
|
items = benchmark.items
|
27
27
|
|
28
28
|
report = parse_results(items, results, arf_digest)
|
29
|
+
report[:openscap_proxy_name] = proxy_name
|
30
|
+
report[:openscap_proxy_url] = proxy_url
|
31
|
+
|
29
32
|
File.write file_out, report.to_json
|
30
33
|
ensure
|
31
34
|
cleanup test_result, benchmark, sds, arf
|
@@ -28,7 +28,11 @@ module Proxy
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def command(in_file, out_file)
|
31
|
-
"#{script_location}
|
31
|
+
"#{script_location} " <<
|
32
|
+
"#{in_file.path} " <<
|
33
|
+
"#{out_file.path} " <<
|
34
|
+
"#{Proxy::OpenSCAP::Plugin.settings.registered_proxy_name} " <<
|
35
|
+
"#{Proxy::OpenSCAP::Plugin.settings.registered_proxy_url}"
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -59,7 +59,7 @@ module Proxy::OpenSCAP
|
|
59
59
|
logger.error "Failed to parse Arf Report at #{arf_file_path}, moving to #{@loaded_settings.corrupted_dir}"
|
60
60
|
|
61
61
|
Proxy::OpenSCAP::StorageFS.new(@loaded_settings.corrupted_dir, cname, policy_id, date).
|
62
|
-
move_corrupted(arf_file_path.split('/').last)
|
62
|
+
move_corrupted(arf_file_path.split('/').last, @loaded_settings.spooldir)
|
63
63
|
|
64
64
|
rescue StandardError => e
|
65
65
|
logger.error "smart-proxy-openscap-send failed to upload Compliance report for #{cname}, generated on #{Time.at date.to_i}. Cause: #{e}"
|
@@ -18,8 +18,8 @@ module Proxy::OpenSCAP
|
|
18
18
|
store(data, StoreCorruptedError)
|
19
19
|
end
|
20
20
|
|
21
|
-
def move_corrupted(digest)
|
22
|
-
source = "#{
|
21
|
+
def move_corrupted(digest, spooldir)
|
22
|
+
source = "#{spooldir}/#{@namespace}/#{@cname}/#{@id}/#{@date}"
|
23
23
|
move "#{source}/#{digest}", StoreCorruptedError
|
24
24
|
end
|
25
25
|
|
data/test/script_class_test.rb
CHANGED
@@ -17,10 +17,12 @@ class ScriptClassTest < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
def test_arf_as_json
|
19
19
|
carry_out do |tmp|
|
20
|
-
Proxy::OpenSCAP::ArfJson.new.as_json("#{Dir.getwd}/test/data/arf_report", tmp.path)
|
20
|
+
Proxy::OpenSCAP::ArfJson.new.as_json("#{Dir.getwd}/test/data/arf_report", tmp.path, 'my-proxy', 'http://test-proxy.org')
|
21
21
|
json = read_json tmp
|
22
22
|
refute json['logs'].empty?
|
23
23
|
refute json['metrics'].empty?
|
24
|
+
refute json['openscap_proxy_name'].empty?
|
25
|
+
refute json['openscap_proxy_url'].empty?
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -53,7 +55,7 @@ class ScriptClassTest < Test::Unit::TestCase
|
|
53
55
|
|
54
56
|
def test_arf_json
|
55
57
|
carry_out do |tmp|
|
56
|
-
Proxy::OpenSCAP::ArfJson.new.as_json("#{Dir.getwd}/test/data/arf_report", tmp.path)
|
58
|
+
Proxy::OpenSCAP::ArfJson.new.as_json("#{Dir.getwd}/test/data/arf_report", tmp.path, 'my-proxy', 'http://test-proxy.org')
|
57
59
|
json = read_json tmp
|
58
60
|
refute json['logs'].empty?
|
59
61
|
refute json['metrics'].empty?
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'smart_proxy_openscap'
|
3
3
|
require 'smart_proxy_openscap/openscap_lib'
|
4
|
+
require 'ostruct'
|
4
5
|
|
5
6
|
class SpoolForwarderTest < Test::Unit::TestCase
|
6
7
|
def setup
|
@@ -9,11 +10,13 @@ class SpoolForwarderTest < Test::Unit::TestCase
|
|
9
10
|
@base_spool_for_test = ("#{Dir.getwd}/test/data/spool")
|
10
11
|
@results_path = ("#{Dir.getwd}/test/test_run_files")
|
11
12
|
FileUtils.mkdir_p(@results_path)
|
12
|
-
Proxy::OpenSCAP::Plugin.settings.stubs(:contentdir).returns(@results_path)
|
13
13
|
@spooldir = @results_path + "/spool"
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
@loaded_settings = OpenStruct.new(
|
15
|
+
:spooldir => @spooldir,
|
16
|
+
:contentdir => @results_path,
|
17
|
+
:reportsdir => @results_path + "/reports",
|
18
|
+
:corrupted_dir => @results_path + "/corrupted")
|
19
|
+
|
17
20
|
@policy_id = 1
|
18
21
|
@date_1 = 1484309984
|
19
22
|
@date_2 = 1484313035
|
@@ -24,14 +27,13 @@ class SpoolForwarderTest < Test::Unit::TestCase
|
|
24
27
|
@cname = "e20b9695-f655-401a-9dda-8cca7a47a8c0"
|
25
28
|
@cname_2 = "2c101b95-033f-4b15-b490-f50bf9090dae"
|
26
29
|
|
27
|
-
@arf_dir = File.join(
|
30
|
+
@arf_dir = File.join(@loaded_settings.spooldir, "/arf")
|
28
31
|
|
29
32
|
stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname}/#{@policy_id}/#{@date_1}")
|
30
33
|
.to_return(:status => 200, :body => "{\"result\":\"OK\",\"id\":\"#{@id_1}\"}")
|
31
34
|
|
32
35
|
stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname}/#{@policy_id}/#{@date_2}")
|
33
36
|
.to_return(:status => 200, :body => "{\"result\":\"OK\",\"id\":\"#{@id_2}\"}")
|
34
|
-
|
35
37
|
end
|
36
38
|
|
37
39
|
def teardown
|
@@ -42,7 +44,7 @@ class SpoolForwarderTest < Test::Unit::TestCase
|
|
42
44
|
test_spool = @base_spool_for_test + "/valid_spool/"
|
43
45
|
FileUtils.cp_r test_spool, @spooldir
|
44
46
|
|
45
|
-
Proxy::OpenSCAP::SpoolForwarder.new.post_arf_from_spool(@arf_dir)
|
47
|
+
Proxy::OpenSCAP::SpoolForwarder.new(@loaded_settings).post_arf_from_spool(@arf_dir)
|
46
48
|
assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_1}/#{@date_1}/#{@valid_digest}"), "File should be in reports directory")
|
47
49
|
assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_2}/#{@date_2}/#{@valid_digest}"), "File should be in reports directory")
|
48
50
|
refute(File.file?("#{@spooldir}/arf/#{@cname}/#{@policy_id}/#{@date_1}/#{@valid_digest}"), "File should not be in spool directory")
|
@@ -53,7 +55,7 @@ class SpoolForwarderTest < Test::Unit::TestCase
|
|
53
55
|
test_spool = @base_spool_for_test + "/corrupted_spool/"
|
54
56
|
FileUtils.cp_r test_spool, @spooldir
|
55
57
|
|
56
|
-
Proxy::OpenSCAP::SpoolForwarder.new.post_arf_from_spool(@arf_dir)
|
58
|
+
Proxy::OpenSCAP::SpoolForwarder.new(@loaded_settings).post_arf_from_spool(@arf_dir)
|
57
59
|
|
58
60
|
assert(File.file?("#{@results_path}/corrupted/arf/#{@cname}/#{@policy_id}/#{@date_1}/#{@corrupted_digest}"), "File should be in corrupted directory")
|
59
61
|
assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_2}/#{@date_2}/#{@valid_digest}"), "File should be in reports directory")
|
@@ -72,7 +74,7 @@ class SpoolForwarderTest < Test::Unit::TestCase
|
|
72
74
|
stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname_2}/#{@policy_id}/#{@date_2}")
|
73
75
|
.to_return(:status => 500)
|
74
76
|
|
75
|
-
Proxy::OpenSCAP::SpoolForwarder.new.post_arf_from_spool(@arf_dir)
|
77
|
+
Proxy::OpenSCAP::SpoolForwarder.new(@loaded_settings).post_arf_from_spool(@arf_dir)
|
76
78
|
|
77
79
|
assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_1}/#{@date_1}/#{@valid_digest}"), "File should be in reports directory")
|
78
80
|
assert(File.file?("#{@spooldir}/arf/#{@cname_2}/#{@policy_id}/#{@date_2}/#{@valid_digest}"), "File should be in spool directory")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_openscap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Šimon Lukašík
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|