|
@@ -18,23 +18,20 @@
|
|
|
|
|
|
package org.apache.hadoop.mapreduce.v2.hs.webapp;
|
|
|
|
|
|
-import static org.junit.Assert.assertEquals;
|
|
|
-import static org.junit.Assert.fail;
|
|
|
-import static org.mockito.Mockito.mock;
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
-
|
|
|
import java.io.IOException;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
-
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
import javax.ws.rs.core.Response.Status;
|
|
|
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
@@ -60,9 +57,19 @@ import org.apache.hadoop.security.Groups;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.authorize.AccessControlList;
|
|
|
import org.apache.hadoop.yarn.api.records.Priority;
|
|
|
+import org.apache.hadoop.yarn.server.webapp.LogServlet;
|
|
|
import org.apache.hadoop.yarn.webapp.WebApp;
|
|
|
-import org.junit.Before;
|
|
|
-import org.junit.Test;
|
|
|
+
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.fail;
|
|
|
+import static org.mockito.Matchers.any;
|
|
|
+import static org.mockito.Matchers.anyBoolean;
|
|
|
+import static org.mockito.Matchers.anyString;
|
|
|
+import static org.mockito.Matchers.eq;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.times;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
|
|
public class TestHsWebServicesAcls {
|
|
|
private static String FRIENDLY_USER = "friendly";
|
|
@@ -253,6 +260,29 @@ public class TestHsWebServicesAcls {
|
|
|
this.taskIdStr, this.taskAttemptIdStr);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testLogs() {
|
|
|
+ HttpServletRequest hsr = mock(HttpServletRequest.class);
|
|
|
+ when(hsr.getRemoteUser()).thenReturn(ENEMY_USER);
|
|
|
+ hsWebServices.setLogServlet(mock(LogServlet.class));
|
|
|
+ String cid = "container_e02_" + jobIdStr.substring(4) + "_01_000001";
|
|
|
+ try {
|
|
|
+ hsWebServices.getContainerLogFile(hsr, cid, "syslog",
|
|
|
+ null, null, null, false, false);
|
|
|
+ fail("enemy can access job");
|
|
|
+ } catch (WebApplicationException e) {
|
|
|
+ assertEquals(Status.UNAUTHORIZED,
|
|
|
+ Status.fromStatusCode(e.getResponse().getStatus()));
|
|
|
+ }
|
|
|
+
|
|
|
+ when(hsr.getRemoteUser()).thenReturn(FRIENDLY_USER);
|
|
|
+ hsWebServices.getContainerLogFile(hsr, cid, "syslog",
|
|
|
+ "format", "1024", "nmid", false, false);
|
|
|
+ verify(hsWebServices.getLogServlet(), times(1))
|
|
|
+ .getLogFile(any(), anyString(), anyString(),
|
|
|
+ anyString(), anyString(), anyString(), anyBoolean(), eq(null), anyBoolean());
|
|
|
+ }
|
|
|
+
|
|
|
private static HistoryContext buildHistoryContext(final Configuration conf)
|
|
|
throws IOException {
|
|
|
HistoryContext ctx = new MockHistoryContext(1, 1, 1);
|