1 | import java.io.*; |
---|
2 | import java.util.*; |
---|
3 | |
---|
4 | import net.deterlab.abac.*; |
---|
5 | import net.deterlab.abac.regression.*; |
---|
6 | |
---|
7 | |
---|
8 | /** |
---|
9 | * Simple test of the native Java implementation of ABAC. Loads credentials |
---|
10 | * from an rt0 file and runs a query against them. |
---|
11 | */ |
---|
12 | public class Regression { |
---|
13 | |
---|
14 | static RegressionTest[] tests = new RegressionTest[] { |
---|
15 | new WriteCreds("net.deterlab.abac.GENICredential"), |
---|
16 | new WriteCreds("net.deterlab.abac.X509Credential"), |
---|
17 | new ReadCreds("e0-check-geni.xml", "Acme-check-geni.pem", 1), |
---|
18 | new ReadCreds("e0-check-x509.der", "Acme-check-x509.pem", 1), |
---|
19 | new ReadCreds("priv.xml", "issuer.pem", 6), |
---|
20 | new ReadCreds("ProtoGENI.xml", "PGissuer.pem", 5), |
---|
21 | new ReadCreds("not_ss.xml", "not_ss.pem", 1), |
---|
22 | new RocketsTest("Rockets test"), |
---|
23 | new ExperimentTest("Experiment test"), |
---|
24 | new BigTest("Big test", 20), |
---|
25 | }; |
---|
26 | |
---|
27 | public static void fatal(String s) { |
---|
28 | if (s != null ) |
---|
29 | System.out.println(s); |
---|
30 | System.exit(20); |
---|
31 | } |
---|
32 | |
---|
33 | public static boolean clearDir(File d) { |
---|
34 | for (String fn: d.list() ) { |
---|
35 | File f = new File(d, fn); |
---|
36 | |
---|
37 | if ( f.isDirectory() ) |
---|
38 | if ( !clearDir(f) ) return false; |
---|
39 | if ( !f.delete() ) return false; |
---|
40 | } |
---|
41 | return true; |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | public static void main(String[] args) throws IOException { |
---|
46 | if (args.length < 2 ) |
---|
47 | fatal("Usage Regression regression_data_dir scratch"); |
---|
48 | |
---|
49 | File data = new File(args[0]); |
---|
50 | File scratch = new File(args[1]); |
---|
51 | |
---|
52 | if ( !data.isDirectory() ) |
---|
53 | fatal(data + " is not a directory"); |
---|
54 | if ( !scratch.isDirectory() ) |
---|
55 | fatal(scratch + " is not a directory"); |
---|
56 | |
---|
57 | int i = 0; |
---|
58 | for (RegressionTest test: tests) { |
---|
59 | File testDir = new File(scratch, "test" +i); |
---|
60 | if ( testDir.isDirectory()) |
---|
61 | clearDir(testDir); |
---|
62 | if (!testDir.mkdir()) |
---|
63 | fatal("Cannot make " +testDir); |
---|
64 | |
---|
65 | if ( test.runTest(data, testDir)) |
---|
66 | System.out.println(test.getName() + " Passed."); |
---|
67 | else |
---|
68 | fatal(test.getName() + " Failed: " + test.getReason()); |
---|
69 | i++; |
---|
70 | } |
---|
71 | System.exit(0); |
---|
72 | } |
---|
73 | } |
---|