Search in sources :

Example 31 with ProvisioningConnectionString

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

Example 32 with ProvisioningConnectionString

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

Example 33 with ProvisioningConnectionString

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

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

Example 35 with ProvisioningConnectionString

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

Aggregations

ProvisioningConnectionString (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString)48 Test (org.junit.Test)47 Expectations (mockit.Expectations)7 AuthenticationMethod (com.microsoft.azure.sdk.iot.provisioning.service.auth.AuthenticationMethod)5 ProvisioningSasToken (com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningSasToken)4 Verifications (mockit.Verifications)4 Base64.encodeBase64String (org.apache.commons.codec.binary.Base64.encodeBase64String)3 ContractApiHttp (com.microsoft.azure.sdk.iot.provisioning.service.contract.ContractApiHttp)1 URLEncoder (java.net.URLEncoder)1 Mac (javax.crypto.Mac)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1