goiri commented on code in PR #4354: URL: https://github.com/apache/hadoop/pull/4354#discussion_r898608726
########## hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/security/TestSecureLogin.java: ########## @@ -0,0 +1,94 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.hadoop.yarn.server.router.security; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.CommonConfigurationKeysPublic; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.server.router.Router; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import org.apache.hadoop.minikdc.MiniKdc; +import org.junit.Test; +import org.apache.hadoop.security.authentication.KerberosTestUtils; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class TestSecureLogin { + + private static final File TEST_ROOT_DIR = new File("target", + TestSecureLogin.class.getName() + "-root"); + private static File routerKeytabFile = new File( + KerberosTestUtils.getKeytabFile()); + + private static MiniKdc testMiniKDC; + private static Router router; + private static Configuration conf; + + @BeforeClass + public static void setUp() { + try { + testMiniKDC = new MiniKdc(MiniKdc.createConf(), TEST_ROOT_DIR); + testMiniKDC.start(); + testMiniKDC.createPrincipal(routerKeytabFile, "yarn/localhost"); + } catch (Exception e) { + fail("Couldn't setup MiniKDC"); + } + } + + @Test + public void testRouterSecureLogin() { + try { + conf = new YarnConfiguration(); + conf.set(YarnConfiguration.ROUTER_BIND_HOST, "0.0.0.0"); + conf.set(YarnConfiguration.ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE, + "org.apache.hadoop.yarn.server.router.clientrm.FederationClientInterceptor"); + conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, + "kerberos"); + conf.set("yarn.router.principal", "yarn/[email protected]"); + conf.set("yarn.router.keytab", routerKeytabFile.getAbsolutePath()); + assertEquals(UserGroupInformation.getLoginUser() + .getAuthenticationMethod(), AuthenticationMethod.SIMPLE); + UserGroupInformation.setConfiguration(conf); + router = new Router(); + router.init(conf); + router.start(); + assertEquals(UserGroupInformation.getLoginUser() + .getAuthenticationMethod(), AuthenticationMethod.KERBEROS); + assertEquals(UserGroupInformation.getLoginUser().getUserName(), + "yarn/[email protected]"); + } catch (Throwable t) { + fail("Can't start router!"); + } finally { + router.stop(); + } + } + + @AfterClass + public static void cleanUp() { + if (testMiniKDC != null) { + testMiniKDC.stop(); Review Comment: I mean that after you shut it down, set it to null -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
