1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 "golang.org/x/net/internal/socks"
15 func TestParseAuthRequest(t *testing.T) {
16 for i, tt := range []struct {
28 []byte{0x05, 0x01, 0xff},
32 socks.AuthMethodNoAcceptableMethods,
37 []byte{0x05, 0x02, 0x00, 0xff},
41 socks.AuthMethodNotRequired,
42 socks.AuthMethodNoAcceptableMethods,
49 {[]byte{0x00, 0x01}, nil},
50 {[]byte{0x06, 0x00}, nil},
51 {[]byte{0x05, 0x02, 0x00}, nil},
53 req, err := ParseAuthRequest(tt.wire)
54 if !reflect.DeepEqual(req, tt.req) {
55 t.Errorf("#%d: got %v, %v; want %v", i, req, err, tt.req)
61 func TestParseCmdRequest(t *testing.T) {
62 for i, tt := range []struct {
67 []byte{0x05, 0x01, 0x00, 0x01, 192, 0, 2, 1, 0x17, 0x4b},
72 IP: net.IP{192, 0, 2, 1},
78 []byte{0x05, 0x01, 0x00, 0x03, 0x04, 'F', 'Q', 'D', 'N', 0x17, 0x4b},
92 {[]byte{0x06, 0x01, 0x00, 0x01, 192, 0, 2, 2, 0x17, 0x4b}, nil},
93 {[]byte{0x05, 0x01, 0xff, 0x01, 192, 0, 2, 3}, nil},
94 {[]byte{0x05, 0x01, 0x00, 0x01, 192, 0, 2, 4}, nil},
95 {[]byte{0x05, 0x01, 0x00, 0x03, 0x04, 'F', 'Q', 'D', 'N'}, nil},
97 req, err := ParseCmdRequest(tt.wire)
98 if !reflect.DeepEqual(req, tt.req) {
99 t.Errorf("#%d: got %v, %v; want %v", i, req, err, tt.req)