Search in sources :

Example 16 with AuthenticationMechanism

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

the class AuthenticationMechanismTest method constructorThrowsIllegalArgumentExceptionForNullSymmetricKey.

// Tests_SRS_AUTHENTICATION_MECHANISM_34_012: [This constructor shall throw an IllegalArgumentException if the provided symmetricKey is null.]
@Test(expected = IllegalArgumentException.class)
public void constructorThrowsIllegalArgumentExceptionForNullSymmetricKey() {
    // arrange
    SymmetricKey key = null;
    // act
    new AuthenticationMechanism(key);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) Test(org.junit.Test)

Example 17 with AuthenticationMechanism

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

the class AuthenticationMechanismTest method testSelfSignedAuthenticationTypeConstructor.

// Tests_SRS_AUTHENTICATION_MECHANISM_34_023: [If the provided authentication type is self signed, a thumbprint will be generated, but no symmetric key will be generated.]
@Test
public void testSelfSignedAuthenticationTypeConstructor() {
    // act
    AuthenticationMechanism selfSignedAuth = new AuthenticationMechanism(AuthenticationType.SELF_SIGNED);
    // assert
    assertNotNull(selfSignedAuth.getPrimaryThumbprint());
    assertNotNull(selfSignedAuth.getSecondaryThumbprint());
    assertNull(selfSignedAuth.getSymmetricKey());
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) Test(org.junit.Test)

Example 18 with AuthenticationMechanism

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

the class AuthenticationMechanismTest method testThumbprintConstructor.

// Tests_SRS_AUTHENTICATION_MECHANISM_34_004: [This constructor shall save the provided thumbprint to the returned instance.]
@Test
public void testThumbprintConstructor() {
    // act
    AuthenticationMechanism authenticationSelfSigned = new AuthenticationMechanism(expectedPrimaryThumbprint, expectedSecondaryThumbprint);
    // assert
    assertEquals(expectedPrimaryThumbprint, authenticationSelfSigned.getPrimaryThumbprint());
    assertEquals(expectedSecondaryThumbprint, authenticationSelfSigned.getSecondaryThumbprint());
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) Test(org.junit.Test)

Example 19 with AuthenticationMechanism

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

the class ExportImportTests method createListofDevices.

private static List<ExportImportDevice> createListofDevices() {
    // Creating the list of devices to be created, then deleted
    Integer numberOfDevices = 10;
    List<ExportImportDevice> devicesForImport = new ArrayList<>(numberOfDevices);
    for (int i = 0; i < numberOfDevices; i++) {
        String deviceId = "java-bulk-test-" + UUID.randomUUID().toString();
        Device device = Device.createFromId(deviceId, null, null);
        AuthenticationMechanism authentication = new AuthenticationMechanism(device.getSymmetricKey());
        ExportImportDevice deviceToAdd = new ExportImportDevice();
        deviceToAdd.setId(deviceId);
        deviceToAdd.setAuthentication(authentication);
        deviceToAdd.setStatus(DeviceStatus.Enabled);
        TwinCollection tags = new TwinCollection();
        tags.putFinal("test01", "firstvalue");
        deviceToAdd.setTags(tags);
        devicesForImport.add(deviceToAdd);
    }
    return devicesForImport;
}
Also used : TwinCollection(com.microsoft.azure.sdk.iot.deps.twin.TwinCollection) Device(com.microsoft.azure.sdk.iot.service.Device) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) ArrayList(java.util.ArrayList)

Example 20 with AuthenticationMechanism

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

the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutThumbprintSaved.

// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_061: [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
    ExportImportDevice device = new ExportImportDevice();
    device.setId("someDevice");
    AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SELF_SIGNED);
    Deencapsulation.setField(authentication, "thumbprint", null);
    device.setAuthentication(authentication);
    // act
    reflectivelyInvokeToExportImportDeviceParser(device);
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) ExportImportDevice(com.microsoft.azure.sdk.iot.service.ExportImportDevice) Test(org.junit.Test)

Aggregations

AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)29 Test (org.junit.Test)25 ExportImportDevice (com.microsoft.azure.sdk.iot.service.ExportImportDevice)8 SymmetricKey (com.microsoft.azure.sdk.iot.service.auth.SymmetricKey)5 BaseDevice (com.microsoft.azure.sdk.iot.service.BaseDevice)4 X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)3 TwinCollection (com.microsoft.azure.sdk.iot.deps.twin.TwinCollection)1 Device (com.microsoft.azure.sdk.iot.service.Device)1 DeviceStatus (com.microsoft.azure.sdk.iot.service.DeviceStatus)1 ImportMode (com.microsoft.azure.sdk.iot.service.ImportMode)1 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1