Search in sources :

Example 21 with AuthenticationMechanism

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

the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutPrimaryKeySaved.

// Tests_SRS_SERVICE_SDK_JAVA_IMPORT_EXPORT_DEVICE_34_060: [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
    ExportImportDevice device = new ExportImportDevice();
    device.setId("someDevice");
    AuthenticationMechanism authentication = new AuthenticationMechanism(AuthenticationType.SAS);
    SymmetricKey symmetricKey = new SymmetricKey();
    Deencapsulation.setField(symmetricKey, "primaryKey", null);
    Deencapsulation.setField(authentication, "symmetricKey", symmetricKey);
    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) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) Test(org.junit.Test)

Example 22 with AuthenticationMechanism

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

the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutSymmetricKeySaved.

// 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 toParserIllegalStateThrownWhenUsingSASAuthenticationWithoutSymmetricKeySaved() {
    // arrange
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SAS);
    AuthenticationMechanism authenticationMechanism = new AuthenticationMechanism(new SymmetricKey());
    Deencapsulation.setField(authenticationMechanism.getSymmetricKey(), "primaryKey", null);
    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 23 with AuthenticationMechanism

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

the class BaseDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved.

// 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 toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved() {
    // arrange
    BaseDevice device = Deencapsulation.newInstance(BaseDevice.class, new Class[] { String.class, AuthenticationType.class }, "someDevice", AuthenticationType.SELF_SIGNED);
    X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class);
    Deencapsulation.setField(thumbprint, "primaryThumbprint", null);
    AuthenticationMechanism authentication = new AuthenticationMechanism(SAMPLE_THUMBPRINT, SAMPLE_THUMBPRINT);
    Deencapsulation.setField(authentication, "thumbprint", thumbprint);
    Deencapsulation.setField(device, "authentication", authentication);
    // 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)

Example 24 with AuthenticationMechanism

use of com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism 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)

Example 25 with AuthenticationMechanism

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

the class AuthenticationMechanismTest method equalsWorks.

@Test
public void equalsWorks() {
    // arrange
    AuthenticationMechanism auth1 = new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY);
    AuthenticationMechanism auth2 = new AuthenticationMechanism(AuthenticationType.SELF_SIGNED);
    AuthenticationMechanism auth3 = new AuthenticationMechanism(AuthenticationType.SAS);
    AuthenticationMechanism auth4 = new AuthenticationMechanism("0000000000000000000000000000000000000000", "0000000000000000000000000000000000000000");
    AuthenticationMechanism auth5 = new AuthenticationMechanism(new SymmetricKey());
    AuthenticationMechanism auth6 = new AuthenticationMechanism(new SymmetricKey());
    AuthenticationMechanism auth7 = new AuthenticationMechanism(AuthenticationType.CERTIFICATE_AUTHORITY);
    // assert
    assertNotEquals(auth1, auth2);
    assertNotEquals(auth1, auth3);
    assertNotEquals(auth1, auth4);
    assertNotEquals(auth1, auth5);
    assertNotEquals(auth1, auth6);
    assertEquals(auth1, auth7);
    assertNotEquals(auth2, auth3);
    assertNotEquals(auth2, auth4);
    assertNotEquals(auth2, auth5);
    assertNotEquals(auth2, auth6);
    assertNotEquals(auth3, auth4);
    assertNotEquals(auth3, auth5);
    assertNotEquals(auth3, auth6);
    assertNotEquals(auth4, auth5);
    assertNotEquals(auth4, auth6);
    assertNotEquals(auth5, auth6);
    assertNotEquals(auth1, "not an authentication object");
}
Also used : AuthenticationMechanism(com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism) SymmetricKey(com.microsoft.azure.sdk.iot.service.auth.SymmetricKey) 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