Search in sources :

Example 6 with AuthenticationMethod

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);
}
Also used : AuthenticationMethod(com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod) Test(org.junit.Test)

Example 7 with 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());
}
Also used : Expectations(mockit.Expectations) ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) AuthenticationMethod(com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod) Test(org.junit.Test)

Example 8 with AuthenticationMethod

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);
}
Also used : AuthenticationMethod(com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod) Test(org.junit.Test)

Aggregations

AuthenticationMethod (com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod)8 Test (org.junit.Test)8 ProvisioningConnectionString (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString)5 Expectations (mockit.Expectations)2