use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method validateValidatesFormatsSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_017: [The function shall call property validation functions for hostname, sharedAccessKeyName, sharedAccessKey, sharedAccessSignature.] */
@Test
public void validateValidatesFormatsSucceeded() throws Exception {
// arrange
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);
Deencapsulation.invoke(provisioningConnectionString, "validateFormatIfSpecified", anyString, SHARED_ACCESS_KEY_NAME_PROPERTY_NAME, anyString);
Deencapsulation.invoke(provisioningConnectionString, "validateFormatIfSpecified", anyString, SHARED_ACCESS_KEY_PROPERTY_NAME, anyString);
Deencapsulation.invoke(provisioningConnectionString, "validateFormatIfSpecified", anyString, SHARED_ACCESS_SIGNATURE_PROPERTY_NAME, anyString);
}
};
// 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 parserValidateConnectionStringSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_012: [The function shall validate the connection string object.] */
@Test
public void parserValidateConnectionStringSucceeded() throws Exception {
// arrange
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, "validate", provisioningConnectionString);
}
};
// act
Deencapsulation.invoke(provisioningConnectionString, "parse", connectionString, provisioningConnectionString);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString 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.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method parserSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_009: [The function shall tokenize and parse the given connection string and fill up the target ProvisioningConnectionString object with proper values.] */
@Test
public void parserSucceeded() 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
Deencapsulation.invoke(provisioningConnectionString, "parse", connectionString, provisioningConnectionString);
// assert
assertEquals("Parser error: HostName mismatch!", deviceProvisioningServiceName + "." + iotHubHostName, provisioningConnectionString.getHostName());
assertEquals("Parser error: SharedAccessKeyName mismatch!", sharedAccessKeyName, provisioningConnectionString.getSharedAccessKeyName());
assertEquals("Parser error: SharedAccessKey mismatch!", provisioningConnectionString.getSharedAccessKey(), sharedAccessKey);
assertEquals("Parser error: SharedAccessSignature mismatch!", "", provisioningConnectionString.getSharedAccessSignature());
assertEquals("Parser error: DeviceProvisioningServiceName mismatch!", deviceProvisioningServiceName, provisioningConnectionString.getDeviceProvisioningServiceName());
assertEquals("Parser error: UserString mismatch!", userString, provisioningConnectionString.getUserString());
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method parserDeviceProvisioningServiceNameWithMultipleSeparatorSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_013: [The function shall return the substring of the host name until the first `.` character.] */
@Test
public void parserDeviceProvisioningServiceNameWithMultipleSeparatorSucceeded() throws Exception {
// arrange
String deviceProvisioningServiceName = "PROVISIONINGNAME";
String iotHubHostName = "HOSTNAME.POSTFIX1.POSTFIX2";
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);
}
Aggregations