"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "gin_test.go" between
gin-1.7.6.tar.gz and gin-1.7.7.tar.gz

About: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API (with much better performance).

gin_test.go  (gin-1.7.6):gin_test.go  (gin-1.7.7)
skipping to change at line 542 skipping to change at line 542
assert.Equal(t, int64(expectValue), handlerCounter) assert.Equal(t, int64(expectValue), handlerCounter)
assert.Equal(t, int64(expectValue), middlewareCounter) assert.Equal(t, int64(expectValue), middlewareCounter)
} }
func TestPrepareTrustedCIRDsWith(t *testing.T) { func TestPrepareTrustedCIRDsWith(t *testing.T) {
r := New() r := New()
// valid ipv4 cidr // valid ipv4 cidr
{ {
expectedTrustedCIDRs := []*net.IPNet{parseCIDR("0.0.0.0/0")} expectedTrustedCIDRs := []*net.IPNet{parseCIDR("0.0.0.0/0")}
r.TrustedProxies = []string{"0.0.0.0/0"} err := r.SetTrustedProxies([]string{"0.0.0.0/0"})
trustedCIDRs, err := r.prepareTrustedCIDRs()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedTrustedCIDRs, trustedCIDRs) assert.Equal(t, expectedTrustedCIDRs, r.trustedCIDRs)
} }
// invalid ipv4 cidr // invalid ipv4 cidr
{ {
r.TrustedProxies = []string{"192.168.1.33/33"} err := r.SetTrustedProxies([]string{"192.168.1.33/33"})
_, err := r.prepareTrustedCIDRs()
assert.Error(t, err) assert.Error(t, err)
} }
// valid ipv4 address // valid ipv4 address
{ {
expectedTrustedCIDRs := []*net.IPNet{parseCIDR("192.168.1.33/32") } expectedTrustedCIDRs := []*net.IPNet{parseCIDR("192.168.1.33/32") }
r.TrustedProxies = []string{"192.168.1.33"}
trustedCIDRs, err := r.prepareTrustedCIDRs() err := r.SetTrustedProxies([]string{"192.168.1.33"})
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedTrustedCIDRs, trustedCIDRs) assert.Equal(t, expectedTrustedCIDRs, r.trustedCIDRs)
} }
// invalid ipv4 address // invalid ipv4 address
{ {
r.TrustedProxies = []string{"192.168.1.256"} err := r.SetTrustedProxies([]string{"192.168.1.256"})
_, err := r.prepareTrustedCIDRs()
assert.Error(t, err) assert.Error(t, err)
} }
// valid ipv6 address // valid ipv6 address
{ {
expectedTrustedCIDRs := []*net.IPNet{parseCIDR("2002:0000:0000:12 34:abcd:ffff:c0a8:0101/128")} expectedTrustedCIDRs := []*net.IPNet{parseCIDR("2002:0000:0000:12 34:abcd:ffff:c0a8:0101/128")}
r.TrustedProxies = []string{"2002:0000:0000:1234:abcd:ffff:c0a8:0 err := r.SetTrustedProxies([]string{"2002:0000:0000:1234:abcd:fff
101"} f:c0a8:0101"})
trustedCIDRs, err := r.prepareTrustedCIDRs()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedTrustedCIDRs, trustedCIDRs) assert.Equal(t, expectedTrustedCIDRs, r.trustedCIDRs)
} }
// invalid ipv6 address // invalid ipv6 address
{ {
r.TrustedProxies = []string{"gggg:0000:0000:1234:abcd:ffff:c0a8:0 err := r.SetTrustedProxies([]string{"gggg:0000:0000:1234:abcd:fff
101"} f:c0a8:0101"})
_, err := r.prepareTrustedCIDRs()
assert.Error(t, err) assert.Error(t, err)
} }
// valid ipv6 cidr // valid ipv6 cidr
{ {
expectedTrustedCIDRs := []*net.IPNet{parseCIDR("::/0")} expectedTrustedCIDRs := []*net.IPNet{parseCIDR("::/0")}
r.TrustedProxies = []string{"::/0"} err := r.SetTrustedProxies([]string{"::/0"})
trustedCIDRs, err := r.prepareTrustedCIDRs()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedTrustedCIDRs, trustedCIDRs) assert.Equal(t, expectedTrustedCIDRs, r.trustedCIDRs)
} }
// invalid ipv6 cidr // invalid ipv6 cidr
{ {
r.TrustedProxies = []string{"gggg:0000:0000:1234:abcd:ffff:c0a8:0 err := r.SetTrustedProxies([]string{"gggg:0000:0000:1234:abcd:fff
101/129"} f:c0a8:0101/129"})
_, err := r.prepareTrustedCIDRs()
assert.Error(t, err) assert.Error(t, err)
} }
// valid combination // valid combination
{ {
expectedTrustedCIDRs := []*net.IPNet{ expectedTrustedCIDRs := []*net.IPNet{
parseCIDR("::/0"), parseCIDR("::/0"),
parseCIDR("192.168.0.0/16"), parseCIDR("192.168.0.0/16"),
parseCIDR("172.16.0.1/32"), parseCIDR("172.16.0.1/32"),
} }
r.TrustedProxies = []string{ err := r.SetTrustedProxies([]string{
"::/0", "::/0",
"192.168.0.0/16", "192.168.0.0/16",
"172.16.0.1", "172.16.0.1",
} })
trustedCIDRs, err := r.prepareTrustedCIDRs()
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedTrustedCIDRs, trustedCIDRs) assert.Equal(t, expectedTrustedCIDRs, r.trustedCIDRs)
} }
// invalid combination // invalid combination
{ {
r.TrustedProxies = []string{ err := r.SetTrustedProxies([]string{
"::/0", "::/0",
"192.168.0.0/16", "192.168.0.0/16",
"172.16.0.256", "172.16.0.256",
} })
_, err := r.prepareTrustedCIDRs()
assert.Error(t, err) assert.Error(t, err)
} }
// nil value // nil value
{ {
r.TrustedProxies = nil err := r.SetTrustedProxies(nil)
trustedCIDRs, err := r.prepareTrustedCIDRs()
assert.Nil(t, trustedCIDRs) assert.Nil(t, r.trustedCIDRs)
assert.Nil(t, err) assert.Nil(t, err)
} }
} }
func parseCIDR(cidr string) *net.IPNet { func parseCIDR(cidr string) *net.IPNet {
_, parsedCIDR, err := net.ParseCIDR(cidr) _, parsedCIDR, err := net.ParseCIDR(cidr)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
 End of changes. 20 change blocks. 
41 lines changed or deleted 22 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)