Search in sources :

Example 16 with IotHubAuthenticationProvider

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);
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) Test(org.junit.Test)

Example 17 with IotHubAuthenticationProvider

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();
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) CertificateException(java.security.cert.CertificateException) Test(org.junit.Test)

Example 18 with IotHubAuthenticationProvider

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;
        }
    };
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) Test(org.junit.Test)

Aggregations

IotHubAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider)18 Test (org.junit.Test)17 IotHubX509HardwareAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider)7 IotHubSSLContext (com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext)3 SSLContext (javax.net.ssl.SSLContext)2 NonStrictExpectations (mockit.NonStrictExpectations)2 SignatureProvider (com.microsoft.azure.sdk.iot.device.auth.SignatureProvider)1 HttpsHsmTrustBundleProvider (com.microsoft.azure.sdk.iot.device.edge.HttpsHsmTrustBundleProvider)1 TrustBundleProvider (com.microsoft.azure.sdk.iot.device.edge.TrustBundleProvider)1 ModuleClientException (com.microsoft.azure.sdk.iot.device.exceptions.ModuleClientException)1 TransportException (com.microsoft.azure.sdk.iot.device.exceptions.TransportException)1 HsmException (com.microsoft.azure.sdk.iot.device.hsm.HsmException)1 HttpHsmSignatureProvider (com.microsoft.azure.sdk.iot.device.hsm.HttpHsmSignatureProvider)1 SecurityProvider (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider)1 SecurityProviderException (com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1