From 79cedc4da8983682de265b8bd28645b1d2b04a66 Mon Sep 17 00:00:00 2001 From: Andrew Kofink Date: Fri, 6 Sep 2019 15:23:02 -0400 Subject: [PATCH] Add an SSG module for interacting with SSG Policies and Rules come from the SCAP Security Guide, generated from https://github.com/ComplianceAsCode/content. This adds rake tasks to download and unarchive released versions of SSG for a given application, and a shortcut rake task for all the RHEL SSG content. Signed-off-by: Andrew Kofink --- README.md | 11 +++++ Rakefile | 2 + lib/ssg.rb | 5 ++ lib/ssg/downloader.rb | 94 +++++++++++++++++++++++++++++++++++++ lib/ssg/unarchiver.rb | 34 ++++++++++++++ lib/tasks/ssg.rake | 32 +++++++++++++ openscap_parser.gemspec | 1 + test/ssg/downloader_test.rb | 21 +++++++++ test/ssg/unarchiver_test.rb | 25 ++++++++++ test/test_helper.rb | 1 + 10 files changed, 226 insertions(+) create mode 100644 lib/ssg.rb create mode 100644 lib/ssg/downloader.rb create mode 100644 lib/ssg/unarchiver.rb create mode 100644 lib/tasks/ssg.rake create mode 100644 test/ssg/downloader_test.rb create mode 100644 test/ssg/unarchiver_test.rb diff --git a/README.md b/README.md index 42eba0e..b148984 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,17 @@ parser.rule_results # [# 2.0" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "minitest", "~> 5.0" + spec.add_development_dependency "mocha", "~> 1.0" spec.add_development_dependency "shoulda-context" spec.add_development_dependency "pry" spec.add_development_dependency "pry-byebug" diff --git a/test/ssg/downloader_test.rb b/test/ssg/downloader_test.rb new file mode 100644 index 0000000..75ad7ea --- /dev/null +++ b/test/ssg/downloader_test.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'ssg/downloader' + +module Ssg + class DownloaderTest < MiniTest::Test + context 'fetch_datastream_file' do + test 'returns the fetched file' do + FILE = 'scap-security-guide-0.0.0.zip' + uri = URI("https://example.com/#{FILE}") + downloader = Downloader.new + downloader.expects(:datastream_uri). + at_least_once.returns(uri) + downloader.expects(:get_chunked).with uri + + assert_equal FILE, downloader.fetch_datastream_file + end + end + end +end diff --git a/test/ssg/unarchiver_test.rb b/test/ssg/unarchiver_test.rb new file mode 100644 index 0000000..21018c7 --- /dev/null +++ b/test/ssg/unarchiver_test.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'ssg/unarchiver' + +module Ssg + class UnarchiverTest < MiniTest::Test + context 'datastream_files' do + test 'properly shells out to unzip' do + ZIP_FILE = 'scap-security-guide-0.0.0.zip' + DATASTREAMS = ['rhel6'] + FILES = [] + unarchiver = Unarchiver.new(ZIP_FILE, DATASTREAMS) + unarchiver.expects(:system).with( + "unzip", "-o", + "scap-security-guide-0.0.0.zip", + "scap-security-guide-0.0.0/ssg-rhel6-ds.xml" + ).returns(true) + + assert_equal ['scap-security-guide-0.0.0/ssg-rhel6-ds.xml'], + unarchiver.datastream_files + end + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index c48d75b..bfcc8ab 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,6 +4,7 @@ require "minitest/autorun" require 'shoulda-context' +require 'mocha/minitest' def test(name, &block) test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym