mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/yusing/go-proxy/internal/types"
|
|
. "github.com/yusing/go-proxy/internal/utils/testing"
|
|
)
|
|
|
|
func TestSetRealIP(t *testing.T) {
|
|
opts := OptionsRaw{
|
|
"header": "X-Real-IP",
|
|
"from": []string{
|
|
"127.0.0.0/8",
|
|
"192.168.0.0/16",
|
|
"172.16.0.0/12",
|
|
},
|
|
"recursive": true,
|
|
}
|
|
optExpected := &realIPOpts{
|
|
Header: "X-Real-IP",
|
|
From: []*types.CIDR{
|
|
{
|
|
IP: net.ParseIP("127.0.0.0"),
|
|
Mask: net.IPv4Mask(255, 0, 0, 0),
|
|
},
|
|
{
|
|
IP: net.ParseIP("192.168.0.0"),
|
|
Mask: net.IPv4Mask(255, 255, 0, 0),
|
|
},
|
|
{
|
|
IP: net.ParseIP("172.16.0.0"),
|
|
Mask: net.IPv4Mask(255, 240, 0, 0),
|
|
},
|
|
},
|
|
Recursive: true,
|
|
}
|
|
|
|
t.Run("set_options", func(t *testing.T) {
|
|
ri, err := RealIP.m.WithOptionsClone(opts)
|
|
ExpectNoError(t, err.Error())
|
|
// ExpectEqual(t, ri.impl.(*realIP).Header, optExpected.Header)
|
|
// ExpectDeepEqual(t, ri.impl.(*realIP).From, optExpected.From)
|
|
// ExpectEqual(t, ri.impl.(*realIP).Recursive, optExpected.Recursive)
|
|
ExpectDeepEqual(t, ri.impl.(*realIP).realIPOpts, optExpected)
|
|
})
|
|
// TODO test
|
|
}
|