diff --git a/license_sh/helpers.py b/license_sh/helpers.py index a7c4139..686f980 100644 --- a/license_sh/helpers.py +++ b/license_sh/helpers.py @@ -97,7 +97,7 @@ def is_license_ok(license_text, whitelist): try: license = licensing.parse(license_text) except: - return license_text in whitelist + return f"{license_text}" in whitelist if license is None: return None diff --git a/tests/runners/test_helpers.py b/tests/runners/test_helpers.py index 3e77f28..1a0f966 100644 --- a/tests/runners/test_helpers.py +++ b/tests/runners/test_helpers.py @@ -6,6 +6,7 @@ from license_sh.helpers import ( flatten_dependency_tree, annotate_dep_tree, + is_license_ok, extract_npm_license, get_npm_license_from_licenses_array, UNKNOWN, @@ -225,6 +226,29 @@ def test_bad_licenses_identified__one_package_ignored_by_package_whitelist(self) _, unknown_licenses = annotate_dep_tree(tree, whitelist, ignored_packages) self.assertSetEqual(set({"GPL"}), unknown_licenses) + def test_is_license_ok_simple(self): + self.assertEqual(is_license_ok("MIT", ["MIT"]), True) + + def test_is_license_ok_negative(self): + self.assertEqual(is_license_ok("MIT", [""]), False) + + def test_is_license_ok_brackets(self): + self.assertEqual(is_license_ok("MIT AND Zlib", ["MIT", "Zlib"]), True) + + def test_is_license_ok_json(self): + self.assertEqual( + is_license_ok( + { + "type": "MIT", + "url": "https://github.com/thlorenz/bunyan-format/blob/master/LICENSE", + }, + [ + "{'type': 'MIT', 'url': 'https://github.com/thlorenz/bunyan-format/blob/master/LICENSE'}" + ], + ), + True, + ) + def test_extract_npm_license_None_data(self): name = extract_npm_license(None, None) self.assertEqual(name, None)