mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-03 15:27:57 +08:00
Merge pull request #7797 from ipfs/fix/p2p-proxy-checks
More p2p proxy checks
This commit is contained in:
commit
edde2809e7
@ -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,12 +61,16 @@ 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
|
||||
}
|
||||
|
||||
split = strings.SplitN(path, "/", 7)
|
||||
if split[3] != "x" || split[5] != "http" {
|
||||
if len(split) < 7 || split[3] != "x" || split[5] != "http" {
|
||||
return nil, fmt.Errorf("Invalid request path '%s'", path)
|
||||
}
|
||||
|
||||
|
||||
@ -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' '
|
||||
|
||||
Loading…
Reference in New Issue
Block a user