-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2834 from buildkite/redact-jobapi-token
Redact Job API token like other env vars
- Loading branch information
Showing
4 changed files
with
89 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package redact | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/buildkite/agent/v3/internal/job/shell" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestValuesToRedact(t *testing.T) { | ||
t.Parallel() | ||
|
||
redactConfig := []string{ | ||
"*_PASSWORD", | ||
"*_TOKEN", | ||
} | ||
environment := map[string]string{ | ||
"BUILDKITE_PIPELINE": "unit-test", | ||
// These are example values, and are not leaked credentials | ||
"DATABASE_USERNAME": "AzureDiamond", | ||
"DATABASE_PASSWORD": "hunter2", | ||
} | ||
|
||
got := Values(shell.DiscardLogger, redactConfig, environment) | ||
want := []string{"hunter2"} | ||
|
||
if diff := cmp.Diff(got, want); diff != "" { | ||
t.Errorf("Values(%q, %q) diff (-got +want)\n%s", redactConfig, environment, diff) | ||
} | ||
} | ||
|
||
func TestValuesToRedactEmpty(t *testing.T) { | ||
t.Parallel() | ||
|
||
redactConfig := []string{} | ||
environment := map[string]string{ | ||
"FOO": "BAR", | ||
"BUILDKITE_PIPELINE": "unit-test", | ||
} | ||
|
||
got := Values(shell.DiscardLogger, redactConfig, environment) | ||
if len(got) != 0 { | ||
t.Errorf("Values(%q, %q) = %q, want empty slice", redactConfig, environment, got) | ||
} | ||
} |