Search in sources :

Example 1 with BaseDevice

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());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 2 with BaseDevice

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);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 3 with BaseDevice

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());
}
Also used : BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 4 with BaseDevice

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);
}
Also used : SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) NonStrictExpectations(mockit.NonStrictExpectations) BaseDevice(com.microsoft.azure.sdk.iot.service.BaseDevice) Test(org.junit.Test)

Example 5 with BaseDevice

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();
}
Also used : SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) 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