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