Fossil SCM

Add tests for operations over HTTP and "file:", integrity, and some dry runs.

danshearer 2026-11-26 18:29 UTC test-suite-new
Commit 5388e51fdbb2e2f48950ab81bd63580c037586727d4b5149586fce86de36603d
--- a/test/http-relay.py
+++ b/test/http-relay.py
@@ -0,0 +1,107 @@
1
+#!/usr/bin/env python3
2
+#
3
+# Usage: python3 http-relay.py ADDRESS reset
4
+# python3 http-relay.py ADDRESS UPSTREAM CERT KEY ?notify?
5
+#
6
+# Does for test/http.test what Tcl cannot. With "reset", listens on
7
+# ADDRESS and resets each connection it accepts. Otherwise it accepts
8
+# TLS connections on ADDRESS with the certificate CERT and its key KEY,
9
+# relays each request to the HTTP server on port UPSTREAM of 127.0.0.1,
10
+# and sends the reply back. It ends the TLS session with close_notify
11
+# only when "notify" is given. It prints "listening PORT" when ready,
12
+# and "SNI: NAME" for the TLS server name each client sends.
13
+
14
+import re
15
+import socket
16
+import ssl
17
+import struct
18
+import sys
19
+import threading
20
+
21
+
22
+# Returns the HTTP request that CLIENT sends, with its body.
23
+def read_request(client):
24
+ data = b""
25
+ while b"\r\n\r\n" not in data:
26
+ part = client.recv(65536)
27
+ if not part:
28
+ return data
29
+ data += part
30
+ header = data.split(b"\r\n\r\n", 1)[0]
31
+ match = re.search(rb"(?im)^content-length:\s*(\d+)", header)
32
+ length = len(header) + 4 + (int(match.group(1)) if match else 0)
33
+ while len(data) < length:
34
+ part = client.recv(65536)
35
+ if not part:
36
+ break
37
+ data += part
38
+ return data
39
+
40
+
41
+# Serves one TLS connection: sends the request to the server on port
42
+# UPSTREAM and the whole reply back, then ends the TLS session.
43
+def relay(context, client, upstream, notify):
44
+ try:
45
+ client = context.wrap_socket(client, server_side=True)
46
+ request = read_request(client)
47
+ reply = b""
48
+ with socket.create_connection(("127.0.0.1", upstream)) as server:
49
+ server.sendall(request)
50
+ while part := server.recv(65536):
51
+ reply += part
52
+ client.sendall(reply)
53
+ if notify:
54
+ client = client.unwrap()
55
+ else:
56
+ client.shutdown(socket.SHUT_RDWR)
57
+ except OSError:
58
+ pass
59
+ client.close()
60
+
61
+
62
+# Resets each connection that LISTENER accepts. Closing a socket whose
63
+# linger time is zero sends a reset.
64
+def reset_connections(listener):
65
+ while True:
66
+ client, _ = listener.accept()
67
+ client.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
68
+ struct.pack("ii", 1, 0))
69
+ client.close()
70
+
71
+
72
+def print_server_name(tls_socket, name, context):
73
+ print("SNI:", name, flush=True)
74
+
75
+
76
+# Relays each TLS connection that LISTENER accepts, in a thread of its
77
+# own.
78
+def relay_connections(listener, upstream, cert, key, notify):
79
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
80
+ context.load_cert_chain(cert, key)
81
+ context.sni_callback = print_server_name
82
+ while True:
83
+ client, _ = listener.accept()
84
+ thread = threading.Thread(
85
+ target=relay, args=(context, client, upstream, notify),
86
+ daemon=True)
87
+ thread.start()
88
+
89
+
90
+def main():
91
+ address = sys.argv[1]
92
+ family = socket.AF_INET6 if ":" in address else socket.AF_INET
93
+ listener = socket.socket(family)
94
+ listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
95
+ listener.bind((address, 0))
96
+ listener.listen(8)
97
+ print("listening", listener.getsockname()[1], flush=True)
98
+ if sys.argv[2] == "reset":
99
+ reset_connections(listener)
100
+ else:
101
+ upstream = int(sys.argv[2])
102
+ cert, key = sys.argv[3:5]
103
+ notify = sys.argv[5:] == ["notify"]
104
+ relay_connections(listener, upstream, cert, key, notify)
105
+
106
+
107
+main()
--- a/test/http-relay.py
+++ b/test/http-relay.py
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/http-relay.py
+++ b/test/http-relay.py
@@ -0,0 +1,107 @@
1 #!/usr/bin/env python3
2 #
3 # Usage: python3 http-relay.py ADDRESS reset
4 # python3 http-relay.py ADDRESS UPSTREAM CERT KEY ?notify?
5 #
6 # Does for test/http.test what Tcl cannot. With "reset", listens on
7 # ADDRESS and resets each connection it accepts. Otherwise it accepts
8 # TLS connections on ADDRESS with the certificate CERT and its key KEY,
9 # relays each request to the HTTP server on port UPSTREAM of 127.0.0.1,
10 # and sends the reply back. It ends the TLS session with close_notify
11 # only when "notify" is given. It prints "listening PORT" when ready,
12 # and "SNI: NAME" for the TLS server name each client sends.
13
14 import re
15 import socket
16 import ssl
17 import struct
18 import sys
19 import threading
20
21
22 # Returns the HTTP request that CLIENT sends, with its body.
23 def read_request(client):
24 data = b""
25 while b"\r\n\r\n" not in data:
26 part = client.recv(65536)
27 if not part:
28 return data
29 data += part
30 header = data.split(b"\r\n\r\n", 1)[0]
31 match = re.search(rb"(?im)^content-length:\s*(\d+)", header)
32 length = len(header) + 4 + (int(match.group(1)) if match else 0)
33 while len(data) < length:
34 part = client.recv(65536)
35 if not part:
36 break
37 data += part
38 return data
39
40
41 # Serves one TLS connection: sends the request to the server on port
42 # UPSTREAM and the whole reply back, then ends the TLS session.
43 def relay(context, client, upstream, notify):
44 try:
45 client = context.wrap_socket(client, server_side=True)
46 request = read_request(client)
47 reply = b""
48 with socket.create_connection(("127.0.0.1", upstream)) as server:
49 server.sendall(request)
50 while part := server.recv(65536):
51 reply += part
52 client.sendall(reply)
53 if notify:
54 client = client.unwrap()
55 else:
56 client.shutdown(socket.SHUT_RDWR)
57 except OSError:
58 pass
59 client.close()
60
61
62 # Resets each connection that LISTENER accepts. Closing a socket whose
63 # linger time is zero sends a reset.
64 def reset_connections(listener):
65 while True:
66 client, _ = listener.accept()
67 client.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
68 struct.pack("ii", 1, 0))
69 client.close()
70
71
72 def print_server_name(tls_socket, name, context):
73 print("SNI:", name, flush=True)
74
75
76 # Relays each TLS connection that LISTENER accepts, in a thread of its
77 # own.
78 def relay_connections(listener, upstream, cert, key, notify):
79 context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
80 context.load_cert_chain(cert, key)
81 context.sni_callback = print_server_name
82 while True:
83 client, _ = listener.accept()
84 thread = threading.Thread(
85 target=relay, args=(context, client, upstream, notify),
86 daemon=True)
87 thread.start()
88
89
90 def main():
91 address = sys.argv[1]
92 family = socket.AF_INET6 if ":" in address else socket.AF_INET
93 listener = socket.socket(family)
94 listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
95 listener.bind((address, 0))
96 listener.listen(8)
97 print("listening", listener.getsockname()[1], flush=True)
98 if sys.argv[2] == "reset":
99 reset_connections(listener)
100 else:
101 upstream = int(sys.argv[2])
102 cert, key = sys.argv[3:5]
103 notify = sys.argv[5:] == ["notify"]
104 relay_connections(listener, upstream, cert, key, notify)
105
106
107 main()
--- a/test/http.test
+++ b/test/http.test
@@ -0,0 +1,591 @@
1
+###################Servers in this file send
2
+# fossil replies that HTTP/1.1 allows, which must give a complete clone,
3
+# and malformed replies, which must make the clone fail with a message
4
+# and not leave a repository behind. Others########################
5
+#
6
+# Tts of fossil's HTTP and HTTPS client. A clone must work when the
7
+# reply ihich certificates it trusts.
8
+#
9
+# The HTTPS tests need openssl and a fossil built with TLS support. The
10
+# tests that reset a connection, and the HTTPS tests that check what
11
+# fossil does with a reply, need python3 to run http-relay.py.
12
+#
13
+
14
+require_no_open_checkout
15
+
16
+if {$::is_windows} {
17
+ test_skip "http.test stops its servers with kill"
18
+}
19
+if {![loopback_available]} {
20
+ test_skip "the tests need a TCP connection over the loopback interface"
21
+proxy or#########################_CERT_FILE and SSL_CERT_DIR are unset until the end of
22
+# this file.
23
+#
24
+foreach var {SSL_CERT_FILE SSL_CERT_DIR} {
25
+ if {[info exists env($var)]} {
26
+ set httpSavedEnv($var) $env($var)
27
+ unset env($var)
28
+ }
29
+}
30
+test_setup ""
31
+fossil test-th-eval {hasfeature ssl}
32
+set haveTls [expr {[normalize_result] eq "1" && [auto_execok openssl] ne ""}]
33
+set havePython [expr {[auto_execok python3] ne ""}]
34
+set haveIpv6 [expr {![catch {close [socket -server list -myaddr ::1 0]}]}]
35
+set httpPids [list]
36
+set httpFossilServers [list]
37
+set httpAnswer ""
38
+
39
+# Clones URL into c.fossil with the options in ARGS, answering fossil's
40
+# prompts with the lines in httpAnswer. Returns "cloned" when the clone
41
+# is a complete copy of r.fossil. When fossil exits with status 1 and
42
+# does not leave c.fossil, returns its output, and otherwise says what
43
+# went wrong.
44
+#
45
+proc http_clone {url args} {
46
+ file delete c.fossil
47
+ fossil_raw -seconds 60 -input $::httpAnswer clone $url c.fossil {*}$args
48
+ set ::RESULT [string trim $::RESULT]
49
+ if {$::CODE == 0} {
50
+ fossil sql -R c.fossil "SELECT count(*) FROM blob"
51
+ if {$::RESULT == $::httpBlobs} {return cloned}
52
+ return "cloned $::RESULT of $::httpBlobs blobs"
53
+ }
54
+ if {$::CODE ne "1"} {return "exit $::CODE"}
55
+ if {[file exists c.fossil]} {return "c.fossil is left"}
56
+ return $::RESULT
57
+}
58
+
59
+# Listens on a port on 127.0.0.1 that the system chooses, and returns
60
+# the port. Calls HANDLER with each connection and the request on it,
61
+# once the whole request has arrived, and then closes the connection.
62
+#
63
+proc http_listen {handler} {
64
+ return [test_listen [list http_receive $handler]]
65
+}
66
+
67
+proc http_receive {handler chan request} {
68
+ if {[string first "\r\n\r\n" $request] >= 0} {
69
+ {*}$handler $chan $request
70
+ }
71
+}
72
+
73
+proc http_listen_close {} {
74
+ set server [socket -server {apply {{chan address port} {close $chan}}} \
75
+ -myaddr 127.0.0.1 0]
76
+ lappend ::testListeners $server
77
+ return [lindex [fconfigure $server -sockname] 2]
78
+}
79
+
80
+# Starts http-relay.py with ARGS and returns the port it listens on. Its
81
+# output goes to relay-PORT.log.
82
+#
83
+proc http_relay {args} {
84
+ set log relay-[getSeqNo].log
85
+ lappend ::httpPids {*}[exec python3 -I \
86
+ [file join $::testfiledir http-relay.py] {*}$args >& $log &]
87
+ for {set i 0} {$i < 100} {incr i} {
88
+ after 100
89
+ if {[regexp {listening (\d+)} [read_file $log] -> port]} {
90
+ file rename $log relay-$port.log
91
+ return $port
92
+ }
93
+ }
94
+ error "http-relay.py did not start: [read_file $log]"
95
+}
96
+
97
+# Returns the TLS server names that clients sent to the relay on PORT
98
+# since the last call, sorted and without duplicates.
99
+#
100
+proc http_server_names {port} {
101
+ set names [regexp -all -inline -line {^SNI: .*$} \
102
+ [read_file relay-$port.log]]
103
+ set seen 0
104
+ if {[info exists ::httpNamesSeen($port)]} {set seen $::httpNamesSeen($port)}
105
+ set ::httpNamesSeen($port) [llength $names]
106
+ return [join [lsort -unique [lrange $names $seen end]] \n]
107
+}
108
+
109
+# Starts "fossil server" with the options in ARGS on REPOSITORY, and
110
+# returns the port it listens on.
111
+#
112
+proc http_server {repository args} {
113
+ set server [test_start_server $repository "" {*}$args]
114
+ lappend ::httpFossilServers $server
115
+ return [lindex $server 1]
116
+}
117
+
118
+# A repository of eight check-ins, which anyone can clone. Each check-in
119
+# adds a file of 20000 random characters, so that a clone takes several
120
+# round trips and each reply is large enough to split.
121
+#
122
+fossil new r.fossil
123
+fossil user capabilities nobody gio -R r.fossil
124
+fossil settings backoffice-disable 1 -R r.fossil
125
+file mkdir co
126
+cd co
127
+fossil open ../r.fossil
128
+for {set i 1} {$i <= 8} {incr i} {
129
+ write_file f$i.txt [rand_str 20000]
130
+ fossil add f$i.txt
131
+ fossil commit -m "check-in $i"
132
+}
133
+fossil close
134
+cd ..
135
+fossil sql -R r.fossil "SELECT count(*) FROM blob"
136
+set httpBlobs [normalize_result]
137
+set upstream [http_server r.fossil]
138
+set closePort [http_listen_close]
139
+
140
+# Writes the reply of the fossil server to REQUEST to CHAN, with its
141
+# framing changed as the test NAME says. RFC 9112 sections 6 and 7 say
142
+# what HTTP/1.1 allows.
143
+#
144
+proc http_proxy {name chan request} {
145
+ set server [socket 127.0.0.1 $::upstream]
146
+ fconfigure $server -translation binary
147
+ puts -nonewline $server $request
148
+ flush $server
149
+ set reply [read $server]
150
+ close $server
151
+ set end [string first "\r\n\r\n" $reply]
152
+ set header [split [string map {"\r\n" \n} \
153
+ [string range $reply 0 [expr {$end - 1}]]] \n]
154
+ set body [string range $reply [expr {$end + 4}] end]
155
+ set length [string length $body]
156
+ set half [expr {$length / 2}]
157
+ set cl [lsearch -regexp $header {(?i)^content-length:}]
158
+ set ct [lsearch -regexp $header {(?i)^content-type:}]
159
+ switch -- $name {
160
+ trunc {
161
+ set body [string range $body 0 [string last \n $body $half]]
162
+ }
163
+ content-length-negative {lset header $cl "Content-Length: -1"}
164
+ content-length-no-space {lset header $cl "Content-Length:$length"}
165
+ content-length-letters {lset header $cl "Content-Length: abc"}
166
+ content-length-huge {lset header $cl "Content-Length: 99999999999"}
167
+ content-length-overflow {
168
+ lset header $cl "Content-Length: 99999999999999999999999"
169
+ }
170
+ content-length-two-values {
171
+ lappend header "Content-Length: [expr {$length + 1}]"
172
+ }
173
+ content-length-repeated {lappend header "Content-Length: $length"}
174
+ content-length-folded {set header [linsert $header $cl+1 " 0"]}
175
+ content-type-no-space {
176
+ regexp {:\s*(.*)} [lindex $header $ct] -> type
177
+ lset header $ct "Content-Type:$type"
178
+ }
179
+ bytes-after-reply {
180
+ append body "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\njunk\n"
181
+ }
182
+ }
183
+ if {[string match chunk* $name] || $name eq "interim-100-continue" ||
184
+ $name eq "transfer-encoding-twice"} {
185
+ lset header $cl "Transfer-Encoding: chunked"
186
+ if {$name eq "transfer-encoding-twice"} {
187
+ lappend header "Transfer-Encoding: chunked"
188
+ }
189
+ set size $half
190
+ if {$name eq "chunk-short"} {incr size -1}
191
+ set first [format %x $size]
192
+ switch -- $name {
193
+ chunk-extension-empty {append first ";"}
194
+ chunk-size-cr {append first "\rX"}
195
+ chunk-size-nul {append first "\0"}
196
+ }
197
+ set last "0\r\n\r\n"
198
+ if {$name eq "chunk-no-final-crlf"} {set last "0\r\n"}
199
+ set body [string cat $first \r\n \
200
+ [string range $body 0 [expr {$half - 1}]] \r\n \
201
+ [format %x [expr {$length - $half}]] \r\n \
202
+ [string range $body $half end] \r\n $last]
203
+ }
204
+ if {$name eq "interim-100-continue"} {
205
+ puts -nonewline $chan "HTTP/1.1 100 Continue\r\n\r\n"
206
+ }
207
+ puts -nonewline $chan [join $header \r\n]\r\n\r\n$body
208
+}
209
+
210
+foreach {name expected} {
211
+ pass ^cloned$
212
+ trunc {response truncated}
213
+ content-length-negative {bad content-length}
214
+ content-length-no-space ^cloned$
215
+ content-length-letters {bad content-length}
216
+ content-length-huge {bad content-length}
217
+ content-length-overflow {bad content-length}
218
+ content-length-two-values {two different content-length values}
219
+ content-length-repeated ^cloned$
220
+ content-length-folded {folded header line}
221
+ content-type-no-space ^cloned$
222
+ chunked ^cloned$
223
+ chunk-short {no line end after chunk data}
224
+ interim-100-continue ^cloned$
225
+ transfer-encoding-twice {two transfer-encoding headers}
226
+ chunk-extension-empty {malformed chunk size line}
227
+ chunk-size-cr {malformed chunk size line}
228
+ chunk-no-final-crlf ^cloned$
229
+ bytes-after-reply ^cloned$
230
+} {
231
+ set port [http_listen [list http_proxy $name]]
232
+ test_match http-proxy-$name [http_clone http://127.0.0.1:$port/] $expected
233
+}
234
+# A chunk size line that ends in a zero byte is malformed. Fossil accepts
235
+# it and the clone succeeds.
236
+seame [http_clone http://127.0.0.1:%20repo HTTP/1.1} $proxy knownBug
237
+http_request_line http-rfc-proxy-path-utf8 http://localhost:9/répo \
238
+ {POST http://localhost:9/r%C3%A9po HTTP/1.1} $proxy knownBug
239
+
240
+# URLs with an upper-case scheme or host, a percent-encoded host, and a
241
+# file: URL with a space.
242
+#
243
+file copy r.fossil "my repo.fossil"
244
+foreach {name url} [list \
245
+ file-url-escaped-space file://[pwd]/my%20repo.fossil \
246
+ file-url-space "file://[pwd]/my repo.fossil" \
247
+ upper-case-scheme HTTP://127.0.0.1:$upstream/ \
248
+ upper-case-host http://LOCALHOST:$upstream/ \
249
+ percent-encoded-host http://loc%61lhost:$upstream/] {
250
+ test_eq http-rfc-$name [http_clone $url] cloned
251
+}
252
+
253
+# A redirect to a relative reference, which RFC 9110 section 10.2.2
254
+# allows in Location.
255
+#
256
+proc http_redirect {chan request} {
257
+ if {[string match "* /old *" [lindex [split $request \r] 0]]} {
258
+ puts -nonewline $chan "HTTP/1.1 302 Found\r\nLocation: /new\r\n"
259
+ puts -nonewline $chan "Content-Length: 0\r\nConnection: close\r\n\r\n"
260
+ } else {
261
+ puts -nonewline $chan "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n"
262
+ puts -nonewline $chan "Connection: close\r\n\r\nnew"
263
+ }
264
+}
265
+set port [http_listen http_redirect]
266
+# Fossil does not follow the relative Location: it fails with "unknown
267
+# repository: /new" and fetches notP/1.1} $proxy
268
+# Sent to a proxy, Fossil writes the space as "+" (POST
269
+# http://localhost:9/my%2Brepo HTTP/1.1) and encodes the "%" of each escape
270
+# of a UTF-8 byte again (POST http://localhost:9/r%25C3%25A9po HTTP/1.1).
271
+http_request_line http-rfc-proxy-path-space {http://localhost:9/my repo} \
272
+ {POST http://localhost:9/my%20repo HTTP/1.1} $proxy knownBug
273
+http_request_line http-rfc-proxy-path-utf8 http://localhost:9/répo \
274
+ {POST http://localhost:9/r%C3%A9po HTTP/1.1} $proxy knownBug
275
+
276
+# URLs with an upper-case scheme or host, a percent-encoded host, and a
277
+# file: URL with a space.
278
+#
279
+file copy r.fossil "my repo.fossil"
280
+foreach {name url} [list \
281
+ file-url-escaped-space file://[pwd]/my%20repo.fossil \
282
+ file-url-space "file://[pwd]/my repo.fossil" \
283
+ upper-case-scheme HTTP://127.0.0.1:$upstream/ \
284
+ upper-case-host http://LOCALHOST:$upstream/ \
285
+ percent-encoded-host http://loc%61lhost:$upstream/] {
286
+ test_eq http-rfc-$name [http_clone $url] cloned
287
+}
288
+
289
+# A redirect to a relative reference, which RFC 9110 section 10.2.2
290
+# allows in Location.
291
+#
292
+proc http_redirect {chan request} {
293
+ if {[string match "* /old *" [lindex [split $request \r] 0]]} {
294
+ puts -nonewline $chan "HTTP/1.1 302 Found\r\nLocation: /new\r\n"
295
+ puts -nonewline $chan "Content-Length: 0\r\nConnection: close\r\n\r\n"
296
+ } else {
297
+ puts -nonewline $chan "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n"
298
+ puts -nonewline $chan "Connection: close\r\n\r\nnew"
299
+ }
300
+}
301
+set port [http_listen http_redirect]
302
+# Fossil does not follow the relative Location: it fails with "unknown
303
+# repository: /new" and fetches nothing from /new.
304
+fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/old --out new.txt
305
+test_eq http-rfc-relative-redirect \
306
+ [expr {[file exists new.txt] ? [read_file new.txt] : ""}] new-reset-reason \
307
+ {![string match "*SSL connection*()*" $output]} knownBug
308
+}
309
+test_eq http-sigpipe-clone-after-failures \
310
+ [http_clone http://127.0.0.1:$upstream/] cloned
311
+
312
+# Users and passwords in the URL, in raw UTF-8 and percent-encoded, with
313
+# "fossil server --repolist", for a repository anonymous users cannot
314
+# read.
315
+#
316
+file mkdir repos
317
+file copy r.fossil repos/répo.fossil
318
+set repo repos/répo.fossil
319
+fossil user capabilities nobody "" -R $repo
320
+fossil user capabilities anonymous "" -R $repo
321
+fossil user new jérôme "" pässwörd -R $repo
322
+fossil user capabilities jérôme gio -R $repo
323
+fossil user new a@b:c "" p@ss:w/rd -R $repo
324
+fossil user capabilities a@b:c gio -R $repo
325
+set schemes [list http [http_server repos --repolist]]
326
+
327
+# Certificates signed by a private CA: for localhost, for another host,
328
+# for 127.0.0.1, for ::1, and for all of localhost, 127.0.0.1 and ::1.
329
+#
330
+if {$haveTls} {
331
+ if {[catch {
332
+ exec openssl req -x509 -newkey rsa:2048 -nodes -days 2 -subj /CN=TestCA \
333
+ -keyout ca.key -out ca.pem >& /dev/null
334
+ foreach {cert names} {
335
+ localhost DNS:localhost
336
+ otherhost DNS:otherhost
337
+ ip IP:127.0.0.1
338
+ ip6 IP:::1
339
+ all DNS:localhost,IP:127.0.0.1,IP:::1
340
+ } {
341
+ write_file $cert.ext subjectAltName=$names\n
342
+ exec openssl req -newkey rsa:2048 -nodes -subj /CN=$cert \
343
+ -keyout $cert.key -out $cert.csr >& /dev/null
344
+ exec openssl x509 -req -in $cert.csr -CA ca.pem -CAkey ca.key \
345
+ -CAcreateserial -days 2 -extfile $cert.ext -out $cert.pem \
346
+ >& /dev/null
347
+ }
348
+ } msg]} {
349
+ protOut "SKIPPED the HTTPS tests: openssl failed: $msg" 1
350
+ set haveTls 0
351
+ }
352
+}
353
+if {$haveTls} {
354
+ set ca [file join [pwd] ca.pem]
355
+ lappend schemes https [http_server repos --repolist --cert all.pem \
356
+ --pkey all.key]
357
+}
358
+
359
+# Test NAME passes when a clone of URL gives EXPECTED: "cloned", or
360
+# "failed" when fossil fails without leaving a repository.
361
+#
362
+proc http_expect {name url expected} {
363
+ set result [http_clone $url]
364
+ if {$result ne "cloned" && $::CODE == 1 && ![file exists c.fossil]} {
365
+ set result failed
366
+ }
367
+ test_eq $name $result $expected
368
+}
369
+if {$haveTls} {set env(SSL_CERT_FILE) $ca}
370
+foreach {scheme port} $schemes {
371
+ set host localhost:$port
372
+ http_expect http-userinfo-$scheme-raw-utf8 \
373
+ $scheme://jérôme:pässwörd@$host/répo cloned
374
+ http_expect http-userinfo-$scheme-percent-encoded-utf8 \
375
+ $scheme://j%C3%A9r%C3%B4me:p%C3%A4ssw%C3%B6rd@$host/répo cloned
376
+ http_expect http-userinfo-$scheme-percent-encoded-delimiters \
377
+ $scheme://a%40b%3Ac:p%40ss%3Aw%2Frd@$host/répo cloned
378
+ http_expect http-userinfo-$scheme-percent-encoded-path \
379
+ $scheme://jérôme:pässwörd@$host/r%C3%A9po cloned
380
+ http_expect http-userinfo-$scheme-wrong-password \
381
+ $scheme://jérôme:wrong@$host/répo failed
382
+ http_expect http-userinfo-$scheme-no-password \
383
+ $scheme://jérôme@$host/répo failed
384
+}
385
+unset -nocomplain env(SSL_CERT_FILE)
386
+
387
+# Returns the SHA-256 fingerprint of the certificate in the file CERT, as
388
+# fossil stores it.
389
+#
390
+proc http_fingerprint {cert} {
391
+ set line [exec openssl x509 -in $cert -noout -fingerprint -sha256]
392
+ return [string tolower [string map {: ""} [lindex [split $line =] 1]]]
393
+}
394
+
395
+# Makes fossil remember the certificate with FINGERPRINT as one it may
396
+# trust for HOST, or forget the certificate for HOST when FINGERPRINT is
397
+# empty. fossil keeps it as the global setting cert:HOST.
398
+#
399
+proc http_remember {host fingerprint} {
400
+ set config [file join $::env(FOSSIL_HOME) .fossil]
401
+ if {$fingerprint eq ""} {
402
+ fossil sqlite3 --no-repository $config \
403
+ "DELETE FROM global_config WHERE name='cert:$host'"
404
+ } else {
405
+ fossil sqlite3 --no-repository $config \
406
+ "REPLACE INTO global_config VALUES('cert:$host','$fingerprint')"
407
+ }
408
+}
409
+
410
+# Which certificates fossil trusts: an untrusted CA, a certificate for
411
+# another host, a CA trusted through SSL_CERT_FILE, SSL_CERT_DIR or the
412
+# ssl-ca-location setting, IP addresses in the certificate, a remembered
413
+# exception, an answer to the certificate prompt, and --accept-any-cert.
414
+#
415
+if {$haveTls} {
416
+ set localhostPort [http_server r.fossil --cert localhost.pem \
417
+ --pkey localhost.key]
418
+ set otherhostPort [http_server r.fossil --cert otherhost.pem \
419
+ --pkey otherhost.key]
420
+ set ipPort [http_server r.fossil --cert ip.pem --pkey ip.key]
421
+ set ip6Port [http_server r.fossil --cert ip6.pem --pkey ip6.key]
422
+ set localhost https://localhost:$localhostPort/
423
+ set otherhost https://localhost:$otherhostPort/
424
+ set declined {SSL cert declined}
425
+ test_match http-tls-ca-untrusted [http_clone $localhost] $declined
426
+ test_match http-tls-wrong-host [http_clone $otherhost] $declined
427
+ set env(SSL_CERT_FILE) $ca
428
+ test_eq http-tls-ssl-cert-file [http_clone $localhost] cloned
429
+ test_match http-tls-ssl-cert-file-wrong-host [http_clone $otherhost] \
430
+ $declined
431
+ test_eq http-tls-ip-in-certificate [http_clone https://127.0.0.1:$ipPort/] \
432
+ cloned
433
+ test_match http-tls-ip-not-in-certificate \
434
+ [http_clone https://127.0.0.1:$localhostPort/] $declined
435
+ if {$haveIpv6} {
436
+ test_eq http-tls-ipv6-in-certificate \
437
+ [http_clone https://\[::1\]:$ip6Port/] cloned
438
+ }
439
+ unset env(SSL_CERT_FILE)
440
+
441
+ file mkdir certdir
442
+ file copy ca.pem certdir
443
+ if {![catch {exec openssl rehash certdir >& /dev/null}]} {
444
+ set env(SSL_CERT_DIR) [file join [pwd] certdir]
445
+ test_eq http-tls-ssl-cert-dir [http_clone $localhost] cloned
446
+ unset env(SSL_CERT_DIR)
447
+ }
448
+ fossil settings -g ssl-ca-location $ca
449
+ test_eq http-tls-ssl-ca-location [http_clone $localhost] cloned
450
+ fossil unset -g ssl-ca-location
451
+
452
+ # A certificate that fossil has remembered does not need a CA.
453
+ set fingerprint [http_fingerprint localhost.pem]
454
+ http_remember localhost $fingerprint
455
+ test_eq http-tls-remembered-exception [http_clone $localhost] cloned
456
+ http_remember localhost 00$fingerprint
457
+ test_match http-tls-exception-wrong-fingerprint [http_clone $localhost] \
458
+ $declined
459
+ http_remember localhost ""
460
+ if {$haveIpv6} {
461
+ http_remember ::1 [http_fingerprint ip6.pem]
462
+ test_eq http-tls-remembered-exception-ipv6 \
463
+ [http_clone https://\[::1\]:$ip6Port/] cloned
464
+ http_remember ::1 ""
465
+ }
466
+
467
+ # The certificate prompt: accept once, accept and remember, and a
468
+ # fingerprint that is not the certificate's.
469
+ set httpAnswer "y\nn\n"
470
+ test_eq http-tls-prompt-yes [http_clone $localhost] cloned
471
+ set httpAnswer "$fingerprint\ny\n"
472
+ test_eq http-tls-prompt-fingerprint-remembered [http_clone $localhost] \
473
+ cloned
474
+ fossil sqlite3 --no-repository [file join $env(FOSSIL_HOME) .fossil] \
475
+ "SELECT value FROM global_config WHERE name='cert:localhost'"
476
+ test_eq http-tls-prompt-fingerprint-stored [normalize_result] $fingerprint
477
+ http_remember localhost ""
478
+ set httpAnswer "00$fingerprint\n"
479
+ test_match http-tls-prompt-wrong-fingerprint [http_clone $localhost] \
480
+ $declined
481
+ set httpAnswer ""
482
+ test_eq http-tls-accept-any-cert \
483
+ [http_clone $localhost --accept-any-cert] cloned
484
+}
485
+
486
+# HTTPS through http-relay.py, which ends the TLS session with or
487
+# without close_notify, and records the TLS server name fossil sends.
488
+# RFC 6066 section 3 requires the name without a trailing dot, and no
489
+# name for an IP address.
490
+#
491
+if {$haveTls && $havePython} {
492
+ set env(SSL_CERT_FILE) $ca
493
+ set pass [http_listen [list http_proxy pass]]
494
+ set rela this
495
+##############
496
+#
497
+# Test##########################
498
+#
499
+# Tests of fossil's HTTP and HTTPS client. A clServers [listoptions in ARGS, answering fossil's
500
+# prompts with the lines in httpAnswRuns fossil with ARGS and INPUT on its standard input, while the event
501
+# loop runs the servers in this file. Sets RESULT to fossil's output and
502
+# CODE to its exit status, the name of the signal that ended it, or
503
+# "timeout" if it ran for more than 60 seconds.
504
+#
505
+proc http_fossil {input args} {
506
+ global RESULT CODE LASTCMD
507
+ set LASTCMD [list $::fossilexe {*}$args]
508
+ protOut $LASTCMD
509
+ set chan [open |[concat $LASTCMD [list << $input 2>@1]] r]
510
+ fconfigure $chan -blocking 0
511
+ set ::httpOutput ""
512
+ set ::httpDone 0
513
+ fileevent $chan readable [list http_fossil_read $chan]
514
+ set timer [after 60000 {set ::httpDone timeout}]
515
+ vwait ::httpDone
516
+ after cancel $timer
517
+ if {$::httpDone eq "timeout"} {
518
+ catch {exec kill -KILL {*}[pid $chan]}
519
+ }
520
+ fconfigure $chan -blocking 1
521
+ set CODE 0
522
+ if {[catch {close $chan} msg options]} {
523
+ set CODE [lindex [dict get $options -errorcode] 2]
524
+ }
525
+ if {$::httpDone eq "timeout""
526
+ if {$::RESULT == httpOutput]
527
+}
528
+
529
+proc http_fossil_read {chan} {
530
+ append ::httpOutput [read $chan]
531
+ if {[eof $Answer. Returns "cloned" when the clone
532
+# is a complete copy of r.fossil. When fossil exits with status 1 and
533
+# does not leave c.fossil, returns its output, and otherwise says what
534
+# went wrong.
535
+#
536
+proc http_clone {url args} {
537
+ file delete c.fossil
538
+ fossil_raw -seconds 60 -input $::httpAnswer clone $url c.fossil {*}$args
539
+ set http_fossilLT]
540
+ if {$::CODE =if {$::RESULT == $::httpBlobs} {return cloned}
541
+ return "cloned $::RESULT of $::httpBlobs blobs"
542
+ }
543
+ if {$::CODE ne "1"} {return "exit $::CODE"}
544
+ if {[file exists c.fossil]} {return "c.fossil is left"}
545
+ return $::RESULT
546
+}
547
+
548
+# Listens on a port on 127.0.0.1 that the system chooses, and returns
549
+# the port. Calls HANDLER with each connection and the request on it,
550
+# once the whole request has arrived, and then closes the connection.
551
+#
552
+proc http_listen {handler} {
553
+ return [test_listen [list http_receive $handler]]
554
+}
555
+nfo exists env($var)]} {
556
+ [list http_accept $handler]-eval {hasfeature ssl}
557
+set haveTlshttp##########################
558
+#
559
+# Te#########
560
+proc http_accept {handler chan address port} {
561
+ fconfigure $chan -translation binary -blocking 0c http_redirect {cha($chan) ""connection over the loopback interface"
562
+proxy or#########################_CERT_FILE and SSL_CERT_DIR are unset until the end of
563
+# this file.
564
+#
565
+foreach var {SSL_CERT_FILE SSL_CERT_DIR} {
566
+ if {[info exists env($var)]} {
567
+ set httpSavedEnv($var) $env($var)
568
+ unset env($var)
569
+ }
570
+}
571
+test_setup ""
572
+fossil test-th-eval {hasfeature ssl}
573
+set haveTls [expr {[normalize_result] eq "1" && [auto_execok openssl] ne ""}]
574
+set havePython [expr {[auto_execok python3] ne ""}]
575
+set haveIpv6 [expr {![catch {close [socket -server list -myaddr ::1 0]}]}]
576
+set httpPids [list]
577
+set httpFossilServers [list]
578
+set httpAnswer ""
579
+
580
+# Clones URL into c.fossil with the options in ARGS, answering fossil's
581
+# prompts with the lines in httpAnswer. Returns "cloned" when the clone
582
+# is a complete copy of r.fossil. When fossil exits with status 1 and
583
+# does not leave c.fossil, returns its output, and otherwise says what
584
+# went wrong.
585
+#
586
+proc http_clone {url args} {
587
+ file delete c.fossil
588
+ fossil_raw -seconds 60 -input $::httpAnswer clone $url c.fossil {*}$args
589
+ set ::RESULT [string trim $::RESULT]
590
+ if {$::CODE == 0} {
591
+ fossil sql -R c.fossil "SELECT count(*) FROM blob"
--- a/test/http.test
+++ b/test/http.test
@@ -0,0 +1,591 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/http.test
+++ b/test/http.test
@@ -0,0 +1,591 @@
1 ###################Servers in this file send
2 # fossil replies that HTTP/1.1 allows, which must give a complete clone,
3 # and malformed replies, which must make the clone fail with a message
4 # and not leave a repository behind. Others########################
5 #
6 # Tts of fossil's HTTP and HTTPS client. A clone must work when the
7 # reply ihich certificates it trusts.
8 #
9 # The HTTPS tests need openssl and a fossil built with TLS support. The
10 # tests that reset a connection, and the HTTPS tests that check what
11 # fossil does with a reply, need python3 to run http-relay.py.
12 #
13
14 require_no_open_checkout
15
16 if {$::is_windows} {
17 test_skip "http.test stops its servers with kill"
18 }
19 if {![loopback_available]} {
20 test_skip "the tests need a TCP connection over the loopback interface"
21 proxy or#########################_CERT_FILE and SSL_CERT_DIR are unset until the end of
22 # this file.
23 #
24 foreach var {SSL_CERT_FILE SSL_CERT_DIR} {
25 if {[info exists env($var)]} {
26 set httpSavedEnv($var) $env($var)
27 unset env($var)
28 }
29 }
30 test_setup ""
31 fossil test-th-eval {hasfeature ssl}
32 set haveTls [expr {[normalize_result] eq "1" && [auto_execok openssl] ne ""}]
33 set havePython [expr {[auto_execok python3] ne ""}]
34 set haveIpv6 [expr {![catch {close [socket -server list -myaddr ::1 0]}]}]
35 set httpPids [list]
36 set httpFossilServers [list]
37 set httpAnswer ""
38
39 # Clones URL into c.fossil with the options in ARGS, answering fossil's
40 # prompts with the lines in httpAnswer. Returns "cloned" when the clone
41 # is a complete copy of r.fossil. When fossil exits with status 1 and
42 # does not leave c.fossil, returns its output, and otherwise says what
43 # went wrong.
44 #
45 proc http_clone {url args} {
46 file delete c.fossil
47 fossil_raw -seconds 60 -input $::httpAnswer clone $url c.fossil {*}$args
48 set ::RESULT [string trim $::RESULT]
49 if {$::CODE == 0} {
50 fossil sql -R c.fossil "SELECT count(*) FROM blob"
51 if {$::RESULT == $::httpBlobs} {return cloned}
52 return "cloned $::RESULT of $::httpBlobs blobs"
53 }
54 if {$::CODE ne "1"} {return "exit $::CODE"}
55 if {[file exists c.fossil]} {return "c.fossil is left"}
56 return $::RESULT
57 }
58
59 # Listens on a port on 127.0.0.1 that the system chooses, and returns
60 # the port. Calls HANDLER with each connection and the request on it,
61 # once the whole request has arrived, and then closes the connection.
62 #
63 proc http_listen {handler} {
64 return [test_listen [list http_receive $handler]]
65 }
66
67 proc http_receive {handler chan request} {
68 if {[string first "\r\n\r\n" $request] >= 0} {
69 {*}$handler $chan $request
70 }
71 }
72
73 proc http_listen_close {} {
74 set server [socket -server {apply {{chan address port} {close $chan}}} \
75 -myaddr 127.0.0.1 0]
76 lappend ::testListeners $server
77 return [lindex [fconfigure $server -sockname] 2]
78 }
79
80 # Starts http-relay.py with ARGS and returns the port it listens on. Its
81 # output goes to relay-PORT.log.
82 #
83 proc http_relay {args} {
84 set log relay-[getSeqNo].log
85 lappend ::httpPids {*}[exec python3 -I \
86 [file join $::testfiledir http-relay.py] {*}$args >& $log &]
87 for {set i 0} {$i < 100} {incr i} {
88 after 100
89 if {[regexp {listening (\d+)} [read_file $log] -> port]} {
90 file rename $log relay-$port.log
91 return $port
92 }
93 }
94 error "http-relay.py did not start: [read_file $log]"
95 }
96
97 # Returns the TLS server names that clients sent to the relay on PORT
98 # since the last call, sorted and without duplicates.
99 #
100 proc http_server_names {port} {
101 set names [regexp -all -inline -line {^SNI: .*$} \
102 [read_file relay-$port.log]]
103 set seen 0
104 if {[info exists ::httpNamesSeen($port)]} {set seen $::httpNamesSeen($port)}
105 set ::httpNamesSeen($port) [llength $names]
106 return [join [lsort -unique [lrange $names $seen end]] \n]
107 }
108
109 # Starts "fossil server" with the options in ARGS on REPOSITORY, and
110 # returns the port it listens on.
111 #
112 proc http_server {repository args} {
113 set server [test_start_server $repository "" {*}$args]
114 lappend ::httpFossilServers $server
115 return [lindex $server 1]
116 }
117
118 # A repository of eight check-ins, which anyone can clone. Each check-in
119 # adds a file of 20000 random characters, so that a clone takes several
120 # round trips and each reply is large enough to split.
121 #
122 fossil new r.fossil
123 fossil user capabilities nobody gio -R r.fossil
124 fossil settings backoffice-disable 1 -R r.fossil
125 file mkdir co
126 cd co
127 fossil open ../r.fossil
128 for {set i 1} {$i <= 8} {incr i} {
129 write_file f$i.txt [rand_str 20000]
130 fossil add f$i.txt
131 fossil commit -m "check-in $i"
132 }
133 fossil close
134 cd ..
135 fossil sql -R r.fossil "SELECT count(*) FROM blob"
136 set httpBlobs [normalize_result]
137 set upstream [http_server r.fossil]
138 set closePort [http_listen_close]
139
140 # Writes the reply of the fossil server to REQUEST to CHAN, with its
141 # framing changed as the test NAME says. RFC 9112 sections 6 and 7 say
142 # what HTTP/1.1 allows.
143 #
144 proc http_proxy {name chan request} {
145 set server [socket 127.0.0.1 $::upstream]
146 fconfigure $server -translation binary
147 puts -nonewline $server $request
148 flush $server
149 set reply [read $server]
150 close $server
151 set end [string first "\r\n\r\n" $reply]
152 set header [split [string map {"\r\n" \n} \
153 [string range $reply 0 [expr {$end - 1}]]] \n]
154 set body [string range $reply [expr {$end + 4}] end]
155 set length [string length $body]
156 set half [expr {$length / 2}]
157 set cl [lsearch -regexp $header {(?i)^content-length:}]
158 set ct [lsearch -regexp $header {(?i)^content-type:}]
159 switch -- $name {
160 trunc {
161 set body [string range $body 0 [string last \n $body $half]]
162 }
163 content-length-negative {lset header $cl "Content-Length: -1"}
164 content-length-no-space {lset header $cl "Content-Length:$length"}
165 content-length-letters {lset header $cl "Content-Length: abc"}
166 content-length-huge {lset header $cl "Content-Length: 99999999999"}
167 content-length-overflow {
168 lset header $cl "Content-Length: 99999999999999999999999"
169 }
170 content-length-two-values {
171 lappend header "Content-Length: [expr {$length + 1}]"
172 }
173 content-length-repeated {lappend header "Content-Length: $length"}
174 content-length-folded {set header [linsert $header $cl+1 " 0"]}
175 content-type-no-space {
176 regexp {:\s*(.*)} [lindex $header $ct] -> type
177 lset header $ct "Content-Type:$type"
178 }
179 bytes-after-reply {
180 append body "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\njunk\n"
181 }
182 }
183 if {[string match chunk* $name] || $name eq "interim-100-continue" ||
184 $name eq "transfer-encoding-twice"} {
185 lset header $cl "Transfer-Encoding: chunked"
186 if {$name eq "transfer-encoding-twice"} {
187 lappend header "Transfer-Encoding: chunked"
188 }
189 set size $half
190 if {$name eq "chunk-short"} {incr size -1}
191 set first [format %x $size]
192 switch -- $name {
193 chunk-extension-empty {append first ";"}
194 chunk-size-cr {append first "\rX"}
195 chunk-size-nul {append first "\0"}
196 }
197 set last "0\r\n\r\n"
198 if {$name eq "chunk-no-final-crlf"} {set last "0\r\n"}
199 set body [string cat $first \r\n \
200 [string range $body 0 [expr {$half - 1}]] \r\n \
201 [format %x [expr {$length - $half}]] \r\n \
202 [string range $body $half end] \r\n $last]
203 }
204 if {$name eq "interim-100-continue"} {
205 puts -nonewline $chan "HTTP/1.1 100 Continue\r\n\r\n"
206 }
207 puts -nonewline $chan [join $header \r\n]\r\n\r\n$body
208 }
209
210 foreach {name expected} {
211 pass ^cloned$
212 trunc {response truncated}
213 content-length-negative {bad content-length}
214 content-length-no-space ^cloned$
215 content-length-letters {bad content-length}
216 content-length-huge {bad content-length}
217 content-length-overflow {bad content-length}
218 content-length-two-values {two different content-length values}
219 content-length-repeated ^cloned$
220 content-length-folded {folded header line}
221 content-type-no-space ^cloned$
222 chunked ^cloned$
223 chunk-short {no line end after chunk data}
224 interim-100-continue ^cloned$
225 transfer-encoding-twice {two transfer-encoding headers}
226 chunk-extension-empty {malformed chunk size line}
227 chunk-size-cr {malformed chunk size line}
228 chunk-no-final-crlf ^cloned$
229 bytes-after-reply ^cloned$
230 } {
231 set port [http_listen [list http_proxy $name]]
232 test_match http-proxy-$name [http_clone http://127.0.0.1:$port/] $expected
233 }
234 # A chunk size line that ends in a zero byte is malformed. Fossil accepts
235 # it and the clone succeeds.
236 seame [http_clone http://127.0.0.1:%20repo HTTP/1.1} $proxy knownBug
237 http_request_line http-rfc-proxy-path-utf8 http://localhost:9/répo \
238 {POST http://localhost:9/r%C3%A9po HTTP/1.1} $proxy knownBug
239
240 # URLs with an upper-case scheme or host, a percent-encoded host, and a
241 # file: URL with a space.
242 #
243 file copy r.fossil "my repo.fossil"
244 foreach {name url} [list \
245 file-url-escaped-space file://[pwd]/my%20repo.fossil \
246 file-url-space "file://[pwd]/my repo.fossil" \
247 upper-case-scheme HTTP://127.0.0.1:$upstream/ \
248 upper-case-host http://LOCALHOST:$upstream/ \
249 percent-encoded-host http://loc%61lhost:$upstream/] {
250 test_eq http-rfc-$name [http_clone $url] cloned
251 }
252
253 # A redirect to a relative reference, which RFC 9110 section 10.2.2
254 # allows in Location.
255 #
256 proc http_redirect {chan request} {
257 if {[string match "* /old *" [lindex [split $request \r] 0]]} {
258 puts -nonewline $chan "HTTP/1.1 302 Found\r\nLocation: /new\r\n"
259 puts -nonewline $chan "Content-Length: 0\r\nConnection: close\r\n\r\n"
260 } else {
261 puts -nonewline $chan "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n"
262 puts -nonewline $chan "Connection: close\r\n\r\nnew"
263 }
264 }
265 set port [http_listen http_redirect]
266 # Fossil does not follow the relative Location: it fails with "unknown
267 # repository: /new" and fetches notP/1.1} $proxy
268 # Sent to a proxy, Fossil writes the space as "+" (POST
269 # http://localhost:9/my%2Brepo HTTP/1.1) and encodes the "%" of each escape
270 # of a UTF-8 byte again (POST http://localhost:9/r%25C3%25A9po HTTP/1.1).
271 http_request_line http-rfc-proxy-path-space {http://localhost:9/my repo} \
272 {POST http://localhost:9/my%20repo HTTP/1.1} $proxy knownBug
273 http_request_line http-rfc-proxy-path-utf8 http://localhost:9/répo \
274 {POST http://localhost:9/r%C3%A9po HTTP/1.1} $proxy knownBug
275
276 # URLs with an upper-case scheme or host, a percent-encoded host, and a
277 # file: URL with a space.
278 #
279 file copy r.fossil "my repo.fossil"
280 foreach {name url} [list \
281 file-url-escaped-space file://[pwd]/my%20repo.fossil \
282 file-url-space "file://[pwd]/my repo.fossil" \
283 upper-case-scheme HTTP://127.0.0.1:$upstream/ \
284 upper-case-host http://LOCALHOST:$upstream/ \
285 percent-encoded-host http://loc%61lhost:$upstream/] {
286 test_eq http-rfc-$name [http_clone $url] cloned
287 }
288
289 # A redirect to a relative reference, which RFC 9110 section 10.2.2
290 # allows in Location.
291 #
292 proc http_redirect {chan request} {
293 if {[string match "* /old *" [lindex [split $request \r] 0]]} {
294 puts -nonewline $chan "HTTP/1.1 302 Found\r\nLocation: /new\r\n"
295 puts -nonewline $chan "Content-Length: 0\r\nConnection: close\r\n\r\n"
296 } else {
297 puts -nonewline $chan "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n"
298 puts -nonewline $chan "Connection: close\r\n\r\nnew"
299 }
300 }
301 set port [http_listen http_redirect]
302 # Fossil does not follow the relative Location: it fails with "unknown
303 # repository: /new" and fetches nothing from /new.
304 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/old --out new.txt
305 test_eq http-rfc-relative-redirect \
306 [expr {[file exists new.txt] ? [read_file new.txt] : ""}] new-reset-reason \
307 {![string match "*SSL connection*()*" $output]} knownBug
308 }
309 test_eq http-sigpipe-clone-after-failures \
310 [http_clone http://127.0.0.1:$upstream/] cloned
311
312 # Users and passwords in the URL, in raw UTF-8 and percent-encoded, with
313 # "fossil server --repolist", for a repository anonymous users cannot
314 # read.
315 #
316 file mkdir repos
317 file copy r.fossil repos/répo.fossil
318 set repo repos/répo.fossil
319 fossil user capabilities nobody "" -R $repo
320 fossil user capabilities anonymous "" -R $repo
321 fossil user new jérôme "" pässwörd -R $repo
322 fossil user capabilities jérôme gio -R $repo
323 fossil user new a@b:c "" p@ss:w/rd -R $repo
324 fossil user capabilities a@b:c gio -R $repo
325 set schemes [list http [http_server repos --repolist]]
326
327 # Certificates signed by a private CA: for localhost, for another host,
328 # for 127.0.0.1, for ::1, and for all of localhost, 127.0.0.1 and ::1.
329 #
330 if {$haveTls} {
331 if {[catch {
332 exec openssl req -x509 -newkey rsa:2048 -nodes -days 2 -subj /CN=TestCA \
333 -keyout ca.key -out ca.pem >& /dev/null
334 foreach {cert names} {
335 localhost DNS:localhost
336 otherhost DNS:otherhost
337 ip IP:127.0.0.1
338 ip6 IP:::1
339 all DNS:localhost,IP:127.0.0.1,IP:::1
340 } {
341 write_file $cert.ext subjectAltName=$names\n
342 exec openssl req -newkey rsa:2048 -nodes -subj /CN=$cert \
343 -keyout $cert.key -out $cert.csr >& /dev/null
344 exec openssl x509 -req -in $cert.csr -CA ca.pem -CAkey ca.key \
345 -CAcreateserial -days 2 -extfile $cert.ext -out $cert.pem \
346 >& /dev/null
347 }
348 } msg]} {
349 protOut "SKIPPED the HTTPS tests: openssl failed: $msg" 1
350 set haveTls 0
351 }
352 }
353 if {$haveTls} {
354 set ca [file join [pwd] ca.pem]
355 lappend schemes https [http_server repos --repolist --cert all.pem \
356 --pkey all.key]
357 }
358
359 # Test NAME passes when a clone of URL gives EXPECTED: "cloned", or
360 # "failed" when fossil fails without leaving a repository.
361 #
362 proc http_expect {name url expected} {
363 set result [http_clone $url]
364 if {$result ne "cloned" && $::CODE == 1 && ![file exists c.fossil]} {
365 set result failed
366 }
367 test_eq $name $result $expected
368 }
369 if {$haveTls} {set env(SSL_CERT_FILE) $ca}
370 foreach {scheme port} $schemes {
371 set host localhost:$port
372 http_expect http-userinfo-$scheme-raw-utf8 \
373 $scheme://jérôme:pässwörd@$host/répo cloned
374 http_expect http-userinfo-$scheme-percent-encoded-utf8 \
375 $scheme://j%C3%A9r%C3%B4me:p%C3%A4ssw%C3%B6rd@$host/répo cloned
376 http_expect http-userinfo-$scheme-percent-encoded-delimiters \
377 $scheme://a%40b%3Ac:p%40ss%3Aw%2Frd@$host/répo cloned
378 http_expect http-userinfo-$scheme-percent-encoded-path \
379 $scheme://jérôme:pässwörd@$host/r%C3%A9po cloned
380 http_expect http-userinfo-$scheme-wrong-password \
381 $scheme://jérôme:wrong@$host/répo failed
382 http_expect http-userinfo-$scheme-no-password \
383 $scheme://jérôme@$host/répo failed
384 }
385 unset -nocomplain env(SSL_CERT_FILE)
386
387 # Returns the SHA-256 fingerprint of the certificate in the file CERT, as
388 # fossil stores it.
389 #
390 proc http_fingerprint {cert} {
391 set line [exec openssl x509 -in $cert -noout -fingerprint -sha256]
392 return [string tolower [string map {: ""} [lindex [split $line =] 1]]]
393 }
394
395 # Makes fossil remember the certificate with FINGERPRINT as one it may
396 # trust for HOST, or forget the certificate for HOST when FINGERPRINT is
397 # empty. fossil keeps it as the global setting cert:HOST.
398 #
399 proc http_remember {host fingerprint} {
400 set config [file join $::env(FOSSIL_HOME) .fossil]
401 if {$fingerprint eq ""} {
402 fossil sqlite3 --no-repository $config \
403 "DELETE FROM global_config WHERE name='cert:$host'"
404 } else {
405 fossil sqlite3 --no-repository $config \
406 "REPLACE INTO global_config VALUES('cert:$host','$fingerprint')"
407 }
408 }
409
410 # Which certificates fossil trusts: an untrusted CA, a certificate for
411 # another host, a CA trusted through SSL_CERT_FILE, SSL_CERT_DIR or the
412 # ssl-ca-location setting, IP addresses in the certificate, a remembered
413 # exception, an answer to the certificate prompt, and --accept-any-cert.
414 #
415 if {$haveTls} {
416 set localhostPort [http_server r.fossil --cert localhost.pem \
417 --pkey localhost.key]
418 set otherhostPort [http_server r.fossil --cert otherhost.pem \
419 --pkey otherhost.key]
420 set ipPort [http_server r.fossil --cert ip.pem --pkey ip.key]
421 set ip6Port [http_server r.fossil --cert ip6.pem --pkey ip6.key]
422 set localhost https://localhost:$localhostPort/
423 set otherhost https://localhost:$otherhostPort/
424 set declined {SSL cert declined}
425 test_match http-tls-ca-untrusted [http_clone $localhost] $declined
426 test_match http-tls-wrong-host [http_clone $otherhost] $declined
427 set env(SSL_CERT_FILE) $ca
428 test_eq http-tls-ssl-cert-file [http_clone $localhost] cloned
429 test_match http-tls-ssl-cert-file-wrong-host [http_clone $otherhost] \
430 $declined
431 test_eq http-tls-ip-in-certificate [http_clone https://127.0.0.1:$ipPort/] \
432 cloned
433 test_match http-tls-ip-not-in-certificate \
434 [http_clone https://127.0.0.1:$localhostPort/] $declined
435 if {$haveIpv6} {
436 test_eq http-tls-ipv6-in-certificate \
437 [http_clone https://\[::1\]:$ip6Port/] cloned
438 }
439 unset env(SSL_CERT_FILE)
440
441 file mkdir certdir
442 file copy ca.pem certdir
443 if {![catch {exec openssl rehash certdir >& /dev/null}]} {
444 set env(SSL_CERT_DIR) [file join [pwd] certdir]
445 test_eq http-tls-ssl-cert-dir [http_clone $localhost] cloned
446 unset env(SSL_CERT_DIR)
447 }
448 fossil settings -g ssl-ca-location $ca
449 test_eq http-tls-ssl-ca-location [http_clone $localhost] cloned
450 fossil unset -g ssl-ca-location
451
452 # A certificate that fossil has remembered does not need a CA.
453 set fingerprint [http_fingerprint localhost.pem]
454 http_remember localhost $fingerprint
455 test_eq http-tls-remembered-exception [http_clone $localhost] cloned
456 http_remember localhost 00$fingerprint
457 test_match http-tls-exception-wrong-fingerprint [http_clone $localhost] \
458 $declined
459 http_remember localhost ""
460 if {$haveIpv6} {
461 http_remember ::1 [http_fingerprint ip6.pem]
462 test_eq http-tls-remembered-exception-ipv6 \
463 [http_clone https://\[::1\]:$ip6Port/] cloned
464 http_remember ::1 ""
465 }
466
467 # The certificate prompt: accept once, accept and remember, and a
468 # fingerprint that is not the certificate's.
469 set httpAnswer "y\nn\n"
470 test_eq http-tls-prompt-yes [http_clone $localhost] cloned
471 set httpAnswer "$fingerprint\ny\n"
472 test_eq http-tls-prompt-fingerprint-remembered [http_clone $localhost] \
473 cloned
474 fossil sqlite3 --no-repository [file join $env(FOSSIL_HOME) .fossil] \
475 "SELECT value FROM global_config WHERE name='cert:localhost'"
476 test_eq http-tls-prompt-fingerprint-stored [normalize_result] $fingerprint
477 http_remember localhost ""
478 set httpAnswer "00$fingerprint\n"
479 test_match http-tls-prompt-wrong-fingerprint [http_clone $localhost] \
480 $declined
481 set httpAnswer ""
482 test_eq http-tls-accept-any-cert \
483 [http_clone $localhost --accept-any-cert] cloned
484 }
485
486 # HTTPS through http-relay.py, which ends the TLS session with or
487 # without close_notify, and records the TLS server name fossil sends.
488 # RFC 6066 section 3 requires the name without a trailing dot, and no
489 # name for an IP address.
490 #
491 if {$haveTls && $havePython} {
492 set env(SSL_CERT_FILE) $ca
493 set pass [http_listen [list http_proxy pass]]
494 set rela this
495 ##############
496 #
497 # Test##########################
498 #
499 # Tests of fossil's HTTP and HTTPS client. A clServers [listoptions in ARGS, answering fossil's
500 # prompts with the lines in httpAnswRuns fossil with ARGS and INPUT on its standard input, while the event
501 # loop runs the servers in this file. Sets RESULT to fossil's output and
502 # CODE to its exit status, the name of the signal that ended it, or
503 # "timeout" if it ran for more than 60 seconds.
504 #
505 proc http_fossil {input args} {
506 global RESULT CODE LASTCMD
507 set LASTCMD [list $::fossilexe {*}$args]
508 protOut $LASTCMD
509 set chan [open |[concat $LASTCMD [list << $input 2>@1]] r]
510 fconfigure $chan -blocking 0
511 set ::httpOutput ""
512 set ::httpDone 0
513 fileevent $chan readable [list http_fossil_read $chan]
514 set timer [after 60000 {set ::httpDone timeout}]
515 vwait ::httpDone
516 after cancel $timer
517 if {$::httpDone eq "timeout"} {
518 catch {exec kill -KILL {*}[pid $chan]}
519 }
520 fconfigure $chan -blocking 1
521 set CODE 0
522 if {[catch {close $chan} msg options]} {
523 set CODE [lindex [dict get $options -errorcode] 2]
524 }
525 if {$::httpDone eq "timeout""
526 if {$::RESULT == httpOutput]
527 }
528
529 proc http_fossil_read {chan} {
530 append ::httpOutput [read $chan]
531 if {[eof $Answer. Returns "cloned" when the clone
532 # is a complete copy of r.fossil. When fossil exits with status 1 and
533 # does not leave c.fossil, returns its output, and otherwise says what
534 # went wrong.
535 #
536 proc http_clone {url args} {
537 file delete c.fossil
538 fossil_raw -seconds 60 -input $::httpAnswer clone $url c.fossil {*}$args
539 set http_fossilLT]
540 if {$::CODE =if {$::RESULT == $::httpBlobs} {return cloned}
541 return "cloned $::RESULT of $::httpBlobs blobs"
542 }
543 if {$::CODE ne "1"} {return "exit $::CODE"}
544 if {[file exists c.fossil]} {return "c.fossil is left"}
545 return $::RESULT
546 }
547
548 # Listens on a port on 127.0.0.1 that the system chooses, and returns
549 # the port. Calls HANDLER with each connection and the request on it,
550 # once the whole request has arrived, and then closes the connection.
551 #
552 proc http_listen {handler} {
553 return [test_listen [list http_receive $handler]]
554 }
555 nfo exists env($var)]} {
556 [list http_accept $handler]-eval {hasfeature ssl}
557 set haveTlshttp##########################
558 #
559 # Te#########
560 proc http_accept {handler chan address port} {
561 fconfigure $chan -translation binary -blocking 0c http_redirect {cha($chan) ""connection over the loopback interface"
562 proxy or#########################_CERT_FILE and SSL_CERT_DIR are unset until the end of
563 # this file.
564 #
565 foreach var {SSL_CERT_FILE SSL_CERT_DIR} {
566 if {[info exists env($var)]} {
567 set httpSavedEnv($var) $env($var)
568 unset env($var)
569 }
570 }
571 test_setup ""
572 fossil test-th-eval {hasfeature ssl}
573 set haveTls [expr {[normalize_result] eq "1" && [auto_execok openssl] ne ""}]
574 set havePython [expr {[auto_execok python3] ne ""}]
575 set haveIpv6 [expr {![catch {close [socket -server list -myaddr ::1 0]}]}]
576 set httpPids [list]
577 set httpFossilServers [list]
578 set httpAnswer ""
579
580 # Clones URL into c.fossil with the options in ARGS, answering fossil's
581 # prompts with the lines in httpAnswer. Returns "cloned" when the clone
582 # is a complete copy of r.fossil. When fossil exits with status 1 and
583 # does not leave c.fossil, returns its output, and otherwise says what
584 # went wrong.
585 #
586 proc http_clone {url args} {
587 file delete c.fossil
588 fossil_raw -seconds 60 -input $::httpAnswer clone $url c.fossil {*}$args
589 set ::RESULT [string trim $::RESULT]
590 if {$::CODE == 0} {
591 fossil sql -R c.fossil "SELECT count(*) FROM blob"
--- a/test/integrity.test
+++ b/test/integrity.test
@@ -0,0 +1,31 @@
1
+#
2
+# Tests thatf damage made withand a "fossil nstruct" and "fossil
3
+# keep every (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime
4
+ FROM plink ORDER BY 2, 3;
5
+SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid),
6
+ (SELECT uuid FROM blob WHERE rid=fid),
7
+ (SELECT uuid FROM blob WHERE rid=pid),
8
+ (SELECT name FROM filename WHERE fnid=mlink.fnid),
9
+ (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux
10
+ FROM mlink ORDER BY 2, 5, 3, 4;
11
+SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid),
12
+ tagtype, (SELECT uuid FROM blob WHERE rid=srcid),
13
+ (SELECT uuid FROM blob WHERE rid=origid), value, mtime,
14
+ (SELECT uuid FROM blob WHERE rid=tagxref.rid)
15
+ FROM tagxref ORDER BY 2, 8, 3;
16
+SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid)
17
+ FROM leaf ORDER BY 2;
18
+SELECT 'filename', name FROM filename ORDER BY 2;
19
+SELECT 'tag', tagname FROM tag
20
+ WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2;
21
+SELECT 'backlink', target, srctype,
22
+ (SELECT uuid FROM blob WHERE rid=srcid), mtime
23
+ FROM backlink ORDER BY 2, 4;
24
+SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user
25
+ FROM attachment ORDER BY 3, 4;
26
+}
27
+
28
+# Returns the derived tables of repository REPO as such text.
29
+#
30
+proc integrity_derived {repo} {
31
+ fo
--- a/test/integrity.test
+++ b/test/integrity.test
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/integrity.test
+++ b/test/integrity.test
@@ -0,0 +1,31 @@
1 #
2 # Tests thatf damage made withand a "fossil nstruct" and "fossil
3 # keep every (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime
4 FROM plink ORDER BY 2, 3;
5 SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid),
6 (SELECT uuid FROM blob WHERE rid=fid),
7 (SELECT uuid FROM blob WHERE rid=pid),
8 (SELECT name FROM filename WHERE fnid=mlink.fnid),
9 (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux
10 FROM mlink ORDER BY 2, 5, 3, 4;
11 SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid),
12 tagtype, (SELECT uuid FROM blob WHERE rid=srcid),
13 (SELECT uuid FROM blob WHERE rid=origid), value, mtime,
14 (SELECT uuid FROM blob WHERE rid=tagxref.rid)
15 FROM tagxref ORDER BY 2, 8, 3;
16 SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid)
17 FROM leaf ORDER BY 2;
18 SELECT 'filename', name FROM filename ORDER BY 2;
19 SELECT 'tag', tagname FROM tag
20 WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2;
21 SELECT 'backlink', target, srctype,
22 (SELECT uuid FROM blob WHERE rid=srcid), mtime
23 FROM backlink ORDER BY 2, 4;
24 SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user
25 FROM attachment ORDER BY 3, 4;
26 }
27
28 # Returns the derived tables of repository REPO as such text.
29 #
30 proc integrity_derived {repo} {
31 fo
--- test/merge_warn.test
+++ test/merge_warn.test
@@ -34,10 +34,16 @@
3434
commit_file f4 "f4" "add f4"
3535
3636
fossil update trunk
3737
write_file f1 "f1.1"
3838
write_file f3 "f3.1"
39
+
40
+# "fossil merge --dry-run" must not change the check-out.
41
+fossil merge --dry-run --integrate mrg -expectError
42
+test_eq merge_warn-dry-run-files [glob -nocomplain f3*] f3 knownBug
43
+test_eq merge_warn-dry-run-content [read_file f3] f3.1
44
+
3945
fossil merge --integrate mrg -expectError
4046
test_status_list merge_warn-1 $RESULT {
4147
WARNING: 1 unmanaged files were overwritten
4248
WARNING: 2 merge conflicts
4349
DELETE f1
4450
4551
ADDED test/sync.test
--- test/merge_warn.test
+++ test/merge_warn.test
@@ -34,10 +34,16 @@
34 commit_file f4 "f4" "add f4"
35
36 fossil update trunk
37 write_file f1 "f1.1"
38 write_file f3 "f3.1"
 
 
 
 
 
 
39 fossil merge --integrate mrg -expectError
40 test_status_list merge_warn-1 $RESULT {
41 WARNING: 1 unmanaged files were overwritten
42 WARNING: 2 merge conflicts
43 DELETE f1
44
45 DDED test/sync.test
--- test/merge_warn.test
+++ test/merge_warn.test
@@ -34,10 +34,16 @@
34 commit_file f4 "f4" "add f4"
35
36 fossil update trunk
37 write_file f1 "f1.1"
38 write_file f3 "f3.1"
39
40 # "fossil merge --dry-run" must not change the check-out.
41 fossil merge --dry-run --integrate mrg -expectError
42 test_eq merge_warn-dry-run-files [glob -nocomplain f3*] f3 knownBug
43 test_eq merge_warn-dry-run-content [read_file f3] f3.1
44
45 fossil merge --integrate mrg -expectError
46 test_status_list merge_warn-1 $RESULT {
47 WARNING: 1 unmanaged files were overwritten
48 WARNING: 2 merge conflicts
49 DELETE f1
50
51 DDED test/sync.test
--- a/test/sync.test
+++ b/test/sync.test
@@ -0,0 +1,56 @@
1
+#
2
+# Tests of clone, push, pull and sync, over file: URLs and over HTTP to
3
+# "fossil server". After each operation, the repositories must hold the
4
+# same artifacts, except for private ones, and pass "fowith -assurance stress"
5
+}
6
+
7
+require_no_open_checkout
8
+
9
+test_setup ""
10
+set dir [pwd]
11
+set ::env(FOSSIL_USER) tester
12
+
13
+# Returns the hashes of the artifacts in repository REPO that are
14
+# neither phantoms nor private, in order.
15
+#
16
+proc sync_artifacts {repo} {
17
+ fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0\
18
+ AND rid NOT IN private ORDER BY uuid"
19
+ return [normalize_result]
20
+}
21
+
22
+# Returns the hashes of the check-ins in repository REPO that are not
23
+# private, in order.
24
+#
25
+proc sync_checkins {repo} {
26
+ fossil sql -R $repo "SELECT uuid FROM blob JOIN event ON objid=rid\
27
+ WHERE type='ci' AND rid NOT IN private\
28
+ ORDER BY uuid"
29
+ return [normalize_result]
30
+}
31
+
32
+# Returns the number of private artifacts in repository REPO.
33
+#
34
+proc sync_private_count {repo} {
35
+ fossil sql -R $repo "SELECT count(*) FROM private"
36
+ return [normalize_result]
37
+}
38
+
39
+# Test NAME passes when "fossil test-integrity" finds no problems in
40
+# repository REPO.
41
+#
42
+proc sync_test_integrity {name repo} {
43
+ fossil test-integrity -R $repo
44
+ test_match $name [normalize_result] {checked: 0 errors}
45
+}
46
+
47
+# Commits a change to FILE in check-out DIR, with the comment COMMENT
48
+# and the extra commit options in ARGS.
49
+#
50
+proc sync_commit {dir file comment args} {
51
+ write_file [file join $dir $file] "$comment\n"
52
+ fossil add $file --chdir $dir
53
+ fossil commit -m $comment N bytes of deterministic}
54
+
55
+write_file $syncWrapper "#!/bin/sh\n: >\"\$3\"\n"
56
+ file attributes $sy
--- a/test/sync.test
+++ b/test/sync.test
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/sync.test
+++ b/test/sync.test
@@ -0,0 +1,56 @@
1 #
2 # Tests of clone, push, pull and sync, over file: URLs and over HTTP to
3 # "fossil server". After each operation, the repositories must hold the
4 # same artifacts, except for private ones, and pass "fowith -assurance stress"
5 }
6
7 require_no_open_checkout
8
9 test_setup ""
10 set dir [pwd]
11 set ::env(FOSSIL_USER) tester
12
13 # Returns the hashes of the artifacts in repository REPO that are
14 # neither phantoms nor private, in order.
15 #
16 proc sync_artifacts {repo} {
17 fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0\
18 AND rid NOT IN private ORDER BY uuid"
19 return [normalize_result]
20 }
21
22 # Returns the hashes of the check-ins in repository REPO that are not
23 # private, in order.
24 #
25 proc sync_checkins {repo} {
26 fossil sql -R $repo "SELECT uuid FROM blob JOIN event ON objid=rid\
27 WHERE type='ci' AND rid NOT IN private\
28 ORDER BY uuid"
29 return [normalize_result]
30 }
31
32 # Returns the number of private artifacts in repository REPO.
33 #
34 proc sync_private_count {repo} {
35 fossil sql -R $repo "SELECT count(*) FROM private"
36 return [normalize_result]
37 }
38
39 # Test NAME passes when "fossil test-integrity" finds no problems in
40 # repository REPO.
41 #
42 proc sync_test_integrity {name repo} {
43 fossil test-integrity -R $repo
44 test_match $name [normalize_result] {checked: 0 errors}
45 }
46
47 # Commits a change to FILE in check-out DIR, with the comment COMMENT
48 # and the extra commit options in ARGS.
49 #
50 proc sync_commit {dir file comment args} {
51 write_file [file join $dir $file] "$comment\n"
52 fossil add $file --chdir $dir
53 fossil commit -m $comment N bytes of deterministic}
54
55 write_file $syncWrapper "#!/bin/sh\n: >\"\$3\"\n"
56 file attributes $sy
--- test/update.test
+++ test/update.test
@@ -235,9 +235,22 @@
235235
write_seq_to_file "$fname"
236236
fossil add "$fname"
237237
fossil commit -m "Add $fname"
238238
fossil up previous
239239
test_update $testname $message $changes
240
+
241
+# "fossil update --dry-run" must not change the check-out, even where the
242
+# update would overwrite an unmanaged file.
243
+set testname "dry-run"
244
+set fname [test_update_setup $testname]
245
+write_seq_to_file $fname
246
+fossil add $fname
247
+fossil commit -m "Add $fname"
248
+fossil up previous
249
+write_file $fname "unmanaged\n"
250
+fossil update --dry-run -expectError
251
+test_eq update-dry-run-files [glob -nocomplain $fname*] $fname knownBug
252
+test_eq update-dry-run-content [read_file $fname] "unmanaged\n"
240253
241254
###############################################################################
242255
243256
test_cleanup
244257
--- test/update.test
+++ test/update.test
@@ -235,9 +235,22 @@
235 write_seq_to_file "$fname"
236 fossil add "$fname"
237 fossil commit -m "Add $fname"
238 fossil up previous
239 test_update $testname $message $changes
 
 
 
 
 
 
 
 
 
 
 
 
 
240
241 ###############################################################################
242
243 test_cleanup
244
--- test/update.test
+++ test/update.test
@@ -235,9 +235,22 @@
235 write_seq_to_file "$fname"
236 fossil add "$fname"
237 fossil commit -m "Add $fname"
238 fossil up previous
239 test_update $testname $message $changes
240
241 # "fossil update --dry-run" must not change the check-out, even where the
242 # update would overwrite an unmanaged file.
243 set testname "dry-run"
244 set fname [test_update_setup $testname]
245 write_seq_to_file $fname
246 fossil add $fname
247 fossil commit -m "Add $fname"
248 fossil up previous
249 write_file $fname "unmanaged\n"
250 fossil update --dry-run -expectError
251 test_eq update-dry-run-files [glob -nocomplain $fname*] $fname knownBug
252 test_eq update-dry-run-content [read_file $fname] "unmanaged\n"
253
254 ###############################################################################
255
256 test_cleanup
257

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button