Search in sources :

Example 21 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 choseSaslMechanismThrowsIfNotWaitingToChooseMechanism.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_003: [If this handler is not in the state where it is expecting to choose a sasl mechanism, this function shall throw in IllegalStateException.]
@Test(expected = IllegalStateException.class)
public void choseSaslMechanismThrowsIfNotWaitingToChooseMechanism() throws ProvisioningDeviceSecurityException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    handler.chooseSaslMechanism(new String[] { "NotTPM", "TPM" });
    // act
    handler.chooseSaslMechanism(new String[] { "NotTPM", "TPM" });
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 22 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 handleOutcomeAuthThrowsProvisioningDeviceSecurityException.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_022: [If the sasl outcome is not OK, this function shall throw a ProvisioningDeviceSecurityException.]
@Test(expected = ProvisioningDeviceSecurityException.class)
public void handleOutcomeAuthThrowsProvisioningDeviceSecurityException() 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.AUTH);
}
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