-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathaddrsplosion_test.go
More file actions
92 lines (84 loc) · 2.4 KB
/
Copy pathaddrsplosion_test.go
File metadata and controls
92 lines (84 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package autorelay
import (
"testing"
ma "github.com/multiformats/go-multiaddr"
matest "github.com/multiformats/go-multiaddr/matest"
)
func TestCleanupAddrs(t *testing.T) {
t.Run("with no addrplosion", func(t *testing.T) {
addrs := makeAddrList(
"/ip4/127.0.0.1/tcp/4001",
"/ip4/127.0.0.1/udp/4002/quic-v1",
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/udp/4002/quic-v1",
"/dnsaddr/somedomain.com/tcp/4002/ws",
)
clean := makeAddrList(
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/udp/4002/quic-v1",
"/dnsaddr/somedomain.com/tcp/4002/ws",
)
matest.AssertMultiaddrsMatch(t, clean, cleanupAddressSet(addrs))
})
t.Run("with default port", func(t *testing.T) {
// test with default port addrspolosion
addrs := makeAddrList(
"/ip4/127.0.0.1/tcp/4001",
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/tcp/33333",
"/ip4/1.2.3.4/tcp/33334",
"/ip4/1.2.3.4/tcp/33335",
"/ip4/1.2.3.4/udp/4002/quic-v1",
)
clean := makeAddrList(
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/udp/4002/quic-v1",
)
matest.AssertMultiaddrsMatch(t, clean, cleanupAddressSet(addrs))
})
t.Run("with default port, but no private addrs", func(t *testing.T) {
// test with default port addrsplosion but no private addrs
addrs := makeAddrList(
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/tcp/33333",
"/ip4/1.2.3.4/tcp/33334",
"/ip4/1.2.3.4/tcp/33335",
"/ip4/1.2.3.4/udp/4002/quic-v1",
)
clean := makeAddrList(
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/udp/4002/quic-v1",
)
matest.AssertMultiaddrsMatch(t, clean, cleanupAddressSet(addrs))
})
t.Run("with non-standard port", func(t *testing.T) {
addrs := makeAddrList(
"/ip4/127.0.0.1/tcp/12345",
"/ip4/1.2.3.4/tcp/12345",
"/ip4/1.2.3.4/tcp/33333",
"/ip4/1.2.3.4/tcp/33334",
"/ip4/1.2.3.4/tcp/33335",
)
clean := makeAddrList(
"/ip4/1.2.3.4/tcp/12345",
)
if !matest.AssertEqualMultiaddrs(t, clean, cleanupAddressSet(addrs)) {
t.Log("cleaned up set doesn't match expected")
}
})
t.Run("with a clean address set", func(t *testing.T) {
// test with a squeaky clean address set
addrs := makeAddrList(
"/ip4/1.2.3.4/tcp/4001",
"/ip4/1.2.3.4/udp/4001/quic-v1",
)
matest.AssertMultiaddrsMatch(t, addrs, cleanupAddressSet(addrs))
})
}
func makeAddrList(strs ...string) []ma.Multiaddr {
result := make([]ma.Multiaddr, 0, len(strs))
for _, s := range strs {
result = append(result, ma.StringCast(s))
}
return result
}