Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add randomreseed to internal testsuite, new utils unit tests

  • Loading branch information...
commit a57110c7aedcee9188855016d50bd565896d909a 1 parent cb4514c
Stefan Wold authored
3  src/main/java/org/unitedid/yhsm/utility/Utils.java
@@ -18,7 +18,6 @@
18 18
19 19 package org.unitedid.yhsm.utility;
20 20
21   -import com.sun.corba.se.spi.monitoring.StatisticMonitoredAttribute;
22 21 import org.unitedid.yhsm.internal.Defines;
23 22 import org.unitedid.yhsm.internal.YubiHSMErrorException;
24 23 import org.unitedid.yhsm.internal.YubiHSMInputException;
@@ -182,7 +181,7 @@ public static String validateCmdResponseString(String name, String got, String e
182 181 (byte)((value >> 24) & 0xff),
183 182 (byte)((value >> 16) & 0xff),
184 183 (byte)((value >> 8 ) & 0xff),
185   - (byte)((value >> 0) & 0xff),
  184 + (byte)(value & 0xff),
186 185 };
187 186 }
188 187
3  src/test/java/org/unitedid/yhsm/internal/InternalTestSuite.java
@@ -33,7 +33,8 @@
33 33 LoadTemporaryKeyCmdTest.class,
34 34 OathHOTPCmdTest.class,
35 35 NonceGetCmdTest.class,
36   - RandomCmdTest.class})
  36 + RandomCmdTest.class,
  37 + RandomReseedCmdTest.class})
37 38
38 39 public class InternalTestSuite {
39 40
48 src/test/java/org/unitedid/yhsm/utility/UtilsTest.java
@@ -95,4 +95,52 @@ public void testNonceInputException() throws YubiHSMInputException {
95 95 String data = "1234567";
96 96 Utils.validateNonce(data.getBytes(), false);
97 97 }
  98 +
  99 + @Test
  100 + public void testLeShortToByteArray() {
  101 + byte[] expected = {0x00, 0x20};
  102 + assertArrayEquals(expected, Utils.leShortToByteArray((short) 8192));
  103 + }
  104 +
  105 + @Test
  106 + public void testLeBAToBeShort() {
  107 + byte[] data = {0x00, 0x20};
  108 + assertEquals(8192, Utils.leBAToBeShort(data));
  109 + }
  110 +
  111 + @Test
  112 + public void testHexToByteArrayIncompleteHex() throws YubiHSMInputException {
  113 + thrown.expect(YubiHSMInputException.class);
  114 + thrown.expectMessage("Invalid hex string (aac)!");
  115 + Utils.hexToByteArray("aac");
  116 + }
  117 +
  118 + @Test
  119 + public void testHexToByteArrayInvalidHexValue() throws YubiHSMInputException {
  120 + thrown.expect(YubiHSMInputException.class);
  121 + thrown.expectMessage("Invalid hex string (aaxx)!");
  122 + Utils.hexToByteArray("aaxx");
  123 + }
  124 +
  125 + @Test
  126 + public void testValidateByteArrayMaxLength() throws YubiHSMInputException {
  127 + thrown.expect(YubiHSMInputException.class);
  128 + thrown.expectMessage("Argument 'test' is too long, expected max 10 but got 12");
  129 + String data = "Test";
  130 + Utils.validateByteArray("test", data.getBytes(), 10, 0, 12);
  131 + }
  132 +
  133 + @Test
  134 + public void testValidateByteArrayExactLength() throws YubiHSMInputException {
  135 + thrown.expect(YubiHSMInputException.class);
  136 + thrown.expectMessage("Wrong size of argument 'test', expected 10 but got 12");
  137 + String data = "Test";
  138 + Utils.validateByteArray("test", data.getBytes(), 0, 10, 12);
  139 + }
  140 +
  141 + @Test
  142 + public void testLongToByteArray() {
  143 + byte[] expected = {0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00};
  144 + assertArrayEquals(expected, Utils.longToByteArray((long) 8192));
  145 + }
98 146 }

0 comments on commit a57110c

Please sign in to comment.
Something went wrong with that request. Please try again.