@@ -12,6 +12,7 @@ import (
1212 "github.com/hashicorp/terraform/internal/tfdiags"
1313 "github.com/zclconf/go-cty/cty"
1414 "google.golang.org/grpc"
15+ gproto "google.golang.org/protobuf/proto"
1516
1617 "github.com/hashicorp/terraform/internal/policy/callback"
1718 "github.com/hashicorp/terraform/internal/policy/proto"
@@ -42,8 +43,8 @@ func TestClientEvaluate(t *testing.T) {
4243
4344 tests := []struct {
4445 name string
45- attrs cty. Value
46- priorAttrs cty. Value
46+ attrs PolicyValue
47+ priorAttrs PolicyValue
4748
4849 // an optional function to override the default evaluateResourceFn
4950 evaluateResourceFn func (* proto.PolicyEvaluateResourceRequest ) (* proto.PolicyEvaluateResourceResponse , error )
@@ -53,8 +54,8 @@ func TestClientEvaluate(t *testing.T) {
5354 }{
5455 {
5556 name : "nil attrs and prior attrs" ,
56- attrs : cty .NilVal ,
57- priorAttrs : cty .NilVal ,
57+ attrs : PolicyValue { Raw : cty .NilVal } ,
58+ priorAttrs : PolicyValue { Raw : cty .NilVal } ,
5859 assertResponse : func (t * testing.T , registry * callback.MockRegistry , req * proto.PolicyEvaluateResourceRequest , resp EvaluationResponse ) {
5960 t .Helper ()
6061 if resp .Overall != AllowResult {
@@ -69,9 +70,14 @@ func TestClientEvaluate(t *testing.T) {
6970 },
7071 },
7172 {
72- name : "non-nil attrs and prior attrs" ,
73- attrs : cty .ObjectVal (map [string ]cty.Value {"name" : cty .StringVal ("test" )}),
74- priorAttrs : cty .ObjectVal (map [string ]cty.Value {"name" : cty .StringVal ("prior" )}),
73+ name : "non-nil attrs and prior attrs" ,
74+ attrs : PolicyValue {
75+ Raw : cty .ObjectVal (map [string ]cty.Value {"name" : cty .StringVal ("test" )}),
76+ RedactedPaths : []cty.Path {cty .GetAttrPath ("secret" )},
77+ },
78+ priorAttrs : PolicyValue {
79+ Raw : cty .ObjectVal (map [string ]cty.Value {"name" : cty .StringVal ("prior" )}),
80+ },
7581 assertResponse : func (t * testing.T , registry * callback.MockRegistry , req * proto.PolicyEvaluateResourceRequest , resp EvaluationResponse ) {
7682 t .Helper ()
7783 if resp .Overall != AllowResult {
@@ -80,12 +86,19 @@ func TestClientEvaluate(t *testing.T) {
8086 if len (resp .Diagnostics ) != 0 {
8187 t .Fatalf ("unexpected diagnostics: %#v" , resp .Diagnostics )
8288 }
89+
90+ want := & proto.AttributePath {Steps : []* proto.AttributePath_Step {{
91+ Selector : & proto.AttributePath_Step_AttributeName {AttributeName : "secret" },
92+ }}}
93+ if len (req .Attrs .RedactedPaths ) != 1 || ! gproto .Equal (req .Attrs .RedactedPaths [0 ], want ) {
94+ t .Fatalf ("unexpected redacted paths: %#v" , req .Attrs .RedactedPaths )
95+ }
8396 },
8497 },
8598 {
8699 name : "transforms diagnostics from response" ,
87- attrs : cty .NilVal ,
88- priorAttrs : cty .NilVal ,
100+ attrs : PolicyValue { Raw : cty .NilVal } ,
101+ priorAttrs : PolicyValue { Raw : cty .NilVal } ,
89102 evaluateResourceFn : func (req * proto.PolicyEvaluateResourceRequest ) (* proto.PolicyEvaluateResourceResponse , error ) {
90103 return & proto.PolicyEvaluateResourceResponse {
91104 Result : proto .EvaluateResult_DENY_EVALUATE_RESULT ,
@@ -204,13 +217,13 @@ func TestClientEvaluateProvider(t *testing.T) {
204217
205218 tests := []struct {
206219 name string
207- attrs cty. Value
220+ attrs PolicyValue
208221 evaluateProviderFn func (* proto.PolicyEvaluateProviderRequest ) (* proto.PolicyEvaluateProviderResponse , error )
209222 assertResponse func (* testing.T , EvaluationResponse )
210223 }{
211224 {
212225 name : "nil attrs" ,
213- attrs : cty .NilVal ,
226+ attrs : PolicyValue { Raw : cty .NilVal } ,
214227 assertResponse : func (t * testing.T , resp EvaluationResponse ) {
215228 t .Helper ()
216229 if resp .Overall != AllowResult {
@@ -223,7 +236,7 @@ func TestClientEvaluateProvider(t *testing.T) {
223236 },
224237 {
225238 name : "unknown attrs" ,
226- attrs : cty .UnknownVal (cty .EmptyObject ),
239+ attrs : PolicyValue { Raw : cty .UnknownVal (cty .EmptyObject )} ,
227240 assertResponse : func (t * testing.T , resp EvaluationResponse ) {
228241 t .Helper ()
229242 if resp .Overall != AllowResult {
@@ -236,7 +249,7 @@ func TestClientEvaluateProvider(t *testing.T) {
236249 },
237250 {
238251 name : "non-nil attrs" ,
239- attrs : cty .ObjectVal (map [string ]cty.Value {"name" : cty .StringVal ("test" )}),
252+ attrs : PolicyValue { Raw : cty .ObjectVal (map [string ]cty.Value {"name" : cty .StringVal ("test" )})} ,
240253 assertResponse : func (t * testing.T , resp EvaluationResponse ) {
241254 t .Helper ()
242255 if resp .Overall != AllowResult {
@@ -249,7 +262,7 @@ func TestClientEvaluateProvider(t *testing.T) {
249262 },
250263 {
251264 name : "transforms diagnostics from response" ,
252- attrs : cty .NilVal ,
265+ attrs : PolicyValue { Raw : cty .NilVal } ,
253266 evaluateProviderFn : func (req * proto.PolicyEvaluateProviderRequest ) (* proto.PolicyEvaluateProviderResponse , error ) {
254267 return & proto.PolicyEvaluateProviderResponse {
255268 Result : proto .EvaluateResult_DENY_EVALUATE_RESULT ,
0 commit comments