-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move redact tests to the redact package
- Loading branch information
1 parent
261e9dc
commit 3dec4f6
Showing
2 changed files
with
45 additions
and
39 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
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) | ||
} | ||
} |