Class: Net::SSH::Test::Packet

### Home Classes Methods

### In Files

- lib/net/ssh/test/packet.rb

### Parent

Object

### Methods

- ::new
- #instantiate!
- #local?
- #remote?
- #types

### Included Modules

- Net::SSH::Transport::Constants
- Net::SSH::Connection::Constants

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Net
- Net::SSH
- Net::SSH::Authentication
- Net::SSH::Authentication::Agent
- Net::SSH::Authentication::Agent::Comment
- Net::SSH::Authentication::AgentError
- Net::SSH::Authentication::AgentNotAvailable
- Net::SSH::Authentication::Constants
- Net::SSH::Authentication::DisallowedMethod
- Net::SSH::Authentication::KeyManager
- Net::SSH::Authentication::KeyManagerError
- Net::SSH::Authentication::Methods
- Net::SSH::Authentication::Methods::Abstract
- Net::SSH::Authentication::Methods::Hostbased
- Net::SSH::Authentication::Methods::KeyboardInteractive
- Net::SSH::Authentication::Methods::None
- Net::SSH::Authentication::Methods::Password
- Net::SSH::Authentication::Methods::Publickey
- Net::SSH::Authentication::Session
- Net::SSH::AuthenticationFailed
- Net::SSH::Buffer
- Net::SSH::ChannelOpenFailed
- Net::SSH::ChannelRequestFailed
- Net::SSH::Compat
- Net::SSH::Config
- Net::SSH::Connection
- Net::SSH::Connection::Channel
- Net::SSH::Connection::Constants
- Net::SSH::Connection::Session
- Net::SSH::Connection::Session::NilChannel
- Net::SSH::Connection::Term
- Net::SSH::ConnectionTimeout
- Net::SSH::Disconnect
- Net::SSH::Exception
- Net::SSH::HostKeyError
- Net::SSH::HostKeyMismatch
- Net::SSH::HostKeyUnknown
- Net::SSH::KeyFactory
- Net::SSH::KnownHosts
- Net::SSH::Loggable
- Net::SSH::Packet
- Net::SSH::PromptMethods
- Net::SSH::PromptMethods::Clear
- Net::SSH::PromptMethods::Highline
- Net::SSH::PromptMethods::Termios
- Net::SSH::Proxy
- Net::SSH::Proxy::Command
- Net::SSH::Proxy::ConnectError
- Net::SSH::Proxy::Error
- Net::SSH::Proxy::HTTP
- Net::SSH::Proxy::SOCKS4
- Net::SSH::Proxy::SOCKS5
- Net::SSH::Proxy::UnauthorizedError
- Net::SSH::Test
- Net::SSH::Test::Channel
- Net::SSH::Test::Extensions
- Net::SSH::Test::Extensions::BufferedIo
- Net::SSH::Test::Extensions::Channel
- Net::SSH::Test::Extensions::IO
- Net::SSH::Test::Extensions::IO::ClassMethods
- Net::SSH::Test::Extensions::PacketStream
- Net::SSH::Test::Kex
- Net::SSH::Test::LocalPacket
- Net::SSH::Test::Packet
- Net::SSH::Test::RemotePacket
- Net::SSH::Test::Script
- Net::SSH::Test::Socket
- Net::SSH::Transport
- Net::SSH::Transport::Algorithms
- Net::SSH::Transport::CTR
- Net::SSH::Transport::CipherFactory
- Net::SSH::Transport::Constants
- Net::SSH::Transport::HMAC
- Net::SSH::Transport::HMAC::Abstract
- Net::SSH::Transport::HMAC::MD5
- Net::SSH::Transport::HMAC::MD5_96
- Net::SSH::Transport::HMAC::None
- Net::SSH::Transport::HMAC::RIPEMD160
- Net::SSH::Transport::HMAC::SHA1
- Net::SSH::Transport::HMAC::SHA1_96
- Net::SSH::Transport::HMAC::SHA2_256
- Net::SSH::Transport::HMAC::SHA2_256_96
- Net::SSH::Transport::HMAC::SHA2_512
- Net::SSH::Transport::HMAC::SHA2_512_96
- Net::SSH::Transport::IdentityCipher
- Net::SSH::Transport::Kex
- Net::SSH::Transport::Kex::DiffieHellmanGroup14SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA256
- Net::SSH::Transport::Kex::EcdhSHA2NistP256
- Net::SSH::Transport::Kex::EcdhSHA2NistP384
- Net::SSH::Transport::Kex::EcdhSHA2NistP521
- Net::SSH::Transport::KeyExpander
- Net::SSH::Transport::PacketStream
- Net::SSH::Transport::ServerVersion
- Net::SSH::Transport::Session
- Net::SSH::Transport::State
- Net::SSH::Verifiers
- Net::SSH::Verifiers::Lenient
- Net::SSH::Verifiers::Null
- Net::SSH::Verifiers::Secure
- Net::SSH::Verifiers::Strict
- Net::SSH::Version
- OpenSSL
- OpenSSL::BN
- OpenSSL::PKey
- OpenSSL::PKey::DH
- OpenSSL::PKey::DSA
- OpenSSL::PKey::EC
- OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey::ECError
- OpenSSL::PKey::PKey
- OpenSSL::PKey::RSA
- String

No matching classes.

# 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 23
    def initialize(type, *args)
      @type = self.class.const_get(type.to_s.upcase)
      @data = args
    end

### 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 45
    def instantiate!
      @data.map! { |i| i.respond_to?(:call) ? i.call : i }
    end

local?() click to toggle source

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

    # File lib/net/ssh/test/packet.rb, line 34
    def local?
      false
    end

remote?() click to toggle source

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

    # File lib/net/ssh/test/packet.rb, line 29
    def remote?
      false
    end

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 58
    def types
      @types ||= case @type
        when KEXINIT then
          [:long, :long, :long, :long,
           :string, :string, :string, :string, :string, :string, :string, :string, :string, :string,
           :bool]
        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]
        when CHANNEL_EOF, CHANNEL_CLOSE, CHANNEL_SUCCESS, CHANNEL_FAILURE then [:long]
        when CHANNEL_REQUEST
          parts = [:long, :string, :bool]
          case @data[1]
          when "exec", "subsystem" then parts << :string
          when "exit-status" then parts << :long
          else raise "don't know what to do about #{@data[1]} channel request"
          end
        else raise "don't know how to parse packet type #{@type}"
        end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.