Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjunbo committed Feb 21, 2024
1 parent a8713a6 commit dc9857a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ import javax.security.sasl.AuthenticationException

import org.apache.kyuubi.{KyuubiFunSuite, Utils}
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.THRIFT_BINARY

class AuthenticationProviderFactorySuite extends KyuubiFunSuite {

import AuthenticationProviderFactory._

test("get auth provider") {
val conf = KyuubiConf()
val p1 = getAuthenticationProvider(AuthMethods.withName("NONE"), conf)
val p1 = getAuthenticationProvider(AuthMethods.withName("NONE"), conf, THRIFT_BINARY)
p1.authenticate(Utils.currentUser, "")
val p2 = getAuthenticationProvider(AuthMethods.withName("LDAP"), conf)
val p2 = getAuthenticationProvider(AuthMethods.withName("LDAP"), conf, THRIFT_BINARY)
val e1 = intercept[AuthenticationException](p2.authenticate("test", "test"))
assert(e1.getMessage.contains("Error validating LDAP user:"))
val e2 = intercept[AuthenticationException](
AuthenticationProviderFactory.getAuthenticationProvider(null, conf))
AuthenticationProviderFactory.getAuthenticationProvider(null, conf, THRIFT_BINARY))
assert(e2.getMessage === "Not a valid authentication method")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ import javax.security.sasl.AuthenticationException

import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.THRIFT_BINARY
import org.apache.kyuubi.service.authentication.AuthenticationProviderFactory.getAuthenticationProvider

class CustomAuthenticationProviderImplSuite extends KyuubiFunSuite {
test("Test user defined authentication") {
val conf = KyuubiConf()

val e1 = intercept[AuthenticationException](
getAuthenticationProvider(AuthMethods.withName("CUSTOM"), conf))
getAuthenticationProvider(AuthMethods.withName("CUSTOM"), conf, THRIFT_BINARY))
assert(e1.getMessage.contains(
"authentication.custom.class must be set when auth method was CUSTOM."))

conf.set(
KyuubiConf.AUTHENTICATION_CUSTOM_CLASS,
classOf[UserDefineAuthenticationProviderImpl].getCanonicalName)
val p1 = getAuthenticationProvider(AuthMethods.withName("CUSTOM"), conf)
val p1 = getAuthenticationProvider(AuthMethods.withName("CUSTOM"), conf, THRIFT_BINARY)
val e2 = intercept[AuthenticationException](p1.authenticate("test", "test"))
assert(e2.getMessage.contains("Username or password is not valid!"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ package org.apache.kyuubi.server.http.authentication
import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.AUTHENTICATION_METHOD
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.{THRIFT_BINARY, THRIFT_HTTP}
import org.apache.kyuubi.service.authentication.AuthTypes

class AuthenticationFilterSuite extends KyuubiFunSuite {
test("add auth handler and destroy") {
val conf = KyuubiConf()
val filter =
new AuthenticationFilter(conf, conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName))
filter.addAuthHandler(new BasicAuthenticationHandler(null))
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
THRIFT_BINARY)
filter.addAuthHandler(new BasicAuthenticationHandler(null, THRIFT_BINARY))
assert(filter.authSchemeHandlers.isEmpty)
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP))
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP, THRIFT_BINARY))
assert(filter.authSchemeHandlers.size == 1)
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP))
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP, THRIFT_BINARY))
assert(filter.authSchemeHandlers.size == 1)
filter.addAuthHandler(new KerberosAuthenticationHandler())
assert(filter.authSchemeHandlers.size == 1)
Expand Down

0 comments on commit dc9857a

Please sign in to comment.