|
|
@ -25,6 +25,7 @@ import (
|
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/tstest"
|
|
|
|
"tailscale.com/tstest"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
|
|
|
|
"tailscale.com/types/netmap"
|
|
|
|
"tailscale.com/util/must"
|
|
|
|
"tailscale.com/util/must"
|
|
|
|
"tailscale.com/wgengine"
|
|
|
|
"tailscale.com/wgengine"
|
|
|
|
"tailscale.com/wgengine/filter"
|
|
|
|
"tailscale.com/wgengine/filter"
|
|
|
@ -113,6 +114,7 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
name string
|
|
|
|
name string
|
|
|
|
isSelf bool // the peer sending the request is owned by us
|
|
|
|
isSelf bool // the peer sending the request is owned by us
|
|
|
|
capSharing bool // self node has file sharing capability
|
|
|
|
capSharing bool // self node has file sharing capability
|
|
|
|
|
|
|
|
debugCap bool // self node has debug capability
|
|
|
|
omitRoot bool // don't configure
|
|
|
|
omitRoot bool // don't configure
|
|
|
|
req *http.Request
|
|
|
|
req *http.Request
|
|
|
|
checks []check
|
|
|
|
checks []check
|
|
|
@ -140,14 +142,23 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "peer_api_goroutines_deny",
|
|
|
|
name: "goroutines/deny-self-no-cap",
|
|
|
|
|
|
|
|
isSelf: true,
|
|
|
|
|
|
|
|
debugCap: false,
|
|
|
|
|
|
|
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
|
|
|
|
|
|
|
checks: checks(httpStatus(403)),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "goroutines/deny-nonself",
|
|
|
|
isSelf: false,
|
|
|
|
isSelf: false,
|
|
|
|
|
|
|
|
debugCap: true,
|
|
|
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
|
|
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
|
|
|
checks: checks(httpStatus(403)),
|
|
|
|
checks: checks(httpStatus(403)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "peer_api_goroutines",
|
|
|
|
name: "goroutines/accept-self",
|
|
|
|
isSelf: true,
|
|
|
|
isSelf: true,
|
|
|
|
|
|
|
|
debugCap: true,
|
|
|
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
|
|
|
req: httptest.NewRequest("GET", "/v0/goroutines", nil),
|
|
|
|
checks: checks(
|
|
|
|
checks: checks(
|
|
|
|
httpStatus(200),
|
|
|
|
httpStatus(200),
|
|
|
@ -406,6 +417,7 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "host-val/bad-ip",
|
|
|
|
name: "host-val/bad-ip",
|
|
|
|
isSelf: true,
|
|
|
|
isSelf: true,
|
|
|
|
|
|
|
|
debugCap: true,
|
|
|
|
req: httptest.NewRequest("GET", "http://12.23.45.66:1234/v0/env", nil),
|
|
|
|
req: httptest.NewRequest("GET", "http://12.23.45.66:1234/v0/env", nil),
|
|
|
|
checks: checks(
|
|
|
|
checks: checks(
|
|
|
|
httpStatus(403),
|
|
|
|
httpStatus(403),
|
|
|
@ -414,6 +426,7 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "host-val/no-port",
|
|
|
|
name: "host-val/no-port",
|
|
|
|
isSelf: true,
|
|
|
|
isSelf: true,
|
|
|
|
|
|
|
|
debugCap: true,
|
|
|
|
req: httptest.NewRequest("GET", "http://100.100.100.101/v0/env", nil),
|
|
|
|
req: httptest.NewRequest("GET", "http://100.100.100.101/v0/env", nil),
|
|
|
|
checks: checks(
|
|
|
|
checks: checks(
|
|
|
|
httpStatus(403),
|
|
|
|
httpStatus(403),
|
|
|
@ -422,6 +435,7 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "host-val/peer",
|
|
|
|
name: "host-val/peer",
|
|
|
|
isSelf: true,
|
|
|
|
isSelf: true,
|
|
|
|
|
|
|
|
debugCap: true,
|
|
|
|
req: httptest.NewRequest("GET", "http://peer/v0/env", nil),
|
|
|
|
req: httptest.NewRequest("GET", "http://peer/v0/env", nil),
|
|
|
|
checks: checks(
|
|
|
|
checks: checks(
|
|
|
|
httpStatus(200),
|
|
|
|
httpStatus(200),
|
|
|
@ -430,10 +444,16 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
|
|
|
selfNode := &tailcfg.Node{
|
|
|
|
|
|
|
|
Addresses: []netip.Prefix{
|
|
|
|
|
|
|
|
netip.MustParsePrefix("100.100.100.101/32"),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
var e peerAPITestEnv
|
|
|
|
var e peerAPITestEnv
|
|
|
|
lb := &LocalBackend{
|
|
|
|
lb := &LocalBackend{
|
|
|
|
logf: e.logBuf.Logf,
|
|
|
|
logf: e.logBuf.Logf,
|
|
|
|
capFileSharing: tt.capSharing,
|
|
|
|
capFileSharing: tt.capSharing,
|
|
|
|
|
|
|
|
netMap: &netmap.NetworkMap{SelfNode: selfNode},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.ph = &peerAPIHandler{
|
|
|
|
e.ph = &peerAPIHandler{
|
|
|
|
isSelf: tt.isSelf,
|
|
|
|
isSelf: tt.isSelf,
|
|
|
@ -442,13 +462,12 @@ func TestHandlePeerAPI(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ps: &peerAPIServer{
|
|
|
|
ps: &peerAPIServer{
|
|
|
|
b: lb,
|
|
|
|
b: lb,
|
|
|
|
selfNode: &tailcfg.Node{
|
|
|
|
selfNode: selfNode,
|
|
|
|
Addresses: []netip.Prefix{
|
|
|
|
|
|
|
|
netip.MustParsePrefix("100.100.100.101/32"),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if tt.debugCap {
|
|
|
|
|
|
|
|
e.ph.ps.selfNode.Capabilities = append(e.ph.ps.selfNode.Capabilities, tailcfg.CapabilityDebug)
|
|
|
|
|
|
|
|
}
|
|
|
|
var rootDir string
|
|
|
|
var rootDir string
|
|
|
|
if !tt.omitRoot {
|
|
|
|
if !tt.omitRoot {
|
|
|
|
rootDir = t.TempDir()
|
|
|
|
rootDir = t.TempDir()
|
|
|
|