source: examples/python_tests/alumni_rt1/query.py @ 47d5cf9

mei_rt2mei_rt2_fix_1
Last change on this file since 47d5cf9 was 669b481, checked in by Mei <mei@…>, 12 years ago

1) finish test conversion from creddy-prover to python
2) update the abac.hh/API doc more, adding more intermediate calls

to make abac.hh more uniform

3) found out why a very long attribute rule can not survive in/out of

ietf_attribute_t call (m64 en/decoding - abac_verifier, alice_rt1)

  • Property mode set to 100755
File size: 2.1 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./query.py
7cmd2: env ABAC_CN=1 keystore=`pwd` ./query.py
8
9"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
16# print "ABAC version %s" % ctxt.version()
17
18keystore=os.environ["keystore"]
19
20ctxt.load_directory(keystore)
21
22stateUID=ABAC.ID("StateU_ID.pem")
23stateUID.id_load_privkey_file("StateU_private.pem")
24stateU=stateUID.id_keyid()
25
26bobID=ABAC.ID("Bob_ID.pem")
27bobID.id_load_privkey_file("Bob_private.pem")
28bob=bobID.id_keyid()
29
30joeID=ABAC.ID("Joe_ID.pem")
31joeID.id_load_privkey_file("Joe_private.pem")
32joe=joeID.id_keyid()
33
34maryannID=ABAC.ID("Maryann_ID.pem")
35maryannID.id_load_privkey_file("Maryann_private.pem")
36maryann=maryannID.id_keyid()
37
38##########################################################################
39# role=[keyid:stateU].role:foundingAlumni
40# p=[keyid:Bob]
41role = ABAC.Role(stateU,"foundingAlumni")
42p = ABAC.Role(bob)
43print "\n===bad============ stateU.foundingAlumni <- Bob"
44out = ctxt.query(role, p)
45for c in out[1]:
46    print "%s <- %s" % (c.head_string(), c.tail_string())
47
48##########################################################################
49# role=[keyid:stateU].role:foundingAlumni
50# p=[keyid:Maryann]
51role = ABAC.Role(stateU,"foundingAlumni")
52p = ABAC.Role(maryann)
53print "\n===good============ stateU.foundingAlumni <- Maryann"
54out = ctxt.query(role, p)
55for c in out[1]:
56    print "%s <- %s" % (c.head_string(), c.tail_string())
57
58##########################################################################
59# role=[keyid:stateU].role:foundingAlumni
60# p=[keyid:Joe]
61role = ABAC.Role(stateU,"foundingAlumni")
62p = ABAC.Role(joe)
63print "\n===good============ stateU.foundingAlumni <- Joe"
64out = ctxt.query(role, p)
65for c in out[1]:
66    print "%s <- %s" % (c.head_string(), c.tail_string())
67
68##########################################################################
69# dump the loaded principals/policies
70#
71out = ctxt.context_principals()
72print "\n...final principal set..."
73for x in out[1]:
74    print "%s " % x.string()
75print "\n"
76out = ctxt.context_credentials()
77print "\n...final policy attribute set..."
78for c in out[1]:
79    print "%s <- %s" % (c.head_string(), c.tail_string())
80print "\n"
81
82
Note: See TracBrowser for help on using the repository browser.