Search in sources :

Example 1 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class IotHubConnectionStringBuilderTest method parse_SharedAccessKey_not_defined.

// Tests_SRS_SERVICE_SDK_JAVA_IOTHUBCONNECTIONSTRINGBUILDER_12_010: [The function shall create new ServiceAuthenticationWithSharedAccessPolicyToken and set the authenticationMethod if sharedAccessKey is not defined]
@Test
public void parse_SharedAccessKey_not_defined() throws Exception {
    // Arrange
    String iotHubName = "b.c.d";
    String hostName = "HOSTNAME." + iotHubName;
    String sharedAccessKeyName = "ACCESSKEYNAME";
    String policyName = "SharedAccessSignature";
    String sharedAccessSignature = "1234567890abcdefghijklmnopqrstvwxyz";
    String connectionString = "HostName=" + hostName + ";SharedAccessKeyName=" + sharedAccessKeyName + ";" + policyName + "=" + sharedAccessSignature;
    // Assert
    new Expectations() {

        {
            new ServiceAuthenticationWithSharedAccessPolicyToken(anyString, anyString);
        }
    };
    // Act
    IotHubConnectionString iotHubConnectionString = IotHubConnectionStringBuilder.createConnectionString(connectionString);
}
Also used : Expectations(mockit.Expectations) 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 2 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class IotHubConnectionStringBuilderTest method setAuthenticationMethod_good_case_token.

// 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_token() 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";
    ServiceAuthenticationWithSharedAccessPolicyToken auth = new ServiceAuthenticationWithSharedAccessPolicyToken(newPolicyName, newPolicyKey);
    new Expectations() {

        {
            Deencapsulation.invoke(iotHubConnectionString, "validateFormat", hostName, HOST_NAME_PROPERTY_NAME, regex);
        }
    };
    // Act
    Deencapsulation.invoke(iotHubConnectionString, "setAuthenticationMethod", auth, iotHubConnectionString);
    // Assert
    assertEquals(auth, iotHubConnectionString.getAuthenticationMethod());
    assertEquals(newPolicyName, iotHubConnectionString.getSharedAccessKeyName());
    assertEquals(newPolicyKey, iotHubConnectionString.getSharedAccessSignature());
    assertEquals(null, iotHubConnectionString.getSharedAccessKey());
}
Also used : Expectations(mockit.Expectations) 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 3 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)

Example 4 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 5 with ServiceAuthenticationWithSharedAccessPolicyToken

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

the class AuthenticationMethodTest method getAuthenticationMethodSharedAccessToken.

/**
     * Test of ServiceAuthenticationWithSharedAccessPolicyToken class.
     * Create and get
     */
@Test
public void getAuthenticationMethodSharedAccessToken() throws Exception {
    // Arrange
    String policyName = "SharedAccessKey";
    String sharedAccessToken = "1234567890abcdefghijklmnopqrstvwxyz=";
    // Act
    ServiceAuthenticationWithSharedAccessPolicyToken serviceAuthenticationWithSharedAccessPolicyToken = new ServiceAuthenticationWithSharedAccessPolicyToken(policyName, sharedAccessToken);
    // Assert
    assertEquals("PolicyName mismatch!", policyName, serviceAuthenticationWithSharedAccessPolicyToken.getPolicyName());
    assertEquals("SharedAccessToken mismatch!", sharedAccessToken, serviceAuthenticationWithSharedAccessPolicyToken.getToken());
}
Also used : 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