-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add provisioner key cli commands #13875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
83e3868
e4cf813
9fd47c8
3d1b075
c67ed19
adffefd
da95666
90412c7
86c0d02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package cli_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/v2/cli/clitest" | ||
"github.com/coder/coder/v2/coderd/coderdtest" | ||
"github.com/coder/coder/v2/coderd/rbac" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest" | ||
"github.com/coder/coder/v2/enterprise/coderd/license" | ||
"github.com/coder/coder/v2/pty/ptytest" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
|
||
func TestProvisionerKeys(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("CRUD", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
dv := coderdtest.DeploymentValues(t) | ||
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)} | ||
client, owner := coderdenttest.New(t, &coderdenttest.Options{ | ||
Options: &coderdtest.Options{ | ||
DeploymentValues: dv, | ||
}, | ||
LicenseOptions: &coderdenttest.LicenseOptions{ | ||
Features: license.Features{ | ||
codersdk.FeatureMultipleOrganizations: 1, | ||
}, | ||
}, | ||
}) | ||
orgAdminClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgAdmin(owner.OrganizationID)) | ||
|
||
name := "dont-TEST-me" | ||
ctx := testutil.Context(t, testutil.WaitMedium) | ||
inv, conf := newCLI( | ||
t, | ||
"provisioner", "keys", "create", name, | ||
) | ||
|
||
pty := ptytest.New(t) | ||
inv.Stdout = pty.Output() | ||
clitest.SetupConfig(t, orgAdminClient, conf) | ||
|
||
err := inv.WithContext(ctx).Run() | ||
require.NoError(t, err) | ||
|
||
line := pty.ReadLine(ctx) | ||
require.Contains(t, line, "Successfully created provisioner key") | ||
require.Contains(t, line, strings.ToLower(name)) | ||
// empty line | ||
_ = pty.ReadLine(ctx) | ||
key := pty.ReadLine(ctx) | ||
require.NotEmpty(t, key) | ||
parts := strings.Split(key, ":") | ||
require.Len(t, parts, 2, "expected 2 parts") | ||
_, err = uuid.Parse(parts[0]) | ||
require.NoError(t, err, "expected token to be a uuid") | ||
|
||
inv, conf = newCLI( | ||
t, | ||
"provisioner", "keys", "ls", | ||
) | ||
pty = ptytest.New(t) | ||
inv.Stdout = pty.Output() | ||
clitest.SetupConfig(t, orgAdminClient, conf) | ||
|
||
err = inv.WithContext(ctx).Run() | ||
require.NoError(t, err) | ||
line = pty.ReadLine(ctx) | ||
require.Contains(t, line, "NAME") | ||
require.Contains(t, line, "CREATED AT") | ||
require.Contains(t, line, "ORGANIZATION ID") | ||
line = pty.ReadLine(ctx) | ||
require.Contains(t, line, strings.ToLower(name)) | ||
|
||
inv, conf = newCLI( | ||
t, | ||
"provisioner", "keys", "delete", "-y", name, | ||
) | ||
|
||
pty = ptytest.New(t) | ||
inv.Stdout = pty.Output() | ||
clitest.SetupConfig(t, orgAdminClient, conf) | ||
|
||
err = inv.WithContext(ctx).Run() | ||
require.NoError(t, err) | ||
line = pty.ReadLine(ctx) | ||
require.Contains(t, line, "Successfully deleted provisioner key") | ||
require.Contains(t, line, strings.ToLower(name)) | ||
|
||
inv, conf = newCLI( | ||
t, | ||
"provisioner", "keys", "ls", | ||
) | ||
pty = ptytest.New(t) | ||
inv.Stdout = pty.Output() | ||
clitest.SetupConfig(t, orgAdminClient, conf) | ||
|
||
err = inv.WithContext(ctx).Run() | ||
require.NoError(t, err) | ||
line = pty.ReadLine(ctx) | ||
require.Contains(t, line, "No provisioner keys found") | ||
}) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.