### Question:
XMLDSigVerifier { public XMLDsigVerificationResult VerifyXMLDSig(InputStream fileStream) { XMLDsigVerificationResult result = new XMLDsigVerificationResult(); try { XMLSignature signature = getValidXMLSignature(fileStream); result.isValid = true; return validateCertificateIssuer(signature, result); } catch(Exception e) { result.isValid = false; result.failureReason = e.getMessage(); return result; } }  XMLDsigVerificationResult VerifyXMLDSig(InputStream fileStream);  }### Answer:
@Test public void testRSACertSignedByInvalidAuthority() throws Exception { InputStream EntryToken = new FileInputStream("src/test/ts/EntryToken.tsml"); XMLDsigVerificationResult result = new XMLDSigVerifier().VerifyXMLDSig(EntryToken); assert(!result.isValid); assert(result.failureReason.equals("Path does not chain with any of the trust anchors")); }
@Test public void verifyRSAxmldsig() throws Exception { InputStream DAIToken = new FileInputStream("src/test/ts/EntryToken-valid-RSA.tsml"); XMLDsigVerificationResult result = new XMLDSigVerifier().VerifyXMLDSig(DAIToken); assert(result.isValid); assert(result.subjectPrincipal.equals("CN=aw.app")); }
@Test public void testFifaTSMLECDSA() throws Exception { InputStream EntryToken = new FileInputStream("src/test/ts/fifa.tsml"); XMLDsigVerificationResult result = new XMLDSigVerifier().VerifyXMLDSig(EntryToken); assert(result.isValid); }
@Test public void testDuplicateKeyInfo() throws Exception { InputStream EntryToken = new FileInputStream("src/test/ts/EntryToken-duplicate-Values.tsml"); XMLDsigVerificationResult result = new XMLDSigVerifier().VerifyXMLDSig(EntryToken); assert(!result.isValid); System.out.println(result.failureReason); assert(result.failureReason.contains("expected KeyInfo or Object")); }
@Test public void testNotYetValidCertificate() throws Exception { InputStream EntryToken = new FileInputStream("src/test/ts/EntryToken-future-cert-self-signed.tsml"); XMLDsigVerificationResult result = new XMLDSigVerifier().VerifyXMLDSig(EntryToken); assert(!result.isValid); assert(result.failureReason.contains("NotBefore")); }