ftpd 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Changelog.md +15 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +57 -48
- data/README.md +8 -1
- data/VERSION +1 -1
- data/examples/example.rb +12 -0
- data/features/example/step_definitions/example_server.rb +2 -0
- data/features/ftp_server/eprt.feature +1 -0
- data/features/ftp_server/epsv.feature +1 -0
- data/features/ftp_server/get_ipv6.feature +3 -0
- data/features/ftp_server/pasv.feature +10 -3
- data/features/ftp_server/step_definitions/logging.rb +2 -0
- data/features/ftp_server/step_definitions/test_server.rb +6 -0
- data/features/step_definitions/append.rb +2 -0
- data/features/step_definitions/client.rb +3 -0
- data/features/step_definitions/client_and_server_files.rb +2 -0
- data/features/step_definitions/client_files.rb +2 -0
- data/features/step_definitions/command.rb +2 -0
- data/features/step_definitions/connect.rb +2 -0
- data/features/step_definitions/delete.rb +2 -0
- data/features/step_definitions/directory_navigation.rb +2 -0
- data/features/step_definitions/error_replies.rb +2 -0
- data/features/step_definitions/features.rb +2 -0
- data/features/step_definitions/file_structure.rb +2 -0
- data/features/step_definitions/generic_send.rb +2 -0
- data/features/step_definitions/get.rb +2 -0
- data/features/step_definitions/help.rb +2 -0
- data/features/step_definitions/invalid_commands.rb +2 -0
- data/features/step_definitions/ipv6.rb +11 -0
- data/features/step_definitions/line_endings.rb +2 -0
- data/features/step_definitions/list.rb +2 -0
- data/features/step_definitions/login.rb +2 -0
- data/features/step_definitions/mkdir.rb +2 -0
- data/features/step_definitions/mode.rb +2 -0
- data/features/step_definitions/mtime.rb +2 -0
- data/features/step_definitions/noop.rb +2 -0
- data/features/step_definitions/options.rb +2 -0
- data/features/step_definitions/passive.rb +7 -0
- data/features/step_definitions/pending.rb +2 -0
- data/features/step_definitions/port.rb +2 -0
- data/features/step_definitions/put.rb +2 -0
- data/features/step_definitions/quit.rb +2 -0
- data/features/step_definitions/rename.rb +2 -0
- data/features/step_definitions/rmdir.rb +2 -0
- data/features/step_definitions/server_files.rb +2 -0
- data/features/step_definitions/server_title.rb +2 -0
- data/features/step_definitions/size.rb +2 -0
- data/features/step_definitions/status.rb +2 -0
- data/features/step_definitions/success_replies.rb +2 -0
- data/features/step_definitions/system.rb +5 -0
- data/features/step_definitions/timing.rb +2 -0
- data/features/step_definitions/type.rb +2 -0
- data/features/support/env.rb +2 -0
- data/features/support/example_server.rb +3 -1
- data/features/support/test_client.rb +27 -19
- data/features/support/test_file_templates.rb +2 -0
- data/features/support/test_server.rb +31 -20
- data/features/support/test_server_files.rb +2 -0
- data/ftpd.gemspec +17 -11
- data/lib/ftpd.rb +2 -0
- data/lib/ftpd/auth_levels.rb +2 -0
- data/lib/ftpd/cmd_abor.rb +2 -0
- data/lib/ftpd/cmd_allo.rb +2 -0
- data/lib/ftpd/cmd_appe.rb +2 -0
- data/lib/ftpd/cmd_auth.rb +2 -0
- data/lib/ftpd/cmd_cdup.rb +2 -0
- data/lib/ftpd/cmd_cwd.rb +2 -0
- data/lib/ftpd/cmd_dele.rb +2 -0
- data/lib/ftpd/cmd_eprt.rb +2 -0
- data/lib/ftpd/cmd_epsv.rb +4 -2
- data/lib/ftpd/cmd_feat.rb +2 -0
- data/lib/ftpd/cmd_help.rb +2 -0
- data/lib/ftpd/cmd_list.rb +2 -0
- data/lib/ftpd/cmd_login.rb +2 -0
- data/lib/ftpd/cmd_mdtm.rb +2 -0
- data/lib/ftpd/cmd_mkd.rb +2 -0
- data/lib/ftpd/cmd_mode.rb +2 -0
- data/lib/ftpd/cmd_nlst.rb +2 -0
- data/lib/ftpd/cmd_noop.rb +2 -0
- data/lib/ftpd/cmd_opts.rb +2 -0
- data/lib/ftpd/cmd_pasv.rb +5 -3
- data/lib/ftpd/cmd_pbsz.rb +2 -0
- data/lib/ftpd/cmd_port.rb +2 -0
- data/lib/ftpd/cmd_prot.rb +2 -0
- data/lib/ftpd/cmd_pwd.rb +2 -0
- data/lib/ftpd/cmd_quit.rb +2 -0
- data/lib/ftpd/cmd_rein.rb +2 -0
- data/lib/ftpd/cmd_rename.rb +2 -0
- data/lib/ftpd/cmd_rest.rb +2 -0
- data/lib/ftpd/cmd_retr.rb +2 -0
- data/lib/ftpd/cmd_rmd.rb +2 -0
- data/lib/ftpd/cmd_site.rb +2 -0
- data/lib/ftpd/cmd_size.rb +2 -0
- data/lib/ftpd/cmd_smnt.rb +2 -0
- data/lib/ftpd/cmd_stat.rb +2 -0
- data/lib/ftpd/cmd_stor.rb +2 -0
- data/lib/ftpd/cmd_stou.rb +2 -0
- data/lib/ftpd/cmd_stru.rb +2 -0
- data/lib/ftpd/cmd_syst.rb +2 -0
- data/lib/ftpd/cmd_type.rb +2 -0
- data/lib/ftpd/command_handler.rb +3 -0
- data/lib/ftpd/command_handler_factory.rb +2 -0
- data/lib/ftpd/command_handlers.rb +2 -0
- data/lib/ftpd/command_loop.rb +2 -0
- data/lib/ftpd/command_sequence_checker.rb +2 -0
- data/lib/ftpd/config.rb +2 -0
- data/lib/ftpd/connection_throttle.rb +2 -0
- data/lib/ftpd/connection_tracker.rb +2 -0
- data/lib/ftpd/data_connection_helper.rb +2 -0
- data/lib/ftpd/data_server_factory.rb +44 -0
- data/lib/ftpd/data_server_factory/random_ephemeral_port.rb +26 -0
- data/lib/ftpd/data_server_factory/specific_port_range.rb +37 -0
- data/lib/ftpd/disk_file_system.rb +2 -0
- data/lib/ftpd/error.rb +2 -0
- data/lib/ftpd/exception_translator.rb +2 -0
- data/lib/ftpd/exceptions.rb +2 -0
- data/lib/ftpd/file_info.rb +2 -0
- data/lib/ftpd/file_system_helper.rb +2 -0
- data/lib/ftpd/ftp_server.rb +27 -0
- data/lib/ftpd/gets_peer_address.rb +2 -0
- data/lib/ftpd/insecure_certificate.rb +2 -0
- data/lib/ftpd/list_format/eplf.rb +2 -0
- data/lib/ftpd/list_format/ls.rb +2 -0
- data/lib/ftpd/list_path.rb +2 -0
- data/lib/ftpd/null_logger.rb +2 -0
- data/lib/ftpd/protocols.rb +2 -0
- data/lib/ftpd/read_only_disk_file_system.rb +2 -0
- data/lib/ftpd/server.rb +2 -0
- data/lib/ftpd/session.rb +7 -0
- data/lib/ftpd/session_config.rb +26 -2
- data/lib/ftpd/stream.rb +2 -0
- data/lib/ftpd/telnet.rb +3 -2
- data/lib/ftpd/temp_dir.rb +2 -0
- data/lib/ftpd/tls_server.rb +2 -0
- data/lib/ftpd/translate_exceptions.rb +2 -0
- data/spec/command_sequence_checker_spec.rb +2 -0
- data/spec/connection_throttle_spec.rb +2 -0
- data/spec/connection_tracker_spec.rb +2 -0
- data/spec/data_server_factory_spec.rb +104 -0
- data/spec/disk_file_system_spec.rb +2 -0
- data/spec/exception_translator_spec.rb +2 -0
- data/spec/file_info_spec.rb +2 -0
- data/spec/ftp_server_error_spec.rb +2 -0
- data/spec/list_format/eplf_spec.rb +2 -0
- data/spec/list_format/ls_spec.rb +2 -0
- data/spec/list_path_spec.rb +2 -0
- data/spec/null_logger_spec.rb +2 -0
- data/spec/protocols_spec.rb +58 -38
- data/spec/server_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/telnet_spec.rb +2 -0
- data/spec/translate_exceptions_spec.rb +2 -0
- data/testlib/network.rb +17 -0
- metadata +13 -7
@@ -1,3 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Given /^the client is in (passive|active) mode$/ do |mode|
|
2
4
|
client.passive = mode == 'passive'
|
3
5
|
end
|
6
|
+
|
7
|
+
Then(/^the server advertises passive IP (\S+)$/) do |ip|
|
8
|
+
quads = @reply.scan(/\d+/)[1..4].join(".")
|
9
|
+
expect(quads).to eq ip
|
10
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
When /^the client successfully queries system ID$/ do
|
2
4
|
@reply = client.system
|
5
|
+
# Prior to ruby-2.3.0, the #system call returned a string ending in
|
6
|
+
# a new-line.
|
7
|
+
@reply += "\n" unless @reply =~ /\n$/
|
3
8
|
end
|
4
9
|
|
5
10
|
Then /^the server returns a system ID reply$/ do
|
data/features/support/env.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fileutils'
|
2
4
|
require 'forwardable'
|
3
5
|
require File.expand_path('test_server_files',
|
@@ -50,7 +52,7 @@ class ExampleServer
|
|
50
52
|
private
|
51
53
|
|
52
54
|
def read_output
|
53
|
-
output = ''
|
55
|
+
output = ''.dup
|
54
56
|
loop do
|
55
57
|
line = @io.gets
|
56
58
|
break if line.nil?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'double_bag_ftps'
|
2
4
|
require 'net/ftp'
|
3
5
|
|
@@ -20,10 +22,11 @@ class TestClient
|
|
20
22
|
|
21
23
|
def close
|
22
24
|
return unless @ftp
|
23
|
-
|
25
|
+
ftp.close
|
26
|
+
@ftp = nil
|
24
27
|
end
|
25
28
|
|
26
|
-
def_delegators
|
29
|
+
def_delegators :ftp,
|
27
30
|
:chdir,
|
28
31
|
:connect,
|
29
32
|
:delete,
|
@@ -54,33 +57,33 @@ class TestClient
|
|
54
57
|
socket.connect(out_addr)
|
55
58
|
decorate_socket socket
|
56
59
|
@ftp = make_ftp
|
57
|
-
|
60
|
+
ftp.set_socket(socket)
|
58
61
|
end
|
59
62
|
|
60
63
|
def raw(*command)
|
61
|
-
|
64
|
+
ftp.sendcmd command.compact.join(' ')
|
62
65
|
end
|
63
66
|
|
64
67
|
def get(mode, remote_path)
|
65
68
|
method = "get#{mode}file"
|
66
|
-
|
69
|
+
ftp.send method, remote_path, local_path(remote_path)
|
67
70
|
end
|
68
71
|
|
69
72
|
def put(mode, remote_path)
|
70
73
|
method = "put#{mode}file"
|
71
|
-
|
74
|
+
ftp.send method, local_path(remote_path), remote_path
|
72
75
|
end
|
73
76
|
|
74
77
|
def get_size(mode, remote_path)
|
75
78
|
raise unless ['binary', 'text'].include?(mode)
|
76
|
-
|
79
|
+
ftp.binary = mode == 'binary'
|
77
80
|
override_with_binary do
|
78
|
-
|
81
|
+
ftp.size(remote_path)
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
85
|
def get_mtime(remote_path)
|
83
|
-
|
86
|
+
ftp.mtime(remote_path)
|
84
87
|
end
|
85
88
|
|
86
89
|
def add_file(path)
|
@@ -100,34 +103,34 @@ class TestClient
|
|
100
103
|
end
|
101
104
|
|
102
105
|
def xpwd
|
103
|
-
response =
|
106
|
+
response = ftp.sendcmd('XPWD')
|
104
107
|
response[/"(.+)"/, 1]
|
105
108
|
end
|
106
109
|
|
107
110
|
def store_unique(local_path, remote_path)
|
108
111
|
command = ['STOU', remote_path].compact.join(' ')
|
109
112
|
File.open(temp_path(local_path), 'rb') do |file|
|
110
|
-
|
113
|
+
ftp.storbinary command, file, Net::FTP::DEFAULT_BLOCKSIZE
|
111
114
|
end
|
112
115
|
end
|
113
116
|
|
114
117
|
def append_binary(local_path, remote_path)
|
115
118
|
command = ['APPE', remote_path].compact.join(' ')
|
116
119
|
File.open(temp_path(local_path), 'rb') do |file|
|
117
|
-
|
120
|
+
ftp.storbinary command, file, Net::FTP::DEFAULT_BLOCKSIZE
|
118
121
|
end
|
119
122
|
end
|
120
123
|
|
121
124
|
def append_text(local_path, remote_path)
|
122
125
|
command = ['APPE', remote_path].compact.join(' ')
|
123
126
|
File.open(temp_path(local_path), 'rb') do |file|
|
124
|
-
|
127
|
+
ftp.storlines command, file
|
125
128
|
end
|
126
129
|
end
|
127
130
|
|
128
131
|
def connected?
|
129
132
|
begin
|
130
|
-
|
133
|
+
ftp.noop
|
131
134
|
true
|
132
135
|
rescue Net::FTPTempError => e
|
133
136
|
!!e.to_s =~ /^421/
|
@@ -137,13 +140,18 @@ class TestClient
|
|
137
140
|
end
|
138
141
|
|
139
142
|
def set_option(option)
|
140
|
-
|
143
|
+
ftp.sendcmd "OPTS #{option}"
|
141
144
|
end
|
142
145
|
|
143
146
|
private
|
144
|
-
|
147
|
+
|
145
148
|
RAW_METHOD_REGEX = /^send_(.*)$/
|
146
149
|
|
150
|
+
def ftp
|
151
|
+
raise "Not started" unless @ftp
|
152
|
+
@ftp
|
153
|
+
end
|
154
|
+
|
147
155
|
def local_path(remote_path)
|
148
156
|
temp_path(File.basename(remote_path))
|
149
157
|
end
|
@@ -207,12 +215,12 @@ class TestClient
|
|
207
215
|
end
|
208
216
|
|
209
217
|
def override_with_binary
|
210
|
-
orig =
|
218
|
+
orig = ftp.override_with_binary
|
211
219
|
begin
|
212
|
-
|
220
|
+
ftp.override_with_binary = true
|
213
221
|
yield
|
214
222
|
ensure
|
215
|
-
|
223
|
+
ftp.override_with_binary = orig
|
216
224
|
end
|
217
225
|
end
|
218
226
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fileutils'
|
2
4
|
require 'forwardable'
|
3
5
|
require 'stringio'
|
@@ -209,24 +211,22 @@ class TestServer
|
|
209
211
|
@temp_dir = Ftpd::TempDir.make
|
210
212
|
@log_device = StringIO.new
|
211
213
|
@driver = TestServerDriver.new(@temp_dir)
|
212
|
-
@server = Ftpd::FtpServer.new(@driver)
|
213
|
-
@server.certfile_path = insecure_certfile_path
|
214
214
|
@templates = TestFileTemplates.new
|
215
|
-
self.tls = :off
|
216
215
|
end
|
217
216
|
|
218
|
-
def_delegator
|
219
|
-
def_delegator
|
220
|
-
def_delegator
|
221
|
-
def_delegator
|
222
|
-
def_delegator
|
223
|
-
def_delegator
|
224
|
-
def_delegator
|
225
|
-
def_delegator
|
226
|
-
def_delegator
|
227
|
-
def_delegator
|
228
|
-
def_delegator
|
229
|
-
def_delegator
|
217
|
+
def_delegator :server, :'allow_low_data_ports='
|
218
|
+
def_delegator :server, :'auth_level'
|
219
|
+
def_delegator :server, :'auth_level='
|
220
|
+
def_delegator :server, :'failed_login_delay='
|
221
|
+
def_delegator :server, :'interface='
|
222
|
+
def_delegator :server, :'max_connections='
|
223
|
+
def_delegator :server, :'max_connections_per_ip='
|
224
|
+
def_delegator :server, :'max_failed_logins='
|
225
|
+
def_delegator :server, :'nat_ip='
|
226
|
+
def_delegator :server, :'server_name'
|
227
|
+
def_delegator :server, :'server_name='
|
228
|
+
def_delegator :server, :'session_timeout='
|
229
|
+
def_delegator :server, :'tls='
|
230
230
|
|
231
231
|
def_delegator :@driver, :'append='
|
232
232
|
def_delegator :@driver, :'delete='
|
@@ -242,16 +242,16 @@ class TestServer
|
|
242
242
|
end
|
243
243
|
|
244
244
|
def start
|
245
|
-
|
246
|
-
|
245
|
+
server.log = make_log
|
246
|
+
server.start
|
247
247
|
end
|
248
248
|
|
249
249
|
def stop
|
250
|
-
|
250
|
+
server.stop
|
251
251
|
end
|
252
252
|
|
253
253
|
def host
|
254
|
-
|
254
|
+
server.interface
|
255
255
|
end
|
256
256
|
|
257
257
|
def user
|
@@ -267,7 +267,7 @@ class TestServer
|
|
267
267
|
end
|
268
268
|
|
269
269
|
def port
|
270
|
-
|
270
|
+
server.bound_port
|
271
271
|
end
|
272
272
|
|
273
273
|
def template(path)
|
@@ -276,6 +276,17 @@ class TestServer
|
|
276
276
|
|
277
277
|
private
|
278
278
|
|
279
|
+
def server
|
280
|
+
@server ||= make_server
|
281
|
+
end
|
282
|
+
|
283
|
+
def make_server
|
284
|
+
s = Ftpd::FtpServer.new(@driver)
|
285
|
+
s.certfile_path = insecure_certfile_path
|
286
|
+
s.tls = :off
|
287
|
+
s
|
288
|
+
end
|
289
|
+
|
279
290
|
def temp_dir
|
280
291
|
@temp_dir
|
281
292
|
end
|