You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/01/13 13:51:25 UTC
svn commit: r1058534 [2/2] - in
/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test:
encryption/ external/org/apache/xalan/XPathAPI/ interop/ version/
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTester.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTester.java?rev=1058534&r1=1058533&r2=1058534&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTester.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/encryption/XMLCipherTester.java Thu Jan 13 12:51:25 2011
@@ -36,9 +36,6 @@ import javax.crypto.spec.SecretKeySpec;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.apache.xml.security.algorithms.JCEMapper;
import org.apache.xml.security.c14n.Canonicalizer;
import org.apache.xml.security.encryption.XMLCipher;
@@ -60,12 +57,16 @@ import org.w3c.dom.NodeList;
* @author Axl Mattheus
* @author Berin Lautenbach
*/
-public class XMLCipherTester extends TestCase {
+public class XMLCipherTester extends org.junit.Assert {
/** {@link org.apache.commons.logging} logging facility */
static org.apache.commons.logging.Log log =
org.apache.commons.logging.LogFactory.getLog(XMLCipherTester.class.getName());
+ static {
+ org.apache.xml.security.Init.init();
+ }
+
private String documentName;
private String elementName;
private String elementIndex;
@@ -75,189 +76,152 @@ public class XMLCipherTester extends Tes
private boolean haveKeyWraps;
private String tstBase64EncodedString;
- public XMLCipherTester(String test) {
- super(test);
- }
-
- protected void setUp() {
+ public XMLCipherTester() {
basedir = System.getProperty("basedir",".");
documentName = System.getProperty("org.apache.xml.enc.test.doc",
- basedir + "/build.xml");
- elementName = System.getProperty("org.apache.xml.enc.test.elem",
- "path");
- elementIndex = System.getProperty("org.apache.xml.enc.test.idx",
- "0");
-
- tstBase64EncodedString = new String("YmNkZWZnaGlqa2xtbm9wcRrPXjQ1hvhDFT+EdesMAPE4F6vlT+y0HPXe0+nAGLQ8");
-
- // Determine if we have ISO 10126 Padding - needed for Bulk AES or
- // 3DES encryption
-
- haveISOPadding = false;
- String algorithmId =
- JCEMapper.translateURItoJCEID(org.apache.xml.security.utils.EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
-
- if (algorithmId != null) {
- try {
- if (Cipher.getInstance(algorithmId) != null)
- haveISOPadding = true;
- } catch (NoSuchAlgorithmException nsae) {
- } catch (NoSuchPaddingException nspe) {
- }
- }
-
- haveKeyWraps = (JCEMapper.translateURItoJCEID(org.apache.xml.security.utils.EncryptionConstants.ALGO_ID_KEYWRAP_AES128) != null);
-
- }
-
- protected void tearDown() {
- }
-
- private Document document() {
- Document d = null;
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- File f = new File(documentName);
- d = db.parse(f);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(-1);
+ basedir + "/build.xml");
+ elementName = System.getProperty("org.apache.xml.enc.test.elem", "path");
+ elementIndex = System.getProperty("org.apache.xml.enc.test.idx", "0");
+
+ tstBase64EncodedString =
+ new String("YmNkZWZnaGlqa2xtbm9wcRrPXjQ1hvhDFT+EdesMAPE4F6vlT+y0HPXe0+nAGLQ8");
+
+ // Determine if we have ISO 10126 Padding - needed for Bulk AES or
+ // 3DES encryption
+
+ haveISOPadding = false;
+ String algorithmId =
+ JCEMapper.translateURItoJCEID(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);
+
+ if (algorithmId != null) {
+ try {
+ if (Cipher.getInstance(algorithmId) != null) {
+ haveISOPadding = true;
+ }
+ } catch (NoSuchAlgorithmException nsae) {
+ //
+ } catch (NoSuchPaddingException nspe) {
+ //
+ }
}
- return (d);
- }
-
- private String element() {
- return (elementName);
+ haveKeyWraps =
+ (JCEMapper.translateURItoJCEID(EncryptionConstants.ALGO_ID_KEYWRAP_AES128) != null);
}
- private int index() {
- int result = -1;
+ /**
+ * Test encryption using a generated AES 128 bit key that is
+ * encrypted using a AES 192 bit key. Then reverse using the KEK
+ */
+ @org.junit.Test
+ public void testAES128ElementAES192KWCipherUsingKEK() throws Exception {
- try {
- result = Integer.parseInt(elementIndex);
- } catch (NumberFormatException nfe) {
- nfe.printStackTrace();
- System.exit(-1);
- }
-
- return (result);
- }
-
- /**
- * Test encryption using a generated AES 128 bit key that is
- * encrypted using a AES 192 bit key. Then reverse using the KEK
- */
-
- public void testAES128ElementAES192KWCipherUsingKEK() throws Exception {
-
- Document d = document(); // source
- Document ed = null;
- Document dd = null;
- Element e = (Element) d.getElementsByTagName(element()).item(index());
- Element ee = null;
+ Document d = document(); // source
+ Document ed = null;
+ Document dd = null;
+ Element e = (Element) d.getElementsByTagName(element()).item(index());
+ Element ee = null;
- String source = null;
- String target = null;
+ String source = null;
+ String target = null;
if (haveISOPadding && haveKeyWraps) {
+ source = toString(d);
- source = toString(d);
-
- // Set up a Key Encryption Key
- byte[] bits192 = "abcdefghijklmnopqrstuvwx".getBytes();
- Key kek = new SecretKeySpec(bits192, "AES");
-
- // Generate a traffic key
- KeyGenerator keygen = KeyGenerator.getInstance("AES");
- keygen.init(128);
- Key key = keygen.generateKey();
+ // Set up a Key Encryption Key
+ byte[] bits192 = "abcdefghijklmnopqrstuvwx".getBytes();
+ Key kek = new SecretKeySpec(bits192, "AES");
+
+ // Generate a traffic key
+ KeyGenerator keygen = KeyGenerator.getInstance("AES");
+ keygen.init(128);
+ Key key = keygen.generateKey();
cipher = XMLCipher.getInstance(XMLCipher.AES_192_KeyWrap);
- cipher.init(XMLCipher.WRAP_MODE, kek);
- EncryptedKey encryptedKey = cipher.encryptKey(d, key);
+ cipher.init(XMLCipher.WRAP_MODE, kek);
+ EncryptedKey encryptedKey = cipher.encryptKey(d, key);
// encrypt
cipher = XMLCipher.getInstance(XMLCipher.AES_128);
cipher.init(XMLCipher.ENCRYPT_MODE, key);
- EncryptedData builder = cipher.getEncryptedData();
+ EncryptedData builder = cipher.getEncryptedData();
- KeyInfo builderKeyInfo = builder.getKeyInfo();
- if (builderKeyInfo == null) {
- builderKeyInfo = new KeyInfo(d);
- builder.setKeyInfo(builderKeyInfo);
- }
+ KeyInfo builderKeyInfo = builder.getKeyInfo();
+ if (builderKeyInfo == null) {
+ builderKeyInfo = new KeyInfo(d);
+ builder.setKeyInfo(builderKeyInfo);
+ }
- builderKeyInfo.add(encryptedKey);
+ builderKeyInfo.add(encryptedKey);
ed = cipher.doFinal(d, e);
//decrypt
- key = null;
+ key = null;
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
cipher = XMLCipher.getInstance(XMLCipher.AES_128);
cipher.init(XMLCipher.DECRYPT_MODE, null);
- cipher.setKEK(kek);
- dd = cipher.doFinal(ed, ee);
+ cipher.setKEK(kek);
+ dd = cipher.doFinal(ed, ee);
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testAES128ElementAES192KWCipherUsingKEK skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn(
+ "Test testAES128ElementAES192KWCipherUsingKEK skipped as "
+ + "necessary algorithms not available"
+ );
+ }
}
-
- /**
- * Test encryption using a generated AES 256 bit key that is
- * encrypted using an RSA key. Reverse using KEK
- */
-
- public void testAES128ElementRSAKWCipherUsingKEK() throws Exception {
-
- Document d = document(); // source
- Document ed = null;
- Document dd = null;
- Element e = (Element) d.getElementsByTagName(element()).item(index());
- Element ee = null;
- String source = null;
- String target = null;
+ /**
+ * Test encryption using a generated AES 256 bit key that is
+ * encrypted using an RSA key. Reverse using KEK
+ */
+ @org.junit.Test
+ public void testAES128ElementRSAKWCipherUsingKEK() throws Exception {
- if (haveISOPadding) {
+ Document d = document(); // source
+ Document ed = null;
+ Document dd = null;
+ Element e = (Element) d.getElementsByTagName(element()).item(index());
+ Element ee = null;
- source = toString(d);
+ String source = null;
+ String target = null;
+
+ if (haveISOPadding) {
+ source = toString(d);
// Generate an RSA key
KeyPairGenerator rsaKeygen = KeyPairGenerator.getInstance("RSA");
KeyPair kp = rsaKeygen.generateKeyPair();
PrivateKey priv = kp.getPrivate();
PublicKey pub = kp.getPublic();
-
- // Generate a traffic key
- KeyGenerator keygen = KeyGenerator.getInstance("AES");
- keygen.init(256);
- Key key = keygen.generateKey();
-
+ // Generate a traffic key
+ KeyGenerator keygen = KeyGenerator.getInstance("AES");
+ keygen.init(256);
+ Key key = keygen.generateKey();
+
+
cipher = XMLCipher.getInstance(XMLCipher.RSA_v1dot5);
- cipher.init(XMLCipher.WRAP_MODE, pub);
- EncryptedKey encryptedKey = cipher.encryptKey(d, key);
+ cipher.init(XMLCipher.WRAP_MODE, pub);
+ EncryptedKey encryptedKey = cipher.encryptKey(d, key);
// encrypt
cipher = XMLCipher.getInstance(XMLCipher.AES_256);
cipher.init(XMLCipher.ENCRYPT_MODE, key);
- EncryptedData builder = cipher.getEncryptedData();
+ EncryptedData builder = cipher.getEncryptedData();
- KeyInfo builderKeyInfo = builder.getKeyInfo();
- if (builderKeyInfo == null) {
- builderKeyInfo = new KeyInfo(d);
- builder.setKeyInfo(builderKeyInfo);
- }
+ KeyInfo builderKeyInfo = builder.getKeyInfo();
+ if (builderKeyInfo == null) {
+ builderKeyInfo = new KeyInfo(d);
+ builder.setKeyInfo(builderKeyInfo);
+ }
- builderKeyInfo.add(encryptedKey);
+ builderKeyInfo.add(encryptedKey);
ed = cipher.doFinal(d, e);
log.debug("Encrypted document");
@@ -265,112 +229,116 @@ public class XMLCipherTester extends Tes
//decrypt
- key = null;
+ key = null;
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
cipher = XMLCipher.getInstance(XMLCipher.AES_128);
cipher.init(XMLCipher.DECRYPT_MODE, null);
- cipher.setKEK(priv);
- dd = cipher.doFinal(ed, ee);
+ cipher.setKEK(priv);
+ dd = cipher.doFinal(ed, ee);
target = toString(dd);
log.debug("Output document");
log.debug(target);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testAES128ElementRSAKWCipherUsingKEK skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn(
+ "Test testAES128ElementRSAKWCipherUsingKEK skipped as "
+ + "necessary algorithms not available"
+ );
+ }
}
- /**
- * Test encryption using a generated AES 192 bit key that is
- * encrypted using a 3DES key. Then reverse by decrypting
- * EncryptedKey by hand
- */
-
- public void testAES192ElementAES256KWCipher() throws Exception {
-
- Document d = document(); // source
- Document ed = null;
- Document dd = null;
- Element e = (Element) d.getElementsByTagName(element()).item(index());
- Element ee = null;
+ /**
+ * Test encryption using a generated AES 192 bit key that is
+ * encrypted using a 3DES key. Then reverse by decrypting
+ * EncryptedKey by hand
+ */
+ @org.junit.Test
+ public void testAES192ElementAES256KWCipher() throws Exception {
- String source = null;
- String target = null;
+ Document d = document(); // source
+ Document ed = null;
+ Document dd = null;
+ Element e = (Element) d.getElementsByTagName(element()).item(index());
+ Element ee = null;
- if (haveISOPadding && haveKeyWraps) {
+ String source = null;
+ String target = null;
- source = toString(d);
+ if (haveISOPadding && haveKeyWraps) {
+ source = toString(d);
- // Set up a Key Encryption Key
- byte[] bits192 = "abcdefghijklmnopqrstuvwx".getBytes();
+ // Set up a Key Encryption Key
+ byte[] bits192 = "abcdefghijklmnopqrstuvwx".getBytes();
DESedeKeySpec keySpec = new DESedeKeySpec(bits192);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
Key kek = keyFactory.generateSecret(keySpec);
- // Generate a traffic key
- KeyGenerator keygen = KeyGenerator.getInstance("AES");
- keygen.init(192);
- Key key = keygen.generateKey();
+ // Generate a traffic key
+ KeyGenerator keygen = KeyGenerator.getInstance("AES");
+ keygen.init(192);
+ Key key = keygen.generateKey();
cipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES_KeyWrap);
- cipher.init(XMLCipher.WRAP_MODE, kek);
- EncryptedKey encryptedKey = cipher.encryptKey(d, key);
+ cipher.init(XMLCipher.WRAP_MODE, kek);
+ EncryptedKey encryptedKey = cipher.encryptKey(d, key);
// encrypt
cipher = XMLCipher.getInstance(XMLCipher.AES_192);
cipher.init(XMLCipher.ENCRYPT_MODE, key);
- EncryptedData builder = cipher.getEncryptedData();
+ EncryptedData builder = cipher.getEncryptedData();
- KeyInfo builderKeyInfo = builder.getKeyInfo();
- if (builderKeyInfo == null) {
- builderKeyInfo = new KeyInfo(d);
- builder.setKeyInfo(builderKeyInfo);
- }
+ KeyInfo builderKeyInfo = builder.getKeyInfo();
+ if (builderKeyInfo == null) {
+ builderKeyInfo = new KeyInfo(d);
+ builder.setKeyInfo(builderKeyInfo);
+ }
- builderKeyInfo.add(encryptedKey);
+ builderKeyInfo.add(encryptedKey);
ed = cipher.doFinal(d, e);
//decrypt
- key = null;
+ key = null;
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
cipher = XMLCipher.getInstance();
cipher.init(XMLCipher.DECRYPT_MODE, null);
- EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
-
- if(encryptedData == null) {
- System.out.println("ed is null");
- }
- else if (encryptedData.getKeyInfo() == null) {
- System.out.println("ki is null");
- }
- EncryptedKey ek = encryptedData.getKeyInfo().itemEncryptedKey(0);
-
- if (ek != null) {
- XMLCipher keyCipher = XMLCipher.getInstance();
- keyCipher.init(XMLCipher.UNWRAP_MODE, kek);
- key = keyCipher.decryptKey(ek, encryptedData.getEncryptionMethod().getAlgorithm());
- }
-
- // Create a new cipher just to be paranoid
- XMLCipher cipher3 = XMLCipher.getInstance();
- cipher3.init(XMLCipher.DECRYPT_MODE, key);
+ EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
+
+ if(encryptedData == null) {
+ System.out.println("ed is null");
+ }
+ else if (encryptedData.getKeyInfo() == null) {
+ System.out.println("ki is null");
+ }
+ EncryptedKey ek = encryptedData.getKeyInfo().itemEncryptedKey(0);
+
+ if (ek != null) {
+ XMLCipher keyCipher = XMLCipher.getInstance();
+ keyCipher.init(XMLCipher.UNWRAP_MODE, kek);
+ key = keyCipher.decryptKey(ek, encryptedData.getEncryptionMethod().getAlgorithm());
+ }
+
+ // Create a new cipher just to be paranoid
+ XMLCipher cipher3 = XMLCipher.getInstance();
+ cipher3.init(XMLCipher.DECRYPT_MODE, key);
dd = cipher3.doFinal(ed, ee);
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testAES192ElementAES256KWCipher skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn(
+ "Test testAES192ElementAES256KWCipher skipped as "
+ + "necessary algorithms not available"
+ );
+ }
}
- public void testTrippleDesElementCipher() throws Exception {
+ @org.junit.Test
+ public void testTripleDesElementCipher() throws Exception {
Document d = document(); // source
Document ed = null; // target
Document dd = null; // target
@@ -381,8 +349,7 @@ public class XMLCipherTester extends Tes
String target = null;
if (haveISOPadding) {
-
- source = toString(d);
+ source = toString(d);
// prepare for encryption
byte[] passPhrase = "24 Bytes per DESede key!".getBytes();
@@ -399,25 +366,27 @@ public class XMLCipherTester extends Tes
cipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
cipher.init(XMLCipher.DECRYPT_MODE, key);
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
- EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
- Assert.assertEquals(encryptedData.getEncryptionMethod().getAlgorithm(),
- XMLCipher.TRIPLEDES);
+ EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
+ String algorithm = encryptedData.getEncryptionMethod().getAlgorithm();
+ assert(XMLCipher.TRIPLEDES.equals(algorithm));
dd = cipher.doFinal(ed, ee);
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testTrippleDesElementCipher skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn(
+ "Test testTripleDesElementCipher skipped as necessary algorithms not available"
+ );
+ }
}
+ @org.junit.Test
public void testAes128ElementCipher() throws Exception {
byte[] bits128 = {
- (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
- (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
- (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
- (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
+ (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
+ (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
+ (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
+ (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
Key key = new SecretKeySpec(bits128, "AES");
Document d = document(); // source
@@ -430,8 +399,7 @@ public class XMLCipherTester extends Tes
String target = null;
if (haveISOPadding) {
-
- source = toString(d);
+ source = toString(d);
// encrypt
cipher = XMLCipher.getInstance(XMLCipher.AES_128);
@@ -442,27 +410,29 @@ public class XMLCipherTester extends Tes
cipher = XMLCipher.getInstance(XMLCipher.AES_128);
cipher.init(XMLCipher.DECRYPT_MODE, key);
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
- EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
- Assert.assertEquals(encryptedData.getEncryptionMethod().getAlgorithm(),
- XMLCipher.AES_128);
+ EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
+ String algorithm = encryptedData.getEncryptionMethod().getAlgorithm();
+ assert(XMLCipher.AES_128.equals(algorithm));
dd = cipher.doFinal(ed, ee);
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testAes128ElementCipher skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn(
+ "Test testAes128ElementCipher skipped as necessary algorithms not available"
+ );
+ }
}
+ @org.junit.Test
public void testAes192ElementCipher() throws Exception {
byte[] bits192 = {
- (byte) 0x08, (byte) 0x09, (byte) 0x0A, (byte) 0x0B,
- (byte) 0x0C, (byte) 0x0D, (byte) 0x0E, (byte) 0x0F,
- (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
- (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
- (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
- (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
+ (byte) 0x08, (byte) 0x09, (byte) 0x0A, (byte) 0x0B,
+ (byte) 0x0C, (byte) 0x0D, (byte) 0x0E, (byte) 0x0F,
+ (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
+ (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
+ (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
+ (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
Key key = new SecretKeySpec(bits192, "AES");
Document d = document(); // source
@@ -475,8 +445,7 @@ public class XMLCipherTester extends Tes
String target = null;
if (haveISOPadding) {
-
- source = toString(d);
+ source = toString(d);
// encrypt
cipher = XMLCipher.getInstance(XMLCipher.AES_192);
@@ -487,29 +456,29 @@ public class XMLCipherTester extends Tes
cipher = XMLCipher.getInstance(XMLCipher.AES_192);
cipher.init(XMLCipher.DECRYPT_MODE, key);
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
- EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
- Assert.assertEquals(encryptedData.getEncryptionMethod().getAlgorithm(),
- XMLCipher.AES_192);
+ EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
+ String algorithm = encryptedData.getEncryptionMethod().getAlgorithm();
+ assert(XMLCipher.AES_192.equals(algorithm));
dd = cipher.doFinal(ed, ee);
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testAes192ElementCipher skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn("Test testAes192ElementCipher skipped as necessary algorithms not available");
+ }
}
+ @org.junit.Test
public void testAes265ElementCipher() throws Exception {
byte[] bits256 = {
- (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03,
- (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
- (byte) 0x08, (byte) 0x09, (byte) 0x0A, (byte) 0x0B,
- (byte) 0x0C, (byte) 0x0D, (byte) 0x0E, (byte) 0x0F,
- (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
- (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
- (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
- (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
+ (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03,
+ (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07,
+ (byte) 0x08, (byte) 0x09, (byte) 0x0A, (byte) 0x0B,
+ (byte) 0x0C, (byte) 0x0D, (byte) 0x0E, (byte) 0x0F,
+ (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
+ (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
+ (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
+ (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
Key key = new SecretKeySpec(bits256, "AES");
Document d = document(); // source
@@ -522,8 +491,7 @@ public class XMLCipherTester extends Tes
String target = null;
if (haveISOPadding) {
-
- source = toString(d);
+ source = toString(d);
// encrypt
cipher = XMLCipher.getInstance(XMLCipher.AES_256);
@@ -534,25 +502,24 @@ public class XMLCipherTester extends Tes
cipher = XMLCipher.getInstance(XMLCipher.AES_256);
cipher.init(XMLCipher.DECRYPT_MODE, key);
ee = (Element) ed.getElementsByTagName("xenc:EncryptedData").item(0);
- EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
- Assert.assertEquals(encryptedData.getEncryptionMethod().getAlgorithm(),
- XMLCipher.AES_256);
+ EncryptedData encryptedData = cipher.loadEncryptedData(ed, ee);
+ String algorithm = encryptedData.getEncryptionMethod().getAlgorithm();
+ assert(XMLCipher.AES_256.equals(algorithm));
dd = cipher.doFinal(ed, ee);
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testAes265ElementCipher skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn("Test testAes265ElementCipher skipped as necessary algorithms not available");
+ }
}
/*
- * Test case for when the entire document is encrypted and decrypted
- * In this case the EncryptedData becomes the root element of the document
- */
-
- public void testTrippleDesDocumentCipher() throws Exception {
+ * Test case for when the entire document is encrypted and decrypted
+ * In this case the EncryptedData becomes the root element of the document
+ */
+ @org.junit.Test
+ public void testTripleDesDocumentCipher() throws Exception {
Document d = document(); // source
Document ed = null; // target
Document dd = null; // target
@@ -563,8 +530,7 @@ public class XMLCipherTester extends Tes
String target = null;
if (haveISOPadding) {
-
- source = toString(d);
+ source = toString(d);
// prepare for encryption
byte[] passPhrase = "24 Bytes per DESede key!".getBytes();
@@ -585,96 +551,101 @@ public class XMLCipherTester extends Tes
target = toString(dd);
- Assert.assertEquals(source, target);
- }
- else {
- log.warn("Test testTrippleDesDocumentCipher skipped as necessary algorithms not available");
- }
+ assert source.equals(target);
+ } else {
+ log.warn(
+ "Test testTripleDesDocumentCipher skipped as "
+ + "necessary algorithms not available"
+ );
+ }
}
- /*
- * Test a Cipher Reference
- */
-
- public void testSameDocumentCipherReference() throws Exception {
+ /*
+ * Test a Cipher Reference
+ */
+ @org.junit.Test
+ public void testSameDocumentCipherReference() throws Exception {
if (haveISOPadding) {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
-
- Document d = db.newDocument();
-
- Element docElement = d.createElement("EncryptedDoc");
- d.appendChild(docElement);
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
- // Create the XMLCipher object
- cipher = XMLCipher.getInstance();
-
- EncryptedData ed =
- cipher.createEncryptedData(CipherData.REFERENCE_TYPE,
- "#CipherTextId");
- EncryptionMethod em =
- cipher.createEncryptionMethod(XMLCipher.AES_128);
-
- ed.setEncryptionMethod(em);
-
- org.apache.xml.security.encryption.Transforms xencTransforms =
- cipher.createTransforms(d);
- ed.getCipherData().getCipherReference().setTransforms(xencTransforms);
- org.apache.xml.security.transforms.Transforms dsTransforms =
- xencTransforms.getDSTransforms();
-
- // An XPath transform
- XPathContainer xpc = new XPathContainer(d);
- xpc.setXPath("self::text()[parent::CipherText[@Id=\"CipherTextId\"]]");
- dsTransforms.addTransform(org.apache.xml.security.transforms.Transforms.TRANSFORM_XPATH,
- xpc.getElementPlusReturns());
-
- // Add a Base64 Transforms
- dsTransforms.addTransform(
- org.apache.xml.security.transforms.Transforms.TRANSFORM_BASE64_DECODE);
-
- Element ee = cipher.martial(d, ed);
-
- docElement.appendChild(ee);
-
- // Add the cipher text
- Element encryptedElement = d.createElement("CipherText");
- encryptedElement.setAttributeNS(null, "Id", "CipherTextId");
- IdResolver.registerElementById(encryptedElement, "CipherTextId");
- encryptedElement.appendChild(d.createTextNode(tstBase64EncodedString));
- docElement.appendChild(encryptedElement);
- // dump(d);
-
- // Now the decrypt, with a brand new cipher
- XMLCipher cipherDecrypt = XMLCipher.getInstance();
- Key key =
- new SecretKeySpec("abcdefghijklmnop".getBytes("ASCII"), "AES");
+ Document d = db.newDocument();
- cipherDecrypt.init(XMLCipher.DECRYPT_MODE, key);
- byte[] decryptBytes = cipherDecrypt.decryptToByteArray(ee);
+ Element docElement = d.createElement("EncryptedDoc");
+ d.appendChild(docElement);
- Assert.assertEquals(new String(decryptBytes, "ASCII"),
- new String("A test encrypted secret"));
- }
- else {
- log.warn("Test testSameDocumentCipherReference skipped as necessary algorithms not available");
- }
+ // Create the XMLCipher object
+ cipher = XMLCipher.getInstance();
+ EncryptedData ed =
+ cipher.createEncryptedData(CipherData.REFERENCE_TYPE,
+ "#CipherTextId");
+ EncryptionMethod em =
+ cipher.createEncryptionMethod(XMLCipher.AES_128);
+
+ ed.setEncryptionMethod(em);
+
+ org.apache.xml.security.encryption.Transforms xencTransforms =
+ cipher.createTransforms(d);
+ ed.getCipherData().getCipherReference().setTransforms(xencTransforms);
+ org.apache.xml.security.transforms.Transforms dsTransforms =
+ xencTransforms.getDSTransforms();
+
+ // An XPath transform
+ XPathContainer xpc = new XPathContainer(d);
+ xpc.setXPath("self::text()[parent::CipherText[@Id=\"CipherTextId\"]]");
+ dsTransforms.addTransform(
+ org.apache.xml.security.transforms.Transforms.TRANSFORM_XPATH,
+ xpc.getElementPlusReturns()
+ );
+
+ // Add a Base64 Transforms
+ dsTransforms.addTransform(
+ org.apache.xml.security.transforms.Transforms.TRANSFORM_BASE64_DECODE
+ );
+
+ Element ee = cipher.martial(d, ed);
+
+ docElement.appendChild(ee);
+
+ // Add the cipher text
+ Element encryptedElement = d.createElement("CipherText");
+ encryptedElement.setAttributeNS(null, "Id", "CipherTextId");
+ IdResolver.registerElementById(encryptedElement, "CipherTextId");
+ encryptedElement.appendChild(d.createTextNode(tstBase64EncodedString));
+ docElement.appendChild(encryptedElement);
+ // dump(d);
+
+ // Now the decrypt, with a brand new cipher
+ XMLCipher cipherDecrypt = XMLCipher.getInstance();
+ Key key = new SecretKeySpec("abcdefghijklmnop".getBytes("ASCII"), "AES");
+
+ cipherDecrypt.init(XMLCipher.DECRYPT_MODE, key);
+ byte[] decryptBytes = cipherDecrypt.decryptToByteArray(ee);
+
+ assert (new String(decryptBytes, "ASCII")).equals(
+ new String("A test encrypted secret"));
+ } else {
+ log.warn(
+ "Test testSameDocumentCipherReference skipped as "
+ + "necessary algorithms not available"
+ );
}
+ }
+ @org.junit.Test
public void testSerializedData() throws Exception {
-
if (!haveISOPadding) {
log.warn("Test testSerializedData skipped as necessary algorithms not available");
return;
}
-
+
byte[] bits128 = {
- (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
- (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
- (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
- (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
+ (byte) 0x10, (byte) 0x11, (byte) 0x12, (byte) 0x13,
+ (byte) 0x14, (byte) 0x15, (byte) 0x16, (byte) 0x17,
+ (byte) 0x18, (byte) 0x19, (byte) 0x1A, (byte) 0x1B,
+ (byte) 0x1C, (byte) 0x1D, (byte) 0x1E, (byte) 0x1F};
Key key = new SecretKeySpec(bits128, "AES");
Document d = document(); // source
@@ -695,68 +666,95 @@ public class XMLCipherTester extends Tes
String before = baos.toString("UTF-8");
byte[] serialized = baos.toByteArray();
- EncryptedData encryptedData = cipher.encryptData
- (d, EncryptionConstants.TYPE_ELEMENT,
- new ByteArrayInputStream(serialized));
+ EncryptedData encryptedData =
+ cipher.encryptData(
+ d, EncryptionConstants.TYPE_ELEMENT, new ByteArrayInputStream(serialized)
+ );
//decrypt
XMLCipher dcipher = XMLCipher.getInstance(XMLCipher.AES_128);
dcipher.init(XMLCipher.DECRYPT_MODE, key);
- Assert.assertEquals
- (encryptedData.getEncryptionMethod().getAlgorithm(),
- XMLCipher.AES_128);
+ String algorithm = encryptedData.getEncryptionMethod().getAlgorithm();
+ assert(XMLCipher.AES_128.equals(algorithm));
byte[] bytes = dcipher.decryptToByteArray(dcipher.martial(encryptedData));
String after = new String(bytes, "UTF-8");
- Assert.assertEquals(before, after);
+ assert before.equals(after);
// test with null type
- encryptedData = cipher.encryptData
- (d, null, new ByteArrayInputStream(serialized));
+ encryptedData = cipher.encryptData(d, null, new ByteArrayInputStream(serialized));
}
+ @org.junit.Test
public void testEncryptedKeyWithRecipient() throws Exception {
-
String filename =
"data/org/apache/xml/security/encryption/encryptedKey.xml";
if (basedir != null && !"".equals(basedir)) {
filename = basedir + "/" + filename;
}
File f = new File(filename);
-
+
DocumentBuilderFactory builderFactory =
DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware (true);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document document = builder.parse(f);
-
+
XMLCipher keyCipher = XMLCipher.getInstance();
keyCipher.init(XMLCipher.UNWRAP_MODE, null);
-
- NodeList ekList = document.getElementsByTagNameNS
- (EncryptionConstants.EncryptionSpecNS,
- EncryptionConstants._TAG_ENCRYPTEDKEY);
+
+ NodeList ekList =
+ document.getElementsByTagNameNS(
+ EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDKEY
+ );
for (int i = 0; i < ekList.getLength(); i++) {
- EncryptedKey ek = keyCipher.loadEncryptedKey
- (document, (Element) ekList.item(i));
+ EncryptedKey ek =
+ keyCipher.loadEncryptedKey(document, (Element) ekList.item(i));
assertNotNull(ek.getRecipient());
}
}
private String toString (Node n) throws Exception {
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Canonicalizer c14n = Canonicalizer.getInstance
- (Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
+ (Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS);
byte[] serBytes = c14n.canonicalizeSubtree(n);
baos.write(serBytes);
baos.close();
return baos.toString("UTF-8");
+ }
+
+ private Document document() {
+ Document d = null;
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ File f = new File(documentName);
+ d = db.parse(f);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ return (d);
}
-
- static {
- org.apache.xml.security.Init.init();
+
+ private String element() {
+ return (elementName);
+ }
+
+ private int index() {
+ int result = -1;
+
+ try {
+ result = Integer.parseInt(elementIndex);
+ } catch (NumberFormatException nfe) {
+ nfe.printStackTrace();
+ System.exit(-1);
+ }
+
+ return (result);
}
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/AttributeAncestorOrSelfTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/AttributeAncestorOrSelfTest.java?rev=1058534&r1=1058533&r2=1058534&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/AttributeAncestorOrSelfTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/AttributeAncestorOrSelfTest.java Thu Jan 13 12:51:25 2011
@@ -16,17 +16,11 @@
*/
package org.apache.xml.security.test.external.org.apache.xalan.XPathAPI;
-
-
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.xml.security.utils.Constants;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XObject;
@@ -38,132 +32,99 @@ import org.w3c.dom.Node;
/**
* This test is to ensure that the owner element of an Attribute is on the
* ancestor-or-self axis.
- *
- * @author $Author$
*/
-public class AttributeAncestorOrSelfTest extends TestCase {
+public class AttributeAncestorOrSelfTest extends org.junit.Assert {
- /** {@link org.apache.commons.logging} logging facility */
+ /** {@link org.apache.commons.logging} logging facility */
static org.apache.commons.logging.Log log =
- org.apache.commons.logging.LogFactory.getLog(
- AttributeAncestorOrSelfTest.class.getName());
+ org.apache.commons.logging.LogFactory.getLog(AttributeAncestorOrSelfTest.class.getName());
+
+ private static final String _nodeSetInput1 =
+ "<?xml version=\"1.0\"?>\n"
+ + "<ds:Signature xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>" + "\n"
+ + "<ds:Object Id='id1'>" + "\n"
+ + "<!-- the comment -->and text"
+ + "</ds:Object>" + "\n"
+ + "</ds:Signature>";
+
+ static {
+ org.apache.xml.security.Init.init();
+ }
+
+ /**
+ * Method test01
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void test01() throws Exception {
+
+ String ctxNodeStr = "/ds:Signature/ds:Object";
+ String evalStr = "ancestor-or-self::ds:Signature";
+
+ assertTrue("Bad " + ctxNodeStr + " " + evalStr + " ",
+ isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
+ }
+
+ /**
+ * Method test02
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void test02() throws Exception {
+
+ String ctxNodeStr = "/ds:Signature/ds:Object/text()";
+ String evalStr = "ancestor-or-self::ds:Signature";
+
+ assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " ,
+ isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
+ }
+
+ /**
+ * Method test03
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void test03() throws Exception {
+
+ String ctxNodeStr = "/ds:Signature/ds:Object/@Id";
+ String evalStr = "ancestor-or-self::ds:Object";
+
+ assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " ,
+ isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
+ }
+
+ /**
+ * Process input args and execute the XPath.
+ *
+ * @param xmlString
+ * @param ctxNodeStr
+ * @param evalStr
+ *
+ * @throws Exception
+ */
+ private static boolean isAncestorOf(String xmlString, String ctxNodeStr, String evalStr)
+ throws Exception {
+ DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
+
+ dfactory.setValidating(false);
+ dfactory.setNamespaceAware(true);
+
+ DocumentBuilder db = dfactory.newDocumentBuilder();
+ Document document =
+ db.parse(new ByteArrayInputStream(_nodeSetInput1.getBytes()));
+ Element nscontext = document.createElementNS(null, "nscontext");
+
+ nscontext.setAttributeNS(
+ Constants.NamespaceSpecNS, "xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"
+ );
+
+ Node ctxNode = XPathAPI.selectSingleNode(document, ctxNodeStr, nscontext);
+ XObject include = XPathAPI.eval(ctxNode, evalStr, nscontext);
+ return include.bool();
+ }
- /**
- * Method suite
- *
- *
- */
- public static Test suite() {
- return new TestSuite(AttributeAncestorOrSelfTest.class);
- }
-
- /**
- * Constructor AttributeAncestorOrSelf
- *
- * @param Name_
- */
- public AttributeAncestorOrSelfTest(String Name_) {
- super(Name_);
- }
-
- /**
- * Method main
- *
- * @param args
- */
- public static void main(String[] args) {
-
- String[] testCaseName = { "-noloading",
- AttributeAncestorOrSelfTest.class.getName() };
-
- junit.textui.TestRunner.main(testCaseName);
- }
-
- /**
- * Process input args and execute the XPath.
- *
- * @param xmlString
- * @param ctxNodeStr
- * @param evalStr
- *
- * @throws Exception
- */
- static private boolean isAncestorOf(
- String xmlString, String ctxNodeStr, String evalStr)
- throws Exception {
-
- DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
-
- dfactory.setValidating(false);
- dfactory.setNamespaceAware(true);
-
- DocumentBuilder db = dfactory.newDocumentBuilder();
- Document document =
- db.parse(new ByteArrayInputStream(_nodeSetInput1.getBytes()));
- Element nscontext = document.createElementNS(null, "nscontext");
-
- nscontext.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", "http://www.w3.org/2000/09/xmldsig#");
-
- Node ctxNode = XPathAPI.selectSingleNode(document, ctxNodeStr, nscontext);
- XObject include = XPathAPI.eval(ctxNode, evalStr, nscontext);
-
- return include.bool();
- }
-
- //J-
- static final String _nodeSetInput1 =
- "<?xml version=\"1.0\"?>\n"
- + "<ds:Signature xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>" + "\n"
- + "<ds:Object Id='id1'>" + "\n"
- + "<!-- the comment -->and text"
- + "</ds:Object>" + "\n"
- + "</ds:Signature>";
- //J+
-
- /**
- * Method test01
- *
- * @throws Exception
- */
- public static void test01() throws Exception {
-
- String ctxNodeStr = "/ds:Signature/ds:Object";
- String evalStr = "ancestor-or-self::ds:Signature";
-
- assertTrue("Bad " + ctxNodeStr + " " + evalStr + " ",
- isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
- }
-
- /**
- * Method test02
- *
- * @throws Exception
- */
- public static void test02() throws Exception {
-
- String ctxNodeStr = "/ds:Signature/ds:Object/text()";
- String evalStr = "ancestor-or-self::ds:Signature";
-
- assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " ,
- isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
- }
-
- /**
- * Method test03
- *
- * @throws Exception
- */
- public static void test03() throws Exception {
-
- String ctxNodeStr = "/ds:Signature/ds:Object/@Id";
- String evalStr = "ancestor-or-self::ds:Object";
-
- assertTrue("Bad " + ctxNodeStr + " " + evalStr + " " ,
- isAncestorOf(_nodeSetInput1, ctxNodeStr, evalStr));
- }
-
- static {
- org.apache.xml.security.Init.init();
- }
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/XalanBug1425Test.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/XalanBug1425Test.java?rev=1058534&r1=1058533&r2=1058534&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/XalanBug1425Test.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/external/org/apache/xalan/XPathAPI/XalanBug1425Test.java Thu Jan 13 12:51:25 2011
@@ -17,9 +17,6 @@
*/
package org.apache.xml.security.test.external.org.apache.xalan.XPathAPI;
-
-
-// This file uses 4 space indents, no tabs.
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
@@ -28,10 +25,6 @@ import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -39,209 +32,181 @@ import org.w3c.dom.traversal.NodeIterato
/**
- * Testcase for testing the <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1425">Xalan Bug 1425</A>.
+ * Testcase for testing the
+ * <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1425">Xalan Bug 1425</A>.
*
* This fails with Xalan v2.1.0 and works with Xalan v2.2D6.
*/
-public class XalanBug1425Test extends TestCase {
+public class XalanBug1425Test extends org.junit.Assert {
- /** {@link org.apache.commons.logging} logging facility */
+ /** {@link org.apache.commons.logging} logging facility */
static org.apache.commons.logging.Log log =
- org.apache.commons.logging.LogFactory.getLog(
- XalanBug1425Test.class.getName());
-
+ org.apache.commons.logging.LogFactory.getLog(XalanBug1425Test.class.getName());
- /**
- * Method suite
- *
- *
- */
- public static Test suite() {
- return new TestSuite(XalanBug1425Test.class);
- }
-
- /**
- * Constructor XalanBug1425Test
- *
- * @param Name_
- */
- public XalanBug1425Test(String Name_) {
- super(Name_);
- }
-
- /**
- * Method main
- *
- * @param args
- */
- public static void main(String[] args) {
-
- String[] testCaseName = { "-noloading",
- XalanBug1425Test.class.getName() };
-
- junit.textui.TestRunner.main(testCaseName);
- }
-
- /**
- * Process input args and execute the XPath.
- *
- * @param xmlString
- * @param xpath
- *
- * @throws Exception
- */
- static private boolean containsDocumentElement(
- String xmlString, String xpath) throws Exception {
-
- DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dfactory.newDocumentBuilder();
- Document doc = db.parse(new ByteArrayInputStream(xmlString.getBytes()));
-
- // Set up an identity transformer to use as serializer.
- Transformer serializer =
- TransformerFactory.newInstance().newTransformer();
-
- serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
-
- // Use the simple XPath API to select a nodeIterator.
- // System.out.println("Querying DOM using " + xpath);
- NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
-
- // Serialize the found nodes to System.out.
- // System.out.println("<output>");
- Node n;
-
- while ((n = nl.nextNode()) != null) {
-
- // System.out.println("<node" + ++i + " nodeType=\"" + nodeTypeString[n.getNodeType()] + "\">");
- // serializer.transform(new DOMSource(n), new StreamResult(System.out));
- // System.out.println("</node" + i + ">");
- // System.out.println();
- if (n == doc.getDocumentElement()) {
- return true;
- }
- }
-
- // System.out.println("</output>");
- return false;
- }
-
- /**
- * Method testBad01
- *
- * @throws Exception
- */
- public static void testBad01() throws Exception {
-
- String xml = "<doc><a /> </doc><!-- -->";
- String desc = " # mixed content and following comment";
- String xpath = "(//.)";
-
- assertTrue("Bad " + xml + desc + " " ,
- containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testBad02
- *
- * @throws Exception
- */
- public static void testBad02() throws Exception {
-
- String xml = "<doc><a /> </doc><?pi?>";
- String desc = " # mixed content and following PI";
- String xpath = "(//.)";
-
- assertTrue("Bad " + xml + desc + " " ,
- containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testBad03
- *
- * @throws Exception
- */
- public static void testBad03() throws Exception {
-
- String xml = "<doc><a /><b /></doc><!-- -->";
- String desc = " # mixed content and following comment";
- String xpath = "(//.)";
-
- assertTrue("Bad " + xml + desc + " " ,
- containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testGood01
- *
- * @throws Exception
- */
- public static void testGood01() throws Exception {
-
- String xml = "<doc><a /></doc><!-- -->";
- String desc = " # 'clean' content and following comment";
- String xpath = "(//.)";
-
- assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testGood02
- *
- * @throws Exception
- */
- public static void testGood02() throws Exception {
-
- String xml = "<doc><a /> </doc>";
- String desc = " # mixed content and nothing follows";
- String xpath = "(//.)";
-
- assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testGood03
- *
- * @throws Exception
- */
- public static void testGood03() throws Exception {
-
- String xml = "<!-- --><doc><a /> </doc>";
- String desc = " # mixed content and preceding comment";
- String xpath = "(//.)";
-
- assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testGood04
- *
- * @throws Exception
- */
- public static void testGood04() throws Exception {
-
- String xml = "<?pi?><doc><a /> </doc>";
- String desc = " # mixed content and preceding PI";
- String xpath = "(//.)";
-
- assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
- }
-
- /**
- * Method testGood05
- *
- * @throws Exception
- */
- public static void testGood05() throws Exception {
-
- String xml = "<doc><a /><b /></doc>";
- String desc = " # mixed ElemContent";
- String xpath = "(//.)";
-
- assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
- }
-
- static {
- org.apache.xml.security.Init.init();
- }
+ static {
+ org.apache.xml.security.Init.init();
+ }
+
+ /**
+ * Method testBad01
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testBad01() throws Exception {
+
+ String xml = "<doc><a /> </doc><!-- -->";
+ String desc = " # mixed content and following comment";
+ String xpath = "(//.)";
+
+ assertTrue("Bad " + xml + desc + " " , containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testBad02
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testBad02() throws Exception {
+
+ String xml = "<doc><a /> </doc><?pi?>";
+ String desc = " # mixed content and following PI";
+ String xpath = "(//.)";
+
+ assertTrue("Bad " + xml + desc + " " , containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testBad03
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testBad03() throws Exception {
+
+ String xml = "<doc><a /><b /></doc><!-- -->";
+ String desc = " # mixed content and following comment";
+ String xpath = "(//.)";
+
+ assertTrue("Bad " + xml + desc + " " , containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testGood01
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testGood01() throws Exception {
+
+ String xml = "<doc><a /></doc><!-- -->";
+ String desc = " # 'clean' content and following comment";
+ String xpath = "(//.)";
+
+ assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testGood02
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testGood02() throws Exception {
+
+ String xml = "<doc><a /> </doc>";
+ String desc = " # mixed content and nothing follows";
+ String xpath = "(//.)";
+
+ assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testGood03
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testGood03() throws Exception {
+
+ String xml = "<!-- --><doc><a /> </doc>";
+ String desc = " # mixed content and preceding comment";
+ String xpath = "(//.)";
+
+ assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testGood04
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testGood04() throws Exception {
+
+ String xml = "<?pi?><doc><a /> </doc>";
+ String desc = " # mixed content and preceding PI";
+ String xpath = "(//.)";
+
+ assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Method testGood05
+ *
+ * @throws Exception
+ */
+ @org.junit.Test
+ public void testGood05() throws Exception {
+
+ String xml = "<doc><a /><b /></doc>";
+ String desc = " # mixed ElemContent";
+ String xpath = "(//.)";
+
+ assertTrue("Good " + xml + desc, containsDocumentElement(xml, xpath));
+ }
+
+ /**
+ * Process input args and execute the XPath.
+ *
+ * @param xmlString
+ * @param xpath
+ *
+ * @throws Exception
+ */
+ private static boolean containsDocumentElement(String xmlString, String xpath)
+ throws Exception {
+ DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dfactory.newDocumentBuilder();
+ Document doc = db.parse(new ByteArrayInputStream(xmlString.getBytes()));
+
+ // Set up an identity transformer to use as serializer.
+ Transformer serializer =
+ TransformerFactory.newInstance().newTransformer();
+
+ serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+
+ // Use the simple XPath API to select a nodeIterator.
+ // System.out.println("Querying DOM using " + xpath);
+ NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
+
+ // Serialize the found nodes to System.out.
+ // System.out.println("<output>");
+ Node n;
+
+ while ((n = nl.nextNode()) != null) {
+ // System.out.println("<node" + ++i + " nodeType=\"" + nodeTypeString[n.getNodeType()] + "\">");
+ // serializer.transform(new DOMSource(n), new StreamResult(System.out));
+ // System.out.println("</node" + i + ">");
+ // System.out.println();
+ if (n == doc.getDocumentElement()) {
+ return true;
+ }
+ }
+
+ // System.out.println("</output>");
+ return false;
+ }
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/interop/IAIKTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/interop/IAIKTest.java?rev=1058534&r1=1058533&r2=1058534&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/interop/IAIKTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/interop/IAIKTest.java Thu Jan 13 12:51:25 2011
@@ -68,10 +68,9 @@ public class IAIKTest extends InteropTes
ResourceResolverSpi resolver = new OfflineResolver();
boolean followManifests = false;
byte[] hmacKey = "secret".getBytes("ASCII");
- boolean verify = false;
try {
- verify = this.verifyHMAC(filename, resolver, followManifests, hmacKey);
+ this.verifyHMAC(filename, resolver, followManifests, hmacKey);
fail("HMACOutputLength Exception not caught");
} catch (RuntimeException ex) {
log.error("Verification crashed for " + filename);
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/version/VersionTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/version/VersionTest.java?rev=1058534&r1=1058533&r2=1058534&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/version/VersionTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/version/VersionTest.java Thu Jan 13 12:51:25 2011
@@ -69,10 +69,7 @@ public class VersionTest extends TestCas
double versionD = Double.parseDouble(version);
assertTrue(versionD == provider.getVersion());
- String info = "Apache Santuario XMLDSig " +
- "(DOM XMLSignatureFactory; DOM KeyInfoFactory)";
-
- assertTrue(info.equals(provider.getInfo()));
+ assertTrue(provider.getInfo().contains("Santuario"));
}
/**