Search in sources :

Example 16 with AmqpsProvisioningSaslHandler

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler in project azure-iot-sdk-java by Azure.

the class AmqpsProvisioningSaslHandlerTest method handleChallengeThrowsForNullChallengeData.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_009: [If the provided saslChallenge is null, this function shall throw an IllegalArgumentException.]
@Test(expected = IllegalArgumentException.class)
public void handleChallengeThrowsForNullChallengeData() throws ProvisioningDeviceClientException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    handler.chooseSaslMechanism(new String[] { "TPM", "notTPM" });
    handler.getInitPayload("TPM");
    // act
    handler.handleChallenge(null);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 17 with AmqpsProvisioningSaslHandler

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler in project azure-iot-sdk-java by Azure.

the class AmqpsProvisioningSaslHandlerTest method constructorSavesArgumentValues.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_001: [This constructor shall save the provided idScope, registrationId, endorsementKey, storageRootKey, responseCallback and autorizationCallbackContext .]
@Test
public void constructorSavesArgumentValues() {
    // act
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, new Class[] { String.class, String.class, byte[].class, byte[].class, ResponseCallback.class, Object.class }, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // assert
    String actualIdScope = Deencapsulation.getField(handler, "idScope");
    String actualRegistrationId = Deencapsulation.getField(handler, "registrationId");
    byte[] actualEndorsementKey = Deencapsulation.getField(handler, "endorsementKey");
    byte[] actualStorageRootKey = Deencapsulation.getField(handler, "storageRootKey");
    ResponseCallback actualNonceCallback = Deencapsulation.getField(handler, "responseCallback");
    String actualSasToken = Deencapsulation.getField(handler, "sasToken");
    assertEquals(idScope, actualIdScope);
    assertEquals(registrationId, actualRegistrationId);
    assertEquals(endorsementKey, actualEndorsementKey);
    assertEquals(storageRootKey, actualStorageRootKey);
    assertEquals(mockedResponseCallback, actualNonceCallback);
    assertNull(actualSasToken);
}
Also used : ResponseCallback(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.ResponseCallback) AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 18 with AmqpsProvisioningSaslHandler

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler in project azure-iot-sdk-java by Azure.

the class AmqpsProvisioningSaslHandlerTest method handleChallengeThirdChallengeSuccess.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_013: [If this object is waiting for the second challenge, this function shall read the challenge in the format "control byte + nonce (first half)" and save the nonce portion.]
// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_016: [If this object is waiting for the third challenge, this function shall read the challenge in the format "control byte + nonce (second half)" and save the nonce portion.]
// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_017: [If this object is waiting for the third challenge, this function shall put together the full nonce byte array and run the saved responseCallback with the nonce and DPS_REGISTRATION_RECEIVED.]
// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_018: [If this object is waiting for the third challenge, after running the saved responseCallback, this function shall wait for the sas token to be set before returning a payload in the format "control byte + sas token".]
@Test
public void handleChallengeThirdChallengeSuccess() throws ProvisioningDeviceClientException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    handler.chooseSaslMechanism(new String[] { "TPM", "notTPM" });
    handler.getInitPayload("TPM");
    handler.handleChallenge(validFirstChallenge);
    handler.handleChallenge(validSecondChallenge);
    Deencapsulation.setField(handler, "sasToken", sasToken);
    new NonStrictExpectations() {

        {
            new ResponseData(expectedFullNonce, ContractState.DPS_REGISTRATION_RECEIVED, 0);
            result = mockedResponseData;
        }
    };
    // act
    byte[] actualFinalChallengeResponsePayload = handler.handleChallenge(validThirdChallenge);
    // assert
    assertArraysEqual(expectedFinalChallengeResponsePayload, actualFinalChallengeResponsePayload);
    new Verifications() {

        {
            mockedResponseCallback.run(mockedResponseData, any);
            times = 1;
        }
    };
}
Also used : ResponseData(com.microsoft.azure.sdk.iot.provisioning.device.internal.task.ResponseData) AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 19 with AmqpsProvisioningSaslHandler

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler in project azure-iot-sdk-java by Azure.

the class AmqpsProvisioningSaslHandlerTest method setSasTokenSets.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_008: [This function shall save the provided sas token.]
@Test
public void setSasTokenSets() {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // act
    handler.setSasToken(sasToken);
    // assert
    String actualSasToken = Deencapsulation.getField(handler, "sasToken");
    assertEquals(sasToken, actualSasToken);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 20 with AmqpsProvisioningSaslHandler

use of com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler in project azure-iot-sdk-java by Azure.

the class AmqpsProvisioningSaslHandlerTest method buildInitThrowsIfNotWaitingToBuildInit.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_006: [If this handler is not in the state where it is expecting to build the init payload, this function shall throw in IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void buildInitThrowsIfNotWaitingToBuildInit() {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // act
    handler.getInitPayload("TPM");
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Aggregations

AmqpsProvisioningSaslHandler (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler)22 Test (org.junit.Test)22 ResponseCallback (com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.ResponseCallback)1 ResponseData (com.microsoft.azure.sdk.iot.provisioning.device.internal.task.ResponseData)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Verifications (mockit.Verifications)1