socks4_test.go 982 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package protocol
  2. import (
  3. "bytes"
  4. "testing"
  5. "github.com/v2ray/v2ray-core/testing/unit"
  6. )
  7. func TestSocks4AuthenticationRequestRead(t *testing.T) {
  8. assert := unit.Assert(t)
  9. rawRequest := []byte{
  10. 0x04, // version
  11. 0x01, // command
  12. 0x00, 0x35,
  13. 0x72, 0x72, 0x72, 0x72,
  14. }
  15. _, request4, err := ReadAuthentication(bytes.NewReader(rawRequest))
  16. assert.Error(err).HasCode(1000)
  17. assert.Byte(request4.Version).Named("Version").Equals(0x04)
  18. assert.Byte(request4.Command).Named("Command").Equals(0x01)
  19. assert.Uint16(request4.Port).Named("Port").Equals(53)
  20. assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72})
  21. }
  22. func TestSocks4AuthenticationResponseToBytes(t *testing.T) {
  23. assert := unit.Assert(t)
  24. response := &Socks4AuthenticationResponse{
  25. result: byte(0x10),
  26. port: 443,
  27. ip: []byte{1, 2, 3, 4},
  28. }
  29. responseBytes := response.ToBytes(nil)
  30. assert.Bytes(responseBytes).Equals([]byte{0x00, 0x10, 0x01, 0xBB, 0x01, 0x02, 0x03, 0x04})
  31. }