use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubX509HardwareIotHubAuthenticationProviderTest method getSSLContextThrowsIOExceptionIfExceptionEncountered.
// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_004: [If the security provider throws a SecurityProviderException while generating an SSLContext, this function shall throw an IOException.]
@Test(expected = IOException.class)
public void getSSLContextThrowsIOExceptionIfExceptionEncountered() throws SecurityProviderException, IOException, TransportException {
// arrange
IotHubAuthenticationProvider authentication = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
new NonStrictExpectations() {
{
mockSecurityProviderX509.getSSLContext();
result = new SecurityProviderException("");
}
};
// act
authentication.getSSLContext();
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubX509HardwareIotHubAuthenticationProviderTest method setPathToCertificateThrows.
// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_006: [This function shall throw an UnsupportedOperationException.]
@Test(expected = UnsupportedOperationException.class)
public void setPathToCertificateThrows() {
// arrange
IotHubAuthenticationProvider auth = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
// act
auth.setPathToIotHubTrustedCert("any string");
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method getSSLContextSuccess.
// Codes_SRS_AUTHENTICATIONPROVIDER_34_011: [This function shall return the generated IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws IOException {
// arrange
IotHubAuthenticationProvider sasAuth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(IotHubSSLContext.class);
result = mockedIotHubSSLContext;
Deencapsulation.invoke(mockedIotHubSSLContext, "getSSLContext");
result = mockedSSLContext;
}
};
// act
SSLContext actualSSLContext = sasAuth.getSSLContext();
// assert
assertEquals(mockedSSLContext, actualSSLContext);
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method gettersWork.
// Tests_SRS_AUTHENTICATIONPROVIDER_34_002: [This function shall return the saved hostname.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_003: [This function shall return the saved gatewayHostname.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_004: [This function shall return the saved deviceId.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_005: [This function shall return the saved moduleId.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_008: [This function shall return the saved iotHubTrustedCert.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_009: [This function shall return the saved pathToIotHubTrustedCert.]
@Test
public void gettersWork() {
// arrange
String expectedCert = "some cert";
String expectedCertPath = "some/path";
IotHubAuthenticationProvider iotHubAuthenticationProvider = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
Deencapsulation.setField(iotHubAuthenticationProvider, "iotHubTrustedCert", expectedCert);
Deencapsulation.setField(iotHubAuthenticationProvider, "pathToIotHubTrustedCert", expectedCertPath);
// act
String actualHostName = iotHubAuthenticationProvider.getHostname();
String actualGatewayHostname = iotHubAuthenticationProvider.getGatewayHostname();
String actualDeviceId = iotHubAuthenticationProvider.getDeviceId();
String actualModuleId = iotHubAuthenticationProvider.getModuleId();
String actualCert = iotHubAuthenticationProvider.getIotHubTrustedCert();
String actualCertPath = iotHubAuthenticationProvider.getPathToIotHubTrustedCert();
// assert
assertEquals(expectedHostname, actualHostName);
assertEquals(expectedGatewayHostname, actualGatewayHostname);
assertEquals(expectedDeviceId, actualDeviceId);
assertEquals(expectedModuleId, actualModuleId);
assertEquals(expectedCert, actualCert);
assertEquals(expectedCertPath, actualCertPath);
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method generateSSLContextGeneratesDefaultIotHubSSLContext.
// Tests_SRS_AUTHENTICATIONPROVIDER_34_021: [If this has no saved iotHubTrustedCert or path, This function shall create and save a new default IotHubSSLContext object.]
@Test
public void generateSSLContextGeneratesDefaultIotHubSSLContext() {
// arrange
IotHubAuthenticationProvider auth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
// act
Deencapsulation.invoke(auth, "generateSSLContext");
// assert
new Verifications() {
{
Deencapsulation.newInstance(IotHubSSLContext.class);
times = 1;
}
};
}
Aggregations