diff --git a/CHANGES.txt b/CHANGES.txt index e3fee8b3bb..af79894b57 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -265,6 +265,9 @@ Release 1.1.0 - unreleased HDFS-3551. WebHDFS CREATE should use client location for HTTP redirection. (szetszwo) + HDFS-6527. Backport HADOOP-7389: Use of TestingGroups by tests causes + subsequent tests to fail. (Ivan Mitic via szetszwo) + Release 1.0.3 - 2012.05.07 NEW FEATURES diff --git a/src/core/org/apache/hadoop/security/UserGroupInformation.java b/src/core/org/apache/hadoop/security/UserGroupInformation.java index fce9aeb05f..77e5a0f190 100644 --- a/src/core/org/apache/hadoop/security/UserGroupInformation.java +++ b/src/core/org/apache/hadoop/security/UserGroupInformation.java @@ -895,17 +895,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; } @@ -926,7 +930,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); @@ -951,7 +955,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/src/test/org/apache/hadoop/mapred/TestQueueManager.java b/src/test/org/apache/hadoop/mapred/TestQueueManager.java index 16171a2b21..d3d17bccce 100644 --- a/src/test/org/apache/hadoop/mapred/TestQueueManager.java +++ b/src/test/org/apache/hadoop/mapred/TestQueueManager.java @@ -48,19 +48,8 @@ public class TestQueueManager extends TestCase { MiniDFSCluster miniDFSCluster; MiniMRCluster miniMRCluster = null; - - /** - * For some tests it is necessary to sandbox them in a doAs with a fake user - * due to bug HADOOP-6527, which wipes out real group mappings. It's also - * necessary to then add the real user running the test to the fake users - * so that child processes can write to the DFS. - */ + UserGroupInformation createNecessaryUsers() throws IOException { - // Add real user to fake groups mapping so that child processes (tasks) - // will have permissions on the dfs - String j = UserGroupInformation.getCurrentUser().getShortUserName(); - UserGroupInformation.createUserForTesting(j, new String [] { "myGroup"}); - // Create a fake user for all processes to execute within UserGroupInformation ugi = UserGroupInformation.createUserForTesting("Zork", new String [] {"ZorkGroup"}); @@ -130,12 +119,10 @@ public void testAllDisabledACLForJobSubmission() verifyJobSubmissionToDefaultQueue(conf, true, userName + "," + groupName); verifyJobSubmissionToDefaultQueue(conf, true, user2 + "," + group2); - // Check if MROwner(user who started the mapreduce cluster) can submit job - UserGroupInformation mrOwner = UserGroupInformation.getCurrentUser(); - userName = mrOwner.getShortUserName(); - String[] groups = mrOwner.getGroupNames(); - groupName = groups[groups.length - 1]; - verifyJobSubmissionToDefaultQueue(conf, true, userName + "," + groupName); + // Check if MROwner (user who started the mapreduce cluster) can submit + // job. By passing null as userInfo we fallback to using the + // UserGroupInformation.getCurrentUser() what is the intent of the test. + verifyJobSubmissionToDefaultQueue(conf, true, null); } finally { tearDownCluster(); } diff --git a/src/test/org/apache/hadoop/security/TestUserGroupInformation.java b/src/test/org/apache/hadoop/security/TestUserGroupInformation.java index 1a445082dc..4719568a57 100644 --- a/src/test/org/apache/hadoop/security/TestUserGroupInformation.java +++ b/src/test/org/apache/hadoop/security/TestUserGroupInformation.java @@ -76,6 +76,29 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) { 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. * Needs to happen before creating the test users @@ -120,29 +143,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 {