1 | package net.deterlab.abac.regression; |
---|
2 | |
---|
3 | import java.io.*; |
---|
4 | import java.util.*; |
---|
5 | |
---|
6 | import net.deterlab.abac.*; |
---|
7 | |
---|
8 | public class BigTest extends RegressionTest { |
---|
9 | protected int nids; |
---|
10 | /** |
---|
11 | * Create a new Credential/Identity writing test for the given class of |
---|
12 | * credentials. |
---|
13 | * @param cn a String containing the binary name of the class to test |
---|
14 | */ |
---|
15 | public BigTest(String n, int ids) { |
---|
16 | super(n); |
---|
17 | nids = ids; |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | * Carry out the test. Create credentials for the create_experiment |
---|
22 | * example, run the proof and make sure the correct proof is generated. |
---|
23 | * @param data a File pointing to a directory that contains files the test |
---|
24 | * may need |
---|
25 | * @param scratch a File pointing to a directory that the test can use to |
---|
26 | * store data |
---|
27 | * @return a boolean, true if the test is passed |
---|
28 | */ |
---|
29 | public boolean runTest(File data, File scratch) { |
---|
30 | try { |
---|
31 | Context ctxt = new Context(); |
---|
32 | Vector<Identity> ids = new Vector<Identity>(); |
---|
33 | |
---|
34 | for (int i =0; i< nids; i++) { |
---|
35 | Identity id = new Identity("Identity" + i); |
---|
36 | ids.add(id); |
---|
37 | ctxt.load_id_chunk(id); |
---|
38 | } |
---|
39 | |
---|
40 | for (int i = 0 ; i < nids; i++ ) { |
---|
41 | for ( int j = 0; j < nids ; j++ ) { |
---|
42 | Credential c = ctxt.newCredential( |
---|
43 | new Role(ids.elementAt(i).getKeyID() + ".role"+j), |
---|
44 | (j > 0) ? |
---|
45 | new Role(ids.elementAt(i).getKeyID() + |
---|
46 | ".role"+(j-1)) : |
---|
47 | new Role(ids.elementAt(i).getKeyID())); |
---|
48 | c.make_cert(ids.elementAt(i)); |
---|
49 | ctxt.load_attribute_chunk(c); |
---|
50 | |
---|
51 | c = ctxt.newCredential( |
---|
52 | new Role(ids.elementAt(i).getKeyID() + ".role"+j), |
---|
53 | new Role(ids.elementAt((i+1)%nids).getKeyID() + |
---|
54 | ".role"+j)); |
---|
55 | c.make_cert(ids.elementAt(i)); |
---|
56 | ctxt.load_attribute_chunk(c); |
---|
57 | } |
---|
58 | } |
---|
59 | Context.QueryResult q = ctxt.query( |
---|
60 | ids.elementAt(nids-1).getKeyID() + ".role" + (nids-1), |
---|
61 | ids.elementAt(0).getKeyID()); |
---|
62 | if (!q.getSuccess() ) { |
---|
63 | setReason("Cannot prove " + |
---|
64 | new Role(ids.elementAt(nids-1).getKeyID() |
---|
65 | + ".role" + (nids-1)).simpleString(ctxt) + " <- " + |
---|
66 | new Role(ids.elementAt(0).getKeyID()).simpleString(ctxt)); |
---|
67 | return false; |
---|
68 | } |
---|
69 | } |
---|
70 | catch (Exception e) { |
---|
71 | setReason(e.getMessage()); |
---|
72 | return false; |
---|
73 | } |
---|
74 | return true; |
---|
75 | } |
---|
76 | } |
---|