Package org.jivesoftware.smackx.bytestreams.socks5.packet

Examples of org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream


     * 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

     * @throws Exception should not happen
     */
    @Test
    public void shouldRespondWithErrorIfNoSupportedAuthenticationMethod() 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();

        // request username/password-authentication
        out.write(new byte[] { (byte) 0x05, (byte) 0x01, (byte) 0x02 });

        InputStream in = socket.getInputStream();

        assertEquals((byte) 0x05, (byte) in.read());
        assertEquals((byte) 0xFF, (byte) in.read());

        assertEquals(-1, in.read());

        proxy.stop();

    }
View Full Code Here

     * @throws Exception should not happen
     */
    @Test
    public void shouldRespondWithErrorIfConnectionIsNotAllowed() 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[] { (byte) 0x05, (byte) 0x01, (byte) 0x00 });

        InputStream in = socket.getInputStream();

        assertEquals((byte) 0x05, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read());

        // send valid SOCKS5 message
        out.write(new byte[] { (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x01,
                        (byte) 0xAA, (byte) 0x00, (byte) 0x00 });

        // verify error message
        assertEquals((byte) 0x05, (byte) in.read());
        assertFalse((byte) 0x00 == (byte) in.read()); // something other than 0 == success
        assertEquals((byte) 0x00, (byte) in.read());
        assertEquals((byte) 0x03, (byte) in.read());
        assertEquals((byte) 0x01, (byte) in.read());
        assertEquals((byte) 0xAA, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read());

        assertEquals(-1, in.read());

        proxy.stop();

    }
View Full Code Here

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

        assertTrue(proxy.isRunning());

        String digest = new String(new byte[] { (byte) 0xAA });

        // add digest to allow connection
        proxy.addTransfer(digest);

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

        OutputStream out = socket.getOutputStream();
        out.write(new byte[] { (byte) 0x05, (byte) 0x01, (byte) 0x00 });

        InputStream in = socket.getInputStream();

        assertEquals((byte) 0x05, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read());

        // send valid SOCKS5 message
        out.write(new byte[] { (byte) 0x05, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x01,
                        (byte) 0xAA, (byte) 0x00, (byte) 0x00 });

        // verify response
        assertEquals((byte) 0x05, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read()); // success
        assertEquals((byte) 0x00, (byte) in.read());
        assertEquals((byte) 0x03, (byte) in.read());
        assertEquals((byte) 0x01, (byte) in.read());
        assertEquals((byte) 0xAA, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read());
        assertEquals((byte) 0x00, (byte) in.read());

        Thread.sleep(200);

        Socket remoteSocket = proxy.getSocket(digest);

        // remove digest
        proxy.removeTransfer(digest);

        // test stream
        OutputStream remoteOut = remoteSocket.getOutputStream();
        byte[] data = new byte[] { 1, 2, 3, 4, 5 };
        remoteOut.write(data);
        remoteOut.flush();

        for (int i = 0; i < data.length; i++) {
            assertEquals(data[i], in.read());
        }

        remoteSocket.close();

        assertEquals(-1, in.read());

        proxy.stop();

    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream

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.