|
@@ -16,12 +16,7 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.security;
|
|
package org.apache.hadoop.security;
|
|
|
|
|
|
-import static org.junit.Assert.assertArrayEquals;
|
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
|
-import static org.junit.Assert.assertFalse;
|
|
|
|
-import static org.junit.Assert.assertTrue;
|
|
|
|
-import static org.junit.Assert.fail;
|
|
|
|
-
|
|
|
|
|
|
+import static org.junit.Assert.*;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
@@ -32,6 +27,7 @@ import java.util.Collection;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
+import javax.security.auth.Subject;
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
|
|
|
|
import junit.framework.Assert;
|
|
import junit.framework.Assert;
|
|
@@ -339,4 +335,22 @@ public class TestUserGroupInformation {
|
|
assertGaugeGt("loginFailure_avg_time", 0, rb);
|
|
assertGaugeGt("loginFailure_avg_time", 0, rb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test for the case that UserGroupInformation.getCurrentUser()
|
|
|
|
+ * is called when the AccessControlContext has a Subject associated
|
|
|
|
+ * with it, but that Subject was not created by Hadoop (ie it has no
|
|
|
|
+ * associated User principal)
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testUGIUnderNonHadoopContext() throws Exception {
|
|
|
|
+ Subject nonHadoopSubject = new Subject();
|
|
|
|
+ Subject.doAs(nonHadoopSubject, new PrivilegedExceptionAction<Void>() {
|
|
|
|
+ public Void run() throws IOException {
|
|
|
|
+ UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
|
|
+ assertNotNull(ugi);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|