Changeset View
Changeset View
Standalone View
Standalone View
autotests/ftpd
- This file was added.
1 | #!/usr/bin/env ruby | ||||
---|---|---|---|---|---|
2 | # Copyright (c) 2019 Harald Sitter <sitter@kde.org> | ||||
3 | # | ||||
4 | # This library is free software; you can redistribute it and/or modify | ||||
5 | # it under the terms of the GNU Lesser General Public License as published by | ||||
6 | # the Free Software Foundation; either version 2 of the License or ( at | ||||
7 | # your option ) version 3 or, at the discretion of KDE e.V. ( which shall | ||||
8 | # act as a proxy as in section 14 of the GPLv3 ), any later version. | ||||
9 | # | ||||
10 | # This library is distributed in the hope that it will be useful, | ||||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | # Library General Public License for more details. | ||||
14 | # | ||||
15 | # You should have received a copy of the GNU Lesser General Public License | ||||
16 | # along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | # Boston, MA 02110-1301, USA. | ||||
19 | | ||||
20 | require 'ftpd' | ||||
21 | require 'tmpdir' | ||||
22 | | ||||
23 | STDOUT.sync = true | ||||
24 | | ||||
25 | # Monkey patch the site handler, it's not implemented so fake it a bit for ftp | ||||
26 | # slave purposes. | ||||
27 | | ||||
28 | # FIXME: and yet I seee kio_ftp(8319)/(kf5.kio.kio_ftp) Ftp::ftpChmod: ftpChmod: CHMOD not supported - disabling | ||||
29 | | ||||
30 | module Ftpd | ||||
31 | class CmdSite | ||||
32 | alias cmd_site_orig cmd_site | ||||
33 | def cmd_site(_argument) | ||||
34 | # We don't support chmod bugger off. | ||||
35 | reply '500 cmd_site.' | ||||
36 | end | ||||
37 | end | ||||
38 | end | ||||
39 | | ||||
40 | module Ftpd | ||||
41 | class CmdRest | ||||
42 | def cmd_rest(_argument) | ||||
43 | reply "350 cmd_rest." | ||||
44 | end | ||||
45 | end | ||||
46 | end | ||||
47 | | ||||
48 | module Ftpd | ||||
49 | class CmdStor | ||||
50 | alias cmd_stor_orig cmd_stor | ||||
51 | def cmd_stor(argument) | ||||
52 | if argument.include?('__badResume__') | ||||
53 | reply '550 out of quota' | ||||
54 | else | ||||
55 | cmd_stor_orig(argument) | ||||
56 | end | ||||
57 | end | ||||
58 | end | ||||
59 | end | ||||
60 | | ||||
61 | # Add some simulation capabilities to the file sytem | ||||
62 | class MangledDiskFileSystem < Ftpd::DiskFileSystem | ||||
63 | def accessible?(path, *args) | ||||
64 | return false if path.include?('__inaccessiblePath__') | ||||
65 | | ||||
66 | super(path, *args) | ||||
67 | end | ||||
68 | end | ||||
69 | | ||||
70 | class Driver | ||||
71 | def initialize(temp_dir) | ||||
72 | @temp_dir = temp_dir | ||||
73 | end | ||||
74 | | ||||
75 | def authenticate(_user, _password) | ||||
76 | true | ||||
77 | end | ||||
78 | | ||||
79 | def file_system(_user) | ||||
80 | MangledDiskFileSystem.new(@temp_dir) | ||||
81 | end | ||||
82 | end | ||||
83 | | ||||
84 | # NB: stderr is used to communicate with the parent! | ||||
85 | | ||||
86 | port = ARGV.fetch(0) | ||||
87 | temp_dir = ARGV.fetch(1) | ||||
88 | | ||||
89 | require 'logger/colors' | ||||
90 | driver = Driver.new(temp_dir) | ||||
91 | server = Ftpd::FtpServer.new(driver) | ||||
92 | server.port = port | ||||
93 | server.log = Logger.new($stdout) | ||||
94 | server.start | ||||
95 | warn "port = #{server.bound_port}" | ||||
96 | puts "Server listening on port #{server.bound_port}" | ||||
97 | loop do | ||||
98 | sleep(1) | ||||
99 | end |