mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-02 23:35:40 -05:00
remove dep on assert lib
This commit is contained in:
@@ -6,26 +6,23 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/net"
|
||||
. "v2ray.com/core/common/protocol/http"
|
||||
. "v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestParseXForwardedFor(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
header := http.Header{}
|
||||
header.Add("X-Forwarded-For", "129.78.138.66, 129.78.64.103")
|
||||
addrs := ParseXForwardedFor(header)
|
||||
assert(len(addrs), Equals, 2)
|
||||
assert(addrs[0].String(), Equals, "129.78.138.66")
|
||||
assert(addrs[1].String(), Equals, "129.78.64.103")
|
||||
if r := cmp.Diff(addrs, []net.Address{net.ParseAddress("129.78.138.66"), net.ParseAddress("129.78.64.103")}); r != "" {
|
||||
t.Error(r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHopByHopHeadersRemoving(t *testing.T) {
|
||||
assert := With(t)
|
||||
|
||||
rawRequest := `GET /pkg/net/http/ HTTP/1.1
|
||||
Host: golang.org
|
||||
Connection: keep-alive,Foo, Bar
|
||||
@@ -42,18 +39,44 @@ Accept-Language: de,en;q=0.7,en-us;q=0.3
|
||||
b := bufio.NewReader(strings.NewReader(rawRequest))
|
||||
req, err := http.ReadRequest(b)
|
||||
common.Must(err)
|
||||
assert(req.Header.Get("Foo"), Equals, "foo")
|
||||
assert(req.Header.Get("Bar"), Equals, "bar")
|
||||
assert(req.Header.Get("Connection"), Equals, "keep-alive,Foo, Bar")
|
||||
assert(req.Header.Get("Proxy-Connection"), Equals, "keep-alive")
|
||||
assert(req.Header.Get("Proxy-Authenticate"), Equals, "abc")
|
||||
headers := []struct {
|
||||
Key string
|
||||
Value string
|
||||
}{
|
||||
{
|
||||
Key: "Foo",
|
||||
Value: "foo",
|
||||
},
|
||||
{
|
||||
Key: "Bar",
|
||||
Value: "bar",
|
||||
},
|
||||
{
|
||||
Key: "Connection",
|
||||
Value: "keep-alive,Foo, Bar",
|
||||
},
|
||||
{
|
||||
Key: "Proxy-Connection",
|
||||
Value: "keep-alive",
|
||||
},
|
||||
{
|
||||
Key: "Proxy-Authenticate",
|
||||
Value: "abc",
|
||||
},
|
||||
}
|
||||
for _, header := range headers {
|
||||
if v := req.Header.Get(header.Key); v != header.Value {
|
||||
t.Error("header ", header.Key, " = ", v, " want ", header.Value)
|
||||
}
|
||||
}
|
||||
|
||||
RemoveHopByHopHeaders(req.Header)
|
||||
assert(req.Header.Get("Connection"), IsEmpty)
|
||||
assert(req.Header.Get("Foo"), IsEmpty)
|
||||
assert(req.Header.Get("Bar"), IsEmpty)
|
||||
assert(req.Header.Get("Proxy-Connection"), IsEmpty)
|
||||
assert(req.Header.Get("Proxy-Authenticate"), IsEmpty)
|
||||
|
||||
for _, header := range []string{"Connection", "Foo", "Bar", "Proxy-Connection", "Proxy-Authenticate"} {
|
||||
if v := req.Header.Get(header); v != "" {
|
||||
t.Error("header ", header, " = ", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHost(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user