Search in sources :

Example 1 with X509Thumbprint

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

the class ExportImportDeviceTest method toParserIllegalStateThrownWhenUsingSelfSignedAuthenticationWithoutPrimaryThumbprintSaved.

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

Example 2 with X509Thumbprint

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

the class X509ThumbprintTest method emptyConstructorGeneratesThumbprints.

// Tests_SRS_X509THUMBPRINT_34_011: [This constructor shall generate a random primary and secondary thumbprint.]
@Test
public void emptyConstructorGeneratesThumbprints() {
    // act
    X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class, new Class[] {});
    // assert
    assertNotNull(Deencapsulation.getField(thumbprint, "primaryThumbprint"));
    assertNotNull(Deencapsulation.getField(thumbprint, "secondaryThumbprint"));
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) Test(org.junit.Test)

Example 3 with X509Thumbprint

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

the class X509ThumbprintTest method illegalArgumentExceptionThrownBySetSecondaryThumbprintForIllegalThumbprint.

// Tests_SRS_X509THUMBPRINT_34_008: [If the provided thumbprint string is not the proper format, an IllegalArgumentException shall be thrown.]
@Test(expected = IllegalArgumentException.class)
public void illegalArgumentExceptionThrownBySetSecondaryThumbprintForIllegalThumbprint() {
    // arrange
    X509Thumbprint thumbprint = createTestThumbprint(null, null);
    // act
    Deencapsulation.invoke(thumbprint, "setSecondaryThumbprint", new Class[] { String.class }, "");
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) Test(org.junit.Test)

Example 4 with X509Thumbprint

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

the class X509ThumbprintTest method equalsWorks.

@Test
public void equalsWorks() {
    // Arrange
    X509Thumbprint s1 = createTestThumbprintWithInvalidThumbprintValues(null, null);
    X509Thumbprint s2 = createTestThumbprintWithInvalidThumbprintValues("", null);
    X509Thumbprint s3 = createTestThumbprintWithInvalidThumbprintValues(null, "");
    X509Thumbprint s4 = createTestThumbprintWithInvalidThumbprintValues("", "");
    X509Thumbprint s5 = createTestThumbprintWithInvalidThumbprintValues("", "secondaryThumbprint");
    X509Thumbprint s6 = createTestThumbprintWithInvalidThumbprintValues("primaryThumbprint", "secondaryThumbprint2");
    X509Thumbprint s7 = createTestThumbprintWithInvalidThumbprintValues("primaryThumbprint2", "secondaryThumbprint");
    X509Thumbprint s8 = createTestThumbprintWithInvalidThumbprintValues("primaryThumbprint", "secondaryThumbprint");
    X509Thumbprint s9 = createTestThumbprintWithInvalidThumbprintValues("primaryThumbprint", "secondaryThumbprint");
    // Assert
    assertNotEquals(s1, s2);
    assertNotEquals(s1, s3);
    assertNotEquals(s1, s4);
    assertNotEquals(s1, s5);
    assertNotEquals(s1, s6);
    assertNotEquals(s1, s7);
    assertNotEquals(s1, s8);
    assertNotEquals(s2, s3);
    assertNotEquals(s2, s4);
    assertNotEquals(s2, s5);
    assertNotEquals(s2, s6);
    assertNotEquals(s2, s7);
    assertNotEquals(s2, s8);
    assertNotEquals(s3, s4);
    assertNotEquals(s3, s5);
    assertNotEquals(s3, s6);
    assertNotEquals(s3, s7);
    assertNotEquals(s3, s8);
    assertNotEquals(s4, s5);
    assertNotEquals(s4, s6);
    assertNotEquals(s4, s7);
    assertNotEquals(s4, s8);
    assertNotEquals(s5, s6);
    assertNotEquals(s5, s7);
    assertNotEquals(s5, s8);
    assertNotEquals(s6, s7);
    assertNotEquals(s6, s8);
    assertNotEquals(s7, s8);
    assertEquals(s8, s9);
    assertNotEquals(s1, "not a thumbprint object");
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) Test(org.junit.Test)

Example 5 with X509Thumbprint

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

the class X509ThumbprintTest method illegalArgumentExceptionThrownBySetPrimaryThumbprintForIllegalThumbprint.

// Tests_SRS_X509THUMBPRINT_34_007: [If the provided thumbprint string is not the proper format, an IllegalArgumentException shall be thrown.]
@Test(expected = IllegalArgumentException.class)
public void illegalArgumentExceptionThrownBySetPrimaryThumbprintForIllegalThumbprint() {
    // arrange
    X509Thumbprint thumbprint = createTestThumbprint(null, null);
    // act
    Deencapsulation.invoke(thumbprint, "setPrimaryThumbprint", new Class[] { String.class }, "");
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) Test(org.junit.Test)

Aggregations

X509Thumbprint (com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)11 Test (org.junit.Test)9 AuthenticationMechanism (com.microsoft.azure.sdk.iot.service.auth.AuthenticationMechanism)3 BaseDevice (com.microsoft.azure.sdk.iot.service.BaseDevice)2 ExportImportDevice (com.microsoft.azure.sdk.iot.service.ExportImportDevice)1 Before (org.junit.Before)1