use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslOutcomeTempTest.
// Tests_SRS_SASLLISTENERIMPL_34_006: [If the sasl outcome is PN_SASL_TEMP, this function shall tell the saved saslHandler to handleOutcome with SYS_TEMP.]
@Test
public void onSaslOutcomeTempTest() throws Exception {
// arrange
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_TEMP;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS_TEMP);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslMechanismsWithPlainMechanism.
// Tests_SRS_SASLLISTENERIMPL_34_015: [If the chosen mechanism is PLAIN, this function shall call sasl.plain(...) with the inputs given by the saslhandler.]
@Test
public void onSaslMechanismsWithPlainMechanism() throws Exception {
// arrange
final String[] remoteMechanisms = new String[] { "PLAIN" };
final String chosenMechanism = "PLAIN";
final byte[] initPayload = new byte[0];
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
final String expectedUsername = "1234";
final String expectedPass = "5678";
new NonStrictExpectations() {
{
mockedSasl.getRemoteMechanisms();
result = remoteMechanisms;
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
result = chosenMechanism;
mockedSaslHandler.getInitPayload(chosenMechanism);
result = initPayload;
mockedSaslHandler.getPlainUsername();
result = expectedUsername;
mockedSaslHandler.getPlainPassword();
result = expectedPass;
}
};
// act
saslListener.onSaslMechanisms(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
times = 1;
mockedSaslHandler.getInitPayload(chosenMechanism);
times = 1;
mockedSasl.send(initPayload, 0, initPayload.length);
times = 0;
mockedSasl.plain(expectedUsername, expectedPass);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslOutcomePermTest.
// Tests_SRS_SASLLISTENERIMPL_34_007: [If the sasl outcome is PN_SASL_PERM, this function shall tell the saved saslHandler to handleOutcome with SYS_PERM.]
@Test
public void onSaslOutcomePermTest() throws Exception {
// arrange
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_PERM;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS_PERM);
times = 1;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslOutcomeNoneTest.
// Tests_SRS_SASLLISTENERIMPL_34_011: [If the sasl outcome is PN_SASL_NONE, this function shall save an IllegalStateException.]
@Test
public void onSaslOutcomeNoneTest() {
// arrange
SaslListenerImpl saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_NONE;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
assertNotNull(saslListener.getSavedException());
assertEquals(IllegalStateException.class, saslListener.getSavedException().getClass());
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslMechanismHandlerThrowsDoesNotSendInit.
// Tests_SRS_SASLLISTENERIMPL_34_012: [If any exception is thrown while the saslHandler handles the sasl mechanisms, this function shall save that exception and shall not create and send the init payload.]
@Test
public void onSaslMechanismHandlerThrowsDoesNotSendInit() throws Exception {
// arrange
final String[] remoteMechanisms = new String[] { "1", "2" };
final String chosenMechanism = "1";
final byte[] initPayload = new byte[] { 0, 0, 0 };
SaslListenerImpl saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getRemoteMechanisms();
result = remoteMechanisms;
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
result = new Exception();
mockedSaslHandler.getInitPayload(chosenMechanism);
result = initPayload;
}
};
// act
saslListener.onSaslMechanisms(mockedSasl, mockedTransport);
// assert
assertNotNull("Expected a saved exception", saslListener.getSavedException());
new Verifications() {
{
mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
times = 1;
mockedSaslHandler.getInitPayload(chosenMechanism);
times = 0;
mockedSasl.send(initPayload, 0, initPayload.length);
times = 0;
}
};
}
Aggregations