Skip to content

Commit

Permalink
add test case to reproduce juanfont#1885
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed May 1, 2024
1 parent d5ed8bc commit 2582f7f
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions integration/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,101 @@ func TestPreAuthKeyCommandReusableEphemeral(t *testing.T) {
assert.Len(t, listedPreAuthKeys, 3)
}

func TestPreAuthKeyCorrectUserLoggedInCommand(t *testing.T) {
IntegrationSkip(t)
t.Parallel()

user1 := "user1"
user2 := "user2"

scenario, err := NewScenario(dockertestMaxWait())
assertNoErr(t, err)
defer scenario.Shutdown()

spec := map[string]int{
user1: 1,
user2: 0,
}

err = scenario.CreateHeadscaleEnv(spec, []tsic.Option{}, hsic.WithTestName("clipak"))
assertNoErr(t, err)

headscale, err := scenario.Headscale()
assertNoErr(t, err)

var user2Key v1.PreAuthKey

err = executeAndUnmarshal(
headscale,
[]string{
"headscale",
"preauthkeys",
"--user",
user2,
"create",
"--reusable",
"--expiration",
"24h",
"--output",
"json",
"--tags",
"tag:test1,tag:test2",
},
&user2Key,
)
assertNoErr(t, err)

allClients, err := scenario.ListTailscaleClients()
assertNoErrListClients(t, err)

assert.Len(t, allClients, 1)

client := allClients[0]

// Log out from user1
err = client.Logout()
assertNoErr(t, err)

err = scenario.WaitForTailscaleLogout()
assertNoErr(t, err)

status, err := client.Status()
assertNoErr(t, err)
if status.BackendState == "Starting" || status.BackendState == "Running" {
t.Fatalf("expected node to be logged out, backend state: %s", status.BackendState)
}

err = client.Login(headscale.GetEndpoint(), user2Key.GetKey())
assertNoErr(t, err)

status, err = client.Status()
assertNoErr(t, err)
if status.BackendState != "Running" {
t.Fatalf("expected node to be logged in, backend state: %s", status.BackendState)
}

if status.Self.UserID.String() != "2" {
t.Fatalf("expected node to be logged in as user2, got: %s", status.Self.UserID.String())
}

var listNodes []v1.Node
err = executeAndUnmarshal(
headscale,
[]string{
"headscale",
"nodes",
"list",
"--output",
"json",
},
&listNodes,
)
assert.Nil(t, err)
assert.Len(t, listNodes, 1)

assert.Equal(t, "user2", listNodes[0].User.Name)
}

func TestApiKeyCommand(t *testing.T) {
IntegrationSkip(t)
t.Parallel()
Expand Down

0 comments on commit 2582f7f

Please sign in to comment.