Search in sources :

Example 36 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 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);
}
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) Test(org.junit.Test)

Example 37 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 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);
}
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) Test(org.junit.Test)

Example 38 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 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 39 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 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());
}
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 40 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 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);
}
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)

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