Class Net::SSH::Test::Packet

  1. lib/net/ssh/test/packet.rb
Parent: Object

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).

Methods

public class

  1. new

public instance

  1. instantiate!
  2. local?
  3. remote?
  4. types

Public class methods

new (type, *args)

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).

[show source]
    # File lib/net/ssh/test/packet.rb, line 23
23:     def initialize(type, *args)
24:       @type = self.class.const_get(type.to_s.upcase)
25:       @data = args
26:     end

Public instance methods

instantiate! ()

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).

[show source]
    # File lib/net/ssh/test/packet.rb, line 45
45:     def instantiate!
46:       @data.map! { |i| i.respond_to?(:call) ? i.call : i }
47:     end
local? ()

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

[show source]
    # File lib/net/ssh/test/packet.rb, line 34
34:     def local?
35:       false
36:     end
remote? ()

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

[show source]
    # File lib/net/ssh/test/packet.rb, line 29
29:     def remote?
30:       false
31:     end
types ()

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.

[show source]
    # File lib/net/ssh/test/packet.rb, line 58
58:     def types
59:       @types ||= case @type
60:         when KEXINIT then 
61:           [:long, :long, :long, :long,
62:            :string, :string, :string, :string, :string, :string, :string, :string, :string, :string,
63:            :bool]
64:         when NEWKEYS then []
65:         when CHANNEL_OPEN then [:string, :long, :long, :long]
66:         when CHANNEL_OPEN_CONFIRMATION then [:long, :long, :long, :long]
67:         when CHANNEL_DATA then [:long, :string]
68:         when CHANNEL_EOF, CHANNEL_CLOSE, CHANNEL_SUCCESS, CHANNEL_FAILURE then [:long]
69:         when CHANNEL_REQUEST
70:           parts = [:long, :string, :bool]
71:           case @data[1]
72:           when "exec", "subsystem" then parts << :string
73:           when "exit-status" then parts << :long
74:           else raise "don't know what to do about #{@data[1]} channel request"
75:           end
76:         else raise "don't know how to parse packet type #{@type}"
77:         end
78:     end