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[] {}));
}
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);
}
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);
}
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");
}
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;
}
Aggregations