mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore(cli): add linter to detect potential spurious usage of owner user in cli tests (#10133)
* Detects the following pattern where the CLI is initialized with a client authenticated as the "first user":
client := coderdtest.New(t, ...)
[...]
user := coderdtest.CreateFirstUser(t, client)
[...]
clitest.SetupConfig(t, client, root)
* Updates documentation regarding role permissions on workspaces.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -35,13 +36,14 @@ func TestUserStatus(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client := coderdtest.New(t, nil)
|
||||
admin := coderdtest.CreateFirstUser(t, client)
|
||||
other, _ := coderdtest.CreateAnotherUser(t, client, admin.OrganizationID)
|
||||
owner := coderdtest.CreateFirstUser(t, client)
|
||||
userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
|
||||
other, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
|
||||
otherUser, err := other.User(context.Background(), codersdk.Me)
|
||||
require.NoError(t, err, "fetch user")
|
||||
|
||||
inv, root := clitest.New(t, "users", "suspend", otherUser.Username)
|
||||
clitest.SetupConfig(t, client, root)
|
||||
clitest.SetupConfig(t, userAdmin, root)
|
||||
// Yes to the prompt
|
||||
inv.Stdin = bytes.NewReader([]byte("yes\n"))
|
||||
err = inv.Run()
|
||||
@@ -54,7 +56,7 @@ func TestUserStatus(t *testing.T) {
|
||||
|
||||
// Set back to active. Try using a uuid as well
|
||||
inv, root = clitest.New(t, "users", "activate", otherUser.ID.String())
|
||||
clitest.SetupConfig(t, client, root)
|
||||
clitest.SetupConfig(t, userAdmin, root)
|
||||
// Yes to the prompt
|
||||
inv.Stdin = bytes.NewReader([]byte("yes\n"))
|
||||
err = inv.Run()
|
||||
|
||||
Reference in New Issue
Block a user