Class: Net::SSH::Test::LocalPacket

Inherits:
Packet
  • Object
show all
Defined in:
lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb

Overview

This is a specialization of Net::SSH::Test::Packet for representing mock packets that are sent from the local (client) host. These are created automatically by Net::SSH::Test::Script and Net::SSH::Test::Channel by any of the sends_* methods.

Constant Summary

Constants included from Connection::Constants

Connection::Constants::CHANNEL_CLOSE, Connection::Constants::CHANNEL_DATA, Connection::Constants::CHANNEL_EOF, Connection::Constants::CHANNEL_EXTENDED_DATA, Connection::Constants::CHANNEL_FAILURE, Connection::Constants::CHANNEL_OPEN, Connection::Constants::CHANNEL_OPEN_CONFIRMATION, Connection::Constants::CHANNEL_OPEN_FAILURE, Connection::Constants::CHANNEL_REQUEST, Connection::Constants::CHANNEL_SUCCESS, Connection::Constants::CHANNEL_WINDOW_ADJUST, Connection::Constants::GLOBAL_REQUEST, Connection::Constants::REQUEST_FAILURE, Connection::Constants::REQUEST_SUCCESS

Constants included from Net::SSH::Transport::Constants

Net::SSH::Transport::Constants::DEBUG, Net::SSH::Transport::Constants::DISCONNECT, Net::SSH::Transport::Constants::IGNORE, Net::SSH::Transport::Constants::KEXDH_INIT, Net::SSH::Transport::Constants::KEXDH_REPLY, Net::SSH::Transport::Constants::KEXINIT, Net::SSH::Transport::Constants::NEWKEYS, Net::SSH::Transport::Constants::SERVICE_ACCEPT, Net::SSH::Transport::Constants::SERVICE_REQUEST, Net::SSH::Transport::Constants::UNIMPLEMENTED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

#instantiate!, #remote?, #types

Constructor Details

#initialize(type, *args, &block) ⇒ LocalPacket

Extend the default Net::SSH::Test::Packet constructor to also accept an optional block, which is used to finalize the initialization of the packet when #process is first called.



16
17
18
19
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb', line 16

def initialize(type, *args, &block)
  super(type, *args)
  @init = block
end

Instance Attribute Details

#initObject (readonly)

Returns the value of attribute init.



11
12
13
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb', line 11

def init
  @init
end

Instance Method Details

#local?Boolean

Returns true; this is a local packet.

Returns:

  • (Boolean)


22
23
24
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb', line 22

def local?
  true
end

#process(packet) ⇒ Object

Called by Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet to mimic remote processing of a locally-sent packet. It compares the packet it was given with the contents of this LocalPacket’s data, to see if what was sent matches what was scripted. If it differs in any way, an exception is raised.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb', line 31

def process(packet)
  @init.call(Net::SSH::Packet.new(packet.to_s)) if @init
  type = packet.read_byte
  raise "expected #{@type}, but got #{type}" if @type != type

  @data.zip(types).each do |expected, type|
    type ||= case expected
      when nil then break
      when Numeric then :long
      when String then :string
      when TrueClass, FalseClass then :bool
      end

    actual = packet.send("read_#{type}")
    next if expected.nil?
    raise "expected #{type} #{expected.inspect} but got #{actual.inspect}" unless expected == actual
  end
end