Skip to content

Commit

Permalink
Move redact tests to the redact package
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJosh9000 committed Jun 13, 2024
1 parent 261e9dc commit 3dec4f6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
39 changes: 0 additions & 39 deletions internal/job/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"testing"

"github.com/buildkite/agent/v3/internal/job/shell"
"github.com/buildkite/agent/v3/internal/redact"
"github.com/buildkite/agent/v3/tracetools"
"github.com/google/go-cmp/cmp"
"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
Expand Down Expand Up @@ -46,43 +44,6 @@ func TestDirForRepository(t *testing.T) {
}
}

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 := redact.Values(shell.DiscardLogger, redactConfig, environment)
want := []string{"hunter2"}

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("redact.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 := redact.Values(shell.DiscardLogger, redactConfig, environment)
if len(got) != 0 {
t.Errorf("redact.Values(%q, %q) = %q, want empty slice", redactConfig, environment, got)
}
}

func TestStartTracing_NoTracingBackend(t *testing.T) {
var err error

Expand Down
45 changes: 45 additions & 0 deletions internal/redact/redact_test.go
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)
}
}

0 comments on commit 3dec4f6

Please sign in to comment.