def test_fail_pattern_matched_nothing_in_target_materials(self): """["MATCH", "MATERIAL", "bar", "FROM", "link-1"], pattern bar does not match any materials in target, fails. """ rule = ["MATCH", "MATERIAL", "bar", "FROM", "link-1"] with self.assertRaises(RuleVerficationFailed): verify_match_rule(rule, [], [], self.links)
def test_fail_pattern_matched_nothing_in_target_products(self): """["MATCH", "PRODUCT", "foo", "FROM", "link-1"], pattern foo does not match any products in target, fails. """ rule = ["MATCH", "PRODUCT", "foo", "FROM", "link-1"] with self.assertRaises(RuleVerficationFailed): # Pass an empty artifacts queue and artifacts dictionary # to match nothing verify_match_rule(rule, [], [], self.links)
def test_fail_hash_matched_but_wrong_name(self): """["MATCH", "MATERIAL", "foo", "FROM", "link-1"], no source artifact matches target material's hash and path pattern, fails. """ rule = ["MATCH", "MATERIAL", "dist/foo", "AS", "foo", "FROM", "link-1"] artifacts = { "foo": { "sha256": self.sha256_foo }, } queue = artifacts.keys() with self.assertRaises(RuleVerficationFailed): verify_match_rule(rule, queue, artifacts, self.links)
def test_fail_hash_not_found_in_artifacts_queue(self): """["MATCH", "MATERIAL", "foo", "FROM", "link-1"], no source artifact still in queue matches target material's hash, fails. """ rule = ["MATCH", "MATERIAL", "foo", "FROM", "link-1"] artifacts = { "foo": { "sha256": self.sha256_foo }, } queue = [] with self.assertRaises(RuleVerficationFailed): verify_match_rule(rule, queue, artifacts, self.links)
def test_fail_target_hash_not_found_in_source_artifacts(self): """["MATCH", "MATERIAL", "foo", "FROM", "link-1"], no source artifact matches target material's hash, fails. """ rule = ["MATCH", "MATERIAL", "foo", "FROM", "link-1"] artifacts = { "bar": { "sha256": self.sha256_bar }, } queue = artifacts.keys() with self.assertRaises(RuleVerficationFailed): verify_match_rule(rule, queue, artifacts, self.links)
def test_pass_match_product_as_name(self): """["MATCH", "PRODUCT", "dist/bar", "AS", "bar", "FROM", "link-1"], source artifact dist/bar and target product bar hahes match, passes. """ rule = ["MATCH", "PRODUCT", "dist/bar", "AS", "bar", "FROM", "link-1"] artifacts = {"dist/bar": {"sha256": self.sha256_bar}} queue = artifacts.keys() self.assertListEqual( verify_match_rule(rule, queue, artifacts, self.links), [])
def test_pass_match_material_as_name(self): """["MATCH", "MATERIAL", "dist/foo", "AS", "foo", "FROM", "link-1"], source artifact dist/foo and target material foo hashes match, passes. """ rule = ["MATCH", "MATERIAL", "dist/foo", "AS", "foo", "FROM", "link-1"] artifacts = {"dist/foo": {"sha256": self.sha256_foo}} queue = artifacts.keys() self.assertListEqual( verify_match_rule(rule, queue, artifacts, self.links), [])
def test_pass_match_product_as_star(self): """["MATCH", "PRODUCT", "dist/*", "AS", "bar*", "FROM", "link-1"], source artifacts dist/* match target products bar* hashes, passes. """ rule = ["MATCH", "PRODUCT", "dist/*", "AS", "bar*", "FROM", "link-1"] artifacts = { "dist/bar": { "sha256": self.sha256_bar }, "dist/barfoo": { "sha256": self.sha256_barfoo } } queue = artifacts.keys() self.assertListEqual( verify_match_rule(rule, queue, artifacts, self.links), [])
def test_pass_match_material_as_star(self): """["MATCH", "MATERIAL", "dist/*", "AS", "foo*", "FROM", "link-1"], source artifacts dist/* match target materials foo* hashes, passes. """ rule = ["MATCH", "MATERIAL", "dist/*", "AS", "foo*", "FROM", "link-1"] artifacts = { "dist/foo": { "sha256": self.sha256_foo }, "dist/foobar": { "sha256": self.sha256_foobar } } queue = artifacts.keys() self.assertListEqual( verify_match_rule(rule, queue, artifacts, self.links), [])