net-ssh 5.0.0.beta1 → 5.0.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.rubocop_todo.yml +98 -258
  5. data/CHANGES.txt +8 -0
  6. data/Gemfile +1 -3
  7. data/Rakefile +37 -39
  8. data/lib/net/ssh.rb +26 -25
  9. data/lib/net/ssh/authentication/agent.rb +228 -225
  10. data/lib/net/ssh/authentication/certificate.rb +166 -164
  11. data/lib/net/ssh/authentication/constants.rb +17 -14
  12. data/lib/net/ssh/authentication/ed25519.rb +107 -104
  13. data/lib/net/ssh/authentication/ed25519_loader.rb +32 -28
  14. data/lib/net/ssh/authentication/key_manager.rb +5 -3
  15. data/lib/net/ssh/authentication/methods/abstract.rb +53 -47
  16. data/lib/net/ssh/authentication/methods/hostbased.rb +32 -33
  17. data/lib/net/ssh/authentication/methods/keyboard_interactive.rb +2 -4
  18. data/lib/net/ssh/authentication/methods/none.rb +10 -10
  19. data/lib/net/ssh/authentication/methods/password.rb +13 -13
  20. data/lib/net/ssh/authentication/methods/publickey.rb +54 -55
  21. data/lib/net/ssh/authentication/pageant.rb +468 -465
  22. data/lib/net/ssh/authentication/pub_key_fingerprint.rb +44 -0
  23. data/lib/net/ssh/authentication/session.rb +127 -123
  24. data/lib/net/ssh/buffer.rb +305 -303
  25. data/lib/net/ssh/buffered_io.rb +163 -162
  26. data/lib/net/ssh/config.rb +230 -227
  27. data/lib/net/ssh/connection/channel.rb +659 -654
  28. data/lib/net/ssh/connection/constants.rb +30 -26
  29. data/lib/net/ssh/connection/event_loop.rb +108 -104
  30. data/lib/net/ssh/connection/keepalive.rb +54 -50
  31. data/lib/net/ssh/connection/session.rb +677 -678
  32. data/lib/net/ssh/connection/term.rb +180 -176
  33. data/lib/net/ssh/errors.rb +101 -99
  34. data/lib/net/ssh/key_factory.rb +108 -108
  35. data/lib/net/ssh/known_hosts.rb +148 -154
  36. data/lib/net/ssh/loggable.rb +56 -54
  37. data/lib/net/ssh/packet.rb +82 -78
  38. data/lib/net/ssh/prompt.rb +55 -53
  39. data/lib/net/ssh/proxy/command.rb +103 -102
  40. data/lib/net/ssh/proxy/errors.rb +12 -8
  41. data/lib/net/ssh/proxy/http.rb +92 -91
  42. data/lib/net/ssh/proxy/https.rb +42 -39
  43. data/lib/net/ssh/proxy/jump.rb +50 -47
  44. data/lib/net/ssh/proxy/socks4.rb +0 -2
  45. data/lib/net/ssh/proxy/socks5.rb +11 -11
  46. data/lib/net/ssh/ruby_compat.rb +1 -0
  47. data/lib/net/ssh/service/forward.rb +364 -362
  48. data/lib/net/ssh/test.rb +85 -83
  49. data/lib/net/ssh/test/channel.rb +146 -142
  50. data/lib/net/ssh/test/extensions.rb +148 -146
  51. data/lib/net/ssh/test/kex.rb +35 -31
  52. data/lib/net/ssh/test/local_packet.rb +48 -44
  53. data/lib/net/ssh/test/packet.rb +87 -84
  54. data/lib/net/ssh/test/remote_packet.rb +35 -31
  55. data/lib/net/ssh/test/script.rb +173 -171
  56. data/lib/net/ssh/test/socket.rb +59 -55
  57. data/lib/net/ssh/transport/algorithms.rb +413 -412
  58. data/lib/net/ssh/transport/cipher_factory.rb +108 -105
  59. data/lib/net/ssh/transport/constants.rb +35 -31
  60. data/lib/net/ssh/transport/ctr.rb +1 -1
  61. data/lib/net/ssh/transport/hmac.rb +1 -1
  62. data/lib/net/ssh/transport/hmac/abstract.rb +67 -64
  63. data/lib/net/ssh/transport/hmac/sha2_256_96.rb +1 -1
  64. data/lib/net/ssh/transport/hmac/sha2_512_96.rb +1 -1
  65. data/lib/net/ssh/transport/identity_cipher.rb +55 -51
  66. data/lib/net/ssh/transport/kex.rb +2 -4
  67. data/lib/net/ssh/transport/kex/diffie_hellman_group14_sha1.rb +47 -40
  68. data/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +201 -197
  69. data/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +53 -56
  70. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp256.rb +94 -87
  71. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp384.rb +17 -10
  72. data/lib/net/ssh/transport/kex/ecdh_sha2_nistp521.rb +17 -10
  73. data/lib/net/ssh/transport/key_expander.rb +29 -25
  74. data/lib/net/ssh/transport/openssl.rb +17 -30
  75. data/lib/net/ssh/transport/packet_stream.rb +193 -192
  76. data/lib/net/ssh/transport/server_version.rb +64 -66
  77. data/lib/net/ssh/transport/session.rb +286 -284
  78. data/lib/net/ssh/transport/state.rb +198 -196
  79. data/lib/net/ssh/verifiers/lenient.rb +29 -25
  80. data/lib/net/ssh/verifiers/null.rb +13 -9
  81. data/lib/net/ssh/verifiers/secure.rb +45 -45
  82. data/lib/net/ssh/verifiers/strict.rb +20 -16
  83. data/lib/net/ssh/version.rb +55 -53
  84. data/net-ssh.gemspec +4 -4
  85. data/support/ssh_tunnel_bug.rb +2 -2
  86. metadata +25 -24
  87. metadata.gz.sig +0 -0
@@ -1,98 +1,101 @@
1
1
  require 'net/ssh/connection/constants'
2
2
  require 'net/ssh/transport/constants'
3
3
 
4
- module Net; module SSH; module Test
4
+ module Net
5
+ module SSH
6
+ module Test
5
7
 
6
- # This is an abstract class, not to be instantiated directly, subclassed by
7
- # Net::SSH::Test::LocalPacket and Net::SSH::Test::RemotePacket. It implements
8
- # functionality common to those subclasses.
9
- #
10
- # These packets are not true packets, in that they don't represent what was
11
- # actually sent between the hosst; rather, they represent what was expected
12
- # to be sent, as dictated by the script (Net::SSH::Test::Script). Thus,
13
- # though they are defined with data elements, these data elements are used
14
- # to either validate data that was sent by the local host (Net::SSH::Test::LocalPacket)
15
- # or to mimic the sending of data by the remote host (Net::SSH::Test::RemotePacket).
16
- class Packet
17
- include Net::SSH::Transport::Constants
18
- include Net::SSH::Connection::Constants
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
- # Register a custom channel request. extra_parts is an array of types
21
- # of extra parameters
22
- def self.register_channel_request(request, extra_parts)
23
- @registered_requests ||= {}
24
- @registered_requests[request] = {extra_parts: extra_parts}
25
- end
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
- def self.registered_channel_requests(request)
28
- @registered_requests && @registered_requests[request]
29
- end
29
+ def self.registered_channel_requests(request)
30
+ @registered_requests && @registered_requests[request]
31
+ end
30
32
 
31
- # Ceate a new packet of the given +type+, and with +args+ being a list of
32
- # data elements in the order expected for packets of the given +type+
33
- # (see #types).
34
- def initialize(type, *args)
35
- @type = self.class.const_get(type.to_s.upcase)
36
- @data = args
37
- end
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
- # The default for +remote?+ is false. Subclasses should override as necessary.
40
- def remote?
41
- false
42
- end
41
+ # The default for +remote?+ is false. Subclasses should override as necessary.
42
+ def remote?
43
+ false
44
+ end
43
45
 
44
- # The default for +local?+ is false. Subclasses should override as necessary.
45
- def local?
46
- false
47
- end
46
+ # The default for +local?+ is false. Subclasses should override as necessary.
47
+ def local?
48
+ false
49
+ end
48
50
 
49
- # Instantiates the packets data elements. When the packet was first defined,
50
- # some elements may not have been fully realized, and were described as
51
- # Proc objects rather than atomic types. This invokes those Proc objects
52
- # and replaces them with their returned values. This allows for values
53
- # like Net::SSH::Test::Channel#remote_id to be used in scripts before
54
- # the remote_id is known (since it is only known after a channel has been
55
- # confirmed open).
56
- def instantiate!
57
- @data.map! { |i| i.respond_to?(:call) ? i.call : i }
58
- end
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
- # Returns an array of symbols describing the data elements for packets of
61
- # the same type as this packet. These types are used to either validate
62
- # sent packets (Net::SSH::Test::LocalPacket) or build received packets
63
- # (Net::SSH::Test::RemotePacket).
64
- #
65
- # Not all packet types are defined here. As new packet types are required
66
- # (e.g., a unit test needs to test that the remote host sent a packet that
67
- # is not implemented here), the description of that packet should be
68
- # added. Unsupported packet types will otherwise raise an exception.
69
- def types
70
- @types ||= case @type
71
- when KEXINIT then
72
- [:long, :long, :long, :long,
73
- :string, :string, :string, :string, :string, :string, :string, :string, :string, :string,
74
- :bool]
75
- when NEWKEYS then []
76
- when CHANNEL_OPEN then [:string, :long, :long, :long]
77
- when CHANNEL_OPEN_CONFIRMATION then [:long, :long, :long, :long]
78
- when CHANNEL_DATA then [:long, :string]
79
- when CHANNEL_EXTENDED_DATA then [:long, :long, :string]
80
- when CHANNEL_EOF, CHANNEL_CLOSE, CHANNEL_SUCCESS, CHANNEL_FAILURE then [:long]
81
- when CHANNEL_REQUEST
82
- parts = [:long, :string, :bool]
83
- case @data[1]
84
- when "exec", "subsystem","shell" then parts << :string
85
- when "exit-status" then parts << :long
86
- when "pty-req" then parts.concat([:string, :long, :long, :long, :long, :string])
87
- when "env" then parts.contact([:string,:string])
88
- else
89
- request = Packet.registered_channel_requests(@data[1])
90
- raise "don't know what to do about #{@data[1]} channel request" unless request
91
- parts.concat(request[:extra_parts])
92
- end
93
- else raise "don't know how to parse packet type #{@type}"
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; module SSH; module Test
4
+ module Net
5
+ module SSH
6
+ module Test
5
7
 
6
- # This is a specialization of Net::SSH::Test::Packet for representing mock
7
- # packets that are received by the local (client) host. These are created
8
- # automatically by Net::SSH::Test::Script and Net::SSH::Test::Channel by any
9
- # of the gets_* methods.
10
- class RemotePacket < Packet
11
- # Returns +true+; this is a remote packet.
12
- def remote?
13
- true
14
- end
15
-
16
- # The #process method should only be called on Net::SSH::Test::LocalPacket
17
- # packets; if it is attempted on a remote packet, then it is an expectation
18
- # mismatch (a remote packet was received when a local packet was expected
19
- # to be sent). This will happen when either your test script
20
- # (Net::SSH::Test::Script) or your program are wrong.
21
- def process(packet)
22
- raise "received packet type #{packet.read_byte} and was not expecting any packet"
23
- end
24
-
25
- # Returns this remote packet as a string, suitable for parsing by
26
- # Net::SSH::Transport::PacketStream and friends. When a remote packet is
27
- # received, this method is called and the result concatenated onto the
28
- # input buffer for the packet stream.
29
- def to_s
30
- @to_s ||= begin
31
- instantiate!
32
- string = Net::SSH::Buffer.from(:byte, @type, *types.zip(@data).flatten).to_s
33
- [string.length, string].pack("NA*")
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
@@ -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; module SSH; module Test
6
-
7
- # Represents a sequence of scripted events that identify the behavior that
8
- # a test expects. Methods named "sends_*" create events for packets being
9
- # sent from the local to the remote host, and methods named "gets_*" create
10
- # events for packets being received by the local from the remote host.
11
- #
12
- # A reference to a script. is generally obtained in a unit test via the
13
- # Net::SSH::Test#story helper method:
14
- #
15
- # story do |script|
16
- # channel = script.opens_channel
17
- # ...
18
- # end
19
- class Script
20
- # The list of scripted events. These will be Net::SSH::Test::LocalPacket
21
- # and Net::SSH::Test::RemotePacket instances.
22
- attr_reader :events
23
-
24
- # Create a new, empty script.
25
- def initialize
26
- @events = []
27
- end
28
-
29
- # Scripts the opening of a channel by adding a local packet sending the
30
- # channel open request, and if +confirm+ is true (the default), also
31
- # adding a remote packet confirming the new channel.
32
- #
33
- # A new Net::SSH::Test::Channel instance is returned, which can be used
34
- # to script additional channel operations.
35
- def opens_channel(confirm=true)
36
- channel = Channel.new(self)
37
- channel.remote_id = 5555
38
-
39
- events << LocalPacket.new(:channel_open) { |p| channel.local_id = p[:remote_id] }
40
-
41
- if confirm
42
- events << RemotePacket.new(:channel_open_confirmation, channel.local_id, channel.remote_id, 0x20000, 0x10000)
43
- end
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)
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