net-sftp 2.1.2 → 3.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 +2 -0
  3. data/.gitignore +5 -0
  4. data/.travis.yml +20 -0
  5. data/CHANGES.txt +4 -0
  6. data/Gemfile +15 -0
  7. data/README.rdoc +4 -1
  8. data/Rakefile +24 -30
  9. data/lib/net/sftp/operations/dir.rb +3 -3
  10. data/lib/net/sftp/operations/download.rb +7 -6
  11. data/lib/net/sftp/operations/file.rb +30 -7
  12. data/lib/net/sftp/operations/upload.rb +1 -1
  13. data/lib/net/sftp/session.rb +6 -4
  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
metadata CHANGED
@@ -1,107 +1,103 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-sftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
5
- prerelease:
4
+ version: 3.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jamis Buck
9
8
  - Delano Mandelbaum
9
+ - Miklós Fazekas
10
10
  autorequire:
11
- bindir: bin
11
+ bindir: exe
12
12
  cert_chain:
13
- - !binary |-
14
- LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUROakNDQWg2Z0F3SUJB
15
- Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREJCTVE4d0RRWURWUVFEREFaa1pX
16
- eGgKYm04eEdUQVhCZ29Ka2lhSmsvSXNaQUVaRmdsemIyeDFkR2x2ZFhNeEV6
17
- QVJCZ29Ka2lhSmsvSXNaQUVaRmdOagpiMjB3SGhjTk1UTXdNakEyTVRFMU56
18
- UTFXaGNOTVRRd01qQTJNVEUxTnpRMVdqQkJNUTh3RFFZRFZRUUREQVprClpX
19
- eGhibTh4R1RBWEJnb0praWFKay9Jc1pBRVpGZ2x6YjJ4MWRHbHZkWE14RXpB
20
- UkJnb0praWFKay9Jc1pBRVoKRmdOamIyMHdnZ0VpTUEwR0NTcUdTSWIzRFFF
21
- QkFRVUFBNElCRHdBd2dnRUtBb0lCQVFEZzFoTXRsMFhzTXVVSwpBS1RnWVd2
22
- M2dqajd2dUVzRTJFalQrdnlCZzgvTHBxVlZ3WnppaWFlYkpUOUlaaVErc0NG
23
- cWJpYWtqMGI1M3BJCmhnMXlPYUJFbUg2L1cwTDdyd3pxYVJWOXNXMWVKczlK
24
- eEZZUUNuZDY3elVuemo4bm5SbE9qRytoaElHK1ZzaWoKbnBzR2J0MjhwZWZ1
25
- TlpKak81cTJjbEFsZlNuaUlJSGZJc1U3L1N0RVl1NkZVR09qbndyeVowcjV5
26
- SmxyOVJyRQpHcytxMERXOFFuWjlVcEFmdURGUVp1SXFlS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Mps=
33
+ -----END CERTIFICATE-----
34
+ date: 2020-04-27 00:00:00.000000000 Z
42
35
  dependencies:
43
36
  - !ruby/object:Gem::Dependency
44
37
  name: net-ssh
45
38
  requirement: !ruby/object:Gem::Requirement
46
- none: false
47
39
  requirements:
48
- - - ! '>='
40
+ - - ">="
49
41
  - !ruby/object:Gem::Version
50
- version: 2.6.5
42
+ version: 5.0.0
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: 7.0.0
51
46
  type: :runtime
52
47
  prerelease: false
53
48
  version_requirements: !ruby/object:Gem::Requirement
54
- none: false
55
49
  requirements:
56
- - - ! '>='
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 5.0.0
53
+ - - "<"
57
54
  - !ruby/object:Gem::Version
58
- version: 2.6.5
55
+ version: 7.0.0
59
56
  - !ruby/object:Gem::Dependency
60
- name: test-unit
57
+ name: minitest
61
58
  requirement: !ruby/object:Gem::Requirement
62
- none: false
63
59
  requirements:
64
- - - ! '>='
60
+ - - ">="
65
61
  - !ruby/object:Gem::Version
66
- version: '0'
62
+ version: '5'
67
63
  type: :development
68
64
  prerelease: false
69
65
  version_requirements: !ruby/object:Gem::Requirement
70
- none: false
71
66
  requirements:
72
- - - ! '>='
67
+ - - ">="
73
68
  - !ruby/object:Gem::Version
74
- version: '0'
69
+ version: '5'
75
70
  - !ruby/object:Gem::Dependency
76
71
  name: mocha
77
72
  requirement: !ruby/object:Gem::Requirement
78
- none: false
79
73
  requirements:
80
- - - ! '>='
74
+ - - ">="
81
75
  - !ruby/object:Gem::Version
82
76
  version: '0'
83
77
  type: :development
84
78
  prerelease: false
85
79
  version_requirements: !ruby/object:Gem::Requirement
86
- none: false
87
80
  requirements:
88
- - - ! '>='
81
+ - - ">="
89
82
  - !ruby/object:Gem::Version
90
83
  version: '0'
91
84
  description: A pure Ruby implementation of the SFTP client protocol
92
- email: net-ssh@solutious.com
85
+ email:
86
+ - net-ssh@solutious.com
93
87
  executables: []
94
88
  extensions: []
95
89
  extra_rdoc_files:
96
90
  - LICENSE.txt
97
91
  - README.rdoc
98
92
  files:
93
+ - ".gitignore"
94
+ - ".travis.yml"
99
95
  - CHANGES.txt
96
+ - Gemfile
100
97
  - LICENSE.txt
101
98
  - Manifest
102
99
  - README.rdoc
103
100
  - Rakefile
104
- - gem-public_cert.pem
105
101
  - lib/net/sftp.rb
106
102
  - lib/net/sftp/constants.rb
107
103
  - lib/net/sftp/errors.rb
@@ -128,55 +124,30 @@ files:
128
124
  - lib/net/sftp/response.rb
129
125
  - lib/net/sftp/session.rb
130
126
  - lib/net/sftp/version.rb
127
+ - net-sftp-public_cert.pem
131
128
  - net-sftp.gemspec
132
129
  - setup.rb
133
- - test/common.rb
134
- - test/protocol/01/test_attributes.rb
135
- - test/protocol/01/test_base.rb
136
- - test/protocol/01/test_name.rb
137
- - test/protocol/02/test_base.rb
138
- - test/protocol/03/test_base.rb
139
- - test/protocol/04/test_attributes.rb
140
- - test/protocol/04/test_base.rb
141
- - test/protocol/04/test_name.rb
142
- - test/protocol/05/test_base.rb
143
- - test/protocol/06/test_attributes.rb
144
- - test/protocol/06/test_base.rb
145
- - test/protocol/test_base.rb
146
- - test/test_all.rb
147
- - test/test_dir.rb
148
- - test/test_download.rb
149
- - test/test_file.rb
150
- - test/test_file_factory.rb
151
- - test/test_packet.rb
152
- - test/test_protocol.rb
153
- - test/test_request.rb
154
- - test/test_response.rb
155
- - test/test_session.rb
156
- - test/test_upload.rb
157
130
  homepage: https://github.com/net-ssh/net-sftp
158
131
  licenses:
159
132
  - MIT
133
+ metadata: {}
160
134
  post_install_message:
161
135
  rdoc_options: []
162
136
  require_paths:
163
137
  - lib
164
138
  required_ruby_version: !ruby/object:Gem::Requirement
165
- none: false
166
139
  requirements:
167
- - - ! '>='
140
+ - - ">="
168
141
  - !ruby/object:Gem::Version
169
142
  version: '0'
170
143
  required_rubygems_version: !ruby/object:Gem::Requirement
171
- none: false
172
144
  requirements:
173
- - - ! '>='
145
+ - - ">="
174
146
  - !ruby/object:Gem::Version
175
147
  version: '0'
176
148
  requirements: []
177
- rubyforge_project: net-sftp
178
- rubygems_version: 1.8.25
149
+ rubygems_version: 3.0.3
179
150
  signing_key:
180
151
  specification_version: 3
181
- summary: A pure Ruby implementation of the SFTP client protocol
152
+ summary: A pure Ruby implementation of the SFTP client protocol.
182
153
  test_files: []
metadata.gz.sig CHANGED
Binary file
data/gem-public_cert.pem DELETED
@@ -1,20 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZkZWxh
3
- bm8xGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgoJkiaJk/IsZAEZFgNj
4
- b20wHhcNMTMwMjA2MTE1NzQ1WhcNMTQwMjA2MTE1NzQ1WjBBMQ8wDQYDVQQDDAZk
5
- ZWxhbm8xGTAXBgoJkiaJk/IsZAEZFglzb2x1dGlvdXMxEzARBgoJkiaJk/IsZAEZ
6
- FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDg1hMtl0XsMuUK
7
- AKTgYWv3gjj7vuEsE2EjT+vyBg8/LpqVVwZziiaebJT9IZiQ+sCFqbiakj0b53pI
8
- hg1yOaBEmH6/W0L7rwzqaRV9sW1eJs9JxFYQCnd67zUnzj8nnRlOjG+hhIG+Vsij
9
- npsGbt28pefuNZJjO5q2clAlfSniIIHfIsU7/StEYu6FUGOjnwryZ0r5yJlr9RrE
10
- Gs+q0DW8QnZ9UpAfuDFQZuIqeKQFFLE7nMmCGaA+0BN1nLl3fVHNbLHq7Avk8+Z+
11
- ZuuvkdscbHlO/l+3xCNQ5nUnHwq0ADAbMLOlmiYYzqXoWLjmeI6me/clktJCfN2R
12
- oZG3UQvvAgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFMSJOEtHzE4l0azv
13
- M0JK0kKNToK1MAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEAtOdE73qx
14
- OH2ydi9oT2hS5f9G0y1Z70Tlwh+VGExyfxzVE9XwC+iPpJxNraiHYgF/9/oky7ZZ
15
- R9q0/tJneuhAenZdiQkX7oi4O3v9wRS6YHoWBxMPFKVRLNTzvVJsbmfpCAlp5/5g
16
- ps4wQFy5mibElGVlOobf/ghqZ25HS9J6kd0/C/ry0AUtTogsL7TxGwT4kbCx63ub
17
- 3vywEEhsJUzfd97GCABmtQfRTldX/j7F1z/5wd8p+hfdox1iibds9ZtfaZA3KzKn
18
- kchWN9B6zg9r1XMQ8BM2Jz0XoPanPe354+lWwjpkRKbFow/ZbQHcCLCq24+N6b6g
19
- dgKfNDzwiDpqCA==
20
- -----END CERTIFICATE-----
data/test/common.rb DELETED
@@ -1,184 +0,0 @@
1
- require 'test/unit'
2
- require 'mocha/setup'
3
- require 'stringio'
4
-
5
- begin
6
- require 'net/ssh'
7
- require 'net/ssh/version'
8
- raise LoadError, "wrong version" unless Net::SSH::Version::STRING >= '1.99.0'
9
- rescue LoadError
10
- begin
11
- gem 'net-ssh', ">= 2.0.0"
12
- require 'net/ssh'
13
- rescue LoadError => e
14
- abort "could not load net/ssh v2 (#{e.inspect})"
15
- end
16
- end
17
-
18
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
19
- require 'net/sftp'
20
- require 'net/sftp/constants'
21
- require 'net/ssh/test'
22
-
23
- class Net::SFTP::TestCase < Test::Unit::TestCase
24
- include Net::SFTP::Constants::PacketTypes
25
- include Net::SSH::Test
26
-
27
- def default_test
28
- # do nothing, this is just hacky-hack to work around Test::Unit's
29
- # insistence that all TestCase subclasses have at least one test
30
- # method defined.
31
- end
32
-
33
- protected
34
-
35
- def raw(*args)
36
- Net::SSH::Buffer.from(*args).to_s
37
- end
38
-
39
- def sftp(options={})
40
- @sftp ||= Net::SFTP::Session.new(connection(options))
41
- end
42
-
43
- def expect_sftp_session(opts={})
44
- story do |session|
45
- channel = session.opens_channel
46
- channel.sends_subsystem("sftp")
47
- channel.sends_packet(FXP_INIT, :long, opts[:client_version] || Net::SFTP::Session::HIGHEST_PROTOCOL_VERSION_SUPPORTED)
48
- channel.gets_packet(FXP_VERSION, :long, opts[:server_version] || Net::SFTP::Session::HIGHEST_PROTOCOL_VERSION_SUPPORTED)
49
- yield channel if block_given?
50
- end
51
- end
52
-
53
- def assert_scripted_command
54
- assert_scripted do
55
- sftp.connect!
56
- yield
57
- sftp.loop
58
- end
59
- end
60
-
61
- def assert_progress_reported_open(expect={})
62
- assert_progress_reported(:open, expect)
63
- end
64
-
65
- def assert_progress_reported_put(offset, data, expect={})
66
- assert_equal offset, current_event[3] if offset
67
- assert_equal data, current_event[4] if data
68
- assert_progress_reported(:put, expect)
69
- end
70
-
71
- def assert_progress_reported_get(offset, data, expect={})
72
- assert_equal offset, current_event[3] if offset
73
- if data.is_a?(Fixnum)
74
- assert_equal data, current_event[4].length
75
- elsif data
76
- assert_equal data, current_event[4]
77
- end
78
- assert_progress_reported(:get, expect)
79
- end
80
-
81
- def assert_progress_reported_close(expect={})
82
- assert_progress_reported(:close, expect)
83
- end
84
-
85
- def assert_progress_reported_mkdir(dir)
86
- assert_equal dir, current_event[2]
87
- assert_progress_reported(:mkdir)
88
- end
89
-
90
- def assert_progress_reported_finish
91
- assert_progress_reported(:finish)
92
- end
93
-
94
- def assert_progress_reported(event, expect={})
95
- assert_equal event, current_event[0]
96
- expect.each do |key, value|
97
- assert_equal value, current_event[2].send(key)
98
- end
99
- next_event!
100
- end
101
-
102
- def assert_no_more_reported_events
103
- assert @progress.empty?, "expected #{@progress.empty?} to be empty"
104
- end
105
-
106
- def prepare_progress!
107
- @progress = []
108
- end
109
-
110
- def record_progress(event)
111
- @progress << event
112
- end
113
-
114
- def current_event
115
- @progress.first
116
- end
117
-
118
- def next_event!
119
- @progress.shift
120
- end
121
- end
122
-
123
- class Net::SSH::Test::Channel
124
- def gets_packet(type, *args)
125
- gets_data(sftp_packet(type, *args))
126
- end
127
-
128
- def gets_packet_in_two(fragment_len, type, *args)
129
- fragment_len ||= 0
130
- whole_packet = sftp_packet(type, *args)
131
-
132
- if 0 < fragment_len && fragment_len < whole_packet.length
133
- gets_data(whole_packet[0, whole_packet.length - fragment_len])
134
- gets_data(whole_packet[-fragment_len..-1])
135
- else
136
- gets_data(whole_packet)
137
- end
138
- end
139
-
140
- def sends_packet(type, *args)
141
- sends_data(sftp_packet(type, *args))
142
- end
143
-
144
- private
145
-
146
- def sftp_packet(type, *args)
147
- data = Net::SSH::Buffer.from(*args)
148
- Net::SSH::Buffer.from(:long, data.length+1, :byte, type, :raw, data).to_s
149
- end
150
- end
151
-
152
- class ProgressHandler
153
- def initialize(progress_ref)
154
- @progress = progress_ref
155
- end
156
-
157
- def on_open(*args)
158
- @progress << [:open, *args]
159
- end
160
-
161
- def on_put(*args)
162
- @progress << [:put, *args]
163
- end
164
-
165
- def on_close(*args)
166
- @progress << [:close, *args]
167
- end
168
-
169
- def on_finish(*args)
170
- @progress << [:finish, *args]
171
- end
172
- end
173
-
174
- # "prime the pump", so to speak: predefine the modules we need so we can
175
- # define the test classes in a more elegant short-hand.
176
-
177
- module Protocol
178
- module V01; end
179
- module V02; end
180
- module V03; end
181
- module V04; end
182
- module V05; end
183
- module V06; end
184
- end
@@ -1,97 +0,0 @@
1
- require 'common'
2
-
3
- module Etc; end
4
-
5
- class Protocol::V01::TestAttributes < Net::SFTP::TestCase
6
- def test_from_buffer_should_correctly_parse_buffer_and_return_attribute_object
7
- attributes = attributes_factory.from_buffer(full_buffer)
8
-
9
- assert_equal 1234567890, attributes.size
10
- assert_equal 100, attributes.uid
11
- assert_equal 200, attributes.gid
12
- assert_equal 0755, attributes.permissions
13
- assert_equal 1234567890, attributes.atime
14
- assert_equal 2345678901, attributes.mtime
15
- assert_equal "second", attributes.extended["first"]
16
- end
17
-
18
- def test_from_buffer_should_correctly_parse_buffer_with_attribute_subset_and_return_attribute_object
19
- buffer = Net::SSH::Buffer.from(:long, 0x4, :long, 0755)
20
-
21
- attributes = attributes_factory.from_buffer(buffer)
22
-
23
- assert_equal 0755, attributes.permissions
24
-
25
- assert_nil attributes.size
26
- assert_nil attributes.uid
27
- assert_nil attributes.gid
28
- assert_nil attributes.atime
29
- assert_nil attributes.mtime
30
- assert_nil attributes.extended
31
- end
32
-
33
- def test_attributes_to_s_should_build_binary_representation
34
- attributes = attributes_factory.new(
35
- :size => 1234567890,
36
- :uid => 100, :gid => 200,
37
- :permissions => 0755,
38
- :atime => 1234567890, :mtime => 2345678901,
39
- :extended => { "first" => "second" })
40
-
41
- assert_equal full_buffer.to_s, attributes.to_s
42
- end
43
-
44
- def test_attributes_to_s_should_build_binary_representation_when_subset_is_present
45
- attributes = attributes_factory.new(:permissions => 0755)
46
- assert_equal Net::SSH::Buffer.from(:long, 0x4, :long, 0755).to_s, attributes.to_s
47
- end
48
-
49
- def test_attributes_to_s_with_owner_and_group_should_translate_to_uid_and_gid
50
- attributes = attributes_factory.new(:owner => "jamis", :group => "sftp")
51
- attributes.expects(:require).with("etc").times(2)
52
- Etc.expects(:getpwnam).with("jamis").returns(mock('user', :uid => 100))
53
- Etc.expects(:getgrnam).with("sftp").returns(mock('group', :gid => 200))
54
- assert_equal Net::SSH::Buffer.from(:long, 0x2, :long, 100, :long, 200).to_s, attributes.to_s
55
- end
56
-
57
- def test_owner_should_translate_from_uid
58
- attributes = attributes_factory.new(:uid => 100)
59
- attributes.expects(:require).with("etc")
60
- Etc.expects(:getpwuid).with(100).returns(mock('user', :name => "jamis"))
61
- assert_equal "jamis", attributes.owner
62
- end
63
-
64
- def test_group_should_translate_from_gid
65
- attributes = attributes_factory.new(:gid => 200)
66
- attributes.expects(:require).with("etc")
67
- Etc.expects(:getgrgid).with(200).returns(mock('group', :name => "sftp"))
68
- assert_equal "sftp", attributes.group
69
- end
70
-
71
- def test_type_should_infer_type_from_permissions
72
- assert_equal af::T_SOCKET, af.new(:permissions => 0140755).type
73
- assert_equal af::T_SYMLINK, af.new(:permissions => 0120755).type
74
- assert_equal af::T_REGULAR, af.new(:permissions => 0100755).type
75
- assert_equal af::T_BLOCK_DEVICE, af.new(:permissions => 060755).type
76
- assert_equal af::T_DIRECTORY, af.new(:permissions => 040755).type
77
- assert_equal af::T_CHAR_DEVICE, af.new(:permissions => 020755).type
78
- assert_equal af::T_FIFO, af.new(:permissions => 010755).type
79
- assert_equal af::T_UNKNOWN, af.new(:permissions => 0755).type
80
- assert_equal af::T_UNKNOWN, af.new.type
81
- end
82
-
83
- private
84
-
85
- def full_buffer
86
- Net::SSH::Buffer.from(:long, 0x8000000f,
87
- :int64, 1234567890, :long, 100, :long, 200,
88
- :long, 0755, :long, 1234567890, :long, 2345678901,
89
- :long, 1, :string, "first", :string, "second")
90
- end
91
-
92
- def attributes_factory
93
- Net::SFTP::Protocol::V01::Attributes
94
- end
95
-
96
- alias af attributes_factory
97
- end