Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #64 from webscopeio/fix/whitelist
Browse files Browse the repository at this point in the history
fix: is_license_ok fixed for complex license
  • Loading branch information
4rokis authored Jan 16, 2020
2 parents 4beafdc + 271444e commit 68c502b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion license_sh/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/runners/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 68c502b

Please sign in to comment.