Socks5Server { public boolean acceptAuthentication() throws IOException { checkProtocolVersion(); int numMethods = in.read(); byte[] methods = new byte[numMethods]; in.readFully(methods); boolean success = isSuccess(methods); byte[] reply = new byte[2]; reply[0] = 0x05; if (!success) { reply[1] = (byte) 0xFF; } out.write(reply); return success; } 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 testAuthentication_NotSocks5_Failure() throws Exception { ByteArrayInputStream in = wrapBytes((byte) 0x01, (byte) 0x01, (byte) 0x00); ByteArrayOutputStream out = new ByteArrayOutputStream(); Socks5Server server = new Socks5Server(in, out); server.acceptAuthentication(); }
@Test public void testAuthentication_MultipleMethods_Success() throws Exception { InputStream in = wrapBytes((byte) 0x05, (byte) 0x03, (byte) 0x02, (byte) 0x01, (byte) 0x00); ByteArrayOutputStream out = new ByteArrayOutputStream(); Socks5Server server = new Socks5Server(in, out); assertTrue(server.acceptAuthentication()); assertArrayEquals(new byte[]{0x05, 0x00}, out.toByteArray()); }
@Test public void testAuthentication_UnsupportedAuth() throws Exception { InputStream in = wrapBytes(new byte[] { 0x05, 0x01, 0x02 }); ByteArrayOutputStream out = new ByteArrayOutputStream(); Socks5Server server = new Socks5Server(in, out); assertFalse(server.acceptAuthentication()); assertArrayEquals(new byte[] { 0x05, (byte) 0xFF }, out.toByteArray()); }