|
1 | | -require "test_helper" |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test_helper' |
2 | 4 |
|
3 | 5 | class OpenscapParserTest < Minitest::Test |
4 | | - def test_that_it_has_a_version_number |
5 | | - refute_nil ::OpenscapParser::VERSION |
| 6 | + def setup |
| 7 | + fake_report = file_fixture('xccdf_report.xml').read |
| 8 | + @profile = { |
| 9 | + 'xccdf_org.ssgproject.content_profile_standard' => |
| 10 | + 'Standard System Security Profile for Fedora' |
| 11 | + } |
| 12 | + @report_parser = ::OpenscapParser::Base.new(fake_report) |
6 | 13 | end |
7 | 14 |
|
8 | | - def test_it_does_something_useful |
9 | | - assert false |
| 15 | + context 'profile' do |
| 16 | + should 'be able to parse it' do |
| 17 | + assert_equal(@profile, @report_parser.profiles) |
| 18 | + end |
| 19 | + |
| 20 | + should 'not save more than one profile when there are no test results' do |
| 21 | + fake_report = file_fixture('rhel-xccdf-report.xml').read |
| 22 | + @profile = { |
| 23 | + 'xccdf_org.ssgproject.content_profile_rht-ccp' => |
| 24 | + 'Red Hat Corporate Profile for Certified Cloud Providers (RH CCP)' |
| 25 | + } |
| 26 | + @report_parser = ::OpenscapParser::Base.new(fake_report) |
| 27 | + assert_equal 1, @report_parser.profiles.count |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context 'host' do |
| 32 | + should 'be able to parse host name' do |
| 33 | + assert_equal 'lenovolobato.lobatolan.home', @report_parser.host |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + test 'score can be parsed' do |
| 38 | + assert_equal(16.220238, @report_parser.score) |
| 39 | + end |
| 40 | + |
| 41 | + context 'rules' do |
| 42 | + setup do |
| 43 | + @arbitrary_rules = [ |
| 44 | + # rubocop:disable Metrics/LineLength |
| 45 | + 'xccdf_org.ssgproject.content_rule_dir_perms_world_writable_system_owned', |
| 46 | + 'xccdf_org.ssgproject.content_rule_bios_enable_execution_restrictions', |
| 47 | + 'xccdf_org.ssgproject.content_rule_gconf_gnome_screensaver_lock_enabled', |
| 48 | + 'xccdf_org.ssgproject.content_rule_selinux_all_devicefiles_labeled' |
| 49 | + # rubocop:enable Metrics/LineLength |
| 50 | + ] |
| 51 | + end |
| 52 | + |
| 53 | + should 'list all rules' do |
| 54 | + assert_empty(@arbitrary_rules - @report_parser.rule_ids) |
| 55 | + end |
10 | 56 | end |
11 | 57 | end |
0 commit comments