use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.
the class SecurityProviderX509Test method getSslContextThrowsIfX509TrustManagerNotFound.
// SRS_SecurityClientX509_25_004: [ This method shall throw SecurityProviderException if X509 Trust Manager is not found. ]
@Test(expected = SecurityProviderException.class)
public void getSslContextThrowsIfX509TrustManagerNotFound() throws SecurityProviderException, KeyManagementException, KeyStoreException {
// arrange
Collection<X509Certificate> certificates = new LinkedList<>();
certificates.add(mockedX509Certificate);
SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, mockedKey, certificates);
new NonStrictExpectations() {
{
mockedKeyManagerFactory.getKeyManagers();
result = mockedX509KeyManager;
mockedTrustManagerFactory.getTrustManagers();
// not necessarily X509
result = mockedTrustManager;
}
};
// act
securityClientX509Test.getSSLContext();
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.
the class SecurityProviderX509Test method getSslContextThrowsOnNullPrivateKey.
@Test(expected = IllegalArgumentException.class)
public void getSslContextThrowsOnNullPrivateKey() throws SecurityProviderException, KeyManagementException, KeyStoreException {
// arrange
Collection<X509Certificate> certificates = new LinkedList<>();
certificates.add(mockedX509Certificate);
SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, null, certificates);
// act
securityClientX509Test.getSSLContext();
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.
the class SecurityProviderX509Test method getSslContextThrowsIfAnyOfTheUnderlyingAPIFails.
// SRS_SecurityClientX509_25_003: [ This method shall throw SecurityProviderException chained with the exception thrown from underlying API calls to SSL library. ]
@Test(expected = SecurityProviderException.class)
public void getSslContextThrowsIfAnyOfTheUnderlyingAPIFails() throws SecurityProviderException, KeyManagementException, KeyStoreException {
// arrange
Collection<X509Certificate> certificates = new LinkedList<>();
certificates.add(mockedX509Certificate);
SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, mockedKey, certificates);
new NonStrictExpectations() {
{
mockedKeyManagerFactory.getKeyManagers();
result = mockedX509KeyManager;
mockedTrustManagerFactory.getTrustManagers();
result = mockedX509TrustManager;
mockedSslContext.init((KeyManager[]) any, (TrustManager[]) any, (SecureRandom) any);
result = new KeyManagementException();
}
};
// act
securityClientX509Test.getSSLContext();
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.
the class SecurityProviderX509Test method getRegistrationIdSucceeds.
// SRS_SecurityClientX509_25_001: [ This method shall retrieve the commonName of the client certificate and return as registration Id. ]
@Test
public void getRegistrationIdSucceeds() throws SecurityProviderException {
// arrange
Collection<X509Certificate> certificates = new LinkedList<>();
certificates.add(mockedX509Certificate);
SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, mockedX509Certificate, mockedKey, certificates);
assertEquals(TEST_COMMON_NAME, securityClientX509Test.getRegistrationId());
}
use of com.microsoft.azure.sdk.iot.provisioning.security.SecurityProviderX509 in project azure-iot-sdk-java by Azure.
the class SecurityProviderX509Test method getSslContextThrowsOnNullLeaf.
// SRS_SecurityClientX509_25_006: [ This method shall throw IllegalArgumentException if input parameters are null. ]
@Test(expected = IllegalArgumentException.class)
public void getSslContextThrowsOnNullLeaf() throws SecurityProviderException, KeyManagementException, KeyStoreException {
// arrange
Collection<X509Certificate> certificates = new LinkedList<>();
certificates.add(mockedX509Certificate);
SecurityProviderX509 securityClientX509Test = new SecurityProviderX509TestImpl(TEST_COMMON_NAME, null, mockedKey, certificates);
// act
securityClientX509Test.getSSLContext();
}
Aggregations