Search in sources :

Example 6 with ServiceAuthenticationWithSharedAccessPolicyKey

use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.

the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method propertyAccess.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_001: [Provide access to the following properties: policyName, key, token]
@Test
public void propertyAccess() {
    // Arrange
    String policyName = "accessKeyPolicy";
    String key = "11223344556677889900";
    // Act
    ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(policyName, key);
    // Assert
    assertEquals(policyName, auth.getPolicyName());
    assertEquals(key, auth.getKey());
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 7 with ServiceAuthenticationWithSharedAccessPolicyKey

use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.

the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method populate_input_null.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_002: [The function shall throw IllegalArgumentException if the input object is null]
// Assert
@Test(expected = IllegalArgumentException.class)
public void populate_input_null() throws Exception {
    // Arrange
    String newPolicyName = "XXX";
    String newPolicyKey = "YYY";
    ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
    // Act        
    Deencapsulation.invoke(auth, "populate", IotHubConnectionString.class);
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 8 with ServiceAuthenticationWithSharedAccessPolicyKey

use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.

the class ServiceAuthenticationWithSharedAccessPolicyKeyTest method populate_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_003: [The function shall save the policyName and policyKey to the target object]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSKEY_12_004: [The function shall set the access signature (token) to null]
@Test
public void populate_good_case() throws Exception {
    // Arrange
    String regex = "[a-zA-Z0-9_\\-\\.]+$";
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    String newPolicyName = "XXX";
    String newPolicyKey = "YYY";
    ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
    // Act
    Deencapsulation.invoke(auth, "populate", iotHubConnectionString);
    // Assert
    assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
    assertEquals(newPolicyKey, iotHubConnectionString.getSharedAccessKey());
    assertEquals(null, iotHubConnectionString.getSharedAccessSignature());
    // Act
    Deencapsulation.invoke(auth, "setPolicyName", policyName);
    Deencapsulation.invoke(auth, "setKey", sharedAccessKey);
    // Assert
    assertEquals(policyName, auth.getPolicyName());
    assertEquals(sharedAccessKey, auth.getKey());
}
Also used : ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Example 9 with ServiceAuthenticationWithSharedAccessPolicyKey

use of com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey in project azure-iot-sdk-java by Azure.

the class IotHubConnectionStringBuilderTest method setAuthenticationMethod_good_case_key.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_023: [The function shall populate and set the authenticationMethod on the given target iotHubConnectionString object]
@Test
public void setAuthenticationMethod_good_case_key() throws Exception {
    // Arrange
    String regex = "[a-zA-Z0-9_\\-\\.]+$";
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessKey";
    String sharedAccessKey = "1234567890abcdefghijklmnopqrstvwxyz=";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessKey;
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
    String newPolicyName = "XXX";
    String newPolicyKey = "YYY";
    ServiceAuthenticationWithSharedAccessPolicyKey auth = new ServiceAuthenticationWithSharedAccessPolicyKey(newPolicyName, newPolicyKey);
    new Expectations() {

        {
            Deencapsulation.invoke(iotHubConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
        }
    };
    // Act
    Deencapsulation.invoke(iotHubConnectionString, "setAuthenticationMethod", auth, iotHubConnectionString);
    // Assert
    assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
    assertEquals(newPolicyKey, iotHubConnectionString.getSharedAccessKey());
    assertEquals(null, iotHubConnectionString.getSharedAccessSignature());
}
Also used : Expectations(mockit.Expectations) ServiceAuthenticationWithSharedAccessPolicyKey(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) Test(org.junit.Test)

Aggregations

ServiceAuthenticationWithSharedAccessPolicyKey (com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyKey)9 Test (org.junit.Test)9 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)8 AuthenticationMethod (com.microsoft.azure.sdk.iot.service.AuthenticationMethod)2 Expectations (mockit.Expectations)2