aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-12-25 22:58:09 -0600
committerKenny Root <kenny@the-b.org>2015-12-25 23:03:14 -0600
commit93e998a377cf6bd4098ec38e99d6c191e274c3a9 (patch)
treebfeea240b5978db72e9aed01c4f705ba79a897b2
parentd60c23560bd0464b2f8862f43711781eb45eac49 (diff)
downloadsshlib-93e998a377cf6bd4098ec38e99d6c191e274c3a9.tar.gz
sshlib-93e998a377cf6bd4098ec38e99d6c191e274c3a9.tar.bz2
sshlib-93e998a377cf6bd4098ec38e99d6c191e274c3a9.zip
Add unit tests for readOid
-rw-r--r--sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java b/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java
index cabadce..6a97218 100644
--- a/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java
+++ b/sshlib/src/test/java/com/trilead/ssh2/crypto/SimpleDERReaderTest.java
@@ -112,4 +112,76 @@ public class SimpleDERReaderTest {
} catch (IOException expected) {
}
}
+
+ @Test
+ public void readOid_InvalidLength() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x02, (byte) 0x80, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ try {
+ reader.readOid();
+ } catch (IOException expected) {
+ }
+ }
+
+ @Test
+ public void readOid_TooShort() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x02, (byte) 0x00
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ try {
+ reader.readOid();
+ } catch (IOException expected) {
+ }
+ }
+
+ @Test
+ public void readOid_NotOidValue() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x02, (byte) 0x04, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ try {
+ reader.readOid();
+ } catch (IOException expected) {
+ }
+ }
+
+ @Test
+ public void readOid_Valid1() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x06, (byte) 0x01, (byte) 0x28
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals("1.0", reader.readOid());
+ }
+
+ @Test
+ public void readOid_Valid1Prefix() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x06, (byte) 0x09, (byte) 0x2a, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xf7, (byte) 0x0d, (byte) 0x01, (byte) 0x01, (byte) 0x0b
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals("1.2.840.113549.1.1.11", reader.readOid());
+ }
+
+ @Test
+ public void readOid_Valid0Prefix() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x06, (byte) 0x0A, (byte) 0x09, (byte) 0x92, (byte) 0x26, (byte) 0x89, (byte) 0x93, (byte) 0xF2, (byte) 0x2C, (byte) 0x64, (byte) 0x04, (byte) 0x0D
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals("0.9.2342.19200300.100.4.13", reader.readOid());
+ }
+
+ @Test
+ public void readOid_Valid2Prefix() throws Exception {
+ byte[] vector = new byte[]{
+ (byte) 0x06, (byte) 0x03, (byte) 0x55, (byte) 0x1D, (byte) 0x0E
+ };
+ SimpleDERReader reader = new SimpleDERReader(vector);
+ assertEquals("2.5.29.14", reader.readOid());
+ }
} \ No newline at end of file