net-ssh 5.0.0.beta1 → 5.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.rubocop_todo.yml +98 -258
- data/CHANGES.txt +8 -0
- data/Gemfile +1 -3
- data/Rakefile +37 -39
- data/lib/net/ssh.rb +26 -25
- data/lib/net/ssh/authentication/agent.rb +228 -225
- data/lib/net/ssh/authentication/certificate.rb +166 -164
- data/lib/net/ssh/authentication/constants.rb +17 -14
- data/lib/net/ssh/authentication/ed25519.rb +107 -104
- data/lib/net/ssh/authentication/ed25519_loader.rb +32 -28
- data/lib/net/ssh/authentication/key_manager.rb +5 -3
- data/lib/net/ssh/authentication/methods/abstract.rb +53 -47
- data/lib/net/ssh/authentication/methods/hostbased.rb +32 -33
- data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +2 -4
- data/lib/net/ssh/authentication/methods/none.rb +10 -10
- data/lib/net/ssh/authentication/methods/password.rb +13 -13
- data/lib/net/ssh/authentication/methods/publickey.rb +54 -55
- data/lib/net/ssh/authentication/pageant.rb +468 -465
- data/lib/net/ssh/authentication/pub_key_fingerprint.rb +44 -0
- data/lib/net/ssh/authentication/session.rb +127 -123
- data/lib/net/ssh/buffer.rb +305 -303
- data/lib/net/ssh/buffered_io.rb +163 -162
- data/lib/net/ssh/config.rb +230 -227
- data/lib/net/ssh/connection/channel.rb +659 -654
- data/lib/net/ssh/connection/constants.rb +30 -26
- data/lib/net/ssh/connection/event_loop.rb +108 -104
- data/lib/net/ssh/connection/keepalive.rb +54 -50
- data/lib/net/ssh/connection/session.rb +677 -678
- data/lib/net/ssh/connection/term.rb +180 -176
- data/lib/net/ssh/errors.rb +101 -99
- data/lib/net/ssh/key_factory.rb +108 -108
- data/lib/net/ssh/known_hosts.rb +148 -154
- data/lib/net/ssh/loggable.rb +56 -54
- data/lib/net/ssh/packet.rb +82 -78
- data/lib/net/ssh/prompt.rb +55 -53
- data/lib/net/ssh/proxy/command.rb +103 -102
- data/lib/net/ssh/proxy/errors.rb +12 -8
- data/lib/net/ssh/proxy/http.rb +92 -91
- data/lib/net/ssh/proxy/https.rb +42 -39
- data/lib/net/ssh/proxy/jump.rb +50 -47
- data/lib/net/ssh/proxy/socks4.rb +0 -2
- data/lib/net/ssh/proxy/socks5.rb +11 -11
- data/lib/net/ssh/ruby_compat.rb +1 -0
- data/lib/net/ssh/service/forward.rb +364 -362
- data/lib/net/ssh/test.rb +85 -83
- data/lib/net/ssh/test/channel.rb +146 -142
- data/lib/net/ssh/test/extensions.rb +148 -146
- data/lib/net/ssh/test/kex.rb +35 -31
- data/lib/net/ssh/test/local_packet.rb +48 -44
- data/lib/net/ssh/test/packet.rb +87 -84
- data/lib/net/ssh/test/remote_packet.rb +35 -31
- data/lib/net/ssh/test/script.rb +173 -171
- data/lib/net/ssh/test/socket.rb +59 -55
- data/lib/net/ssh/transport/algorithms.rb +413 -412
- data/lib/net/ssh/transport/cipher_factory.rb +108 -105
- data/lib/net/ssh/transport/constants.rb +35 -31
- data/lib/net/ssh/transport/ctr.rb +1 -1
- data/lib/net/ssh/transport/hmac.rb +1 -1
- data/lib/net/ssh/transport/hmac/abstract.rb +67 -64
- data/lib/net/ssh/transport/hmac/sha2_256_96.rb +1 -1
- data/lib/net/ssh/transport/hmac/sha2_512_96.rb +1 -1
- data/lib/net/ssh/transport/identity_cipher.rb +55 -51
- data/lib/net/ssh/transport/kex.rb +2 -4
- data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +47 -40
- data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +201 -197
- data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -56
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +94 -87
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +17 -10
- data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +17 -10
- data/lib/net/ssh/transport/key_expander.rb +29 -25
- data/lib/net/ssh/transport/openssl.rb +17 -30
- data/lib/net/ssh/transport/packet_stream.rb +193 -192
- data/lib/net/ssh/transport/server_version.rb +64 -66
- data/lib/net/ssh/transport/session.rb +286 -284
- data/lib/net/ssh/transport/state.rb +198 -196
- data/lib/net/ssh/verifiers/lenient.rb +29 -25
- data/lib/net/ssh/verifiers/null.rb +13 -9
- data/lib/net/ssh/verifiers/secure.rb +45 -45
- data/lib/net/ssh/verifiers/strict.rb +20 -16
- data/lib/net/ssh/version.rb +55 -53
- data/net-ssh.gemspec +4 -4
- data/support/ssh_tunnel_bug.rb +2 -2
- metadata +25 -24
- metadata.gz.sig +0 -0
data/lib/net/ssh/test/packet.rb
CHANGED
@@ -1,98 +1,101 @@
|
|
1
1
|
require 'net/ssh/connection/constants'
|
2
2
|
require 'net/ssh/transport/constants'
|
3
3
|
|
4
|
-
module Net
|
4
|
+
module Net
|
5
|
+
module SSH
|
6
|
+
module Test
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
# This is an abstract class, not to be instantiated directly, subclassed by
|
9
|
+
# Net::SSH::Test::LocalPacket and Net::SSH::Test::RemotePacket. It implements
|
10
|
+
# functionality common to those subclasses.
|
11
|
+
#
|
12
|
+
# These packets are not true packets, in that they don't represent what was
|
13
|
+
# actually sent between the hosst; rather, they represent what was expected
|
14
|
+
# to be sent, as dictated by the script (Net::SSH::Test::Script). Thus,
|
15
|
+
# though they are defined with data elements, these data elements are used
|
16
|
+
# to either validate data that was sent by the local host (Net::SSH::Test::LocalPacket)
|
17
|
+
# or to mimic the sending of data by the remote host (Net::SSH::Test::RemotePacket).
|
18
|
+
class Packet
|
19
|
+
include Net::SSH::Transport::Constants
|
20
|
+
include Net::SSH::Connection::Constants
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# Register a custom channel request. extra_parts is an array of types
|
23
|
+
# of extra parameters
|
24
|
+
def self.register_channel_request(request, extra_parts)
|
25
|
+
@registered_requests ||= {}
|
26
|
+
@registered_requests[request] = { extra_parts: extra_parts }
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
def self.registered_channel_requests(request)
|
30
|
+
@registered_requests && @registered_requests[request]
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
# Ceate a new packet of the given +type+, and with +args+ being a list of
|
34
|
+
# data elements in the order expected for packets of the given +type+
|
35
|
+
# (see #types).
|
36
|
+
def initialize(type, *args)
|
37
|
+
@type = self.class.const_get(type.to_s.upcase)
|
38
|
+
@data = args
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
# The default for +remote?+ is false. Subclasses should override as necessary.
|
42
|
+
def remote?
|
43
|
+
false
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
# The default for +local?+ is false. Subclasses should override as necessary.
|
47
|
+
def local?
|
48
|
+
false
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
# Instantiates the packets data elements. When the packet was first defined,
|
52
|
+
# some elements may not have been fully realized, and were described as
|
53
|
+
# Proc objects rather than atomic types. This invokes those Proc objects
|
54
|
+
# and replaces them with their returned values. This allows for values
|
55
|
+
# like Net::SSH::Test::Channel#remote_id to be used in scripts before
|
56
|
+
# the remote_id is known (since it is only known after a channel has been
|
57
|
+
# confirmed open).
|
58
|
+
def instantiate!
|
59
|
+
@data.map! { |i| i.respond_to?(:call) ? i.call : i }
|
60
|
+
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
62
|
+
# Returns an array of symbols describing the data elements for packets of
|
63
|
+
# the same type as this packet. These types are used to either validate
|
64
|
+
# sent packets (Net::SSH::Test::LocalPacket) or build received packets
|
65
|
+
# (Net::SSH::Test::RemotePacket).
|
66
|
+
#
|
67
|
+
# Not all packet types are defined here. As new packet types are required
|
68
|
+
# (e.g., a unit test needs to test that the remote host sent a packet that
|
69
|
+
# is not implemented here), the description of that packet should be
|
70
|
+
# added. Unsupported packet types will otherwise raise an exception.
|
71
|
+
def types
|
72
|
+
@types ||= case @type
|
73
|
+
when KEXINIT then
|
74
|
+
%i[long long long long
|
75
|
+
string string string string string string string string string string
|
76
|
+
bool]
|
77
|
+
when NEWKEYS then []
|
78
|
+
when CHANNEL_OPEN then %i[string long long long]
|
79
|
+
when CHANNEL_OPEN_CONFIRMATION then %i[long long long long]
|
80
|
+
when CHANNEL_DATA then %i[long string]
|
81
|
+
when CHANNEL_EXTENDED_DATA then %i[long long string]
|
82
|
+
when CHANNEL_EOF, CHANNEL_CLOSE, CHANNEL_SUCCESS, CHANNEL_FAILURE then [:long]
|
83
|
+
when CHANNEL_REQUEST
|
84
|
+
parts = %i[long string bool]
|
85
|
+
case @data[1]
|
86
|
+
when "exec", "subsystem","shell" then parts << :string
|
87
|
+
when "exit-status" then parts << :long
|
88
|
+
when "pty-req" then parts.concat(%i[string long long long long string])
|
89
|
+
when "env" then parts.contact(%i[string string])
|
90
|
+
else
|
91
|
+
request = Packet.registered_channel_requests(@data[1])
|
92
|
+
raise "don't know what to do about #{@data[1]} channel request" unless request
|
93
|
+
parts.concat(request[:extra_parts])
|
94
|
+
end
|
95
|
+
else raise "don't know how to parse packet type #{@type}"
|
96
|
+
end
|
94
97
|
end
|
98
|
+
end
|
95
99
|
end
|
96
100
|
end
|
97
|
-
|
98
|
-
end; end; end
|
101
|
+
end
|
@@ -1,38 +1,42 @@
|
|
1
1
|
require 'net/ssh/buffer'
|
2
2
|
require 'net/ssh/test/packet'
|
3
3
|
|
4
|
-
module Net
|
4
|
+
module Net
|
5
|
+
module SSH
|
6
|
+
module Test
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
8
|
+
# This is a specialization of Net::SSH::Test::Packet for representing mock
|
9
|
+
# packets that are received by the local (client) host. These are created
|
10
|
+
# automatically by Net::SSH::Test::Script and Net::SSH::Test::Channel by any
|
11
|
+
# of the gets_* methods.
|
12
|
+
class RemotePacket < Packet
|
13
|
+
# Returns +true+; this is a remote packet.
|
14
|
+
def remote?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
# The #process method should only be called on Net::SSH::Test::LocalPacket
|
19
|
+
# packets; if it is attempted on a remote packet, then it is an expectation
|
20
|
+
# mismatch (a remote packet was received when a local packet was expected
|
21
|
+
# to be sent). This will happen when either your test script
|
22
|
+
# (Net::SSH::Test::Script) or your program are wrong.
|
23
|
+
def process(packet)
|
24
|
+
raise "received packet type #{packet.read_byte} and was not expecting any packet"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns this remote packet as a string, suitable for parsing by
|
28
|
+
# Net::SSH::Transport::PacketStream and friends. When a remote packet is
|
29
|
+
# received, this method is called and the result concatenated onto the
|
30
|
+
# input buffer for the packet stream.
|
31
|
+
def to_s
|
32
|
+
@to_s ||= begin
|
33
|
+
instantiate!
|
34
|
+
string = Net::SSH::Buffer.from(:byte, @type, *types.zip(@data).flatten).to_s
|
35
|
+
[string.length, string].pack("NA*")
|
36
|
+
end
|
37
|
+
end
|
34
38
|
end
|
39
|
+
|
35
40
|
end
|
36
41
|
end
|
37
|
-
|
38
|
-
end; end; end
|
42
|
+
end
|
data/lib/net/ssh/test/script.rb
CHANGED
@@ -2,179 +2,181 @@ require 'net/ssh/test/channel'
|
|
2
2
|
require 'net/ssh/test/local_packet'
|
3
3
|
require 'net/ssh/test/remote_packet'
|
4
4
|
|
5
|
-
module Net
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
5
|
+
module Net
|
6
|
+
module SSH
|
7
|
+
module Test
|
8
|
+
|
9
|
+
# Represents a sequence of scripted events that identify the behavior that
|
10
|
+
# a test expects. Methods named "sends_*" create events for packets being
|
11
|
+
# sent from the local to the remote host, and methods named "gets_*" create
|
12
|
+
# events for packets being received by the local from the remote host.
|
13
|
+
#
|
14
|
+
# A reference to a script. is generally obtained in a unit test via the
|
15
|
+
# Net::SSH::Test#story helper method:
|
16
|
+
#
|
17
|
+
# story do |script|
|
18
|
+
# channel = script.opens_channel
|
19
|
+
# ...
|
20
|
+
# end
|
21
|
+
class Script
|
22
|
+
# The list of scripted events. These will be Net::SSH::Test::LocalPacket
|
23
|
+
# and Net::SSH::Test::RemotePacket instances.
|
24
|
+
attr_reader :events
|
25
|
+
|
26
|
+
# Create a new, empty script.
|
27
|
+
def initialize
|
28
|
+
@events = []
|
29
|
+
end
|
30
|
+
|
31
|
+
# Scripts the opening of a channel by adding a local packet sending the
|
32
|
+
# channel open request, and if +confirm+ is true (the default), also
|
33
|
+
# adding a remote packet confirming the new channel.
|
34
|
+
#
|
35
|
+
# A new Net::SSH::Test::Channel instance is returned, which can be used
|
36
|
+
# to script additional channel operations.
|
37
|
+
def opens_channel(confirm=true)
|
38
|
+
channel = Channel.new(self)
|
39
|
+
channel.remote_id = 5555
|
40
|
+
|
41
|
+
events << LocalPacket.new(:channel_open) { |p| channel.local_id = p[:remote_id] }
|
42
|
+
|
43
|
+
events << RemotePacket.new(:channel_open_confirmation, channel.local_id, channel.remote_id, 0x20000, 0x10000) if confirm
|
44
|
+
|
45
|
+
channel
|
46
|
+
end
|
47
|
+
|
48
|
+
# A convenience method for adding an arbitrary local packet to the events
|
49
|
+
# list.
|
50
|
+
def sends(type, *args, &block)
|
51
|
+
events << LocalPacket.new(type, *args, &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
# A convenience method for adding an arbitrary remote packet to the events
|
55
|
+
# list.
|
56
|
+
def gets(type, *args)
|
57
|
+
events << RemotePacket.new(type, *args)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Scripts the sending of a new channel request packet to the remote host.
|
61
|
+
# +channel+ should be an instance of Net::SSH::Test::Channel. +request+
|
62
|
+
# is a string naming the request type to send, +reply+ is a boolean
|
63
|
+
# indicating whether a response to this packet is required , and +data+
|
64
|
+
# is any additional request-specific data that this packet should send.
|
65
|
+
# +success+ indicates whether the response (if one is required) should be
|
66
|
+
# success or failure. If +data+ is an array it will be treated as multiple
|
67
|
+
# data.
|
68
|
+
#
|
69
|
+
# If a reply is desired, a remote packet will also be queued, :channel_success
|
70
|
+
# if +success+ is true, or :channel_failure if +success+ is false.
|
71
|
+
#
|
72
|
+
# This will typically be called via Net::SSH::Test::Channel#sends_exec or
|
73
|
+
# Net::SSH::Test::Channel#sends_subsystem.
|
74
|
+
def sends_channel_request(channel, request, reply, data, success=true)
|
75
|
+
if data.is_a? Array
|
76
|
+
events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, *data)
|
77
|
+
else
|
78
|
+
events << LocalPacket.new(:channel_request, channel.remote_id, request, reply, data)
|
79
|
+
end
|
80
|
+
if reply
|
81
|
+
if success
|
82
|
+
events << RemotePacket.new(:channel_success, channel.local_id)
|
83
|
+
else
|
84
|
+
events << RemotePacket.new(:channel_failure, channel.local_id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Scripts the sending of a channel data packet. +channel+ must be a
|
90
|
+
# Net::SSH::Test::Channel object, and +data+ is the (string) data to
|
91
|
+
# expect will be sent.
|
92
|
+
#
|
93
|
+
# This will typically be called via Net::SSH::Test::Channel#sends_data.
|
94
|
+
def sends_channel_data(channel, data)
|
95
|
+
events << LocalPacket.new(:channel_data, channel.remote_id, data)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Scripts the sending of a channel EOF packet from the given
|
99
|
+
# Net::SSH::Test::Channel +channel+. This will typically be called via
|
100
|
+
# Net::SSH::Test::Channel#sends_eof.
|
101
|
+
def sends_channel_eof(channel)
|
102
|
+
events << LocalPacket.new(:channel_eof, channel.remote_id)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Scripts the sending of a channel close packet from the given
|
106
|
+
# Net::SSH::Test::Channel +channel+. This will typically be called via
|
107
|
+
# Net::SSH::Test::Channel#sends_close.
|
108
|
+
def sends_channel_close(channel)
|
109
|
+
events << LocalPacket.new(:channel_close, channel.remote_id)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Scripts the sending of a channel request pty packets from the given
|
113
|
+
# Net::SSH::Test::Channel +channel+. This will typically be called via
|
114
|
+
# Net::SSH::Test::Channel#sends_request_pty.
|
115
|
+
def sends_channel_request_pty(channel)
|
116
|
+
data = ['pty-req', false]
|
117
|
+
data += Net::SSH::Connection::Channel::VALID_PTY_OPTIONS.merge(modes: "\0").values
|
118
|
+
events << LocalPacket.new(:channel_request, channel.remote_id, *data)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Scripts the reception of a channel data packet from the remote host by
|
122
|
+
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
123
|
+
# called via Net::SSH::Test::Channel#gets_data.
|
124
|
+
def gets_channel_data(channel, data)
|
125
|
+
events << RemotePacket.new(:channel_data, channel.local_id, data)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Scripts the reception of a channel extended data packet from the remote
|
129
|
+
# host by the given Net::SSH::Test::Channel +channel+. This will typically
|
130
|
+
# be called via Net::SSH::Test::Channel#gets_extended_data.
|
131
|
+
#
|
132
|
+
# Currently the only extended data type is stderr == 1.
|
133
|
+
def gets_channel_extended_data(channel, data)
|
134
|
+
events << RemotePacket.new(:channel_extended_data, channel.local_id, 1, data)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Scripts the reception of a channel request packet from the remote host by
|
138
|
+
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
139
|
+
# called via Net::SSH::Test::Channel#gets_exit_status.
|
140
|
+
def gets_channel_request(channel, request, reply, data)
|
141
|
+
events << RemotePacket.new(:channel_request, channel.local_id, request, reply, data)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Scripts the reception of a channel EOF packet from the remote host by
|
145
|
+
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
146
|
+
# called via Net::SSH::Test::Channel#gets_eof.
|
147
|
+
def gets_channel_eof(channel)
|
148
|
+
events << RemotePacket.new(:channel_eof, channel.local_id)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Scripts the reception of a channel close packet from the remote host by
|
152
|
+
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
153
|
+
# called via Net::SSH::Test::Channel#gets_close.
|
154
|
+
def gets_channel_close(channel)
|
155
|
+
events << RemotePacket.new(:channel_close, channel.local_id)
|
156
|
+
end
|
157
|
+
|
158
|
+
# By default, removes the next event in the list and returns it. However,
|
159
|
+
# this can also be used to non-destructively peek at the next event in the
|
160
|
+
# list, by passing :first as the argument.
|
161
|
+
#
|
162
|
+
# # remove the next event and return it
|
163
|
+
# event = script.next
|
164
|
+
#
|
165
|
+
# # peek at the next event
|
166
|
+
# event = script.next(:first)
|
167
|
+
def next(mode=:shift)
|
168
|
+
events.send(mode)
|
169
|
+
end
|
170
|
+
|
171
|
+
# Compare the given packet against the next event in the list. If there is
|
172
|
+
# no next event, an exception will be raised. This is called by
|
173
|
+
# Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet.
|
174
|
+
def process(packet)
|
175
|
+
event = events.shift or raise "end of script reached, but got a packet type #{packet.read_byte}"
|
176
|
+
event.process(packet)
|
85
177
|
end
|
86
178
|
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Scripts the sending of a channel data packet. +channel+ must be a
|
90
|
-
# Net::SSH::Test::Channel object, and +data+ is the (string) data to
|
91
|
-
# expect will be sent.
|
92
|
-
#
|
93
|
-
# This will typically be called via Net::SSH::Test::Channel#sends_data.
|
94
|
-
def sends_channel_data(channel, data)
|
95
|
-
events << LocalPacket.new(:channel_data, channel.remote_id, data)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Scripts the sending of a channel EOF packet from the given
|
99
|
-
# Net::SSH::Test::Channel +channel+. This will typically be called via
|
100
|
-
# Net::SSH::Test::Channel#sends_eof.
|
101
|
-
def sends_channel_eof(channel)
|
102
|
-
events << LocalPacket.new(:channel_eof, channel.remote_id)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Scripts the sending of a channel close packet from the given
|
106
|
-
# Net::SSH::Test::Channel +channel+. This will typically be called via
|
107
|
-
# Net::SSH::Test::Channel#sends_close.
|
108
|
-
def sends_channel_close(channel)
|
109
|
-
events << LocalPacket.new(:channel_close, channel.remote_id)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Scripts the sending of a channel request pty packets from the given
|
113
|
-
# Net::SSH::Test::Channel +channel+. This will typically be called via
|
114
|
-
# Net::SSH::Test::Channel#sends_request_pty.
|
115
|
-
def sends_channel_request_pty(channel)
|
116
|
-
data = ['pty-req', false]
|
117
|
-
data += Net::SSH::Connection::Channel::VALID_PTY_OPTIONS.merge(modes: "\0").values
|
118
|
-
events << LocalPacket.new(:channel_request, channel.remote_id, *data)
|
119
|
-
end
|
120
179
|
|
121
|
-
# Scripts the reception of a channel data packet from the remote host by
|
122
|
-
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
123
|
-
# called via Net::SSH::Test::Channel#gets_data.
|
124
|
-
def gets_channel_data(channel, data)
|
125
|
-
events << RemotePacket.new(:channel_data, channel.local_id, data)
|
126
|
-
end
|
127
|
-
|
128
|
-
# Scripts the reception of a channel extended data packet from the remote
|
129
|
-
# host by the given Net::SSH::Test::Channel +channel+. This will typically
|
130
|
-
# be called via Net::SSH::Test::Channel#gets_extended_data.
|
131
|
-
#
|
132
|
-
# Currently the only extended data type is stderr == 1.
|
133
|
-
def gets_channel_extended_data(channel, data)
|
134
|
-
events << RemotePacket.new(:channel_extended_data, channel.local_id, 1, data)
|
135
|
-
end
|
136
|
-
|
137
|
-
# Scripts the reception of a channel request packet from the remote host by
|
138
|
-
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
139
|
-
# called via Net::SSH::Test::Channel#gets_exit_status.
|
140
|
-
def gets_channel_request(channel, request, reply, data)
|
141
|
-
events << RemotePacket.new(:channel_request, channel.local_id, request, reply, data)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Scripts the reception of a channel EOF packet from the remote host by
|
145
|
-
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
146
|
-
# called via Net::SSH::Test::Channel#gets_eof.
|
147
|
-
def gets_channel_eof(channel)
|
148
|
-
events << RemotePacket.new(:channel_eof, channel.local_id)
|
149
|
-
end
|
150
|
-
|
151
|
-
# Scripts the reception of a channel close packet from the remote host by
|
152
|
-
# the given Net::SSH::Test::Channel +channel+. This will typically be
|
153
|
-
# called via Net::SSH::Test::Channel#gets_close.
|
154
|
-
def gets_channel_close(channel)
|
155
|
-
events << RemotePacket.new(:channel_close, channel.local_id)
|
156
|
-
end
|
157
|
-
|
158
|
-
# By default, removes the next event in the list and returns it. However,
|
159
|
-
# this can also be used to non-destructively peek at the next event in the
|
160
|
-
# list, by passing :first as the argument.
|
161
|
-
#
|
162
|
-
# # remove the next event and return it
|
163
|
-
# event = script.next
|
164
|
-
#
|
165
|
-
# # peek at the next event
|
166
|
-
# event = script.next(:first)
|
167
|
-
def next(mode=:shift)
|
168
|
-
events.send(mode)
|
169
|
-
end
|
170
|
-
|
171
|
-
# Compare the given packet against the next event in the list. If there is
|
172
|
-
# no next event, an exception will be raised. This is called by
|
173
|
-
# Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet.
|
174
|
-
def process(packet)
|
175
|
-
event = events.shift or raise "end of script reached, but got a packet type #{packet.read_byte}"
|
176
|
-
event.process(packet)
|
177
180
|
end
|
178
181
|
end
|
179
|
-
|
180
|
-
end; end; end
|
182
|
+
end
|