Search in sources :

Example 1 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 handleFirstChallengeThrowsForChallengeDataWithIncorrectControlByte.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_010: [If this object is waiting for the first challenge, this function shall validate that this challenge payload contains only a null byte and shall throw an IllegalStateException if it is not.]
@Test(expected = IllegalStateException.class)
public void handleFirstChallengeThrowsForChallengeDataWithIncorrectControlByte() 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(validSecondChallenge);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 2 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 handleChallengeFirstChallengeSuccess.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_011: [If this object is waiting for the first challenge, this function shall return a payload in the format "control byte + base64 decoded storage root key".]
@Test
public void handleChallengeFirstChallengeSuccess() 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
    byte[] actualFirstChallengeResponsePayload = handler.handleChallenge(validFirstChallenge);
    // assert
    assertArraysEqual(expectedFirstChallengeResponsePayload, actualFirstChallengeResponsePayload);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 3 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 handleChallengeSecondChallengeSuccess.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_014: [If this object is waiting for the second challenge, this function shall return a payload of one null byte.]
@Test
public void handleChallengeSecondChallengeSuccess() 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);
    // act
    byte[] actualSecondChallengeResponsePayload = handler.handleChallenge(validSecondChallenge);
    // assert
    assertArraysEqual(expectedSecondChallengeResponsePayload, actualSecondChallengeResponsePayload);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 4 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 handleChallengeThrowsIfWaitingForSaslOutcome.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_020: [If this object is not waiting for a first, second or third challenge, this function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void handleChallengeThrowsIfWaitingForSaslOutcome() 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);
    handler.handleChallenge(validThirdChallenge);
    // act
    handler.handleChallenge(validThirdChallenge);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 5 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 choseSaslMechanismThrowsIfTPMNotPresent.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_004: [If the provided mechanisms array does not contain "TPM" then this function shall throw a ProvisioningDeviceSecurityException.]
@Test(expected = ProvisioningDeviceSecurityException.class)
public void choseSaslMechanismThrowsIfTPMNotPresent() throws ProvisioningDeviceSecurityException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // act
    handler.chooseSaslMechanism(new String[] { "NotTPM" });
}
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