Search in sources :

Example 1 with IotHubSSLContext

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

the class IotHubSSLContextTest method constructorWithParamsCreatesSSLContext.

//Tests_SRS_IOTHUBSSLCONTEXT_25_010: [**The constructor shall create a certificate with 'cert' if it were a not a path by calling setValidCert.**]**
@Test
public void constructorWithParamsCreatesSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException {
    //arrange
    testCollection.add(mockedCertificate);
    generateSSLContextExpectations();
    //act
    IotHubSSLContext testContext = Deencapsulation.newInstance(IotHubSSLContext.class, "TestCertString", false);
    //assert
    generateSSLContextVerifications();
    new Verifications() {

        {
            Deencapsulation.invoke(mockedDefaultCert, "setValidCert", anyString);
            times = 1;
        }
    };
    assertNotNull(Deencapsulation.invoke(testContext, "getIotHubSSlContext"));
    testCollection.remove(mockedCertificate);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) Test(org.junit.Test)

Example 2 with IotHubSSLContext

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

the class IotHubSSLContextTest method constructorCreatesSSLContext.

//Tests_SRS_IOTHUBSSLCONTEXT_25_001: [**The constructor shall create a default certificate to be used with IotHub.**]**
//Tests_SRS_IOTHUBSSLCONTEXT_25_002: [**The constructor shall create default SSL context for TLSv1.2.**]**
//Tests_SRS_IOTHUBSSLCONTEXT_25_003: [**The constructor shall create default TrustManagerFactory with the default algorithm.**]**
//Tests_SRS_IOTHUBSSLCONTEXT_25_004: [**The constructor shall create default KeyStore instance with the default type and initialize it.**]**
//Tests_SRS_IOTHUBSSLCONTEXT_25_005: [**The constructor shall set the above created certificate into a keystore.**]**
//Tests_SRS_IOTHUBSSLCONTEXT_25_006: [**The constructor shall initialize TrustManagerFactory with the above initialized keystore.**]**
//Tests_SRS_IOTHUBSSLCONTEXT_25_007: [**The constructor shall initialize SSL context with the above initialized TrustManagerFactory and a new secure random.**]**
@Test
public void constructorCreatesSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException {
    //arrange
    testCollection.add(mockedCertificate);
    generateSSLContextExpectations();
    //act
    IotHubSSLContext testContext = Deencapsulation.newInstance(IotHubSSLContext.class);
    //assert
    generateSSLContextVerifications();
    assertNotNull(Deencapsulation.invoke(testContext, "getIotHubSSlContext"));
    testCollection.remove(mockedCertificate);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) Test(org.junit.Test)

Example 3 with IotHubSSLContext

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

the class IotHubSSLContextTest method constructorWithParamsAsPathCreatesSSLContext.

//Tests_SRS_IOTHUBSSLCONTEXT_25_009: [**The constructor shall create a certificate to be used with IotHub with cert only if it were a path by calling setValidCertPath**]**
@Test
public void constructorWithParamsAsPathCreatesSSLContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException {
    //arrange
    testCollection.add(mockedCertificate);
    generateSSLContextExpectations();
    //act
    IotHubSSLContext testContext = Deencapsulation.newInstance(IotHubSSLContext.class, "Test/Cert/Path", true);
    //assert
    generateSSLContextVerifications();
    new Verifications() {

        {
            Deencapsulation.invoke(mockedDefaultCert, "setValidCertPath", anyString);
            times = 1;
        }
    };
    assertNotNull(Deencapsulation.invoke(testContext, "getIotHubSSlContext"));
    testCollection.remove(mockedCertificate);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) Test(org.junit.Test)

Example 4 with IotHubSSLContext

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

the class DeviceClientConfigTest method setIotHubSSLContextSets.

//Tests_SRS_DEVICECLIENTCONFIG_25_031: [**The function shall set IotHub SSL Context**] **
@Test
public void setIotHubSSLContextSets(@Mocked final IotHubSSLContext mockedContext) throws URISyntaxException {
    final String iotHubHostname = "test.iothubhostname";
    final String deviceId = "test-deviceid";
    final String deviceKey = "test-devicekey";
    final String sharedAccessToken = null;
    final String cert = "ValidCertString";
    final IotHubConnectionString iotHubConnectionString = Deencapsulation.newInstance(IotHubConnectionString.class, new Class[] { String.class, String.class, String.class, String.class }, iotHubHostname, deviceId, deviceKey, sharedAccessToken);
    DeviceClientConfig config = new DeviceClientConfig(iotHubConnectionString);
    config.setIotHubSSLContext(mockedContext);
    IotHubSSLContext testContext = config.getIotHubSSLContext();
    assertNotNull(testContext);
    assertEquals(testContext, mockedContext);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) DeviceClientConfig(com.microsoft.azure.sdk.iot.device.DeviceClientConfig) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.device.IotHubConnectionString) Test(org.junit.Test)

Example 5 with IotHubSSLContext

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

the class IotHubSSLContextTest method getterGetsContext.

//Tests_SRS_IOTHUBSSLCONTEXT_25_017: [*This method shall return the value of sslContext.**]**
@Test
public void getterGetsContext() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException {
    //arrange
    testCollection.add(mockedCertificate);
    generateSSLContextExpectations();
    IotHubSSLContext testContext = Deencapsulation.newInstance(IotHubSSLContext.class, "Test/Cert/Path", true);
    //act
    SSLContext testSSLContext = Deencapsulation.invoke(testContext, "getIotHubSSlContext");
    //assert
    generateSSLContextVerifications();
    new Verifications() {

        {
            Deencapsulation.invoke(mockedDefaultCert, "setValidCertPath", anyString);
            times = 1;
        }
    };
    assertNotNull(testSSLContext);
    testCollection.remove(mockedCertificate);
}
Also used : IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) IotHubSSLContext(com.microsoft.azure.sdk.iot.device.IotHubSSLContext) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Aggregations

IotHubSSLContext (com.microsoft.azure.sdk.iot.device.IotHubSSLContext)7 Test (org.junit.Test)7 DeviceClientConfig (com.microsoft.azure.sdk.iot.device.DeviceClientConfig)2 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)2 FileNotFoundException (java.io.FileNotFoundException)1 SSLContext (javax.net.ssl.SSLContext)1