source: java/net/deterlab/abac/regression/ExperimentTest.java @ c694dff

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

Experiment test

  • Property mode set to 100644
File size: 3.0 KB
Line 
1package net.deterlab.abac.regression;
2
3import java.io.*;
4import java.util.*;
5
6import net.deterlab.abac.*;
7
8public class ExperimentTest extends RegressionTest {
9    /**
10     * Create a new Credential/Identity writing test for the given class of
11     * credentials.
12     * @param cn a String containing the binary name of the class to test
13     */
14     public ExperimentTest(String n) { 
15         super(n);
16     }
17
18    /**
19     * Carry out the test.  Create credentials for the create_experiment
20     * example, run the proof and make sure the correct proof is generated.
21     * @param data a File pointing to a directory that contains files the test
22     * may need
23     * @param scratch a File pointing to a directory that the test can use to
24     * store data
25     * @return a boolean, true if the test is passed
26     */
27    public boolean runTest(File data, File scratch) {
28        try {
29            Context ctxt = new Context();
30            Identity acme = new Identity("Acme");
31            Identity globotron = new Identity("Globotron");
32            Identity alice = new Identity("Alice");
33            Identity bob = new Identity("Bob");
34            Vector<Identity> ids = new Vector<Identity>();
35            Vector<Credential> creds = new Vector<Credential>();
36            Collections.addAll(ids, acme, globotron, alice, bob);
37
38
39            Credential c = ctxt.newCredential(
40                    new Role(acme.getKeyID() + ".experiment_create"),
41                    new Role(acme.getKeyID() + ".partner.experiment_create"));
42            c.make_cert(acme);
43            creds.add(c);
44            c = ctxt.newCredential(
45                    new Role(acme.getKeyID() + ".partner"),
46                    new Role(globotron.getKeyID()));
47            c.make_cert(acme);
48            creds.add(c);
49            c = ctxt.newCredential(
50                    new Role(globotron.getKeyID() + ".experiment_create"),
51                    new Role(globotron.getKeyID() + ".admin.power_user"));
52            c.make_cert(globotron);
53            creds.add(c);
54            c = ctxt.newCredential(
55                    new Role(globotron.getKeyID() + ".admin"),
56                    new Role(alice.getKeyID()));
57            c.make_cert(globotron);
58            creds.add(c);
59            c = ctxt.newCredential(
60                    new Role(alice.getKeyID() + ".power_user"),
61                    new Role(bob.getKeyID()));
62            c.make_cert(alice);
63            creds.add(c);
64
65            for (Identity id: ids ) 
66                ctxt.load_id_chunk(id);
67            for (Credential cc: creds ) 
68                ctxt.load_attribute_chunk(cc);
69
70            Context.QueryResult q = ctxt.query(
71                    acme.getKeyID() + ".experiment_create",
72                    bob.getKeyID());
73
74            if ( !q.getSuccess() ) { 
75                setReason("Could not prove Bob can create experiment");
76                return false;
77            }
78
79            if ( creds.size() != q.getCredentials().size()) {
80                setReason("Bob's proof is the wrong size");
81                return false;
82            }
83
84            for ( Credential cc: creds )
85                if ( !q.getCredentials().contains(cc)) {
86                    setReason("Credential missing from proof: " + cc);
87                    return false;
88                }
89
90            q = ctxt.query(
91                    acme.getKeyID() + ".experiment_create",
92                    alice.getKeyID());
93
94            if ( q.getSuccess() ) { 
95                setReason("Could prove Alice can create experiment");
96                return false;
97            }
98
99        }
100        catch (Exception e) {
101            setReason(e.getMessage());
102            return false;
103        }
104        return true;
105    }
106}
Note: See TracBrowser for help on using the repository browser.