Unverified Commit 651d8d7e authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #46 from ipfs/fix/45

return ErrNotFound when resolving commands with valid prefixes
parents 707476dc cf7b8bc6
......@@ -39,7 +39,7 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
sub := cmd.Subcommand(pth[len(pth)-1])
if sub == nil {
if len(pth) <= 1 {
if cmd.Run == nil {
return nil, ErrNotFound
}
......
package http
import (
"net/http"
"testing"
cmds "github.com/ipfs/go-ipfs-cmds"
)
func TestParse(t *testing.T) {
root := &cmds.Command{
Subcommands: map[string]*cmds.Command{
"block": &cmds.Command{
Subcommands: map[string]*cmds.Command{
"put": &cmds.Command{
Run: func(req cmds.Request, resp cmds.ResponseEmitter) {
defer resp.Close()
resp.Emit("done")
},
},
},
},
},
}
r, err := http.NewRequest("GET", "/api/v0/block/put", nil)
if err != nil {
t.Fatal(err)
}
req, err := Parse(r, root)
if err != nil {
t.Fatal(err)
}
pth := req.Path()
if pth[0] != "block" || pth[1] != "put" || len(pth) != 2 {
t.Errorf("incorrect path %v, expected %v", pth, []string{"block", "put"})
}
r, err = http.NewRequest("GET", "/api/v0/block/bla", nil)
if err != nil {
t.Fatal(err)
}
req, err = Parse(r, root)
if err != ErrNotFound {
t.Errorf("expected ErrNotFound, got: %v", err)
}
}
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