I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects

Test Socks4Client

Closed LoveIsGrief requested to merge loveisgrief/i2p.i2p:test-socks4-client into master
2 unresolved threads

Confirms that the SOCKS4a CONNECT spec was implemented correctly. Once the format of the tests is confirmed and the MR merged, the SOCKS5 client and then the server components can be tested - that is, if the server doesn't make too much use of private static variables.

Mirror MR on gitlab with CI pipeline

Edited by zzz

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
3 import org.junit.Test;
4 import org.mockito.Mockito;
5 import sun.net.util.IPAddressUtil;
6
7 import java.io.ByteArrayInputStream;
8 import java.io.ByteArrayOutputStream;
9 import java.io.DataOutputStream;
10 import java.io.IOException;
11 import java.net.Socket;
12 import java.nio.charset.StandardCharsets;
13
14 import static net.i2p.socks.SOCKS4Constants.SOCKS_VERSION_4;
15 import static org.junit.Assert.assertArrayEquals;
16 import static org.junit.Assert.assertThrows;
17
18 public class SOCKS4ClientTest {
  • zzz
    zzz @zzz started a thread on the diff
  • 82 writerStream.writeShort(connectionPort);
    83 writerStream.write(new byte[]{0,0,0,1}); // 0.0.0.1
    84 writerStream.write((byte) 0); // empty userID
    85 writerStream.write(host.getBytes(StandardCharsets.ISO_8859_1));
    86 writerStream.write((byte) 0);
    87
    88 ByteArrayInputStream ips = new ByteArrayInputStream(new byte[]{
    89 0, // dummy
    90 SOCKS4Constants.Reply.SUCCEEDED, // Connection succeeded
    91 0, 0, 0, 0, 0, 0 // filler
    92 });
    93 ByteArrayOutputStream ops = new ByteArrayOutputStream();
    94
    95 SOCKS4Client.connect(ips, ops, host, connectionPort);
    96 assertArrayEquals(expectedByteStream.toByteArray(), ops.toByteArray());
    97 }
    • Maintainer

      You're not closing the socket or streams here as the SOCKS4Client javadocs say you should. I guess it doesn't really matter because they are BAIS/BAOS or a mocked socket, but it's still good practice to close everything in a finally{} block. This also applies to all the other tests below.

    • Author Contributor

      Even though it doesn't really, would you like me to do it anyway?

    • Maintainer

      lets ask @zlatinb

    • Agreed re closing the all streams, either in a finally or in an @After method. That protects us from future bugs in the class under test that would only become visible if the streams are not closed.

    • Author Contributor

      Modified. Used @After and try/finally where necessary in 1c1b1e87.

      Could you please review the changes?

      Edited by LoveIsGrief
    • Maintainer

      you're still not closing the socket or the input stream.

    • Please register or sign in to reply
  • Maintainer

    Also please look at the comments at the bottom of recently-merged MR !15 (merged) about how the mocking dependencies weren't added to build.xml. let's make sure this one gets tested before merging.

  • Ghost User added 2 commits

    added 2 commits

    • c42390d9 - Add @since to SOCKS4ClientTest
    • 1c1b1e87 - Close streams in SOCKS4ClientTest

    Compare with previous version

  • Maintainer

    closing, no response

  • closed

  • Please register or sign in to reply
    Loading