1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Run the queries described in README |
---|
5 | |
---|
6 | cmd:env keystore=`pwd` ./query.py |
---|
7 | """ |
---|
8 | |
---|
9 | import os |
---|
10 | import ABAC |
---|
11 | from test_util import runTest |
---|
12 | |
---|
13 | ctxt = ABAC.Context() |
---|
14 | |
---|
15 | # Keystore is the directory containing the principal credentials. |
---|
16 | # Load existing principals and/or policy credentials |
---|
17 | if (os.environ.has_key("keystore")) : |
---|
18 | keystore=os.environ["keystore"] |
---|
19 | ctxt.load_directory(keystore) |
---|
20 | else: |
---|
21 | print("keystore is not set, using current directory...") |
---|
22 | ctxt.load_directory(".") |
---|
23 | |
---|
24 | # retrieve principals' keyid value from local credential files |
---|
25 | acmeID=ABAC.ID("Acme_ID.pem"); |
---|
26 | acmeID.load_privkey("Acme_private.pem"); |
---|
27 | acme=acmeID.keyid() |
---|
28 | |
---|
29 | coyoteID=ABAC.ID("Coyote_ID.pem"); |
---|
30 | coyoteID.load_privkey("Coyote_private.pem"); |
---|
31 | coyote=coyoteID.keyid() |
---|
32 | |
---|
33 | warnerbrosID=ABAC.ID("WarnerBros_ID.pem"); |
---|
34 | warnerbrosID.load_privkey("WarnerBros_private.pem"); |
---|
35 | warnerbros=warnerbrosID.keyid() |
---|
36 | |
---|
37 | batmanID=ABAC.ID("Batman_ID.pem"); |
---|
38 | batmanID.load_privkey("Batman_private.pem"); |
---|
39 | batman=batmanID.keyid() |
---|
40 | |
---|
41 | ########################################################################## |
---|
42 | # dump the loaded principals/policies |
---|
43 | # |
---|
44 | print "\n...policy attribute set..." |
---|
45 | credentials = ctxt.credentials() |
---|
46 | for credential in credentials: |
---|
47 | print "context: %s <- %s" % (credential.head().string(), credential.tail().string()) |
---|
48 | |
---|
49 | ########################################################################## |
---|
50 | # can coyote buy rockets from Acme ? |
---|
51 | # role = "[keyid:Acme].role:buy_rockets" |
---|
52 | # p = "[keyid:coyote]" |
---|
53 | print "===good============ Acme.buy_rockets <- Coyote" |
---|
54 | runTest("python_tests/acme_rockets_intersection_rt0","test1",ctxt,"%s.buy_rockets" % acme, coyote, 1, "query in python with intersect") |
---|
55 | |
---|
56 | ########################################################################## |
---|
57 | # can batman buy rockets from Acme ? |
---|
58 | # role = "[keyid:Acme].role:buy_rockets" |
---|
59 | # p = "[keyid:batman]" |
---|
60 | print "===bad============ Acme.buy_rockets <- Batman" |
---|
61 | runTest("python_tests/acme_rockets_intersection_rt0","test2",ctxt,"%s.buy_rockets" % acme, batman, 0, "expected failure, no such relation in db") |
---|
62 | |
---|
63 | |
---|