source: tests/python_tests/basic_id/query.py @ 6cd69a0

abac0-leakabac0-mei
Last change on this file since 6cd69a0 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.8 KB
Line 
1#!/usr/bin/env python
2
3"""
4  to test with python
5
6cmd:env keystore=`pwd` ./query.py
7
8No real query (originally id.py)
9"""
10
11import os
12import ABAC
13
14ctxt = ABAC.Context()
15
16# Keystore is the directory containing the principal credentials.
17# Load existing principals and/or policy credentials
18if (os.environ.has_key("keystore")) :
19    keystore=os.environ["keystore"]
20#    ctxt.load_directory(keystore)
21else:
22    print("keystore is not set, using current directory...")
23    ctxt.load_directory(".")
24
25## case 1
26## creating and writing out using libabac ID
27id=ABAC.ID("Mary", 0)
28print "adding -> %s(Mary/good)" % id.keyid()
29id.write_cert_file("Mary_ID.pem")
30id.write_privkey_file("Mary_private.pem")
31## load principal with id/key file pair
32## note, with this, we do not have handle on the keyid
33## to Mary but it will be in the db
34#XXX# ctxt.load_id_files("Mary_ID.pem","Mary_private.pem")
35
36## case 2
37## creating principal using ID
38id2=ABAC.ID("Jack2", 0)
39print "adding -> %s(Jack2/good)" % id2.keyid()
40## load principal directly with the ID, no external
41## credential files were created
42#XXX# ctxt.load_id(id2)
43
44## case 3
45## creating principal using ID
46id3=ABAC.ID("Mark", 0)
47print "adding -> %s(Mark/good)" % id3.keyid()
48## write cert and key content to a combo file. One is appended
49## after another
50id3.write_privkey_file("Mark_IDKEY.pem")
51id3.write_cert_file("Mark_IDKEY.pem")
52## load principal in with the combo file with the tandem format
53ctxt.load_id_file("Mark_IDKEY.pem")
54
55## case 4
56## creating principal using ID
57id4=ABAC.ID("John", 0)
58print "adding -> %s(John/good,invisible)" % id4.keyid()
59id4.write_cert_file("John_other.pem")
60## load id without the key file
61ctxt.load_id_file("John_other.pem")
62
63## case 5
64## creating principal using ID
65id5=ABAC.ID("Lori", 0)
66print "adding -> %s(Lori/good,nokey)" % id5.keyid()
67## write just cert into the combo file
68id5.write_cert_file("Lori_IDKEY.pem")
69##load principal from a combo file that only contains cert part
70ctxt.load_id_file("Lori2_IDKEY.pem")
71
72## case 6
73## creating principal using ID
74id6=ABAC.ID("Tom", 0)
75print "adding -> %s(Tom/bad,nocert)" % id6.keyid()
76## write just key into the combo file
77id6.write_privkey_file("Tom_IDKEY.pem")
78## load principal from combo file that only contains key part
79ctxt.load_id_file("Tom_IDKEY.pem")
80
81## case 7
82## creating ID using chunk
83## this already created a Tim with private key and
84## stored in the master list
85id7=ABAC.ID("Tim", 0)
86chunk=id7.cert_chunk() 
87id77=ABAC.ID_chunk(chunk)
88## load principal from new id
89ctxt.load_id_chunk(id77.cert_chunk())
90
91## case 8
92## load directly using chunk
93## this already created a Stanley with private key
94## and stored in the master list
95id8=ABAC.ID("Stanley", 0)
96chunk=id8.cert_chunk() 
97## load principal as chunk
98ctxt.load_id_chunk(chunk)
99
100## case 9
101## failure case, loading a non-existing combo file
102print "adding -> Casper(bad,unknown file)"
103ctxt.load_id_file("Casper_IDKEY.pem")
104
Note: See TracBrowser for help on using the repository browser.