-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrequest_test.go
More file actions
77 lines (68 loc) · 1.59 KB
/
request_test.go
File metadata and controls
77 lines (68 loc) · 1.59 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
68
69
70
71
72
73
74
75
76
77
package socks
import (
"bytes"
"encoding/hex"
"testing"
)
func TestMarshalUnmarshalDomain(t *testing.T) {
b := []byte{
VERSION, // Socks version
byte(CONNECT), // Command
0x0, // Reserved
byte(DOMAIN), // Addr type
0x9, // Addr length
}
b = append(b, []byte("google.se")...) // Destination Addr
b = append(b, 0, 80) // Port
r, err := Unmarshal(b)
if err != nil {
t.Error(err)
}
if r.Ver != VERSION {
t.Error("Invalid socks version:", r.Ver)
}
if r.Cmd != CONNECT {
t.Error("Invalid cmd:", r.Cmd)
}
if r.Atyp != DOMAIN {
t.Error("Invalid atyp:", r.Atyp)
}
if !bytes.Equal(r.Addr, []byte("google.se")) {
t.Error("Invalid addr:", string(r.Addr))
}
m := Marshal(&r)
if bytes.Equal(m, b) != true {
t.Logf("Original:\n%s\n", hex.Dump(b))
t.Logf("Marshalled:\n%s\n", hex.Dump(m))
t.Error("Marshalled bytes does not match original bytes")
}
}
func TestMarshallUnmarshalIP(t *testing.T) {
b := []byte{
VERSION, // Socks version
byte(CONNECT), // Command
0x0, // Reserved
byte(IPV4), // Addr type
0x8, 0x8, 0x8, 0x8, // IPv4 address
0x0, 0x80, // Port
}
r, err := Unmarshal(b)
if err != nil {
t.Error(err)
}
if !bytes.Equal(r.Addr, []byte{0x8, 0x8, 0x8, 0x8}) {
t.Error("Invalid addr:", r.Addr)
}
}
func TestIntToBytesToInt(t *testing.T) {
b := []byte{0, 80}
i := uint16(80)
r := IntToBytes(i)
if !bytes.Equal(r, b) {
t.Logf("%v != %v", b, r)
t.Error("Bytes not equal for port 80")
}
if BytesToInt(r) != i {
t.Error("Could not convert bytes back to int")
}
}