use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method populateReturnConnectionString.
/* Tests_SRS_SERVICE_AUTHENTICATION_WITH_SHARED_ACCESS_POLICY_KEY_21_007: [The populateWithAuthenticationProperties shall return the populated connection string.] */
@Test
public void populateReturnConnectionString() {
// arrange
final String policyName = "validPolicyName";
final String key = "validKey";
final ProvisioningConnectionString provisioningConnectionString = mockedProvisioningConnectionString;
Object authenticationMethodResult = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyKey", new Class[] { String.class, String.class }, policyName, key);
// act
ProvisioningConnectionString resultConnectionString = Deencapsulation.invoke(authenticationMethodResult, "populateWithAuthenticationProperties", new Class[] { ProvisioningConnectionString.class }, provisioningConnectionString);
// assert
assertEquals(mockedProvisioningConnectionString, resultConnectionString);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method validateFormatSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_018: [The function shall validate the property value against the given regex.] */
@Test
public void validateFormatSucceeded() 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);
// act - assert
Deencapsulation.invoke(provisioningConnectionString, "validateFormat", hostName, "hostName", regex);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method validateThrowsOnEmptySharedAccessKeyAndSignature.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_016: [The function shall throw IllegalArgumentException if either of the sharedAccessKey or the sharedAccessSignature of the input itoHubConnectionString is null or empty.] */
@Test(expected = IllegalArgumentException.class)
public void validateThrowsOnEmptySharedAccessKeyAndSignature() throws Exception {
// arrange
ProvisioningConnectionString provisioningConnectionString = Deencapsulation.newInstance(ProvisioningConnectionString.class);
Deencapsulation.setField(provisioningConnectionString, "hostName", "PROVISIONINGNAME.azure.net");
Deencapsulation.setField(provisioningConnectionString, "sharedAccessKeyName", "ACCESSKEYNAME");
Deencapsulation.setField(provisioningConnectionString, "sharedAccessKey", "");
Deencapsulation.setField(provisioningConnectionString, "sharedAccessSignature", "");
Deencapsulation.setField(provisioningConnectionString, "deviceProvisioningServiceName", "PROVISIONINGNAME");
// act
Deencapsulation.invoke(provisioningConnectionString, "validate", provisioningConnectionString);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method validateFormatThrowsIfNotMatch.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_019: [The function shall throw IllegalArgumentException if the value did not match with the pattern.] */
@Test(expected = IllegalArgumentException.class)
public void validateFormatThrowsIfNotMatch() 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);
// act - assert
Deencapsulation.invoke(provisioningConnectionString, "validateFormat", "+++", "hostName", regex);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method validateThrowsOnEmptySharedAccessKeyName.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_015: [The function shall throw IllegalArgumentException if the sharedAccessKeyName of the input itoHubConnectionString is null or empty.] */
@Test(expected = IllegalArgumentException.class)
public void validateThrowsOnEmptySharedAccessKeyName() throws Exception {
// arrange
ProvisioningConnectionString provisioningConnectionString = Deencapsulation.newInstance(ProvisioningConnectionString.class);
Deencapsulation.setField(provisioningConnectionString, "hostName", "PROVISIONINGNAME.azure.net");
Deencapsulation.setField(provisioningConnectionString, "sharedAccessKeyName", "");
Deencapsulation.setField(provisioningConnectionString, "sharedAccessKey", "SharedAccessKey");
Deencapsulation.setField(provisioningConnectionString, "sharedAccessSignature", "1234567890abcdefghijklmnopqrstvwxyz=");
Deencapsulation.setField(provisioningConnectionString, "deviceProvisioningServiceName", "PROVISIONINGNAME");
// act
Deencapsulation.invoke(provisioningConnectionString, "validate", provisioningConnectionString);
}
Aggregations