use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProvider method setSSLContext.
public void setSSLContext(SSLContext sslContext) {
this.iotHubSSLContext = new IotHubSSLContext(sslContext);
this.sslContextNeedsUpdate = false;
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext 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);
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubAuthenticationProviderTest method constructorSuccessWithSSLContext.
@Test
public void constructorSuccessWithSSLContext() {
// arrange
new Expectations() {
{
new IotHubSSLContext(mockedSSLContext);
result = mockedIotHubSSLContext;
}
};
// act
IotHubAuthenticationProvider iotHubAuthenticationProvider = new IotHubAuthenticationProviderMock(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId, mockedSSLContext);
// assert
assertFalse((boolean) Deencapsulation.getField(iotHubAuthenticationProvider, "sslContextNeedsUpdate"));
assertEquals(expectedHostname, Deencapsulation.getField(iotHubAuthenticationProvider, "hostname"));
assertEquals(expectedGatewayHostname, Deencapsulation.getField(iotHubAuthenticationProvider, "gatewayHostname"));
assertEquals(expectedDeviceId, Deencapsulation.getField(iotHubAuthenticationProvider, "deviceId"));
assertEquals(expectedModuleId, Deencapsulation.getField(iotHubAuthenticationProvider, "moduleId"));
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubSasTokenHardwareAuthenticationProviderTest method getSSLContextSuccess.
// Tests_SRS_IOTHUBSASTOKENHARDWAREAUTHENTICATION_34_008: [This function shall return the generated IotHubSSLContext.]
@Test
public void getSSLContextSuccess() throws IOException, InvalidKeyException, SecurityProviderException {
// arrange
final String someToken = "someToken";
final byte[] tokenBytes = someToken.getBytes(StandardCharsets.UTF_8);
new NonStrictExpectations() {
{
URLEncoder.encode(anyString, encodingName);
result = someToken;
mockSecurityProviderTpm.signWithIdentity((byte[]) any);
result = tokenBytes;
encodeBase64((byte[]) any);
result = tokenBytes;
URLEncoder.encode(anyString, encodingName);
result = someToken;
mockSecurityProviderTpm.getSSLContext();
result = mockSSLContext;
Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { SSLContext.class }, mockSSLContext);
result = mockIotHubSSLContext;
mockSecurityProviderTpm.getSSLContext();
result = mockSSLContext;
Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { SSLContext.class }, mockSSLContext);
result = mockIotHubSSLContext;
Deencapsulation.invoke(mockIotHubSSLContext, "getSSLContext");
result = mockSSLContext;
}
};
IotHubSasTokenAuthenticationProvider sasTokenAuthentication = new IotHubSasTokenHardwareAuthenticationProvider(expectedHostname, expectedGatewayHostname, expectedDeviceId, expectedModuleId, mockSecurityProviderTpm);
// act
SSLContext actualSSLContext = sasTokenAuthentication.getSSLContext();
// assert
assertEquals(mockSSLContext, actualSSLContext);
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class MultiplexingClientTests method registrationsUnwindForX509Client.
@Test
public void registrationsUnwindForX509Client() throws Exception {
// Create a new device client that uses x509 auth, which should throw an UnsupportedOperationException
// since x509 auth isn't supported while multiplexing
Device x509Device = Tools.getTestDevice(iotHubConnectionString, IotHubClientProtocol.MQTT, AuthenticationType.SELF_SIGNED, false).getDevice();
String deviceConnectionString = registryManager.getDeviceConnectionString(x509Device);
DeviceClient x509DeviceClient = new DeviceClient(deviceConnectionString, testInstance.protocol, new IotHubSSLContext().getSSLContext());
registrationsUnwindForUnsupportedOperationExceptions(x509DeviceClient);
}
Aggregations