def test_get_known_unknown_pkgs_with_and_without_cve_golang(self, _mock1): """Test Known Unknown Pkgs, with and Without CVE for golang.""" input_pkgs = [ ('github.com/hashicorp/nomad', 'github.com/hashicorp/nomad', '0.7.1', 'v0.7.1', False), ('code.cloudfoundry.org/gorouter/route', 'code.cloudfoundry.org/gorouter/[email protected]/gorouter', '0.0.0-20170410000936-a663fba25f7a', 'v0.0.0-20170410000936-a663fba25f7a', True) ] normalised_input_pkgs = [ normlize_packages(pkg, gvn_pkg, vr, gvn_vr, isp) for pkg, gvn_pkg, vr, gvn_vr, isp in input_pkgs ] batch_data_no_cve = os.path.join( '/bayesian/tests/data/gremlin/batch_data_with_n_without_cve_golang.json' ) with open(batch_data_no_cve) as f: data_with_n_without_cve = json.load(f) ideal_resp = os.path.join( '/bayesian/tests/data/response/ca_batch_with_n_without_vul_golang.json' ) with open(ideal_resp) as f: ideal_output = json.load(f) stack_recommendation, unknown_pkgs = get_known_unknown_pkgs( "golang", data_with_n_without_cve, normalised_input_pkgs) self.assertListEqual(stack_recommendation, ideal_output) self.assertSetEqual(unknown_pkgs, set())
def test_get_known_unknown_pkgs_no_cve(self, _mock1, _mock2): """Test Known Unknown Pkgs, No Cve.""" normalised_input_pkgs = [normlize_packages("markdown2", "markdown2", "2.3.2", "2.3.2", False)] batch_data_no_cve = os.path.join('/bayesian/tests/data/gremlin/batch_data_no_cve.json') with open(batch_data_no_cve) as f: gremlin_batch_data_no_cve = json.load(f) stack_recommendation, unknown_pkgs = get_known_unknown_pkgs( "pypi", gremlin_batch_data_no_cve, normalised_input_pkgs) ideal_output = [{'package': 'markdown2', 'version': '2.3.2', 'package_unknown': False, 'recommendation': {}}] self.assertListEqual(stack_recommendation, ideal_output) self.assertSetEqual(unknown_pkgs, set())
def test_get_known_unknown_pkgs_with_and_without_cve(self, _mock1, _mock2, _mock3): """Test Known Unknown Pkgs, with and Without CVE.""" input_pkgs = [("flask", "flask", "1.1.1", "1.1.1"), ("django", "django", "1.1.1", "1.1.1")] normalised_input_pkgs = [normlize_packages(pkg, gvn_pkg, vr, gvn_vr, False) for pkg, gvn_pkg, vr, gvn_vr in input_pkgs] batch_data_no_cve = os.path.join( '/bayesian/tests/data/gremlin/batch_data_with_n_without_cve.json') with open(batch_data_no_cve) as f: data_with_n_without_cve = json.load(f) ideal_resp = os.path.join( '/bayesian/tests/data/response/ca_batch_with_n_without_vul.json') with open(ideal_resp) as f: ideal_output = json.load(f) stack_recommendation, unknown_pkgs = get_known_unknown_pkgs( "pypi", data_with_n_without_cve, normalised_input_pkgs) self.assertListEqual(stack_recommendation, ideal_output) self.assertSetEqual(unknown_pkgs, set())
def test_add_unknown_pkg_info(self): """Test Known Unknown Pkgs, with and Without CVE for golang.""" input_pkgs = [ ('github.com/hashicorp/nomad', 'github.com/hashicorp/nomad', '0.7.1', 'v0.7.1', False), ('code.cloudfoundry.org/gorouter/route', 'code.cloudfoundry.org/gorouter/[email protected]/gorouter', '0.0.0-20170410000936-a663fba25f7a', 'v0.0.0-20170410000936-a663fba25f7a', True) ] unknown_pkgs = set( normlize_packages(pkg, gvn_pkg, vr, gvn_vr, isp) for pkg, gvn_pkg, vr, gvn_vr, isp in input_pkgs) stack_recommendation = [{ "package": "github.com/existing/package", "version": "v3.4.0", "package_unknown": False }] ideal_output = [{ "package": "github.com/existing/package", "version": "v3.4.0", "package_unknown": False }, { "package": "github.com/hashicorp/nomad", "version": "v0.7.1", "package_unknown": True }, { "package": "code.cloudfoundry.org/gorouter/[email protected]/gorouter", "version": "v0.0.0-20170410000936-a663fba25f7a", "package_unknown": True }] stack_recommendation = add_unknown_pkg_info(stack_recommendation, unknown_pkgs) self.assertListEqual( sorted(stack_recommendation, key=itemgetter('package')), sorted(ideal_output, key=itemgetter('package')))