net-scp 1.2.1 → 2.0.0

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.
@@ -1,60 +0,0 @@
1
- require 'common'
2
-
3
- class TestSCP < Net::SCP::TestCase
4
- def test_start_without_block_should_return_scp_instance
5
- ssh = stub('session', :logger => nil)
6
- Net::SSH.expects(:start).
7
- with("remote.host", "username", :password => "foo").
8
- returns(ssh)
9
-
10
- ssh.expects(:close).never
11
- scp = Net::SCP.start("remote.host", "username", :password => "foo")
12
- assert_instance_of Net::SCP, scp
13
- assert_equal ssh, scp.session
14
- end
15
-
16
- def test_start_with_block_should_yield_scp_and_close_ssh_session
17
- ssh = stub('session', :logger => nil)
18
- Net::SSH.expects(:start).
19
- with("remote.host", "username", :password => "foo").
20
- returns(ssh)
21
-
22
- ssh.expects(:loop)
23
- ssh.expects(:close)
24
-
25
- yielded = false
26
- Net::SCP.start("remote.host", "username", :password => "foo") do |scp|
27
- yielded = true
28
- assert_instance_of Net::SCP, scp
29
- assert_equal ssh, scp.session
30
- end
31
-
32
- assert yielded
33
- end
34
-
35
- def test_self_upload_should_instatiate_scp_and_invoke_synchronous_upload
36
- scp = stub('scp')
37
- scp.expects(:upload!).with("/path/to/local", "/path/to/remote", :recursive => true)
38
-
39
- Net::SCP.expects(:start).
40
- with("remote.host", "username", :password => "foo").
41
- yields(scp)
42
-
43
- Net::SCP.upload!("remote.host", "username", "/path/to/local", "/path/to/remote",
44
- :ssh => { :password => "foo" }, :recursive => true)
45
- end
46
-
47
- def test_self_download_should_instatiate_scp_and_invoke_synchronous_download
48
- scp = stub('scp')
49
- scp.expects(:download!).with("/path/to/remote", "/path/to/local", :recursive => true).returns(:result)
50
-
51
- Net::SCP.expects(:start).
52
- with("remote.host", "username", :password => "foo").
53
- yields(scp)
54
-
55
- result = Net::SCP.download!("remote.host", "username", "/path/to/remote", "/path/to/local",
56
- :ssh => { :password => "foo" }, :recursive => true)
57
-
58
- assert_equal :result, result
59
- end
60
- end
@@ -1,269 +0,0 @@
1
- require 'common'
2
-
3
- class TestUpload < Net::SCP::TestCase
4
- def test_upload_file_should_transfer_file
5
- prepare_file("/path/to/local.txt", "a" * 1234)
6
-
7
- expect_scp_session "-t /path/to/remote.txt" do |channel|
8
- channel.gets_ok
9
- channel.sends_data "C0666 1234 local.txt\n"
10
- channel.gets_ok
11
- channel.sends_data "a" * 1234
12
- channel.sends_ok
13
- channel.gets_ok
14
- end
15
-
16
- assert_scripted { scp.upload!("/path/to/local.txt", "/path/to/remote.txt") }
17
- end
18
-
19
- def test_upload_file_with_spaces_in_name_should_escape_remote_file_name
20
- prepare_file("/path/to/local file.txt", "")
21
-
22
- expect_scp_session "-t /path/to/remote\\ file.txt" do |channel|
23
- channel.gets_ok
24
- channel.sends_data "C0666 0 local file.txt\n"
25
- channel.gets_ok
26
- channel.sends_ok
27
- channel.gets_ok
28
- end
29
-
30
- assert_scripted { scp.upload!("/path/to/local file.txt", "/path/to/remote file.txt") }
31
- end
32
-
33
- def test_upload_file_with_metacharacters_in_name_should_escape_remote_file_name
34
- prepare_file("/path/to/local/#{awful_file_name}", "")
35
-
36
- expect_scp_session "-t /path/to/remote/#{escaped_file_name}" do |channel|
37
- channel.gets_ok
38
- channel.sends_data "C0666 0 #{awful_file_name}\n"
39
- channel.gets_ok
40
- channel.sends_ok
41
- channel.gets_ok
42
- end
43
-
44
- assert_scripted { scp.upload!("/path/to/local/#{awful_file_name}", "/path/to/remote/#{awful_file_name}") }
45
- end
46
-
47
- def test_upload_file_with_preserve_should_send_times
48
- prepare_file("/path/to/local.txt", "a" * 1234, 0666, Time.at(1234567890, 123456), Time.at(1234543210, 345678))
49
-
50
- expect_scp_session "-t -p /path/to/remote.txt" do |channel|
51
- channel.gets_ok
52
- channel.sends_data "T1234567890 123456 1234543210 345678\n"
53
- channel.gets_ok
54
- channel.sends_data "C0666 1234 local.txt\n"
55
- channel.gets_ok
56
- channel.sends_data "a" * 1234
57
- channel.sends_ok
58
- channel.gets_ok
59
- end
60
-
61
- assert_scripted { scp.upload!("/path/to/local.txt", "/path/to/remote.txt", :preserve => true) }
62
- end
63
-
64
- def test_upload_file_with_progress_callback_should_invoke_callback
65
- prepare_file("/path/to/local.txt", "a" * 3000 + "b" * 3000 + "c" * 3000 + "d" * 3000)
66
-
67
- expect_scp_session "-t /path/to/remote.txt" do |channel|
68
- channel.gets_ok
69
- channel.sends_data "C0666 12000 local.txt\n"
70
- channel.gets_ok
71
- channel.sends_data "a" * 3000
72
- channel.sends_data "b" * 3000
73
- channel.sends_data "c" * 3000
74
- channel.sends_data "d" * 3000
75
- channel.sends_ok
76
- channel.gets_ok
77
- end
78
-
79
- calls = []
80
- progress = Proc.new do |ch, name, sent, total|
81
- calls << [name, sent, total]
82
- end
83
-
84
- assert_scripted do
85
- scp.upload!("/path/to/local.txt", "/path/to/remote.txt", :chunk_size => 3000, &progress)
86
- end
87
-
88
- assert_equal ["/path/to/local.txt", 0, 12000], calls.shift
89
- assert_equal ["/path/to/local.txt", 3000, 12000], calls.shift
90
- assert_equal ["/path/to/local.txt", 6000, 12000], calls.shift
91
- assert_equal ["/path/to/local.txt", 9000, 12000], calls.shift
92
- assert_equal ["/path/to/local.txt", 12000, 12000], calls.shift
93
- assert calls.empty?
94
- end
95
-
96
- def test_upload_io_with_recursive_should_ignore_recursive
97
- expect_scp_session "-t -r /path/to/remote.txt" do |channel|
98
- channel.gets_ok
99
- channel.sends_data "C0640 1234 remote.txt\n"
100
- channel.gets_ok
101
- channel.sends_data "a" * 1234
102
- channel.sends_ok
103
- channel.gets_ok
104
- end
105
-
106
- io = StringIO.new("a" * 1234)
107
- assert_scripted { scp.upload!(io, "/path/to/remote.txt", :recursive => true) }
108
- end
109
-
110
- def test_upload_io_with_preserve_should_ignore_preserve
111
- expect_scp_session "-t -p /path/to/remote.txt" do |channel|
112
- channel.gets_ok
113
- channel.sends_data "C0640 1234 remote.txt\n"
114
- channel.gets_ok
115
- channel.sends_data "a" * 1234
116
- channel.sends_ok
117
- channel.gets_ok
118
- end
119
-
120
- io = StringIO.new("a" * 1234)
121
- assert_scripted { scp.upload!(io, "/path/to/remote.txt", :preserve => true) }
122
- end
123
-
124
- def test_upload_io_should_transfer_data
125
- expect_scp_session "-t /path/to/remote.txt" do |channel|
126
- channel.gets_ok
127
- channel.sends_data "C0640 1234 remote.txt\n"
128
- channel.gets_ok
129
- channel.sends_data "a" * 1234
130
- channel.sends_ok
131
- channel.gets_ok
132
- end
133
-
134
- io = StringIO.new("a" * 1234)
135
- assert_scripted { scp.upload!(io, "/path/to/remote.txt") }
136
- end
137
-
138
- def test_upload_io_with_mode_should_honor_mode_as_permissions
139
- expect_scp_session "-t /path/to/remote.txt" do |channel|
140
- channel.gets_ok
141
- channel.sends_data "C0666 1234 remote.txt\n"
142
- channel.gets_ok
143
- channel.sends_data "a" * 1234
144
- channel.sends_ok
145
- channel.gets_ok
146
- end
147
-
148
- io = StringIO.new("a" * 1234)
149
- assert_scripted { scp.upload!(io, "/path/to/remote.txt", :mode => 0666) }
150
- end
151
-
152
- def test_upload_directory_without_recursive_should_error
153
- prepare_directory("/path/to/local")
154
-
155
- expect_scp_session("-t /path/to/remote") do |channel|
156
- channel.gets_ok
157
- end
158
-
159
- assert_raises(Net::SCP::Error) { scp.upload!("/path/to/local", "/path/to/remote") }
160
- end
161
-
162
- def test_upload_empty_directory_should_create_directory_and_finish
163
- prepare_directory("/path/to/local")
164
-
165
- expect_scp_session("-t -r /path/to/remote") do |channel|
166
- channel.gets_ok
167
- channel.sends_data "D0777 0 local\n"
168
- channel.gets_ok
169
- channel.sends_data "E\n"
170
- channel.gets_ok
171
- end
172
-
173
- assert_scripted { scp.upload!("/path/to/local", "/path/to/remote", :recursive => true) }
174
- end
175
-
176
- def test_upload_directory_should_recursively_create_and_upload_items
177
- prepare_directory("/path/to/local") do |d|
178
- d.file "hello.txt", "hello world\n"
179
- d.directory "others" do |d2|
180
- d2.file "data.dat", "abcdefghijklmnopqrstuvwxyz"
181
- end
182
- d.file "zoo.doc", "going to the zoo\n"
183
- end
184
-
185
- expect_scp_session("-t -r /path/to/remote") do |channel|
186
- channel.gets_ok
187
- channel.sends_data "D0777 0 local\n"
188
- channel.gets_ok
189
- channel.sends_data "C0666 12 hello.txt\n"
190
- channel.gets_ok
191
- channel.sends_data "hello world\n"
192
- channel.sends_ok
193
- channel.gets_ok
194
- channel.sends_data "D0777 0 others\n"
195
- channel.gets_ok
196
- channel.sends_data "C0666 26 data.dat\n"
197
- channel.gets_ok
198
- channel.sends_data "abcdefghijklmnopqrstuvwxyz"
199
- channel.sends_ok
200
- channel.gets_ok
201
- channel.sends_data "E\n"
202
- channel.gets_ok
203
- channel.sends_data "C0666 17 zoo.doc\n"
204
- channel.gets_ok
205
- channel.sends_data "going to the zoo\n"
206
- channel.sends_ok
207
- channel.gets_ok
208
- channel.sends_data "E\n"
209
- channel.gets_ok
210
- end
211
-
212
- assert_scripted { scp.upload!("/path/to/local", "/path/to/remote", :recursive => true) }
213
- end
214
-
215
- def test_upload_directory_with_preserve_should_send_times_for_all_items
216
- prepare_directory("/path/to/local", 0755, Time.at(17171717, 191919), Time.at(18181818, 101010)) do |d|
217
- d.file "hello.txt", "hello world\n", 0640, Time.at(12345, 67890), Time.at(234567, 890)
218
- d.directory "others", 0770, Time.at(112233, 4455), Time.at(22334455, 667788) do |d2|
219
- d2.file "data.dat", "abcdefghijklmnopqrstuvwxyz", 0600, Time.at(13579135, 13131), Time.at(7654321, 654321)
220
- end
221
- d.file "zoo.doc", "going to the zoo\n", 0444, Time.at(12121212, 131313), Time.at(23232323, 242424)
222
- end
223
-
224
- expect_scp_session("-t -r -p /path/to/remote") do |channel|
225
- channel.gets_ok
226
- channel.sends_data "T17171717 191919 18181818 101010\n"
227
- channel.gets_ok
228
- channel.sends_data "D0755 0 local\n"
229
- channel.gets_ok
230
- channel.sends_data "T12345 67890 234567 890\n"
231
- channel.gets_ok
232
- channel.sends_data "C0640 12 hello.txt\n"
233
- channel.gets_ok
234
- channel.sends_data "hello world\n"
235
- channel.sends_ok
236
- channel.gets_ok
237
- channel.sends_data "T112233 4455 22334455 667788\n"
238
- channel.gets_ok
239
- channel.sends_data "D0770 0 others\n"
240
- channel.gets_ok
241
- channel.sends_data "T13579135 13131 7654321 654321\n"
242
- channel.gets_ok
243
- channel.sends_data "C0600 26 data.dat\n"
244
- channel.gets_ok
245
- channel.sends_data "abcdefghijklmnopqrstuvwxyz"
246
- channel.sends_ok
247
- channel.gets_ok
248
- channel.sends_data "E\n"
249
- channel.gets_ok
250
- channel.sends_data "T12121212 131313 23232323 242424\n"
251
- channel.gets_ok
252
- channel.sends_data "C0444 17 zoo.doc\n"
253
- channel.gets_ok
254
- channel.sends_data "going to the zoo\n"
255
- channel.sends_ok
256
- channel.gets_ok
257
- channel.sends_data "E\n"
258
- channel.gets_ok
259
- end
260
-
261
- assert_scripted { scp.upload!("/path/to/local", "/path/to/remote", :preserve => true, :recursive => true) }
262
- end
263
-
264
- def test_upload_should_not_block
265
- prepare_file("/path/to/local.txt", "data")
266
- story { |s| s.opens_channel(false) }
267
- assert_scripted { scp.upload("/path/to/local.txt", "/path/to/remote.txt") }
268
- end
269
- end