class IncompleteDataTest(unittest.TestCase): def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def nothing_given_test(self): with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def no_content_type_test(self): for line in ["content-url = http://example.com/test_ds.xml", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def no_content_url_test(self): for line in ["content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def no_profile_test(self): for line in ["content-url = http://example.com/test_ds.xml", "content-type = datastream", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() self.assertEqual(self.oscap_data.profile_id, "default")
class IncompleteDataTest(unittest.TestCase): def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def nothing_given_test(self): with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def no_content_type_test(self): for line in ["content-url = http://example.com/test_ds.xml", "profile = Web Server"]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def no_content_url_test(self): for line in ["content-type = datastream", "profile = Web Server"]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def no_profile_test(self): for line in ["content-url = http://example.com/test_ds.xml", "content-type = datastream"]: self.oscap_data.handle_line(line) self.oscap_data.finalize() self.assertEqual(self.oscap_data.profile_id, "default")
class EverythingOKtest(unittest.TestCase): def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def enough_for_ds_test(self): for line in ["content-url = http://example.com/test_ds.xml", "content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() def enough_for_rpm_test(self): for line in ["content-url = http://example.com/oscap_content.rpm", "content-type = RPM", "profile = Web Server", "xccdf-path = /usr/share/oscap/xccdf.xml" ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() def enough_for_archive_test(self): for line in ["content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", "xccdf-path = /usr/share/oscap/xccdf.xml" ]: self.oscap_data.handle_line(line) self.oscap_data.finalize()
class EverythingOKtest(unittest.TestCase): def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def enough_for_ds_test(self): for line in [ "content-url = http://example.com/test_ds.xml", "content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() def enough_for_rpm_test(self): for line in [ "content-url = http://example.com/oscap_content.rpm", "content-type = RPM", "profile = Web Server", "xccdf-path = /usr/share/oscap/xccdf.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() def enough_for_archive_test(self): for line in [ "content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", "xccdf-path = /usr/share/oscap/xccdf.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize()
class InvalidDataTest(unittest.TestCase): def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def rpm_without_path_test(self): for line in [ "content-url = http://example.com/oscap_content.rpm", "content-type = RPM", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def rpm_with_wrong_suffix_test(self): for line in [ "content-url = http://example.com/oscap_content.xml", "content-type = RPM", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def archive_without_path_test(self): for line in [ "content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def unsupported_archive_type_test(self): for line in [ "content-url = http://example.com/oscap_content.tbz", "content-type = archive", "profile = Web Server", "xccdf-path = xccdf.xml", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize()
class InvalidDataTest(unittest.TestCase): def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def rpm_without_path_test(self): for line in [ "content-url = http://example.com/oscap_content.rpm", "content-type = RPM", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def rpm_with_wrong_suffix_test(self): for line in [ "content-url = http://example.com/oscap_content.xml", "content-type = RPM", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def archive_without_path_test(self): for line in [ "content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize() def unsupported_archive_type_test(self): for line in [ "content-url = http://example.com/oscap_content.tbz", "content-type = archive", "profile = Web Server", "xccdf-path = xccdf.xml" ]: self.oscap_data.handle_line(line) with self.assertRaises(KickstartValueError): self.oscap_data.finalize()
class ArchiveHandlingTest(unittest.TestCase): """Tests for handling archives.""" def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def archive_preinst_content_path_test(self): for line in ["content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", "xccdf-path = oscap/xccdf.xml" ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name should be the archive's name self.assertEqual(self.oscap_data.content_name, "oscap_content.tar") # content path should end with the xccdf path self.assertTrue(self.oscap_data.preinst_content_path.endswith( "oscap/xccdf.xml")) def ds_preinst_content_path_test(self): for line in ["content-url = http://example.com/scap_content.xml", "content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # both content_name and content path should point to the data stream # XML self.assertEqual(self.oscap_data.content_name, "scap_content.xml") self.assertTrue(self.oscap_data.preinst_content_path.endswith( "scap_content.xml")) def archive_raw_content_paths_test(self): for line in ["content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", "xccdf-path = oscap/xccdf.xml", "tailoring-path = oscap/tailoring.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name should be the archive's name self.assertEqual(self.oscap_data.content_name, "oscap_content.tar") # content path should end with the archive's name self.assertTrue(self.oscap_data.raw_preinst_content_path.endswith( "oscap_content.tar")) self.assertTrue(self.oscap_data.raw_postinst_content_path.endswith( "oscap_content.tar")) # tailoring paths should be returned properly self.assertEqual(self.oscap_data.preinst_tailoring_path, common.INSTALLATION_CONTENT_DIR + self.oscap_data.tailoring_path) self.assertEqual(self.oscap_data.postinst_tailoring_path, common.TARGET_CONTENT_DIR + self.oscap_data.tailoring_path) def rpm_raw_content_paths_test(self): for line in ["content-url = http://example.com/oscap_content.rpm", "content-type = rpm", "profile = Web Server", "xccdf-path = /usr/share/oscap/xccdf.xml", "tailoring-path = /usr/share/oscap/tailoring.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name should be the rpm's name self.assertEqual(self.oscap_data.content_name, "oscap_content.rpm") # content path should end with the rpm's name self.assertTrue(self.oscap_data.raw_preinst_content_path.endswith( "oscap_content.rpm")) self.assertTrue(self.oscap_data.raw_postinst_content_path.endswith( "oscap_content.rpm")) # content paths should be returned as expected self.assertEqual(self.oscap_data.preinst_content_path, os.path.normpath(common.INSTALLATION_CONTENT_DIR + self.oscap_data.content_path)) # when using rpm, content_path doesn't change for the post-installation # phase self.assertEqual(self.oscap_data.postinst_content_path, self.oscap_data.content_path) def ds_raw_content_paths_test(self): for line in ["content-url = http://example.com/scap_content.xml", "content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name and content paths should all point to the data stream # XML self.assertEqual(self.oscap_data.content_name, "scap_content.xml") self.assertTrue(self.oscap_data.raw_preinst_content_path.endswith( "scap_content.xml")) self.assertTrue(self.oscap_data.raw_postinst_content_path.endswith( "scap_content.xml"))
class ArchiveHandlingTest(unittest.TestCase): """Tests for handling archives.""" def setUp(self): self.oscap_data = OSCAPdata("org_fedora_oscap") def archive_preinst_content_path_test(self): for line in [ "content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", "xccdf-path = oscap/xccdf.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name should be the archive's name self.assertEqual(self.oscap_data.content_name, "oscap_content.tar") # content path should end with the xccdf path self.assertTrue(self.oscap_data.preinst_content_path.endswith("oscap/xccdf.xml")) def ds_preinst_content_path_test(self): for line in [ "content-url = http://example.com/scap_content.xml", "content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # both content_name and content path should point to the data stream XML self.assertEqual(self.oscap_data.content_name, "scap_content.xml") self.assertTrue(self.oscap_data.preinst_content_path.endswith("scap_content.xml")) def archive_raw_content_paths_test(self): for line in [ "content-url = http://example.com/oscap_content.tar", "content-type = archive", "profile = Web Server", "xccdf-path = oscap/xccdf.xml", "tailoring-path = oscap/tailoring.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name should be the archive's name self.assertEqual(self.oscap_data.content_name, "oscap_content.tar") # content path should end with the archive's name self.assertTrue(self.oscap_data.raw_preinst_content_path.endswith("oscap_content.tar")) self.assertTrue(self.oscap_data.raw_postinst_content_path.endswith("oscap_content.tar")) # tailoring paths should be returned properly self.assertEqual( self.oscap_data.preinst_tailoring_path, common.INSTALLATION_CONTENT_DIR + self.oscap_data.tailoring_path ) self.assertEqual( self.oscap_data.postinst_tailoring_path, common.TARGET_CONTENT_DIR + self.oscap_data.tailoring_path ) def rpm_raw_content_paths_test(self): for line in [ "content-url = http://example.com/oscap_content.rpm", "content-type = rpm", "profile = Web Server", "xccdf-path = /usr/share/oscap/xccdf.xml", "tailoring-path = /usr/share/oscap/tailoring.xml", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name should be the rpm's name self.assertEqual(self.oscap_data.content_name, "oscap_content.rpm") # content path should end with the rpm's name self.assertTrue(self.oscap_data.raw_preinst_content_path.endswith("oscap_content.rpm")) self.assertTrue(self.oscap_data.raw_postinst_content_path.endswith("oscap_content.rpm")) # content paths should be returned as expected self.assertEqual( self.oscap_data.preinst_content_path, os.path.normpath(common.INSTALLATION_CONTENT_DIR + self.oscap_data.xccdf_path), ) # when using rpm, xccdf_path doesn't change for the post-installation # phase self.assertEqual(self.oscap_data.postinst_content_path, self.oscap_data.xccdf_path) def ds_raw_content_paths_test(self): for line in [ "content-url = http://example.com/scap_content.xml", "content-type = datastream", "profile = Web Server", ]: self.oscap_data.handle_line(line) self.oscap_data.finalize() # content_name and content paths should all point to the data stream XML self.assertEqual(self.oscap_data.content_name, "scap_content.xml") self.assertTrue(self.oscap_data.raw_preinst_content_path.endswith("scap_content.xml")) self.assertTrue(self.oscap_data.raw_postinst_content_path.endswith("scap_content.xml"))