Skip to content

Commit 13b6f58

Browse files
committed
refactor: cleanup isDNSLinkName mess
1 parent c091fd6 commit 13b6f58

File tree

7 files changed

+171
-141
lines changed

7 files changed

+171
-141
lines changed

examples/gateway-car/api.go

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func (api *blocksGateway) ResolvePath(ctx context.Context, p ifacepath.Path) (if
139139
return ifacepath.NewResolvedPath(ipath, node, root, gopath.Join(rest...)), nil
140140
}
141141

142+
func (api *blocksGateway) HasDNSLinkRecord(ctx context.Context, host string) bool {
143+
// Not implemented.
144+
return false
145+
}
146+
142147
func (api *blocksGateway) resolveNode(ctx context.Context, p ifacepath.Path) (format.Node, error) {
143148
rp, err := api.ResolvePath(ctx, p)
144149
if err != nil {

examples/go.mod

-15
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ require (
3535
github.com/go-logr/stdr v1.2.2 // indirect
3636
github.com/gogo/protobuf v1.3.2 // indirect
3737
github.com/golang/protobuf v1.5.2 // indirect
38-
github.com/google/gopacket v1.1.19 // indirect
3938
github.com/google/uuid v1.3.0 // indirect
40-
github.com/hashicorp/errwrap v1.1.0 // indirect
41-
github.com/hashicorp/go-multierror v1.1.1 // indirect
4239
github.com/hashicorp/golang-lru v0.5.4 // indirect
4340
github.com/ipfs/bbloom v0.0.4 // indirect
4441
github.com/ipfs/go-bitfield v1.0.0 // indirect
@@ -55,20 +52,12 @@ require (
5552
github.com/ipfs/go-log v1.0.5 // indirect
5653
github.com/ipfs/go-log/v2 v2.5.1 // indirect
5754
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
58-
github.com/ipfs/go-namesys v0.7.0 // indirect
5955
github.com/ipfs/go-verifcid v0.0.2 // indirect
6056
github.com/ipld/go-car v0.5.0 // indirect
6157
github.com/jbenet/goprocess v0.1.4 // indirect
6258
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
6359
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
64-
github.com/libp2p/go-cidranger v1.1.0 // indirect
6560
github.com/libp2p/go-libp2p v0.23.4 // indirect
66-
github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect
67-
github.com/libp2p/go-libp2p-kad-dht v0.19.0 // indirect
68-
github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect
69-
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
70-
github.com/libp2p/go-msgio v0.2.0 // indirect
71-
github.com/libp2p/go-netroute v0.2.0 // indirect
7261
github.com/libp2p/go-openssl v0.1.0 // indirect
7362
github.com/mattn/go-isatty v0.0.17 // indirect
7463
github.com/mattn/go-pointer v0.0.1 // indirect
@@ -79,7 +68,6 @@ require (
7968
github.com/multiformats/go-base32 v0.1.0 // indirect
8069
github.com/multiformats/go-base36 v0.2.0 // indirect
8170
github.com/multiformats/go-multiaddr v0.8.0 // indirect
82-
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
8371
github.com/multiformats/go-multibase v0.1.1 // indirect
8472
github.com/multiformats/go-multicodec v0.7.0 // indirect
8573
github.com/multiformats/go-multihash v0.2.1 // indirect
@@ -96,11 +84,8 @@ require (
9684
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
9785
github.com/spaolacci/murmur3 v1.1.0 // indirect
9886
github.com/ucarion/urlpath v0.0.0-20200424170820-7ccc79b76bbb // indirect
99-
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
10087
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect
10188
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect
102-
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
103-
go.opencensus.io v0.23.0 // indirect
10489
go.opentelemetry.io/otel v1.12.0 // indirect
10590
go.opentelemetry.io/otel/trace v1.12.0 // indirect
10691
go.uber.org/atomic v1.10.0 // indirect

examples/go.sum

-43
Large diffs are not rendered by default.

gateway/gateway.go

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ type API interface {
3939
// exist due to a missing link, it should return an error of type:
4040
// https://pkg.go.dev/github.com/ipfs/[email protected]/resolver#ErrNoLink
4141
ResolvePath(context.Context, path.Path) (path.Resolved, error)
42+
43+
// HasDNSLinkRecord returns if the provided path has a DNSLink TXT record.
44+
// It does not perform any validation, only checks for the existence of
45+
// a DNSLink TXT record.
46+
HasDNSLinkRecord(context.Context, string) bool
4247
}
4348

4449
// A helper function to clean up a set of headers:

gateway/gateway_test.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package gateway
2+
3+
import (
4+
"context"
5+
"errors"
6+
"strings"
7+
8+
cid "github.com/ipfs/go-cid"
9+
"github.com/ipfs/go-libipfs/blocks"
10+
"github.com/ipfs/go-libipfs/files"
11+
"github.com/ipfs/go-namesys"
12+
path "github.com/ipfs/go-path"
13+
iface "github.com/ipfs/interface-go-ipfs-core"
14+
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
15+
ipath "github.com/ipfs/interface-go-ipfs-core/path"
16+
"github.com/libp2p/go-libp2p/core/crypto"
17+
)
18+
19+
type mockNamesys map[string]path.Path
20+
21+
func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.ResolveOpt) (value path.Path, err error) {
22+
cfg := nsopts.DefaultResolveOpts()
23+
for _, o := range opts {
24+
o(&cfg)
25+
}
26+
depth := cfg.Depth
27+
if depth == nsopts.UnlimitedDepth {
28+
// max uint
29+
depth = ^uint(0)
30+
}
31+
for strings.HasPrefix(name, "/ipns/") {
32+
if depth == 0 {
33+
return value, namesys.ErrResolveRecursion
34+
}
35+
depth--
36+
37+
var ok bool
38+
value, ok = m[name]
39+
if !ok {
40+
return "", namesys.ErrResolveFailed
41+
}
42+
name = value.String()
43+
}
44+
return value, nil
45+
}
46+
47+
func (m mockNamesys) ResolveAsync(ctx context.Context, name string, opts ...nsopts.ResolveOpt) <-chan namesys.Result {
48+
out := make(chan namesys.Result, 1)
49+
v, err := m.Resolve(ctx, name, opts...)
50+
out <- namesys.Result{Path: v, Err: err}
51+
close(out)
52+
return out
53+
}
54+
55+
func (m mockNamesys) Publish(ctx context.Context, name crypto.PrivKey, value path.Path, opts ...nsopts.PublishOption) error {
56+
return errors.New("not implemented for mockNamesys")
57+
}
58+
59+
func (m mockNamesys) GetResolver(subs string) (namesys.Resolver, bool) {
60+
return nil, false
61+
}
62+
63+
type mockApi struct {
64+
ns mockNamesys
65+
}
66+
67+
func newMockApi() *mockApi {
68+
return &mockApi{
69+
ns: mockNamesys{},
70+
}
71+
}
72+
73+
func (m *mockApi) GetUnixFsNode(context.Context, ipath.Resolved) (files.Node, error) {
74+
return nil, errors.New("not implemented")
75+
}
76+
77+
func (m *mockApi) LsUnixFsDir(context.Context, ipath.Resolved) (<-chan iface.DirEntry, error) {
78+
return nil, errors.New("not implemented")
79+
}
80+
81+
func (m *mockApi) GetBlock(context.Context, cid.Cid) (blocks.Block, error) {
82+
return nil, errors.New("not implemented")
83+
}
84+
85+
func (m *mockApi) GetIPNSRecord(context.Context, cid.Cid) ([]byte, error) {
86+
return nil, errors.New("not implemented")
87+
}
88+
89+
func (m *mockApi) IsCached(context.Context, ipath.Path) bool {
90+
return false
91+
}
92+
93+
func (m *mockApi) ResolvePath(context.Context, ipath.Path) (ipath.Resolved, error) {
94+
return nil, errors.New("not implemented")
95+
}
96+
97+
func (m *mockApi) HasDNSLinkRecord(ctx context.Context, hostname string) bool {
98+
_, err := m.ns.Resolve(ctx, "/ipns/"+hostname, nsopts.Depth(1))
99+
return err == nil || err == namesys.ErrResolveRecursion
100+
}

gateway/hostname.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"strings"
1111

1212
cid "github.com/ipfs/go-cid"
13-
"github.com/ipfs/go-namesys"
14-
"github.com/ipfs/interface-go-ipfs-core/path"
1513
"github.com/libp2p/go-libp2p/core/peer"
1614
dns "github.com/miekg/dns"
1715

@@ -113,7 +111,7 @@ func WithHostname(next http.Handler, api API, publicGateways map[string]*Specifi
113111
// Not a whitelisted path
114112

115113
// Try DNSLink, if it was not explicitly disabled for the hostname
116-
if !gw.NoDNSLink && isDNSLinkName(r.Context(), api, host) {
114+
if !gw.NoDNSLink && hasDNSLinkRecord(r.Context(), api, host) {
117115
// rewrite path and handle as DNSLink
118116
r.URL.Path = "/ipns/" + stripPort(host) + r.URL.Path
119117
next.ServeHTTP(w, withHostnameContext(r, host))
@@ -184,7 +182,6 @@ func WithHostname(next http.Handler, api API, publicGateways map[string]*Specifi
184182
}
185183
}
186184
} else { // rootID is not a CID..
187-
188185
// Check if rootID is a single DNS label with an inlined
189186
// DNSLink FQDN a single DNS label. We support this so
190187
// loading DNSLink names over TLS "just works" on public
@@ -200,10 +197,10 @@ func WithHostname(next http.Handler, api API, publicGateways map[string]*Specifi
200197
// https://my-v--long-example-com.ipns.dweb.link
201198
if ns == "ipns" && !strings.Contains(rootID, ".") {
202199
// if there is no TXT recordfor rootID
203-
if !isDNSLinkName(r.Context(), api, rootID) {
200+
if !hasDNSLinkRecord(r.Context(), api, rootID) {
204201
// my-v--long-example-com → my.v-long.example.com
205202
dnslinkFQDN := toDNSLinkFQDN(rootID)
206-
if isDNSLinkName(r.Context(), api, dnslinkFQDN) {
203+
if hasDNSLinkRecord(r.Context(), api, dnslinkFQDN) {
207204
// update path prefix to use real FQDN with DNSLink
208205
pathPrefix = "/ipns/" + dnslinkFQDN
209206
}
@@ -218,13 +215,14 @@ func WithHostname(next http.Handler, api API, publicGateways map[string]*Specifi
218215
next.ServeHTTP(w, withHostnameContext(r, gwHostname))
219216
return
220217
}
218+
221219
// We don't have a known gateway. Fallback on DNSLink lookup
222220

223221
// Wildcard HTTP Host check:
224222
// 1. is wildcard DNSLink enabled (Gateway.NoDNSLink=false)?
225223
// 2. does Host header include a fully qualified domain name (FQDN)?
226224
// 3. does DNSLink record exist in DNS?
227-
if !noDNSLink && isDNSLinkName(r.Context(), api, host) {
225+
if !noDNSLink && hasDNSLinkRecord(r.Context(), api, host) {
228226
// rewrite path and handle as DNSLink
229227
r.URL.Path = "/ipns/" + stripPort(host) + r.URL.Path
230228
ctx := context.WithValue(r.Context(), DNSLinkHostnameKey, host)
@@ -262,18 +260,15 @@ func isDomainNameAndNotPeerID(hostname string) bool {
262260
return ok
263261
}
264262

265-
// isDNSLinkName returns bool if a valid DNS TXT record exist for provided host
266-
func isDNSLinkName(ctx context.Context, api API, host string) bool {
263+
// hasDNSLinkRecord returns if a DNS TXT record exists for the provided host.
264+
func hasDNSLinkRecord(ctx context.Context, api API, host string) bool {
267265
dnslinkName := stripPort(host)
268266

269267
if !isDomainNameAndNotPeerID(dnslinkName) {
270268
return false
271269
}
272270

273-
name := "/ipns/" + dnslinkName
274-
_, err := api.ResolvePath(ctx, path.New(name))
275-
// check if DNSLink exists
276-
return err == nil || err == namesys.ErrResolveRecursion
271+
return api.HasDNSLinkRecord(ctx, dnslinkName)
277272
}
278273

279274
func isSubdomainNamespace(ns string) bool {
@@ -456,7 +451,7 @@ func toSubdomainURL(hostname, path string, r *http.Request, inlineDNSLink bool,
456451
// represented as a single DNS label:
457452
// https://my-v--long-example-com.ipns.dweb.link
458453
if (inlineDNSLink || isHTTPS) && ns == "ipns" && strings.Contains(rootID, ".") {
459-
if isDNSLinkName(r.Context(), api, rootID) {
454+
if hasDNSLinkRecord(r.Context(), api, rootID) {
460455
// my.v-long.example.com → my-v--long-example-com
461456
dnsLabel, err := toDNSLinkDNSLabel(rootID)
462457
if err != nil {

gateway/hostname_test.go

+52-69
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,63 @@ import (
77
"testing"
88

99
cid "github.com/ipfs/go-cid"
10+
path "github.com/ipfs/go-path"
1011
)
1112

12-
// import (
13-
// "errors"
14-
// "net/http"
15-
// "net/http/httptest"
16-
// "testing"
13+
func TestToSubdomainURL(t *testing.T) {
14+
gwAPI := newMockApi()
15+
testCID, err := cid.Decode("bafkqaglimvwgy3zakrsxg5cun5jxkyten5wwc2lokvjeycq")
16+
if err != nil {
17+
t.Fatal(err)
18+
}
19+
20+
gwAPI.ns["/ipns/dnslink.long-name.example.com"] = path.FromString(testCID.String())
21+
gwAPI.ns["/ipns/dnslink.too-long.f1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5o.example.com"] = path.FromString(testCID.String())
22+
httpRequest := httptest.NewRequest("GET", "http://127.0.0.1:8080", nil)
23+
httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil)
24+
httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil)
25+
httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https")
1726

18-
// cid "github.com/ipfs/go-cid"
19-
// "github.com/ipfs/go-libipfs/files"
20-
// path "github.com/ipfs/go-path"
21-
// config "github.com/ipfs/kubo/config"
22-
// coreapi "github.com/ipfs/kubo/core/coreapi"
23-
// )
27+
for _, test := range []struct {
28+
// in:
29+
request *http.Request
30+
gwHostname string
31+
inlineDNSLink bool
32+
path string
33+
// out:
34+
url string
35+
err error
36+
}{
2437

25-
// func TestToSubdomainURL(t *testing.T) {
26-
// ns := mockNamesys{}
27-
// n, err := newNodeWithMockNamesys(ns)
28-
// if err != nil {
29-
// t.Fatal(err)
30-
// }
31-
// coreAPI, err := coreapi.NewCoreAPI(n)
32-
// if err != nil {
33-
// t.Fatal(err)
34-
// }
35-
// testCID, err := coreAPI.Unixfs().Add(n.Context(), files.NewBytesFile([]byte("fnord")))
36-
// if err != nil {
37-
// t.Fatal(err)
38-
// }
39-
// ns["/ipns/dnslink.long-name.example.com"] = path.FromString(testCID.String())
40-
// ns["/ipns/dnslink.too-long.f1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5o.example.com"] = path.FromString(testCID.String())
41-
// httpRequest := httptest.NewRequest("GET", "http://127.0.0.1:8080", nil)
42-
// httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil)
43-
// httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil)
44-
// httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https")
38+
// DNSLink
39+
{httpRequest, "localhost", false, "/ipns/dnslink.io", "http://dnslink.io.ipns.localhost/", nil},
40+
// Hostname with port
41+
{httpRequest, "localhost:8080", false, "/ipns/dnslink.io", "http://dnslink.io.ipns.localhost:8080/", nil},
42+
// CIDv0 → CIDv1base32
43+
{httpRequest, "localhost", false, "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.localhost/", nil},
44+
// CIDv1 with long sha512
45+
{httpRequest, "localhost", false, "/ipfs/bafkrgqe3ohjcjplc6n4f3fwunlj6upltggn7xqujbsvnvyw764srszz4u4rshq6ztos4chl4plgg4ffyyxnayrtdi5oc4xb2332g645433aeg", "", errors.New("CID incompatible with DNS label length limit of 63: kf1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5oj")},
46+
// PeerID as CIDv1 needs to have libp2p-key multicodec
47+
{httpRequest, "localhost", false, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/", nil},
48+
{httpRequest, "localhost", false, "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm", "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/", nil},
49+
// PeerID: ed25519+identity multihash → CIDv1Base36
50+
{httpRequest, "localhost", false, "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna.ipns.localhost/", nil},
51+
{httpRequest, "sub.localhost", false, "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/", nil},
52+
// HTTPS requires DNSLink name to fit in a single DNS label – see "Option C" from https://github.com/ipfs/in-web-browsers/issues/169
53+
{httpRequest, "dweb.link", false, "/ipns/dnslink.long-name.example.com", "http://dnslink.long-name.example.com.ipns.dweb.link/", nil},
54+
{httpsRequest, "dweb.link", false, "/ipns/dnslink.long-name.example.com", "https://dnslink-long--name-example-com.ipns.dweb.link/", nil},
55+
{httpsProxiedRequest, "dweb.link", false, "/ipns/dnslink.long-name.example.com", "https://dnslink-long--name-example-com.ipns.dweb.link/", nil},
56+
// HTTP requests can also be converted to fit into a single DNS label - https://github.com/ipfs/kubo/issues/9243
57+
{httpRequest, "localhost", true, "/ipns/dnslink.long-name.example.com", "http://dnslink-long--name-example-com.ipns.localhost/", nil},
58+
{httpRequest, "dweb.link", true, "/ipns/dnslink.long-name.example.com", "http://dnslink-long--name-example-com.ipns.dweb.link/", nil},
59+
} {
4560

46-
// for _, test := range []struct {
47-
// // in:
48-
// request *http.Request
49-
// gwHostname string
50-
// inlineDNSLink bool
51-
// path string
52-
// // out:
53-
// url string
54-
// err error
55-
// }{
56-
// // DNSLink
57-
// {httpRequest, "localhost", false, "/ipns/dnslink.io", "http://dnslink.io.ipns.localhost/", nil},
58-
// // Hostname with port
59-
// {httpRequest, "localhost:8080", false, "/ipns/dnslink.io", "http://dnslink.io.ipns.localhost:8080/", nil},
60-
// // CIDv0 → CIDv1base32
61-
// {httpRequest, "localhost", false, "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.localhost/", nil},
62-
// // CIDv1 with long sha512
63-
// {httpRequest, "localhost", false, "/ipfs/bafkrgqe3ohjcjplc6n4f3fwunlj6upltggn7xqujbsvnvyw764srszz4u4rshq6ztos4chl4plgg4ffyyxnayrtdi5oc4xb2332g645433aeg", "", errors.New("CID incompatible with DNS label length limit of 63: kf1siqrebi3vir8sab33hu5vcy008djegvay6atmz91ojesyjs8lx350b7y7i1nvyw2haytfukfyu2f2x4tocdrfa0zgij6p4zpl4u5oj")},
64-
// // PeerID as CIDv1 needs to have libp2p-key multicodec
65-
// {httpRequest, "localhost", false, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/", nil},
66-
// {httpRequest, "localhost", false, "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm", "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/", nil},
67-
// // PeerID: ed25519+identity multihash → CIDv1Base36
68-
// {httpRequest, "localhost", false, "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna.ipns.localhost/", nil},
69-
// {httpRequest, "sub.localhost", false, "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/", nil},
70-
// // HTTPS requires DNSLink name to fit in a single DNS label – see "Option C" from https://github.com/ipfs/in-web-browsers/issues/169
71-
// {httpRequest, "dweb.link", false, "/ipns/dnslink.long-name.example.com", "http://dnslink.long-name.example.com.ipns.dweb.link/", nil},
72-
// {httpsRequest, "dweb.link", false, "/ipns/dnslink.long-name.example.com", "https://dnslink-long--name-example-com.ipns.dweb.link/", nil},
73-
// {httpsProxiedRequest, "dweb.link", false, "/ipns/dnslink.long-name.example.com", "https://dnslink-long--name-example-com.ipns.dweb.link/", nil},
74-
// // HTTP requests can also be converted to fit into a single DNS label - https://github.com/ipfs/kubo/issues/9243
75-
// {httpRequest, "localhost", true, "/ipns/dnslink.long-name.example.com", "http://dnslink-long--name-example-com.ipns.localhost/", nil},
76-
// {httpRequest, "dweb.link", true, "/ipns/dnslink.long-name.example.com", "http://dnslink-long--name-example-com.ipns.dweb.link/", nil},
77-
// } {
78-
// url, err := toSubdomainURL(test.gwHostname, test.path, test.request, test.inlineDNSLink, coreAPI)
79-
// if url != test.url || !equalError(err, test.err) {
80-
// t.Errorf("(%s, %v, %s) returned (%s, %v), expected (%s, %v)", test.gwHostname, test.inlineDNSLink, test.path, url, err, test.url, test.err)
81-
// }
82-
// }
83-
// }
61+
url, err := toSubdomainURL(test.gwHostname, test.path, test.request, test.inlineDNSLink, gwAPI)
62+
if url != test.url || !equalError(err, test.err) {
63+
t.Errorf("(%s, %v, %s) returned (%s, %v), expected (%s, %v)", test.gwHostname, test.inlineDNSLink, test.path, url, err, test.url, test.err)
64+
}
65+
}
66+
}
8467

8568
func TestToDNSLinkDNSLabel(t *testing.T) {
8669
for _, test := range []struct {

0 commit comments

Comments
 (0)