You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2007/12/21 17:53:37 UTC

svn commit: r606244 - /xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java

Author: mullan
Date: Fri Dec 21 08:53:37 2007
New Revision: 606244

URL: http://svn.apache.org/viewvc?rev=606244&view=rev
Log:
Add testsignWithProvider method which tests bug 43056: Library does not allow 
specify provider for private key operations

Modified:
    xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java

Modified: xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java?rev=606244&r1=606243&r2=606244&view=diff
==============================================================================
--- xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java (original)
+++ xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/XMLSignatureTest.java Fri Dec 21 08:53:37 2007
@@ -195,6 +195,37 @@
 	assertTrue(status);
     }
 
+    public void testsignWithProvider() throws Exception {
+	XMLSignature sig;
+	SignedInfo si;
+	KeyInfo ki = null;
+	XMLSignContext signContext;
+	Provider p = new TestProvider();
+	for (int i = SIGN_KEYS.length-2; i>=0 ; i--) {
+	    si = createSignedInfo(SIG_METHODS[i]);
+	    if (VALIDATE_KEYS[i] instanceof PublicKey) {
+		ki = kifac.newKeyInfo(Collections.singletonList
+		    (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[i])));
+	    } else {
+		ki = kifac.newKeyInfo(Collections.singletonList
+		    (kifac.newKeyName("testuser")));
+	    }
+	    sig = fac.newXMLSignature(si, ki, objs, id, sigValueId); 
+	    Document doc = TestUtils.newDocument();
+	    signContext = new DOMSignContext(SIGN_KEYS[i], doc);
+	    signContext.setProperty
+		("org.jcp.xml.dsig.internal.dom.SignatureProvider", p);
+	    try {
+	        sig.sign(signContext);
+	        fail("Should have failed because TestProvider does not " +
+		     "support " + SIGN_KEYS[i].getAlgorithm());
+	    } catch (Exception e) {
+		assertTrue(e.getMessage(), 
+		    e.getCause() instanceof InvalidKeyException);
+	    }
+	}
+    }
+
     private SignedInfo createSignedInfo(SignatureMethod sm) throws Exception {
 	// set up the building blocks
 	CanonicalizationMethod cm = fac.newCanonicalizationMethod
@@ -204,5 +235,11 @@
 	List refs = Collections.singletonList(fac.newReference
 	    ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", dm));
         return fac.newSignedInfo(cm, sm, refs);
+    }
+
+    static class TestProvider extends Provider {
+	TestProvider() {
+	    super("TestProvider", 0, "TestProvider");
+	}
     }
 }