[8375d4f] | 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[] { |
---|
[5b277d6] | 15 | new WriteCreds("net.deterlab.abac.GENICredential"), |
---|
| 16 | new WriteCreds("net.deterlab.abac.X509Credential"), |
---|
[1fb793f] | 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), |
---|
[8375d4f] | 20 | }; |
---|
| 21 | |
---|
| 22 | public static void fatal(String s) { |
---|
| 23 | if (s != null ) |
---|
[1fb793f] | 24 | System.out.println(s); |
---|
[8375d4f] | 25 | System.exit(20); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | public static boolean clearDir(File d) { |
---|
| 29 | for (String fn: d.list() ) { |
---|
| 30 | File f = new File(d, fn); |
---|
| 31 | |
---|
| 32 | if ( f.isDirectory() ) |
---|
| 33 | if ( !clearDir(f) ) return false; |
---|
| 34 | if ( !f.delete() ) return false; |
---|
| 35 | } |
---|
| 36 | return true; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | public static void main(String[] args) throws IOException { |
---|
| 41 | if (args.length < 2 ) |
---|
| 42 | fatal("Usage Regression regression_data_dir scratch"); |
---|
| 43 | |
---|
| 44 | File data = new File(args[0]); |
---|
| 45 | File scratch = new File(args[1]); |
---|
| 46 | |
---|
| 47 | if ( !data.isDirectory() ) |
---|
| 48 | fatal(data + " is not a directory"); |
---|
| 49 | if ( !scratch.isDirectory() ) |
---|
| 50 | fatal(scratch + " is not a directory"); |
---|
| 51 | |
---|
| 52 | for (RegressionTest test: tests) { |
---|
| 53 | if (!clearDir(scratch) ) |
---|
| 54 | fatal("Could not clear " + scratch); |
---|
| 55 | |
---|
| 56 | if ( test.runTest(data, scratch)) |
---|
| 57 | System.out.println(test.getName() + " Passed."); |
---|
| 58 | else |
---|
| 59 | fatal(test.getName() + " Failed: " + test.getReason()); |
---|
| 60 | } |
---|
| 61 | System.exit(0); |
---|
| 62 | } |
---|
| 63 | } |
---|