Exemplo n.º 1
0
  /** Test whether onWindowExpanded is called from server session */
  @Test
  public void testHandleWindowAdjust() throws Exception {
    final Buffer buffer = new ByteArrayBuffer();
    buffer.putInt(1234);

    try (ChannelSession channelSession = new ChannelSession()) {
      channelSession.asyncOut =
          new ChannelAsyncOutputStream(new BogusChannel(), (byte) 0) {
            @SuppressWarnings("synthetic-access")
            @Override
            public void onWindowExpanded() throws IOException {
              expanded = true;
              super.onWindowExpanded();
            }
          };
      channelSession.handleWindowAdjust(buffer);
      assertTrue(expanded);
    }
  }
Exemplo n.º 2
0
  protected void doOpen() throws Exception {
    super.doOpen();

    Buffer buffer;

    if (agentForwarding) {
      log.info("Send agent forwarding request");
      buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
      buffer.putInt(recipient);
      buffer.putString("*****@*****.**");
      buffer.putBoolean(false);
      session.writePacket(buffer);
    }

    if (usePty) {
      log.info("Send SSH_MSG_CHANNEL_REQUEST pty-req");
      buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
      buffer.putInt(recipient);
      buffer.putString("pty-req");
      buffer.putBoolean(false);
      buffer.putString(ptyType);
      buffer.putInt(ptyColumns);
      buffer.putInt(ptyLines);
      buffer.putInt(ptyHeight);
      buffer.putInt(ptyWidth);
      Buffer modes = new Buffer();
      for (PtyMode mode : ptyModes.keySet()) {
        modes.putByte((byte) mode.toInt());
        modes.putInt(ptyModes.get(mode));
      }
      modes.putByte((byte) 0);
      buffer.putBytes(modes.getCompactData());
      session.writePacket(buffer);
    }

    if (!env.isEmpty()) {
      log.info("Send SSH_MSG_CHANNEL_REQUEST env");
      for (Map.Entry<String, String> entry : env.entrySet()) {
        buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
        buffer.putInt(recipient);
        buffer.putString("env");
        buffer.putBoolean(false);
        buffer.putString(entry.getKey());
        buffer.putString(entry.getValue());
        session.writePacket(buffer);
      }
    }

    log.info("Send SSH_MSG_CHANNEL_REQUEST shell");
    buffer = session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0);
    buffer.putInt(recipient);
    buffer.putString("shell");
    buffer.putBoolean(false);
    session.writePacket(buffer);
  }