Search in sources :

Example 16 with BaseDevice

use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.

the class BaseDeviceTest method deviceConstructorWithSelfSignedGeneratesKeysCorrectly.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_013: [If the provided authenticationType is self signed, a thumbprint shall be generated but no symmetric key shall be generated]
@Test
public void deviceConstructorWithSelfSignedGeneratesKeysCorrectly() {
    // act
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SELF_SIGNED);
    // assert
    assertNotNull(device.getPrimaryThumbprint());
    assertNotNull(device.getSecondaryThumbprint());
    assertNull(device.getSymmetricKey());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 17 with BaseDevice

use of com.microsoft.azure.sdk.iot.service.BaseDevice in project azure-iot-sdk-java by Azure.

the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutThumbprintSaved.

// Tests_SRS_SERVICE_SDK_JAVA_BASEDEVICE_34_020: [If this device uses self signed authentication, but does not have a primary and secondary thumbprint saved, an IllegalStateException shall be thrown.]
@Test(expected = IllegalStateException.class)
public void toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutThumbprintSaved() {
    // arrange
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SELF_SIGNED);
    AuthenticationMechanism authenticationMechanism = new AuthenticationMechanism(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT);
    X509Thumbprint thumbprint = Deencapsulation.getField(authenticationMechanism, "thumbprint");
    Deencapsulation.setField(thumbprint, "primaryThumbprint", null);
    Deencapsulation.setField(device, "authentication", authenticationMechanism);
    // act
    reflectivelyInvokeToDeviceParser(device);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Aggregations

BaseDevice (com.microsoft.azure.sdk.iot.service.BaseDevice)17 Test (org.junit.Test)17 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)5 AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)4 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)3 DeviceConnectionState (com.microsoft.azure.sdk.iot.service.DeviceConnectionState)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 NonStrictExpectations (mockit.NonStrictExpectations)1