Search in sources :

Example 11 with IotHubAuthenticationProvider

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

the class IotHubX509HardwareIotHubAuthenticationProviderTest method constructorSuccess.

// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_001: [This function shall save the provided security provider.]
@Test
public void constructorSuccess() {
    // act
    IotHubAuthenticationProvider authentication = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
    // assert
    SecurityProvider actualSecurityProvider = Deencapsulation.getField(authentication, "securityProviderX509");
    assertEquals(mockSecurityProviderX509, actualSecurityProvider);
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) IotHubX509HardwareAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider) SecurityProvider(com.microsoft.azure.sdk.iot.provisioning.security.SecurityProvider) Test(org.junit.Test)

Example 12 with IotHubAuthenticationProvider

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

the class IotHubX509HardwareIotHubAuthenticationProviderTest method cannotSetNewDefaultCertIfConstructedWithSSLContext.

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

Example 13 with IotHubAuthenticationProvider

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

the class IotHubX509HardwareIotHubAuthenticationProviderTest method setCertificateThrows.

// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_007: [This function shall throw an UnsupportedOperationException.]
@Test(expected = UnsupportedOperationException.class)
public void setCertificateThrows() {
    // arrange
    IotHubAuthenticationProvider auth = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
    // act
    auth.setIotHubTrustedCert("any string");
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) IotHubX509HardwareAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider) Test(org.junit.Test)

Example 14 with IotHubAuthenticationProvider

use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider 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 15 with IotHubAuthenticationProvider

use of com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider 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)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