package mykeynote.junit;
import java.io.File;
import java.io.IOException;
import mykeynote.exceptions.keynote.SignatureVerificationException;
import mykeynote.exceptions.keynote.SyntaxError;
import mykeynote.exceptions.keynote.cl.KeyNoteCLException;
import mykeynote.exceptions.keynote.cl.UnknownCLException;
import mykeynote.keynote.KeyNoteCL;
import mykeynote.server.Report;
import mykeynote.server.configuration.Configuration;
import junit.framework.TestCase;
public class SigVerifyTest extends TestCase{
Configuration config = null;
public void testSigVerify() {
File configuration = new File(new File("etc", "mykeynote"), "MyKeyNote.conf.example");
File base = new File(new File("mykeynote", "junit"), "keynote");
String syntaxErrorFile = new File(base,"test-assertion1-signed.fail").getAbsolutePath();
String falseSignatureFile = new File(base,"test-assertion1-signed.fail2").getAbsolutePath();
String fileToOk=new File(base,"test-assertion1-signed.ok").getAbsolutePath();
Report report = null;
try{
config = new Configuration(configuration, true);
config.readConfigFile();
report = config.getReport();
} catch (Exception e){
assertNull(e);
}
KeyNoteCL cl = new KeyNoteCL(config, report);
try {
cl.sigVerify("101", fileToOk);
} catch (InterruptedException e) {
assertNull(e);
} catch (KeyNoteCLException e) {
assertNull(e);
} catch (SignatureVerificationException e) {
assertNull(e);
} catch (UnknownCLException e) {
assertNull(e);
} catch (SyntaxError e) {
assertNull(e);
} catch (IOException e) {
assertNull(e);
}
boolean assertExceptionHit = false;
//This test should failwith a syntax error
try {
cl.sigVerify("100", syntaxErrorFile);
} catch (InterruptedException e) {
assertNull(e);
} catch (KeyNoteCLException e) {
assertNull(e);
} catch (SignatureVerificationException e) {
assertNull(e);
} catch (UnknownCLException e) {
assertNull(e);
} catch (SyntaxError e) {
assertExceptionHit = true;
} catch (IOException e) {
assertNull(e);
}
assertTrue(assertExceptionHit);
assertExceptionHit = false;
try {
cl.sigVerify("100", falseSignatureFile);
} catch (InterruptedException e) {
assertNull(e);
} catch (KeyNoteCLException e) {
assertNull(e);
} catch (SignatureVerificationException e) {
assertExceptionHit = true;
} catch (UnknownCLException e) {
assertNull(e);
} catch (SyntaxError e) {
assertNull(e);
} catch (IOException e) {
assertNull(e);
}
assertTrue("This means that in the example above SignatureVerificationException" +
"was not hit!",assertExceptionHit);
}
public void tearDown() {
try {
config.finalizeConfiguration();
} catch (IOException e) {
assertNull(e);
}
}
}