net-sftp 2.0.5 → 3.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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data/.gitignore +5 -0
- data/.travis.yml +20 -0
- data/{CHANGELOG.rdoc → CHANGES.txt} +18 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +19 -0
- data/README.rdoc +23 -1
- data/Rakefile +44 -21
- data/lib/net/sftp/operations/dir.rb +3 -3
- data/lib/net/sftp/operations/download.rb +8 -7
- data/lib/net/sftp/operations/file.rb +30 -8
- data/lib/net/sftp/operations/upload.rb +14 -6
- data/lib/net/sftp/session.rb +9 -7
- data/lib/net/sftp/version.rb +63 -13
- data/lib/net/sftp.rb +12 -4
- data/net-sftp-public_cert.pem +20 -0
- data/net-sftp.gemspec +38 -24
- data.tar.gz.sig +0 -0
- metadata +110 -127
- metadata.gz.sig +0 -0
- data/test/common.rb +0 -172
- data/test/protocol/01/test_attributes.rb +0 -97
- data/test/protocol/01/test_base.rb +0 -210
- data/test/protocol/01/test_name.rb +0 -27
- data/test/protocol/02/test_base.rb +0 -26
- data/test/protocol/03/test_base.rb +0 -27
- data/test/protocol/04/test_attributes.rb +0 -148
- data/test/protocol/04/test_base.rb +0 -74
- data/test/protocol/04/test_name.rb +0 -53
- data/test/protocol/05/test_base.rb +0 -62
- data/test/protocol/06/test_attributes.rb +0 -124
- data/test/protocol/06/test_base.rb +0 -51
- data/test/protocol/test_base.rb +0 -42
- data/test/test_all.rb +0 -7
- data/test/test_dir.rb +0 -47
- data/test/test_download.rb +0 -252
- data/test/test_file.rb +0 -159
- data/test/test_file_factory.rb +0 -48
- data/test/test_packet.rb +0 -9
- data/test/test_protocol.rb +0 -17
- data/test/test_request.rb +0 -71
- data/test/test_response.rb +0 -53
- data/test/test_session.rb +0 -741
- data/test/test_upload.rb +0 -219
data/test/test_file_factory.rb
DELETED
@@ -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
|
data/test/test_protocol.rb
DELETED
@@ -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
|
data/test/test_response.rb
DELETED
@@ -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
|