- Notifications
You must be signed in to change notification settings - Fork926
fix(cli): add check for DisableOwnerWorkspaceExec in scaletest#14417
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,70 @@ | ||||||||||
package exptest_test | ||||||||||
import ( | ||||||||||
"bytes" | ||||||||||
"context" | ||||||||||
"testing" | ||||||||||
"github.com/stretchr/testify/require" | ||||||||||
"cdr.dev/slog/sloggers/slogtest" | ||||||||||
"github.com/coder/coder/v2/cli/clitest" | ||||||||||
"github.com/coder/coder/v2/coderd/coderdtest" | ||||||||||
"github.com/coder/coder/v2/codersdk" | ||||||||||
"github.com/coder/coder/v2/testutil" | ||||||||||
) | ||||||||||
// This test validates that the scaletest CLI filters out workspaces not owned | ||||||||||
// when disable owner workspace access is set. | ||||||||||
// This test is in its own package because it mutates a global variable that | ||||||||||
// can influence other tests in the same package. | ||||||||||
// nolint:paralleltest | ||||||||||
func TestScaleTestWorkspaceTraffic_UseHostLogin(t *testing.T) { | ||||||||||
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitMedium) | ||||||||||
defer cancelFunc() | ||||||||||
log := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) | ||||||||||
client := coderdtest.New(t, &coderdtest.Options{ | ||||||||||
Logger: &log, | ||||||||||
IncludeProvisionerDaemon: true, | ||||||||||
DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) { | ||||||||||
dv.DisableOwnerWorkspaceExec = true | ||||||||||
}), | ||||||||||
}) | ||||||||||
Comment on lines +22 to +33 Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Does this test not run in I ask because these roles are global, and it is an unfortunate consequence atm. (maybe custom roles can solve this without being global in the future). You can see how I reset the global state here when using this option: coder/coderd/rbac/roles_test.go Lines 63 to 66 ine6ed3c3
and of course, no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. As far as I can tell, each package is its own test binary. So the global variable would only affect tests run in the same package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I added a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. CI is passing, so the global-ness is not impacting the rest 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Yeah, Cian is right, you can think of each package as being built as its own test binary (basically that's what actually happens too), so global scope changes are constrained to that package. This is one of the test parallelism mechanisms in Go too (run different packages concurrently) and works irrespective of | ||||||||||
owner := coderdtest.CreateFirstUser(t, client) | ||||||||||
tv := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil) | ||||||||||
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, tv.ID) | ||||||||||
tpl := coderdtest.CreateTemplate(t, client, owner.OrganizationID, tv.ID) | ||||||||||
// Create a workspace owned by a different user | ||||||||||
memberClient, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID) | ||||||||||
_ = coderdtest.CreateWorkspace(t, memberClient, tpl.ID, func(cwr *codersdk.CreateWorkspaceRequest) { | ||||||||||
cwr.Name = "scaletest-workspace" | ||||||||||
}) | ||||||||||
// Test without --use-host-login first.g | ||||||||||
inv, root := clitest.New(t, "exp", "scaletest", "workspace-traffic", | ||||||||||
"--template", tpl.Name, | ||||||||||
) | ||||||||||
// nolint:gocritic // We are intentionally testing this as the owner. | ||||||||||
clitest.SetupConfig(t, client, root) | ||||||||||
var stdoutBuf bytes.Buffer | ||||||||||
inv.Stdout = &stdoutBuf | ||||||||||
err := inv.WithContext(ctx).Run() | ||||||||||
require.ErrorContains(t, err, "no scaletest workspaces exist") | ||||||||||
require.Contains(t, stdoutBuf.String(), `1 workspace(s) were skipped`) | ||||||||||
// Test once again with --use-host-login. | ||||||||||
inv, root = clitest.New(t, "exp", "scaletest", "workspace-traffic", | ||||||||||
"--template", tpl.Name, | ||||||||||
"--use-host-login", | ||||||||||
) | ||||||||||
// nolint:gocritic // We are intentionally testing this as the owner. | ||||||||||
clitest.SetupConfig(t, client, root) | ||||||||||
stdoutBuf.Reset() | ||||||||||
inv.Stdout = &stdoutBuf | ||||||||||
err = inv.WithContext(ctx).Run() | ||||||||||
require.ErrorContains(t, err, "no scaletest workspaces exist") | ||||||||||
require.NotContains(t, stdoutBuf.String(), `1 workspace(s) were skipped`) | ||||||||||
} |
Uh oh!
There was an error while loading.Please reload this page.