Java Code Examples for com.jcraft.jsch.ChannelShell#disconnect()

The following examples show how to use com.jcraft.jsch.ChannelShell#disconnect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SshdShellAutoConfigurationWithPublicKeyAndBannerImageTest.java    From sshd-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
@Test
public void testTestCommand() throws JSchException, IOException {
    JSch jsch = new JSch();
    Session session = jsch.getSession("admin", "localhost", properties.getShell().getPort());
    jsch.addIdentity("src/test/resources/id_rsa");
    Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect();
    ChannelShell channel = (ChannelShell) session.openChannel("shell");
    try (PipedInputStream pis = new PipedInputStream(); PipedOutputStream pos = new PipedOutputStream()) {
        channel.setInputStream(new PipedInputStream(pos));
        channel.setOutputStream(new PipedOutputStream(pis));
        channel.connect();
        pos.write("test run bob\r".getBytes(StandardCharsets.UTF_8));
        pos.flush();
        verifyResponseContains(pis, "test run bob");
    }
    channel.disconnect();
    session.disconnect();
}
 
Example 2
Source File: SSHServerTest.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
@Test
public void testResizeHandler(TestContext context) throws Exception {
  Async async = context.async();
  termHandler = term -> {
    term.resizehandler(v -> {
      context.assertEquals(20, term.width());
      context.assertEquals(10, term.height());
      async.complete();
    });
  };
  startShell();
  Session session = createSession("paulo", "secret", false);
  session.connect();
  ChannelShell channel = (ChannelShell) session.openChannel("shell");
  channel.connect();
  OutputStream out = channel.getOutputStream();
  channel.setPtySize(20, 10, 20 * 8, 10 * 8);
  out.flush();
  channel.disconnect();
  session.disconnect();
}