use of com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method createConnectionStringThrowsOnNullHostName.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_003: [The function shall throw IllegalArgumentException if the input string is empty or null.] */
@Test(expected = IllegalArgumentException.class)
public void createConnectionStringThrowsOnNullHostName() throws Exception {
// arrange
AuthenticationMethod authenticationMethod = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyKey", "myPolicy", "<key>");
// act
ProvisioningConnectionStringBuilder.createConnectionString(null, authenticationMethod);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method setAuthenticationMethodWithTokenSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_023: [The function shall populate and set the authenticationMethod on the given target provisioningConnectionString object.] */
@Test
public void setAuthenticationMethodWithTokenSucceeded() throws Exception {
// arrange
String regex = "[a-zA-Z0-9_\\-\\.]+$";
String deviceProvisioningServiceName = "b.c.d";
String hostName = "HOSTNAME." + deviceProvisioningServiceName;
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
ProvisioningConnectionString provisioningConnectionString = ProvisioningConnectionStringBuilder.createConnectionString(connectionString);
String newPolicyName = "XXX";
String newPolicyKey = "YYY";
AuthenticationMethod auth = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyToken", newPolicyName, newPolicyKey);
new Expectations() {
{
Deencapsulation.invoke(provisioningConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
}
};
// act
Deencapsulation.invoke(provisioningConnectionString, "setAuthenticationMethod", auth, provisioningConnectionString);
// assert
assertEquals(auth, provisioningConnectionString.getAuthenticationMethod());
assertEquals(newPolicyName, provisioningConnectionString.getSharedAccessKeyName());
assertEquals(newPolicyKey, provisioningConnectionString.getSharedAccessSignature());
assertNull(provisioningConnectionString.getSharedAccessKey());
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method createConnectionStringThrowsOnEmptyHostName.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_003: [The function shall throw IllegalArgumentException if the input string is empty or null.] */
@Test(expected = IllegalArgumentException.class)
public void createConnectionStringThrowsOnEmptyHostName() throws Exception {
// arrange
AuthenticationMethod authenticationMethod = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyKey", "myPolicy", "<key>");
// act
ProvisioningConnectionStringBuilder.createConnectionString("", authenticationMethod);
}
Aggregations