Search in sources :

Example 6 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener 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;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 7 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener 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;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 8 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslOutcomeSkippedTest.

// 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 onSaslOutcomeSkippedTest() throws Exception {
    // arrange
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getOutcome();
            result = PN_SASL_SKIPPED;
        }
    };
    // act
    saslListener.onSaslOutcome(mockedSasl, mockedTransport);
    // assert
    new Verifications() {

        {
            mockedSaslHandler.handleOutcome(SaslHandler.SaslOutcome.SYS);
            times = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 9 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslMechanismsTest.

// Tests_SRS_SASLLISTENERIMPL_34_002: [This function shall retrieve the remote mechanisms and give them to the saved saslHandler object to decide which mechanism to use.]
// Tests_SRS_SASLLISTENERIMPL_34_003: [This function shall ask the saved saslHandler object to create the init payload for the chosen sasl mechanism and then send that payload if the init payload is larger than 0 bytes.]
@Test
public void onSaslMechanismsTest() throws Exception {
    // arrange
    final String[] remoteMechanisms = new String[] { "1", "2" };
    final String chosenMechanism = "1";
    final byte[] initPayload = new byte[] { 0, 0, 0 };
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getRemoteMechanisms();
            result = remoteMechanisms;
            mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
            result = chosenMechanism;
            mockedSaslHandler.getInitPayload(chosenMechanism);
            result = initPayload;
        }
    };
    // 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 = 1;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Example 10 with SaslListener

use of org.apache.qpid.proton.engine.SaslListener in project azure-iot-sdk-java by Azure.

the class SaslListenerImplTest method onSaslMechanismsTestWithoutInit.

// Tests_SRS_SASLLISTENERIMPL_34_003: [This function shall ask the saved saslHandler object to create the init payload for the chosen sasl mechanism and then send that payload if the init payload is larger than 0 bytes.]
@Test
public void onSaslMechanismsTestWithoutInit() throws Exception {
    // arrange
    final String[] remoteMechanisms = new String[] { "1", "2" };
    final String chosenMechanism = "1";
    final byte[] initPayload = new byte[0];
    SaslListener saslListener = new SaslListenerImpl(mockedSaslHandler);
    new NonStrictExpectations() {

        {
            mockedSasl.getRemoteMechanisms();
            result = remoteMechanisms;
            mockedSaslHandler.chooseSaslMechanism(remoteMechanisms);
            result = chosenMechanism;
            mockedSaslHandler.getInitPayload(chosenMechanism);
            result = initPayload;
        }
    };
    // 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;
        }
    };
}
Also used : SaslListenerImpl(com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) SaslListener(org.apache.qpid.proton.engine.SaslListener) Test(org.junit.Test)

Aggregations

SaslListenerImpl (com.microsoft.azure.sdk.iot.deps.transport.amqp.SaslListenerImpl)10 NonStrictExpectations (mockit.NonStrictExpectations)10 Verifications (mockit.Verifications)10 SaslListener (org.apache.qpid.proton.engine.SaslListener)10 Test (org.junit.Test)10