This commit is contained in:
Kent Yao 2018-12-06 11:02:15 +08:00
parent cf617ee5a6
commit 0a166e71ae
2 changed files with 22 additions and 1 deletions

View File

@ -17,22 +17,44 @@
package yaooqinn.kyuubi
import java.io.IOException
import org.apache.hadoop.minikdc.MiniKdc
import org.apache.hadoop.security.UserGroupInformation
import org.apache.spark.{KyuubiSparkUtil, SparkConf}
trait SecuredFunSuite {
var kdc: MiniKdc = null
val baseDir = KyuubiSparkUtil.createTempDir(namePrefix = "kyuubi-kdc")
try {
val kdcConf = MiniKdc.createConf()
kdcConf.setProperty(MiniKdc.INSTANCE, "KyuubiKrbServer")
kdcConf.setProperty(MiniKdc.ORG_NAME, "KYUUBI")
kdcConf.setProperty(MiniKdc.ORG_DOMAIN, "COM")
if (kdc == null) {
kdc = new MiniKdc(kdcConf, baseDir)
kdc.start()
}
} catch {
case e: IOException =>
throw new AssertionError("unable to create temporary directory: " + e.getMessage)
}
def tryWithSecurityEnabled(block: => Unit): Unit = {
val conf = new SparkConf(true)
assert(!UserGroupInformation.isSecurityEnabled)
val authType = "spark.hadoop.hadoop.security.authentication"
try {
conf.set(authType, "KERBEROS")
System.setProperty("java.security.krb5.realm", kdc.getRealm)
UserGroupInformation.setConfiguration(KyuubiSparkUtil.newConfiguration(conf))
assert(UserGroupInformation.isSecurityEnabled)
block
} finally {
conf.remove(authType)
System.clearProperty("java.security.krb5.realm")
UserGroupInformation.setConfiguration(KyuubiSparkUtil.newConfiguration(conf))
assert(!UserGroupInformation.isSecurityEnabled)
}

View File

@ -46,7 +46,6 @@ class KyuubiSessionSecuredSuite extends SparkFunSuite with SecuredFunSuite {
super.afterAll()
}
test("secured ugi test") {
val be = server.beService
val sessionMgr = be.getSessionManager