From 8434eab14c1658c73d852a7126dd72f2e94d01c5 Mon Sep 17 00:00:00 2001 From: Scott Piper Date: Mon, 8 Nov 2021 14:00:35 -0700 Subject: [PATCH] Add test, bug fix, file bump --- parliament/__init__.py | 2 +- parliament/policy.py | 6 ++++++ tests/unit/test_usage.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_usage.py diff --git a/parliament/__init__.py b/parliament/__init__.py index 85f3728..094acf7 100644 --- a/parliament/__init__.py +++ b/parliament/__init__.py @@ -1,7 +1,7 @@ """ This library is a linter for AWS IAM policies. """ -__version__ = "1.5.0" +__version__ = "1.5.1" import fnmatch import functools diff --git a/parliament/policy.py b/parliament/policy.py index 8f36222..e169e86 100644 --- a/parliament/policy.py +++ b/parliament/policy.py @@ -28,6 +28,9 @@ def __init__(self, policy_json, filepath=None, config=None): self.config = config if config else {} def add_finding(self, finding, detail="", location={}): + print(type(location)) + print(location) + print(type({})) if type(location) == tuple and "jsoncfg.config_classes" in str( type(location[1]) ): @@ -42,6 +45,9 @@ def add_finding(self, finding, detail="", location={}): location_data["lineno"] = jsoncfg.node_location(location).line location_data["column"] = jsoncfg.node_location(location).column location = location_data + + if type(location) != dict: + location = {'filepath': location} if "filepath" not in location: location["filepath"] = self.filepath self._findings.append(Finding(finding, detail, location)) diff --git a/tests/unit/test_usage.py b/tests/unit/test_usage.py new file mode 100644 index 0000000..31acd93 --- /dev/null +++ b/tests/unit/test_usage.py @@ -0,0 +1,28 @@ +import unittest +from nose.tools import raises, assert_equal, assert_true, assert_false +import json +import parliament + + +class TestUsage(unittest.TestCase): + """Test basic usage of the library""" + + def test_using_library(self): + # This is a common use of the library, so just follow the path to ensure no exceptions are thrown. + policy_doc = """ + { + "Statement": [ + { + "Effect": "Allow", + "Action": "s3:ListAllMyBuckets", + "Resource": "*", + "Condition": { + "StringEquals": { "aws:PrincipalTag/project": "web" } + } + } + ], + "Version": "2012-10-17" + }""" + policy_doc = json.loads(policy_doc) + policy = parliament.policy.Policy(policy_doc) + policy.analyze() \ No newline at end of file