|
5 | 5 | "context"
|
6 | 6 | "io"
|
7 | 7 | "net/http"
|
| 8 | + "strings" |
8 | 9 | "testing"
|
9 | 10 | "time"
|
10 | 11 |
|
@@ -57,6 +58,7 @@ func TestRun(t *testing.T) {
|
57 | 58 | require.NotEmpty(t, bun.Network.TailnetDebug)
|
58 | 59 | require.NotNil(t, bun.Network.NetcheckLocal)
|
59 | 60 | require.NotNil(t, bun.Workspace.Workspace)
|
| 61 | + assertSanitizedWorkspace(t, bun.Workspace.Workspace) |
60 | 62 | require.NotEmpty(t, bun.Workspace.BuildLogs)
|
61 | 63 | require.NotNil(t, bun.Workspace.Agent)
|
62 | 64 | require.NotEmpty(t, bun.Workspace.AgentStartupLogs)
|
@@ -92,6 +94,7 @@ func TestRun(t *testing.T) {
|
92 | 94 | require.NotEmpty(t, bun.Network.CoordinatorDebug)
|
93 | 95 | require.NotEmpty(t, bun.Network.TailnetDebug)
|
94 | 96 | require.NotNil(t, bun.Workspace)
|
| 97 | + assertSanitizedWorkspace(t, bun.Workspace.Workspace) |
95 | 98 | require.NotEmpty(t, bun.Logs)
|
96 | 99 | })
|
97 | 100 |
|
@@ -140,6 +143,20 @@ func assertSanitizedDeploymentConfig(t *testing.T, dc *codersdk.DeploymentConfig
|
140 | 143 | }
|
141 | 144 | }
|
142 | 145 |
|
| 146 | +func assertSanitizedWorkspace(t *testing.T, ws codersdk.Workspace) { |
| 147 | + t.Helper() |
| 148 | + for _, res := range ws.LatestBuild.Resources { |
| 149 | + for _, agt := range res.Agents { |
| 150 | + for k, v := range agt.EnvironmentVariables { |
| 151 | + kl := strings.ToLower(k) |
| 152 | + if strings.Contains(kl, "secret") || strings.Contains(kl, "token") || strings.Contains(kl, "pass") { |
| 153 | + assert.Empty(t, v, "environment variable %q not sanitized", k) |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + } |
| 158 | +} |
| 159 | + |
143 | 160 | func setupWorkspaceAndAgent(ctx context.Context, t *testing.T, client *codersdk.Client, db database.Store, user codersdk.CreateFirstUserResponse) (codersdk.Workspace, codersdk.WorkspaceAgent) {
|
144 | 161 | // This is a valid zip file
|
145 | 162 | zipBytes := make([]byte, 22)
|
|
0 commit comments