Fossil SCM

Extend the coverage tests in regress, ssh, sync, integrity, xfer-client and xfer-server, and remove derived.sql, which they no longer use.

dmestas 2026-11-27 15:55 UTC test-suite-new
Commit c6198f4645de0c6b135a84f2417f0cae8c9d0e5b5367282371d81e2cea88cc18
D test/derived.sql
-27
--- a/test/derived.sql
+++ b/test/derived.sql
@@ -1,35 +0,0 @@
--- Print the tables of a Fossil repository that are derived from its
--- artifacts, with each record number replaced by the hash or name it
--- stands for and the rows in a fixed order. Two repositories that hold
--- the same artifacts should print the same text, and so should one
--- repository before and after "fossil rebuild". integrity.test runs it:
---
--- fossil sql -R REPOSITORY <test/derived.sql
---
1
-SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
2
- user, euser, comment, ecomment, bgcolor, brief
3
- FROM event ORDER BY 2;
4
-SELECT 'plink', (SELECT uuid FROM blob WHERE rid=pid),
5
- (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime
6
- FROM plink ORDER BY 2, 3;
7
-SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid),
8
- (SELECT uuid FROM blob WHERE rid=fid),
9
- (SELECT uuid FROM blob WHERE rid=pid),
10
- (SELECT name FROM filename WHERE fnid=mlink.fnid),
11
- (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux
12
- FROM mlink ORDER BY 2, 5, 3, 4;
13
-SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid),
14
- tagtype, (SELECT uuid FROM blob WHERE rid=srcid),
15
- (SELECT uuid FROM blob WHERE rid=origid), value, mtime,
16
- (SELECT uuid FROM blob WHERE rid=tagxref.rid)
17
- FROM tagxref ORDER BY 2, 8, 3;
18
-SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid)
19
- FROM leaf ORDER BY 2;
20
-SELECT 'filename', name FROM filename ORDER BY 2;
21
-SELECT 'tag', tagname FROM tag
22
- WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2;
23
-SELECT 'backlink', target, srctype,
24
- (SELECT uuid FROM blob WHERE rid=srcid), mtime
25
- FROM backlink ORDER BY 2, 4;
26
-SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user
27
- FROM attachment ORDER BY 3, 4;
--- a/test/derived.sql
+++ b/test/derived.sql
@@ -1,35 +0,0 @@
--- Print the tables of a Fossil repository that are derived from its
--- artifacts, with each record number replaced by the hash or name it
--- stands for and the rows in a fixed order. Two repositories that hold
--- the same artifacts should print the same text, and so should one
--- repository before and after "fossil rebuild". integrity.test runs it:
---
--- fossil sql -R REPOSITORY <test/derived.sql
---
1 SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
2 user, euser, comment, ecomment, bgcolor, brief
3 FROM event ORDER BY 2;
4 SELECT 'plink', (SELECT uuid FROM blob WHERE rid=pid),
5 (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime
6 FROM plink ORDER BY 2, 3;
7 SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid),
8 (SELECT uuid FROM blob WHERE rid=fid),
9 (SELECT uuid FROM blob WHERE rid=pid),
10 (SELECT name FROM filename WHERE fnid=mlink.fnid),
11 (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux
12 FROM mlink ORDER BY 2, 5, 3, 4;
13 SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid),
14 tagtype, (SELECT uuid FROM blob WHERE rid=srcid),
15 (SELECT uuid FROM blob WHERE rid=origid), value, mtime,
16 (SELECT uuid FROM blob WHERE rid=tagxref.rid)
17 FROM tagxref ORDER BY 2, 8, 3;
18 SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid)
19 FROM leaf ORDER BY 2;
20 SELECT 'filename', name FROM filename ORDER BY 2;
21 SELECT 'tag', tagname FROM tag
22 WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2;
23 SELECT 'backlink', target, srctype,
24 (SELECT uuid FROM blob WHERE rid=srcid), mtime
25 FROM backlink ORDER BY 2, 4;
26 SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user
27 FROM attachment ORDER BY 3, 4;
--- a/test/derived.sql
+++ b/test/derived.sql
@@ -1,35 +0,0 @@
--- Print the tables of a Fossil repository that are derived from its
--- artifacts, with each record number replaced by the hash or name it
--- stands for and the rows in a fixed order. Two repositories that hold
--- the same artifacts should print the same text, and so should one
--- repository before and after "fossil rebuild". integrity.test runs it:
---
--- fossil sql -R REPOSITORY <test/derived.sql
---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- test/integrity.test
+++ test/integrity.test
@@ -8,10 +8,15 @@
88
# * "fossil test-integrity" and "fossil test-missing" pass on a sound
99
# repository and fail, with a non-zero exit status, on each of nine
1010
# kinds of damage made with SQL; and "fossil rebuild" leaves the
1111
# tables derived from the artifacts as they were, or repairs them.
1212
#
13
+
14
+# These tests run only in a long pass: -assurance stress.
15
+if {[test_assurance] ne "stress"} {
16
+ test_skip "runs only with -assurance stress"
17
+}
1318
1419
require_no_open_checkout
1520
1621
test_setup ""
1722
set ::env(FOSSIL_USER) tester
@@ -41,15 +46,50 @@
4146
proc integrity_ok {name repo} {
4247
fossil test-integrity --parse -R $repo
4348
test_match $name [normalize_result] {checked: 0 errors}
4449
}
4550
46
-# Returns the derived tables of repository REPO as text that does not
47
-# depend on record numbers. See derived.sql.
51
+# The tables of a repository that are derived from its artifacts, with
52
+# each record number replaced by the hash or name it stands for and the
53
+# rows in a fixed order. Two repositories that hold the same artifacts
54
+# give the same text, and so does one repository before and after a
55
+# rebuild.
56
+#
57
+set integrityDerivedSql {
58
+SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
59
+ user, euser, comment, ecomment, bgcolor, brief
60
+ FROM event ORDER BY 2;
61
+SELECT 'plink', (SELECT uuid FROM blob WHERE rid=pid),
62
+ (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime
63
+ FROM plink ORDER BY 2, 3;
64
+SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid),
65
+ (SELECT uuid FROM blob WHERE rid=fid),
66
+ (SELECT uuid FROM blob WHERE rid=pid),
67
+ (SELECT name FROM filename WHERE fnid=mlink.fnid),
68
+ (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux
69
+ FROM mlink ORDER BY 2, 5, 3, 4;
70
+SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid),
71
+ tagtype, (SELECT uuid FROM blob WHERE rid=srcid),
72
+ (SELECT uuid FROM blob WHERE rid=origid), value, mtime,
73
+ (SELECT uuid FROM blob WHERE rid=tagxref.rid)
74
+ FROM tagxref ORDER BY 2, 8, 3;
75
+SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid)
76
+ FROM leaf ORDER BY 2;
77
+SELECT 'filename', name FROM filename ORDER BY 2;
78
+SELECT 'tag', tagname FROM tag
79
+ WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2;
80
+SELECT 'backlink', target, srctype,
81
+ (SELECT uuid FROM blob WHERE rid=srcid), mtime
82
+ FROM backlink ORDER BY 2, 4;
83
+SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user
84
+ FROM attachment ORDER BY 3, 4;
85
+}
86
+
87
+# Returns the derived tables of repository REPO as such text.
4888
#
4989
proc integrity_derived {repo} {
50
- fossil sql -R $repo ".read [file join $::testfiledir derived.sql]"
90
+ fossil sql -R $repo $::integrityDerivedSql
5191
return $::RESULT
5292
}
5393
5494
# An origin repository with three check-ins of one file (so the store
5595
# holds deltas), a tag and a wiki page.
5696
--- test/integrity.test
+++ test/integrity.test
@@ -8,10 +8,15 @@
8 # * "fossil test-integrity" and "fossil test-missing" pass on a sound
9 # repository and fail, with a non-zero exit status, on each of nine
10 # kinds of damage made with SQL; and "fossil rebuild" leaves the
11 # tables derived from the artifacts as they were, or repairs them.
12 #
 
 
 
 
 
13
14 require_no_open_checkout
15
16 test_setup ""
17 set ::env(FOSSIL_USER) tester
@@ -41,15 +46,50 @@
41 proc integrity_ok {name repo} {
42 fossil test-integrity --parse -R $repo
43 test_match $name [normalize_result] {checked: 0 errors}
44 }
45
46 # Returns the derived tables of repository REPO as text that does not
47 # depend on record numbers. See derived.sql.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48 #
49 proc integrity_derived {repo} {
50 fossil sql -R $repo ".read [file join $::testfiledir derived.sql]"
51 return $::RESULT
52 }
53
54 # An origin repository with three check-ins of one file (so the store
55 # holds deltas), a tag and a wiki page.
56
--- test/integrity.test
+++ test/integrity.test
@@ -8,10 +8,15 @@
8 # * "fossil test-integrity" and "fossil test-missing" pass on a sound
9 # repository and fail, with a non-zero exit status, on each of nine
10 # kinds of damage made with SQL; and "fossil rebuild" leaves the
11 # tables derived from the artifacts as they were, or repairs them.
12 #
13
14 # These tests run only in a long pass: -assurance stress.
15 if {[test_assurance] ne "stress"} {
16 test_skip "runs only with -assurance stress"
17 }
18
19 require_no_open_checkout
20
21 test_setup ""
22 set ::env(FOSSIL_USER) tester
@@ -41,15 +46,50 @@
46 proc integrity_ok {name repo} {
47 fossil test-integrity --parse -R $repo
48 test_match $name [normalize_result] {checked: 0 errors}
49 }
50
51 # The tables of a repository that are derived from its artifacts, with
52 # each record number replaced by the hash or name it stands for and the
53 # rows in a fixed order. Two repositories that hold the same artifacts
54 # give the same text, and so does one repository before and after a
55 # rebuild.
56 #
57 set integrityDerivedSql {
58 SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
59 user, euser, comment, ecomment, bgcolor, brief
60 FROM event ORDER BY 2;
61 SELECT 'plink', (SELECT uuid FROM blob WHERE rid=pid),
62 (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime
63 FROM plink ORDER BY 2, 3;
64 SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid),
65 (SELECT uuid FROM blob WHERE rid=fid),
66 (SELECT uuid FROM blob WHERE rid=pid),
67 (SELECT name FROM filename WHERE fnid=mlink.fnid),
68 (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux
69 FROM mlink ORDER BY 2, 5, 3, 4;
70 SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid),
71 tagtype, (SELECT uuid FROM blob WHERE rid=srcid),
72 (SELECT uuid FROM blob WHERE rid=origid), value, mtime,
73 (SELECT uuid FROM blob WHERE rid=tagxref.rid)
74 FROM tagxref ORDER BY 2, 8, 3;
75 SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid)
76 FROM leaf ORDER BY 2;
77 SELECT 'filename', name FROM filename ORDER BY 2;
78 SELECT 'tag', tagname FROM tag
79 WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2;
80 SELECT 'backlink', target, srctype,
81 (SELECT uuid FROM blob WHERE rid=srcid), mtime
82 FROM backlink ORDER BY 2, 4;
83 SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user
84 FROM attachment ORDER BY 3, 4;
85 }
86
87 # Returns the derived tables of repository REPO as such text.
88 #
89 proc integrity_derived {repo} {
90 fossil sql -R $repo $::integrityDerivedSql
91 return $::RESULT
92 }
93
94 # An origin repository with three check-ins of one file (so the store
95 # holds deltas), a tag and a wiki page.
96
+98 -18
--- test/regress.test
+++ test/regress.test
@@ -1,8 +1,13 @@
11
#
22
# Tests for faults that have been fixed, which have no better home.
33
#
4
+
5
+# These tests run only in a long pass: -assurance stress.
6
+if {[test_assurance] ne "stress"} {
7
+ test_skip "runs only with -assurance stress"
8
+}
49
510
require_no_open_checkout
611
712
test_setup
813
@@ -10,29 +15,29 @@
1015
fossil add a.txt
1116
fossil commit -m "regress-c1"
1217
1318
###############################################################################
1419
# "fossil test-dir-list" on an empty directory, and on one that does not
15
-# exist, used to crash.
20
+# exist.
1621
1722
file mkdir empty-directory
1823
fossil test-dir-list empty-directory
1924
test regress-dir-list-empty {$CODE == 0}
2025
fossil test-dir-list no-such-directory
2126
test regress-dir-list-missing {$CODE == 0}
2227
2328
###############################################################################
24
-# "fossil test-xfer" used to print a robot captcha and then crash.
29
+# "fossil test-xfer" answers a request, with no robot captcha.
2530
2631
write_file request.txt $CLIENT_VERSION_CARD
2732
fossil test-xfer request.txt
2833
test regress-test-xfer {$CODE == 0}
2934
test_match regress-test-xfer-reply $RESULT {# timestamp}
3035
3136
###############################################################################
32
-# A branch name shorter than "date:" was read past its end when it was
33
-# looked up. This shows only in a build with run-time checking.
37
+# A branch name shorter than "date:" is looked up without reading past its
38
+# end. A fault here shows only in a build with run-time checking.
3439
3540
fossil branch new br trunk
3641
fossil update br
3742
test regress-short-branch-name {$CODE == 0}
3843
fossil update trunk
@@ -72,12 +77,12 @@
7277
append block "V [string length $value]\n$value\n"
7378
}
7479
return "${block}PROPS-END\n"
7580
}
7681
77
-# Each import has a time limit of 60 seconds, because one of these faults
78
-# was an endless loop.
82
+# Each import has a time limit of 60 seconds, so that an endless loop
83
+# fails the test.
7984
set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n"
8085
foreach {regressName regressProps} {
8186
short-block "abcd\n"
8287
negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n"
8388
oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n"
@@ -102,14 +107,12 @@
102107
fossil import --svn svn-sound.fossil svn-sound.dump
103108
test regress-svn-import-sound {$CODE == 0}
104109
file delete svn-sound.fossil
105110
106111
###############################################################################
107
-# Two more faults in the property block of "fossil import --svn". A NUL
108
-# byte in the block made the search for the end of a line fail, which
109
-# crashed the import. A negative length for the block itself was passed
110
-# on as the size of an allocation.
112
+# Two more malformed property blocks for "fossil import --svn": one with a
113
+# NUL byte in it, and one whose length is negative. Each is refused.
111114
112115
write_file svn-nul-in-block.dump \
113116
$regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"]
114117
set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n"
115118
append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n"
@@ -121,22 +124,22 @@
121124
{$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
122125
file delete svn-$regressName.fossil
123126
}
124127
125128
###############################################################################
126
-# A Markdown header that holds an HTML comment was read past its end when
127
-# its id was made. This shows only in a build with run-time checking.
129
+# A Markdown header that holds an HTML comment is read within its bounds
130
+# when its id is made. A fault here shows only in a build with run-time
131
+# checking.
128132
129133
write_file md-header.md "intro\n\n# a <!-- -->\n"
130134
fossil test-markdown-render md-header.md
131135
test regress-markdown-header-comment \
132136
{$CODE == 0 && [string first {<h1 id="a">} $RESULT] >= 0}
133137
134138
###############################################################################
135139
# The name of a file in a sibling directory, relative to the current
136
-# directory, was copied with the length of the wrong string. This shows
137
-# only in a build with run-time checking.
140
+# directory. A fault here shows only in a build with run-time checking.
138141
139142
file mkdir rel/b rel/c-with-a-longer-name/sub
140143
fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt
141144
test regress-relative-name-sibling \
142145
{$CODE == 0
@@ -146,14 +149,13 @@
146149
{$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"}
147150
148151
###############################################################################
149152
# The names of the files in a merge conflict are put into the
150153
# gmerge-command as they are, inside the double quotes that the setting
151
-# has around them. A name with a double quote reached the merge tool as
152
-# several arguments, and one with a dollar sign or a backquote stopped the
153
-# merge. For such a name the tool is now left out, with a warning, and
154
-# the conflict stays marked in the file. The merge tool here is
154
+# has around them. For a name with a double quote, a dollar sign or a
155
+# backquote the tool is left out, with a warning, and the conflict stays
156
+# marked in the file. The merge tool here is
155157
# standin/log-args.sh, which records its arguments and resolves nothing.
156158
157159
if {$::tcl_platform(platform) ne "windows"} {
158160
set regressTop [pwd]
159161
set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]]
@@ -197,9 +199,87 @@
197199
fossil close --force
198200
cd $regressTop
199201
}
200202
unset ::env(ARGS_LOG)
201203
}
204
+
205
+###############################################################################
206
+# A port number above 65535 in a URL is refused with an error.
207
+
208
+fossil remote http://example.invalid:99999999999/x -expectError
209
+test regress-url-port-too-large {$CODE != 0
210
+ && [string match "*port number too large*" $RESULT]}
211
+fossil remote http://example.invalid:65535/x
212
+test regress-url-port-largest {$CODE == 0}
213
+fossil remote off
214
+
215
+###############################################################################
216
+# "fossil ticket add" and "ticket set" with plain fields, a field to
217
+# append to, and a private field. The change artifact lists the cards that
218
+# append before the cards that assign, and the private value is stored
219
+# concealed.
220
+
221
+fossil ticket add title "A ticket" status Open comment first
222
+test regress-ticket-add {$CODE == 0}
223
+fossil sql "SELECT tkt_uuid FROM ticket WHERE title='A ticket'"
224
+set regressTkt [string trim $RESULT]
225
+fossil ticket set $regressTkt status Closed +comment " second" \
226
+ private_contact [email protected]
227
+test regress-ticket-set {$CODE == 0}
228
+fossil sql "SELECT status, comment FROM ticket WHERE tkt_uuid='$regressTkt'"
229
+test_eq regress-ticket-set-fields [string trim $RESULT] "Closed|first second"
230
+fossil sql "SELECT private_contact FROM ticket WHERE tkt_uuid='$regressTkt'"
231
+test regress-ticket-private-concealed \
232
+ {[string trim $RESULT] ne "" && ![string match "*someone*" $RESULT]}
233
+fossil sql "SELECT uuid FROM blob, event WHERE objid=rid AND type='t'
234
+ ORDER BY mtime DESC LIMIT 1"
235
+fossil artifact [string trim $RESULT]
236
+set regressTktCards [regexp -all -inline -line {^J \+?\S+} $RESULT]
237
+test regress-ticket-append-first \
238
+ {[lindex $regressTktCards 0] eq "J +comment"
239
+ && "J status" in $regressTktCards
240
+ && "J private_contact" in $regressTktCards}
241
+
242
+###############################################################################
243
+# A push into a clone that already holds a wiki attachment succeeds, and
244
+# the clone keeps one attachment row for it.
245
+
246
+write_file attach.txt "attached\n"
247
+write_file wiki.txt "wiki\n"
248
+fossil wiki create AttachPage wiki.txt
249
+fossil attachment add AttachPage attach.txt
250
+fossil clone .rep.fossil regress-attach-clone.fossil
251
+fossil push regress-attach-clone.fossil --once
252
+test regress-push-held-attachment {$CODE == 0
253
+ && ![string match "*UNIQUE constraint*" $RESULT]}
254
+fossil sql -R regress-attach-clone.fossil \
255
+ "SELECT count(*) FROM attachment WHERE target='AttachPage'"
256
+test_eq regress-push-held-attachment-rows [string trim $RESULT] 1
257
+file delete regress-attach-clone.fossil
258
+
259
+###############################################################################
260
+# The TH1 command styleHeader run from the command line writes the page
261
+# header, whatever the robot-restrict setting.
262
+
263
+foreach {regressName regressRobot} {unset {} list timelineX,diff all *} {
264
+ fossil settings robot-restrict $regressRobot
265
+ fossil_raw test-th-eval --open-config {styleHeader {Page Title}}
266
+ test regress-styleheader-cli-$regressName \
267
+ {$CODE == 0 && [string match "*<title>*: Page Title</title>*" $RESULT]}
268
+}
269
+fossil settings robot-restrict ""
270
+
271
+###############################################################################
272
+# A base URL given with --baseurl and no path, with or without a slash after
273
+# the host, serves pages at the root. A fault here shows only in a build
274
+# with run-time checking.
275
+
276
+write_file baseurl-req.txt "GET /robots.txt HTTP/1.1\r\nHost: x\r\n\r\n"
277
+foreach {regressName regressUrl} {bare https://x slash https://x/} {
278
+ fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl
279
+ test regress-baseurl-no-path-$regressName \
280
+ {$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]}
281
+}
202282
203283
###############################################################################
204284
205285
test_cleanup
206286
--- test/regress.test
+++ test/regress.test
@@ -1,8 +1,13 @@
1 #
2 # Tests for faults that have been fixed, which have no better home.
3 #
 
 
 
 
 
4
5 require_no_open_checkout
6
7 test_setup
8
@@ -10,29 +15,29 @@
10 fossil add a.txt
11 fossil commit -m "regress-c1"
12
13 ###############################################################################
14 # "fossil test-dir-list" on an empty directory, and on one that does not
15 # exist, used to crash.
16
17 file mkdir empty-directory
18 fossil test-dir-list empty-directory
19 test regress-dir-list-empty {$CODE == 0}
20 fossil test-dir-list no-such-directory
21 test regress-dir-list-missing {$CODE == 0}
22
23 ###############################################################################
24 # "fossil test-xfer" used to print a robot captcha and then crash.
25
26 write_file request.txt $CLIENT_VERSION_CARD
27 fossil test-xfer request.txt
28 test regress-test-xfer {$CODE == 0}
29 test_match regress-test-xfer-reply $RESULT {# timestamp}
30
31 ###############################################################################
32 # A branch name shorter than "date:" was read past its end when it was
33 # looked up. This shows only in a build with run-time checking.
34
35 fossil branch new br trunk
36 fossil update br
37 test regress-short-branch-name {$CODE == 0}
38 fossil update trunk
@@ -72,12 +77,12 @@
72 append block "V [string length $value]\n$value\n"
73 }
74 return "${block}PROPS-END\n"
75 }
76
77 # Each import has a time limit of 60 seconds, because one of these faults
78 # was an endless loop.
79 set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n"
80 foreach {regressName regressProps} {
81 short-block "abcd\n"
82 negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n"
83 oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n"
@@ -102,14 +107,12 @@
102 fossil import --svn svn-sound.fossil svn-sound.dump
103 test regress-svn-import-sound {$CODE == 0}
104 file delete svn-sound.fossil
105
106 ###############################################################################
107 # Two more faults in the property block of "fossil import --svn". A NUL
108 # byte in the block made the search for the end of a line fail, which
109 # crashed the import. A negative length for the block itself was passed
110 # on as the size of an allocation.
111
112 write_file svn-nul-in-block.dump \
113 $regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"]
114 set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n"
115 append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n"
@@ -121,22 +124,22 @@
121 {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
122 file delete svn-$regressName.fossil
123 }
124
125 ###############################################################################
126 # A Markdown header that holds an HTML comment was read past its end when
127 # its id was made. This shows only in a build with run-time checking.
 
128
129 write_file md-header.md "intro\n\n# a <!-- -->\n"
130 fossil test-markdown-render md-header.md
131 test regress-markdown-header-comment \
132 {$CODE == 0 && [string first {<h1 id="a">} $RESULT] >= 0}
133
134 ###############################################################################
135 # The name of a file in a sibling directory, relative to the current
136 # directory, was copied with the length of the wrong string. This shows
137 # only in a build with run-time checking.
138
139 file mkdir rel/b rel/c-with-a-longer-name/sub
140 fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt
141 test regress-relative-name-sibling \
142 {$CODE == 0
@@ -146,14 +149,13 @@
146 {$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"}
147
148 ###############################################################################
149 # The names of the files in a merge conflict are put into the
150 # gmerge-command as they are, inside the double quotes that the setting
151 # has around them. A name with a double quote reached the merge tool as
152 # several arguments, and one with a dollar sign or a backquote stopped the
153 # merge. For such a name the tool is now left out, with a warning, and
154 # the conflict stays marked in the file. The merge tool here is
155 # standin/log-args.sh, which records its arguments and resolves nothing.
156
157 if {$::tcl_platform(platform) ne "windows"} {
158 set regressTop [pwd]
159 set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]]
@@ -197,9 +199,87 @@
197 fossil close --force
198 cd $regressTop
199 }
200 unset ::env(ARGS_LOG)
201 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
203 ###############################################################################
204
205 test_cleanup
206
--- test/regress.test
+++ test/regress.test
@@ -1,8 +1,13 @@
1 #
2 # Tests for faults that have been fixed, which have no better home.
3 #
4
5 # These tests run only in a long pass: -assurance stress.
6 if {[test_assurance] ne "stress"} {
7 test_skip "runs only with -assurance stress"
8 }
9
10 require_no_open_checkout
11
12 test_setup
13
@@ -10,29 +15,29 @@
15 fossil add a.txt
16 fossil commit -m "regress-c1"
17
18 ###############################################################################
19 # "fossil test-dir-list" on an empty directory, and on one that does not
20 # exist.
21
22 file mkdir empty-directory
23 fossil test-dir-list empty-directory
24 test regress-dir-list-empty {$CODE == 0}
25 fossil test-dir-list no-such-directory
26 test regress-dir-list-missing {$CODE == 0}
27
28 ###############################################################################
29 # "fossil test-xfer" answers a request, with no robot captcha.
30
31 write_file request.txt $CLIENT_VERSION_CARD
32 fossil test-xfer request.txt
33 test regress-test-xfer {$CODE == 0}
34 test_match regress-test-xfer-reply $RESULT {# timestamp}
35
36 ###############################################################################
37 # A branch name shorter than "date:" is looked up without reading past its
38 # end. A fault here shows only in a build with run-time checking.
39
40 fossil branch new br trunk
41 fossil update br
42 test regress-short-branch-name {$CODE == 0}
43 fossil update trunk
@@ -72,12 +77,12 @@
77 append block "V [string length $value]\n$value\n"
78 }
79 return "${block}PROPS-END\n"
80 }
81
82 # Each import has a time limit of 60 seconds, so that an endless loop
83 # fails the test.
84 set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n"
85 foreach {regressName regressProps} {
86 short-block "abcd\n"
87 negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n"
88 oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n"
@@ -102,14 +107,12 @@
107 fossil import --svn svn-sound.fossil svn-sound.dump
108 test regress-svn-import-sound {$CODE == 0}
109 file delete svn-sound.fossil
110
111 ###############################################################################
112 # Two more malformed property blocks for "fossil import --svn": one with a
113 # NUL byte in it, and one whose length is negative. Each is refused.
 
 
114
115 write_file svn-nul-in-block.dump \
116 $regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"]
117 set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n"
118 append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n"
@@ -121,22 +124,22 @@
124 {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
125 file delete svn-$regressName.fossil
126 }
127
128 ###############################################################################
129 # A Markdown header that holds an HTML comment is read within its bounds
130 # when its id is made. A fault here shows only in a build with run-time
131 # checking.
132
133 write_file md-header.md "intro\n\n# a <!-- -->\n"
134 fossil test-markdown-render md-header.md
135 test regress-markdown-header-comment \
136 {$CODE == 0 && [string first {<h1 id="a">} $RESULT] >= 0}
137
138 ###############################################################################
139 # The name of a file in a sibling directory, relative to the current
140 # directory. A fault here shows only in a build with run-time checking.
 
141
142 file mkdir rel/b rel/c-with-a-longer-name/sub
143 fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt
144 test regress-relative-name-sibling \
145 {$CODE == 0
@@ -146,14 +149,13 @@
149 {$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"}
150
151 ###############################################################################
152 # The names of the files in a merge conflict are put into the
153 # gmerge-command as they are, inside the double quotes that the setting
154 # has around them. For a name with a double quote, a dollar sign or a
155 # backquote the tool is left out, with a warning, and the conflict stays
156 # marked in the file. The merge tool here is
 
157 # standin/log-args.sh, which records its arguments and resolves nothing.
158
159 if {$::tcl_platform(platform) ne "windows"} {
160 set regressTop [pwd]
161 set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]]
@@ -197,9 +199,87 @@
199 fossil close --force
200 cd $regressTop
201 }
202 unset ::env(ARGS_LOG)
203 }
204
205 ###############################################################################
206 # A port number above 65535 in a URL is refused with an error.
207
208 fossil remote http://example.invalid:99999999999/x -expectError
209 test regress-url-port-too-large {$CODE != 0
210 && [string match "*port number too large*" $RESULT]}
211 fossil remote http://example.invalid:65535/x
212 test regress-url-port-largest {$CODE == 0}
213 fossil remote off
214
215 ###############################################################################
216 # "fossil ticket add" and "ticket set" with plain fields, a field to
217 # append to, and a private field. The change artifact lists the cards that
218 # append before the cards that assign, and the private value is stored
219 # concealed.
220
221 fossil ticket add title "A ticket" status Open comment first
222 test regress-ticket-add {$CODE == 0}
223 fossil sql "SELECT tkt_uuid FROM ticket WHERE title='A ticket'"
224 set regressTkt [string trim $RESULT]
225 fossil ticket set $regressTkt status Closed +comment " second" \
226 private_contact [email protected]
227 test regress-ticket-set {$CODE == 0}
228 fossil sql "SELECT status, comment FROM ticket WHERE tkt_uuid='$regressTkt'"
229 test_eq regress-ticket-set-fields [string trim $RESULT] "Closed|first second"
230 fossil sql "SELECT private_contact FROM ticket WHERE tkt_uuid='$regressTkt'"
231 test regress-ticket-private-concealed \
232 {[string trim $RESULT] ne "" && ![string match "*someone*" $RESULT]}
233 fossil sql "SELECT uuid FROM blob, event WHERE objid=rid AND type='t'
234 ORDER BY mtime DESC LIMIT 1"
235 fossil artifact [string trim $RESULT]
236 set regressTktCards [regexp -all -inline -line {^J \+?\S+} $RESULT]
237 test regress-ticket-append-first \
238 {[lindex $regressTktCards 0] eq "J +comment"
239 && "J status" in $regressTktCards
240 && "J private_contact" in $regressTktCards}
241
242 ###############################################################################
243 # A push into a clone that already holds a wiki attachment succeeds, and
244 # the clone keeps one attachment row for it.
245
246 write_file attach.txt "attached\n"
247 write_file wiki.txt "wiki\n"
248 fossil wiki create AttachPage wiki.txt
249 fossil attachment add AttachPage attach.txt
250 fossil clone .rep.fossil regress-attach-clone.fossil
251 fossil push regress-attach-clone.fossil --once
252 test regress-push-held-attachment {$CODE == 0
253 && ![string match "*UNIQUE constraint*" $RESULT]}
254 fossil sql -R regress-attach-clone.fossil \
255 "SELECT count(*) FROM attachment WHERE target='AttachPage'"
256 test_eq regress-push-held-attachment-rows [string trim $RESULT] 1
257 file delete regress-attach-clone.fossil
258
259 ###############################################################################
260 # The TH1 command styleHeader run from the command line writes the page
261 # header, whatever the robot-restrict setting.
262
263 foreach {regressName regressRobot} {unset {} list timelineX,diff all *} {
264 fossil settings robot-restrict $regressRobot
265 fossil_raw test-th-eval --open-config {styleHeader {Page Title}}
266 test regress-styleheader-cli-$regressName \
267 {$CODE == 0 && [string match "*<title>*: Page Title</title>*" $RESULT]}
268 }
269 fossil settings robot-restrict ""
270
271 ###############################################################################
272 # A base URL given with --baseurl and no path, with or without a slash after
273 # the host, serves pages at the root. A fault here shows only in a build
274 # with run-time checking.
275
276 write_file baseurl-req.txt "GET /robots.txt HTTP/1.1\r\nHost: x\r\n\r\n"
277 foreach {regressName regressUrl} {bare https://x slash https://x/} {
278 fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl
279 test regress-baseurl-no-path-$regressName \
280 {$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]}
281 }
282
283 ###############################################################################
284
285 test_cleanup
286
+7 -2
--- test/ssh.test
+++ test/ssh.test
@@ -9,10 +9,15 @@
99
# string by ssh and parsed again by the login shell on the server, so
1010
# quoting for the local shell does not protect it. These tests require
1111
# that a value with a character special to a shell never reaches ssh,
1212
# and that ordinary values reach it unchanged.
1313
#
14
+
15
+# These tests run only in a long pass: -assurance stress.
16
+if {[test_assurance] ne "stress"} {
17
+ test_skip "runs only with -assurance stress"
18
+}
1419
1520
require_no_open_checkout
1621
1722
if {$::tcl_platform(platform) eq "windows"} {
1823
test_skip "the stand-in for ssh is a shell script"
@@ -69,12 +74,12 @@
6974
{[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0}
7075
ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil"
7176
test ssh-clone-fossil-parameter \
7277
{[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0}
7378
74
-# A path that begins with "~" is for the server to expand. It was
75
-# previously expanded on the local machine.
79
+# A path that begins with "~" is for the server to expand, so it goes to
80
+# the server as it is.
7681
ssh_clone ssh://hh/~/repo.fossil
7782
test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0}
7883
7984
###############################################################################
8085
# A path or a fossil= value with a character special to a shell is
8186
--- test/ssh.test
+++ test/ssh.test
@@ -9,10 +9,15 @@
9 # string by ssh and parsed again by the login shell on the server, so
10 # quoting for the local shell does not protect it. These tests require
11 # that a value with a character special to a shell never reaches ssh,
12 # and that ordinary values reach it unchanged.
13 #
 
 
 
 
 
14
15 require_no_open_checkout
16
17 if {$::tcl_platform(platform) eq "windows"} {
18 test_skip "the stand-in for ssh is a shell script"
@@ -69,12 +74,12 @@
69 {[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0}
70 ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil"
71 test ssh-clone-fossil-parameter \
72 {[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0}
73
74 # A path that begins with "~" is for the server to expand. It was
75 # previously expanded on the local machine.
76 ssh_clone ssh://hh/~/repo.fossil
77 test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0}
78
79 ###############################################################################
80 # A path or a fossil= value with a character special to a shell is
81
--- test/ssh.test
+++ test/ssh.test
@@ -9,10 +9,15 @@
9 # string by ssh and parsed again by the login shell on the server, so
10 # quoting for the local shell does not protect it. These tests require
11 # that a value with a character special to a shell never reaches ssh,
12 # and that ordinary values reach it unchanged.
13 #
14
15 # These tests run only in a long pass: -assurance stress.
16 if {[test_assurance] ne "stress"} {
17 test_skip "runs only with -assurance stress"
18 }
19
20 require_no_open_checkout
21
22 if {$::tcl_platform(platform) eq "windows"} {
23 test_skip "the stand-in for ssh is a shell script"
@@ -69,12 +74,12 @@
74 {[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0}
75 ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil"
76 test ssh-clone-fossil-parameter \
77 {[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0}
78
79 # A path that begins with "~" is for the server to expand, so it goes to
80 # the server as it is.
81 ssh_clone ssh://hh/~/repo.fossil
82 test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0}
83
84 ###############################################################################
85 # A path or a fossil= value with a character special to a shell is
86
--- test/sync.test
+++ test/sync.test
@@ -2,10 +2,15 @@
22
# Tests of clone, push, pull and sync, over file: URLs and over HTTP to
33
# "fossil server". After each operation, the repositories must hold the
44
# same artifacts, except for private ones, and pass "fossil
55
# test-integrity".
66
#
7
+
8
+# These tests run only in a long pass: -assurance stress.
9
+if {[test_assurance] ne "stress"} {
10
+ test_skip "runs only with -assurance stress"
11
+}
712
813
require_no_open_checkout
914
1015
test_setup ""
1116
set dir [pwd]
@@ -106,10 +111,457 @@
106111
test_eq sync-private-not-pushed [sync_private_count a.fossil] 0
107112
test_eq sync-private-artifacts [sync_artifacts a.fossil] \
108113
[sync_artifacts b.fossil]
109114
fossil update trunk --chdir b
110115
116
+# The sections below that were written for a checkout of their own each
117
+# run in a directory of their own, with a repository of their own and
118
+# without the user name that the sections above set.
119
+proc sync_enter {name} {
120
+ global dir
121
+ file mkdir [file join $dir $name]
122
+ cd [file join $dir $name]
123
+ set ::syncUser $::env(FOSSIL_USER)
124
+ unset ::env(FOSSIL_USER)
125
+ fossil new .rep.fossil
126
+ fossil open .rep.fossil
127
+ fossil set mtime-changes off
128
+}
129
+proc sync_leave {} {
130
+ global dir
131
+ cd $dir
132
+ set ::env(FOSSIL_USER) $::syncUser
133
+}
134
+
135
+###############################################################################
136
+# Whole syncs between repositories on one machine. A push, pull or sync
137
+# with a repository named by its file starts "fossil http" on that file,
138
+# so both sides speak the sync protocol in full, and the other side
139
+# grants every permission. Where the other side has to check
140
+# permissions, the messages go through standin/scenario-wire.tcl.
141
+
142
+sync_enter xfer-sync
143
+
144
+set syncXferDir [pwd]
145
+set syncXferSrv [file join $syncXferDir srv.fossil]
146
+
147
+proc sync_sql {repo sql} {
148
+ fossil sql -R $repo $sql
149
+ return [string trim $::RESULT]
150
+}
151
+
152
+# How many timeline entries of REPO have the comment COMMENT.
153
+proc sync_has {repo comment} {
154
+ return [sync_sql $repo "SELECT count(*) FROM event
155
+ WHERE comment='$comment'"]
156
+}
157
+
158
+# The artifacts REPO holds that are neither phantoms nor private.
159
+proc sync_public {repo} {
160
+ return [sync_sql $repo "SELECT group_concat(uuid, ' ') FROM (SELECT uuid
161
+ FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"]
162
+}
163
+proc sync_private_held {repo} {
164
+ return [sync_sql $repo "SELECT count(*) FROM private, blob
165
+ WHERE private.rid=blob.rid AND size>=0"]
166
+}
167
+proc sync_integrity {name repo} {
168
+ fossil test-integrity -R $repo
169
+ test $name {$::CODE == 0}
170
+}
171
+
172
+# Commit FILE with CONTENT in the checkout and return the check-in's hash.
173
+proc sync_checkin {file content comment args} {
174
+ set new [expr {![file exists $file]}]
175
+ write_file $file $content
176
+ if {$new} {fossil add $file}
177
+ fossil commit -m $comment --no-warnings {*}$args
178
+ return [sync_sql .rep.fossil "SELECT uuid FROM blob, event
179
+ WHERE objid=rid AND comment='$comment'"]
180
+}
181
+
182
+set syncXferText ""
183
+for {set syncXferI 0} {$syncXferI < 60} {incr syncXferI} {
184
+ append syncXferText "line $syncXferI of a file that is kept in versions\n"
185
+}
186
+fossil settings autosync off
187
+sync_checkin a.txt $syncXferText xfersync-first
188
+file copy .rep.fossil srv.fossil
189
+file copy .rep.fossil c2.fossil
190
+file copy .rep.fossil c3.fossil
191
+
192
+###############################################################################
193
+# A check-in that was private and is made public, while its file is still
194
+# stored as a delta from a private one. Neither a push nor a clone may
195
+# hand out the delta: the other side lacks what it was made from.
196
+
197
+set syncXferG1 [sync_checkin big.txt "${syncXferText}first\n" \
198
+ xfersync-g1 --private]
199
+set syncXferG2 [sync_checkin big.txt "${syncXferText}first\nsecond\n" \
200
+ xfersync-g2]
201
+fossil publish $syncXferG1
202
+test xfer-sync-publish {$CODE == 0}
203
+test xfer-sync-public-delta-from-private {[sync_sql .rep.fossil "SELECT
204
+ count(*) FROM delta WHERE rid NOT IN private AND srcid IN private"] > 0}
205
+
206
+fossil push $syncXferSrv
207
+test xfer-sync-push {$CODE == 0}
208
+test_eq xfer-sync-push-published [sync_has srv.fossil xfersync-g1] 1
209
+test_eq xfer-sync-push-not-private [sync_has srv.fossil xfersync-g2] 0
210
+test_eq xfer-sync-push-no-private-artifacts [sync_private_held srv.fossil] 0
211
+test_eq xfer-sync-push-artifacts [sync_public srv.fossil] \
212
+ [sync_public .rep.fossil]
213
+fossil cat big.txt -R srv.fossil -r $syncXferG1
214
+test_eq xfer-sync-push-content $RESULT "${syncXferText}first"
215
+sync_integrity xfer-sync-push-integrity srv.fossil
216
+
217
+set syncXferWire [file join $syncXferDir wire.tcl]
218
+file copy [file join $::testfiledir standin scenario-wire.tcl] $syncXferWire
219
+set syncXferWire "\"[info nameofexecutable]\" \"$syncXferWire\""
220
+set ::env(SCN_EXE) $::fossilexe
221
+set ::env(SCN_REPO) [file join $syncXferDir .rep.fossil]
222
+set ::env(SCN_FAULT) 0
223
+fossil_raw -seconds 120 clone http://xfersync.invalid/x c4.fossil \
224
+ --transport-command $syncXferWire --no-open
225
+test xfer-sync-clone {$CODE == 0}
226
+test_eq xfer-sync-clone-artifacts [sync_public c4.fossil] \
227
+ [sync_public .rep.fossil]
228
+test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0
229
+fossil cat big.txt -R c4.fossil -r $syncXferG1
230
+test_eq xfer-sync-clone-content $RESULT "${syncXferText}first"
231
+sync_integrity xfer-sync-clone-integrity c4.fossil
232
+
233
+###############################################################################
234
+# Private check-ins go only when asked for, and stay private where they
235
+# arrive.
236
+
237
+fossil push --private $syncXferSrv
238
+test xfer-sync-push-private {$CODE == 0}
239
+test_eq xfer-sync-push-private-arrived [sync_has srv.fossil xfersync-g2] 1
240
+test xfer-sync-push-private-marked {[sync_private_held srv.fossil] > 0}
241
+test_eq xfer-sync-push-private-count [sync_private_held srv.fossil] \
242
+ [sync_private_held .rep.fossil]
243
+
244
+fossil pull $syncXferSrv -R c2.fossil
245
+test xfer-sync-pull {$CODE == 0}
246
+test_eq xfer-sync-pull-no-private [sync_has c2.fossil xfersync-g2] 0
247
+test_eq xfer-sync-pull-artifacts [sync_public c2.fossil] \
248
+ [sync_public srv.fossil]
249
+fossil pull --private $syncXferSrv -R c2.fossil
250
+test xfer-sync-pull-private {$CODE == 0}
251
+test_eq xfer-sync-pull-private-arrived [sync_has c2.fossil xfersync-g2] 1
252
+test_eq xfer-sync-pull-private-count [sync_private_held c2.fossil] \
253
+ [sync_private_held srv.fossil]
254
+fossil cat big.txt -R c2.fossil -r $syncXferG2
255
+test_eq xfer-sync-pull-private-content $RESULT "${syncXferText}first\nsecond"
256
+sync_integrity xfer-sync-pull-private-integrity c2.fossil
257
+
258
+# With --verily each side lists everything it holds. The result is the
259
+# same. The options that change only what is printed do not change it
260
+# either.
261
+fossil pull --verily $syncXferSrv -R c3.fossil
262
+test xfer-sync-pull-verily {$CODE == 0}
263
+test_eq xfer-sync-pull-verily-artifacts [sync_public c3.fossil] \
264
+ [sync_public srv.fossil]
265
+fossil sync --verily --private $syncXferSrv -R c3.fossil
266
+test xfer-sync-sync-verily {$CODE == 0}
267
+test_eq xfer-sync-sync-verily-private [sync_private_held c3.fossil] \
268
+ [sync_private_held srv.fossil]
269
+fossil sync -v -v --no-http-compression $syncXferSrv -R c3.fossil
270
+test xfer-sync-verbose {$CODE == 0 && [string first "Sent:" $RESULT] >= 0}
271
+fossil sync --quiet $syncXferSrv -R c3.fossil
272
+test xfer-sync-quiet {$CODE == 0}
273
+sync_integrity xfer-sync-verily-integrity c3.fossil
274
+
275
+###############################################################################
276
+# Unversioned files. The newer of two versions wins, whichever side has
277
+# it; a removal is a version like any other.
278
+
279
+proc sync_uv {repo name} {
280
+ return [sync_sql $repo "SELECT ifnull(hash,'removed') || ' ' || mtime
281
+ FROM unversioned WHERE name='$name'"]
282
+}
283
+proc sync_uvtime {text} {
284
+ return [sync_sql .rep.fossil "SELECT strftime('%s','$text')"]
285
+}
286
+
287
+write_file one.txt "the first version of one\n"
288
+fossil uv add one.txt --mtime 2026-01-01T00:00:00
289
+fossil uv sync $syncXferSrv
290
+test xfer-sync-uv-push {$CODE == 0}
291
+test_eq xfer-sync-uv-push-arrived [sync_uv srv.fossil one.txt] \
292
+ [sync_uv .rep.fossil one.txt]
293
+fossil uv cat one.txt -R srv.fossil
294
+test_eq xfer-sync-uv-push-content $RESULT "the first version of one"
295
+
296
+write_file two.txt "a file added on the other side\n"
297
+fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00
298
+fossil uv sync -v $syncXferSrv
299
+test xfer-sync-uv-pull {$CODE == 0}
300
+test xfer-sync-uv-pull-said {[string first "UV-PULL: two.txt" $RESULT] >= 0
301
+ && [string first "Unversioned-file received: two.txt" $RESULT] >= 0}
302
+fossil uv cat two.txt
303
+test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side"
304
+
305
+# A trial run says what would go and sends nothing.
306
+write_file one.txt "the second version of one\n"
307
+fossil uv add one.txt --mtime 2026-01-03T00:00:00
308
+fossil uv sync -n $syncXferSrv
309
+test xfer-sync-uv-dry-run {$CODE == 0 &&
310
+ [string first "UV-PUSH: one.txt" $RESULT] >= 0}
311
+fossil uv cat one.txt -R srv.fossil
312
+test_eq xfer-sync-uv-dry-run-sent-nothing $RESULT "the first version of one"
313
+
314
+# A revert takes the other side's version although it is older.
315
+fossil uv revert $syncXferSrv
316
+test xfer-sync-uv-revert {$CODE == 0}
317
+fossil uv cat one.txt
318
+test_eq xfer-sync-uv-revert-content $RESULT "the first version of one"
319
+
320
+write_file one.txt "the second version of one\n"
321
+fossil uv add one.txt --mtime 2026-01-03T00:00:00
322
+fossil uv sync -v $syncXferSrv
323
+test xfer-sync-uv-push-newer {$CODE == 0}
324
+test xfer-sync-uv-push-newer-said \
325
+ {[string first "UV-PUSH: one.txt" $RESULT] >= 0
326
+ && [string first "Unversioned-file sent: one.txt" $RESULT] >= 0}
327
+fossil uv cat one.txt -R srv.fossil
328
+test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one"
329
+
330
+# A removal on the other side.
331
+fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00
332
+fossil uv sync -v $syncXferSrv
333
+test xfer-sync-uv-removal {$CODE == 0}
334
+test_eq xfer-sync-uv-removal-arrived [sync_uv .rep.fossil two.txt] \
335
+ "removed [sync_uvtime 2026-01-04T00:00:00]"
336
+
337
+# The same content with a newer time, first there and then here.
338
+fossil uv touch one.txt -R srv.fossil --mtime 2026-01-05T00:00:00
339
+fossil uv sync -v $syncXferSrv
340
+test xfer-sync-uv-time-pulled {$CODE == 0 &&
341
+ [string first "UV-PULL-MTIME-ONLY: one.txt" $RESULT] >= 0}
342
+test_eq xfer-sync-uv-time-pulled-value \
343
+ [lindex [sync_uv .rep.fossil one.txt] 1] \
344
+ [sync_uvtime 2026-01-05T00:00:00]
345
+fossil uv touch one.txt --mtime 2026-01-06T00:00:00
346
+fossil uv sync -v $syncXferSrv
347
+test xfer-sync-uv-time-pushed {$CODE == 0 &&
348
+ [string first "UV-PUSH-MTIME-ONLY: one.txt" $RESULT] >= 0}
349
+test_eq xfer-sync-uv-time-pushed-value \
350
+ [lindex [sync_uv srv.fossil one.txt] 1] \
351
+ [sync_uvtime 2026-01-06T00:00:00]
352
+test_eq xfer-sync-uv-same-at-end [sync_uv srv.fossil one.txt] \
353
+ [sync_uv .rep.fossil one.txt]
354
+
355
+# A user who may read and not write unversioned files is told so, and
356
+# what was to be sent stays here.
357
+set ::env(SCN_REPO) $syncXferSrv
358
+set ::env(SCN_AUTH) 1
359
+fossil sql -R srv.fossil \
360
+ "UPDATE user SET cap='o' WHERE login IN ('nobody','anonymous')"
361
+fossil uv touch one.txt --mtime 2026-01-07T00:00:00
362
+fossil_raw -seconds 120 uv sync -v http://xfersync.invalid/x \
363
+ --transport-command $syncXferWire
364
+test xfer-sync-uv-pull-only {[string first "uv-pull-only" $RESULT] >= 0}
365
+test_eq xfer-sync-uv-pull-only-not-sent \
366
+ [lindex [sync_uv srv.fossil one.txt] 1] \
367
+ [sync_uvtime 2026-01-06T00:00:00]
368
+
369
+# The same for a file that the other side has never held.
370
+fossil uv touch one.txt --mtime 2026-01-06T00:00:00
371
+write_file three.txt "a file the other side will not take\n"
372
+fossil uv add three.txt --mtime 2026-01-07T00:00:00
373
+fossil_raw -seconds 120 uv sync -v http://xfersync.invalid/x \
374
+ --transport-command $syncXferWire
375
+set syncXferSaid $RESULT
376
+test_eq xfer-sync-uv-pull-only-new-not-sent [sync_uv srv.fossil three.txt] ""
377
+test xfer-sync-uv-pull-only-new-said \
378
+ {[string first "uv-pull-only" $syncXferSaid] >= 0}
379
+test xfer-sync-uv-pull-only-new-kept {[sync_uv .rep.fossil three.txt] ne ""}
380
+
381
+# A revert from such a server still makes this side match it: the file
382
+# the server never had goes, and nothing is said about pushing.
383
+fossil_raw -seconds 120 uv revert http://xfersync.invalid/x \
384
+ --transport-command $syncXferWire
385
+test xfer-sync-uv-pull-only-revert {$CODE == 0 &&
386
+ [string first "uv-pull-only" $RESULT] < 0}
387
+test_eq xfer-sync-uv-pull-only-revert-removed [sync_uv .rep.fossil three.txt] ""
388
+unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
389
+
390
+###############################################################################
391
+# A project that was split off pulls from the project it came from only
392
+# when it says that it means to.
393
+
394
+file copy srv.fossil child2.fossil
395
+fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)
396
+ VALUES('project-name','xfersync parent',now())"
397
+file copy srv.fossil child.fossil
398
+fossil_raw -input "y\n" detach child.fossil
399
+test xfer-sync-detach {$CODE == 0}
400
+test xfer-sync-detach-new-code {[sync_sql child.fossil "SELECT value
401
+ FROM config WHERE name='project-code'"] ne [sync_sql srv.fossil "SELECT
402
+ value FROM config WHERE name='project-code'"]}
403
+sync_checkin a.txt "${syncXferText}more\n" xfersync-after-split
404
+fossil push --private $syncXferSrv
405
+test_eq xfer-sync-parent-has-new [sync_has srv.fossil xfersync-after-split] 1
406
+fossil pull $syncXferSrv -R child.fossil -expectError
407
+test xfer-sync-child-plain-pull-refused {$CODE != 0}
408
+test_eq xfer-sync-child-plain-pull-nothing \
409
+ [sync_has child.fossil xfersync-after-split] 0
410
+# The new check-in follows a private one, so it is private too.
411
+fossil pull --from-parent-project $syncXferSrv -R child.fossil
412
+test xfer-sync-child-parent-pull-public-only {$CODE == 0 &&
413
+ [sync_has child.fossil xfersync-after-split] == 0}
414
+fossil pull --private --from-parent-project $syncXferSrv -R child.fossil
415
+test xfer-sync-child-parent-pull {$CODE == 0}
416
+test_eq xfer-sync-child-parent-pull-arrived \
417
+ [sync_has child.fossil xfersync-after-split] 1
418
+sync_integrity xfer-sync-child-integrity child.fossil
419
+
420
+# The same when the project it came from has no name.
421
+fossil_raw -input "y\n" detach child2.fossil
422
+fossil_raw pull --from-parent-project $syncXferSrv -R child2.fossil
423
+test xfer-sync-unnamed-parent-pull {$CODE == 0}
424
+test_eq xfer-sync-unnamed-parent-pull-arrived [sync_public child2.fossil] \
425
+ [sync_public srv.fossil]
426
+
427
+sync_leave
428
+
429
+###############################################################################
430
+# A clone made over the sync protocol. "fossil clone" of a file on the
431
+# same machine copies the file and never speaks the protocol, so here a
432
+# real client clones from a real server through
433
+# standin/scenario-wire.tcl, which hands each request to "fossil http"
434
+# on the server's repository.
435
+
436
+sync_enter xfer-clone
437
+
438
+# The server: several versions of one file, so that it stores deltas, an
439
+# empty file, a branch, a tag, a wiki page and an unversioned file.
440
+set syncCloneText ""
441
+for {set syncCloneI 0} {$syncCloneI < 40} {incr syncCloneI} {
442
+ append syncCloneText "line $syncCloneI of a file with several versions\n"
443
+}
444
+write_file empty.txt ""
445
+fossil add empty.txt
446
+foreach syncCloneI {1 2 3 4 5} {
447
+ append syncCloneText "version $syncCloneI\n"
448
+ write_file a.txt $syncCloneText
449
+ if {$syncCloneI == 1} {fossil add a.txt}
450
+ fossil commit -m "xferclone-v$syncCloneI" --no-warnings
451
+}
452
+fossil branch new side trunk
453
+fossil tag add marked trunk
454
+write_file page.txt "a wiki page\n"
455
+fossil wiki create ClonePage page.txt
456
+write_file note.txt "an unversioned note\n"
457
+fossil unversioned add note.txt
458
+file copy .rep.fossil srv.fossil
459
+
460
+set syncCloneWire [file join [pwd] wire.tcl]
461
+file copy [file join $::testfiledir standin scenario-wire.tcl] $syncCloneWire
462
+set syncCloneWire "\"[info nameofexecutable]\" \"$syncCloneWire\""
463
+set ::env(SCN_EXE) $::fossilexe
464
+set ::env(SCN_REPO) [file join [pwd] srv.fossil]
465
+set ::env(SCN_FAULT) 0
466
+
467
+# Clone the server into the repository file NAME, with any more
468
+# arguments for "fossil clone".
469
+#
470
+proc sync_clone_wire {name args} {
471
+ global syncCloneWire
472
+ fossil_raw -seconds 120 clone http://xferclone.invalid/x $name \
473
+ --transport-command $syncCloneWire --no-open {*}$args
474
+}
475
+
476
+# What a repository holds: the artifacts with content, the timeline, the
477
+# branches and tags, and the unversioned files.
478
+#
479
+proc sync_holds {repo} {
480
+ fossil sql -R $repo "SELECT group_concat(uuid, ' ') FROM (SELECT uuid
481
+ FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid);
482
+ SELECT group_concat(x, ' ') FROM (SELECT type || comment AS x
483
+ FROM event ORDER BY mtime, objid);
484
+ SELECT group_concat(x, ' ') FROM (SELECT tagname || tagtype AS x
485
+ FROM tagxref, tag WHERE tag.tagid=tagxref.tagid AND tagname LIKE 'sym-%'
486
+ ORDER BY 1)"
487
+ return [string trim $::RESULT]
488
+}
489
+proc sync_uv_files {repo} {
490
+ fossil sql -R $repo "SELECT group_concat(name || '/' || hash, ' ')
491
+ FROM unversioned WHERE hash IS NOT NULL"
492
+ return [string trim $::RESULT]
493
+}
494
+
495
+set syncCloneWant [sync_holds srv.fossil]
496
+
497
+###############################################################################
498
+# An ordinary clone holds what the server holds, and is sound.
499
+
500
+sync_clone_wire c1.fossil
501
+test xfer-clone {$CODE == 0}
502
+test_eq xfer-clone-holds [sync_holds c1.fossil] $syncCloneWant
503
+fossil test-integrity -R c1.fossil
504
+test xfer-clone-integrity {$CODE == 0}
505
+fossil sql -R c1.fossil "SELECT value FROM config WHERE name='project-code'"
506
+set syncCloneCode [string trim $RESULT]
507
+fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'"
508
+test_eq xfer-clone-project-code $syncCloneCode [string trim $RESULT]
509
+
510
+# The files of the newest and of the first check-in can be read from it.
511
+fossil cat a.txt -R c1.fossil -r trunk
512
+test_eq xfer-clone-newest-file [string trim $RESULT] \
513
+ [string trim $syncCloneText]
514
+fossil cat empty.txt -R c1.fossil -r trunk
515
+test_eq xfer-clone-empty-file $RESULT ""
516
+
517
+# Unversioned files come only when they are asked for.
518
+fossil sql -R c1.fossil "SELECT count(*) FROM sqlite_schema
519
+ WHERE name='unversioned'"
520
+set syncCloneHasUv [string trim $RESULT]
521
+test xfer-clone-without-unversioned \
522
+ {!$syncCloneHasUv || [sync_uv_files c1.fossil] eq ""}
523
+sync_clone_wire c2.fossil --unversioned
524
+test xfer-clone-unversioned {$CODE == 0}
525
+test_eq xfer-clone-unversioned-files [sync_uv_files c2.fossil] \
526
+ [sync_uv_files srv.fossil]
527
+test_eq xfer-clone-unversioned-holds [sync_holds c2.fossil] $syncCloneWant
528
+
529
+# With small messages the clone takes many round trips and ends the same.
530
+fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)
531
+ VALUES('max-download',2000,now())"
532
+sync_clone_wire c3.fossil
533
+test xfer-clone-small-replies {$CODE == 0}
534
+test_eq xfer-clone-small-replies-holds [sync_holds c3.fossil] \
535
+ $syncCloneWant
536
+fossil test-integrity -R c3.fossil
537
+test xfer-clone-small-replies-integrity {$CODE == 0}
538
+fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download'"
539
+
540
+###############################################################################
541
+# A server that checks permissions refuses a clone to a user without the
542
+# permission, and no repository is left behind.
543
+
544
+set ::env(SCN_AUTH) 1
545
+fossil sql -R srv.fossil \
546
+ "UPDATE user SET cap='o' WHERE login IN ('nobody','anonymous')"
547
+sync_clone_wire c4.fossil
548
+test xfer-clone-refused \
549
+ {$CODE != 0 && [string first "not authorized to clone" $RESULT] >= 0}
550
+test xfer-clone-refused-leaves-nothing {![file exists c4.fossil]}
551
+fossil sql -R srv.fossil \
552
+ "UPDATE user SET cap='go' WHERE login IN ('nobody','anonymous')"
553
+sync_clone_wire c5.fossil
554
+test xfer-clone-permitted {$CODE == 0}
555
+test_eq xfer-clone-permitted-holds [sync_holds c5.fossil] $syncCloneWant
556
+
557
+unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
558
+
559
+sync_leave
560
+
561
+###############################################################################
562
+
111563
if {![loopback_available]} {
112564
unset ::env(FOSSIL_USER)
113565
test_skip "the tests that run fossil server cannot start a server"
114566
}
115567
set server [test_start_server a.fossil stopArg]
116568
--- test/sync.test
+++ test/sync.test
@@ -2,10 +2,15 @@
2 # Tests of clone, push, pull and sync, over file: URLs and over HTTP to
3 # "fossil server". After each operation, the repositories must hold the
4 # same artifacts, except for private ones, and pass "fossil
5 # test-integrity".
6 #
 
 
 
 
 
7
8 require_no_open_checkout
9
10 test_setup ""
11 set dir [pwd]
@@ -106,10 +111,457 @@
106 test_eq sync-private-not-pushed [sync_private_count a.fossil] 0
107 test_eq sync-private-artifacts [sync_artifacts a.fossil] \
108 [sync_artifacts b.fossil]
109 fossil update trunk --chdir b
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111 if {![loopback_available]} {
112 unset ::env(FOSSIL_USER)
113 test_skip "the tests that run fossil server cannot start a server"
114 }
115 set server [test_start_server a.fossil stopArg]
116
--- test/sync.test
+++ test/sync.test
@@ -2,10 +2,15 @@
2 # Tests of clone, push, pull and sync, over file: URLs and over HTTP to
3 # "fossil server". After each operation, the repositories must hold the
4 # same artifacts, except for private ones, and pass "fossil
5 # test-integrity".
6 #
7
8 # These tests run only in a long pass: -assurance stress.
9 if {[test_assurance] ne "stress"} {
10 test_skip "runs only with -assurance stress"
11 }
12
13 require_no_open_checkout
14
15 test_setup ""
16 set dir [pwd]
@@ -106,10 +111,457 @@
111 test_eq sync-private-not-pushed [sync_private_count a.fossil] 0
112 test_eq sync-private-artifacts [sync_artifacts a.fossil] \
113 [sync_artifacts b.fossil]
114 fossil update trunk --chdir b
115
116 # The sections below that were written for a checkout of their own each
117 # run in a directory of their own, with a repository of their own and
118 # without the user name that the sections above set.
119 proc sync_enter {name} {
120 global dir
121 file mkdir [file join $dir $name]
122 cd [file join $dir $name]
123 set ::syncUser $::env(FOSSIL_USER)
124 unset ::env(FOSSIL_USER)
125 fossil new .rep.fossil
126 fossil open .rep.fossil
127 fossil set mtime-changes off
128 }
129 proc sync_leave {} {
130 global dir
131 cd $dir
132 set ::env(FOSSIL_USER) $::syncUser
133 }
134
135 ###############################################################################
136 # Whole syncs between repositories on one machine. A push, pull or sync
137 # with a repository named by its file starts "fossil http" on that file,
138 # so both sides speak the sync protocol in full, and the other side
139 # grants every permission. Where the other side has to check
140 # permissions, the messages go through standin/scenario-wire.tcl.
141
142 sync_enter xfer-sync
143
144 set syncXferDir [pwd]
145 set syncXferSrv [file join $syncXferDir srv.fossil]
146
147 proc sync_sql {repo sql} {
148 fossil sql -R $repo $sql
149 return [string trim $::RESULT]
150 }
151
152 # How many timeline entries of REPO have the comment COMMENT.
153 proc sync_has {repo comment} {
154 return [sync_sql $repo "SELECT count(*) FROM event
155 WHERE comment='$comment'"]
156 }
157
158 # The artifacts REPO holds that are neither phantoms nor private.
159 proc sync_public {repo} {
160 return [sync_sql $repo "SELECT group_concat(uuid, ' ') FROM (SELECT uuid
161 FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"]
162 }
163 proc sync_private_held {repo} {
164 return [sync_sql $repo "SELECT count(*) FROM private, blob
165 WHERE private.rid=blob.rid AND size>=0"]
166 }
167 proc sync_integrity {name repo} {
168 fossil test-integrity -R $repo
169 test $name {$::CODE == 0}
170 }
171
172 # Commit FILE with CONTENT in the checkout and return the check-in's hash.
173 proc sync_checkin {file content comment args} {
174 set new [expr {![file exists $file]}]
175 write_file $file $content
176 if {$new} {fossil add $file}
177 fossil commit -m $comment --no-warnings {*}$args
178 return [sync_sql .rep.fossil "SELECT uuid FROM blob, event
179 WHERE objid=rid AND comment='$comment'"]
180 }
181
182 set syncXferText ""
183 for {set syncXferI 0} {$syncXferI < 60} {incr syncXferI} {
184 append syncXferText "line $syncXferI of a file that is kept in versions\n"
185 }
186 fossil settings autosync off
187 sync_checkin a.txt $syncXferText xfersync-first
188 file copy .rep.fossil srv.fossil
189 file copy .rep.fossil c2.fossil
190 file copy .rep.fossil c3.fossil
191
192 ###############################################################################
193 # A check-in that was private and is made public, while its file is still
194 # stored as a delta from a private one. Neither a push nor a clone may
195 # hand out the delta: the other side lacks what it was made from.
196
197 set syncXferG1 [sync_checkin big.txt "${syncXferText}first\n" \
198 xfersync-g1 --private]
199 set syncXferG2 [sync_checkin big.txt "${syncXferText}first\nsecond\n" \
200 xfersync-g2]
201 fossil publish $syncXferG1
202 test xfer-sync-publish {$CODE == 0}
203 test xfer-sync-public-delta-from-private {[sync_sql .rep.fossil "SELECT
204 count(*) FROM delta WHERE rid NOT IN private AND srcid IN private"] > 0}
205
206 fossil push $syncXferSrv
207 test xfer-sync-push {$CODE == 0}
208 test_eq xfer-sync-push-published [sync_has srv.fossil xfersync-g1] 1
209 test_eq xfer-sync-push-not-private [sync_has srv.fossil xfersync-g2] 0
210 test_eq xfer-sync-push-no-private-artifacts [sync_private_held srv.fossil] 0
211 test_eq xfer-sync-push-artifacts [sync_public srv.fossil] \
212 [sync_public .rep.fossil]
213 fossil cat big.txt -R srv.fossil -r $syncXferG1
214 test_eq xfer-sync-push-content $RESULT "${syncXferText}first"
215 sync_integrity xfer-sync-push-integrity srv.fossil
216
217 set syncXferWire [file join $syncXferDir wire.tcl]
218 file copy [file join $::testfiledir standin scenario-wire.tcl] $syncXferWire
219 set syncXferWire "\"[info nameofexecutable]\" \"$syncXferWire\""
220 set ::env(SCN_EXE) $::fossilexe
221 set ::env(SCN_REPO) [file join $syncXferDir .rep.fossil]
222 set ::env(SCN_FAULT) 0
223 fossil_raw -seconds 120 clone http://xfersync.invalid/x c4.fossil \
224 --transport-command $syncXferWire --no-open
225 test xfer-sync-clone {$CODE == 0}
226 test_eq xfer-sync-clone-artifacts [sync_public c4.fossil] \
227 [sync_public .rep.fossil]
228 test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0
229 fossil cat big.txt -R c4.fossil -r $syncXferG1
230 test_eq xfer-sync-clone-content $RESULT "${syncXferText}first"
231 sync_integrity xfer-sync-clone-integrity c4.fossil
232
233 ###############################################################################
234 # Private check-ins go only when asked for, and stay private where they
235 # arrive.
236
237 fossil push --private $syncXferSrv
238 test xfer-sync-push-private {$CODE == 0}
239 test_eq xfer-sync-push-private-arrived [sync_has srv.fossil xfersync-g2] 1
240 test xfer-sync-push-private-marked {[sync_private_held srv.fossil] > 0}
241 test_eq xfer-sync-push-private-count [sync_private_held srv.fossil] \
242 [sync_private_held .rep.fossil]
243
244 fossil pull $syncXferSrv -R c2.fossil
245 test xfer-sync-pull {$CODE == 0}
246 test_eq xfer-sync-pull-no-private [sync_has c2.fossil xfersync-g2] 0
247 test_eq xfer-sync-pull-artifacts [sync_public c2.fossil] \
248 [sync_public srv.fossil]
249 fossil pull --private $syncXferSrv -R c2.fossil
250 test xfer-sync-pull-private {$CODE == 0}
251 test_eq xfer-sync-pull-private-arrived [sync_has c2.fossil xfersync-g2] 1
252 test_eq xfer-sync-pull-private-count [sync_private_held c2.fossil] \
253 [sync_private_held srv.fossil]
254 fossil cat big.txt -R c2.fossil -r $syncXferG2
255 test_eq xfer-sync-pull-private-content $RESULT "${syncXferText}first\nsecond"
256 sync_integrity xfer-sync-pull-private-integrity c2.fossil
257
258 # With --verily each side lists everything it holds. The result is the
259 # same. The options that change only what is printed do not change it
260 # either.
261 fossil pull --verily $syncXferSrv -R c3.fossil
262 test xfer-sync-pull-verily {$CODE == 0}
263 test_eq xfer-sync-pull-verily-artifacts [sync_public c3.fossil] \
264 [sync_public srv.fossil]
265 fossil sync --verily --private $syncXferSrv -R c3.fossil
266 test xfer-sync-sync-verily {$CODE == 0}
267 test_eq xfer-sync-sync-verily-private [sync_private_held c3.fossil] \
268 [sync_private_held srv.fossil]
269 fossil sync -v -v --no-http-compression $syncXferSrv -R c3.fossil
270 test xfer-sync-verbose {$CODE == 0 && [string first "Sent:" $RESULT] >= 0}
271 fossil sync --quiet $syncXferSrv -R c3.fossil
272 test xfer-sync-quiet {$CODE == 0}
273 sync_integrity xfer-sync-verily-integrity c3.fossil
274
275 ###############################################################################
276 # Unversioned files. The newer of two versions wins, whichever side has
277 # it; a removal is a version like any other.
278
279 proc sync_uv {repo name} {
280 return [sync_sql $repo "SELECT ifnull(hash,'removed') || ' ' || mtime
281 FROM unversioned WHERE name='$name'"]
282 }
283 proc sync_uvtime {text} {
284 return [sync_sql .rep.fossil "SELECT strftime('%s','$text')"]
285 }
286
287 write_file one.txt "the first version of one\n"
288 fossil uv add one.txt --mtime 2026-01-01T00:00:00
289 fossil uv sync $syncXferSrv
290 test xfer-sync-uv-push {$CODE == 0}
291 test_eq xfer-sync-uv-push-arrived [sync_uv srv.fossil one.txt] \
292 [sync_uv .rep.fossil one.txt]
293 fossil uv cat one.txt -R srv.fossil
294 test_eq xfer-sync-uv-push-content $RESULT "the first version of one"
295
296 write_file two.txt "a file added on the other side\n"
297 fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00
298 fossil uv sync -v $syncXferSrv
299 test xfer-sync-uv-pull {$CODE == 0}
300 test xfer-sync-uv-pull-said {[string first "UV-PULL: two.txt" $RESULT] >= 0
301 && [string first "Unversioned-file received: two.txt" $RESULT] >= 0}
302 fossil uv cat two.txt
303 test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side"
304
305 # A trial run says what would go and sends nothing.
306 write_file one.txt "the second version of one\n"
307 fossil uv add one.txt --mtime 2026-01-03T00:00:00
308 fossil uv sync -n $syncXferSrv
309 test xfer-sync-uv-dry-run {$CODE == 0 &&
310 [string first "UV-PUSH: one.txt" $RESULT] >= 0}
311 fossil uv cat one.txt -R srv.fossil
312 test_eq xfer-sync-uv-dry-run-sent-nothing $RESULT "the first version of one"
313
314 # A revert takes the other side's version although it is older.
315 fossil uv revert $syncXferSrv
316 test xfer-sync-uv-revert {$CODE == 0}
317 fossil uv cat one.txt
318 test_eq xfer-sync-uv-revert-content $RESULT "the first version of one"
319
320 write_file one.txt "the second version of one\n"
321 fossil uv add one.txt --mtime 2026-01-03T00:00:00
322 fossil uv sync -v $syncXferSrv
323 test xfer-sync-uv-push-newer {$CODE == 0}
324 test xfer-sync-uv-push-newer-said \
325 {[string first "UV-PUSH: one.txt" $RESULT] >= 0
326 && [string first "Unversioned-file sent: one.txt" $RESULT] >= 0}
327 fossil uv cat one.txt -R srv.fossil
328 test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one"
329
330 # A removal on the other side.
331 fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00
332 fossil uv sync -v $syncXferSrv
333 test xfer-sync-uv-removal {$CODE == 0}
334 test_eq xfer-sync-uv-removal-arrived [sync_uv .rep.fossil two.txt] \
335 "removed [sync_uvtime 2026-01-04T00:00:00]"
336
337 # The same content with a newer time, first there and then here.
338 fossil uv touch one.txt -R srv.fossil --mtime 2026-01-05T00:00:00
339 fossil uv sync -v $syncXferSrv
340 test xfer-sync-uv-time-pulled {$CODE == 0 &&
341 [string first "UV-PULL-MTIME-ONLY: one.txt" $RESULT] >= 0}
342 test_eq xfer-sync-uv-time-pulled-value \
343 [lindex [sync_uv .rep.fossil one.txt] 1] \
344 [sync_uvtime 2026-01-05T00:00:00]
345 fossil uv touch one.txt --mtime 2026-01-06T00:00:00
346 fossil uv sync -v $syncXferSrv
347 test xfer-sync-uv-time-pushed {$CODE == 0 &&
348 [string first "UV-PUSH-MTIME-ONLY: one.txt" $RESULT] >= 0}
349 test_eq xfer-sync-uv-time-pushed-value \
350 [lindex [sync_uv srv.fossil one.txt] 1] \
351 [sync_uvtime 2026-01-06T00:00:00]
352 test_eq xfer-sync-uv-same-at-end [sync_uv srv.fossil one.txt] \
353 [sync_uv .rep.fossil one.txt]
354
355 # A user who may read and not write unversioned files is told so, and
356 # what was to be sent stays here.
357 set ::env(SCN_REPO) $syncXferSrv
358 set ::env(SCN_AUTH) 1
359 fossil sql -R srv.fossil \
360 "UPDATE user SET cap='o' WHERE login IN ('nobody','anonymous')"
361 fossil uv touch one.txt --mtime 2026-01-07T00:00:00
362 fossil_raw -seconds 120 uv sync -v http://xfersync.invalid/x \
363 --transport-command $syncXferWire
364 test xfer-sync-uv-pull-only {[string first "uv-pull-only" $RESULT] >= 0}
365 test_eq xfer-sync-uv-pull-only-not-sent \
366 [lindex [sync_uv srv.fossil one.txt] 1] \
367 [sync_uvtime 2026-01-06T00:00:00]
368
369 # The same for a file that the other side has never held.
370 fossil uv touch one.txt --mtime 2026-01-06T00:00:00
371 write_file three.txt "a file the other side will not take\n"
372 fossil uv add three.txt --mtime 2026-01-07T00:00:00
373 fossil_raw -seconds 120 uv sync -v http://xfersync.invalid/x \
374 --transport-command $syncXferWire
375 set syncXferSaid $RESULT
376 test_eq xfer-sync-uv-pull-only-new-not-sent [sync_uv srv.fossil three.txt] ""
377 test xfer-sync-uv-pull-only-new-said \
378 {[string first "uv-pull-only" $syncXferSaid] >= 0}
379 test xfer-sync-uv-pull-only-new-kept {[sync_uv .rep.fossil three.txt] ne ""}
380
381 # A revert from such a server still makes this side match it: the file
382 # the server never had goes, and nothing is said about pushing.
383 fossil_raw -seconds 120 uv revert http://xfersync.invalid/x \
384 --transport-command $syncXferWire
385 test xfer-sync-uv-pull-only-revert {$CODE == 0 &&
386 [string first "uv-pull-only" $RESULT] < 0}
387 test_eq xfer-sync-uv-pull-only-revert-removed [sync_uv .rep.fossil three.txt] ""
388 unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
389
390 ###############################################################################
391 # A project that was split off pulls from the project it came from only
392 # when it says that it means to.
393
394 file copy srv.fossil child2.fossil
395 fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)
396 VALUES('project-name','xfersync parent',now())"
397 file copy srv.fossil child.fossil
398 fossil_raw -input "y\n" detach child.fossil
399 test xfer-sync-detach {$CODE == 0}
400 test xfer-sync-detach-new-code {[sync_sql child.fossil "SELECT value
401 FROM config WHERE name='project-code'"] ne [sync_sql srv.fossil "SELECT
402 value FROM config WHERE name='project-code'"]}
403 sync_checkin a.txt "${syncXferText}more\n" xfersync-after-split
404 fossil push --private $syncXferSrv
405 test_eq xfer-sync-parent-has-new [sync_has srv.fossil xfersync-after-split] 1
406 fossil pull $syncXferSrv -R child.fossil -expectError
407 test xfer-sync-child-plain-pull-refused {$CODE != 0}
408 test_eq xfer-sync-child-plain-pull-nothing \
409 [sync_has child.fossil xfersync-after-split] 0
410 # The new check-in follows a private one, so it is private too.
411 fossil pull --from-parent-project $syncXferSrv -R child.fossil
412 test xfer-sync-child-parent-pull-public-only {$CODE == 0 &&
413 [sync_has child.fossil xfersync-after-split] == 0}
414 fossil pull --private --from-parent-project $syncXferSrv -R child.fossil
415 test xfer-sync-child-parent-pull {$CODE == 0}
416 test_eq xfer-sync-child-parent-pull-arrived \
417 [sync_has child.fossil xfersync-after-split] 1
418 sync_integrity xfer-sync-child-integrity child.fossil
419
420 # The same when the project it came from has no name.
421 fossil_raw -input "y\n" detach child2.fossil
422 fossil_raw pull --from-parent-project $syncXferSrv -R child2.fossil
423 test xfer-sync-unnamed-parent-pull {$CODE == 0}
424 test_eq xfer-sync-unnamed-parent-pull-arrived [sync_public child2.fossil] \
425 [sync_public srv.fossil]
426
427 sync_leave
428
429 ###############################################################################
430 # A clone made over the sync protocol. "fossil clone" of a file on the
431 # same machine copies the file and never speaks the protocol, so here a
432 # real client clones from a real server through
433 # standin/scenario-wire.tcl, which hands each request to "fossil http"
434 # on the server's repository.
435
436 sync_enter xfer-clone
437
438 # The server: several versions of one file, so that it stores deltas, an
439 # empty file, a branch, a tag, a wiki page and an unversioned file.
440 set syncCloneText ""
441 for {set syncCloneI 0} {$syncCloneI < 40} {incr syncCloneI} {
442 append syncCloneText "line $syncCloneI of a file with several versions\n"
443 }
444 write_file empty.txt ""
445 fossil add empty.txt
446 foreach syncCloneI {1 2 3 4 5} {
447 append syncCloneText "version $syncCloneI\n"
448 write_file a.txt $syncCloneText
449 if {$syncCloneI == 1} {fossil add a.txt}
450 fossil commit -m "xferclone-v$syncCloneI" --no-warnings
451 }
452 fossil branch new side trunk
453 fossil tag add marked trunk
454 write_file page.txt "a wiki page\n"
455 fossil wiki create ClonePage page.txt
456 write_file note.txt "an unversioned note\n"
457 fossil unversioned add note.txt
458 file copy .rep.fossil srv.fossil
459
460 set syncCloneWire [file join [pwd] wire.tcl]
461 file copy [file join $::testfiledir standin scenario-wire.tcl] $syncCloneWire
462 set syncCloneWire "\"[info nameofexecutable]\" \"$syncCloneWire\""
463 set ::env(SCN_EXE) $::fossilexe
464 set ::env(SCN_REPO) [file join [pwd] srv.fossil]
465 set ::env(SCN_FAULT) 0
466
467 # Clone the server into the repository file NAME, with any more
468 # arguments for "fossil clone".
469 #
470 proc sync_clone_wire {name args} {
471 global syncCloneWire
472 fossil_raw -seconds 120 clone http://xferclone.invalid/x $name \
473 --transport-command $syncCloneWire --no-open {*}$args
474 }
475
476 # What a repository holds: the artifacts with content, the timeline, the
477 # branches and tags, and the unversioned files.
478 #
479 proc sync_holds {repo} {
480 fossil sql -R $repo "SELECT group_concat(uuid, ' ') FROM (SELECT uuid
481 FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid);
482 SELECT group_concat(x, ' ') FROM (SELECT type || comment AS x
483 FROM event ORDER BY mtime, objid);
484 SELECT group_concat(x, ' ') FROM (SELECT tagname || tagtype AS x
485 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid AND tagname LIKE 'sym-%'
486 ORDER BY 1)"
487 return [string trim $::RESULT]
488 }
489 proc sync_uv_files {repo} {
490 fossil sql -R $repo "SELECT group_concat(name || '/' || hash, ' ')
491 FROM unversioned WHERE hash IS NOT NULL"
492 return [string trim $::RESULT]
493 }
494
495 set syncCloneWant [sync_holds srv.fossil]
496
497 ###############################################################################
498 # An ordinary clone holds what the server holds, and is sound.
499
500 sync_clone_wire c1.fossil
501 test xfer-clone {$CODE == 0}
502 test_eq xfer-clone-holds [sync_holds c1.fossil] $syncCloneWant
503 fossil test-integrity -R c1.fossil
504 test xfer-clone-integrity {$CODE == 0}
505 fossil sql -R c1.fossil "SELECT value FROM config WHERE name='project-code'"
506 set syncCloneCode [string trim $RESULT]
507 fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'"
508 test_eq xfer-clone-project-code $syncCloneCode [string trim $RESULT]
509
510 # The files of the newest and of the first check-in can be read from it.
511 fossil cat a.txt -R c1.fossil -r trunk
512 test_eq xfer-clone-newest-file [string trim $RESULT] \
513 [string trim $syncCloneText]
514 fossil cat empty.txt -R c1.fossil -r trunk
515 test_eq xfer-clone-empty-file $RESULT ""
516
517 # Unversioned files come only when they are asked for.
518 fossil sql -R c1.fossil "SELECT count(*) FROM sqlite_schema
519 WHERE name='unversioned'"
520 set syncCloneHasUv [string trim $RESULT]
521 test xfer-clone-without-unversioned \
522 {!$syncCloneHasUv || [sync_uv_files c1.fossil] eq ""}
523 sync_clone_wire c2.fossil --unversioned
524 test xfer-clone-unversioned {$CODE == 0}
525 test_eq xfer-clone-unversioned-files [sync_uv_files c2.fossil] \
526 [sync_uv_files srv.fossil]
527 test_eq xfer-clone-unversioned-holds [sync_holds c2.fossil] $syncCloneWant
528
529 # With small messages the clone takes many round trips and ends the same.
530 fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)
531 VALUES('max-download',2000,now())"
532 sync_clone_wire c3.fossil
533 test xfer-clone-small-replies {$CODE == 0}
534 test_eq xfer-clone-small-replies-holds [sync_holds c3.fossil] \
535 $syncCloneWant
536 fossil test-integrity -R c3.fossil
537 test xfer-clone-small-replies-integrity {$CODE == 0}
538 fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download'"
539
540 ###############################################################################
541 # A server that checks permissions refuses a clone to a user without the
542 # permission, and no repository is left behind.
543
544 set ::env(SCN_AUTH) 1
545 fossil sql -R srv.fossil \
546 "UPDATE user SET cap='o' WHERE login IN ('nobody','anonymous')"
547 sync_clone_wire c4.fossil
548 test xfer-clone-refused \
549 {$CODE != 0 && [string first "not authorized to clone" $RESULT] >= 0}
550 test xfer-clone-refused-leaves-nothing {![file exists c4.fossil]}
551 fossil sql -R srv.fossil \
552 "UPDATE user SET cap='go' WHERE login IN ('nobody','anonymous')"
553 sync_clone_wire c5.fossil
554 test xfer-clone-permitted {$CODE == 0}
555 test_eq xfer-clone-permitted-holds [sync_holds c5.fossil] $syncCloneWant
556
557 unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
558
559 sync_leave
560
561 ###############################################################################
562
563 if {![loopback_available]} {
564 unset ::env(FOSSIL_USER)
565 test_skip "the tests that run fossil server cannot start a server"
566 }
567 set server [test_start_server a.fossil stopArg]
568
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -4,12 +4,17 @@
44
# must not crash. There is no server: "fossil pull" and "fossil push"
55
# get standin/transport.sh as their --transport-command. It saves each
66
# request and answers with a reply that the test wrote, or with a bare
77
# timestamp, which ends the sync.
88
#
9
-# xfer-cards.test and xfer-server.test test the server side.
9
+# xfer-server.test tests the server side.
1010
#
11
+
12
+# These tests run only in a long pass: -assurance stress.
13
+if {[test_assurance] ne "stress"} {
14
+ test_skip "runs only with -assurance stress"
15
+}
1116
1217
require_no_open_checkout
1318
1419
if {$::tcl_platform(platform) eq "windows"} {
1520
test_skip "the stand-in for a server is a shell script"
@@ -45,10 +50,24 @@
4550
fossil_raw $verb http://localhost/x --once \
4651
--transport-command $xferclientWire {*}$args
4752
set xferclientCode $::CODE
4853
set xferclientOut $::RESULT
4954
}
55
+
56
+# Like xferclient_sync, for the server at URL.
57
+proc xferclient_sync_url {verb url replies args} {
58
+ global xferclientDir xferclientWire xferclientCode xferclientOut
59
+ file delete {*}[glob -nocomplain -directory $xferclientDir \
60
+ reply.* request.* count]
61
+ set number 0
62
+ foreach reply $replies {
63
+ write_file [file join $xferclientDir reply.[incr number]] $reply
64
+ }
65
+ fossil_raw $verb $url --once --transport-command $xferclientWire {*}$args
66
+ set xferclientCode $::CODE
67
+ set xferclientOut $::RESULT
68
+}
5069
5170
proc xferclient_run {verb reply args} {
5271
xferclient_sync $verb [list $reply] {*}$args
5372
}
5473
@@ -130,10 +149,62 @@
130149
xferclient_expect clock-behind pull \
131150
"# timestamp 2016-01-01T00:00:00 errors 0\n" 0 {} "time skew"
132151
xferclient_expect clock-ahead pull \
133152
"# timestamp 2036-01-01T00:00:00 errors 0\n" 0 {}
134153
xferclient_expect clock-unreadable pull "# timestamp garbage errors 0\n" 0 {}
154
+
155
+###############################################################################
156
+# Settings and options of the client that change what it sends.
157
+
158
+# With dont-push, a push is refused and a sync only pulls.
159
+fossil settings dont-push 1
160
+xferclient_sync push {}
161
+test xfer-client-dont-push {$xferclientCode != 0
162
+ && [string match "*pushing is prohibited*" $xferclientOut]
163
+ && [xferclient_requests] == 0}
164
+xferclient_sync sync {}
165
+test xfer-client-dont-push-sync {$xferclientCode == 0
166
+ && [string match "*\npull *" "\n[xferclient_request 1]"]
167
+ && ![string match "*\npush *" "\n[xferclient_request 1]"]}
168
+fossil settings dont-push 0
169
+
170
+# A repository with a public URL tells the server where it is.
171
+fossil settings email-url https://client.example
172
+fossil sql "REPLACE INTO config(name,value,mtime)
173
+ VALUES('baseurl:https://client.example',1,now())"
174
+xferclient_sync pull {}
175
+test xfer-client-client-url \
176
+ {[string match "*pragma client-url https://client.example\n*" \
177
+ [xferclient_request 1]]}
178
+fossil unset email-url
179
+
180
+# --from-parent-project needs the code of the parent project, and a code
181
+# that is the repository's own is not taken for a parent's.
182
+xferclient_sync pull {} --from-parent-project
183
+test xfer-client-no-parent-project {$xferclientCode != 0
184
+ && [string match "*no parent project*" $xferclientOut]
185
+ && [xferclient_requests] == 0}
186
+fossil sql "REPLACE INTO config(name,value,mtime) SELECT 'parent-project-code',
187
+ value, now() FROM config WHERE name='project-code'"
188
+xferclient_sync pull {} --from-parent-project
189
+test xfer-client-own-code-as-parent {$xferclientCode == 0
190
+ && [xferclient_requests] >= 1}
191
+# A repository with no project code of its own asks for the project of its
192
+# parent.
193
+fossil sql "SELECT value FROM config WHERE name='project-code'"
194
+set xferclientOwnCode [string trim $RESULT]
195
+set xferclientParentCode [string repeat 0123abcd 5]
196
+fossil sql "DELETE FROM config WHERE name='project-code';
197
+ REPLACE INTO config(name,value,mtime)
198
+ VALUES('parent-project-code','$xferclientParentCode',now())"
199
+xferclient_sync pull {} --from-parent-project
200
+test xfer-client-parent-of-project-without-code {$xferclientCode == 0
201
+ && [regexp -line "^pull \\S+ $xferclientParentCode\$" \
202
+ [xferclient_request 1]]}
203
+fossil sql "REPLACE INTO config(name,value,mtime)
204
+ VALUES('project-code','$xferclientOwnCode',now())"
205
+fossil sql "DELETE FROM config WHERE name='parent-project-code'"
135206
136207
###############################################################################
137208
# igot and gimme. What the client asks for, or sends, shows in its
138209
# second request.
139210
@@ -170,13 +241,12 @@
170241
xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \
171242
"unknown command"
172243
173244
###############################################################################
174245
# An igot card can say that an artifact is private. The client marks its
175
-# own copy private only in a sync of private content. In an ordinary
176
-# pull a server could previously make a public check-in private, after
177
-# which the client sent it to nobody.
246
+# own copy private only in a sync of private content, so in an ordinary
247
+# pull a server cannot make a public check-in private.
178248
179249
fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT max(objid) FROM event\
180250
WHERE type='ci')"
181251
set xferclientCkin [string trim $::RESULT]
182252
xferclient_run pull "igot $xferclientCkin 1\n"
@@ -204,13 +274,13 @@
204274
xferclient_run pull "# nothing\n"
205275
test xfer-client-private-phantom-not-asked-for-again \
206276
{[string first "gimme $xferclientPhantom" [xferclient_request 1]] < 0}
207277
208278
###############################################################################
209
-# Artifacts are accepted only in a sync that pulls. A server could
210
-# previously add one to the client in answer to a push. The hash is that of
211
-# the five bytes "hello" under SHA3-256.
279
+# Artifacts are accepted only in a sync that pulls, so a server cannot add
280
+# one to the client in answer to a push. The hash is that of the five
281
+# bytes "hello" under SHA3-256.
212282
213283
set xferclientHello \
214284
3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392
215285
fossil sql "SELECT count(*) FROM blob"
216286
set xferclientBlobs [string trim $::RESULT]
@@ -276,10 +346,535 @@
276346
"unknown command"
277347
xferclient_expect uvigot-bad-hash pull \
278348
"uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
279349
xferclient_expect uvigot-bad-name pull \
280350
"uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
351
+
352
+###############################################################################
353
+# Each card that has a fixed number of words, and each word that selects a
354
+# card, decides alone whether the card is acted on. A card of the wrong
355
+# number of words, or with a first word that has the length of a card name
356
+# but is not it, is an unknown command and ends the sync with an error.
357
+
358
+foreach {xferclientName xferclientCard} [list \
359
+ gimme-no-argument "gimme\n" \
360
+ gimme-two-arguments "gimme $xferclientAbsent x\n" \
361
+ config-no-size "config /project\n" \
362
+ config-extra-argument "config /project 0 x\n" \
363
+ clone-seqno-no-argument "clone_seqno\n" \
364
+ clone-seqno-two-numbers "clone_seqno 1 2\n" \
365
+ clone-seqno-other-word "clone_seqnx 1\n" \
366
+ message-no-text "message\n" \
367
+ message-two-words "message a b\n" \
368
+ message-other-word "messagf hi\n" \
369
+ error-two-words "error a b\n" \
370
+] {
371
+ xferclient_expect mcdc-shape-$xferclientName pull $xferclientCard 1 {} \
372
+ "unknown command"
373
+}
374
+
375
+# An igot card names the artifact and may add the flag 1 for private. Any
376
+# other third word, of any length, is not that flag: the artifact is
377
+# public and the client asks for it.
378
+set xferclientFlagHash(other-digit) [string repeat 1111222233334444 4]
379
+set xferclientFlagHash(long-flag) [string repeat 5555666677778888 4]
380
+set xferclientFlagHash(letter) [string repeat 9999aaaabbbbcccc 4]
381
+foreach {xferclientName xferclientFlag} {
382
+ other-digit 2
383
+ long-flag 11
384
+ letter x
385
+} {
386
+ set xferclientHash $xferclientFlagHash($xferclientName)
387
+ xferclient_run pull "igot $xferclientHash $xferclientFlag\n"
388
+ test xfer-client-mcdc-igot-flag-$xferclientName \
389
+ {$xferclientCode == 0
390
+ && [string first "gimme $xferclientHash" [xferclient_request 2]] >= 0}
391
+}
392
+
393
+# A message in a push that does not begin with "pull only" is shown, and an
394
+# empty message is not.
395
+xferclient_expect mcdc-message-in-push push "message hi\n" 0 {} \
396
+ "Server says: hi"
397
+xferclient_expect mcdc-message-empty pull "message \\0\n" 0 {} \
398
+ "!Server says"
399
+
400
+# A pragma with the wrong number of words, or with a name of the length
401
+# of a known one, does nothing.
402
+foreach {xferclientName xferclientCard} [list \
403
+ ci-lock-fail-two-words "pragma ci-lock-fail someone\n" \
404
+ ci-lock-fail-four-words "pragma ci-lock-fail someone 1700000000 x\n" \
405
+] {
406
+ xferclient_expect mcdc-pragma-$xferclientName pull $xferclientCard 0 {} \
407
+ "!Parent check-in locked"
408
+}
409
+xferclient_expect mcdc-ci-lock-fail-future pull \
410
+ "pragma ci-lock-fail someone 99999999999\n" 0 {} \
411
+ "Parent check-in locked by someone\n" "!ago"
412
+
413
+# Links from the server are kept only with --share-links, for a URL of the
414
+# http or https kind and a time above zero.
415
+foreach {xferclientName xferclientCard xferclientKept} [list \
416
+ http "pragma link http://example.org/a {} 1790000000\n" 1 \
417
+ https "pragma link https://example.org/b {} 1790000000\n" 1 \
418
+ ssh "pragma link ssh://example.org/c {} 1790000000\n" 0 \
419
+ ftp "pragma link ftp://example.org/h {} 1790000000\n" 0 \
420
+ no-scheme "pragma link example.org/i {} 1790000000\n" 0 \
421
+ zero-time "pragma link http://example.org/e {} 0\n" 0 \
422
+ four-words "pragma link http://example.org/f {}\n" 0 \
423
+ other-name "pragma lonk http://example.org/g {} 1790000000\n" 0 \
424
+] {
425
+ fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
426
+ xferclient_run pull $xferclientCard --share-links
427
+ fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'"
428
+ test_eq xfer-client-mcdc-link-$xferclientName \
429
+ "$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
430
+}
431
+fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
432
+
433
+###############################################################################
434
+# A "private" card makes the next file private. A client that does not sync
435
+# private content ignores that file, whatever its content; one that does
436
+# keeps it and marks it private.
437
+
438
+write_file world.txt "world\n"
439
+fossil sha3sum world.txt
440
+set xferclientWorld [lindex $RESULT 0]
441
+fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
442
+set xferclientBefore [string trim $RESULT]
443
+xferclient_run pull "private\nfile $xferclientWorld 6\nworld\n"
444
+fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
445
+test xfer-client-mcdc-private-file-ignored \
446
+ {$xferclientCode == 0 && [string trim $RESULT] == $xferclientBefore}
447
+xferclient_run pull "private\ncfile $xferclientWorld 6 0\n"
448
+fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
449
+test xfer-client-mcdc-private-cfile-ignored \
450
+ {$xferclientCode == 0 && [string trim $RESULT] == $xferclientBefore}
451
+xferclient_run pull "private\nfile $xferclientWorld 6\nworld\n" --private
452
+fossil sql "SELECT count(*) FROM blob b, private p
453
+ WHERE b.rid=p.rid AND b.uuid='$xferclientWorld' AND b.size>=0"
454
+test xfer-client-mcdc-private-file-kept-in-private-pull \
455
+ {$xferclientCode == 0 && [string trim $RESULT] == 1}
456
+
457
+###############################################################################
458
+# How many rounds a sync makes.
459
+
460
+# A pull asks for every phantom in every round, so the cases below start
461
+# with none.
462
+proc xferclient_no_phantoms {name} {
463
+ fossil sql "DELETE FROM private WHERE rid IN (SELECT rid FROM phantom);
464
+ DELETE FROM unclustered WHERE rid IN (SELECT rid FROM phantom);
465
+ DELETE FROM blob WHERE rid IN (SELECT rid FROM phantom);
466
+ DELETE FROM phantom"
467
+ fossil sql "SELECT count(*) FROM phantom"
468
+ test_eq xfer-client-mcdc-no-phantoms-$name [string trim $::RESULT] 0
469
+}
470
+xferclient_no_phantoms before-resync
471
+
472
+# A resync asks for the catalog of the server in its first request only. A
473
+# pull asks for the clusters of the server in the third request, because it
474
+# asks for artifacts in it, and not in the first two.
475
+set xferclientPhantomB [string repeat 0a1b2c3d4e5f6a7b 4]
476
+set xferclientPhantomA [string repeat f0e1d2c3b4a59687 4]
477
+xferclient_sync pull \
478
+ [list "igot $xferclientPhantomA\n" "igot $xferclientPhantomB\n"] --verily
479
+test xfer-client-mcdc-resync-catalog {$xferclientCode == 0
480
+ && [xferclient_requests] == 3
481
+ && [string first "pragma send-catalog" [xferclient_request 1]] >= 0
482
+ && [string first "pragma send-catalog" [xferclient_request 2]] < 0
483
+ && [string first "pragma send-catalog" [xferclient_request 3]] < 0}
484
+test xfer-client-mcdc-req-clusters-third-request {
485
+ [string first "pragma req-clusters" [xferclient_request 1]] < 0
486
+ && [string first "pragma req-clusters" [xferclient_request 2]] < 0
487
+ && [string first "pragma req-clusters" [xferclient_request 3]] >= 0}
488
+
489
+# A sync that sends a file in each round and is asked for one again in the
490
+# third asks for no artifact there, so it does not ask for clusters.
491
+xferclient_no_phantoms before-sync
492
+xferclient_sync sync [list "gimme $xferclientFile\n" "gimme $xferclientFile\n"]
493
+test xfer-client-mcdc-no-req-clusters-without-phantoms {$xferclientCode == 0
494
+ && [xferclient_requests] >= 3
495
+ && [string first "pragma req-clusters" [xferclient_request 3]] < 0}
496
+
497
+# A server that asks for a private artifact in a push that is not of private
498
+# content is told that the artifact exists and is private, and the client
499
+# goes on for a second round. It goes on only once: a server that asks
500
+# again in the second round gets the same answer and no third round.
501
+write_file private.txt "a private file\n"
502
+fossil add private.txt
503
+fossil commit -m private --private --no-warnings
504
+fossil sql "SELECT uuid FROM blob WHERE rid IN (SELECT rid FROM private)
505
+ AND size>0 LIMIT 1"
506
+set xferclientPrivate [string trim $RESULT]
507
+set xferclientAsk "${SERVER_VERSION_CARD}gimme $xferclientPrivate\n"
508
+xferclient_sync push [list $xferclientAsk $xferclientAsk $xferclientAsk]
509
+test xfer-client-mcdc-private-igot-one-more-round {$xferclientCode == 0
510
+ && [xferclient_requests] == 2
511
+ && [string first "igot $xferclientPrivate 1" [xferclient_request 2]] >= 0
512
+ && [string first "file $xferclientPrivate" [xferclient_request 2]] < 0}
513
+xferclient_sync push {}
514
+test xfer-client-mcdc-no-private-igot-one-round {$xferclientCode == 0
515
+ && [xferclient_requests] == 1}
516
+
517
+# A pull asks for at most 200 of the artifacts that a server has announced
518
+# in one request.
519
+xferclient_no_phantoms before-limit
520
+set xferclientMany ""
521
+for {set xferclientI 0} {$xferclientI < 250} {incr xferclientI} {
522
+ append xferclientMany "igot [format %064x [expr {$xferclientI + 1}]]\n"
523
+}
524
+xferclient_run pull $xferclientMany
525
+test xfer-client-mcdc-asks-for-200 {$xferclientCode == 0
526
+ && [llength [regexp -all -inline {gimme } [xferclient_request 2]]] == 200}
527
+xferclient_no_phantoms after-limit
528
+
529
+# A reply with no card at all, only an empty line, is accepted.
530
+xferclient_expect mcdc-reply-empty-line pull "\n" 0 {-v}
531
+
532
+# The repository records the address of a server that is not on the local
533
+# host, for the http and https kinds of address and not for others.
534
+foreach {xferclientName xferclientUrl xferclientKept} {
535
+ https-other https://example.org/x 1
536
+ http-other http://example.org/y 1
537
+ local http://localhost/z 0
538
+} {
539
+ fossil sql "DELETE FROM config WHERE name GLOB 'syncwith:*'"
540
+ xferclient_sync_url pull $xferclientUrl {}
541
+ fossil sql "SELECT count(*) FROM config WHERE name GLOB 'syncwith:*'"
542
+ test_eq xfer-client-mcdc-syncwith-$xferclientName \
543
+ "$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
544
+}
545
+fossil sql "DELETE FROM config WHERE name GLOB 'syncwith:*'"
546
+
547
+###############################################################################
548
+# Unversioned files: the server announces a file of that name with a card,
549
+# and the client asks for it. Each word of the card decides alone whether it
550
+# is accepted.
551
+
552
+set xferclientUvCards [list \
553
+ uvigot-ok "uvigot new.txt 2000000000 $xferclientAbcHash 3\n" gimme \
554
+ uvigot-delete "uvigot new.txt 2000000000 - 0\n" quiet \
555
+ bad-name "uvigot ../x 2000000000 $xferclientAbcHash 3\n" refused \
556
+ bad-mtime "uvigot new.txt notint $xferclientAbcHash 3\n" refused \
557
+ bad-size "uvigot new.txt 2000000000 $xferclientAbcHash x\n" refused \
558
+ hash-too-short "uvigot new.txt 2000000000 abc 3\n" refused \
559
+ hash-one-letter "uvigot new.txt 2000000000 x 3\n" refused \
560
+ four-words "uvigot new.txt 2000000000 $xferclientAbcHash\n" refused \
561
+ six-words "uvigot new.txt 2000000000 $xferclientAbcHash 3 x\n" refused \
562
+ short-name "uvigo new.txt 2000000000 $xferclientAbcHash 3\n" refused \
563
+ other-name "uvigoz new.txt 2000000000 $xferclientAbcHash 3\n" refused \
564
+]
565
+# "gimme": the client asks for the file. "quiet": the card is accepted and
566
+# nothing is asked. "refused": the card is an unknown command.
567
+foreach {xferclientName xferclientCard xferclientOutcome} $xferclientUvCards {
568
+ xferclient_run sync $xferclientCard -u
569
+ set xferclientAsked [expr {
570
+ [string first "uvgimme new.txt" [xferclient_request 2]] >= 0}]
571
+ set xferclientRefused [expr {$xferclientCode == 1
572
+ && [string first "unknown command" $xferclientOut] >= 0}]
573
+ test xfer-client-mcdc-uv-$xferclientName {
574
+ ($xferclientOutcome eq "gimme" && $xferclientCode == 0 && $xferclientAsked)
575
+ || ($xferclientOutcome eq "quiet" && $xferclientCode == 0
576
+ && !$xferclientAsked)
577
+ || ($xferclientOutcome eq "refused" && $xferclientRefused)}
578
+}
579
+
580
+# The server announces a file in every round and sends none: the client
581
+# asks for it in three rounds and then stops.
582
+set xferclientUvAgain "uvigot new.txt 2000000000 $xferclientAbcHash 3\n"
583
+xferclient_sync sync [list $xferclientUvAgain $xferclientUvAgain \
584
+ $xferclientUvAgain $xferclientUvAgain $xferclientUvAgain] -u
585
+test xfer-client-mcdc-uv-asks-in-three-rounds {$xferclientCode == 0
586
+ && [xferclient_requests] == 3}
587
+# While a file arrives in each round and another is announced, the client
588
+# goes on asking, and stops after the reply that announces the last one.
589
+proc xferclient_uvfile {name} {
590
+ return "uvfile $name 2000000000 $::xferclientAbcHash 3 0\nabc\n"
591
+}
592
+proc xferclient_uvigot {name} {
593
+ return "uvigot $name 2000000000 $::xferclientAbcHash 3\n"
594
+}
595
+xferclient_sync sync [list [xferclient_uvigot n1.txt] \
596
+ "[xferclient_uvfile n1.txt][xferclient_uvigot n2.txt]" \
597
+ "[xferclient_uvfile n2.txt][xferclient_uvigot n3.txt]" \
598
+ "[xferclient_uvfile n3.txt][xferclient_uvigot n4.txt]" \
599
+ "[xferclient_uvfile n4.txt][xferclient_uvigot n5.txt]" \
600
+ "[xferclient_uvfile n5.txt][xferclient_uvigot n6.txt]"] -u
601
+test xfer-client-mcdc-uv-goes-on-while-files-arrive {$xferclientCode == 0
602
+ && [xferclient_requests] == 7}
603
+
604
+# A server that takes unversioned content is sent every file that it has not
605
+# announced, whole.
606
+xferclient_sync sync [list "pragma uv-push-ok\n"] -u
607
+test xfer-client-mcdc-uv-push-sends-file {$xferclientCode == 0
608
+ && [string first "uvfile note.txt " [xferclient_request 2]] >= 0
609
+ && [string first "uvigot" [xferclient_request 2]] < 0}
610
+
611
+# A server that takes no unversioned content, and a client with none to
612
+# send, makes no warning.
613
+fossil sql "DELETE FROM unversioned"
614
+xferclient_expect mcdc-uv-pull-only-nothing-to-send sync \
615
+ "pragma uv-pull-only\n" 0 {-u} "!unversioned"
616
+
617
+###############################################################################
618
+# A repository that cannot be written to can pull from a server that has
619
+# nothing new. It does not record the address of the server.
620
+
621
+set xferclientMode [file attributes .rep.fossil -permissions]
622
+file attributes .rep.fossil -permissions 0444
623
+xferclient_sync_url pull http://example.org/readonly {}
624
+file attributes .rep.fossil -permissions $xferclientMode
625
+fossil sql "SELECT count(*) FROM config WHERE name GLOB 'syncwith:*'"
626
+test_eq xfer-client-mcdc-pull-into-read-only \
627
+ "$xferclientCode [xferclient_requests] [string trim $RESULT]" "0 1 0"
628
+
629
+###############################################################################
630
+# Clones. The stand-in answers a clone as it answers a pull, so each clone
631
+# here gets the replies that the test wrote and then bare timestamps.
632
+
633
+fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT min(objid) FROM event
634
+ WHERE type='ci')"
635
+set xferclientFirst [string trim $RESULT]
636
+fossil artifact $xferclientFirst first-manifest.out
637
+set xferclientManifest [read_file first-manifest.out]
638
+set xferclientPush "push $xferclientOwnCode $xferclientOwnCode\n"
639
+
640
+# Clone into clone.fossil from a server that gives the replies REPLIES.
641
+# Sets xferclientCode and xferclientOut as xferclient_sync does.
642
+proc xferclient_clone {replies} {
643
+ global xferclientDir xferclientWire xferclientCode xferclientOut
644
+ file delete clone.fossil
645
+ file delete {*}[glob -nocomplain -directory $xferclientDir \
646
+ reply.* request.* count]
647
+ set number 0
648
+ foreach reply $replies {
649
+ write_file [file join $xferclientDir reply.[incr number]] $reply
650
+ }
651
+ fossil_raw clone http://localhost/x clone.fossil --no-open \
652
+ --transport-command $xferclientWire
653
+ set xferclientCode $::CODE
654
+ set xferclientOut $::RESULT
655
+}
656
+
657
+# The number of the artifacts HASHES that clone.fossil holds.
658
+proc xferclient_clone_holds {hashes} {
659
+ fossil sql -R clone.fossil "SELECT count(*) FROM blob WHERE size>=0
660
+ AND uuid IN ('[join $hashes ',']')"
661
+ return [string trim $::RESULT]
662
+}
663
+
664
+# A server of the first version of the protocol lists what it has in
665
+# "igot" cards and sends each artifact, in a "file" card, when it is asked
666
+# for it. The clone asks in every round and never asks for clusters.
667
+xferclient_clone [list \
668
+ "${xferclientPush}igot $xferclientFirst\nigot $xferclientFile\n" \
669
+ "file $xferclientFirst [string length $xferclientManifest]\n\
670
+$xferclientManifest" \
671
+ "file $xferclientFile 12\nhello world\n"]
672
+test xfer-client-mcdc-clone-by-igot {$xferclientCode == 0
673
+ && [xferclient_requests] == 4
674
+ && [string first "gimme $xferclientFirst" [xferclient_request 2]] >= 0
675
+ && [string first "gimme $xferclientFile" [xferclient_request 3]] >= 0
676
+ && [string first "pragma req-clusters" [xferclient_request 3]] < 0}
677
+test_eq xfer-client-mcdc-clone-by-igot-holds \
678
+ [xferclient_clone_holds [list $xferclientFirst $xferclientFile]] 2
679
+fossil sql -R clone.fossil "SELECT value FROM config WHERE name='project-code'"
680
+test_eq xfer-client-mcdc-clone-project-code [string trim $RESULT] \
681
+ $xferclientOwnCode
682
+
683
+# The card that gives a clone its project code has three words, the third
684
+# a hash. Any other card that begins with "push" ends the clone with an
685
+# error and leaves no repository.
686
+foreach {xferclientName xferclientCard} [list \
687
+ two-words "push $xferclientOwnCode\n" \
688
+ not-a-hash "push $xferclientOwnCode nothash\n" \
689
+] {
690
+ xferclient_clone [list $xferclientCard]
691
+ test xfer-client-mcdc-clone-push-$xferclientName {$xferclientCode == 1
692
+ && [string first "unknown command" $xferclientOut] >= 0
693
+ && ![file exists clone.fossil]}
694
+}
695
+
696
+# An error in the first reply ends the clone, unless it says that the
697
+# login failed or that the client is not authorized: the first request of
698
+# a clone has no login card, so those are expected and the clone goes on.
699
+foreach {xferclientName xferclientError xferclientGoesOn} {
700
+ other-error {something\sfailed} 0
701
+ login-failed {login\sfailed} 1
702
+ not-authorized {not\sauthorized\sto\sclone} 1
703
+} {
704
+ xferclient_clone [list "${xferclientPush}error $xferclientError\n"]
705
+ test xfer-client-mcdc-clone-first-error-$xferclientName {
706
+ $xferclientGoesOn
707
+ ? ($xferclientCode == 0 && [xferclient_requests] == 2
708
+ && [file exists clone.fossil])
709
+ : ($xferclientCode == 1
710
+ && [string first "Error: something failed" $xferclientOut] >= 0
711
+ && ![file exists clone.fossil])}
712
+}
713
+
714
+# A clone goes on asking while the server says that it has more to send
715
+# and something arrives, here an unversioned file. It stops after a reply
716
+# in which nothing arrives.
717
+xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
718
+ "[xferclient_uvfile cloned.txt]clone_seqno 3\n$xferclientPush" \
719
+ "clone_seqno 4\n$xferclientPush"]
720
+test xfer-client-mcdc-clone-goes-on-while-content-arrives \
721
+ {$xferclientCode == 0 && [xferclient_requests] == 3
722
+ && [string first "clone 3 3" [xferclient_request 3]] >= 0}
723
+fossil unversioned cat cloned.txt -R clone.fossil
724
+test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc
725
+xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
726
+ "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"]
727
+test xfer-client-mcdc-clone-stops-when-nothing-arrives \
728
+ {$xferclientCode == 0 && [xferclient_requests] == 2}
729
+file delete clone.fossil
730
+
731
+###############################################################################
732
+# What a sync with -v says at its end about the server. A server that
733
+# could not be reached is named as the URL names it, with no address. The
734
+# URLs here have no host; the one for ssh is given standin/log-args.sh as
735
+# its ssh command, which exits at once.
736
+
737
+fossil_raw pull -v --once --proxy off http:///x
738
+test xfer-client-mcdc-remote-no-host {$CODE == 1
739
+ && [string first "Pull done," $RESULT] >= 0
740
+ && [string first "remote: \n" $RESULT] >= 0}
741
+set xferclientSsh \
742
+ [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]]
743
+set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt]
744
+fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x
745
+test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1
746
+ && [file exists $::env(ARGS_LOG)]
747
+ && [string first "Pull done," $RESULT] >= 0
748
+ && [string first "remote: \n" $RESULT] >= 0}
749
+unset ::env(ARGS_LOG)
750
+
751
+###############################################################################
752
+# What shows only when the client speaks HTTP. The server is made here: it
753
+# answers request N with item N of the list xferclientHttpReplies, or with
754
+# a bare timestamp where that is empty, and keeps the header and the cards
755
+# of each request in the list xferclientHttpRequests.
756
+
757
+proc xferclient_http_accept {chan address port} {
758
+ fconfigure $chan -translation binary -blocking 0
759
+ set ::xferclientHttpBuf($chan) ""
760
+ fileevent $chan readable [list xferclient_http_read $chan]
761
+}
762
+proc xferclient_http_read {chan} {
763
+ global xferclientHttpBuf xferclientHttpRequests xferclientHttpReplies
764
+ append xferclientHttpBuf($chan) [read $chan]
765
+ set request $xferclientHttpBuf($chan)
766
+ set end [string first "\r\n\r\n" $request]
767
+ set length 0
768
+ regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
769
+ if {![eof $chan] &&
770
+ ($end < 0 || [string length $request] < $end + 4 + $length)} {
771
+ return
772
+ }
773
+ unset xferclientHttpBuf($chan)
774
+ fileevent $chan readable {}
775
+ fconfigure $chan -blocking 1
776
+ # The cards follow four bytes of size when they are compressed.
777
+ set header [string range $request 0 $end+1]
778
+ set cards [string range $request $end+4 end]
779
+ catch {set cards [zlib decompress [string range $cards 4 end]]}
780
+ set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]]
781
+ lappend xferclientHttpRequests [list $header $cards]
782
+ if {$reply eq ""} {
783
+ set reply "# timestamp [clock format [clock seconds] -gmt 1 \
784
+ -format %Y-%m-%dT%H:%M:%S] errors 0\n"
785
+ }
786
+ catch {
787
+ puts -nonewline $chan "HTTP/1.0 200 OK\r\nContent-Type:\
788
+ application/x-fossil-uncompressed\r\nContent-Length:\
789
+ [string length $reply]\r\n\r\n$reply"
790
+ close $chan
791
+ }
792
+}
793
+
794
+# Run fossil with the arguments ARGS while the server gives the replies
795
+# REPLIES. Sets xferclientCode and xferclientOut as xferclient_sync does.
796
+proc xferclient_http_run {replies args} {
797
+ global xferclientHttpReplies xferclientHttpRequests
798
+ global xferclientCode xferclientOut
799
+ set xferclientHttpReplies $replies
800
+ set xferclientHttpRequests {}
801
+ fossil_raw -seconds 60 {*}$args
802
+ set xferclientCode $::CODE
803
+ set xferclientOut $::RESULT
804
+}
805
+
806
+if {[loopback_available]} {
807
+ set xferclientHttpServer \
808
+ [socket -server xferclient_http_accept -myaddr 127.0.0.1 0]
809
+ set xferclientHttpPort [lindex [fconfigure $xferclientHttpServer -sockname] 2]
810
+
811
+ # The login card goes in front of the cards of a request. Once the
812
+ # server has said that it is of version 2.27 or later and was built at or
813
+ # after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The
814
+ # second request shows where the client puts it.
815
+ foreach {xferclientName xferclientVersion xferclientWhere} {
816
+ older-version "22699 20260101 120000" cards
817
+ day-before "22700 20250726 235959" cards
818
+ second-before "22700 20250727 110459" cards
819
+ same-second "22700 20250727 110500" cookie
820
+ day-after "22700 20250728 0" cookie
821
+ } {
822
+ xferclient_no_phantoms login-card-$xferclientName
823
+ xferclient_http_run [list \
824
+ "pragma server-version $xferclientVersion\nigot $xferclientAbsent\n"] \
825
+ pull http://tester:[email protected]:$xferclientHttpPort/x --once \
826
+ --proxy off --no-http-compression
827
+ lassign [lindex $xferclientHttpRequests 1] xferclientHeader xferclientCards
828
+ set xferclientInCookie [regexp -nocase -line \
829
+ {^Cookie: x-f-l-c=login.tester} $xferclientHeader]
830
+ set xferclientInCards [regexp -line {^login tester } $xferclientCards]
831
+ test_eq xfer-client-mcdc-login-card-$xferclientName \
832
+ "$xferclientCode [llength $xferclientHttpRequests]\
833
+ $xferclientInCookie $xferclientInCards" \
834
+ "0 2 [expr {$xferclientWhere eq "cookie" ? "1 0" : "0 1"}]"
835
+ }
836
+ xferclient_no_phantoms after-login-card
837
+
838
+ # A sync with -v names the server at its end, and adds the address that
839
+ # it connected to when that is not what the URL has.
840
+ xferclient_http_run {} pull -v --once --proxy off \
841
+ http://127.0.0.1:$xferclientHttpPort/x
842
+ test xfer-client-mcdc-remote-by-address {$xferclientCode == 0
843
+ && [string first "remote: 127.0.0.1\n" $xferclientOut] >= 0}
844
+ xferclient_http_run {} pull -v --once --proxy off \
845
+ http://localhost:$xferclientHttpPort/x
846
+ test xfer-client-mcdc-remote-by-name {$xferclientCode == 0
847
+ && [string first "remote: localhost (127.0.0.1)\n" $xferclientOut] >= 0}
848
+
849
+ # A commit pushes when it is done. A server that says the user may not
850
+ # write does not make the commit fail: the user is told that the check-in
851
+ # is kept here. Any other error from the server is reported as it is.
852
+ fossil update $xferclientCkin
853
+ fossil settings proxy off
854
+ fossil settings autosync on
855
+ fossil remote http://127.0.0.1:$xferclientHttpPort/auto
856
+ foreach {xferclientName xferclientError xferclientSaid} {
857
+ not-authorized {not\sauthorized\sto\swrite}
858
+ {"not authorized to push the changes" "!Autosync failed" "!Error:"}
859
+ other-error {something\sfailed}
860
+ {"Error: something failed" "Autosync failed" "!not authorized to push"}
861
+ } {
862
+ write_file auto-$xferclientName.txt "$xferclientName\n"
863
+ fossil add auto-$xferclientName.txt
864
+ xferclient_http_run [list "" "error $xferclientError\n"] \
865
+ commit -m auto-$xferclientName --no-warnings --allow-fork
866
+ fossil sql "SELECT count(*) FROM event WHERE comment='auto-$xferclientName'"
867
+ test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0
868
+ && [string trim $RESULT] == 1
869
+ && [llength $xferclientHttpRequests] == 2
870
+ && [holds_strings $xferclientOut $xferclientSaid]}
871
+ }
872
+ fossil remote off
873
+ fossil settings autosync off
874
+ close $xferclientHttpServer
875
+}
281876
282877
###############################################################################
283878
284879
unset ::env(TRANSPORT_DIR)
285880
test_cleanup
286881
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -4,12 +4,17 @@
4 # must not crash. There is no server: "fossil pull" and "fossil push"
5 # get standin/transport.sh as their --transport-command. It saves each
6 # request and answers with a reply that the test wrote, or with a bare
7 # timestamp, which ends the sync.
8 #
9 # xfer-cards.test and xfer-server.test test the server side.
10 #
 
 
 
 
 
11
12 require_no_open_checkout
13
14 if {$::tcl_platform(platform) eq "windows"} {
15 test_skip "the stand-in for a server is a shell script"
@@ -45,10 +50,24 @@
45 fossil_raw $verb http://localhost/x --once \
46 --transport-command $xferclientWire {*}$args
47 set xferclientCode $::CODE
48 set xferclientOut $::RESULT
49 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
51 proc xferclient_run {verb reply args} {
52 xferclient_sync $verb [list $reply] {*}$args
53 }
54
@@ -130,10 +149,62 @@
130 xferclient_expect clock-behind pull \
131 "# timestamp 2016-01-01T00:00:00 errors 0\n" 0 {} "time skew"
132 xferclient_expect clock-ahead pull \
133 "# timestamp 2036-01-01T00:00:00 errors 0\n" 0 {}
134 xferclient_expect clock-unreadable pull "# timestamp garbage errors 0\n" 0 {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
136 ###############################################################################
137 # igot and gimme. What the client asks for, or sends, shows in its
138 # second request.
139
@@ -170,13 +241,12 @@
170 xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \
171 "unknown command"
172
173 ###############################################################################
174 # An igot card can say that an artifact is private. The client marks its
175 # own copy private only in a sync of private content. In an ordinary
176 # pull a server could previously make a public check-in private, after
177 # which the client sent it to nobody.
178
179 fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT max(objid) FROM event\
180 WHERE type='ci')"
181 set xferclientCkin [string trim $::RESULT]
182 xferclient_run pull "igot $xferclientCkin 1\n"
@@ -204,13 +274,13 @@
204 xferclient_run pull "# nothing\n"
205 test xfer-client-private-phantom-not-asked-for-again \
206 {[string first "gimme $xferclientPhantom" [xferclient_request 1]] < 0}
207
208 ###############################################################################
209 # Artifacts are accepted only in a sync that pulls. A server could
210 # previously add one to the client in answer to a push. The hash is that of
211 # the five bytes "hello" under SHA3-256.
212
213 set xferclientHello \
214 3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392
215 fossil sql "SELECT count(*) FROM blob"
216 set xferclientBlobs [string trim $::RESULT]
@@ -276,10 +346,535 @@
276 "unknown command"
277 xferclient_expect uvigot-bad-hash pull \
278 "uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
279 xferclient_expect uvigot-bad-name pull \
280 "uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
282 ###############################################################################
283
284 unset ::env(TRANSPORT_DIR)
285 test_cleanup
286
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -4,12 +4,17 @@
4 # must not crash. There is no server: "fossil pull" and "fossil push"
5 # get standin/transport.sh as their --transport-command. It saves each
6 # request and answers with a reply that the test wrote, or with a bare
7 # timestamp, which ends the sync.
8 #
9 # xfer-server.test tests the server side.
10 #
11
12 # These tests run only in a long pass: -assurance stress.
13 if {[test_assurance] ne "stress"} {
14 test_skip "runs only with -assurance stress"
15 }
16
17 require_no_open_checkout
18
19 if {$::tcl_platform(platform) eq "windows"} {
20 test_skip "the stand-in for a server is a shell script"
@@ -45,10 +50,24 @@
50 fossil_raw $verb http://localhost/x --once \
51 --transport-command $xferclientWire {*}$args
52 set xferclientCode $::CODE
53 set xferclientOut $::RESULT
54 }
55
56 # Like xferclient_sync, for the server at URL.
57 proc xferclient_sync_url {verb url replies args} {
58 global xferclientDir xferclientWire xferclientCode xferclientOut
59 file delete {*}[glob -nocomplain -directory $xferclientDir \
60 reply.* request.* count]
61 set number 0
62 foreach reply $replies {
63 write_file [file join $xferclientDir reply.[incr number]] $reply
64 }
65 fossil_raw $verb $url --once --transport-command $xferclientWire {*}$args
66 set xferclientCode $::CODE
67 set xferclientOut $::RESULT
68 }
69
70 proc xferclient_run {verb reply args} {
71 xferclient_sync $verb [list $reply] {*}$args
72 }
73
@@ -130,10 +149,62 @@
149 xferclient_expect clock-behind pull \
150 "# timestamp 2016-01-01T00:00:00 errors 0\n" 0 {} "time skew"
151 xferclient_expect clock-ahead pull \
152 "# timestamp 2036-01-01T00:00:00 errors 0\n" 0 {}
153 xferclient_expect clock-unreadable pull "# timestamp garbage errors 0\n" 0 {}
154
155 ###############################################################################
156 # Settings and options of the client that change what it sends.
157
158 # With dont-push, a push is refused and a sync only pulls.
159 fossil settings dont-push 1
160 xferclient_sync push {}
161 test xfer-client-dont-push {$xferclientCode != 0
162 && [string match "*pushing is prohibited*" $xferclientOut]
163 && [xferclient_requests] == 0}
164 xferclient_sync sync {}
165 test xfer-client-dont-push-sync {$xferclientCode == 0
166 && [string match "*\npull *" "\n[xferclient_request 1]"]
167 && ![string match "*\npush *" "\n[xferclient_request 1]"]}
168 fossil settings dont-push 0
169
170 # A repository with a public URL tells the server where it is.
171 fossil settings email-url https://client.example
172 fossil sql "REPLACE INTO config(name,value,mtime)
173 VALUES('baseurl:https://client.example',1,now())"
174 xferclient_sync pull {}
175 test xfer-client-client-url \
176 {[string match "*pragma client-url https://client.example\n*" \
177 [xferclient_request 1]]}
178 fossil unset email-url
179
180 # --from-parent-project needs the code of the parent project, and a code
181 # that is the repository's own is not taken for a parent's.
182 xferclient_sync pull {} --from-parent-project
183 test xfer-client-no-parent-project {$xferclientCode != 0
184 && [string match "*no parent project*" $xferclientOut]
185 && [xferclient_requests] == 0}
186 fossil sql "REPLACE INTO config(name,value,mtime) SELECT 'parent-project-code',
187 value, now() FROM config WHERE name='project-code'"
188 xferclient_sync pull {} --from-parent-project
189 test xfer-client-own-code-as-parent {$xferclientCode == 0
190 && [xferclient_requests] >= 1}
191 # A repository with no project code of its own asks for the project of its
192 # parent.
193 fossil sql "SELECT value FROM config WHERE name='project-code'"
194 set xferclientOwnCode [string trim $RESULT]
195 set xferclientParentCode [string repeat 0123abcd 5]
196 fossil sql "DELETE FROM config WHERE name='project-code';
197 REPLACE INTO config(name,value,mtime)
198 VALUES('parent-project-code','$xferclientParentCode',now())"
199 xferclient_sync pull {} --from-parent-project
200 test xfer-client-parent-of-project-without-code {$xferclientCode == 0
201 && [regexp -line "^pull \\S+ $xferclientParentCode\$" \
202 [xferclient_request 1]]}
203 fossil sql "REPLACE INTO config(name,value,mtime)
204 VALUES('project-code','$xferclientOwnCode',now())"
205 fossil sql "DELETE FROM config WHERE name='parent-project-code'"
206
207 ###############################################################################
208 # igot and gimme. What the client asks for, or sends, shows in its
209 # second request.
210
@@ -170,13 +241,12 @@
241 xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \
242 "unknown command"
243
244 ###############################################################################
245 # An igot card can say that an artifact is private. The client marks its
246 # own copy private only in a sync of private content, so in an ordinary
247 # pull a server cannot make a public check-in private.
 
248
249 fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT max(objid) FROM event\
250 WHERE type='ci')"
251 set xferclientCkin [string trim $::RESULT]
252 xferclient_run pull "igot $xferclientCkin 1\n"
@@ -204,13 +274,13 @@
274 xferclient_run pull "# nothing\n"
275 test xfer-client-private-phantom-not-asked-for-again \
276 {[string first "gimme $xferclientPhantom" [xferclient_request 1]] < 0}
277
278 ###############################################################################
279 # Artifacts are accepted only in a sync that pulls, so a server cannot add
280 # one to the client in answer to a push. The hash is that of the five
281 # bytes "hello" under SHA3-256.
282
283 set xferclientHello \
284 3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392
285 fossil sql "SELECT count(*) FROM blob"
286 set xferclientBlobs [string trim $::RESULT]
@@ -276,10 +346,535 @@
346 "unknown command"
347 xferclient_expect uvigot-bad-hash pull \
348 "uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
349 xferclient_expect uvigot-bad-name pull \
350 "uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
351
352 ###############################################################################
353 # Each card that has a fixed number of words, and each word that selects a
354 # card, decides alone whether the card is acted on. A card of the wrong
355 # number of words, or with a first word that has the length of a card name
356 # but is not it, is an unknown command and ends the sync with an error.
357
358 foreach {xferclientName xferclientCard} [list \
359 gimme-no-argument "gimme\n" \
360 gimme-two-arguments "gimme $xferclientAbsent x\n" \
361 config-no-size "config /project\n" \
362 config-extra-argument "config /project 0 x\n" \
363 clone-seqno-no-argument "clone_seqno\n" \
364 clone-seqno-two-numbers "clone_seqno 1 2\n" \
365 clone-seqno-other-word "clone_seqnx 1\n" \
366 message-no-text "message\n" \
367 message-two-words "message a b\n" \
368 message-other-word "messagf hi\n" \
369 error-two-words "error a b\n" \
370 ] {
371 xferclient_expect mcdc-shape-$xferclientName pull $xferclientCard 1 {} \
372 "unknown command"
373 }
374
375 # An igot card names the artifact and may add the flag 1 for private. Any
376 # other third word, of any length, is not that flag: the artifact is
377 # public and the client asks for it.
378 set xferclientFlagHash(other-digit) [string repeat 1111222233334444 4]
379 set xferclientFlagHash(long-flag) [string repeat 5555666677778888 4]
380 set xferclientFlagHash(letter) [string repeat 9999aaaabbbbcccc 4]
381 foreach {xferclientName xferclientFlag} {
382 other-digit 2
383 long-flag 11
384 letter x
385 } {
386 set xferclientHash $xferclientFlagHash($xferclientName)
387 xferclient_run pull "igot $xferclientHash $xferclientFlag\n"
388 test xfer-client-mcdc-igot-flag-$xferclientName \
389 {$xferclientCode == 0
390 && [string first "gimme $xferclientHash" [xferclient_request 2]] >= 0}
391 }
392
393 # A message in a push that does not begin with "pull only" is shown, and an
394 # empty message is not.
395 xferclient_expect mcdc-message-in-push push "message hi\n" 0 {} \
396 "Server says: hi"
397 xferclient_expect mcdc-message-empty pull "message \\0\n" 0 {} \
398 "!Server says"
399
400 # A pragma with the wrong number of words, or with a name of the length
401 # of a known one, does nothing.
402 foreach {xferclientName xferclientCard} [list \
403 ci-lock-fail-two-words "pragma ci-lock-fail someone\n" \
404 ci-lock-fail-four-words "pragma ci-lock-fail someone 1700000000 x\n" \
405 ] {
406 xferclient_expect mcdc-pragma-$xferclientName pull $xferclientCard 0 {} \
407 "!Parent check-in locked"
408 }
409 xferclient_expect mcdc-ci-lock-fail-future pull \
410 "pragma ci-lock-fail someone 99999999999\n" 0 {} \
411 "Parent check-in locked by someone\n" "!ago"
412
413 # Links from the server are kept only with --share-links, for a URL of the
414 # http or https kind and a time above zero.
415 foreach {xferclientName xferclientCard xferclientKept} [list \
416 http "pragma link http://example.org/a {} 1790000000\n" 1 \
417 https "pragma link https://example.org/b {} 1790000000\n" 1 \
418 ssh "pragma link ssh://example.org/c {} 1790000000\n" 0 \
419 ftp "pragma link ftp://example.org/h {} 1790000000\n" 0 \
420 no-scheme "pragma link example.org/i {} 1790000000\n" 0 \
421 zero-time "pragma link http://example.org/e {} 0\n" 0 \
422 four-words "pragma link http://example.org/f {}\n" 0 \
423 other-name "pragma lonk http://example.org/g {} 1790000000\n" 0 \
424 ] {
425 fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
426 xferclient_run pull $xferclientCard --share-links
427 fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'"
428 test_eq xfer-client-mcdc-link-$xferclientName \
429 "$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
430 }
431 fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
432
433 ###############################################################################
434 # A "private" card makes the next file private. A client that does not sync
435 # private content ignores that file, whatever its content; one that does
436 # keeps it and marks it private.
437
438 write_file world.txt "world\n"
439 fossil sha3sum world.txt
440 set xferclientWorld [lindex $RESULT 0]
441 fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
442 set xferclientBefore [string trim $RESULT]
443 xferclient_run pull "private\nfile $xferclientWorld 6\nworld\n"
444 fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
445 test xfer-client-mcdc-private-file-ignored \
446 {$xferclientCode == 0 && [string trim $RESULT] == $xferclientBefore}
447 xferclient_run pull "private\ncfile $xferclientWorld 6 0\n"
448 fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientWorld'"
449 test xfer-client-mcdc-private-cfile-ignored \
450 {$xferclientCode == 0 && [string trim $RESULT] == $xferclientBefore}
451 xferclient_run pull "private\nfile $xferclientWorld 6\nworld\n" --private
452 fossil sql "SELECT count(*) FROM blob b, private p
453 WHERE b.rid=p.rid AND b.uuid='$xferclientWorld' AND b.size>=0"
454 test xfer-client-mcdc-private-file-kept-in-private-pull \
455 {$xferclientCode == 0 && [string trim $RESULT] == 1}
456
457 ###############################################################################
458 # How many rounds a sync makes.
459
460 # A pull asks for every phantom in every round, so the cases below start
461 # with none.
462 proc xferclient_no_phantoms {name} {
463 fossil sql "DELETE FROM private WHERE rid IN (SELECT rid FROM phantom);
464 DELETE FROM unclustered WHERE rid IN (SELECT rid FROM phantom);
465 DELETE FROM blob WHERE rid IN (SELECT rid FROM phantom);
466 DELETE FROM phantom"
467 fossil sql "SELECT count(*) FROM phantom"
468 test_eq xfer-client-mcdc-no-phantoms-$name [string trim $::RESULT] 0
469 }
470 xferclient_no_phantoms before-resync
471
472 # A resync asks for the catalog of the server in its first request only. A
473 # pull asks for the clusters of the server in the third request, because it
474 # asks for artifacts in it, and not in the first two.
475 set xferclientPhantomB [string repeat 0a1b2c3d4e5f6a7b 4]
476 set xferclientPhantomA [string repeat f0e1d2c3b4a59687 4]
477 xferclient_sync pull \
478 [list "igot $xferclientPhantomA\n" "igot $xferclientPhantomB\n"] --verily
479 test xfer-client-mcdc-resync-catalog {$xferclientCode == 0
480 && [xferclient_requests] == 3
481 && [string first "pragma send-catalog" [xferclient_request 1]] >= 0
482 && [string first "pragma send-catalog" [xferclient_request 2]] < 0
483 && [string first "pragma send-catalog" [xferclient_request 3]] < 0}
484 test xfer-client-mcdc-req-clusters-third-request {
485 [string first "pragma req-clusters" [xferclient_request 1]] < 0
486 && [string first "pragma req-clusters" [xferclient_request 2]] < 0
487 && [string first "pragma req-clusters" [xferclient_request 3]] >= 0}
488
489 # A sync that sends a file in each round and is asked for one again in the
490 # third asks for no artifact there, so it does not ask for clusters.
491 xferclient_no_phantoms before-sync
492 xferclient_sync sync [list "gimme $xferclientFile\n" "gimme $xferclientFile\n"]
493 test xfer-client-mcdc-no-req-clusters-without-phantoms {$xferclientCode == 0
494 && [xferclient_requests] >= 3
495 && [string first "pragma req-clusters" [xferclient_request 3]] < 0}
496
497 # A server that asks for a private artifact in a push that is not of private
498 # content is told that the artifact exists and is private, and the client
499 # goes on for a second round. It goes on only once: a server that asks
500 # again in the second round gets the same answer and no third round.
501 write_file private.txt "a private file\n"
502 fossil add private.txt
503 fossil commit -m private --private --no-warnings
504 fossil sql "SELECT uuid FROM blob WHERE rid IN (SELECT rid FROM private)
505 AND size>0 LIMIT 1"
506 set xferclientPrivate [string trim $RESULT]
507 set xferclientAsk "${SERVER_VERSION_CARD}gimme $xferclientPrivate\n"
508 xferclient_sync push [list $xferclientAsk $xferclientAsk $xferclientAsk]
509 test xfer-client-mcdc-private-igot-one-more-round {$xferclientCode == 0
510 && [xferclient_requests] == 2
511 && [string first "igot $xferclientPrivate 1" [xferclient_request 2]] >= 0
512 && [string first "file $xferclientPrivate" [xferclient_request 2]] < 0}
513 xferclient_sync push {}
514 test xfer-client-mcdc-no-private-igot-one-round {$xferclientCode == 0
515 && [xferclient_requests] == 1}
516
517 # A pull asks for at most 200 of the artifacts that a server has announced
518 # in one request.
519 xferclient_no_phantoms before-limit
520 set xferclientMany ""
521 for {set xferclientI 0} {$xferclientI < 250} {incr xferclientI} {
522 append xferclientMany "igot [format %064x [expr {$xferclientI + 1}]]\n"
523 }
524 xferclient_run pull $xferclientMany
525 test xfer-client-mcdc-asks-for-200 {$xferclientCode == 0
526 && [llength [regexp -all -inline {gimme } [xferclient_request 2]]] == 200}
527 xferclient_no_phantoms after-limit
528
529 # A reply with no card at all, only an empty line, is accepted.
530 xferclient_expect mcdc-reply-empty-line pull "\n" 0 {-v}
531
532 # The repository records the address of a server that is not on the local
533 # host, for the http and https kinds of address and not for others.
534 foreach {xferclientName xferclientUrl xferclientKept} {
535 https-other https://example.org/x 1
536 http-other http://example.org/y 1
537 local http://localhost/z 0
538 } {
539 fossil sql "DELETE FROM config WHERE name GLOB 'syncwith:*'"
540 xferclient_sync_url pull $xferclientUrl {}
541 fossil sql "SELECT count(*) FROM config WHERE name GLOB 'syncwith:*'"
542 test_eq xfer-client-mcdc-syncwith-$xferclientName \
543 "$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
544 }
545 fossil sql "DELETE FROM config WHERE name GLOB 'syncwith:*'"
546
547 ###############################################################################
548 # Unversioned files: the server announces a file of that name with a card,
549 # and the client asks for it. Each word of the card decides alone whether it
550 # is accepted.
551
552 set xferclientUvCards [list \
553 uvigot-ok "uvigot new.txt 2000000000 $xferclientAbcHash 3\n" gimme \
554 uvigot-delete "uvigot new.txt 2000000000 - 0\n" quiet \
555 bad-name "uvigot ../x 2000000000 $xferclientAbcHash 3\n" refused \
556 bad-mtime "uvigot new.txt notint $xferclientAbcHash 3\n" refused \
557 bad-size "uvigot new.txt 2000000000 $xferclientAbcHash x\n" refused \
558 hash-too-short "uvigot new.txt 2000000000 abc 3\n" refused \
559 hash-one-letter "uvigot new.txt 2000000000 x 3\n" refused \
560 four-words "uvigot new.txt 2000000000 $xferclientAbcHash\n" refused \
561 six-words "uvigot new.txt 2000000000 $xferclientAbcHash 3 x\n" refused \
562 short-name "uvigo new.txt 2000000000 $xferclientAbcHash 3\n" refused \
563 other-name "uvigoz new.txt 2000000000 $xferclientAbcHash 3\n" refused \
564 ]
565 # "gimme": the client asks for the file. "quiet": the card is accepted and
566 # nothing is asked. "refused": the card is an unknown command.
567 foreach {xferclientName xferclientCard xferclientOutcome} $xferclientUvCards {
568 xferclient_run sync $xferclientCard -u
569 set xferclientAsked [expr {
570 [string first "uvgimme new.txt" [xferclient_request 2]] >= 0}]
571 set xferclientRefused [expr {$xferclientCode == 1
572 && [string first "unknown command" $xferclientOut] >= 0}]
573 test xfer-client-mcdc-uv-$xferclientName {
574 ($xferclientOutcome eq "gimme" && $xferclientCode == 0 && $xferclientAsked)
575 || ($xferclientOutcome eq "quiet" && $xferclientCode == 0
576 && !$xferclientAsked)
577 || ($xferclientOutcome eq "refused" && $xferclientRefused)}
578 }
579
580 # The server announces a file in every round and sends none: the client
581 # asks for it in three rounds and then stops.
582 set xferclientUvAgain "uvigot new.txt 2000000000 $xferclientAbcHash 3\n"
583 xferclient_sync sync [list $xferclientUvAgain $xferclientUvAgain \
584 $xferclientUvAgain $xferclientUvAgain $xferclientUvAgain] -u
585 test xfer-client-mcdc-uv-asks-in-three-rounds {$xferclientCode == 0
586 && [xferclient_requests] == 3}
587 # While a file arrives in each round and another is announced, the client
588 # goes on asking, and stops after the reply that announces the last one.
589 proc xferclient_uvfile {name} {
590 return "uvfile $name 2000000000 $::xferclientAbcHash 3 0\nabc\n"
591 }
592 proc xferclient_uvigot {name} {
593 return "uvigot $name 2000000000 $::xferclientAbcHash 3\n"
594 }
595 xferclient_sync sync [list [xferclient_uvigot n1.txt] \
596 "[xferclient_uvfile n1.txt][xferclient_uvigot n2.txt]" \
597 "[xferclient_uvfile n2.txt][xferclient_uvigot n3.txt]" \
598 "[xferclient_uvfile n3.txt][xferclient_uvigot n4.txt]" \
599 "[xferclient_uvfile n4.txt][xferclient_uvigot n5.txt]" \
600 "[xferclient_uvfile n5.txt][xferclient_uvigot n6.txt]"] -u
601 test xfer-client-mcdc-uv-goes-on-while-files-arrive {$xferclientCode == 0
602 && [xferclient_requests] == 7}
603
604 # A server that takes unversioned content is sent every file that it has not
605 # announced, whole.
606 xferclient_sync sync [list "pragma uv-push-ok\n"] -u
607 test xfer-client-mcdc-uv-push-sends-file {$xferclientCode == 0
608 && [string first "uvfile note.txt " [xferclient_request 2]] >= 0
609 && [string first "uvigot" [xferclient_request 2]] < 0}
610
611 # A server that takes no unversioned content, and a client with none to
612 # send, makes no warning.
613 fossil sql "DELETE FROM unversioned"
614 xferclient_expect mcdc-uv-pull-only-nothing-to-send sync \
615 "pragma uv-pull-only\n" 0 {-u} "!unversioned"
616
617 ###############################################################################
618 # A repository that cannot be written to can pull from a server that has
619 # nothing new. It does not record the address of the server.
620
621 set xferclientMode [file attributes .rep.fossil -permissions]
622 file attributes .rep.fossil -permissions 0444
623 xferclient_sync_url pull http://example.org/readonly {}
624 file attributes .rep.fossil -permissions $xferclientMode
625 fossil sql "SELECT count(*) FROM config WHERE name GLOB 'syncwith:*'"
626 test_eq xfer-client-mcdc-pull-into-read-only \
627 "$xferclientCode [xferclient_requests] [string trim $RESULT]" "0 1 0"
628
629 ###############################################################################
630 # Clones. The stand-in answers a clone as it answers a pull, so each clone
631 # here gets the replies that the test wrote and then bare timestamps.
632
633 fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT min(objid) FROM event
634 WHERE type='ci')"
635 set xferclientFirst [string trim $RESULT]
636 fossil artifact $xferclientFirst first-manifest.out
637 set xferclientManifest [read_file first-manifest.out]
638 set xferclientPush "push $xferclientOwnCode $xferclientOwnCode\n"
639
640 # Clone into clone.fossil from a server that gives the replies REPLIES.
641 # Sets xferclientCode and xferclientOut as xferclient_sync does.
642 proc xferclient_clone {replies} {
643 global xferclientDir xferclientWire xferclientCode xferclientOut
644 file delete clone.fossil
645 file delete {*}[glob -nocomplain -directory $xferclientDir \
646 reply.* request.* count]
647 set number 0
648 foreach reply $replies {
649 write_file [file join $xferclientDir reply.[incr number]] $reply
650 }
651 fossil_raw clone http://localhost/x clone.fossil --no-open \
652 --transport-command $xferclientWire
653 set xferclientCode $::CODE
654 set xferclientOut $::RESULT
655 }
656
657 # The number of the artifacts HASHES that clone.fossil holds.
658 proc xferclient_clone_holds {hashes} {
659 fossil sql -R clone.fossil "SELECT count(*) FROM blob WHERE size>=0
660 AND uuid IN ('[join $hashes ',']')"
661 return [string trim $::RESULT]
662 }
663
664 # A server of the first version of the protocol lists what it has in
665 # "igot" cards and sends each artifact, in a "file" card, when it is asked
666 # for it. The clone asks in every round and never asks for clusters.
667 xferclient_clone [list \
668 "${xferclientPush}igot $xferclientFirst\nigot $xferclientFile\n" \
669 "file $xferclientFirst [string length $xferclientManifest]\n\
670 $xferclientManifest" \
671 "file $xferclientFile 12\nhello world\n"]
672 test xfer-client-mcdc-clone-by-igot {$xferclientCode == 0
673 && [xferclient_requests] == 4
674 && [string first "gimme $xferclientFirst" [xferclient_request 2]] >= 0
675 && [string first "gimme $xferclientFile" [xferclient_request 3]] >= 0
676 && [string first "pragma req-clusters" [xferclient_request 3]] < 0}
677 test_eq xfer-client-mcdc-clone-by-igot-holds \
678 [xferclient_clone_holds [list $xferclientFirst $xferclientFile]] 2
679 fossil sql -R clone.fossil "SELECT value FROM config WHERE name='project-code'"
680 test_eq xfer-client-mcdc-clone-project-code [string trim $RESULT] \
681 $xferclientOwnCode
682
683 # The card that gives a clone its project code has three words, the third
684 # a hash. Any other card that begins with "push" ends the clone with an
685 # error and leaves no repository.
686 foreach {xferclientName xferclientCard} [list \
687 two-words "push $xferclientOwnCode\n" \
688 not-a-hash "push $xferclientOwnCode nothash\n" \
689 ] {
690 xferclient_clone [list $xferclientCard]
691 test xfer-client-mcdc-clone-push-$xferclientName {$xferclientCode == 1
692 && [string first "unknown command" $xferclientOut] >= 0
693 && ![file exists clone.fossil]}
694 }
695
696 # An error in the first reply ends the clone, unless it says that the
697 # login failed or that the client is not authorized: the first request of
698 # a clone has no login card, so those are expected and the clone goes on.
699 foreach {xferclientName xferclientError xferclientGoesOn} {
700 other-error {something\sfailed} 0
701 login-failed {login\sfailed} 1
702 not-authorized {not\sauthorized\sto\sclone} 1
703 } {
704 xferclient_clone [list "${xferclientPush}error $xferclientError\n"]
705 test xfer-client-mcdc-clone-first-error-$xferclientName {
706 $xferclientGoesOn
707 ? ($xferclientCode == 0 && [xferclient_requests] == 2
708 && [file exists clone.fossil])
709 : ($xferclientCode == 1
710 && [string first "Error: something failed" $xferclientOut] >= 0
711 && ![file exists clone.fossil])}
712 }
713
714 # A clone goes on asking while the server says that it has more to send
715 # and something arrives, here an unversioned file. It stops after a reply
716 # in which nothing arrives.
717 xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
718 "[xferclient_uvfile cloned.txt]clone_seqno 3\n$xferclientPush" \
719 "clone_seqno 4\n$xferclientPush"]
720 test xfer-client-mcdc-clone-goes-on-while-content-arrives \
721 {$xferclientCode == 0 && [xferclient_requests] == 3
722 && [string first "clone 3 3" [xferclient_request 3]] >= 0}
723 fossil unversioned cat cloned.txt -R clone.fossil
724 test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc
725 xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
726 "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"]
727 test xfer-client-mcdc-clone-stops-when-nothing-arrives \
728 {$xferclientCode == 0 && [xferclient_requests] == 2}
729 file delete clone.fossil
730
731 ###############################################################################
732 # What a sync with -v says at its end about the server. A server that
733 # could not be reached is named as the URL names it, with no address. The
734 # URLs here have no host; the one for ssh is given standin/log-args.sh as
735 # its ssh command, which exits at once.
736
737 fossil_raw pull -v --once --proxy off http:///x
738 test xfer-client-mcdc-remote-no-host {$CODE == 1
739 && [string first "Pull done," $RESULT] >= 0
740 && [string first "remote: \n" $RESULT] >= 0}
741 set xferclientSsh \
742 [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]]
743 set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt]
744 fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x
745 test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1
746 && [file exists $::env(ARGS_LOG)]
747 && [string first "Pull done," $RESULT] >= 0
748 && [string first "remote: \n" $RESULT] >= 0}
749 unset ::env(ARGS_LOG)
750
751 ###############################################################################
752 # What shows only when the client speaks HTTP. The server is made here: it
753 # answers request N with item N of the list xferclientHttpReplies, or with
754 # a bare timestamp where that is empty, and keeps the header and the cards
755 # of each request in the list xferclientHttpRequests.
756
757 proc xferclient_http_accept {chan address port} {
758 fconfigure $chan -translation binary -blocking 0
759 set ::xferclientHttpBuf($chan) ""
760 fileevent $chan readable [list xferclient_http_read $chan]
761 }
762 proc xferclient_http_read {chan} {
763 global xferclientHttpBuf xferclientHttpRequests xferclientHttpReplies
764 append xferclientHttpBuf($chan) [read $chan]
765 set request $xferclientHttpBuf($chan)
766 set end [string first "\r\n\r\n" $request]
767 set length 0
768 regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
769 if {![eof $chan] &&
770 ($end < 0 || [string length $request] < $end + 4 + $length)} {
771 return
772 }
773 unset xferclientHttpBuf($chan)
774 fileevent $chan readable {}
775 fconfigure $chan -blocking 1
776 # The cards follow four bytes of size when they are compressed.
777 set header [string range $request 0 $end+1]
778 set cards [string range $request $end+4 end]
779 catch {set cards [zlib decompress [string range $cards 4 end]]}
780 set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]]
781 lappend xferclientHttpRequests [list $header $cards]
782 if {$reply eq ""} {
783 set reply "# timestamp [clock format [clock seconds] -gmt 1 \
784 -format %Y-%m-%dT%H:%M:%S] errors 0\n"
785 }
786 catch {
787 puts -nonewline $chan "HTTP/1.0 200 OK\r\nContent-Type:\
788 application/x-fossil-uncompressed\r\nContent-Length:\
789 [string length $reply]\r\n\r\n$reply"
790 close $chan
791 }
792 }
793
794 # Run fossil with the arguments ARGS while the server gives the replies
795 # REPLIES. Sets xferclientCode and xferclientOut as xferclient_sync does.
796 proc xferclient_http_run {replies args} {
797 global xferclientHttpReplies xferclientHttpRequests
798 global xferclientCode xferclientOut
799 set xferclientHttpReplies $replies
800 set xferclientHttpRequests {}
801 fossil_raw -seconds 60 {*}$args
802 set xferclientCode $::CODE
803 set xferclientOut $::RESULT
804 }
805
806 if {[loopback_available]} {
807 set xferclientHttpServer \
808 [socket -server xferclient_http_accept -myaddr 127.0.0.1 0]
809 set xferclientHttpPort [lindex [fconfigure $xferclientHttpServer -sockname] 2]
810
811 # The login card goes in front of the cards of a request. Once the
812 # server has said that it is of version 2.27 or later and was built at or
813 # after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The
814 # second request shows where the client puts it.
815 foreach {xferclientName xferclientVersion xferclientWhere} {
816 older-version "22699 20260101 120000" cards
817 day-before "22700 20250726 235959" cards
818 second-before "22700 20250727 110459" cards
819 same-second "22700 20250727 110500" cookie
820 day-after "22700 20250728 0" cookie
821 } {
822 xferclient_no_phantoms login-card-$xferclientName
823 xferclient_http_run [list \
824 "pragma server-version $xferclientVersion\nigot $xferclientAbsent\n"] \
825 pull http://tester:[email protected]:$xferclientHttpPort/x --once \
826 --proxy off --no-http-compression
827 lassign [lindex $xferclientHttpRequests 1] xferclientHeader xferclientCards
828 set xferclientInCookie [regexp -nocase -line \
829 {^Cookie: x-f-l-c=login.tester} $xferclientHeader]
830 set xferclientInCards [regexp -line {^login tester } $xferclientCards]
831 test_eq xfer-client-mcdc-login-card-$xferclientName \
832 "$xferclientCode [llength $xferclientHttpRequests]\
833 $xferclientInCookie $xferclientInCards" \
834 "0 2 [expr {$xferclientWhere eq "cookie" ? "1 0" : "0 1"}]"
835 }
836 xferclient_no_phantoms after-login-card
837
838 # A sync with -v names the server at its end, and adds the address that
839 # it connected to when that is not what the URL has.
840 xferclient_http_run {} pull -v --once --proxy off \
841 http://127.0.0.1:$xferclientHttpPort/x
842 test xfer-client-mcdc-remote-by-address {$xferclientCode == 0
843 && [string first "remote: 127.0.0.1\n" $xferclientOut] >= 0}
844 xferclient_http_run {} pull -v --once --proxy off \
845 http://localhost:$xferclientHttpPort/x
846 test xfer-client-mcdc-remote-by-name {$xferclientCode == 0
847 && [string first "remote: localhost (127.0.0.1)\n" $xferclientOut] >= 0}
848
849 # A commit pushes when it is done. A server that says the user may not
850 # write does not make the commit fail: the user is told that the check-in
851 # is kept here. Any other error from the server is reported as it is.
852 fossil update $xferclientCkin
853 fossil settings proxy off
854 fossil settings autosync on
855 fossil remote http://127.0.0.1:$xferclientHttpPort/auto
856 foreach {xferclientName xferclientError xferclientSaid} {
857 not-authorized {not\sauthorized\sto\swrite}
858 {"not authorized to push the changes" "!Autosync failed" "!Error:"}
859 other-error {something\sfailed}
860 {"Error: something failed" "Autosync failed" "!not authorized to push"}
861 } {
862 write_file auto-$xferclientName.txt "$xferclientName\n"
863 fossil add auto-$xferclientName.txt
864 xferclient_http_run [list "" "error $xferclientError\n"] \
865 commit -m auto-$xferclientName --no-warnings --allow-fork
866 fossil sql "SELECT count(*) FROM event WHERE comment='auto-$xferclientName'"
867 test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0
868 && [string trim $RESULT] == 1
869 && [llength $xferclientHttpRequests] == 2
870 && [holds_strings $xferclientOut $xferclientSaid]}
871 }
872 fossil remote off
873 fossil settings autosync off
874 close $xferclientHttpServer
875 }
876
877 ###############################################################################
878
879 unset ::env(TRANSPORT_DIR)
880 test_cleanup
881
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -1,15 +1,20 @@
11
#
22
# Each kind of card and pragma of the sync protocol, sent to the server
33
# side through "fossil test-xfer", with and without valid card
44
# permissions. The server must give the documented answer and must not
5
-# crash. xfer-cards.test has the cards with content.
5
+# crash. The cards with content are in the sections at the end.
66
#
77
# "fossil test-xfer" treats a login card as a grant of the Read, Write,
88
# Private and Admin permissions. A message without a login card runs
99
# with the permissions of the user "nobody", which these tests set.
1010
#
11
+
12
+# These tests run only in a long pass: -assurance stress.
13
+if {[test_assurance] ne "stress"} {
14
+ test_skip "runs only with -assurance stress"
15
+}
1116
1217
require_no_open_checkout
1318
1419
test_setup
1520
@@ -196,10 +201,32 @@
196201
xferserver_expect write-client-url \
197202
"${xferserverPush}pragma client-url http://example.org/x\n" "errors 0"
198203
test xfer-server-write-client-url-recorded \
199204
{[xferserver_count \
200205
"config WHERE name GLOB 'syncfrom:*example.org*'"] == 1}
206
+# A client URL that is not http or https is ignored and the request goes
207
+# on; it is not read as a path on the server.
208
+foreach {xferserverName xferserverUrl} {ftp ftp://example.org/y path /} {
209
+ xferserver_expect write-client-url-$xferserverName \
210
+ "${xferserverPush}pragma client-url $xferserverUrl\n" \
211
+ "!unknown repository" "errors 0"
212
+}
213
+
214
+# A first word that has the length of a card name and is not it selects no
215
+# card. A pragma with a name of the length of a known one that is not it
216
+# does nothing.
217
+foreach {xferserverName xferserverBody} [list \
218
+ pull-other-word "pulx x $xferserverPcode\n" \
219
+ reqconfig-other-word "reqconfih /project\n" \
220
+] {
221
+ xferserver_expect bad-$xferserverName $xferserverBody \
222
+ {error bad\scommand:} "!config " "!igot "
223
+}
224
+xferserver_expect write-pragma-other-word \
225
+ "${xferserverPush}pragma client-urx http://example.net/w\n" "errors 0"
226
+test xfer-server-write-pragma-other-word-not-recorded \
227
+ {[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0}
201228
202229
###############################################################################
203230
# With a login card: private content, configuration, clone and locks.
204231
205232
xferserver_caps ""
@@ -239,10 +266,51 @@
239266
}
240267
xferserver_expect login-config-roundtrip \
241268
"$xferserverLogin$xferserverPush$xferserverCards" "errors 0"
242269
xferserver_expect login-config-negative-size \
243270
"${xferserverLogin}config /project -5\n" {error bad\scommand:}
271
+
272
+# A value in a config card for a table must be a string or blob literal,
273
+# an integer or NULL. A card with any other value is ignored, and the
274
+# request goes on.
275
+proc xferserver_config_user {content} {
276
+ global xferserverLogin xferserverPush
277
+ return "$xferserverLogin${xferserverPush}config /user\
278
+ [string length $content]\n$content\n"
279
+}
280
+foreach {xferserverName xferserverValue} {
281
+ word x column pw blob-not-hex X'zz' blob-odd X'abc'
282
+} {
283
+ xferserver_expect config-value-$xferserverName [xferserver_config_user \
284
+ "1262304000 'cfgbad$xferserverName' info $xferserverValue"] \
285
+ "!Database error" "errors 0"
286
+}
287
+test_eq xfer-server-config-value-ignored \
288
+ [xferserver_count "user WHERE login GLOB 'cfgbad*'"] 0
289
+foreach {xferserverName xferserverValue} {
290
+ string 'text' integer 7 null NULL blob X'00ff' empty-blob X''
291
+} {
292
+ xferserver_expect config-value-$xferserverName [xferserver_config_user \
293
+ "1262304000 'cfgok$xferserverName' info $xferserverValue"] "errors 0"
294
+}
295
+test_eq xfer-server-config-value-stored \
296
+ [xferserver_count "user WHERE login GLOB 'cfgok*'"] 5
297
+
298
+# A hash with a zero byte inside is not a hash. Each card that names an
299
+# artifact by hash refuses it, and nothing is stored under a short hash.
300
+set xferserverZeroHash "ceafb\000[string repeat a 58]"
301
+foreach {xferserverName xferserverCard xferserverWant} [list \
302
+ igot "igot $xferserverZeroHash\n" {error bad\scommand:} \
303
+ gimme "gimme $xferserverZeroHash\n" {error bad\scommand:} \
304
+ file "file $xferserverZeroHash 3\nabc\n" "error malformed" \
305
+] {
306
+ xferserver_expect hash-zero-byte-$xferserverName \
307
+ "$xferserverLogin$xferserverPush$xferserverCard" \
308
+ "!Database error" $xferserverWant
309
+}
310
+test_eq xfer-server-hash-zero-byte-nothing-stored \
311
+ [xferserver_count "blob WHERE length(uuid)<40"] 0
244312
245313
# Clone, in each version of the protocol. A login card to test-xfer does
246314
# not grant the Clone permission, so "nobody" is given it and these
247315
# messages have no login card.
248316
xferserver_caps "g"
@@ -349,10 +417,24 @@
349417
# Links to other repositories of the project are given on request, except
350418
# those on the local host.
351419
xferserver_set syncwith:http://localhost:8080/y "{}"
352420
xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \
353421
"pragma link http://example.org/x" "!localhost:8080/y"
422
+# A repository that is mirrored to Git has the address it pushes to among
423
+# these links when that address is an http or https URL. An address that
424
+# Git takes and that is not a URL is left out, and the reply goes on.
425
+xferserver_set gitpush:https://git.example.org/someone/mirror.git "{}"
426
+xferserver_set gitpush:[email protected]:someone/other.git "{}"
427
+xferserver_set gitpush:[email protected]:someone/other.git "{}"
428
+xferserver_send "${xferserverPull}pragma req-links\n"
429
+test xfer-server-read-req-links-git-address \
430
+ {$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
431
+test xfer-server-read-req-links-git-https \
432
+ {[string match "*pragma link https://git.example.org/someone/mirror.git*" $RESULT]}
433
+test xfer-server-read-req-links-git-other-left-out \
434
+ {![string match "*other.git*" $RESULT]}
435
+xferserver_unset gitpush:*
354436
355437
# The address configuration is given only to a client that may read
356438
# addresses.
357439
xferserver_caps "oe"
358440
xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0"
@@ -415,9 +497,1192 @@
415497
# A repository with no project code cannot answer a pull or a push.
416498
xferserver_unset project-code
417499
xferserver_send "$xferserverLogin$xferserverPull"
418500
test xfer-server-no-project-code \
419501
{$CODE == 1 && [string first "missing project code" $RESULT] >= 0}
502
+
503
+###############################################################################
504
+# The sections below each run in a directory of their own, with a repository
505
+# and a checkout of their own inside this one.
506
+
507
+set xferserverDir [pwd]
508
+proc xferserver_enter {name} {
509
+ global xferserverDir
510
+ file mkdir [file join $xferserverDir $name]
511
+ cd [file join $xferserverDir $name]
512
+ fossil new .rep.fossil
513
+ fossil open .rep.fossil --nested
514
+ fossil set mtime-changes off
515
+}
516
+proc xferserver_leave {} {
517
+ global xferserverDir
518
+ cd $xferserverDir
519
+}
520
+
521
+###############################################################################
522
+# Malformed "file", "cfile" and "uvfile" cards, sent to the server side
523
+# of the sync protocol through "fossil test-xfer". The server must
524
+# refuse each one and must not crash. These cards reach the checks in
525
+# xfer_accept_file(), xfer_accept_compressed_file() and
526
+# xfer_accept_unversioned_file() in src/xfer.c.
527
+
528
+xferserver_enter cards
529
+
530
+set xferserverCardsContent "hello world\n"
531
+set xferserverCardsSize [string length $xferserverCardsContent]
532
+write_file a.txt $xferserverCardsContent
533
+fossil add a.txt
534
+fossil commit -m one --no-warnings
535
+fossil sha3sum a.txt
536
+set xferserverCardsHash [lindex $RESULT 0]
537
+
538
+fossil init tgt.fossil -A tester
539
+fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'"
540
+set xferserverCardsPcode [string trim $::RESULT]
541
+
542
+# Push the cards in BODY to the target. test-xfer disables the login
543
+# check, so the nonce and signature in the login card are ignored. The
544
+# push card has the target's project code.
545
+#
546
+# Sets xferserverCardsCode to the exit status of fossil,
547
+# xferserverCardsErrors to the number of errors that the reply reports, and
548
+# xferserverCardsStored to 1 when the target now holds the source file.
549
+proc xferserver_cards_push {body} {
550
+ global xferserverCardsHash xferserverCardsPcode
551
+ global xferserverCardsCode xferserverCardsErrors xferserverCardsStored
552
+ fossil sql -R tgt.fossil "DELETE FROM blob WHERE uuid='$xferserverCardsHash'"
553
+ write_file push.txt "login tester 0 0\npush x $xferserverCardsPcode\n$body"
554
+ fossil_raw test-xfer -R tgt.fossil push.txt
555
+ set xferserverCardsCode $::CODE
556
+ set xferserverCardsErrors 0
557
+ regexp {errors ([0-9]+)} $::RESULT -> xferserverCardsErrors
558
+ fossil sql -R tgt.fossil \
559
+ "SELECT count(*) FROM blob WHERE uuid='$xferserverCardsHash' AND size>=0"
560
+ set xferserverCardsStored [string trim $::RESULT]
561
+}
562
+
563
+xferserver_cards_push "file $xferserverCardsHash\
564
+ $xferserverCardsSize\n$xferserverCardsContent"
565
+test xfer-cards-valid-accepted \
566
+ {$xferserverCardsCode == 0 && $xferserverCardsErrors == 0 &&
567
+ $xferserverCardsStored == 1}
568
+
569
+set xferserverCardsZeros [string repeat 0 64]
570
+set xferserverCardsUv "uvfile note.txt 1700000000"
571
+foreach {xferserverCardsName xferserverCardsBody} [list \
572
+ too-few-tokens "file $xferserverCardsHash\n" \
573
+ bad-hash-name \
574
+ "file nothash $xferserverCardsSize\n$xferserverCardsContent" \
575
+ bad-size-int \
576
+ "file $xferserverCardsHash notint\n$xferserverCardsContent" \
577
+ bad-delta-source \
578
+ "file $xferserverCardsHash zz\
579
+ $xferserverCardsSize\n$xferserverCardsContent" \
580
+ size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \
581
+ size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \
582
+ size-at-end "file $xferserverCardsHash 5\n" \
583
+ size-with-nul "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \
584
+ content-wrong-hash \
585
+ "file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \
586
+ cfile-too-few "cfile $xferserverCardsHash\n" \
587
+ cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \
588
+ uvfile-too-few "uvfile note.txt\n" \
589
+ uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \
590
+ uvfile-mtime-nul "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \
591
+ uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \
592
+ uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \
593
+ uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \
594
+ uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \
595
+ uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \
596
+] {
597
+ xferserver_cards_push $xferserverCardsBody
598
+ test xfer-cards-reject-$xferserverCardsName \
599
+ {$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 &&
600
+ $xferserverCardsStored == 0}
601
+}
602
+
603
+# A client that does not send a version is treated as older than 2.0 and
604
+# cannot be sent a SHA3 hash. When such a client asks for an unversioned
605
+# file the server answers with an error; a current client gets the file.
606
+write_file note.txt "hi\n"
607
+fossil unversioned add note.txt -R tgt.fossil --user tester
608
+set xferserverCardsUvgimme \
609
+ "login tester 0 0\npull x $xferserverCardsPcode\nuvgimme note.txt\n"
610
+write_file uvgimme.txt $xferserverCardsUvgimme
611
+fossil_raw test-xfer -R tgt.fossil uvgimme.txt
612
+test xfer-cards-uvgimme-old-client \
613
+ {$CODE == 0
614
+ && [holds_strings $RESULT [list {or\slater\srequired} "!uvfile note.txt"]]}
615
+write_file uvgimme.txt $CLIENT_VERSION_CARD$xferserverCardsUvgimme
616
+fossil_raw test-xfer -R tgt.fossil uvgimme.txt
617
+test xfer-cards-uvgimme-current-client \
618
+ {$CODE == 0 && [string first "uvfile note.txt" $RESULT] >= 0}
619
+
620
+fossil sql -R tgt.fossil \
621
+ "INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)"
622
+xferserver_cards_push "file $xferserverCardsHash\
623
+ $xferserverCardsSize\n$xferserverCardsContent"
624
+test xfer-cards-reject-shunned \
625
+ {$xferserverCardsCode == 0 && $xferserverCardsStored == 0}
626
+
627
+xferserver_leave
628
+
629
+###############################################################################
630
+# More cards sent to the server side of the sync protocol through
631
+# "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme"
632
+# and "uvgimme" that xfer-cards.test and xfer-server.test do not send.
633
+# Each has a stated effect on the server's repository or on the reply,
634
+# and none may crash.
635
+#
636
+# The messages carry no login card, so they run with the permissions of
637
+# the user "nobody", which these tests set.
638
+#
639
+
640
+
641
+xferserver_enter edge
642
+
643
+# The answer of one SQL statement on the server, trimmed.
644
+#
645
+proc xferserver_sql {sql} {
646
+ fossil sql -R srv.fossil $sql
647
+ return [string trim $::RESULT]
648
+}
649
+
650
+# Send the cards BODY to the server after a client-version card and a
651
+# card of KIND, which is "push" or "pull". RESULT is the reply, as
652
+# bytes. xferserverEdgeErrors is the number of errors that the reply reports,
653
+# or -1 if it reports none at all.
654
+#
655
+proc xferserver_edge_send {kind body} {
656
+ global xferserverEdgePcode xferserverEdgeErrors CLIENT_VERSION_CARD
657
+ write_file msg.txt "${CLIENT_VERSION_CARD}$kind x $xferserverEdgePcode\n$body"
658
+ fossil_raw test-xfer -R srv.fossil msg.txt
659
+ set xferserverEdgeErrors -1
660
+ regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors
661
+}
662
+
663
+# The hash that Fossil gives TEXT.
664
+#
665
+proc xferserver_hash {text} {
666
+ write_file hash-me.txt $text
667
+ fossil sha3sum hash-me.txt
668
+ return [lindex $::RESULT 0]
669
+}
670
+
671
+# Content as a "cfile" card carries it: the size, then the zlib stream.
672
+#
673
+proc xferserver_compress {text} {
674
+ return [binary format I [string length $text]][zlib compress $text]
675
+}
676
+
677
+# 1 if the server holds the content of the artifact HASH.
678
+#
679
+proc xferserver_holds {hash} {
680
+ return [xferserver_sql "SELECT count(*) FROM blob
681
+ WHERE uuid='$hash' AND size>=0"]
682
+}
683
+
684
+# Remove every trace of the artifacts HASHES from the server.
685
+#
686
+proc xferserver_forget {hashes} {
687
+ set list '[join $hashes ',']'
688
+ xferserver_sql "CREATE TEMP TABLE gone AS
689
+ SELECT rid FROM blob WHERE uuid IN ($list);
690
+ DELETE FROM delta WHERE rid IN gone OR srcid IN gone;
691
+ DELETE FROM phantom WHERE rid IN gone;
692
+ DELETE FROM unclustered WHERE rid IN gone;
693
+ DELETE FROM private WHERE rid IN gone;
694
+ DELETE FROM blob WHERE rid IN gone"
695
+}
696
+
697
+# Three versions of one file, so that the server stores deltas.
698
+set xferserverEdgeText ""
699
+for {set xferserverEdgeI 0} {$xferserverEdgeI < 40} {incr xferserverEdgeI} {
700
+ append xferserverEdgeText \
701
+ "line $xferserverEdgeI of a file that is worth a delta\n"
702
+}
703
+foreach xferserverEdgeI {1 2 3} {
704
+ append xferserverEdgeText "version $xferserverEdgeI\n"
705
+ write_file a.txt $xferserverEdgeText
706
+ if {$xferserverEdgeI == 1} {fossil add a.txt}
707
+ fossil commit -m "xferedge-v$xferserverEdgeI" --no-warnings
708
+ set xferserverEdgeVersion($xferserverEdgeI) $xferserverEdgeText
709
+}
710
+file copy .rep.fossil srv.fossil
711
+fossil unversioned list -R srv.fossil
712
+set xferserverEdgePcode [xferserver_sql \
713
+ "SELECT value FROM config WHERE name='project-code'"]
714
+xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'"
715
+set xferserverEdgeAbsent [string repeat 0123456789abcdef 4]
716
+
717
+###############################################################################
718
+# "file" cards.
719
+
720
+set xferserverEdgeNew "content that the server does not have yet\n"
721
+set xferserverEdgeNewHash [xferserver_hash $xferserverEdgeNew]
722
+set xferserverEdgeLen [string length $xferserverEdgeNew]
723
+
724
+foreach {xferserverEdgeName xferserverEdgeCard} [list \
725
+ too-many-tokens \
726
+ "file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\
727
+ $xferserverEdgeLen\n$xferserverEdgeNew" \
728
+ negative-size "file $xferserverEdgeNewHash -1\n$xferserverEdgeNew" \
729
+] {
730
+ xferserver_edge_send push $xferserverEdgeCard
731
+ test xfer-edge-file-$xferserverEdgeName \
732
+ {$CODE == 0 && $xferserverEdgeErrors > 0 &&
733
+ ![xferserver_holds $xferserverEdgeNewHash]}
734
+}
735
+
736
+# A delta whose source the server does not have is kept as it is, with a
737
+# phantom for the source, and is public.
738
+xferserver_edge_send push \
739
+ "file $xferserverEdgeNewHash $xferserverEdgeAbsent 9\nnot-delta"
740
+test xfer-edge-file-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0}
741
+test_eq xfer-edge-file-dangling-delta-stored [xferserver_sql "SELECT
742
+ (SELECT size FROM blob WHERE uuid='$xferserverEdgeAbsent'),
743
+ (SELECT count(*) FROM delta, blob a, blob b WHERE delta.rid=a.rid
744
+ AND delta.srcid=b.rid AND a.uuid='$xferserverEdgeNewHash'
745
+ AND b.uuid='$xferserverEdgeAbsent'),
746
+ (SELECT count(*) FROM private, blob WHERE private.rid=blob.rid
747
+ AND uuid='$xferserverEdgeNewHash')"] {-1|1|0}
748
+xferserver_forget [list $xferserverEdgeNewHash $xferserverEdgeAbsent]
749
+
750
+###############################################################################
751
+# "cfile" cards.
752
+
753
+set xferserverEdgeZ [xferserver_compress $xferserverEdgeNew]
754
+set xferserverEdgeZLen [string length $xferserverEdgeZ]
755
+foreach {xferserverEdgeName xferserverEdgeCard} [list \
756
+ too-many-tokens \
757
+ "cfile $xferserverEdgeNewHash $xferserverEdgeAbsent 1 $xferserverEdgeLen\
758
+ $xferserverEdgeZLen\n$xferserverEdgeZ" \
759
+ bad-hash \
760
+ "cfile nothash $xferserverEdgeLen $xferserverEdgeZLen\n$xferserverEdgeZ" \
761
+ bad-usize \
762
+ "cfile $xferserverEdgeNewHash notint\
763
+ $xferserverEdgeZLen\n$xferserverEdgeZ" \
764
+ bad-csize \
765
+ "cfile $xferserverEdgeNewHash $xferserverEdgeLen notint\n$xferserverEdgeZ" \
766
+ negative-usize \
767
+ "cfile $xferserverEdgeNewHash -1 $xferserverEdgeZLen\n$xferserverEdgeZ" \
768
+ negative-csize \
769
+ "cfile $xferserverEdgeNewHash $xferserverEdgeLen -1\n$xferserverEdgeZ" \
770
+ bad-source \
771
+ "cfile $xferserverEdgeNewHash zz $xferserverEdgeLen\
772
+ $xferserverEdgeZLen\n$xferserverEdgeZ" \
773
+] {
774
+ xferserver_edge_send push $xferserverEdgeCard
775
+ test xfer-edge-cfile-$xferserverEdgeName \
776
+ {$CODE == 0 && $xferserverEdgeErrors > 0 &&
777
+ ![xferserver_holds $xferserverEdgeNewHash]}
778
+}
779
+
780
+xferserver_edge_send push "cfile $xferserverEdgeNewHash $xferserverEdgeLen\
781
+$xferserverEdgeZLen\n$xferserverEdgeZ"
782
+test xfer-edge-cfile-accepted \
783
+ {$CODE == 0 && $xferserverEdgeErrors == 0 &&
784
+ [xferserver_holds $xferserverEdgeNewHash]}
785
+fossil artifact $xferserverEdgeNewHash -R srv.fossil cfile.out
786
+test_eq xfer-edge-cfile-content [read_file cfile.out] $xferserverEdgeNew
787
+
788
+# The size recorded for the artifact is that of its content, not of its
789
+# compressed form.
790
+test_eq xfer-edge-cfile-size-recorded [xferserver_sql "SELECT size FROM blob
791
+ WHERE uuid='$xferserverEdgeNewHash'"] $xferserverEdgeLen
792
+
793
+# Content that does not have the hash or the size on the card is refused
794
+# with an error, as it is for a "file" card.
795
+set xferserverEdgeWrong "content that is not what its card says\n"
796
+set xferserverEdgeZ [xferserver_compress $xferserverEdgeWrong]
797
+xferserver_edge_send push "cfile $xferserverEdgeAbsent\
798
+[string length $xferserverEdgeWrong]\
799
+[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
800
+test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0}
801
+test xfer-edge-cfile-wrong-hash-not-stored \
802
+ {![xferserver_holds $xferserverEdgeAbsent]}
803
+set xferserverEdgeSized "content with the wrong size on its card\n"
804
+set xferserverEdgeSizedHash [xferserver_hash $xferserverEdgeSized]
805
+set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized]
806
+xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\
807
+[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
808
+test xfer-edge-cfile-wrong-size \
809
+ {$CODE == 0 && $xferserverEdgeErrors > 0 &&
810
+ ![xferserver_holds $xferserverEdgeSizedHash]}
811
+xferserver_edge_send push \
812
+ "cfile $xferserverEdgeAbsent 16 20\n\x00\x00\x00\x10not zlib data !!"
813
+test xfer-edge-cfile-not-compressed \
814
+ {$CODE == 0 && $xferserverEdgeErrors > 0 &&
815
+ ![xferserver_holds $xferserverEdgeAbsent]}
816
+
817
+# A shunned artifact is not stored.
818
+set xferserverEdgeShun "content that the server has shunned\n"
819
+set xferserverEdgeShunHash [xferserver_hash $xferserverEdgeShun]
820
+xferserver_sql "INSERT INTO shun(uuid,mtime)\
821
+ VALUES('$xferserverEdgeShunHash',0)"
822
+set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun]
823
+xferserver_edge_send push "cfile $xferserverEdgeShunHash\
824
+[string length $xferserverEdgeShun]\
825
+[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
826
+test xfer-edge-cfile-shunned \
827
+ {$CODE == 0 && ![xferserver_holds $xferserverEdgeShunHash]}
828
+
829
+# A compressed delta whose source the server does not have is kept as it
830
+# is. Its hash cannot be checked yet; its size can, and a delta that
831
+# does not make content of the size on the card is refused.
832
+set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4]
833
+write_file delta-src.txt $xferserverEdgeVersion(1)
834
+write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n"
835
+fossil test-delta-create delta-src.txt delta-tgt.txt delta.out
836
+set xferserverEdgeTgtHash [xferserver_hash [read_file delta-tgt.txt]]
837
+set xferserverEdgeZ [xferserver_compress [read_file delta.out]]
838
+xferserver_edge_send push "cfile $xferserverEdgeTgtHash\
839
+$xferserverEdgeAbsent2 7777\
840
+[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
841
+test xfer-edge-cfile-dangling-delta-wrong-size \
842
+ {$CODE == 0 && $xferserverEdgeErrors > 0}
843
+xferserver_edge_send push "cfile $xferserverEdgeTgtHash $xferserverEdgeAbsent2\
844
+[file size delta-tgt.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
845
+test xfer-edge-cfile-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0}
846
+test_eq xfer-edge-cfile-dangling-delta-stored [xferserver_sql "SELECT a.size
847
+ FROM delta, blob a WHERE delta.rid=a.rid
848
+ AND a.uuid='$xferserverEdgeTgtHash'"] \
849
+ [file size delta-tgt.txt]
850
+xferserver_forget [list $xferserverEdgeTgtHash $xferserverEdgeAbsent2]
851
+
852
+# Content that is too short to hold a size, or that is not compressed
853
+# data, is refused as malformed, whether or not the card gives a size
854
+# for the content.
855
+foreach {xferserverEdgeName xferserverEdgeCard} [list \
856
+ short-content "cfile $xferserverEdgeAbsent 5 3\nabc\n" \
857
+ no-usize-short "cfile $xferserverEdgeAbsent 0 3\nabc\n" \
858
+ no-usize-not-compressed \
859
+ "cfile $xferserverEdgeAbsent 0 20\n\x00\x00\x00\x10not zlib data !!" \
860
+] {
861
+ xferserver_edge_send push $xferserverEdgeCard
862
+ test xfer-edge-cfile-$xferserverEdgeName \
863
+ {$CODE == 0 && $xferserverEdgeErrors > 0 &&
864
+ [string first {malformed+cfile+content} $RESULT] >= 0 &&
865
+ ![xferserver_holds $xferserverEdgeAbsent]}
866
+}
867
+
868
+# A compressed delta whose source the server has is applied and checked.
869
+# One that does not apply, and one that makes content with another hash
870
+# than the card gives, are refused; one that makes the content that the
871
+# card names is stored.
872
+set xferserverEdgeSrcHash [xferserver_hash $xferserverEdgeVersion(1)]
873
+test xfer-edge-cfile-delta-setup-source-held \
874
+ {[xferserver_holds $xferserverEdgeSrcHash] == 1}
875
+write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n"
876
+fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out
877
+set xferserverEdgeTgt2Hash [xferserver_hash [read_file delta-tgt2.txt]]
878
+set xferserverEdgeDelta [read_file delta2.out]
879
+# The same delta without the checksum that ends it.
880
+regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta
881
+test xfer-edge-cfile-delta-setup-cut \
882
+ {[string length $xferserverEdgeBadDelta] > 0 &&
883
+ [string length $xferserverEdgeBadDelta]
884
+ < [string length $xferserverEdgeDelta]}
885
+foreach {xferserverEdgeName xferserverEdgeHash xferserverEdgeBody
886
+ xferserverEdgeStored} [list \
887
+ does-not-apply $xferserverEdgeTgt2Hash $xferserverEdgeBadDelta 0 \
888
+ other-hash $xferserverEdgeAbsent2 $xferserverEdgeDelta 0 \
889
+ accepted $xferserverEdgeTgt2Hash $xferserverEdgeDelta 1 \
890
+] {
891
+ set xferserverEdgeZ [xferserver_compress $xferserverEdgeBody]
892
+ xferserver_edge_send push "cfile $xferserverEdgeHash $xferserverEdgeSrcHash\
893
+[file size delta-tgt2.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
894
+ test xfer-edge-cfile-delta-$xferserverEdgeName \
895
+ {$CODE == 0 && ($xferserverEdgeErrors > 0) != $xferserverEdgeStored
896
+ && [xferserver_holds $xferserverEdgeHash] == $xferserverEdgeStored}
897
+}
898
+fossil artifact $xferserverEdgeTgt2Hash -R srv.fossil cfile-delta.out
899
+test_eq xfer-edge-cfile-delta-content [read_file cfile-delta.out] \
900
+ [read_file delta-tgt2.txt]
901
+xferserver_forget [list $xferserverEdgeTgt2Hash]
902
+
903
+###############################################################################
904
+# "uvfile" cards.
905
+
906
+set xferserverEdgeUv "an unversioned note\n"
907
+set xferserverEdgeUvHash [xferserver_hash $xferserverEdgeUv]
908
+set xferserverEdgeUvLen [string length $xferserverEdgeUv]
909
+proc xferserver_uv {name} {
910
+ return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL
911
+ FROM unversioned WHERE name='$name'"]
912
+}
913
+
914
+foreach {xferserverEdgeName xferserverEdgeCard} [list \
915
+ five-tokens \
916
+ "uvfile note.txt 1700000000 $xferserverEdgeUvHash\
917
+ $xferserverEdgeUvLen\n$xferserverEdgeUv" \
918
+ bad-filename \
919
+ "uvfile ../note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\
920
+ 0\n$xferserverEdgeUv" \
921
+] {
922
+ xferserver_edge_send push $xferserverEdgeCard
923
+ test xfer-edge-uvfile-$xferserverEdgeName \
924
+ {$CODE == 0 && $xferserverEdgeErrors > 0}
925
+}
926
+test_eq xfer-edge-uvfile-none-stored [xferserver_sql \
927
+ "SELECT count(*) FROM unversioned"] 0
928
+
929
+xferserver_edge_send push \
930
+ "uvfile note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\
931
+ 0\n$xferserverEdgeUv"
932
+test xfer-edge-uvfile-accepted {$CODE == 0 && $xferserverEdgeErrors == 0}
933
+test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \
934
+ "1700000000|$xferserverEdgeUvLen|0|1"
935
+
936
+# Content that compresses well is stored compressed.
937
+set xferserverEdgeBig [string repeat "the same line again and again\n" 200]
938
+set xferserverEdgeBigHash [xferserver_hash $xferserverEdgeBig]
939
+xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\
940
+[string length $xferserverEdgeBig] 0\n$xferserverEdgeBig"
941
+test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \
942
+ "1700000000|[string length $xferserverEdgeBig]|1|1"
943
+
944
+# The same content with a newer time and no content: only the time
945
+# changes.
946
+xferserver_edge_send push \
947
+ "uvfile note.txt 1700000500 $xferserverEdgeUvHash $xferserverEdgeUvLen 4\n"
948
+test_eq xfer-edge-uvfile-time-only [xferserver_uv note.txt] \
949
+ "1700000500|$xferserverEdgeUvLen|0|1"
950
+
951
+# Older content does not replace newer.
952
+set xferserverEdgeOld "an older note\n"
953
+xferserver_edge_send push "uvfile note.txt 1600000000\
954
+[xferserver_hash $xferserverEdgeOld]\
955
+[string length $xferserverEdgeOld] 0\n$xferserverEdgeOld"
956
+test xfer-edge-uvfile-older {$CODE == 0}
957
+test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash
958
+ FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash
959
+
960
+# A newer deletion empties the file but keeps its name.
961
+xferserver_edge_send push "uvfile note.txt 1700001000 - 0 1\n"
962
+test xfer-edge-uvfile-delete {$CODE == 0 && $xferserverEdgeErrors == 0}
963
+test_eq xfer-edge-uvfile-deleted [xferserver_uv note.txt] {1700001000|0|0|0}
964
+
965
+# Without the permission to write unversioned files, nothing is stored.
966
+xferserver_sql "UPDATE user SET cap='oi' WHERE login='nobody'"
967
+xferserver_edge_send push \
968
+ "uvfile other.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\
969
+ 0\n$xferserverEdgeUv"
970
+test xfer-edge-uvfile-no-permission {$CODE == 0 && $xferserverEdgeErrors > 0}
971
+test_eq xfer-edge-uvfile-no-permission-stored [xferserver_sql "SELECT count(*)
972
+ FROM unversioned WHERE name='other.txt'"] 0
973
+xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'"
974
+
975
+###############################################################################
976
+# "uvgimme" cards.
977
+
978
+xferserver_edge_send pull "uvgimme big.txt\n"
979
+test xfer-edge-uvgimme-file {$CODE == 0 && [string first \
980
+ "uvfile big.txt 1700000000 $xferserverEdgeBigHash [string length\
981
+ $xferserverEdgeBig] 0\n$xferserverEdgeBig" \
982
+ $RESULT] >= 0}
983
+xferserver_edge_send pull "uvgimme note.txt\n"
984
+test xfer-edge-uvgimme-deleted \
985
+ {$CODE == 0 &&
986
+ [string first "uvfile note.txt 1700001000 - 0 1\n" $RESULT] >= 0}
987
+xferserver_edge_send pull "uvgimme no-such-file.txt\n"
988
+test xfer-edge-uvgimme-unknown \
989
+ {$CODE == 0 && [string first "uvfile no-such-file.txt" $RESULT] < 0}
990
+
991
+###############################################################################
992
+# "gimme" cards.
993
+
994
+proc xferserver_file_hash {version} {
995
+ return [xferserver_sql "SELECT uuid FROM blob, mlink, event
996
+ WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
997
+ AND event.comment='xferedge-v$version'"]
998
+}
999
+set xferserverEdgeV1 [xferserver_file_hash 1]
1000
+set xferserverEdgeV2 [xferserver_file_hash 2]
1001
+set xferserverEdgeV3 [xferserver_file_hash 3]
1002
+
1003
+# The server sends a version as a delta from the version before it,
1004
+# which the client is likely to have. The first version has none and
1005
+# goes whole, although the server stores it as a delta.
1006
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1007
+test xfer-edge-gimme-delta-from-parent \
1008
+ {$CODE == 0 &&
1009
+ [string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0}
1010
+xferserver_edge_send pull "gimme $xferserverEdgeV1\n"
1011
+test xfer-edge-gimme-whole {$CODE == 0 && [string first \
1012
+ "file $xferserverEdgeV1 [string length $xferserverEdgeVersion(1)]\n"\
1013
+ $RESULT] >= 0}
1014
+
1015
+# An artifact that the server does not have, and one that it has
1016
+# shunned, are not sent.
1017
+xferserver_edge_send pull "gimme $xferserverEdgeAbsent\n"
1018
+test xfer-edge-gimme-absent \
1019
+ {$CODE == 0 && [string first "file $xferserverEdgeAbsent" $RESULT] < 0}
1020
+xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV3',0)"
1021
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1022
+test xfer-edge-gimme-shunned \
1023
+ {$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0}
1024
+xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV3'"
1025
+
1026
+# A delta is not sent from a shunned source: the content goes whole.
1027
+xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV2',0)"
1028
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1029
+test xfer-edge-gimme-shunned-source {$CODE == 0 && [string first \
1030
+ "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\
1031
+ $RESULT] >= 0}
1032
+xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV2'"
1033
+
1034
+# A private artifact is not sent to a client that has not asked for
1035
+# private content, and a delta is not sent from a private source.
1036
+xferserver_sql "INSERT INTO private SELECT rid FROM blob
1037
+ WHERE uuid='$xferserverEdgeV3'"
1038
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1039
+test xfer-edge-gimme-private \
1040
+ {$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0}
1041
+xferserver_sql "DELETE FROM private"
1042
+xferserver_sql "INSERT INTO private SELECT rid FROM blob
1043
+ WHERE uuid='$xferserverEdgeV2'"
1044
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1045
+test xfer-edge-gimme-private-source {$CODE == 0 && [string first \
1046
+ "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\
1047
+ $RESULT] >= 0}
1048
+xferserver_sql "DELETE FROM private"
1049
+
1050
+# A delta is not sent from a version that the server holds only as a
1051
+# delta whose own source has not arrived, because that version cannot be
1052
+# rebuilt: the content goes whole.
1053
+set xferserverEdgeMissing [string repeat 0a1b2c3d 8]
1054
+set xferserverEdgeV2Src [xferserver_sql "SELECT srcid FROM delta, blob
1055
+ WHERE delta.rid=blob.rid AND uuid='$xferserverEdgeV2'"]
1056
+xferserver_sql "INSERT INTO blob(rcvid,size,uuid)
1057
+ VALUES(0,-1,'$xferserverEdgeMissing');
1058
+ INSERT INTO phantom SELECT rid FROM blob
1059
+ WHERE uuid='$xferserverEdgeMissing';
1060
+ REPLACE INTO delta(rid,srcid) SELECT a.rid, b.rid FROM blob a, blob b
1061
+ WHERE a.uuid='$xferserverEdgeV2' AND b.uuid='$xferserverEdgeMissing'"
1062
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1063
+test xfer-edge-gimme-source-cannot-be-rebuilt {$CODE == 0 && [string first \
1064
+ "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\
1065
+ $RESULT] >= 0}
1066
+if {$xferserverEdgeV2Src eq ""} {
1067
+ xferserver_sql "DELETE FROM delta WHERE rid=(SELECT rid FROM blob
1068
+ WHERE uuid='$xferserverEdgeV2')"
1069
+} else {
1070
+ xferserver_sql "UPDATE delta SET srcid=$xferserverEdgeV2Src
1071
+ WHERE rid=(SELECT rid FROM blob WHERE uuid='$xferserverEdgeV2')"
1072
+}
1073
+xferserver_forget [list $xferserverEdgeMissing]
1074
+xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1075
+test xfer-edge-gimme-delta-again \
1076
+ {$CODE == 0 &&
1077
+ [string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0}
1078
+
1079
+fossil test-integrity -R srv.fossil
1080
+test xfer-edge-integrity {$CODE == 0}
1081
+
1082
+###############################################################################
1083
+# A repository that has never held an unversioned file has no table for
1084
+# them. A request for one is answered like any other request for a file
1085
+# that is not there.
1086
+
1087
+fossil init fresh.fossil
1088
+fossil sql -R fresh.fossil "UPDATE user SET cap='oiy' WHERE login='nobody'"
1089
+fossil sql -R fresh.fossil "SELECT value FROM config WHERE name='project-code'"
1090
+write_file msg.txt \
1091
+ "${CLIENT_VERSION_CARD}pull x [string trim $RESULT]\nuvgimme note.txt\n"
1092
+fossil_raw test-xfer -R fresh.fossil msg.txt
1093
+test xfer-edge-uvgimme-no-table \
1094
+ {$CODE == 0 && [string first "Database error" $RESULT] < 0}
1095
+
1096
+xferserver_leave
1097
+
1098
+###############################################################################
1099
+# The login card of the sync protocol, checked by a server as it is on a
1100
+# network. A real client syncs with a real server through
1101
+# standin/scenario-wire.tcl, which hands each request to "fossil http"
1102
+# on the server's repository without --localauth, so the server decides
1103
+# what the client may do from the login card alone. Fossil puts no login
1104
+# card on a request that goes through a transport command, so the
1105
+# stand-in adds the card, made as http_build_login_card() makes it.
1106
+
1107
+xferserver_enter login
1108
+
1109
+write_file a.txt "first\n"
1110
+fossil add a.txt
1111
+fossil commit -m "xferlogin-c1" --no-warnings
1112
+file copy .rep.fossil srv.fossil
1113
+file copy .rep.fossil cli.fossil
1114
+
1115
+set xferserverLoginWire [file join [pwd] wire.tcl]
1116
+file copy [file join $::testfiledir standin scenario-wire.tcl] \
1117
+ $xferserverLoginWire
1118
+set xferserverLoginWire "\"[info nameofexecutable]\" \"$xferserverLoginWire\""
1119
+set ::env(SCN_EXE) $::fossilexe
1120
+set ::env(SCN_REPO) [file join [pwd] srv.fossil]
1121
+set ::env(SCN_FAULT) 0
1122
+set ::env(SCN_AUTH) 1
1123
+fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'"
1124
+set ::env(SCN_PROJECT) [string trim $RESULT]
1125
+
1126
+# Sync the client with the server as USERINFO, which is "user:password"
1127
+# or empty for no login card. VERB is pull, push or sync.
1128
+#
1129
+proc xferserver_login_sync {verb userinfo} {
1130
+ global xferserverLoginWire
1131
+ if {$userinfo ne ""} {set ::env(SCN_LOGIN) $userinfo}
1132
+ fossil_raw -seconds 60 $verb http://xferlogin.invalid/x --once \
1133
+ --transport-command $xferserverLoginWire -R cli.fossil
1134
+ unset -nocomplain ::env(SCN_LOGIN)
1135
+}
1136
+
1137
+# The number of artifacts with content that the repository holds.
1138
+#
1139
+proc xferserver_blobs {repo} {
1140
+ fossil sql -R $repo "SELECT count(*) FROM blob WHERE size>=0"
1141
+ return [string trim $::RESULT]
1142
+}
1143
+
1144
+# Give the server something that the client does not have.
1145
+#
1146
+proc xferserver_login_new_on_server {} {
1147
+ global xferserverLoginN
1148
+ write_file srv-[incr xferserverLoginN].txt \
1149
+ "content number $xferserverLoginN\n"
1150
+ fossil test-content-put srv-$xferserverLoginN.txt -R srv.fossil
1151
+}
1152
+set xferserverLoginN 0
1153
+
1154
+# Nobody may do anything; the user "tester" may read and write.
1155
+xferserver_sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')"
1156
+fossil user new tester "" secret -R srv.fossil
1157
+xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'"
1158
+test_eq xfer-login-password-stored-hashed \
1159
+ [xferserver_sql "SELECT length(pw) FROM user WHERE login='tester'"] 40
1160
+
1161
+###############################################################################
1162
+# With no login card the client is "nobody", who may not read.
1163
+
1164
+xferserver_login_new_on_server
1165
+set xferserverLoginBefore [xferserver_blobs cli.fossil]
1166
+xferserver_login_sync pull ""
1167
+test xfer-login-nobody-refused \
1168
+ {$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0}
1169
+test_eq xfer-login-nobody-got-nothing [xferserver_blobs cli.fossil] \
1170
+ $xferserverLoginBefore
1171
+
1172
+###############################################################################
1173
+# The right password gives the user's permissions.
1174
+
1175
+xferserver_login_sync pull tester:secret
1176
+test xfer-login-accepted {$CODE == 0}
1177
+test_eq xfer-login-accepted-pulled [xferserver_blobs cli.fossil] \
1178
+ [expr {$xferserverLoginBefore + 1}]
1179
+
1180
+# The same for a push.
1181
+write_file cli-1.txt "content from the client\n"
1182
+fossil test-content-put cli-1.txt -R cli.fossil
1183
+set xferserverLoginBefore [xferserver_blobs srv.fossil]
1184
+xferserver_login_sync push tester:secret
1185
+test xfer-login-push-accepted {$CODE == 0}
1186
+test_eq xfer-login-push-arrived [xferserver_blobs srv.fossil] \
1187
+ [expr {$xferserverLoginBefore + 1}]
1188
+
1189
+###############################################################################
1190
+# A wrong password, and a user that the server does not know.
1191
+
1192
+xferserver_login_new_on_server
1193
+set xferserverLoginBefore [xferserver_blobs cli.fossil]
1194
+foreach {xferserverLoginName xferserverLoginUser} {
1195
+ wrong-password tester:wrong
1196
+ unknown-user stranger:secret
1197
+} {
1198
+ xferserver_login_sync pull $xferserverLoginUser
1199
+ test xfer-login-$xferserverLoginName \
1200
+ {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1201
+ test_eq xfer-login-$xferserverLoginName-got-nothing \
1202
+ [xferserver_blobs cli.fossil] \
1203
+ $xferserverLoginBefore
1204
+}
1205
+
1206
+# The special users cannot be logged in as with a password, whatever
1207
+# password the server has for them.
1208
+xferserver_sql "UPDATE user SET pw='secret', cap='oi' WHERE login='developer'"
1209
+xferserver_login_sync pull developer:secret
1210
+test xfer-login-special-user-refused {$CODE != 0}
1211
+test_eq xfer-login-special-user-got-nothing [xferserver_blobs cli.fossil] \
1212
+ $xferserverLoginBefore
1213
+
1214
+###############################################################################
1215
+# A user with read permission only may not push.
1216
+
1217
+xferserver_sql "UPDATE user SET cap='o' WHERE login='tester'"
1218
+write_file cli-2.txt "more content from the client\n"
1219
+fossil test-content-put cli-2.txt -R cli.fossil
1220
+set xferserverLoginSrvBefore [xferserver_blobs srv.fossil]
1221
+xferserver_login_sync push tester:secret
1222
+test xfer-login-push-without-write \
1223
+ {$CODE != 0 && [string first "not authorized to write" $RESULT] >= 0}
1224
+test_eq xfer-login-push-without-write-nothing-arrived \
1225
+ [xferserver_blobs srv.fossil] $xferserverLoginSrvBefore
1226
+xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'"
1227
+
1228
+###############################################################################
1229
+# A server that keeps the password as the user typed it still accepts the
1230
+# login, and still refuses a wrong password.
1231
+
1232
+xferserver_sql "UPDATE user SET pw='secret' WHERE login='tester'"
1233
+xferserver_login_sync pull tester:wrong
1234
+test xfer-login-cleartext-wrong \
1235
+ {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1236
+set xferserverLoginBefore [xferserver_blobs cli.fossil]
1237
+xferserver_login_sync pull tester:secret
1238
+test xfer-login-cleartext-accepted {$CODE == 0}
1239
+test_eq xfer-login-cleartext-pulled [xferserver_blobs cli.fossil] \
1240
+ [expr {$xferserverLoginBefore + 1}]
1241
+
1242
+###############################################################################
1243
+# A login card for "nobody" or "anonymous" is accepted without a
1244
+# password, and gives the permissions of "nobody".
1245
+
1246
+xferserver_login_new_on_server
1247
+set xferserverLoginBefore [xferserver_blobs cli.fossil]
1248
+foreach xferserverLoginUser {nobody anonymous} {
1249
+ xferserver_login_sync pull $xferserverLoginUser:anything
1250
+ test xfer-login-as-$xferserverLoginUser \
1251
+ {$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0}
1252
+}
1253
+xferserver_sql "UPDATE user SET cap='o' WHERE login='nobody'"
1254
+xferserver_login_sync pull nobody:anything
1255
+test xfer-login-as-nobody-who-may-read {$CODE == 0}
1256
+test_eq xfer-login-as-nobody-pulled [xferserver_blobs cli.fossil] \
1257
+ [expr {$xferserverLoginBefore + 1}]
1258
+xferserver_sql "UPDATE user SET cap='' WHERE login='nobody'"
1259
+
1260
+###############################################################################
1261
+# A web server that has already checked the user's password says so in
1262
+# REMOTE_USER. The login card of that user is then accepted whatever
1263
+# its signature, but only if the remote_user_ok setting is on.
1264
+
1265
+xferserver_login_new_on_server
1266
+set xferserverLoginBefore [xferserver_blobs cli.fossil]
1267
+set ::env(REMOTE_USER) tester
1268
+xferserver_login_sync pull tester:wrong
1269
+test xfer-login-remote-user-setting-off \
1270
+ {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1271
+xferserver_sql "REPLACE INTO config(name,value,mtime)
1272
+ VALUES('remote_user_ok',1,now())"
1273
+xferserver_login_sync pull stranger:wrong
1274
+test xfer-login-remote-user-other-name \
1275
+ {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1276
+test_eq xfer-login-remote-user-nothing-yet [xferserver_blobs cli.fossil] \
1277
+ $xferserverLoginBefore
1278
+xferserver_login_sync pull tester:wrong
1279
+test xfer-login-remote-user-accepted {$CODE == 0}
1280
+test_eq xfer-login-remote-user-pulled [xferserver_blobs cli.fossil] \
1281
+ [expr {$xferserverLoginBefore + 1}]
1282
+unset ::env(REMOTE_USER)
1283
+xferserver_sql "DELETE FROM config WHERE name='remote_user_ok'"
1284
+
1285
+###############################################################################
1286
+# Requests written here and given to "fossil http" as a web server gives
1287
+# them, so that the login card can be wrong in one way at a time and can
1288
+# come in a cookie.
1289
+
1290
+set xferserverLoginProject $::env(SCN_PROJECT)
1291
+set xferserverLoginPull "pull x $xferserverLoginProject\n"
1292
+
1293
+# Give the server the cards BODY in a request with the extra header lines
1294
+# HEADERS, from the address ADDRESS, with any more options for "fossil
1295
+# http" in ARGS. RESULT is the reply without its header.
1296
+#
1297
+proc xferserver_http {body headers address args} {
1298
+ set request "POST /xfer HTTP/1.0\r\n"
1299
+ append request "Content-Type: application/x-fossil-debug\r\n"
1300
+ foreach header $headers {
1301
+ append request "$header\r\n"
1302
+ }
1303
+ append request "Content-Length: [string length $body]\r\n\r\n$body"
1304
+ write_file http-request.txt $request
1305
+ file delete http-reply.txt
1306
+ fossil_raw http --in http-request.txt --out http-reply.txt \
1307
+ --ipaddr $address srv.fossil {*}$args
1308
+ set reply ""
1309
+ if {[file exists http-reply.txt]} {
1310
+ set reply [read_file http-reply.txt]
1311
+ }
1312
+ set end [string first "\r\n\r\n" $reply]
1313
+ set ::RESULT [expr {$end < 0 ? "" : [string range $reply $end+4 end]}]
1314
+}
1315
+
1316
+# The login card of USER with PASSWORD for a message of the cards BODY,
1317
+# with the nonce made from the cards NONCEBODY.
1318
+#
1319
+proc xferserver_login_card {user password body {nonceBody ""}} {
1320
+ global xferserverLoginProject
1321
+ if {$nonceBody eq ""} {set nonceBody $body}
1322
+ set secret [sha1_text $xferserverLoginProject/$user/$password]
1323
+ set nonce [sha1_text $nonceBody]
1324
+ return "login $user $nonce [sha1_text $nonce$secret]"
1325
+}
1326
+
1327
+# The card is accepted when its nonce is the hash of the cards after it.
1328
+# A card with a nonce made from other cards is refused, although its
1329
+# signature fits that nonce.
1330
+xferserver_http "[xferserver_login_card tester secret \
1331
+ $xferserverLoginPull]\n$xferserverLoginPull" {} 127.0.0.1
1332
+test xfer-login-http-accepted \
1333
+ {$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]}
1334
+xferserver_http "[xferserver_login_card tester secret $xferserverLoginPull \
1335
+ "other cards\n"]\n$xferserverLoginPull" {} 127.0.0.1
1336
+test xfer-login-http-nonce-of-other-cards \
1337
+ {$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]}
1338
+
1339
+# A signature that is not as long as a hash is refused.
1340
+foreach {xferserverLoginName xferserverLoginSig} [list \
1341
+ short-signature abc \
1342
+ long-signature [string repeat a 41] \
1343
+] {
1344
+ xferserver_http "login tester [sha1_text $xferserverLoginPull]\
1345
+ $xferserverLoginSig\n$xferserverLoginPull" {} 127.0.0.1
1346
+ test xfer-login-http-$xferserverLoginName \
1347
+ {$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]}
1348
+}
1349
+
1350
+# The same card in the cookie x-f-l-c logs the user in. A cookie that is
1351
+# not a login card of four words is ignored, and the request is that of
1352
+# "nobody".
1353
+set xferserverLoginCard \
1354
+ [xferserver_login_card tester secret $xferserverLoginPull]
1355
+foreach {xferserverLoginName xferserverLoginCookie xferserverLoginOk} [list \
1356
+ card $xferserverLoginCard 1 \
1357
+ three-words [lrange $xferserverLoginCard 0 2] 0 \
1358
+ longer-word [lreplace $xferserverLoginCard 0 0 logins] 0 \
1359
+ other-word [lreplace $xferserverLoginCard 0 0 logix] 0 \
1360
+] {
1361
+ xferserver_http $xferserverLoginPull [list \
1362
+ "Cookie: x-f-l-c=[string map {{ } %20} $xferserverLoginCookie]"] \
1363
+ 127.0.0.1
1364
+ set xferserverLoginWant [expr {$xferserverLoginOk
1365
+ ? {"igot " "errors 0"} : {{error not\sauthorized\sto\sread} "!igot "}}]
1366
+ test xfer-login-cookie-$xferserverLoginName \
1367
+ {$CODE == 0 && [holds_strings $RESULT $xferserverLoginWant]}
1368
+}
1369
+
1370
+# With --localauth a request from this machine needs no login, unless the
1371
+# localauth setting is on; the refusal then says so. A request from
1372
+# another machine is refused without that reason.
1373
+xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
1374
+test xfer-login-localauth-local \
1375
+ {$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]}
1376
+xferserver_http $xferserverLoginPull {} 10.1.2.3 --localauth
1377
+test xfer-login-localauth-other-machine {$CODE == 0 && [holds_strings $RESULT \
1378
+ {{error not\sauthorized\sto\sread} "!localauth" "!igot "}]}
1379
+xferserver_sql "REPLACE INTO config(name,value,mtime)
1380
+ VALUES('localauth',1,now())"
1381
+xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
1382
+test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \
1383
+ {{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting}
1384
+ "!igot "}]}
1385
+xferserver_sql "DELETE FROM config WHERE name='localauth'"
1386
+
1387
+unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
1388
+unset ::env(SCN_PROJECT)
1389
+
1390
+xferserver_leave
1391
+
1392
+###############################################################################
1393
+# Checks on the server side of the protocol that each decide on several
1394
+# conditions: check-in locks, clones with private content and with content
1395
+# that an old client cannot take, the limits on what the server sends, new
1396
+# clusters, and the way "fossil test-xfer" reads its message. Each case has
1397
+# one input that changes only one of the conditions.
1398
+#
1399
+# The server is a repository of its own with a public check-in, then three
1400
+# private ones on top of it; the first of the three is then made public. So
1401
+# it holds a public artifact stored as a delta of a private one, a private
1402
+# artifact stored as a delta of another private one, and a public artifact
1403
+# stored as a delta of a public one.
1404
+
1405
+xferserver_enter mcdc
1406
+
1407
+proc xferserver_mcdc_sql {sql} {
1408
+ fossil sql -R srv.fossil $sql
1409
+ return [string trim $::RESULT]
1410
+}
1411
+
1412
+# Send MESSAGE to the server and set RESULT and CODE.
1413
+proc xferserver_mcdc_send {message} {
1414
+ write_file msg.txt $message
1415
+ fossil_raw test-xfer -R srv.fossil msg.txt
1416
+}
1417
+
1418
+# Test NAME passes when the reply to MESSAGE holds each of the strings
1419
+# given, and none that begins with "!".
1420
+proc xferserver_mcdc_expect {name message args} {
1421
+ xferserver_mcdc_send $message
1422
+ test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
1423
+}
1424
+
1425
+set xferserverMcdcText ""
1426
+for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} {
1427
+ append xferserverMcdcText "line $xferserverMcdcI of a file that is worth a delta\n"
1428
+}
1429
+write_file a.txt $xferserverMcdcText
1430
+fossil add a.txt
1431
+fossil commit -m public-1 --no-warnings
1432
+foreach xferserverMcdcI {2 3 4} {
1433
+ append xferserverMcdcText "version $xferserverMcdcI\n"
1434
+ write_file a.txt $xferserverMcdcText
1435
+ fossil commit -m private-$xferserverMcdcI --private --no-warnings
1436
+}
1437
+# The blob of the file in each version.
1438
+proc xferserverMcdc_fid {comment} {
1439
+ fossil sql "SELECT mlink.fid FROM mlink, event WHERE mlink.mid=event.objid
1440
+ AND event.comment='$comment'"
1441
+ return [string trim $::RESULT]
1442
+}
1443
+# Version 2 becomes public while it is stored as a delta of the private
1444
+# version 3, and version 1 becomes a delta of version 2.
1445
+fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT objid FROM event
1446
+ WHERE comment='private-2')"
1447
+fossil publish [string trim $RESULT]
1448
+fossil test-content-deltify [xferserverMcdc_fid public-1] \
1449
+ [xferserverMcdc_fid private-2]
1450
+file copy .rep.fossil srv.fossil
1451
+set xferserverMcdcPcode [xferserver_mcdc_sql \
1452
+ "SELECT value FROM config WHERE name='project-code'"]
1453
+set xferserverMcdcTip [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE rid=
1454
+ (SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"]
1455
+set xferserverMcdcLogin "login tester 0 0\n"
1456
+set xferserverMcdcPull "pull x $xferserverMcdcPcode\n"
1457
+set xferserverMcdcPush "push x $xferserverMcdcPcode\n"
1458
+xferserver_mcdc_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'"
1459
+# A public check-in, named by a SHA3 hash.
1460
+set xferserverMcdcPublic [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE
1461
+ rid IN (SELECT objid FROM event WHERE type='ci')
1462
+ AND rid NOT IN (SELECT rid FROM private) LIMIT 1"]
1463
+
1464
+# A private artifact that is stored as a delta of another private artifact.
1465
+set xferserverMcdcDelta [xferserver_mcdc_sql "SELECT b.uuid FROM blob b, delta d,
1466
+ private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN
1467
+ (SELECT rid FROM private) LIMIT 1"]
1468
+test xfer-server-mcdc-setup-private-delta \
1469
+ {[string length $xferserverMcdcDelta] >= 40}
1470
+foreach xferserverMcdcI {1 2} {
1471
+ set xferserverMcdcFile($xferserverMcdcI) [xferserver_mcdc_sql \
1472
+ "SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \
1473
+ [lindex {x public-1 private-2} $xferserverMcdcI]]"]
1474
+}
1475
+lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1
1476
+lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2
1477
+test xfer-server-mcdc-setup-public-from-private {[xferserver_mcdc_sql "SELECT
1478
+ count(*) FROM delta d, private p WHERE d.rid=
1479
+ [xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1}
1480
+test xfer-server-mcdc-setup-public-from-public {[xferserver_mcdc_sql "SELECT
1481
+ count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1]
1482
+ AND d.srcid=[xferserverMcdc_fid private-2]"] == 1}
1483
+
1484
+###############################################################################
1485
+# A lock on a check-in is reported to a second client with the name of the
1486
+# user who holds it, "nobody" when the lock has no name or an empty one.
1487
+
1488
+set xferserverMcdcA [string repeat a 40]
1489
+set xferserverMcdcB [string repeat b 40]
1490
+foreach {xferserverMcdcName xferserverMcdcValue xferserverMcdcWho} {
1491
+ named {json_object('login','alice','clientid',$A)} alice
1492
+ empty {json_object('login','','clientid',$A)} nobody
1493
+ absent {json_object('clientid',$A)} nobody
1494
+} {
1495
+ set xferserverMcdcValue [string map \
1496
+ [list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue]
1497
+ xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*';
1498
+ REPLACE INTO config(name,value,mtime)
1499
+ VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())"
1500
+ xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \
1501
+ "$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\
1502
+ $xferserverMcdcTip $xferserverMcdcB\n" \
1503
+ "pragma ci-lock-fail $xferserverMcdcWho "
1504
+}
1505
+xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
1506
+
1507
+###############################################################################
1508
+# A clone of a server that has private artifacts. A client that does not
1509
+# ask for private content is sent none, and one that does is sent each of
1510
+# them behind a "private" card, a delta of a private artifact as a delta.
1511
+
1512
+xferserver_mcdc_expect clone-no-private \
1513
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1514
+ "cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta"
1515
+xferserver_mcdc_expect clone-private \
1516
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 3 1\n" \
1517
+ "private\ncfile $xferserverMcdcDelta "
1518
+# A public artifact whose source is private is sent whole: the card names no
1519
+# source.
1520
+xferserver_mcdc_expect clone-public-from-private \
1521
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1522
+ "cfile $xferserverMcdcHash2 $xferserverMcdcSize2 "
1523
+xferserver_mcdc_expect clone-public-from-public \
1524
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1525
+ "cfile $xferserverMcdcHash1 $xferserverMcdcHash2 $xferserverMcdcSize1 "
1526
+xferserver_mcdc_expect clone-v2-public-from-private \
1527
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
1528
+ "file $xferserverMcdcHash2 $xferserverMcdcSize2\n"
1529
+xferserver_mcdc_expect clone-v2-public-from-public \
1530
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
1531
+ "file $xferserverMcdcHash1 $xferserverMcdcHash2 "
1532
+xferserver_mcdc_expect clone-v2-private \
1533
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 2 1\n" \
1534
+ "private\nfile $xferserverMcdcDelta "
1535
+
1536
+###############################################################################
1537
+# Artifacts named by a SHA1 hash. A client that does not state its version
1538
+# is taken to be older than 2.0: it is sent them, and gets an error in place
1539
+# of an artifact named by a SHA3 hash.
1540
+
1541
+write_file sha1.txt "sha1 content\n"
1542
+fossil sha1sum sha1.txt
1543
+set xferserverMcdcSha1 [lindex $RESULT 0]
1544
+xferserver_mcdc_expect push-sha1 \
1545
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\
1546
+ $xferserverMcdcSha1 13\nsha1 content\n" "errors 0"
1547
+test xfer-server-mcdc-push-sha1-stored \
1548
+ {[xferserver_mcdc_sql "SELECT count(*) FROM blob WHERE
1549
+ uuid='$xferserverMcdcSha1' AND size=13"] == 1}
1550
+xferserver_mcdc_expect old-client-gimme-sha1 \
1551
+ "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \
1552
+ "file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil"
1553
+xferserver_mcdc_expect old-client-gimme-sha3 \
1554
+ "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \
1555
+ {error Fossil\sversion\s2.0\sor\slater\srequired} "!file $xferserverMcdcPublic"
1556
+xferserver_mcdc_expect old-client-clone-sha1 \
1557
+ "${xferserverMcdcLogin}clone 3 1\n" \
1558
+ "cfile $xferserverMcdcSha1 13 " {error Fossil\sversion\s2.0\sor\slater\srequired}
1559
+
1560
+###############################################################################
1561
+# A server whose send limit is reached stops sending files and tells the
1562
+# client in "igot" cards, and in "uvigot" cards for unversioned files.
1563
+
1564
+write_file note.txt "hi\n"
1565
+fossil unversioned add note.txt -R srv.fossil
1566
+xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime)
1567
+ VALUES('max-download','1',now())"
1568
+xferserver_mcdc_expect uvgimme-limit \
1569
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1570
+ note.txt\n" "uvigot note.txt " "!uvfile note.txt"
1571
+xferserver_mcdc_expect catalog-limit \
1572
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\
1573
+ send-catalog x\n" "igot " "errors 0"
1574
+xferserver_mcdc_sql "DELETE FROM config WHERE name='max-download'"
1575
+xferserver_mcdc_expect uvgimme-no-limit \
1576
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1577
+ note.txt\n" "uvfile note.txt " "!uvigot"
1578
+
1579
+# A client that does not state its version is sent an unversioned file
1580
+# that is named by a SHA1 hash, and gets an error in place of one named by
1581
+# a SHA3 hash.
1582
+fossil hash-policy sha1 -R srv.fossil
1583
+write_file old.txt "old\n"
1584
+fossil unversioned add old.txt -R srv.fossil
1585
+fossil hash-policy sha3 -R srv.fossil
1586
+test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_mcdc_sql "SELECT
1587
+ group_concat(length(hash)) FROM (SELECT hash FROM unversioned
1588
+ WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40"
1589
+xferserver_mcdc_expect old-client-uvgimme-sha1 \
1590
+ "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \
1591
+ "uvfile old.txt " "!error Fossil"
1592
+xferserver_mcdc_expect old-client-uvgimme-sha3 \
1593
+ "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme note.txt\n" \
1594
+ {error Fossil\sversion\s2.0\sor\slater\srequired} "!uvfile note.txt"
1595
+
1596
+###############################################################################
1597
+# A server has the number of seconds in max-download-time to make a reply.
1598
+# Once they have passed it sends no more artifacts: a client that asks for
1599
+# one is told in an "igot" card that the server has it, and a clone is told
1600
+# to ask again from where it was. Here the script that the server runs
1601
+# before it reads the request keeps it busy for more than one second.
1602
+
1603
+xferserver_mcdc_expect gimme-in-time \
1604
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1605
+ $xferserverMcdcPublic\n" "file $xferserverMcdcPublic "
1606
+set xferserverMcdcBusy {set s [expr {[utime]+[stime]}]}
1607
+append xferserverMcdcBusy \
1608
+ {; for {set t $s} {$t-$s < 1100000} {set t [expr {[utime]+[stime]}]} {}}
1609
+xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime) VALUES
1610
+ ('max-download-time','1',now()),
1611
+ ('xfer-common-script','$xferserverMcdcBusy',now())"
1612
+xferserver_mcdc_expect gimme-out-of-time \
1613
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1614
+ $xferserverMcdcPublic\n" \
1615
+ "igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0"
1616
+xferserver_mcdc_expect clone-out-of-time \
1617
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1618
+ "clone_seqno 1\n" "!cfile " "errors 0"
1619
+xferserver_mcdc_sql "DELETE FROM config
1620
+ WHERE name IN ('max-download-time','xfer-common-script')"
1621
+
1622
+###############################################################################
1623
+# A client that says where it can be reached is recorded when the address
1624
+# is an http or https one and does not name the local host.
1625
+
1626
+foreach {xferserverMcdcName xferserverMcdcUrl xferserverMcdcKept} {
1627
+ http http://example.org/a 1
1628
+ https https://example.org/b 1
1629
+ localhost http://localhost/c 0
1630
+ ssh ssh://example.org/d 0
1631
+} {
1632
+ xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'"
1633
+ xferserver_mcdc_expect client-url-$xferserverMcdcName \
1634
+ "${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\
1635
+ $xferserverMcdcUrl\n" "errors 0"
1636
+ test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \
1637
+ {[xferserver_mcdc_sql "SELECT count(*) FROM config
1638
+ WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept}
1639
+}
1640
+
1641
+###############################################################################
1642
+# "fossil test-xfer" reads the message from the file it is given, or from
1643
+# its standard input when it is given none, and takes no more arguments.
1644
+
1645
+fossil_raw -input "${xferserverMcdcLogin}${xferserverMcdcPull}" \
1646
+ test-xfer -R srv.fossil
1647
+test xfer-server-mcdc-test-xfer-stdin \
1648
+ {$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
1649
+fossil_raw test-xfer -R srv.fossil msg.txt msg.txt
1650
+test xfer-server-mcdc-test-xfer-extra-argument \
1651
+ {$CODE != 0 && [string first "Usage:" $RESULT] >= 0}
1652
+
1653
+xferserver_leave
1654
+
1655
+###############################################################################
1656
+# New clusters. A pull on a server with many artifacts that no cluster
1657
+# lists makes clusters of up to 800 artifacts, but not one that leaves
1658
+# 100 or fewer for the next. The artifacts here are inserted with their
1659
+# contents empty: only their names are listed in a cluster.
1660
+
1661
+foreach {xferserverMcdcName xferserverMcdcCount xferserverMcdcClusters} {
1662
+ few 700 1
1663
+ many 850 1
1664
+ more 1100 2
1665
+} {
1666
+ xferserver_enter mcdc-cluster-$xferserverMcdcName
1667
+ fossil sql "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM n
1668
+ WHERE i<$xferserverMcdcCount)
1669
+ INSERT INTO blob(rcvid,size,uuid,content)
1670
+ SELECT 1, 0, printf('%040x', i+1000000), x'' FROM n;
1671
+ INSERT OR IGNORE INTO unclustered
1672
+ SELECT rid FROM blob WHERE uuid GLOB '0000000000*'"
1673
+ fossil sql "SELECT value FROM config WHERE name='project-code'"
1674
+ set xferserverMcdcCode [string trim $RESULT]
1675
+ fossil sql "UPDATE user SET cap='o' WHERE login='nobody'"
1676
+ write_file msg.txt "pull x $xferserverMcdcCode\n"
1677
+ fossil_raw test-xfer -R .rep.fossil msg.txt
1678
+ test xfer-server-mcdc-cluster-$xferserverMcdcName-pull {$CODE == 0}
1679
+ fossil sql "SELECT count(*) FROM tagxref WHERE tagid=
1680
+ (SELECT tagid FROM tag WHERE tagname='cluster')"
1681
+ test_eq xfer-server-mcdc-cluster-$xferserverMcdcName-count \
1682
+ [string trim $RESULT] $xferserverMcdcClusters
1683
+ xferserver_leave
1684
+}
4201685
4211686
###############################################################################
4221687
4231688
test_cleanup
4241689
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -1,15 +1,20 @@
1 #
2 # Each kind of card and pragma of the sync protocol, sent to the server
3 # side through "fossil test-xfer", with and without valid card
4 # permissions. The server must give the documented answer and must not
5 # crash. xfer-cards.test has the cards with content.
6 #
7 # "fossil test-xfer" treats a login card as a grant of the Read, Write,
8 # Private and Admin permissions. A message without a login card runs
9 # with the permissions of the user "nobody", which these tests set.
10 #
 
 
 
 
 
11
12 require_no_open_checkout
13
14 test_setup
15
@@ -196,10 +201,32 @@
196 xferserver_expect write-client-url \
197 "${xferserverPush}pragma client-url http://example.org/x\n" "errors 0"
198 test xfer-server-write-client-url-recorded \
199 {[xferserver_count \
200 "config WHERE name GLOB 'syncfrom:*example.org*'"] == 1}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
202 ###############################################################################
203 # With a login card: private content, configuration, clone and locks.
204
205 xferserver_caps ""
@@ -239,10 +266,51 @@
239 }
240 xferserver_expect login-config-roundtrip \
241 "$xferserverLogin$xferserverPush$xferserverCards" "errors 0"
242 xferserver_expect login-config-negative-size \
243 "${xferserverLogin}config /project -5\n" {error bad\scommand:}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
245 # Clone, in each version of the protocol. A login card to test-xfer does
246 # not grant the Clone permission, so "nobody" is given it and these
247 # messages have no login card.
248 xferserver_caps "g"
@@ -349,10 +417,24 @@
349 # Links to other repositories of the project are given on request, except
350 # those on the local host.
351 xferserver_set syncwith:http://localhost:8080/y "{}"
352 xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \
353 "pragma link http://example.org/x" "!localhost:8080/y"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
355 # The address configuration is given only to a client that may read
356 # addresses.
357 xferserver_caps "oe"
358 xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0"
@@ -415,9 +497,1192 @@
415 # A repository with no project code cannot answer a pull or a push.
416 xferserver_unset project-code
417 xferserver_send "$xferserverLogin$xferserverPull"
418 test xfer-server-no-project-code \
419 {$CODE == 1 && [string first "missing project code" $RESULT] >= 0}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
421 ###############################################################################
422
423 test_cleanup
424
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -1,15 +1,20 @@
1 #
2 # Each kind of card and pragma of the sync protocol, sent to the server
3 # side through "fossil test-xfer", with and without valid card
4 # permissions. The server must give the documented answer and must not
5 # crash. The cards with content are in the sections at the end.
6 #
7 # "fossil test-xfer" treats a login card as a grant of the Read, Write,
8 # Private and Admin permissions. A message without a login card runs
9 # with the permissions of the user "nobody", which these tests set.
10 #
11
12 # These tests run only in a long pass: -assurance stress.
13 if {[test_assurance] ne "stress"} {
14 test_skip "runs only with -assurance stress"
15 }
16
17 require_no_open_checkout
18
19 test_setup
20
@@ -196,10 +201,32 @@
201 xferserver_expect write-client-url \
202 "${xferserverPush}pragma client-url http://example.org/x\n" "errors 0"
203 test xfer-server-write-client-url-recorded \
204 {[xferserver_count \
205 "config WHERE name GLOB 'syncfrom:*example.org*'"] == 1}
206 # A client URL that is not http or https is ignored and the request goes
207 # on; it is not read as a path on the server.
208 foreach {xferserverName xferserverUrl} {ftp ftp://example.org/y path /} {
209 xferserver_expect write-client-url-$xferserverName \
210 "${xferserverPush}pragma client-url $xferserverUrl\n" \
211 "!unknown repository" "errors 0"
212 }
213
214 # A first word that has the length of a card name and is not it selects no
215 # card. A pragma with a name of the length of a known one that is not it
216 # does nothing.
217 foreach {xferserverName xferserverBody} [list \
218 pull-other-word "pulx x $xferserverPcode\n" \
219 reqconfig-other-word "reqconfih /project\n" \
220 ] {
221 xferserver_expect bad-$xferserverName $xferserverBody \
222 {error bad\scommand:} "!config " "!igot "
223 }
224 xferserver_expect write-pragma-other-word \
225 "${xferserverPush}pragma client-urx http://example.net/w\n" "errors 0"
226 test xfer-server-write-pragma-other-word-not-recorded \
227 {[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0}
228
229 ###############################################################################
230 # With a login card: private content, configuration, clone and locks.
231
232 xferserver_caps ""
@@ -239,10 +266,51 @@
266 }
267 xferserver_expect login-config-roundtrip \
268 "$xferserverLogin$xferserverPush$xferserverCards" "errors 0"
269 xferserver_expect login-config-negative-size \
270 "${xferserverLogin}config /project -5\n" {error bad\scommand:}
271
272 # A value in a config card for a table must be a string or blob literal,
273 # an integer or NULL. A card with any other value is ignored, and the
274 # request goes on.
275 proc xferserver_config_user {content} {
276 global xferserverLogin xferserverPush
277 return "$xferserverLogin${xferserverPush}config /user\
278 [string length $content]\n$content\n"
279 }
280 foreach {xferserverName xferserverValue} {
281 word x column pw blob-not-hex X'zz' blob-odd X'abc'
282 } {
283 xferserver_expect config-value-$xferserverName [xferserver_config_user \
284 "1262304000 'cfgbad$xferserverName' info $xferserverValue"] \
285 "!Database error" "errors 0"
286 }
287 test_eq xfer-server-config-value-ignored \
288 [xferserver_count "user WHERE login GLOB 'cfgbad*'"] 0
289 foreach {xferserverName xferserverValue} {
290 string 'text' integer 7 null NULL blob X'00ff' empty-blob X''
291 } {
292 xferserver_expect config-value-$xferserverName [xferserver_config_user \
293 "1262304000 'cfgok$xferserverName' info $xferserverValue"] "errors 0"
294 }
295 test_eq xfer-server-config-value-stored \
296 [xferserver_count "user WHERE login GLOB 'cfgok*'"] 5
297
298 # A hash with a zero byte inside is not a hash. Each card that names an
299 # artifact by hash refuses it, and nothing is stored under a short hash.
300 set xferserverZeroHash "ceafb\000[string repeat a 58]"
301 foreach {xferserverName xferserverCard xferserverWant} [list \
302 igot "igot $xferserverZeroHash\n" {error bad\scommand:} \
303 gimme "gimme $xferserverZeroHash\n" {error bad\scommand:} \
304 file "file $xferserverZeroHash 3\nabc\n" "error malformed" \
305 ] {
306 xferserver_expect hash-zero-byte-$xferserverName \
307 "$xferserverLogin$xferserverPush$xferserverCard" \
308 "!Database error" $xferserverWant
309 }
310 test_eq xfer-server-hash-zero-byte-nothing-stored \
311 [xferserver_count "blob WHERE length(uuid)<40"] 0
312
313 # Clone, in each version of the protocol. A login card to test-xfer does
314 # not grant the Clone permission, so "nobody" is given it and these
315 # messages have no login card.
316 xferserver_caps "g"
@@ -349,10 +417,24 @@
417 # Links to other repositories of the project are given on request, except
418 # those on the local host.
419 xferserver_set syncwith:http://localhost:8080/y "{}"
420 xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \
421 "pragma link http://example.org/x" "!localhost:8080/y"
422 # A repository that is mirrored to Git has the address it pushes to among
423 # these links when that address is an http or https URL. An address that
424 # Git takes and that is not a URL is left out, and the reply goes on.
425 xferserver_set gitpush:https://git.example.org/someone/mirror.git "{}"
426 xferserver_set gitpush:[email protected]:someone/other.git "{}"
427 xferserver_set gitpush:[email protected]:someone/other.git "{}"
428 xferserver_send "${xferserverPull}pragma req-links\n"
429 test xfer-server-read-req-links-git-address \
430 {$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
431 test xfer-server-read-req-links-git-https \
432 {[string match "*pragma link https://git.example.org/someone/mirror.git*" $RESULT]}
433 test xfer-server-read-req-links-git-other-left-out \
434 {![string match "*other.git*" $RESULT]}
435 xferserver_unset gitpush:*
436
437 # The address configuration is given only to a client that may read
438 # addresses.
439 xferserver_caps "oe"
440 xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0"
@@ -415,9 +497,1192 @@
497 # A repository with no project code cannot answer a pull or a push.
498 xferserver_unset project-code
499 xferserver_send "$xferserverLogin$xferserverPull"
500 test xfer-server-no-project-code \
501 {$CODE == 1 && [string first "missing project code" $RESULT] >= 0}
502
503 ###############################################################################
504 # The sections below each run in a directory of their own, with a repository
505 # and a checkout of their own inside this one.
506
507 set xferserverDir [pwd]
508 proc xferserver_enter {name} {
509 global xferserverDir
510 file mkdir [file join $xferserverDir $name]
511 cd [file join $xferserverDir $name]
512 fossil new .rep.fossil
513 fossil open .rep.fossil --nested
514 fossil set mtime-changes off
515 }
516 proc xferserver_leave {} {
517 global xferserverDir
518 cd $xferserverDir
519 }
520
521 ###############################################################################
522 # Malformed "file", "cfile" and "uvfile" cards, sent to the server side
523 # of the sync protocol through "fossil test-xfer". The server must
524 # refuse each one and must not crash. These cards reach the checks in
525 # xfer_accept_file(), xfer_accept_compressed_file() and
526 # xfer_accept_unversioned_file() in src/xfer.c.
527
528 xferserver_enter cards
529
530 set xferserverCardsContent "hello world\n"
531 set xferserverCardsSize [string length $xferserverCardsContent]
532 write_file a.txt $xferserverCardsContent
533 fossil add a.txt
534 fossil commit -m one --no-warnings
535 fossil sha3sum a.txt
536 set xferserverCardsHash [lindex $RESULT 0]
537
538 fossil init tgt.fossil -A tester
539 fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'"
540 set xferserverCardsPcode [string trim $::RESULT]
541
542 # Push the cards in BODY to the target. test-xfer disables the login
543 # check, so the nonce and signature in the login card are ignored. The
544 # push card has the target's project code.
545 #
546 # Sets xferserverCardsCode to the exit status of fossil,
547 # xferserverCardsErrors to the number of errors that the reply reports, and
548 # xferserverCardsStored to 1 when the target now holds the source file.
549 proc xferserver_cards_push {body} {
550 global xferserverCardsHash xferserverCardsPcode
551 global xferserverCardsCode xferserverCardsErrors xferserverCardsStored
552 fossil sql -R tgt.fossil "DELETE FROM blob WHERE uuid='$xferserverCardsHash'"
553 write_file push.txt "login tester 0 0\npush x $xferserverCardsPcode\n$body"
554 fossil_raw test-xfer -R tgt.fossil push.txt
555 set xferserverCardsCode $::CODE
556 set xferserverCardsErrors 0
557 regexp {errors ([0-9]+)} $::RESULT -> xferserverCardsErrors
558 fossil sql -R tgt.fossil \
559 "SELECT count(*) FROM blob WHERE uuid='$xferserverCardsHash' AND size>=0"
560 set xferserverCardsStored [string trim $::RESULT]
561 }
562
563 xferserver_cards_push "file $xferserverCardsHash\
564 $xferserverCardsSize\n$xferserverCardsContent"
565 test xfer-cards-valid-accepted \
566 {$xferserverCardsCode == 0 && $xferserverCardsErrors == 0 &&
567 $xferserverCardsStored == 1}
568
569 set xferserverCardsZeros [string repeat 0 64]
570 set xferserverCardsUv "uvfile note.txt 1700000000"
571 foreach {xferserverCardsName xferserverCardsBody} [list \
572 too-few-tokens "file $xferserverCardsHash\n" \
573 bad-hash-name \
574 "file nothash $xferserverCardsSize\n$xferserverCardsContent" \
575 bad-size-int \
576 "file $xferserverCardsHash notint\n$xferserverCardsContent" \
577 bad-delta-source \
578 "file $xferserverCardsHash zz\
579 $xferserverCardsSize\n$xferserverCardsContent" \
580 size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \
581 size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \
582 size-at-end "file $xferserverCardsHash 5\n" \
583 size-with-nul "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \
584 content-wrong-hash \
585 "file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \
586 cfile-too-few "cfile $xferserverCardsHash\n" \
587 cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \
588 uvfile-too-few "uvfile note.txt\n" \
589 uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \
590 uvfile-mtime-nul "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \
591 uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \
592 uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \
593 uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \
594 uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \
595 uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \
596 ] {
597 xferserver_cards_push $xferserverCardsBody
598 test xfer-cards-reject-$xferserverCardsName \
599 {$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 &&
600 $xferserverCardsStored == 0}
601 }
602
603 # A client that does not send a version is treated as older than 2.0 and
604 # cannot be sent a SHA3 hash. When such a client asks for an unversioned
605 # file the server answers with an error; a current client gets the file.
606 write_file note.txt "hi\n"
607 fossil unversioned add note.txt -R tgt.fossil --user tester
608 set xferserverCardsUvgimme \
609 "login tester 0 0\npull x $xferserverCardsPcode\nuvgimme note.txt\n"
610 write_file uvgimme.txt $xferserverCardsUvgimme
611 fossil_raw test-xfer -R tgt.fossil uvgimme.txt
612 test xfer-cards-uvgimme-old-client \
613 {$CODE == 0
614 && [holds_strings $RESULT [list {or\slater\srequired} "!uvfile note.txt"]]}
615 write_file uvgimme.txt $CLIENT_VERSION_CARD$xferserverCardsUvgimme
616 fossil_raw test-xfer -R tgt.fossil uvgimme.txt
617 test xfer-cards-uvgimme-current-client \
618 {$CODE == 0 && [string first "uvfile note.txt" $RESULT] >= 0}
619
620 fossil sql -R tgt.fossil \
621 "INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)"
622 xferserver_cards_push "file $xferserverCardsHash\
623 $xferserverCardsSize\n$xferserverCardsContent"
624 test xfer-cards-reject-shunned \
625 {$xferserverCardsCode == 0 && $xferserverCardsStored == 0}
626
627 xferserver_leave
628
629 ###############################################################################
630 # More cards sent to the server side of the sync protocol through
631 # "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme"
632 # and "uvgimme" that xfer-cards.test and xfer-server.test do not send.
633 # Each has a stated effect on the server's repository or on the reply,
634 # and none may crash.
635 #
636 # The messages carry no login card, so they run with the permissions of
637 # the user "nobody", which these tests set.
638 #
639
640
641 xferserver_enter edge
642
643 # The answer of one SQL statement on the server, trimmed.
644 #
645 proc xferserver_sql {sql} {
646 fossil sql -R srv.fossil $sql
647 return [string trim $::RESULT]
648 }
649
650 # Send the cards BODY to the server after a client-version card and a
651 # card of KIND, which is "push" or "pull". RESULT is the reply, as
652 # bytes. xferserverEdgeErrors is the number of errors that the reply reports,
653 # or -1 if it reports none at all.
654 #
655 proc xferserver_edge_send {kind body} {
656 global xferserverEdgePcode xferserverEdgeErrors CLIENT_VERSION_CARD
657 write_file msg.txt "${CLIENT_VERSION_CARD}$kind x $xferserverEdgePcode\n$body"
658 fossil_raw test-xfer -R srv.fossil msg.txt
659 set xferserverEdgeErrors -1
660 regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors
661 }
662
663 # The hash that Fossil gives TEXT.
664 #
665 proc xferserver_hash {text} {
666 write_file hash-me.txt $text
667 fossil sha3sum hash-me.txt
668 return [lindex $::RESULT 0]
669 }
670
671 # Content as a "cfile" card carries it: the size, then the zlib stream.
672 #
673 proc xferserver_compress {text} {
674 return [binary format I [string length $text]][zlib compress $text]
675 }
676
677 # 1 if the server holds the content of the artifact HASH.
678 #
679 proc xferserver_holds {hash} {
680 return [xferserver_sql "SELECT count(*) FROM blob
681 WHERE uuid='$hash' AND size>=0"]
682 }
683
684 # Remove every trace of the artifacts HASHES from the server.
685 #
686 proc xferserver_forget {hashes} {
687 set list '[join $hashes ',']'
688 xferserver_sql "CREATE TEMP TABLE gone AS
689 SELECT rid FROM blob WHERE uuid IN ($list);
690 DELETE FROM delta WHERE rid IN gone OR srcid IN gone;
691 DELETE FROM phantom WHERE rid IN gone;
692 DELETE FROM unclustered WHERE rid IN gone;
693 DELETE FROM private WHERE rid IN gone;
694 DELETE FROM blob WHERE rid IN gone"
695 }
696
697 # Three versions of one file, so that the server stores deltas.
698 set xferserverEdgeText ""
699 for {set xferserverEdgeI 0} {$xferserverEdgeI < 40} {incr xferserverEdgeI} {
700 append xferserverEdgeText \
701 "line $xferserverEdgeI of a file that is worth a delta\n"
702 }
703 foreach xferserverEdgeI {1 2 3} {
704 append xferserverEdgeText "version $xferserverEdgeI\n"
705 write_file a.txt $xferserverEdgeText
706 if {$xferserverEdgeI == 1} {fossil add a.txt}
707 fossil commit -m "xferedge-v$xferserverEdgeI" --no-warnings
708 set xferserverEdgeVersion($xferserverEdgeI) $xferserverEdgeText
709 }
710 file copy .rep.fossil srv.fossil
711 fossil unversioned list -R srv.fossil
712 set xferserverEdgePcode [xferserver_sql \
713 "SELECT value FROM config WHERE name='project-code'"]
714 xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'"
715 set xferserverEdgeAbsent [string repeat 0123456789abcdef 4]
716
717 ###############################################################################
718 # "file" cards.
719
720 set xferserverEdgeNew "content that the server does not have yet\n"
721 set xferserverEdgeNewHash [xferserver_hash $xferserverEdgeNew]
722 set xferserverEdgeLen [string length $xferserverEdgeNew]
723
724 foreach {xferserverEdgeName xferserverEdgeCard} [list \
725 too-many-tokens \
726 "file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\
727 $xferserverEdgeLen\n$xferserverEdgeNew" \
728 negative-size "file $xferserverEdgeNewHash -1\n$xferserverEdgeNew" \
729 ] {
730 xferserver_edge_send push $xferserverEdgeCard
731 test xfer-edge-file-$xferserverEdgeName \
732 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
733 ![xferserver_holds $xferserverEdgeNewHash]}
734 }
735
736 # A delta whose source the server does not have is kept as it is, with a
737 # phantom for the source, and is public.
738 xferserver_edge_send push \
739 "file $xferserverEdgeNewHash $xferserverEdgeAbsent 9\nnot-delta"
740 test xfer-edge-file-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0}
741 test_eq xfer-edge-file-dangling-delta-stored [xferserver_sql "SELECT
742 (SELECT size FROM blob WHERE uuid='$xferserverEdgeAbsent'),
743 (SELECT count(*) FROM delta, blob a, blob b WHERE delta.rid=a.rid
744 AND delta.srcid=b.rid AND a.uuid='$xferserverEdgeNewHash'
745 AND b.uuid='$xferserverEdgeAbsent'),
746 (SELECT count(*) FROM private, blob WHERE private.rid=blob.rid
747 AND uuid='$xferserverEdgeNewHash')"] {-1|1|0}
748 xferserver_forget [list $xferserverEdgeNewHash $xferserverEdgeAbsent]
749
750 ###############################################################################
751 # "cfile" cards.
752
753 set xferserverEdgeZ [xferserver_compress $xferserverEdgeNew]
754 set xferserverEdgeZLen [string length $xferserverEdgeZ]
755 foreach {xferserverEdgeName xferserverEdgeCard} [list \
756 too-many-tokens \
757 "cfile $xferserverEdgeNewHash $xferserverEdgeAbsent 1 $xferserverEdgeLen\
758 $xferserverEdgeZLen\n$xferserverEdgeZ" \
759 bad-hash \
760 "cfile nothash $xferserverEdgeLen $xferserverEdgeZLen\n$xferserverEdgeZ" \
761 bad-usize \
762 "cfile $xferserverEdgeNewHash notint\
763 $xferserverEdgeZLen\n$xferserverEdgeZ" \
764 bad-csize \
765 "cfile $xferserverEdgeNewHash $xferserverEdgeLen notint\n$xferserverEdgeZ" \
766 negative-usize \
767 "cfile $xferserverEdgeNewHash -1 $xferserverEdgeZLen\n$xferserverEdgeZ" \
768 negative-csize \
769 "cfile $xferserverEdgeNewHash $xferserverEdgeLen -1\n$xferserverEdgeZ" \
770 bad-source \
771 "cfile $xferserverEdgeNewHash zz $xferserverEdgeLen\
772 $xferserverEdgeZLen\n$xferserverEdgeZ" \
773 ] {
774 xferserver_edge_send push $xferserverEdgeCard
775 test xfer-edge-cfile-$xferserverEdgeName \
776 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
777 ![xferserver_holds $xferserverEdgeNewHash]}
778 }
779
780 xferserver_edge_send push "cfile $xferserverEdgeNewHash $xferserverEdgeLen\
781 $xferserverEdgeZLen\n$xferserverEdgeZ"
782 test xfer-edge-cfile-accepted \
783 {$CODE == 0 && $xferserverEdgeErrors == 0 &&
784 [xferserver_holds $xferserverEdgeNewHash]}
785 fossil artifact $xferserverEdgeNewHash -R srv.fossil cfile.out
786 test_eq xfer-edge-cfile-content [read_file cfile.out] $xferserverEdgeNew
787
788 # The size recorded for the artifact is that of its content, not of its
789 # compressed form.
790 test_eq xfer-edge-cfile-size-recorded [xferserver_sql "SELECT size FROM blob
791 WHERE uuid='$xferserverEdgeNewHash'"] $xferserverEdgeLen
792
793 # Content that does not have the hash or the size on the card is refused
794 # with an error, as it is for a "file" card.
795 set xferserverEdgeWrong "content that is not what its card says\n"
796 set xferserverEdgeZ [xferserver_compress $xferserverEdgeWrong]
797 xferserver_edge_send push "cfile $xferserverEdgeAbsent\
798 [string length $xferserverEdgeWrong]\
799 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
800 test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0}
801 test xfer-edge-cfile-wrong-hash-not-stored \
802 {![xferserver_holds $xferserverEdgeAbsent]}
803 set xferserverEdgeSized "content with the wrong size on its card\n"
804 set xferserverEdgeSizedHash [xferserver_hash $xferserverEdgeSized]
805 set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized]
806 xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\
807 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
808 test xfer-edge-cfile-wrong-size \
809 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
810 ![xferserver_holds $xferserverEdgeSizedHash]}
811 xferserver_edge_send push \
812 "cfile $xferserverEdgeAbsent 16 20\n\x00\x00\x00\x10not zlib data !!"
813 test xfer-edge-cfile-not-compressed \
814 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
815 ![xferserver_holds $xferserverEdgeAbsent]}
816
817 # A shunned artifact is not stored.
818 set xferserverEdgeShun "content that the server has shunned\n"
819 set xferserverEdgeShunHash [xferserver_hash $xferserverEdgeShun]
820 xferserver_sql "INSERT INTO shun(uuid,mtime)\
821 VALUES('$xferserverEdgeShunHash',0)"
822 set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun]
823 xferserver_edge_send push "cfile $xferserverEdgeShunHash\
824 [string length $xferserverEdgeShun]\
825 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
826 test xfer-edge-cfile-shunned \
827 {$CODE == 0 && ![xferserver_holds $xferserverEdgeShunHash]}
828
829 # A compressed delta whose source the server does not have is kept as it
830 # is. Its hash cannot be checked yet; its size can, and a delta that
831 # does not make content of the size on the card is refused.
832 set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4]
833 write_file delta-src.txt $xferserverEdgeVersion(1)
834 write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n"
835 fossil test-delta-create delta-src.txt delta-tgt.txt delta.out
836 set xferserverEdgeTgtHash [xferserver_hash [read_file delta-tgt.txt]]
837 set xferserverEdgeZ [xferserver_compress [read_file delta.out]]
838 xferserver_edge_send push "cfile $xferserverEdgeTgtHash\
839 $xferserverEdgeAbsent2 7777\
840 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
841 test xfer-edge-cfile-dangling-delta-wrong-size \
842 {$CODE == 0 && $xferserverEdgeErrors > 0}
843 xferserver_edge_send push "cfile $xferserverEdgeTgtHash $xferserverEdgeAbsent2\
844 [file size delta-tgt.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
845 test xfer-edge-cfile-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0}
846 test_eq xfer-edge-cfile-dangling-delta-stored [xferserver_sql "SELECT a.size
847 FROM delta, blob a WHERE delta.rid=a.rid
848 AND a.uuid='$xferserverEdgeTgtHash'"] \
849 [file size delta-tgt.txt]
850 xferserver_forget [list $xferserverEdgeTgtHash $xferserverEdgeAbsent2]
851
852 # Content that is too short to hold a size, or that is not compressed
853 # data, is refused as malformed, whether or not the card gives a size
854 # for the content.
855 foreach {xferserverEdgeName xferserverEdgeCard} [list \
856 short-content "cfile $xferserverEdgeAbsent 5 3\nabc\n" \
857 no-usize-short "cfile $xferserverEdgeAbsent 0 3\nabc\n" \
858 no-usize-not-compressed \
859 "cfile $xferserverEdgeAbsent 0 20\n\x00\x00\x00\x10not zlib data !!" \
860 ] {
861 xferserver_edge_send push $xferserverEdgeCard
862 test xfer-edge-cfile-$xferserverEdgeName \
863 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
864 [string first {malformed+cfile+content} $RESULT] >= 0 &&
865 ![xferserver_holds $xferserverEdgeAbsent]}
866 }
867
868 # A compressed delta whose source the server has is applied and checked.
869 # One that does not apply, and one that makes content with another hash
870 # than the card gives, are refused; one that makes the content that the
871 # card names is stored.
872 set xferserverEdgeSrcHash [xferserver_hash $xferserverEdgeVersion(1)]
873 test xfer-edge-cfile-delta-setup-source-held \
874 {[xferserver_holds $xferserverEdgeSrcHash] == 1}
875 write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n"
876 fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out
877 set xferserverEdgeTgt2Hash [xferserver_hash [read_file delta-tgt2.txt]]
878 set xferserverEdgeDelta [read_file delta2.out]
879 # The same delta without the checksum that ends it.
880 regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta
881 test xfer-edge-cfile-delta-setup-cut \
882 {[string length $xferserverEdgeBadDelta] > 0 &&
883 [string length $xferserverEdgeBadDelta]
884 < [string length $xferserverEdgeDelta]}
885 foreach {xferserverEdgeName xferserverEdgeHash xferserverEdgeBody
886 xferserverEdgeStored} [list \
887 does-not-apply $xferserverEdgeTgt2Hash $xferserverEdgeBadDelta 0 \
888 other-hash $xferserverEdgeAbsent2 $xferserverEdgeDelta 0 \
889 accepted $xferserverEdgeTgt2Hash $xferserverEdgeDelta 1 \
890 ] {
891 set xferserverEdgeZ [xferserver_compress $xferserverEdgeBody]
892 xferserver_edge_send push "cfile $xferserverEdgeHash $xferserverEdgeSrcHash\
893 [file size delta-tgt2.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
894 test xfer-edge-cfile-delta-$xferserverEdgeName \
895 {$CODE == 0 && ($xferserverEdgeErrors > 0) != $xferserverEdgeStored
896 && [xferserver_holds $xferserverEdgeHash] == $xferserverEdgeStored}
897 }
898 fossil artifact $xferserverEdgeTgt2Hash -R srv.fossil cfile-delta.out
899 test_eq xfer-edge-cfile-delta-content [read_file cfile-delta.out] \
900 [read_file delta-tgt2.txt]
901 xferserver_forget [list $xferserverEdgeTgt2Hash]
902
903 ###############################################################################
904 # "uvfile" cards.
905
906 set xferserverEdgeUv "an unversioned note\n"
907 set xferserverEdgeUvHash [xferserver_hash $xferserverEdgeUv]
908 set xferserverEdgeUvLen [string length $xferserverEdgeUv]
909 proc xferserver_uv {name} {
910 return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL
911 FROM unversioned WHERE name='$name'"]
912 }
913
914 foreach {xferserverEdgeName xferserverEdgeCard} [list \
915 five-tokens \
916 "uvfile note.txt 1700000000 $xferserverEdgeUvHash\
917 $xferserverEdgeUvLen\n$xferserverEdgeUv" \
918 bad-filename \
919 "uvfile ../note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\
920 0\n$xferserverEdgeUv" \
921 ] {
922 xferserver_edge_send push $xferserverEdgeCard
923 test xfer-edge-uvfile-$xferserverEdgeName \
924 {$CODE == 0 && $xferserverEdgeErrors > 0}
925 }
926 test_eq xfer-edge-uvfile-none-stored [xferserver_sql \
927 "SELECT count(*) FROM unversioned"] 0
928
929 xferserver_edge_send push \
930 "uvfile note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\
931 0\n$xferserverEdgeUv"
932 test xfer-edge-uvfile-accepted {$CODE == 0 && $xferserverEdgeErrors == 0}
933 test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \
934 "1700000000|$xferserverEdgeUvLen|0|1"
935
936 # Content that compresses well is stored compressed.
937 set xferserverEdgeBig [string repeat "the same line again and again\n" 200]
938 set xferserverEdgeBigHash [xferserver_hash $xferserverEdgeBig]
939 xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\
940 [string length $xferserverEdgeBig] 0\n$xferserverEdgeBig"
941 test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \
942 "1700000000|[string length $xferserverEdgeBig]|1|1"
943
944 # The same content with a newer time and no content: only the time
945 # changes.
946 xferserver_edge_send push \
947 "uvfile note.txt 1700000500 $xferserverEdgeUvHash $xferserverEdgeUvLen 4\n"
948 test_eq xfer-edge-uvfile-time-only [xferserver_uv note.txt] \
949 "1700000500|$xferserverEdgeUvLen|0|1"
950
951 # Older content does not replace newer.
952 set xferserverEdgeOld "an older note\n"
953 xferserver_edge_send push "uvfile note.txt 1600000000\
954 [xferserver_hash $xferserverEdgeOld]\
955 [string length $xferserverEdgeOld] 0\n$xferserverEdgeOld"
956 test xfer-edge-uvfile-older {$CODE == 0}
957 test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash
958 FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash
959
960 # A newer deletion empties the file but keeps its name.
961 xferserver_edge_send push "uvfile note.txt 1700001000 - 0 1\n"
962 test xfer-edge-uvfile-delete {$CODE == 0 && $xferserverEdgeErrors == 0}
963 test_eq xfer-edge-uvfile-deleted [xferserver_uv note.txt] {1700001000|0|0|0}
964
965 # Without the permission to write unversioned files, nothing is stored.
966 xferserver_sql "UPDATE user SET cap='oi' WHERE login='nobody'"
967 xferserver_edge_send push \
968 "uvfile other.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\
969 0\n$xferserverEdgeUv"
970 test xfer-edge-uvfile-no-permission {$CODE == 0 && $xferserverEdgeErrors > 0}
971 test_eq xfer-edge-uvfile-no-permission-stored [xferserver_sql "SELECT count(*)
972 FROM unversioned WHERE name='other.txt'"] 0
973 xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'"
974
975 ###############################################################################
976 # "uvgimme" cards.
977
978 xferserver_edge_send pull "uvgimme big.txt\n"
979 test xfer-edge-uvgimme-file {$CODE == 0 && [string first \
980 "uvfile big.txt 1700000000 $xferserverEdgeBigHash [string length\
981 $xferserverEdgeBig] 0\n$xferserverEdgeBig" \
982 $RESULT] >= 0}
983 xferserver_edge_send pull "uvgimme note.txt\n"
984 test xfer-edge-uvgimme-deleted \
985 {$CODE == 0 &&
986 [string first "uvfile note.txt 1700001000 - 0 1\n" $RESULT] >= 0}
987 xferserver_edge_send pull "uvgimme no-such-file.txt\n"
988 test xfer-edge-uvgimme-unknown \
989 {$CODE == 0 && [string first "uvfile no-such-file.txt" $RESULT] < 0}
990
991 ###############################################################################
992 # "gimme" cards.
993
994 proc xferserver_file_hash {version} {
995 return [xferserver_sql "SELECT uuid FROM blob, mlink, event
996 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
997 AND event.comment='xferedge-v$version'"]
998 }
999 set xferserverEdgeV1 [xferserver_file_hash 1]
1000 set xferserverEdgeV2 [xferserver_file_hash 2]
1001 set xferserverEdgeV3 [xferserver_file_hash 3]
1002
1003 # The server sends a version as a delta from the version before it,
1004 # which the client is likely to have. The first version has none and
1005 # goes whole, although the server stores it as a delta.
1006 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1007 test xfer-edge-gimme-delta-from-parent \
1008 {$CODE == 0 &&
1009 [string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0}
1010 xferserver_edge_send pull "gimme $xferserverEdgeV1\n"
1011 test xfer-edge-gimme-whole {$CODE == 0 && [string first \
1012 "file $xferserverEdgeV1 [string length $xferserverEdgeVersion(1)]\n"\
1013 $RESULT] >= 0}
1014
1015 # An artifact that the server does not have, and one that it has
1016 # shunned, are not sent.
1017 xferserver_edge_send pull "gimme $xferserverEdgeAbsent\n"
1018 test xfer-edge-gimme-absent \
1019 {$CODE == 0 && [string first "file $xferserverEdgeAbsent" $RESULT] < 0}
1020 xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV3',0)"
1021 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1022 test xfer-edge-gimme-shunned \
1023 {$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0}
1024 xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV3'"
1025
1026 # A delta is not sent from a shunned source: the content goes whole.
1027 xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV2',0)"
1028 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1029 test xfer-edge-gimme-shunned-source {$CODE == 0 && [string first \
1030 "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\
1031 $RESULT] >= 0}
1032 xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV2'"
1033
1034 # A private artifact is not sent to a client that has not asked for
1035 # private content, and a delta is not sent from a private source.
1036 xferserver_sql "INSERT INTO private SELECT rid FROM blob
1037 WHERE uuid='$xferserverEdgeV3'"
1038 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1039 test xfer-edge-gimme-private \
1040 {$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0}
1041 xferserver_sql "DELETE FROM private"
1042 xferserver_sql "INSERT INTO private SELECT rid FROM blob
1043 WHERE uuid='$xferserverEdgeV2'"
1044 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1045 test xfer-edge-gimme-private-source {$CODE == 0 && [string first \
1046 "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\
1047 $RESULT] >= 0}
1048 xferserver_sql "DELETE FROM private"
1049
1050 # A delta is not sent from a version that the server holds only as a
1051 # delta whose own source has not arrived, because that version cannot be
1052 # rebuilt: the content goes whole.
1053 set xferserverEdgeMissing [string repeat 0a1b2c3d 8]
1054 set xferserverEdgeV2Src [xferserver_sql "SELECT srcid FROM delta, blob
1055 WHERE delta.rid=blob.rid AND uuid='$xferserverEdgeV2'"]
1056 xferserver_sql "INSERT INTO blob(rcvid,size,uuid)
1057 VALUES(0,-1,'$xferserverEdgeMissing');
1058 INSERT INTO phantom SELECT rid FROM blob
1059 WHERE uuid='$xferserverEdgeMissing';
1060 REPLACE INTO delta(rid,srcid) SELECT a.rid, b.rid FROM blob a, blob b
1061 WHERE a.uuid='$xferserverEdgeV2' AND b.uuid='$xferserverEdgeMissing'"
1062 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1063 test xfer-edge-gimme-source-cannot-be-rebuilt {$CODE == 0 && [string first \
1064 "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\
1065 $RESULT] >= 0}
1066 if {$xferserverEdgeV2Src eq ""} {
1067 xferserver_sql "DELETE FROM delta WHERE rid=(SELECT rid FROM blob
1068 WHERE uuid='$xferserverEdgeV2')"
1069 } else {
1070 xferserver_sql "UPDATE delta SET srcid=$xferserverEdgeV2Src
1071 WHERE rid=(SELECT rid FROM blob WHERE uuid='$xferserverEdgeV2')"
1072 }
1073 xferserver_forget [list $xferserverEdgeMissing]
1074 xferserver_edge_send pull "gimme $xferserverEdgeV3\n"
1075 test xfer-edge-gimme-delta-again \
1076 {$CODE == 0 &&
1077 [string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0}
1078
1079 fossil test-integrity -R srv.fossil
1080 test xfer-edge-integrity {$CODE == 0}
1081
1082 ###############################################################################
1083 # A repository that has never held an unversioned file has no table for
1084 # them. A request for one is answered like any other request for a file
1085 # that is not there.
1086
1087 fossil init fresh.fossil
1088 fossil sql -R fresh.fossil "UPDATE user SET cap='oiy' WHERE login='nobody'"
1089 fossil sql -R fresh.fossil "SELECT value FROM config WHERE name='project-code'"
1090 write_file msg.txt \
1091 "${CLIENT_VERSION_CARD}pull x [string trim $RESULT]\nuvgimme note.txt\n"
1092 fossil_raw test-xfer -R fresh.fossil msg.txt
1093 test xfer-edge-uvgimme-no-table \
1094 {$CODE == 0 && [string first "Database error" $RESULT] < 0}
1095
1096 xferserver_leave
1097
1098 ###############################################################################
1099 # The login card of the sync protocol, checked by a server as it is on a
1100 # network. A real client syncs with a real server through
1101 # standin/scenario-wire.tcl, which hands each request to "fossil http"
1102 # on the server's repository without --localauth, so the server decides
1103 # what the client may do from the login card alone. Fossil puts no login
1104 # card on a request that goes through a transport command, so the
1105 # stand-in adds the card, made as http_build_login_card() makes it.
1106
1107 xferserver_enter login
1108
1109 write_file a.txt "first\n"
1110 fossil add a.txt
1111 fossil commit -m "xferlogin-c1" --no-warnings
1112 file copy .rep.fossil srv.fossil
1113 file copy .rep.fossil cli.fossil
1114
1115 set xferserverLoginWire [file join [pwd] wire.tcl]
1116 file copy [file join $::testfiledir standin scenario-wire.tcl] \
1117 $xferserverLoginWire
1118 set xferserverLoginWire "\"[info nameofexecutable]\" \"$xferserverLoginWire\""
1119 set ::env(SCN_EXE) $::fossilexe
1120 set ::env(SCN_REPO) [file join [pwd] srv.fossil]
1121 set ::env(SCN_FAULT) 0
1122 set ::env(SCN_AUTH) 1
1123 fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'"
1124 set ::env(SCN_PROJECT) [string trim $RESULT]
1125
1126 # Sync the client with the server as USERINFO, which is "user:password"
1127 # or empty for no login card. VERB is pull, push or sync.
1128 #
1129 proc xferserver_login_sync {verb userinfo} {
1130 global xferserverLoginWire
1131 if {$userinfo ne ""} {set ::env(SCN_LOGIN) $userinfo}
1132 fossil_raw -seconds 60 $verb http://xferlogin.invalid/x --once \
1133 --transport-command $xferserverLoginWire -R cli.fossil
1134 unset -nocomplain ::env(SCN_LOGIN)
1135 }
1136
1137 # The number of artifacts with content that the repository holds.
1138 #
1139 proc xferserver_blobs {repo} {
1140 fossil sql -R $repo "SELECT count(*) FROM blob WHERE size>=0"
1141 return [string trim $::RESULT]
1142 }
1143
1144 # Give the server something that the client does not have.
1145 #
1146 proc xferserver_login_new_on_server {} {
1147 global xferserverLoginN
1148 write_file srv-[incr xferserverLoginN].txt \
1149 "content number $xferserverLoginN\n"
1150 fossil test-content-put srv-$xferserverLoginN.txt -R srv.fossil
1151 }
1152 set xferserverLoginN 0
1153
1154 # Nobody may do anything; the user "tester" may read and write.
1155 xferserver_sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')"
1156 fossil user new tester "" secret -R srv.fossil
1157 xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'"
1158 test_eq xfer-login-password-stored-hashed \
1159 [xferserver_sql "SELECT length(pw) FROM user WHERE login='tester'"] 40
1160
1161 ###############################################################################
1162 # With no login card the client is "nobody", who may not read.
1163
1164 xferserver_login_new_on_server
1165 set xferserverLoginBefore [xferserver_blobs cli.fossil]
1166 xferserver_login_sync pull ""
1167 test xfer-login-nobody-refused \
1168 {$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0}
1169 test_eq xfer-login-nobody-got-nothing [xferserver_blobs cli.fossil] \
1170 $xferserverLoginBefore
1171
1172 ###############################################################################
1173 # The right password gives the user's permissions.
1174
1175 xferserver_login_sync pull tester:secret
1176 test xfer-login-accepted {$CODE == 0}
1177 test_eq xfer-login-accepted-pulled [xferserver_blobs cli.fossil] \
1178 [expr {$xferserverLoginBefore + 1}]
1179
1180 # The same for a push.
1181 write_file cli-1.txt "content from the client\n"
1182 fossil test-content-put cli-1.txt -R cli.fossil
1183 set xferserverLoginBefore [xferserver_blobs srv.fossil]
1184 xferserver_login_sync push tester:secret
1185 test xfer-login-push-accepted {$CODE == 0}
1186 test_eq xfer-login-push-arrived [xferserver_blobs srv.fossil] \
1187 [expr {$xferserverLoginBefore + 1}]
1188
1189 ###############################################################################
1190 # A wrong password, and a user that the server does not know.
1191
1192 xferserver_login_new_on_server
1193 set xferserverLoginBefore [xferserver_blobs cli.fossil]
1194 foreach {xferserverLoginName xferserverLoginUser} {
1195 wrong-password tester:wrong
1196 unknown-user stranger:secret
1197 } {
1198 xferserver_login_sync pull $xferserverLoginUser
1199 test xfer-login-$xferserverLoginName \
1200 {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1201 test_eq xfer-login-$xferserverLoginName-got-nothing \
1202 [xferserver_blobs cli.fossil] \
1203 $xferserverLoginBefore
1204 }
1205
1206 # The special users cannot be logged in as with a password, whatever
1207 # password the server has for them.
1208 xferserver_sql "UPDATE user SET pw='secret', cap='oi' WHERE login='developer'"
1209 xferserver_login_sync pull developer:secret
1210 test xfer-login-special-user-refused {$CODE != 0}
1211 test_eq xfer-login-special-user-got-nothing [xferserver_blobs cli.fossil] \
1212 $xferserverLoginBefore
1213
1214 ###############################################################################
1215 # A user with read permission only may not push.
1216
1217 xferserver_sql "UPDATE user SET cap='o' WHERE login='tester'"
1218 write_file cli-2.txt "more content from the client\n"
1219 fossil test-content-put cli-2.txt -R cli.fossil
1220 set xferserverLoginSrvBefore [xferserver_blobs srv.fossil]
1221 xferserver_login_sync push tester:secret
1222 test xfer-login-push-without-write \
1223 {$CODE != 0 && [string first "not authorized to write" $RESULT] >= 0}
1224 test_eq xfer-login-push-without-write-nothing-arrived \
1225 [xferserver_blobs srv.fossil] $xferserverLoginSrvBefore
1226 xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'"
1227
1228 ###############################################################################
1229 # A server that keeps the password as the user typed it still accepts the
1230 # login, and still refuses a wrong password.
1231
1232 xferserver_sql "UPDATE user SET pw='secret' WHERE login='tester'"
1233 xferserver_login_sync pull tester:wrong
1234 test xfer-login-cleartext-wrong \
1235 {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1236 set xferserverLoginBefore [xferserver_blobs cli.fossil]
1237 xferserver_login_sync pull tester:secret
1238 test xfer-login-cleartext-accepted {$CODE == 0}
1239 test_eq xfer-login-cleartext-pulled [xferserver_blobs cli.fossil] \
1240 [expr {$xferserverLoginBefore + 1}]
1241
1242 ###############################################################################
1243 # A login card for "nobody" or "anonymous" is accepted without a
1244 # password, and gives the permissions of "nobody".
1245
1246 xferserver_login_new_on_server
1247 set xferserverLoginBefore [xferserver_blobs cli.fossil]
1248 foreach xferserverLoginUser {nobody anonymous} {
1249 xferserver_login_sync pull $xferserverLoginUser:anything
1250 test xfer-login-as-$xferserverLoginUser \
1251 {$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0}
1252 }
1253 xferserver_sql "UPDATE user SET cap='o' WHERE login='nobody'"
1254 xferserver_login_sync pull nobody:anything
1255 test xfer-login-as-nobody-who-may-read {$CODE == 0}
1256 test_eq xfer-login-as-nobody-pulled [xferserver_blobs cli.fossil] \
1257 [expr {$xferserverLoginBefore + 1}]
1258 xferserver_sql "UPDATE user SET cap='' WHERE login='nobody'"
1259
1260 ###############################################################################
1261 # A web server that has already checked the user's password says so in
1262 # REMOTE_USER. The login card of that user is then accepted whatever
1263 # its signature, but only if the remote_user_ok setting is on.
1264
1265 xferserver_login_new_on_server
1266 set xferserverLoginBefore [xferserver_blobs cli.fossil]
1267 set ::env(REMOTE_USER) tester
1268 xferserver_login_sync pull tester:wrong
1269 test xfer-login-remote-user-setting-off \
1270 {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1271 xferserver_sql "REPLACE INTO config(name,value,mtime)
1272 VALUES('remote_user_ok',1,now())"
1273 xferserver_login_sync pull stranger:wrong
1274 test xfer-login-remote-user-other-name \
1275 {$CODE != 0 && [string first "login failed" $RESULT] >= 0}
1276 test_eq xfer-login-remote-user-nothing-yet [xferserver_blobs cli.fossil] \
1277 $xferserverLoginBefore
1278 xferserver_login_sync pull tester:wrong
1279 test xfer-login-remote-user-accepted {$CODE == 0}
1280 test_eq xfer-login-remote-user-pulled [xferserver_blobs cli.fossil] \
1281 [expr {$xferserverLoginBefore + 1}]
1282 unset ::env(REMOTE_USER)
1283 xferserver_sql "DELETE FROM config WHERE name='remote_user_ok'"
1284
1285 ###############################################################################
1286 # Requests written here and given to "fossil http" as a web server gives
1287 # them, so that the login card can be wrong in one way at a time and can
1288 # come in a cookie.
1289
1290 set xferserverLoginProject $::env(SCN_PROJECT)
1291 set xferserverLoginPull "pull x $xferserverLoginProject\n"
1292
1293 # Give the server the cards BODY in a request with the extra header lines
1294 # HEADERS, from the address ADDRESS, with any more options for "fossil
1295 # http" in ARGS. RESULT is the reply without its header.
1296 #
1297 proc xferserver_http {body headers address args} {
1298 set request "POST /xfer HTTP/1.0\r\n"
1299 append request "Content-Type: application/x-fossil-debug\r\n"
1300 foreach header $headers {
1301 append request "$header\r\n"
1302 }
1303 append request "Content-Length: [string length $body]\r\n\r\n$body"
1304 write_file http-request.txt $request
1305 file delete http-reply.txt
1306 fossil_raw http --in http-request.txt --out http-reply.txt \
1307 --ipaddr $address srv.fossil {*}$args
1308 set reply ""
1309 if {[file exists http-reply.txt]} {
1310 set reply [read_file http-reply.txt]
1311 }
1312 set end [string first "\r\n\r\n" $reply]
1313 set ::RESULT [expr {$end < 0 ? "" : [string range $reply $end+4 end]}]
1314 }
1315
1316 # The login card of USER with PASSWORD for a message of the cards BODY,
1317 # with the nonce made from the cards NONCEBODY.
1318 #
1319 proc xferserver_login_card {user password body {nonceBody ""}} {
1320 global xferserverLoginProject
1321 if {$nonceBody eq ""} {set nonceBody $body}
1322 set secret [sha1_text $xferserverLoginProject/$user/$password]
1323 set nonce [sha1_text $nonceBody]
1324 return "login $user $nonce [sha1_text $nonce$secret]"
1325 }
1326
1327 # The card is accepted when its nonce is the hash of the cards after it.
1328 # A card with a nonce made from other cards is refused, although its
1329 # signature fits that nonce.
1330 xferserver_http "[xferserver_login_card tester secret \
1331 $xferserverLoginPull]\n$xferserverLoginPull" {} 127.0.0.1
1332 test xfer-login-http-accepted \
1333 {$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]}
1334 xferserver_http "[xferserver_login_card tester secret $xferserverLoginPull \
1335 "other cards\n"]\n$xferserverLoginPull" {} 127.0.0.1
1336 test xfer-login-http-nonce-of-other-cards \
1337 {$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]}
1338
1339 # A signature that is not as long as a hash is refused.
1340 foreach {xferserverLoginName xferserverLoginSig} [list \
1341 short-signature abc \
1342 long-signature [string repeat a 41] \
1343 ] {
1344 xferserver_http "login tester [sha1_text $xferserverLoginPull]\
1345 $xferserverLoginSig\n$xferserverLoginPull" {} 127.0.0.1
1346 test xfer-login-http-$xferserverLoginName \
1347 {$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]}
1348 }
1349
1350 # The same card in the cookie x-f-l-c logs the user in. A cookie that is
1351 # not a login card of four words is ignored, and the request is that of
1352 # "nobody".
1353 set xferserverLoginCard \
1354 [xferserver_login_card tester secret $xferserverLoginPull]
1355 foreach {xferserverLoginName xferserverLoginCookie xferserverLoginOk} [list \
1356 card $xferserverLoginCard 1 \
1357 three-words [lrange $xferserverLoginCard 0 2] 0 \
1358 longer-word [lreplace $xferserverLoginCard 0 0 logins] 0 \
1359 other-word [lreplace $xferserverLoginCard 0 0 logix] 0 \
1360 ] {
1361 xferserver_http $xferserverLoginPull [list \
1362 "Cookie: x-f-l-c=[string map {{ } %20} $xferserverLoginCookie]"] \
1363 127.0.0.1
1364 set xferserverLoginWant [expr {$xferserverLoginOk
1365 ? {"igot " "errors 0"} : {{error not\sauthorized\sto\sread} "!igot "}}]
1366 test xfer-login-cookie-$xferserverLoginName \
1367 {$CODE == 0 && [holds_strings $RESULT $xferserverLoginWant]}
1368 }
1369
1370 # With --localauth a request from this machine needs no login, unless the
1371 # localauth setting is on; the refusal then says so. A request from
1372 # another machine is refused without that reason.
1373 xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
1374 test xfer-login-localauth-local \
1375 {$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]}
1376 xferserver_http $xferserverLoginPull {} 10.1.2.3 --localauth
1377 test xfer-login-localauth-other-machine {$CODE == 0 && [holds_strings $RESULT \
1378 {{error not\sauthorized\sto\sread} "!localauth" "!igot "}]}
1379 xferserver_sql "REPLACE INTO config(name,value,mtime)
1380 VALUES('localauth',1,now())"
1381 xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
1382 test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \
1383 {{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting}
1384 "!igot "}]}
1385 xferserver_sql "DELETE FROM config WHERE name='localauth'"
1386
1387 unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
1388 unset ::env(SCN_PROJECT)
1389
1390 xferserver_leave
1391
1392 ###############################################################################
1393 # Checks on the server side of the protocol that each decide on several
1394 # conditions: check-in locks, clones with private content and with content
1395 # that an old client cannot take, the limits on what the server sends, new
1396 # clusters, and the way "fossil test-xfer" reads its message. Each case has
1397 # one input that changes only one of the conditions.
1398 #
1399 # The server is a repository of its own with a public check-in, then three
1400 # private ones on top of it; the first of the three is then made public. So
1401 # it holds a public artifact stored as a delta of a private one, a private
1402 # artifact stored as a delta of another private one, and a public artifact
1403 # stored as a delta of a public one.
1404
1405 xferserver_enter mcdc
1406
1407 proc xferserver_mcdc_sql {sql} {
1408 fossil sql -R srv.fossil $sql
1409 return [string trim $::RESULT]
1410 }
1411
1412 # Send MESSAGE to the server and set RESULT and CODE.
1413 proc xferserver_mcdc_send {message} {
1414 write_file msg.txt $message
1415 fossil_raw test-xfer -R srv.fossil msg.txt
1416 }
1417
1418 # Test NAME passes when the reply to MESSAGE holds each of the strings
1419 # given, and none that begins with "!".
1420 proc xferserver_mcdc_expect {name message args} {
1421 xferserver_mcdc_send $message
1422 test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
1423 }
1424
1425 set xferserverMcdcText ""
1426 for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} {
1427 append xferserverMcdcText "line $xferserverMcdcI of a file that is worth a delta\n"
1428 }
1429 write_file a.txt $xferserverMcdcText
1430 fossil add a.txt
1431 fossil commit -m public-1 --no-warnings
1432 foreach xferserverMcdcI {2 3 4} {
1433 append xferserverMcdcText "version $xferserverMcdcI\n"
1434 write_file a.txt $xferserverMcdcText
1435 fossil commit -m private-$xferserverMcdcI --private --no-warnings
1436 }
1437 # The blob of the file in each version.
1438 proc xferserverMcdc_fid {comment} {
1439 fossil sql "SELECT mlink.fid FROM mlink, event WHERE mlink.mid=event.objid
1440 AND event.comment='$comment'"
1441 return [string trim $::RESULT]
1442 }
1443 # Version 2 becomes public while it is stored as a delta of the private
1444 # version 3, and version 1 becomes a delta of version 2.
1445 fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT objid FROM event
1446 WHERE comment='private-2')"
1447 fossil publish [string trim $RESULT]
1448 fossil test-content-deltify [xferserverMcdc_fid public-1] \
1449 [xferserverMcdc_fid private-2]
1450 file copy .rep.fossil srv.fossil
1451 set xferserverMcdcPcode [xferserver_mcdc_sql \
1452 "SELECT value FROM config WHERE name='project-code'"]
1453 set xferserverMcdcTip [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE rid=
1454 (SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"]
1455 set xferserverMcdcLogin "login tester 0 0\n"
1456 set xferserverMcdcPull "pull x $xferserverMcdcPcode\n"
1457 set xferserverMcdcPush "push x $xferserverMcdcPcode\n"
1458 xferserver_mcdc_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'"
1459 # A public check-in, named by a SHA3 hash.
1460 set xferserverMcdcPublic [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE
1461 rid IN (SELECT objid FROM event WHERE type='ci')
1462 AND rid NOT IN (SELECT rid FROM private) LIMIT 1"]
1463
1464 # A private artifact that is stored as a delta of another private artifact.
1465 set xferserverMcdcDelta [xferserver_mcdc_sql "SELECT b.uuid FROM blob b, delta d,
1466 private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN
1467 (SELECT rid FROM private) LIMIT 1"]
1468 test xfer-server-mcdc-setup-private-delta \
1469 {[string length $xferserverMcdcDelta] >= 40}
1470 foreach xferserverMcdcI {1 2} {
1471 set xferserverMcdcFile($xferserverMcdcI) [xferserver_mcdc_sql \
1472 "SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \
1473 [lindex {x public-1 private-2} $xferserverMcdcI]]"]
1474 }
1475 lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1
1476 lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2
1477 test xfer-server-mcdc-setup-public-from-private {[xferserver_mcdc_sql "SELECT
1478 count(*) FROM delta d, private p WHERE d.rid=
1479 [xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1}
1480 test xfer-server-mcdc-setup-public-from-public {[xferserver_mcdc_sql "SELECT
1481 count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1]
1482 AND d.srcid=[xferserverMcdc_fid private-2]"] == 1}
1483
1484 ###############################################################################
1485 # A lock on a check-in is reported to a second client with the name of the
1486 # user who holds it, "nobody" when the lock has no name or an empty one.
1487
1488 set xferserverMcdcA [string repeat a 40]
1489 set xferserverMcdcB [string repeat b 40]
1490 foreach {xferserverMcdcName xferserverMcdcValue xferserverMcdcWho} {
1491 named {json_object('login','alice','clientid',$A)} alice
1492 empty {json_object('login','','clientid',$A)} nobody
1493 absent {json_object('clientid',$A)} nobody
1494 } {
1495 set xferserverMcdcValue [string map \
1496 [list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue]
1497 xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*';
1498 REPLACE INTO config(name,value,mtime)
1499 VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())"
1500 xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \
1501 "$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\
1502 $xferserverMcdcTip $xferserverMcdcB\n" \
1503 "pragma ci-lock-fail $xferserverMcdcWho "
1504 }
1505 xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
1506
1507 ###############################################################################
1508 # A clone of a server that has private artifacts. A client that does not
1509 # ask for private content is sent none, and one that does is sent each of
1510 # them behind a "private" card, a delta of a private artifact as a delta.
1511
1512 xferserver_mcdc_expect clone-no-private \
1513 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1514 "cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta"
1515 xferserver_mcdc_expect clone-private \
1516 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 3 1\n" \
1517 "private\ncfile $xferserverMcdcDelta "
1518 # A public artifact whose source is private is sent whole: the card names no
1519 # source.
1520 xferserver_mcdc_expect clone-public-from-private \
1521 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1522 "cfile $xferserverMcdcHash2 $xferserverMcdcSize2 "
1523 xferserver_mcdc_expect clone-public-from-public \
1524 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1525 "cfile $xferserverMcdcHash1 $xferserverMcdcHash2 $xferserverMcdcSize1 "
1526 xferserver_mcdc_expect clone-v2-public-from-private \
1527 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
1528 "file $xferserverMcdcHash2 $xferserverMcdcSize2\n"
1529 xferserver_mcdc_expect clone-v2-public-from-public \
1530 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
1531 "file $xferserverMcdcHash1 $xferserverMcdcHash2 "
1532 xferserver_mcdc_expect clone-v2-private \
1533 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 2 1\n" \
1534 "private\nfile $xferserverMcdcDelta "
1535
1536 ###############################################################################
1537 # Artifacts named by a SHA1 hash. A client that does not state its version
1538 # is taken to be older than 2.0: it is sent them, and gets an error in place
1539 # of an artifact named by a SHA3 hash.
1540
1541 write_file sha1.txt "sha1 content\n"
1542 fossil sha1sum sha1.txt
1543 set xferserverMcdcSha1 [lindex $RESULT 0]
1544 xferserver_mcdc_expect push-sha1 \
1545 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\
1546 $xferserverMcdcSha1 13\nsha1 content\n" "errors 0"
1547 test xfer-server-mcdc-push-sha1-stored \
1548 {[xferserver_mcdc_sql "SELECT count(*) FROM blob WHERE
1549 uuid='$xferserverMcdcSha1' AND size=13"] == 1}
1550 xferserver_mcdc_expect old-client-gimme-sha1 \
1551 "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \
1552 "file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil"
1553 xferserver_mcdc_expect old-client-gimme-sha3 \
1554 "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \
1555 {error Fossil\sversion\s2.0\sor\slater\srequired} "!file $xferserverMcdcPublic"
1556 xferserver_mcdc_expect old-client-clone-sha1 \
1557 "${xferserverMcdcLogin}clone 3 1\n" \
1558 "cfile $xferserverMcdcSha1 13 " {error Fossil\sversion\s2.0\sor\slater\srequired}
1559
1560 ###############################################################################
1561 # A server whose send limit is reached stops sending files and tells the
1562 # client in "igot" cards, and in "uvigot" cards for unversioned files.
1563
1564 write_file note.txt "hi\n"
1565 fossil unversioned add note.txt -R srv.fossil
1566 xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime)
1567 VALUES('max-download','1',now())"
1568 xferserver_mcdc_expect uvgimme-limit \
1569 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1570 note.txt\n" "uvigot note.txt " "!uvfile note.txt"
1571 xferserver_mcdc_expect catalog-limit \
1572 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\
1573 send-catalog x\n" "igot " "errors 0"
1574 xferserver_mcdc_sql "DELETE FROM config WHERE name='max-download'"
1575 xferserver_mcdc_expect uvgimme-no-limit \
1576 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1577 note.txt\n" "uvfile note.txt " "!uvigot"
1578
1579 # A client that does not state its version is sent an unversioned file
1580 # that is named by a SHA1 hash, and gets an error in place of one named by
1581 # a SHA3 hash.
1582 fossil hash-policy sha1 -R srv.fossil
1583 write_file old.txt "old\n"
1584 fossil unversioned add old.txt -R srv.fossil
1585 fossil hash-policy sha3 -R srv.fossil
1586 test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_mcdc_sql "SELECT
1587 group_concat(length(hash)) FROM (SELECT hash FROM unversioned
1588 WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40"
1589 xferserver_mcdc_expect old-client-uvgimme-sha1 \
1590 "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \
1591 "uvfile old.txt " "!error Fossil"
1592 xferserver_mcdc_expect old-client-uvgimme-sha3 \
1593 "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme note.txt\n" \
1594 {error Fossil\sversion\s2.0\sor\slater\srequired} "!uvfile note.txt"
1595
1596 ###############################################################################
1597 # A server has the number of seconds in max-download-time to make a reply.
1598 # Once they have passed it sends no more artifacts: a client that asks for
1599 # one is told in an "igot" card that the server has it, and a clone is told
1600 # to ask again from where it was. Here the script that the server runs
1601 # before it reads the request keeps it busy for more than one second.
1602
1603 xferserver_mcdc_expect gimme-in-time \
1604 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1605 $xferserverMcdcPublic\n" "file $xferserverMcdcPublic "
1606 set xferserverMcdcBusy {set s [expr {[utime]+[stime]}]}
1607 append xferserverMcdcBusy \
1608 {; for {set t $s} {$t-$s < 1100000} {set t [expr {[utime]+[stime]}]} {}}
1609 xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime) VALUES
1610 ('max-download-time','1',now()),
1611 ('xfer-common-script','$xferserverMcdcBusy',now())"
1612 xferserver_mcdc_expect gimme-out-of-time \
1613 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1614 $xferserverMcdcPublic\n" \
1615 "igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0"
1616 xferserver_mcdc_expect clone-out-of-time \
1617 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1618 "clone_seqno 1\n" "!cfile " "errors 0"
1619 xferserver_mcdc_sql "DELETE FROM config
1620 WHERE name IN ('max-download-time','xfer-common-script')"
1621
1622 ###############################################################################
1623 # A client that says where it can be reached is recorded when the address
1624 # is an http or https one and does not name the local host.
1625
1626 foreach {xferserverMcdcName xferserverMcdcUrl xferserverMcdcKept} {
1627 http http://example.org/a 1
1628 https https://example.org/b 1
1629 localhost http://localhost/c 0
1630 ssh ssh://example.org/d 0
1631 } {
1632 xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'"
1633 xferserver_mcdc_expect client-url-$xferserverMcdcName \
1634 "${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\
1635 $xferserverMcdcUrl\n" "errors 0"
1636 test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \
1637 {[xferserver_mcdc_sql "SELECT count(*) FROM config
1638 WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept}
1639 }
1640
1641 ###############################################################################
1642 # "fossil test-xfer" reads the message from the file it is given, or from
1643 # its standard input when it is given none, and takes no more arguments.
1644
1645 fossil_raw -input "${xferserverMcdcLogin}${xferserverMcdcPull}" \
1646 test-xfer -R srv.fossil
1647 test xfer-server-mcdc-test-xfer-stdin \
1648 {$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
1649 fossil_raw test-xfer -R srv.fossil msg.txt msg.txt
1650 test xfer-server-mcdc-test-xfer-extra-argument \
1651 {$CODE != 0 && [string first "Usage:" $RESULT] >= 0}
1652
1653 xferserver_leave
1654
1655 ###############################################################################
1656 # New clusters. A pull on a server with many artifacts that no cluster
1657 # lists makes clusters of up to 800 artifacts, but not one that leaves
1658 # 100 or fewer for the next. The artifacts here are inserted with their
1659 # contents empty: only their names are listed in a cluster.
1660
1661 foreach {xferserverMcdcName xferserverMcdcCount xferserverMcdcClusters} {
1662 few 700 1
1663 many 850 1
1664 more 1100 2
1665 } {
1666 xferserver_enter mcdc-cluster-$xferserverMcdcName
1667 fossil sql "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM n
1668 WHERE i<$xferserverMcdcCount)
1669 INSERT INTO blob(rcvid,size,uuid,content)
1670 SELECT 1, 0, printf('%040x', i+1000000), x'' FROM n;
1671 INSERT OR IGNORE INTO unclustered
1672 SELECT rid FROM blob WHERE uuid GLOB '0000000000*'"
1673 fossil sql "SELECT value FROM config WHERE name='project-code'"
1674 set xferserverMcdcCode [string trim $RESULT]
1675 fossil sql "UPDATE user SET cap='o' WHERE login='nobody'"
1676 write_file msg.txt "pull x $xferserverMcdcCode\n"
1677 fossil_raw test-xfer -R .rep.fossil msg.txt
1678 test xfer-server-mcdc-cluster-$xferserverMcdcName-pull {$CODE == 0}
1679 fossil sql "SELECT count(*) FROM tagxref WHERE tagid=
1680 (SELECT tagid FROM tag WHERE tagname='cluster')"
1681 test_eq xfer-server-mcdc-cluster-$xferserverMcdcName-count \
1682 [string trim $RESULT] $xferserverMcdcClusters
1683 xferserver_leave
1684 }
1685
1686 ###############################################################################
1687
1688 test_cleanup
1689

Keyboard Shortcuts

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