redcar 0.3.7.1 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. data/CHANGES +16 -0
  2. data/README.md +5 -0
  3. data/ROADMAP.md +7 -9
  4. data/Rakefile +55 -22
  5. data/lib/redcar.rb +12 -6
  6. data/lib/redcar/installer.rb +119 -44
  7. data/plugins/application/features/step_definitions/speedbar_steps.rb +62 -0
  8. data/plugins/application/features/step_definitions/tree_steps.rb +3 -3
  9. data/plugins/application/features/support/env.rb +2 -1
  10. data/plugins/application/lib/application/notebook.rb +53 -7
  11. data/plugins/application/lib/application/speedbar.rb +12 -0
  12. data/plugins/application/lib/application/tab.rb +16 -5
  13. data/plugins/application/lib/application/treebook.rb +21 -1
  14. data/plugins/application_swt/lib/application_swt.rb +12 -2
  15. data/plugins/application_swt/lib/application_swt/html_tab.rb +4 -0
  16. data/plugins/application_swt/lib/application_swt/notebook.rb +5 -3
  17. data/plugins/application_swt/lib/application_swt/speedbar.rb +15 -27
  18. data/plugins/application_swt/lib/application_swt/swt_wrapper.rb +1 -0
  19. data/plugins/application_swt/lib/application_swt/tab.rb +1 -0
  20. data/plugins/application_swt/lib/application_swt/treebook.rb +36 -8
  21. data/plugins/application_swt/lib/application_swt/window.rb +24 -18
  22. data/plugins/auto_completer/lib/auto_completer.rb +5 -20
  23. data/plugins/core/lib/core.rb +7 -4
  24. data/plugins/core/lib/core/observable_struct.rb +2 -2
  25. data/plugins/declarations/lib/declarations.rb +3 -17
  26. data/plugins/document_search/features/search.feature +163 -0
  27. data/plugins/document_search/features/support/env.rb +4 -0
  28. data/plugins/document_search/lib/document_search.rb +121 -0
  29. data/plugins/document_search/plugin.rb +8 -0
  30. data/plugins/edit_view/features/line_delimiter.feature +7 -0
  31. data/plugins/edit_view/features/step_definitions/editing_steps.rb +49 -1
  32. data/plugins/edit_view/features/step_definitions/tab_steps.rb +10 -11
  33. data/plugins/edit_view/features/switch_tabs.feature +61 -10
  34. data/plugins/edit_view/lib/edit_view.rb +4 -0
  35. data/plugins/edit_view/lib/edit_view/document.rb +56 -0
  36. data/plugins/edit_view/lib/edit_view/document/command.rb +1 -1
  37. data/plugins/edit_view/lib/edit_view/edit_tab.rb +0 -8
  38. data/plugins/edit_view_swt/lib/edit_view_swt.rb +4 -0
  39. data/plugins/html_view/lib/html_controller.rb +19 -1
  40. data/plugins/html_view/lib/html_view.rb +28 -1
  41. data/plugins/html_view/lib/html_view/html_tab.rb +10 -1
  42. data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +3 -1
  43. data/plugins/project/features/open_directory_tree.feature +3 -3
  44. data/plugins/project/lib/project.rb +4 -6
  45. data/plugins/project/lib/project/commands.rb +17 -0
  46. data/plugins/project/lib/project/dir_controller.rb +2 -1
  47. data/plugins/project/lib/project/dir_mirror.rb +8 -0
  48. data/plugins/project/lib/project/manager.rb +2 -0
  49. data/plugins/project/plugin.rb +2 -1
  50. data/plugins/project/vendor/net-sftp/Manifest +55 -0
  51. data/plugins/project/vendor/net-sftp/Rakefile +30 -0
  52. data/plugins/project/vendor/net-sftp/lib/net/sftp.rb +70 -0
  53. data/plugins/project/vendor/net-sftp/lib/net/sftp/constants.rb +187 -0
  54. data/plugins/project/vendor/net-sftp/lib/net/sftp/errors.rb +39 -0
  55. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/dir.rb +93 -0
  56. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/download.rb +364 -0
  57. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file.rb +176 -0
  58. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/file_factory.rb +60 -0
  59. data/plugins/project/vendor/net-sftp/lib/net/sftp/operations/upload.rb +387 -0
  60. data/plugins/project/vendor/net-sftp/lib/net/sftp/packet.rb +21 -0
  61. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol.rb +32 -0
  62. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/attributes.rb +315 -0
  63. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/base.rb +268 -0
  64. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/01/name.rb +43 -0
  65. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/02/base.rb +31 -0
  66. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/03/base.rb +35 -0
  67. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/attributes.rb +152 -0
  68. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/base.rb +94 -0
  69. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/04/name.rb +67 -0
  70. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/05/base.rb +66 -0
  71. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/attributes.rb +107 -0
  72. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/06/base.rb +63 -0
  73. data/plugins/project/vendor/net-sftp/lib/net/sftp/protocol/base.rb +50 -0
  74. data/plugins/project/vendor/net-sftp/lib/net/sftp/request.rb +91 -0
  75. data/plugins/project/vendor/net-sftp/lib/net/sftp/response.rb +76 -0
  76. data/plugins/project/vendor/net-sftp/lib/net/sftp/session.rb +951 -0
  77. data/plugins/project/vendor/net-sftp/lib/net/sftp/version.rb +18 -0
  78. data/plugins/project/vendor/net-sftp/setup.rb +1331 -0
  79. data/plugins/project/vendor/net-sftp/test/common.rb +171 -0
  80. data/plugins/project/vendor/net-sftp/test/protocol/01/test_attributes.rb +97 -0
  81. data/plugins/project/vendor/net-sftp/test/protocol/01/test_base.rb +210 -0
  82. data/plugins/project/vendor/net-sftp/test/protocol/01/test_name.rb +27 -0
  83. data/plugins/project/vendor/net-sftp/test/protocol/02/test_base.rb +26 -0
  84. data/plugins/project/vendor/net-sftp/test/protocol/03/test_base.rb +27 -0
  85. data/plugins/project/vendor/net-sftp/test/protocol/04/test_attributes.rb +148 -0
  86. data/plugins/project/vendor/net-sftp/test/protocol/04/test_base.rb +74 -0
  87. data/plugins/project/vendor/net-sftp/test/protocol/04/test_name.rb +53 -0
  88. data/plugins/project/vendor/net-sftp/test/protocol/05/test_base.rb +62 -0
  89. data/plugins/project/vendor/net-sftp/test/protocol/06/test_attributes.rb +124 -0
  90. data/plugins/project/vendor/net-sftp/test/protocol/06/test_base.rb +51 -0
  91. data/plugins/project/vendor/net-sftp/test/protocol/test_base.rb +42 -0
  92. data/plugins/project/vendor/net-sftp/test/test_all.rb +7 -0
  93. data/plugins/project/vendor/net-sftp/test/test_dir.rb +47 -0
  94. data/plugins/project/vendor/net-sftp/test/test_download.rb +252 -0
  95. data/plugins/project/vendor/net-sftp/test/test_file.rb +159 -0
  96. data/plugins/project/vendor/net-sftp/test/test_file_factory.rb +48 -0
  97. data/plugins/project/vendor/net-sftp/test/test_packet.rb +9 -0
  98. data/plugins/project/vendor/net-sftp/test/test_protocol.rb +17 -0
  99. data/plugins/project/vendor/net-sftp/test/test_request.rb +71 -0
  100. data/plugins/project/vendor/net-sftp/test/test_response.rb +53 -0
  101. data/plugins/project/vendor/net-sftp/test/test_session.rb +741 -0
  102. data/plugins/project/vendor/net-sftp/test/test_upload.rb +219 -0
  103. data/plugins/project/vendor/net-ssh/Manifest +110 -0
  104. data/plugins/project/vendor/net-ssh/Rakefile +85 -0
  105. data/plugins/project/vendor/net-ssh/Rudyfile +96 -0
  106. data/plugins/project/vendor/net-ssh/lib/net/ssh.rb +215 -0
  107. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/agent.rb +179 -0
  108. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/constants.rb +18 -0
  109. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/key_manager.rb +193 -0
  110. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  111. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  112. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  113. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/password.rb +39 -0
  114. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  115. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/pageant.rb +183 -0
  116. data/plugins/project/vendor/net-ssh/lib/net/ssh/authentication/session.rb +134 -0
  117. data/plugins/project/vendor/net-ssh/lib/net/ssh/buffer.rb +340 -0
  118. data/plugins/project/vendor/net-ssh/lib/net/ssh/buffered_io.rb +198 -0
  119. data/plugins/project/vendor/net-ssh/lib/net/ssh/config.rb +202 -0
  120. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/channel.rb +630 -0
  121. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/constants.rb +33 -0
  122. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/session.rb +597 -0
  123. data/plugins/project/vendor/net-ssh/lib/net/ssh/connection/term.rb +178 -0
  124. data/plugins/project/vendor/net-ssh/lib/net/ssh/errors.rb +85 -0
  125. data/plugins/project/vendor/net-ssh/lib/net/ssh/key_factory.rb +102 -0
  126. data/plugins/project/vendor/net-ssh/lib/net/ssh/known_hosts.rb +129 -0
  127. data/plugins/project/vendor/net-ssh/lib/net/ssh/loggable.rb +61 -0
  128. data/plugins/project/vendor/net-ssh/lib/net/ssh/packet.rb +102 -0
  129. data/plugins/project/vendor/net-ssh/lib/net/ssh/prompt.rb +93 -0
  130. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/command.rb +75 -0
  131. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/errors.rb +14 -0
  132. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/http.rb +94 -0
  133. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks4.rb +70 -0
  134. data/plugins/project/vendor/net-ssh/lib/net/ssh/proxy/socks5.rb +142 -0
  135. data/plugins/project/vendor/net-ssh/lib/net/ssh/ruby_compat.rb +43 -0
  136. data/plugins/project/vendor/net-ssh/lib/net/ssh/service/forward.rb +288 -0
  137. data/plugins/project/vendor/net-ssh/lib/net/ssh/test.rb +89 -0
  138. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/channel.rb +129 -0
  139. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/extensions.rb +152 -0
  140. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/kex.rb +44 -0
  141. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/local_packet.rb +51 -0
  142. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/packet.rb +81 -0
  143. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/remote_packet.rb +38 -0
  144. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/script.rb +157 -0
  145. data/plugins/project/vendor/net-ssh/lib/net/ssh/test/socket.rb +64 -0
  146. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/algorithms.rb +384 -0
  147. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/cipher_factory.rb +97 -0
  148. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/constants.rb +30 -0
  149. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac.rb +31 -0
  150. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  151. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5.rb +12 -0
  152. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  153. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/none.rb +15 -0
  154. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  155. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  156. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/identity_cipher.rb +55 -0
  157. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex.rb +13 -0
  158. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  159. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  160. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/openssl.rb +128 -0
  161. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/packet_stream.rb +235 -0
  162. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/server_version.rb +71 -0
  163. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/session.rb +276 -0
  164. data/plugins/project/vendor/net-ssh/lib/net/ssh/transport/state.rb +206 -0
  165. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/lenient.rb +30 -0
  166. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/null.rb +12 -0
  167. data/plugins/project/vendor/net-ssh/lib/net/ssh/verifiers/strict.rb +53 -0
  168. data/plugins/project/vendor/net-ssh/lib/net/ssh/version.rb +62 -0
  169. data/plugins/project/vendor/net-ssh/net-ssh.gemspec +138 -0
  170. data/plugins/project/vendor/net-ssh/setup.rb +1585 -0
  171. data/plugins/project/vendor/net-ssh/support/arcfour_check.rb +20 -0
  172. data/plugins/project/vendor/net-ssh/support/ssh_tunnel_bug.rb +65 -0
  173. data/plugins/project/vendor/net-ssh/test/README.txt +42 -0
  174. data/plugins/project/vendor/net-ssh/test/authentication/methods/common.rb +28 -0
  175. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_abstract.rb +51 -0
  176. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_hostbased.rb +114 -0
  177. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_keyboard_interactive.rb +98 -0
  178. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_password.rb +50 -0
  179. data/plugins/project/vendor/net-ssh/test/authentication/methods/test_publickey.rb +127 -0
  180. data/plugins/project/vendor/net-ssh/test/authentication/test_agent.rb +205 -0
  181. data/plugins/project/vendor/net-ssh/test/authentication/test_key_manager.rb +105 -0
  182. data/plugins/project/vendor/net-ssh/test/authentication/test_session.rb +93 -0
  183. data/plugins/project/vendor/net-ssh/test/common.rb +107 -0
  184. data/plugins/project/vendor/net-ssh/test/configs/eqsign +3 -0
  185. data/plugins/project/vendor/net-ssh/test/configs/exact_match +8 -0
  186. data/plugins/project/vendor/net-ssh/test/configs/host_plus +10 -0
  187. data/plugins/project/vendor/net-ssh/test/configs/multihost +4 -0
  188. data/plugins/project/vendor/net-ssh/test/configs/nohost +19 -0
  189. data/plugins/project/vendor/net-ssh/test/configs/numeric_host +4 -0
  190. data/plugins/project/vendor/net-ssh/test/configs/wild_cards +14 -0
  191. data/plugins/project/vendor/net-ssh/test/connection/test_channel.rb +467 -0
  192. data/plugins/project/vendor/net-ssh/test/connection/test_session.rb +488 -0
  193. data/plugins/project/vendor/net-ssh/test/manual/test_forward.rb +185 -0
  194. data/plugins/project/vendor/net-ssh/test/test_all.rb +9 -0
  195. data/plugins/project/vendor/net-ssh/test/test_buffer.rb +336 -0
  196. data/plugins/project/vendor/net-ssh/test/test_buffered_io.rb +63 -0
  197. data/plugins/project/vendor/net-ssh/test/test_config.rb +117 -0
  198. data/plugins/project/vendor/net-ssh/test/test_key_factory.rb +67 -0
  199. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5.rb +39 -0
  200. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_md5_96.rb +25 -0
  201. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_none.rb +34 -0
  202. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1.rb +34 -0
  203. data/plugins/project/vendor/net-ssh/test/transport/hmac/test_sha1_96.rb +25 -0
  204. data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group1_sha1.rb +146 -0
  205. data/plugins/project/vendor/net-ssh/test/transport/kex/test_diffie_hellman_group_exchange_sha1.rb +92 -0
  206. data/plugins/project/vendor/net-ssh/test/transport/test_algorithms.rb +302 -0
  207. data/plugins/project/vendor/net-ssh/test/transport/test_cipher_factory.rb +213 -0
  208. data/plugins/project/vendor/net-ssh/test/transport/test_hmac.rb +34 -0
  209. data/plugins/project/vendor/net-ssh/test/transport/test_identity_cipher.rb +40 -0
  210. data/plugins/project/vendor/net-ssh/test/transport/test_packet_stream.rb +441 -0
  211. data/plugins/project/vendor/net-ssh/test/transport/test_server_version.rb +78 -0
  212. data/plugins/project/vendor/net-ssh/test/transport/test_session.rb +315 -0
  213. data/plugins/project/vendor/net-ssh/test/transport/test_state.rb +173 -0
  214. data/plugins/redcar/plugin.rb +3 -1
  215. data/plugins/redcar/redcar.rb +108 -121
  216. data/plugins/redcar_debug/lib/redcar_debug.rb +2 -0
  217. data/plugins/runnables/lib/runnables.rb +80 -23
  218. data/plugins/runnables/lib/runnables/command_output_controller.rb +102 -0
  219. data/plugins/runnables/lib/runnables/running_process_checker.rb +34 -0
  220. data/plugins/runnables/{plugin_no_load.rb → plugin.rb} +2 -1
  221. data/plugins/runnables/vendor/session-2.4.0/HISTORY +73 -0
  222. data/plugins/runnables/vendor/session-2.4.0/README +89 -0
  223. data/plugins/runnables/vendor/session-2.4.0/TODO +3 -0
  224. data/plugins/runnables/vendor/session-2.4.0/VERSION +1 -0
  225. data/plugins/runnables/vendor/session-2.4.0/gemspec.rb +22 -0
  226. data/plugins/runnables/vendor/session-2.4.0/install.rb +143 -0
  227. data/plugins/runnables/vendor/session-2.4.0/lib/session.rb +757 -0
  228. data/plugins/runnables/vendor/session-2.4.0/sample/bash.rb +60 -0
  229. data/plugins/runnables/vendor/session-2.4.0/sample/driver.rb +47 -0
  230. data/plugins/runnables/vendor/session-2.4.0/sample/session_idl.rb +25 -0
  231. data/plugins/runnables/vendor/session-2.4.0/sample/session_sh.rb +29 -0
  232. data/plugins/runnables/vendor/session-2.4.0/sample/sh0.rb +23 -0
  233. data/plugins/runnables/vendor/session-2.4.0/sample/stdin.rb +17 -0
  234. data/plugins/runnables/vendor/session-2.4.0/sample/threadtest.rb +42 -0
  235. data/plugins/runnables/vendor/session-2.4.0/session-2.4.0.gem +0 -0
  236. data/plugins/runnables/vendor/session-2.4.0/test/session.rb +227 -0
  237. data/plugins/runnables/views/command_output.html.erb +32 -0
  238. data/plugins/task_manager/lib/task_manager.rb +2 -0
  239. data/plugins/textmate/lib/textmate/plist.rb +1 -1
  240. data/plugins/textmate/lib/textmate/snippet.rb +1 -0
  241. data/plugins/tree/lib/tree/mirror.rb +8 -1
  242. data/plugins/tree_view_swt/lib/tree_view_swt.rb +29 -2
  243. metadata +191 -6
  244. data/plugins/declarations/TODO +0 -3
  245. data/plugins/redcar/spec/redcar/redcar_spec.rb +0 -70
  246. data/plugins/redcar/spec/spec_helper.rb +0 -4
@@ -0,0 +1,48 @@
1
+ require "common"
2
+
3
+ class FileFactoryTest < Net::SFTP::TestCase
4
+ def setup
5
+ @sftp = stub(:sftp)
6
+ @factory = Net::SFTP::Operations::FileFactory.new(@sftp)
7
+ end
8
+
9
+ def test_open_with_block_should_yield_and_close_handle
10
+ @sftp.expects(:open!).with("/path/to/remote", "r", :permissions => nil).returns("handle")
11
+ @sftp.expects(:close!).with("handle")
12
+
13
+ called = false
14
+ @factory.open("/path/to/remote") do |f|
15
+ called = true
16
+ assert_instance_of Net::SFTP::Operations::File, f
17
+ end
18
+
19
+ assert called
20
+ end
21
+
22
+ def test_open_with_block_should_close_file_even_if_exception_is_raised
23
+ @sftp.expects(:open!).with("/path/to/remote", "r", :permissions => nil).returns("handle")
24
+ @sftp.expects(:close!).with("handle")
25
+
26
+ assert_raises(RuntimeError) do
27
+ @factory.open("/path/to/remote") { |f| raise RuntimeError, "b00m" }
28
+ end
29
+ end
30
+
31
+ def test_open_without_block_should_return_new_file
32
+ @sftp.expects(:open!).with("/path/to/remote", "r", :permissions => nil).returns("handle")
33
+ @sftp.expects(:close!).never
34
+
35
+ f = @factory.open("/path/to/remote")
36
+ assert_instance_of Net::SFTP::Operations::File, f
37
+ end
38
+
39
+ def test_directory_should_be_true_for_directory
40
+ @sftp.expects(:lstat!).with("/path/to/dir").returns(mock('attrs', :directory? => true))
41
+ assert @factory.directory?("/path/to/dir")
42
+ end
43
+
44
+ def test_directory_should_be_false_for_non_directory
45
+ @sftp.expects(:lstat!).with("/path/to/file").returns(mock('attrs', :directory? => false))
46
+ assert !@factory.directory?("/path/to/file")
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ require 'common'
2
+
3
+ class PacketTest < Net::SFTP::TestCase
4
+ def test_packet_should_auto_read_type_byte
5
+ packet = Net::SFTP::Packet.new("\001rest-of-packet-here")
6
+ assert_equal 1, packet.type
7
+ assert_equal "rest-of-packet-here", packet.content[packet.position..-1]
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'common'
2
+
3
+ class ProtocolTest < Net::SFTP::TestCase
4
+ 1.upto(6) do |version|
5
+ define_method("test_load_version_#{version}_should_return_v#{version}_driver") do
6
+ session = stub('session', :logger => nil)
7
+ driver = Net::SFTP::Protocol.load(session, version)
8
+ assert_instance_of Net::SFTP::Protocol.const_get("V%02d" % version)::Base, driver
9
+ end
10
+ end
11
+
12
+ def test_load_version_7_should_be_unsupported
13
+ assert_raises(NotImplementedError) do
14
+ Net::SFTP::Protocol.load(stub('session'), 7)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,71 @@
1
+ require 'common'
2
+
3
+ class RequestTest < Net::SFTP::TestCase
4
+ def test_property_setter_should_symbolize_key
5
+ request = Net::SFTP::Request.new(stub("session"), :open, 1)
6
+ request["key"] = :value
7
+ assert_equal :value, request['key']
8
+ assert_equal :value, request[:key]
9
+ assert_equal :value, request.properties[:key]
10
+ assert_nil request.properties['key']
11
+ end
12
+
13
+ def test_pending_should_query_pending_requests_of_session
14
+ session = stub("session", :pending_requests => {1 => true})
15
+ request = Net::SFTP::Request.new(session, :open, 1)
16
+ assert request.pending?
17
+ request = Net::SFTP::Request.new(session, :open, 2)
18
+ assert !request.pending?
19
+ end
20
+
21
+ def test_wait_should_run_loop_while_pending_and_return_self
22
+ session = MockSession.new
23
+ request = Net::SFTP::Request.new(session, :open, 1)
24
+ request.expects(:pending?).times(4).returns(true, true, true, false)
25
+ assert_equal 0, session.loops
26
+ assert_equal request, request.wait
27
+ assert_equal 4, session.loops
28
+ end
29
+
30
+ def test_respond_to_should_set_response_property
31
+ packet = stub("packet", :type => 1)
32
+ session = stub("session", :protocol => mock("protocol"))
33
+ session.protocol.expects(:parse).with(packet).returns({})
34
+ request = Net::SFTP::Request.new(session, :open, 1)
35
+ assert_nil request.response
36
+ request.respond_to(packet)
37
+ assert_instance_of Net::SFTP::Response, request.response
38
+ end
39
+
40
+ def test_respond_to_with_callback_should_invoke_callback
41
+ packet = stub("packet", :type => 1)
42
+ session = stub("session", :protocol => mock("protocol"))
43
+ session.protocol.expects(:parse).with(packet).returns({})
44
+
45
+ called = false
46
+ request = Net::SFTP::Request.new(session, :open, 1) do |response|
47
+ called = true
48
+ assert_equal request.response, response
49
+ end
50
+
51
+ request.respond_to(packet)
52
+ assert called
53
+ end
54
+
55
+ private
56
+
57
+ class MockSession
58
+ attr_reader :loops
59
+
60
+ def initialize
61
+ @loops = 0
62
+ end
63
+
64
+ def loop
65
+ while true
66
+ @loops += 1
67
+ break unless yield
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,53 @@
1
+ require 'common'
2
+
3
+ class ResponseTest < Net::SFTP::TestCase
4
+ def test_code_should_default_to_FX_OK
5
+ response = Net::SFTP::Response.new(mock("response"))
6
+ assert_equal Net::SFTP::Response::FX_OK, response.code
7
+ end
8
+
9
+ def test_brackets_should_symbolize_key
10
+ response = Net::SFTP::Response.new(mock("response"), :handle => "foo")
11
+ assert_equal "foo", response['handle']
12
+ end
13
+
14
+ def test_to_s_with_nil_message_should_show_default_message
15
+ response = Net::SFTP::Response.new(mock("response"), :code => 14)
16
+ assert_equal "no space on filesystem (14)", response.to_s
17
+ end
18
+
19
+ def test_to_s_with_empty_message_should_show_default_message
20
+ response = Net::SFTP::Response.new(mock("response"), :code => 14, :message => "")
21
+ assert_equal "no space on filesystem (14)", response.to_s
22
+ end
23
+
24
+ def test_to_s_with_default_message_should_show_default_message
25
+ response = Net::SFTP::Response.new(mock("response"), :code => 14, :message => "no space on filesystem")
26
+ assert_equal "no space on filesystem (14)", response.to_s
27
+ end
28
+
29
+ def test_to_s_with_explicit_message_should_show_explicit_message
30
+ response = Net::SFTP::Response.new(mock("response"), :code => 14, :message => "out of space")
31
+ assert_equal "out of space (no space on filesystem, 14)", response.to_s
32
+ end
33
+
34
+ def test_ok_should_be_true_when_code_is_FX_OK
35
+ response = Net::SFTP::Response.new(mock("response"))
36
+ assert_equal true, response.ok?
37
+ end
38
+
39
+ def test_ok_should_be_false_when_code_is_not_FX_OK
40
+ response = Net::SFTP::Response.new(mock("response"), :code => 14)
41
+ assert_equal false, response.ok?
42
+ end
43
+
44
+ def test_eof_should_be_true_when_code_is_FX_EOF
45
+ response = Net::SFTP::Response.new(mock("response"), :code => 1)
46
+ assert_equal true, response.eof?
47
+ end
48
+
49
+ def test_eof_should_be_false_when_code_is_not_FX_EOF
50
+ response = Net::SFTP::Response.new(mock("response"), :code => 14)
51
+ assert_equal false, response.eof?
52
+ end
53
+ end
@@ -0,0 +1,741 @@
1
+ require "common"
2
+
3
+ class SessionTest < Net::SFTP::TestCase
4
+ include Net::SFTP::Constants
5
+ include Net::SFTP::Constants::OpenFlags
6
+ include Net::SFTP::Constants::PacketTypes
7
+
8
+ (1..6).each do |version|
9
+ define_method("test_server_reporting_version_#{version}_should_cause_version_#{version}_to_be_used") do
10
+ expect_sftp_session :server_version => version
11
+ assert_scripted { sftp.connect! }
12
+ assert_equal version, sftp.protocol.version
13
+ end
14
+ end
15
+
16
+ def test_v1_open_read_only_that_succeeds_should_invoke_callback
17
+ expect_open("/path/to/file", "r", nil, :server_version => 1)
18
+ assert_successful_open("/path/to/file")
19
+ end
20
+
21
+ def test_v1_open_read_only_that_fails_should_invoke_callback
22
+ expect_open("/path/to/file", "r", nil, :server_version => 1, :fail => 2)
23
+
24
+ assert_command_with_callback(:open, "/path/to/file") do |response|
25
+ assert !response.ok?
26
+ assert_equal 2, response.code
27
+ end
28
+ end
29
+
30
+ def test_v1_open_write_only_that_succeeds_should_invoke_callback
31
+ expect_open("/path/to/file", "w", nil, :server_version => 1)
32
+ assert_successful_open("/path/to/file", "w")
33
+ end
34
+
35
+ def test_v1_open_read_write_that_succeeds_should_invoke_callback
36
+ expect_open("/path/to/file", "rw", nil, :server_version => 1)
37
+ assert_successful_open("/path/to/file", "r+")
38
+ end
39
+
40
+ def test_v1_open_append_that_succeeds_should_invoke_callback
41
+ expect_open("/path/to/file", "a", nil, :server_version => 1)
42
+ assert_successful_open("/path/to/file", "a")
43
+ end
44
+
45
+ def test_v1_open_with_permissions_should_specify_permissions
46
+ expect_open("/path/to/file", "r", 0765, :server_version => 1)
47
+ assert_successful_open("/path/to/file", "r", :permissions => 0765)
48
+ end
49
+
50
+ def test_v4_open_with_permissions_should_specify_permissions
51
+ expect_open("/path/to/file", "r", 0765, :server_version => 4)
52
+ assert_successful_open("/path/to/file", "r", :permissions => 0765)
53
+ end
54
+
55
+ def test_v5_open_read_only_shuld_invoke_callback
56
+ expect_open("/path/to/file", "r", 0765, :server_version => 5)
57
+ assert_successful_open("/path/to/file", "r", :permissions => 0765)
58
+ end
59
+
60
+ def test_v6_open_with_permissions_should_specify_permissions
61
+ expect_open("/path/to/file", "r", 0765, :server_version => 6)
62
+ assert_successful_open("/path/to/file", "r", :permissions => 0765)
63
+ end
64
+
65
+ def test_open_bang_should_block_and_return_handle
66
+ expect_open("/path/to/file", "r", nil)
67
+ handle = assert_synchronous_command(:open!, "/path/to/file", "r")
68
+ assert_equal "handle", handle
69
+ end
70
+
71
+ def test_open_bang_should_block_and_raise_exception_on_error
72
+ expect_open("/path/to/file", "r", nil, :fail => 5)
73
+ assert_raises(Net::SFTP::StatusException) do
74
+ assert_synchronous_command(:open!, "/path/to/file", "r")
75
+ end
76
+ end
77
+
78
+ def test_close_should_send_close_request_and_invoke_callback
79
+ expect_sftp_session do |channel|
80
+ channel.sends_packet(FXP_CLOSE, :long, 0, :string, "handle")
81
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
82
+ end
83
+
84
+ assert_command_with_callback(:close, "handle") { |r| assert r.ok? }
85
+ end
86
+
87
+ def test_close_bang_should_block_and_return_response
88
+ expect_sftp_session do |channel|
89
+ channel.sends_packet(FXP_CLOSE, :long, 0, :string, "handle")
90
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
91
+ end
92
+
93
+ response = assert_synchronous_command(:close!, "handle")
94
+ assert response.ok?
95
+ end
96
+
97
+ def test_read_should_send_read_request_and_invoke_callback
98
+ expect_sftp_session do |channel|
99
+ channel.sends_packet(FXP_READ, :long, 0, :string, "handle", :int64, 512123, :long, 1024)
100
+ channel.gets_packet(FXP_DATA, :long, 0, :string, "this is some data!")
101
+ end
102
+
103
+ assert_command_with_callback(:read, "handle", 512123, 1024) do |response|
104
+ assert response.ok?
105
+ assert_equal "this is some data!", response[:data]
106
+ end
107
+ end
108
+
109
+ def test_read_bang_should_block_and_return_data
110
+ expect_sftp_session do |channel|
111
+ channel.sends_packet(FXP_READ, :long, 0, :string, "handle", :int64, 512123, :long, 1024)
112
+ channel.gets_packet(FXP_DATA, :long, 0, :string, "this is some data!")
113
+ end
114
+
115
+ data = assert_synchronous_command(:read!, "handle", 512123, 1024)
116
+ assert_equal "this is some data!", data
117
+ end
118
+
119
+ def test_read_bang_should_block_and_return_nil_on_eof
120
+ expect_sftp_session do |channel|
121
+ channel.sends_packet(FXP_READ, :long, 0, :string, "handle", :int64, 512123, :long, 1024)
122
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 1)
123
+ end
124
+
125
+ data = assert_synchronous_command(:read!, "handle", 512123, 1024)
126
+ assert_nil data
127
+ end
128
+
129
+ def test_write_should_send_write_request_and_invoke_callback
130
+ expect_sftp_session do |channel|
131
+ channel.sends_packet(FXP_WRITE, :long, 0, :string, "handle", :int64, 512123, :string, "this is some data!")
132
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
133
+ end
134
+
135
+ assert_command_with_callback(:write, "handle", 512123, "this is some data!") do |response|
136
+ assert response.ok?
137
+ end
138
+ end
139
+
140
+ def test_write_bang_should_block_and_return_response
141
+ expect_sftp_session do |channel|
142
+ channel.sends_packet(FXP_WRITE, :long, 0, :string, "handle", :int64, 512123, :string, "this is some data!")
143
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
144
+ end
145
+
146
+ response = assert_synchronous_command(:write!, "handle", 512123, "this is some data!")
147
+ assert response.ok?
148
+ end
149
+
150
+ def test_v1_lstat_should_send_lstat_request_and_invoke_callback
151
+ expect_sftp_session :server_version => 1 do |channel|
152
+ channel.sends_packet(FXP_LSTAT, :long, 0, :string, "/path/to/file")
153
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
154
+ end
155
+
156
+ assert_command_with_callback(:lstat, "/path/to/file") do |response|
157
+ assert response.ok?
158
+ assert_equal 123456, response[:attrs].size
159
+ assert_equal 1, response[:attrs].uid
160
+ assert_equal 2, response[:attrs].gid
161
+ assert_equal 0765, response[:attrs].permissions
162
+ assert_equal 123456789, response[:attrs].atime
163
+ assert_equal 234567890, response[:attrs].mtime
164
+ end
165
+ end
166
+
167
+ def test_v4_lstat_should_send_default_flags_parameter
168
+ expect_sftp_session :server_version => 4 do |channel|
169
+ channel.sends_packet(FXP_LSTAT, :long, 0, :string, "/path/to/file", :long, 0x800001fd)
170
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
171
+ end
172
+
173
+ assert_command_with_callback(:lstat, "/path/to/file")
174
+ end
175
+
176
+ def test_v4_lstat_should_honor_flags_parameter
177
+ expect_sftp_session :server_version => 4 do |channel|
178
+ channel.sends_packet(FXP_LSTAT, :long, 0, :string, "/path/to/file", :long, 0x1)
179
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
180
+ end
181
+
182
+ assert_command_with_callback(:lstat, "/path/to/file", 0x1)
183
+ end
184
+
185
+ def test_lstat_bang_should_block_and_return_attrs
186
+ expect_sftp_session :server_version => 1 do |channel|
187
+ channel.sends_packet(FXP_LSTAT, :long, 0, :string, "/path/to/file")
188
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
189
+ end
190
+
191
+ attrs = assert_synchronous_command(:lstat!, "/path/to/file")
192
+
193
+ assert_equal 123456, attrs.size
194
+ assert_equal 1, attrs.uid
195
+ assert_equal 2, attrs.gid
196
+ assert_equal 0765, attrs.permissions
197
+ assert_equal 123456789, attrs.atime
198
+ assert_equal 234567890, attrs.mtime
199
+ end
200
+
201
+ def test_v1_fstat_should_send_fstat_request_and_invoke_callback
202
+ expect_sftp_session :server_version => 1 do |channel|
203
+ channel.sends_packet(FXP_FSTAT, :long, 0, :string, "handle")
204
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
205
+ end
206
+
207
+ assert_command_with_callback(:fstat, "handle") do |response|
208
+ assert response.ok?
209
+ assert_equal 123456, response[:attrs].size
210
+ assert_equal 1, response[:attrs].uid
211
+ assert_equal 2, response[:attrs].gid
212
+ assert_equal 0765, response[:attrs].permissions
213
+ assert_equal 123456789, response[:attrs].atime
214
+ assert_equal 234567890, response[:attrs].mtime
215
+ end
216
+ end
217
+
218
+ def test_v4_fstat_should_send_default_flags_parameter
219
+ expect_sftp_session :server_version => 4 do |channel|
220
+ channel.sends_packet(FXP_FSTAT, :long, 0, :string, "handle", :long, 0x800001fd)
221
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
222
+ end
223
+
224
+ assert_command_with_callback(:fstat, "handle")
225
+ end
226
+
227
+ def test_v4_fstat_should_honor_flags_parameter
228
+ expect_sftp_session :server_version => 4 do |channel|
229
+ channel.sends_packet(FXP_FSTAT, :long, 0, :string, "handle", :long, 0x1)
230
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
231
+ end
232
+
233
+ assert_command_with_callback(:fstat, "handle", 0x1)
234
+ end
235
+
236
+ def test_fstat_bang_should_block_and_return_attrs
237
+ expect_sftp_session :server_version => 1 do |channel|
238
+ channel.sends_packet(FXP_FSTAT, :long, 0, :string, "handle")
239
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
240
+ end
241
+
242
+ attrs = assert_synchronous_command(:fstat!, "handle")
243
+
244
+ assert_equal 123456, attrs.size
245
+ assert_equal 1, attrs.uid
246
+ assert_equal 2, attrs.gid
247
+ assert_equal 0765, attrs.permissions
248
+ assert_equal 123456789, attrs.atime
249
+ assert_equal 234567890, attrs.mtime
250
+ end
251
+
252
+ def test_v1_setstat_should_send_v1_attributes
253
+ expect_sftp_session :server_version => 1 do |channel|
254
+ channel.sends_packet(FXP_SETSTAT, :long, 0, :string, "/path/to/file", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
255
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
256
+ end
257
+
258
+ assert_command_with_callback(:setstat, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
259
+ end
260
+
261
+ def test_v4_setstat_should_send_v4_attributes
262
+ expect_sftp_session :server_version => 4 do |channel|
263
+ channel.sends_packet(FXP_SETSTAT, :long, 0, :string, "/path/to/file", :long, 0x2c, :byte, 1, :long, 0765, :int64, 1234567890, :int64, 2345678901)
264
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
265
+ end
266
+
267
+ assert_command_with_callback(:setstat, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
268
+ end
269
+
270
+ def test_v6_setstat_should_send_v6_attributes
271
+ expect_sftp_session :server_version => 6 do |channel|
272
+ channel.sends_packet(FXP_SETSTAT, :long, 0, :string, "/path/to/file", :long, 0x102c, :byte, 1, :long, 0765, :int64, 1234567890, :int64, 2345678901, :string, "text/plain")
273
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
274
+ end
275
+
276
+ assert_command_with_callback(:setstat, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901, :mime_type => "text/plain")
277
+ end
278
+
279
+ def test_setstat_bang_should_block_and_return_response
280
+ expect_sftp_session :server_version => 1 do |channel|
281
+ channel.sends_packet(FXP_SETSTAT, :long, 0, :string, "/path/to/file", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
282
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
283
+ end
284
+
285
+ response = assert_synchronous_command(:setstat!, "/path/to/file", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
286
+ assert response.ok?
287
+ end
288
+
289
+ def test_v1_fsetstat_should_send_v1_attributes
290
+ expect_sftp_session :server_version => 1 do |channel|
291
+ channel.sends_packet(FXP_FSETSTAT, :long, 0, :string, "handle", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
292
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
293
+ end
294
+
295
+ assert_command_with_callback(:fsetstat, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
296
+ end
297
+
298
+ def test_v4_fsetstat_should_send_v4_attributes
299
+ expect_sftp_session :server_version => 4 do |channel|
300
+ channel.sends_packet(FXP_FSETSTAT, :long, 0, :string, "handle", :long, 0x2c, :byte, 1, :long, 0765, :int64, 1234567890, :int64, 2345678901)
301
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
302
+ end
303
+
304
+ assert_command_with_callback(:fsetstat, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
305
+ end
306
+
307
+ def test_v6_fsetstat_should_send_v6_attributes
308
+ expect_sftp_session :server_version => 6 do |channel|
309
+ channel.sends_packet(FXP_FSETSTAT, :long, 0, :string, "handle", :long, 0x102c, :byte, 1, :long, 0765, :int64, 1234567890, :int64, 2345678901, :string, "text/plain")
310
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
311
+ end
312
+
313
+ assert_command_with_callback(:fsetstat, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901, :mime_type => "text/plain")
314
+ end
315
+
316
+ def test_fsetstat_bang_should_block_and_return_response
317
+ expect_sftp_session :server_version => 1 do |channel|
318
+ channel.sends_packet(FXP_FSETSTAT, :long, 0, :string, "handle", :long, 0xc, :long, 0765, :long, 1234567890, :long, 2345678901)
319
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
320
+ end
321
+
322
+ response = assert_synchronous_command(:fsetstat!, "handle", :permissions => 0765, :atime => 1234567890, :mtime => 2345678901)
323
+ assert response.ok?
324
+ end
325
+
326
+ def test_opendir_should_send_opendir_request_and_invoke_callback
327
+ expect_sftp_session do |channel|
328
+ channel.sends_packet(FXP_OPENDIR, :long, 0, :string, "/path/to/dir")
329
+ channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
330
+ end
331
+
332
+ assert_command_with_callback(:opendir, "/path/to/dir")
333
+ end
334
+
335
+ def test_opendir_bang_should_block_and_return_handle
336
+ expect_sftp_session do |channel|
337
+ channel.sends_packet(FXP_OPENDIR, :long, 0, :string, "/path/to/dir")
338
+ channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
339
+ end
340
+
341
+ handle = assert_synchronous_command(:opendir!, "/path/to/dir")
342
+ assert_equal "handle", handle
343
+ end
344
+
345
+ def test_readdir_should_send_readdir_request_and_invoke_callback
346
+ expect_sftp_session do |channel|
347
+ channel.sends_packet(FXP_READDIR, :long, 0, :string, "handle")
348
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 1)
349
+ end
350
+
351
+ assert_command_with_callback(:readdir, "handle") { |r| assert r.eof? }
352
+ end
353
+
354
+ def test_readdir_bang_should_block_and_return_names_array
355
+ expect_sftp_session :server_version => 1 do |channel|
356
+ channel.sends_packet(FXP_READDIR, :long, 0, :string, "handle")
357
+ channel.gets_packet(FXP_NAME, :long, 0, :long, 2,
358
+ :string, "first", :string, "longfirst", :long, 0x0,
359
+ :string, "next", :string, "longnext", :long, 0x0)
360
+ end
361
+
362
+ names = assert_synchronous_command(:readdir!, "handle")
363
+ assert_equal 2, names.length
364
+ assert_equal %w(first next), names.map { |n| n.name }
365
+ end
366
+
367
+ def test_remove_should_send_remove_packet
368
+ expect_sftp_session do |channel|
369
+ channel.sends_packet(FXP_REMOVE, :long, 0, :string, "/path/to/file")
370
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
371
+ end
372
+
373
+ assert_command_with_callback(:remove, "/path/to/file")
374
+ end
375
+
376
+ def test_remove_bang_should_block_and_return_response
377
+ expect_sftp_session do |channel|
378
+ channel.sends_packet(FXP_REMOVE, :long, 0, :string, "/path/to/file")
379
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
380
+ end
381
+
382
+ response = assert_synchronous_command(:remove!, "/path/to/file")
383
+ assert response.ok?
384
+ end
385
+
386
+ def test_mkdir_should_send_mkdir_packet
387
+ expect_sftp_session do |channel|
388
+ channel.sends_packet(FXP_MKDIR, :long, 0, :string, "/path/to/dir", :long, 0x4, :byte, 1, :long, 0765)
389
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
390
+ end
391
+
392
+ assert_command_with_callback(:mkdir, "/path/to/dir", :permissions => 0765)
393
+ end
394
+
395
+ def test_mkdir_bang_should_block_and_return_response
396
+ expect_sftp_session do |channel|
397
+ channel.sends_packet(FXP_MKDIR, :long, 0, :string, "/path/to/dir", :long, 0x4, :byte, 1, :long, 0765)
398
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
399
+ end
400
+
401
+ response = assert_synchronous_command(:mkdir!, "/path/to/dir", :permissions => 0765)
402
+ assert response.ok?
403
+ end
404
+
405
+ def test_rmdir_should_send_rmdir_packet
406
+ expect_sftp_session do |channel|
407
+ channel.sends_packet(FXP_RMDIR, :long, 0, :string, "/path/to/dir")
408
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
409
+ end
410
+
411
+ assert_command_with_callback(:rmdir, "/path/to/dir")
412
+ end
413
+
414
+ def test_rmdir_bang_should_block_and_return_response
415
+ expect_sftp_session do |channel|
416
+ channel.sends_packet(FXP_RMDIR, :long, 0, :string, "/path/to/dir")
417
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
418
+ end
419
+
420
+ response = assert_synchronous_command(:rmdir!, "/path/to/dir")
421
+ assert response.ok?
422
+ end
423
+
424
+ def test_realpath_should_send_realpath_packet
425
+ expect_sftp_session do |channel|
426
+ channel.sends_packet(FXP_REALPATH, :long, 0, :string, "/path/to/dir")
427
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
428
+ end
429
+
430
+ assert_command_with_callback(:realpath, "/path/to/dir")
431
+ end
432
+
433
+ def test_realpath_bang_should_block_and_return_names_item
434
+ expect_sftp_session do |channel|
435
+ channel.sends_packet(FXP_REALPATH, :long, 0, :string, "/path/to/dir")
436
+ channel.gets_packet(FXP_NAME, :long, 0, :long, 1, :string, "dir", :long, 0x0, :long, 2)
437
+ end
438
+
439
+ name = assert_synchronous_command(:realpath!, "/path/to/dir")
440
+ assert_equal "dir", name.name
441
+ end
442
+
443
+ def test_v1_stat_should_send_stat_request_and_invoke_callback
444
+ expect_sftp_session :server_version => 1 do |channel|
445
+ channel.sends_packet(FXP_STAT, :long, 0, :string, "/path/to/file")
446
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
447
+ end
448
+
449
+ assert_command_with_callback(:stat, "/path/to/file") do |response|
450
+ assert response.ok?
451
+ assert_equal 123456, response[:attrs].size
452
+ assert_equal 1, response[:attrs].uid
453
+ assert_equal 2, response[:attrs].gid
454
+ assert_equal 0765, response[:attrs].permissions
455
+ assert_equal 123456789, response[:attrs].atime
456
+ assert_equal 234567890, response[:attrs].mtime
457
+ end
458
+ end
459
+
460
+ def test_v4_stat_should_send_default_flags_parameter
461
+ expect_sftp_session :server_version => 4 do |channel|
462
+ channel.sends_packet(FXP_STAT, :long, 0, :string, "/path/to/file", :long, 0x800001fd)
463
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
464
+ end
465
+
466
+ assert_command_with_callback(:stat, "/path/to/file")
467
+ end
468
+
469
+ def test_v4_stat_should_honor_flags_parameter
470
+ expect_sftp_session :server_version => 4 do |channel|
471
+ channel.sends_packet(FXP_STAT, :long, 0, :string, "/path/to/file", :long, 0x1)
472
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
473
+ end
474
+
475
+ assert_command_with_callback(:stat, "/path/to/file", 0x1)
476
+ end
477
+
478
+ def test_stat_bang_should_block_and_return_attrs
479
+ expect_sftp_session :server_version => 1 do |channel|
480
+ channel.sends_packet(FXP_STAT, :long, 0, :string, "/path/to/file")
481
+ channel.gets_packet(FXP_ATTRS, :long, 0, :long, 0xF, :int64, 123456, :long, 1, :long, 2, :long, 0765, :long, 123456789, :long, 234567890)
482
+ end
483
+
484
+ attrs = assert_synchronous_command(:stat!, "/path/to/file")
485
+
486
+ assert_equal 123456, attrs.size
487
+ assert_equal 1, attrs.uid
488
+ assert_equal 2, attrs.gid
489
+ assert_equal 0765, attrs.permissions
490
+ assert_equal 123456789, attrs.atime
491
+ assert_equal 234567890, attrs.mtime
492
+ end
493
+
494
+ def test_v1_rename_should_be_unimplemented
495
+ assert_not_implemented 1, :rename, "from", "to"
496
+ end
497
+
498
+ def test_v2_rename_should_send_rename_packet
499
+ expect_sftp_session :server_version => 2 do |channel|
500
+ channel.sends_packet(FXP_RENAME, :long, 0, :string, "from", :string, "to")
501
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
502
+ end
503
+
504
+ assert_command_with_callback(:rename, "from", "to")
505
+ end
506
+
507
+ def test_v5_rename_should_send_rename_packet_and_default_flags
508
+ expect_sftp_session :server_version => 5 do |channel|
509
+ channel.sends_packet(FXP_RENAME, :long, 0, :string, "from", :string, "to", :long, 0)
510
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
511
+ end
512
+
513
+ assert_command_with_callback(:rename, "from", "to")
514
+ end
515
+
516
+ def test_v5_rename_should_send_rename_packet_and_honor_flags
517
+ expect_sftp_session :server_version => 5 do |channel|
518
+ channel.sends_packet(FXP_RENAME, :long, 0, :string, "from", :string, "to", :long, 1)
519
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
520
+ end
521
+
522
+ assert_command_with_callback(:rename, "from", "to", 1)
523
+ end
524
+
525
+ def test_rename_bang_should_block_and_return_response
526
+ expect_sftp_session :server_version => 2 do |channel|
527
+ channel.sends_packet(FXP_RENAME, :long, 0, :string, "from", :string, "to")
528
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
529
+ end
530
+
531
+ response = assert_synchronous_command(:rename!, "from", "to")
532
+ assert response.ok?
533
+ end
534
+
535
+ def test_v2_readlink_should_be_unimplemented
536
+ assert_not_implemented 2, :readlink, "/path/to/link"
537
+ end
538
+
539
+ def test_v3_readlink_should_send_readlink_packet
540
+ expect_sftp_session :server_version => 3 do |channel|
541
+ channel.sends_packet(FXP_READLINK, :long, 0, :string, "/path/to/link")
542
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 2)
543
+ end
544
+
545
+ assert_command_with_callback(:readlink, "/path/to/link")
546
+ end
547
+
548
+ def test_readlink_bang_should_block_and_return_name
549
+ expect_sftp_session :server_version => 3 do |channel|
550
+ channel.sends_packet(FXP_READLINK, :long, 0, :string, "/path/to/link")
551
+ channel.gets_packet(FXP_NAME, :long, 0, :long, 1, :string, "target", :string, "longtarget", :long, 0x0)
552
+ end
553
+
554
+ name = assert_synchronous_command(:readlink!, "/path/to/link")
555
+ assert_equal "target", name.name
556
+ end
557
+
558
+ def test_v2_symlink_should_be_unimplemented
559
+ assert_not_implemented 2, :symlink, "/path/to/source", "/path/to/link"
560
+ end
561
+
562
+ def test_v3_symlink_should_send_symlink_packet
563
+ expect_sftp_session :server_version => 3 do |channel|
564
+ channel.sends_packet(FXP_SYMLINK, :long, 0, :string, "/path/to/source", :string, "/path/to/link")
565
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
566
+ end
567
+
568
+ assert_command_with_callback(:symlink, "/path/to/source", "/path/to/link")
569
+ end
570
+
571
+ def test_v6_symlink_should_send_link_packet
572
+ expect_sftp_session :server_version => 6 do |channel|
573
+ channel.sends_packet(FXP_LINK, :long, 0, :string, "/path/to/link", :string, "/path/to/source", :bool, true)
574
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
575
+ end
576
+
577
+ assert_command_with_callback(:symlink, "/path/to/link", "/path/to/source")
578
+ end
579
+
580
+ def test_symlink_bang_should_block_and_return_response
581
+ expect_sftp_session :server_version => 3 do |channel|
582
+ channel.sends_packet(FXP_SYMLINK, :long, 0, :string, "/path/to/source", :string, "/path/to/link")
583
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
584
+ end
585
+
586
+ response = assert_synchronous_command(:symlink!, "/path/to/source", "/path/to/link")
587
+ assert response.ok?
588
+ end
589
+
590
+ def test_v5_link_should_be_unimplemented
591
+ assert_not_implemented 5, :link, "/path/to/source", "/path/to/link", true
592
+ end
593
+
594
+ def test_v6_link_should_send_link_packet
595
+ expect_sftp_session :server_version => 6 do |channel|
596
+ channel.sends_packet(FXP_LINK, :long, 0, :string, "/path/to/link", :string, "/path/to/source", :bool, true)
597
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
598
+ end
599
+
600
+ assert_command_with_callback(:link, "/path/to/link", "/path/to/source", true)
601
+ end
602
+
603
+ def test_link_bang_should_block_and_return_response
604
+ expect_sftp_session :server_version => 6 do |channel|
605
+ channel.sends_packet(FXP_LINK, :long, 0, :string, "/path/to/link", :string, "/path/to/source", :bool, true)
606
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
607
+ end
608
+
609
+ response = assert_synchronous_command(:link!, "/path/to/link", "/path/to/source", true)
610
+ assert response.ok?
611
+ end
612
+
613
+ def test_v5_block_should_be_unimplemented
614
+ assert_not_implemented 5, :block, "handle", 12345, 67890, 0xabcd
615
+ end
616
+
617
+ def test_v6_block_should_send_block_packet
618
+ expect_sftp_session :server_version => 6 do |channel|
619
+ channel.sends_packet(FXP_BLOCK, :long, 0, :string, "handle", :int64, 12345, :int64, 67890, :long, 0xabcd)
620
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
621
+ end
622
+
623
+ assert_command_with_callback(:block, "handle", 12345, 67890, 0xabcd)
624
+ end
625
+
626
+ def test_block_bang_should_block_and_return_response
627
+ expect_sftp_session :server_version => 6 do |channel|
628
+ channel.sends_packet(FXP_BLOCK, :long, 0, :string, "handle", :int64, 12345, :int64, 67890, :long, 0xabcd)
629
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
630
+ end
631
+
632
+ response = assert_synchronous_command(:block!, "handle", 12345, 67890, 0xabcd)
633
+ assert response.ok?
634
+ end
635
+
636
+ def test_v5_unblock_should_be_unimplemented
637
+ assert_not_implemented 5, :unblock, "handle", 12345, 67890
638
+ end
639
+
640
+ def test_v6_unblock_should_send_block_packet
641
+ expect_sftp_session :server_version => 6 do |channel|
642
+ channel.sends_packet(FXP_UNBLOCK, :long, 0, :string, "handle", :int64, 12345, :int64, 67890)
643
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
644
+ end
645
+
646
+ assert_command_with_callback(:unblock, "handle", 12345, 67890)
647
+ end
648
+
649
+ def test_unblock_bang_should_block_and_return_response
650
+ expect_sftp_session :server_version => 6 do |channel|
651
+ channel.sends_packet(FXP_UNBLOCK, :long, 0, :string, "handle", :int64, 12345, :int64, 67890)
652
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, 0)
653
+ end
654
+
655
+ response = assert_synchronous_command(:unblock!, "handle", 12345, 67890)
656
+ assert response.ok?
657
+ end
658
+
659
+ private
660
+
661
+ def assert_not_implemented(server_version, command, *args)
662
+ expect_sftp_session :server_version => 1
663
+ sftp.connect!
664
+ assert_raises(NotImplementedError) { sftp.send(command, *args) }
665
+ end
666
+
667
+ def assert_command_with_callback(command, *args)
668
+ called = false
669
+ assert_scripted_command do
670
+ sftp.send(command, *args) do |response|
671
+ called = true
672
+ yield response if block_given?
673
+ end
674
+ end
675
+ assert called, "expected callback to be invoked, but it wasn't"
676
+ end
677
+
678
+ def assert_synchronous_command(command, *args)
679
+ assert_scripted_command do
680
+ sequence = [:start]
681
+ result = sftp.send(command, *args) do |response|
682
+ sequence << :done
683
+ yield response if block_given?
684
+ end
685
+ sequence << :after
686
+ assert_equal [:start, :done, :after], sequence, "expected #{command} to be synchronous"
687
+ return result
688
+ end
689
+ end
690
+
691
+ def assert_successful_open(*args)
692
+ assert_command_with_callback(:open, *args) do |response|
693
+ assert response.ok?
694
+ assert_equal "handle", response[:handle]
695
+ end
696
+ end
697
+
698
+ def expect_open(path, mode, perms, options={})
699
+ version = options[:server_version] || 6
700
+
701
+ fail = options.delete(:fail)
702
+
703
+ attrs = [:long, perms ? 0x4 : 0]
704
+ attrs += [:byte, 1] if version >= 4
705
+ attrs += [:long, perms] if perms
706
+
707
+ expect_sftp_session(options) do |channel|
708
+ if version >= 5
709
+ flags, access = case mode
710
+ when "r" then
711
+ [FV5::OPEN_EXISTING, ACE::Mask::READ_DATA | ACE::Mask::READ_ATTRIBUTES]
712
+ when "w" then
713
+ [FV5::CREATE_TRUNCATE, ACE::Mask::WRITE_DATA | ACE::Mask::WRITE_ATTRIBUTES]
714
+ when "rw" then
715
+ [FV5::OPEN_OR_CREATE, ACE::Mask::READ_DATA | ACE::Mask::READ_ATTRIBUTES | ACE::Mask::WRITE_DATA | ACE::Mask::WRITE_ATTRIBUTES]
716
+ when "a" then
717
+ [FV5::OPEN_OR_CREATE | FV5::APPEND_DATA, ACE::Mask::WRITE_DATA | ACE::Mask::WRITE_ATTRIBUTES | ACE::Mask::APPEND_DATA]
718
+ else raise ArgumentError, "unsupported mode #{mode.inspect}"
719
+ end
720
+
721
+ channel.sends_packet(FXP_OPEN, :long, 0, :string, path, :long, access, :long, flags, *attrs)
722
+ else
723
+ flags = case mode
724
+ when "r" then FV1::READ
725
+ when "w" then FV1::WRITE | FV1::TRUNC | FV1::CREAT
726
+ when "rw" then FV1::WRITE | FV1::READ
727
+ when "a" then FV1::APPEND | FV1::WRITE | FV1::CREAT
728
+ else raise ArgumentError, "unsupported mode #{mode.inspect}"
729
+ end
730
+
731
+ channel.sends_packet(FXP_OPEN, :long, 0, :string, path, :long, flags, *attrs)
732
+ end
733
+
734
+ if fail
735
+ channel.gets_packet(FXP_STATUS, :long, 0, :long, fail)
736
+ else
737
+ channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
738
+ end
739
+ end
740
+ end
741
+ end