@@ -14,8 +14,17 @@ package example
1414
1515deny[msg] {
1616 input.apiVersion == "badVersion"
17- input.extraKey == "extraBadValue"
1817 msg = "Cannot have bad api version"
18+ }
19+
20+ deny[msg] {
21+ input.extraKey == "extraBadValue"
22+ msg = "Cannot have bad extra key"
23+ }
24+
25+ deny[msg] {
26+ input.extraKey2 == "warnValue"
27+ msg = "WARN: Cannot have warn value"
1928}`
2029
2130 allowPolicyStr = `
@@ -56,9 +65,6 @@ func TestPolicyChecker(t *testing.T) {
5665 Contents : denyPolicyStr ,
5766 Package : "example" ,
5867 Result : "deny" ,
59- ExtraFields : map [string ]interface {}{
60- "extraKey" : "extraBadValue" ,
61- },
6268 },
6369 resource : MakeResource ("test/path" , []byte (goodVersionResourceStr ), 0 ),
6470 expected : CheckResult {
@@ -82,8 +88,32 @@ func TestPolicyChecker(t *testing.T) {
8288 expected : CheckResult {
8389 CheckType : CheckTypeOPA ,
8490 CheckName : "testDenyPolicy" ,
85- Status : StatusValid ,
86- Message : "Policy returned 0 deny reasons" ,
91+ Status : StatusInvalid ,
92+ Message : "Policy returned 1 deny reason(s)" ,
93+ Reasons : []string {
94+ "Cannot have bad api version" ,
95+ },
96+ },
97+ },
98+ {
99+ policyModule : PolicyModule {
100+ Name : "testDenyPolicy" ,
101+ Contents : denyPolicyStr ,
102+ Package : "example" ,
103+ Result : "deny" ,
104+ ExtraFields : map [string ]interface {}{
105+ "extraKey2" : "warnValue" ,
106+ },
107+ },
108+ resource : MakeResource ("test/path" , []byte (goodVersionResourceStr ), 0 ),
109+ expected : CheckResult {
110+ CheckType : CheckTypeOPA ,
111+ CheckName : "testDenyPolicy" ,
112+ Status : StatusWarning ,
113+ Message : "Policy returned 1 warn reason(s)" ,
114+ Reasons : []string {
115+ "WARN: Cannot have warn value" ,
116+ },
87117 },
88118 },
89119 {
@@ -101,7 +131,35 @@ func TestPolicyChecker(t *testing.T) {
101131 CheckType : CheckTypeOPA ,
102132 CheckName : "testDenyPolicy" ,
103133 Status : StatusInvalid ,
104- Message : "Policy returned 1 deny reason(s): [Cannot have bad api version]" ,
134+ Message : "Policy returned 2 deny reason(s)" ,
135+ Reasons : []string {
136+ "Cannot have bad extra key" ,
137+ "Cannot have bad api version" ,
138+ },
139+ },
140+ },
141+ {
142+ policyModule : PolicyModule {
143+ Name : "testDenyPolicy" ,
144+ Contents : denyPolicyStr ,
145+ Package : "example" ,
146+ Result : "deny" ,
147+ ExtraFields : map [string ]interface {}{
148+ "extraKey" : "extraBadValue" ,
149+ "extraKey2" : "warnValue" ,
150+ },
151+ },
152+ resource : MakeResource ("test/path" , []byte (badVersionResourceStr ), 0 ),
153+ expected : CheckResult {
154+ CheckType : CheckTypeOPA ,
155+ CheckName : "testDenyPolicy" ,
156+ Status : StatusInvalid ,
157+ Message : "Policy returned 2 deny reason(s) and 1 warn reason(s)" ,
158+ Reasons : []string {
159+ "Cannot have bad extra key" ,
160+ "Cannot have bad api version" ,
161+ "WARN: Cannot have warn value" ,
162+ },
105163 },
106164 },
107165 {
0 commit comments