Browse files

Add randomreseed to internal testsuite, new utils unit tests

  • Loading branch information...
1 parent cb4514c commit a57110c7aedcee9188855016d50bd565896d909a @Ratler committed Aug 10, 2011
View
3 src/main/java/org/unitedid/yhsm/utility/Utils.java
@@ -18,7 +18,6 @@
package org.unitedid.yhsm.utility;
-import com.sun.corba.se.spi.monitoring.StatisticMonitoredAttribute;
import org.unitedid.yhsm.internal.Defines;
import org.unitedid.yhsm.internal.YubiHSMErrorException;
import org.unitedid.yhsm.internal.YubiHSMInputException;
@@ -182,7 +181,7 @@ public static String validateCmdResponseString(String name, String got, String e
(byte)((value >> 24) & 0xff),
(byte)((value >> 16) & 0xff),
(byte)((value >> 8 ) & 0xff),
- (byte)((value >> 0) & 0xff),
+ (byte)(value & 0xff),
};
}
View
3 src/test/java/org/unitedid/yhsm/internal/InternalTestSuite.java
@@ -33,7 +33,8 @@
LoadTemporaryKeyCmdTest.class,
OathHOTPCmdTest.class,
NonceGetCmdTest.class,
- RandomCmdTest.class})
+ RandomCmdTest.class,
+ RandomReseedCmdTest.class})
public class InternalTestSuite {
View
48 src/test/java/org/unitedid/yhsm/utility/UtilsTest.java
@@ -95,4 +95,52 @@ public void testNonceInputException() throws YubiHSMInputException {
String data = "1234567";
Utils.validateNonce(data.getBytes(), false);
}
+
+ @Test
+ public void testLeShortToByteArray() {
+ byte[] expected = {0x00, 0x20};
+ assertArrayEquals(expected, Utils.leShortToByteArray((short) 8192));
+ }
+
+ @Test
+ public void testLeBAToBeShort() {
+ byte[] data = {0x00, 0x20};
+ assertEquals(8192, Utils.leBAToBeShort(data));
+ }
+
+ @Test
+ public void testHexToByteArrayIncompleteHex() throws YubiHSMInputException {
+ thrown.expect(YubiHSMInputException.class);
+ thrown.expectMessage("Invalid hex string (aac)!");
+ Utils.hexToByteArray("aac");
+ }
+
+ @Test
+ public void testHexToByteArrayInvalidHexValue() throws YubiHSMInputException {
+ thrown.expect(YubiHSMInputException.class);
+ thrown.expectMessage("Invalid hex string (aaxx)!");
+ Utils.hexToByteArray("aaxx");
+ }
+
+ @Test
+ public void testValidateByteArrayMaxLength() throws YubiHSMInputException {
+ thrown.expect(YubiHSMInputException.class);
+ thrown.expectMessage("Argument 'test' is too long, expected max 10 but got 12");
+ String data = "Test";
+ Utils.validateByteArray("test", data.getBytes(), 10, 0, 12);
+ }
+
+ @Test
+ public void testValidateByteArrayExactLength() throws YubiHSMInputException {
+ thrown.expect(YubiHSMInputException.class);
+ thrown.expectMessage("Wrong size of argument 'test', expected 10 but got 12");
+ String data = "Test";
+ Utils.validateByteArray("test", data.getBytes(), 0, 10, 12);
+ }
+
+ @Test
+ public void testLongToByteArray() {
+ byte[] expected = {0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00};
+ assertArrayEquals(expected, Utils.longToByteArray((long) 8192));
+ }
}

0 comments on commit a57110c

Please sign in to comment.