@cryptotaxi247 / kubo / commits / dcc4da0b3

Replaced old logic to check for valid path

Added the original logic to check for a invalid path and a simple test.

Travis Person committed May 20, 2015 at 20:38 UTC dcc4da0b37109d7073590731794b4891f6bd4b69
2 files changed +45 -2
core/pathresolver.go
+4 -2
@@ -3,6 +3,7 @@ package core
3 import (
4 "errors"
5 "strings"
6 + "fmt"
7
8 context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
9
@@ -29,8 +30,9 @@ func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, er
30 }
31
32 seg := p.Segments()
32 - if len(seg) < 2 {
33 - return nil, errors.New("No path given")
33 +
34 + if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
35 + return nil, fmt.Errorf("invalid path: %s", string(p))
36 }
37
38 extensions := seg[2:]
core/pathresolver_test.go new
+41
@@ -0,0 +1,41 @@
1 +package core
2 +
3 +import (
4 + "testing"
5 +
6 + context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7 + config "github.com/ipfs/go-ipfs/repo/config"
8 + "github.com/ipfs/go-ipfs/util/testutil"
9 + "github.com/ipfs/go-ipfs/repo"
10 + path "github.com/ipfs/go-ipfs/path"
11 +)
12 +
13 +func TestResolveInvalidPath(t *testing.T) {
14 + ctx := context.TODO()
15 + id := testIdentity
16 +
17 + r := &repo.Mock{
18 + C: config.Config{
19 + Identity: id,
20 + Datastore: config.Datastore{
21 + Type: "memory",
22 + },
23 + Addresses: config.Addresses{
24 + Swarm: []string{"/ip4/0.0.0.0/tcp/4001"},
25 + API: "/ip4/127.0.0.1/tcp/8000",
26 + },
27 + },
28 + D: testutil.ThreadSafeCloserMapDatastore(),
29 + }
30 +
31 + n, err := NewIPFSNode(ctx, Standard(r, false))
32 + if n == nil || err != nil {
33 + t.Error("Should have constructed.", err)
34 + }
35 +
36 + _, err = Resolve(ctx, n, path.Path("/ipfs/"))
37 + if err == nil {
38 + t.Error("Should get invalid path")
39 + }
40 +
41 +}