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