diff --git a/common/CHANGES.txt b/common/CHANGES.txt index f97579cb2b..8eba79e71f 100644 --- a/common/CHANGES.txt +++ b/common/CHANGES.txt @@ -306,6 +306,9 @@ Trunk (unreleased changes) HADOOP-7356. RPM packages broke bin/hadoop script in developer environment. (Eric Yang via todd) + HADOOP-7389. Use of TestingGroups by tests causes subsequent tests to fail. + (atm via tomwhite) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/common/src/java/org/apache/hadoop/security/UserGroupInformation.java b/common/src/java/org/apache/hadoop/security/UserGroupInformation.java index 0b00af7ce4..45a1bad278 100644 --- a/common/src/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/common/src/java/org/apache/hadoop/security/UserGroupInformation.java @@ -878,17 +878,21 @@ public UserGroupInformation getRealUser() { private static class TestingGroups extends Groups { private final Map> userToGroupsMapping = new HashMap>(); + private Groups underlyingImplementation; - private TestingGroups() { + private TestingGroups(Groups underlyingImplementation) { super(new org.apache.hadoop.conf.Configuration()); + this.underlyingImplementation = underlyingImplementation; } @Override - public List getGroups(String user) { + public List getGroups(String user) throws IOException { List result = userToGroupsMapping.get(user); + if (result == null) { - result = new ArrayList(); + result = underlyingImplementation.getGroups(user); } + return result; } @@ -910,7 +914,7 @@ public static UserGroupInformation createUserForTesting(String user, UserGroupInformation ugi = createRemoteUser(user); // make sure that the testing object is setup if (!(groups instanceof TestingGroups)) { - groups = new TestingGroups(); + groups = new TestingGroups(groups); } // add the user groups ((TestingGroups) groups).setUserGroups(ugi.getShortUserName(), userGroups); @@ -936,7 +940,7 @@ public static UserGroupInformation createProxyUserForTesting(String user, UserGroupInformation ugi = createProxyUser(user, realUser); // make sure that the testing object is setup if (!(groups instanceof TestingGroups)) { - groups = new TestingGroups(); + groups = new TestingGroups(groups); } // add the user groups ((TestingGroups) groups).setUserGroups(ugi.getShortUserName(), userGroups); diff --git a/common/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java b/common/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java index afc49765ed..76d64d91fd 100644 --- a/common/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java +++ b/common/src/test/core/org/apache/hadoop/security/TestUserGroupInformation.java @@ -62,6 +62,29 @@ public class TestUserGroupInformation { + "DEFAULT"); UserGroupInformation.setConfiguration(conf); } + + /** Test login method */ + @Test + public void testLogin() throws Exception { + // login from unix + UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); + assertEquals(UserGroupInformation.getCurrentUser(), + UserGroupInformation.getLoginUser()); + assertTrue(ugi.getGroupNames().length >= 1); + + // ensure that doAs works correctly + UserGroupInformation userGroupInfo = + UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES); + UserGroupInformation curUGI = + userGroupInfo.doAs(new PrivilegedExceptionAction(){ + public UserGroupInformation run() throws IOException { + return UserGroupInformation.getCurrentUser(); + }}); + // make sure in the scope of the doAs, the right user is current + assertEquals(curUGI, userGroupInfo); + // make sure it is not the same as the login user + assertFalse(curUGI.equals(UserGroupInformation.getLoginUser())); + } /** * given user name - get all the groups. @@ -107,29 +130,6 @@ public Object run() throws IOException { }}); } - /** Test login method */ - @Test - public void testLogin() throws Exception { - // login from unix - UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); - assertEquals(UserGroupInformation.getCurrentUser(), - UserGroupInformation.getLoginUser()); - assertTrue(ugi.getGroupNames().length >= 1); - - // ensure that doAs works correctly - UserGroupInformation userGroupInfo = - UserGroupInformation.createUserForTesting(USER_NAME, GROUP_NAMES); - UserGroupInformation curUGI = - userGroupInfo.doAs(new PrivilegedExceptionAction(){ - public UserGroupInformation run() throws IOException { - return UserGroupInformation.getCurrentUser(); - }}); - // make sure in the scope of the doAs, the right user is current - assertEquals(curUGI, userGroupInfo); - // make sure it is not the same as the login user - assertFalse(curUGI.equals(UserGroupInformation.getLoginUser())); - } - /** test constructor */ @Test public void testConstructor() throws Exception {