protocol_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package shadowsocks_test
  2. import (
  3. "testing"
  4. "github.com/v2ray/v2ray-core/common/alloc"
  5. v2net "github.com/v2ray/v2ray-core/common/net"
  6. netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
  7. . "github.com/v2ray/v2ray-core/proxy/shadowsocks"
  8. v2testing "github.com/v2ray/v2ray-core/testing"
  9. "github.com/v2ray/v2ray-core/testing/assert"
  10. )
  11. func TestNormalRequestParsing(t *testing.T) {
  12. v2testing.Current(t)
  13. buffer := alloc.NewSmallBuffer().Clear()
  14. buffer.AppendBytes(1, 127, 0, 0, 1, 0, 80)
  15. request, err := ReadRequest(buffer)
  16. assert.Error(err).IsNil()
  17. netassert.Address(request.Address).Equals(v2net.IPAddress([]byte{127, 0, 0, 1}))
  18. netassert.Port(request.Port).Equals(v2net.Port(80))
  19. assert.Bool(request.OTA).IsFalse()
  20. }
  21. func TestOTARequest(t *testing.T) {
  22. v2testing.Current(t)
  23. buffer := alloc.NewSmallBuffer().Clear()
  24. buffer.AppendBytes(0x13, 13, 119, 119, 119, 46, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 0)
  25. request, err := ReadRequest(buffer)
  26. assert.Error(err).IsNil()
  27. netassert.Address(request.Address).Equals(v2net.DomainAddress("www.v2ray.com"))
  28. assert.Bool(request.OTA).IsTrue()
  29. }