use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method setPathToCertificateWorks.
// Tests_SRS_AUTHENTICATIONPROVIDER_34_059: [This function shall save the provided pathToCertificate.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_030: [If the provided pathToCertificate is different than the saved path, this function shall set sslContextNeedsRenewal to true.]
@Test
public void setPathToCertificateWorks() throws IOException {
// arrange
IotHubAuthenticationProvider auth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
String pathToCert = "somePath";
// act
auth.setPathToIotHubTrustedCert(pathToCert);
// assert
String actualPathToCert = auth.getPathToIotHubTrustedCert();
assertEquals(pathToCert, actualPathToCert);
boolean sslContextNeedsRenewal = Deencapsulation.getField(auth, "sslContextNeedsUpdate");
assertTrue(sslContextNeedsRenewal);
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method getSSLContextWrapsExceptions.
// Codes_SRS_AUTHENTICATIONPROVIDER_34_012: [If a CertificateException, NoSuchAlgorithmException, KeyManagementException, or KeyStoreException is thrown during this function, this function shall throw an IOException.]
// Codes_SRS_AUTHENTICATIONPROVIDER_34_010: [If this object's ssl context has not been generated yet or if it needs to be re-generated, this function shall regenerate the ssl context.]
@Test(expected = IOException.class)
public void getSSLContextWrapsExceptions() throws IOException {
// arrange
IotHubAuthenticationProvider sasAuth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
new NonStrictExpectations() {
{
Deencapsulation.newInstance(IotHubSSLContext.class);
result = new CertificateException();
}
};
// act
sasAuth.getSSLContext();
}
use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method generateSSLContextUsesSavedTrustedCert.
// Tests_SRS_AUTHENTICATIONPROVIDER_34_019: [If this has a saved iotHubTrustedCert, this function shall generate a new IotHubSSLContext object with that saved cert as the trusted cert.]
@Test
public void generateSSLContextUsesSavedTrustedCert() {
// arrange
final String expectedCert = "someTrustedCert";
IotHubAuthenticationProvider auth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
auth.setIotHubTrustedCert(expectedCert);
// act
Deencapsulation.invoke(auth, "generateSSLContext");
// assert
new Verifications() {
{
Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { String.class, boolean.class }, expectedCert, false);
times = 1;
}
};
}
Aggregations