@cryptotaxi247 / kubo / commits / bcfb3d722

Included more namesys tests.

Fixed some issues with trailing slashes. License: MIT Signed-off-by: Jakub (Kubuxu) Sztandera <kubuxu@gmail.com>

Jakub (Kubuxu) Sztandera committed Jan 5, 2016 at 18:13 UTC bcfb3d72243ed93fe5592ca65510cb27aec831e2
3 files changed +13 -2
namesys/dns.go
+1 -1
@@ -61,7 +61,7 @@ func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path,
61 p, err := parseEntry(t)
62 if err == nil {
63 if len(segments) > 1 {
64 - return path.FromSegments(p.String() + "/", segments[1])
64 + return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[1])
65 }
66 return p, nil
67 }
namesys/dns_test.go
+11
@@ -26,6 +26,7 @@ func TestDnsEntryParsing(t *testing.T) {
26 "dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo",
27 "dnslink=/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/bar",
28 "dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo/bar/baz",
29 + "dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/foo/bar/baz/",
30 "dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
31 }
32
@@ -93,6 +94,12 @@ func newMockDNS() *mockDNS {
94 "withrecsegment.example.com": []string{
95 "dnslink=/ipns/withsegment.example.com/subsub",
96 },
97 + "withtrailing.example.com": []string{
98 + "dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/",
99 + },
100 + "withtrailingrec.example.com": []string{
101 + "dnslink=/ipns/withtrailing.example.com/segment/",
102 + },
103 },
104 }
105 }
@@ -118,4 +125,8 @@ func TestDNSResolution(t *testing.T) {
125 testResolution(t, r, "bad.example.com", DefaultDepthLimit, "", ErrResolveFailed)
126 testResolution(t, r, "withsegment.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment", nil)
127 testResolution(t, r, "withrecsegment.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub", nil)
128 + testResolution(t, r, "withsegment.example.com/test1", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/test1", nil)
129 + testResolution(t, r, "withrecsegment.example.com/test2", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub/test2", nil)
130 + testResolution(t, r, "withrecsegment.example.com/test3/", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/subsub/test3/", nil)
131 + testResolution(t, r, "withtrailingrec.example.com", DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/", nil)
132 }
namesys/namesys.go
+1 -1
@@ -75,7 +75,7 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
75 p, err := resolver.resolveOnce(ctx, segments[2])
76 if err == nil {
77 if len(segments) > 3 {
78 - return path.FromSegments(p.String() + "/", segments[3])
78 + return path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3])
79 } else {
80 return p, err
81 }