mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
Included more namesys tests.
Fixed some issues with trailing slashes. License: MIT Signed-off-by: Jakub (Kubuxu) Sztandera <kubuxu@gmail.com>
This commit is contained in:
parent
85774b89d3
commit
bcfb3d7224
@ -61,7 +61,7 @@ func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path,
|
||||
p, err := parseEntry(t)
|
||||
if err == nil {
|
||||
if len(segments) > 1 {
|
||||
return path.FromSegments(p.String() + "/", segments[1])
|
||||
return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[1])
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ func TestDnsEntryParsing(t *testing.T) {
|
||||
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo",
|
||||
"dnslink=/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/bar",
|
||||
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo/bar/baz",
|
||||
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo/bar/baz/",
|
||||
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
|
||||
}
|
||||
|
||||
@ -93,6 +94,12 @@ func newMockDNS() *mockDNS {
|
||||
"withrecsegment.example.com": []string{
|
||||
"dnslink=/ipns/withsegment.example.com/subsub",
|
||||
},
|
||||
"withtrailing.example.com": []string{
|
||||
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/",
|
||||
},
|
||||
"withtrailingrec.example.com": []string{
|
||||
"dnslink=/ipns/withtrailing.example.com/segment/",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -118,4 +125,8 @@ func TestDNSResolution(t *testing.T) {
|
||||
testResolution(t, r, "bad.example.com", DefaultDepthLimit, "", ErrResolveFailed)
|
||||
testResolution(t, r, "withsegment.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment", nil)
|
||||
testResolution(t, r, "withrecsegment.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub", nil)
|
||||
testResolution(t, r, "withsegment.example.com/test1", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/test1", nil)
|
||||
testResolution(t, r, "withrecsegment.example.com/test2", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub/test2", nil)
|
||||
testResolution(t, r, "withrecsegment.example.com/test3/", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub/test3/", nil)
|
||||
testResolution(t, r, "withtrailingrec.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/", nil)
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
|
||||
p, err := resolver.resolveOnce(ctx, segments[2])
|
||||
if err == nil {
|
||||
if len(segments) > 3 {
|
||||
return path.FromSegments(p.String() + "/", segments[3])
|
||||
return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
|
||||
} else {
|
||||
return p, err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user