Fossil SCM

fossil-scm / test / xfer-client.test
Blame History Raw 869 lines
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
# Replies that a server would not normally give, sent to the client side
15
# of the sync protocol. The client must handle each as documented and
16
# must not crash. There is no server: "fossil pull" and "fossil push"
17
# get standin/transport.sh as their --transport-command. It saves each
18
# request and answers with a reply that the test wrote, or with a bare
19
# timestamp, which ends the sync.
20
#
21
# xfer-server.test tests the server side.
22
#
23
24
# The first sections run at every level, and the rest need
25
# -assurance stress.
26
require_no_open_checkout
27
28
if {$::tcl_platform(platform) eq "windows"} {
29
test_skip "the stand-in for a server is a shell script"
30
}
31
32
test_setup
33
34
write_file a.txt "hello world\n"
35
fossil add a.txt
36
fossil commit -m one --no-warnings
37
fossil sha3sum a.txt
38
set xferclientFile [lindex $RESULT 0]
39
set xferclientAbsent [string repeat 0123456789abcdef 4]
40
41
set xferclientDir [file join [pwd] xferclient-wire]
42
file mkdir $xferclientDir
43
set xferclientWire \
44
[test_standin transport.sh [file join $xferclientDir transport.sh]]
45
set ::env(TRANSPORT_DIR) $xferclientDir
46
47
# Run "fossil VERB" against the stand-in, which answers request N with
48
# item N of the list REPLIES. Further arguments are options for the
49
# command. Sets xferclientCode to the exit status, or to "crash", and
50
# xferclientOut to what fossil printed.
51
proc xferclient_sync {verb replies args} {
52
xferclient_sync_url $verb http://localhost/x $replies {*}$args
53
}
54
55
# Like xferclient_sync, for the server at URL.
56
proc xferclient_sync_url {verb url replies args} {
57
global xferclientDir xferclientWire xferclientCode xferclientOut
58
file delete {*}[glob -nocomplain -directory $xferclientDir \
59
reply.* request.* count]
60
set number 0
61
foreach reply $replies {
62
write_file [file join $xferclientDir reply.[incr number]] $reply
63
}
64
fossil_raw $verb $url --once --transport-command $xferclientWire {*}$args
65
set xferclientCode $::CODE
66
set xferclientOut $::RESULT
67
}
68
69
proc xferclient_run {verb reply args} {
70
xferclient_sync $verb [list $reply] {*}$args
71
}
72
73
# Returns request NUMBER of the last run, or an empty string if fossil
74
# made fewer requests.
75
proc xferclient_request {number} {
76
set file [file join $::xferclientDir request.$number]
77
if {![file exists $file]} {
78
return ""
79
}
80
return [read_file $file]
81
}
82
83
proc xferclient_requests {} {
84
return [llength [glob -nocomplain -directory $::xferclientDir request.*]]
85
}
86
87
# Run one case. Test NAME passes when the exit status is CODE and the
88
# output holds each of the strings given. A string that begins with "!"
89
# must be absent.
90
proc xferclient_expect {name verb reply code options args} {
91
global xferclientCode xferclientOut
92
xferclient_run $verb $reply {*}$options
93
test xfer-client-$name {$xferclientCode eq $code
94
&& [xferclient_requests] <= 20
95
&& [holds_strings $xferclientOut $args]}
96
}
97
98
###############################################################################
99
# Messages and errors from the server.
100
101
xferclient_expect message pull "message hello\\sworld\n" 0 {} \
102
"Server says: hello world"
103
xferclient_expect message-verbose pull "message hi\n" 0 {-v} \
104
"Server says: hi" "Received:"
105
xferclient_expect pull-only-message push \
106
"message pull\\sonly\\s-\\snot\\sauthorized\\sto\\spush\n" 0 {}
107
xferclient_expect error pull "error something\\sfailed\n" 1 {} \
108
"Error: something failed"
109
xferclient_expect html-reply pull \
110
"<html><body>Not found</body></html>\n" 1 {} "server replies with HTML"
111
xferclient_expect unknown-card pull "frobnicate 1 2\n" 1 {} "unknown command"
112
xferclient_expect push-card-outside-clone pull \
113
"push $xferclientAbsent $xferclientAbsent\n" 1 {} "unknown command"
114
xferclient_expect empty-reply pull "" 1 {}
115
116
###############################################################################
117
# Pragmas, cookies and other cards without content.
118
119
xferclient_expect server-version pull $SERVER_VERSION_CARD 0 {}
120
xferclient_expect server-version-short pull "pragma server-version 22900\n" 0 {}
121
xferclient_expect uv-pull-only pull "pragma uv-pull-only\n" 0 {}
122
xferclient_expect uv-push-ok pull "pragma uv-push-ok\n" 0 {}
123
xferclient_expect avoid-delta-manifests pull \
124
"pragma avoid-delta-manifests\n" 0 {}
125
xferclient_expect unknown-pragma pull "pragma no-such-pragma 1 2\n" 0 {}
126
xferclient_expect pragma-alone pull "pragma\n" 1 {} "unknown command"
127
xferclient_expect ci-lock-fail pull \
128
"pragma ci-lock-fail someone 1700000000\n" 0 {} \
129
"Parent check-in locked by someone"
130
xferclient_expect ci-lock-fail-negative-time pull \
131
"pragma ci-lock-fail someone -5\n" 0 {} "Parent check-in locked by someone"
132
xferclient_expect ci-lock-fail-bad-time pull \
133
"pragma ci-lock-fail someone notint\n" 0 {} \
134
"Parent check-in locked by someone"
135
xferclient_expect link pull \
136
"pragma link http://example.org/z {} 1790000000\n" 0 {--share-links}
137
xferclient_expect link-not-asked-for pull \
138
"pragma link http://example.org/y {} 1790000000\n" 0 {}
139
xferclient_expect cookie pull "cookie abc\n" 0 {}
140
xferclient_expect cookie-alone pull "cookie\n" 1 {} "unknown command"
141
# A clone_seqno that is not a count: the pull ends, with or without
142
# an error.
143
foreach {name seqno} {negative -1 not-a-number x} {
144
xferclient_run pull "clone_seqno $seqno\n"
145
test xfer-client-clone-seqno-$name {$xferclientCode in {0 1}
146
&& [xferclient_requests] <= 20}
147
}
148
xferclient_expect comment-only pull "# a comment\n" 0 {}
149
150
###############################################################################
151
# The clock of the server. A server that is behind is reported.
152
153
xferclient_expect clock-behind pull \
154
"# timestamp 2016-01-01T00:00:00 errors 0\n" 0 {} "time skew"
155
xferclient_expect clock-ahead pull \
156
"# timestamp 2036-01-01T00:00:00 errors 0\n" 0 {}
157
xferclient_expect clock-unreadable pull "# timestamp garbage errors 0\n" 0 {}
158
159
###############################################################################
160
# Settings and options of the client that change what it sends.
161
162
# With dont-push, a push is refused and a sync only pulls.
163
fossil settings dont-push 1
164
xferclient_sync push {}
165
test xfer-client-dont-push {$xferclientCode != 0
166
&& [string match "*pushing is prohibited*" $xferclientOut]
167
&& [xferclient_requests] == 0}
168
xferclient_sync sync {}
169
test xfer-client-dont-push-sync {$xferclientCode == 0
170
&& [string match "*\npull *" "\n[xferclient_request 1]"]
171
&& ![string match "*\npush *" "\n[xferclient_request 1]"]}
172
fossil settings dont-push 0
173
174
# A repository with a public URL tells the server where it is.
175
fossil settings email-url https://client.example
176
fossil sql "REPLACE INTO config(name,value,mtime)
177
VALUES('baseurl:https://client.example',1,now())"
178
xferclient_sync pull {}
179
test xfer-client-client-url \
180
{[string match "*pragma client-url https://client.example\n*" \
181
[xferclient_request 1]]}
182
fossil unset email-url
183
184
# --from-parent-project needs the code of the parent project, and a code
185
# that is the repository's own is not taken for a parent's.
186
xferclient_sync pull {} --from-parent-project
187
test xfer-client-no-parent-project {$xferclientCode != 0
188
&& [string match "*no parent project*" $xferclientOut]
189
&& [xferclient_requests] == 0}
190
fossil sql "REPLACE INTO config(name,value,mtime) SELECT 'parent-project-code',
191
value, now() FROM config WHERE name='project-code'"
192
xferclient_sync pull {} --from-parent-project
193
test xfer-client-own-code-as-parent {$xferclientCode == 0
194
&& [xferclient_requests] >= 1}
195
# A repository with no project code of its own asks for the project of its
196
# parent.
197
fossil sql "SELECT value FROM config WHERE name='project-code'"
198
set xferclientOwnCode [string trim $RESULT]
199
set xferclientParentCode [string repeat 0123abcd 5]
200
fossil sql "DELETE FROM config WHERE name='project-code';
201
REPLACE INTO config(name,value,mtime)
202
VALUES('parent-project-code','$xferclientParentCode',now())"
203
xferclient_sync pull {} --from-parent-project
204
test xfer-client-parent-of-project-without-code {$xferclientCode == 0
205
&& [regexp -line "^pull \\S+ $xferclientParentCode\$" \
206
[xferclient_request 1]]}
207
fossil sql "REPLACE INTO config(name,value,mtime)
208
VALUES('project-code','$xferclientOwnCode',now())"
209
fossil sql "DELETE FROM config WHERE name='parent-project-code'"
210
211
if {[test_assurance] ne "stress"} {
212
test_skip "the tests after the first sections need -assurance stress"
213
}
214
215
###############################################################################
216
# igot and gimme. What the client asks for, or sends, shows in its
217
# second request.
218
219
xferclient_run pull "igot $xferclientAbsent\n"
220
test xfer-client-igot-asks-for-it \
221
{$xferclientCode == 0
222
&& [string first "gimme $xferclientAbsent" [xferclient_request 2]] >= 0}
223
# A hash that the client hears of only as private, or only in a push.
224
set xferclientPrivate [string repeat fedcba9876543210 4]
225
xferclient_run pull "igot $xferclientPrivate 1\n"
226
test xfer-client-igot-private-not-asked-for \
227
{$xferclientCode == 0
228
&& [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0}
229
xferclient_run pull "igot $xferclientFile\n"
230
test xfer-client-igot-held-not-asked-for \
231
{$xferclientCode == 0
232
&& [string first "gimme $xferclientFile" [xferclient_request 2]] < 0}
233
xferclient_run push "igot $xferclientPrivate\n"
234
test xfer-client-igot-on-push-not-asked-for \
235
{$xferclientCode == 0
236
&& [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0}
237
xferclient_expect igot-not-a-hash pull "igot nothash\n" 1 {} "unknown command"
238
xferclient_expect igot-alone pull "igot\n" 1 {} "unknown command"
239
240
xferclient_run push "gimme $xferclientFile\n"
241
test xfer-client-gimme-sends-it \
242
{$xferclientCode == 0
243
&& [string first "file $xferclientFile" [xferclient_request 2]] >= 0}
244
xferclient_run pull "gimme $xferclientFile\n"
245
test xfer-client-gimme-on-pull-sends-nothing \
246
{$xferclientCode == 0
247
&& [string first "file $xferclientFile" [xferclient_request 2]] < 0}
248
xferclient_expect gimme-absent push "gimme $xferclientAbsent\n" 0 {}
249
xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \
250
"unknown command"
251
252
###############################################################################
253
# An igot card can say that an artifact is private. The client marks its
254
# own copy private only in a sync of private content, so in an ordinary
255
# pull a server cannot make a public check-in private.
256
257
fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT max(objid) FROM event\
258
WHERE type='ci')"
259
set xferclientCkin [string trim $::RESULT]
260
xferclient_run pull "igot $xferclientCkin 1\n"
261
fossil sql "SELECT count(*) FROM private"
262
test xfer-client-igot-private-in-pull-marks-nothing \
263
{$xferclientCode == 0 && [string trim $RESULT] == 0}
264
xferclient_run pull "igot $xferclientCkin 1\n" --private
265
fossil sql "SELECT count(*) FROM private"
266
test xfer-client-igot-private-in-private-pull-marks-it \
267
{$xferclientCode == 0 && [string trim $RESULT] == 1}
268
xferclient_run pull "igot $xferclientCkin\n"
269
fossil sql "SELECT count(*) FROM private"
270
test xfer-client-igot-public-unmarks-it \
271
{$xferclientCode == 0 && [string trim $RESULT] == 0}
272
273
# An artifact that the client has asked for and does not hold yet is still
274
# marked: the server says it is private, and the client stops asking.
275
set xferclientPhantom [string repeat 00112233445566778899aabbccddeeff 2]
276
xferclient_sync pull \
277
[list "igot $xferclientPhantom\n" "igot $xferclientPhantom 1\n"]
278
fossil sql "SELECT count(*) FROM private p, blob b\
279
WHERE b.rid=p.rid AND b.uuid='$xferclientPhantom'"
280
test xfer-client-igot-private-marks-a-phantom \
281
{$xferclientCode == 0 && [string trim $RESULT] == 1}
282
xferclient_run pull "# nothing\n"
283
test xfer-client-private-phantom-not-asked-for-again \
284
{[string first "gimme $xferclientPhantom" [xferclient_request 1]] < 0}
285
286
###############################################################################
287
# Artifacts are accepted only in a sync that pulls, so a server cannot add
288
# one to the client in answer to a push. The hash is that of the five
289
# bytes "hello" under SHA3-256.
290
291
set xferclientHello \
292
3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392
293
fossil sql "SELECT count(*) FROM blob"
294
set xferclientBlobs [string trim $::RESULT]
295
xferclient_expect file-in-push-refused push \
296
"file $xferclientHello 5\nhello\n" 1 {} "unknown command"
297
xferclient_expect cfile-in-push-refused push \
298
"cfile $xferclientHello 5 3\nabc\n" 1 {} "unknown command"
299
fossil sql "SELECT count(*) FROM blob"
300
test xfer-client-file-in-push-stores-nothing \
301
{[string trim $RESULT] == $xferclientBlobs}
302
xferclient_run pull "file $xferclientHello 5\nhello\n"
303
fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientHello'"
304
test xfer-client-file-in-pull-stored \
305
{$xferclientCode == 0 && [string trim $RESULT] == 1}
306
307
###############################################################################
308
# Content that does not match its card is refused and nothing is stored.
309
310
xferclient_expect file-wrong-hash pull \
311
"file $xferclientAbsent 5\nhello\n" 1 {} "wrong hash on received artifact"
312
fossil sql \
313
"SELECT count(*) FROM blob WHERE uuid='$xferclientAbsent' AND size>=0"
314
test xfer-client-file-wrong-hash-not-stored {[string trim $RESULT] == 0}
315
xferclient_expect file-size-past-end pull \
316
"file $xferclientAbsent 99\nhello\n" 1 {}
317
xferclient_expect file-too-few-tokens pull "file $xferclientAbsent\n" 1 {}
318
xferclient_expect file-size-not-a-number pull \
319
"file $xferclientAbsent notint\nhello\n" 1 {}
320
xferclient_expect cfile-size-past-end pull \
321
"cfile $xferclientAbsent 5 99\nxx\n" 1 {}
322
xferclient_expect config-not-asked-for pull "config /project 0\n\n" 0 {}
323
xferclient_expect config-size-not-a-number pull \
324
"config /project notint\n" 1 {} "unknown command"
325
326
###############################################################################
327
# Unversioned files. The cards for them are acted on only in a sync of
328
# unversioned content, or in a clone. In an ordinary pull a uvigot or
329
# uvfile card is an unknown command: the pull ends with that error, not an
330
# SQL error, and the local unversioned file is unchanged.
331
332
write_file note.txt "local note\n"
333
fossil unversioned add note.txt
334
set xferclientUvHash [string repeat 0 64]
335
xferclient_expect uvigot-refused-in-pull pull \
336
"uvigot note.txt 2000000000 $xferclientUvHash 3\n" 1 {} \
337
"unknown command" "!SQLITE_ERROR"
338
xferclient_expect uvigot-delete-refused-in-pull pull \
339
"uvigot note.txt 2000000000 - 0\n" 1 {} "unknown command" "!SQLITE_ERROR"
340
# The hash is that of the three bytes "abc" under SHA3-256.
341
set xferclientAbcHash \
342
3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532
343
xferclient_expect uvfile-refused-in-pull pull \
344
"uvfile note.txt 2000000001 $xferclientAbcHash 3 0\nabc\n" 1 {} \
345
"unknown command"
346
fossil unversioned cat note.txt
347
test_eq xfer-client-uvfile-in-pull-changes-nothing [string trim $RESULT] \
348
"local note"
349
350
###############################################################################
351
# Each card that has a fixed number of words, and each word that selects a
352
# card, decides alone whether the card is acted on. A card of the wrong
353
# number of words, or with a first word that has the length of a card name
354
# but is not it, is an unknown command and ends the sync with an error.
355
356
foreach {xferclientName xferclientCard} [list \
357
gimme-no-argument "gimme\n" \
358
gimme-two-arguments "gimme $xferclientAbsent x\n" \
359
config-no-size "config /project\n" \
360
config-extra-argument "config /project 0 x\n" \
361
clone-seqno-no-argument "clone_seqno\n" \
362
clone-seqno-two-numbers "clone_seqno 1 2\n" \
363
clone-seqno-other-word "clone_seqnx 1\n" \
364
message-no-text "message\n" \
365
message-two-words "message a b\n" \
366
message-other-word "messagf hi\n" \
367
error-two-words "error a b\n" \
368
] {
369
xferclient_expect mcdc-shape-$xferclientName pull $xferclientCard 1 {} \
370
"unknown command"
371
}
372
373
# An igot card names the artifact and may add the flag 1 for private. Any
374
# other third word, of any length, is not that flag: the artifact is
375
# public and the client asks for it.
376
set xferclientFlagHash(other-digit) [string repeat 1111222233334444 4]
377
set xferclientFlagHash(long-flag) [string repeat 5555666677778888 4]
378
set xferclientFlagHash(letter) [string repeat 9999aaaabbbbcccc 4]
379
foreach {xferclientName xferclientFlag} {
380
other-digit 2
381
long-flag 11
382
letter x
383
} {
384
set xferclientHash $xferclientFlagHash($xferclientName)
385
xferclient_run pull "igot $xferclientHash $xferclientFlag\n"
386
test xfer-client-mcdc-igot-flag-$xferclientName \
387
{$xferclientCode == 0
388
&& [string first "gimme $xferclientHash" [xferclient_request 2]] >= 0}
389
}
390
391
# A message in a push that does not begin with "pull only" is shown, and an
392
# empty message is not.
393
xferclient_expect mcdc-message-in-push push "message hi\n" 0 {} \
394
"Server says: hi"
395
xferclient_expect mcdc-message-empty pull "message \\0\n" 0 {} \
396
"!Server says"
397
398
# A pragma with the wrong number of words, or with a name of the length
399
# of a known one, does nothing.
400
foreach {xferclientName xferclientCard} [list \
401
ci-lock-fail-two-words "pragma ci-lock-fail someone\n" \
402
ci-lock-fail-four-words "pragma ci-lock-fail someone 1700000000 x\n" \
403
] {
404
xferclient_expect mcdc-pragma-$xferclientName pull $xferclientCard 0 {} \
405
"!Parent check-in locked"
406
}
407
xferclient_expect mcdc-ci-lock-fail-future pull \
408
"pragma ci-lock-fail someone 99999999999\n" 0 {} \
409
"Parent check-in locked by someone\n" "!ago"
410
411
# Links from the server are kept only with --share-links, for a URL of the
412
# http or https kind and a time above zero.
413
foreach {xferclientName xferclientCard xferclientKept} [list \
414
http "pragma link http://example.org/a {} 1790000000\n" 1 \
415
https "pragma link https://example.org/b {} 1790000000\n" 1 \
416
ssh "pragma link ssh://example.org/c {} 1790000000\n" 0 \
417
ftp "pragma link ftp://example.org/h {} 1790000000\n" 0 \
418
no-scheme "pragma link example.org/i {} 1790000000\n" 0 \
419
zero-time "pragma link http://example.org/e {} 0\n" 0 \
420
four-words "pragma link http://example.org/f {}\n" 0 \
421
other-name "pragma lonk http://example.org/g {} 1790000000\n" 0 \
422
] {
423
fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
424
xferclient_run pull $xferclientCard --share-links
425
fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'"
426
test_eq xfer-client-mcdc-link-$xferclientName \
427
"$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
428
}
429
430
###############################################################################
431
# A "private" card makes the next file private. A client that does not sync
432
# private content ignores that file, whatever its content; one that does
433
# keeps it and marks it private.
434
435
write_file world.txt "world\n"
436
fossil sha3sum world.txt
437
set xferclientWorld [lindex $RESULT 0]
438
fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
439
set xferclientBefore [string trim $RESULT]
440
xferclient_run pull "private\nfile $xferclientWorld 6\nworld\n"
441
fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
442
test xfer-client-mcdc-private-file-ignored \
443
{$xferclientCode == 0 && [string trim $RESULT] == $xferclientBefore}
444
xferclient_run pull "private\ncfile $xferclientWorld 6 0\n"
445
fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
446
test xfer-client-mcdc-private-cfile-ignored \
447
{$xferclientCode == 0 && [string trim $RESULT] == $xferclientBefore}
448
xferclient_run pull "private\nfile $xferclientWorld 6\nworld\n" --private
449
fossil sql "SELECT count(*) FROM blob b, private p
450
WHERE b.rid=p.rid AND b.uuid='$xferclientWorld' AND b.size>=0"
451
test xfer-client-mcdc-private-file-kept-in-private-pull \
452
{$xferclientCode == 0 && [string trim $RESULT] == 1}
453
454
###############################################################################
455
# How many rounds a sync makes.
456
457
# A pull asks for every phantom in every round, so the cases below start
458
# with none.
459
proc xferclient_no_phantoms {name} {
460
fossil sql "DELETE FROM private WHERE rid IN (SELECT rid FROM phantom);
461
DELETE FROM unclustered WHERE rid IN (SELECT rid FROM phantom);
462
DELETE FROM blob WHERE rid IN (SELECT rid FROM phantom);
463
DELETE FROM phantom"
464
fossil sql "SELECT count(*) FROM phantom"
465
test_eq xfer-client-mcdc-no-phantoms-$name [string trim $::RESULT] 0
466
}
467
xferclient_no_phantoms before-resync
468
469
# A resync asks for the catalog of the server in its first request only. A
470
# pull asks for the clusters of the server in the third request, because it
471
# asks for artifacts in it, and not in the first two.
472
set xferclientPhantomB [string repeat 0a1b2c3d4e5f6a7b 4]
473
set xferclientPhantomA [string repeat f0e1d2c3b4a59687 4]
474
xferclient_sync pull \
475
[list "igot $xferclientPhantomA\n" "igot $xferclientPhantomB\n"] --verily
476
test xfer-client-mcdc-resync-catalog {$xferclientCode == 0
477
&& [xferclient_requests] == 3
478
&& [string first "pragma send-catalog" [xferclient_request 1]] >= 0
479
&& [string first "pragma send-catalog" [xferclient_request 2]] < 0
480
&& [string first "pragma send-catalog" [xferclient_request 3]] < 0}
481
test xfer-client-mcdc-req-clusters-third-request {
482
[string first "pragma req-clusters" [xferclient_request 1]] < 0
483
&& [string first "pragma req-clusters" [xferclient_request 2]] < 0
484
&& [string first "pragma req-clusters" [xferclient_request 3]] >= 0}
485
486
# A sync that sends a file in each round and is asked for one again in the
487
# third asks for no artifact there, so it does not ask for clusters.
488
xferclient_no_phantoms before-sync
489
xferclient_sync sync [list "gimme $xferclientFile\n" "gimme $xferclientFile\n"]
490
test xfer-client-mcdc-no-req-clusters-without-phantoms {$xferclientCode == 0
491
&& [xferclient_requests] >= 3
492
&& [string first "pragma req-clusters" [xferclient_request 3]] < 0}
493
494
# A server that asks for a private artifact in a push that is not of private
495
# content is told that the artifact exists and is private, and the client
496
# goes on for a second round. It goes on only once: a server that asks
497
# again in the second round gets the same answer and no third round.
498
write_file private.txt "a private file\n"
499
fossil add private.txt
500
fossil commit -m private --private --no-warnings
501
fossil sql "SELECT uuid FROM blob WHERE rid IN (SELECT rid FROM private)
502
AND size>0 LIMIT 1"
503
set xferclientPrivate [string trim $RESULT]
504
set xferclientAsk "${SERVER_VERSION_CARD}gimme $xferclientPrivate\n"
505
xferclient_sync push [list $xferclientAsk $xferclientAsk $xferclientAsk]
506
test xfer-client-mcdc-private-igot-one-more-round {$xferclientCode == 0
507
&& [xferclient_requests] == 2
508
&& [string first "igot $xferclientPrivate 1" [xferclient_request 2]] >= 0
509
&& [string first "file $xferclientPrivate" [xferclient_request 2]] < 0}
510
xferclient_sync push {}
511
test xfer-client-mcdc-no-private-igot-one-round {$xferclientCode == 0
512
&& [xferclient_requests] == 1}
513
514
# A pull asks for at most 200 of the artifacts that a server has announced
515
# in one request.
516
xferclient_no_phantoms before-limit
517
set xferclientMany ""
518
for {set xferclientI 0} {$xferclientI < 250} {incr xferclientI} {
519
append xferclientMany "igot [format %064x [expr {$xferclientI + 1}]]\n"
520
}
521
xferclient_run pull $xferclientMany
522
test xfer-client-mcdc-asks-for-200 {$xferclientCode == 0
523
&& [llength [regexp -all -inline {gimme } [xferclient_request 2]]] == 200}
524
xferclient_no_phantoms after-limit
525
526
# A reply with no card at all, only an empty line, is accepted.
527
xferclient_expect mcdc-reply-empty-line pull "\n" 0 {-v}
528
529
# The repository records the address of a server that is not on the local
530
# host, for the http and https kinds of address and not for others.
531
foreach {xferclientName xferclientUrl xferclientKept} {
532
https-other https://example.org/x 1
533
http-other http://example.org/y 1
534
local http://localhost/z 0
535
} {
536
fossil sql "DELETE FROM config WHERE name GLOB 'syncwith:*'"
537
xferclient_sync_url pull $xferclientUrl {}
538
fossil sql "SELECT count(*) FROM config WHERE name GLOB 'syncwith:*'"
539
test_eq xfer-client-mcdc-syncwith-$xferclientName \
540
"$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
541
}
542
fossil sql "DELETE FROM config WHERE name GLOB 'syncwith:*'"
543
544
###############################################################################
545
# Unversioned files: the server announces a file of that name with a card,
546
# and the client asks for it. Each word of the card decides alone whether it
547
# is accepted.
548
549
set xferclientUvCards [list \
550
uvigot-ok "uvigot new.txt 2000000000 $xferclientAbcHash 3\n" gimme \
551
uvigot-delete "uvigot new.txt 2000000000 - 0\n" quiet \
552
bad-name "uvigot ../x 2000000000 $xferclientAbcHash 3\n" refused \
553
bad-mtime "uvigot new.txt notint $xferclientAbcHash 3\n" refused \
554
bad-size "uvigot new.txt 2000000000 $xferclientAbcHash x\n" refused \
555
hash-too-short "uvigot new.txt 2000000000 abc 3\n" refused \
556
hash-one-letter "uvigot new.txt 2000000000 x 3\n" refused \
557
four-words "uvigot new.txt 2000000000 $xferclientAbcHash\n" refused \
558
six-words "uvigot new.txt 2000000000 $xferclientAbcHash 3 x\n" refused \
559
short-name "uvigo new.txt 2000000000 $xferclientAbcHash 3\n" refused \
560
other-name "uvigoz new.txt 2000000000 $xferclientAbcHash 3\n" refused \
561
]
562
# "gimme": the client asks for the file. "quiet": the card is accepted and
563
# nothing is asked. "refused": the card is an unknown command.
564
foreach {xferclientName xferclientCard xferclientOutcome} $xferclientUvCards {
565
xferclient_run sync $xferclientCard -u
566
set xferclientAsked [expr {
567
[string first "uvgimme new.txt" [xferclient_request 2]] >= 0}]
568
set xferclientRefused [expr {$xferclientCode == 1
569
&& [string first "unknown command" $xferclientOut] >= 0}]
570
test xfer-client-mcdc-uv-$xferclientName {
571
($xferclientOutcome eq "gimme" && $xferclientCode == 0 && $xferclientAsked)
572
|| ($xferclientOutcome eq "quiet" && $xferclientCode == 0
573
&& !$xferclientAsked)
574
|| ($xferclientOutcome eq "refused" && $xferclientRefused)}
575
}
576
577
# The server announces a file in every round and sends none: the client
578
# asks for it in three rounds and then stops.
579
set xferclientUvAgain "uvigot new.txt 2000000000 $xferclientAbcHash 3\n"
580
xferclient_sync sync [list $xferclientUvAgain $xferclientUvAgain \
581
$xferclientUvAgain $xferclientUvAgain $xferclientUvAgain] -u
582
test xfer-client-mcdc-uv-asks-in-three-rounds {$xferclientCode == 0
583
&& [xferclient_requests] == 3}
584
# While a file arrives in each round and another is announced, the client
585
# goes on asking, and stops after the reply that announces the last one.
586
proc xferclient_uvfile {name} {
587
return "uvfile $name 2000000000 $::xferclientAbcHash 3 0\nabc\n"
588
}
589
proc xferclient_uvigot {name} {
590
return "uvigot $name 2000000000 $::xferclientAbcHash 3\n"
591
}
592
xferclient_sync sync [list [xferclient_uvigot n1.txt] \
593
"[xferclient_uvfile n1.txt][xferclient_uvigot n2.txt]" \
594
"[xferclient_uvfile n2.txt][xferclient_uvigot n3.txt]" \
595
"[xferclient_uvfile n3.txt][xferclient_uvigot n4.txt]" \
596
"[xferclient_uvfile n4.txt][xferclient_uvigot n5.txt]" \
597
"[xferclient_uvfile n5.txt][xferclient_uvigot n6.txt]"] -u
598
test xfer-client-mcdc-uv-goes-on-while-files-arrive {$xferclientCode == 0
599
&& [xferclient_requests] == 7}
600
601
# A server that takes unversioned content is sent every file that it has not
602
# announced, whole.
603
xferclient_sync sync [list "pragma uv-push-ok\n"] -u
604
test xfer-client-mcdc-uv-push-sends-file {$xferclientCode == 0
605
&& [string first "uvfile note.txt " [xferclient_request 2]] >= 0
606
&& [string first "uvigot" [xferclient_request 2]] < 0}
607
608
# A server that takes no unversioned content, and a client with none to
609
# send, makes no warning.
610
fossil sql "DELETE FROM unversioned"
611
xferclient_expect mcdc-uv-pull-only-nothing-to-send sync \
612
"pragma uv-pull-only\n" 0 {-u} "!unversioned"
613
614
###############################################################################
615
# A repository that cannot be written to can pull from a server that has
616
# nothing new. It does not record the address of the server.
617
618
set xferclientMode [file attributes .rep.fossil -permissions]
619
file attributes .rep.fossil -permissions 0444
620
xferclient_sync_url pull http://example.org/readonly {}
621
file attributes .rep.fossil -permissions $xferclientMode
622
fossil sql "SELECT count(*) FROM config WHERE name GLOB 'syncwith:*'"
623
test_eq xfer-client-mcdc-pull-into-read-only \
624
"$xferclientCode [xferclient_requests] [string trim $RESULT]" "0 1 0"
625
626
###############################################################################
627
# Clones. The stand-in answers a clone as it answers a pull, so each clone
628
# here gets the replies that the test wrote and then bare timestamps.
629
630
fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT min(objid) FROM event
631
WHERE type='ci')"
632
set xferclientFirst [string trim $RESULT]
633
fossil artifact $xferclientFirst first-manifest.out
634
set xferclientManifest [read_file first-manifest.out]
635
set xferclientPush "push $xferclientOwnCode $xferclientOwnCode\n"
636
637
# Clone into clone.fossil from a server that gives the replies REPLIES.
638
# Sets xferclientCode and xferclientOut as xferclient_sync does.
639
proc xferclient_clone {replies} {
640
global xferclientDir xferclientWire xferclientCode xferclientOut
641
file delete clone.fossil
642
file delete {*}[glob -nocomplain -directory $xferclientDir \
643
reply.* request.* count]
644
set number 0
645
foreach reply $replies {
646
write_file [file join $xferclientDir reply.[incr number]] $reply
647
}
648
fossil_raw clone http://localhost/x clone.fossil --no-open \
649
--transport-command $xferclientWire
650
set xferclientCode $::CODE
651
set xferclientOut $::RESULT
652
}
653
654
# The number of the artifacts HASHES that clone.fossil holds.
655
proc xferclient_clone_holds {hashes} {
656
fossil sql -R clone.fossil "SELECT count(*) FROM blob WHERE size>=0
657
AND uuid IN ('[join $hashes ',']')"
658
return [string trim $::RESULT]
659
}
660
661
# A server of the first version of the protocol lists what it has in
662
# "igot" cards and sends each artifact, in a "file" card, when it is asked
663
# for it. The clone asks in every round and never asks for clusters.
664
xferclient_clone [list \
665
"${xferclientPush}igot $xferclientFirst\nigot $xferclientFile\n" \
666
"file $xferclientFirst [string length $xferclientManifest]\n\
667
$xferclientManifest" \
668
"file $xferclientFile 12\nhello world\n"]
669
test xfer-client-mcdc-clone-by-igot {$xferclientCode == 0
670
&& [xferclient_requests] == 4
671
&& [string first "gimme $xferclientFirst" [xferclient_request 2]] >= 0
672
&& [string first "gimme $xferclientFile" [xferclient_request 3]] >= 0
673
&& [string first "pragma req-clusters" [xferclient_request 3]] < 0}
674
test_eq xfer-client-mcdc-clone-by-igot-holds \
675
[xferclient_clone_holds [list $xferclientFirst $xferclientFile]] 2
676
fossil sql -R clone.fossil "SELECT value FROM config WHERE name='project-code'"
677
test_eq xfer-client-mcdc-clone-project-code [string trim $RESULT] \
678
$xferclientOwnCode
679
680
# The card that gives a clone its project code has three words, the third
681
# a hash. Any other card that begins with "push" ends the clone with an
682
# error and leaves no repository.
683
foreach {xferclientName xferclientCard} [list \
684
two-words "push $xferclientOwnCode\n" \
685
not-a-hash "push $xferclientOwnCode nothash\n" \
686
] {
687
xferclient_clone [list $xferclientCard]
688
test xfer-client-mcdc-clone-push-$xferclientName {$xferclientCode == 1
689
&& [string first "unknown command" $xferclientOut] >= 0
690
&& ![file exists clone.fossil]}
691
}
692
693
# An error in the first reply ends the clone, unless it says that the
694
# login failed or that the client is not authorized: the first request of
695
# a clone has no login card, so those are expected and the clone goes on.
696
foreach {xferclientName xferclientError xferclientGoesOn} {
697
other-error {something\sfailed} 0
698
login-failed {login\sfailed} 1
699
not-authorized {not\sauthorized\sto\sclone} 1
700
} {
701
xferclient_clone [list "${xferclientPush}error $xferclientError\n"]
702
test xfer-client-mcdc-clone-first-error-$xferclientName {
703
$xferclientGoesOn
704
? ($xferclientCode == 0 && [xferclient_requests] == 2
705
&& [file exists clone.fossil])
706
: ($xferclientCode == 1
707
&& [string first "Error: something failed" $xferclientOut] >= 0
708
&& ![file exists clone.fossil])}
709
}
710
711
# A clone goes on asking while the server says that it has more to send
712
# and something arrives, here an unversioned file. It stops after a reply
713
# in which nothing arrives.
714
xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
715
"[xferclient_uvfile cloned.txt]clone_seqno 3\n$xferclientPush" \
716
"clone_seqno 4\n$xferclientPush"]
717
test xfer-client-mcdc-clone-goes-on-while-content-arrives \
718
{$xferclientCode == 0 && [xferclient_requests] == 3
719
&& [string first "clone 3 3" [xferclient_request 3]] >= 0}
720
fossil unversioned cat cloned.txt -R clone.fossil
721
test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc
722
xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
723
"clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"]
724
test xfer-client-mcdc-clone-stops-when-nothing-arrives \
725
{$xferclientCode == 0 && [xferclient_requests] == 2}
726
727
###############################################################################
728
# What a sync with -v says at its end about the server. A server that
729
# could not be reached is named as the URL names it, with no address. The
730
# URLs here have no host; the one for http names port 9, on which nothing
731
# is expected to listen, and the one for ssh is given standin/log-args.sh
732
# as its ssh command, which exits at once. The stand-in is also first on
733
# the PATH as "ssh"; if it cannot be, the ssh case is skipped.
734
735
fossil_raw pull -v --once --proxy off http://:9/x
736
test xfer-client-mcdc-remote-no-host {$CODE == 1 &&
737
[holds_strings $RESULT [list "Pull done," "remote: \n"]]}
738
set xferclientSshDir [file join $xferclientDir ssh-standin]
739
file mkdir $xferclientSshDir
740
set xferclientSsh \
741
[test_standin log-args.sh [file join $xferclientSshDir ssh]]
742
set xferclientSavedPath $::env(PATH)
743
set ::env(PATH) "$xferclientSshDir:$::env(PATH)"
744
unset -nocomplain ::auto_execs(ssh)
745
if {[lindex [auto_execok ssh] 0] ne $xferclientSsh} {
746
test_skip_part "xfer-client-mcdc-remote-ssh-no-host: cannot put a\
747
stand-in for ssh first on the PATH"
748
} else {
749
set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt]
750
fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x
751
test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1 &&
752
[file exists $::env(ARGS_LOG)] &&
753
[holds_strings $RESULT [list "Pull done," "remote: \n"]]}
754
unset ::env(ARGS_LOG)
755
}
756
set ::env(PATH) $xferclientSavedPath
757
unset -nocomplain ::auto_execs(ssh)
758
759
###############################################################################
760
# What shows only when the client speaks HTTP. The server is made here: it
761
# answers request N with item N of the list xferclientHttpReplies, or with
762
# a bare timestamp where that is empty, and keeps the header and the cards
763
# of each request in the list xferclientHttpRequests.
764
765
proc xferclient_http_read {chan request} {
766
global xferclientHttpRequests xferclientHttpReplies
767
set end [string first "\r\n\r\n" $request]
768
# The cards follow four bytes of size when they are compressed.
769
set header [string range $request 0 $end+1]
770
set cards [string range $request $end+4 end]
771
catch {set cards [zlib decompress [string range $cards 4 end]]}
772
set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]]
773
lappend xferclientHttpRequests [list $header $cards]
774
if {$reply eq ""} {
775
set reply "# timestamp [clock format [clock seconds] -gmt 1 \
776
-format %Y-%m-%dT%H:%M:%S] errors 0\n"
777
}
778
catch {
779
puts -nonewline $chan "HTTP/1.0 200 OK\r\nContent-Type:\
780
application/x-fossil-uncompressed\r\nContent-Length:\
781
[string length $reply]\r\n\r\n$reply"
782
close $chan
783
}
784
}
785
786
# Run fossil with the arguments ARGS while the server gives the replies
787
# REPLIES. Sets xferclientCode and xferclientOut as xferclient_sync does.
788
proc xferclient_http_run {replies args} {
789
global xferclientHttpReplies xferclientHttpRequests
790
global xferclientCode xferclientOut
791
set xferclientHttpReplies $replies
792
set xferclientHttpRequests {}
793
fossil_raw -seconds 60 {*}$args
794
set xferclientCode $::CODE
795
set xferclientOut $::RESULT
796
}
797
798
if {[loopback_available]} {
799
set xferclientHttpPort [test_listen xferclient_http_read]
800
801
# The login card goes in front of the cards of a request. Once the
802
# server has said that it is of version 2.27 or later and was built at or
803
# after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The
804
# second request shows where the client puts it.
805
foreach {xferclientName xferclientVersion xferclientWhere} {
806
older-version "22699 20260101 120000" cards
807
day-before "22700 20250726 235959" cards
808
second-before "22700 20250727 110459" cards
809
same-second "22700 20250727 110500" cookie
810
day-after "22700 20250728 0" cookie
811
} {
812
xferclient_no_phantoms login-card-$xferclientName
813
xferclient_http_run [list \
814
"pragma server-version $xferclientVersion\nigot $xferclientAbsent\n"] \
815
pull http://tester:[email protected]:$xferclientHttpPort/x --once \
816
--proxy off --no-http-compression
817
lassign [lindex $xferclientHttpRequests 1] xferclientHeader xferclientCards
818
set xferclientInCookie [regexp -nocase -line \
819
{^Cookie: x-f-l-c=login.tester} $xferclientHeader]
820
set xferclientInCards [regexp -line {^login tester } $xferclientCards]
821
test_eq xfer-client-mcdc-login-card-$xferclientName \
822
"$xferclientCode [llength $xferclientHttpRequests]\
823
$xferclientInCookie $xferclientInCards" \
824
"0 2 [expr {$xferclientWhere eq "cookie" ? "1 0" : "0 1"}]"
825
}
826
xferclient_no_phantoms after-login-card
827
828
# A sync with -v names the server at its end, and adds the address that
829
# it connected to when that is not what the URL has.
830
xferclient_http_run {} pull -v --once --proxy off \
831
http://127.0.0.1:$xferclientHttpPort/x
832
test xfer-client-mcdc-remote-by-address {$xferclientCode == 0
833
&& [string first "remote: 127.0.0.1\n" $xferclientOut] >= 0}
834
xferclient_http_run {} pull -v --once --proxy off \
835
http://localhost:$xferclientHttpPort/x
836
test xfer-client-mcdc-remote-by-name {$xferclientCode == 0
837
&& [string first "remote: localhost (127.0.0.1)\n" $xferclientOut] >= 0}
838
839
# A commit pushes when it is done. A server that says the user may not
840
# write does not make the commit fail: the user is told that the check-in
841
# is kept here. Any other error from the server is reported as it is.
842
fossil update $xferclientCkin
843
fossil settings proxy off
844
fossil settings autosync on
845
fossil remote http://127.0.0.1:$xferclientHttpPort/auto
846
foreach {xferclientName xferclientError xferclientSaid} {
847
not-authorized {not\sauthorized\sto\swrite}
848
{"not authorized to push the changes" "!Autosync failed" "!Error:"}
849
other-error {something\sfailed}
850
{"Error: something failed" "Autosync failed" "!not authorized to push"}
851
} {
852
write_file auto-$xferclientName.txt "$xferclientName\n"
853
fossil add auto-$xferclientName.txt
854
xferclient_http_run [list "" "error $xferclientError\n"] \
855
commit -m auto-$xferclientName --no-warnings --allow-fork
856
fossil sql "SELECT count(*) FROM event WHERE comment='auto-$xferclientName'"
857
test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0
858
&& [string trim $RESULT] == 1
859
&& [llength $xferclientHttpRequests] == 2
860
&& [holds_strings $xferclientOut $xferclientSaid]}
861
}
862
test_listen_stop
863
}
864
865
###############################################################################
866
867
unset ::env(TRANSPORT_DIR)
868
test_cleanup
869

Keyboard Shortcuts

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