Search in sources :

Example 6 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class ServiceAuthenticationWithSharedAccessPolicyTokenTest method populate_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSTOKEN_12_003: [The function shall save the policyName and token to the target object]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSTOKEN_12_004: [The function shall set the access key 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 newPolicyToken = "YYY";
    ServiceAuthenticationWithSharedAccessPolicyToken auth = new ServiceAuthenticationWithSharedAccessPolicyToken(newPolicyName, newPolicyToken);
    // Act
    auth.populate(iotHubConnectionString);
    // Assert
    assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
    assertEquals(newPolicyToken, iotHubConnectionString.getSharedAccessSignature());
    assertNull(iotHubConnectionString.getSharedAccessKey());
    // Act
    Deencapsulation.invoke(auth, "setPolicyName", policyName);
    Deencapsulation.invoke(auth, "setToken", sharedAccessKey);
    // Assert
    assertEquals(policyName, auth.getPolicyName());
    assertEquals(sharedAccessKey, auth.getToken());
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) ServiceAuthenticationWithSharedAccessPolicyToken(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyToken) Test(org.junit.Test)

Example 7 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class IotHubConnectionStringBuilderTest method createConnectionString_good_case_policy_token.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_005: [The function shall create a new IotHubConnectionString object using the given hostname and auhtenticationMethod]
@Test
public void createConnectionString_good_case_policy_token() throws Exception {
    // Arrange
    ServiceAuthenticationWithSharedAccessPolicyToken auth = new ServiceAuthenticationWithSharedAccessPolicyToken("myPolicy", "<key>");
    // Act
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString("hostname", auth);
    String connString = iotHubConnectionString.toString();
    // Assert
    assertEquals("Connection string mismatch!", "HostName=hostname;SharedAccessKeyName=myPolicy;SharedAccessKey=null;SharedAccessSignature=<key>", connString);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) ServiceAuthenticationWithSharedAccessPolicyToken(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyToken) Test(org.junit.Test)

Example 8 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class ServiceAuthenticationWithSharedAccessPolicyTokenTest method populate_good_case.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSTOKEN_12_003: [The function shall save the policyName and token to the target object]
// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSTOKEN_12_004: [The function shall set the access key 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 newPolicyToken = "YYY";
    ServiceAuthenticationWithSharedAccessPolicyToken auth = new ServiceAuthenticationWithSharedAccessPolicyToken(newPolicyName, newPolicyToken);
    // Act
    auth.populate(iotHubConnectionString);
    // Assert
    assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
    assertEquals(newPolicyToken, iotHubConnectionString.getSharedAccessSignature());
    assertEquals(null, iotHubConnectionString.getSharedAccessKey());
    // Act
    Deencapsulation.invoke(auth, "setPolicyName", policyName);
    Deencapsulation.invoke(auth, "setToken", sharedAccessKey);
    // Assert
    assertEquals(policyName, auth.getPolicyName());
    assertEquals(sharedAccessKey, auth.getToken());
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) ServiceAuthenticationWithSharedAccessPolicyToken(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyToken) Test(org.junit.Test)

Example 9 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class ServiceAuthenticationWithSharedAccessPolicyTokenTest method propertyAccess.

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

Example 10 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class ServiceAuthenticationWithSharedAccessPolicyTokenTest method populate_input_null.

// Tests_SRS_SERVICE_SDK_JAVA_SERVICEAUTHENTICATIONWITHSHAREDACCESSTOKEN_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 newPolicyToken = "YYY";
    ServiceAuthenticationWithSharedAccessPolicyToken auth = new ServiceAuthenticationWithSharedAccessPolicyToken(newPolicyName, newPolicyToken);
    // Act
    auth.populate(null);
}
Also used : IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) ServiceAuthenticationWithSharedAccessPolicyToken(com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyToken) Test(org.junit.Test)

Aggregations

ServiceAuthenticationWithSharedAccessPolicyToken (com.microsoft.azure.sdk.iot.service.ServiceAuthenticationWithSharedAccessPolicyToken)11 Test (org.junit.Test)11 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)9 Expectations (mockit.Expectations)2