-
Notifications
You must be signed in to change notification settings - Fork 3
/
masque_test.go
65 lines (62 loc) · 1.37 KB
/
masque_test.go
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
package led
import (
"net/url"
"testing"
)
func TestParseMasqueTarget(t *testing.T) {
for i, c := range []struct {
url string
addr string
}{
{
url: "https://example.org/.well-known/masque/udp/10.0.0.1/443/",
addr: "10.0.0.1:443",
},
{
url: "https://proxy.example.org:4443/masque?h=10.0.0.1&p=443",
addr: "10.0.0.1:443",
},
{
url: "https://proxy.example.org:4443/masque?10.0.0.1,443",
addr: "10.0.0.1:443",
},
{
url: "https://example.org/.well-known/masque/udp/2001%3Adb8%3A%3A1/443/",
addr: "[2001:db8::1]:443",
},
{
url: "https://proxy.example.org:4443/masque?h=2001%3Adb8%3A%3A1&p=443",
addr: "[2001:db8::1]:443",
},
{
url: "https://proxy.example.org:4443/masque?2001%3Adb8%3A%3A1,443",
addr: "[2001:db8::1]:443",
},
{
url: "https://example.org/.well-known/masque/udp/example.com/443/",
addr: "example.com:443",
},
{
url: "https://example.org/.well-known/masque/udp/10.0.0.1/",
addr: "",
},
{
url: "https://proxy.example.org:4443/masque?h=&p=443",
addr: "",
},
{
url: "https://proxy.example.org:4443/masque?",
addr: "",
},
} {
t.Logf("case: %d", i)
u, err := url.Parse(c.url)
if err != nil {
t.Fatal("invalid url case:", err)
}
addr, err := parseMasqueTarget(u)
if c.addr != addr {
t.Fatal("invalid parsed addr, expected:", c.addr, ", got:", addr)
}
}
}