use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslChallengeThrowsDoesNotSendResponseTest.
// Tests_SRS_SASLLISTENERIMPL_34_014: [If any exception is thrown while the saslHandler handles the challenge, this function shall save that exception and shall not send the challenge response.]
@Test
public void onSaslChallengeThrowsDoesNotSendResponseTest() throws Exception {
// arrange
final byte[] challengePayload = new byte[] { 0, 0, 0 };
final byte[] challengeResponsePayload = new byte[] { 1, 1, 1 };
SaslListenerImpl saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.pending();
result = challengePayload.length;
mockedSasl.recv((byte[]) any, 0, challengePayload.length);
mockedSaslHandler.handleChallenge((byte[]) any);
result = new SecurityException();
}
};
// act
saslListener.onSaslChallenge(mockedSasl, mockedTransport);
// assert
assertNotNull(saslListener.getSavedException());
assertEquals(SecurityException.class, saslListener.getSavedException().getClass());
new Verifications() {
{
mockedSasl.recv((byte[]) any, 0, challengePayload.length);
times = 1;
mockedSaslHandler.handleChallenge((byte[]) any);
times = 1;
mockedSasl.send(challengeResponsePayload, 0, challengeResponsePayload.length);
times = 0;
}
};
}
use of com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl in project azure-iot-sdk-java by Azure.
the class SaslListenerImplTest method onSaslOutcomeOkTest.
// Tests_SRS_SASLLISTENERIMPL_34_009: [If the sasl outcome is PN_SASL_OK, this function shall tell the saved saslHandler to handleOutcome with OK.]
@Test
public void onSaslOutcomeOkTest() throws Exception {
// arrange
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_OK;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.OK);
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 onSaslOutcomeAuthTest.
// Tests_SRS_SASLLISTENERIMPL_34_008: [If the sasl outcome is PN_SASL_AUTH, this function shall tell the saved saslHandler to handleOutcome with AUTH.]
@Test
public void onSaslOutcomeAuthTest() throws Exception {
// arrange
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_AUTH;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.AUTH);
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 onSaslOutcomeSysTest.
// Tests_SRS_SASLLISTENERIMPL_34_010: [If the sasl outcome is PN_SASL_SYS or PN_SASL_SKIPPED, this function shall tell the saved saslHandler to handleOutcome with SYS.]
@Test
public void onSaslOutcomeSysTest() throws Exception {
// arrange
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.getOutcome();
result = PN_SASL_SYS;
}
};
// act
saslListener.onSaslOutcome(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS);
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 onSaslChallengeTest.
// Tests_SRS_SASLLISTENERIMPL_34_004: [This function shall retrieve the sasl challenge from the provided sasl object.]
// Tests_SRS_SASLLISTENERIMPL_34_005: [This function shall give the sasl challenge bytes to the saved saslHandler and send the payload it returns.]
@Test
public void onSaslChallengeTest() throws Exception {
// arrange
final byte[] challengePayload = new byte[] { 0, 0, 0 };
final byte[] challengeResponsePayload = new byte[] { 1, 1, 1 };
SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
new NonStrictExpectations() {
{
mockedSasl.pending();
result = challengePayload.length;
mockedSasl.recv((byte[]) any, 0, challengePayload.length);
mockedSaslHandler.handleChallenge((byte[]) any);
result = challengeResponsePayload;
}
};
// act
saslListener.onSaslChallenge(mockedSasl, mockedTransport);
// assert
new Verifications() {
{
mockedSasl.recv((byte[]) any, 0, challengePayload.length);
times = 1;
mockedSaslHandler.handleChallenge((byte[]) any);
times = 1;
mockedSasl.send(challengeResponsePayload, 0, challengeResponsePayload.length);
times = 1;
}
};
}
Aggregations