v2ray-core/proxy/socks/protocol/socks4_test.go

40 lines
1000 B
Go
Raw Normal View History

2015-09-25 18:48:55 +00:00
package protocol
import (
"bytes"
"testing"
2016-12-09 10:35:27 +00:00
"v2ray.com/core/common/buf"
2016-08-20 18:55:45 +00:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
2015-09-25 18:48:55 +00:00
)
func TestSocks4AuthenticationRequestRead(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2015-09-25 18:48:55 +00:00
rawRequest := []byte{
0x04, // version
0x01, // command
0x00, 0x35,
0x72, 0x72, 0x72, 0x72,
}
_, request4, err := ReadAuthentication(bytes.NewReader(rawRequest))
2015-10-13 11:55:06 +00:00
assert.Error(err).Equals(Socks4Downgrade)
2016-05-24 19:55:46 +00:00
assert.Byte(request4.Version).Equals(0x04)
assert.Byte(request4.Command).Equals(0x01)
assert.Port(request4.Port).Equals(v2net.Port(53))
assert.Bytes(request4.IP[:]).Equals([]byte{0x72, 0x72, 0x72, 0x72})
2015-09-25 18:48:55 +00:00
}
func TestSocks4AuthenticationResponseToBytes(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2015-09-25 18:48:55 +00:00
2015-11-02 22:55:10 +00:00
response := NewSocks4AuthenticationResponse(byte(0x10), 443, []byte{1, 2, 3, 4})
2015-10-08 21:06:12 +00:00
2016-12-09 11:08:25 +00:00
buffer := buf.NewLocal(2048)
2015-10-08 21:06:12 +00:00
defer buffer.Release()
response.Write(buffer)
2016-12-06 10:03:42 +00:00
assert.Bytes(buffer.Bytes()).Equals([]byte{0x00, 0x10, 0x01, 0xBB, 0x01, 0x02, 0x03, 0x04})
2015-09-25 18:48:55 +00:00
}