services: improve Oracle redirection check
Move IP check to later stage and do not resolve URI manually.
This commit is contained in:
parent
537de18ac3
commit
5ace840cc7
3 changed files with 85 additions and 41 deletions
|
@ -1,9 +1,13 @@
|
|||
package oracle
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -16,3 +20,30 @@ func TestIsReserved(t *testing.T) {
|
|||
|
||||
require.False(t, isReserved(net.IPv4(8, 8, 8, 8)))
|
||||
}
|
||||
|
||||
func TestDefaultClient_RestrictedRedirectErr(t *testing.T) {
|
||||
cfg := config.OracleConfiguration{
|
||||
AllowPrivateHost: false,
|
||||
RequestTimeout: time.Second,
|
||||
}
|
||||
cl := getDefaultClient(cfg)
|
||||
|
||||
testCases := []string{
|
||||
"http://localhost:8080",
|
||||
"http://localhost",
|
||||
"https://localhost:443",
|
||||
"https://" + net.IPv4zero.String(),
|
||||
"https://" + net.IPv4(10, 0, 0, 1).String(),
|
||||
"https://" + net.IPv4(192, 168, 0, 1).String(),
|
||||
"https://[" + net.IPv6interfacelocalallnodes.String() + "]",
|
||||
"https://[" + net.IPv6loopback.String() + "]",
|
||||
}
|
||||
for _, c := range testCases {
|
||||
t.Run(c, func(t *testing.T) {
|
||||
_, err := cl.Get(c)
|
||||
require.Error(t, err)
|
||||
require.True(t, errors.Is(err, ErrRestrictedRedirect), err)
|
||||
require.True(t, strings.Contains(err.Error(), "IP is not global unicast"), err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue