use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubSSLContextTest method constructorWithCertAndKeySuccess.
// Tests_SRS_IOTHUBSSLCONTEXT_34_018: [This constructor shall generate a temporary password to protect the created keystore holding the private key.]
// Tests_SRS_IOTHUBSSLCONTEXT_34_019: [The constructor shall create default SSL context for TLSv1.2.]
// Tests_SRS_IOTHUBSSLCONTEXT_34_020: [The constructor shall create a keystore containing the public key certificate and the private key.]
// Tests_SRS_IOTHUBSSLCONTEXT_34_021: [The constructor shall initialize a default trust manager factory that accepts communications from Iot Hub.]
// Tests_SRS_IOTHUBSSLCONTEXT_34_024: [The constructor shall initialize SSL context with its initialized keystore, its initialized TrustManagerFactory and a new secure random.]
@Test
public void constructorWithCertAndKeySuccess() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException, CertificateException, UnrecoverableKeyException {
// arrange
final String publicKeyCert = "someCert";
final String privateKey = "someKey";
final Collection<X509Certificate> testCertChain = new ArrayList<>();
testCertChain.add(mockedX509Certificate);
new MockUp<IotHubSSLContext>() {
@Mock
Key parsePrivateKey(String privateKeyString) throws CertificateException {
return mockedPrivateKey;
}
@Mock
Collection<X509Certificate> parsePublicKeyCertificate(String publicKeyCertificateString) throws CertificateException {
return testCertChain;
}
};
new Expectations() {
{
new SecureRandom();
result = mockedSecureRandom;
mockedSecureRandom.nextInt(anyInt);
result = 'a';
Deencapsulation.newInstance(IotHubCertificateManager.class);
result = mockedCertificateManager;
mockKeyManagerFactory.getKeyManagers();
result = mockKeyManagers;
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
result = mockedTrustManagerFactory;
mockedTrustManagerFactory.getTrustManagers();
result = mockedTrustManager;
}
};
final IotHubSSLContext iotHubSSLContext = Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] { String.class, String.class }, publicKeyCert, privateKey);
}
use of com.microsoft.azure.sdk.iot.deps.auth.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(mockedX509Certificate);
generateSSLContextExpectations();
IotHubSSLContext testContext = Deencapsulation.newInstance(IotHubSSLContext.class, new Class[] {});
// act
SSLContext testSSLContext = Deencapsulation.invoke(testContext, "getSSLContext");
// assert
generateSSLContextVerifications();
assertNotNull(testSSLContext);
testCollection.remove(mockedX509Certificate);
}
use of com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext in project azure-iot-sdk-java by Azure.
the class IotHubSSLContextTest method constructorWithSSLContextSavesSSLContext.
// Tests_SRS_IOTHUBSSLCONTEXT_34_027: [This constructor shall save the provided ssl context.]
@Test
public void constructorWithSSLContextSavesSSLContext() {
// act
IotHubSSLContext iotHubSSLContext = new IotHubSSLContext(mockedSSLContext);
// assert
SSLContext savedSSLContext = Deencapsulation.getField(iotHubSSLContext, "sslContext");
assertEquals(mockedSSLContext, savedSSLContext);
}
Aggregations