|
1
|
# |
|
2
|
# Copyright (c) 2026 Dan Mestas |
|
3
|
# |
|
4
|
# This program is free software; you can redistribute it and/or |
|
5
|
# modify it under the terms of the Simplified BSD License (also |
|
6
|
# known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
# |
|
8
|
# This program is distributed in the hope that it will be useful, |
|
9
|
# but without any warranty; without even the implied warranty of |
|
10
|
# merchantability or fitness for a particular purpose. |
|
11
|
# |
|
12
|
############################################################################ |
|
13
|
# |
|
14
|
# What fossil puts on an ssh command line. Nothing here connects to |
|
15
|
# another machine: "ssh" is a copy of standin/log-args.sh, which writes |
|
16
|
# down its arguments and exits. A command that has the --ssh-command |
|
17
|
# option is given the script with it. The other commands find the |
|
18
|
# script first on the PATH. |
|
19
|
# |
|
20
|
# Whatever follows the host on an ssh command line is joined into one |
|
21
|
# string by ssh and parsed again by the login shell on the server, so |
|
22
|
# quoting for the local shell does not protect it. These tests require |
|
23
|
# that a value with a character special to a shell never reaches ssh, |
|
24
|
# and that ordinary values reach it unchanged. |
|
25
|
# |
|
26
|
|
|
27
|
require_no_open_checkout |
|
28
|
|
|
29
|
if {$::tcl_platform(platform) eq "windows"} { |
|
30
|
test_skip "the stand-in for ssh is a shell script" |
|
31
|
} |
|
32
|
|
|
33
|
test_setup |
|
34
|
|
|
35
|
set sshDir [file join [pwd] ssh-standin] |
|
36
|
file mkdir $sshDir |
|
37
|
set sshStub [test_standin log-args.sh [file join $sshDir ssh]] |
|
38
|
set sshLog [file join [pwd] ssh-args.txt] |
|
39
|
set ::env(ARGS_LOG) $sshLog |
|
40
|
set sshSavedPath $::env(PATH) |
|
41
|
set ::env(PATH) "$sshDir:$::env(PATH)" |
|
42
|
|
|
43
|
# The stand-in must be what "ssh" means from here on. If it is not, run |
|
44
|
# nothing that could start the real one. |
|
45
|
if {[lindex [auto_execok ssh] 0] ne $sshStub} { |
|
46
|
set ::env(PATH) $sshSavedPath |
|
47
|
test_skip "cannot put a stand-in for ssh first on the PATH" |
|
48
|
} |
|
49
|
|
|
50
|
# Run fossil with the arguments given. Sets RESULT to everything it |
|
51
|
# printed and sshArgs to the arguments the stand-in was given, one per |
|
52
|
# line inside <>, or to an empty string if it was not run. |
|
53
|
proc ssh_run {args} { |
|
54
|
global sshArgs sshLog |
|
55
|
file delete $sshLog |
|
56
|
fossil_raw {*}$args |
|
57
|
set sshArgs "" |
|
58
|
if {[file exists $sshLog]} { |
|
59
|
set sshArgs [read_file $sshLog] |
|
60
|
} |
|
61
|
} |
|
62
|
proc ssh_clone {url} { |
|
63
|
file delete ssh-clone.fossil |
|
64
|
ssh_run clone --ssh-command $::sshStub $url ssh-clone.fossil |
|
65
|
} |
|
66
|
|
|
67
|
############################################################################### |
|
68
|
# Ordinary URLs reach ssh, with "--" before the host and the path as one |
|
69
|
# argument. |
|
70
|
|
|
71
|
ssh_clone ssh://hh/dir/repo.fossil |
|
72
|
test ssh-clone-plain \ |
|
73
|
{[holds_strings $sshArgs \ |
|
74
|
[list "<-->\n<hh>\n" "<test-http>\n<dir/repo.fossil>"]]} |
|
75
|
ssh_clone ssh://uu@hh:2222/dir/repo.fossil |
|
76
|
test ssh-clone-user-port \ |
|
77
|
{[holds_strings $sshArgs [list "<-p>\n<2222>\n" "<-->\n<uu@hh>\n"]]} |
|
78
|
ssh_clone "ssh://hh/dir/a-b_c.d,e=f@g/repo.fossil" |
|
79
|
test ssh-clone-punctuation \ |
|
80
|
{[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0} |
|
81
|
ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil" |
|
82
|
test ssh-clone-fossil-parameter \ |
|
83
|
{[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0} |
|
84
|
|
|
85
|
# A path that begins with "~" is for the server to expand, so it goes to |
|
86
|
# the server as it is. |
|
87
|
ssh_clone ssh://hh/~/repo.fossil |
|
88
|
test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0} |
|
89
|
|
|
90
|
############################################################################### |
|
91
|
# A path or a fossil= value with a character special to a shell is |
|
92
|
# refused, and ssh is not run. |
|
93
|
|
|
94
|
foreach {sshName sshUrl} { |
|
95
|
semicolon ssh://hh/a;b.fossil |
|
96
|
space ssh://hh/a%20b.fossil |
|
97
|
dollar ssh://hh/$HOME/b.fossil |
|
98
|
ampersand ssh://hh/a%26b.fossil |
|
99
|
backquote ssh://hh/a%60b.fossil |
|
100
|
pipe ssh://hh/a|b.fossil |
|
101
|
parenthesis ssh://hh/a(b).fossil |
|
102
|
redirect ssh://hh/a>b.fossil |
|
103
|
} { |
|
104
|
ssh_clone $sshUrl |
|
105
|
test ssh-clone-refused-$sshName \ |
|
106
|
{$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0} |
|
107
|
} |
|
108
|
foreach {sshName sshUrl} { |
|
109
|
semicolon ssh://hh/repo.fossil?fossil=a;b/fossil |
|
110
|
dollar ssh://hh/repo.fossil?fossil=$HOME/bin/fossil |
|
111
|
other ssh://hh/repo.fossil?fossil=/bin/other |
|
112
|
} { |
|
113
|
ssh_clone $sshUrl |
|
114
|
test ssh-clone-fossil-refused-$sshName \ |
|
115
|
{$sshArgs eq "" && [string first "unsafe command" $RESULT] >= 0} |
|
116
|
} |
|
117
|
|
|
118
|
############################################################################### |
|
119
|
# "fossil ui HOST:REPO" refuses such a repository name, and puts "--" |
|
120
|
# before the host. |
|
121
|
|
|
122
|
ssh_run ui --nobrowser hh:dir/repo.fossil |
|
123
|
test ssh-ui-plain \ |
|
124
|
{[holds_strings $sshArgs [list "<-->\n<hh>\n" "<dir/repo.fossil>"]]} |
|
125
|
ssh_run ui --nobrowser "hh:dir/a;b.fossil" |
|
126
|
test ssh-ui-refused-semicolon \ |
|
127
|
{$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0} |
|
128
|
ssh_run ui --nobrowser "hh:dir/a b.fossil" |
|
129
|
test ssh-ui-refused-space \ |
|
130
|
{$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0} |
|
131
|
ssh_run ui --nobrowser -- "-x@hh:dir/repo.fossil" |
|
132
|
test ssh-ui-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} |
|
133
|
|
|
134
|
############################################################################### |
|
135
|
# "fossil patch push" and "fossil patch pull" put "--" before the host. |
|
136
|
|
|
137
|
write_file ssh-file.txt "one\n" |
|
138
|
fossil add ssh-file.txt |
|
139
|
ssh_run patch push -- "-x@hh:dir" |
|
140
|
test ssh-patch-push-user-with-dash \ |
|
141
|
{[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} |
|
142
|
ssh_run patch pull -- "-x@hh:dir" |
|
143
|
test ssh-patch-pull-user-with-dash \ |
|
144
|
{[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} |
|
145
|
|
|
146
|
############################################################################### |
|
147
|
# An argument that begins with "~" is quoted, so that the shell does not |
|
148
|
# replace it with a home directory. |
|
149
|
|
|
150
|
ssh_run test-escaped-arg ~ ~root/x |
|
151
|
test ssh-escaped-tilde \ |
|
152
|
{[holds_strings $RESULT {{argv[2] = [~]} {argv[2] = [~root/x]}}]} |
|
153
|
|
|
154
|
############################################################################### |
|
155
|
# "sync --all" with two remotes: the default one answers every request |
|
156
|
# with a redirect to an ssh: URL, and the second, a repository file, has |
|
157
|
# an artifact that the local repository lacks, so the sync makes a |
|
158
|
# second pass. The redirect is refused on each pass and ssh is not run. |
|
159
|
# Known bug: a refused redirect replaces the URL of the remote, so the |
|
160
|
# second pass connects to the ssh: URL. |
|
161
|
|
|
162
|
proc ssh_redirect {chan request} { |
|
163
|
puts -nonewline $chan "HTTP/1.1 302 Found\r\nLocation: ssh://hh/r.fossil\r\n" |
|
164
|
puts -nonewline $chan "Content-Length: 0\r\nConnection: close\r\n\r\n" |
|
165
|
} |
|
166
|
fossil new ssh-local.fossil |
|
167
|
file copy -force ssh-local.fossil ssh-other.fossil |
|
168
|
write_file ssh-page.txt "page\n" |
|
169
|
fossil wiki create SshPage ssh-page.txt -R ssh-other.fossil |
|
170
|
set sshPort [test_listen ssh_redirect] |
|
171
|
fossil remote http://127.0.0.1:$sshPort/x -R ssh-local.fossil |
|
172
|
fossil remote add other [file join [pwd] ssh-other.fossil] -R ssh-local.fossil |
|
173
|
ssh_run sync --all -R ssh-local.fossil |
|
174
|
test_listen_stop |
|
175
|
test ssh-sync-all-refused-redirect {$sshArgs eq "" && |
|
176
|
[string first "cannot redirect to ssh://hh/r.fossil" $RESULT] >= 0} \ |
|
177
|
knownBug |
|
178
|
|
|
179
|
set ::env(PATH) $sshSavedPath |
|
180
|
unset ::env(ARGS_LOG) |
|
181
|
test_cleanup |
|
182
|
|