-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_test.go
More file actions
67 lines (61 loc) · 1.45 KB
/
request_test.go
File metadata and controls
67 lines (61 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package socks5
import (
"bytes"
"testing"
)
func TestNewClientRequestMessage(t *testing.T) {
tests := []struct {
Version byte
Cmd Command
AddressType AddressType
Address []byte
Port []byte
Error error
Message ClientRequestMessage
}{
{
Version: SOCKS5Version,
Cmd: CommandConnect,
AddressType: TypeIPv4,
Address: []byte{123, 35, 13, 90},
Port: []byte{0x00, 0x50},
Error: nil,
Message: ClientRequestMessage{
Cmd: CommandConnect,
AddressType: TypeIPv4,
Address: "123.35.13.90",
Port: 0x0050,
},
},
{
Version: 0x04,
Cmd: CommandConnect,
AddressType: TypeIPv4,
Address: []byte{123, 35, 13, 90},
Port: []byte{0x00, 0x50},
Error: ErrVersionNotSupported,
Message: ClientRequestMessage{
Cmd: CommandConnect,
AddressType: TypeIPv4,
Address: "123.35.13.90",
Port: 0x0050,
},
},
}
for _, test := range tests {
var buf bytes.Buffer
buf.Write([]byte{test.Version, test.Cmd, ReservedField, test.AddressType})
buf.Write(test.Address)
buf.Write(test.Port)
message, err := NewClientRequestMessage(&buf)
if err != test.Error {
t.Fatalf("should get error %s, but got %s\n", test.Error, err)
}
if err != nil {
return
}
if *message != test.Message {
t.Fatalf("should get message %v, but got %v\n", test.Message, *message)
}
}
}