class Net::SSH::Test::Packet

This is an abstract class, not to be instantiated directly, subclassed by Net::SSH::Test::LocalPacket and Net::SSH::Test::RemotePacket. It implements functionality common to those subclasses.

These packets are not true packets, in that they don't represent what was actually sent between the hosst; rather, they represent what was expected to be sent, as dictated by the script (Net::SSH::Test::Script). Thus, though they are defined with data elements, these data elements are used to either validate data that was sent by the local host (Net::SSH::Test::LocalPacket) or to mimic the sending of data by the remote host (Net::SSH::Test::RemotePacket).

Public Class Methods

new(type, *args) click to toggle source

Ceate a new packet of the given type, and with args being a list of data elements in the order expected for packets of the given type (see types).

# File lib/net/ssh/test/packet.rb, line 34
def initialize(type, *args)
  @type = self.class.const_get(type.to_s.upcase)
  @data = args
register_channel_request(request, extra_parts) click to toggle source

Register a custom channel request. extra_parts is an array of types of extra parameters

# File lib/net/ssh/test/packet.rb, line 22
def self.register_channel_request(request, extra_parts)
  @registered_requests ||= {}
  @registered_requests[request] = {extra_parts: extra_parts}
registered_channel_requests(request) click to toggle source
# File lib/net/ssh/test/packet.rb, line 27
def self.registered_channel_requests(request)
  @registered_requests && @registered_requests[request]

Public Instance Methods

instantiate!() click to toggle source

Instantiates the packets data elements. When the packet was first defined, some elements may not have been fully realized, and were described as Proc objects rather than atomic types. This invokes those Proc objects and replaces them with their returned values. This allows for values like Net::SSH::Test::Channel#remote_id to be used in scripts before the remote_id is known (since it is only known after a channel has been confirmed open).

# File lib/net/ssh/test/packet.rb, line 56
def instantiate!! { |i| i.respond_to?(:call) ? : i }
local?() click to toggle source

The default for local? is false. Subclasses should override as necessary.

# File lib/net/ssh/test/packet.rb, line 45
def local?
remote?() click to toggle source

The default for remote? is false. Subclasses should override as necessary.

# File lib/net/ssh/test/packet.rb, line 40
def remote?
types() click to toggle source

Returns an array of symbols describing the data elements for packets of the same type as this packet. These types are used to either validate sent packets (Net::SSH::Test::LocalPacket) or build received packets (Net::SSH::Test::RemotePacket).

Not all packet types are defined here. As new packet types are required (e.g., a unit test needs to test that the remote host sent a packet that is not implemented here), the description of that packet should be added. Unsupported packet types will otherwise raise an exception.

# File lib/net/ssh/test/packet.rb, line 69
def types
  @types ||= case @type
    when KEXINIT then 
      [:long, :long, :long, :long,
       :string, :string, :string, :string, :string, :string, :string, :string, :string, :string,
    when NEWKEYS then []
    when CHANNEL_OPEN then [:string, :long, :long, :long]
    when CHANNEL_OPEN_CONFIRMATION then [:long, :long, :long, :long]
    when CHANNEL_DATA then [:long, :string]
    when CHANNEL_EXTENDED_DATA then [:long, :long, :string]
      parts = [:long, :string, :bool]
      case @data[1]
      when "exec", "subsystem","shell" then parts << :string
      when "exit-status" then parts << :long
      when "pty-req" then parts.concat([:string, :long, :long, :long, :long, :string])
      when "env" then[:string,:string])
        request = Packet.registered_channel_requests(@data[1])
        raise "don't know what to do about #{@data[1]} channel request" unless request
    else raise "don't know how to parse packet type #{@type}"