@@ -63,6 +63,30 @@ func postureLabelsRegexExceptionPolicyAlertOnlyMock() *armotypes.PostureExceptio
6363 }
6464}
6565
66+ func postureResourceIDExceptionPolicyMock (resourceID string ) * armotypes.PostureExceptionPolicy {
67+ return & armotypes.PostureExceptionPolicy {
68+ PortalBase : armotypes.PortalBase {
69+ Name : "postureResourceIDExceptionPolicyMock" ,
70+ },
71+ PolicyType : "postureExceptionPolicy" ,
72+ Actions : []armotypes.PostureExceptionPolicyActions {armotypes .AlertOnly },
73+ Resources : []armotypes.PortalDesignator {
74+ {
75+ DesignatorType : armotypes .DesignatorAttributes ,
76+ Attributes : map [string ]string {
77+ armotypes .AttributeCluster : "test" ,
78+ armotypes .AttributeResourceID : resourceID ,
79+ },
80+ },
81+ },
82+ PosturePolicies : []armotypes.PosturePolicy {
83+ {
84+ FrameworkName : "MIT.*" ,
85+ },
86+ },
87+ }
88+ }
89+
6690func emptyPostureExceptionPolicyAlertOnlyMock () * armotypes.PostureExceptionPolicy {
6791 return & armotypes.PostureExceptionPolicy {
6892 PortalBase : armotypes.PortalBase {
@@ -153,6 +177,13 @@ func TestGetResourceExceptions(t *testing.T) {
153177 withAnnotationObj , err := workloadinterface .NewBaseObjBytes ([]byte (`{"apiVersion": "v1", "kind":"Deployment", "metadata": {"name": "test", "annotations": {"myLabelOrAnnotation" : "static_test"}}}` ))
154178 require .NoError (t , err )
155179
180+ idObj , err := workloadinterface .NewBaseObjBytes ([]byte (`{"apiVersion": "v1/core", "kind":"Deployment", "metadata": {"name": "test", "namespace": "default"}}` ))
181+ require .NoError (t , err )
182+
183+ exceptionPolicyResourceID := postureResourceIDExceptionPolicyMock (idObj .GetID ())
184+ exceptionPolicyResourceIDRegex := postureResourceIDExceptionPolicyMock ("*" )
185+ exceptionPolicyResourceOtherID := postureResourceIDExceptionPolicyMock ("v1/core/default/ConfigMap/test" )
186+
156187 exceptionPolicy := postureLabelsRegexExceptionPolicyAlertOnlyMock ()
157188 exceptionPolicyRegex := postureLabelsRegexExceptionPolicyAlertOnlyMock ()
158189 exceptionPolicyRegex .Resources [0 ].Attributes ["myLabelOrAnnotation" ] = "static_.*"
@@ -201,14 +232,32 @@ func TestGetResourceExceptions(t *testing.T) {
201232 workloadObj : withAnnotationObj ,
202233 expectedExceptionsCount : 1 ,
203234 },
235+ {
236+ desc : "exception by ID" ,
237+ exceptionPolicy : exceptionPolicyResourceID ,
238+ workloadObj : idObj ,
239+ expectedExceptionsCount : 1 ,
240+ },
241+ {
242+ desc : "exception by ID regex" ,
243+ exceptionPolicy : exceptionPolicyResourceIDRegex ,
244+ workloadObj : idObj ,
245+ expectedExceptionsCount : 1 ,
246+ },
247+ {
248+ desc : "exception with not matching ID" ,
249+ exceptionPolicy : exceptionPolicyResourceOtherID ,
250+ workloadObj : idObj ,
251+ expectedExceptionsCount : 0 ,
252+ },
204253 }
205254
206255 for _ , test := range testCases {
207256 test := test
208257 t .Run (test .desc , func (t * testing.T ) {
209258 t .Parallel ()
210259
211- res := p .GetResourceExceptions ([]armotypes.PostureExceptionPolicy {* exceptionPolicy }, test .workloadObj , "" )
260+ res := p .GetResourceExceptions ([]armotypes.PostureExceptionPolicy {* test . exceptionPolicy }, test .workloadObj , "test " )
212261 assert .Equal (t , test .expectedExceptionsCount , len (res ))
213262 })
214263 }
0 commit comments