kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject [kafka] branch trunk updated: MINOR: Test authorization of MetadataRequest with existing and non-existing topics (#5155)
Date Wed, 13 Jun 2018 00:35:41 GMT
This is an automated email from the ASF dual-hosted git repository.

ijuma pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 477ae9e  MINOR: Test authorization of MetadataRequest with existing and non-existing
topics (#5155)
477ae9e is described below

commit 477ae9e860fd2a2e605bb6d9892c6eab12ef7824
Author: Edoardo Comar <ecomar@uk.ibm.com>
AuthorDate: Wed Jun 13 01:35:26 2018 +0100

    MINOR: Test authorization of MetadataRequest with existing and non-existing topics (#5155)
    
    A bug in the original KIP-277 submission was caught during code review,
    but it was not detected by the tests. Fix that gap.
    
    Co-authored-by: Edoardo Comar <ecomar@uk.ibm.com>
    Co-authored-by: Mickael Maison <mickael.maison@gmail.com>
---
 .../kafka/api/AuthorizerIntegrationTest.scala      | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/core/src/test/scala/integration/kafka/api/AuthorizerIntegrationTest.scala b/core/src/test/scala/integration/kafka/api/AuthorizerIntegrationTest.scala
index c1923dc..7450511 100644
--- a/core/src/test/scala/integration/kafka/api/AuthorizerIntegrationTest.scala
+++ b/core/src/test/scala/integration/kafka/api/AuthorizerIntegrationTest.scala
@@ -45,6 +45,8 @@ import org.apache.kafka.common.resource.ResourceNameType.LITERAL
 import org.apache.kafka.common.resource.{ResourcePattern, ResourcePatternFilter, ResourceType
=> AdminResourceType}
 import org.apache.kafka.common.security.auth.{KafkaPrincipal, SecurityProtocol}
 import org.apache.kafka.common.{KafkaException, Node, TopicPartition, requests}
+import org.apache.kafka.test.{TestUtils => JTestUtils}
+
 import org.junit.Assert._
 import org.junit.{After, Assert, Before, Test}
 
@@ -862,6 +864,31 @@ class AuthorizerIntegrationTest extends BaseRequestTest {
     }, "Expected topic was not created")
   }
 
+  @Test
+  def testCreatePermissionMetadataRequestAutoCreate() {
+    val readAcls = topicReadAcl.get(topicResource).get
+    addAndVerifyAcls(readAcls, topicResource)
+    assertTrue(zkClient.topicExists(topicResource.name))
+
+    addAndVerifyAcls(readAcls, createTopicResource)
+    assertFalse(zkClient.topicExists(createTopic))
+
+    val metadataRequest = new MetadataRequest.Builder(List(topic, createTopic).asJava, true).build()
+    val metadataResponse = MetadataResponse.parse(connectAndSend(metadataRequest, ApiKeys.METADATA),
ApiKeys.METADATA.latestVersion)
+
+    assertEquals(Set(topic).asJava, metadataResponse.topicsByError(Errors.NONE));
+    assertEquals(Set(createTopic).asJava, metadataResponse.topicsByError(Errors.TOPIC_AUTHORIZATION_FAILED))
+
+    val createAcls = topicCreateAcl.get(createTopicResource).get
+    addAndVerifyAcls(createAcls, createTopicResource)
+
+    // retry as topic being created can have MetadataResponse with Errors.LEADER_NOT_AVAILABLE
+    TestUtils.retry(JTestUtils.DEFAULT_MAX_WAIT_MS)(() => {
+      val metadataResponse = MetadataResponse.parse(connectAndSend(metadataRequest, ApiKeys.METADATA),
ApiKeys.METADATA.latestVersion)
+      assertEquals(Set(topic, createTopic).asJava, metadataResponse.topicsByError(Errors.NONE))
+    })
+  }
+
   @Test(expected = classOf[AuthorizationException])
   def testCommitWithNoAccess() {
     this.consumers.head.commitSync(Map(tp -> new OffsetAndMetadata(5)).asJava)

-- 
To stop receiving notification emails like this one, please contact
ijuma@apache.org.

Mime
View raw message