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("not_ss.xml", "not_ss.pem", 1), |
---|
21 | new RocketsTest("Rockets test"), |
---|
22 | new ExperimentTest("Experiment test"), |
---|
23 | new BigTest("Big test", 20), |
---|
24 | }; |
---|
25 | |
---|
26 | public static void fatal(String s) { |
---|
27 | if (s != null ) |
---|
28 | System.out.println(s); |
---|
29 | System.exit(20); |
---|
30 | } |
---|
31 | |
---|
32 | public static boolean clearDir(File d) { |
---|
33 | for (String fn: d.list() ) { |
---|
34 | File f = new File(d, fn); |
---|
35 | |
---|
36 | if ( f.isDirectory() ) |
---|
37 | if ( !clearDir(f) ) return false; |
---|
38 | if ( !f.delete() ) return false; |
---|
39 | } |
---|
40 | return true; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | public static void main(String[] args) throws IOException { |
---|
45 | if (args.length < 2 ) |
---|
46 | fatal("Usage Regression regression_data_dir scratch"); |
---|
47 | |
---|
48 | File data = new File(args[0]); |
---|
49 | File scratch = new File(args[1]); |
---|
50 | |
---|
51 | if ( !data.isDirectory() ) |
---|
52 | fatal(data + " is not a directory"); |
---|
53 | if ( !scratch.isDirectory() ) |
---|
54 | fatal(scratch + " is not a directory"); |
---|
55 | |
---|
56 | int i = 0; |
---|
57 | for (RegressionTest test: tests) { |
---|
58 | File testDir = new File(scratch, "test" +i); |
---|
59 | if ( testDir.isDirectory()) |
---|
60 | clearDir(testDir); |
---|
61 | if (!testDir.mkdir()) |
---|
62 | fatal("Cannot make " +testDir); |
---|
63 | |
---|
64 | if ( test.runTest(data, testDir)) |
---|
65 | System.out.println(test.getName() + " Passed."); |
---|
66 | else |
---|
67 | fatal(test.getName() + " Failed: " + test.getReason()); |
---|
68 | i++; |
---|
69 | } |
---|
70 | System.exit(0); |
---|
71 | } |
---|
72 | } |
---|