hsheinblatt commented on code in PR #1402:
URL: https://github.com/apache/knox/pull/1402#discussion_r4021722170


##########
gateway-server/src/test/java/org/apache/knox/gateway/services/knoxidf/delegation/JdbcDelegationPolicyServiceTest.java:
##########
@@ -859,14 +861,123 @@ public void testEvaluateDenyHeadlessNotAllowed() throws 
Exception {
   }
 
   @Test
-  public void testEvaluateGroupsNotEmptyThrowsServerError() throws Exception {
+  public void testEvaluateAuthorizedViaGroupMembership() throws Exception {
     registerPolicy("oidc", "groups",
         Collections.emptySet(),
         new HashSet<>(Collections.singleton("admins")),
         singleResourcePolicy("/api", "read"));
 
-    assertThrows(UnsupportedOperationException.class, () ->
+    final KnoxLDAPService ldap = EasyMock.createMock(KnoxLDAPService.class);
+    EasyMock.expect(ldap.isEnabled()).andReturn(true).anyTimes();
+    
EasyMock.expect(ldap.getUserGroups("alice")).andReturn(Arrays.asList("users", 
"admins")).once();
+    EasyMock.replay(ldap);
+    service.setLdapService(ldap);
+
+    final PolicyDecision decision = service.evaluate(
+        new PolicyCheckRequest("oidc", "groups", "alice", Set.of("/api"), 
Collections.singleton("read"), false));
+
+    assertNull("group membership should authorize the exchange", 
decision.getDenyReason());
+    assertEquals(CONFIGURED_TTL, decision.getEffectiveTtlSec());
+    EasyMock.verify(ldap);
+  }
+
+  @Test
+  public void testEvaluateDenyWhenSubjectInNoAllowedGroup() throws Exception {
+    registerPolicy("oidc", "groups",
+        Collections.emptySet(),
+        new HashSet<>(Collections.singleton("admins")),
+        singleResourcePolicy("/api", "read"));
+
+    final KnoxLDAPService ldap = EasyMock.createMock(KnoxLDAPService.class);
+    EasyMock.expect(ldap.isEnabled()).andReturn(true).anyTimes();
+    
EasyMock.expect(ldap.getUserGroups("alice")).andReturn(Collections.singletonList("users")).once();
+    EasyMock.replay(ldap);
+    service.setLdapService(ldap);
+
+    final PolicyDecision decision = service.evaluate(
+        new PolicyCheckRequest("oidc", "groups", "alice", Set.of("/api"), 
Collections.singleton("read"), false));
+
+    assertEquals("subject_not_allowed", decision.getDenyReason());
+    EasyMock.verify(ldap);
+  }

Review Comment:
   Arguably also boundary when the user is in no groups.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to