@@ -225,16 +225,16 @@ def test_download_directory_should_create_directory_and_files_locally
225
225
assert_equal "a" * 1234 , file . io . string
226
226
end
227
227
228
- def test_download_should_work_when_remote_closes_channel_without_eof
228
+ def test_download_should_work_when_remote_closes_channel_without_exit_status
229
229
file = prepare_file ( '/path/to/local.txt' , 'a' * 1234 )
230
230
231
231
story do |session |
232
232
channel = session . opens_channel
233
233
channel . sends_exec 'scp -f /path/to/remote.txt'
234
234
simple_download ( channel )
235
- # Remote closes without sending an eof
235
+ # Remote closes without sending an exit-status
236
236
channel . gets_close
237
- # We are polite and send an eof & close the channel
237
+ # We just send eof and close the channel
238
238
channel . sends_eof
239
239
channel . sends_close
240
240
end
@@ -243,6 +243,35 @@ def test_download_should_work_when_remote_closes_channel_without_eof
243
243
assert_equal 'a' * 1234 , file . io . string
244
244
end
245
245
246
+ def test_download_should_raise_error_when_remote_closes_channel_before_end
247
+ file = prepare_file ( '/path/to/local.txt' , 'a' * 1234 )
248
+
249
+ story do |session |
250
+ channel = session . opens_channel
251
+ channel . sends_exec 'scp -f /path/to/remote.txt'
252
+ channel . sends_ok
253
+ channel . gets_data "C%04o 1234 remote.txt\n " % 0666
254
+ channel . sends_ok
255
+ channel . gets_data 'a' * 500
256
+ # We should have received 1234 bytes and \0 but remote closed before the end
257
+ channel . gets_close
258
+ # We just send eof and close the channel
259
+ channel . sends_eof
260
+ channel . sends_close
261
+ end
262
+
263
+ error = nil
264
+ begin
265
+ assert_scripted { scp . download! ( '/path/to/remote.txt' , '/path/to/local.txt' ) }
266
+ rescue => e
267
+ error = e
268
+ end
269
+
270
+ assert_equal Net ::SCP ::Error , error . class
271
+ assert_equal 'SCP did not finish successfully (channel closed before end of transmission)' ,
272
+ error . message
273
+ end
274
+
246
275
private
247
276
248
277
def simple_download ( channel , mode = 0666 )
0 commit comments