net-sftp 2.1.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.github/workflows/ci.yml +35 -0
  4. data/.gitignore +6 -0
  5. data/CHANGES.txt +4 -0
  6. data/Gemfile +15 -0
  7. data/README.rdoc +7 -4
  8. data/Rakefile +24 -30
  9. data/lib/net/sftp/operations/dir.rb +3 -3
  10. data/lib/net/sftp/operations/download.rb +8 -7
  11. data/lib/net/sftp/operations/file.rb +32 -9
  12. data/lib/net/sftp/operations/upload.rb +3 -3
  13. data/lib/net/sftp/session.rb +7 -5
  14. data/lib/net/sftp/version.rb +63 -13
  15. data/lib/net/sftp.rb +12 -4
  16. data/net-sftp-public_cert.pem +20 -0
  17. data/net-sftp.gemspec +35 -93
  18. data.tar.gz.sig +0 -0
  19. metadata +53 -82
  20. metadata.gz.sig +0 -0
  21. data/gem-public_cert.pem +0 -20
  22. data/test/common.rb +0 -184
  23. data/test/protocol/01/test_attributes.rb +0 -97
  24. data/test/protocol/01/test_base.rb +0 -210
  25. data/test/protocol/01/test_name.rb +0 -27
  26. data/test/protocol/02/test_base.rb +0 -26
  27. data/test/protocol/03/test_base.rb +0 -27
  28. data/test/protocol/04/test_attributes.rb +0 -148
  29. data/test/protocol/04/test_base.rb +0 -74
  30. data/test/protocol/04/test_name.rb +0 -53
  31. data/test/protocol/05/test_base.rb +0 -62
  32. data/test/protocol/06/test_attributes.rb +0 -124
  33. data/test/protocol/06/test_base.rb +0 -51
  34. data/test/protocol/test_base.rb +0 -42
  35. data/test/test_all.rb +0 -7
  36. data/test/test_dir.rb +0 -47
  37. data/test/test_download.rb +0 -287
  38. data/test/test_file.rb +0 -159
  39. data/test/test_file_factory.rb +0 -48
  40. data/test/test_packet.rb +0 -9
  41. data/test/test_protocol.rb +0 -17
  42. data/test/test_request.rb +0 -71
  43. data/test/test_response.rb +0 -53
  44. data/test/test_session.rb +0 -741
  45. data/test/test_upload.rb +0 -233
data/test/test_file.rb DELETED
@@ -1,159 +0,0 @@
1
- require 'common'
2
-
3
- class FileOperationsTest < Net::SFTP::TestCase
4
- def setup
5
- @sftp = mock("sftp")
6
- @file = Net::SFTP::Operations::File.new(@sftp, "handle")
7
- @save_dollar_fslash, $/ = $/, "\n"
8
- @save_dollar_bslash, $\ = $\, nil
9
- end
10
-
11
- def teardown
12
- $/ = @save_dollar_fslash
13
- $\ = @save_dollar_bslash
14
- end
15
-
16
- def test_pos_assignment_should_set_position
17
- @file.pos = 15
18
- assert_equal 15, @file.pos
19
- end
20
-
21
- def test_pos_assignment_should_reset_eof
22
- @sftp.expects(:read!).with("handle", 0, 8192).returns(nil)
23
- assert !@file.eof?
24
- @file.read
25
- assert @file.eof?
26
- @file.pos = 0
27
- assert !@file.eof?
28
- end
29
-
30
- def test_close_should_close_handle_and_set_handle_to_nil
31
- assert_equal "handle", @file.handle
32
- @sftp.expects(:close!).with("handle")
33
- @file.close
34
- assert_nil @file.handle
35
- end
36
-
37
- def test_eof_should_be_false_if_at_eof_but_data_remains_in_buffer
38
- @sftp.expects(:read!).returns("hello world", nil)
39
- @file.read(1)
40
- assert !@file.eof?
41
- end
42
-
43
- def test_eof_should_be_true_if_at_eof_and_no_data_in_buffer
44
- @sftp.expects(:read!).times(2).returns("hello world", nil)
45
- @file.read
46
- assert @file.eof?
47
- end
48
-
49
- def test_read_without_argument_should_read_and_return_remainder_of_file_and_set_pos
50
- @sftp.expects(:read!).times(2).returns("hello world", nil)
51
- assert_equal "hello world", @file.read
52
- assert_equal 11, @file.pos
53
- end
54
-
55
- def test_read_with_argument_should_read_and_return_n_bytes_and_set_pos
56
- @sftp.expects(:read!).returns("hello world")
57
- assert_equal "hello", @file.read(5)
58
- assert_equal 5, @file.pos
59
- end
60
-
61
- def test_read_after_pos_assignment_should_read_from_specified_position
62
- @sftp.expects(:read!).with("handle", 5, 8192).returns("hello world")
63
- @file.pos = 5
64
- assert_equal "hello", @file.read(5)
65
- assert_equal 10, @file.pos
66
- end
67
-
68
- def test_gets_without_argument_should_read_until_first_dollar_fslash
69
- @sftp.expects(:read!).returns("hello world\ngoodbye world\n\nfarewell!\n")
70
- assert_equal "\n", $/
71
- assert_equal "hello world\n", @file.gets
72
- assert_equal 12, @file.pos
73
- end
74
-
75
- def test_gets_with_empty_argument_should_read_until_double_dollar_fslash
76
- @sftp.expects(:read!).returns("hello world\ngoodbye world\n\nfarewell!\n")
77
- assert_equal "\n", $/
78
- assert_equal "hello world\ngoodbye world\n\n", @file.gets("")
79
- assert_equal 27, @file.pos
80
- end
81
-
82
- def test_gets_with_argument_should_read_until_first_instance_of_argument
83
- @sftp.expects(:read!).returns("hello world\ngoodbye world\n\nfarewell!\n")
84
- assert_equal "hello w", @file.gets("w")
85
- assert_equal 7, @file.pos
86
- end
87
-
88
- def test_gets_when_no_such_delimiter_exists_in_stream_should_read_to_EOF
89
- @sftp.expects(:read!).times(2).returns("hello world\ngoodbye world\n\nfarewell!\n", nil)
90
- assert_equal "hello world\ngoodbye world\n\nfarewell!\n", @file.gets("X")
91
- assert @file.eof?
92
- end
93
-
94
- def test_gets_at_EOF_should_return_nil
95
- @sftp.expects(:read!).returns(nil)
96
- assert_nil @file.gets
97
- assert @file.eof?
98
- end
99
-
100
- def test_readline_should_raise_exception_on_EOF
101
- @sftp.expects(:read!).returns(nil)
102
- assert_raises(EOFError) { @file.readline }
103
- end
104
-
105
- def test_write_should_write_data_and_increment_pos_and_return_data_length
106
- @sftp.expects(:write!).with("handle", 0, "hello world")
107
- assert_equal 11, @file.write("hello world")
108
- assert_equal 11, @file.pos
109
- end
110
-
111
- def test_write_after_pos_assignment_should_write_at_position
112
- @sftp.expects(:write!).with("handle", 15, "hello world")
113
- @file.pos = 15
114
- assert_equal 11, @file.write("hello world")
115
- assert_equal 26, @file.pos
116
- end
117
-
118
- def test_print_with_no_arguments_should_write_nothing_if_dollar_bslash_is_nil
119
- assert_nil $\
120
- @sftp.expects(:write!).never
121
- @file.print
122
- end
123
-
124
- def test_print_with_no_arguments_should_write_dollar_bslash_if_dollar_bslash_is_not_nil
125
- $\ = "-"
126
- @sftp.expects(:write!).with("handle", 0, "-")
127
- @file.print
128
- end
129
-
130
- def test_print_with_arguments_should_write_all_arguments
131
- @sftp.expects(:write!).with("handle", 0, "hello")
132
- @sftp.expects(:write!).with("handle", 5, " ")
133
- @sftp.expects(:write!).with("handle", 6, "world")
134
- @file.print("hello", " ", "world")
135
- end
136
-
137
- def test_puts_should_recursively_puts_array_arguments
138
- 10.times do |i|
139
- @sftp.expects(:write!).with("handle", i*2, i.to_s)
140
- @sftp.expects(:write!).with("handle", i*2+1, "\n")
141
- end
142
- @file.puts 0, [1, [2, 3], 4, [5, [6, 7, 8]]], 9
143
- end
144
-
145
- def test_puts_should_not_append_newline_if_argument_ends_in_newline
146
- @sftp.expects(:write!).with("handle", 0, "a")
147
- @sftp.expects(:write!).with("handle", 1, "\n")
148
- @sftp.expects(:write!).with("handle", 2, "b\n")
149
- @sftp.expects(:write!).with("handle", 4, "c")
150
- @sftp.expects(:write!).with("handle", 5, "\n")
151
- @file.puts "a", "b\n", "c"
152
- end
153
-
154
- def test_stat_should_return_attributes_object_for_handle
155
- stat = stub("stat")
156
- @sftp.expects(:fstat!).with("handle").returns(stat)
157
- assert_equal stat, @file.stat
158
- end
159
- end
@@ -1,48 +0,0 @@
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
data/test/test_packet.rb DELETED
@@ -1,9 +0,0 @@
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
@@ -1,17 +0,0 @@
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
data/test/test_request.rb DELETED
@@ -1,71 +0,0 @@
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
@@ -1,53 +0,0 @@
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