2020-09-25 14:39:11 +00:00
|
|
|
package oracle
|
|
|
|
|
|
|
|
import (
|
2022-03-04 11:09:43 +00:00
|
|
|
"errors"
|
2020-09-25 14:39:11 +00:00
|
|
|
"net"
|
2022-03-04 11:09:43 +00:00
|
|
|
"strings"
|
2020-09-25 14:39:11 +00:00
|
|
|
"testing"
|
2022-03-04 11:09:43 +00:00
|
|
|
"time"
|
2020-09-25 14:39:11 +00:00
|
|
|
|
2022-03-04 11:09:43 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2020-09-25 14:39:11 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsReserved(t *testing.T) {
|
|
|
|
require.True(t, isReserved(net.IPv4zero))
|
|
|
|
require.True(t, isReserved(net.IPv4(10, 0, 0, 1)))
|
|
|
|
require.True(t, isReserved(net.IPv4(192, 168, 0, 1)))
|
|
|
|
require.True(t, isReserved(net.IPv6interfacelocalallnodes))
|
|
|
|
require.True(t, isReserved(net.IPv6loopback))
|
|
|
|
|
|
|
|
require.False(t, isReserved(net.IPv4(8, 8, 8, 8)))
|
|
|
|
}
|
2022-03-04 11:09:43 +00:00
|
|
|
|
|
|
|
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) {
|
2022-09-02 09:21:24 +00:00
|
|
|
_, err := cl.Get(c) //nolint:bodyclose // It errors out and it's a test.
|
2022-03-04 11:09:43 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|