@@ -55,7 +55,7 @@ func TestToSubdomainURL(t *testing.T) {
55
55
{httpRequest , "localhost" , "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD" , "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/" , nil },
56
56
{httpRequest , "localhost" , "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm" , "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/" , nil },
57
57
// PeerID: ed25519+identity multihash → CIDv1Base36
58
- {httpRequest , "localhost" , "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5" , "http://12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5 .ipns.localhost/" , nil },
58
+ {httpRequest , "localhost" , "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5" , "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna .ipns.localhost/" , nil },
59
59
{httpRequest , "sub.localhost" , "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n" , "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/" , nil },
60
60
// HTTPS requires DNSLink name to fit in a single DNS label – see "Option C" from https://github.com/ipfs/in-web-browsers/issues/169
61
61
{httpRequest , "dweb.link" , "/ipns/dnslink.long-name.example.com" , "http://dnslink.long-name.example.com.ipns.dweb.link/" , nil },
@@ -144,6 +144,25 @@ func TestHasPrefix(t *testing.T) {
144
144
}
145
145
}
146
146
147
+ func TestIsDomainNameAndNotPeerID (t * testing.T ) {
148
+ for _ , test := range []struct {
149
+ hostname string
150
+ out bool
151
+ }{
152
+ {"" , false },
153
+ {"example.com" , true },
154
+ {"non-icann.something" , true },
155
+ {".." , false },
156
+ {"12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5" , false }, // valid peerid
157
+ {"k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna" , false }, // valid peerid
158
+ } {
159
+ out := isDomainNameAndNotPeerID (test .hostname )
160
+ if out != test .out {
161
+ t .Errorf ("(%s) returned '%t', expected '%t'" , test .hostname , out , test .out )
162
+ }
163
+ }
164
+ }
165
+
147
166
func TestPortStripping (t * testing.T ) {
148
167
for _ , test := range []struct {
149
168
in string
0 commit comments