source: tests/python_tests/basic_attribute/query.py @ 3c30b59

abac0-leakabac0-mei
Last change on this file since 3c30b59 was 3c30b59, checked in by Mei <mei@…>, 11 years ago

1) add in new refactored regression testing directory
2) undo the abac.hh/ABAC.hh api changes
3) merged with Ted's changes to attribute format/nickname/issuer processing

  • Property mode set to 100755
File size: 2.9 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd1:env keystore=`pwd` ./query.py
7
8"""
9
10import os
11import ABAC
12
13from test_util import runTest
14
15ctxt = ABAC.Context()
16
17def print_a(ctxt, msg, dotdot):
18    print "%s rule set..." % msg
19    credentials = ctxt.credentials()
20    for credential in credentials:
21        print "%s:%s<-%s" % (dotdot,credential.head().string(), credential.tail().string())
22
23# Keystore is the directory containing the principal credentials.
24# Load existing principals and/or policy credentials
25if (os.environ.has_key("keystore")) :
26    keystore=os.environ["keystore"]
27else:
28    print("keystore is not set, using current directory...")
29    ctxt.load_directory(".")
30
31superKID=ABAC.ID("SuperK_ID.pem");
32superKID.load_privkey("SuperK_private.pem");
33ctxt.load_id_chunk(superKID.cert_chunk())
34superK=superKID.keyid()
35
36jackID=ABAC.ID("Jack_ID.pem");
37jackID.load_privkey("Jack_private.pem");
38ctxt.load_id_chunk(jackID.cert_chunk())
39jack=jackID.keyid()
40
41bobID=ABAC.ID("Bob_ID.pem");
42bobID.load_privkey("Bob_private.pem");
43ctxt.load_id_chunk(bobID.cert_chunk())
44bob=bobID.keyid()
45
46maryID=ABAC.ID("Mary_ID.pem");
47maryID.load_privkey("Mary_private.pem");
48ctxt.load_id_chunk(maryID.cert_chunk())
49mary=maryID.keyid()
50
51#case 1:
52#Only employee of SuperK can park
53#[keyid:SuperK].role:park <- [keyid:SuperK].role:employee
54attr = ABAC.Attribute(superKID, "park", 0)
55attr.role(superK,"employee")
56attr.bake()
57attr.write_file("SuperK_park__SuperK_employee_attr.xml")
58ctxt.load_attribute_file("SuperK_park__SuperK_employee_attr.xml")
59print_a(ctxt,"case1","..")
60
61#case 2:
62#Jack is an employee of SuperK
63#[keyid:SuperK].role:employee <- [keyid:Jack]
64attr = ABAC.Attribute(superKID, "employee", 0)
65attr.principal(jack)
66attr.bake()
67# create a policy file at the file system
68attr.write_file("SuperK_employee__Jack_attr.xml")
69ctxt.load_attribute_chunk(attr.cert_chunk());
70print_a(ctxt,"case2","....")
71##########################################################################
72#Jack of SuperK can park?
73print "===good============ SuperK.park <-?- Jack"
74runTest("python_tests/basic_attribute","test1",ctxt,"%s.park" % superK, jack, 1, "check loading of attribute as cert chunk")
75
76#case 3:
77#Bob is an employee of SuperK
78#[keyid:SuperK].role:employee <- [keyid:Bob]
79attr = ABAC.Attribute(superKID, "employee", 0)
80attr.principal(bob)
81attr.bake()
82#chunk=attr.cert_chunk()
83#nattr=ABAC.Attribute_chunk(chunk)
84#ctxt.load_attribute(nattr);
85#print_a(ctxt,"case3", "....")
86
87#case 4:
88#Mary is an employee of SuperK
89#[keyid:SuperK].role:employee <- [keyid:Mary]
90attr = ABAC.Attribute(superKID, "employee", 0)
91attr.principal(mary)
92attr.bake()
93chunk=attr.cert_chunk()
94ctxt.load_attribute_chunk(chunk);
95print_a(ctxt,"case4","......")
96##########################################################################
97#is Mary an employee of superK?
98print "===good============ SuperK.employee <-?- Mary"
99runTest("python_tests/basic_attribute","test2",ctxt,"%s.employee" % superK, mary, 1, "check loading of attribute as chunk")
100
Note: See TracBrowser for help on using the repository browser.