Search in sources :

Example 6 with X509Thumbprint

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

the class X509ThumbprintTest method gettersAndSettersWork.

// Tests_SRS_X509THUMBPRINT_34_001: [The function shall return the primary thumbprint value of this.]
// Tests_SRS_X509THUMBPRINT_34_002: [The function shall return the secondary thumbprint value of this.]
// Tests_SRS_X509THUMBPRINT_34_003: [The function shall set the primary thumbprint to the given value.]
// Tests_SRS_X509THUMBPRINT_34_004: [The function shall set the secondary thumbprint to the given value.]
@Test
public void gettersAndSettersWork() {
    // arrange
    X509Thumbprint thumbprint = createTestThumbprint(expectedPrimaryThumbprint.toLowerCase(), expectedSecondaryThumbprint.toLowerCase());
    // act
    Deencapsulation.invoke(thumbprint, "setPrimaryThumbprint", new Class[] { String.class }, expectedPrimaryThumbprint);
    Deencapsulation.invoke(thumbprint, "setSecondaryThumbprint", new Class[] { String.class }, expectedSecondaryThumbprint);
    // assert
    assertEquals(expectedPrimaryThumbprint, Deencapsulation.invoke(thumbprint, "getPrimaryThumbprint", new Class[] {}));
    assertEquals(expectedSecondaryThumbprint, Deencapsulation.invoke(thumbprint, "getSecondaryThumbprint", new Class[] {}));
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) Test(org.junit.Test)

Example 7 with X509Thumbprint

use of com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint 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 8 with X509Thumbprint

use of com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint 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 9 with X509Thumbprint

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

the class X509ThumbprintTest method setUp.

@Before
public void setUp() {
    X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class);
    expectedPrimaryThumbprint = Deencapsulation.invoke(thumbprint, "getPrimaryThumbprint");
    expectedSecondaryThumbprint = Deencapsulation.invoke(thumbprint, "getSecondaryThumbprint");
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint) Before(org.junit.Before)

Example 10 with X509Thumbprint

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

the class X509ThumbprintTest method createTestThumbprintWithInvalidThumbprintValues.

/**
 * Creates a thumbprint using the empty constructor for X509Thumbprint and then sets the primary and secondary thumbprints using reflection.
 * This avoids some checks in the constructor and allows for creating thumbprints in illegal states.
 * @param primaryThumbprint the primary thumbprint value to set
 * @param secondaryThumbprint the secondary thumbprint value to set
 * @return the created thumbprint object
 */
private X509Thumbprint createTestThumbprintWithInvalidThumbprintValues(String primaryThumbprint, String secondaryThumbprint) {
    X509Thumbprint thumbprint = Deencapsulation.newInstance(X509Thumbprint.class, new Class[] { String.class, String.class }, expectedPrimaryThumbprint, expectedSecondaryThumbprint);
    Deencapsulation.setField(thumbprint, "primaryThumbprint", primaryThumbprint);
    Deencapsulation.setField(thumbprint, "secondaryThumbprint", secondaryThumbprint);
    return thumbprint;
}
Also used : X509Thumbprint(com.microsoft.azure.sdk.iot.service.auth.X509Thumbprint)

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