diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 31554b8801..042d3c50c3 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1383,6 +1383,8 @@ Release 0.23.7 - UNRELEASED HADOOP-9336. Allow UGI of current connection to be queried. (Daryn Sharp via kihwal) + HADOOP-9352. Expose UGI.setLoginUser for tests (daryn) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java index b01e12b5a4..afca92f3cc 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java @@ -67,6 +67,8 @@ import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Time; +import com.google.common.annotations.VisibleForTesting; + /** * User and group information for Hadoop. * This class wraps around a JAAS Subject and provides methods to determine the @@ -713,7 +715,8 @@ static UserGroupInformation getLoginUser() throws IOException { @InterfaceAudience.Private @InterfaceStability.Unstable - synchronized static void setLoginUser(UserGroupInformation ugi) { + @VisibleForTesting + public synchronized static void setLoginUser(UserGroupInformation ugi) { // if this is to become stable, should probably logout the currently // logged in ugi if it's different loginUser = ugi; diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java index 414aeb958d..858e33c3d1 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestUserGroupInformation.java @@ -644,4 +644,11 @@ public void testHasSufficientTimeElapsed() throws Exception { // Restore hasSufficientTimElapsed back to private method.setAccessible(false); } + + @Test(timeout=1000) + public void testSetLoginUser() throws IOException { + UserGroupInformation ugi = UserGroupInformation.createRemoteUser("test-user"); + UserGroupInformation.setLoginUser(ugi); + assertEquals(ugi, UserGroupInformation.getLoginUser()); + } }