Class: Net::SSH::Test::Script

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::new
- #gets
- #gets_channel_close
- #gets_channel_data
- #gets_channel_eof
- #gets_channel_extended_data
- #gets_channel_request
- #next
- #opens_channel
- #process
- #sends
- #sends_channel_close
- #sends_channel_data
- #sends_channel_eof
- #sends_channel_request

### 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::Keepalive
- 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::Timeout
- 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::Script

Represents a sequence of scripted events that identify the behavior that a test expects. Methods named "sends_*" create events for packets being sent from the local to the remote host, and methods named "gets_*" create events for packets being received by the local from the remote host.

A reference to a script. is generally obtained in a unit test via the Net::SSH::Test#story helper method:

    story do |script|
      channel = script.opens_channel
      ...
    end

### Attributes

events[R]

The list of scripted events. These will be Net::SSH::Test::LocalPacket and Net::SSH::Test::RemotePacket instances.

### Public Class Methods

new() click to toggle source

Create a new, empty script.

    # File lib/net/ssh/test/script.rb, line 25
    def initialize
      @events = []
    end

### Public Instance Methods

gets(type, *args) click to toggle source

A convenience method for adding an arbitrary remote packet to the events list.

    # File lib/net/ssh/test/script.rb, line 56
    def gets(type, *args)
      events << RemotePacket.new(type, *args)
    end

gets_channel_close(channel) click to toggle source

Scripts the reception of a channel close packet from the remote host by the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#gets_close.

    # File lib/net/ssh/test/script.rb, line 140
    def gets_channel_close(channel)
      events << RemotePacket.new(:channel_close, channel.local_id)
    end

gets_channel_data(channel, data) click to toggle source

Scripts the reception of a channel data packet from the remote host by the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#gets_data.

    # File lib/net/ssh/test/script.rb, line 110
    def gets_channel_data(channel, data)
      events << RemotePacket.new(:channel_data, channel.local_id, data)
    end

gets_channel_eof(channel) click to toggle source

Scripts the reception of a channel EOF packet from the remote host by the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#gets_eof.

    # File lib/net/ssh/test/script.rb, line 133
    def gets_channel_eof(channel)
      events << RemotePacket.new(:channel_eof, channel.local_id)
    end

gets_channel_extended_data(channel, data) click to toggle source

Scripts the reception of a channel extended data packet from the remote host by the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#gets_extended_data.

Currently the only extended data type is stderr == 1.

    # File lib/net/ssh/test/script.rb, line 119
    def gets_channel_extended_data(channel, data)
      events << RemotePacket.new(:channel_extended_data, channel.local_id, 1, data)
    end

gets_channel_request(channel, request, reply, data) click to toggle source

Scripts the reception of a channel request packet from the remote host by the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#gets_exit_status.

    # File lib/net/ssh/test/script.rb, line 126
    def gets_channel_request(channel, request, reply, data)
      events << RemotePacket.new(:channel_request, channel.local_id, request, reply, data)
    end

next(mode=:shift) click to toggle source

By default, removes the next event in the list and returns it. However, this can also be used to non-destructively peek at the next event in the list, by passing :first as the argument.

    # remove the next event and return it
    event = script.next

    # peek at the next event
    event = script.next(:first)

    # File lib/net/ssh/test/script.rb, line 153
    def next(mode=:shift)
      events.send(mode)
    end

opens_channel(confirm=true) click to toggle source

Scripts the opening of a channel by adding a local packet sending the channel open request, and if `confirm` is true (the default), also adding a remote packet confirming the new channel.

A new Net::SSH::Test::Channel instance is returned, which can be used to script additional channel operations.

    # File lib/net/ssh/test/script.rb, line 35
    def opens_channel(confirm=true)
      channel = Channel.new(self)
      channel.remote_id = 5555

      events << LocalPacket.new(:channel_open) { |p| channel.local_id = p[:remote_id] }

      if confirm
        events << RemotePacket.new(:channel_open_confirmation, channel.local_id, channel.remote_id, 0x20000, 0x10000)
      end

      channel
    end

process(packet) click to toggle source

Compare the given packet against the next event in the list. If there is no next event, an exception will be raised. This is called by Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet.

    # File lib/net/ssh/test/script.rb, line 160
    def process(packet)
      event = events.shift or raise "end of script reached, but got a packet type #{packet.read_byte}"
      event.process(packet)
    end

sends(type, *args, &block) click to toggle source

A convenience method for adding an arbitrary local packet to the events list.

    # File lib/net/ssh/test/script.rb, line 50
    def sends(type, *args, &block)
      events << LocalPacket.new(type, *args, &block)
    end

sends_channel_close(channel) click to toggle source

Scripts the sending of a channel close packet from the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#sends_close.

    # File lib/net/ssh/test/script.rb, line 103
    def sends_channel_close(channel)
      events << LocalPacket.new(:channel_close, channel.remote_id)
    end

sends_channel_data(channel, data) click to toggle source

Scripts the sending of a channel data packet. `channel` must be a Net::SSH::Test::Channel object, and `data` is the (string) data to expect will be sent.

This will typically be called via Net::SSH::Test::Channel#sends_data.

    # File lib/net/ssh/test/script.rb, line 89
    def sends_channel_data(channel, data)
      events << LocalPacket.new(:channel_data, channel.remote_id, data)
    end

sends_channel_eof(channel) click to toggle source

Scripts the sending of a channel EOF packet from the given Net::SSH::Test::Channel `channel`. This will typically be called via Net::SSH::Test::Channel#sends_eof.

    # File lib/net/ssh/test/script.rb, line 96
    def sends_channel_eof(channel)
      events << LocalPacket.new(:channel_eof, channel.remote_id)
    end

sends_channel_request(channel, request, reply, data, success=true) click to toggle source

Scripts the sending of a new channel request packet to the remote host. `channel` should be an instance of Net::SSH::Test::Channel. `request` is a string naming the request type to send, `reply` is a boolean indicating whether a response to this packet is required , and `data` is any additional request-specific data that this packet should send. `success` indicates whether the response (if one is required) should be success or failure.

If a reply is desired, a remote packet will also be queued, :channel_success if `success` is true, or :channel_failure if `success` is false.

This will typically be called via Net::SSH::Test::Channel#sends_exec or Net::SSH::Test::Channel#sends_subsystem.

    # File lib/net/ssh/test/script.rb, line 73
    def sends_channel_request(channel, request, reply, data, success=true)
      events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, data)
      if reply
        if success
          events << RemotePacket.new(:channel_success, channel.local_id)
        else
          events << RemotePacket.new(:channel_failure, channel.local_id)
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.