|
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
|
# Each kind of card and pragma of the sync protocol, sent to the server |
|
15
|
# side through "fossil test-xfer", with and without valid card |
|
16
|
# permissions. The server must give the documented answer and must not |
|
17
|
# crash. The cards with content are in the sections at the end. |
|
18
|
# |
|
19
|
# "fossil test-xfer" treats a login card as a grant of the Read, Write, |
|
20
|
# Private and Admin permissions. A message without a login card runs |
|
21
|
# with the permissions of the user "nobody", which these tests set. |
|
22
|
# |
|
23
|
|
|
24
|
# The first sections run at every level, and the rest need |
|
25
|
# -assurance stress. |
|
26
|
require_no_open_checkout |
|
27
|
|
|
28
|
test_setup |
|
29
|
|
|
30
|
write_file a.txt "hello world\n" |
|
31
|
fossil add a.txt |
|
32
|
fossil commit -m one --no-warnings |
|
33
|
fossil sha3sum a.txt |
|
34
|
set xferserverFile [lindex $RESULT 0] |
|
35
|
fossil sql -R .rep.fossil "SELECT value FROM config WHERE name='project-code'" |
|
36
|
set xferserverPcode [string trim $::RESULT] |
|
37
|
fossil sql -R .rep.fossil "SELECT max(rid) FROM blob" |
|
38
|
set xferserverMaxRid [string trim $::RESULT] |
|
39
|
|
|
40
|
# The server is a copy of the repository of this checkout, so that it |
|
41
|
# holds a check-in. A hash that it does not hold: |
|
42
|
file copy .rep.fossil srv.fossil |
|
43
|
set xferserverAbsent [string repeat 0123456789abcdef 4] |
|
44
|
|
|
45
|
set xferserverLogin "login tester 0 0\n" |
|
46
|
set xferserverPull "pull x $xferserverPcode\n" |
|
47
|
set xferserverPush "push x $xferserverPcode\n" |
|
48
|
|
|
49
|
proc xferserver_caps {caps} { |
|
50
|
fossil sql -R srv.fossil \ |
|
51
|
"UPDATE user SET cap='$caps' WHERE login IN ('nobody','anonymous')" |
|
52
|
} |
|
53
|
|
|
54
|
proc xferserver_set {name value} { |
|
55
|
fossil sql -R srv.fossil \ |
|
56
|
"REPLACE INTO config(name,value,mtime) VALUES('$name','$value',now())" |
|
57
|
} |
|
58
|
|
|
59
|
proc xferserver_unset {pattern} { |
|
60
|
fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB '$pattern'" |
|
61
|
} |
|
62
|
|
|
63
|
# Returns the number of rows on the server that "SELECT count(*) FROM" |
|
64
|
# finds, with FROM as the remainder of the query. |
|
65
|
proc xferserver_count {from} { |
|
66
|
fossil sql -R srv.fossil "SELECT count(*) FROM $from" |
|
67
|
return [string trim $::RESULT] |
|
68
|
} |
|
69
|
|
|
70
|
# Returns 1 if the server holds the artifact HASH, or a phantom for it, |
|
71
|
# and has it marked private. |
|
72
|
proc xferserver_private {hash} { |
|
73
|
return [xferserver_count \ |
|
74
|
"blob b, private p WHERE p.rid=b.rid AND b.uuid='$hash'"] |
|
75
|
} |
|
76
|
|
|
77
|
# Send the message BODY to the server. Sets RESULT to the reply, as |
|
78
|
# bytes because it can hold compressed content, and CODE to the exit |
|
79
|
# status of fossil. |
|
80
|
proc xferserver_send {body} { |
|
81
|
write_file msg.txt $body |
|
82
|
fossil_raw test-xfer -R srv.fossil msg.txt |
|
83
|
} |
|
84
|
|
|
85
|
# Send the message BODY. Test NAME passes when fossil exits with status |
|
86
|
# 0 and the reply holds each of the strings given. A string that begins |
|
87
|
# with "!" must be absent. |
|
88
|
proc xferserver_expect {name body args} { |
|
89
|
xferserver_send $body |
|
90
|
test xfer-server-$name {$::CODE == 0 && [holds_strings $::RESULT $args]} |
|
91
|
} |
|
92
|
|
|
93
|
# The message with which the client CLIENT asks for the lock on the |
|
94
|
# check-in CKIN. |
|
95
|
proc xferserver_lock {ckin client} { |
|
96
|
global xferserverLogin xferserverPull |
|
97
|
return "$xferserverLogin${xferserverPull}pragma ci-lock $ckin $client\n" |
|
98
|
} |
|
99
|
|
|
100
|
############################################################################### |
|
101
|
# With no permissions at all, everything is refused. |
|
102
|
|
|
103
|
xferserver_caps "" |
|
104
|
xferserver_expect none-pull $xferserverPull \ |
|
105
|
{error not\sauthorized\sto\sread} |
|
106
|
xferserver_expect none-push $xferserverPush \ |
|
107
|
{error not\sauthorized\sto\swrite} |
|
108
|
xferserver_expect none-clone "clone 3 1\n" \ |
|
109
|
{error not\sauthorized\sto\sclone} |
|
110
|
xferserver_expect none-file "file $xferserverFile 12\nhello world\n" \ |
|
111
|
{error not\sauthorized\sto\swrite} |
|
112
|
xferserver_expect none-cfile "cfile $xferserverFile 12 3\nabc\n" \ |
|
113
|
{error not\sauthorized\sto\swrite} |
|
114
|
xferserver_expect none-uvgimme "uvgimme note.txt\n" "!uvfile" "errors 0" |
|
115
|
xferserver_expect none-reqconfig "reqconfig /project\n" "!config " "errors 0" |
|
116
|
xferserver_expect none-uv-hash "pragma uv-hash $xferserverAbsent\n" \ |
|
117
|
"!uv-pull-only" "!uv-push-ok" |
|
118
|
xferserver_expect none-private "private\n" \ |
|
119
|
{error not\sauthorized\sto\ssync\sprivate} |
|
120
|
xferserver_expect none-send-private "pragma send-private\n" \ |
|
121
|
{error not\sauthorized\sto\ssync\sprivate} |
|
122
|
xferserver_expect none-config "config /project 0\n\n" \ |
|
123
|
{error not\sauthorized\sto\spush\sconfiguration} |
|
124
|
|
|
125
|
############################################################################### |
|
126
|
# Read only: a pull is served, a push after it is turned into a message. |
|
127
|
|
|
128
|
xferserver_caps "o" |
|
129
|
xferserver_expect read-pull $CLIENT_VERSION_CARD$xferserverPull \ |
|
130
|
"igot " "pragma server-version" "errors 0" |
|
131
|
xferserver_expect read-pull-then-push $xferserverPull$xferserverPush \ |
|
132
|
{message pull\sonly\s-\snot\sauthorized\sto\spush} |
|
133
|
xferserver_expect read-gimme \ |
|
134
|
"$CLIENT_VERSION_CARD${xferserverPull}gimme $xferserverFile\n" \ |
|
135
|
"file $xferserverFile" |
|
136
|
# A client that gives no version is taken to be older than 2.0, which |
|
137
|
# cannot be sent a SHA3 hash. |
|
138
|
xferserver_expect read-gimme-old-client \ |
|
139
|
"${xferserverPull}gimme $xferserverFile\n" \ |
|
140
|
"!file $xferserverFile" {error Fossil\sversion\s2.0\sor\slater\srequired} |
|
141
|
xferserver_expect read-gimme-absent \ |
|
142
|
"${xferserverPull}gimme $xferserverAbsent\n" \ |
|
143
|
"!file $xferserverAbsent" "errors 0" |
|
144
|
xferserver_expect read-gimme-no-pull "gimme $xferserverFile\n" \ |
|
145
|
"!file $xferserverFile" "errors 0" |
|
146
|
xferserver_expect read-igot-no-push \ |
|
147
|
"${xferserverPull}igot $xferserverAbsent\n" \ |
|
148
|
"!gimme $xferserverAbsent" "errors 0" |
|
149
|
xferserver_expect read-uv-hash "pragma uv-hash $xferserverAbsent\n" \ |
|
150
|
"pragma uv-pull-only" |
|
151
|
xferserver_expect read-reqconfig "reqconfig /project\n" "config /config " |
|
152
|
xferserver_expect read-reqconfig-old-style "reqconfig project-name\n" \ |
|
153
|
"!config " "errors 0" |
|
154
|
|
|
155
|
############################################################################### |
|
156
|
# Malformed cards are answered with "bad command", or with an error of |
|
157
|
# their own, and never crash. |
|
158
|
|
|
159
|
foreach {xferserverName xferserverBody} [list \ |
|
160
|
gimme-extra-token "gimme $xferserverFile extra\n" \ |
|
161
|
gimme-not-a-hash "gimme nothash\n" \ |
|
162
|
uvgimme-extra-token "uvgimme a b\n" \ |
|
163
|
uvgimme-bad-name "uvgimme ../etc/passwd\n" \ |
|
164
|
igot-alone "igot\n" \ |
|
165
|
igot-not-a-hash "igot nothash\n" \ |
|
166
|
pull-not-a-hash "pull x nothash\n" \ |
|
167
|
pull-too-few "pull x\n" \ |
|
168
|
login-too-few "login tester 0\n" \ |
|
169
|
reqconfig-extra "reqconfig /project extra\n" \ |
|
170
|
config-size-not-int "config /project notint\n" \ |
|
171
|
cookie-alone "cookie\n" \ |
|
172
|
pragma-alone "pragma\n" \ |
|
173
|
unknown-card "frobnicate 1 2 3\n" \ |
|
174
|
] { |
|
175
|
xferserver_expect bad-$xferserverName $xferserverBody {error bad\scommand:} |
|
176
|
} |
|
177
|
xferserver_expect wrong-project "pull x $xferserverAbsent\n" \ |
|
178
|
{error wrong\sproject} |
|
179
|
xferserver_expect cookie "cookie abc\n" "errors 0" |
|
180
|
xferserver_expect unknown-pragma "pragma no-such-pragma 1 2\n" "errors 0" |
|
181
|
xferserver_expect comment-line "# a comment\n$xferserverPull" "errors 0" |
|
182
|
xferserver_expect ci-lock-too-few "pragma ci-lock $xferserverFile\n" "errors 0" |
|
183
|
xferserver_expect ci-unlock-not-a-hash "pragma ci-unlock nothash\n" "errors 0" |
|
184
|
xferserver_expect client-version-short "pragma client-version 22900\n" \ |
|
185
|
"!pragma server-version" "errors 0" |
|
186
|
|
|
187
|
############################################################################### |
|
188
|
# Write without Private: a client that says an artifact is private is not |
|
189
|
# asked for it, and may not send private content. |
|
190
|
|
|
191
|
xferserver_caps "io" |
|
192
|
xferserver_expect write-igot-public \ |
|
193
|
"${xferserverPush}igot $xferserverAbsent\n" \ |
|
194
|
"gimme $xferserverAbsent" |
|
195
|
test xfer-server-write-igot-public-not-private \ |
|
196
|
{[xferserver_private $xferserverAbsent] == 0} |
|
197
|
xferserver_expect write-igot-private-known \ |
|
198
|
"${xferserverPush}igot $xferserverAbsent 1\n" \ |
|
199
|
"!gimme $xferserverAbsent" "errors 0" |
|
200
|
test xfer-server-write-igot-private-marks-phantom \ |
|
201
|
{[xferserver_private $xferserverAbsent] == 1} |
|
202
|
set xferserverUnknown [string repeat fedcba9876543210 4] |
|
203
|
xferserver_expect write-igot-private-unknown \ |
|
204
|
"${xferserverPush}igot $xferserverUnknown 1\n" \ |
|
205
|
"!gimme $xferserverUnknown" "errors 0" |
|
206
|
test xfer-server-write-igot-private-unknown-not-stored \ |
|
207
|
{[xferserver_count "blob WHERE uuid='$xferserverUnknown'"] == 0} |
|
208
|
xferserver_expect write-private "${xferserverPush}private\n" \ |
|
209
|
{error not\sauthorized\sto\ssync\sprivate} |
|
210
|
xferserver_expect write-client-url \ |
|
211
|
"${xferserverPush}pragma client-url http://example.org/x\n" "errors 0" |
|
212
|
test xfer-server-write-client-url-recorded \ |
|
213
|
{[xferserver_count \ |
|
214
|
"config WHERE name GLOB 'syncfrom:*example.org*'"] == 1} |
|
215
|
# A client URL that is not http or https is ignored and the request goes |
|
216
|
# on; it is not read as a path on the server. |
|
217
|
foreach {xferserverName xferserverUrl} {ftp ftp://example.org/y path /} { |
|
218
|
xferserver_expect write-client-url-$xferserverName \ |
|
219
|
"${xferserverPush}pragma client-url $xferserverUrl\n" \ |
|
220
|
"!unknown repository" "errors 0" |
|
221
|
} |
|
222
|
|
|
223
|
# A first word that has the length of a card name and is not it selects no |
|
224
|
# card. A pragma with a name of the length of a known one that is not it |
|
225
|
# does nothing. |
|
226
|
foreach {xferserverName xferserverBody} [list \ |
|
227
|
pull-other-word "pulx x $xferserverPcode\n" \ |
|
228
|
reqconfig-other-word "reqconfih /project\n" \ |
|
229
|
] { |
|
230
|
xferserver_expect bad-$xferserverName $xferserverBody \ |
|
231
|
{error bad\scommand:} "!config " "!igot " |
|
232
|
} |
|
233
|
xferserver_expect write-pragma-other-word \ |
|
234
|
"${xferserverPush}pragma client-urx http://example.net/w\n" "errors 0" |
|
235
|
test xfer-server-write-pragma-other-word-not-recorded \ |
|
236
|
{[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0} |
|
237
|
|
|
238
|
############################################################################### |
|
239
|
# With a login card: private content, configuration, clone and locks. |
|
240
|
|
|
241
|
xferserver_caps "" |
|
242
|
# A private artifact that the server does not have becomes a private |
|
243
|
# phantom. It is asked for only when the client offers to send private |
|
244
|
# content. |
|
245
|
set xferserverPhantom [string repeat 00112233445566778899aabbccddeeff 2] |
|
246
|
xferserver_expect login-igot-private \ |
|
247
|
"$xferserverLogin${xferserverPush}igot $xferserverPhantom 1\n" \ |
|
248
|
"!gimme $xferserverPhantom" "errors 0" |
|
249
|
test xfer-server-login-igot-private-phantom \ |
|
250
|
{[xferserver_private $xferserverPhantom] == 1} |
|
251
|
xferserver_expect login-private "$xferserverLogin${xferserverPush}private\n" \ |
|
252
|
"errors 0" |
|
253
|
xferserver_expect login-send-private \ |
|
254
|
"$xferserverLogin${xferserverPull}pragma send-private\n" "errors 0" |
|
255
|
xferserver_expect login-send-catalog \ |
|
256
|
"$xferserverLogin${xferserverPull}pragma send-catalog\n" \ |
|
257
|
"igot $xferserverFile" |
|
258
|
xferserver_expect login-req-clusters \ |
|
259
|
"$xferserverLogin${xferserverPull}pragma req-clusters\n" "errors 0" |
|
260
|
xferserver_expect login-req-links \ |
|
261
|
"$xferserverLogin${xferserverPull}pragma req-links\n" "errors 0" |
|
262
|
# The hash is that of the empty string under SHA1. |
|
263
|
xferserver_expect login-uv-hash-same \ |
|
264
|
"${xferserverLogin}pragma uv-hash\ |
|
265
|
da39a3ee5e6b4b0d3255bfef95601890afd80709\n" \ |
|
266
|
"!uv-pull-only" "!uv-push-ok" |
|
267
|
|
|
268
|
xferserver_send "${xferserverLogin}reqconfig /project\n" |
|
269
|
test xfer-server-login-reqconfig \ |
|
270
|
{$CODE == 0 && [string first "config /config " $RESULT] >= 0} |
|
271
|
set xferserverCards "" |
|
272
|
foreach xferserverLine [split $RESULT \n] { |
|
273
|
if {[string match "#*" $xferserverLine]} continue |
|
274
|
append xferserverCards $xferserverLine\n |
|
275
|
} |
|
276
|
xferserver_expect login-config-roundtrip \ |
|
277
|
"$xferserverLogin$xferserverPush$xferserverCards" "errors 0" |
|
278
|
xferserver_expect login-config-negative-size \ |
|
279
|
"${xferserverLogin}config /project -5\n" {error bad\scommand:} |
|
280
|
|
|
281
|
# A value in a config card for a table must be a string or blob literal, |
|
282
|
# an integer or NULL. A card with any other value is ignored, and the |
|
283
|
# request goes on. |
|
284
|
proc xferserver_config_user {content} { |
|
285
|
global xferserverLogin xferserverPush |
|
286
|
return "$xferserverLogin${xferserverPush}config /user\ |
|
287
|
[string length $content]\n$content\n" |
|
288
|
} |
|
289
|
foreach {xferserverName xferserverValue} { |
|
290
|
word x column pw blob-not-hex X'zz' blob-odd X'abc' |
|
291
|
} { |
|
292
|
xferserver_expect config-value-$xferserverName [xferserver_config_user \ |
|
293
|
"1262304000 'cfgbad$xferserverName' info $xferserverValue"] \ |
|
294
|
"!Database error" "errors 0" |
|
295
|
} |
|
296
|
test_eq xfer-server-config-value-ignored \ |
|
297
|
[xferserver_count "user WHERE login GLOB 'cfgbad*'"] 0 |
|
298
|
foreach {xferserverName xferserverValue} { |
|
299
|
string 'text' integer 7 null NULL blob X'00ff' empty-blob X'' |
|
300
|
} { |
|
301
|
xferserver_expect config-value-$xferserverName [xferserver_config_user \ |
|
302
|
"1262304000 'cfgok$xferserverName' info $xferserverValue"] "errors 0" |
|
303
|
} |
|
304
|
test_eq xfer-server-config-value-stored \ |
|
305
|
[xferserver_count "user WHERE login GLOB 'cfgok*'"] 5 |
|
306
|
|
|
307
|
# A hash with a zero byte inside is not a hash. Each card that names an |
|
308
|
# artifact by hash refuses it, and nothing is stored under a short hash. |
|
309
|
set xferserverZeroHash "ceafb\000[string repeat a 58]" |
|
310
|
foreach {xferserverName xferserverCard xferserverWant} [list \ |
|
311
|
igot "igot $xferserverZeroHash\n" {error bad\scommand:} \ |
|
312
|
gimme "gimme $xferserverZeroHash\n" {error bad\scommand:} \ |
|
313
|
file "file $xferserverZeroHash 3\nabc\n" "error malformed" \ |
|
314
|
] { |
|
315
|
xferserver_expect hash-zero-byte-$xferserverName \ |
|
316
|
"$xferserverLogin$xferserverPush$xferserverCard" \ |
|
317
|
"!Database error" $xferserverWant |
|
318
|
} |
|
319
|
test_eq xfer-server-hash-zero-byte-nothing-stored \ |
|
320
|
[xferserver_count "blob WHERE length(uuid)<40"] 0 |
|
321
|
|
|
322
|
if {[test_assurance] ne "stress"} { |
|
323
|
test_skip "the tests after the first sections need -assurance stress" |
|
324
|
} |
|
325
|
|
|
326
|
# Clone, in each version of the protocol. A login card to test-xfer does |
|
327
|
# not grant the Clone permission, so "nobody" is given it and these |
|
328
|
# messages have no login card. |
|
329
|
xferserver_caps "g" |
|
330
|
|
|
331
|
# A clone reply holds compressed content, which has zero bytes. The tests |
|
332
|
# that read past one need a test-xfer that writes its whole reply. |
|
333
|
xferserver_send "${CLIENT_VERSION_CARD}clone 3 1\n" |
|
334
|
set xferserverWhole [expr {[string first \0 $::RESULT] >= 0}] |
|
335
|
if {!$xferserverWhole} { |
|
336
|
test_skip_part "clone-v3 and mcdc-clone-private, -public-from-private and\ |
|
337
|
-public-from-public need a test-xfer that writes a reply past a zero\ |
|
338
|
byte" |
|
339
|
} |
|
340
|
xferserver_expect clone-v2-old-client "clone 2 1\n" \ |
|
341
|
"!file " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0" |
|
342
|
xferserver_expect clone-v3-old-client "clone 3 1\n" \ |
|
343
|
"!cfile " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0" |
|
344
|
xferserver_expect clone-v1 "${CLIENT_VERSION_CARD}clone\n" \ |
|
345
|
"push " "igot $xferserverFile" "errors 0" |
|
346
|
xferserver_expect clone-v1-odd-arguments "${CLIENT_VERSION_CARD}clone x y\n" \ |
|
347
|
"push " "errors 0" |
|
348
|
xferserver_expect clone-v2 "${CLIENT_VERSION_CARD}clone 2 1\n" \ |
|
349
|
"file " "clone_seqno 0" |
|
350
|
if {$xferserverWhole} { |
|
351
|
xferserver_expect clone-v3 "${CLIENT_VERSION_CARD}clone 3 1\n" \ |
|
352
|
"cfile " "clone_seqno 0" "errors 0" |
|
353
|
} |
|
354
|
xferserver_expect clone-v3-past-end \ |
|
355
|
"${CLIENT_VERSION_CARD}clone 3 [expr {$xferserverMaxRid+50}]\n" \ |
|
356
|
"!cfile " "clone_seqno 0" |
|
357
|
xferserver_expect clone-v3-zero "${CLIENT_VERSION_CARD}clone 3 0\n" \ |
|
358
|
{error invalid\sclone\ssequence\snumber} |
|
359
|
xferserver_set max-download 1 |
|
360
|
xferserver_expect clone-v3-small-reply "${CLIENT_VERSION_CARD}clone 3 1\n" \ |
|
361
|
"!cfile " "clone_seqno 1" |
|
362
|
xferserver_unset max-download |
|
363
|
xferserver_set max-download-time 0 |
|
364
|
xferserver_expect clone-v3-no-time "${CLIENT_VERSION_CARD}clone 3 1\n" "cfile " |
|
365
|
xferserver_unset max-download-time |
|
366
|
xferserver_set uv-sync 1 |
|
367
|
xferserver_expect clone-uv-sync "${CLIENT_VERSION_CARD}clone 3 1\n" \ |
|
368
|
"pragma uv-pull-only" |
|
369
|
xferserver_unset uv-sync |
|
370
|
xferserver_caps "" |
|
371
|
|
|
372
|
# Check-in locks. The second client to ask for the lock on the same |
|
373
|
# check-in is told who holds it; the holder asking again is not. |
|
374
|
fossil sql -R srv.fossil "SELECT uuid FROM blob WHERE rid=(SELECT max(objid)\ |
|
375
|
FROM event WHERE type='ci')" |
|
376
|
set xferserverCkin [string trim $::RESULT] |
|
377
|
set xferserverClientA [string repeat a 40] |
|
378
|
set xferserverClientB [string repeat b 40] |
|
379
|
xferserver_expect ci-lock-first \ |
|
380
|
[xferserver_lock $xferserverCkin $xferserverClientA] \ |
|
381
|
"!ci-lock-fail" "pragma avoid-delta-manifests" |
|
382
|
xferserver_expect ci-lock-holder-again \ |
|
383
|
[xferserver_lock $xferserverCkin $xferserverClientA] "!ci-lock-fail" |
|
384
|
xferserver_expect ci-lock-second-client \ |
|
385
|
[xferserver_lock $xferserverCkin $xferserverClientB] "pragma ci-lock-fail " |
|
386
|
xferserver_expect ci-unlock \ |
|
387
|
"$xferserverLogin${xferserverPull}pragma ci-unlock $xferserverClientA\n" \ |
|
388
|
"errors 0" |
|
389
|
test xfer-server-ci-unlock-removed \ |
|
390
|
{[xferserver_count "config WHERE name GLOB 'ci-lock-*'"] == 0} |
|
391
|
xferserver_expect ci-lock-after-unlock \ |
|
392
|
[xferserver_lock $xferserverCkin $xferserverClientB] "!ci-lock-fail" |
|
393
|
fossil sql -R srv.fossil \ |
|
394
|
"UPDATE config SET mtime=mtime-100000 WHERE name GLOB 'ci-lock-*'" |
|
395
|
xferserver_expect ci-lock-expired \ |
|
396
|
[xferserver_lock $xferserverCkin $xferserverClientA] "!ci-lock-fail" |
|
397
|
xferserver_set forbid-delta-manifests 0 |
|
398
|
xferserver_expect ci-lock-delta-manifests-allowed \ |
|
399
|
[xferserver_lock $xferserverCkin $xferserverClientA] \ |
|
400
|
"!avoid-delta-manifests" "errors 0" |
|
401
|
|
|
402
|
############################################################################### |
|
403
|
# More cards and pragmas under particular permissions and settings. |
|
404
|
|
|
405
|
xferserver_unset ci-lock-* |
|
406
|
xferserver_unset forbid-delta-manifests |
|
407
|
# An igot card with a flag of 0 offers a public artifact. |
|
408
|
set xferserverPublic [string repeat 0f1e2d3c4b5a6978 4] |
|
409
|
xferserver_expect login-igot-flag-zero \ |
|
410
|
"$xferserverLogin${xferserverPush}igot $xferserverPublic 0\n" \ |
|
411
|
"gimme $xferserverPublic" |
|
412
|
xferserver_expect bad-config-too-few "${xferserverLogin}config /project\n" \ |
|
413
|
{error bad\scommand:} |
|
414
|
xferserver_expect uv-hash-not-a-hash \ |
|
415
|
"${xferserverLogin}pragma uv-hash nothash\n" \ |
|
416
|
"!uv-pull-only" "!uv-push-ok" "errors 0" |
|
417
|
xferserver_expect ci-lock-not-a-hash \ |
|
418
|
[xferserver_lock nothash $xferserverClientA] \ |
|
419
|
"!avoid-delta-manifests" "errors 0" |
|
420
|
xferserver_expect ci-unlock-too-few "${xferserverLogin}pragma ci-unlock\n" \ |
|
421
|
"errors 0" |
|
422
|
xferserver_expect client-url-too-few "${xferserverLogin}pragma client-url\n" \ |
|
423
|
"errors 0" |
|
424
|
|
|
425
|
# The unversioned catalog is sent once in a reply, and a client that may |
|
426
|
# write unversioned files is told so. |
|
427
|
xferserver_caps "oy" |
|
428
|
xferserver_expect uv-hash-may-push "pragma uv-hash $xferserverAbsent\n" \ |
|
429
|
"pragma uv-push-ok" |
|
430
|
xferserver_expect uv-hash-twice \ |
|
431
|
"pragma uv-hash $xferserverAbsent\npragma uv-hash $xferserverAbsent\n" \ |
|
432
|
"pragma uv-push-ok" "errors 0" |
|
433
|
test xfer-server-uv-hash-twice-one-answer \ |
|
434
|
{[regexp -all {pragma uv-push-ok} $RESULT] == 1} |
|
435
|
|
|
436
|
xferserver_caps "o" |
|
437
|
xferserver_expect read-client-url \ |
|
438
|
"${xferserverPull}pragma client-url http://example.net/z\n" "errors 0" |
|
439
|
test xfer-server-read-client-url-not-recorded \ |
|
440
|
{[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0} |
|
441
|
|
|
442
|
# Links to other repositories of the project are given on request, except |
|
443
|
# those on the local host. |
|
444
|
xferserver_set syncwith:http://localhost:8080/y "{}" |
|
445
|
xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \ |
|
446
|
"pragma link http://example.org/x" "!localhost:8080/y" |
|
447
|
# A repository that is mirrored to Git has the address it pushes to among |
|
448
|
# these links when that address is an http or https URL. An address that |
|
449
|
# Git takes and that is not a URL is left out, and the reply goes on. |
|
450
|
xferserver_set gitpush:https://git.example.org/someone/mirror.git "{}" |
|
451
|
xferserver_set gitpush:[email protected]:someone/other.git "{}" |
|
452
|
xferserver_set gitpush:[email protected]:someone/other.git "{}" |
|
453
|
xferserver_send "${xferserverPull}pragma req-links\n" |
|
454
|
test xfer-server-read-req-links-git-address \ |
|
455
|
{$CODE == 0 && [string first "errors 0" $RESULT] >= 0} |
|
456
|
test xfer-server-read-req-links-git-https \ |
|
457
|
{[string match "*pragma link https://git.example.org/someone/mirror.git*" \ |
|
458
|
$RESULT]} |
|
459
|
test xfer-server-read-req-links-git-other-left-out \ |
|
460
|
{![string match "*other.git*" $RESULT]} |
|
461
|
xferserver_unset gitpush:* |
|
462
|
|
|
463
|
# The address configuration is given only to a client that may read |
|
464
|
# addresses. |
|
465
|
xferserver_caps "oe" |
|
466
|
xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0" |
|
467
|
|
|
468
|
xferserver_caps "gx" |
|
469
|
xferserver_expect clone-version-one "${CLIENT_VERSION_CARD}clone 1 1\n" \ |
|
470
|
"push " "igot $xferserverFile" "errors 0" |
|
471
|
xferserver_expect clone-then-gimme \ |
|
472
|
"${CLIENT_VERSION_CARD}clone\ngimme $xferserverFile\n" \ |
|
473
|
"file $xferserverFile" "errors 0" |
|
474
|
xferserver_expect clone-send-private \ |
|
475
|
"${CLIENT_VERSION_CARD}pragma send-private\nclone\n" "push " "errors 0" |
|
476
|
xferserver_set uv-sync 1 |
|
477
|
xferserver_expect clone-uv-sync-after-uv-hash \ |
|
478
|
"${CLIENT_VERSION_CARD}pragma uv-hash $xferserverAbsent\nclone 3 1\n" \ |
|
479
|
"pragma uv-pull-only" |
|
480
|
test xfer-server-clone-uv-sync-one-catalog \ |
|
481
|
{[regexp -all {pragma uv-pull-only} $RESULT] == 1} |
|
482
|
xferserver_unset uv-sync |
|
483
|
xferserver_caps "" |
|
484
|
|
|
485
|
# More check-in locks: a lock on another check-in does not block this |
|
486
|
# one, a lock on a check-in that has a child is dropped, and a lock with |
|
487
|
# no user name is reported as held by "nobody". |
|
488
|
fossil sql -R srv.fossil "SELECT b.uuid FROM blob b, plink p\ |
|
489
|
WHERE b.rid=p.pid AND p.cid=(SELECT max(objid) FROM event WHERE type='ci')" |
|
490
|
set xferserverParent [string trim $::RESULT] |
|
491
|
test xfer-server-setup-parent {[string length $xferserverParent] >= 40} |
|
492
|
xferserver_expect ci-lock-on-parent \ |
|
493
|
[xferserver_lock $xferserverParent $xferserverClientA] \ |
|
494
|
"!ci-lock-fail" "errors 0" |
|
495
|
xferserver_expect ci-lock-parent-not-a-leaf \ |
|
496
|
[xferserver_lock $xferserverParent $xferserverClientB] \ |
|
497
|
"!ci-lock-fail" "errors 0" |
|
498
|
xferserver_expect ci-lock-tip \ |
|
499
|
[xferserver_lock $xferserverCkin $xferserverClientA] \ |
|
500
|
"!ci-lock-fail" "errors 0" |
|
501
|
test xfer-server-ci-lock-parent-dropped \ |
|
502
|
{[xferserver_count "config WHERE name GLOB 'ci-lock-*'"] == 1} |
|
503
|
fossil sql -R srv.fossil "UPDATE config SET value=json_object('clientid',\ |
|
504
|
'$xferserverClientA') WHERE name GLOB 'ci-lock-*'" |
|
505
|
xferserver_expect ci-lock-held-by-nobody \ |
|
506
|
[xferserver_lock $xferserverCkin $xferserverClientB] \ |
|
507
|
"pragma ci-lock-fail nobody " |
|
508
|
xferserver_unset ci-lock-* |
|
509
|
|
|
510
|
# The TH1 transfer scripts run on the server. One that fails is reported. |
|
511
|
xferserver_set xfer-push-script "set xferserverSeen 1" |
|
512
|
xferserver_expect push-script-ok "$xferserverLogin$xferserverPush" "errors 0" |
|
513
|
xferserver_set xfer-push-script "error push-script-says-no" |
|
514
|
xferserver_expect push-script-fails "$xferserverLogin$xferserverPush" \ |
|
515
|
{error push\sscript\sfailed:} "push-script-says-no" |
|
516
|
xferserver_unset xfer-push-script |
|
517
|
xferserver_set xfer-common-script "error common-script-says-no" |
|
518
|
xferserver_expect common-script-fails \ |
|
519
|
"$xferserverLogin$xferserverPull$xferserverPush" \ |
|
520
|
{error common\sscript\sfailed:} "common-script-says-no" |
|
521
|
xferserver_unset xfer-common-script |
|
522
|
|
|
523
|
# A repository with no project code cannot answer a pull or a push. |
|
524
|
xferserver_unset project-code |
|
525
|
xferserver_send "$xferserverLogin$xferserverPull" |
|
526
|
test xfer-server-no-project-code \ |
|
527
|
{$CODE == 1 && [string first "missing project code" $RESULT] >= 0} |
|
528
|
|
|
529
|
############################################################################### |
|
530
|
# The sections below each run in a directory of their own, with a repository |
|
531
|
# and a checkout of their own inside this one. |
|
532
|
|
|
533
|
set xferserverDir [pwd] |
|
534
|
proc xferserver_enter {name} { |
|
535
|
global xferserverDir |
|
536
|
file mkdir [file join $xferserverDir $name] |
|
537
|
cd [file join $xferserverDir $name] |
|
538
|
fossil new .rep.fossil |
|
539
|
fossil open .rep.fossil --nested |
|
540
|
fossil set mtime-changes off |
|
541
|
} |
|
542
|
proc xferserver_leave {} { |
|
543
|
global xferserverDir |
|
544
|
cd $xferserverDir |
|
545
|
} |
|
546
|
|
|
547
|
############################################################################### |
|
548
|
# Malformed "file", "cfile" and "uvfile" cards, sent to the server side |
|
549
|
# of the sync protocol through "fossil test-xfer". The server must |
|
550
|
# refuse each one and must not crash. These cards reach the checks in |
|
551
|
# xfer_accept_file(), xfer_accept_compressed_file() and |
|
552
|
# xfer_accept_unversioned_file() in src/xfer.c. |
|
553
|
|
|
554
|
xferserver_enter cards |
|
555
|
|
|
556
|
set xferserverCardsContent "hello world\n" |
|
557
|
set xferserverCardsSize [string length $xferserverCardsContent] |
|
558
|
write_file a.txt $xferserverCardsContent |
|
559
|
fossil sha3sum a.txt |
|
560
|
set xferserverCardsHash [lindex $RESULT 0] |
|
561
|
|
|
562
|
fossil init tgt.fossil -A tester |
|
563
|
fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'" |
|
564
|
set xferserverCardsPcode [string trim $::RESULT] |
|
565
|
|
|
566
|
# Push the cards in BODY to the target. test-xfer disables the login |
|
567
|
# check, so the nonce and signature in the login card are ignored. The |
|
568
|
# push card has the target's project code. |
|
569
|
# |
|
570
|
# Sets xferserverCardsCode to the exit status of fossil, |
|
571
|
# xferserverCardsErrors to the number of errors that the reply reports, and |
|
572
|
# xferserverCardsStored to 1 when the target now holds the source file. |
|
573
|
proc xferserver_cards_push {body} { |
|
574
|
global xferserverCardsHash xferserverCardsPcode |
|
575
|
global xferserverCardsCode xferserverCardsErrors xferserverCardsStored |
|
576
|
fossil sql -R tgt.fossil "DELETE FROM blob WHERE uuid='$xferserverCardsHash'" |
|
577
|
write_file push.txt "login tester 0 0\npush x $xferserverCardsPcode\n$body" |
|
578
|
fossil_raw test-xfer -R tgt.fossil push.txt |
|
579
|
set xferserverCardsCode $::CODE |
|
580
|
set xferserverCardsErrors 0 |
|
581
|
regexp {errors ([0-9]+)} $::RESULT -> xferserverCardsErrors |
|
582
|
fossil sql -R tgt.fossil \ |
|
583
|
"SELECT count(*) FROM blob WHERE uuid='$xferserverCardsHash' AND size>=0" |
|
584
|
set xferserverCardsStored [string trim $::RESULT] |
|
585
|
} |
|
586
|
|
|
587
|
xferserver_cards_push "file $xferserverCardsHash\ |
|
588
|
$xferserverCardsSize\n$xferserverCardsContent" |
|
589
|
test xfer-cards-valid-accepted \ |
|
590
|
{$xferserverCardsCode == 0 && $xferserverCardsErrors == 0 && |
|
591
|
$xferserverCardsStored == 1} |
|
592
|
|
|
593
|
set xferserverCardsZeros [string repeat 0 64] |
|
594
|
set xferserverCardsUv "uvfile note.txt 1700000000" |
|
595
|
foreach {xferserverCardsName xferserverCardsBody} [list \ |
|
596
|
too-few-tokens "file $xferserverCardsHash\n" \ |
|
597
|
bad-hash-name \ |
|
598
|
"file nothash $xferserverCardsSize\n$xferserverCardsContent" \ |
|
599
|
bad-size-int \ |
|
600
|
"file $xferserverCardsHash notint\n$xferserverCardsContent" \ |
|
601
|
bad-delta-source \ |
|
602
|
"file $xferserverCardsHash zz\ |
|
603
|
$xferserverCardsSize\n$xferserverCardsContent" \ |
|
604
|
size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \ |
|
605
|
size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \ |
|
606
|
size-at-end "file $xferserverCardsHash 5\n" \ |
|
607
|
size-with-nul \ |
|
608
|
"file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \ |
|
609
|
content-wrong-hash \ |
|
610
|
"file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \ |
|
611
|
cfile-too-few "cfile $xferserverCardsHash\n" \ |
|
612
|
cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \ |
|
613
|
uvfile-too-few "uvfile note.txt\n" \ |
|
614
|
uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \ |
|
615
|
uvfile-mtime-nul \ |
|
616
|
"uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \ |
|
617
|
uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \ |
|
618
|
uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \ |
|
619
|
uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \ |
|
620
|
uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \ |
|
621
|
uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \ |
|
622
|
] { |
|
623
|
xferserver_cards_push $xferserverCardsBody |
|
624
|
test xfer-cards-reject-$xferserverCardsName \ |
|
625
|
{$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 && |
|
626
|
$xferserverCardsStored == 0} |
|
627
|
} |
|
628
|
|
|
629
|
fossil sql -R tgt.fossil \ |
|
630
|
"INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)" |
|
631
|
xferserver_cards_push "file $xferserverCardsHash\ |
|
632
|
$xferserverCardsSize\n$xferserverCardsContent" |
|
633
|
test xfer-cards-reject-shunned \ |
|
634
|
{$xferserverCardsCode == 0 && $xferserverCardsStored == 0} |
|
635
|
|
|
636
|
xferserver_leave |
|
637
|
|
|
638
|
############################################################################### |
|
639
|
# More cards sent to the server side of the sync protocol through |
|
640
|
# "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme" |
|
641
|
# and "uvgimme" that xfer-cards.test and xfer-server.test do not send. |
|
642
|
# Each has a stated effect on the server's repository or on the reply, |
|
643
|
# and none may crash. |
|
644
|
|
|
645
|
xferserver_enter edge |
|
646
|
|
|
647
|
# The answer of one SQL statement on the server, trimmed. |
|
648
|
# |
|
649
|
proc xferserver_sql {sql} { |
|
650
|
return [fossil_sql $sql srv.fossil] |
|
651
|
} |
|
652
|
|
|
653
|
# Send the cards BODY to the server after a client-version card and a |
|
654
|
# card of KIND, which is "push" or "pull". RESULT is the reply, as |
|
655
|
# bytes. xferserverEdgeErrors is the number of errors that the reply reports, |
|
656
|
# or -1 if it reports none at all. |
|
657
|
# |
|
658
|
proc xferserver_edge_send {kind body} { |
|
659
|
global xferserverEdgePcode xferserverEdgeErrors CLIENT_VERSION_CARD |
|
660
|
write_file msg.txt "${CLIENT_VERSION_CARD}$kind x $xferserverEdgePcode\n$body" |
|
661
|
fossil_raw test-xfer -R srv.fossil msg.txt |
|
662
|
set xferserverEdgeErrors -1 |
|
663
|
regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors |
|
664
|
} |
|
665
|
|
|
666
|
# Content as a "cfile" card carries it: the size, then the zlib stream. |
|
667
|
# |
|
668
|
proc xferserver_compress {text} { |
|
669
|
return [binary format I [string length $text]][zlib compress $text] |
|
670
|
} |
|
671
|
|
|
672
|
# 1 if the server holds the content of the artifact HASH. |
|
673
|
# |
|
674
|
proc xferserver_holds {hash} { |
|
675
|
return [xferserver_sql "SELECT count(*) FROM blob |
|
676
|
WHERE uuid='$hash' AND size>=0"] |
|
677
|
} |
|
678
|
|
|
679
|
# Remove every trace of the artifacts HASHES from the server. |
|
680
|
# |
|
681
|
proc xferserver_forget {hashes} { |
|
682
|
set list '[join $hashes ',']' |
|
683
|
xferserver_sql "CREATE TEMP TABLE gone AS |
|
684
|
SELECT rid FROM blob WHERE uuid IN ($list); |
|
685
|
DELETE FROM delta WHERE rid IN gone OR srcid IN gone; |
|
686
|
DELETE FROM phantom WHERE rid IN gone; |
|
687
|
DELETE FROM unclustered WHERE rid IN gone; |
|
688
|
DELETE FROM private WHERE rid IN gone; |
|
689
|
DELETE FROM blob WHERE rid IN gone" |
|
690
|
} |
|
691
|
|
|
692
|
# Three versions of one file, so that the server stores deltas. |
|
693
|
set xferserverEdgeText "" |
|
694
|
for {set xferserverEdgeI 0} {$xferserverEdgeI < 40} {incr xferserverEdgeI} { |
|
695
|
append xferserverEdgeText \ |
|
696
|
"line $xferserverEdgeI of a file that is worth a delta\n" |
|
697
|
} |
|
698
|
foreach xferserverEdgeI {1 2 3} { |
|
699
|
append xferserverEdgeText "version $xferserverEdgeI\n" |
|
700
|
write_file a.txt $xferserverEdgeText |
|
701
|
if {$xferserverEdgeI == 1} {fossil add a.txt} |
|
702
|
fossil commit -m "xferedge-v$xferserverEdgeI" --no-warnings |
|
703
|
set xferserverEdgeVersion($xferserverEdgeI) $xferserverEdgeText |
|
704
|
} |
|
705
|
file copy .rep.fossil srv.fossil |
|
706
|
fossil unversioned list -R srv.fossil |
|
707
|
set xferserverEdgePcode [xferserver_sql \ |
|
708
|
"SELECT value FROM config WHERE name='project-code'"] |
|
709
|
xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'" |
|
710
|
set xferserverEdgeAbsent [string repeat 0123456789abcdef 4] |
|
711
|
|
|
712
|
############################################################################### |
|
713
|
# "file" cards. |
|
714
|
|
|
715
|
set xferserverEdgeNew "content that the server does not have yet\n" |
|
716
|
set xferserverEdgeNewHash [sha3_text $xferserverEdgeNew] |
|
717
|
set xferserverEdgeLen [string length $xferserverEdgeNew] |
|
718
|
|
|
719
|
foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
|
720
|
too-many-tokens \ |
|
721
|
"file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\ |
|
722
|
$xferserverEdgeLen\n$xferserverEdgeNew" \ |
|
723
|
negative-size "file $xferserverEdgeNewHash -1\n$xferserverEdgeNew" \ |
|
724
|
] { |
|
725
|
xferserver_edge_send push $xferserverEdgeCard |
|
726
|
test xfer-edge-file-$xferserverEdgeName \ |
|
727
|
{$CODE == 0 && $xferserverEdgeErrors > 0 && |
|
728
|
![xferserver_holds $xferserverEdgeNewHash]} |
|
729
|
} |
|
730
|
|
|
731
|
# A delta whose source the server does not have is kept as it is, with a |
|
732
|
# phantom for the source, and is public. |
|
733
|
xferserver_edge_send push \ |
|
734
|
"file $xferserverEdgeNewHash $xferserverEdgeAbsent 9\nnot-delta" |
|
735
|
test xfer-edge-file-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0} |
|
736
|
test_eq xfer-edge-file-dangling-delta-stored [xferserver_sql "SELECT |
|
737
|
(SELECT size FROM blob WHERE uuid='$xferserverEdgeAbsent'), |
|
738
|
(SELECT count(*) FROM delta, blob a, blob b WHERE delta.rid=a.rid |
|
739
|
AND delta.srcid=b.rid AND a.uuid='$xferserverEdgeNewHash' |
|
740
|
AND b.uuid='$xferserverEdgeAbsent'), |
|
741
|
(SELECT count(*) FROM private, blob WHERE private.rid=blob.rid |
|
742
|
AND uuid='$xferserverEdgeNewHash')"] {-1|1|0} |
|
743
|
xferserver_forget [list $xferserverEdgeNewHash $xferserverEdgeAbsent] |
|
744
|
|
|
745
|
############################################################################### |
|
746
|
# "cfile" cards. |
|
747
|
|
|
748
|
set xferserverEdgeZ [xferserver_compress $xferserverEdgeNew] |
|
749
|
set xferserverEdgeZLen [string length $xferserverEdgeZ] |
|
750
|
foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
|
751
|
too-many-tokens \ |
|
752
|
"cfile $xferserverEdgeNewHash $xferserverEdgeAbsent 1 $xferserverEdgeLen\ |
|
753
|
$xferserverEdgeZLen\n$xferserverEdgeZ" \ |
|
754
|
bad-hash \ |
|
755
|
"cfile nothash $xferserverEdgeLen $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
|
756
|
bad-usize \ |
|
757
|
"cfile $xferserverEdgeNewHash notint\ |
|
758
|
$xferserverEdgeZLen\n$xferserverEdgeZ" \ |
|
759
|
bad-csize \ |
|
760
|
"cfile $xferserverEdgeNewHash $xferserverEdgeLen notint\n$xferserverEdgeZ" \ |
|
761
|
negative-usize \ |
|
762
|
"cfile $xferserverEdgeNewHash -1 $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
|
763
|
negative-csize \ |
|
764
|
"cfile $xferserverEdgeNewHash $xferserverEdgeLen -1\n$xferserverEdgeZ" \ |
|
765
|
bad-source \ |
|
766
|
"cfile $xferserverEdgeNewHash zz $xferserverEdgeLen\ |
|
767
|
$xferserverEdgeZLen\n$xferserverEdgeZ" \ |
|
768
|
] { |
|
769
|
xferserver_edge_send push $xferserverEdgeCard |
|
770
|
test xfer-edge-cfile-$xferserverEdgeName \ |
|
771
|
{$CODE == 0 && $xferserverEdgeErrors > 0 && |
|
772
|
![xferserver_holds $xferserverEdgeNewHash]} |
|
773
|
} |
|
774
|
|
|
775
|
xferserver_edge_send push "cfile $xferserverEdgeNewHash $xferserverEdgeLen\ |
|
776
|
$xferserverEdgeZLen\n$xferserverEdgeZ" |
|
777
|
test xfer-edge-cfile-accepted \ |
|
778
|
{$CODE == 0 && $xferserverEdgeErrors == 0 && |
|
779
|
[xferserver_holds $xferserverEdgeNewHash]} |
|
780
|
fossil artifact $xferserverEdgeNewHash -R srv.fossil cfile.out |
|
781
|
test_eq xfer-edge-cfile-content [read_file cfile.out] $xferserverEdgeNew |
|
782
|
|
|
783
|
# The size recorded for the artifact is that of its content, not of its |
|
784
|
# compressed form. |
|
785
|
test_eq xfer-edge-cfile-size-recorded [xferserver_sql "SELECT size FROM blob |
|
786
|
WHERE uuid='$xferserverEdgeNewHash'"] $xferserverEdgeLen |
|
787
|
|
|
788
|
# Content that does not have the hash or the size on the card is refused |
|
789
|
# with an error, as it is for a "file" card. |
|
790
|
set xferserverEdgeWrong "content that is not what its card says\n" |
|
791
|
set xferserverEdgeZ [xferserver_compress $xferserverEdgeWrong] |
|
792
|
xferserver_edge_send push "cfile $xferserverEdgeAbsent\ |
|
793
|
[string length $xferserverEdgeWrong]\ |
|
794
|
[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
|
795
|
test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0} |
|
796
|
test xfer-edge-cfile-wrong-hash-not-stored \ |
|
797
|
{![xferserver_holds $xferserverEdgeAbsent]} |
|
798
|
set xferserverEdgeSized "content with the wrong size on its card\n" |
|
799
|
set xferserverEdgeSizedHash [sha3_text $xferserverEdgeSized] |
|
800
|
set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized] |
|
801
|
xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\ |
|
802
|
[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
|
803
|
test xfer-edge-cfile-wrong-size \ |
|
804
|
{$CODE == 0 && $xferserverEdgeErrors > 0 && |
|
805
|
![xferserver_holds $xferserverEdgeSizedHash]} |
|
806
|
xferserver_edge_send push \ |
|
807
|
"cfile $xferserverEdgeAbsent 16 20\n\x00\x00\x00\x10not zlib data !!" |
|
808
|
test xfer-edge-cfile-not-compressed \ |
|
809
|
{$CODE == 0 && $xferserverEdgeErrors > 0 && |
|
810
|
![xferserver_holds $xferserverEdgeAbsent]} |
|
811
|
|
|
812
|
# A shunned artifact is not stored. |
|
813
|
set xferserverEdgeShun "content that the server has shunned\n" |
|
814
|
set xferserverEdgeShunHash [sha3_text $xferserverEdgeShun] |
|
815
|
xferserver_sql "INSERT INTO shun(uuid,mtime)\ |
|
816
|
VALUES('$xferserverEdgeShunHash',0)" |
|
817
|
set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun] |
|
818
|
xferserver_edge_send push "cfile $xferserverEdgeShunHash\ |
|
819
|
[string length $xferserverEdgeShun]\ |
|
820
|
[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
|
821
|
test xfer-edge-cfile-shunned \ |
|
822
|
{$CODE == 0 && ![xferserver_holds $xferserverEdgeShunHash]} |
|
823
|
|
|
824
|
# A compressed delta whose source the server does not have is kept as it |
|
825
|
# is. Its hash cannot be checked yet; its size can, and a delta that |
|
826
|
# does not make content of the size on the card is refused. |
|
827
|
set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4] |
|
828
|
write_file delta-src.txt $xferserverEdgeVersion(1) |
|
829
|
write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n" |
|
830
|
fossil test-delta-create delta-src.txt delta-tgt.txt delta.out |
|
831
|
set xferserverEdgeTgtHash [sha3_text [read_file delta-tgt.txt]] |
|
832
|
set xferserverEdgeZ [xferserver_compress [read_file delta.out]] |
|
833
|
xferserver_edge_send push "cfile $xferserverEdgeTgtHash\ |
|
834
|
$xferserverEdgeAbsent2 7777\ |
|
835
|
[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
|
836
|
test xfer-edge-cfile-dangling-delta-wrong-size \ |
|
837
|
{$CODE == 0 && $xferserverEdgeErrors > 0} |
|
838
|
xferserver_edge_send push "cfile $xferserverEdgeTgtHash $xferserverEdgeAbsent2\ |
|
839
|
[file size delta-tgt.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
|
840
|
test xfer-edge-cfile-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0} |
|
841
|
test_eq xfer-edge-cfile-dangling-delta-stored [xferserver_sql "SELECT a.size |
|
842
|
FROM delta, blob a WHERE delta.rid=a.rid |
|
843
|
AND a.uuid='$xferserverEdgeTgtHash'"] \ |
|
844
|
[file size delta-tgt.txt] |
|
845
|
xferserver_forget [list $xferserverEdgeTgtHash $xferserverEdgeAbsent2] |
|
846
|
|
|
847
|
# Content that is too short to hold a size, or that is not compressed |
|
848
|
# data, is refused as malformed, whether or not the card gives a size |
|
849
|
# for the content. |
|
850
|
foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
|
851
|
short-content "cfile $xferserverEdgeAbsent 5 3\nabc\n" \ |
|
852
|
no-usize-short "cfile $xferserverEdgeAbsent 0 3\nabc\n" \ |
|
853
|
no-usize-not-compressed \ |
|
854
|
"cfile $xferserverEdgeAbsent 0 20\n\x00\x00\x00\x10not zlib data !!" \ |
|
855
|
] { |
|
856
|
xferserver_edge_send push $xferserverEdgeCard |
|
857
|
test xfer-edge-cfile-$xferserverEdgeName \ |
|
858
|
{$CODE == 0 && $xferserverEdgeErrors > 0 && |
|
859
|
[string first {malformed+cfile+content} $RESULT] >= 0 && |
|
860
|
![xferserver_holds $xferserverEdgeAbsent]} |
|
861
|
} |
|
862
|
|
|
863
|
# A compressed delta whose source the server has is applied and checked. |
|
864
|
# One that does not apply, and one that makes content with another hash |
|
865
|
# than the card gives, are refused; one that makes the content that the |
|
866
|
# card names is stored. |
|
867
|
set xferserverEdgeSrcHash [sha3_text $xferserverEdgeVersion(1)] |
|
868
|
test xfer-edge-cfile-delta-setup-source-held \ |
|
869
|
{[xferserver_holds $xferserverEdgeSrcHash] == 1} |
|
870
|
write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n" |
|
871
|
fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out |
|
872
|
set xferserverEdgeTgt2Hash [sha3_text [read_file delta-tgt2.txt]] |
|
873
|
set xferserverEdgeDelta [read_file delta2.out] |
|
874
|
# The same delta without the checksum that ends it. |
|
875
|
regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta |
|
876
|
test xfer-edge-cfile-delta-setup-cut \ |
|
877
|
{[string length $xferserverEdgeBadDelta] > 0 && |
|
878
|
[string length $xferserverEdgeBadDelta] |
|
879
|
< [string length $xferserverEdgeDelta]} |
|
880
|
foreach {xferserverEdgeName xferserverEdgeHash xferserverEdgeBody |
|
881
|
xferserverEdgeStored} [list \ |
|
882
|
does-not-apply $xferserverEdgeTgt2Hash $xferserverEdgeBadDelta 0 \ |
|
883
|
other-hash $xferserverEdgeAbsent2 $xferserverEdgeDelta 0 \ |
|
884
|
accepted $xferserverEdgeTgt2Hash $xferserverEdgeDelta 1 \ |
|
885
|
] { |
|
886
|
set xferserverEdgeZ [xferserver_compress $xferserverEdgeBody] |
|
887
|
xferserver_edge_send push "cfile $xferserverEdgeHash $xferserverEdgeSrcHash\ |
|
888
|
[file size delta-tgt2.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
|
889
|
test xfer-edge-cfile-delta-$xferserverEdgeName \ |
|
890
|
{$CODE == 0 && ($xferserverEdgeErrors > 0) != $xferserverEdgeStored |
|
891
|
&& [xferserver_holds $xferserverEdgeHash] == $xferserverEdgeStored} |
|
892
|
} |
|
893
|
fossil artifact $xferserverEdgeTgt2Hash -R srv.fossil cfile-delta.out |
|
894
|
test_eq xfer-edge-cfile-delta-content [read_file cfile-delta.out] \ |
|
895
|
[read_file delta-tgt2.txt] |
|
896
|
xferserver_forget [list $xferserverEdgeTgt2Hash] |
|
897
|
|
|
898
|
############################################################################### |
|
899
|
# "uvfile" cards. |
|
900
|
|
|
901
|
set xferserverEdgeUv "an unversioned note\n" |
|
902
|
set xferserverEdgeUvHash [sha3_text $xferserverEdgeUv] |
|
903
|
set xferserverEdgeUvLen [string length $xferserverEdgeUv] |
|
904
|
proc xferserver_uv {name} { |
|
905
|
return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL |
|
906
|
FROM unversioned WHERE name='$name'"] |
|
907
|
} |
|
908
|
|
|
909
|
foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
|
910
|
five-tokens \ |
|
911
|
"uvfile note.txt 1700000000 $xferserverEdgeUvHash\ |
|
912
|
$xferserverEdgeUvLen\n$xferserverEdgeUv" \ |
|
913
|
bad-filename \ |
|
914
|
"uvfile ../note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\ |
|
915
|
0\n$xferserverEdgeUv" \ |
|
916
|
] { |
|
917
|
xferserver_edge_send push $xferserverEdgeCard |
|
918
|
test xfer-edge-uvfile-$xferserverEdgeName \ |
|
919
|
{$CODE == 0 && $xferserverEdgeErrors > 0} |
|
920
|
} |
|
921
|
test_eq xfer-edge-uvfile-none-stored [xferserver_sql \ |
|
922
|
"SELECT count(*) FROM unversioned"] 0 |
|
923
|
|
|
924
|
xferserver_edge_send push \ |
|
925
|
"uvfile note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\ |
|
926
|
0\n$xferserverEdgeUv" |
|
927
|
test xfer-edge-uvfile-accepted {$CODE == 0 && $xferserverEdgeErrors == 0} |
|
928
|
test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \ |
|
929
|
"1700000000|$xferserverEdgeUvLen|0|1" |
|
930
|
|
|
931
|
# Content that compresses well is stored compressed. |
|
932
|
set xferserverEdgeBig [string repeat "the same line again and again\n" 200] |
|
933
|
set xferserverEdgeBigHash [sha3_text $xferserverEdgeBig] |
|
934
|
xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\ |
|
935
|
[string length $xferserverEdgeBig] 0\n$xferserverEdgeBig" |
|
936
|
test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \ |
|
937
|
"1700000000|[string length $xferserverEdgeBig]|1|1" |
|
938
|
|
|
939
|
# The same content with a newer time and no content: only the time |
|
940
|
# changes. |
|
941
|
xferserver_edge_send push \ |
|
942
|
"uvfile note.txt 1700000500 $xferserverEdgeUvHash $xferserverEdgeUvLen 4\n" |
|
943
|
test_eq xfer-edge-uvfile-time-only [xferserver_uv note.txt] \ |
|
944
|
"1700000500|$xferserverEdgeUvLen|0|1" |
|
945
|
|
|
946
|
# Older content does not replace newer. |
|
947
|
set xferserverEdgeOld "an older note\n" |
|
948
|
xferserver_edge_send push "uvfile note.txt 1600000000\ |
|
949
|
[sha3_text $xferserverEdgeOld]\ |
|
950
|
[string length $xferserverEdgeOld] 0\n$xferserverEdgeOld" |
|
951
|
test xfer-edge-uvfile-older {$CODE == 0} |
|
952
|
test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash |
|
953
|
FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash |
|
954
|
|
|
955
|
# A newer deletion empties the file but keeps its name. |
|
956
|
xferserver_edge_send push "uvfile note.txt 1700001000 - 0 1\n" |
|
957
|
test xfer-edge-uvfile-delete {$CODE == 0 && $xferserverEdgeErrors == 0} |
|
958
|
test_eq xfer-edge-uvfile-deleted [xferserver_uv note.txt] {1700001000|0|0|0} |
|
959
|
|
|
960
|
# Without the permission to write unversioned files, nothing is stored. |
|
961
|
xferserver_sql "UPDATE user SET cap='oi' WHERE login='nobody'" |
|
962
|
xferserver_edge_send push \ |
|
963
|
"uvfile other.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\ |
|
964
|
0\n$xferserverEdgeUv" |
|
965
|
test xfer-edge-uvfile-no-permission {$CODE == 0 && $xferserverEdgeErrors > 0} |
|
966
|
test_eq xfer-edge-uvfile-no-permission-stored [xferserver_sql "SELECT count(*) |
|
967
|
FROM unversioned WHERE name='other.txt'"] 0 |
|
968
|
xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'" |
|
969
|
|
|
970
|
############################################################################### |
|
971
|
# "uvgimme" cards. |
|
972
|
|
|
973
|
xferserver_edge_send pull "uvgimme big.txt\n" |
|
974
|
test xfer-edge-uvgimme-file {$CODE == 0 && [string first \ |
|
975
|
"uvfile big.txt 1700000000 $xferserverEdgeBigHash [string length\ |
|
976
|
$xferserverEdgeBig] 0\n$xferserverEdgeBig" \ |
|
977
|
$RESULT] >= 0} |
|
978
|
xferserver_edge_send pull "uvgimme note.txt\n" |
|
979
|
test xfer-edge-uvgimme-deleted \ |
|
980
|
{$CODE == 0 && |
|
981
|
[string first "uvfile note.txt 1700001000 - 0 1\n" $RESULT] >= 0} |
|
982
|
xferserver_edge_send pull "uvgimme no-such-file.txt\n" |
|
983
|
test xfer-edge-uvgimme-unknown \ |
|
984
|
{$CODE == 0 && [string first "uvfile no-such-file.txt" $RESULT] < 0} |
|
985
|
|
|
986
|
############################################################################### |
|
987
|
# "gimme" cards. |
|
988
|
|
|
989
|
proc xferserver_file_hash {version} { |
|
990
|
return [xferserver_sql "SELECT uuid FROM blob, mlink, event |
|
991
|
WHERE blob.rid=mlink.fid AND mlink.mid=event.objid |
|
992
|
AND event.comment='xferedge-v$version'"] |
|
993
|
} |
|
994
|
set xferserverEdgeV1 [xferserver_file_hash 1] |
|
995
|
set xferserverEdgeV2 [xferserver_file_hash 2] |
|
996
|
set xferserverEdgeV3 [xferserver_file_hash 3] |
|
997
|
|
|
998
|
# The server sends a version as a delta from the version before it, |
|
999
|
# which the client is likely to have. The first version has none and |
|
1000
|
# goes whole, although the server stores it as a delta. |
|
1001
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1002
|
test xfer-edge-gimme-delta-from-parent \ |
|
1003
|
{$CODE == 0 && |
|
1004
|
[string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0} |
|
1005
|
xferserver_edge_send pull "gimme $xferserverEdgeV1\n" |
|
1006
|
test xfer-edge-gimme-whole {$CODE == 0 && [string first \ |
|
1007
|
"file $xferserverEdgeV1 [string length $xferserverEdgeVersion(1)]\n"\ |
|
1008
|
$RESULT] >= 0} |
|
1009
|
|
|
1010
|
# An artifact that the server does not have, and one that it has |
|
1011
|
# shunned, are not sent. |
|
1012
|
xferserver_edge_send pull "gimme $xferserverEdgeAbsent\n" |
|
1013
|
test xfer-edge-gimme-absent \ |
|
1014
|
{$CODE == 0 && [string first "file $xferserverEdgeAbsent" $RESULT] < 0} |
|
1015
|
xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV3',0)" |
|
1016
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1017
|
test xfer-edge-gimme-shunned \ |
|
1018
|
{$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0} |
|
1019
|
xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV3'" |
|
1020
|
|
|
1021
|
# A delta is not sent from a shunned source: the content goes whole. |
|
1022
|
xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV2',0)" |
|
1023
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1024
|
test xfer-edge-gimme-shunned-source {$CODE == 0 && [string first \ |
|
1025
|
"file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\ |
|
1026
|
$RESULT] >= 0} |
|
1027
|
xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV2'" |
|
1028
|
|
|
1029
|
# A private artifact is not sent to a client that has not asked for |
|
1030
|
# private content, and a delta is not sent from a private source. |
|
1031
|
xferserver_sql "INSERT INTO private SELECT rid FROM blob |
|
1032
|
WHERE uuid='$xferserverEdgeV3'" |
|
1033
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1034
|
test xfer-edge-gimme-private \ |
|
1035
|
{$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0} |
|
1036
|
xferserver_sql "DELETE FROM private" |
|
1037
|
xferserver_sql "INSERT INTO private SELECT rid FROM blob |
|
1038
|
WHERE uuid='$xferserverEdgeV2'" |
|
1039
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1040
|
test xfer-edge-gimme-private-source {$CODE == 0 && [string first \ |
|
1041
|
"file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\ |
|
1042
|
$RESULT] >= 0} |
|
1043
|
xferserver_sql "DELETE FROM private" |
|
1044
|
|
|
1045
|
# A delta is not sent from a version that the server holds only as a |
|
1046
|
# delta whose own source has not arrived, because that version cannot be |
|
1047
|
# rebuilt: the content goes whole. |
|
1048
|
set xferserverEdgeMissing [string repeat 0a1b2c3d 8] |
|
1049
|
set xferserverEdgeV2Src [xferserver_sql "SELECT srcid FROM delta, blob |
|
1050
|
WHERE delta.rid=blob.rid AND uuid='$xferserverEdgeV2'"] |
|
1051
|
xferserver_sql "INSERT INTO blob(rcvid,size,uuid) |
|
1052
|
VALUES(0,-1,'$xferserverEdgeMissing'); |
|
1053
|
INSERT INTO phantom SELECT rid FROM blob |
|
1054
|
WHERE uuid='$xferserverEdgeMissing'; |
|
1055
|
REPLACE INTO delta(rid,srcid) SELECT a.rid, b.rid FROM blob a, blob b |
|
1056
|
WHERE a.uuid='$xferserverEdgeV2' AND b.uuid='$xferserverEdgeMissing'" |
|
1057
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1058
|
test xfer-edge-gimme-source-cannot-be-rebuilt {$CODE == 0 && [string first \ |
|
1059
|
"file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\ |
|
1060
|
$RESULT] >= 0} |
|
1061
|
if {$xferserverEdgeV2Src eq ""} { |
|
1062
|
xferserver_sql "DELETE FROM delta WHERE rid=(SELECT rid FROM blob |
|
1063
|
WHERE uuid='$xferserverEdgeV2')" |
|
1064
|
} else { |
|
1065
|
xferserver_sql "UPDATE delta SET srcid=$xferserverEdgeV2Src |
|
1066
|
WHERE rid=(SELECT rid FROM blob WHERE uuid='$xferserverEdgeV2')" |
|
1067
|
} |
|
1068
|
xferserver_forget [list $xferserverEdgeMissing] |
|
1069
|
xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
|
1070
|
test xfer-edge-gimme-delta-again \ |
|
1071
|
{$CODE == 0 && |
|
1072
|
[string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0} |
|
1073
|
|
|
1074
|
fossil test-integrity -R srv.fossil |
|
1075
|
test xfer-edge-integrity {$CODE == 0} |
|
1076
|
|
|
1077
|
############################################################################### |
|
1078
|
# A repository that has never held an unversioned file has no table for |
|
1079
|
# them. A request for one is answered like any other request for a file |
|
1080
|
# that is not there. |
|
1081
|
|
|
1082
|
fossil init fresh.fossil |
|
1083
|
fossil sql -R fresh.fossil "UPDATE user SET cap='oiy' WHERE login='nobody'" |
|
1084
|
fossil sql -R fresh.fossil "SELECT value FROM config WHERE name='project-code'" |
|
1085
|
write_file msg.txt \ |
|
1086
|
"${CLIENT_VERSION_CARD}pull x [string trim $RESULT]\nuvgimme note.txt\n" |
|
1087
|
fossil_raw test-xfer -R fresh.fossil msg.txt |
|
1088
|
test xfer-edge-uvgimme-no-table \ |
|
1089
|
{$CODE == 0 && [string first "Database error" $RESULT] < 0} |
|
1090
|
|
|
1091
|
xferserver_leave |
|
1092
|
|
|
1093
|
############################################################################### |
|
1094
|
# The login card of the sync protocol, checked by a server as it is on a |
|
1095
|
# network. A real client syncs with a real server through |
|
1096
|
# standin/scenario-wire.tcl, which hands each request to "fossil http" |
|
1097
|
# on the server's repository without --localauth, so the server decides |
|
1098
|
# what the client may do from the login card alone. Fossil puts no login |
|
1099
|
# card on a request that goes through a transport command, so the |
|
1100
|
# stand-in adds the card, made as http_build_login_card() makes it. |
|
1101
|
|
|
1102
|
xferserver_enter login |
|
1103
|
|
|
1104
|
write_file a.txt "first\n" |
|
1105
|
fossil add a.txt |
|
1106
|
fossil commit -m "xferlogin-c1" --no-warnings |
|
1107
|
file copy .rep.fossil srv.fossil |
|
1108
|
file copy .rep.fossil cli.fossil |
|
1109
|
|
|
1110
|
set xferserverLoginWire [file join [pwd] wire.tcl] |
|
1111
|
file copy [file join $::testfiledir standin scenario-wire.tcl] \ |
|
1112
|
$xferserverLoginWire |
|
1113
|
set xferserverLoginWire "\"[info nameofexecutable]\" \"$xferserverLoginWire\"" |
|
1114
|
set ::env(SCN_EXE) $::fossilexe |
|
1115
|
set ::env(SCN_REPO) [file join [pwd] srv.fossil] |
|
1116
|
set ::env(SCN_FAULT) 0 |
|
1117
|
set ::env(SCN_AUTH) 1 |
|
1118
|
fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'" |
|
1119
|
set ::env(SCN_PROJECT) [string trim $RESULT] |
|
1120
|
|
|
1121
|
# Sync the client with the server as USERINFO, which is "user:password" |
|
1122
|
# or empty for no login card. VERB is pull, push or sync. |
|
1123
|
# |
|
1124
|
proc xferserver_login_sync {verb userinfo} { |
|
1125
|
global xferserverLoginWire |
|
1126
|
if {$userinfo ne ""} {set ::env(SCN_LOGIN) $userinfo} |
|
1127
|
fossil_raw -seconds 60 $verb http://xferlogin.invalid/x --once \ |
|
1128
|
--transport-command $xferserverLoginWire -R cli.fossil |
|
1129
|
unset -nocomplain ::env(SCN_LOGIN) |
|
1130
|
} |
|
1131
|
|
|
1132
|
# The number of artifacts with content that the repository holds. |
|
1133
|
# |
|
1134
|
proc xferserver_blobs {repo} { |
|
1135
|
fossil sql -R $repo "SELECT count(*) FROM blob WHERE size>=0" |
|
1136
|
return [string trim $::RESULT] |
|
1137
|
} |
|
1138
|
|
|
1139
|
# Give the server something that the client does not have. |
|
1140
|
# |
|
1141
|
proc xferserver_login_new_on_server {} { |
|
1142
|
global xferserverLoginN |
|
1143
|
write_file srv-[incr xferserverLoginN].txt \ |
|
1144
|
"content number $xferserverLoginN\n" |
|
1145
|
fossil test-content-put srv-$xferserverLoginN.txt -R srv.fossil |
|
1146
|
} |
|
1147
|
set xferserverLoginN 0 |
|
1148
|
|
|
1149
|
# Nobody may do anything; the user "tester" may read and write. |
|
1150
|
xferserver_sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')" |
|
1151
|
fossil user new tester "" secret -R srv.fossil |
|
1152
|
xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'" |
|
1153
|
test_eq xfer-login-password-stored-hashed \ |
|
1154
|
[xferserver_sql "SELECT length(pw) FROM user WHERE login='tester'"] 40 |
|
1155
|
|
|
1156
|
############################################################################### |
|
1157
|
# With no login card the client is "nobody", who may not read. |
|
1158
|
|
|
1159
|
xferserver_login_new_on_server |
|
1160
|
set xferserverLoginBefore [xferserver_blobs cli.fossil] |
|
1161
|
xferserver_login_sync pull "" |
|
1162
|
test xfer-login-nobody-refused \ |
|
1163
|
{$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0} |
|
1164
|
test_eq xfer-login-nobody-got-nothing [xferserver_blobs cli.fossil] \ |
|
1165
|
$xferserverLoginBefore |
|
1166
|
|
|
1167
|
############################################################################### |
|
1168
|
# The right password gives the user's permissions. |
|
1169
|
|
|
1170
|
xferserver_login_sync pull tester:secret |
|
1171
|
test xfer-login-accepted {$CODE == 0} |
|
1172
|
test_eq xfer-login-accepted-pulled [xferserver_blobs cli.fossil] \ |
|
1173
|
[expr {$xferserverLoginBefore + 1}] |
|
1174
|
|
|
1175
|
# The same for a push. |
|
1176
|
write_file cli-1.txt "content from the client\n" |
|
1177
|
fossil test-content-put cli-1.txt -R cli.fossil |
|
1178
|
set xferserverLoginBefore [xferserver_blobs srv.fossil] |
|
1179
|
xferserver_login_sync push tester:secret |
|
1180
|
test xfer-login-push-accepted {$CODE == 0} |
|
1181
|
test_eq xfer-login-push-arrived [xferserver_blobs srv.fossil] \ |
|
1182
|
[expr {$xferserverLoginBefore + 1}] |
|
1183
|
|
|
1184
|
############################################################################### |
|
1185
|
# A wrong password, and a user that the server does not know. |
|
1186
|
|
|
1187
|
xferserver_login_new_on_server |
|
1188
|
set xferserverLoginBefore [xferserver_blobs cli.fossil] |
|
1189
|
foreach {xferserverLoginName xferserverLoginUser} { |
|
1190
|
wrong-password tester:wrong |
|
1191
|
unknown-user stranger:secret |
|
1192
|
} { |
|
1193
|
xferserver_login_sync pull $xferserverLoginUser |
|
1194
|
test xfer-login-$xferserverLoginName \ |
|
1195
|
{$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
|
1196
|
test_eq xfer-login-$xferserverLoginName-got-nothing \ |
|
1197
|
[xferserver_blobs cli.fossil] \ |
|
1198
|
$xferserverLoginBefore |
|
1199
|
} |
|
1200
|
|
|
1201
|
# The special users cannot be logged in as with a password, whatever |
|
1202
|
# password the server has for them. |
|
1203
|
xferserver_sql "UPDATE user SET pw='secret', cap='oi' WHERE login='developer'" |
|
1204
|
xferserver_login_sync pull developer:secret |
|
1205
|
test xfer-login-special-user-refused {$CODE != 0} |
|
1206
|
test_eq xfer-login-special-user-got-nothing [xferserver_blobs cli.fossil] \ |
|
1207
|
$xferserverLoginBefore |
|
1208
|
|
|
1209
|
############################################################################### |
|
1210
|
# A user with read permission only may not push. |
|
1211
|
|
|
1212
|
xferserver_sql "UPDATE user SET cap='o' WHERE login='tester'" |
|
1213
|
write_file cli-2.txt "more content from the client\n" |
|
1214
|
fossil test-content-put cli-2.txt -R cli.fossil |
|
1215
|
set xferserverLoginSrvBefore [xferserver_blobs srv.fossil] |
|
1216
|
xferserver_login_sync push tester:secret |
|
1217
|
test xfer-login-push-without-write \ |
|
1218
|
{$CODE != 0 && [string first "not authorized to write" $RESULT] >= 0} |
|
1219
|
test_eq xfer-login-push-without-write-nothing-arrived \ |
|
1220
|
[xferserver_blobs srv.fossil] $xferserverLoginSrvBefore |
|
1221
|
xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'" |
|
1222
|
|
|
1223
|
############################################################################### |
|
1224
|
# A server that keeps the password as the user typed it still accepts the |
|
1225
|
# login, and still refuses a wrong password. |
|
1226
|
|
|
1227
|
xferserver_sql "UPDATE user SET pw='secret' WHERE login='tester'" |
|
1228
|
xferserver_login_sync pull tester:wrong |
|
1229
|
test xfer-login-cleartext-wrong \ |
|
1230
|
{$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
|
1231
|
set xferserverLoginBefore [xferserver_blobs cli.fossil] |
|
1232
|
xferserver_login_sync pull tester:secret |
|
1233
|
test xfer-login-cleartext-accepted {$CODE == 0} |
|
1234
|
test_eq xfer-login-cleartext-pulled [xferserver_blobs cli.fossil] \ |
|
1235
|
[expr {$xferserverLoginBefore + 1}] |
|
1236
|
|
|
1237
|
############################################################################### |
|
1238
|
# A login card for "nobody" or "anonymous" is accepted without a |
|
1239
|
# password, and gives the permissions of "nobody". |
|
1240
|
|
|
1241
|
xferserver_login_new_on_server |
|
1242
|
set xferserverLoginBefore [xferserver_blobs cli.fossil] |
|
1243
|
foreach xferserverLoginUser {nobody anonymous} { |
|
1244
|
xferserver_login_sync pull $xferserverLoginUser:anything |
|
1245
|
test xfer-login-as-$xferserverLoginUser \ |
|
1246
|
{$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0} |
|
1247
|
} |
|
1248
|
xferserver_sql "UPDATE user SET cap='o' WHERE login='nobody'" |
|
1249
|
xferserver_login_sync pull nobody:anything |
|
1250
|
test xfer-login-as-nobody-who-may-read {$CODE == 0} |
|
1251
|
test_eq xfer-login-as-nobody-pulled [xferserver_blobs cli.fossil] \ |
|
1252
|
[expr {$xferserverLoginBefore + 1}] |
|
1253
|
xferserver_sql "UPDATE user SET cap='' WHERE login='nobody'" |
|
1254
|
|
|
1255
|
############################################################################### |
|
1256
|
# A web server that has already checked the user's password says so in |
|
1257
|
# REMOTE_USER. The login card of that user is then accepted whatever |
|
1258
|
# its signature, but only if the remote_user_ok setting is on. |
|
1259
|
|
|
1260
|
xferserver_login_new_on_server |
|
1261
|
set xferserverLoginBefore [xferserver_blobs cli.fossil] |
|
1262
|
set ::env(REMOTE_USER) tester |
|
1263
|
xferserver_login_sync pull tester:wrong |
|
1264
|
test xfer-login-remote-user-setting-off \ |
|
1265
|
{$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
|
1266
|
xferserver_sql "REPLACE INTO config(name,value,mtime) |
|
1267
|
VALUES('remote_user_ok',1,now())" |
|
1268
|
xferserver_login_sync pull stranger:wrong |
|
1269
|
test xfer-login-remote-user-other-name \ |
|
1270
|
{$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
|
1271
|
test_eq xfer-login-remote-user-nothing-yet [xferserver_blobs cli.fossil] \ |
|
1272
|
$xferserverLoginBefore |
|
1273
|
xferserver_login_sync pull tester:wrong |
|
1274
|
test xfer-login-remote-user-accepted {$CODE == 0} |
|
1275
|
test_eq xfer-login-remote-user-pulled [xferserver_blobs cli.fossil] \ |
|
1276
|
[expr {$xferserverLoginBefore + 1}] |
|
1277
|
unset ::env(REMOTE_USER) |
|
1278
|
xferserver_sql "DELETE FROM config WHERE name='remote_user_ok'" |
|
1279
|
|
|
1280
|
############################################################################### |
|
1281
|
# Requests written here and given to "fossil http" as a web server gives |
|
1282
|
# them, so that the login card can be wrong in one way at a time and can |
|
1283
|
# come in a cookie. |
|
1284
|
|
|
1285
|
set xferserverLoginProject $::env(SCN_PROJECT) |
|
1286
|
set xferserverLoginPull "pull x $xferserverLoginProject\n" |
|
1287
|
|
|
1288
|
# Give the server the cards BODY in a request with the extra header lines |
|
1289
|
# HEADERS, from the address ADDRESS, with any more options for "fossil |
|
1290
|
# http" in ARGS. RESULT is the reply without its header. |
|
1291
|
# |
|
1292
|
proc xferserver_http {body headers address args} { |
|
1293
|
set request "POST /xfer HTTP/1.0\r\n" |
|
1294
|
append request "Content-Type: application/x-fossil-debug\r\n" |
|
1295
|
foreach header $headers { |
|
1296
|
append request "$header\r\n" |
|
1297
|
} |
|
1298
|
append request "Content-Length: [string length $body]\r\n\r\n$body" |
|
1299
|
write_file http-request.txt $request |
|
1300
|
file delete http-reply.txt |
|
1301
|
fossil_raw http --in http-request.txt --out http-reply.txt \ |
|
1302
|
--ipaddr $address srv.fossil {*}$args |
|
1303
|
set reply "" |
|
1304
|
if {[file exists http-reply.txt]} { |
|
1305
|
set reply [read_file http-reply.txt] |
|
1306
|
} |
|
1307
|
set ::RESULT [reply_body $reply] |
|
1308
|
} |
|
1309
|
|
|
1310
|
# The login card of USER with PASSWORD for a message of the cards BODY, |
|
1311
|
# with the nonce made from the cards NONCEBODY. |
|
1312
|
# |
|
1313
|
proc xferserver_login_card {user password body {nonceBody ""}} { |
|
1314
|
global xferserverLoginProject |
|
1315
|
if {$nonceBody eq ""} {set nonceBody $body} |
|
1316
|
set secret [sha1_text $xferserverLoginProject/$user/$password] |
|
1317
|
set nonce [sha1_text $nonceBody] |
|
1318
|
return "login $user $nonce [sha1_text $nonce$secret]" |
|
1319
|
} |
|
1320
|
|
|
1321
|
# The card is accepted when its nonce is the hash of the cards after it. |
|
1322
|
# A card with a nonce made from other cards is refused, although its |
|
1323
|
# signature fits that nonce. |
|
1324
|
xferserver_http "[xferserver_login_card tester secret \ |
|
1325
|
$xferserverLoginPull]\n$xferserverLoginPull" {} 127.0.0.1 |
|
1326
|
test xfer-login-http-accepted \ |
|
1327
|
{$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]} |
|
1328
|
xferserver_http "[xferserver_login_card tester secret $xferserverLoginPull \ |
|
1329
|
"other cards\n"]\n$xferserverLoginPull" {} 127.0.0.1 |
|
1330
|
test xfer-login-http-nonce-of-other-cards \ |
|
1331
|
{$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]} |
|
1332
|
|
|
1333
|
# A signature that is not as long as a hash is refused. |
|
1334
|
foreach {xferserverLoginName xferserverLoginSig} [list \ |
|
1335
|
short-signature abc \ |
|
1336
|
long-signature [string repeat a 41] \ |
|
1337
|
] { |
|
1338
|
xferserver_http "login tester [sha1_text $xferserverLoginPull]\ |
|
1339
|
$xferserverLoginSig\n$xferserverLoginPull" {} 127.0.0.1 |
|
1340
|
test xfer-login-http-$xferserverLoginName \ |
|
1341
|
{$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]} |
|
1342
|
} |
|
1343
|
|
|
1344
|
# The same card in the cookie x-f-l-c logs the user in. A cookie that is |
|
1345
|
# not a login card of four words is ignored, and the request is that of |
|
1346
|
# "nobody". |
|
1347
|
set xferserverLoginCard \ |
|
1348
|
[xferserver_login_card tester secret $xferserverLoginPull] |
|
1349
|
foreach {xferserverLoginName xferserverLoginCookie xferserverLoginOk} [list \ |
|
1350
|
card $xferserverLoginCard 1 \ |
|
1351
|
three-words [lrange $xferserverLoginCard 0 2] 0 \ |
|
1352
|
longer-word [lreplace $xferserverLoginCard 0 0 logins] 0 \ |
|
1353
|
other-word [lreplace $xferserverLoginCard 0 0 logix] 0 \ |
|
1354
|
] { |
|
1355
|
xferserver_http $xferserverLoginPull [list \ |
|
1356
|
"Cookie: x-f-l-c=[string map {{ } %20} $xferserverLoginCookie]"] \ |
|
1357
|
127.0.0.1 |
|
1358
|
set xferserverLoginWant [expr {$xferserverLoginOk |
|
1359
|
? {"igot " "errors 0"} : {{error not\sauthorized\sto\sread} "!igot "}}] |
|
1360
|
test xfer-login-cookie-$xferserverLoginName \ |
|
1361
|
{$CODE == 0 && [holds_strings $RESULT $xferserverLoginWant]} |
|
1362
|
} |
|
1363
|
|
|
1364
|
# With --localauth a request from this machine needs no login, unless the |
|
1365
|
# localauth setting is on; the refusal then says so. A request from |
|
1366
|
# another machine is refused without that reason. |
|
1367
|
xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth |
|
1368
|
test xfer-login-localauth-local \ |
|
1369
|
{$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]} |
|
1370
|
xferserver_http $xferserverLoginPull {} 10.1.2.3 --localauth |
|
1371
|
test xfer-login-localauth-other-machine {$CODE == 0 && [holds_strings $RESULT \ |
|
1372
|
{{error not\sauthorized\sto\sread} "!localauth" "!igot "}]} |
|
1373
|
xferserver_sql "REPLACE INTO config(name,value,mtime) |
|
1374
|
VALUES('localauth',1,now())" |
|
1375
|
xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth |
|
1376
|
test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \ |
|
1377
|
{{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting} |
|
1378
|
"!igot "}]} |
|
1379
|
|
|
1380
|
unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH) |
|
1381
|
unset ::env(SCN_PROJECT) |
|
1382
|
|
|
1383
|
xferserver_leave |
|
1384
|
|
|
1385
|
############################################################################### |
|
1386
|
# Checks on the server side of the protocol that each decide on several |
|
1387
|
# conditions: check-in locks, clones with private content and with content |
|
1388
|
# that an old client cannot take, the limits on what the server sends, new |
|
1389
|
# clusters, and the way "fossil test-xfer" reads its message. Each case has |
|
1390
|
# one input that changes only one of the conditions. |
|
1391
|
# |
|
1392
|
# The server is a repository of its own with a public check-in, then three |
|
1393
|
# private ones on top of it; the first of the three is then made public. So |
|
1394
|
# it holds a public artifact stored as a delta of a private one, a private |
|
1395
|
# artifact stored as a delta of another private one, and a public artifact |
|
1396
|
# stored as a delta of a public one. |
|
1397
|
|
|
1398
|
xferserver_enter mcdc |
|
1399
|
|
|
1400
|
|
|
1401
|
# Test NAME passes when the reply to MESSAGE holds each of the strings |
|
1402
|
# given, and none that begins with "!". |
|
1403
|
proc xferserver_mcdc_expect {name message args} { |
|
1404
|
xferserver_send $message |
|
1405
|
test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]} |
|
1406
|
} |
|
1407
|
|
|
1408
|
set xferserverMcdcText "" |
|
1409
|
for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} { |
|
1410
|
append xferserverMcdcText \ |
|
1411
|
"line $xferserverMcdcI of a file that is worth a delta\n" |
|
1412
|
} |
|
1413
|
write_file a.txt $xferserverMcdcText |
|
1414
|
fossil add a.txt |
|
1415
|
fossil commit -m public-1 --no-warnings |
|
1416
|
foreach xferserverMcdcI {2 3 4} { |
|
1417
|
append xferserverMcdcText "version $xferserverMcdcI\n" |
|
1418
|
write_file a.txt $xferserverMcdcText |
|
1419
|
fossil commit -m private-$xferserverMcdcI --private --no-warnings |
|
1420
|
} |
|
1421
|
# The blob of the file in each version. |
|
1422
|
proc xferserverMcdc_fid {comment} { |
|
1423
|
fossil sql "SELECT mlink.fid FROM mlink, event WHERE mlink.mid=event.objid |
|
1424
|
AND event.comment='$comment'" |
|
1425
|
return [string trim $::RESULT] |
|
1426
|
} |
|
1427
|
# Version 2 becomes public while it is stored as a delta of the private |
|
1428
|
# version 3, and version 1 becomes a delta of version 2. |
|
1429
|
fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT objid FROM event |
|
1430
|
WHERE comment='private-2')" |
|
1431
|
fossil publish [string trim $RESULT] |
|
1432
|
fossil test-content-deltify [xferserverMcdc_fid public-1] \ |
|
1433
|
[xferserverMcdc_fid private-2] |
|
1434
|
file copy .rep.fossil srv.fossil |
|
1435
|
set xferserverMcdcPcode [xferserver_sql \ |
|
1436
|
"SELECT value FROM config WHERE name='project-code'"] |
|
1437
|
set xferserverMcdcTip [xferserver_sql "SELECT uuid FROM blob WHERE rid= |
|
1438
|
(SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"] |
|
1439
|
set xferserverMcdcLogin "login tester 0 0\n" |
|
1440
|
set xferserverMcdcPull "pull x $xferserverMcdcPcode\n" |
|
1441
|
set xferserverMcdcPush "push x $xferserverMcdcPcode\n" |
|
1442
|
xferserver_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'" |
|
1443
|
# A public check-in, named by a SHA3 hash. |
|
1444
|
set xferserverMcdcPublic [xferserver_sql "SELECT uuid FROM blob WHERE |
|
1445
|
rid IN (SELECT objid FROM event WHERE type='ci') |
|
1446
|
AND rid NOT IN (SELECT rid FROM private) LIMIT 1"] |
|
1447
|
|
|
1448
|
# A private artifact that is stored as a delta of another private artifact. |
|
1449
|
set xferserverMcdcDelta [xferserver_sql "SELECT b.uuid FROM blob b, delta d, |
|
1450
|
private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN |
|
1451
|
(SELECT rid FROM private) LIMIT 1"] |
|
1452
|
test xfer-server-mcdc-setup-private-delta \ |
|
1453
|
{[string length $xferserverMcdcDelta] >= 40} |
|
1454
|
foreach xferserverMcdcI {1 2} { |
|
1455
|
set xferserverMcdcFile($xferserverMcdcI) [xferserver_sql \ |
|
1456
|
"SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \ |
|
1457
|
[lindex {x public-1 private-2} $xferserverMcdcI]]"] |
|
1458
|
} |
|
1459
|
lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1 |
|
1460
|
lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2 |
|
1461
|
test xfer-server-mcdc-setup-public-from-private {[xferserver_sql "SELECT |
|
1462
|
count(*) FROM delta d, private p WHERE d.rid= |
|
1463
|
[xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1} |
|
1464
|
test xfer-server-mcdc-setup-public-from-public {[xferserver_sql "SELECT |
|
1465
|
count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1] |
|
1466
|
AND d.srcid=[xferserverMcdc_fid private-2]"] == 1} |
|
1467
|
|
|
1468
|
############################################################################### |
|
1469
|
# A lock on a check-in is reported to a second client with the name of the |
|
1470
|
# user who holds it, "nobody" when the lock has no name or an empty one. |
|
1471
|
|
|
1472
|
set xferserverMcdcA [string repeat a 40] |
|
1473
|
set xferserverMcdcB [string repeat b 40] |
|
1474
|
foreach {xferserverMcdcName xferserverMcdcValue xferserverMcdcWho} { |
|
1475
|
named {json_object('login','alice','clientid',$A)} alice |
|
1476
|
empty {json_object('login','','clientid',$A)} nobody |
|
1477
|
absent {json_object('clientid',$A)} nobody |
|
1478
|
} { |
|
1479
|
set xferserverMcdcValue [string map \ |
|
1480
|
[list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue] |
|
1481
|
xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'; |
|
1482
|
REPLACE INTO config(name,value,mtime) |
|
1483
|
VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())" |
|
1484
|
xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \ |
|
1485
|
"$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\ |
|
1486
|
$xferserverMcdcTip $xferserverMcdcB\n" \ |
|
1487
|
"pragma ci-lock-fail $xferserverMcdcWho " |
|
1488
|
} |
|
1489
|
xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'" |
|
1490
|
|
|
1491
|
############################################################################### |
|
1492
|
# A clone of a server that has private artifacts. A client that does not |
|
1493
|
# ask for private content is sent none, and one that does is sent each of |
|
1494
|
# them behind a "private" card, a delta of a private artifact as a delta. |
|
1495
|
|
|
1496
|
xferserver_mcdc_expect clone-no-private \ |
|
1497
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
|
1498
|
"cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta" |
|
1499
|
if {$xferserverWhole} { |
|
1500
|
xferserver_mcdc_expect clone-private \ |
|
1501
|
[join [list \ |
|
1502
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma " \ |
|
1503
|
"send-private\nclone 3 1\n"] ""] \ |
|
1504
|
"private\ncfile $xferserverMcdcDelta " |
|
1505
|
# A public artifact whose source is private is sent whole: the card names |
|
1506
|
# no source. |
|
1507
|
xferserver_mcdc_expect clone-public-from-private \ |
|
1508
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
|
1509
|
"cfile $xferserverMcdcHash2 $xferserverMcdcSize2 " |
|
1510
|
xferserver_mcdc_expect clone-public-from-public \ |
|
1511
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
|
1512
|
"cfile $xferserverMcdcHash1 $xferserverMcdcHash2 $xferserverMcdcSize1 " |
|
1513
|
} |
|
1514
|
xferserver_mcdc_expect clone-v2-public-from-private \ |
|
1515
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \ |
|
1516
|
"file $xferserverMcdcHash2 $xferserverMcdcSize2\n" |
|
1517
|
xferserver_mcdc_expect clone-v2-public-from-public \ |
|
1518
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \ |
|
1519
|
"file $xferserverMcdcHash1 $xferserverMcdcHash2 " |
|
1520
|
xferserver_mcdc_expect clone-v2-private \ |
|
1521
|
[join [list \ |
|
1522
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma " \ |
|
1523
|
"send-private\nclone 2 1\n"] ""] \ |
|
1524
|
"private\nfile $xferserverMcdcDelta " |
|
1525
|
|
|
1526
|
############################################################################### |
|
1527
|
# Artifacts named by a SHA1 hash. A client that does not state its version |
|
1528
|
# is taken to be older than 2.0: it is sent them, and gets an error in place |
|
1529
|
# of an artifact named by a SHA3 hash. |
|
1530
|
|
|
1531
|
write_file sha1.txt "sha1 content\n" |
|
1532
|
fossil sha1sum sha1.txt |
|
1533
|
set xferserverMcdcSha1 [lindex $RESULT 0] |
|
1534
|
xferserver_mcdc_expect push-sha1 \ |
|
1535
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\ |
|
1536
|
$xferserverMcdcSha1 13\nsha1 content\n" "errors 0" |
|
1537
|
test xfer-server-mcdc-push-sha1-stored \ |
|
1538
|
{[xferserver_sql "SELECT count(*) FROM blob WHERE |
|
1539
|
uuid='$xferserverMcdcSha1' AND size=13"] == 1} |
|
1540
|
xferserver_mcdc_expect old-client-gimme-sha1 \ |
|
1541
|
"${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \ |
|
1542
|
"file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil" |
|
1543
|
xferserver_mcdc_expect old-client-gimme-sha3 \ |
|
1544
|
"${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \ |
|
1545
|
{error Fossil\sversion\s2.0\sor\slater\srequired} \ |
|
1546
|
"!file $xferserverMcdcPublic" |
|
1547
|
xferserver_mcdc_expect old-client-clone-sha1 \ |
|
1548
|
"${xferserverMcdcLogin}clone 3 1\n" \ |
|
1549
|
"cfile $xferserverMcdcSha1 13 " \ |
|
1550
|
{error Fossil\sversion\s2.0\sor\slater\srequired} |
|
1551
|
|
|
1552
|
############################################################################### |
|
1553
|
# A server whose send limit is reached stops sending files and tells the |
|
1554
|
# client in "igot" cards, and in "uvigot" cards for unversioned files. |
|
1555
|
|
|
1556
|
write_file note.txt "hi\n" |
|
1557
|
fossil unversioned add note.txt -R srv.fossil |
|
1558
|
xferserver_sql "REPLACE INTO config(name,value,mtime) |
|
1559
|
VALUES('max-download','1',now())" |
|
1560
|
xferserver_mcdc_expect uvgimme-limit \ |
|
1561
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\ |
|
1562
|
note.txt\n" "uvigot note.txt " "!uvfile note.txt" |
|
1563
|
xferserver_mcdc_expect catalog-limit \ |
|
1564
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\ |
|
1565
|
send-catalog x\n" "igot " "errors 0" |
|
1566
|
xferserver_sql "DELETE FROM config WHERE name='max-download'" |
|
1567
|
xferserver_mcdc_expect uvgimme-no-limit \ |
|
1568
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\ |
|
1569
|
note.txt\n" "uvfile note.txt " "!uvigot" |
|
1570
|
|
|
1571
|
# A client that does not state its version is sent an unversioned file |
|
1572
|
# that is named by a SHA1 hash, and gets an error in place of one named by |
|
1573
|
# a SHA3 hash. |
|
1574
|
fossil hash-policy sha1 -R srv.fossil |
|
1575
|
write_file old.txt "old\n" |
|
1576
|
fossil unversioned add old.txt -R srv.fossil |
|
1577
|
fossil hash-policy sha3 -R srv.fossil |
|
1578
|
test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_sql "SELECT |
|
1579
|
group_concat(length(hash)) FROM (SELECT hash FROM unversioned |
|
1580
|
WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40" |
|
1581
|
xferserver_mcdc_expect old-client-uvgimme-sha1 \ |
|
1582
|
"${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \ |
|
1583
|
"uvfile old.txt " "!error Fossil" |
|
1584
|
xferserver_mcdc_expect old-client-uvgimme-sha3 \ |
|
1585
|
"${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme note.txt\n" \ |
|
1586
|
{error Fossil\sversion\s2.0\sor\slater\srequired} "!uvfile note.txt" |
|
1587
|
|
|
1588
|
############################################################################### |
|
1589
|
# A server has the number of seconds in max-download-time to make a reply. |
|
1590
|
# Once they have passed it sends no more artifacts: a client that asks for |
|
1591
|
# one is told in an "igot" card that the server has it, and a clone is told |
|
1592
|
# to ask again from where it was. The limit is at least one second and |
|
1593
|
# the server counts whole seconds, so the script that the server runs |
|
1594
|
# before it reads the request keeps it busy until the date shows the next |
|
1595
|
# second, and for 20 ms more because the clock that the server reads can |
|
1596
|
# be a few milliseconds behind the date. The server runs the script |
|
1597
|
# again after the request, where the wait is left out. |
|
1598
|
|
|
1599
|
xferserver_mcdc_expect gimme-in-time \ |
|
1600
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\ |
|
1601
|
$xferserverMcdcPublic\n" "file $xferserverMcdcPublic " |
|
1602
|
set xferserverMcdcBusy { |
|
1603
|
if {![info exists waited]} { |
|
1604
|
set waited 1 |
|
1605
|
set s [date] |
|
1606
|
for {} {[string compare [date] $s] == 0} {} {} |
|
1607
|
set t [utime] |
|
1608
|
for {} {[utime]-$t < 20000} {} {} |
|
1609
|
} |
|
1610
|
} |
|
1611
|
xferserver_sql "REPLACE INTO config(name,value,mtime) VALUES |
|
1612
|
('max-download-time','1',now()), |
|
1613
|
('xfer-common-script','$xferserverMcdcBusy',now())" |
|
1614
|
xferserver_mcdc_expect gimme-out-of-time \ |
|
1615
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\ |
|
1616
|
$xferserverMcdcPublic\n" \ |
|
1617
|
"igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0" |
|
1618
|
xferserver_mcdc_expect clone-out-of-time \ |
|
1619
|
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
|
1620
|
"clone_seqno 1\n" "!cfile " "errors 0" |
|
1621
|
xferserver_sql "DELETE FROM config |
|
1622
|
WHERE name IN ('max-download-time','xfer-common-script')" |
|
1623
|
|
|
1624
|
############################################################################### |
|
1625
|
# A client that says where it can be reached is recorded when the address |
|
1626
|
# is an http or https one and does not name the local host. |
|
1627
|
|
|
1628
|
foreach {xferserverMcdcName xferserverMcdcUrl xferserverMcdcKept} { |
|
1629
|
http http://example.org/a 1 |
|
1630
|
https https://example.org/b 1 |
|
1631
|
localhost http://localhost/c 0 |
|
1632
|
ssh ssh://example.org/d 0 |
|
1633
|
} { |
|
1634
|
xferserver_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'" |
|
1635
|
xferserver_mcdc_expect client-url-$xferserverMcdcName \ |
|
1636
|
"${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\ |
|
1637
|
$xferserverMcdcUrl\n" "errors 0" |
|
1638
|
test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \ |
|
1639
|
{[xferserver_sql "SELECT count(*) FROM config |
|
1640
|
WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept} |
|
1641
|
} |
|
1642
|
|
|
1643
|
############################################################################### |
|
1644
|
# "fossil test-xfer" reads the message from the file it is given, or from |
|
1645
|
# its standard input when it is given none, and takes no more arguments. |
|
1646
|
|
|
1647
|
fossil_raw -input "${xferserverMcdcLogin}${xferserverMcdcPull}" \ |
|
1648
|
test-xfer -R srv.fossil |
|
1649
|
test xfer-server-mcdc-test-xfer-stdin \ |
|
1650
|
{$CODE == 0 && [string first "errors 0" $RESULT] >= 0} |
|
1651
|
fossil_raw test-xfer -R srv.fossil msg.txt msg.txt |
|
1652
|
test xfer-server-mcdc-test-xfer-extra-argument \ |
|
1653
|
{$CODE != 0 && [string first "Usage:" $RESULT] >= 0} |
|
1654
|
|
|
1655
|
xferserver_leave |
|
1656
|
|
|
1657
|
############################################################################### |
|
1658
|
# New clusters. A pull on a server with many artifacts that no cluster |
|
1659
|
# lists makes clusters of up to 800 artifacts, but not one that leaves |
|
1660
|
# 100 or fewer for the next. The artifacts here are inserted with their |
|
1661
|
# contents empty: only their names are listed in a cluster. |
|
1662
|
|
|
1663
|
foreach {xferserverMcdcName xferserverMcdcCount xferserverMcdcClusters} { |
|
1664
|
few 700 1 |
|
1665
|
many 850 1 |
|
1666
|
more 1100 2 |
|
1667
|
} { |
|
1668
|
xferserver_enter mcdc-cluster-$xferserverMcdcName |
|
1669
|
fossil sql "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM n |
|
1670
|
WHERE i<$xferserverMcdcCount) |
|
1671
|
INSERT INTO blob(rcvid,size,uuid,content) |
|
1672
|
SELECT 1, 0, printf('%040x', i+1000000), x'' FROM n; |
|
1673
|
INSERT OR IGNORE INTO unclustered |
|
1674
|
SELECT rid FROM blob WHERE uuid GLOB '0000000000*'" |
|
1675
|
fossil sql "SELECT value FROM config WHERE name='project-code'" |
|
1676
|
set xferserverMcdcCode [string trim $RESULT] |
|
1677
|
fossil sql "UPDATE user SET cap='o' WHERE login='nobody'" |
|
1678
|
write_file msg.txt "pull x $xferserverMcdcCode\n" |
|
1679
|
fossil_raw test-xfer -R .rep.fossil msg.txt |
|
1680
|
test xfer-server-mcdc-cluster-$xferserverMcdcName-pull {$CODE == 0} |
|
1681
|
fossil sql "SELECT count(*) FROM tagxref WHERE tagid= |
|
1682
|
(SELECT tagid FROM tag WHERE tagname='cluster')" |
|
1683
|
test_eq xfer-server-mcdc-cluster-$xferserverMcdcName-count \ |
|
1684
|
[string trim $RESULT] $xferserverMcdcClusters |
|
1685
|
xferserver_leave |
|
1686
|
} |
|
1687
|
|
|
1688
|
############################################################################### |
|
1689
|
|
|
1690
|
test_cleanup |
|
1691
|
|