smart_proxy_openscap 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +41 -0
  3. data/.rubocop_todo.yml +111 -0
  4. data/.travis.yml +14 -0
  5. data/COPYING +674 -0
  6. data/Gemfile +14 -0
  7. data/README.md +107 -0
  8. data/Rakefile +16 -0
  9. data/bin/smart-proxy-arf-html +7 -0
  10. data/bin/smart-proxy-arf-json +7 -0
  11. data/bin/smart-proxy-openscap-send +61 -0
  12. data/bin/smart-proxy-policy-guide +7 -0
  13. data/bin/smart-proxy-scap-profiles +7 -0
  14. data/bin/smart-proxy-scap-validation +7 -0
  15. data/bundler.d/openscap.rb +6 -0
  16. data/extra/rubygem-smart_proxy_openscap.spec +101 -0
  17. data/extra/smart-proxy-openscap-send.cron +2 -0
  18. data/lib/smart_proxy_openscap.rb +14 -0
  19. data/lib/smart_proxy_openscap/arf_html.rb +22 -0
  20. data/lib/smart_proxy_openscap/arf_json.rb +114 -0
  21. data/lib/smart_proxy_openscap/arf_parser.rb +39 -0
  22. data/lib/smart_proxy_openscap/content_parser.rb +30 -0
  23. data/lib/smart_proxy_openscap/fetch_file.rb +60 -0
  24. data/lib/smart_proxy_openscap/fetch_scap_content.rb +17 -0
  25. data/lib/smart_proxy_openscap/fetch_tailoring_file.rb +17 -0
  26. data/lib/smart_proxy_openscap/foreman_forwarder.rb +40 -0
  27. data/lib/smart_proxy_openscap/http_config.ru +20 -0
  28. data/lib/smart_proxy_openscap/openscap_api.rb +187 -0
  29. data/lib/smart_proxy_openscap/openscap_exception.rb +9 -0
  30. data/lib/smart_proxy_openscap/openscap_html_generator.rb +38 -0
  31. data/lib/smart_proxy_openscap/openscap_import_api.rb +32 -0
  32. data/lib/smart_proxy_openscap/openscap_lib.rb +67 -0
  33. data/lib/smart_proxy_openscap/openscap_plugin.rb +27 -0
  34. data/lib/smart_proxy_openscap/policy_guide.rb +23 -0
  35. data/lib/smart_proxy_openscap/policy_parser.rb +33 -0
  36. data/lib/smart_proxy_openscap/profiles_parser.rb +32 -0
  37. data/lib/smart_proxy_openscap/scap_profiles.rb +52 -0
  38. data/lib/smart_proxy_openscap/scap_validation.rb +35 -0
  39. data/lib/smart_proxy_openscap/shell_wrapper.rb +77 -0
  40. data/lib/smart_proxy_openscap/spool_forwarder.rb +79 -0
  41. data/lib/smart_proxy_openscap/storage.rb +47 -0
  42. data/lib/smart_proxy_openscap/storage_fs.rb +102 -0
  43. data/lib/smart_proxy_openscap/version.rb +15 -0
  44. data/settings.d/openscap.yml.example +33 -0
  45. data/smart_proxy_openscap.gemspec +23 -0
  46. data/test/data/arf_report +0 -0
  47. data/test/data/corrupted_arf_report +0 -0
  48. data/test/data/spool/cleanup_spool/arf/2c101b95-033f-4b15-b490-f50bf9090dae/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
  49. data/test/data/spool/cleanup_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
  50. data/test/data/spool/corrupted_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/a4dfba5db27b21795e6fa401b8dce7a70faeb25b7963891f07f6f4baaf052afb +0 -0
  51. data/test/data/spool/corrupted_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
  52. data/test/data/spool/valid_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
  53. data/test/data/spool/valid_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1 +0 -0
  54. data/test/data/ssg-rhel7-ds.xml +20271 -0
  55. data/test/data/tailoring.xml +31 -0
  56. data/test/fetch_scap_api_test.rb +73 -0
  57. data/test/fetch_tailoring_api_test.rb +37 -0
  58. data/test/get_report_xml_html_test.rb +58 -0
  59. data/test/post_report_api_test.rb +86 -0
  60. data/test/scap_content_parser_api_test.rb +69 -0
  61. data/test/script_class_test.rb +96 -0
  62. data/test/spool_forwarder_test.rb +84 -0
  63. data/test/test_helper.rb +13 -0
  64. metadata +180 -0
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+ require 'smart_proxy_openscap'
3
+ require 'smart_proxy_openscap/openscap_lib'
4
+ require 'ostruct'
5
+
6
+ class SpoolForwarderTest < Test::Unit::TestCase
7
+ def setup
8
+ @foreman_url = 'https://foreman.example.com'
9
+ Proxy::SETTINGS.stubs(:foreman_url).returns(@foreman_url)
10
+ @base_spool_for_test = ("#{Dir.getwd}/test/data/spool")
11
+ @results_path = ("#{Dir.getwd}/test/test_run_files")
12
+ FileUtils.mkdir_p(@results_path)
13
+ @spooldir = @results_path + "/spool"
14
+ @loaded_settings = OpenStruct.new(
15
+ :spooldir => @spooldir,
16
+ :contentdir => @results_path,
17
+ :reportsdir => @results_path + "/reports",
18
+ :corrupted_dir => @results_path + "/corrupted")
19
+
20
+ @policy_id = 1
21
+ @date_1 = 1484309984
22
+ @date_2 = 1484313035
23
+ @id_1 = 42
24
+ @id_2 = 84
25
+ @valid_digest = "fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1"
26
+ @corrupted_digest = "a4dfba5db27b21795e6fa401b8dce7a70faeb25b7963891f07f6f4baaf052afb"
27
+ @cname = "e20b9695-f655-401a-9dda-8cca7a47a8c0"
28
+ @cname_2 = "2c101b95-033f-4b15-b490-f50bf9090dae"
29
+
30
+ @arf_dir = File.join(@loaded_settings.spooldir, "/arf")
31
+
32
+ stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname}/#{@policy_id}/#{@date_1}")
33
+ .to_return(:status => 200, :body => "{\"result\":\"OK\",\"id\":\"#{@id_1}\"}")
34
+
35
+ stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname}/#{@policy_id}/#{@date_2}")
36
+ .to_return(:status => 200, :body => "{\"result\":\"OK\",\"id\":\"#{@id_2}\"}")
37
+ end
38
+
39
+ def teardown
40
+ FileUtils.rm_rf @results_path
41
+ end
42
+
43
+ def test_send_spool_to_foreman
44
+ test_spool = @base_spool_for_test + "/valid_spool/"
45
+ FileUtils.cp_r test_spool, @spooldir
46
+
47
+ Proxy::OpenSCAP::SpoolForwarder.new(@loaded_settings).post_arf_from_spool(@arf_dir)
48
+ assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_1}/#{@date_1}/#{@valid_digest}"), "File should be in reports directory")
49
+ assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_2}/#{@date_2}/#{@valid_digest}"), "File should be in reports directory")
50
+ refute(File.file?("#{@spooldir}/arf/#{@cname}/#{@policy_id}/#{@date_1}/#{@valid_digest}"), "File should not be in spool directory")
51
+ refute(File.file?("#{@spooldir}/arf/#{@cname}/#{@policy_id}/#{@date_2}/#{@valid_digest}"), "File should not be in spool directory")
52
+ end
53
+
54
+ def test_send_corrupted_spool_to_foreman
55
+ test_spool = @base_spool_for_test + "/corrupted_spool/"
56
+ FileUtils.cp_r test_spool, @spooldir
57
+
58
+ Proxy::OpenSCAP::SpoolForwarder.new(@loaded_settings).post_arf_from_spool(@arf_dir)
59
+
60
+ assert(File.file?("#{@results_path}/corrupted/arf/#{@cname}/#{@policy_id}/#{@date_1}/#{@corrupted_digest}"), "File should be in corrupted directory")
61
+ assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_2}/#{@date_2}/#{@valid_digest}"), "File should be in reports directory")
62
+
63
+ refute(File.file?("#{@spooldir}/arf/#{@cname}/#{@policy_id}/#{@date_1}/#{@corrupted_digest}"), "File should not be in spool directory")
64
+ refute(File.file?("#{@spooldir}/arf/#{@cname}/#{@policy_id}/#{@date_2}/#{@valid_digest}"), "File should not be in spool directory")
65
+ end
66
+
67
+ def test_send_spool_cleans_up
68
+ test_spool = @base_spool_for_test + "/cleanup_spool/"
69
+ FileUtils.cp_r test_spool, @spooldir
70
+
71
+ stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname}/#{@policy_id}/#{@date_1}")
72
+ .to_return(:status => 200, :body => "{\"result\":\"OK\",\"id\":\"#{@id_1}\"}")
73
+
74
+ stub_request(:post, "#{@foreman_url}/api/v2/compliance/arf_reports/#{@cname_2}/#{@policy_id}/#{@date_2}")
75
+ .to_return(:status => 500)
76
+
77
+ Proxy::OpenSCAP::SpoolForwarder.new(@loaded_settings).post_arf_from_spool(@arf_dir)
78
+
79
+ assert(File.file?("#{@results_path}/reports/arf/#{@cname}/#{@id_1}/#{@date_1}/#{@valid_digest}"), "File should be in reports directory")
80
+ assert(File.file?("#{@spooldir}/arf/#{@cname_2}/#{@policy_id}/#{@date_2}/#{@valid_digest}"), "File should be in spool directory")
81
+
82
+ refute(File.exist?("#{@spooldir}/arf/#{@cname}"), "Folder should not exist")
83
+ end
84
+ end
@@ -0,0 +1,13 @@
1
+ require 'rack/test'
2
+ require 'test/unit'
3
+ require 'webmock/test_unit'
4
+ require 'mocha/setup'
5
+ require 'json'
6
+ require 'ostruct'
7
+ require 'tempfile'
8
+
9
+ require 'smart_proxy_for_testing'
10
+
11
+ # create log directory in our (not smart-proxy) directory
12
+ FileUtils.mkdir_p File.dirname(Proxy::SETTINGS.log_file)
13
+ APP_ROOT = "#{File.dirname(__FILE__)}/.."
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_proxy_openscap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.2
5
+ platform: ruby
6
+ authors:
7
+ - Šimon Lukašík
8
+ - Shlomi Zadok
9
+ - Marek Hulan
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2019-05-09 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rack-test
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: mocha
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: webmock
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: openscap
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.7
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 0.4.7
85
+ description: |-
86
+ A plug-in to the Foreman's smart-proxy which receives
87
+ bzip2ed ARF files and forwards them to the Foreman.
88
+ email: slukasik@redhat.com
89
+ executables:
90
+ - smart-proxy-openscap-send
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".rubocop.yml"
95
+ - ".rubocop_todo.yml"
96
+ - ".travis.yml"
97
+ - COPYING
98
+ - Gemfile
99
+ - README.md
100
+ - Rakefile
101
+ - bin/smart-proxy-arf-html
102
+ - bin/smart-proxy-arf-json
103
+ - bin/smart-proxy-openscap-send
104
+ - bin/smart-proxy-policy-guide
105
+ - bin/smart-proxy-scap-profiles
106
+ - bin/smart-proxy-scap-validation
107
+ - bundler.d/openscap.rb
108
+ - extra/rubygem-smart_proxy_openscap.spec
109
+ - extra/smart-proxy-openscap-send.cron
110
+ - lib/smart_proxy_openscap.rb
111
+ - lib/smart_proxy_openscap/arf_html.rb
112
+ - lib/smart_proxy_openscap/arf_json.rb
113
+ - lib/smart_proxy_openscap/arf_parser.rb
114
+ - lib/smart_proxy_openscap/content_parser.rb
115
+ - lib/smart_proxy_openscap/fetch_file.rb
116
+ - lib/smart_proxy_openscap/fetch_scap_content.rb
117
+ - lib/smart_proxy_openscap/fetch_tailoring_file.rb
118
+ - lib/smart_proxy_openscap/foreman_forwarder.rb
119
+ - lib/smart_proxy_openscap/http_config.ru
120
+ - lib/smart_proxy_openscap/openscap_api.rb
121
+ - lib/smart_proxy_openscap/openscap_exception.rb
122
+ - lib/smart_proxy_openscap/openscap_html_generator.rb
123
+ - lib/smart_proxy_openscap/openscap_import_api.rb
124
+ - lib/smart_proxy_openscap/openscap_lib.rb
125
+ - lib/smart_proxy_openscap/openscap_plugin.rb
126
+ - lib/smart_proxy_openscap/policy_guide.rb
127
+ - lib/smart_proxy_openscap/policy_parser.rb
128
+ - lib/smart_proxy_openscap/profiles_parser.rb
129
+ - lib/smart_proxy_openscap/scap_profiles.rb
130
+ - lib/smart_proxy_openscap/scap_validation.rb
131
+ - lib/smart_proxy_openscap/shell_wrapper.rb
132
+ - lib/smart_proxy_openscap/spool_forwarder.rb
133
+ - lib/smart_proxy_openscap/storage.rb
134
+ - lib/smart_proxy_openscap/storage_fs.rb
135
+ - lib/smart_proxy_openscap/version.rb
136
+ - settings.d/openscap.yml.example
137
+ - smart_proxy_openscap.gemspec
138
+ - test/data/arf_report
139
+ - test/data/corrupted_arf_report
140
+ - test/data/spool/cleanup_spool/arf/2c101b95-033f-4b15-b490-f50bf9090dae/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1
141
+ - test/data/spool/cleanup_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1
142
+ - test/data/spool/corrupted_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/a4dfba5db27b21795e6fa401b8dce7a70faeb25b7963891f07f6f4baaf052afb
143
+ - test/data/spool/corrupted_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1
144
+ - test/data/spool/valid_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484309984/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1
145
+ - test/data/spool/valid_spool/arf/e20b9695-f655-401a-9dda-8cca7a47a8c0/1/1484313035/fa2f68ffb944c917332a284dc63ec7f8fa76990cb815ddcad3318b5d9457f8a1
146
+ - test/data/ssg-rhel7-ds.xml
147
+ - test/data/tailoring.xml
148
+ - test/fetch_scap_api_test.rb
149
+ - test/fetch_tailoring_api_test.rb
150
+ - test/get_report_xml_html_test.rb
151
+ - test/post_report_api_test.rb
152
+ - test/scap_content_parser_api_test.rb
153
+ - test/script_class_test.rb
154
+ - test/spool_forwarder_test.rb
155
+ - test/test_helper.rb
156
+ homepage: https://github.com/theforeman/smart_proxy_openscap
157
+ licenses:
158
+ - GPL-3.0-or-later
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.6.8
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: OpenSCAP plug-in for Foreman's smart-proxy.
180
+ test_files: []