source: tests/python_tests/basic_id/id.py @ ec550f7

abac0-leakabac0-meimei-idtvf-new-xml
Last change on this file since ec550f7 was ec550f7, checked in by Mei <mei@…>, 11 years ago

1) reworked how API doc is generated
2) tweak top level Makefile.am
3) loading issuer principal as side-effect of loading

an attribute credentials

4) add examples of GENI specific attribute credentials

and principal certificates into the regression testing

5) rename examples to tests

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