Search in sources :

Example 16 with Protocol

use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.

the class Socks5ByteStreamManagerTest method setup.

/**
     * Initialize fields used in the tests.
     * @throws XMPPException 
     * @throws SmackException 
     * @throws InterruptedException 
     */
@Before
public void setup() throws XMPPException, SmackException, InterruptedException {
    // build protocol verifier
    protocol = new Protocol();
    // create mocked XMPP connection
    connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID, xmppServer);
}
Also used : Protocol(org.jivesoftware.util.Protocol) Before(org.junit.Before)

Example 17 with Protocol

use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.

the class Socks5ByteStreamRequestTest method setup.

/**
     * Initialize fields used in the tests.
     * @throws XMPPException 
     * @throws SmackException 
     * @throws InterruptedException 
     */
@Before
public void setup() throws XMPPException, SmackException, InterruptedException {
    // build protocol verifier
    protocol = new Protocol();
    // create mocked XMPP connection
    connection = ConnectionUtils.createMockedConnection(protocol, targetJID, xmppServer);
}
Also used : Protocol(org.jivesoftware.util.Protocol) Before(org.junit.Before)

Example 18 with Protocol

use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.

the class InBandBytestreamSessionTest method setup.

/**
 * Initialize fields used in the tests.
 * @throws XMPPException if an XMPP protocol error was received.
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws InterruptedException if the calling thread was interrupted.
 */
@BeforeEach
public void setup() throws XMPPException, SmackException, InterruptedException {
    // build protocol verifier
    protocol = new Protocol();
    // create mocked XMPP connection
    connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
    // create a In-Band Bytestream open packet
    initBytestream = new Open(sessionID, blockSize);
    initBytestream.setFrom(initiatorJID);
    initBytestream.setTo(targetJID);
    incrementingSequence = new Verification<Data, IQ>() {

        int lastSeq = 0;

        @Override
        public void verify(Data request, IQ response) {
            assertEquals(lastSeq++, request.getDataPacketExtension().getSeq().intValue());
        }
    };
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) Protocol(org.jivesoftware.util.Protocol) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with Protocol

use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.

the class Socks5ByteStreamManagerTest method shouldFailIfTargetDoesNotSupportSocks5.

/**
 * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception
 * if the given target does not support SOCKS5 Bytestream.
 * @throws XMPPException if an XMPP protocol error was received.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws IOException if an I/O error occurred.
 */
@Test
public void shouldFailIfTargetDoesNotSupportSocks5() throws XMPPException, SmackException, InterruptedException, IOException {
    final Protocol protocol = new Protocol();
    final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
    Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
    FeatureNotSupportedException e = assertThrows(FeatureNotSupportedException.class, () -> {
        // build empty discover info as reply if targets features are queried
        DiscoverInfo discoverInfo = DiscoverInfo.builder("disco-1").build();
        protocol.addResponse(discoverInfo);
        // start SOCKS5 Bytestream
        byteStreamManager.establishSession(targetJID);
    });
    assertTrue(e.getFeature().equals("SOCKS5 Bytestream"));
    assertTrue(e.getJid().equals(targetJID));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Protocol(org.jivesoftware.util.Protocol) Test(org.junit.jupiter.api.Test)

Example 20 with Protocol

use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.

the class Socks5ByteStreamManagerTest method shouldFailIfNoSocks5ProxyFound2.

/**
 * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
 * proxy is a SOCKS5 proxy.
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws XMPPException if an XMPP protocol error was received.
 * @throws IOException if an I/O error occurred.
 */
@Test
public void shouldFailIfNoSocks5ProxyFound2() throws SmackException, InterruptedException, IOException, XMPPException {
    final Protocol protocol = new Protocol();
    final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
    final String sessionID = "session_id_shouldFailIfNoSocks5ProxyFound2";
    // get Socks5ByteStreamManager for connection
    Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
    byteStreamManager.setAnnounceLocalStreamHost(false);
    /**
     * create responses in the order they should be queried specified by the XEP-0065
     * specification
     */
    // build discover info that supports the SOCKS5 feature
    DiscoverInfoBuilder discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
    discoverInfo.addFeature(Bytestream.NAMESPACE);
    // return that SOCKS5 is supported if target is queried
    protocol.addResponse(discoverInfo.build(), Verification.correspondingSenderReceiver, Verification.requestTypeGET);
    // build discover items containing a proxy item
    DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID);
    Item item = new Item(proxyJID);
    discoverItems.addItem(item);
    // return the proxy item if XMPP server is queried
    protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
    // build discover info for proxy containing information about NOT being a Socks5
    // proxy
    DiscoverInfoBuilder proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
    Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
    proxyInfo.addIdentity(identity);
    // return the proxy identity if proxy is queried
    protocol.addResponse(proxyInfo.build(), Verification.correspondingSenderReceiver, Verification.requestTypeGET);
    SmackException e = assertThrows(SmackException.class, () -> {
        // start SOCKS5 Bytestream
        byteStreamManager.establishSession(targetJID, sessionID);
    });
    protocol.verifyAll();
    assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
}
Also used : Item(org.jivesoftware.smackx.disco.packet.DiscoverItems.Item) DiscoverInfoBuilder(org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder) SmackException(org.jivesoftware.smack.SmackException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Protocol(org.jivesoftware.util.Protocol) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) Test(org.junit.jupiter.api.Test)

Aggregations

Protocol (org.jivesoftware.util.Protocol)30 XMPPConnection (org.jivesoftware.smack.XMPPConnection)23 Test (org.junit.jupiter.api.Test)23 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)14 IQ (org.jivesoftware.smack.packet.IQ)10 InputStream (java.io.InputStream)9 StreamHost (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost)9 OutputStream (java.io.OutputStream)8 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)8 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)8 SmackException (org.jivesoftware.smack.SmackException)6 Stanza (org.jivesoftware.smack.packet.Stanza)6 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)6 Item (org.jivesoftware.smackx.disco.packet.DiscoverItems.Item)6 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Socket (java.net.Socket)3 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)3 Before (org.junit.Before)3 ServerSocket (java.net.ServerSocket)2