@Test public void testResize(TestContext context) { testResize(context, new JsonObject().put("action", "resize").put("cols", 100).put("rows", 50), 100, 50); }
@Test public void testInitialSizeInvalid4(TestContext context) { testSize(context, basePath + "/shell/websocket?cols=abc", 80, 24); }
server = createServer(context, new HttpTermOptions().setPort(8080)); server.authProvider(authProvider); server.termHandler(term -> {
@Test public void testKeymapFromFilesystem(TestContext context) throws Exception { URL url = TermServer.class.getResource(SSHTermOptions.DEFAULT_INPUTRC); File f = new File(url.toURI()); Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080).setIntputrc(f.getAbsolutePath())); server.termHandler(term -> { term.close(); async.complete(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())), ws -> { ws.handler(buf -> { }); }, context::fail); })); } }
@Test public void testInitialSizeInvalid2(TestContext context) { testSize(context, basePath + "/shell/websocket?cols=abc&rows=50", 80, 24); }
@Test public void testExternalAuthProviderFails(TestContext context) throws Exception { AtomicInteger count = new AtomicInteger(); AuthProvider authProvider = (authInfo, resultHandler) -> { count.incrementAndGet(); resultHandler.handle(Future.failedFuture("not authenticated")); }; Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.authProvider(authProvider); server.termHandler(term -> { context.fail(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())), ws -> { context.fail(); }, err -> { assertEquals(1, count.get()); async.complete(); }); })); }
@Test public void testResizeRows(TestContext context) { testResize(context, new JsonObject().put("action", "resize").put("rows", 50), 80, 50); }
@Test public void testInitialSize(TestContext context) { testSize(context, basePath + "/shell/websocket?cols=100&rows=50", 100, 50); }
@Test public void testServerRead(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.termHandler(term -> { term.stdinHandler(buf -> { context.assertEquals("hello_from_client", buf); async.complete(); }); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.writeFinalTextFrame(new JsonObject().put("action", "read").put("data", "hello_from_client").encode()); }, context::fail); })); }
@Test public void testResizeCols(TestContext context) { testResize(context, new JsonObject().put("action", "resize").put("cols", 100), 100, 24); }
@Test public void testInitialSizeNegative2(TestContext context) { testSize(context, basePath + "/shell/websocket?cols=-100&rows=50", 80, 24); }
@Test public void testDifferentCharset(TestContext context) throws Exception { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080).setCharset("ISO_8859_1")); server.termHandler(term -> { term.write("\u20AC"); term.close(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("paulo:anothersecret".getBytes())), ws -> { ws.handler(buf -> { context.assertTrue(Arrays.equals(new byte[]{63}, buf.getBytes())); async.complete(); }); }, context::fail); })); }
@Test public void testInitialSizeNegative3(TestContext context) { testSize(context, basePath + "/shell/websocket?rows=-50", 80, 24); }
@Test public void testResizeInvalid(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080));; server.termHandler(term -> { term.resizehandler(v -> { context.fail(); }); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.writeFinalTextFrame(new JsonObject().put("action", "resize").put("cols", -50).encode()); vertx.setTimer(1000, id -> { async.complete(); }); }, context::fail); })); }
@Test public void testInitialSizeInvalid1(TestContext context) { testSize(context, basePath + "/shell/websocket?cols=100&rows=abc", 80, 24); }
@Test public void testSecure(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setAuthOptions( new ShiroAuthOptions(). setType(ShiroAuthRealmType.PROPERTIES). setConfig(new JsonObject().put("properties_path", "classpath:test-auth.properties"))).setPort(8080)); server.termHandler(term -> { term.write("hello"); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { context.fail(); }, err -> { // Retry now with auth client.websocket(8080, "localhost", basePath + "/shell/websocket", new CaseInsensitiveHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString("tim:sausages".getBytes())), ws -> { ws.handler(buf -> { context.assertEquals("hello", buf.toString()); async.complete(); }); }, context::fail); }); })); }
@Test public void testInitialSizeInvalid3(TestContext context) { testSize(context, basePath + "/shell/websocket?rows=abc", 80, 24); }
private void testSize(TestContext context, String uri, int expectedCols, int expectedRows) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080));; server.termHandler(term -> { context.assertEquals(expectedCols, term.width()); context.assertEquals(expectedRows, term.height()); async.complete(); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", uri, ws -> { }, context::fail); })); }
@Test public void testInitialSizeCols(TestContext context) { testSize(context, basePath + "/shell/websocket?cols=100", 100, 24); }
@Test public void testServerWrite(TestContext context) { Async async = context.async(); server = createServer(context, new HttpTermOptions().setPort(8080)); server.termHandler(term -> { term.write("hello_from_server"); }); server.listen(context.asyncAssertSuccess(server -> { HttpClient client = vertx.createHttpClient(); client.websocket(8080, "localhost", basePath + "/shell/websocket", ws -> { ws.handler(buf -> { context.assertEquals("hello_from_server", buf.toString()); async.complete(); }); }, context::fail); })); }