You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
2 years ago
|
package p2p
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
ma "github.com/multiformats/go-multiaddr"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestGaterBlocking(t *testing.T) {
|
||
|
gater := NewGater(true)
|
||
|
require.NotNil(t, &gater, "%s", &gater)
|
||
|
|
||
|
public, err := ma.NewMultiaddr("/ip4/1.1.1.1/udp/53")
|
||
|
assert.Nil(t, err, "%s", err)
|
||
|
allowed := gater.InterceptAddrDial("somePeer", public)
|
||
|
assert.True(t, allowed, "%b", allowed)
|
||
|
|
||
|
private, err := ma.NewMultiaddr("/ip4/192.168.1.1/tcp/80")
|
||
|
assert.Nil(t, err, "%s", err)
|
||
|
allowed = gater.InterceptAddrDial("somePeer", private)
|
||
|
assert.False(t, allowed, "%b", allowed)
|
||
|
}
|
||
|
|
||
|
func TestGaterNotBlocking(t *testing.T) {
|
||
|
gater := NewGater(false)
|
||
|
require.NotNil(t, &gater, "%s", &gater)
|
||
|
|
||
|
public, err := ma.NewMultiaddr("/ip4/1.1.1.1/udp/53")
|
||
|
assert.Nil(t, err, "%s", err)
|
||
|
allowed := gater.InterceptAddrDial("somePeer", public)
|
||
|
assert.True(t, allowed, "%b", allowed)
|
||
|
|
||
|
private, err := ma.NewMultiaddr("/ip4/192.168.1.1/tcp/80")
|
||
|
assert.Nil(t, err, "%s", err)
|
||
|
allowed = gater.InterceptAddrDial("somePeer", private)
|
||
|
assert.True(t, allowed, "%b", allowed)
|
||
|
}
|