Search in sources :

Example 6 with IotHubX509HardwareAuthenticationProvider

use of com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider in project azure-iot-sdk-java by Azure.

the class IotHubX509HardwareIotHubAuthenticationProviderTest method getSSLContextSuccess.

// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_003: [If this object's ssl context has not been generated yet, this function shall generate it from the saved security provider.]
// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_005: [This function shall return the saved IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws SecurityProviderException, IOException, TransportException {
    // arrange
    IotHubAuthenticationProvider authentication = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
    new NonStrictExpectations() {

        {
            Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
            result = mockSSLContext;
            mockSecurityProviderX509.getSSLContext();
            result = mockSSLContext;
            Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { SSLContext.class }, mockSSLContext);
            result = mockIotHubSSLContext;
            Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
            result = mockSSLContext;
        }
    };
    Deencapsulation.setField(authentication, "iotHubSSLContext", null);
    // act
    SSLContext actualSSLContext = authentication.getSSLContext();
    assertEquals(mockSSLContext, actualSSLContext);
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) IotHubX509HardwareAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider) SSLContext(javax.net.ssl.SSLContext) IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 7 with IotHubX509HardwareAuthenticationProvider

use of com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider in project azure-iot-sdk-java by Azure.

the class IotHubX509HardwareIotHubAuthenticationProviderTest method cannotSetNewDefaultCertPathIfConstructedWithSSLContext.

// Tests_SRS_IOTHUBX509AUTHENTICATION_34_032: [If this object was created using a constructor that takes an SSLContext, this function shall throw an UnsupportedOperationException.]
@Test(expected = UnsupportedOperationException.class)
public void cannotSetNewDefaultCertPathIfConstructedWithSSLContext() {
    // arrange
    IotHubAuthenticationProvider authentication = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
    // act
    authentication.setPathToIotHubTrustedCert("any path");
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) IotHubX509HardwareAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider) Test(org.junit.Test)

Aggregations

IotHubAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider)7 IotHubX509HardwareAuthenticationProvider (com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider)7 Test (org.junit.Test)7 NonStrictExpectations (mockit.NonStrictExpectations)2 IotHubSSLContext (com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext)1 SecurityProvider (com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider)1 SecurityProviderException (com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException)1 SSLContext (javax.net.ssl.SSLContext)1