@Override protected void assertWriteln(String s) throws Exception { assertWrite((s + "\r")); }
@Override public Command create() { return createConnection(onConnect); } });
@Override protected String assertReadString(int len) throws Exception { byte[] buf = new byte[len]; while (len > 0) { int count = in.read(buf, buf.length - len, len); if (count == -1) { throw failure("Could not read enough"); } len -= count; } return new String(buf, "UTF-8"); }
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Override protected void server(Consumer<TtyConnection> onConnect) { if (sshd != null) { throw failure("Already a server"); } try { sshd = createServer(); sshd.setPort(5000); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); sshd.setPasswordAuthenticator((username, password, session) -> true); sshd.setShellFactory(() -> createConnection(onConnect)); sshd.start(); } catch (Exception e) { throw failure(e); } }
@Override protected void server(final Consumer<TtyConnection> onConnect) { if (sshd != null) { throw failure("Already a server"); } try { sshd = createServer(); sshd.setPort(5000); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); sshd.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) throws PasswordChangeRequiredException { return true; } }); sshd.setShellFactory(new Factory<Command>() { @Override public Command create() { return createConnection(onConnect); } }); sshd.start(); } catch (Exception e) { throw failure(e); } }
@Before public void before() { super.before(); vertx = Vertx.vertx(); context = (ContextInternal) vertx.getOrCreateContext(); }
@After public void after() throws Exception { super.after(); CountDownLatch latch = new CountDownLatch(1); vertx.close(v -> latch.countDown()); await(latch); }
@Test public void testExitCode() throws Exception { server(conn -> { conn.setStdinHandler(bytes -> { conn.close(25); }); }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Override protected void server(Consumer<TtyConnection> onConnect) { if (sshd != null) { throw failure("Already a server"); } try { sshd = createServer(); sshd.setPort(5000); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); sshd.setPasswordAuthenticator((username, password, session) -> true); sshd.setShellFactory(() -> createConnection(onConnect)); sshd.start(); } catch (Exception e) { throw failure(e); } }
@Test public void testExitCode() throws Exception { server(new Consumer<TtyConnection>() { @Override public void accept(final TtyConnection conn) { conn.setStdinHandler(new Consumer<int[]>() { @Override public void accept(int[] bytes) { conn.close(25); } }); } }); assertConnect(); assertWrite("whatever"); long timeout = System.currentTimeMillis() + 5000; while (!channel.isClosed()) { assertTrue(System.currentTimeMillis() < timeout); Thread.sleep(10); } assertEquals(25, channel.getExitStatus()); }
@Override protected String assertReadString(int len) throws Exception { byte[] buf = new byte[len]; while (len > 0) { int count = in.read(buf, buf.length - len, len); if (count == -1) { throw failure("Could not read enough"); } len -= count; } return new String(buf, "UTF-8"); }
@Override protected void assertWriteln(String s) throws Exception { assertWrite((s + "\r")); }
@Override protected String assertReadString(int len) throws Exception { byte[] buf = new byte[len]; while (len > 0) { int count = in.read(buf, buf.length - len, len); if (count == -1) { throw failure("Could not read enough"); } len -= count; } return new String(buf, "UTF-8"); }
@Override protected void assertWriteln(String s) throws Exception { assertWrite((s + "\r")); }
@Override protected void assertConnect(String term) throws Exception { if (session != null) { throw failure("Already a session");
@Override protected void assertConnect(String term) throws Exception { if (session != null) { throw failure("Already a session");
@Override protected void assertConnect(String term) throws Exception { if (session != null) { throw failure("Already a session");