You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ju...@apache.org on 2015/10/29 20:00:56 UTC

kafka git commit: KAFKA-2705; Remove static JAAS config file for ZK auth tests

Repository: kafka
Updated Branches:
  refs/heads/trunk 217eb9044 -> 42bcc4339


KAFKA-2705; Remove static JAAS config file for ZK auth tests

Remove static login config file.

Author: Flavio Junqueira <fp...@apache.org>

Reviewers: Jun Rao <ju...@gmail.com>

Closes #380 from fpj/KAFKA-2705


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/42bcc433
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/42bcc433
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/42bcc433

Branch: refs/heads/trunk
Commit: 42bcc4339f41bed320edde8bf141d0702798c021
Parents: 217eb90
Author: Flavio Junqueira <fp...@apache.org>
Authored: Thu Oct 29 12:00:50 2015 -0700
Committer: Jun Rao <ju...@gmail.com>
Committed: Thu Oct 29 12:00:50 2015 -0700

----------------------------------------------------------------------
 core/src/test/resources/zk-digest-jaas.conf     | 23 -----------
 .../security/auth/ZkAuthorizationTest.scala     |  6 +--
 .../scala/unit/kafka/utils/JaasTestUtils.scala  | 40 ++++++++++++++++++++
 .../scala/unit/kafka/zk/ZKEphemeralTest.scala   |  6 +--
 4 files changed, 44 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/42bcc433/core/src/test/resources/zk-digest-jaas.conf
----------------------------------------------------------------------
diff --git a/core/src/test/resources/zk-digest-jaas.conf b/core/src/test/resources/zk-digest-jaas.conf
deleted file mode 100644
index 49ff60f..0000000
--- a/core/src/test/resources/zk-digest-jaas.conf
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
-* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
-* file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
-* to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
-* License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
-* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations under the License.
-*/
-Server {
-       org.apache.zookeeper.server.auth.DigestLoginModule required
-       user_super="adminsecret"
-       user_fpj="fpjsecret";
-};
-
-Client {
-       org.apache.zookeeper.server.auth.DigestLoginModule required
-       username="fpj"
-       password="fpjsecret";
-};

http://git-wip-us.apache.org/repos/asf/kafka/blob/42bcc433/core/src/test/scala/unit/kafka/security/auth/ZkAuthorizationTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/security/auth/ZkAuthorizationTest.scala b/core/src/test/scala/unit/kafka/security/auth/ZkAuthorizationTest.scala
index 5f3c4ce..7b8ba74 100644
--- a/core/src/test/scala/unit/kafka/security/auth/ZkAuthorizationTest.scala
+++ b/core/src/test/scala/unit/kafka/security/auth/ZkAuthorizationTest.scala
@@ -30,13 +30,11 @@ import scala.util.{Try, Success, Failure}
 
 
 class ZkAuthorizationTest extends ZooKeeperTestHarness with Logging{
-  val jaasFile: String = "zk-digest-jaas.conf"
+  val jaasFile: String = kafka.utils.JaasTestUtils.genZkFile
   val authProvider: String = "zookeeper.authProvider.1"
   @Before
   override def setUp() {
-    val classLoader = getClass.getClassLoader
-    val filePath = classLoader.getResource(jaasFile).getPath
-    System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, filePath)
+    System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, jaasFile)
     System.setProperty(authProvider, "org.apache.zookeeper.server.auth.SASLAuthenticationProvider")
     super.setUp()
   }

http://git-wip-us.apache.org/repos/asf/kafka/blob/42bcc433/core/src/test/scala/unit/kafka/utils/JaasTestUtils.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/utils/JaasTestUtils.scala b/core/src/test/scala/unit/kafka/utils/JaasTestUtils.scala
new file mode 100644
index 0000000..78a74d5
--- /dev/null
+++ b/core/src/test/scala/unit/kafka/utils/JaasTestUtils.scala
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package kafka.utils
+
+
+object JaasTestUtils {
+  val serverContextName = "Server"
+  val userSuperPasswd = "adminpasswd"
+  val user = "fpj"
+  val userPasswd = "fpjsecret"
+  val module = "org.apache.zookeeper.server.auth.DigestLoginModule"
+
+  def genZkFile: String = {
+    val jaasFile = java.io.File.createTempFile("jaas", "conf")
+    val jaasOutputStream = new java.io.FileOutputStream(jaasFile)
+    jaasOutputStream.write(s"Server {\n\t$module required\n".getBytes)
+    jaasOutputStream.write(s"""\tuser_super="$userSuperPasswd"\n""".getBytes)
+    jaasOutputStream.write(s"""\tuser_$user="$userPasswd";\n};\n\n""".getBytes)
+    jaasOutputStream.write(s"""Client {\n\t$module required\n""".getBytes)
+    jaasOutputStream.write(s"""\tusername="$user"\n""".getBytes)
+    jaasOutputStream.write(s"""\tpassword="$userPasswd";\n};""".getBytes)
+    jaasOutputStream.close()
+    jaasFile.deleteOnExit()
+    jaasFile.getCanonicalPath
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/kafka/blob/42bcc433/core/src/test/scala/unit/kafka/zk/ZKEphemeralTest.scala
----------------------------------------------------------------------
diff --git a/core/src/test/scala/unit/kafka/zk/ZKEphemeralTest.scala b/core/src/test/scala/unit/kafka/zk/ZKEphemeralTest.scala
index cfcdc35..0486313 100644
--- a/core/src/test/scala/unit/kafka/zk/ZKEphemeralTest.scala
+++ b/core/src/test/scala/unit/kafka/zk/ZKEphemeralTest.scala
@@ -48,16 +48,14 @@ object ZKEphemeralTest {
 
 @RunWith(value = classOf[Parameterized])
 class ZKEphemeralTest(val secure: Boolean) extends ZooKeeperTestHarness {
-  val jaasFile: String = "zk-digest-jaas.conf"
+  val jaasFile: String = kafka.utils.JaasTestUtils.genZkFile
   val authProvider: String = "zookeeper.authProvider.1"
   var zkSessionTimeoutMs = 1000
   
   @Before
   override def setUp() {
     if(secure) {
-      val classLoader = getClass.getClassLoader
-      val filePath = classLoader.getResource(jaasFile).getPath
-      System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, filePath)
+      System.setProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM, jaasFile)
       System.setProperty(authProvider, "org.apache.zookeeper.server.auth.SASLAuthenticationProvider")
       if(!JaasUtils.isZkSecurityEnabled(System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM))) {
         fail("Secure access not enabled")