Search in sources :

Example 6 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 buildInitSuccess.

// Tests_SRS_AMQPSPROVISIONINGSASLHANDLER_34_007: [This function shall return the init payload bytes in the format "control byte + scopeId + null byte + registration id + null byte + base64 decoded endorsement key".]
@Test
public void buildInitSuccess() throws ProvisioningDeviceSecurityException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    handler.chooseSaslMechanism(new String[] { "TPM", "notTPM" });
    // act
    byte[] actualInitPayload = handler.getInitPayload("TPM");
    // assert
    assertArraysEqual(expectedInitPayload, actualInitPayload);
}
Also used : AmqpsProvisioningSaslHandler(com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.amqp.AmqpsProvisioningSaslHandler) Test(org.junit.Test)

Example 7 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 handleOutcomeSysThrowsProvisioningDeviceSecurityException.

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

Example 8 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 handleSecondChallengeThrowsForChallengeDataWithIncorrectControlByte.

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

Example 9 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 handleOutcomeSysTempThrowsProvisioningDeviceSecurityException.

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

Example 10 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 handleChallengeThrowsIfWaitingToBuildInitPayload.

// 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 handleChallengeThrowsIfWaitingToBuildInitPayload() throws ProvisioningDeviceClientException {
    // arrange
    AmqpsProvisioningSaslHandler handler = Deencapsulation.newInstance(AmqpsProvisioningSaslHandler.class, idScope, registrationId, endorsementKey, storageRootKey, mockedResponseCallback, new Object());
    handler.chooseSaslMechanism(new String[] { "TPM", "notTPM" });
    // act
    handler.handleChallenge(validThirdChallenge);
}
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