Socks5Server { public boolean readRequest() throws IOException { checkProtocolVersion(); boolean correct = true; command = Command.fromCommandNumber(in.read()); if (command == null) { correct = false; } if (in.read() != 0x00) { correct = false; } int atype = in.read(); if (atype == ATYPE_IPV4) { readInetAddress(4); } else if (atype == ATYPE_DNS) { readDns(); } else if (atype == ATYPE_IPV6) { readInetAddress(16); } else { correct = false; } port = in.read() << 8 | in.read(); return correct; } Socks5Server(InputStream in, OutputStream out); boolean acceptAuthentication(); boolean readRequest(); void sendReply(ResponseCode response); Command getCommand(); InetAddress getAddress(); String getHostName(); int getPort();  }
@Test(expected = IOException.class) public void testReadRequest_InvalidProtocol_Failure() throws Exception { Socks5Server server = getAuthenticatedSocks5Server((byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01); assertTrue(server.readRequest()); }
@Test(expected = IOException.class) public void testReadRequest_InvalidReserved_Failure() throws Exception { Socks5Server server = getAuthenticatedSocks5Server((byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x10, (byte) 0x01, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01); assertTrue(server.readRequest()); }
@Test public void testReadRequest_InvalidReservedByte_Failure() throws Exception { Socks5Server server = getAuthenticatedSocks5Server((byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x05, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01); assertFalse(server.readRequest()); }
@Test public void testReadRequest_ConnectUnknownProtocol_Failure() throws Exception { Socks5Server server = getAuthenticatedSocks5Server((byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0xA8, (byte) 0xC0, (byte) 0xA8, (byte) 0x01, (byte) 0x01); assertFalse(server.readRequest()); }