aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_interface/tests/apitests
diff options
context:
space:
mode:
authorasteroide <thomas.duval@orange.com>2017-04-24 14:36:19 +0200
committerasteroide <thomas.duval@orange.com>2017-04-24 14:36:19 +0200
commit623cf53a0a06ac4c3cad6e60b569ccd6418073b6 (patch)
tree0d441526ffdf253ca3d75bc2cbc428f6b04b5993 /moonv4/moon_interface/tests/apitests
parent6fc34508fc18b17a3dfcce1fcee1e43e4f0e32d1 (diff)
Add a file to test authz through a particular scenario
Change-Id: I6dd52ace9e621513a6d7862197c7ffa44c5e11b8
Diffstat (limited to 'moonv4/moon_interface/tests/apitests')
-rw-r--r--moonv4/moon_interface/tests/apitests/set_authz.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/moonv4/moon_interface/tests/apitests/set_authz.py b/moonv4/moon_interface/tests/apitests/set_authz.py
new file mode 100644
index 00000000..7d0d5069
--- /dev/null
+++ b/moonv4/moon_interface/tests/apitests/set_authz.py
@@ -0,0 +1,43 @@
+import sys
+import argparse
+import logging
+from importlib.machinery import SourceFileLoader
+import itertools
+import requests
+from utils.pdp import check_pdp
+
+parser = argparse.ArgumentParser()
+parser.add_argument('filename', help='scenario filename', nargs=1)
+parser.add_argument("--verbose", "-v", action='store_true', help="verbose mode")
+args = parser.parse_args()
+
+FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
+logging.basicConfig(
+ format=FORMAT,
+ level=logging.INFO)
+
+logger = logging.getLogger(__name__)
+
+if args.filename:
+ print("Loading: {}".format(args.filename[0]))
+
+m = SourceFileLoader("scenario", args.filename[0])
+
+scenario = m.load_module()
+
+rules = itertools.product(scenario.subjects.keys(), scenario.objects.keys(), scenario.actions.keys())
+
+keystone_project_id = None
+for pdp_key, pdp_value in check_pdp()["pdps"].items():
+ if pdp_value['security_pipeline'] and pdp_value["keystone_project_id"]:
+ print("Found pdp with keystone_project_id={}".format(pdp_value["keystone_project_id"]))
+ keystone_project_id = pdp_value["keystone_project_id"]
+
+if not keystone_project_id:
+ logger.error("Cannot find PDP with keystone project ID")
+ sys.exit(1)
+
+for rule in rules:
+ url = "http://172.18.0.11:38001/authz/{}/{}".format(keystone_project_id, "/".join(rule))
+ req = requests.get(url)
+ print(url, req.status_code)