Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
svn merge -c 1357994 from branch-1 for HDFS-6527. Backport HADOOP-738…
Browse files Browse the repository at this point in the history
…9: Use of TestingGroups by tests causes subsequent tests to fail.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.1@1357995 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
szetszwo committed Jul 5, 2012
1 parent ef9d644 commit 7471fab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 46 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/core/org/apache/hadoop/security/UserGroupInformation.java
Expand Up @@ -895,17 +895,21 @@ public UserGroupInformation getRealUser() {
private static class TestingGroups extends Groups {
private final Map<String, List<String>> userToGroupsMapping =
new HashMap<String,List<String>>();
private Groups underlyingImplementation;

private TestingGroups() {
private TestingGroups(Groups underlyingImplementation) {
super(new org.apache.hadoop.conf.Configuration());
this.underlyingImplementation = underlyingImplementation;
}

@Override
public List<String> getGroups(String user) {
public List<String> getGroups(String user) throws IOException {
List<String> result = userToGroupsMapping.get(user);

if (result == null) {
result = new ArrayList<String>();
result = underlyingImplementation.getGroups(user);
}

return result;
}

Expand All @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 5 additions & 18 deletions src/test/org/apache/hadoop/mapred/TestQueueManager.java
Expand Up @@ -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"});
Expand Down Expand Up @@ -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();
}
Expand Down
46 changes: 23 additions & 23 deletions src/test/org/apache/hadoop/security/TestUserGroupInformation.java
Expand Up @@ -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<UserGroupInformation>(){
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
Expand Down Expand Up @@ -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<UserGroupInformation>(){
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 {
Expand Down

0 comments on commit 7471fab

Please sign in to comment.