use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method deviceConstructorWithCertificateAuthorityGeneratesKeysCorrectly.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_011: [If the provided authenticationType is certificate authority, no symmetric key shall be generated and no thumbprint shall be generated]
@Test
public void deviceConstructorWithCertificateAuthorityGeneratesKeysCorrectly() {
// act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.CERTIFICATE_AUTHORITY);
// assert
assertNull(device.getPrimaryThumbprint());
assertNull(device.getSecondaryThumbprint());
assertNull(device.getSymmetricKey());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutPrimaryKeySaved.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_019: [If this device uses sas authentication, but does not have a primary and secondary symmetric key saved, an IllegalStateException shall be thrown.]
@Test(expected = IllegalStateException.class)
public void toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutPrimaryKeySaved() {
// arrange
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SAS);
SymmetricKey symmetricKey = new SymmetricKey();
Deencapsulation.setField(symmetricKey, "primaryKey", null);
AuthenticationMechanism authenticationMechanism = new AuthenticationMechanism(symmetricKey);
Deencapsulation.setField(device, "authentication", authenticationMechanism);
// act
reflectivelyInvokeToDeviceParser(device);
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method conversionFromDeviceParserWithSelfSignedAuthentication.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_014: [This constructor shall create a new Device object using the values within the provided parser.]
@Test
public void conversionFromDeviceParserWithSelfSignedAuthentication() {
// arrange
DeviceParser parserSelf = new DeviceParser();
parserSelf.setAuthenticationParser(Deencapsulation.newInstance(AuthenticationParser.class));
parserSelf.getAuthenticationParser().setType(AuthenticationTypeParser.SELF_SIGNED);
parserSelf.getAuthenticationParser().setThumbprint(new X509ThumbprintParser(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT));
parserSelf.setDeviceId("deviceSelf");
// act
BaseDevice deviceSelf = reflectivelyInvokeDeviceParserConstructor(parserSelf);
// assert
assertNull(deviceSelf.getSymmetricKey());
assertNotNull(deviceSelf.getPrimaryThumbprint());
assertNotNull(deviceSelf.getSecondaryThumbprint());
assertEquals(AuthenticationType.SELF_SIGNED, deviceSelf.getAuthenticationType());
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method constructor_create_symmetrickey.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_12_005: [If the input symmetric key is empty, the constructor shall create
// a new SymmetricKey instance using AES encryption and store it into a member variable]
@Test
public void constructor_create_symmetrickey() throws NoSuchAlgorithmException {
// Arrange
String encryptionMethod = "AES";
String deviceId = "xxx-device";
new NonStrictExpectations() {
{
SymmetricKey symmetricKey = new SymmetricKey();
KeyGenerator.getInstance(encryptionMethod);
}
};
// Act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, SymmetricKey.class);
// Assert
assertNotEquals(device.getSymmetricKey(), null);
}
use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.
the class BaseDeviceTest method device_get_all_properties.
// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_12_001: [The BaseDevice class shall have the following properties: deviceId, Etag,
// SymmetricKey, ConnectionState, ConnectionStateUpdatedTime, LastActivityTime, symmetricKey, thumbprint, authentication]
@Test(expected = IllegalArgumentException.class)
public void device_get_all_properties() {
// Arrange
String deviceId = "xxx-device";
SymmetricKey expectedSymmetricKey = new SymmetricKey();
String expectedPrimaryThumbprint = "0000000000000000000000000000000000000000";
String expectedSecondaryThumbprint = "1111111111111111111111111111111111111111";
// Act
BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, deviceId, null, null);
device.setSymmetricKey(expectedSymmetricKey);
assertEquals(expectedSymmetricKey, device.getSymmetricKey());
device.setThumbprintFinal(expectedPrimaryThumbprint, expectedSecondaryThumbprint);
assertEquals(expectedPrimaryThumbprint, device.getPrimaryThumbprint());
assertEquals(expectedSecondaryThumbprint, device.getSecondaryThumbprint());
device.getPrimaryThumbprint();
device.getSecondaryThumbprint();
device.getDeviceId();
device.getGenerationId();
device.getPrimaryKey();
device.getSecondaryKey();
device.geteTag();
device.getConnectionState();
device.getConnectionStateUpdatedTime();
device.getLastActivityTime();
device.getCloudToDeviceMessageCount();
}
Aggregations