2021-12-01 19:10:54 +01:00
|
|
|
package funcs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/internal/lang/marks"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRedactIfSensitive(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
|
|
|
value interface{}
|
|
|
|
marks []cty.ValueMarks
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
"sensitive string": {
|
|
|
|
value: "foo",
|
|
|
|
marks: []cty.ValueMarks{cty.NewValueMarks(marks.Sensitive)},
|
|
|
|
want: "(sensitive value)",
|
|
|
|
},
|
2022-02-09 23:15:53 +01:00
|
|
|
"marked non-sensitive string": {
|
2021-12-01 19:10:54 +01:00
|
|
|
value: "foo",
|
2022-02-09 23:15:53 +01:00
|
|
|
marks: []cty.ValueMarks{cty.NewValueMarks("boop")},
|
2021-12-01 19:10:54 +01:00
|
|
|
want: `"foo"`,
|
|
|
|
},
|
2022-02-09 23:15:53 +01:00
|
|
|
"sensitive string with other marks": {
|
2021-12-01 19:10:54 +01:00
|
|
|
value: "foo",
|
2022-02-09 23:15:53 +01:00
|
|
|
marks: []cty.ValueMarks{cty.NewValueMarks("boop"), cty.NewValueMarks(marks.Sensitive)},
|
2021-12-01 19:10:54 +01:00
|
|
|
want: "(sensitive value)",
|
|
|
|
},
|
|
|
|
"sensitive number": {
|
|
|
|
value: 12345,
|
|
|
|
marks: []cty.ValueMarks{cty.NewValueMarks(marks.Sensitive)},
|
|
|
|
want: "(sensitive value)",
|
|
|
|
},
|
|
|
|
"non-sensitive number": {
|
|
|
|
value: 12345,
|
|
|
|
marks: []cty.ValueMarks{},
|
|
|
|
want: "12345",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
got := redactIfSensitive(tc.value, tc.marks...)
|
|
|
|
if got != tc.want {
|
|
|
|
t.Errorf("wrong result, got %v, want %v", got, tc.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|