jolshan commented on code in PR #12855:
URL: https://github.com/apache/kafka/pull/12855#discussion_r1044762017
##########
core/src/test/scala/unit/kafka/server/KafkaApisTest.scala:
##########
@@ -2061,32 +2072,58 @@ class KafkaApisTest {
@Test
def testHandleDescribeGroupsAuthenticationFailed(): Unit = {
- val describeGroupsRequest = new DescribeGroupsRequestData()
- .setGroups(List(
- "group-1",
- "group-2",
- "group-3"
- ).asJava)
+ val describeGroupsRequest = new DescribeGroupsRequestData().setGroups(List(
+ "group-1",
+ "group-2",
+ "group-3"
+ ).asJava)
val requestChannelRequest = buildRequest(new
DescribeGroupsRequest.Builder(describeGroupsRequest).build())
val authorizer: Authorizer = mock(classOf[Authorizer])
- when(authorizer.authorize(any[RequestContext], any[util.List[Action]]))
- .thenReturn(Seq(AuthorizationResult.DENIED).asJava)
+
+ val acls = Map(
+ "group-1" -> AuthorizationResult.DENIED,
+ "group-2" -> AuthorizationResult.ALLOWED,
+ "group-3" -> AuthorizationResult.DENIED
+ )
+
+ when(authorizer.authorize(
+ any[RequestContext],
+ any[util.List[Action]]
+ )).thenAnswer { invocation =>
+ val actions = invocation.getArgument(1, classOf[util.List[Action]])
+ actions.asScala.map { action =>
+ acls.getOrElse(action.resourcePattern.name, AuthorizationResult.DENIED)
+ }.asJava
+ }
+
+ val future = new
CompletableFuture[util.List[DescribeGroupsResponseData.DescribedGroup]]()
+ when(newGroupCoordinator.describeGroup(
+ requestChannelRequest.context,
+ List("group-2").asJava
+ )).thenReturn(future)
createKafkaApis(authorizer =
Some(authorizer)).handleDescribeGroupsRequest(requestChannelRequest)
- val expectedDescribeGroupsResponse = new DescribeGroupsResponseData()
- .setGroups(List(
- new DescribeGroupsResponseData.DescribedGroup()
- .setGroupId("group-1")
- .setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code),
- new DescribeGroupsResponseData.DescribedGroup()
- .setGroupId("group-2")
- .setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code),
- new DescribeGroupsResponseData.DescribedGroup()
- .setGroupId("group-3")
- .setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code)).asJava)
+ future.complete(List(
+ new DescribeGroupsResponseData.DescribedGroup()
+ .setGroupId("group-2")
+ .setErrorCode(Errors.NOT_COORDINATOR.code)
+ ).asJava)
+
+ val expectedDescribeGroupsResponse = new
DescribeGroupsResponseData().setGroups(List(
+ // group-1 and group-3 are first because unauthorized are put first into
the response.
Review Comment:
I think this is a good addition to test. 👍
--
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]