@@ -90,18 +90,25 @@ func TestFromUDP(t *testing.T) {
90
90
91
91
func TestThinWaist (t * testing.T ) {
92
92
addrs := map [string ]bool {
93
- "/ip4/127.0.0.1/udp/1234" : true ,
94
- "/ip4/127.0.0.1/tcp/1234" : true ,
95
- "/ip4/127.0.0.1/udp/1234/tcp/1234" : true ,
96
- "/ip4/127.0.0.1/tcp/12345/ip4/1.2.3.4" : true ,
97
- "/ip6/::1/tcp/80" : true ,
98
- "/ip6/::1/udp/80" : true ,
99
- "/ip6/::1" : true ,
100
- "/tcp/1234/ip4/1.2.3.4" : false ,
101
- "/tcp/1234" : false ,
102
- "/tcp/1234/udp/1234" : false ,
103
- "/ip4/1.2.3.4/ip4/2.3.4.5" : true ,
104
- "/ip6/::1/ip4/2.3.4.5" : true ,
93
+ "/ip4/127.0.0.1/udp/1234" : true ,
94
+ "/ip4/127.0.0.1/tcp/1234" : true ,
95
+ "/ip4/127.0.0.1/udp/1234/tcp/1234" : true ,
96
+ "/ip4/127.0.0.1/tcp/12345/ip4/1.2.3.4" : true ,
97
+ "/ip6/::1/tcp/80" : true ,
98
+ "/ip6/::1/udp/80" : true ,
99
+ "/ip6/::1" : true ,
100
+ "/ip6zone/hello/ip6/fe80::1/tcp/80" : true ,
101
+ "/ip6zone/hello/ip6/fe80::1" : true ,
102
+ "/tcp/1234/ip4/1.2.3.4" : false ,
103
+ "/tcp/1234" : false ,
104
+ "/tcp/1234/udp/1234" : false ,
105
+ "/ip4/1.2.3.4/ip4/2.3.4.5" : true ,
106
+ "/ip6/fe80::1/ip4/2.3.4.5" : true ,
107
+ "/ip6zone/hello/ip6/fe80::1/ip4/2.3.4.5" : true ,
108
+
109
+ // Invalid ip6zone usage:
110
+ "/ip6zone/hello" : false ,
111
+ "/ip6zone/hello/ip4/1.1.1.1" : false ,
105
112
}
106
113
107
114
for a , res := range addrs {
@@ -120,7 +127,7 @@ func TestDialArgs(t *testing.T) {
120
127
test := func (e_maddr , e_nw , e_host string ) {
121
128
m , err := ma .NewMultiaddr (e_maddr )
122
129
if err != nil {
123
- t .Fatal ("failed to construct" , "/ip4/127.0.0.1/udp/1234" , e_maddr )
130
+ t .Fatal ("failed to construct" , e_maddr )
124
131
}
125
132
126
133
nw , host , err := DialArgs (m )
@@ -137,14 +144,28 @@ func TestDialArgs(t *testing.T) {
137
144
}
138
145
}
139
146
147
+ test_error := func (e_maddr string ) {
148
+ m , err := ma .NewMultiaddr (e_maddr )
149
+ if err != nil {
150
+ t .Fatal ("failed to construct" , e_maddr )
151
+ }
152
+
153
+ _ , _ , err = DialArgs (m )
154
+ if err == nil {
155
+ t .Fatal ("expected DialArgs to fail on" , e_maddr )
156
+ }
157
+ }
158
+
140
159
test ("/ip4/127.0.0.1/udp/1234" , "udp4" , "127.0.0.1:1234" )
141
160
test ("/ip4/127.0.0.1/tcp/4321" , "tcp4" , "127.0.0.1:4321" )
142
161
test ("/ip6/::1/udp/1234" , "udp6" , "[::1]:1234" )
143
162
test ("/ip6/::1/tcp/4321" , "tcp6" , "[::1]:4321" )
144
- test ("/ip6/::1" , "ip6" , "::1" ) // Just an IP
145
- test ("/ip4/1.2.3.4" , "ip4" , "1.2.3.4" ) // Just an IP
146
- test ("/ip6zone/foo/ip6/::1/tcp/4321" , "tcp6" , "[::1%foo]:4321" ) // zone
147
- test ("/ip6zone/foo/ip6/::1" , "ip6" , "::1%foo" ) // no TCP
148
- test ("/ip6zone/foo/ip6/::1/ip6zone/bar" , "ip6" , "::1%foo" ) // IP over IP
149
- test ("/ip6zone/foo/ip4/127.0.0.1/ip6zone/bar" , "ip4" , "127.0.0.1" ) // Skip zones in IP
163
+ test ("/ip6/::1" , "ip6" , "::1" ) // Just an IP
164
+ test ("/ip4/1.2.3.4" , "ip4" , "1.2.3.4" ) // Just an IP
165
+ test ("/ip6zone/foo/ip6/::1/tcp/4321" , "tcp6" , "[::1%foo]:4321" ) // zone
166
+ test ("/ip6zone/foo/ip6/::1/udp/4321" , "udp6" , "[::1%foo]:4321" ) // zone
167
+ test ("/ip6zone/foo/ip6/::1" , "ip6" , "::1%foo" ) // no TCP
168
+ test_error ("/ip6zone/foo/ip4/127.0.0.1" ) // IP4 doesn't take zone
169
+ test ("/ip6zone/foo/ip6/::1/ip6zone/bar" , "ip6" , "::1%foo" ) // IP over IP
170
+ test_error ("/ip6zone/foo/ip6zone/bar/ip6/::1" ) // Only one zone per IP6
150
171
}
0 commit comments