Search in sources :

Example 16 with ProvisioningConnectionString

use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.

the class ServiceAuthenticationWithSharedAccessPolicyTokenTest method populateStorePolicyNameAndToken.

/* Tests_SRS_SERVICE_AUTHENTICATION_WITH_SHARED_ACCESS_POLICY_TOKEN_21_005: [The populateWithAuthenticationProperties shall save the policyName and token to the target object.] */
@Test
public void populateStorePolicyNameAndToken() {
    // arrange
    final String policyName = "validPolicyName";
    final String token = "validToken";
    final ProvisioningConnectionString provisioningConnectionString = mockedProvisioningConnectionString;
    Object authenticationMethodResult = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyToken", new Class[] { String.class, String.class }, policyName, token);
    // act
    Deencapsulation.invoke(authenticationMethodResult, "populateWithAuthenticationProperties", new Class[] { ProvisioningConnectionString.class }, provisioningConnectionString);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedProvisioningConnectionString, "setSharedAccessKeyName", policyName);
            times = 1;
            Deencapsulation.invoke(mockedProvisioningConnectionString, "setSharedAccessSignature", token);
            times = 1;
        }
    };
}
Also used : ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 17 with ProvisioningConnectionString

use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.

the class ServiceAuthenticationWithSharedAccessPolicyTokenTest method populateSetKeyToNull.

/* Tests_SRS_SERVICE_AUTHENTICATION_WITH_SHARED_ACCESS_POLICY_TOKEN_21_006: [The populateWithAuthenticationProperties shall set the access key to null.] */
@Test
public void populateSetKeyToNull() {
    // arrange
    final String policyName = "validPolicyName";
    final String token = "validToken";
    final ProvisioningConnectionString provisioningConnectionString = mockedProvisioningConnectionString;
    Object authenticationMethodResult = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyToken", new Class[] { String.class, String.class }, policyName, token);
    // act
    Deencapsulation.invoke(authenticationMethodResult, "populateWithAuthenticationProperties", new Class[] { ProvisioningConnectionString.class }, provisioningConnectionString);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedProvisioningConnectionString, "setSharedAccessKey", new Class[] { String.class }, (String) null);
            times = 1;
        }
    };
}
Also used : ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 18 with ProvisioningConnectionString

use of com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString in project azure-iot-sdk-java by Azure.

the class ContractApiHttpTest method createFromConnectionStringThrowsOnNullConnectionString.

/* SRS_HTTP_DEVICE_REGISTRATION_CLIENT_21_003: [The createFromConnectionString shall throw IllegalArgumentException if the input string is null, threw by the constructor.] */
@Test(expected = IllegalArgumentException.class)
public void createFromConnectionStringThrowsOnNullConnectionString() throws ProvisioningServiceClientException {
    // arrange
    final ProvisioningConnectionString provisioningConnectionString = null;
    // act
    ContractApiHttp.createFromConnectionString(provisioningConnectionString);
// assert
}
Also used : ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) Test(org.junit.Test)

Example 19 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 populateStorePolicyNameAndKey.

/* Tests_SRS_SERVICE_AUTHENTICATION_WITH_SHARED_ACCESS_POLICY_KEY_21_005: [The populateWithAuthenticationProperties shall save the policyName and key to the target object.] */
@Test
public void populateStorePolicyNameAndKey() {
    // 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
    Deencapsulation.invoke(authenticationMethodResult, "populateWithAuthenticationProperties", new Class[] { ProvisioningConnectionString.class }, provisioningConnectionString);
    // assert
    new Verifications() {

        {
            Deencapsulation.invoke(mockedProvisioningConnectionString, "setSharedAccessKeyName", policyName);
            times = 1;
            Deencapsulation.invoke(mockedProvisioningConnectionString, "setSharedAccessKey", key);
            times = 1;
        }
    };
}
Also used : ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) ProvisioningConnectionString(com.microsoft.azure.sdk.iot.provisioning.service.auth.ProvisioningConnectionString) Verifications(mockit.Verifications) Test(org.junit.Test)

Example 20 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 populateThrowsOnNullConnectionString.

/* Tests_SRS_SERVICE_AUTHENTICATION_WITH_SHARED_ACCESS_POLICY_KEY_21_004: [If the provided provisioningConnectionString is null, the populateWithAuthenticationProperties shall throw IllegalArgumentException.] */
@Test(expected = IllegalArgumentException.class)
public void populateThrowsOnNullConnectionString() {
    // arrange
    final String policyName = "validPolicyName";
    final String key = "validKey";
    final ProvisioningConnectionString provisioningConnectionString = null;
    Object authenticationMethodResult = Deencapsulation.newInstance("com.microsoft.azure.sdk.iot.provisioning.service.auth.ServiceAuthenticationWithSharedAccessPolicyKey", new Class[] { String.class, String.class }, policyName, key);
    // act
    Deencapsulation.invoke(authenticationMethodResult, "populateWithAuthenticationProperties", new Class[] { ProvisioningConnectionString.class }, provisioningConnectionString);
// assert
}
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