summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-01-04 20:30:41 -0600
committerEndi Sukma Dewata <edewata@redhat.com>2012-01-10 20:23:11 -0600
commit58a343b58fb44c93579338b79eaf37089c753d19 (patch)
tree23b87ad663ab900d24810601dd20fdcfb6954f43
parent950766c4899741527aadb7ce785522f0fb14ec5c (diff)
downloadpki-58a343b58fb44c93579338b79eaf37089c753d19.tar.gz
pki-58a343b58fb44c93579338b79eaf37089c753d19.tar.xz
pki-58a343b58fb44c93579338b79eaf37089c753d19.zip
Added unit tests for converting null characters.
New unit tests have been added to verify bug bug 359010. Ticket #3
-rw-r--r--pki/base/util/test/com/netscape/security/util/BMPStringTest.java34
-rw-r--r--pki/base/util/test/com/netscape/security/util/IA5StringTest.java34
-rw-r--r--pki/base/util/test/com/netscape/security/util/PrintableStringTest.java35
-rw-r--r--pki/base/util/test/com/netscape/security/util/StringTestUtil.java2
-rw-r--r--pki/base/util/test/com/netscape/security/util/TeletexStringTest.java34
-rw-r--r--pki/base/util/test/com/netscape/security/util/UTF8StringTest.java34
-rw-r--r--pki/base/util/test/com/netscape/security/util/UniversalStringTest.java34
-rw-r--r--pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java15
-rw-r--r--pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java15
-rw-r--r--pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java15
-rw-r--r--pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java20
11 files changed, 272 insertions, 0 deletions
diff --git a/pki/base/util/test/com/netscape/security/util/BMPStringTest.java b/pki/base/util/test/com/netscape/security/util/BMPStringTest.java
index e1dcb6591..e82ea50ce 100644
--- a/pki/base/util/test/com/netscape/security/util/BMPStringTest.java
+++ b/pki/base/util/test/com/netscape/security/util/BMPStringTest.java
@@ -41,6 +41,40 @@ public class BMPStringTest {
}
@Test
+ public void testEncodingNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Encoding: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(tag, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = StringTestUtil.encode(tag, string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ actual = StringTestUtil.normalizeUnicode(actual);
+ System.out.println(" - norm. : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void testDecodingNullCharacters() throws Exception {
+
+ String input = StringTestUtil.NULL_CHARS;
+ byte[] data = JSSUtil.encode(tag, input);
+
+ System.out.println("Decoding: ["+StringTestUtil.toString(data)+"]");
+
+ System.out.println(" - expected: ["+StringTestUtil.toString(input.getBytes())+"]");
+
+ String output = StringTestUtil.decode(tag, data);
+ System.out.println(" - actual : ["+StringTestUtil.toString(output.getBytes())+"]");
+
+ Assert.assertEquals(input, output);
+ }
+
+ @Test
public void testEncodingPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/util/IA5StringTest.java b/pki/base/util/test/com/netscape/security/util/IA5StringTest.java
index f101e5497..a89624595 100644
--- a/pki/base/util/test/com/netscape/security/util/IA5StringTest.java
+++ b/pki/base/util/test/com/netscape/security/util/IA5StringTest.java
@@ -43,6 +43,40 @@ public class IA5StringTest {
}
@Test
+ public void testEncodingNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Encoding: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(tag, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = StringTestUtil.encode(tag, string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ actual = StringTestUtil.normalizeUnicode(actual);
+ System.out.println(" - norm. : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void testDecodingNullCharacters() throws Exception {
+
+ String input = StringTestUtil.NULL_CHARS;
+ byte[] data = JSSUtil.encode(tag, input);
+
+ System.out.println("Decoding: ["+StringTestUtil.toString(data)+"]");
+
+ System.out.println(" - expected: ["+StringTestUtil.toString(input.getBytes())+"]");
+
+ String output = StringTestUtil.decode(tag, data);
+ System.out.println(" - actual : ["+StringTestUtil.toString(output.getBytes())+"]");
+
+ Assert.assertEquals(input, output);
+ }
+
+ @Test
public void testEncodingPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java b/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java
index 4d0bc2cbf..07525648b 100644
--- a/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java
+++ b/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java
@@ -43,6 +43,41 @@ public class PrintableStringTest {
}
@Test
+ public void testEncodingNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Encoding: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ System.out.println(" - expected: IOException");
+
+ try {
+ byte[] actual = StringTestUtil.encode(tag, string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ Assert.fail();
+
+ } catch (Exception e) {
+ System.out.println(" - actual : "+e.getClass().getSimpleName());
+ Assert.assertTrue(e instanceof IOException);
+ }
+ }
+
+ @Test
+ public void testDecodingNullCharacters() throws Exception {
+
+ byte[] data = { 0x13, 0x01, 0x00 };
+ System.out.println("Decoding: ["+StringTestUtil.toString(data)+"]");
+
+ String expected = ""; // skip null chars (bug 359010)
+ System.out.println(" - expected: ["+expected+"]");
+
+ String output = StringTestUtil.decode(tag, data);
+ System.out.println(" - actual : ["+output+"]");
+
+ Assert.assertEquals(expected, output);
+ }
+
+ @Test
public void testEncodingPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/util/StringTestUtil.java b/pki/base/util/test/com/netscape/security/util/StringTestUtil.java
index 211ba5183..cb536e7b3 100644
--- a/pki/base/util/test/com/netscape/security/util/StringTestUtil.java
+++ b/pki/base/util/test/com/netscape/security/util/StringTestUtil.java
@@ -6,6 +6,8 @@ import netscape.security.util.DerValue;
public class StringTestUtil {
+ public final static String NULL_CHARS = "\u0000";
+
public final static String PRINTABLE_CHARS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 \'()+,-./:=?";
diff --git a/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java b/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java
index 7217cae40..92c61b9f9 100644
--- a/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java
+++ b/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java
@@ -43,6 +43,40 @@ public class TeletexStringTest {
}
@Test
+ public void testEncodingNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Encoding: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(tag, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = StringTestUtil.encode(tag, string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ actual = StringTestUtil.normalizeUnicode(actual);
+ System.out.println(" - norm. : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void testDecodingNullCharacters() throws Exception {
+
+ String input = StringTestUtil.NULL_CHARS;
+ byte[] data = JSSUtil.encode(tag, input);
+
+ System.out.println("Decoding: ["+StringTestUtil.toString(data)+"]");
+
+ System.out.println(" - expected: ["+StringTestUtil.toString(input.getBytes())+"]");
+
+ String output = StringTestUtil.decode(tag, data);
+ System.out.println(" - actual : ["+StringTestUtil.toString(output.getBytes())+"]");
+
+ Assert.assertEquals(input, output);
+ }
+
+ @Test
public void testEncodingPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java b/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java
index 3256a8e33..48c20c49d 100644
--- a/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java
+++ b/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java
@@ -41,6 +41,40 @@ public class UTF8StringTest {
}
@Test
+ public void testEncodingNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Encoding: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(tag, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = StringTestUtil.encode(tag, string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ actual = StringTestUtil.normalizeUnicode(actual);
+ System.out.println(" - norm. : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void testDecodingNullCharacters() throws Exception {
+
+ String input = StringTestUtil.NULL_CHARS;
+ byte[] data = JSSUtil.encode(tag, input);
+
+ System.out.println("Decoding: ["+StringTestUtil.toString(data)+"]");
+
+ System.out.println(" - expected: ["+StringTestUtil.toString(input.getBytes())+"]");
+
+ String output = StringTestUtil.decode(tag, data);
+ System.out.println(" - actual : ["+StringTestUtil.toString(output.getBytes())+"]");
+
+ Assert.assertEquals(input, output);
+ }
+
+ @Test
public void testEncodingPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java b/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java
index aceae03b3..1e2c7efe0 100644
--- a/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java
+++ b/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java
@@ -41,6 +41,40 @@ public class UniversalStringTest {
}
@Test
+ public void testEncodingNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Encoding: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(tag, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = StringTestUtil.encode(tag, string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ actual = StringTestUtil.normalizeUnicode(actual);
+ System.out.println(" - norm. : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
+ public void testDecodingNullCharacters() throws Exception {
+
+ String input = StringTestUtil.NULL_CHARS;
+ byte[] data = JSSUtil.encode(tag, input);
+
+ System.out.println("Decoding: ["+StringTestUtil.toString(data)+"]");
+
+ System.out.println(" - expected: ["+StringTestUtil.toString(input.getBytes())+"]");
+
+ String output = StringTestUtil.decode(tag, data);
+ System.out.println(" - actual : ["+StringTestUtil.toString(output.getBytes())+"]");
+
+ Assert.assertEquals(input, output);
+ }
+
+ @Test
public void testEncodingPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java b/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java
index ec8ddc51b..2abf05714 100644
--- a/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java
+++ b/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java
@@ -27,6 +27,21 @@ public class DirStrConverterTest {
}
@Test
+ public void testNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Converting: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(DerValue.tag_T61String, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
public void testPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java b/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java
index bee2b241f..1962d1bfa 100644
--- a/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java
+++ b/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java
@@ -27,6 +27,21 @@ public class GenericValueConverterTest {
}
@Test
+ public void testNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Converting: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
public void testPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java b/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java
index 682e7384f..a7361ccbf 100644
--- a/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java
+++ b/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java
@@ -27,6 +27,21 @@ public class IA5StringConverterTest {
}
@Test
+ public void testNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Converting: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string);
+ System.out.println(" - expected: "+StringTestUtil.toString(expected));
+
+ byte[] actual = ConverterTestUtil.convert(new IA5StringConverter(), string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+ @Test
public void testPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;
diff --git a/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java b/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java
index acaa5c1b8..e85d11824 100644
--- a/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java
+++ b/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java
@@ -27,6 +27,26 @@ public class PrintableConverterTest {
}
@Test
+ public void testNullCharacters() throws Exception {
+
+ String string = StringTestUtil.NULL_CHARS;
+ System.out.println("Converting: ["+StringTestUtil.toString(string.getBytes())+"]");
+
+ System.out.println(" - expected: IllegalArgumentException");
+
+ try {
+ byte[] actual = ConverterTestUtil.convert(new PrintableConverter(), string);
+ System.out.println(" - actual : "+StringTestUtil.toString(actual));
+
+ Assert.fail();
+
+ } catch (Exception e) {
+ System.out.println(" - actual : "+e.getClass().getSimpleName());
+ Assert.assertTrue(e instanceof IllegalArgumentException);
+ }
+ }
+
+ @Test
public void testPrintableCharacters() throws Exception {
String string = StringTestUtil.PRINTABLE_CHARS;