Skip to content

Commit

Permalink
refactor ldap suite
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Oct 23, 2021
1 parent 8545a03 commit 95ddd35
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,18 @@ package org.apache.kyuubi.service.authentication
import javax.naming.CommunicationException
import javax.security.sasl.AuthenticationException

import com.unboundid.ldap.listener.InMemoryDirectoryServer
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig

import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf._

class LdapAuthenticationProviderImplSuite extends KyuubiFunSuite {

private var ldapServer: InMemoryDirectoryServer = _
class LdapAuthenticationProviderImplSuite extends WithLdapServer {
override protected val user: String = "kentyao"
override protected val password: String = "kentyao"

private val conf = new KyuubiConf()

override def beforeAll(): Unit = {
val config = new InMemoryDirectoryServerConfig("ou=users")
config.addAdditionalBindCredentials("uid=kentyao,ou=users", "kentyao")
ldapServer = new InMemoryDirectoryServer(config)
ldapServer.startListening()

conf.set(AUTHENTICATION_LDAP_URL, s"ldap://localhost:" + ldapServer.getListenPort)

super.beforeAll()
conf.set(AUTHENTICATION_LDAP_URL, ldapUrl)
}

override def afterAll(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 org.apache.kyuubi.service.authentication

import com.unboundid.ldap.listener.{InMemoryDirectoryServer, InMemoryDirectoryServerConfig}

import org.apache.kyuubi.{KyuubiFunSuite, Utils}

class WithLdapServer extends KyuubiFunSuite {
protected var ldapServer: InMemoryDirectoryServer = _
protected val user = Utils.currentUser
protected val password = "password"

protected def ldapUrl = s"ldap://localhost:${ldapServer.getListenPort}"

override def beforeAll(): Unit = {
val config = new InMemoryDirectoryServerConfig("ou=users")
config.addAdditionalBindCredentials(s"uid=${user},ou=users", password)
ldapServer = new InMemoryDirectoryServer()
ldapServer.startListening()
super.beforeAll()
}

override def afterAll(): Unit = {
ldapServer.close()
super.afterAll()
}
}

0 comments on commit 95ddd35

Please sign in to comment.