3030import org .apache .ranger .plugin .policyresourcematcher .RangerPolicyResourceMatcher ;
3131import org .apache .ranger .plugin .util .RangerAccessRequestUtil ;
3232import org .apache .ranger .plugin .util .RangerUserStore ;
33- import org .junit .After ;
34- import org .junit .Assert ;
35- import org .junit .Before ;
36- import org .junit .Test ;
33+ import org .junit .jupiter . api . AfterEach ;
34+ import org .junit .jupiter . api . Assertions ;
35+ import org .junit .jupiter . api . BeforeEach ;
36+ import org .junit .jupiter . api . Test ;
3737
3838import java .util .Arrays ;
3939import java .util .Collections ;
4949import static org .mockito .Mockito .when ;
5050
5151public class RangerCustomConditionMatcherTest {
52- @ Before
52+ @ BeforeEach
5353 public void setUp () throws Exception {
5454 }
5555
56- @ After
56+ @ AfterEach
5757 public void tearDown () throws Exception {
5858 }
5959
@@ -87,31 +87,31 @@ public void testScriptConditionEvaluator() {
8787 RangerScriptConditionEvaluator tagsTypeCondition = createScriptConditionEvaluator ("_ctx.tags['PII']._type == 'PII' && _ctx.tags['PCI']._type == 'PCI'" );
8888 RangerScriptConditionEvaluator tagsAttributesCondition = createScriptConditionEvaluator ("_ctx.tags['PII'].attr1 == 'PII_value' && _ctx.tags['PCI'].attr1 == 'PCI_value'" );
8989
90- Assert .assertTrue ("request.resource.database should be db1" , resourceDbCondition . isMatched ( request ) );
91- Assert .assertTrue ("request.resource.database should not be db2" , resourceDbCondition2 . isMatched ( request ) );
92- Assert .assertTrue ("request.resource.table should be tbl1" , resourceTblCondition . isMatched ( request ) );
93- Assert .assertTrue ("request.resource.column should be col1" , resourceColCondition . isMatched ( request ) );
94- Assert .assertTrue ("request.accessType should be select" , accessTypeCondition . isMatched ( request ) );
95- Assert .assertTrue ("request.action should be query" , actionCondition . isMatched ( request ) );
96- Assert .assertTrue ("request.user should be testUser" , userCondition . isMatched ( request ) );
97- Assert .assertTrue ("request.userGroups should have 2 entries" , userGroupsLenCondition . isMatched ( request ) );
98- Assert .assertTrue ("request.userGroups should have test-group1" , userGroupsHas1Condition . isMatched ( request ) );
99- Assert .assertTrue ("request.userGroups should have test-group2" , userGroupsHas2Condition . isMatched ( request ) );
100- Assert .assertTrue ("request.userRoles should have 2 entries" , userRolesLenCondition . isMatched ( request ) );
101- Assert .assertTrue ("request.userRoles should have test-role1" , userRolesHas1Condition . isMatched ( request ) );
102- Assert .assertTrue ("request.userRoles should have test-role2" , userRolesHas2Condition . isMatched ( request ) );
103- Assert .assertTrue ("request.userAttributes should have 3 entries" , userAttrLenCondition . isMatched ( request ) );
104- Assert .assertTrue ("request.userAttributes[attr1] should be test-user-value1" , userAttr1Condition . isMatched ( request ) );
105- Assert .assertTrue ("request.userAttributes[attr2] should be test-user-value2" , userAttr2Condition . isMatched ( request ) );
106- Assert .assertTrue ("request.userGroup1Attributes[attr1] should be test-group1-value1" , userGroup1Attr1Condition . isMatched ( request ) );
107- Assert .assertTrue ("request.userGroup1Attributes[attr2] should be test-group1-value2" , userGroup1Attr2Condition . isMatched ( request ) );
108- Assert .assertTrue ("request.userGroup2Attributes[attr1] should be test-group2-value1" , userGroup2Attr1Condition . isMatched ( request ) );
109- Assert .assertTrue ("request.userGroup2Attributes[attr2] should be test-group2-value2" , userGroup2Attr2Condition . isMatched ( request ) );
110- Assert .assertTrue ("tag._type should be PCI" , tagTypeCondition . isMatched ( request ) );
111- Assert .assertTrue ("tag.attr1 should be PCI_value" , tagAttributesCondition . isMatched ( request ) );
112- Assert .assertTrue ("should have 2 tags" , tagsLengthCondition . isMatched ( request ) );
113- Assert .assertTrue ("tags PCI and PII should be found" , tagsTypeCondition . isMatched ( request ) );
114- Assert .assertTrue ("tag attributes for PCI and PII should be found" , tagsAttributesCondition . isMatched ( request ) );
90+ Assertions .assertTrue (resourceDbCondition . isMatched ( request ), "request.resource.database should be db1" );
91+ Assertions .assertTrue (resourceDbCondition2 . isMatched ( request ), "request.resource.database should not be db2" );
92+ Assertions .assertTrue (resourceTblCondition . isMatched ( request ), "request.resource.table should be tbl1" );
93+ Assertions .assertTrue (resourceColCondition . isMatched ( request ), "request.resource.column should be col1" );
94+ Assertions .assertTrue (accessTypeCondition . isMatched ( request ), "request.accessType should be select" );
95+ Assertions .assertTrue (actionCondition . isMatched ( request ), "request.action should be query" );
96+ Assertions .assertTrue (userCondition . isMatched ( request ), "request.user should be testUser" );
97+ Assertions .assertTrue (userGroupsLenCondition . isMatched ( request ), "request.userGroups should have 2 entries" );
98+ Assertions .assertTrue (userGroupsHas1Condition . isMatched ( request ), "request.userGroups should have test-group1" );
99+ Assertions .assertTrue (userGroupsHas2Condition . isMatched ( request ), "request.userGroups should have test-group2" );
100+ Assertions .assertTrue (userRolesLenCondition . isMatched ( request ), "request.userRoles should have 2 entries" );
101+ Assertions .assertTrue (userRolesHas1Condition . isMatched ( request ), "request.userRoles should have test-role1" );
102+ Assertions .assertTrue (userRolesHas2Condition . isMatched ( request ), "request.userRoles should have test-role2" );
103+ Assertions .assertTrue (userAttrLenCondition . isMatched ( request ), "request.userAttributes should have 3 entries" );
104+ Assertions .assertTrue (userAttr1Condition . isMatched ( request ), "request.userAttributes[attr1] should be test-user-value1" );
105+ Assertions .assertTrue (userAttr2Condition . isMatched ( request ), "request.userAttributes[attr2] should be test-user-value2" );
106+ Assertions .assertTrue (userGroup1Attr1Condition . isMatched ( request ), "request.userGroup1Attributes[attr1] should be test-group1-value1" );
107+ Assertions .assertTrue (userGroup1Attr2Condition . isMatched ( request ), "request.userGroup1Attributes[attr2] should be test-group1-value2" );
108+ Assertions .assertTrue (userGroup2Attr1Condition . isMatched ( request ), "request.userGroup2Attributes[attr1] should be test-group2-value1" );
109+ Assertions .assertTrue (userGroup2Attr2Condition . isMatched ( request ), "request.userGroup2Attributes[attr2] should be test-group2-value2" );
110+ Assertions .assertTrue (tagTypeCondition . isMatched ( request ), "tag._type should be PCI" );
111+ Assertions .assertTrue (tagAttributesCondition . isMatched ( request ), "tag.attr1 should be PCI_value" );
112+ Assertions .assertTrue (tagsLengthCondition . isMatched ( request ), "should have 2 tags" );
113+ Assertions .assertTrue (tagsTypeCondition . isMatched ( request ), "tags PCI and PII should be found" );
114+ Assertions .assertTrue (tagsAttributesCondition . isMatched ( request ), "tag attributes for PCI and PII should be found" );
115115 }
116116
117117 @ Test
@@ -121,37 +121,37 @@ public void testRangerAnyOfExpectedTagsPresentConditionEvaluator() {
121121
122122 // When any tag in the resourceTags matches policyConditionTags it should return TRUE
123123 List <String > resourceTags = Arrays .asList ("PCI" , "PHI" );
124- Assert .assertTrue (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
124+ Assertions .assertTrue (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
125125 resourceTags = Arrays .asList ("PHI" , "PII" , "HIPPA" );
126- Assert .assertTrue (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
126+ Assertions .assertTrue (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
127127
128128 // When no Tag Matches between resourceTags and PolicyConditionTags it should return FALSE
129129 resourceTags = Arrays .asList ("HIPPA" , "PHI" );
130- Assert .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
130+ Assertions .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
131131
132132 // When policyConditionTags and resourceTags contains empty set it should return TRUE as empty set matches.
133133 policyConditionTags = Arrays .asList ("" );
134134 resourceTags = Arrays .asList ("" );
135135 tagsAnyPresentConditionEvaluator = createRangerAnyOfExpectedTagsPresentConditionEvaluator (policyConditionTags );
136- Assert .assertTrue (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
136+ Assertions .assertTrue (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
137137
138138 // When policyConditionTags is not empty and resourceTags empty it should return FALSE as there is no any match.
139139 policyConditionTags = Arrays .asList ("PCI" , "PII" );
140140 resourceTags = Arrays .asList ("" );
141141 tagsAnyPresentConditionEvaluator = createRangerAnyOfExpectedTagsPresentConditionEvaluator (policyConditionTags );
142- Assert .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
142+ Assertions .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
143143
144144 // When policyConditionTags is empty and resourceTags in not empty it should return FALSE as there is no any match.
145145 policyConditionTags = Arrays .asList ("" );
146146 resourceTags = Arrays .asList ("PCI" , "PII" );
147147 tagsAnyPresentConditionEvaluator = createRangerAnyOfExpectedTagsPresentConditionEvaluator (policyConditionTags );
148- Assert .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
148+ Assertions .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
149149
150150 // When policyConditionTags is not empty and resourceTags is NULL it should return FALSE as there is no any match.
151151 policyConditionTags = Arrays .asList ("PCI" , "PII" );
152152 resourceTags = null ;
153153 tagsAnyPresentConditionEvaluator = createRangerAnyOfExpectedTagsPresentConditionEvaluator (policyConditionTags );
154- Assert .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
154+ Assertions .assertFalse (tagsAnyPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
155155 }
156156
157157 @ Test
@@ -161,35 +161,35 @@ public void testRangerTagsNotPresentConditionEvaluator() {
161161
162162 // When no Tag Matches between resourceTags and PolicyConditionTags it should return TRUE
163163 List <String > resourceTags = Arrays .asList ("HIPPA" , "PHI" );
164- Assert .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
164+ Assertions .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
165165
166166 // When any Tag Matches between resourceTags and PolicyConditionTags it should return FALSE
167167 resourceTags = Arrays .asList ("HIPPA" , "PII" , "" );
168- Assert .assertFalse (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
168+ Assertions .assertFalse (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
169169
170170 // When policyConditionTags and resourceTags both are empty is should return FALSE as both matches.
171171 policyConditionTags = Arrays .asList ("" );
172172 resourceTags = Arrays .asList ("" );
173173 tagsNotPresentConditionEvaluator = createRangerTagsNotPresentConditionEvaluator (policyConditionTags );
174- Assert .assertFalse (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
174+ Assertions .assertFalse (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
175175
176176 // When policyConditionTags is not empty and resourceTags empty it should return TRUE as there is no tag match between these two sets.
177177 policyConditionTags = Arrays .asList ("PCI" , "PII" );
178178 resourceTags = Arrays .asList ("" );
179179 tagsNotPresentConditionEvaluator = createRangerTagsNotPresentConditionEvaluator (policyConditionTags );
180- Assert .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
180+ Assertions .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
181181
182182 // When policyConditionTags is empty and resourceTags in not empty it should return TRUE as there is no tag match between these two sets.
183183 policyConditionTags = Arrays .asList ("" );
184184 resourceTags = Arrays .asList ("PCI" , "PII" );
185185 tagsNotPresentConditionEvaluator = createRangerTagsNotPresentConditionEvaluator (policyConditionTags );
186- Assert .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
186+ Assertions .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
187187
188188 // When policyConditionTags is not empty and resourceTags is NULL it should return TRUE as there is no tag match between these two sets.
189189 policyConditionTags = Arrays .asList ("PCI" , "PII" );
190190 resourceTags = Arrays .asList ("" );
191191 tagsNotPresentConditionEvaluator = createRangerTagsNotPresentConditionEvaluator (policyConditionTags );
192- Assert .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
192+ Assertions .assertTrue (tagsNotPresentConditionEvaluator .isMatched (createRequest (resourceTags )));
193193 }
194194
195195 RangerAnyOfExpectedTagsPresentConditionEvaluator createRangerAnyOfExpectedTagsPresentConditionEvaluator (List <String > policyConditionTags ) {
0 commit comments