net-sftp 1.1.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.
- data/CHANGELOG.rdoc +23 -0
- data/Manifest +55 -0
- data/README.rdoc +96 -0
- data/Rakefile +30 -0
- data/lib/net/sftp.rb +53 -38
- data/lib/net/sftp/constants.rb +187 -0
- data/lib/net/sftp/errors.rb +34 -20
- data/lib/net/sftp/operations/dir.rb +93 -0
- data/lib/net/sftp/operations/download.rb +364 -0
- data/lib/net/sftp/operations/file.rb +176 -0
- data/lib/net/sftp/operations/file_factory.rb +60 -0
- data/lib/net/sftp/operations/upload.rb +387 -0
- data/lib/net/sftp/packet.rb +21 -0
- data/lib/net/sftp/protocol.rb +32 -0
- data/lib/net/sftp/protocol/01/attributes.rb +265 -96
- data/lib/net/sftp/protocol/01/base.rb +268 -0
- data/lib/net/sftp/protocol/01/name.rb +43 -0
- data/lib/net/sftp/protocol/02/base.rb +31 -0
- data/lib/net/sftp/protocol/03/base.rb +35 -0
- data/lib/net/sftp/protocol/04/attributes.rb +120 -195
- data/lib/net/sftp/protocol/04/base.rb +94 -0
- data/lib/net/sftp/protocol/04/name.rb +67 -0
- data/lib/net/sftp/protocol/05/base.rb +66 -0
- data/lib/net/sftp/protocol/06/attributes.rb +107 -0
- data/lib/net/sftp/protocol/06/base.rb +63 -0
- data/lib/net/sftp/protocol/base.rb +50 -0
- data/lib/net/sftp/request.rb +91 -0
- data/lib/net/sftp/response.rb +76 -0
- data/lib/net/sftp/session.rb +914 -238
- data/lib/net/sftp/version.rb +14 -21
- data/net-sftp.gemspec +60 -0
- data/setup.rb +1331 -0
- data/test/common.rb +173 -0
- data/test/protocol/01/test_attributes.rb +97 -0
- data/test/protocol/01/test_base.rb +210 -0
- data/test/protocol/01/test_name.rb +27 -0
- data/test/protocol/02/test_base.rb +26 -0
- data/test/protocol/03/test_base.rb +27 -0
- data/test/protocol/04/test_attributes.rb +148 -0
- data/test/protocol/04/test_base.rb +74 -0
- data/test/protocol/04/test_name.rb +49 -0
- data/test/protocol/05/test_base.rb +62 -0
- data/test/protocol/06/test_attributes.rb +124 -0
- data/test/protocol/06/test_base.rb +51 -0
- data/test/protocol/test_base.rb +42 -0
- data/test/test_all.rb +3 -0
- data/test/test_dir.rb +47 -0
- data/test/test_download.rb +252 -0
- data/test/test_file.rb +159 -0
- data/test/test_file_factory.rb +48 -0
- data/test/test_packet.rb +9 -0
- data/test/test_protocol.rb +17 -0
- data/test/test_request.rb +71 -0
- data/test/test_response.rb +53 -0
- data/test/test_session.rb +741 -0
- data/test/test_upload.rb +219 -0
- metadata +59 -111
- data/doc/LICENSE-BSD +0 -27
- data/doc/LICENSE-GPL +0 -280
- data/doc/LICENSE-RUBY +0 -56
- data/doc/faq/faq.html +0 -298
- data/doc/faq/faq.rb +0 -154
- data/doc/faq/faq.yml +0 -183
- data/examples/asynchronous.rb +0 -57
- data/examples/get-put.rb +0 -45
- data/examples/sftp-open-uri.rb +0 -30
- data/examples/ssh-service.rb +0 -30
- data/examples/synchronous.rb +0 -131
- data/lib/net/sftp/operations/abstract.rb +0 -108
- data/lib/net/sftp/operations/close.rb +0 -31
- data/lib/net/sftp/operations/errors.rb +0 -76
- data/lib/net/sftp/operations/fsetstat.rb +0 -36
- data/lib/net/sftp/operations/fstat.rb +0 -32
- data/lib/net/sftp/operations/lstat.rb +0 -31
- data/lib/net/sftp/operations/mkdir.rb +0 -33
- data/lib/net/sftp/operations/open.rb +0 -32
- data/lib/net/sftp/operations/opendir.rb +0 -32
- data/lib/net/sftp/operations/read.rb +0 -88
- data/lib/net/sftp/operations/readdir.rb +0 -55
- data/lib/net/sftp/operations/realpath.rb +0 -37
- data/lib/net/sftp/operations/remove.rb +0 -31
- data/lib/net/sftp/operations/rename.rb +0 -32
- data/lib/net/sftp/operations/rmdir.rb +0 -31
- data/lib/net/sftp/operations/services.rb +0 -42
- data/lib/net/sftp/operations/setstat.rb +0 -33
- data/lib/net/sftp/operations/stat.rb +0 -31
- data/lib/net/sftp/operations/write.rb +0 -63
- data/lib/net/sftp/protocol/01/impl.rb +0 -251
- data/lib/net/sftp/protocol/01/packet-assistant.rb +0 -82
- data/lib/net/sftp/protocol/01/services.rb +0 -47
- data/lib/net/sftp/protocol/02/impl.rb +0 -39
- data/lib/net/sftp/protocol/02/packet-assistant.rb +0 -32
- data/lib/net/sftp/protocol/02/services.rb +0 -44
- data/lib/net/sftp/protocol/03/impl.rb +0 -42
- data/lib/net/sftp/protocol/03/packet-assistant.rb +0 -35
- data/lib/net/sftp/protocol/03/services.rb +0 -44
- data/lib/net/sftp/protocol/04/impl.rb +0 -86
- data/lib/net/sftp/protocol/04/packet-assistant.rb +0 -45
- data/lib/net/sftp/protocol/04/services.rb +0 -44
- data/lib/net/sftp/protocol/05/impl.rb +0 -90
- data/lib/net/sftp/protocol/05/packet-assistant.rb +0 -34
- data/lib/net/sftp/protocol/05/services.rb +0 -44
- data/lib/net/sftp/protocol/constants.rb +0 -60
- data/lib/net/sftp/protocol/driver.rb +0 -235
- data/lib/net/sftp/protocol/packet-assistant.rb +0 -84
- data/lib/net/sftp/protocol/services.rb +0 -55
- data/lib/uri/open-sftp.rb +0 -54
- data/lib/uri/sftp.rb +0 -42
- data/test/ALL-TESTS.rb +0 -23
- data/test/operations/tc_abstract.rb +0 -124
- data/test/operations/tc_close.rb +0 -40
- data/test/operations/tc_fsetstat.rb +0 -48
- data/test/operations/tc_fstat.rb +0 -40
- data/test/operations/tc_lstat.rb +0 -40
- data/test/operations/tc_mkdir.rb +0 -48
- data/test/operations/tc_open.rb +0 -42
- data/test/operations/tc_opendir.rb +0 -40
- data/test/operations/tc_read.rb +0 -103
- data/test/operations/tc_readdir.rb +0 -88
- data/test/operations/tc_realpath.rb +0 -54
- data/test/operations/tc_remove.rb +0 -40
- data/test/operations/tc_rmdir.rb +0 -40
- data/test/operations/tc_setstat.rb +0 -48
- data/test/operations/tc_stat.rb +0 -40
- data/test/operations/tc_write.rb +0 -91
- data/test/protocol/01/tc_attributes.rb +0 -138
- data/test/protocol/01/tc_impl.rb +0 -294
- data/test/protocol/01/tc_packet_assistant.rb +0 -81
- data/test/protocol/02/tc_impl.rb +0 -41
- data/test/protocol/02/tc_packet_assistant.rb +0 -31
- data/test/protocol/03/tc_impl.rb +0 -48
- data/test/protocol/03/tc_packet_assistant.rb +0 -34
- data/test/protocol/04/tc_attributes.rb +0 -174
- data/test/protocol/04/tc_impl.rb +0 -91
- data/test/protocol/04/tc_packet_assistant.rb +0 -38
- data/test/protocol/05/tc_impl.rb +0 -61
- data/test/protocol/05/tc_packet_assistant.rb +0 -32
- data/test/protocol/tc_driver.rb +0 -219
@@ -1,81 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/protocol/01/packet-assistant'
|
21
|
-
require 'flexmock'
|
22
|
-
require 'net/ssh/util/buffer'
|
23
|
-
|
24
|
-
class TC_01_PacketAssistant < Test::Unit::TestCase
|
25
|
-
|
26
|
-
class Buffers
|
27
|
-
def writer
|
28
|
-
Net::SSH::Util::WriterBuffer.new
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def setup
|
33
|
-
@driver = FlexMock.new
|
34
|
-
@driver.mock_handle( :next_request_id ) { 14 }
|
35
|
-
@packets = packet_assistant_class.new( Buffers.new, @driver )
|
36
|
-
end
|
37
|
-
|
38
|
-
def packet_assistant_class
|
39
|
-
Net::SFTP::Protocol::V_01::PacketAssistant
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.packet( name, args, expect )
|
43
|
-
define_method( "test_#{name}" ) do
|
44
|
-
id, packet = @packets.__send__( name, *[ nil, *args ] )
|
45
|
-
assert_equal 14, id
|
46
|
-
assert_equal "\0\0\0\16" + expect, packet
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
packet :open, [ "a path", 1, "attrs" ], "\0\0\0\6a path\0\0\0\1attrs"
|
51
|
-
|
52
|
-
packet :close, [ "handle" ], "\0\0\0\6handle"
|
53
|
-
|
54
|
-
packet :read, [ "handle", 0, 16 ], "\0\0\0\6handle\0\0\0\0\0\0\0\0\0\0\0\20"
|
55
|
-
|
56
|
-
packet :write, [ "handle", 0, "data" ],
|
57
|
-
"\0\0\0\6handle\0\0\0\0\0\0\0\0\0\0\0\4data"
|
58
|
-
|
59
|
-
packet :opendir, [ "a path" ], "\0\0\0\6a path"
|
60
|
-
|
61
|
-
packet :readdir, [ "handle" ], "\0\0\0\6handle"
|
62
|
-
|
63
|
-
packet :remove, [ "a path" ], "\0\0\0\6a path"
|
64
|
-
|
65
|
-
packet :stat, [ "a path" ], "\0\0\0\6a path"
|
66
|
-
|
67
|
-
packet :lstat, [ "a path" ], "\0\0\0\6a path"
|
68
|
-
|
69
|
-
packet :fstat, [ "handle" ], "\0\0\0\6handle"
|
70
|
-
|
71
|
-
packet :setstat, [ "a path", "attrs" ], "\0\0\0\6a pathattrs"
|
72
|
-
|
73
|
-
packet :fsetstat, [ "handle", "attrs" ], "\0\0\0\6handleattrs"
|
74
|
-
|
75
|
-
packet :mkdir, [ "a path", "attrs" ], "\0\0\0\6a pathattrs"
|
76
|
-
|
77
|
-
packet :rmdir, [ "a path" ], "\0\0\0\6a path"
|
78
|
-
|
79
|
-
packet :realpath, [ "a path" ], "\0\0\0\6a path"
|
80
|
-
|
81
|
-
end
|
data/test/protocol/02/tc_impl.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
-
|
20
|
-
require '01/tc_impl.rb'
|
21
|
-
require 'net/sftp/protocol/02/impl'
|
22
|
-
|
23
|
-
class TC_02_Impl < TC_01_Impl
|
24
|
-
|
25
|
-
def impl_class
|
26
|
-
Net::SFTP::Protocol::V_02::Impl
|
27
|
-
end
|
28
|
-
|
29
|
-
operation :rename, :rename_raw
|
30
|
-
|
31
|
-
def test_rename_flags
|
32
|
-
@assistant.mock_handle( :rename ) { |*a| [ a[0], a[1..-1] ] }
|
33
|
-
id = @impl.rename( 14, :a, :b, :c )
|
34
|
-
assert_equal 14, id
|
35
|
-
assert_equal 1, @assistant.mock_count( :rename )
|
36
|
-
assert_equal 1, @driver.mock_count( :send_data )
|
37
|
-
assert_equal [
|
38
|
-
[ Net::SFTP::Protocol::Constants::FXP_RENAME, [ :a, :b ]] ], @sent_data
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
-
|
20
|
-
require '01/tc_packet_assistant'
|
21
|
-
require 'net/sftp/protocol/02/packet-assistant'
|
22
|
-
|
23
|
-
class TC_02_PacketAssistant < TC_01_PacketAssistant
|
24
|
-
|
25
|
-
def packet_assistant_class
|
26
|
-
Net::SFTP::Protocol::V_02::PacketAssistant
|
27
|
-
end
|
28
|
-
|
29
|
-
packet :rename, [ "a path", "new path" ], "\0\0\0\6a path\0\0\0\10new path"
|
30
|
-
|
31
|
-
end
|
data/test/protocol/03/tc_impl.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
-
|
20
|
-
require '02/tc_impl.rb'
|
21
|
-
require 'net/sftp/protocol/03/impl'
|
22
|
-
|
23
|
-
class TC_03_Impl < TC_02_Impl
|
24
|
-
|
25
|
-
def impl_class
|
26
|
-
Net::SFTP::Protocol::V_03::Impl
|
27
|
-
end
|
28
|
-
|
29
|
-
operation :readlink
|
30
|
-
|
31
|
-
operation :symlink
|
32
|
-
|
33
|
-
def test_do_status_with_callback
|
34
|
-
buffer = Net::SSH::Util::ReaderBuffer.new( "\0\0\0\1\0\0\0\2" +
|
35
|
-
"\0\0\0\1a\0\0\0\1b" )
|
36
|
-
called = false
|
37
|
-
@impl.on_status do |d,i,c,a,b|
|
38
|
-
called = true
|
39
|
-
assert_equal 1, i
|
40
|
-
assert_equal 2, c
|
41
|
-
assert_equal "a", a
|
42
|
-
assert_equal "b", b
|
43
|
-
end
|
44
|
-
@impl.do_status nil, buffer
|
45
|
-
assert called
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
-
|
20
|
-
require '02/tc_packet_assistant'
|
21
|
-
require 'net/sftp/protocol/03/packet-assistant'
|
22
|
-
|
23
|
-
class TC_03_PacketAssistant < TC_02_PacketAssistant
|
24
|
-
|
25
|
-
def packet_assistant_class
|
26
|
-
Net::SFTP::Protocol::V_03::PacketAssistant
|
27
|
-
end
|
28
|
-
|
29
|
-
packet :readlink, [ "a path" ], "\0\0\0\6a path"
|
30
|
-
|
31
|
-
packet :symlink, [ "from path", "to path" ],
|
32
|
-
"\0\0\0\11from path\0\0\0\7to path"
|
33
|
-
|
34
|
-
end
|
@@ -1,174 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
|
19
|
-
require 'test/unit'
|
20
|
-
require 'net/sftp/protocol/04/attributes'
|
21
|
-
|
22
|
-
require 'net/ssh'
|
23
|
-
require 'net/ssh/util/buffer'
|
24
|
-
|
25
|
-
class TC_04_Attributes < Test::Unit::TestCase
|
26
|
-
|
27
|
-
class Buffers
|
28
|
-
def writer
|
29
|
-
Net::SSH::Util::WriterBuffer.new
|
30
|
-
end
|
31
|
-
def reader( text )
|
32
|
-
Net::SSH::Util::ReaderBuffer.new( text )
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def setup
|
37
|
-
@factory = Net::SFTP::Protocol::V_04::Attributes.init( Buffers.new )
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_empty
|
41
|
-
empty = @factory.empty
|
42
|
-
assert_equal 1, empty.type
|
43
|
-
assert_nil empty.size
|
44
|
-
assert_nil empty.owner
|
45
|
-
assert_nil empty.group
|
46
|
-
assert_nil empty.permissions
|
47
|
-
assert_nil empty.atime
|
48
|
-
assert_nil empty.atime_nseconds
|
49
|
-
assert_nil empty.ctime
|
50
|
-
assert_nil empty.ctime_nseconds
|
51
|
-
assert_nil empty.mtime
|
52
|
-
assert_nil empty.mtime_nseconds
|
53
|
-
assert_nil empty.acl
|
54
|
-
assert_nil empty.extended
|
55
|
-
assert_equal "\0\0\0\0\1", empty.to_s
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_from_buffer_empty
|
59
|
-
buffer = @factory.buffers.reader( "\0\0\0\0\2" )
|
60
|
-
attrs = @factory.from_buffer( buffer )
|
61
|
-
assert_equal 2, attrs.type
|
62
|
-
assert_nil attrs.size
|
63
|
-
assert_nil attrs.owner
|
64
|
-
assert_nil attrs.group
|
65
|
-
assert_nil attrs.permissions
|
66
|
-
assert_nil attrs.atime
|
67
|
-
assert_nil attrs.atime_nseconds
|
68
|
-
assert_nil attrs.ctime
|
69
|
-
assert_nil attrs.ctime_nseconds
|
70
|
-
assert_nil attrs.mtime
|
71
|
-
assert_nil attrs.mtime_nseconds
|
72
|
-
assert_nil attrs.acl
|
73
|
-
assert_nil attrs.extended
|
74
|
-
assert_equal "\0\0\0\0\2", attrs.to_s
|
75
|
-
end
|
76
|
-
|
77
|
-
ACL = Net::SFTP::Protocol::V_04::Attributes::ACL
|
78
|
-
ATTRIBUTES =
|
79
|
-
[ [ 0x00000001, "\1\2\3\4\5\6\7\10", :size, 0x0102030405060708 ],
|
80
|
-
[ 0x00000080, "\0\0\0\1a\0\0\0\1b", :owner, "a" ],
|
81
|
-
[ 0x00000080, "\0\0\0\1a\0\0\0\1b", :group, "b" ],
|
82
|
-
[ 0x00000004, "\21\22\23\24", :permissions, 0x11121314 ],
|
83
|
-
[ 0x00000138,
|
84
|
-
"\1\1\1\1\1\1\1\1\0\1\2\3" +
|
85
|
-
"\2\2\2\2\2\2\2\2\4\5\6\7" +
|
86
|
-
"\3\3\3\3\3\3\3\3\2\4\6\10", :atime_nseconds, 0x00010203 ],
|
87
|
-
[ 0x00000008, "\1\2\3\4\1\2\3\4", :atime, 0x0102030401020304 ],
|
88
|
-
[ 0x00000010, "\4\3\4\3\4\3\4\3", :ctime, 0x0403040304030403 ],
|
89
|
-
[ 0x00000020, "\4\3\2\1\4\3\2\1", :mtime, 0x0403020104030201 ],
|
90
|
-
[ 0x00000040, "\0\0\0\46\0\0\0\2\0\0\0\1\0\0\0\2\0\0\0\3\0\0\0\1a" +
|
91
|
-
"\0\0\0\4\0\0\0\5\0\0\0\6\0\0\0\1b", :acl,
|
92
|
-
[ ACL.new( 1, 2, 3, "a" ), ACL.new( 4, 5, 6, "b" ) ] ],
|
93
|
-
[ 0x80000000,
|
94
|
-
"\0\0\0\4" +
|
95
|
-
"\0\0\0\01a\0\0\0\01b" +
|
96
|
-
"\0\0\0\01c\0\0\0\01d" +
|
97
|
-
"\0\0\0\01e\0\0\0\01f" +
|
98
|
-
"\0\0\0\01g\0\0\0\01h",
|
99
|
-
:extended,
|
100
|
-
{ "a" => "b", "c" => "d", "e" => "f", "g" => "h" } ] ]
|
101
|
-
|
102
|
-
# find all possible combinations of the elements of ATTRIBUTES
|
103
|
-
# (i.e., 'n' choose k, for k in [1..ATTRIBUTES.length]).
|
104
|
-
def self.choose( from, k )
|
105
|
-
result = []
|
106
|
-
( from.length - k + 1 ).times do |i|
|
107
|
-
if i+1 < from.length && k > 1
|
108
|
-
choose( from[i+1..-1], k-1 ).each do |chosen|
|
109
|
-
result << [ from[i], *chosen ]
|
110
|
-
end
|
111
|
-
else
|
112
|
-
result << [ from[i] ]
|
113
|
-
end
|
114
|
-
end
|
115
|
-
result
|
116
|
-
end
|
117
|
-
|
118
|
-
method_id = 0
|
119
|
-
ATTRIBUTES.length.times do |k|
|
120
|
-
choose( ATTRIBUTES, k+1 ).each do |attrs|
|
121
|
-
vars = attrs.map { |a| a[2] }.join( "_" )
|
122
|
-
define_method( "test_attributes_#{vars}_%03d" % method_id ) do
|
123
|
-
flags = 0
|
124
|
-
buffer = "\1"
|
125
|
-
attrs.each do |a|
|
126
|
-
if ( flags & a[0] ) == 0
|
127
|
-
flags |= a[0]
|
128
|
-
buffer += a[1]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
buffer = [ flags, buffer ].pack( "NA*" )
|
132
|
-
input = @factory.buffers.reader( buffer )
|
133
|
-
obj = @factory.from_buffer( input )
|
134
|
-
assert_equal 1, obj.type, vars
|
135
|
-
flags = 0
|
136
|
-
attrs.each do |a|
|
137
|
-
if ( flags & a[0] ) == 0
|
138
|
-
assert_equal a[3], obj.__send__( a[2] ), a[2]
|
139
|
-
flags |= a[0]
|
140
|
-
end
|
141
|
-
end
|
142
|
-
assert_equal buffer, obj.to_s, vars
|
143
|
-
end
|
144
|
-
method_id += 1
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
require 'etc'
|
149
|
-
[
|
150
|
-
[ { :type => 3 }, :type, 3 ],
|
151
|
-
[ { :size => 1000 }, :size, 1000, :permissions ],
|
152
|
-
[ { :owner => ENV['USER'] }, :owner, ENV['USER'] ],
|
153
|
-
[ { :group => 'wheel' }, :group, 'wheel' ],
|
154
|
-
[ { :uid => Etc.getpwnam(ENV['USER']).uid }, :owner, ENV['USER'] ],
|
155
|
-
[ { :gid => Etc.getgrnam('wheel').gid }, :group, 'wheel' ],
|
156
|
-
[ { :permissions => 0600 }, :permissions, 0600 ],
|
157
|
-
[ { :atime => 1 }, :atime, 1 ],
|
158
|
-
[ { :atime_nseconds => 2 }, :atime_nseconds, 2 ],
|
159
|
-
[ { :ctime => 1 }, :ctime, 1 ],
|
160
|
-
[ { :ctime_nseconds => 2 }, :ctime_nseconds, 2 ],
|
161
|
-
[ { :mtime => 1 }, :mtime, 1 ],
|
162
|
-
[ { :mtime_nseconds => 2 }, :mtime_nseconds, 2 ],
|
163
|
-
[ { :acl => [ ACL.new(1,2,3,4), ACL.new(5,6,7,8) ] },
|
164
|
-
:acl, [ ACL.new(1,2,3,4), ACL.new(5,6,7,8) ] ],
|
165
|
-
[ { :extended => { "foo" => "bar" } }, :extended, { "foo" => "bar" } ]
|
166
|
-
].each do |fixture|
|
167
|
-
define_method( "test_from_hash_#{fixture[1]}" ) do
|
168
|
-
attrs = @factory.from_hash( fixture[0] )
|
169
|
-
assert_equal fixture[2], attrs.__send__( fixture[1] )
|
170
|
-
assert_nil attrs.__send__( fixture[3] || :size )
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
data/test/protocol/04/tc_impl.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
4
|
-
# All rights reserved.
|
5
|
-
#
|
6
|
-
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
-
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
-
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
-
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
-
# distribution for the texts of these licenses.
|
11
|
-
# -----------------------------------------------------------------------------
|
12
|
-
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
-
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
-
# =============================================================================
|
15
|
-
#++
|
16
|
-
|
17
|
-
$:.unshift "../../../lib"
|
18
|
-
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
-
|
20
|
-
require 'net/sftp/protocol/04/impl'
|
21
|
-
require '03/tc_impl'
|
22
|
-
|
23
|
-
class TC_04_Impl < TC_03_Impl
|
24
|
-
|
25
|
-
def impl_class
|
26
|
-
Net::SFTP::Protocol::V_04::Impl
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_stat_flags
|
30
|
-
@assistant.mock_handle( :stat ) { |*a| [ a[0], a[1..-1] ] }
|
31
|
-
id = @impl.stat( 14, :a, :b )
|
32
|
-
assert_equal 14, id
|
33
|
-
assert_equal 1, @assistant.mock_count( :stat )
|
34
|
-
assert_equal 1, @driver.mock_count( :send_data )
|
35
|
-
assert_equal [
|
36
|
-
[ Net::SFTP::Protocol::Constants::FXP_STAT, [ :a, :b ]] ], @sent_data
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_lstat_flags
|
40
|
-
@assistant.mock_handle( :lstat ) { |*a| [ a[0], a[1..-1] ] }
|
41
|
-
id = @impl.lstat( 14, :a, :b )
|
42
|
-
assert_equal 14, id
|
43
|
-
assert_equal 1, @assistant.mock_count( :lstat )
|
44
|
-
assert_equal 1, @driver.mock_count( :send_data )
|
45
|
-
assert_equal [
|
46
|
-
[ Net::SFTP::Protocol::Constants::FXP_LSTAT, [ :a, :b ]] ], @sent_data
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_fstat_flags
|
50
|
-
@assistant.mock_handle( :fstat ) { |*a| [ a[0], a[1..-1] ] }
|
51
|
-
id = @impl.fstat( 14, :a, :b )
|
52
|
-
assert_equal 14, id
|
53
|
-
assert_equal 1, @assistant.mock_count( :fstat )
|
54
|
-
assert_equal 1, @driver.mock_count( :send_data )
|
55
|
-
assert_equal [
|
56
|
-
[ Net::SFTP::Protocol::Constants::FXP_FSTAT, [ :a, :b ]] ], @sent_data
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_rename_flags
|
60
|
-
@assistant.mock_handle( :rename ) { |*a| [ a[0], a[1..-1] ] }
|
61
|
-
id = @impl.rename( 14, :a, :b, :c )
|
62
|
-
assert_equal 14, id
|
63
|
-
assert_equal 1, @assistant.mock_count( :rename )
|
64
|
-
assert_equal 1, @driver.mock_count( :send_data )
|
65
|
-
assert_equal [
|
66
|
-
[ Net::SFTP::Protocol::Constants::FXP_RENAME, [ :a, :b, :c ]] ],
|
67
|
-
@sent_data
|
68
|
-
end
|
69
|
-
|
70
|
-
# overrides the v1 implementation of the test
|
71
|
-
def test_do_name_with_callback
|
72
|
-
buffer = Net::SSH::Util::ReaderBuffer.new( "\0\0\0\1\0\0\0\2" +
|
73
|
-
"\0\0\0\1a\0\0\0\0" +
|
74
|
-
"\0\0\0\1c\0\0\0\0" )
|
75
|
-
called = false
|
76
|
-
@impl.on_name do |d,i,names|
|
77
|
-
called = true
|
78
|
-
assert_equal 1, i
|
79
|
-
assert_equal 2, names.length
|
80
|
-
assert_equal "a", names.first.filename
|
81
|
-
assert_nil names.first.longname
|
82
|
-
assert_equal 0, names.first.attributes
|
83
|
-
assert_equal "c", names.last.filename
|
84
|
-
assert_nil names.last.longname
|
85
|
-
assert_equal 0, names.last.attributes
|
86
|
-
end
|
87
|
-
@impl.do_name nil, buffer
|
88
|
-
assert called
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|