def test_repeated_step_names(self): """Check that only unique names exist in the steps and inspect lists""" self.layout.steps = [Step(name="name"), Step(name="name")] with self.assertRaises(securesystemslib.exceptions.FormatError): self.layout.validate() self.layout.steps = [Step(name="name")] self.layout.inspect = [Inspection(name="name")] with self.assertRaises(securesystemslib.exceptions.FormatError): self.layout.validate() self.layout.step = [Step(name="name"), Step(name="othername")] self.layout.inspect = [Inspection(name="thirdname")] self.layout.validate()
def test_get_inspection_by_name(self): """Test getting inspection by name. """ names = ["a", "b", "c"] layout = Layout(inspect=[Inspection(name=name) for name in names]) self.assertEqual(layout.get_inspection_by_name("b").name, "b") with self.assertRaises(securesystemslib.exceptions.FormatError): layout.get_inspection_by_name(1)
def test_remove_inspection_by_name(self): """Test removing inspection by name. """ names = ["a", "b", "c"] layout = Layout(inspect=[Inspection(name=name) for name in names]) self.assertEqual(len(layout.inspect), 3) self.assertTrue("b" in layout.get_inspection_name_list()) # Items are only removed if they exist for _ in range(2): layout.remove_inspection_by_name("b") self.assertEqual(len(layout.inspect), 2) self.assertTrue("b" not in layout.get_inspection_name_list()) with self.assertRaises(securesystemslib.exceptions.FormatError): layout.remove_inspection_by_name(False)
def test_wrong_inspect_list(self): """Check that the validate method checks the inspections' correctness.""" self.layout.inspect = "not-an-inspection" with self.assertRaises(securesystemslib.exceptions.FormatError): self.layout.validate() test_inspection = Inspection(name="this-is-a-step") test_inspection.expected_materials = ['this is a malformed artifact rule'] self.layout.inspect = [test_inspection] with self.assertRaises(securesystemslib.exceptions.FormatError): self.layout.validate() test_inspection = Inspection(name="this-is-a-step") test_inspection.expected_materials = [["CREATE", "foo"]] self.layout.inspect = [test_inspection] self.layout.validate()
def test_set_run_from_string(self): """Test shelx parse command string to list. """ inspection = Inspection() inspection.set_run_from_string("echo 'foo bar'") self.assertListEqual(inspection.run, ["echo", "foo bar"])
def setUp(self): """Populate a base layout that we can use.""" self.inspection = Inspection(name="some-inspection")
class TestInspectionValidator(unittest.TestCase): """Test verifylib.verify_delete_rule(rule, artifact_queue) """ def setUp(self): """Populate a base layout that we can use.""" self.inspection = Inspection(name="some-inspection") def test_wrong_type(self): """Test the type field within Validate().""" self.inspection._type = "wrong" with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection._validate_type() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() self.inspection._type = "inspection" self.inspection._validate_type() def test_wrong_run(self): """Test that the run validators catch malformed values.""" self.inspection.run = -1 with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection._validate_run() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() self.inspection.run = ["somecommand"] self.inspection._validate_run() self.inspection.validate() def test_set_run_from_string(self): """Test shelx parse command string to list. """ inspection = Inspection() inspection.set_run_from_string("echo 'foo bar'") self.assertListEqual(inspection.run, ["echo", "foo bar"])
def test_get_inspection_name_list(self): """Test getting list of inspection names. """ names = ["a", "b", "c"] layout = Layout(inspect=[Inspection(name=name) for name in names]) self.assertListEqual(layout.get_inspection_name_list(), names)
def setUp(self): """Create a dummy supply chain with two steps one inspection and the according link metadata: write-code (Step) -> package (step) -> untar (Inspection) 'write-code' creates an artifact foo 'package' creates foo.tar.gz and deletes foo 'untar' untars foo.tar.gz which results in foo.tar.gz and foo """ self.sha256_foo = \ "d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3" self.sha256_foo_tar = \ "93c3c35a039a6a3d53e81c5dbee4ebb684de57b7c8be11b8739fd35804a0e918" self.steps = [ Step( name="write-code", expected_products=[["CREATE", "foo"]], ), Step( name="package", expected_materials=[[ "MATCH", "foo", "WITH", "PRODUCTS", "FROM", "write-code" ]], expected_products=[["CREATE", "foo.tar.gz"], ["DELETE", "foo"]], ) ] self.inspections = [ Inspection(name="untar", expected_materials=[[ "MATCH", "foo.tar.gz", "WITH", "PRODUCTS", "FROM", "package" ]], expected_products=[[ "MATCH", "foo", "IN", "dir", "WITH", "PRODUCTS", "FROM", "write-code" ]]) ] self.links = { "write-code": Metablock( signed=Link(name="write-code", products={"foo": { "sha256": self.sha256_foo }})), "package": Metablock(signed=Link( name="package", materials={"foo": { "sha256": self.sha256_foo }}, products={"foo.tar.gz": { "sha256": self.sha256_foo_tar }})), "untar": Metablock(signed=Link( name="untar", materials={"foo.tar.gz": { "sha256": self.sha256_foo_tar }}, products={ "dir/foo": { "sha256": self.sha256_foo }, })) }
class TestInspectionValidator(unittest.TestCase): """Test verifylib.verify_delete_rule(rule, artifact_queue) """ def setUp(self): """Populate a base layout that we can use.""" self.inspection = Inspection(name="some-inspection") def test_wrong_type(self): """Test the type field within Validate().""" self.inspection._type = "wrong" with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection._validate_type() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() self.inspection._type = "inspection" self.inspection._validate_type() def test_wrong_expected_materials(self): """Test that the material rule validators catch malformed ones.""" with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.expected_materials = [["NONFOO"]] self.inspection._validate_expected_materials() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.expected_materials = "PFF" self.inspection._validate_expected_materials() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() # for more thorough tests, check the test_artifact_rules.py module self.inspection.expected_materials = [["CREATE", "foo"]] self.inspection._validate_expected_materials() self.inspection.validate() def test_wrong_expected_products(self): """Test that the product rule validators catch malformed values.""" self.inspection.expected_products = [["NONFOO"]] with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection._validate_expected_products() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() self.inspection.expected_products = "PFF" with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection._validate_expected_products() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() # for more thorough tests, check the test_artifact_rules.py module self.inspection.expected_products = [["CREATE", "foo"]] self.inspection._validate_expected_products() self.inspection.validate() def test_wrong_run(self): """Test that the run validators catch malformed values.""" self.inspection.run = -1 with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection._validate_run() with self.assertRaises(securesystemslib.exceptions.FormatError): self.inspection.validate() self.inspection.run = ["somecommand"] self.inspection._validate_run() self.inspection.validate()