Search in sources :

Example 1 with IotHubAuthenticationProvider

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

the class IotHubX509HardwareIotHubAuthenticationProviderTest method getSSLContextThrowsIOExceptionIfExceptionEncountered.

// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_004: [If the security provider throws a SecurityProviderException while generating an SSLContext, this function shall throw an IOException.]
@Test(expected = IOException.class)
public void getSSLContextThrowsIOExceptionIfExceptionEncountered() throws SecurityProviderException, IOException, TransportException {
    // arrange
    IotHubAuthenticationProvider authentication = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
    new NonStrictExpectations() {

        {
            mockSecurityProviderX509.getSSLContext();
            result = new SecurityProviderException("");
        }
    };
    // act
    authentication.getSSLContext();
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) IotHubX509HardwareAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubX509HardwareAuthenticationProvider) SecurityProviderException(com.microsoft.azure.sdk.iot.provisioning.security.exceptions.SecurityProviderException) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 2 with IotHubAuthenticationProvider

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

the class IotHubX509HardwareIotHubAuthenticationProviderTest method setPathToCertificateThrows.

// Tests_SRS_IOTHUBX509HARDWAREAUTHENTICATION_34_006: [This function shall throw an UnsupportedOperationException.]
@Test(expected = UnsupportedOperationException.class)
public void setPathToCertificateThrows() {
    // arrange
    IotHubAuthenticationProvider auth = new IotHubX509HardwareAuthenticationProvider(hostname, gatewayHostname, deviceId, moduleId, mockSecurityProviderX509);
    // act
    auth.setPathToIotHubTrustedCert("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 3 with IotHubAuthenticationProvider

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

the class IotHubAuthenticationProviderTest method getSSLContextSuccess.

// Codes_SRS_AUTHENTICATIONPROVIDER_34_011: [This function shall return the generated IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws IOException {
    // arrange
    IotHubAuthenticationProvider sasAuth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
    new NonStrictExpectations() {

        {
            Deencapsulation.newInstance(IotHubSSLContext.class);
            result = mockedIotHubSSLContext;
            Deencapsulation.invoke(mockedIotHubSSLContext, "getSSLContext");
            result = mockedSSLContext;
        }
    };
    // act
    SSLContext actualSSLContext = sasAuth.getSSLContext();
    // assert
    assertEquals(mockedSSLContext, actualSSLContext);
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) SSLContext(javax.net.ssl.SSLContext) IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) Test(org.junit.Test)

Example 4 with IotHubAuthenticationProvider

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

the class IotHubAuthenticationProviderTest method gettersWork.

// Tests_SRS_AUTHENTICATIONPROVIDER_34_002: [This function shall return the saved hostname.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_003: [This function shall return the saved gatewayHostname.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_004: [This function shall return the saved deviceId.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_005: [This function shall return the saved moduleId.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_008: [This function shall return the saved iotHubTrustedCert.]
// Tests_SRS_AUTHENTICATIONPROVIDER_34_009: [This function shall return the saved pathToIotHubTrustedCert.]
@Test
public void gettersWork() {
    // arrange
    String expectedCert = "some cert";
    String expectedCertPath = "some/path";
    IotHubAuthenticationProvider iotHubAuthenticationProvider = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
    Deencapsulation.setField(iotHubAuthenticationProvider, "iotHubTrustedCert", expectedCert);
    Deencapsulation.setField(iotHubAuthenticationProvider, "pathToIotHubTrustedCert", expectedCertPath);
    // act
    String actualHostName = iotHubAuthenticationProvider.getHostname();
    String actualGatewayHostname = iotHubAuthenticationProvider.getGatewayHostname();
    String actualDeviceId = iotHubAuthenticationProvider.getDeviceId();
    String actualModuleId = iotHubAuthenticationProvider.getModuleId();
    String actualCert = iotHubAuthenticationProvider.getIotHubTrustedCert();
    String actualCertPath = iotHubAuthenticationProvider.getPathToIotHubTrustedCert();
    // assert
    assertEquals(expectedHostname, actualHostName);
    assertEquals(expectedGatewayHostname, actualGatewayHostname);
    assertEquals(expectedDeviceId, actualDeviceId);
    assertEquals(expectedModuleId, actualModuleId);
    assertEquals(expectedCert, actualCert);
    assertEquals(expectedCertPath, actualCertPath);
}
Also used : IotHubAuthenticationProvider(com.microsoft.azure.sdk.iot.device.auth.IotHubAuthenticationProvider) Test(org.junit.Test)

Example 5 with IotHubAuthenticationProvider

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

the class IotHubAuthenticationProviderTest method generateSSLContextGeneratesDefaultIotHubSSLContext.

// Tests_SRS_AUTHENTICATIONPROVIDER_34_021: [If this has no saved iotHubTrustedCert or path, This function shall create and save a new default IotHubSSLContext object.]
@Test
public void generateSSLContextGeneratesDefaultIotHubSSLContext() {
    // arrange
    IotHubAuthenticationProvider auth = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId);
    // act
    Deencapsulation.invoke(auth, "generateSSLContext");
    // assert
    new Verifications() {

        {
            Deencapsulation.newInstance(IotHubSSLContext.class);
            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