Fossil SCM

Add the transport and log-args stand-ins, and new test git-export. Move three tests from regress.test into delta1, wiki and git-export, and use the stand-ins.

danshearer 2026-11-27 15:52 UTC test-suite-new
Commit add095ba10ab2d10b5eb84f1215ef4add8360364a13a2dc4cfb9a35f528376fc
+5 -1
--- test/README.md
+++ test/README.md
@@ -95,10 +95,11 @@
9595
| `-assurance ci` or `stress` | `powerloss` |
9696
| `openssl` and a Fossil built with TLS support | the HTTPS tests in `http` |
9797
| `python3` | the tests in `http` that run `http-relay.py` |
9898
| a C compiler (`cc`, or `CC`), `LD_PRELOAD`, `tools/powerloss/powerloss.c` from the source tree, and a Fossil that isn't statically linked | `powerloss` |
9999
| a Unix shell | `ssh`, `xfer-client`, and the no-reply and merge-tool tests in `sync` and `regress` |
100
+| `git` | `git-export` |
100101
| `configure --json` | `json` |
101102
| `configure --with-th1-docs` | `th1-docs` |
102103
| `configure --with-th1-hooks` | `th1-hooks` |
103104
| `configure --with-tcl` | `th1-tcl` |
104105
@@ -117,20 +118,22 @@
117118
| Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `unicode-pathnames`, `update` | `smoke` |
118119
| Branches and tags | `branch-tag` | `smoke` |
119120
| Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` | `smoke` |
120121
| HTTP and HTTPS client | `http` | `smoke` |
121122
| Commands interrupted by a power loss or a killed process | `powerloss` | `ci` |
123
+| Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip`, `git-export` | `smoke` |
122124
| Diffs and deltas | `delta1`, `diff` | `smoke` |
123125
| Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` |
124126
| Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` |
125127
| TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` |
126128
| JSON API | `json` | `smoke` |
127129
| Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` |
128130
129131
## Fuzz inputs and run-time checking
130132
131
-| Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` |
133
+
134
+A build with ASan and UBSan reports memory errors and undefined behavior that a normal build does not detect. `tools/testbuild.sh asan DIR` makes such a build in `DIR`, and `make test` there runs the whole suite against it. `tools/testbuild.sh cov DIR` makes a build that records coverage, and `tools/testbuild.sh report DIR` then prints the branch coverage of each source file.
132135
133136
## Writing new tests
134137
135138
Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the
136139
executable being tested and sets `RESULT` to its output and `CODE` to 0 if the command succeeded and did not write anything to standard error, or 1 otherwise. `test_eq NAME ACTUAL EXPECTED` and `test_match NAME ACTUAL PATTERN`
@@ -161,10 +164,11 @@
161164
* Comment a procedure only if its name and arguments don't say what it does. Don't repeat the code in a comment.
162165
* Call your global variables what you like. `tester.tcl` removes them when your file ends, so two files can't collide. Don't set a variable that `tester.tcl` owns, such as `RESULT`, `CODE`, `testdir` or `fossilexe`.
163166
* If the file needs something the system might not have, call `test_skip` near the top so the summary shows it.
164167
* `fossil ARGS` counts output on standard error as a failure and can't tell a crash from an error. If your test expects either, reads the output as bytes, gives `fossil` input or needs a time limit, use `fossil_raw ARGS`, which sets `CODE` to the exit status, `crash` or `timeout`. Don't call `exec $::fossilexe` yourself.
165168
* Read a file with `read_file` and write one with `write_file`.
169
+* If a test needs a program to stand in for a server, `ssh` or a merge tool, look in `standin/` before writing another script inside a Tcl string. `test_standin NAME DESTINATION` copies one into the test's directory.
166170
* Keep lines within 80 columns.
167171
168172
A command that fails under `fossil_raw` isn't reported as an error, so
169173
check `CODE` yourself. Use `fossil_raw` when you need:
170174
171175
--- test/README.md
+++ test/README.md
@@ -95,10 +95,11 @@
95 | `-assurance ci` or `stress` | `powerloss` |
96 | `openssl` and a Fossil built with TLS support | the HTTPS tests in `http` |
97 | `python3` | the tests in `http` that run `http-relay.py` |
98 | a C compiler (`cc`, or `CC`), `LD_PRELOAD`, `tools/powerloss/powerloss.c` from the source tree, and a Fossil that isn't statically linked | `powerloss` |
99 | a Unix shell | `ssh`, `xfer-client`, and the no-reply and merge-tool tests in `sync` and `regress` |
 
100 | `configure --json` | `json` |
101 | `configure --with-th1-docs` | `th1-docs` |
102 | `configure --with-th1-hooks` | `th1-hooks` |
103 | `configure --with-tcl` | `th1-tcl` |
104
@@ -117,20 +118,22 @@
117 | Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `unicode-pathnames`, `update` | `smoke` |
118 | Branches and tags | `branch-tag` | `smoke` |
119 | Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` | `smoke` |
120 | HTTP and HTTPS client | `http` | `smoke` |
121 | Commands interrupted by a power loss or a killed process | `powerloss` | `ci` |
 
122 | Diffs and deltas | `delta1`, `diff` | `smoke` |
123 | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` |
124 | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` |
125 | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` |
126 | JSON API | `json` | `smoke` |
127 | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` |
128
129 ## Fuzz inputs and run-time checking
130
131 | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` |
 
132
133 ## Writing new tests
134
135 Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the
136 executable being tested and sets `RESULT` to its output and `CODE` to 0 if the command succeeded and did not write anything to standard error, or 1 otherwise. `test_eq NAME ACTUAL EXPECTED` and `test_match NAME ACTUAL PATTERN`
@@ -161,10 +164,11 @@
161 * Comment a procedure only if its name and arguments don't say what it does. Don't repeat the code in a comment.
162 * Call your global variables what you like. `tester.tcl` removes them when your file ends, so two files can't collide. Don't set a variable that `tester.tcl` owns, such as `RESULT`, `CODE`, `testdir` or `fossilexe`.
163 * If the file needs something the system might not have, call `test_skip` near the top so the summary shows it.
164 * `fossil ARGS` counts output on standard error as a failure and can't tell a crash from an error. If your test expects either, reads the output as bytes, gives `fossil` input or needs a time limit, use `fossil_raw ARGS`, which sets `CODE` to the exit status, `crash` or `timeout`. Don't call `exec $::fossilexe` yourself.
165 * Read a file with `read_file` and write one with `write_file`.
 
166 * Keep lines within 80 columns.
167
168 A command that fails under `fossil_raw` isn't reported as an error, so
169 check `CODE` yourself. Use `fossil_raw` when you need:
170
171
--- test/README.md
+++ test/README.md
@@ -95,10 +95,11 @@
95 | `-assurance ci` or `stress` | `powerloss` |
96 | `openssl` and a Fossil built with TLS support | the HTTPS tests in `http` |
97 | `python3` | the tests in `http` that run `http-relay.py` |
98 | a C compiler (`cc`, or `CC`), `LD_PRELOAD`, `tools/powerloss/powerloss.c` from the source tree, and a Fossil that isn't statically linked | `powerloss` |
99 | a Unix shell | `ssh`, `xfer-client`, and the no-reply and merge-tool tests in `sync` and `regress` |
100 | `git` | `git-export` |
101 | `configure --json` | `json` |
102 | `configure --with-th1-docs` | `th1-docs` |
103 | `configure --with-th1-hooks` | `th1-hooks` |
104 | `configure --with-tcl` | `th1-tcl` |
105
@@ -117,20 +118,22 @@
118 | Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `unicode-pathnames`, `update` | `smoke` |
119 | Branches and tags | `branch-tag` | `smoke` |
120 | Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` | `smoke` |
121 | HTTP and HTTPS client | `http` | `smoke` |
122 | Commands interrupted by a power loss or a killed process | `powerloss` | `ci` |
123 | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip`, `git-export` | `smoke` |
124 | Diffs and deltas | `delta1`, `diff` | `smoke` |
125 | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` |
126 | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` |
127 | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` |
128 | JSON API | `json` | `smoke` |
129 | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` |
130
131 ## Fuzz inputs and run-time checking
132
133
134 A build with ASan and UBSan reports memory errors and undefined behavior that a normal build does not detect. `tools/testbuild.sh asan DIR` makes such a build in `DIR`, and `make test` there runs the whole suite against it. `tools/testbuild.sh cov DIR` makes a build that records coverage, and `tools/testbuild.sh report DIR` then prints the branch coverage of each source file.
135
136 ## Writing new tests
137
138 Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the
139 executable being tested and sets `RESULT` to its output and `CODE` to 0 if the command succeeded and did not write anything to standard error, or 1 otherwise. `test_eq NAME ACTUAL EXPECTED` and `test_match NAME ACTUAL PATTERN`
@@ -161,10 +164,11 @@
164 * Comment a procedure only if its name and arguments don't say what it does. Don't repeat the code in a comment.
165 * Call your global variables what you like. `tester.tcl` removes them when your file ends, so two files can't collide. Don't set a variable that `tester.tcl` owns, such as `RESULT`, `CODE`, `testdir` or `fossilexe`.
166 * If the file needs something the system might not have, call `test_skip` near the top so the summary shows it.
167 * `fossil ARGS` counts output on standard error as a failure and can't tell a crash from an error. If your test expects either, reads the output as bytes, gives `fossil` input or needs a time limit, use `fossil_raw ARGS`, which sets `CODE` to the exit status, `crash` or `timeout`. Don't call `exec $::fossilexe` yourself.
168 * Read a file with `read_file` and write one with `write_file`.
169 * If a test needs a program to stand in for a server, `ssh` or a merge tool, look in `standin/` before writing another script inside a Tcl string. `test_standin NAME DESTINATION` copies one into the test's directory.
170 * Keep lines within 80 columns.
171
172 A command that fails under `fossil_raw` isn't reported as an error, so
173 check `CODE` yourself. Use `fossil_raw` when you need:
174
175
--- test/delta1.test
+++ test/delta1.test
@@ -75,8 +75,21 @@
7575
write_file t1 $f1
7676
write_file t2 $f2
7777
fossil test-delta t1 t2
7878
test delta-empty-$i {[normalize_result]=="ok"}
7979
}
80
+
81
+# A delta for a target of 2^24 bytes or more that has nothing in common
82
+# with its source overflowed its buffer by a byte or two. This shows
83
+# only in a build with run-time checking.
84
+#
85
+write_file tiny.txt "x\n"
86
+write_file big.txt [string repeat "0123456789abcde\n" 1048576]
87
+fossil test-delta-create tiny.txt big.txt big.delta
88
+test delta-large-create {$CODE == 0}
89
+fossil test-delta-apply tiny.txt big.delta big.out
90
+test delta-large-apply {$CODE == 0}
91
+test delta-large-same {[same_file big.txt big.out]}
92
+file delete tiny.txt big.txt big.out big.delta
8093
###############################################################################
8194
8295
test_cleanup
8396
--- test/delta1.test
+++ test/delta1.test
@@ -75,8 +75,21 @@
75 write_file t1 $f1
76 write_file t2 $f2
77 fossil test-delta t1 t2
78 test delta-empty-$i {[normalize_result]=="ok"}
79 }
 
 
 
 
 
 
 
 
 
 
 
 
 
80 ###############################################################################
81
82 test_cleanup
83
--- test/delta1.test
+++ test/delta1.test
@@ -75,8 +75,21 @@
75 write_file t1 $f1
76 write_file t2 $f2
77 fossil test-delta t1 t2
78 test delta-empty-$i {[normalize_result]=="ok"}
79 }
80
81 # A delta for a target of 2^24 bytes or more that has nothing in common
82 # with its source overflowed its buffer by a byte or two. This shows
83 # only in a build with run-time checking.
84 #
85 write_file tiny.txt "x\n"
86 write_file big.txt [string repeat "0123456789abcde\n" 1048576]
87 fossil test-delta-create tiny.txt big.txt big.delta
88 test delta-large-create {$CODE == 0}
89 fossil test-delta-apply tiny.txt big.delta big.out
90 test delta-large-apply {$CODE == 0}
91 test delta-large-same {[same_file big.txt big.out]}
92 file delete tiny.txt big.txt big.out big.delta
93 ###############################################################################
94
95 test_cleanup
96
--- test/derived.sql
+++ test/derived.sql
@@ -1,11 +1,10 @@
11
-- Print the tables of a Fossil repository that are derived from its
22
-- artifacts, with each record number replaced by the hash or name it
33
-- stands for and the rows in a fixed order. Two repositories that hold
44
-- the same artifacts should print the same text, and so should one
--- repository before and after "fossil rebuild". Used by integrity.test
--- and sync.test:
5
+-- repository before and after "fossil rebuild". integrity.test runs it:
56
--
67
-- fossil sql -R REPOSITORY <test/derived.sql
78
--
89
SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
910
user, euser, comment, ecomment, bgcolor, brief
1011
1112
ADDED test/git-export.test
--- test/derived.sql
+++ test/derived.sql
@@ -1,11 +1,10 @@
1 -- Print the tables of a Fossil repository that are derived from its
2 -- artifacts, with each record number replaced by the hash or name it
3 -- stands for and the rows in a fixed order. Two repositories that hold
4 -- the same artifacts should print the same text, and so should one
--- repository before and after "fossil rebuild". Used by integrity.test
--- and sync.test:
 
5 --
6 -- fossil sql -R REPOSITORY <test/derived.sql
7 --
8 SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
9 user, euser, comment, ecomment, bgcolor, brief
10
11 DDED test/git-export.test
--- test/derived.sql
+++ test/derived.sql
@@ -1,11 +1,10 @@
1 -- Print the tables of a Fossil repository that are derived from its
2 -- artifacts, with each record number replaced by the hash or name it
3 -- stands for and the rows in a fixed order. Two repositories that hold
4 -- the same artifacts should print the same text, and so should one
--- repository before and after "fossil rebuild". Used by integrity.test
--- and sync.test:
5 -- repository before and after "fossil rebuild". integrity.test runs it:
6 --
7 -- fossil sql -R REPOSITORY <test/derived.sql
8 --
9 SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime,
10 user, euser, comment, ecomment, bgcolor, brief
11
12 DDED test/git-export.test
--- a/test/git-export.test
+++ b/test/git-export.test
@@ -0,0 +1,37 @@
1
+##########################
2
+#
3
+# "fossil git export" of a check-in that holds a shunned file. The
4
+# file is to be exported as an empty file. An earlier fossil left the
5
+# check-in out of the export and exited with status 0.
6
+#
7
+
8
+require_no_open_checkout
9
+
10
+if {[catch {exec git --version}]} {
11
+ test_skip "git is not installed"
12
+}
13
+
14
+test_setup
15
+
16
+write_file keep.txt "keep\n"
17
+write_file shun.txt "first version\n"
18
+fossil add keep.txt shun.txt
19
+fossil commit -m "first"
20
+write_file shun.txt "second version, to be shunned\n"
21
+fossil commit -m "second"
22
+fossil sql "INSERT OR IGNORE INTO shun(uuid,mtime)\
23
+ SELECT b.uuid, 0 FROM blob b, mlink m, filename f\
24
+ WHERE m.fid=b.rid AND f.fnid=m.fnid AND f.name='shun.txt'\
25
+ AND m.mid=(SELECT max(mid) FROM mlink)"
26
+fossil rebuild
27
+
28
+# git writes progress to standard error, which the "fossil" procedure
29
+# counts as a failure.
30
+fossil_raw git export git-mirror
31
+test git-export-shunned-status {$CODE == 0}
32
+set gitexportLog [exec git -C git-mirror log --format=%s]
33
+test git-export-shunned-checkin {[string first second $gitexportLog] >= 0}
34
+set gitexportNew [exec git -C git-mirror cat-file -p HEAD:shun.txt]
35
+test git-export-shunned-empty {[string length $gitexportNew] == 0}
36
+set gitexportOld [exec git -C git-mirror cat-file -p HEAD~1:shun.txt]
37
+test git-export-shunned-o
--- a/test/git-export.test
+++ b/test/git-export.test
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/git-export.test
+++ b/test/git-export.test
@@ -0,0 +1,37 @@
1 ##########################
2 #
3 # "fossil git export" of a check-in that holds a shunned file. The
4 # file is to be exported as an empty file. An earlier fossil left the
5 # check-in out of the export and exited with status 0.
6 #
7
8 require_no_open_checkout
9
10 if {[catch {exec git --version}]} {
11 test_skip "git is not installed"
12 }
13
14 test_setup
15
16 write_file keep.txt "keep\n"
17 write_file shun.txt "first version\n"
18 fossil add keep.txt shun.txt
19 fossil commit -m "first"
20 write_file shun.txt "second version, to be shunned\n"
21 fossil commit -m "second"
22 fossil sql "INSERT OR IGNORE INTO shun(uuid,mtime)\
23 SELECT b.uuid, 0 FROM blob b, mlink m, filename f\
24 WHERE m.fid=b.rid AND f.fnid=m.fnid AND f.name='shun.txt'\
25 AND m.mid=(SELECT max(mid) FROM mlink)"
26 fossil rebuild
27
28 # git writes progress to standard error, which the "fossil" procedure
29 # counts as a failure.
30 fossil_raw git export git-mirror
31 test git-export-shunned-status {$CODE == 0}
32 set gitexportLog [exec git -C git-mirror log --format=%s]
33 test git-export-shunned-checkin {[string first second $gitexportLog] >= 0}
34 set gitexportNew [exec git -C git-mirror cat-file -p HEAD:shun.txt]
35 test git-export-shunned-empty {[string length $gitexportNew] == 0}
36 set gitexportOld [exec git -C git-mirror cat-file -p HEAD~1:shun.txt]
37 test git-export-shunned-o
--- test/integrity.test
+++ test/integrity.test
@@ -14,33 +14,40 @@
1414
require_no_open_checkout
1515
1616
test_setup ""
1717
set ::env(FOSSIL_USER) tester
1818
19
-# The hashes of the artifacts in REPO that are not phantoms, in order.
19
+# Returns the hashes of the artifacts in repository REPO that are not
20
+# phantoms, in order.
21
+#
2022
proc integrity_artifacts {repo} {
2123
fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0 ORDER BY uuid"
2224
return [normalize_result]
2325
}
2426
25
-# The check-ins in REPO with their parents and comments, in order of hash.
27
+# Returns the check-ins in repository REPO with their parents and
28
+# comments, in order of hash.
29
+#
2630
proc integrity_checkins {repo} {
2731
fossil sql -R $repo "SELECT b.uuid, coalesce(p.uuid,''), e.comment\
2832
FROM event e JOIN blob b ON b.rid=e.objid\
2933
LEFT JOIN plink ON cid=e.objid LEFT JOIN blob p ON p.rid=pid\
3034
WHERE e.type='ci' ORDER BY b.uuid"
3135
return [normalize_result]
3236
}
3337
34
-# Test NAME passes when "fossil test-integrity --parse" finds no problems.
38
+# Test NAME passes when "fossil test-integrity --parse" finds no
39
+# problems in repository REPO.
40
+#
3541
proc integrity_ok {name repo} {
3642
fossil test-integrity --parse -R $repo
3743
test_match $name [normalize_result] {checked: 0 errors}
3844
}
3945
40
-# The derived tables of REPO as text that does not depend on record
41
-# numbers. See derived.sql.
46
+# Returns the derived tables of repository REPO as text that does not
47
+# depend on record numbers. See derived.sql.
48
+#
4249
proc integrity_derived {repo} {
4350
fossil sql -R $repo ".read [file join $::testfiledir derived.sql]"
4451
return $::RESULT
4552
}
4653
@@ -50,11 +57,12 @@
5057
file mkdir ck
5158
cd ck
5259
fossil open ../r.fossil
5360
foreach {integrityFile integrityComment} \
5461
{a.txt one b.txt two a.txt three c.txt four} {
55
- write_file $integrityFile "$integrityComment\n[string repeat $integrityComment 200]\n"
62
+ write_file $integrityFile \
63
+ "$integrityComment\n[string repeat $integrityComment 200]\n"
5664
fossil add $integrityFile
5765
fossil commit -m $integrityComment
5866
}
5967
fossil tag add release current
6068
write_file ../wiki.txt "A page"
@@ -77,25 +85,29 @@
7785
file mkdir artifacts
7886
fossil deconstruct -R r.fossil artifacts
7987
test integrity-deconstruct {$CODE == 0}
8088
fossil reconstruct r2.fossil artifacts
8189
test integrity-reconstruct {$CODE == 0}
82
-test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] $artifacts
83
-test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] $checkins
90
+test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] \
91
+ $artifacts
92
+test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] \
93
+ $checkins
8494
integrity_ok integrity-reconstruct-check r2.fossil
8595
8696
# A file artifact whose stored content does not decompress.
8797
fossil sql -R r2.fossil "UPDATE blob SET content=x'00000010deadbeef'\
8898
WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\
8999
WHERE name='b.txt' LIMIT 1)"
90100
fossil test-integrity -R r2.fossil -expectError
91
-test_match integrity-damaged-content [normalize_result] {wrong hash on artifact \d+}
101
+test_match integrity-damaged-content [normalize_result] \
102
+ {wrong hash on artifact \d+}
92103
# An undamaged artifact is still readable.
93104
fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\
94105
JOIN filename USING(fnid) WHERE name='c.txt'"
95106
fossil artifact [normalize_result] -R r2.fossil
96
-test_eq integrity-artifact-readable [normalize_result] "four\n[string repeat four 200]"
107
+test_eq integrity-artifact-readable [normalize_result] \
108
+ "four\n[string repeat four 200]"
97109
file delete r2.fossil
98110
99111
###############################################################################
100112
# test-integrity and test-missing: exit 0 on a sound repository, non-zero
101113
# on each kind of damage. Each kind is made to a copy.
@@ -119,11 +131,12 @@
119131
content-does-not-match-hash \
120132
"UPDATE blob SET content=x'0102030405060708' WHERE rid=$integrityOneFile" \
121133
test-integrity \
122134
hash-does-not-match-content \
123135
"UPDATE blob SET uuid=substr(uuid,1,length(uuid)-1) ||\
124
- CASE substr(uuid,-1) WHEN '0' THEN '1' ELSE '0' END WHERE rid=$integrityOneFile" \
136
+ CASE substr(uuid,-1) WHEN '0' THEN '1' ELSE '0' END\
137
+ WHERE rid=$integrityOneFile" \
125138
test-integrity \
126139
delta-is-its-own-source \
127140
"UPDATE delta SET srcid=rid WHERE rid=(SELECT rid FROM delta LIMIT 1)" \
128141
test-integrity \
129142
delta-source-gone \
@@ -131,11 +144,12 @@
131144
test-integrity \
132145
public-delta-from-private \
133146
"INSERT INTO private SELECT srcid FROM delta LIMIT 1" \
134147
test-integrity \
135148
checkin-is-not-a-manifest \
136
- "UPDATE blob SET content=(SELECT content FROM blob WHERE rid=$integrityOneFile)\
149
+ "UPDATE blob\
150
+ SET content=(SELECT content FROM blob WHERE rid=$integrityOneFile)\
137151
WHERE rid=(SELECT max(objid) FROM event WHERE type='ci')" \
138152
{test-integrity --parse} \
139153
file-gone \
140154
"DELETE FROM blob WHERE rid=$integrityOneFile" \
141155
test-missing \
@@ -164,10 +178,11 @@
164178
fossil sql -R $integrityDamaged \
165179
"DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)"
166180
test integrity-missing-parent-link-shows \
167181
{[integrity_derived $integrityDamaged] ne $integrityBefore}
168182
fossil rebuild $integrityDamaged
169
-test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] $integrityBefore
183
+test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] \
184
+ $integrityBefore
170185
file delete $integrityDamaged
171186
172187
test_cleanup
173188
unset ::env(FOSSIL_USER)
174189
--- test/integrity.test
+++ test/integrity.test
@@ -14,33 +14,40 @@
14 require_no_open_checkout
15
16 test_setup ""
17 set ::env(FOSSIL_USER) tester
18
19 # The hashes of the artifacts in REPO that are not phantoms, in order.
 
 
20 proc integrity_artifacts {repo} {
21 fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0 ORDER BY uuid"
22 return [normalize_result]
23 }
24
25 # The check-ins in REPO with their parents and comments, in order of hash.
 
 
26 proc integrity_checkins {repo} {
27 fossil sql -R $repo "SELECT b.uuid, coalesce(p.uuid,''), e.comment\
28 FROM event e JOIN blob b ON b.rid=e.objid\
29 LEFT JOIN plink ON cid=e.objid LEFT JOIN blob p ON p.rid=pid\
30 WHERE e.type='ci' ORDER BY b.uuid"
31 return [normalize_result]
32 }
33
34 # Test NAME passes when "fossil test-integrity --parse" finds no problems.
 
 
35 proc integrity_ok {name repo} {
36 fossil test-integrity --parse -R $repo
37 test_match $name [normalize_result] {checked: 0 errors}
38 }
39
40 # The derived tables of REPO as text that does not depend on record
41 # numbers. See derived.sql.
 
42 proc integrity_derived {repo} {
43 fossil sql -R $repo ".read [file join $::testfiledir derived.sql]"
44 return $::RESULT
45 }
46
@@ -50,11 +57,12 @@
50 file mkdir ck
51 cd ck
52 fossil open ../r.fossil
53 foreach {integrityFile integrityComment} \
54 {a.txt one b.txt two a.txt three c.txt four} {
55 write_file $integrityFile "$integrityComment\n[string repeat $integrityComment 200]\n"
 
56 fossil add $integrityFile
57 fossil commit -m $integrityComment
58 }
59 fossil tag add release current
60 write_file ../wiki.txt "A page"
@@ -77,25 +85,29 @@
77 file mkdir artifacts
78 fossil deconstruct -R r.fossil artifacts
79 test integrity-deconstruct {$CODE == 0}
80 fossil reconstruct r2.fossil artifacts
81 test integrity-reconstruct {$CODE == 0}
82 test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] $artifacts
83 test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] $checkins
 
 
84 integrity_ok integrity-reconstruct-check r2.fossil
85
86 # A file artifact whose stored content does not decompress.
87 fossil sql -R r2.fossil "UPDATE blob SET content=x'00000010deadbeef'\
88 WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\
89 WHERE name='b.txt' LIMIT 1)"
90 fossil test-integrity -R r2.fossil -expectError
91 test_match integrity-damaged-content [normalize_result] {wrong hash on artifact \d+}
 
92 # An undamaged artifact is still readable.
93 fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\
94 JOIN filename USING(fnid) WHERE name='c.txt'"
95 fossil artifact [normalize_result] -R r2.fossil
96 test_eq integrity-artifact-readable [normalize_result] "four\n[string repeat four 200]"
 
97 file delete r2.fossil
98
99 ###############################################################################
100 # test-integrity and test-missing: exit 0 on a sound repository, non-zero
101 # on each kind of damage. Each kind is made to a copy.
@@ -119,11 +131,12 @@
119 content-does-not-match-hash \
120 "UPDATE blob SET content=x'0102030405060708' WHERE rid=$integrityOneFile" \
121 test-integrity \
122 hash-does-not-match-content \
123 "UPDATE blob SET uuid=substr(uuid,1,length(uuid)-1) ||\
124 CASE substr(uuid,-1) WHEN '0' THEN '1' ELSE '0' END WHERE rid=$integrityOneFile" \
 
125 test-integrity \
126 delta-is-its-own-source \
127 "UPDATE delta SET srcid=rid WHERE rid=(SELECT rid FROM delta LIMIT 1)" \
128 test-integrity \
129 delta-source-gone \
@@ -131,11 +144,12 @@
131 test-integrity \
132 public-delta-from-private \
133 "INSERT INTO private SELECT srcid FROM delta LIMIT 1" \
134 test-integrity \
135 checkin-is-not-a-manifest \
136 "UPDATE blob SET content=(SELECT content FROM blob WHERE rid=$integrityOneFile)\
 
137 WHERE rid=(SELECT max(objid) FROM event WHERE type='ci')" \
138 {test-integrity --parse} \
139 file-gone \
140 "DELETE FROM blob WHERE rid=$integrityOneFile" \
141 test-missing \
@@ -164,10 +178,11 @@
164 fossil sql -R $integrityDamaged \
165 "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)"
166 test integrity-missing-parent-link-shows \
167 {[integrity_derived $integrityDamaged] ne $integrityBefore}
168 fossil rebuild $integrityDamaged
169 test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] $integrityBefore
 
170 file delete $integrityDamaged
171
172 test_cleanup
173 unset ::env(FOSSIL_USER)
174
--- test/integrity.test
+++ test/integrity.test
@@ -14,33 +14,40 @@
14 require_no_open_checkout
15
16 test_setup ""
17 set ::env(FOSSIL_USER) tester
18
19 # Returns the hashes of the artifacts in repository REPO that are not
20 # phantoms, in order.
21 #
22 proc integrity_artifacts {repo} {
23 fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0 ORDER BY uuid"
24 return [normalize_result]
25 }
26
27 # Returns the check-ins in repository REPO with their parents and
28 # comments, in order of hash.
29 #
30 proc integrity_checkins {repo} {
31 fossil sql -R $repo "SELECT b.uuid, coalesce(p.uuid,''), e.comment\
32 FROM event e JOIN blob b ON b.rid=e.objid\
33 LEFT JOIN plink ON cid=e.objid LEFT JOIN blob p ON p.rid=pid\
34 WHERE e.type='ci' ORDER BY b.uuid"
35 return [normalize_result]
36 }
37
38 # Test NAME passes when "fossil test-integrity --parse" finds no
39 # problems in repository REPO.
40 #
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
@@ -50,11 +57,12 @@
57 file mkdir ck
58 cd ck
59 fossil open ../r.fossil
60 foreach {integrityFile integrityComment} \
61 {a.txt one b.txt two a.txt three c.txt four} {
62 write_file $integrityFile \
63 "$integrityComment\n[string repeat $integrityComment 200]\n"
64 fossil add $integrityFile
65 fossil commit -m $integrityComment
66 }
67 fossil tag add release current
68 write_file ../wiki.txt "A page"
@@ -77,25 +85,29 @@
85 file mkdir artifacts
86 fossil deconstruct -R r.fossil artifacts
87 test integrity-deconstruct {$CODE == 0}
88 fossil reconstruct r2.fossil artifacts
89 test integrity-reconstruct {$CODE == 0}
90 test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] \
91 $artifacts
92 test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] \
93 $checkins
94 integrity_ok integrity-reconstruct-check r2.fossil
95
96 # A file artifact whose stored content does not decompress.
97 fossil sql -R r2.fossil "UPDATE blob SET content=x'00000010deadbeef'\
98 WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\
99 WHERE name='b.txt' LIMIT 1)"
100 fossil test-integrity -R r2.fossil -expectError
101 test_match integrity-damaged-content [normalize_result] \
102 {wrong hash on artifact \d+}
103 # An undamaged artifact is still readable.
104 fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\
105 JOIN filename USING(fnid) WHERE name='c.txt'"
106 fossil artifact [normalize_result] -R r2.fossil
107 test_eq integrity-artifact-readable [normalize_result] \
108 "four\n[string repeat four 200]"
109 file delete r2.fossil
110
111 ###############################################################################
112 # test-integrity and test-missing: exit 0 on a sound repository, non-zero
113 # on each kind of damage. Each kind is made to a copy.
@@ -119,11 +131,12 @@
131 content-does-not-match-hash \
132 "UPDATE blob SET content=x'0102030405060708' WHERE rid=$integrityOneFile" \
133 test-integrity \
134 hash-does-not-match-content \
135 "UPDATE blob SET uuid=substr(uuid,1,length(uuid)-1) ||\
136 CASE substr(uuid,-1) WHEN '0' THEN '1' ELSE '0' END\
137 WHERE rid=$integrityOneFile" \
138 test-integrity \
139 delta-is-its-own-source \
140 "UPDATE delta SET srcid=rid WHERE rid=(SELECT rid FROM delta LIMIT 1)" \
141 test-integrity \
142 delta-source-gone \
@@ -131,11 +144,12 @@
144 test-integrity \
145 public-delta-from-private \
146 "INSERT INTO private SELECT srcid FROM delta LIMIT 1" \
147 test-integrity \
148 checkin-is-not-a-manifest \
149 "UPDATE blob\
150 SET content=(SELECT content FROM blob WHERE rid=$integrityOneFile)\
151 WHERE rid=(SELECT max(objid) FROM event WHERE type='ci')" \
152 {test-integrity --parse} \
153 file-gone \
154 "DELETE FROM blob WHERE rid=$integrityOneFile" \
155 test-missing \
@@ -164,10 +178,11 @@
178 fossil sql -R $integrityDamaged \
179 "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)"
180 test integrity-missing-parent-link-shows \
181 {[integrity_derived $integrityDamaged] ne $integrityBefore}
182 fossil rebuild $integrityDamaged
183 test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] \
184 $integrityBefore
185 file delete $integrityDamaged
186
187 test_cleanup
188 unset ::env(FOSSIL_USER)
189
+51 -139
--- test/regress.test
+++ test/regress.test
@@ -21,11 +21,11 @@
2121
test regress-dir-list-missing {$CODE == 0}
2222
2323
###############################################################################
2424
# "fossil test-xfer" used to print a robot captcha and then crash.
2525
26
-write_file request.txt "pragma client-version 22900 20261110 124827\n"
26
+write_file request.txt $CLIENT_VERSION_CARD
2727
fossil test-xfer request.txt
2828
test regress-test-xfer {$CODE == 0}
2929
test_match regress-test-xfer-reply $RESULT {# timestamp}
3030
3131
###############################################################################
@@ -35,24 +35,10 @@
3535
fossil branch new br trunk
3636
fossil update br
3737
test regress-short-branch-name {$CODE == 0}
3838
fossil update trunk
3939
40
-###############################################################################
41
-# A delta for a target of 2^24 bytes or more that has nothing in common
42
-# with its source overflowed its buffer by a byte or two. This shows
43
-# only in a build with run-time checking.
44
-
45
-write_file tiny.txt "x\n"
46
-write_file big.txt [string repeat "0123456789abcde\n" 1048576]
47
-fossil test-delta-create tiny.txt big.txt big.delta
48
-test regress-large-delta-create {$CODE == 0}
49
-fossil test-delta-apply tiny.txt big.delta big.out
50
-test regress-large-delta-apply {$CODE == 0}
51
-test regress-large-delta-same {[same_file big.txt big.out]}
52
-file delete big.txt big.out big.delta
53
-
5440
###############################################################################
5541
# An HTML comment or an HR tag followed by spaces and no newline made the
5642
# Markdown translator copy one byte from past the end of its input into
5743
# the output. That byte was a NUL.
5844
@@ -60,63 +46,38 @@
6046
hr "<hr> "
6147
comment "<!-- x --> "
6248
quoted "> <hr> "
6349
} {
6450
write_file md-$regressName.md $regressText
65
- # The output goes to a file and is read back as bytes, so that a NUL
66
- # in it is seen as one.
67
- set regressRc [catch {exec $::fossilexe test-markdown-render \
68
- md-$regressName.md > md-$regressName.out}]
69
- set regressFd [open md-$regressName.out rb]
70
- set regressOut [read $regressFd]
71
- close $regressFd
51
+ fossil_raw test-markdown-render md-$regressName.md
7252
test regress-markdown-html-block-$regressName \
73
- {$regressRc == 0 && [string first \x00 $regressOut] < 0}
53
+ {$CODE == 0 && [string first \x00 $RESULT] < 0}
7454
}
7555
7656
###############################################################################
7757
# "fossil import --svn" took the lengths in a property block from the dump
7858
# file without checking them. A block too short for its end marker was
7959
# read before its start, a negative length made the import run for ever,
8060
# and an oversized one read and wrote outside the block.
8161
82
-proc regress_svn_rev {regressN regressProps} {
83
- set regressLen [string length $regressProps]
84
- return "Revision-number: $regressN\nProp-content-length: $regressLen\nContent-length: $regressLen\n\n$regressProps\n"
85
-}
86
-# Run fossil with the arguments given and a time limit in seconds, because
87
-# one of these faults was an endless loop. The result is the exit status,
88
-# or -1 if the limit ran out, followed by the output.
89
-proc regress_read {regressFd} {
90
- append ::regressOutput [read $regressFd]
91
- if {[eof $regressFd]} {set ::regressState done}
92
-}
93
-proc regress_limited {regressSeconds args} {
94
- set ::regressOutput ""
95
- set ::regressState running
96
- set regressFd [open "|[linsert $args 0 $::fossilexe] 2>@1" r]
97
- fconfigure $regressFd -blocking 0
98
- fileevent $regressFd readable [list regress_read $regressFd]
99
- set regressTimer [after [expr {$regressSeconds*1000}] \
100
- {set ::regressState late}]
101
- vwait ::regressState
102
- after cancel $regressTimer
103
- if {$::regressState eq "late"} {
104
- foreach regressPid [pid $regressFd] {
105
- if {$::tcl_platform(platform) eq "windows"} {
106
- catch {exec taskkill /F /PID $regressPid}
107
- } else {
108
- catch {exec kill -9 $regressPid}
109
- }
110
- }
111
- catch {close $regressFd}
112
- return [list -1 $::regressOutput]
113
- }
114
- fconfigure $regressFd -blocking 1
115
- set regressRc [catch {close $regressFd}]
116
- return [list $regressRc $::regressOutput]
117
-}
62
+proc regress_svn_rev {number props} {
63
+ set length [string length $props]
64
+ set head "Revision-number: $number\nProp-content-length: $length\n"
65
+ return "${head}Content-length: $length\n\n$props\n"
66
+}
67
+
68
+proc regress_svn_props {props} {
69
+ set block ""
70
+ foreach {name value} $props {
71
+ append block "K [string length $name]\n$name\n"
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.
11879
set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n"
11980
foreach {regressName regressProps} {
12081
short-block "abcd\n"
12182
negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n"
12283
oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n"
@@ -123,21 +84,23 @@
12384
oversized-value "K 2\nab\nV 99999\nx\nPROPS-END\n"
12485
negative-value "K 2\nab\nV -40\nx\nPROPS-END\n"
12586
} {
12687
write_file svn-$regressName.dump \
12788
$regressSvnHead[regress_svn_rev 0 $regressProps]
128
- set regressRes [regress_limited 60 import --svn svn-$regressName.fossil \
129
- svn-$regressName.dump]
89
+ fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
90
+ svn-$regressName.dump
13091
test regress-svn-import-$regressName \
131
- {[lindex $regressRes 0] == 1
132
- && [string match "*svn-dump data*" [lindex $regressRes 1]]}
92
+ {$CODE == 1 && [string match "*svn-dump data*" $RESULT]}
13393
file delete svn-$regressName.fossil
13494
}
135
-# A sound dump of one revision with three properties is still accepted.
136
-write_file svn-sound.dump $regressSvnHead[regress_svn_rev 0 \
137
- "K 8\nsvn:date\nV 27\n2026-01-01T00:00:00.000000Z\nPROPS-END\n"][regress_svn_rev 1 \
138
- "K 7\nsvn:log\nV 5\nfirst\nK 10\nsvn:author\nV 3\ndan\nK 8\nsvn:date\nV 27\n2026-01-01T00:00:00.000000Z\nPROPS-END\n"]
95
+
96
+set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z}
97
+set regressSvnSound $regressSvnHead
98
+append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]]
99
+append regressSvnSound [regress_svn_rev 1 [regress_svn_props \
100
+ [concat {svn:log first svn:author dan} $regressSvnDate]]]
101
+write_file svn-sound.dump $regressSvnSound
139102
fossil import --svn svn-sound.fossil svn-sound.dump
140103
test regress-svn-import-sound {$CODE == 0}
141104
file delete svn-sound.fossil
142105
143106
###############################################################################
@@ -146,32 +109,21 @@
146109
# crashed the import. A negative length for the block itself was passed
147110
# on as the size of an allocation.
148111
149112
write_file svn-nul-in-block.dump \
150113
$regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"]
151
-write_file svn-negative-block.dump \
152
- "${regressSvnHead}Revision-number: 0\nProp-content-length: -5\nContent-length: 10\n\nPROPS-END\n\n"
114
+set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n"
115
+append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n"
116
+write_file svn-negative-block.dump $regressSvnHead$regressSvnNegative
153117
foreach regressName {nul-in-block negative-block} {
154
- set regressRes [regress_limited 60 import --svn svn-$regressName.fossil \
155
- svn-$regressName.dump]
118
+ fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
119
+ svn-$regressName.dump
156120
test regress-svn-import-$regressName \
157
- {[lindex $regressRes 0] == 1
158
- && [string match "*svn-dump data format broken*" [lindex $regressRes 1]]}
121
+ {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
159122
file delete svn-$regressName.fossil
160123
}
161124
162
-###############################################################################
163
-# A wiki tag with an unrecognised attribute whose value is not quoted took
164
-# the text after the tag as attributes of the tag, and the scan could run
165
-# past the end of the text.
166
-
167
-write_file wiki-attr.wiki "x <span foo=bar>id=zz title=yy more</span> end\n"
168
-fossil test-wiki-render wiki-attr.wiki
169
-test regress-wiki-ignored-attribute \
170
- {$CODE == 0
171
- && [string first {<span>id=zz title=yy more</span>} $RESULT] >= 0}
172
-
173125
###############################################################################
174126
# A Markdown header that holds an HTML comment was read past its end when
175127
# its id was made. This shows only in a build with run-time checking.
176128
177129
write_file md-header.md "intro\n\n# a <!-- -->\n"
@@ -197,20 +149,18 @@
197149
# The names of the files in a merge conflict are put into the
198150
# gmerge-command as they are, inside the double quotes that the setting
199151
# has around them. A name with a double quote reached the merge tool as
200152
# several arguments, and one with a dollar sign or a backquote stopped the
201153
# merge. For such a name the tool is now left out, with a warning, and
202
-# the conflict stays marked in the file. The merge tool here is a script
203
-# that counts its arguments and resolves nothing.
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.
204156
205157
if {$::tcl_platform(platform) ne "windows"} {
206158
set regressTop [pwd]
207
- set regressTool [file join $regressTop gmerge-standin.sh]
159
+ set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]]
208160
set regressToolLog [file join $regressTop gmerge-args.txt]
209
- write_file $regressTool \
210
- "#!/bin/sh\nfor a in \"\$@\"; do echo arg; done >> \"$regressToolLog\"\nexit 1\n"
211
- file attributes $regressTool -permissions 0755
161
+ set ::env(ARGS_LOG) $regressToolLog
212162
foreach {regressName regressFile regressRuns} {
213163
plain plain.txt 1
214164
space {sp ace.txt} 1
215165
quote {a" "b.txt} 0
216166
dollar {a$b.txt} 0
@@ -229,65 +179,27 @@
229179
write_file $regressFile "one\nTWO-trunk\nthree\n"
230180
fossil commit -m trunk --no-warnings
231181
fossil settings gmerge-command \
232182
"$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\""
233183
file delete $regressToolLog
234
- set regressRc [catch {exec $::fossilexe merge br 2>@1} regressOut]
184
+ fossil_raw merge br
235185
set regressArgs 0
236186
if {[file exists $regressToolLog]} {
237
- set regressFd [open $regressToolLog r]
238
- set regressArgs [llength [split [string trim [read $regressFd]] \n]]
239
- close $regressFd
240
- }
241
- set regressFd [open $regressFile r]
242
- set regressText [read $regressFd]
243
- close $regressFd
244
- set regressMarked [expr {[string first "<<<<<<<" $regressText] >= 0}]
187
+ set regressArgs \
188
+ [llength [split [string trim [read_file $regressToolLog]] \n]]
189
+ }
190
+ set regressMarked \
191
+ [expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}]
245192
set regressWarned \
246
- [expr {[string first "not running the gmerge-command" $regressOut] >= 0}]
247
- if {$regressRuns} {
248
- test regress-gmerge-$regressName \
249
- {$regressRc == 0 && $regressArgs == 4 && !$regressWarned
250
- && $regressMarked}
251
- } else {
252
- test regress-gmerge-$regressName \
253
- {$regressRc == 0 && $regressArgs == 0 && $regressWarned
254
- && $regressMarked}
255
- }
193
+ [expr {[string first "not running the gmerge-command" $RESULT] >= 0}]
194
+ test regress-gmerge-$regressName \
195
+ {$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns
196
+ && $regressWarned != $regressRuns}
256197
fossil close --force
257198
cd $regressTop
258199
}
259
-}
260
-
261
-###############################################################################
262
-# "fossil git export" left out, with exit status 0, a check-in that holds
263
-# a shunned file. The file is to be exported as an empty file. This
264
-# test changes the repository, so it comes last. It needs git.
265
-
266
-if {[catch {exec git --version}]} {
267
- puts "regress-git-export-shunned skipped: no git"
268
-} else {
269
- write_file keep.txt "keep\n"
270
- write_file shun.txt "first version\n"
271
- fossil add keep.txt shun.txt
272
- fossil commit -m "regress-c2"
273
- write_file shun.txt "second version, to be shunned\n"
274
- fossil commit -m "regress-c3"
275
- fossil sql "INSERT OR IGNORE INTO shun(uuid,mtime) SELECT b.uuid, 0 FROM blob b, mlink m, filename f WHERE m.fid=b.rid AND f.fnid=m.fnid AND f.name='shun.txt' AND m.mid=(SELECT max(mid) FROM mlink)"
276
- fossil rebuild
277
- # git writes progress to standard error, which the "fossil" command of
278
- # this test suite counts as a failure, so run it directly.
279
- set regressRc [catch {exec $::fossilexe git export regress-mirror 2>@1}]
280
- test regress-git-export-shunned-status {$regressRc == 0}
281
- set regressLog [exec git -C regress-mirror log --format=%s]
282
- test regress-git-export-shunned-checkin \
283
- {[string first regress-c3 $regressLog] >= 0}
284
- set regressSize [string length \
285
- [exec git -C regress-mirror cat-file -p HEAD:shun.txt]]
286
- test regress-git-export-shunned-empty {$regressSize == 0}
287
- set regressOld [exec git -C regress-mirror cat-file -p HEAD~1:shun.txt]
288
- test regress-git-export-shunned-older {$regressOld eq "first version"}
200
+ unset ::env(ARGS_LOG)
289201
}
290202
291203
###############################################################################
292204
293205
test_cleanup
294206
--- test/regress.test
+++ test/regress.test
@@ -21,11 +21,11 @@
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 "pragma client-version 22900 20261110 124827\n"
27 fossil test-xfer request.txt
28 test regress-test-xfer {$CODE == 0}
29 test_match regress-test-xfer-reply $RESULT {# timestamp}
30
31 ###############################################################################
@@ -35,24 +35,10 @@
35 fossil branch new br trunk
36 fossil update br
37 test regress-short-branch-name {$CODE == 0}
38 fossil update trunk
39
40 ###############################################################################
41 # A delta for a target of 2^24 bytes or more that has nothing in common
42 # with its source overflowed its buffer by a byte or two. This shows
43 # only in a build with run-time checking.
44
45 write_file tiny.txt "x\n"
46 write_file big.txt [string repeat "0123456789abcde\n" 1048576]
47 fossil test-delta-create tiny.txt big.txt big.delta
48 test regress-large-delta-create {$CODE == 0}
49 fossil test-delta-apply tiny.txt big.delta big.out
50 test regress-large-delta-apply {$CODE == 0}
51 test regress-large-delta-same {[same_file big.txt big.out]}
52 file delete big.txt big.out big.delta
53
54 ###############################################################################
55 # An HTML comment or an HR tag followed by spaces and no newline made the
56 # Markdown translator copy one byte from past the end of its input into
57 # the output. That byte was a NUL.
58
@@ -60,63 +46,38 @@
60 hr "<hr> "
61 comment "<!-- x --> "
62 quoted "> <hr> "
63 } {
64 write_file md-$regressName.md $regressText
65 # The output goes to a file and is read back as bytes, so that a NUL
66 # in it is seen as one.
67 set regressRc [catch {exec $::fossilexe test-markdown-render \
68 md-$regressName.md > md-$regressName.out}]
69 set regressFd [open md-$regressName.out rb]
70 set regressOut [read $regressFd]
71 close $regressFd
72 test regress-markdown-html-block-$regressName \
73 {$regressRc == 0 && [string first \x00 $regressOut] < 0}
74 }
75
76 ###############################################################################
77 # "fossil import --svn" took the lengths in a property block from the dump
78 # file without checking them. A block too short for its end marker was
79 # read before its start, a negative length made the import run for ever,
80 # and an oversized one read and wrote outside the block.
81
82 proc regress_svn_rev {regressN regressProps} {
83 set regressLen [string length $regressProps]
84 return "Revision-number: $regressN\nProp-content-length: $regressLen\nContent-length: $regressLen\n\n$regressProps\n"
85 }
86 # Run fossil with the arguments given and a time limit in seconds, because
87 # one of these faults was an endless loop. The result is the exit status,
88 # or -1 if the limit ran out, followed by the output.
89 proc regress_read {regressFd} {
90 append ::regressOutput [read $regressFd]
91 if {[eof $regressFd]} {set ::regressState done}
92 }
93 proc regress_limited {regressSeconds args} {
94 set ::regressOutput ""
95 set ::regressState running
96 set regressFd [open "|[linsert $args 0 $::fossilexe] 2>@1" r]
97 fconfigure $regressFd -blocking 0
98 fileevent $regressFd readable [list regress_read $regressFd]
99 set regressTimer [after [expr {$regressSeconds*1000}] \
100 {set ::regressState late}]
101 vwait ::regressState
102 after cancel $regressTimer
103 if {$::regressState eq "late"} {
104 foreach regressPid [pid $regressFd] {
105 if {$::tcl_platform(platform) eq "windows"} {
106 catch {exec taskkill /F /PID $regressPid}
107 } else {
108 catch {exec kill -9 $regressPid}
109 }
110 }
111 catch {close $regressFd}
112 return [list -1 $::regressOutput]
113 }
114 fconfigure $regressFd -blocking 1
115 set regressRc [catch {close $regressFd}]
116 return [list $regressRc $::regressOutput]
117 }
118 set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n"
119 foreach {regressName regressProps} {
120 short-block "abcd\n"
121 negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n"
122 oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n"
@@ -123,21 +84,23 @@
123 oversized-value "K 2\nab\nV 99999\nx\nPROPS-END\n"
124 negative-value "K 2\nab\nV -40\nx\nPROPS-END\n"
125 } {
126 write_file svn-$regressName.dump \
127 $regressSvnHead[regress_svn_rev 0 $regressProps]
128 set regressRes [regress_limited 60 import --svn svn-$regressName.fossil \
129 svn-$regressName.dump]
130 test regress-svn-import-$regressName \
131 {[lindex $regressRes 0] == 1
132 && [string match "*svn-dump data*" [lindex $regressRes 1]]}
133 file delete svn-$regressName.fossil
134 }
135 # A sound dump of one revision with three properties is still accepted.
136 write_file svn-sound.dump $regressSvnHead[regress_svn_rev 0 \
137 "K 8\nsvn:date\nV 27\n2026-01-01T00:00:00.000000Z\nPROPS-END\n"][regress_svn_rev 1 \
138 "K 7\nsvn:log\nV 5\nfirst\nK 10\nsvn:author\nV 3\ndan\nK 8\nsvn:date\nV 27\n2026-01-01T00:00:00.000000Z\nPROPS-END\n"]
 
 
 
139 fossil import --svn svn-sound.fossil svn-sound.dump
140 test regress-svn-import-sound {$CODE == 0}
141 file delete svn-sound.fossil
142
143 ###############################################################################
@@ -146,32 +109,21 @@
146 # crashed the import. A negative length for the block itself was passed
147 # on as the size of an allocation.
148
149 write_file svn-nul-in-block.dump \
150 $regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"]
151 write_file svn-negative-block.dump \
152 "${regressSvnHead}Revision-number: 0\nProp-content-length: -5\nContent-length: 10\n\nPROPS-END\n\n"
 
153 foreach regressName {nul-in-block negative-block} {
154 set regressRes [regress_limited 60 import --svn svn-$regressName.fossil \
155 svn-$regressName.dump]
156 test regress-svn-import-$regressName \
157 {[lindex $regressRes 0] == 1
158 && [string match "*svn-dump data format broken*" [lindex $regressRes 1]]}
159 file delete svn-$regressName.fossil
160 }
161
162 ###############################################################################
163 # A wiki tag with an unrecognised attribute whose value is not quoted took
164 # the text after the tag as attributes of the tag, and the scan could run
165 # past the end of the text.
166
167 write_file wiki-attr.wiki "x <span foo=bar>id=zz title=yy more</span> end\n"
168 fossil test-wiki-render wiki-attr.wiki
169 test regress-wiki-ignored-attribute \
170 {$CODE == 0
171 && [string first {<span>id=zz title=yy more</span>} $RESULT] >= 0}
172
173 ###############################################################################
174 # A Markdown header that holds an HTML comment was read past its end when
175 # its id was made. This shows only in a build with run-time checking.
176
177 write_file md-header.md "intro\n\n# a <!-- -->\n"
@@ -197,20 +149,18 @@
197 # The names of the files in a merge conflict are put into the
198 # gmerge-command as they are, inside the double quotes that the setting
199 # has around them. A name with a double quote reached the merge tool as
200 # several arguments, and one with a dollar sign or a backquote stopped the
201 # merge. For such a name the tool is now left out, with a warning, and
202 # the conflict stays marked in the file. The merge tool here is a script
203 # that counts its arguments and resolves nothing.
204
205 if {$::tcl_platform(platform) ne "windows"} {
206 set regressTop [pwd]
207 set regressTool [file join $regressTop gmerge-standin.sh]
208 set regressToolLog [file join $regressTop gmerge-args.txt]
209 write_file $regressTool \
210 "#!/bin/sh\nfor a in \"\$@\"; do echo arg; done >> \"$regressToolLog\"\nexit 1\n"
211 file attributes $regressTool -permissions 0755
212 foreach {regressName regressFile regressRuns} {
213 plain plain.txt 1
214 space {sp ace.txt} 1
215 quote {a" "b.txt} 0
216 dollar {a$b.txt} 0
@@ -229,65 +179,27 @@
229 write_file $regressFile "one\nTWO-trunk\nthree\n"
230 fossil commit -m trunk --no-warnings
231 fossil settings gmerge-command \
232 "$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\""
233 file delete $regressToolLog
234 set regressRc [catch {exec $::fossilexe merge br 2>@1} regressOut]
235 set regressArgs 0
236 if {[file exists $regressToolLog]} {
237 set regressFd [open $regressToolLog r]
238 set regressArgs [llength [split [string trim [read $regressFd]] \n]]
239 close $regressFd
240 }
241 set regressFd [open $regressFile r]
242 set regressText [read $regressFd]
243 close $regressFd
244 set regressMarked [expr {[string first "<<<<<<<" $regressText] >= 0}]
245 set regressWarned \
246 [expr {[string first "not running the gmerge-command" $regressOut] >= 0}]
247 if {$regressRuns} {
248 test regress-gmerge-$regressName \
249 {$regressRc == 0 && $regressArgs == 4 && !$regressWarned
250 && $regressMarked}
251 } else {
252 test regress-gmerge-$regressName \
253 {$regressRc == 0 && $regressArgs == 0 && $regressWarned
254 && $regressMarked}
255 }
256 fossil close --force
257 cd $regressTop
258 }
259 }
260
261 ###############################################################################
262 # "fossil git export" left out, with exit status 0, a check-in that holds
263 # a shunned file. The file is to be exported as an empty file. This
264 # test changes the repository, so it comes last. It needs git.
265
266 if {[catch {exec git --version}]} {
267 puts "regress-git-export-shunned skipped: no git"
268 } else {
269 write_file keep.txt "keep\n"
270 write_file shun.txt "first version\n"
271 fossil add keep.txt shun.txt
272 fossil commit -m "regress-c2"
273 write_file shun.txt "second version, to be shunned\n"
274 fossil commit -m "regress-c3"
275 fossil sql "INSERT OR IGNORE INTO shun(uuid,mtime) SELECT b.uuid, 0 FROM blob b, mlink m, filename f WHERE m.fid=b.rid AND f.fnid=m.fnid AND f.name='shun.txt' AND m.mid=(SELECT max(mid) FROM mlink)"
276 fossil rebuild
277 # git writes progress to standard error, which the "fossil" command of
278 # this test suite counts as a failure, so run it directly.
279 set regressRc [catch {exec $::fossilexe git export regress-mirror 2>@1}]
280 test regress-git-export-shunned-status {$regressRc == 0}
281 set regressLog [exec git -C regress-mirror log --format=%s]
282 test regress-git-export-shunned-checkin \
283 {[string first regress-c3 $regressLog] >= 0}
284 set regressSize [string length \
285 [exec git -C regress-mirror cat-file -p HEAD:shun.txt]]
286 test regress-git-export-shunned-empty {$regressSize == 0}
287 set regressOld [exec git -C regress-mirror cat-file -p HEAD~1:shun.txt]
288 test regress-git-export-shunned-older {$regressOld eq "first version"}
289 }
290
291 ###############################################################################
292
293 test_cleanup
294
--- test/regress.test
+++ test/regress.test
@@ -21,11 +21,11 @@
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 ###############################################################################
@@ -35,24 +35,10 @@
35 fossil branch new br trunk
36 fossil update br
37 test regress-short-branch-name {$CODE == 0}
38 fossil update trunk
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40 ###############################################################################
41 # An HTML comment or an HR tag followed by spaces and no newline made the
42 # Markdown translator copy one byte from past the end of its input into
43 # the output. That byte was a NUL.
44
@@ -60,63 +46,38 @@
46 hr "<hr> "
47 comment "<!-- x --> "
48 quoted "> <hr> "
49 } {
50 write_file md-$regressName.md $regressText
51 fossil_raw test-markdown-render md-$regressName.md
 
 
 
 
 
 
52 test regress-markdown-html-block-$regressName \
53 {$CODE == 0 && [string first \x00 $RESULT] < 0}
54 }
55
56 ###############################################################################
57 # "fossil import --svn" took the lengths in a property block from the dump
58 # file without checking them. A block too short for its end marker was
59 # read before its start, a negative length made the import run for ever,
60 # and an oversized one read and wrote outside the block.
61
62 proc regress_svn_rev {number props} {
63 set length [string length $props]
64 set head "Revision-number: $number\nProp-content-length: $length\n"
65 return "${head}Content-length: $length\n\n$props\n"
66 }
67
68 proc regress_svn_props {props} {
69 set block ""
70 foreach {name value} $props {
71 append block "K [string length $name]\n$name\n"
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"
@@ -123,21 +84,23 @@
84 oversized-value "K 2\nab\nV 99999\nx\nPROPS-END\n"
85 negative-value "K 2\nab\nV -40\nx\nPROPS-END\n"
86 } {
87 write_file svn-$regressName.dump \
88 $regressSvnHead[regress_svn_rev 0 $regressProps]
89 fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
90 svn-$regressName.dump
91 test regress-svn-import-$regressName \
92 {$CODE == 1 && [string match "*svn-dump data*" $RESULT]}
 
93 file delete svn-$regressName.fossil
94 }
95
96 set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z}
97 set regressSvnSound $regressSvnHead
98 append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]]
99 append regressSvnSound [regress_svn_rev 1 [regress_svn_props \
100 [concat {svn:log first svn:author dan} $regressSvnDate]]]
101 write_file svn-sound.dump $regressSvnSound
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 ###############################################################################
@@ -146,32 +109,21 @@
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"
116 write_file svn-negative-block.dump $regressSvnHead$regressSvnNegative
117 foreach regressName {nul-in-block negative-block} {
118 fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
119 svn-$regressName.dump
120 test regress-svn-import-$regressName \
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"
@@ -197,20 +149,18 @@
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]]
160 set regressToolLog [file join $regressTop gmerge-args.txt]
161 set ::env(ARGS_LOG) $regressToolLog
 
 
162 foreach {regressName regressFile regressRuns} {
163 plain plain.txt 1
164 space {sp ace.txt} 1
165 quote {a" "b.txt} 0
166 dollar {a$b.txt} 0
@@ -229,65 +179,27 @@
179 write_file $regressFile "one\nTWO-trunk\nthree\n"
180 fossil commit -m trunk --no-warnings
181 fossil settings gmerge-command \
182 "$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\""
183 file delete $regressToolLog
184 fossil_raw merge br
185 set regressArgs 0
186 if {[file exists $regressToolLog]} {
187 set regressArgs \
188 [llength [split [string trim [read_file $regressToolLog]] \n]]
189 }
190 set regressMarked \
191 [expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}]
 
 
 
192 set regressWarned \
193 [expr {[string first "not running the gmerge-command" $RESULT] >= 0}]
194 test regress-gmerge-$regressName \
195 {$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns
196 && $regressWarned != $regressRuns}
 
 
 
 
 
 
197 fossil close --force
198 cd $regressTop
199 }
200 unset ::env(ARGS_LOG)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201 }
202
203 ###############################################################################
204
205 test_cleanup
206
+28 -29
--- test/ssh.test
+++ test/ssh.test
@@ -1,11 +1,11 @@
11
#
22
# What fossil puts on an ssh command line. Nothing here connects to
3
-# another machine: "ssh" is a script that writes down the arguments it
4
-# is given and exits. The script is named by --ssh-command where a
5
-# command takes that option, and is first on the PATH for the commands
6
-# that do not.
3
+# another machine: "ssh" is a copy of standin/log-args.sh, which writes
4
+# down its arguments and exits. A command that has the --ssh-command
5
+# option is given the script with it. The other commands find the
6
+# script first on the PATH.
77
#
88
# Whatever follows the host on an ssh command line is joined into one
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,
@@ -20,15 +20,13 @@
2020
2121
test_setup
2222
2323
set sshDir [file join [pwd] ssh-standin]
2424
file mkdir $sshDir
25
-set sshStub [file join $sshDir ssh]
25
+set sshStub [test_standin log-args.sh [file join $sshDir ssh]]
2626
set sshLog [file join [pwd] ssh-args.txt]
27
-write_file $sshStub "#!/bin/sh\nfor a in \"\$@\"; do printf '<%s>\\n' \"\$a\"; done >> \"\$SSHTESTLOG\"\nexit 1\n"
28
-file attributes $sshStub -permissions 0755
29
-set ::env(SSHTESTLOG) $sshLog
27
+set ::env(ARGS_LOG) $sshLog
3028
set sshSavedPath $::env(PATH)
3129
set ::env(PATH) "$sshDir:$::env(PATH)"
3230
3331
# The stand-in must be what "ssh" means from here on. If it is not, run
3432
# nothing that could start the real one.
@@ -36,22 +34,20 @@
3634
set ::env(PATH) $sshSavedPath
3735
test_cleanup
3836
test_skip "cannot put a stand-in for ssh first on the PATH"
3937
}
4038
41
-# Run fossil with the arguments given. Sets sshOut to everything it
39
+# Run fossil with the arguments given. Sets RESULT to everything it
4240
# printed and sshArgs to the arguments the stand-in was given, one per
4341
# line inside <>, or to an empty string if it was not run.
4442
proc ssh_run {args} {
45
- global sshOut sshArgs sshLog
43
+ global sshArgs sshLog
4644
file delete $sshLog
47
- catch {exec $::fossilexe {*}$args < /dev/null 2>@1} sshOut
45
+ fossil_raw {*}$args
4846
set sshArgs ""
4947
if {[file exists $sshLog]} {
50
- set sshFd [open $sshLog r]
51
- set sshArgs [read $sshFd]
52
- close $sshFd
48
+ set sshArgs [read_file $sshLog]
5349
}
5450
}
5551
proc ssh_clone {url} {
5652
file delete ssh-clone.fossil
5753
ssh_run clone --ssh-command $::sshStub $url ssh-clone.fossil
@@ -60,24 +56,25 @@
6056
###############################################################################
6157
# Ordinary URLs reach ssh, with "--" before the host and the path as one
6258
# argument.
6359
6460
ssh_clone ssh://hh/dir/repo.fossil
65
-test ssh-clone-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
66
- && [string first "<test-http>\n<dir/repo.fossil>" $sshArgs] >= 0}
61
+test ssh-clone-plain \
62
+ {[holds_strings $sshArgs \
63
+ [list "<-->\n<hh>\n" "<test-http>\n<dir/repo.fossil>"]]}
6764
ssh_clone ssh://uu@hh:2222/dir/repo.fossil
68
-test ssh-clone-user-port {[string first "<-p>\n<2222>\n" $sshArgs] >= 0
69
- && [string first "<-->\n<uu@hh>\n" $sshArgs] >= 0}
65
+test ssh-clone-user-port \
66
+ {[holds_strings $sshArgs [list "<-p>\n<2222>\n" "<-->\n<uu@hh>\n"]]}
7067
ssh_clone "ssh://hh/dir/a-b_c.d,e=f@g/repo.fossil"
7168
test ssh-clone-punctuation \
7269
{[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0}
7370
ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil"
7471
test ssh-clone-fossil-parameter \
7572
{[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0}
7673
77
-# A path that begins with "~" is for the server to expand. It used to be
78
-# expanded on the local machine.
74
+# A path that begins with "~" is for the server to expand. It was
75
+# previously expanded on the local machine.
7976
ssh_clone ssh://hh/~/repo.fossil
8077
test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0}
8178
8279
###############################################################################
8380
# A path or a fossil= value with a character special to a shell is
@@ -93,20 +90,20 @@
9390
parenthesis ssh://hh/a(b).fossil
9491
redirect ssh://hh/a>b.fossil
9592
} {
9693
ssh_clone $sshUrl
9794
test ssh-clone-refused-$sshName \
98
- {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0}
95
+ {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
9996
}
10097
foreach {sshName sshUrl} {
10198
semicolon ssh://hh/repo.fossil?fossil=a;b/fossil
10299
dollar ssh://hh/repo.fossil?fossil=$HOME/bin/fossil
103100
other ssh://hh/repo.fossil?fossil=/bin/other
104101
} {
105102
ssh_clone $sshUrl
106103
test ssh-clone-fossil-refused-$sshName \
107
- {$sshArgs eq "" && [string first "unsafe command" $sshOut] >= 0}
104
+ {$sshArgs eq "" && [string first "unsafe command" $RESULT] >= 0}
108105
}
109106
110107
###############################################################################
111108
# "fossil ui HOST:REPO" refuses such a repository name, and puts "--"
112109
# before the host.
@@ -114,35 +111,37 @@
114111
ssh_run ui --nobrowser hh:dir/repo.fossil
115112
test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
116113
&& [string first "<dir/repo.fossil>" $sshArgs] >= 0}
117114
ssh_run ui --nobrowser "hh:dir/a;b.fossil"
118115
test ssh-ui-refused-semicolon \
119
- {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0}
116
+ {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
120117
ssh_run ui --nobrowser "hh:dir/a b.fossil"
121118
test ssh-ui-refused-space \
122
- {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0}
119
+ {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
123120
ssh_run ui --nobrowser -- "-x@hh:dir/repo.fossil"
124121
test ssh-ui-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
125122
126123
###############################################################################
127124
# "fossil patch push" and "fossil patch pull" put "--" before the host.
128125
129126
write_file ssh-file.txt "one\n"
130127
fossil add ssh-file.txt
131128
ssh_run patch push -- "-x@hh:dir"
132
-test ssh-patch-push-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
129
+test ssh-patch-push-user-with-dash \
130
+ {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
133131
ssh_run patch pull -- "-x@hh:dir"
134
-test ssh-patch-pull-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
132
+test ssh-patch-pull-user-with-dash \
133
+ {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
135134
136135
###############################################################################
137136
# An argument that begins with "~" is quoted, so that the shell does not
138137
# replace it with a home directory.
139138
140139
ssh_run test-escaped-arg ~ ~root/x
141
-test ssh-escaped-tilde {[string first {argv[2] = [~]} $sshOut] >= 0
142
- && [string first {argv[2] = [~root/x]} $sshOut] >= 0}
140
+test ssh-escaped-tilde {[string first {argv[2] = [~]} $RESULT] >= 0
141
+ && [string first {argv[2] = [~root/x]} $RESULT] >= 0}
143142
144143
###############################################################################
145144
146145
set ::env(PATH) $sshSavedPath
147
-unset ::env(SSHTESTLOG)
146
+unset ::env(ARGS_LOG)
148147
test_cleanup
149148
150149
ADDED test/standin/log-args.sh
151150
ADDED test/standin/transport.sh
--- test/ssh.test
+++ test/ssh.test
@@ -1,11 +1,11 @@
1 #
2 # What fossil puts on an ssh command line. Nothing here connects to
3 # another machine: "ssh" is a script that writes down the arguments it
4 # is given and exits. The script is named by --ssh-command where a
5 # command takes that option, and is first on the PATH for the commands
6 # that do not.
7 #
8 # Whatever follows the host on an ssh command line is joined into one
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,
@@ -20,15 +20,13 @@
20
21 test_setup
22
23 set sshDir [file join [pwd] ssh-standin]
24 file mkdir $sshDir
25 set sshStub [file join $sshDir ssh]
26 set sshLog [file join [pwd] ssh-args.txt]
27 write_file $sshStub "#!/bin/sh\nfor a in \"\$@\"; do printf '<%s>\\n' \"\$a\"; done >> \"\$SSHTESTLOG\"\nexit 1\n"
28 file attributes $sshStub -permissions 0755
29 set ::env(SSHTESTLOG) $sshLog
30 set sshSavedPath $::env(PATH)
31 set ::env(PATH) "$sshDir:$::env(PATH)"
32
33 # The stand-in must be what "ssh" means from here on. If it is not, run
34 # nothing that could start the real one.
@@ -36,22 +34,20 @@
36 set ::env(PATH) $sshSavedPath
37 test_cleanup
38 test_skip "cannot put a stand-in for ssh first on the PATH"
39 }
40
41 # Run fossil with the arguments given. Sets sshOut to everything it
42 # printed and sshArgs to the arguments the stand-in was given, one per
43 # line inside <>, or to an empty string if it was not run.
44 proc ssh_run {args} {
45 global sshOut sshArgs sshLog
46 file delete $sshLog
47 catch {exec $::fossilexe {*}$args < /dev/null 2>@1} sshOut
48 set sshArgs ""
49 if {[file exists $sshLog]} {
50 set sshFd [open $sshLog r]
51 set sshArgs [read $sshFd]
52 close $sshFd
53 }
54 }
55 proc ssh_clone {url} {
56 file delete ssh-clone.fossil
57 ssh_run clone --ssh-command $::sshStub $url ssh-clone.fossil
@@ -60,24 +56,25 @@
60 ###############################################################################
61 # Ordinary URLs reach ssh, with "--" before the host and the path as one
62 # argument.
63
64 ssh_clone ssh://hh/dir/repo.fossil
65 test ssh-clone-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
66 && [string first "<test-http>\n<dir/repo.fossil>" $sshArgs] >= 0}
 
67 ssh_clone ssh://uu@hh:2222/dir/repo.fossil
68 test ssh-clone-user-port {[string first "<-p>\n<2222>\n" $sshArgs] >= 0
69 && [string first "<-->\n<uu@hh>\n" $sshArgs] >= 0}
70 ssh_clone "ssh://hh/dir/a-b_c.d,e=f@g/repo.fossil"
71 test ssh-clone-punctuation \
72 {[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0}
73 ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil"
74 test ssh-clone-fossil-parameter \
75 {[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0}
76
77 # A path that begins with "~" is for the server to expand. It used to be
78 # expanded on the local machine.
79 ssh_clone ssh://hh/~/repo.fossil
80 test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0}
81
82 ###############################################################################
83 # A path or a fossil= value with a character special to a shell is
@@ -93,20 +90,20 @@
93 parenthesis ssh://hh/a(b).fossil
94 redirect ssh://hh/a>b.fossil
95 } {
96 ssh_clone $sshUrl
97 test ssh-clone-refused-$sshName \
98 {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0}
99 }
100 foreach {sshName sshUrl} {
101 semicolon ssh://hh/repo.fossil?fossil=a;b/fossil
102 dollar ssh://hh/repo.fossil?fossil=$HOME/bin/fossil
103 other ssh://hh/repo.fossil?fossil=/bin/other
104 } {
105 ssh_clone $sshUrl
106 test ssh-clone-fossil-refused-$sshName \
107 {$sshArgs eq "" && [string first "unsafe command" $sshOut] >= 0}
108 }
109
110 ###############################################################################
111 # "fossil ui HOST:REPO" refuses such a repository name, and puts "--"
112 # before the host.
@@ -114,35 +111,37 @@
114 ssh_run ui --nobrowser hh:dir/repo.fossil
115 test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
116 && [string first "<dir/repo.fossil>" $sshArgs] >= 0}
117 ssh_run ui --nobrowser "hh:dir/a;b.fossil"
118 test ssh-ui-refused-semicolon \
119 {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0}
120 ssh_run ui --nobrowser "hh:dir/a b.fossil"
121 test ssh-ui-refused-space \
122 {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0}
123 ssh_run ui --nobrowser -- "-x@hh:dir/repo.fossil"
124 test ssh-ui-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
125
126 ###############################################################################
127 # "fossil patch push" and "fossil patch pull" put "--" before the host.
128
129 write_file ssh-file.txt "one\n"
130 fossil add ssh-file.txt
131 ssh_run patch push -- "-x@hh:dir"
132 test ssh-patch-push-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
 
133 ssh_run patch pull -- "-x@hh:dir"
134 test ssh-patch-pull-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
 
135
136 ###############################################################################
137 # An argument that begins with "~" is quoted, so that the shell does not
138 # replace it with a home directory.
139
140 ssh_run test-escaped-arg ~ ~root/x
141 test ssh-escaped-tilde {[string first {argv[2] = [~]} $sshOut] >= 0
142 && [string first {argv[2] = [~root/x]} $sshOut] >= 0}
143
144 ###############################################################################
145
146 set ::env(PATH) $sshSavedPath
147 unset ::env(SSHTESTLOG)
148 test_cleanup
149
150 DDED test/standin/log-args.sh
151 DDED test/standin/transport.sh
--- test/ssh.test
+++ test/ssh.test
@@ -1,11 +1,11 @@
1 #
2 # What fossil puts on an ssh command line. Nothing here connects to
3 # another machine: "ssh" is a copy of standin/log-args.sh, which writes
4 # down its arguments and exits. A command that has the --ssh-command
5 # option is given the script with it. The other commands find the
6 # script first on the PATH.
7 #
8 # Whatever follows the host on an ssh command line is joined into one
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,
@@ -20,15 +20,13 @@
20
21 test_setup
22
23 set sshDir [file join [pwd] ssh-standin]
24 file mkdir $sshDir
25 set sshStub [test_standin log-args.sh [file join $sshDir ssh]]
26 set sshLog [file join [pwd] ssh-args.txt]
27 set ::env(ARGS_LOG) $sshLog
 
 
28 set sshSavedPath $::env(PATH)
29 set ::env(PATH) "$sshDir:$::env(PATH)"
30
31 # The stand-in must be what "ssh" means from here on. If it is not, run
32 # nothing that could start the real one.
@@ -36,22 +34,20 @@
34 set ::env(PATH) $sshSavedPath
35 test_cleanup
36 test_skip "cannot put a stand-in for ssh first on the PATH"
37 }
38
39 # Run fossil with the arguments given. Sets RESULT to everything it
40 # printed and sshArgs to the arguments the stand-in was given, one per
41 # line inside <>, or to an empty string if it was not run.
42 proc ssh_run {args} {
43 global sshArgs sshLog
44 file delete $sshLog
45 fossil_raw {*}$args
46 set sshArgs ""
47 if {[file exists $sshLog]} {
48 set sshArgs [read_file $sshLog]
 
 
49 }
50 }
51 proc ssh_clone {url} {
52 file delete ssh-clone.fossil
53 ssh_run clone --ssh-command $::sshStub $url ssh-clone.fossil
@@ -60,24 +56,25 @@
56 ###############################################################################
57 # Ordinary URLs reach ssh, with "--" before the host and the path as one
58 # argument.
59
60 ssh_clone ssh://hh/dir/repo.fossil
61 test ssh-clone-plain \
62 {[holds_strings $sshArgs \
63 [list "<-->\n<hh>\n" "<test-http>\n<dir/repo.fossil>"]]}
64 ssh_clone ssh://uu@hh:2222/dir/repo.fossil
65 test ssh-clone-user-port \
66 {[holds_strings $sshArgs [list "<-p>\n<2222>\n" "<-->\n<uu@hh>\n"]]}
67 ssh_clone "ssh://hh/dir/a-b_c.d,e=f@g/repo.fossil"
68 test ssh-clone-punctuation \
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
@@ -93,20 +90,20 @@
90 parenthesis ssh://hh/a(b).fossil
91 redirect ssh://hh/a>b.fossil
92 } {
93 ssh_clone $sshUrl
94 test ssh-clone-refused-$sshName \
95 {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
96 }
97 foreach {sshName sshUrl} {
98 semicolon ssh://hh/repo.fossil?fossil=a;b/fossil
99 dollar ssh://hh/repo.fossil?fossil=$HOME/bin/fossil
100 other ssh://hh/repo.fossil?fossil=/bin/other
101 } {
102 ssh_clone $sshUrl
103 test ssh-clone-fossil-refused-$sshName \
104 {$sshArgs eq "" && [string first "unsafe command" $RESULT] >= 0}
105 }
106
107 ###############################################################################
108 # "fossil ui HOST:REPO" refuses such a repository name, and puts "--"
109 # before the host.
@@ -114,35 +111,37 @@
111 ssh_run ui --nobrowser hh:dir/repo.fossil
112 test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
113 && [string first "<dir/repo.fossil>" $sshArgs] >= 0}
114 ssh_run ui --nobrowser "hh:dir/a;b.fossil"
115 test ssh-ui-refused-semicolon \
116 {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
117 ssh_run ui --nobrowser "hh:dir/a b.fossil"
118 test ssh-ui-refused-space \
119 {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
120 ssh_run ui --nobrowser -- "-x@hh:dir/repo.fossil"
121 test ssh-ui-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
122
123 ###############################################################################
124 # "fossil patch push" and "fossil patch pull" put "--" before the host.
125
126 write_file ssh-file.txt "one\n"
127 fossil add ssh-file.txt
128 ssh_run patch push -- "-x@hh:dir"
129 test ssh-patch-push-user-with-dash \
130 {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
131 ssh_run patch pull -- "-x@hh:dir"
132 test ssh-patch-pull-user-with-dash \
133 {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0}
134
135 ###############################################################################
136 # An argument that begins with "~" is quoted, so that the shell does not
137 # replace it with a home directory.
138
139 ssh_run test-escaped-arg ~ ~root/x
140 test ssh-escaped-tilde {[string first {argv[2] = [~]} $RESULT] >= 0
141 && [string first {argv[2] = [~root/x]} $RESULT] >= 0}
142
143 ###############################################################################
144
145 set ::env(PATH) $sshSavedPath
146 unset ::env(ARGS_LOG)
147 test_cleanup
148
149 DDED test/standin/log-args.sh
150 DDED test/standin/transport.sh
--- a/test/standin/log-args.sh
+++ b/test/standin/log-args.sh
@@ -0,0 +1,8 @@
1
+#!/bin/sh
2
+# Stands in for a program that fossil runs, such as ssh or a merge tool.
3
+# Appends each of its arguments to the file $ARGS_LOG, on a line of its
4
+# own inside <>, and exits with status 1 without doing anything else.
5
+for argument in "$@"; do
6
+ printf '<%s>\n' "$argument"
7
+done >> "$ARGS_LOG"
8
+exit 1
--- a/test/standin/log-args.sh
+++ b/test/standin/log-args.sh
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
--- a/test/standin/log-args.sh
+++ b/test/standin/log-args.sh
@@ -0,0 +1,8 @@
1 #!/bin/sh
2 # Stands in for a program that fossil runs, such as ssh or a merge tool.
3 # Appends each of its arguments to the file $ARGS_LOG, on a line of its
4 # own inside <>, and exits with status 1 without doing anything else.
5 for argument in "$@"; do
6 printf '<%s>\n' "$argument"
7 done >> "$ARGS_LOG"
8 exit 1
--- a/test/standin/transport.sh
+++ b/test/standin/transport.sh
@@ -0,0 +1,20 @@
1
+#!/bin/sh
2
+# Stands in for a server. A test gives it to "fossil sync", "pull" or
3
+# "push" as the --transport-command, and fossil calls it for each request:
4
+#
5
+# transport.sh URL REQUESTFILE REPLYFILE
6
+#
7
+# Request N is saved as request.N in the directory $TRANSPORT_DIR and
8
+# answered with reply.N from there. Where the test wrote no reply.N, the
9
+# answer is a bare timestamp, which ends the sync. Request 21 fails, so
10
+# that a client that keeps asking is stopped.
11
+count=$(cat "$TRANSPORT_DIR/count" 2>/dev/null || echo 0)
12
+count=$((count + 1))
13
+echo $count > "$TRANSPORT_DIR/count"
14
+cp "$2" "$TRANSPORT_DIR/request.$count"
15
+if test $count -gt 20; then exit 1; fi
16
+if test -f "$TRANSPORT_DIR/reply.$count"; then
17
+ cp "$TRANSPORT_DIR/reply.$count" "$3"
18
+else
19
+ printf '# timestamp %s errors 0\n' "$(date -u +%Y-%m-%dT%H:%M:%S)" > "$3"
20
+fi
--- a/test/standin/transport.sh
+++ b/test/standin/transport.sh
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/standin/transport.sh
+++ b/test/standin/transport.sh
@@ -0,0 +1,20 @@
1 #!/bin/sh
2 # Stands in for a server. A test gives it to "fossil sync", "pull" or
3 # "push" as the --transport-command, and fossil calls it for each request:
4 #
5 # transport.sh URL REQUESTFILE REPLYFILE
6 #
7 # Request N is saved as request.N in the directory $TRANSPORT_DIR and
8 # answered with reply.N from there. Where the test wrote no reply.N, the
9 # answer is a bare timestamp, which ends the sync. Request 21 fails, so
10 # that a client that keeps asking is stopped.
11 count=$(cat "$TRANSPORT_DIR/count" 2>/dev/null || echo 0)
12 count=$((count + 1))
13 echo $count > "$TRANSPORT_DIR/count"
14 cp "$2" "$TRANSPORT_DIR/request.$count"
15 if test $count -gt 20; then exit 1; fi
16 if test -f "$TRANSPORT_DIR/reply.$count"; then
17 cp "$TRANSPORT_DIR/reply.$count" "$3"
18 else
19 printf '# timestamp %s errors 0\n' "$(date -u +%Y-%m-%dT%H:%M:%S)" > "$3"
20 fi
+15 -11
--- test/sync.test
+++ test/sync.test
@@ -28,12 +28,10 @@
2828
WHERE type='ci' AND rid NOT IN private\
2929
ORDER BY uuid"
3030
return [normalize_result]
3131
}
3232
33
-# Returns the number of private artifacts in repository REPO.
34
-#
3533
proc sync_private_count {repo} {
3634
fossil sql -R $repo "SELECT count(*) FROM private"
3735
return [normalize_result]
3836
}
3937
@@ -52,17 +50,19 @@
5250
write_file [file join $dir $file] "$comment\n"
5351
fossil add $file --chdir $dir
5452
fossil commit -m $comment --chdir $dir {*}$args
5553
}
5654
57
-# N bytes of deterministic pseudo-random binary data.
58
-proc sync_random_bytes {n} {
59
- set s ""
60
- for {set syncI 0} {$syncI < $n} {incr syncI 4} {
61
- append s [binary format i [expr {int(rand()*4294967296)}]]
55
+# Returns COUNT bytes of pseudo-random binary data, the same bytes for
56
+# the same seed given to srand().
57
+#
58
+proc sync_random_bytes {count} {
59
+ set bytes ""
60
+ while {[string length $bytes] < $count} {
61
+ append bytes [binary format i [expr {int(rand()*4294967296)}]]
6262
}
63
- return [string range $s 0 [expr {$n-1}]]
63
+ return [string range $bytes 0 [expr {$count-1}]]
6464
}
6565
6666
# The origin repository, with three check-ins, a tag and a wiki page.
6767
fossil new a.fossil
6868
fossil user capabilities nobody gio -R a.fossil
@@ -166,17 +166,21 @@
166166
if {$::tcl_platform(platform) ne "windows"} {
167167
fossil new nr.fossil
168168
file mkdir nr
169169
fossil open ../nr.fossil --chdir nr
170170
sync_commit nr nf.txt one
171
- set syncWrapper [file join $dir no-reply.sh]
172
- write_file $syncWrapper "#!/bin/sh\n: >\"\$3\"\n"
173
- file attributes $syncWrapper -permissions 0755
171
+ set syncWire [file join $dir no-reply]
172
+ file mkdir $syncWire
173
+ write_file [file join $syncWire reply.1] ""
174
+ set ::env(TRANSPORT_DIR) $syncWire
175
+ set syncWrapper \
176
+ [test_standin transport.sh [file join $syncWire transport.sh]]
174177
fossil sync http://sync-test.invalid/x --once \
175178
--transport-command $syncWrapper --chdir nr -expectError
176179
test sync-no-reply-fails {$CODE != 0}
177180
test_match sync-no-reply-message [normalize_result] {empty reply}
181
+ unset ::env(TRANSPORT_DIR)
178182
fossil close --chdir nr
179183
}
180184
181185
###############################################################################
182186
# An unversioned file pushed together with a commit that spans more than
183187
--- test/sync.test
+++ test/sync.test
@@ -28,12 +28,10 @@
28 WHERE type='ci' AND rid NOT IN private\
29 ORDER BY uuid"
30 return [normalize_result]
31 }
32
33 # Returns the number of private artifacts in repository REPO.
34 #
35 proc sync_private_count {repo} {
36 fossil sql -R $repo "SELECT count(*) FROM private"
37 return [normalize_result]
38 }
39
@@ -52,17 +50,19 @@
52 write_file [file join $dir $file] "$comment\n"
53 fossil add $file --chdir $dir
54 fossil commit -m $comment --chdir $dir {*}$args
55 }
56
57 # N bytes of deterministic pseudo-random binary data.
58 proc sync_random_bytes {n} {
59 set s ""
60 for {set syncI 0} {$syncI < $n} {incr syncI 4} {
61 append s [binary format i [expr {int(rand()*4294967296)}]]
 
 
62 }
63 return [string range $s 0 [expr {$n-1}]]
64 }
65
66 # The origin repository, with three check-ins, a tag and a wiki page.
67 fossil new a.fossil
68 fossil user capabilities nobody gio -R a.fossil
@@ -166,17 +166,21 @@
166 if {$::tcl_platform(platform) ne "windows"} {
167 fossil new nr.fossil
168 file mkdir nr
169 fossil open ../nr.fossil --chdir nr
170 sync_commit nr nf.txt one
171 set syncWrapper [file join $dir no-reply.sh]
172 write_file $syncWrapper "#!/bin/sh\n: >\"\$3\"\n"
173 file attributes $syncWrapper -permissions 0755
 
 
 
174 fossil sync http://sync-test.invalid/x --once \
175 --transport-command $syncWrapper --chdir nr -expectError
176 test sync-no-reply-fails {$CODE != 0}
177 test_match sync-no-reply-message [normalize_result] {empty reply}
 
178 fossil close --chdir nr
179 }
180
181 ###############################################################################
182 # An unversioned file pushed together with a commit that spans more than
183
--- test/sync.test
+++ test/sync.test
@@ -28,12 +28,10 @@
28 WHERE type='ci' AND rid NOT IN private\
29 ORDER BY uuid"
30 return [normalize_result]
31 }
32
 
 
33 proc sync_private_count {repo} {
34 fossil sql -R $repo "SELECT count(*) FROM private"
35 return [normalize_result]
36 }
37
@@ -52,17 +50,19 @@
50 write_file [file join $dir $file] "$comment\n"
51 fossil add $file --chdir $dir
52 fossil commit -m $comment --chdir $dir {*}$args
53 }
54
55 # Returns COUNT bytes of pseudo-random binary data, the same bytes for
56 # the same seed given to srand().
57 #
58 proc sync_random_bytes {count} {
59 set bytes ""
60 while {[string length $bytes] < $count} {
61 append bytes [binary format i [expr {int(rand()*4294967296)}]]
62 }
63 return [string range $bytes 0 [expr {$count-1}]]
64 }
65
66 # The origin repository, with three check-ins, a tag and a wiki page.
67 fossil new a.fossil
68 fossil user capabilities nobody gio -R a.fossil
@@ -166,17 +166,21 @@
166 if {$::tcl_platform(platform) ne "windows"} {
167 fossil new nr.fossil
168 file mkdir nr
169 fossil open ../nr.fossil --chdir nr
170 sync_commit nr nf.txt one
171 set syncWire [file join $dir no-reply]
172 file mkdir $syncWire
173 write_file [file join $syncWire reply.1] ""
174 set ::env(TRANSPORT_DIR) $syncWire
175 set syncWrapper \
176 [test_standin transport.sh [file join $syncWire transport.sh]]
177 fossil sync http://sync-test.invalid/x --once \
178 --transport-command $syncWrapper --chdir nr -expectError
179 test sync-no-reply-fails {$CODE != 0}
180 test_match sync-no-reply-message [normalize_result] {empty reply}
181 unset ::env(TRANSPORT_DIR)
182 fossil close --chdir nr
183 }
184
185 ###############################################################################
186 # An unversioned file pushed together with a commit that spans more than
187
--- test/wiki.test
+++ test/wiki.test
@@ -406,9 +406,19 @@
406406
fossil wiki create tcltest-plain-short f1 -mimetype plain
407407
test wiki-56 {[get_mime_type tcltest-plain-short] == "text/plain"}
408408
fossil wiki create tcltest-x-random-short f1 -mimetype random
409409
test wiki-57 {[get_mime_type tcltest-x-random-short] == "text/x-fossil-wiki"}
410410
411
+###############################################################################
412
+# A wiki tag with an unrecognized attribute whose value is not quoted took
413
+# the text after the tag as attributes of the tag, and the scan could run
414
+# past the end of the text.
415
+
416
+write_file wiki-attr.wiki "x <span foo=bar>id=zz title=yy more</span> end\n"
417
+fossil test-wiki-render wiki-attr.wiki
418
+test wiki-ignored-attribute \
419
+ {$CODE == 0
420
+ && [string first {<span>id=zz title=yy more</span>} $RESULT] >= 0}
411421
412422
###############################################################################
413423
test_cleanup
414424
415425
--- test/wiki.test
+++ test/wiki.test
@@ -406,9 +406,19 @@
406 fossil wiki create tcltest-plain-short f1 -mimetype plain
407 test wiki-56 {[get_mime_type tcltest-plain-short] == "text/plain"}
408 fossil wiki create tcltest-x-random-short f1 -mimetype random
409 test wiki-57 {[get_mime_type tcltest-x-random-short] == "text/x-fossil-wiki"}
410
 
 
 
 
 
 
 
 
 
 
411
412 ###############################################################################
413 test_cleanup
414
415
--- test/wiki.test
+++ test/wiki.test
@@ -406,9 +406,19 @@
406 fossil wiki create tcltest-plain-short f1 -mimetype plain
407 test wiki-56 {[get_mime_type tcltest-plain-short] == "text/plain"}
408 fossil wiki create tcltest-x-random-short f1 -mimetype random
409 test wiki-57 {[get_mime_type tcltest-x-random-short] == "text/x-fossil-wiki"}
410
411 ###############################################################################
412 # A wiki tag with an unrecognized attribute whose value is not quoted took
413 # the text after the tag as attributes of the tag, and the scan could run
414 # past the end of the text.
415
416 write_file wiki-attr.wiki "x <span foo=bar>id=zz title=yy more</span> end\n"
417 fossil test-wiki-render wiki-attr.wiki
418 test wiki-ignored-attribute \
419 {$CODE == 0
420 && [string first {<span>id=zz title=yy more</span>} $RESULT] >= 0}
421
422 ###############################################################################
423 test_cleanup
424
425
+109 -145
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -1,15 +1,14 @@
11
#
2
-# Hand the client side of the sync protocol replies that a server would
3
-# not normally give, and require that each is answered as documented and
4
-# without a crash. No server is involved: "fossil pull" and "fossil push"
5
-# are given a --transport-command, a script that saves each request and
6
-# answers with a reply prepared by the test. When the prepared replies
7
-# run out it answers with a bare timestamp, which ends the sync.
8
-#
9
-# This complements xfer-cards.test and xfer-server.test, which do the
10
-# same for the server side through "fossil test-xfer".
2
+# Replies that a server would not normally give, sent to the client side
3
+# of the sync protocol. The client must handle each as documented and
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.
1110
#
1211
1312
require_no_open_checkout
1413
1514
if {$::tcl_platform(platform) eq "windows"} {
@@ -19,93 +18,65 @@
1918
test_setup
2019
2120
write_file a.txt "hello world\n"
2221
fossil add a.txt
2322
fossil commit -m one --no-warnings
24
-fossil sql "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\
25
- JOIN filename f USING(fnid) WHERE f.name='a.txt'"
26
-set xferclientFile [string trim $::RESULT]
23
+fossil sha3sum a.txt
24
+set xferclientFile [lindex $RESULT 0]
2725
set xferclientAbsent [string repeat 0123456789abcdef 4]
2826
2927
set xferclientDir [file join [pwd] xferclient-wire]
3028
file mkdir $xferclientDir
31
-set xferclientWire [file join $xferclientDir wire.sh]
32
-write_file $xferclientWire {#!/bin/sh
33
-# Called as: wire.sh URL REQUESTFILE REPLYFILE
34
-n=`cat "$XFERCLIENT_DIR/count" 2>/dev/null || echo 0`
35
-n=`expr $n + 1`
36
-echo $n > "$XFERCLIENT_DIR/count"
37
-cp "$2" "$XFERCLIENT_DIR/request.$n"
38
-if test $n -gt 20; then exit 1; fi
39
-if test -f "$XFERCLIENT_DIR/reply.$n"; then
40
- cp "$XFERCLIENT_DIR/reply.$n" "$3"
41
-else
42
- printf '# timestamp %s errors 0\n' "`date -u +%Y-%m-%dT%H:%M:%S`" > "$3"
43
-fi
44
-}
45
-file attributes $xferclientWire -permissions 0755
46
-set ::env(XFERCLIENT_DIR) $xferclientDir
47
-
48
-# Run "fossil VERB" against the stand-in, which answers the first request
49
-# with REPLY. Further arguments are options for the command. Sets
50
-# xferclientRc to the exit status (0, or 1 for any failure that is not a
51
-# crash), xferclientOut to what fossil printed, xferclientRounds to the
52
-# number of requests made, and xferclientSecond to the second request, or
53
-# an empty string if there was only one.
54
-proc xferclient_run {verb reply args} {
55
- global xferclientDir xferclientWire xferclientRc xferclientOut
56
- global xferclientRounds xferclientSecond
57
- foreach xferclientF [glob -nocomplain -directory $xferclientDir \
58
- reply.* request.* count] {
59
- file delete $xferclientF
60
- }
61
- write_file [file join $xferclientDir reply.1] $reply
62
- set xferclientRc 0
63
- if {[catch {exec $::fossilexe $verb http://localhost/x --once \
64
- --transport-command $xferclientWire {*}$args \
65
- < /dev/null 2>@1} xferclientOut]} {
66
- set xferclientRc 1
67
- if {[lindex $::errorCode 0] ne "CHILDSTATUS"
68
- || [lindex $::errorCode 2] != 1} {
69
- set xferclientRc crash
70
- }
71
- }
72
- set xferclientRounds 0
73
- set xferclientSecond ""
74
- set xferclientF [file join $xferclientDir count]
75
- if {[file exists $xferclientF]} {
76
- set xferclientFd [open $xferclientF r]
77
- set xferclientRounds [string trim [read $xferclientFd]]
78
- close $xferclientFd
79
- }
80
- set xferclientF [file join $xferclientDir request.2]
81
- if {[file exists $xferclientF]} {
82
- set xferclientFd [open $xferclientF rb]
83
- set xferclientSecond [read $xferclientFd]
84
- close $xferclientFd
85
- }
86
-}
87
-
88
-# Run one case and require an exit status and, in the output, each of the
89
-# strings given. A string that begins with "!" must be absent.
90
-proc xferclient_expect {name verb reply rc opts args} {
91
- global xferclientRc xferclientOut xferclientRounds
92
- xferclient_run $verb $reply {*}$opts
93
- set xferclientGood [expr {$xferclientRc eq $rc && $xferclientRounds <= 20}]
94
- foreach xferclientWant $args {
95
- if {[string index $xferclientWant 0] eq "!"} {
96
- if {[string first [string range $xferclientWant 1 end] \
97
- $xferclientOut] >= 0} {set xferclientGood 0}
98
- } elseif {[string first $xferclientWant $xferclientOut] < 0} {
99
- set xferclientGood 0
100
- }
101
- }
102
- if {!$xferclientGood} {
103
- puts " $name: status $xferclientRc after $xferclientRounds requests:\
104
- $xferclientOut"
105
- }
106
- test xfer-client-$name {$xferclientGood}
29
+set xferclientWire \
30
+ [test_standin transport.sh [file join $xferclientDir transport.sh]]
31
+set ::env(TRANSPORT_DIR) $xferclientDir
32
+
33
+# Run "fossil VERB" against the stand-in, which answers request N with
34
+# item N of the list REPLIES. Further arguments are options for the
35
+# command. Sets xferclientCode to the exit status, or to "crash", and
36
+# xferclientOut to what fossil printed.
37
+proc xferclient_sync {verb replies args} {
38
+ global xferclientDir xferclientWire xferclientCode xferclientOut
39
+ file delete {*}[glob -nocomplain -directory $xferclientDir \
40
+ reply.* request.* count]
41
+ set number 0
42
+ foreach reply $replies {
43
+ write_file [file join $xferclientDir reply.[incr number]] $reply
44
+ }
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
+
55
+# Returns request NUMBER of the last run, or an empty string if fossil
56
+# made fewer requests.
57
+proc xferclient_request {number} {
58
+ set file [file join $::xferclientDir request.$number]
59
+ if {![file exists $file]} {
60
+ return ""
61
+ }
62
+ return [read_file $file]
63
+}
64
+
65
+proc xferclient_requests {} {
66
+ return [llength [glob -nocomplain -directory $::xferclientDir request.*]]
67
+}
68
+
69
+# Run one case. Test NAME passes when the exit status is CODE and the
70
+# output holds each of the strings given. A string that begins with "!"
71
+# must be absent.
72
+proc xferclient_expect {name verb reply code options args} {
73
+ global xferclientCode xferclientOut
74
+ xferclient_run $verb $reply {*}$options
75
+ test xfer-client-$name {$xferclientCode eq $code
76
+ && [xferclient_requests] <= 20
77
+ && [holds_strings $xferclientOut $args]}
10778
}
10879
10980
###############################################################################
11081
# Messages and errors from the server.
11182
@@ -115,35 +86,36 @@
11586
"Server says: hi" "Received:"
11687
xferclient_expect pull-only-message push \
11788
"message pull\\sonly\\s-\\snot\\sauthorized\\sto\\spush\n" 0 {}
11889
xferclient_expect error pull "error something\\sfailed\n" 1 {} \
11990
"Error: something failed"
120
-xferclient_expect html-reply pull "<html><body>Not found</body></html>\n" 1 {} \
121
- "server replies with HTML"
91
+xferclient_expect html-reply pull \
92
+ "<html><body>Not found</body></html>\n" 1 {} "server replies with HTML"
12293
xferclient_expect unknown-card pull "frobnicate 1 2\n" 1 {} "unknown command"
12394
xferclient_expect push-card-outside-clone pull \
12495
"push $xferclientAbsent $xferclientAbsent\n" 1 {} "unknown command"
12596
xferclient_expect empty-reply pull "" 1 {}
12697
12798
###############################################################################
128
-# Pragmas, cookies and other cards that carry no content.
99
+# Pragmas, cookies and other cards without content.
129100
130
-xferclient_expect server-version pull \
131
- "pragma server-version 22900 20261110 124827\n" 0 {}
101
+xferclient_expect server-version pull $SERVER_VERSION_CARD 0 {}
132102
xferclient_expect server-version-short pull "pragma server-version 22900\n" 0 {}
133103
xferclient_expect uv-pull-only pull "pragma uv-pull-only\n" 0 {}
134104
xferclient_expect uv-push-ok pull "pragma uv-push-ok\n" 0 {}
135
-xferclient_expect avoid-delta-manifests pull "pragma avoid-delta-manifests\n" 0 {}
105
+xferclient_expect avoid-delta-manifests pull \
106
+ "pragma avoid-delta-manifests\n" 0 {}
136107
xferclient_expect unknown-pragma pull "pragma no-such-pragma 1 2\n" 0 {}
137108
xferclient_expect pragma-alone pull "pragma\n" 1 {} "unknown command"
138109
xferclient_expect ci-lock-fail pull \
139110
"pragma ci-lock-fail someone 1700000000\n" 0 {} \
140111
"Parent check-in locked by someone"
141112
xferclient_expect ci-lock-fail-negative-time pull \
142113
"pragma ci-lock-fail someone -5\n" 0 {} "Parent check-in locked by someone"
143114
xferclient_expect ci-lock-fail-bad-time pull \
144
- "pragma ci-lock-fail someone notint\n" 0 {} "Parent check-in locked by someone"
115
+ "pragma ci-lock-fail someone notint\n" 0 {} \
116
+ "Parent check-in locked by someone"
145117
xferclient_expect link pull \
146118
"pragma link http://example.org/z {} 1790000000\n" 0 {--share-links}
147119
xferclient_expect link-not-asked-for pull \
148120
"pragma link http://example.org/y {} 1790000000\n" 0 {}
149121
xferclient_expect cookie pull "cookie abc\n" 0 {}
@@ -165,90 +137,79 @@
165137
# igot and gimme. What the client asks for, or sends, shows in its
166138
# second request.
167139
168140
xferclient_run pull "igot $xferclientAbsent\n"
169141
test xfer-client-igot-asks-for-it \
170
- {$xferclientRc eq 0
171
- && [string first "gimme $xferclientAbsent" $xferclientSecond] >= 0}
172
-set xferclientAbsent2 [string repeat fedcba9876543210 4]
173
-xferclient_run pull "igot $xferclientAbsent2 1\n"
142
+ {$xferclientCode == 0
143
+ && [string first "gimme $xferclientAbsent" [xferclient_request 2]] >= 0}
144
+# A hash that the client hears of only as private, or only in a push.
145
+set xferclientPrivate [string repeat fedcba9876543210 4]
146
+xferclient_run pull "igot $xferclientPrivate 1\n"
174147
test xfer-client-igot-private-not-asked-for \
175
- {$xferclientRc eq 0
176
- && [string first "gimme $xferclientAbsent2" $xferclientSecond] < 0}
148
+ {$xferclientCode == 0
149
+ && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0}
177150
xferclient_run pull "igot $xferclientFile\n"
178151
test xfer-client-igot-held-not-asked-for \
179
- {$xferclientRc eq 0
180
- && [string first "gimme $xferclientFile" $xferclientSecond] < 0}
181
-xferclient_run push "igot $xferclientAbsent2\n"
152
+ {$xferclientCode == 0
153
+ && [string first "gimme $xferclientFile" [xferclient_request 2]] < 0}
154
+xferclient_run push "igot $xferclientPrivate\n"
182155
test xfer-client-igot-on-push-not-asked-for \
183
- {$xferclientRc eq 0
184
- && [string first "gimme $xferclientAbsent2" $xferclientSecond] < 0}
156
+ {$xferclientCode == 0
157
+ && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0}
185158
xferclient_expect igot-not-a-hash pull "igot nothash\n" 1 {} "unknown command"
186159
xferclient_expect igot-alone pull "igot\n" 1 {} "unknown command"
187160
188161
xferclient_run push "gimme $xferclientFile\n"
189162
test xfer-client-gimme-sends-it \
190
- {$xferclientRc eq 0
191
- && [string first "file $xferclientFile" $xferclientSecond] >= 0}
163
+ {$xferclientCode == 0
164
+ && [string first "file $xferclientFile" [xferclient_request 2]] >= 0}
192165
xferclient_run pull "gimme $xferclientFile\n"
193166
test xfer-client-gimme-on-pull-sends-nothing \
194
- {$xferclientRc eq 0
195
- && [string first "file $xferclientFile" $xferclientSecond] < 0}
167
+ {$xferclientCode == 0
168
+ && [string first "file $xferclientFile" [xferclient_request 2]] < 0}
196169
xferclient_expect gimme-absent push "gimme $xferclientAbsent\n" 0 {}
197
-xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} "unknown command"
170
+xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \
171
+ "unknown command"
198172
199173
###############################################################################
200174
# An igot card can say that an artifact is private. The client marks its
201175
# own copy private only in a sync of private content. In an ordinary
202
-# pull a server used to be able to make a public check-in private, after
176
+# pull a server could previously make a public check-in private, after
203177
# which the client sent it to nobody.
204178
205179
fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT max(objid) FROM event\
206180
WHERE type='ci')"
207181
set xferclientCkin [string trim $::RESULT]
208182
xferclient_run pull "igot $xferclientCkin 1\n"
209183
fossil sql "SELECT count(*) FROM private"
210184
test xfer-client-igot-private-in-pull-marks-nothing \
211
- {$xferclientRc eq 0 && [string trim $RESULT] == 0}
185
+ {$xferclientCode == 0 && [string trim $RESULT] == 0}
212186
xferclient_run pull "igot $xferclientCkin 1\n" --private
213187
fossil sql "SELECT count(*) FROM private"
214188
test xfer-client-igot-private-in-private-pull-marks-it \
215
- {$xferclientRc eq 0 && [string trim $RESULT] == 1}
189
+ {$xferclientCode == 0 && [string trim $RESULT] == 1}
216190
xferclient_run pull "igot $xferclientCkin\n"
217191
fossil sql "SELECT count(*) FROM private"
218192
test xfer-client-igot-public-unmarks-it \
219
- {$xferclientRc eq 0 && [string trim $RESULT] == 0}
193
+ {$xferclientCode == 0 && [string trim $RESULT] == 0}
220194
221195
# An artifact that the client has asked for and does not hold yet is still
222196
# marked: the server says it is private, and the client stops asking.
223
-set xferclientAbsent3 [string repeat 00112233445566778899aabbccddeeff 2]
224
-proc xferclient_run_two {verb reply1 reply2} {
225
- global xferclientDir xferclientWire xferclientRc
226
- foreach xferclientF [glob -nocomplain -directory $xferclientDir \
227
- reply.* request.* count] {
228
- file delete $xferclientF
229
- }
230
- write_file [file join $xferclientDir reply.1] $reply1
231
- write_file [file join $xferclientDir reply.2] $reply2
232
- set xferclientRc [catch {exec $::fossilexe $verb http://localhost/x --once \
233
- --transport-command $xferclientWire < /dev/null 2>@1}]
234
-}
235
-xferclient_run_two pull "igot $xferclientAbsent3\n" "igot $xferclientAbsent3 1\n"
197
+set xferclientPhantom [string repeat 00112233445566778899aabbccddeeff 2]
198
+xferclient_sync pull \
199
+ [list "igot $xferclientPhantom\n" "igot $xferclientPhantom 1\n"]
236200
fossil sql "SELECT count(*) FROM private p, blob b\
237
- WHERE b.rid=p.rid AND b.uuid='$xferclientAbsent3'"
201
+ WHERE b.rid=p.rid AND b.uuid='$xferclientPhantom'"
238202
test xfer-client-igot-private-marks-a-phantom \
239
- {$xferclientRc == 0 && [string trim $RESULT] == 1}
203
+ {$xferclientCode == 0 && [string trim $RESULT] == 1}
240204
xferclient_run pull "# nothing\n"
241
-set xferclientFd [open [file join $xferclientDir request.1] rb]
242
-set xferclientFirst [read $xferclientFd]
243
-close $xferclientFd
244205
test xfer-client-private-phantom-not-asked-for-again \
245
- {[string first "gimme $xferclientAbsent3" $xferclientFirst] < 0}
206
+ {[string first "gimme $xferclientPhantom" [xferclient_request 1]] < 0}
246207
247208
###############################################################################
248
-# Artifacts are accepted only in a sync that pulls. A server used to be
249
-# able to add one to the client in answer to a push. The hash is that of
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
250211
# the five bytes "hello" under SHA3-256.
251212
252213
set xferclientHello \
253214
3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392
254215
fossil sql "SELECT count(*) FROM blob"
@@ -261,28 +222,30 @@
261222
test xfer-client-file-in-push-stores-nothing \
262223
{[string trim $RESULT] == $xferclientBlobs}
263224
xferclient_run pull "file $xferclientHello 5\nhello\n"
264225
fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientHello'"
265226
test xfer-client-file-in-pull-stored \
266
- {$xferclientRc eq 0 && [string trim $RESULT] == 1}
227
+ {$xferclientCode == 0 && [string trim $RESULT] == 1}
267228
268229
###############################################################################
269230
# Content that does not match its card is refused and nothing is stored.
270231
271
-xferclient_expect file-wrong-hash pull "file $xferclientAbsent 5\nhello\n" 1 {} \
272
- "wrong hash on received artifact"
273
-fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientAbsent' AND size>=0"
232
+xferclient_expect file-wrong-hash pull \
233
+ "file $xferclientAbsent 5\nhello\n" 1 {} "wrong hash on received artifact"
234
+fossil sql \
235
+ "SELECT count(*) FROM blob WHERE uuid='$xferclientAbsent' AND size>=0"
274236
test xfer-client-file-wrong-hash-not-stored {[string trim $RESULT] == 0}
275
-xferclient_expect file-size-past-end pull "file $xferclientAbsent 99\nhello\n" 1 {}
237
+xferclient_expect file-size-past-end pull \
238
+ "file $xferclientAbsent 99\nhello\n" 1 {}
276239
xferclient_expect file-too-few-tokens pull "file $xferclientAbsent\n" 1 {}
277240
xferclient_expect file-size-not-a-number pull \
278241
"file $xferclientAbsent notint\nhello\n" 1 {}
279242
xferclient_expect cfile-size-past-end pull \
280243
"cfile $xferclientAbsent 5 99\nxx\n" 1 {}
281244
xferclient_expect config-not-asked-for pull "config /project 0\n\n" 0 {}
282
-xferclient_expect config-size-not-a-number pull "config /project notint\n" 1 {} \
283
- "unknown command"
245
+xferclient_expect config-size-not-a-number pull \
246
+ "config /project notint\n" 1 {} "unknown command"
284247
285248
###############################################################################
286249
# Unversioned files. The cards for them are acted on only in a sync of
287250
# unversioned content, or in a clone. In an ordinary pull a server used
288251
# to be able to replace an unversioned file with a uvfile card that the
@@ -307,15 +270,16 @@
307270
test xfer-client-uvfile-in-pull-changes-nothing \
308271
{[string trim $RESULT] eq "local note"}
309272
xferclient_expect uvigot-bad-mtime pull \
310273
"uvigot note.txt notint $xferclientUvHash 3\n" 1 {} "unknown command"
311274
xferclient_expect uvigot-bad-size pull \
312
- "uvigot note.txt 1700000000 $xferclientUvHash notint\n" 1 {} "unknown command"
275
+ "uvigot note.txt 1700000000 $xferclientUvHash notint\n" 1 {} \
276
+ "unknown command"
313277
xferclient_expect uvigot-bad-hash pull \
314278
"uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
315279
xferclient_expect uvigot-bad-name pull \
316280
"uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
317281
318282
###############################################################################
319283
320
-unset ::env(XFERCLIENT_DIR)
284
+unset ::env(TRANSPORT_DIR)
321285
test_cleanup
322286
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -1,15 +1,14 @@
1 #
2 # Hand the client side of the sync protocol replies that a server would
3 # not normally give, and require that each is answered as documented and
4 # without a crash. No server is involved: "fossil pull" and "fossil push"
5 # are given a --transport-command, a script that saves each request and
6 # answers with a reply prepared by the test. When the prepared replies
7 # run out it answers with a bare timestamp, which ends the sync.
8 #
9 # This complements xfer-cards.test and xfer-server.test, which do the
10 # same for the server side through "fossil test-xfer".
11 #
12
13 require_no_open_checkout
14
15 if {$::tcl_platform(platform) eq "windows"} {
@@ -19,93 +18,65 @@
19 test_setup
20
21 write_file a.txt "hello world\n"
22 fossil add a.txt
23 fossil commit -m one --no-warnings
24 fossil sql "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\
25 JOIN filename f USING(fnid) WHERE f.name='a.txt'"
26 set xferclientFile [string trim $::RESULT]
27 set xferclientAbsent [string repeat 0123456789abcdef 4]
28
29 set xferclientDir [file join [pwd] xferclient-wire]
30 file mkdir $xferclientDir
31 set xferclientWire [file join $xferclientDir wire.sh]
32 write_file $xferclientWire {#!/bin/sh
33 # Called as: wire.sh URL REQUESTFILE REPLYFILE
34 n=`cat "$XFERCLIENT_DIR/count" 2>/dev/null || echo 0`
35 n=`expr $n + 1`
36 echo $n > "$XFERCLIENT_DIR/count"
37 cp "$2" "$XFERCLIENT_DIR/request.$n"
38 if test $n -gt 20; then exit 1; fi
39 if test -f "$XFERCLIENT_DIR/reply.$n"; then
40 cp "$XFERCLIENT_DIR/reply.$n" "$3"
41 else
42 printf '# timestamp %s errors 0\n' "`date -u +%Y-%m-%dT%H:%M:%S`" > "$3"
43 fi
44 }
45 file attributes $xferclientWire -permissions 0755
46 set ::env(XFERCLIENT_DIR) $xferclientDir
47
48 # Run "fossil VERB" against the stand-in, which answers the first request
49 # with REPLY. Further arguments are options for the command. Sets
50 # xferclientRc to the exit status (0, or 1 for any failure that is not a
51 # crash), xferclientOut to what fossil printed, xferclientRounds to the
52 # number of requests made, and xferclientSecond to the second request, or
53 # an empty string if there was only one.
54 proc xferclient_run {verb reply args} {
55 global xferclientDir xferclientWire xferclientRc xferclientOut
56 global xferclientRounds xferclientSecond
57 foreach xferclientF [glob -nocomplain -directory $xferclientDir \
58 reply.* request.* count] {
59 file delete $xferclientF
60 }
61 write_file [file join $xferclientDir reply.1] $reply
62 set xferclientRc 0
63 if {[catch {exec $::fossilexe $verb http://localhost/x --once \
64 --transport-command $xferclientWire {*}$args \
65 < /dev/null 2>@1} xferclientOut]} {
66 set xferclientRc 1
67 if {[lindex $::errorCode 0] ne "CHILDSTATUS"
68 || [lindex $::errorCode 2] != 1} {
69 set xferclientRc crash
70 }
71 }
72 set xferclientRounds 0
73 set xferclientSecond ""
74 set xferclientF [file join $xferclientDir count]
75 if {[file exists $xferclientF]} {
76 set xferclientFd [open $xferclientF r]
77 set xferclientRounds [string trim [read $xferclientFd]]
78 close $xferclientFd
79 }
80 set xferclientF [file join $xferclientDir request.2]
81 if {[file exists $xferclientF]} {
82 set xferclientFd [open $xferclientF rb]
83 set xferclientSecond [read $xferclientFd]
84 close $xferclientFd
85 }
86 }
87
88 # Run one case and require an exit status and, in the output, each of the
89 # strings given. A string that begins with "!" must be absent.
90 proc xferclient_expect {name verb reply rc opts args} {
91 global xferclientRc xferclientOut xferclientRounds
92 xferclient_run $verb $reply {*}$opts
93 set xferclientGood [expr {$xferclientRc eq $rc && $xferclientRounds <= 20}]
94 foreach xferclientWant $args {
95 if {[string index $xferclientWant 0] eq "!"} {
96 if {[string first [string range $xferclientWant 1 end] \
97 $xferclientOut] >= 0} {set xferclientGood 0}
98 } elseif {[string first $xferclientWant $xferclientOut] < 0} {
99 set xferclientGood 0
100 }
101 }
102 if {!$xferclientGood} {
103 puts " $name: status $xferclientRc after $xferclientRounds requests:\
104 $xferclientOut"
105 }
106 test xfer-client-$name {$xferclientGood}
107 }
108
109 ###############################################################################
110 # Messages and errors from the server.
111
@@ -115,35 +86,36 @@
115 "Server says: hi" "Received:"
116 xferclient_expect pull-only-message push \
117 "message pull\\sonly\\s-\\snot\\sauthorized\\sto\\spush\n" 0 {}
118 xferclient_expect error pull "error something\\sfailed\n" 1 {} \
119 "Error: something failed"
120 xferclient_expect html-reply pull "<html><body>Not found</body></html>\n" 1 {} \
121 "server replies with HTML"
122 xferclient_expect unknown-card pull "frobnicate 1 2\n" 1 {} "unknown command"
123 xferclient_expect push-card-outside-clone pull \
124 "push $xferclientAbsent $xferclientAbsent\n" 1 {} "unknown command"
125 xferclient_expect empty-reply pull "" 1 {}
126
127 ###############################################################################
128 # Pragmas, cookies and other cards that carry no content.
129
130 xferclient_expect server-version pull \
131 "pragma server-version 22900 20261110 124827\n" 0 {}
132 xferclient_expect server-version-short pull "pragma server-version 22900\n" 0 {}
133 xferclient_expect uv-pull-only pull "pragma uv-pull-only\n" 0 {}
134 xferclient_expect uv-push-ok pull "pragma uv-push-ok\n" 0 {}
135 xferclient_expect avoid-delta-manifests pull "pragma avoid-delta-manifests\n" 0 {}
 
136 xferclient_expect unknown-pragma pull "pragma no-such-pragma 1 2\n" 0 {}
137 xferclient_expect pragma-alone pull "pragma\n" 1 {} "unknown command"
138 xferclient_expect ci-lock-fail pull \
139 "pragma ci-lock-fail someone 1700000000\n" 0 {} \
140 "Parent check-in locked by someone"
141 xferclient_expect ci-lock-fail-negative-time pull \
142 "pragma ci-lock-fail someone -5\n" 0 {} "Parent check-in locked by someone"
143 xferclient_expect ci-lock-fail-bad-time pull \
144 "pragma ci-lock-fail someone notint\n" 0 {} "Parent check-in locked by someone"
 
145 xferclient_expect link pull \
146 "pragma link http://example.org/z {} 1790000000\n" 0 {--share-links}
147 xferclient_expect link-not-asked-for pull \
148 "pragma link http://example.org/y {} 1790000000\n" 0 {}
149 xferclient_expect cookie pull "cookie abc\n" 0 {}
@@ -165,90 +137,79 @@
165 # igot and gimme. What the client asks for, or sends, shows in its
166 # second request.
167
168 xferclient_run pull "igot $xferclientAbsent\n"
169 test xfer-client-igot-asks-for-it \
170 {$xferclientRc eq 0
171 && [string first "gimme $xferclientAbsent" $xferclientSecond] >= 0}
172 set xferclientAbsent2 [string repeat fedcba9876543210 4]
173 xferclient_run pull "igot $xferclientAbsent2 1\n"
 
174 test xfer-client-igot-private-not-asked-for \
175 {$xferclientRc eq 0
176 && [string first "gimme $xferclientAbsent2" $xferclientSecond] < 0}
177 xferclient_run pull "igot $xferclientFile\n"
178 test xfer-client-igot-held-not-asked-for \
179 {$xferclientRc eq 0
180 && [string first "gimme $xferclientFile" $xferclientSecond] < 0}
181 xferclient_run push "igot $xferclientAbsent2\n"
182 test xfer-client-igot-on-push-not-asked-for \
183 {$xferclientRc eq 0
184 && [string first "gimme $xferclientAbsent2" $xferclientSecond] < 0}
185 xferclient_expect igot-not-a-hash pull "igot nothash\n" 1 {} "unknown command"
186 xferclient_expect igot-alone pull "igot\n" 1 {} "unknown command"
187
188 xferclient_run push "gimme $xferclientFile\n"
189 test xfer-client-gimme-sends-it \
190 {$xferclientRc eq 0
191 && [string first "file $xferclientFile" $xferclientSecond] >= 0}
192 xferclient_run pull "gimme $xferclientFile\n"
193 test xfer-client-gimme-on-pull-sends-nothing \
194 {$xferclientRc eq 0
195 && [string first "file $xferclientFile" $xferclientSecond] < 0}
196 xferclient_expect gimme-absent push "gimme $xferclientAbsent\n" 0 {}
197 xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} "unknown command"
 
198
199 ###############################################################################
200 # An igot card can say that an artifact is private. The client marks its
201 # own copy private only in a sync of private content. In an ordinary
202 # pull a server used to be able to make a public check-in private, after
203 # which the client sent it to nobody.
204
205 fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT max(objid) FROM event\
206 WHERE type='ci')"
207 set xferclientCkin [string trim $::RESULT]
208 xferclient_run pull "igot $xferclientCkin 1\n"
209 fossil sql "SELECT count(*) FROM private"
210 test xfer-client-igot-private-in-pull-marks-nothing \
211 {$xferclientRc eq 0 && [string trim $RESULT] == 0}
212 xferclient_run pull "igot $xferclientCkin 1\n" --private
213 fossil sql "SELECT count(*) FROM private"
214 test xfer-client-igot-private-in-private-pull-marks-it \
215 {$xferclientRc eq 0 && [string trim $RESULT] == 1}
216 xferclient_run pull "igot $xferclientCkin\n"
217 fossil sql "SELECT count(*) FROM private"
218 test xfer-client-igot-public-unmarks-it \
219 {$xferclientRc eq 0 && [string trim $RESULT] == 0}
220
221 # An artifact that the client has asked for and does not hold yet is still
222 # marked: the server says it is private, and the client stops asking.
223 set xferclientAbsent3 [string repeat 00112233445566778899aabbccddeeff 2]
224 proc xferclient_run_two {verb reply1 reply2} {
225 global xferclientDir xferclientWire xferclientRc
226 foreach xferclientF [glob -nocomplain -directory $xferclientDir \
227 reply.* request.* count] {
228 file delete $xferclientF
229 }
230 write_file [file join $xferclientDir reply.1] $reply1
231 write_file [file join $xferclientDir reply.2] $reply2
232 set xferclientRc [catch {exec $::fossilexe $verb http://localhost/x --once \
233 --transport-command $xferclientWire < /dev/null 2>@1}]
234 }
235 xferclient_run_two pull "igot $xferclientAbsent3\n" "igot $xferclientAbsent3 1\n"
236 fossil sql "SELECT count(*) FROM private p, blob b\
237 WHERE b.rid=p.rid AND b.uuid='$xferclientAbsent3'"
238 test xfer-client-igot-private-marks-a-phantom \
239 {$xferclientRc == 0 && [string trim $RESULT] == 1}
240 xferclient_run pull "# nothing\n"
241 set xferclientFd [open [file join $xferclientDir request.1] rb]
242 set xferclientFirst [read $xferclientFd]
243 close $xferclientFd
244 test xfer-client-private-phantom-not-asked-for-again \
245 {[string first "gimme $xferclientAbsent3" $xferclientFirst] < 0}
246
247 ###############################################################################
248 # Artifacts are accepted only in a sync that pulls. A server used to be
249 # able to add one to the client in answer to a push. The hash is that of
250 # the five bytes "hello" under SHA3-256.
251
252 set xferclientHello \
253 3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392
254 fossil sql "SELECT count(*) FROM blob"
@@ -261,28 +222,30 @@
261 test xfer-client-file-in-push-stores-nothing \
262 {[string trim $RESULT] == $xferclientBlobs}
263 xferclient_run pull "file $xferclientHello 5\nhello\n"
264 fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientHello'"
265 test xfer-client-file-in-pull-stored \
266 {$xferclientRc eq 0 && [string trim $RESULT] == 1}
267
268 ###############################################################################
269 # Content that does not match its card is refused and nothing is stored.
270
271 xferclient_expect file-wrong-hash pull "file $xferclientAbsent 5\nhello\n" 1 {} \
272 "wrong hash on received artifact"
273 fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientAbsent' AND size>=0"
 
274 test xfer-client-file-wrong-hash-not-stored {[string trim $RESULT] == 0}
275 xferclient_expect file-size-past-end pull "file $xferclientAbsent 99\nhello\n" 1 {}
 
276 xferclient_expect file-too-few-tokens pull "file $xferclientAbsent\n" 1 {}
277 xferclient_expect file-size-not-a-number pull \
278 "file $xferclientAbsent notint\nhello\n" 1 {}
279 xferclient_expect cfile-size-past-end pull \
280 "cfile $xferclientAbsent 5 99\nxx\n" 1 {}
281 xferclient_expect config-not-asked-for pull "config /project 0\n\n" 0 {}
282 xferclient_expect config-size-not-a-number pull "config /project notint\n" 1 {} \
283 "unknown command"
284
285 ###############################################################################
286 # Unversioned files. The cards for them are acted on only in a sync of
287 # unversioned content, or in a clone. In an ordinary pull a server used
288 # to be able to replace an unversioned file with a uvfile card that the
@@ -307,15 +270,16 @@
307 test xfer-client-uvfile-in-pull-changes-nothing \
308 {[string trim $RESULT] eq "local note"}
309 xferclient_expect uvigot-bad-mtime pull \
310 "uvigot note.txt notint $xferclientUvHash 3\n" 1 {} "unknown command"
311 xferclient_expect uvigot-bad-size pull \
312 "uvigot note.txt 1700000000 $xferclientUvHash notint\n" 1 {} "unknown command"
 
313 xferclient_expect uvigot-bad-hash pull \
314 "uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
315 xferclient_expect uvigot-bad-name pull \
316 "uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
317
318 ###############################################################################
319
320 unset ::env(XFERCLIENT_DIR)
321 test_cleanup
322
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -1,15 +1,14 @@
1 #
2 # Replies that a server would not normally give, sent to the client side
3 # of the sync protocol. The client must handle each as documented and
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"} {
@@ -19,93 +18,65 @@
18 test_setup
19
20 write_file a.txt "hello world\n"
21 fossil add a.txt
22 fossil commit -m one --no-warnings
23 fossil sha3sum a.txt
24 set xferclientFile [lindex $RESULT 0]
 
25 set xferclientAbsent [string repeat 0123456789abcdef 4]
26
27 set xferclientDir [file join [pwd] xferclient-wire]
28 file mkdir $xferclientDir
29 set xferclientWire \
30 [test_standin transport.sh [file join $xferclientDir transport.sh]]
31 set ::env(TRANSPORT_DIR) $xferclientDir
32
33 # Run "fossil VERB" against the stand-in, which answers request N with
34 # item N of the list REPLIES. Further arguments are options for the
35 # command. Sets xferclientCode to the exit status, or to "crash", and
36 # xferclientOut to what fossil printed.
37 proc xferclient_sync {verb replies args} {
38 global xferclientDir xferclientWire xferclientCode xferclientOut
39 file delete {*}[glob -nocomplain -directory $xferclientDir \
40 reply.* request.* count]
41 set number 0
42 foreach reply $replies {
43 write_file [file join $xferclientDir reply.[incr number]] $reply
44 }
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
55 # Returns request NUMBER of the last run, or an empty string if fossil
56 # made fewer requests.
57 proc xferclient_request {number} {
58 set file [file join $::xferclientDir request.$number]
59 if {![file exists $file]} {
60 return ""
61 }
62 return [read_file $file]
63 }
64
65 proc xferclient_requests {} {
66 return [llength [glob -nocomplain -directory $::xferclientDir request.*]]
67 }
68
69 # Run one case. Test NAME passes when the exit status is CODE and the
70 # output holds each of the strings given. A string that begins with "!"
71 # must be absent.
72 proc xferclient_expect {name verb reply code options args} {
73 global xferclientCode xferclientOut
74 xferclient_run $verb $reply {*}$options
75 test xfer-client-$name {$xferclientCode eq $code
76 && [xferclient_requests] <= 20
77 && [holds_strings $xferclientOut $args]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78 }
79
80 ###############################################################################
81 # Messages and errors from the server.
82
@@ -115,35 +86,36 @@
86 "Server says: hi" "Received:"
87 xferclient_expect pull-only-message push \
88 "message pull\\sonly\\s-\\snot\\sauthorized\\sto\\spush\n" 0 {}
89 xferclient_expect error pull "error something\\sfailed\n" 1 {} \
90 "Error: something failed"
91 xferclient_expect html-reply pull \
92 "<html><body>Not found</body></html>\n" 1 {} "server replies with HTML"
93 xferclient_expect unknown-card pull "frobnicate 1 2\n" 1 {} "unknown command"
94 xferclient_expect push-card-outside-clone pull \
95 "push $xferclientAbsent $xferclientAbsent\n" 1 {} "unknown command"
96 xferclient_expect empty-reply pull "" 1 {}
97
98 ###############################################################################
99 # Pragmas, cookies and other cards without content.
100
101 xferclient_expect server-version pull $SERVER_VERSION_CARD 0 {}
 
102 xferclient_expect server-version-short pull "pragma server-version 22900\n" 0 {}
103 xferclient_expect uv-pull-only pull "pragma uv-pull-only\n" 0 {}
104 xferclient_expect uv-push-ok pull "pragma uv-push-ok\n" 0 {}
105 xferclient_expect avoid-delta-manifests pull \
106 "pragma avoid-delta-manifests\n" 0 {}
107 xferclient_expect unknown-pragma pull "pragma no-such-pragma 1 2\n" 0 {}
108 xferclient_expect pragma-alone pull "pragma\n" 1 {} "unknown command"
109 xferclient_expect ci-lock-fail pull \
110 "pragma ci-lock-fail someone 1700000000\n" 0 {} \
111 "Parent check-in locked by someone"
112 xferclient_expect ci-lock-fail-negative-time pull \
113 "pragma ci-lock-fail someone -5\n" 0 {} "Parent check-in locked by someone"
114 xferclient_expect ci-lock-fail-bad-time pull \
115 "pragma ci-lock-fail someone notint\n" 0 {} \
116 "Parent check-in locked by someone"
117 xferclient_expect link pull \
118 "pragma link http://example.org/z {} 1790000000\n" 0 {--share-links}
119 xferclient_expect link-not-asked-for pull \
120 "pragma link http://example.org/y {} 1790000000\n" 0 {}
121 xferclient_expect cookie pull "cookie abc\n" 0 {}
@@ -165,90 +137,79 @@
137 # igot and gimme. What the client asks for, or sends, shows in its
138 # second request.
139
140 xferclient_run pull "igot $xferclientAbsent\n"
141 test xfer-client-igot-asks-for-it \
142 {$xferclientCode == 0
143 && [string first "gimme $xferclientAbsent" [xferclient_request 2]] >= 0}
144 # A hash that the client hears of only as private, or only in a push.
145 set xferclientPrivate [string repeat fedcba9876543210 4]
146 xferclient_run pull "igot $xferclientPrivate 1\n"
147 test xfer-client-igot-private-not-asked-for \
148 {$xferclientCode == 0
149 && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0}
150 xferclient_run pull "igot $xferclientFile\n"
151 test xfer-client-igot-held-not-asked-for \
152 {$xferclientCode == 0
153 && [string first "gimme $xferclientFile" [xferclient_request 2]] < 0}
154 xferclient_run push "igot $xferclientPrivate\n"
155 test xfer-client-igot-on-push-not-asked-for \
156 {$xferclientCode == 0
157 && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0}
158 xferclient_expect igot-not-a-hash pull "igot nothash\n" 1 {} "unknown command"
159 xferclient_expect igot-alone pull "igot\n" 1 {} "unknown command"
160
161 xferclient_run push "gimme $xferclientFile\n"
162 test xfer-client-gimme-sends-it \
163 {$xferclientCode == 0
164 && [string first "file $xferclientFile" [xferclient_request 2]] >= 0}
165 xferclient_run pull "gimme $xferclientFile\n"
166 test xfer-client-gimme-on-pull-sends-nothing \
167 {$xferclientCode == 0
168 && [string first "file $xferclientFile" [xferclient_request 2]] < 0}
169 xferclient_expect gimme-absent push "gimme $xferclientAbsent\n" 0 {}
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"
183 fossil sql "SELECT count(*) FROM private"
184 test xfer-client-igot-private-in-pull-marks-nothing \
185 {$xferclientCode == 0 && [string trim $RESULT] == 0}
186 xferclient_run pull "igot $xferclientCkin 1\n" --private
187 fossil sql "SELECT count(*) FROM private"
188 test xfer-client-igot-private-in-private-pull-marks-it \
189 {$xferclientCode == 0 && [string trim $RESULT] == 1}
190 xferclient_run pull "igot $xferclientCkin\n"
191 fossil sql "SELECT count(*) FROM private"
192 test xfer-client-igot-public-unmarks-it \
193 {$xferclientCode == 0 && [string trim $RESULT] == 0}
194
195 # An artifact that the client has asked for and does not hold yet is still
196 # marked: the server says it is private, and the client stops asking.
197 set xferclientPhantom [string repeat 00112233445566778899aabbccddeeff 2]
198 xferclient_sync pull \
199 [list "igot $xferclientPhantom\n" "igot $xferclientPhantom 1\n"]
 
 
 
 
 
 
 
 
 
 
200 fossil sql "SELECT count(*) FROM private p, blob b\
201 WHERE b.rid=p.rid AND b.uuid='$xferclientPhantom'"
202 test xfer-client-igot-private-marks-a-phantom \
203 {$xferclientCode == 0 && [string trim $RESULT] == 1}
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"
@@ -261,28 +222,30 @@
222 test xfer-client-file-in-push-stores-nothing \
223 {[string trim $RESULT] == $xferclientBlobs}
224 xferclient_run pull "file $xferclientHello 5\nhello\n"
225 fossil sql "SELECT count(*) FROM blob WHERE uuid='$xferclientHello'"
226 test xfer-client-file-in-pull-stored \
227 {$xferclientCode == 0 && [string trim $RESULT] == 1}
228
229 ###############################################################################
230 # Content that does not match its card is refused and nothing is stored.
231
232 xferclient_expect file-wrong-hash pull \
233 "file $xferclientAbsent 5\nhello\n" 1 {} "wrong hash on received artifact"
234 fossil sql \
235 "SELECT count(*) FROM blob WHERE uuid='$xferclientAbsent' AND size>=0"
236 test xfer-client-file-wrong-hash-not-stored {[string trim $RESULT] == 0}
237 xferclient_expect file-size-past-end pull \
238 "file $xferclientAbsent 99\nhello\n" 1 {}
239 xferclient_expect file-too-few-tokens pull "file $xferclientAbsent\n" 1 {}
240 xferclient_expect file-size-not-a-number pull \
241 "file $xferclientAbsent notint\nhello\n" 1 {}
242 xferclient_expect cfile-size-past-end pull \
243 "cfile $xferclientAbsent 5 99\nxx\n" 1 {}
244 xferclient_expect config-not-asked-for pull "config /project 0\n\n" 0 {}
245 xferclient_expect config-size-not-a-number pull \
246 "config /project notint\n" 1 {} "unknown command"
247
248 ###############################################################################
249 # Unversioned files. The cards for them are acted on only in a sync of
250 # unversioned content, or in a clone. In an ordinary pull a server used
251 # to be able to replace an unversioned file with a uvfile card that the
@@ -307,15 +270,16 @@
270 test xfer-client-uvfile-in-pull-changes-nothing \
271 {[string trim $RESULT] eq "local note"}
272 xferclient_expect uvigot-bad-mtime pull \
273 "uvigot note.txt notint $xferclientUvHash 3\n" 1 {} "unknown command"
274 xferclient_expect uvigot-bad-size pull \
275 "uvigot note.txt 1700000000 $xferclientUvHash notint\n" 1 {} \
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
+160 -166
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -1,10 +1,10 @@
11
#
2
-# Send each kind of card and pragma of the sync protocol to the server
3
-# side, through "fossil test-xfer", with and without the permission it
4
-# needs, and require the documented answer and no crash. This complements
5
-# xfer-cards.test, which covers the cards that carry content.
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.
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
#
@@ -14,68 +14,76 @@
1414
test_setup
1515
1616
write_file a.txt "hello world\n"
1717
fossil add a.txt
1818
fossil commit -m one --no-warnings
19
-fossil sql -R .rep.fossil \
20
- "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\
21
- JOIN filename f USING(fnid) WHERE f.name='a.txt'"
22
-set xferserverFile [string trim $::RESULT]
19
+fossil sha3sum a.txt
20
+set xferserverFile [lindex $RESULT 0]
2321
fossil sql -R .rep.fossil "SELECT value FROM config WHERE name='project-code'"
2422
set xferserverPcode [string trim $::RESULT]
2523
fossil sql -R .rep.fossil "SELECT max(rid) FROM blob"
2624
set xferserverMaxRid [string trim $::RESULT]
2725
2826
# The server is a copy of the repository of this checkout, so that it
2927
# holds a check-in. A hash that it does not hold:
3028
file copy .rep.fossil srv.fossil
3129
set xferserverAbsent [string repeat 0123456789abcdef 4]
30
+
3231
set xferserverLogin "login tester 0 0\n"
33
-set xferserverVersion "pragma client-version 22900 20261110 124827\n"
32
+set xferserverPull "pull x $xferserverPcode\n"
33
+set xferserverPush "push x $xferserverPcode\n"
3434
35
-# Set the capabilities of the user "nobody" on the server.
3635
proc xferserver_caps {caps} {
3736
fossil sql -R srv.fossil \
3837
"UPDATE user SET cap='$caps' WHERE login IN ('nobody','anonymous')"
3938
}
4039
41
-# Send one message. Sets xferserverOk to 1 when fossil did not crash and
42
-# xferserverReply to what it printed. The reply goes through a file and
43
-# is read back as bytes, because it can hold compressed content.
44
-proc xferserver_send {body} {
45
- global xferserverOk xferserverReply
46
- write_file msg.txt $body
47
- set xferserverOk [expr {[catch {exec $::fossilexe test-xfer -R srv.fossil \
48
- msg.txt > reply.out 2>@1}]==0}]
49
- set xferserverFd [open reply.out rb]
50
- set xferserverReply [read $xferserverFd]
51
- close $xferserverFd
52
-}
53
-
54
-# Send a message and require that it is answered without a crash and
55
-# that the reply does, or does not, hold each of the strings given. A
56
-# string that begins with "!" must be absent.
57
-proc xferserver_expect {name body args} {
58
- global xferserverOk xferserverReply
59
- xferserver_send $body
60
- set xferserverGood $xferserverOk
61
- foreach xferserverWant $args {
62
- if {[string index $xferserverWant 0] eq "!"} {
63
- if {[string first [string range $xferserverWant 1 end] \
64
- $xferserverReply]>=0} {set xferserverGood 0}
65
- } elseif {[string first $xferserverWant $xferserverReply]<0} {
66
- set xferserverGood 0
67
- }
68
- }
69
- if {!$xferserverGood} {
70
- puts " reply to $name: $xferserverReply"
71
- }
72
- test xfer-server-$name {$xferserverGood}
73
-}
74
-
75
-set xferserverPull "pull x $xferserverPcode\n"
76
-set xferserverPush "push x $xferserverPcode\n"
40
+proc xferserver_set {name value} {
41
+ fossil sql -R srv.fossil \
42
+ "REPLACE INTO config(name,value,mtime) VALUES('$name','$value',now())"
43
+}
44
+
45
+proc xferserver_unset {pattern} {
46
+ fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB '$pattern'"
47
+}
48
+
49
+# Returns the number of rows on the server that "SELECT count(*) FROM"
50
+# finds, with FROM as the remainder of the query.
51
+proc xferserver_count {from} {
52
+ fossil sql -R srv.fossil "SELECT count(*) FROM $from"
53
+ return [string trim $::RESULT]
54
+}
55
+
56
+# Returns 1 if the server holds the artifact HASH, or a phantom for it,
57
+# and has it marked private.
58
+proc xferserver_private {hash} {
59
+ return [xferserver_count \
60
+ "blob b, private p WHERE p.rid=b.rid AND b.uuid='$hash'"]
61
+}
62
+
63
+# Send the message BODY to the server. Sets RESULT to the reply, as
64
+# bytes because it can hold compressed content, and CODE to the exit
65
+# status of fossil.
66
+proc xferserver_send {body} {
67
+ write_file msg.txt $body
68
+ fossil_raw test-xfer -R srv.fossil msg.txt
69
+}
70
+
71
+# Send the message BODY. Test NAME passes when fossil exits with status
72
+# 0 and the reply holds each of the strings given. A string that begins
73
+# with "!" must be absent.
74
+proc xferserver_expect {name body args} {
75
+ xferserver_send $body
76
+ test xfer-server-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
77
+}
78
+
79
+# The message with which the client CLIENT asks for the lock on the
80
+# check-in CKIN.
81
+proc xferserver_lock {ckin client} {
82
+ global xferserverLogin xferserverPull
83
+ return "$xferserverLogin${xferserverPull}pragma ci-lock $ckin $client\n"
84
+}
7785
7886
###############################################################################
7987
# With no permissions at all, everything is refused.
8088
8189
xferserver_caps ""
@@ -91,37 +99,40 @@
9199
{error not\sauthorized\sto\swrite}
92100
xferserver_expect none-uvgimme "uvgimme note.txt\n" "!uvfile" "errors 0"
93101
xferserver_expect none-reqconfig "reqconfig /project\n" "!config " "errors 0"
94102
xferserver_expect none-uv-hash "pragma uv-hash $xferserverAbsent\n" \
95103
"!uv-pull-only" "!uv-push-ok"
96
-xferserver_expect none-private "private\n" {error not\sauthorized\sto\ssync\sprivate}
104
+xferserver_expect none-private "private\n" \
105
+ {error not\sauthorized\sto\ssync\sprivate}
97106
xferserver_expect none-send-private "pragma send-private\n" \
98107
{error not\sauthorized\sto\ssync\sprivate}
99108
xferserver_expect none-config "config /project 0\n\n" \
100109
{error not\sauthorized\sto\spush\sconfiguration}
101110
102111
###############################################################################
103112
# Read only: a pull is served, a push after it is turned into a message.
104113
105114
xferserver_caps "o"
106
-xferserver_expect read-pull $xferserverVersion$xferserverPull \
115
+xferserver_expect read-pull $CLIENT_VERSION_CARD$xferserverPull \
107116
"igot " "pragma server-version" "errors 0"
108117
xferserver_expect read-pull-then-push $xferserverPull$xferserverPush \
109118
{message pull\sonly\s-\snot\sauthorized\sto\spush}
110119
xferserver_expect read-gimme \
111
- "$xferserverVersion${xferserverPull}gimme $xferserverFile\n" \
120
+ "$CLIENT_VERSION_CARD${xferserverPull}gimme $xferserverFile\n" \
112121
"file $xferserverFile"
113122
# A client that gives no version is taken to be older than 2.0, which
114123
# cannot be sent a SHA3 hash.
115124
xferserver_expect read-gimme-old-client \
116125
"${xferserverPull}gimme $xferserverFile\n" \
117126
"!file $xferserverFile" {error Fossil\sversion\s2.0\sor\slater\srequired}
118
-xferserver_expect read-gimme-absent "${xferserverPull}gimme $xferserverAbsent\n" \
127
+xferserver_expect read-gimme-absent \
128
+ "${xferserverPull}gimme $xferserverAbsent\n" \
119129
"!file $xferserverAbsent" "errors 0"
120130
xferserver_expect read-gimme-no-pull "gimme $xferserverFile\n" \
121131
"!file $xferserverFile" "errors 0"
122
-xferserver_expect read-igot-no-push "${xferserverPull}igot $xferserverAbsent\n" \
132
+xferserver_expect read-igot-no-push \
133
+ "${xferserverPull}igot $xferserverAbsent\n" \
123134
"!gimme $xferserverAbsent" "errors 0"
124135
xferserver_expect read-uv-hash "pragma uv-hash $xferserverAbsent\n" \
125136
"pragma uv-pull-only"
126137
xferserver_expect read-reqconfig "reqconfig /project\n" "config /config "
127138
xferserver_expect read-reqconfig-old-style "reqconfig project-name\n" \
@@ -162,49 +173,47 @@
162173
###############################################################################
163174
# Write without Private: a client that says an artifact is private is not
164175
# asked for it, and may not send private content.
165176
166177
xferserver_caps "io"
167
-xferserver_expect write-igot-public "${xferserverPush}igot $xferserverAbsent\n" \
178
+xferserver_expect write-igot-public \
179
+ "${xferserverPush}igot $xferserverAbsent\n" \
168180
"gimme $xferserverAbsent"
169
-fossil sql -R srv.fossil "SELECT count(*) FROM blob b, private p\
170
- WHERE p.rid=b.rid AND b.uuid='$xferserverAbsent'"
171
-test xfer-server-write-igot-public-not-private {[string trim $RESULT]==0}
181
+test xfer-server-write-igot-public-not-private \
182
+ {[xferserver_private $xferserverAbsent] == 0}
172183
xferserver_expect write-igot-private-known \
173184
"${xferserverPush}igot $xferserverAbsent 1\n" \
174185
"!gimme $xferserverAbsent" "errors 0"
175
-fossil sql -R srv.fossil "SELECT count(*) FROM blob b, private p\
176
- WHERE p.rid=b.rid AND b.uuid='$xferserverAbsent'"
177
-test xfer-server-write-igot-private-marks-phantom {[string trim $RESULT]==1}
178
-set xferserverAbsent2 [string repeat fedcba9876543210 4]
186
+test xfer-server-write-igot-private-marks-phantom \
187
+ {[xferserver_private $xferserverAbsent] == 1}
188
+set xferserverUnknown [string repeat fedcba9876543210 4]
179189
xferserver_expect write-igot-private-unknown \
180
- "${xferserverPush}igot $xferserverAbsent2 1\n" \
181
- "!gimme $xferserverAbsent2" "errors 0"
182
-fossil sql -R srv.fossil \
183
- "SELECT count(*) FROM blob WHERE uuid='$xferserverAbsent2'"
184
-test xfer-server-write-igot-private-unknown-not-stored {[string trim $RESULT]==0}
190
+ "${xferserverPush}igot $xferserverUnknown 1\n" \
191
+ "!gimme $xferserverUnknown" "errors 0"
192
+test xfer-server-write-igot-private-unknown-not-stored \
193
+ {[xferserver_count "blob WHERE uuid='$xferserverUnknown'"] == 0}
185194
xferserver_expect write-private "${xferserverPush}private\n" \
186195
{error not\sauthorized\sto\ssync\sprivate}
187196
xferserver_expect write-client-url \
188197
"${xferserverPush}pragma client-url http://example.org/x\n" "errors 0"
189
-fossil sql -R srv.fossil \
190
- "SELECT count(*) FROM config WHERE name GLOB 'syncfrom:*example.org*'"
191
-test xfer-server-write-client-url-recorded {[string trim $RESULT]==1}
198
+test xfer-server-write-client-url-recorded \
199
+ {[xferserver_count \
200
+ "config WHERE name GLOB 'syncfrom:*example.org*'"] == 1}
192201
193202
###############################################################################
194203
# With a login card: private content, configuration, clone and locks.
195204
196205
xferserver_caps ""
197
-set xferserverAbsent3 [string repeat 00112233445566778899aabbccddeeff 2]
198
-# A private artifact that the server lacks becomes a private phantom. It
199
-# is asked for only when the client offers to send private content.
206
+# A private artifact that the server does not have becomes a private
207
+# phantom. It is asked for only when the client offers to send private
208
+# content.
209
+set xferserverPhantom [string repeat 00112233445566778899aabbccddeeff 2]
200210
xferserver_expect login-igot-private \
201
- "$xferserverLogin${xferserverPush}igot $xferserverAbsent3 1\n" \
202
- "!gimme $xferserverAbsent3" "errors 0"
203
-fossil sql -R srv.fossil "SELECT count(*) FROM blob b, private p\
204
- WHERE p.rid=b.rid AND b.uuid='$xferserverAbsent3'"
205
-test xfer-server-login-igot-private-phantom {[string trim $RESULT]==1}
211
+ "$xferserverLogin${xferserverPush}igot $xferserverPhantom 1\n" \
212
+ "!gimme $xferserverPhantom" "errors 0"
213
+test xfer-server-login-igot-private-phantom \
214
+ {[xferserver_private $xferserverPhantom] == 1}
206215
xferserver_expect login-private "$xferserverLogin${xferserverPush}private\n" \
207216
"errors 0"
208217
xferserver_expect login-send-private \
209218
"$xferserverLogin${xferserverPull}pragma send-private\n" "errors 0"
210219
xferserver_expect login-send-catalog \
@@ -212,67 +221,61 @@
212221
"igot $xferserverFile"
213222
xferserver_expect login-req-clusters \
214223
"$xferserverLogin${xferserverPull}pragma req-clusters\n" "errors 0"
215224
xferserver_expect login-req-links \
216225
"$xferserverLogin${xferserverPull}pragma req-links\n" "errors 0"
226
+# The hash is that of the empty string under SHA1.
217227
xferserver_expect login-uv-hash-same \
218
- "${xferserverLogin}pragma uv-hash da39a3ee5e6b4b0d3255bfef95601890afd80709\n" \
228
+ "${xferserverLogin}pragma uv-hash\
229
+ da39a3ee5e6b4b0d3255bfef95601890afd80709\n" \
219230
"!uv-pull-only" "!uv-push-ok"
220231
221
-# The configuration that the server gives out is accepted back.
222232
xferserver_send "${xferserverLogin}reqconfig /project\n"
223233
test xfer-server-login-reqconfig \
224
- {$xferserverOk && [string first "config /config " $xferserverReply]>=0}
234
+ {$CODE == 0 && [string first "config /config " $RESULT] >= 0}
225235
set xferserverCards ""
226
-foreach xferserverLine [split $xferserverReply \n] {
236
+foreach xferserverLine [split $RESULT \n] {
227237
if {[string match "#*" $xferserverLine]} continue
228238
append xferserverCards $xferserverLine\n
229239
}
230240
xferserver_expect login-config-roundtrip \
231241
"$xferserverLogin$xferserverPush$xferserverCards" "errors 0"
232242
xferserver_expect login-config-negative-size \
233243
"${xferserverLogin}config /project -5\n" {error bad\scommand:}
234244
235245
# Clone, in each version of the protocol. A login card to test-xfer does
236
-# not grant the Clone permission, so "nobody" is given it.
246
+# not grant the Clone permission, so "nobody" is given it and these
247
+# messages have no login card.
237248
xferserver_caps "g"
238
-set xferserverLogin $xferserverVersion
239249
xferserver_expect clone-v2-old-client "clone 2 1\n" \
240250
"!file " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0"
241251
xferserver_expect clone-v3-old-client "clone 3 1\n" \
242252
"!cfile " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0"
243
-xferserver_expect clone-v1 "${xferserverLogin}clone\n" \
253
+xferserver_expect clone-v1 "${CLIENT_VERSION_CARD}clone\n" \
244254
"push " "igot $xferserverFile" "errors 0"
245
-xferserver_expect clone-v1-odd-arguments "${xferserverLogin}clone x y\n" \
255
+xferserver_expect clone-v1-odd-arguments "${CLIENT_VERSION_CARD}clone x y\n" \
246256
"push " "errors 0"
247
-xferserver_expect clone-v2 "${xferserverLogin}clone 2 1\n" \
257
+xferserver_expect clone-v2 "${CLIENT_VERSION_CARD}clone 2 1\n" \
248258
"file " "clone_seqno 0"
249
-# "fossil test-xfer" prints the reply as a string, so a reply that holds
250
-# compressed content is cut at its first zero byte. Only the start of
251
-# such a reply can be checked.
252
-xferserver_expect clone-v3 "${xferserverLogin}clone 3 1\n" "cfile "
259
+xferserver_expect clone-v3 "${CLIENT_VERSION_CARD}clone 3 1\n" \
260
+ "cfile " "clone_seqno 0" "errors 0"
253261
xferserver_expect clone-v3-past-end \
254
- "${xferserverLogin}clone 3 [expr {$xferserverMaxRid+50}]\n" \
262
+ "${CLIENT_VERSION_CARD}clone 3 [expr {$xferserverMaxRid+50}]\n" \
255263
"!cfile " "clone_seqno 0"
256
-xferserver_expect clone-v3-zero "${xferserverLogin}clone 3 0\n" \
264
+xferserver_expect clone-v3-zero "${CLIENT_VERSION_CARD}clone 3 0\n" \
257265
{error invalid\sclone\ssequence\snumber}
258
-fossil sql -R srv.fossil \
259
- "REPLACE INTO config(name,value,mtime) VALUES('max-download',1,now())"
260
-xferserver_expect clone-v3-small-reply "${xferserverLogin}clone 3 1\n" \
266
+xferserver_set max-download 1
267
+xferserver_expect clone-v3-small-reply "${CLIENT_VERSION_CARD}clone 3 1\n" \
261268
"!cfile " "clone_seqno 1"
262
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download'"
263
-fossil sql -R srv.fossil \
264
- "REPLACE INTO config(name,value,mtime) VALUES('max-download-time',0,now())"
265
-xferserver_expect clone-v3-no-time "${xferserverLogin}clone 3 1\n" "cfile "
266
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download-time'"
267
-fossil sql -R srv.fossil \
268
- "REPLACE INTO config(name,value,mtime) VALUES('uv-sync',1,now())"
269
-xferserver_expect clone-uv-sync "${xferserverLogin}clone 3 1\n" \
269
+xferserver_unset max-download
270
+xferserver_set max-download-time 0
271
+xferserver_expect clone-v3-no-time "${CLIENT_VERSION_CARD}clone 3 1\n" "cfile "
272
+xferserver_unset max-download-time
273
+xferserver_set uv-sync 1
274
+xferserver_expect clone-uv-sync "${CLIENT_VERSION_CARD}clone 3 1\n" \
270275
"pragma uv-pull-only"
271
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='uv-sync'"
272
-
273
-set xferserverLogin "login tester 0 0\n"
276
+xferserver_unset uv-sync
274277
xferserver_caps ""
275278
276279
# Check-in locks. The second client to ask for the lock on the same
277280
# check-in is told who holds it; the holder asking again is not.
278281
fossil sql -R srv.fossil "SELECT uuid FROM blob WHERE rid=(SELECT max(objid)\
@@ -279,53 +282,52 @@
279282
FROM event WHERE type='ci')"
280283
set xferserverCkin [string trim $::RESULT]
281284
set xferserverClientA [string repeat a 40]
282285
set xferserverClientB [string repeat b 40]
283286
xferserver_expect ci-lock-first \
284
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
287
+ [xferserver_lock $xferserverCkin $xferserverClientA] \
285288
"!ci-lock-fail" "pragma avoid-delta-manifests"
286289
xferserver_expect ci-lock-holder-again \
287
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
288
- "!ci-lock-fail"
290
+ [xferserver_lock $xferserverCkin $xferserverClientA] "!ci-lock-fail"
289291
xferserver_expect ci-lock-second-client \
290
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientB\n" \
291
- "pragma ci-lock-fail "
292
+ [xferserver_lock $xferserverCkin $xferserverClientB] "pragma ci-lock-fail "
292293
xferserver_expect ci-unlock \
293
- "$xferserverLogin${xferserverPull}pragma ci-unlock $xferserverClientA\n" "errors 0"
294
-fossil sql -R srv.fossil "SELECT count(*) FROM config WHERE name GLOB 'ci-lock-*'"
295
-test xfer-server-ci-unlock-removed {[string trim $RESULT]==0}
294
+ "$xferserverLogin${xferserverPull}pragma ci-unlock $xferserverClientA\n" \
295
+ "errors 0"
296
+test xfer-server-ci-unlock-removed \
297
+ {[xferserver_count "config WHERE name GLOB 'ci-lock-*'"] == 0}
296298
xferserver_expect ci-lock-after-unlock \
297
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientB\n" \
298
- "!ci-lock-fail"
299
-# A lock older than the lock-timeout setting is dropped.
300
-fossil sql -R srv.fossil "UPDATE config SET mtime=mtime-100000 WHERE name GLOB 'ci-lock-*'"
299
+ [xferserver_lock $xferserverCkin $xferserverClientB] "!ci-lock-fail"
300
+fossil sql -R srv.fossil \
301
+ "UPDATE config SET mtime=mtime-100000 WHERE name GLOB 'ci-lock-*'"
301302
xferserver_expect ci-lock-expired \
302
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
303
- "!ci-lock-fail"
304
-fossil sql -R srv.fossil \
305
- "REPLACE INTO config(name,value,mtime) VALUES('forbid-delta-manifests',0,now())"
303
+ [xferserver_lock $xferserverCkin $xferserverClientA] "!ci-lock-fail"
304
+xferserver_set forbid-delta-manifests 0
306305
xferserver_expect ci-lock-delta-manifests-allowed \
307
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
306
+ [xferserver_lock $xferserverCkin $xferserverClientA] \
308307
"!avoid-delta-manifests" "errors 0"
309308
310309
###############################################################################
311310
# More cards and pragmas under particular permissions and settings.
312311
313
-fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
314
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='forbid-delta-manifests'"
315
-set xferserverAbsent4 [string repeat 0f1e2d3c4b5a6978 4]
312
+xferserver_unset ci-lock-*
313
+xferserver_unset forbid-delta-manifests
314
+# An igot card with a flag of 0 offers a public artifact.
315
+set xferserverPublic [string repeat 0f1e2d3c4b5a6978 4]
316316
xferserver_expect login-igot-flag-zero \
317
- "$xferserverLogin${xferserverPush}igot $xferserverAbsent4 0\n" \
318
- "gimme $xferserverAbsent4"
317
+ "$xferserverLogin${xferserverPush}igot $xferserverPublic 0\n" \
318
+ "gimme $xferserverPublic"
319319
xferserver_expect bad-config-too-few "${xferserverLogin}config /project\n" \
320320
{error bad\scommand:}
321
-xferserver_expect uv-hash-not-a-hash "${xferserverLogin}pragma uv-hash nothash\n" \
321
+xferserver_expect uv-hash-not-a-hash \
322
+ "${xferserverLogin}pragma uv-hash nothash\n" \
322323
"!uv-pull-only" "!uv-push-ok" "errors 0"
323324
xferserver_expect ci-lock-not-a-hash \
324
- "$xferserverLogin${xferserverPull}pragma ci-lock nothash $xferserverClientA\n" \
325
+ [xferserver_lock nothash $xferserverClientA] \
325326
"!avoid-delta-manifests" "errors 0"
326
-xferserver_expect ci-unlock-too-few "${xferserverLogin}pragma ci-unlock\n" "errors 0"
327
+xferserver_expect ci-unlock-too-few "${xferserverLogin}pragma ci-unlock\n" \
328
+ "errors 0"
327329
xferserver_expect client-url-too-few "${xferserverLogin}pragma client-url\n" \
328330
"errors 0"
329331
330332
# The unversioned catalog is sent once in a reply, and a client that may
331333
# write unversioned files is told so.
@@ -334,96 +336,88 @@
334336
"pragma uv-push-ok"
335337
xferserver_expect uv-hash-twice \
336338
"pragma uv-hash $xferserverAbsent\npragma uv-hash $xferserverAbsent\n" \
337339
"pragma uv-push-ok" "errors 0"
338340
test xfer-server-uv-hash-twice-one-answer \
339
- {[regexp -all {pragma uv-push-ok} $xferserverReply]==1}
341
+ {[regexp -all {pragma uv-push-ok} $RESULT] == 1}
340342
341
-# Without the Write permission a client URL is not recorded.
342343
xferserver_caps "o"
343344
xferserver_expect read-client-url \
344345
"${xferserverPull}pragma client-url http://example.net/z\n" "errors 0"
345
-fossil sql -R srv.fossil \
346
- "SELECT count(*) FROM config WHERE name GLOB 'sync*example.net*'"
347
-test xfer-server-read-client-url-not-recorded {[string trim $RESULT]==0}
346
+test xfer-server-read-client-url-not-recorded \
347
+ {[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0}
348348
349349
# Links to other repositories of the project are given on request, except
350350
# those on the local host.
351
-fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
352
- VALUES('syncwith:http://localhost:8080/y','{}',now())"
351
+xferserver_set syncwith:http://localhost:8080/y "{}"
353352
xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \
354353
"pragma link http://example.org/x" "!localhost:8080/y"
355354
356355
# The address configuration is given only to a client that may read
357356
# addresses.
358357
xferserver_caps "oe"
359358
xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0"
360359
361
-# Clone combined with other cards.
362360
xferserver_caps "gx"
363
-xferserver_expect clone-version-one "${xferserverVersion}clone 1 1\n" \
361
+xferserver_expect clone-version-one "${CLIENT_VERSION_CARD}clone 1 1\n" \
364362
"push " "igot $xferserverFile" "errors 0"
365363
xferserver_expect clone-then-gimme \
366
- "${xferserverVersion}clone\ngimme $xferserverFile\n" \
364
+ "${CLIENT_VERSION_CARD}clone\ngimme $xferserverFile\n" \
367365
"file $xferserverFile" "errors 0"
368366
xferserver_expect clone-send-private \
369
- "${xferserverVersion}pragma send-private\nclone\n" "push " "errors 0"
370
-fossil sql -R srv.fossil \
371
- "REPLACE INTO config(name,value,mtime) VALUES('uv-sync',1,now())"
367
+ "${CLIENT_VERSION_CARD}pragma send-private\nclone\n" "push " "errors 0"
368
+xferserver_set uv-sync 1
372369
xferserver_expect clone-uv-sync-after-uv-hash \
373
- "${xferserverVersion}pragma uv-hash $xferserverAbsent\nclone 3 1\n" \
370
+ "${CLIENT_VERSION_CARD}pragma uv-hash $xferserverAbsent\nclone 3 1\n" \
374371
"pragma uv-pull-only"
375372
test xfer-server-clone-uv-sync-one-catalog \
376
- {[regexp -all {pragma uv-pull-only} $xferserverReply]==1}
377
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='uv-sync'"
373
+ {[regexp -all {pragma uv-pull-only} $RESULT] == 1}
374
+xferserver_unset uv-sync
378375
xferserver_caps ""
379376
380
-# More check-in locks: a lock on another check-in does not get in the
381
-# way, a lock on a check-in that is no longer a leaf is dropped, and a
382
-# lock with no user name is reported as held by "nobody".
377
+# More check-in locks: a lock on another check-in does not block this
378
+# one, a lock on a check-in that has a child is dropped, and a lock with
379
+# no user name is reported as held by "nobody".
383380
fossil sql -R srv.fossil "SELECT b.uuid FROM blob b, plink p\
384381
WHERE b.rid=p.pid AND p.cid=(SELECT max(objid) FROM event WHERE type='ci')"
385382
set xferserverParent [string trim $::RESULT]
386
-test xfer-server-setup-parent {[string length $xferserverParent]>=40}
383
+test xfer-server-setup-parent {[string length $xferserverParent] >= 40}
387384
xferserver_expect ci-lock-on-parent \
388
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverParent $xferserverClientA\n" \
385
+ [xferserver_lock $xferserverParent $xferserverClientA] \
389386
"!ci-lock-fail" "errors 0"
390387
xferserver_expect ci-lock-parent-not-a-leaf \
391
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverParent $xferserverClientB\n" \
388
+ [xferserver_lock $xferserverParent $xferserverClientB] \
392389
"!ci-lock-fail" "errors 0"
393390
xferserver_expect ci-lock-tip \
394
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
391
+ [xferserver_lock $xferserverCkin $xferserverClientA] \
395392
"!ci-lock-fail" "errors 0"
396
-fossil sql -R srv.fossil "SELECT count(*) FROM config WHERE name GLOB 'ci-lock-*'"
397
-test xfer-server-ci-lock-parent-dropped {[string trim $RESULT]==1}
393
+test xfer-server-ci-lock-parent-dropped \
394
+ {[xferserver_count "config WHERE name GLOB 'ci-lock-*'"] == 1}
398395
fossil sql -R srv.fossil "UPDATE config SET value=json_object('clientid',\
399396
'$xferserverClientA') WHERE name GLOB 'ci-lock-*'"
400397
xferserver_expect ci-lock-held-by-nobody \
401
- "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientB\n" \
398
+ [xferserver_lock $xferserverCkin $xferserverClientB] \
402399
"pragma ci-lock-fail nobody "
403
-fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
400
+xferserver_unset ci-lock-*
404401
405402
# The TH1 transfer scripts run on the server. One that fails is reported.
406
-fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
407
- VALUES('xfer-push-script','set xferserverSeen 1',now())"
403
+xferserver_set xfer-push-script "set xferserverSeen 1"
408404
xferserver_expect push-script-ok "$xferserverLogin$xferserverPush" "errors 0"
409
-fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
410
- VALUES('xfer-push-script','error push-script-says-no',now())"
405
+xferserver_set xfer-push-script "error push-script-says-no"
411406
xferserver_expect push-script-fails "$xferserverLogin$xferserverPush" \
412407
{error push\sscript\sfailed:} "push-script-says-no"
413
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='xfer-push-script'"
414
-fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
415
- VALUES('xfer-common-script','error common-script-says-no',now())"
408
+xferserver_unset xfer-push-script
409
+xferserver_set xfer-common-script "error common-script-says-no"
416410
xferserver_expect common-script-fails \
417411
"$xferserverLogin$xferserverPull$xferserverPush" \
418412
{error common\sscript\sfailed:} "common-script-says-no"
419
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='xfer-common-script'"
413
+xferserver_unset xfer-common-script
420414
421415
# A repository with no project code cannot answer a pull or a push.
422
-fossil sql -R srv.fossil "DELETE FROM config WHERE name='project-code'"
416
+xferserver_unset project-code
423417
xferserver_send "$xferserverLogin$xferserverPull"
424418
test xfer-server-no-project-code \
425
- {!$xferserverOk && [string first "missing project code" $xferserverReply]>=0}
419
+ {$CODE == 1 && [string first "missing project code" $RESULT] >= 0}
426420
427421
###############################################################################
428422
429423
test_cleanup
430424
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -1,10 +1,10 @@
1 #
2 # Send each kind of card and pragma of the sync protocol to the server
3 # side, through "fossil test-xfer", with and without the permission it
4 # needs, and require the documented answer and no crash. This complements
5 # xfer-cards.test, which covers the cards that carry 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 #
@@ -14,68 +14,76 @@
14 test_setup
15
16 write_file a.txt "hello world\n"
17 fossil add a.txt
18 fossil commit -m one --no-warnings
19 fossil sql -R .rep.fossil \
20 "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\
21 JOIN filename f USING(fnid) WHERE f.name='a.txt'"
22 set xferserverFile [string trim $::RESULT]
23 fossil sql -R .rep.fossil "SELECT value FROM config WHERE name='project-code'"
24 set xferserverPcode [string trim $::RESULT]
25 fossil sql -R .rep.fossil "SELECT max(rid) FROM blob"
26 set xferserverMaxRid [string trim $::RESULT]
27
28 # The server is a copy of the repository of this checkout, so that it
29 # holds a check-in. A hash that it does not hold:
30 file copy .rep.fossil srv.fossil
31 set xferserverAbsent [string repeat 0123456789abcdef 4]
 
32 set xferserverLogin "login tester 0 0\n"
33 set xferserverVersion "pragma client-version 22900 20261110 124827\n"
 
34
35 # Set the capabilities of the user "nobody" on the server.
36 proc xferserver_caps {caps} {
37 fossil sql -R srv.fossil \
38 "UPDATE user SET cap='$caps' WHERE login IN ('nobody','anonymous')"
39 }
40
41 # Send one message. Sets xferserverOk to 1 when fossil did not crash and
42 # xferserverReply to what it printed. The reply goes through a file and
43 # is read back as bytes, because it can hold compressed content.
44 proc xferserver_send {body} {
45 global xferserverOk xferserverReply
46 write_file msg.txt $body
47 set xferserverOk [expr {[catch {exec $::fossilexe test-xfer -R srv.fossil \
48 msg.txt > reply.out 2>@1}]==0}]
49 set xferserverFd [open reply.out rb]
50 set xferserverReply [read $xferserverFd]
51 close $xferserverFd
52 }
53
54 # Send a message and require that it is answered without a crash and
55 # that the reply does, or does not, hold each of the strings given. A
56 # string that begins with "!" must be absent.
57 proc xferserver_expect {name body args} {
58 global xferserverOk xferserverReply
59 xferserver_send $body
60 set xferserverGood $xferserverOk
61 foreach xferserverWant $args {
62 if {[string index $xferserverWant 0] eq "!"} {
63 if {[string first [string range $xferserverWant 1 end] \
64 $xferserverReply]>=0} {set xferserverGood 0}
65 } elseif {[string first $xferserverWant $xferserverReply]<0} {
66 set xferserverGood 0
67 }
68 }
69 if {!$xferserverGood} {
70 puts " reply to $name: $xferserverReply"
71 }
72 test xfer-server-$name {$xferserverGood}
73 }
74
75 set xferserverPull "pull x $xferserverPcode\n"
76 set xferserverPush "push x $xferserverPcode\n"
 
 
 
 
 
 
 
 
 
77
78 ###############################################################################
79 # With no permissions at all, everything is refused.
80
81 xferserver_caps ""
@@ -91,37 +99,40 @@
91 {error not\sauthorized\sto\swrite}
92 xferserver_expect none-uvgimme "uvgimme note.txt\n" "!uvfile" "errors 0"
93 xferserver_expect none-reqconfig "reqconfig /project\n" "!config " "errors 0"
94 xferserver_expect none-uv-hash "pragma uv-hash $xferserverAbsent\n" \
95 "!uv-pull-only" "!uv-push-ok"
96 xferserver_expect none-private "private\n" {error not\sauthorized\sto\ssync\sprivate}
 
97 xferserver_expect none-send-private "pragma send-private\n" \
98 {error not\sauthorized\sto\ssync\sprivate}
99 xferserver_expect none-config "config /project 0\n\n" \
100 {error not\sauthorized\sto\spush\sconfiguration}
101
102 ###############################################################################
103 # Read only: a pull is served, a push after it is turned into a message.
104
105 xferserver_caps "o"
106 xferserver_expect read-pull $xferserverVersion$xferserverPull \
107 "igot " "pragma server-version" "errors 0"
108 xferserver_expect read-pull-then-push $xferserverPull$xferserverPush \
109 {message pull\sonly\s-\snot\sauthorized\sto\spush}
110 xferserver_expect read-gimme \
111 "$xferserverVersion${xferserverPull}gimme $xferserverFile\n" \
112 "file $xferserverFile"
113 # A client that gives no version is taken to be older than 2.0, which
114 # cannot be sent a SHA3 hash.
115 xferserver_expect read-gimme-old-client \
116 "${xferserverPull}gimme $xferserverFile\n" \
117 "!file $xferserverFile" {error Fossil\sversion\s2.0\sor\slater\srequired}
118 xferserver_expect read-gimme-absent "${xferserverPull}gimme $xferserverAbsent\n" \
 
119 "!file $xferserverAbsent" "errors 0"
120 xferserver_expect read-gimme-no-pull "gimme $xferserverFile\n" \
121 "!file $xferserverFile" "errors 0"
122 xferserver_expect read-igot-no-push "${xferserverPull}igot $xferserverAbsent\n" \
 
123 "!gimme $xferserverAbsent" "errors 0"
124 xferserver_expect read-uv-hash "pragma uv-hash $xferserverAbsent\n" \
125 "pragma uv-pull-only"
126 xferserver_expect read-reqconfig "reqconfig /project\n" "config /config "
127 xferserver_expect read-reqconfig-old-style "reqconfig project-name\n" \
@@ -162,49 +173,47 @@
162 ###############################################################################
163 # Write without Private: a client that says an artifact is private is not
164 # asked for it, and may not send private content.
165
166 xferserver_caps "io"
167 xferserver_expect write-igot-public "${xferserverPush}igot $xferserverAbsent\n" \
 
168 "gimme $xferserverAbsent"
169 fossil sql -R srv.fossil "SELECT count(*) FROM blob b, private p\
170 WHERE p.rid=b.rid AND b.uuid='$xferserverAbsent'"
171 test xfer-server-write-igot-public-not-private {[string trim $RESULT]==0}
172 xferserver_expect write-igot-private-known \
173 "${xferserverPush}igot $xferserverAbsent 1\n" \
174 "!gimme $xferserverAbsent" "errors 0"
175 fossil sql -R srv.fossil "SELECT count(*) FROM blob b, private p\
176 WHERE p.rid=b.rid AND b.uuid='$xferserverAbsent'"
177 test xfer-server-write-igot-private-marks-phantom {[string trim $RESULT]==1}
178 set xferserverAbsent2 [string repeat fedcba9876543210 4]
179 xferserver_expect write-igot-private-unknown \
180 "${xferserverPush}igot $xferserverAbsent2 1\n" \
181 "!gimme $xferserverAbsent2" "errors 0"
182 fossil sql -R srv.fossil \
183 "SELECT count(*) FROM blob WHERE uuid='$xferserverAbsent2'"
184 test xfer-server-write-igot-private-unknown-not-stored {[string trim $RESULT]==0}
185 xferserver_expect write-private "${xferserverPush}private\n" \
186 {error not\sauthorized\sto\ssync\sprivate}
187 xferserver_expect write-client-url \
188 "${xferserverPush}pragma client-url http://example.org/x\n" "errors 0"
189 fossil sql -R srv.fossil \
190 "SELECT count(*) FROM config WHERE name GLOB 'syncfrom:*example.org*'"
191 test xfer-server-write-client-url-recorded {[string trim $RESULT]==1}
192
193 ###############################################################################
194 # With a login card: private content, configuration, clone and locks.
195
196 xferserver_caps ""
197 set xferserverAbsent3 [string repeat 00112233445566778899aabbccddeeff 2]
198 # A private artifact that the server lacks becomes a private phantom. It
199 # is asked for only when the client offers to send private content.
 
200 xferserver_expect login-igot-private \
201 "$xferserverLogin${xferserverPush}igot $xferserverAbsent3 1\n" \
202 "!gimme $xferserverAbsent3" "errors 0"
203 fossil sql -R srv.fossil "SELECT count(*) FROM blob b, private p\
204 WHERE p.rid=b.rid AND b.uuid='$xferserverAbsent3'"
205 test xfer-server-login-igot-private-phantom {[string trim $RESULT]==1}
206 xferserver_expect login-private "$xferserverLogin${xferserverPush}private\n" \
207 "errors 0"
208 xferserver_expect login-send-private \
209 "$xferserverLogin${xferserverPull}pragma send-private\n" "errors 0"
210 xferserver_expect login-send-catalog \
@@ -212,67 +221,61 @@
212 "igot $xferserverFile"
213 xferserver_expect login-req-clusters \
214 "$xferserverLogin${xferserverPull}pragma req-clusters\n" "errors 0"
215 xferserver_expect login-req-links \
216 "$xferserverLogin${xferserverPull}pragma req-links\n" "errors 0"
 
217 xferserver_expect login-uv-hash-same \
218 "${xferserverLogin}pragma uv-hash da39a3ee5e6b4b0d3255bfef95601890afd80709\n" \
 
219 "!uv-pull-only" "!uv-push-ok"
220
221 # The configuration that the server gives out is accepted back.
222 xferserver_send "${xferserverLogin}reqconfig /project\n"
223 test xfer-server-login-reqconfig \
224 {$xferserverOk && [string first "config /config " $xferserverReply]>=0}
225 set xferserverCards ""
226 foreach xferserverLine [split $xferserverReply \n] {
227 if {[string match "#*" $xferserverLine]} continue
228 append xferserverCards $xferserverLine\n
229 }
230 xferserver_expect login-config-roundtrip \
231 "$xferserverLogin$xferserverPush$xferserverCards" "errors 0"
232 xferserver_expect login-config-negative-size \
233 "${xferserverLogin}config /project -5\n" {error bad\scommand:}
234
235 # Clone, in each version of the protocol. A login card to test-xfer does
236 # not grant the Clone permission, so "nobody" is given it.
 
237 xferserver_caps "g"
238 set xferserverLogin $xferserverVersion
239 xferserver_expect clone-v2-old-client "clone 2 1\n" \
240 "!file " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0"
241 xferserver_expect clone-v3-old-client "clone 3 1\n" \
242 "!cfile " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0"
243 xferserver_expect clone-v1 "${xferserverLogin}clone\n" \
244 "push " "igot $xferserverFile" "errors 0"
245 xferserver_expect clone-v1-odd-arguments "${xferserverLogin}clone x y\n" \
246 "push " "errors 0"
247 xferserver_expect clone-v2 "${xferserverLogin}clone 2 1\n" \
248 "file " "clone_seqno 0"
249 # "fossil test-xfer" prints the reply as a string, so a reply that holds
250 # compressed content is cut at its first zero byte. Only the start of
251 # such a reply can be checked.
252 xferserver_expect clone-v3 "${xferserverLogin}clone 3 1\n" "cfile "
253 xferserver_expect clone-v3-past-end \
254 "${xferserverLogin}clone 3 [expr {$xferserverMaxRid+50}]\n" \
255 "!cfile " "clone_seqno 0"
256 xferserver_expect clone-v3-zero "${xferserverLogin}clone 3 0\n" \
257 {error invalid\sclone\ssequence\snumber}
258 fossil sql -R srv.fossil \
259 "REPLACE INTO config(name,value,mtime) VALUES('max-download',1,now())"
260 xferserver_expect clone-v3-small-reply "${xferserverLogin}clone 3 1\n" \
261 "!cfile " "clone_seqno 1"
262 fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download'"
263 fossil sql -R srv.fossil \
264 "REPLACE INTO config(name,value,mtime) VALUES('max-download-time',0,now())"
265 xferserver_expect clone-v3-no-time "${xferserverLogin}clone 3 1\n" "cfile "
266 fossil sql -R srv.fossil "DELETE FROM config WHERE name='max-download-time'"
267 fossil sql -R srv.fossil \
268 "REPLACE INTO config(name,value,mtime) VALUES('uv-sync',1,now())"
269 xferserver_expect clone-uv-sync "${xferserverLogin}clone 3 1\n" \
270 "pragma uv-pull-only"
271 fossil sql -R srv.fossil "DELETE FROM config WHERE name='uv-sync'"
272
273 set xferserverLogin "login tester 0 0\n"
274 xferserver_caps ""
275
276 # Check-in locks. The second client to ask for the lock on the same
277 # check-in is told who holds it; the holder asking again is not.
278 fossil sql -R srv.fossil "SELECT uuid FROM blob WHERE rid=(SELECT max(objid)\
@@ -279,53 +282,52 @@
279 FROM event WHERE type='ci')"
280 set xferserverCkin [string trim $::RESULT]
281 set xferserverClientA [string repeat a 40]
282 set xferserverClientB [string repeat b 40]
283 xferserver_expect ci-lock-first \
284 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
285 "!ci-lock-fail" "pragma avoid-delta-manifests"
286 xferserver_expect ci-lock-holder-again \
287 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
288 "!ci-lock-fail"
289 xferserver_expect ci-lock-second-client \
290 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientB\n" \
291 "pragma ci-lock-fail "
292 xferserver_expect ci-unlock \
293 "$xferserverLogin${xferserverPull}pragma ci-unlock $xferserverClientA\n" "errors 0"
294 fossil sql -R srv.fossil "SELECT count(*) FROM config WHERE name GLOB 'ci-lock-*'"
295 test xfer-server-ci-unlock-removed {[string trim $RESULT]==0}
 
296 xferserver_expect ci-lock-after-unlock \
297 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientB\n" \
298 "!ci-lock-fail"
299 # A lock older than the lock-timeout setting is dropped.
300 fossil sql -R srv.fossil "UPDATE config SET mtime=mtime-100000 WHERE name GLOB 'ci-lock-*'"
301 xferserver_expect ci-lock-expired \
302 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
303 "!ci-lock-fail"
304 fossil sql -R srv.fossil \
305 "REPLACE INTO config(name,value,mtime) VALUES('forbid-delta-manifests',0,now())"
306 xferserver_expect ci-lock-delta-manifests-allowed \
307 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
308 "!avoid-delta-manifests" "errors 0"
309
310 ###############################################################################
311 # More cards and pragmas under particular permissions and settings.
312
313 fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
314 fossil sql -R srv.fossil "DELETE FROM config WHERE name='forbid-delta-manifests'"
315 set xferserverAbsent4 [string repeat 0f1e2d3c4b5a6978 4]
 
316 xferserver_expect login-igot-flag-zero \
317 "$xferserverLogin${xferserverPush}igot $xferserverAbsent4 0\n" \
318 "gimme $xferserverAbsent4"
319 xferserver_expect bad-config-too-few "${xferserverLogin}config /project\n" \
320 {error bad\scommand:}
321 xferserver_expect uv-hash-not-a-hash "${xferserverLogin}pragma uv-hash nothash\n" \
 
322 "!uv-pull-only" "!uv-push-ok" "errors 0"
323 xferserver_expect ci-lock-not-a-hash \
324 "$xferserverLogin${xferserverPull}pragma ci-lock nothash $xferserverClientA\n" \
325 "!avoid-delta-manifests" "errors 0"
326 xferserver_expect ci-unlock-too-few "${xferserverLogin}pragma ci-unlock\n" "errors 0"
 
327 xferserver_expect client-url-too-few "${xferserverLogin}pragma client-url\n" \
328 "errors 0"
329
330 # The unversioned catalog is sent once in a reply, and a client that may
331 # write unversioned files is told so.
@@ -334,96 +336,88 @@
334 "pragma uv-push-ok"
335 xferserver_expect uv-hash-twice \
336 "pragma uv-hash $xferserverAbsent\npragma uv-hash $xferserverAbsent\n" \
337 "pragma uv-push-ok" "errors 0"
338 test xfer-server-uv-hash-twice-one-answer \
339 {[regexp -all {pragma uv-push-ok} $xferserverReply]==1}
340
341 # Without the Write permission a client URL is not recorded.
342 xferserver_caps "o"
343 xferserver_expect read-client-url \
344 "${xferserverPull}pragma client-url http://example.net/z\n" "errors 0"
345 fossil sql -R srv.fossil \
346 "SELECT count(*) FROM config WHERE name GLOB 'sync*example.net*'"
347 test xfer-server-read-client-url-not-recorded {[string trim $RESULT]==0}
348
349 # Links to other repositories of the project are given on request, except
350 # those on the local host.
351 fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
352 VALUES('syncwith:http://localhost:8080/y','{}',now())"
353 xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \
354 "pragma link http://example.org/x" "!localhost:8080/y"
355
356 # The address configuration is given only to a client that may read
357 # addresses.
358 xferserver_caps "oe"
359 xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0"
360
361 # Clone combined with other cards.
362 xferserver_caps "gx"
363 xferserver_expect clone-version-one "${xferserverVersion}clone 1 1\n" \
364 "push " "igot $xferserverFile" "errors 0"
365 xferserver_expect clone-then-gimme \
366 "${xferserverVersion}clone\ngimme $xferserverFile\n" \
367 "file $xferserverFile" "errors 0"
368 xferserver_expect clone-send-private \
369 "${xferserverVersion}pragma send-private\nclone\n" "push " "errors 0"
370 fossil sql -R srv.fossil \
371 "REPLACE INTO config(name,value,mtime) VALUES('uv-sync',1,now())"
372 xferserver_expect clone-uv-sync-after-uv-hash \
373 "${xferserverVersion}pragma uv-hash $xferserverAbsent\nclone 3 1\n" \
374 "pragma uv-pull-only"
375 test xfer-server-clone-uv-sync-one-catalog \
376 {[regexp -all {pragma uv-pull-only} $xferserverReply]==1}
377 fossil sql -R srv.fossil "DELETE FROM config WHERE name='uv-sync'"
378 xferserver_caps ""
379
380 # More check-in locks: a lock on another check-in does not get in the
381 # way, a lock on a check-in that is no longer a leaf is dropped, and a
382 # lock with no user name is reported as held by "nobody".
383 fossil sql -R srv.fossil "SELECT b.uuid FROM blob b, plink p\
384 WHERE b.rid=p.pid AND p.cid=(SELECT max(objid) FROM event WHERE type='ci')"
385 set xferserverParent [string trim $::RESULT]
386 test xfer-server-setup-parent {[string length $xferserverParent]>=40}
387 xferserver_expect ci-lock-on-parent \
388 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverParent $xferserverClientA\n" \
389 "!ci-lock-fail" "errors 0"
390 xferserver_expect ci-lock-parent-not-a-leaf \
391 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverParent $xferserverClientB\n" \
392 "!ci-lock-fail" "errors 0"
393 xferserver_expect ci-lock-tip \
394 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientA\n" \
395 "!ci-lock-fail" "errors 0"
396 fossil sql -R srv.fossil "SELECT count(*) FROM config WHERE name GLOB 'ci-lock-*'"
397 test xfer-server-ci-lock-parent-dropped {[string trim $RESULT]==1}
398 fossil sql -R srv.fossil "UPDATE config SET value=json_object('clientid',\
399 '$xferserverClientA') WHERE name GLOB 'ci-lock-*'"
400 xferserver_expect ci-lock-held-by-nobody \
401 "$xferserverLogin${xferserverPull}pragma ci-lock $xferserverCkin $xferserverClientB\n" \
402 "pragma ci-lock-fail nobody "
403 fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
404
405 # The TH1 transfer scripts run on the server. One that fails is reported.
406 fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
407 VALUES('xfer-push-script','set xferserverSeen 1',now())"
408 xferserver_expect push-script-ok "$xferserverLogin$xferserverPush" "errors 0"
409 fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
410 VALUES('xfer-push-script','error push-script-says-no',now())"
411 xferserver_expect push-script-fails "$xferserverLogin$xferserverPush" \
412 {error push\sscript\sfailed:} "push-script-says-no"
413 fossil sql -R srv.fossil "DELETE FROM config WHERE name='xfer-push-script'"
414 fossil sql -R srv.fossil "REPLACE INTO config(name,value,mtime)\
415 VALUES('xfer-common-script','error common-script-says-no',now())"
416 xferserver_expect common-script-fails \
417 "$xferserverLogin$xferserverPull$xferserverPush" \
418 {error common\sscript\sfailed:} "common-script-says-no"
419 fossil sql -R srv.fossil "DELETE FROM config WHERE name='xfer-common-script'"
420
421 # A repository with no project code cannot answer a pull or a push.
422 fossil sql -R srv.fossil "DELETE FROM config WHERE name='project-code'"
423 xferserver_send "$xferserverLogin$xferserverPull"
424 test xfer-server-no-project-code \
425 {!$xferserverOk && [string first "missing project code" $xferserverReply]>=0}
426
427 ###############################################################################
428
429 test_cleanup
430
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -1,10 +1,10 @@
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 #
@@ -14,68 +14,76 @@
14 test_setup
15
16 write_file a.txt "hello world\n"
17 fossil add a.txt
18 fossil commit -m one --no-warnings
19 fossil sha3sum a.txt
20 set xferserverFile [lindex $RESULT 0]
 
 
21 fossil sql -R .rep.fossil "SELECT value FROM config WHERE name='project-code'"
22 set xferserverPcode [string trim $::RESULT]
23 fossil sql -R .rep.fossil "SELECT max(rid) FROM blob"
24 set xferserverMaxRid [string trim $::RESULT]
25
26 # The server is a copy of the repository of this checkout, so that it
27 # holds a check-in. A hash that it does not hold:
28 file copy .rep.fossil srv.fossil
29 set xferserverAbsent [string repeat 0123456789abcdef 4]
30
31 set xferserverLogin "login tester 0 0\n"
32 set xferserverPull "pull x $xferserverPcode\n"
33 set xferserverPush "push x $xferserverPcode\n"
34
 
35 proc xferserver_caps {caps} {
36 fossil sql -R srv.fossil \
37 "UPDATE user SET cap='$caps' WHERE login IN ('nobody','anonymous')"
38 }
39
40 proc xferserver_set {name value} {
41 fossil sql -R srv.fossil \
42 "REPLACE INTO config(name,value,mtime) VALUES('$name','$value',now())"
43 }
44
45 proc xferserver_unset {pattern} {
46 fossil sql -R srv.fossil "DELETE FROM config WHERE name GLOB '$pattern'"
47 }
48
49 # Returns the number of rows on the server that "SELECT count(*) FROM"
50 # finds, with FROM as the remainder of the query.
51 proc xferserver_count {from} {
52 fossil sql -R srv.fossil "SELECT count(*) FROM $from"
53 return [string trim $::RESULT]
54 }
55
56 # Returns 1 if the server holds the artifact HASH, or a phantom for it,
57 # and has it marked private.
58 proc xferserver_private {hash} {
59 return [xferserver_count \
60 "blob b, private p WHERE p.rid=b.rid AND b.uuid='$hash'"]
61 }
62
63 # Send the message BODY to the server. Sets RESULT to the reply, as
64 # bytes because it can hold compressed content, and CODE to the exit
65 # status of fossil.
66 proc xferserver_send {body} {
67 write_file msg.txt $body
68 fossil_raw test-xfer -R srv.fossil msg.txt
69 }
70
71 # Send the message BODY. Test NAME passes when fossil exits with status
72 # 0 and the reply holds each of the strings given. A string that begins
73 # with "!" must be absent.
74 proc xferserver_expect {name body args} {
75 xferserver_send $body
76 test xfer-server-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
77 }
78
79 # The message with which the client CLIENT asks for the lock on the
80 # check-in CKIN.
81 proc xferserver_lock {ckin client} {
82 global xferserverLogin xferserverPull
83 return "$xferserverLogin${xferserverPull}pragma ci-lock $ckin $client\n"
84 }
85
86 ###############################################################################
87 # With no permissions at all, everything is refused.
88
89 xferserver_caps ""
@@ -91,37 +99,40 @@
99 {error not\sauthorized\sto\swrite}
100 xferserver_expect none-uvgimme "uvgimme note.txt\n" "!uvfile" "errors 0"
101 xferserver_expect none-reqconfig "reqconfig /project\n" "!config " "errors 0"
102 xferserver_expect none-uv-hash "pragma uv-hash $xferserverAbsent\n" \
103 "!uv-pull-only" "!uv-push-ok"
104 xferserver_expect none-private "private\n" \
105 {error not\sauthorized\sto\ssync\sprivate}
106 xferserver_expect none-send-private "pragma send-private\n" \
107 {error not\sauthorized\sto\ssync\sprivate}
108 xferserver_expect none-config "config /project 0\n\n" \
109 {error not\sauthorized\sto\spush\sconfiguration}
110
111 ###############################################################################
112 # Read only: a pull is served, a push after it is turned into a message.
113
114 xferserver_caps "o"
115 xferserver_expect read-pull $CLIENT_VERSION_CARD$xferserverPull \
116 "igot " "pragma server-version" "errors 0"
117 xferserver_expect read-pull-then-push $xferserverPull$xferserverPush \
118 {message pull\sonly\s-\snot\sauthorized\sto\spush}
119 xferserver_expect read-gimme \
120 "$CLIENT_VERSION_CARD${xferserverPull}gimme $xferserverFile\n" \
121 "file $xferserverFile"
122 # A client that gives no version is taken to be older than 2.0, which
123 # cannot be sent a SHA3 hash.
124 xferserver_expect read-gimme-old-client \
125 "${xferserverPull}gimme $xferserverFile\n" \
126 "!file $xferserverFile" {error Fossil\sversion\s2.0\sor\slater\srequired}
127 xferserver_expect read-gimme-absent \
128 "${xferserverPull}gimme $xferserverAbsent\n" \
129 "!file $xferserverAbsent" "errors 0"
130 xferserver_expect read-gimme-no-pull "gimme $xferserverFile\n" \
131 "!file $xferserverFile" "errors 0"
132 xferserver_expect read-igot-no-push \
133 "${xferserverPull}igot $xferserverAbsent\n" \
134 "!gimme $xferserverAbsent" "errors 0"
135 xferserver_expect read-uv-hash "pragma uv-hash $xferserverAbsent\n" \
136 "pragma uv-pull-only"
137 xferserver_expect read-reqconfig "reqconfig /project\n" "config /config "
138 xferserver_expect read-reqconfig-old-style "reqconfig project-name\n" \
@@ -162,49 +173,47 @@
173 ###############################################################################
174 # Write without Private: a client that says an artifact is private is not
175 # asked for it, and may not send private content.
176
177 xferserver_caps "io"
178 xferserver_expect write-igot-public \
179 "${xferserverPush}igot $xferserverAbsent\n" \
180 "gimme $xferserverAbsent"
181 test xfer-server-write-igot-public-not-private \
182 {[xferserver_private $xferserverAbsent] == 0}
 
183 xferserver_expect write-igot-private-known \
184 "${xferserverPush}igot $xferserverAbsent 1\n" \
185 "!gimme $xferserverAbsent" "errors 0"
186 test xfer-server-write-igot-private-marks-phantom \
187 {[xferserver_private $xferserverAbsent] == 1}
188 set xferserverUnknown [string repeat fedcba9876543210 4]
 
189 xferserver_expect write-igot-private-unknown \
190 "${xferserverPush}igot $xferserverUnknown 1\n" \
191 "!gimme $xferserverUnknown" "errors 0"
192 test xfer-server-write-igot-private-unknown-not-stored \
193 {[xferserver_count "blob WHERE uuid='$xferserverUnknown'"] == 0}
 
194 xferserver_expect write-private "${xferserverPush}private\n" \
195 {error not\sauthorized\sto\ssync\sprivate}
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 ""
206 # A private artifact that the server does not have becomes a private
207 # phantom. It is asked for only when the client offers to send private
208 # content.
209 set xferserverPhantom [string repeat 00112233445566778899aabbccddeeff 2]
210 xferserver_expect login-igot-private \
211 "$xferserverLogin${xferserverPush}igot $xferserverPhantom 1\n" \
212 "!gimme $xferserverPhantom" "errors 0"
213 test xfer-server-login-igot-private-phantom \
214 {[xferserver_private $xferserverPhantom] == 1}
 
215 xferserver_expect login-private "$xferserverLogin${xferserverPush}private\n" \
216 "errors 0"
217 xferserver_expect login-send-private \
218 "$xferserverLogin${xferserverPull}pragma send-private\n" "errors 0"
219 xferserver_expect login-send-catalog \
@@ -212,67 +221,61 @@
221 "igot $xferserverFile"
222 xferserver_expect login-req-clusters \
223 "$xferserverLogin${xferserverPull}pragma req-clusters\n" "errors 0"
224 xferserver_expect login-req-links \
225 "$xferserverLogin${xferserverPull}pragma req-links\n" "errors 0"
226 # The hash is that of the empty string under SHA1.
227 xferserver_expect login-uv-hash-same \
228 "${xferserverLogin}pragma uv-hash\
229 da39a3ee5e6b4b0d3255bfef95601890afd80709\n" \
230 "!uv-pull-only" "!uv-push-ok"
231
 
232 xferserver_send "${xferserverLogin}reqconfig /project\n"
233 test xfer-server-login-reqconfig \
234 {$CODE == 0 && [string first "config /config " $RESULT] >= 0}
235 set xferserverCards ""
236 foreach xferserverLine [split $RESULT \n] {
237 if {[string match "#*" $xferserverLine]} continue
238 append xferserverCards $xferserverLine\n
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"
 
249 xferserver_expect clone-v2-old-client "clone 2 1\n" \
250 "!file " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0"
251 xferserver_expect clone-v3-old-client "clone 3 1\n" \
252 "!cfile " {error Fossil\sversion\s2.0\sor\slater\srequired} "clone_seqno 0"
253 xferserver_expect clone-v1 "${CLIENT_VERSION_CARD}clone\n" \
254 "push " "igot $xferserverFile" "errors 0"
255 xferserver_expect clone-v1-odd-arguments "${CLIENT_VERSION_CARD}clone x y\n" \
256 "push " "errors 0"
257 xferserver_expect clone-v2 "${CLIENT_VERSION_CARD}clone 2 1\n" \
258 "file " "clone_seqno 0"
259 xferserver_expect clone-v3 "${CLIENT_VERSION_CARD}clone 3 1\n" \
260 "cfile " "clone_seqno 0" "errors 0"
 
 
261 xferserver_expect clone-v3-past-end \
262 "${CLIENT_VERSION_CARD}clone 3 [expr {$xferserverMaxRid+50}]\n" \
263 "!cfile " "clone_seqno 0"
264 xferserver_expect clone-v3-zero "${CLIENT_VERSION_CARD}clone 3 0\n" \
265 {error invalid\sclone\ssequence\snumber}
266 xferserver_set max-download 1
267 xferserver_expect clone-v3-small-reply "${CLIENT_VERSION_CARD}clone 3 1\n" \
 
268 "!cfile " "clone_seqno 1"
269 xferserver_unset max-download
270 xferserver_set max-download-time 0
271 xferserver_expect clone-v3-no-time "${CLIENT_VERSION_CARD}clone 3 1\n" "cfile "
272 xferserver_unset max-download-time
273 xferserver_set uv-sync 1
274 xferserver_expect clone-uv-sync "${CLIENT_VERSION_CARD}clone 3 1\n" \
 
 
275 "pragma uv-pull-only"
276 xferserver_unset uv-sync
 
 
277 xferserver_caps ""
278
279 # Check-in locks. The second client to ask for the lock on the same
280 # check-in is told who holds it; the holder asking again is not.
281 fossil sql -R srv.fossil "SELECT uuid FROM blob WHERE rid=(SELECT max(objid)\
@@ -279,53 +282,52 @@
282 FROM event WHERE type='ci')"
283 set xferserverCkin [string trim $::RESULT]
284 set xferserverClientA [string repeat a 40]
285 set xferserverClientB [string repeat b 40]
286 xferserver_expect ci-lock-first \
287 [xferserver_lock $xferserverCkin $xferserverClientA] \
288 "!ci-lock-fail" "pragma avoid-delta-manifests"
289 xferserver_expect ci-lock-holder-again \
290 [xferserver_lock $xferserverCkin $xferserverClientA] "!ci-lock-fail"
 
291 xferserver_expect ci-lock-second-client \
292 [xferserver_lock $xferserverCkin $xferserverClientB] "pragma ci-lock-fail "
 
293 xferserver_expect ci-unlock \
294 "$xferserverLogin${xferserverPull}pragma ci-unlock $xferserverClientA\n" \
295 "errors 0"
296 test xfer-server-ci-unlock-removed \
297 {[xferserver_count "config WHERE name GLOB 'ci-lock-*'"] == 0}
298 xferserver_expect ci-lock-after-unlock \
299 [xferserver_lock $xferserverCkin $xferserverClientB] "!ci-lock-fail"
300 fossil sql -R srv.fossil \
301 "UPDATE config SET mtime=mtime-100000 WHERE name GLOB 'ci-lock-*'"
 
302 xferserver_expect ci-lock-expired \
303 [xferserver_lock $xferserverCkin $xferserverClientA] "!ci-lock-fail"
304 xferserver_set forbid-delta-manifests 0
 
 
305 xferserver_expect ci-lock-delta-manifests-allowed \
306 [xferserver_lock $xferserverCkin $xferserverClientA] \
307 "!avoid-delta-manifests" "errors 0"
308
309 ###############################################################################
310 # More cards and pragmas under particular permissions and settings.
311
312 xferserver_unset ci-lock-*
313 xferserver_unset forbid-delta-manifests
314 # An igot card with a flag of 0 offers a public artifact.
315 set xferserverPublic [string repeat 0f1e2d3c4b5a6978 4]
316 xferserver_expect login-igot-flag-zero \
317 "$xferserverLogin${xferserverPush}igot $xferserverPublic 0\n" \
318 "gimme $xferserverPublic"
319 xferserver_expect bad-config-too-few "${xferserverLogin}config /project\n" \
320 {error bad\scommand:}
321 xferserver_expect uv-hash-not-a-hash \
322 "${xferserverLogin}pragma uv-hash nothash\n" \
323 "!uv-pull-only" "!uv-push-ok" "errors 0"
324 xferserver_expect ci-lock-not-a-hash \
325 [xferserver_lock nothash $xferserverClientA] \
326 "!avoid-delta-manifests" "errors 0"
327 xferserver_expect ci-unlock-too-few "${xferserverLogin}pragma ci-unlock\n" \
328 "errors 0"
329 xferserver_expect client-url-too-few "${xferserverLogin}pragma client-url\n" \
330 "errors 0"
331
332 # The unversioned catalog is sent once in a reply, and a client that may
333 # write unversioned files is told so.
@@ -334,96 +336,88 @@
336 "pragma uv-push-ok"
337 xferserver_expect uv-hash-twice \
338 "pragma uv-hash $xferserverAbsent\npragma uv-hash $xferserverAbsent\n" \
339 "pragma uv-push-ok" "errors 0"
340 test xfer-server-uv-hash-twice-one-answer \
341 {[regexp -all {pragma uv-push-ok} $RESULT] == 1}
342
 
343 xferserver_caps "o"
344 xferserver_expect read-client-url \
345 "${xferserverPull}pragma client-url http://example.net/z\n" "errors 0"
346 test xfer-server-read-client-url-not-recorded \
347 {[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0}
 
348
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"
359
 
360 xferserver_caps "gx"
361 xferserver_expect clone-version-one "${CLIENT_VERSION_CARD}clone 1 1\n" \
362 "push " "igot $xferserverFile" "errors 0"
363 xferserver_expect clone-then-gimme \
364 "${CLIENT_VERSION_CARD}clone\ngimme $xferserverFile\n" \
365 "file $xferserverFile" "errors 0"
366 xferserver_expect clone-send-private \
367 "${CLIENT_VERSION_CARD}pragma send-private\nclone\n" "push " "errors 0"
368 xferserver_set uv-sync 1
 
369 xferserver_expect clone-uv-sync-after-uv-hash \
370 "${CLIENT_VERSION_CARD}pragma uv-hash $xferserverAbsent\nclone 3 1\n" \
371 "pragma uv-pull-only"
372 test xfer-server-clone-uv-sync-one-catalog \
373 {[regexp -all {pragma uv-pull-only} $RESULT] == 1}
374 xferserver_unset uv-sync
375 xferserver_caps ""
376
377 # More check-in locks: a lock on another check-in does not block this
378 # one, a lock on a check-in that has a child is dropped, and a lock with
379 # no user name is reported as held by "nobody".
380 fossil sql -R srv.fossil "SELECT b.uuid FROM blob b, plink p\
381 WHERE b.rid=p.pid AND p.cid=(SELECT max(objid) FROM event WHERE type='ci')"
382 set xferserverParent [string trim $::RESULT]
383 test xfer-server-setup-parent {[string length $xferserverParent] >= 40}
384 xferserver_expect ci-lock-on-parent \
385 [xferserver_lock $xferserverParent $xferserverClientA] \
386 "!ci-lock-fail" "errors 0"
387 xferserver_expect ci-lock-parent-not-a-leaf \
388 [xferserver_lock $xferserverParent $xferserverClientB] \
389 "!ci-lock-fail" "errors 0"
390 xferserver_expect ci-lock-tip \
391 [xferserver_lock $xferserverCkin $xferserverClientA] \
392 "!ci-lock-fail" "errors 0"
393 test xfer-server-ci-lock-parent-dropped \
394 {[xferserver_count "config WHERE name GLOB 'ci-lock-*'"] == 1}
395 fossil sql -R srv.fossil "UPDATE config SET value=json_object('clientid',\
396 '$xferserverClientA') WHERE name GLOB 'ci-lock-*'"
397 xferserver_expect ci-lock-held-by-nobody \
398 [xferserver_lock $xferserverCkin $xferserverClientB] \
399 "pragma ci-lock-fail nobody "
400 xferserver_unset ci-lock-*
401
402 # The TH1 transfer scripts run on the server. One that fails is reported.
403 xferserver_set xfer-push-script "set xferserverSeen 1"
 
404 xferserver_expect push-script-ok "$xferserverLogin$xferserverPush" "errors 0"
405 xferserver_set xfer-push-script "error push-script-says-no"
 
406 xferserver_expect push-script-fails "$xferserverLogin$xferserverPush" \
407 {error push\sscript\sfailed:} "push-script-says-no"
408 xferserver_unset xfer-push-script
409 xferserver_set xfer-common-script "error common-script-says-no"
 
410 xferserver_expect common-script-fails \
411 "$xferserverLogin$xferserverPull$xferserverPush" \
412 {error common\sscript\sfailed:} "common-script-says-no"
413 xferserver_unset xfer-common-script
414
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

Keyboard Shortcuts

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