Commit 76f3395e authored by Adin Schmahmann's avatar Adin Schmahmann

p2p-proxy: earlier peerID validation check

parent a329e4fc
......@@ -9,6 +9,7 @@ import (
"strings"
core "github.com/ipfs/go-ipfs/core"
peer "github.com/libp2p/go-libp2p-core/peer"
protocol "github.com/libp2p/go-libp2p-core/protocol"
p2phttp "github.com/libp2p/go-libp2p-http"
......@@ -60,6 +61,10 @@ func parseRequest(request *http.Request) (*proxyRequest, error) {
return nil, fmt.Errorf("Invalid request path '%s'", path)
}
if _, err := peer.Decode(split[2]); err != nil {
return nil, fmt.Errorf("Invalid request path '%s'", path)
}
if split[3] == "http" {
return &proxyRequest{split[2], protocol.ID("/http"), split[4]}, nil
}
......
......@@ -194,7 +194,12 @@ test_expect_success 'handle proxy http request invalid request' '
'
test_expect_success 'handle proxy http request unknown proxy peer ' '
curl_check_response_code 502 p2p/unknown_peer/http/index.txt
UNKNOWN_PEER="k51qzi5uqu5dlmbel1sd8rs4emr3bfosk9bm4eb42514r4lakt4oxw3a3fa2tm" &&
curl_check_response_code 502 p2p/$UNKNOWN_PEER/http/index.txt
'
test_expect_success 'handle proxy http request to invalid proxy peer ' '
curl_check_response_code 400 p2p/invalid_peer/http/index.txt
'
test_expect_success 'handle proxy http request to custom protocol' '
......
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