aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_interface/tests/apitests/set_authz.py
blob: 7d0d5069e5a94fff3477379d437a946623957fd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)