[5348b6c] | 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 RocketsTest 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 Credential/Identity writing test for the given class of |
---|
| 25 | * credentials. |
---|
| 26 | * @param cn a String containing the binary name of the class to test |
---|
| 27 | */ |
---|
| 28 | public RocketsTest(String name) { |
---|
| 29 | super(name); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * Carry out the test. Create credentials for the create_experiment |
---|
| 34 | * example, run the proof and make sure the correct proof is generated. |
---|
| 35 | * @param data a File pointing to a directory that contains files the test |
---|
| 36 | * may need |
---|
| 37 | * @param scratch a File pointing to a directory that the test can use to |
---|
| 38 | * store data |
---|
| 39 | * @return a boolean, true if the test is passed |
---|
| 40 | */ |
---|
| 41 | public boolean runTest(File data, File scratch) { |
---|
| 42 | try { |
---|
| 43 | Context ctxt = new Context(); |
---|
| 44 | Identity acme = new Identity("Acme"); |
---|
| 45 | Identity warnerBros = new Identity("WarnerBros"); |
---|
| 46 | Identity batman = new Identity("Batman"); |
---|
| 47 | Identity coyote = new Identity("Coyote"); |
---|
| 48 | ArrayList<Credential> inProof = new ArrayList<Credential>(); |
---|
| 49 | |
---|
| 50 | ctxt.load_id_chunk(acme); |
---|
| 51 | ctxt.load_id_chunk(warnerBros); |
---|
| 52 | ctxt.load_id_chunk(batman); |
---|
| 53 | ctxt.load_id_chunk(coyote); |
---|
| 54 | |
---|
| 55 | Credential c = ctxt.newCredential( |
---|
| 56 | new Role(acme.getKeyID() + ".buy_rockets"), |
---|
| 57 | new Role(acme.getKeyID() + ".preferred_customer & " + |
---|
| 58 | warnerBros.getKeyID() + ".character")); |
---|
| 59 | c.make_cert(acme); |
---|
| 60 | ctxt.load_attribute_chunk(c); |
---|
| 61 | inProof.add(c); |
---|
| 62 | c = ctxt.newCredential( |
---|
| 63 | new Role(acme.getKeyID() + ".preferred_customer"), |
---|
| 64 | new Role(coyote.getKeyID())); |
---|
| 65 | c.make_cert(acme); |
---|
| 66 | ctxt.load_attribute_chunk(c); |
---|
| 67 | inProof.add(c); |
---|
| 68 | c = ctxt.newCredential( |
---|
| 69 | new Role(acme.getKeyID() + ".preferred_customer"), |
---|
| 70 | new Role(batman.getKeyID())); |
---|
| 71 | c.make_cert(acme); |
---|
| 72 | ctxt.load_attribute_chunk(c); |
---|
| 73 | c = ctxt.newCredential( |
---|
| 74 | new Role(warnerBros.getKeyID() + ".character"), |
---|
| 75 | new Role(coyote.getKeyID())); |
---|
| 76 | c.make_cert(warnerBros); |
---|
| 77 | ctxt.load_attribute_chunk(c); |
---|
| 78 | inProof.add(c); |
---|
| 79 | |
---|
| 80 | Context.QueryResult q = ctxt.query( |
---|
| 81 | acme.getKeyID() + ".buy_rockets", |
---|
| 82 | coyote.getKeyID()); |
---|
| 83 | |
---|
| 84 | if ( !q.getSuccess()) { |
---|
| 85 | setReason("Coyote can buy rockets proof failed?"); |
---|
| 86 | return false; |
---|
| 87 | } |
---|
| 88 | if ( inProof.size() != q.getCredentials().size()) { |
---|
| 89 | setReason("Coyote can buy rockets proof is the wrong size"); |
---|
| 90 | return false; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | for (Credential cc: inProof) |
---|
| 94 | if ( !q.getCredentials().contains(cc)) { |
---|
| 95 | setReason("Coyote can buy rockets proof missing cred "+cc); |
---|
| 96 | return false; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | q = ctxt.query(acme.getKeyID() + ".buy_rockets", |
---|
| 100 | batman.getKeyID()); |
---|
| 101 | if ( q.getSuccess()) { |
---|
| 102 | setReason("Batman can buy rockets ?"); |
---|
| 103 | return false; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | catch (Exception e) { |
---|
| 107 | setReason(e.getMessage()); |
---|
| 108 | return false; |
---|
| 109 | } |
---|
| 110 | return true; |
---|
| 111 | } |
---|
| 112 | } |
---|