source: java/net/deterlab/abac/regression/GENIWriteCreds.java @ 98a9afb

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since 98a9afb was 8375d4f, checked in by Ted Faber <faber@…>, 11 years ago

Regression test framework

  • Property mode set to 100644
File size: 3.5 KB
Line 
1package net.deterlab.abac.regression;
2
3import java.io.*;
4import java.util.*;
5
6import net.deterlab.abac.*;
7
8public class GENIWriteCreds extends RegressionTest {
9    /**
10     * Put out an identity and key into dir named by the name of the Identity
11     * @param i the Identity to write
12     * @param dir a File holding the destination directory
13     * @throws IOException if the file writing fails
14     */
15    public void writeCombinedIdentity(Identity i, File dir) 
16            throws IOException {
17        FileOutputStream f = new FileOutputStream(
18                new File(dir,  i.getName() + ".pem"));
19
20        i.write(f);
21        i.writePrivateKey(f);
22    }
23    /**
24     * Create a new GENI simple proof test
25     */
26     public GENIWriteCreds() { super("GENI credential writing test"); }
27
28    /**
29     * Carry out the test.  Create credentials for the create_experiment
30     * example, run the proof and make sure the correct proof is generated.
31     * @param data a File pointing to a directory that contains files the test
32     * may need
33     * @param scratch a File pointing to a directory that the test can use to
34     * store data
35     * @return a boolean, true if the test is passed
36     */
37    public boolean runTest(File data, File scratch) {
38        try {
39            Context ctxt = new Context();
40            Identity acme = new Identity("Acme");
41            Identity globotron = new Identity("Globotron");
42            Identity alice = new Identity("Alice");
43            Identity bob = new Identity("Bob");
44            Vector<Identity> ids = new Vector<Identity>();
45            Vector<Credential> creds = new Vector<Credential>();
46            Collections.addAll(ids, acme, globotron, alice, bob);
47
48            for ( Identity i: ids) 
49                writeCombinedIdentity(i, scratch);
50
51            ctxt.setCredentialFactory(new CredentialFactory(
52                        new String[] {"net.deterlab.abac.GENICredential"}));
53
54
55            Credential c = ctxt.newCredential(
56                    new Role(acme.getKeyID() + ".experiment_create"),
57                    new Role(acme.getKeyID() + ".partner.experiment_create"));
58            c.make_cert(acme);
59            creds.add(c);
60            c = ctxt.newCredential(
61                    new Role(acme.getKeyID() + ".partner"),
62                    new Role(globotron.getKeyID()));
63            c.make_cert(acme);
64            creds.add(c);
65            c = ctxt.newCredential(
66                    new Role(globotron.getKeyID() + ".experiment_create"),
67                    new Role(globotron.getKeyID() + ".admin.power_user"));
68            c.make_cert(globotron);
69            creds.add(c);
70            c = ctxt.newCredential(
71                    new Role(globotron.getKeyID() + ".admin"),
72                    new Role(alice.getKeyID()));
73            c.make_cert(globotron);
74            creds.add(c);
75            c = ctxt.newCredential(
76                    new Role(alice.getKeyID() + ".power_user"),
77                    new Role(bob.getKeyID()));
78            c.make_cert(alice);
79            creds.add(c);
80
81            int i =0;
82            for (Credential cc: creds) {
83                cc.write(new File(scratch, "e" + i + ".cred").toString());
84                i ++;
85            }
86
87            Context ctxt2 = new Context();
88
89            ctxt2.load_directory(scratch);
90            Collection<Identity> nids = ctxt2.identities();
91            Collection<Credential> ncreds = ctxt2.credentials();
92
93            if ( nids.size() != ids.size()) {
94                setReason("Different number of identities read");
95                return false;
96            }
97            for (Identity ii: ids ) 
98                if ( !nids.contains(ii)) {
99                    setReason("Identity " + ii + " not read successfully");
100                    return false;
101                }
102
103            if ( ncreds.size() != creds.size()) {
104                setReason("Different number of credentials read");
105                return false;
106            }
107            for (Credential cc: creds ) 
108                if ( !ncreds.contains(cc)) {
109                    setReason("Credential " + cc + " not read successfully");
110                    return false;
111                } 
112
113        }
114        catch (Exception e) {
115            setReason(e.getMessage());
116            return false;
117        }
118        return true;
119    }
120}
Note: See TracBrowser for help on using the repository browser.