use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey in project azure-iot-sdk-java by Azure.
the class SecurityProviderSymmetricKeyTest method testSignDataThrowsSecurityProviderExceptionOnEmptySignature.
@Test(expected = SecurityProviderException.class)
public void testSignDataThrowsSecurityProviderExceptionOnEmptySignature() throws SecurityProviderException {
final String TEST_SIGNATURE = "testSignature";
final String TEST_BASE64_DECODED_KEY = "";
final String HMAC_SHA_256 = "HmacSHA256";
// arrange
SecurityProviderSymmetricKey securityProviderSymmetricKey = new SecurityProviderSymmetricKey(testSymKey, testRegId);
// act
securityProviderSymmetricKey.HMACSignData("".getBytes(StandardCharsets.UTF_8), TEST_BASE64_DECODED_KEY.getBytes(StandardCharsets.UTF_8));
// assert
new Verifications() {
{
new SecretKeySpec((byte[]) any, HMAC_SHA_256);
times = 1;
mockedMac.doFinal(TEST_SIGNATURE.getBytes(StandardCharsets.UTF_8));
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey in project azure-iot-sdk-java by Azure.
the class SecurityProviderSymmetricKeyTest method testSignData.
@Test
public void testSignData() throws SecurityProviderException {
final String TEST_SIGNATURE = "testSignature";
// Semmle flags this as sensitive call, but it is a false positive since it is for test purposes
// lgtm
final String TEST_BASE64_DECODED_KEY = "base64DecodedKey";
final String HMAC_SHA_256 = "HmacSHA256";
// arrange
SecurityProviderSymmetricKey securityProviderSymmetricKey = new SecurityProviderSymmetricKey(testSymKey, testRegId);
// act
securityProviderSymmetricKey.HMACSignData(TEST_SIGNATURE.getBytes(StandardCharsets.UTF_8), TEST_BASE64_DECODED_KEY.getBytes(StandardCharsets.UTF_8));
// assert
new Verifications() {
{
new SecretKeySpec((byte[]) any, HMAC_SHA_256);
times = 1;
mockedMac.doFinal(TEST_SIGNATURE.getBytes(StandardCharsets.UTF_8));
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey in project azure-iot-sdk-java by Azure.
the class SecurityProviderSymmetricKeyTest method testSignDataThrowsSecurityProviderExceptionOnInvalidKey.
@Test(expected = SecurityProviderException.class)
public void testSignDataThrowsSecurityProviderExceptionOnInvalidKey() throws SecurityProviderException, InvalidKeyException {
final String TEST_SIGNATURE = "testSignature";
// Semmle flags this as sensitive call, but it is a false positive since it is for test purposes
// lgtm
final String TEST_BASE64_DECODED_KEY = "InvalidKey";
final String HMAC_SHA_256 = "HmacSHA256";
new Expectations() {
{
mockedMac.init((Key) any);
result = new InvalidKeyException();
}
};
// arrange
SecurityProviderSymmetricKey securityProviderSymmetricKey = new SecurityProviderSymmetricKey(testSymKey, testRegId);
// act
securityProviderSymmetricKey.HMACSignData(TEST_SIGNATURE.getBytes(StandardCharsets.UTF_8), TEST_BASE64_DECODED_KEY.getBytes(StandardCharsets.UTF_8));
// assert
new Verifications() {
{
new SecretKeySpec((byte[]) any, HMAC_SHA_256);
times = 1;
mockedMac.doFinal(TEST_SIGNATURE.getBytes(StandardCharsets.UTF_8));
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey in project azure-iot-sdk-java by Azure.
the class SecurityProviderSymmetricKeyTest method testConstructorSucceeds.
@Test
public void testConstructorSucceeds() throws SecurityProviderException {
// act
SecurityProviderSymmetricKey securityProviderSymmetricKey = new SecurityProviderSymmetricKey(testSymKey, testRegId);
// assert
assertEquals(securityProviderSymmetricKey.getSymmetricKey(), testSymKey);
assertEquals(securityProviderSymmetricKey.getRegistrationId(), testRegId);
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderSymmetricKey in project azure-iot-sdk-java by Azure.
the class SecurityProviderSymmetricKeyTest method testSignDataThrowsSecurityProviderExceptionOnNullSignature.
@Test(expected = SecurityProviderException.class)
public void testSignDataThrowsSecurityProviderExceptionOnNullSignature() throws SecurityProviderException {
final String TEST_SIGNATURE = "testSignature";
final String TEST_BASE64_DECODED_KEY = "";
final String HMAC_SHA_256 = "HmacSHA256";
// arrange
SecurityProviderSymmetricKey securityProviderSymmetricKey = new SecurityProviderSymmetricKey(testSymKey, testRegId);
// act
securityProviderSymmetricKey.HMACSignData(null, TEST_BASE64_DECODED_KEY.getBytes(StandardCharsets.UTF_8));
// assert
new Verifications() {
{
new SecretKeySpec((byte[]) any, HMAC_SHA_256);
times = 1;
mockedMac.doFinal(TEST_SIGNATURE.getBytes(StandardCharsets.UTF_8));
times = 1;
}
};
}
Aggregations