Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 6a8c9f2

Browse files
committed
Add integration test for CODER_TOKEN static auth
1 parent 7bf7d01 commit 6a8c9f2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

ci/integration/statictokens_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
"strings"
9+
"testing"
10+
11+
"cdr.dev/coder-cli/pkg/tcli"
12+
)
13+
14+
func TestStaticAuth(t *testing.T) {
15+
t.Parallel()
16+
run(t, "static-auth-test", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
17+
headlessLogin(ctx, t, c)
18+
19+
c.Run(ctx, "coder tokens ls").Assert(t,
20+
tcli.Success(),
21+
)
22+
23+
var result *tcli.CommandResult
24+
tokenName := randString(5)
25+
c.Run(ctx, "coder tokens create "+tokenName).Assert(t,
26+
tcli.Success(),
27+
tcli.GetResult(&result),
28+
)
29+
30+
c.Run(ctx, "rm -rf ~/.config/coder")
31+
32+
cmd := exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder envs ls", os.Getenv("CODER_URL")))
33+
cmd.Stdin = strings.NewReader(string(result.Stdout))
34+
c.RunCmd(cmd).Assert(t,
35+
tcli.Success(),
36+
)
37+
38+
c.Run(ctx, "coder envs ls").Assert(t,
39+
tcli.Success(),
40+
)
41+
})
42+
}

0 commit comments

Comments
 (0)