Package org.jivesoftware.smackx.bytestreams.socks5

Examples of org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiatorTest


        streamHost.setPort(socks5Proxy.getPort());

        // create digest to get the socket opened by target
        String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

        Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
                        connection, sessionID, targetJID);

        try {

            socks5Client.getSocket(10000);

            fail("exception should be thrown");
        }
        catch (XMPPException e) {
            assertTrue(e.getMessage().contains("activating SOCKS5 Bytestream failed"));
View Full Code Here


        streamHost.setPort(socks5Proxy.getPort());

        // create digest to get the socket opened by target
        String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

        Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest,
                        connection, sessionID, targetJID);

        Socket initiatorSocket = socks5Client.getSocket(10000);
        InputStream in = initiatorSocket.getInputStream();

        Socket targetSocket = socks5Proxy.getSocket(digest);
        OutputStream out = targetSocket.getOutputStream();
View Full Code Here

     */
    @Test
    public void shouldBeASingleton() {
        SmackConfiguration.setLocalSocks5ProxyEnabled(false);

        Socks5Proxy proxy1 = Socks5Proxy.getSocks5Proxy();
        Socks5Proxy proxy2 = Socks5Proxy.getSocks5Proxy();

        assertNotNull(proxy1);
        assertNotNull(proxy2);
        assertSame(proxy1, proxy2);
    }
View Full Code Here

     * The SOCKS5 proxy should not be started if disabled by configuration.
     */
    @Test
    public void shouldNotBeRunningIfDisabled() {
        SmackConfiguration.setLocalSocks5ProxyEnabled(false);
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
        assertFalse(proxy.isRunning());
    }
View Full Code Here

     * @throws Exception should not happen
     */
    @Test
    public void shouldUseFreePortOnNegativeValues() throws Exception {
        SmackConfiguration.setLocalSocks5ProxyEnabled(false);
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
        assertFalse(proxy.isRunning());

        ServerSocket serverSocket = new ServerSocket(0);
        SmackConfiguration.setLocalSocks5ProxyPort(-serverSocket.getLocalPort());

        proxy.start();

        assertTrue(proxy.isRunning());

        serverSocket.close();

        assertTrue(proxy.getPort() > serverSocket.getLocalPort());

    }
View Full Code Here

     * When inserting new network addresses to the proxy the order should remain in the order they
     * were inserted.
     */
    @Test
    public void shouldPreserveAddressOrderOnInsertions() {
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
        List<String> addresses = new ArrayList<String>(proxy.getLocalAddresses());
        addresses.add("1");
        addresses.add("2");
        addresses.add("3");
        for (String address : addresses) {
            proxy.addLocalAddress(address);
        }

        List<String> localAddresses = proxy.getLocalAddresses();
        for (int i = 0; i < addresses.size(); i++) {
            assertEquals(addresses.get(i), localAddresses.get(i));
        }
    }
View Full Code Here

     * When replacing network addresses of the proxy the order should remain in the order if the
     * given list.
     */
    @Test
    public void shouldPreserveAddressOrderOnReplace() {
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
        List<String> addresses = new ArrayList<String>(proxy.getLocalAddresses());
        addresses.add("1");
        addresses.add("2");
        addresses.add("3");

        proxy.replaceLocalAddresses(addresses);

        List<String> localAddresses = proxy.getLocalAddresses();
        for (int i = 0; i < addresses.size(); i++) {
            assertEquals(addresses.get(i), localAddresses.get(i));
        }
    }
View Full Code Here

     * Inserting the same address multiple times should not cause the proxy to return this address
     * multiple times.
     */
    @Test
    public void shouldNotReturnMultipleSameAddress() {
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();

        proxy.addLocalAddress("same");
        proxy.addLocalAddress("same");
        proxy.addLocalAddress("same");

        assertEquals(2, proxy.getLocalAddresses().size());
    }
View Full Code Here

    @Test
    public void shouldOnlyStartOneServerThread() {
        int threadCount = Thread.activeCount();

        SmackConfiguration.setLocalSocks5ProxyPort(7890);
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
        proxy.start();

        assertTrue(proxy.isRunning());
        assertEquals(threadCount + 1, Thread.activeCount());

        proxy.start();

        assertTrue(proxy.isRunning());
        assertEquals(threadCount + 1, Thread.activeCount());

        proxy.stop();

        assertFalse(proxy.isRunning());
        assertEquals(threadCount, Thread.activeCount());

        proxy.start();

        assertTrue(proxy.isRunning());
        assertEquals(threadCount + 1, Thread.activeCount());

        proxy.stop();

    }
View Full Code Here

     * @throws Exception should not happen
     */
    @Test
    public void shouldCloseSocketIfNoSocks5Request() throws Exception {
        SmackConfiguration.setLocalSocks5ProxyPort(7890);
        Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
        proxy.start();

        Socket socket = new Socket(proxy.getLocalAddresses().get(0), proxy.getPort());

        OutputStream out = socket.getOutputStream();
        out.write(new byte[] { 1, 2, 3 });

        assertEquals(-1, socket.getInputStream().read());

        proxy.stop();

    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiatorTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.