Esempio n. 1
0
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"])
Esempio n. 2
0
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()