Commit dcc4da0b authored by Travis Person's avatar Travis Person

Replaced old logic to check for valid path

Added the original logic to check for a invalid path and a simple test.
parent 42289d4f
......@@ -3,6 +3,7 @@ package core
import (
"errors"
"strings"
"fmt"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
......@@ -29,8 +30,9 @@ func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, er
}
seg := p.Segments()
if len(seg) < 2 {
return nil, errors.New("No path given")
if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
return nil, fmt.Errorf("invalid path: %s", string(p))
}
extensions := seg[2:]
......
package core
import (
"testing"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
config "github.com/ipfs/go-ipfs/repo/config"
"github.com/ipfs/go-ipfs/util/testutil"
"github.com/ipfs/go-ipfs/repo"
path "github.com/ipfs/go-ipfs/path"
)
func TestResolveInvalidPath(t *testing.T) {
ctx := context.TODO()
id := testIdentity
r := &repo.Mock{
C: config.Config{
Identity: id,
Datastore: config.Datastore{
Type: "memory",
},
Addresses: config.Addresses{
Swarm: []string{"/ip4/0.0.0.0/tcp/4001"},
API: "/ip4/127.0.0.1/tcp/8000",
},
},
D: testutil.ThreadSafeCloserMapDatastore(),
}
n, err := NewIPFSNode(ctx, Standard(r, false))
if n == nil || err != nil {
t.Error("Should have constructed.", err)
}
_, err = Resolve(ctx, n, path.Path("/ipfs/"))
if err == nil {
t.Error("Should get invalid path")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment