Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore(cli): add another test to ensure no secret leakage
  • Loading branch information
johnstcn committed Mar 25, 2024
commit b67a187e7cee353819b6ddb78ccb4f269ede003d
24 changes: 20 additions & 4 deletions cli/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ func TestSupportBundle(t *testing.T) {
t.Run("Workspace", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)
client, db := coderdtest.NewWithDatabase(t, nil)
var dc codersdk.DeploymentConfig
secretValue := uuid.NewString()
seedSecretDeploymentOptions(t, &dc, secretValue)
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
DeploymentValues: dc.Values,
})
owner := coderdtest.CreateFirstUser(t, client)
randSecretValue := uuid.NewString()
r := dbfake.WorkspaceBuild(t, db, database.Workspace{
OrganizationID: owner.OrganizationID,
OwnerID: owner.UserID,
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
// This should not show up in the bundle output
agents[0].Env["SECRET_VALUE"] = randSecretValue
agents[0].Env["SECRET_VALUE"] = secretValue
return agents
}).Do()
ws, err := client.Workspace(ctx, r.Workspace.ID)
Expand Down Expand Up @@ -89,7 +93,7 @@ func TestSupportBundle(t *testing.T) {
clitest.SetupConfig(t, client, root)
err = inv.Run()
require.NoError(t, err)
assertBundleContents(t, path, randSecretValue)
assertBundleContents(t, path, secretValue)
})

t.Run("NoWorkspace", func(t *testing.T) {
Expand Down Expand Up @@ -263,3 +267,15 @@ func assertDoesNotContain(t *testing.T, f *zip.File, vals ...string) {
}
}
}

func seedSecretDeploymentOptions(t *testing.T, dc *codersdk.DeploymentConfig, secretValue string) {
t.Helper()
if dc == nil {
dc = &codersdk.DeploymentConfig{}
}
for _, opt := range dc.Options {
if codersdk.IsSecretDeploymentOption(opt) {
opt.Value.Set(secretValue)
}
}
}