use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method createConnectionStringWithPolicyTokenSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_005: [The function shall create a new ProvisioningConnectionString object using the given hostname and authenticationMethod.] */
@Test
public void createConnectionStringWithPolicyTokenSucceeded() throws Exception {
// arrange
AuthenticationMethod auth = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyToken", "myPolicy", "<token>");
// act
ProvisioningConnectionString provisioningConnectionString = ProvisioningConnectionStringBuilder.createConnectionString("hostname", auth);
// assert
String connString = provisioningConnectionString.toString();
assertEquals("Connection string mismatch!", "HostName=hostname;SharedAccessKeyName=myPolicy;SharedAccessKey=null;SharedAccessSignature=<token>", connString);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method validateFormatIfSpecifiedSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_020: [The function shall validate the property value against the given regex if the value is not null or empty.] */
@Test
public void validateFormatIfSpecifiedSucceeded() 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);
// assert
new Expectations() {
{
Deencapsulation.invoke(provisioningConnectionString, "validateFormat", anyString, HOST_NAME_PROPERTY_NAME, anyString);
}
};
// act
Deencapsulation.invoke(provisioningConnectionString, "validateFormatIfSpecified", 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 setAuthenticationMethodWithKeySucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_023: [The function shall populate and set the authenticationMethod on the given target provisioningConnectionString object.] */
@Test
public void setAuthenticationMethodWithKeySucceeded() 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.ServiceAuthenticationWithSharedAccessPolicyKey", newPolicyName, newPolicyKey);
new Expectations() {
{
Deencapsulation.invoke(provisioningConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
}
};
// act
Deencapsulation.invoke(provisioningConnectionString, "setAuthenticationMethod", auth, provisioningConnectionString);
// assert
assertEquals(newPolicyName, provisioningConnectionString.getSharedAccessKeyName());
assertEquals(newPolicyKey, provisioningConnectionString.getSharedAccessKey());
assertNull(provisioningConnectionString.getSharedAccessSignature());
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method parserDeviceProvisioningServiceNameWithOneSeparatorSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_013: [The function shall return the substring of the host name until the first `.` character.] */
@Test
public void parserDeviceProvisioningServiceNameWithOneSeparatorSucceeded() throws Exception {
// arrange
String deviceProvisioningServiceName = "PROVISIONINGNAME";
String iotHubHostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + deviceProvisioningServiceName + "." + iotHubHostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
String userString = sharedAccessKeyName + "@SAS.root." + deviceProvisioningServiceName;
ProvisioningConnectionString provisioningConnectionString = ProvisioningConnectionStringBuilder.createConnectionString(connectionString);
// act
String actual = Deencapsulation.invoke(provisioningConnectionString, "parseDeviceProvisioningServiceName", provisioningConnectionString);
// assert
assertEquals("Parser error: DeviceProvisioningServiceName mismatch!", deviceProvisioningServiceName, actual);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method parserThrowsOnNullProvisioningConnectionString.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_007: [The function shall throw IllegalArgumentException if the input target itoHubConnectionString is null.] */
@Test(expected = IllegalArgumentException.class)
public void parserThrowsOnNullProvisioningConnectionString() throws Exception {
// arrange
String deviceProvisioningServiceName = "PROVISIONINGNAME";
String iotHubHostName = "HOSTNAME";
String sharedAccessKeyName = "ACCESSKEYNAME";
String policyName = "SharedAccessKey";
String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
String connectionString = "HostName=" + deviceProvisioningServiceName + "." + iotHubHostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
ProvisioningConnectionString provisioningConnectionString = ProvisioningConnectionStringBuilder.createConnectionString(connectionString);
// act
Deencapsulation.invoke(provisioningConnectionString, "parse", connectionString, ProvisioningConnectionString.class);
}
Aggregations