2022-10-26 13:31:30 +02:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-08-31 18:37:18 +02:00
|
|
|
"log"
|
2022-11-21 13:56:18 +01:00
|
|
|
"strings"
|
2022-10-26 13:31:30 +02:00
|
|
|
"testing"
|
2022-11-08 16:10:03 +01:00
|
|
|
"time"
|
2022-10-26 13:31:30 +02:00
|
|
|
|
2023-05-21 18:37:59 +02:00
|
|
|
"github.com/juanfont/headscale/hscontrol/policy"
|
2022-11-11 13:20:12 +01:00
|
|
|
"github.com/juanfont/headscale/integration/hsic"
|
|
|
|
"github.com/juanfont/headscale/integration/tsic"
|
2022-11-19 12:41:12 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-10-26 13:31:30 +02:00
|
|
|
)
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
var retry = func(times int, sleepInterval time.Duration,
|
|
|
|
doWork func() (string, string, error),
|
|
|
|
) (string, string, error) {
|
|
|
|
var result string
|
|
|
|
var stderr string
|
2022-11-11 13:20:12 +01:00
|
|
|
var err error
|
2022-11-19 12:41:12 +01:00
|
|
|
|
2022-11-11 13:20:12 +01:00
|
|
|
for attempts := 0; attempts < times; attempts++ {
|
2022-11-19 12:41:12 +01:00
|
|
|
tempResult, tempStderr, err := doWork()
|
|
|
|
|
|
|
|
result += tempResult
|
|
|
|
stderr += tempStderr
|
|
|
|
|
2022-11-11 13:20:12 +01:00
|
|
|
if err == nil {
|
2022-11-19 12:41:12 +01:00
|
|
|
return result, stderr, nil
|
2022-11-08 16:10:03 +01:00
|
|
|
}
|
2022-11-21 14:08:24 +01:00
|
|
|
|
|
|
|
// If we get a permission denied error, we can fail immediately
|
|
|
|
// since that is something we wont recover from by retrying.
|
|
|
|
if err != nil && strings.Contains(stderr, "Permission denied (tailscale)") {
|
|
|
|
return result, stderr, err
|
|
|
|
}
|
|
|
|
|
2022-11-11 13:20:12 +01:00
|
|
|
time.Sleep(sleepInterval)
|
2022-11-08 16:10:03 +01:00
|
|
|
}
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
return result, stderr, err
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
func sshScenario(t *testing.T, policy *policy.ACLPolicy, clientsPerUser int) *Scenario {
|
|
|
|
t.Helper()
|
2024-04-21 18:28:17 +02:00
|
|
|
scenario, err := NewScenario(dockertestMaxWait())
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErr(t, err)
|
2022-10-26 13:31:30 +02:00
|
|
|
|
2022-11-11 13:20:12 +01:00
|
|
|
spec := map[string]int{
|
2023-08-29 08:33:33 +02:00
|
|
|
"user1": clientsPerUser,
|
|
|
|
"user2": clientsPerUser,
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
err = scenario.CreateHeadscaleEnv(spec,
|
2023-08-29 08:33:33 +02:00
|
|
|
[]tsic.Option{
|
2023-08-31 18:37:18 +02:00
|
|
|
tsic.WithSSH(),
|
|
|
|
|
|
|
|
// Alpine containers dont have ip6tables set up, which causes
|
|
|
|
// tailscaled to stop configuring the wgengine, causing it
|
|
|
|
// to not configure DNS.
|
|
|
|
tsic.WithNetfilter("off"),
|
2023-08-29 08:33:33 +02:00
|
|
|
tsic.WithDockerEntrypoint([]string{
|
|
|
|
"/bin/sh",
|
|
|
|
"-c",
|
2023-08-31 18:37:18 +02:00
|
|
|
"/bin/sleep 3 ; apk add openssh ; adduser ssh-it-user ; update-ca-certificates ; tailscaled --tun=tsdev",
|
2023-08-29 08:33:33 +02:00
|
|
|
}),
|
|
|
|
tsic.WithDockerWorkdir("/"),
|
|
|
|
},
|
|
|
|
hsic.WithACLPolicy(policy),
|
|
|
|
hsic.WithTestName("ssh"),
|
2022-11-24 16:41:33 +01:00
|
|
|
hsic.WithConfigEnv(map[string]string{
|
2022-11-24 17:26:52 +01:00
|
|
|
"HEADSCALE_EXPERIMENTAL_FEATURE_SSH": "1",
|
2022-11-24 16:41:33 +01:00
|
|
|
}),
|
2022-11-11 13:20:12 +01:00
|
|
|
)
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErr(t, err)
|
|
|
|
|
|
|
|
err = scenario.WaitForTailscaleSync()
|
|
|
|
assertNoErr(t, err)
|
|
|
|
|
|
|
|
_, err = scenario.ListTailscaleClientsFQDNs()
|
|
|
|
assertNoErr(t, err)
|
|
|
|
|
|
|
|
return scenario
|
|
|
|
}
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
func TestSSHOneUserToAll(t *testing.T) {
|
2023-08-29 08:33:33 +02:00
|
|
|
IntegrationSkip(t)
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
scenario := sshScenario(t,
|
|
|
|
&policy.ACLPolicy{
|
|
|
|
Groups: map[string][]string{
|
|
|
|
"group:integration-test": {"user1"},
|
|
|
|
},
|
|
|
|
ACLs: []policy.ACL{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"*"},
|
|
|
|
Destinations: []string{"*:*"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
SSHs: []policy.SSH{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"group:integration-test"},
|
2023-08-31 18:37:18 +02:00
|
|
|
Destinations: []string{"*"},
|
2023-08-29 08:33:33 +02:00
|
|
|
Users: []string{"ssh-it-user"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-12-09 18:09:24 +01:00
|
|
|
len(MustTestVersions),
|
2023-08-29 08:33:33 +02:00
|
|
|
)
|
|
|
|
defer scenario.Shutdown()
|
2022-11-08 16:10:03 +01:00
|
|
|
|
|
|
|
allClients, err := scenario.ListTailscaleClients()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListClients(t, err)
|
2022-11-08 16:10:03 +01:00
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
user1Clients, err := scenario.ListTailscaleClients("user1")
|
|
|
|
assertNoErrListClients(t, err)
|
|
|
|
|
|
|
|
user2Clients, err := scenario.ListTailscaleClients("user2")
|
|
|
|
assertNoErrListClients(t, err)
|
|
|
|
|
2022-10-26 13:31:30 +02:00
|
|
|
err = scenario.WaitForTailscaleSync()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrSync(t, err)
|
2022-10-26 13:31:30 +02:00
|
|
|
|
2022-11-08 16:10:03 +01:00
|
|
|
_, err = scenario.ListTailscaleClientsFQDNs()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListFQDN(t, err)
|
2022-10-26 13:31:30 +02:00
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
for _, client := range user1Clients {
|
2022-11-08 16:10:03 +01:00
|
|
|
for _, peer := range allClients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
2022-10-26 13:31:30 +02:00
|
|
|
}
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
assertSSHHostname(t, client, peer)
|
2022-10-26 13:31:30 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-31 18:37:18 +02:00
|
|
|
|
|
|
|
for _, client := range user2Clients {
|
|
|
|
for _, peer := range allClients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
assertSSHPermissionDenied(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
2022-10-26 13:31:30 +02:00
|
|
|
}
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-01-17 17:43:44 +01:00
|
|
|
func TestSSHMultipleUsersAllToAll(t *testing.T) {
|
2022-11-11 13:20:12 +01:00
|
|
|
IntegrationSkip(t)
|
2022-11-24 16:17:24 +01:00
|
|
|
t.Parallel()
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
scenario := sshScenario(t,
|
|
|
|
&policy.ACLPolicy{
|
|
|
|
Groups: map[string][]string{
|
|
|
|
"group:integration-test": {"user1", "user2"},
|
|
|
|
},
|
|
|
|
ACLs: []policy.ACL{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"*"},
|
|
|
|
Destinations: []string{"*:*"},
|
2022-11-11 13:20:12 +01:00
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
},
|
|
|
|
SSHs: []policy.SSH{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"group:integration-test"},
|
|
|
|
Destinations: []string{"group:integration-test"},
|
|
|
|
Users: []string{"ssh-it-user"},
|
2022-11-11 13:20:12 +01:00
|
|
|
},
|
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
},
|
2023-12-09 18:09:24 +01:00
|
|
|
len(MustTestVersions),
|
2022-11-11 13:20:12 +01:00
|
|
|
)
|
2023-08-29 08:33:33 +02:00
|
|
|
defer scenario.Shutdown()
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-01-17 17:43:44 +01:00
|
|
|
nsOneClients, err := scenario.ListTailscaleClients("user1")
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListClients(t, err)
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-01-17 17:43:44 +01:00
|
|
|
nsTwoClients, err := scenario.ListTailscaleClients("user2")
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListClients(t, err)
|
2022-11-11 13:20:12 +01:00
|
|
|
|
|
|
|
err = scenario.WaitForTailscaleSync()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrSync(t, err)
|
2022-11-11 13:20:12 +01:00
|
|
|
|
|
|
|
_, err = scenario.ListTailscaleClientsFQDNs()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListFQDN(t, err)
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-01-17 17:43:44 +01:00
|
|
|
testInterUserSSH := func(sourceClients []TailscaleClient, targetClients []TailscaleClient) {
|
2022-11-11 13:20:12 +01:00
|
|
|
for _, client := range sourceClients {
|
|
|
|
for _, peer := range targetClients {
|
2022-11-19 12:41:12 +01:00
|
|
|
assertSSHHostname(t, client, peer)
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:43:44 +01:00
|
|
|
testInterUserSSH(nsOneClients, nsTwoClients)
|
|
|
|
testInterUserSSH(nsTwoClients, nsOneClients)
|
2022-11-19 12:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSSHNoSSHConfigured(t *testing.T) {
|
|
|
|
IntegrationSkip(t)
|
2022-11-24 16:17:24 +01:00
|
|
|
t.Parallel()
|
2022-11-19 12:41:12 +01:00
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
scenario := sshScenario(t,
|
|
|
|
&policy.ACLPolicy{
|
|
|
|
Groups: map[string][]string{
|
|
|
|
"group:integration-test": {"user1"},
|
|
|
|
},
|
|
|
|
ACLs: []policy.ACL{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"*"},
|
|
|
|
Destinations: []string{"*:*"},
|
2022-11-19 12:41:12 +01:00
|
|
|
},
|
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
SSHs: []policy.SSH{},
|
|
|
|
},
|
2023-12-09 18:09:24 +01:00
|
|
|
len(MustTestVersions),
|
2022-11-11 13:20:12 +01:00
|
|
|
)
|
2023-08-29 08:33:33 +02:00
|
|
|
defer scenario.Shutdown()
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
allClients, err := scenario.ListTailscaleClients()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListClients(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
err = scenario.WaitForTailscaleSync()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrSync(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
_, err = scenario.ListTailscaleClientsFQDNs()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListFQDN(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
for _, client := range allClients {
|
|
|
|
for _, peer := range allClients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
assertSSHPermissionDenied(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
func TestSSHIsBlockedInACL(t *testing.T) {
|
|
|
|
IntegrationSkip(t)
|
2022-11-24 16:17:24 +01:00
|
|
|
t.Parallel()
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
scenario := sshScenario(t,
|
|
|
|
&policy.ACLPolicy{
|
|
|
|
Groups: map[string][]string{
|
|
|
|
"group:integration-test": {"user1"},
|
|
|
|
},
|
|
|
|
ACLs: []policy.ACL{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"*"},
|
|
|
|
Destinations: []string{"*:80"},
|
2022-11-19 12:41:12 +01:00
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
},
|
|
|
|
SSHs: []policy.SSH{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"group:integration-test"},
|
|
|
|
Destinations: []string{"group:integration-test"},
|
|
|
|
Users: []string{"ssh-it-user"},
|
2022-11-19 12:41:12 +01:00
|
|
|
},
|
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
},
|
2023-12-09 18:09:24 +01:00
|
|
|
len(MustTestVersions),
|
2022-11-19 12:41:12 +01:00
|
|
|
)
|
2023-08-29 08:33:33 +02:00
|
|
|
defer scenario.Shutdown()
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
allClients, err := scenario.ListTailscaleClients()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListClients(t, err)
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
err = scenario.WaitForTailscaleSync()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrSync(t, err)
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
_, err = scenario.ListTailscaleClientsFQDNs()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListFQDN(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
for _, client := range allClients {
|
|
|
|
for _, peer := range allClients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
assertSSHTimeout(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
func TestSSHUserOnlyIsolation(t *testing.T) {
|
2022-11-19 12:41:12 +01:00
|
|
|
IntegrationSkip(t)
|
2022-11-24 16:17:24 +01:00
|
|
|
t.Parallel()
|
2022-11-19 12:41:12 +01:00
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
scenario := sshScenario(t,
|
|
|
|
&policy.ACLPolicy{
|
|
|
|
Groups: map[string][]string{
|
|
|
|
"group:ssh1": {"user1"},
|
|
|
|
"group:ssh2": {"user2"},
|
|
|
|
},
|
|
|
|
ACLs: []policy.ACL{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"*"},
|
|
|
|
Destinations: []string{"*:*"},
|
2022-11-19 12:41:12 +01:00
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
},
|
|
|
|
SSHs: []policy.SSH{
|
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"group:ssh1"},
|
|
|
|
Destinations: []string{"group:ssh1"},
|
|
|
|
Users: []string{"ssh-it-user"},
|
2022-11-19 12:41:12 +01:00
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
{
|
|
|
|
Action: "accept",
|
|
|
|
Sources: []string{"group:ssh2"},
|
|
|
|
Destinations: []string{"group:ssh2"},
|
|
|
|
Users: []string{"ssh-it-user"},
|
2022-11-19 12:41:12 +01:00
|
|
|
},
|
|
|
|
},
|
2023-08-29 08:33:33 +02:00
|
|
|
},
|
2023-12-09 18:09:24 +01:00
|
|
|
len(MustTestVersions),
|
2022-11-19 12:41:12 +01:00
|
|
|
)
|
2023-08-29 08:33:33 +02:00
|
|
|
defer scenario.Shutdown()
|
2022-11-11 13:20:12 +01:00
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
ssh1Clients, err := scenario.ListTailscaleClients("user1")
|
|
|
|
assertNoErrListClients(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
2023-08-29 08:33:33 +02:00
|
|
|
ssh2Clients, err := scenario.ListTailscaleClients("user2")
|
|
|
|
assertNoErrListClients(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
err = scenario.WaitForTailscaleSync()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrSync(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
_, err = scenario.ListTailscaleClientsFQDNs()
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErrListFQDN(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
2023-06-08 19:50:59 +02:00
|
|
|
for _, client := range ssh1Clients {
|
|
|
|
for _, peer := range ssh2Clients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
assertSSHPermissionDenied(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, client := range ssh2Clients {
|
|
|
|
for _, peer := range ssh1Clients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
assertSSHPermissionDenied(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
for _, client := range ssh1Clients {
|
|
|
|
for _, peer := range ssh1Clients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
assertSSHHostname(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, client := range ssh2Clients {
|
|
|
|
for _, peer := range ssh2Clients {
|
|
|
|
if client.Hostname() == peer.Hostname() {
|
|
|
|
continue
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
assertSSHHostname(t, client, peer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func doSSH(t *testing.T, client TailscaleClient, peer TailscaleClient) (string, string, error) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
peerFQDN, _ := peer.FQDN()
|
|
|
|
|
|
|
|
command := []string{
|
2023-08-31 18:37:18 +02:00
|
|
|
"/usr/bin/ssh", "-o StrictHostKeyChecking=no", "-o ConnectTimeout=1",
|
2022-11-19 12:41:12 +01:00
|
|
|
fmt.Sprintf("%s@%s", "ssh-it-user", peerFQDN),
|
|
|
|
"'hostname'",
|
|
|
|
}
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
log.Printf("Running from %s to %s", client.Hostname(), peer.Hostname())
|
|
|
|
log.Printf("Command: %s", strings.Join(command, " "))
|
|
|
|
|
2022-11-19 12:41:12 +01:00
|
|
|
return retry(10, 1*time.Second, func() (string, string, error) {
|
|
|
|
return client.Execute(command)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertSSHHostname(t *testing.T, client TailscaleClient, peer TailscaleClient) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
result, _, err := doSSH(t, client, peer)
|
2023-08-29 08:33:33 +02:00
|
|
|
assertNoErr(t, err)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
assertContains(t, peer.ID(), strings.ReplaceAll(result, "\n", ""))
|
2022-11-19 12:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func assertSSHPermissionDenied(t *testing.T, client TailscaleClient, peer TailscaleClient) {
|
|
|
|
t.Helper()
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
result, stderr, _ := doSSH(t, client, peer)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
assert.Empty(t, result)
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
assertContains(t, stderr, "Permission denied (tailscale)")
|
2022-11-19 12:41:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func assertSSHTimeout(t *testing.T, client TailscaleClient, peer TailscaleClient) {
|
|
|
|
t.Helper()
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
result, stderr, _ := doSSH(t, client, peer)
|
2022-11-19 12:41:12 +01:00
|
|
|
|
|
|
|
assert.Empty(t, result)
|
|
|
|
|
2023-08-31 18:37:18 +02:00
|
|
|
if !strings.Contains(stderr, "Connection timed out") &&
|
|
|
|
!strings.Contains(stderr, "Operation timed out") {
|
|
|
|
t.Fatalf("connection did not time out")
|
|
|
|
}
|
2022-11-11 13:20:12 +01:00
|
|
|
}
|