|
@@ -27,17 +27,25 @@ import org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.NodeHealthCheckerService;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.NodeManager;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.ResourceView;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
|
|
import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
|
|
|
import org.eclipse.jetty.websocket.api.Session;
|
|
|
+import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
|
|
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
|
|
import org.junit.After;
|
|
|
+import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
|
/**
|
|
@@ -51,6 +59,7 @@ public class TestNMContainerWebSocket {
|
|
|
TestNMWebServer.class.getSimpleName());
|
|
|
private static File testLogDir = new File("target",
|
|
|
TestNMWebServer.class.getSimpleName() + "LogDir");
|
|
|
+ private WebServer server;
|
|
|
|
|
|
@Before
|
|
|
public void setup() {
|
|
@@ -101,7 +110,7 @@ public class TestNMContainerWebSocket {
|
|
|
healthChecker.init(conf);
|
|
|
LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
|
|
|
conf.set(YarnConfiguration.NM_WEBAPP_ADDRESS, webAddr);
|
|
|
- WebServer server = new WebServer(nmContext, resourceView,
|
|
|
+ server = new WebServer(nmContext, resourceView,
|
|
|
new ApplicationACLsManager(conf), dirsHandler);
|
|
|
try {
|
|
|
server.init(conf);
|
|
@@ -141,9 +150,36 @@ public class TestNMContainerWebSocket {
|
|
|
} finally {
|
|
|
try {
|
|
|
client.stop();
|
|
|
+ server.close();
|
|
|
} catch (Exception e) {
|
|
|
LOG.error("Failed to close client", e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testContainerShellWebSocket() {
|
|
|
+ Context nm = mock(Context.class);
|
|
|
+ Session session = mock(Session.class);
|
|
|
+ Container container = mock(Container.class);
|
|
|
+ UpgradeRequest request = mock(UpgradeRequest.class);
|
|
|
+ ApplicationACLsManager aclManager = mock(ApplicationACLsManager.class);
|
|
|
+ ContainerShellWebSocket.init(nm);
|
|
|
+ ContainerShellWebSocket ws = new ContainerShellWebSocket();
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
+ names.add("foobar");
|
|
|
+ Map<String, List<String>> mockParameters = new HashMap<>();
|
|
|
+ mockParameters.put("user.name", names);
|
|
|
+ when(session.getUpgradeRequest()).thenReturn(request);
|
|
|
+ when(request.getParameterMap()).thenReturn(mockParameters);
|
|
|
+ when(container.getUser()).thenReturn("foobar");
|
|
|
+ when(nm.getApplicationACLsManager()).thenReturn(aclManager);
|
|
|
+ when(aclManager.areACLsEnabled()).thenReturn(false);
|
|
|
+ try {
|
|
|
+ boolean authorized = ws.checkAuthorization(session, container);
|
|
|
+ Assert.assertTrue("Not authorized", authorized);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.fail("Should not throw exception.");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|