use of com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method createConnectionStringWithPolicyKeySucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_005: [The function shall create a new ProvisioningConnectionString object using the given hostname and authenticationMethod.] */
@Test
public void createConnectionStringWithPolicyKeySucceeded() throws Exception {
// arrange
AuthenticationMethod auth = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyKey", "myPolicy", "<key>");
// act
ProvisioningConnectionString provisioningConnectionString = ProvisioningConnectionStringBuilder.createConnectionString("hostname", auth);
// assert
String connString = provisioningConnectionString.toString();
assertEquals("Connection string mismatch!", "HostName=hostname;SharedAccessKeyName=myPolicy;SharedAccessKey=<key>;SharedAccessSignature=null", connString);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod 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.AuthenticationMethod in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringBuilderTest method createConnectionStringThrowsOnNullAuthenticationMethod.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_BUILDER_21_004: [The function shall throw IllegalArgumentException if the input authenticationMethod is null.] */
@Test(expected = IllegalArgumentException.class)
public void createConnectionStringThrowsOnNullAuthenticationMethod() throws Exception {
// arrange
AuthenticationMethod authenticationMethod = null;
// act
ProvisioningConnectionStringBuilder.createConnectionString("test", authenticationMethod);
}
use of com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod 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.AuthenticationMethod in project azure-iot-sdk-java by Azure.
the class ProvisioningConnectionStringTest method getAuthenticationMethodSucceeded.
/* Tests_SRS_PROVISIONINGCONNECTIONSTRING_21_004: [The getAuthenticationMethod shall return the stored authenticationMethod.] */
@Test
public void getAuthenticationMethodSucceeded() {
// arrange
ProvisioningConnectionString provisioningConnectionString = buildProvisioningConnectionString();
// act
AuthenticationMethod result = provisioningConnectionString.getAuthenticationMethod();
// assert
assertEquals(mockedAuthenticationMethod, result);
}
Aggregations