1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 11:51:02 -05:00
v2fly/proxy/socks/protocol/socks4_test.go

42 lines
1.2 KiB
Go
Raw Normal View History

2015-09-25 14:48:55 -04:00
package protocol
import (
"bytes"
"testing"
2015-10-08 17:06:12 -04:00
"github.com/v2ray/v2ray-core/common/alloc"
2015-12-02 15:44:01 -05:00
v2net "github.com/v2ray/v2ray-core/common/net"
v2netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
2015-09-25 14:48:55 -04:00
)
func TestSocks4AuthenticationRequestRead(t *testing.T) {
v2testing.Current(t)
2015-09-25 14:48:55 -04:00
rawRequest := []byte{
0x04, // version
0x01, // command
0x00, 0x35,
0x72, 0x72, 0x72, 0x72,
}
_, request4, err := ReadAuthentication(bytes.NewReader(rawRequest))
2015-10-13 07:55:06 -04:00
assert.Error(err).Equals(Socks4Downgrade)
2015-09-25 14:48:55 -04:00
assert.Byte(request4.Version).Named("Version").Equals(0x04)
assert.Byte(request4.Command).Named("Command").Equals(0x01)
2015-12-02 15:44:01 -05:00
v2netassert.Port(request4.Port).Named("Port").Equals(v2net.Port(53))
2015-09-25 14:48:55 -04:00
assert.Bytes(request4.IP[:]).Named("IP").Equals([]byte{0x72, 0x72, 0x72, 0x72})
}
func TestSocks4AuthenticationResponseToBytes(t *testing.T) {
v2testing.Current(t)
2015-09-25 14:48:55 -04:00
2015-11-02 17:55:10 -05:00
response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4})
2015-10-08 17:06:12 -04:00
buffer := alloc.NewSmallBuffer().Clear()
defer buffer.Release()
response.Write(buffer)
assert.Bytes(buffer.Value).Equals([]byte{0x00, 0x10, 0x01, 0xBB, 0x01, 0x02, 0x03, 0x04})
2015-09-25 14:48:55 -04:00
}