Files
metasploit-gs/lib/net/ssh/test/local_packet.rb
T
Tod Beardsley 810133acc2 Fixes #841. Initial commit for net-ssh by Jamis Buck. http://github.com/jamis/net-ssh
Note that net-ssh is no longer actively maintained: http://weblog.jamisbuck.org/2009/2/25/net-ssh-capistrano-and-saying-goodbye



git-svn-id: file:///home/svn/framework3/trunk@8523 4d416f70-5f16-0410-b530-b9f4589650da
2010-02-16 19:18:19 +00:00

51 lines
1.7 KiB
Ruby

require 'net/ssh/packet'
require 'net/ssh/test/packet'
module Net; module SSH; module Test
# 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.
class LocalPacket < Packet
attr_reader :init
# 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.
def initialize(type, *args, &block)
super(type, *args)
@init = block
end
# Returns +true+; this is a local packet.
def local?
true
end
# 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.
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
end
end; end; end