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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations