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

Add new tokens command for managing API tokens #170

Merged
merged 8 commits into from
Nov 3, 2020
Prev Previous commit
Next Next commit
Add integration test for CODER_TOKEN static auth
  • Loading branch information
cmoog committed Nov 3, 2020
commit 6a8c9f20a09704618f941fe241cf00018fb1088e
42 changes: 42 additions & 0 deletions ci/integration/statictokens_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package integration

import (
"context"
"fmt"
"os"
"os/exec"
"strings"
"testing"

"cdr.dev/coder-cli/pkg/tcli"
)

func TestStaticAuth(t *testing.T) {
t.Parallel()
run(t, "static-auth-test", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
headlessLogin(ctx, t, c)

c.Run(ctx, "coder tokens ls").Assert(t,
tcli.Success(),
)

var result *tcli.CommandResult
tokenName := randString(5)
c.Run(ctx, "coder tokens create "+tokenName).Assert(t,
tcli.Success(),
tcli.GetResult(&result),
)

c.Run(ctx, "rm -rf ~/.config/coder")

cmd := exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder envs ls", os.Getenv("CODER_URL")))
cmd.Stdin = strings.NewReader(string(result.Stdout))
c.RunCmd(cmd).Assert(t,
tcli.Success(),
)

c.Run(ctx, "coder envs ls").Assert(t,
tcli.Success(),
)
})
}