Search in sources :

Example 11 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 choseSaslMechanismReturnsTPMIfPresent.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_005: [This function shall return "TPM".]
@Test
public void choseSaslMechanismReturnsTPMIfPresent() throws ProvisioningDeviceSecurityException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // act
    String chosenMechanism = handler.chooseSaslMechanism(new String[] { "NotTPM", "TPM" });
    // assert
    String expectedMechanism = Deencapsulation.getField(handler, "TPM_MECHANISM");
    assertEquals(expectedMechanism, chosenMechanism);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 12 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 handleChallengeThrowsIfWaitingToChooseMechanism.

// 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 handleChallengeThrowsIfWaitingToChooseMechanism() throws ProvisioningDeviceClientException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // act
    handler.handleChallenge(validThirdChallenge);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 13 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 handleOutcomeSysPermThrowsProvisioningDeviceSecurityException.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_022: [If the sasl outcome is not OK, this function shall throw a ProvisioningDeviceSecurityException.]
@Test(expected = ProvisioningDeviceSecurityException.class)
public void handleOutcomeSysPermThrowsProvisioningDeviceSecurityException() 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.handleOutcome(SaslHandler.SaslOutcome.SYS_PERM);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 14 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 handleThirdChallengeThrowsForChallengeDataWithIncorrectControlByte.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_015: [If this object is waiting for the third challenge, this function shall validate that this challenge payload contains a control byte with the mask 0xC1 and shall throw an IllegalStateException if it is not.]
@Test(expected = IllegalStateException.class)
public void handleThirdChallengeThrowsForChallengeDataWithIncorrectControlByte() 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);
    // act
    handler.handleChallenge(validFirstChallenge);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 15 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 handleOutcomeThrowsIfNotWaitingOnOutcome.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_021: [If this object is not waiting for the sasl outcome, this function shall throw an IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void handleOutcomeThrowsIfNotWaitingOnOutcome() throws ProvisioningDeviceSecurityException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    // act
    handler.handleOutcome(SaslHandler.SaslOutcome.SYS_PERM);
}
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