walterddr commented on a change in pull request #12462: URL: https://github.com/apache/flink/pull/12462#discussion_r434627463
########## File path: flink-filesystems/flink-hadoop-fs/src/test/java/org/apache/flink/runtime/util/HadoopUtilsTest.java ########## @@ -0,0 +1,49 @@ +/* + * 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.flink.runtime.util; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Unit tests for Hadoop utils. + */ +public class HadoopUtilsTest { + + @Test + public void testShouldNotCheckKerberosCredentialsForOtherAuthMethods() throws Exception { + UserGroupInformation.setConfiguration(getHadoopConfigWithAuthMethodOtherThanKerberos()); + UserGroupInformation user = UserGroupInformation.createUserForTesting("test-user", new String[]{"user-group"}); + + boolean result = HadoopUtils.isCredentialsConfigured(user, true); + + assertTrue(result); + } + + private static Configuration getHadoopConfigWithAuthMethodOtherThanKerberos() { Review comment: we can probably generalize this so we can test both side ``` Configuration getHadoopConfigWithAutMethod(AuthenticationMethod method) { // ... ``` ########## File path: flink-filesystems/flink-hadoop-fs/src/main/java/org/apache/flink/runtime/util/HadoopUtils.java ########## @@ -113,7 +113,8 @@ public static Configuration getHadoopConfiguration(org.apache.flink.configuratio } public static boolean isCredentialsConfigured(UserGroupInformation ugi, boolean useTicketCache) throws Exception { - if (UserGroupInformation.isSecurityEnabled()) { + if (UserGroupInformation.isSecurityEnabled() + && ugi.getAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.KERBEROS) { Review comment: adding this line means the function name should not be `isCredentialsConfigured` but more like `isKerberosCredentialsConfigured`. I was wondering if we should change the public API naming. ########## File path: flink-filesystems/flink-hadoop-fs/src/test/java/org/apache/flink/runtime/util/HadoopUtilsTest.java ########## @@ -0,0 +1,49 @@ +/* + * 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.flink.runtime.util; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Unit tests for Hadoop utils. + */ +public class HadoopUtilsTest { + + @Test + public void testShouldNotCheckKerberosCredentialsForOtherAuthMethods() throws Exception { Review comment: can you also add another test that verifies Kerberos-based auth actually walk into the if branch? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
