Fossil SCM

Make the cgi, login, content, config and xfer-server tests faster. Ensure that at least one thing is run by all test files at assurance level smoke, except powerloss. Move repeated code from coverage tests into helpers in tester.tcl.

danshearer 2026-11-27 16:05 UTC test-suite-new
Commit 5aaa98564dccbae7e2b74b035ca0abb79f8045554262c05138da87a98c4c70f7
+59 -17
--- test/README.md
+++ test/README.md
@@ -46,23 +46,19 @@
4646
run per input kind. The default is 20 (5 for expensive `large` /
4747
`repeats` inputs). Use `-trials 100` for the historical full fuzz.
4848
This flag is only the fuzz loop count; it does not select
4949
`-assurance` cases.
5050
* `-assurance smoke|ci|stress` selects how thoroughly the tests run.
51
- The default is `smoke`, which skips `powerloss`. It also sets the
52
- cases that `unicode-pathnames` and `utf` run:
53
- - `unicode-pathnames`: `smoke` is one pair per fold-behavior class;
54
- `ci` is the full hand-written lists; `stress` adds generated pairs.
55
- At startup the harness classifies the temporary filesystem once
56
- (ASCII case, NFC/NFD, and sharp-s versus `ss`). Predictions use
57
- that classification with Fossil's `case-sensitive` setting
58
- (byte-for-byte when on; Unicode D145 caseless match when off).
59
- - `utf`: `smoke` is a stratified edge set of `test-looks-like-utf`
60
- cells; `ci` is the full BOM×payload×extra product; `stress` adds
61
- generated payloads. A Tcl predictor scores each LOOK_*/BOM line
62
- for both yes and no.
63
- Unmet predictions fail the run.
51
+ The default is `smoke`, which runs something from every file but
52
+ `powerloss`. `ci` adds `powerloss`, the full hand-written cases of
53
+ `unicode-pathnames` and `utf`, and the slower tests of `content`,
54
+ `cgi`, `login` and `config`. `stress` adds generated cases for
55
+ `unicode-pathnames` and `utf`, and the rest of the coverage tests,
56
+ which aim at every branch and condition of the code they test. At
57
+ `smoke` each coverage test file runs only its first sections, about
58
+ half a second of them. The Coverage table below says which files need
59
+ which level.
6460
6561
`make test TESTFLAGS="-quiet update"` passes options and names via `make`.
6662
6763
Assurance recipes:
6864
@@ -116,22 +112,57 @@
116112
| Area | Test files | Runs at |
117113
| --- | --- | --- |
118114
| Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `unicode-pathnames`, `update` | `smoke` |
119115
| Branches and tags | `branch-tag` | `smoke` |
120116
| Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` | `smoke` |
117
+| Clone, push, pull and sync | `sync` | `smoke` for the first sections, and the rest at `stress` |
121118
| HTTP and HTTPS client | `http` | `smoke` |
119
+| Rebuild, reconstruct, and `test-integrity` and `test-missing` on damaged repositories | `integrity` | `smoke` |
120
+| Commands that must not change what a repository holds: `rebuild`, `repack`, `deconstruct`, `reconstruct` and `detach` | `rebuild` | `smoke` for the first sections, and the rest at `stress` |
121
+| The content store: long delta chains, the cache of reconstructed artifacts, making and undoing deltas, content that arrives late, and what `test-integrity --parse`, `test-missing` and `test-orphans` report | `content` | `smoke`, and the cache limits at `ci` |
122
+| What the database shows after an artifact of each kind is stored, and what the artifact parser refuses | `crosslink` | `smoke` for the first sections, and the rest at `stress` |
123
+| Check-ins read by name and their files found: two check-ins compared, `/dir` and `/tree`, delta manifests, file names in another letter case, and the JSON form of each kind of artifact | `manifest` | `smoke` |
124
+| How a name from a user or a URL becomes an artifact | `name` | `smoke` for the first sections, and the rest at `stress` |
122125
| Commands interrupted by a power loss or a killed process | `powerloss` | `ci` |
123126
| Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip`, `git-export` | `smoke` |
127
+| Sync protocol cards, sent to the server and to the client | `xfer-server`, `xfer-client` | `smoke` for the first sections, and the rest at `stress` |
128
+| The login card of the sync protocol, checked by a server without `--localauth` | `xfer-server` | `smoke` for the first sections, and the rest at `stress` |
129
+| A clone made over the sync protocol, with and without unversioned files, with small replies, and refused | `sync` | `smoke` for the first sections, and the rest at `stress` |
130
+| Whole pushes, pulls and syncs: private check-ins, unversioned files in both directions, and a pull from a parent project | `sync` | `smoke` for the first sections, and the rest at `stress` |
131
+| URLs of remote repositories, and well-formed and malformed replies to the sync client | `url` | `smoke` for the first sections, and the rest at `stress` |
132
+| `fossil configuration` export, import, merge and reset, and the configuration that push, pull and sync transfer | `config` | `smoke` for the first sections, and the rest at `ci` |
133
+| Commands that remove content: `purge` with its graveyard, undo and obliterate, `scrub`, and `repack` | `purge` | `smoke` for the first sections, and the rest at `stress` |
134
+| How a server reads a request: query strings, forms, uploads in several parts, dates in headers, SCGI, and requests over ssh | `cgi` | `smoke` for the first request of each kind, and the rest at `ci` |
135
+| How a server decides who the user is | `login` | `smoke`, and the logins that Fossil delays by a second at `ci` |
136
+| `fossil import --svn` of dumps whose contents are svndiff0 deltas | `import` | `smoke` for the first sections, and the rest at `stress` |
137
+| What Fossil puts on an `ssh` command line | `ssh` | `smoke` |
124138
| Diffs and deltas | `delta1`, `diff` | `smoke` |
139
+| Fossil's text buffer, `src/blob.c` | `blob` | `smoke` for the first sections, and the rest at `stress` |
140
+| Malformed input to the delta and manifest parsers, from the inputs in `corpus/corpus.pack` | `fuzz` | `smoke` |
141
+| Random integration tests of sync: sequences of commits, merges and syncs among three clones, with lost and cut-short sync messages, from the scenario inputs in `corpus/corpus.pack`. Slow for its 16 tests, because each step is a separate run of `fossil`. | `scenario` | `smoke` for one input, and the rest at `stress` |
142
+| Faults that have been fixed | `regress` | `smoke` |
125143
| Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` |
126144
| Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` |
127145
| TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` |
146
+| Fossil's own TH1 commands and the template renderer | `th1main` | `smoke` for the first sections, and the rest at `stress` |
128147
| JSON API | `json` | `smoke` |
129148
| Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` |
130149
131150
## Fuzz inputs and run-time checking
132151
152
+`corpus/corpus.pack` has the inputs that `fuzz.test` gives to
153
+`fossil test-fuzz`, and the inputs of `scenario.test`. They are packed in
154
+one file so that the corpus doesn't add hundreds of files to every check-in
155
+manifest, and the tests unpack it themselves. To add an input, or to give a
156
+fuzzing engine a starting corpus, unpack it and pack it again:
157
+
158
+```sh
159
+tclsh corpus.tcl unpack corpus/corpus.pack DIR
160
+tclsh corpus.tcl pack DIR corpus/corpus.pack
161
+```
162
+
163
+`corpus.tcl` describes the format and each type of input.
133164
134165
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.
135166
136167
## Writing new tests
137168
@@ -178,14 +209,25 @@
178209
* standard input, with `-input TEXT`
179210
* a time limit, with `-seconds N`. The default is 600.
180211
* a server in the test's own Tcl. The Tcl event loop runs while the
181212
command does, so a `socket -server` in your test file can answer it.
182213
183
-`holds_strings TEXT WANTED` returns 1 if `TEXT` has every string in the
184
-list `WANTED`, where a string starting with `!` must be absent.
185
-`test_start_server` takes options for `fossil server` after its second
186
-argument.
214
+Before you write a helper procedure, look in `tester.tcl` for one. Each has
215
+a comment saying what it does. There are helpers for these jobs:
216
+
217
+* asking a repository a question in SQL: `fossil_sql`
218
+* requesting a web page without a server: `request_get` or `request_post`,
219
+ then `fossil_http`, then `reply_status`, `reply_header` and `reply_body`
220
+* answering Fossil when it is the client: `test_listen`
221
+* checking that a command left a repository as it was: `repository_state`
222
+ before and after, then `repository_state_diff`
223
+* checking that a repository isn't damaged: `repository_sound`
224
+* hashing a file or a string: `sha3_file`, `sha3_text` and the `sha1`
225
+ pair
226
+* checking output for several strings at once: `holds_strings`
227
+* starting and stopping `fossil server`: `test_start_server` and
228
+ `test_stop_server`
187229
188230
## Maintaining the tests
189231
190232
First step is noticing bugs. One pattern is when Fossil's output changes causing tests that rely on changed output to fail. `tester.tcl` prints the expected and the actual text for each but this won't always be obvious. It's possible that output changes may mask a code failure too.
191233
192234
--- test/README.md
+++ test/README.md
@@ -46,23 +46,19 @@
46 run per input kind. The default is 20 (5 for expensive `large` /
47 `repeats` inputs). Use `-trials 100` for the historical full fuzz.
48 This flag is only the fuzz loop count; it does not select
49 `-assurance` cases.
50 * `-assurance smoke|ci|stress` selects how thoroughly the tests run.
51 The default is `smoke`, which skips `powerloss`. It also sets the
52 cases that `unicode-pathnames` and `utf` run:
53 - `unicode-pathnames`: `smoke` is one pair per fold-behavior class;
54 `ci` is the full hand-written lists; `stress` adds generated pairs.
55 At startup the harness classifies the temporary filesystem once
56 (ASCII case, NFC/NFD, and sharp-s versus `ss`). Predictions use
57 that classification with Fossil's `case-sensitive` setting
58 (byte-for-byte when on; Unicode D145 caseless match when off).
59 - `utf`: `smoke` is a stratified edge set of `test-looks-like-utf`
60 cells; `ci` is the full BOM×payload×extra product; `stress` adds
61 generated payloads. A Tcl predictor scores each LOOK_*/BOM line
62 for both yes and no.
63 Unmet predictions fail the run.
64
65 `make test TESTFLAGS="-quiet update"` passes options and names via `make`.
66
67 Assurance recipes:
68
@@ -116,22 +112,57 @@
116 | Area | Test files | Runs at |
117 | --- | --- | --- |
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
@@ -178,14 +209,25 @@
178 * standard input, with `-input TEXT`
179 * a time limit, with `-seconds N`. The default is 600.
180 * a server in the test's own Tcl. The Tcl event loop runs while the
181 command does, so a `socket -server` in your test file can answer it.
182
183 `holds_strings TEXT WANTED` returns 1 if `TEXT` has every string in the
184 list `WANTED`, where a string starting with `!` must be absent.
185 `test_start_server` takes options for `fossil server` after its second
186 argument.
 
 
 
 
 
 
 
 
 
 
 
187
188 ## Maintaining the tests
189
190 First step is noticing bugs. One pattern is when Fossil's output changes causing tests that rely on changed output to fail. `tester.tcl` prints the expected and the actual text for each but this won't always be obvious. It's possible that output changes may mask a code failure too.
191
192
--- test/README.md
+++ test/README.md
@@ -46,23 +46,19 @@
46 run per input kind. The default is 20 (5 for expensive `large` /
47 `repeats` inputs). Use `-trials 100` for the historical full fuzz.
48 This flag is only the fuzz loop count; it does not select
49 `-assurance` cases.
50 * `-assurance smoke|ci|stress` selects how thoroughly the tests run.
51 The default is `smoke`, which runs something from every file but
52 `powerloss`. `ci` adds `powerloss`, the full hand-written cases of
53 `unicode-pathnames` and `utf`, and the slower tests of `content`,
54 `cgi`, `login` and `config`. `stress` adds generated cases for
55 `unicode-pathnames` and `utf`, and the rest of the coverage tests,
56 which aim at every branch and condition of the code they test. At
57 `smoke` each coverage test file runs only its first sections, about
58 half a second of them. The Coverage table below says which files need
59 which level.
 
 
 
 
60
61 `make test TESTFLAGS="-quiet update"` passes options and names via `make`.
62
63 Assurance recipes:
64
@@ -116,22 +112,57 @@
112 | Area | Test files | Runs at |
113 | --- | --- | --- |
114 | Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `unicode-pathnames`, `update` | `smoke` |
115 | Branches and tags | `branch-tag` | `smoke` |
116 | Merges, cherrypicks, backouts, and annotate and blame after them | `merge1` to `merge6`, `merge-history`, `merge_exe`, `merge_renames`, `merge_renames_2`, `merge_warn` | `smoke` |
117 | Clone, push, pull and sync | `sync` | `smoke` for the first sections, and the rest at `stress` |
118 | HTTP and HTTPS client | `http` | `smoke` |
119 | Rebuild, reconstruct, and `test-integrity` and `test-missing` on damaged repositories | `integrity` | `smoke` |
120 | Commands that must not change what a repository holds: `rebuild`, `repack`, `deconstruct`, `reconstruct` and `detach` | `rebuild` | `smoke` for the first sections, and the rest at `stress` |
121 | The content store: long delta chains, the cache of reconstructed artifacts, making and undoing deltas, content that arrives late, and what `test-integrity --parse`, `test-missing` and `test-orphans` report | `content` | `smoke`, and the cache limits at `ci` |
122 | What the database shows after an artifact of each kind is stored, and what the artifact parser refuses | `crosslink` | `smoke` for the first sections, and the rest at `stress` |
123 | Check-ins read by name and their files found: two check-ins compared, `/dir` and `/tree`, delta manifests, file names in another letter case, and the JSON form of each kind of artifact | `manifest` | `smoke` |
124 | How a name from a user or a URL becomes an artifact | `name` | `smoke` for the first sections, and the rest at `stress` |
125 | Commands interrupted by a power loss or a killed process | `powerloss` | `ci` |
126 | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip`, `git-export` | `smoke` |
127 | Sync protocol cards, sent to the server and to the client | `xfer-server`, `xfer-client` | `smoke` for the first sections, and the rest at `stress` |
128 | The login card of the sync protocol, checked by a server without `--localauth` | `xfer-server` | `smoke` for the first sections, and the rest at `stress` |
129 | A clone made over the sync protocol, with and without unversioned files, with small replies, and refused | `sync` | `smoke` for the first sections, and the rest at `stress` |
130 | Whole pushes, pulls and syncs: private check-ins, unversioned files in both directions, and a pull from a parent project | `sync` | `smoke` for the first sections, and the rest at `stress` |
131 | URLs of remote repositories, and well-formed and malformed replies to the sync client | `url` | `smoke` for the first sections, and the rest at `stress` |
132 | `fossil configuration` export, import, merge and reset, and the configuration that push, pull and sync transfer | `config` | `smoke` for the first sections, and the rest at `ci` |
133 | Commands that remove content: `purge` with its graveyard, undo and obliterate, `scrub`, and `repack` | `purge` | `smoke` for the first sections, and the rest at `stress` |
134 | How a server reads a request: query strings, forms, uploads in several parts, dates in headers, SCGI, and requests over ssh | `cgi` | `smoke` for the first request of each kind, and the rest at `ci` |
135 | How a server decides who the user is | `login` | `smoke`, and the logins that Fossil delays by a second at `ci` |
136 | `fossil import --svn` of dumps whose contents are svndiff0 deltas | `import` | `smoke` for the first sections, and the rest at `stress` |
137 | What Fossil puts on an `ssh` command line | `ssh` | `smoke` |
138 | Diffs and deltas | `delta1`, `diff` | `smoke` |
139 | Fossil's text buffer, `src/blob.c` | `blob` | `smoke` for the first sections, and the rest at `stress` |
140 | Malformed input to the delta and manifest parsers, from the inputs in `corpus/corpus.pack` | `fuzz` | `smoke` |
141 | Random integration tests of sync: sequences of commits, merges and syncs among three clones, with lost and cut-short sync messages, from the scenario inputs in `corpus/corpus.pack`. Slow for its 16 tests, because each step is a separate run of `fossil`. | `scenario` | `smoke` for one input, and the rest at `stress` |
142 | Faults that have been fixed | `regress` | `smoke` |
143 | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` |
144 | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` |
145 | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` |
146 | Fossil's own TH1 commands and the template renderer | `th1main` | `smoke` for the first sections, and the rest at `stress` |
147 | JSON API | `json` | `smoke` |
148 | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` |
149
150 ## Fuzz inputs and run-time checking
151
152 `corpus/corpus.pack` has the inputs that `fuzz.test` gives to
153 `fossil test-fuzz`, and the inputs of `scenario.test`. They are packed in
154 one file so that the corpus doesn't add hundreds of files to every check-in
155 manifest, and the tests unpack it themselves. To add an input, or to give a
156 fuzzing engine a starting corpus, unpack it and pack it again:
157
158 ```sh
159 tclsh corpus.tcl unpack corpus/corpus.pack DIR
160 tclsh corpus.tcl pack DIR corpus/corpus.pack
161 ```
162
163 `corpus.tcl` describes the format and each type of input.
164
165 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.
166
167 ## Writing new tests
168
@@ -178,14 +209,25 @@
209 * standard input, with `-input TEXT`
210 * a time limit, with `-seconds N`. The default is 600.
211 * a server in the test's own Tcl. The Tcl event loop runs while the
212 command does, so a `socket -server` in your test file can answer it.
213
214 Before you write a helper procedure, look in `tester.tcl` for one. Each has
215 a comment saying what it does. There are helpers for these jobs:
216
217 * asking a repository a question in SQL: `fossil_sql`
218 * requesting a web page without a server: `request_get` or `request_post`,
219 then `fossil_http`, then `reply_status`, `reply_header` and `reply_body`
220 * answering Fossil when it is the client: `test_listen`
221 * checking that a command left a repository as it was: `repository_state`
222 before and after, then `repository_state_diff`
223 * checking that a repository isn't damaged: `repository_sound`
224 * hashing a file or a string: `sha3_file`, `sha3_text` and the `sha1`
225 pair
226 * checking output for several strings at once: `holds_strings`
227 * starting and stopping `fossil server`: `test_start_server` and
228 `test_stop_server`
229
230 ## Maintaining the tests
231
232 First step is noticing bugs. One pattern is when Fossil's output changes causing tests that rely on changed output to fail. `tester.tcl` prints the expected and the actual text for each but this won't always be obvious. It's possible that output changes may mask a code failure too.
233
234
+65 -64
--- test/blob.test
+++ test/blob.test
@@ -7,15 +7,12 @@
77
# through other commands: the string literals of "diff --json" and
88
# "diff --tcl", and the conversions that a commit offers for a file in
99
# another encoding.
1010
#
1111
12
-# These tests run only in a long pass: -assurance stress.
13
-if {[test_assurance] ne "stress"} {
14
- test_skip "runs only with -assurance stress"
15
-}
16
-
12
+# The first sections run at every level, and the rest need
13
+# -assurance stress.
1714
require_no_open_checkout
1815
1916
test_setup
2017
2118
# The bytes that the hexadecimal digits in $hex stand for.
@@ -33,11 +30,11 @@
3330
3431
###############################################################################
3532
# test-isspace checks fossil_isspace() against every byte value.
3633
3734
fossil test-isspace
38
-test blob-isspace-1 {[string trim $RESULT] eq "All 256 characters OK"}
35
+test_eq blob-isspace-1 [string trim $RESULT] "All 256 characters OK"
3936
4037
###############################################################################
4138
# test-atoi prints, for each argument, whether it is a non-negative
4239
# integer of 32 bits and of 64 bits, and the value. Each row: the
4340
# argument, then the two answers and values that must be printed.
@@ -147,13 +144,15 @@
147144
[string length [lindex [split $RESULT \n] 0]] == $blobWide}
148145
}
149146
150147
# The command takes exactly one file.
151148
fossil_raw test-strip-comment-lines
152
-test blob-strip-usage-none {$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
149
+test blob-strip-usage-none \
150
+ {$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
153151
fossil_raw test-strip-comment-lines strip-sbs.txt strip-sbs.txt
154
-test blob-strip-usage-two {$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
152
+test blob-strip-usage-two {$CODE == 1 && [string match "Usage:*INPUTFILE*" \
153
+ $RESULT]}
155154
156155
###############################################################################
157156
# Reading a file. A file that is not there and a file that cannot be
158157
# opened are errors that name the file.
159158
@@ -268,13 +267,16 @@
268267
# Each of the three commands wants an exact number of file names.
269268
foreach {blobName blobCommand blobUsage} {
270269
compress-0 {test-compress} "INPUTFILE OUTPUTFILE"
271270
compress-1 {test-compress z-text.in} "INPUTFILE OUTPUTFILE"
272271
compress-3 {test-compress z-text.in a b} "INPUTFILE OUTPUTFILE"
273
- compress2-0 {test-compress-2} "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
274
- compress2-2 {test-compress-2 z-text.in a} "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
275
- compress2-4 {test-compress-2 z-text.in a b c} "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
272
+ compress2-0 {test-compress-2}
273
+ "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
274
+ compress2-2 {test-compress-2 z-text.in a}
275
+ "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
276
+ compress2-4 {test-compress-2 z-text.in a b c}
277
+ "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
276278
uncompress-0 {test-uncompress} "INPUTFILE OUTPUTFILE"
277279
uncompress-1 {test-uncompress z-text.z} "INPUTFILE OUTPUTFILE"
278280
uncompress-3 {test-uncompress z-text.z a b} "INPUTFILE OUTPUTFILE"
279281
} {
280282
fossil_raw {*}$blobCommand
@@ -289,11 +291,12 @@
289291
# that cannot be made is an error that names it.
290292
291293
fossil_raw test-compress z-text.in -
292294
test blob-write-stdout-dash {$CODE == 0 && $RESULT eq [read_file z-text.z]}
293295
fossil_raw test-compress z-text.in {}
294
-test blob-write-stdout-empty-name {$CODE == 0 && $RESULT eq [read_file z-text.z]}
296
+test blob-write-stdout-empty-name \
297
+ {$CODE == 0 && $RESULT eq [read_file z-text.z]}
295298
fossil_raw test-uncompress z-empty.z -
296299
test blob-write-stdout-nothing {$CODE == 0 && $RESULT eq ""}
297300
fossil_raw test-uncompress z-empty.z write-empty.out
298301
test blob-write-empty-file {$CODE == 0 && [file exists write-empty.out] &&
299302
[file size write-empty.out] == 0}
@@ -314,10 +317,14 @@
314317
test blob-write-closed-directory {$CODE == 1 &&
315318
[string match "*unable to open file \"write-closed/out.z\" for writing*" \
316319
$RESULT]}
317320
file attributes write-closed -permissions 0755
318321
}
322
+
323
+if {[test_assurance] ne "stress"} {
324
+ test_skip "the tests after the first sections need -assurance stress"
325
+}
319326
320327
###############################################################################
321328
# test-escaped-arg quotes each argument for the shell, shows the command
322329
# line it made, and runs "fossil test-echo" with it, which prints the
323330
# argument as it arrived. With --hex the argument is given as hexadecimal
@@ -364,22 +371,23 @@
364371
mixed 61c3a962e282ac63 {'a<c3a9>b<e282ac>c'} {'a<c3a9>b<e282ac>c'}
365372
two-byte-quote c3a927 {\<c3a9>\'} {\<c3a9>\'}
366373
dash-two-byte 2dc3a9 {'./-<c3a9>'} {'-<c3a9>'}
367374
} {
368375
set blobArg [blob_bytes $blobArgHex]
369
- foreach {blobKind blobFlag blobQuoted} [list file 1 $blobFile other 0 $blobOther] {
376
+ foreach {blobKind blobFlag blobQuoted} \
377
+ [list file 1 $blobFile other 0 $blobOther] {
370378
while {[regexp {<([0-9a-f]+)>} $blobQuoted -> blobPart]} {
371379
regsub {<[0-9a-f]+>} $blobQuoted [blob_bytes $blobPart] blobQuoted
372380
}
373381
set blobArrives $blobArg
374382
if {$blobFlag && [string index $blobArg 0] eq "-"} {
375383
set blobArrives ./$blobArg
376384
}
377385
blob_escaped $blobFlag $blobArgHex
378386
test blob-escaped-$blobName-$blobKind {$CODE == 0 &&
379
- [string first " test-echo $blobQuoted\n" $RESULT] >= 0 &&
380
- [string first "argv\[2\] = \[$blobArrives\]\n" $RESULT] >= 0}
387
+ [holds_strings $RESULT [list " test-echo $blobQuoted\n" \
388
+ "argv\[2\] = \[$blobArrives\]\n"]]}
381389
}
382390
}
383391
}
384392
385393
# An argument that holds a control character, a byte that can only
@@ -414,12 +422,11 @@
414422
late-control 616263202701 "ascii 0x01"
415423
} {
416424
foreach blobFlag {1 0} {
417425
blob_escaped $blobFlag $blobArgHex
418426
test blob-escaped-refused-$blobName-$blobFlag {$CODE == 1 &&
419
- [string first $blobWhy $RESULT] >= 0 &&
420
- [string first "argv\[" $RESULT] < 0}
427
+ [holds_strings $RESULT [list $blobWhy "!argv\["]]}
421428
}
422429
}
423430
424431
if {$::tcl_platform(platform) eq "unix"} {
425432
# Several arguments make several command lines, numbered by their place
@@ -427,13 +434,12 @@
427434
# kinds of argument. A --filename-args that ends the command line is
428435
# skipped.
429436
fossil_raw test-escaped-arg -a --filename-args no -b --filename-args yes -c \
430437
--filename-args
431438
test blob-escaped-several {$CODE == 0 &&
432
- [string first "argv\[2\] = \[./-a\]" $RESULT] >= 0 &&
433
- [string first "argv\[2\] = \[-b\]" $RESULT] >= 0 &&
434
- [string first "argv\[2\] = \[./-c\]" $RESULT] >= 0 &&
439
+ [holds_strings $RESULT [list "argv\[2\] = \[./-a\]" \
440
+ "argv\[2\] = \[-b\]" "argv\[2\] = \[./-c\]"]] &&
435441
[regexp -line {^ 2 \[-a\]: } $RESULT] &&
436442
[regexp -line {^ 5 \[-b\]: } $RESULT] &&
437443
[regexp -line {^ 8 \[-c\]: } $RESULT] &&
438444
[regexp -all {argv\[2\]} $RESULT] == 3}
439445
@@ -444,12 +450,12 @@
444450
test blob-escaped-bare$blobOption {$CODE == 0 &&
445451
[string first "argv\[2\] = \[./$blobOption\]" $RESULT] >= 0}
446452
}
447453
fossil_raw test-escaped-arg --compare 61
448454
test blob-escaped-bare--compare {$CODE == 0 &&
449
- [string first "argv\[2\] = \[./--compare\]" $RESULT] >= 0 &&
450
- [string first "argv\[2\] = \[61\]" $RESULT] >= 0}
455
+ [holds_strings $RESULT [list "argv\[2\] = \[./--compare\]" \
456
+ "argv\[2\] = \[61\]"]]}
451457
}
452458
453459
# --hex takes up to 196 digits.
454460
set blobDigits [string repeat 41 98]
455461
fossil_raw test-escaped-arg --hex $blobDigits
@@ -463,11 +469,12 @@
463469
# HEX stands for. A "./" before a TEXT whose bytes begin with "-" is not
464470
# counted.
465471
set blobDot [expr {$::tcl_platform(platform) eq "windows" ? ".\\" : "./"}]
466472
foreach {blobName blobHex blobText blobCode blobSays} {
467473
same 616263 abc 0 {}
468
- differs 616263 abd 1 "argument disagree: \"abc\" (616263) versus \"abd\""
474
+ differs 616263 abd 1
475
+ "argument disagree: \"abc\" (616263) versus \"abd\""
469476
shorter 616263 ab 1 "argument disagree"
470477
dash-prefixed 2d61 ./-a 0 {}
471478
dash-bare 2d61 -a 1 "filename argument \"-a\" begins with \"-\""
472479
dot-slash-kept 61 ./a 1 "argument disagree: \"a\" (61)"
473480
dash-dot-only 2d61 .-a 1 "argument disagree"
@@ -513,15 +520,19 @@
513520
return 610d62 {"a\rb"} {"a\rb"}
514521
tab 610962 {"a\tb"} {"a<09>b"}
515522
backspace 610862 {"a\bb"} {"a<08>b"}
516523
formfeed 610c62 {"a\fb"} {"a<0c>b"}
517524
ctl-01 0161 {"\u0001a"} {"<01>a"}
518
- ctl-02-07 020304050607 {"\u0002\u0003\u0004\u0005\u0006\u0007"} {"<020304050607>"}
525
+ ctl-02-07 020304050607 {"\u0002\u0003\u0004\u0005\u0006\u0007"}
526
+ {"<020304050607>"}
519527
ctl-0b 0b {"\u000b"} {"<0b>"}
520528
ctl-0e-0f 0e0f {"\u000e\u000f"} {"<0e0f>"}
521
- ctl-10-19 10111213141516171819 {"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019"} {"<10111213141516171819>"}
522
- ctl-1a-1f 1a1b1c1d1e1f {"\u001a\u001b\u001c\u001d\u001e\u001f"} {"<1a1b1c1d1e1f>"}
529
+ ctl-10-19 10111213141516171819
530
+ {"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019"}
531
+ {"<10111213141516171819>"}
532
+ ctl-1a-1f 1a1b1c1d1e1f {"\u001a\u001b\u001c\u001d\u001e\u001f"}
533
+ {"<1a1b1c1d1e1f>"}
523534
delete 7f {"<7f>"} {"<7f>"}
524535
two-byte c3a9 {"<c3a9>"} {"<c3a9>"}
525536
empty {} {""} {""}
526537
} {
527538
foreach blobVar {blobJson blobTcl} {
@@ -546,19 +557,18 @@
546557
test blob-tcl-literal-filenames {$CODE == 0 &&
547558
[string first {FILE "lit \[n\]\$.1" "lit \[n\]\$.2"} $RESULT] >= 0}
548559
549560
# In a checkout "diff --tcl" prints the same literals without collecting
550561
# them first.
551
-write_file lit-checkout.txt "first\n"
552
-fossil add lit-checkout.txt
553
-fossil commit -m "lit checkout" --no-warnings lit-checkout.txt
562
+commit_file lit-checkout.txt "first\n" "lit checkout" --no-warnings \
563
+ lit-checkout.txt
554564
write_file lit-checkout.txt "\[second\] \$x\n"
555565
fossil_raw diff --tcl lit-checkout.txt
556566
test blob-tcl-literal-checkout {$CODE == 0 &&
557
- [string first "FILE \"lit-checkout.txt\" \"lit-checkout.txt\"\n" \
558
- $RESULT] >= 0 &&
559
- [string first {EDIT "" "first" "\[second\] \$x"} $RESULT] >= 0}
567
+ [holds_strings $RESULT [list \
568
+ "FILE \"lit-checkout.txt\" \"lit-checkout.txt\"\n" \
569
+ {EDIT "" "first" "\[second\] \$x"}]]}
560570
fossil revert lit-checkout.txt
561571
562572
# "diff --webpage" without --side-by-side builds four columns at once:
563573
# the line numbers of each file, the marks, and the text.
564574
write_file web.1 "one\ntwo\nthree\n"
@@ -573,13 +583,11 @@
573583
# or --convert-eol-windows it gives the content the line ends of that
574584
# system first; with --convert-eol-inherit it gives it the line ends of
575585
# the version before. Each row: the option, the content before, the
576586
# content given, and the content that must be checked in.
577587
578
-write_file eol.txt "start\n"
579
-fossil add eol.txt
580
-fossil commit -m "eol start" --no-warnings
588
+commit_file eol.txt "start\n" "eol start" --no-warnings
581589
582590
# Check in eol.txt with the content $before, then with $given and the
583591
# option $option. Returns the content of eol.txt in the last check-in.
584592
proc blob_eol {before given option} {
585593
global RESULT
@@ -605,18 +613,19 @@
605613
"x\ny\nz\n"
606614
inherit-windows --convert-eol-inherit "p\r\nq\r\n" "x\ny\nz\n"
607615
"x\r\ny\r\nz\r\n"
608616
inherit-same --convert-eol-inherit "p\nq\n" "x\ny\n" "x\ny\n"
609617
} {
610
- test blob-eol-$blobName \
611
- {[blob_eol $blobBefore $blobGiven $blobOption] eq $blobStored}
618
+ test_eq blob-eol-$blobName [blob_eol $blobBefore $blobGiven $blobOption] \
619
+ $blobStored
612620
}
613621
614622
# Content with a zero byte after its lines keeps the bytes that follow
615623
# the zero byte.
616
-test blob-eol-to-unix-nul {[blob_eol "s\n" "x\r\ny\r\n\x00tail\r\nmore\r\n" \
617
- --convert-eol-unix] eq "x\ny\n\x00tail\nmore\n"} knownBug
624
+test_eq blob-eol-to-unix-nul [blob_eol "s\n" "x\r\ny\r\n\x00tail\r\nmore\r\n" \
625
+ --convert-eol-unix] \
626
+ "x\ny\n\x00tail\nmore\n" knownBug
618627
619628
# test-ci-mini leaves the checkout as it was.
620629
fossil revert eol.txt
621630
fossil update tip
622631
@@ -637,11 +646,12 @@
637646
foreach {blobName blobBefore blobAfter} {
638647
utf16-le fffe6800e9000d000a00ac200a00 efbbbf68c3a90ae282ac0a
639648
utf16-be feff006800e9000d000a20ac000a efbbbf68c3a90ae282ac0a
640649
utf16-le-short fffe6800 efbbbf68
641650
utf16-be-short feff0068 efbbbf68
642
- cp1252 63e920802081209920a020ff0d0a61 63c3a920e282ac20c28120e284a220c2a020c3bf0a61
651
+ cp1252 63e920802081209920a020ff0d0a61
652
+ 63c3a920e282ac20c28120e284a220c2a020c3bf0a61
643653
cp1252-9f 9f8a0a c5b8c5a00a
644654
cp1252-plain e90a c3a90a
645655
cp1252-long __long__ __long__
646656
} {
647657
if {$blobBefore eq "__long__"} {
@@ -664,13 +674,12 @@
664674
# byte-order mark is taken off, UTF-16 with a mark is converted, and
665675
# bytes that are not UTF-8 are read as code page 1252. Each row: the
666676
# bytes of the file and the bytes of the comment that must be stored,
667677
# both in hexadecimal.
668678
669
-write_file comment-subject.txt "0\n"
670
-fossil add comment-subject.txt
671
-fossil commit -m "comment subject" --no-warnings comment-subject.txt
679
+commit_file comment-subject.txt "0\n" "comment subject" --no-warnings \
680
+ comment-subject.txt
672681
foreach {blobName blobFile blobComment} {
673682
ascii 706c61696e 706c61696e
674683
utf8 636166c3a920e282ac 636166c3a920e282ac
675684
utf8-bom efbbbf636166c3a9 636166c3a9
676685
utf16-le fffe63006100e900 6361c3a9
@@ -683,18 +692,17 @@
683692
write_file comment-subject.txt "$blobName\n"
684693
fossil commit -M comment-$blobName.txt --no-warnings \
685694
--no-verify-comment comment-subject.txt
686695
fossil sql "SELECT lower(hex(comment)) FROM event
687696
ORDER BY mtime DESC, objid DESC LIMIT 1"
688
- test blob-comment-file-$blobName {[string trim $RESULT] eq $blobComment}
697
+ test_eq blob-comment-file-$blobName [string trim $RESULT] $blobComment
689698
}
690699
691700
# A comment typed in an editor is converted in the same way, after it
692701
# is cut at a row of ten "#". The editor here is a script that writes
693702
# the given bytes as the comment.
694
-fossil settings editor "[info nameofexecutable]\
695
- [file join $::testfiledir fake-editor.tcl]"
703
+fossil settings editor [fake_editor_command]
696704
foreach {blobName blobTyped blobComment} {
697705
utf8 636166c3a90a 636166c3a9
698706
cp1252 636166e920800a 636166c3a920e282ac
699707
cp1252-cut 63e90a232323232323232323232063757420800a 63c3a9
700708
utf8-cut 63c3a90a232323232323232323232063757420800a 63c3a9
@@ -703,23 +711,21 @@
703711
set ::env(FAKE_EDITOR_SCRIPT) [list set data [blob_bytes $blobTyped]]
704712
fossil commit --no-warnings --no-verify-comment comment-subject.txt
705713
unset ::env(FAKE_EDITOR_SCRIPT)
706714
fossil sql "SELECT lower(hex(comment)) FROM event
707715
ORDER BY mtime DESC, objid DESC LIMIT 1"
708
- test blob-comment-editor-$blobName {[string trim $RESULT] eq $blobComment}
716
+ test_eq blob-comment-editor-$blobName [string trim $RESULT] $blobComment
709717
}
710718
fossil unset editor
711719
712720
###############################################################################
713721
# A diff does not show a byte-order mark, and reads UTF-16 text that has
714722
# one. Each row: the bytes of the second file, in hexadecimal. The first
715723
# file is "one" and "two" on two lines, and the diff must say that "2"
716724
# replaces the second line.
717725
718
-write_file bom-plain.txt "one\ntwo\n"
719
-fossil add bom-plain.txt
720
-fossil commit -m "bom plain" --no-warnings bom-plain.txt
726
+commit_file bom-plain.txt "one\ntwo\n" "bom plain" --no-warnings bom-plain.txt
721727
foreach {blobName blobSecond} {
722728
none 6f6e650a320a
723729
utf8 efbbbf6f6e650a320a
724730
utf16-le fffe6f006e0065000a0032000a00
725731
utf16-be feff006f006e0065000a0032000a
@@ -755,18 +761,12 @@
755761
###############################################################################
756762
# Web pages. The page PATH of the repository of this checkout, asked for
757763
# by a local administrator with the header lines in HEADERS.
758764
759765
proc blob_page {path {headers {}}} {
760
- set text "GET $path HTTP/1.1\r\nHost: x\r\n"
761
- foreach line $headers { append text $line "\r\n" }
762
- write_file page-request.txt "$text\r\n"
763
- file delete page-reply.txt
764
- fossil_raw http .rep.fossil --in page-request.txt --out page-reply.txt \
765
- --ipaddr 127.0.0.1 --localauth
766
- if {[file exists page-reply.txt]} { return [read_file page-reply.txt] }
767
- return ""
766
+ return [fossil_http .rep.fossil [request_get $path $headers] \
767
+ --ipaddr 127.0.0.1 --localauth]
768768
}
769769
770770
# /test-bgcolor takes a colour as "#" and three or six hexadecimal
771771
# digits in lower case. Each row: what follows the "#" and whether it is
772772
# a colour.
@@ -824,11 +824,12 @@
824824
test blob-xdigit-cookie-name-g {$CODE == 0 &&
825825
[string first "This cookie was not generated by Fossil" $blobReply] >= 0}
826826
827827
# A request that announces more content than a buffer may hold is ended
828828
# with "out of memory" before any of the content is read.
829
-write_file page-request.txt "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type:\
829
+write_file page-request.txt \
830
+ "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type:\
830831
text/plain\r\nContent-Length: 2147483647\r\n\r\nabc"
831832
file delete page-reply.txt
832833
fossil_raw -seconds 60 http .rep.fossil --in page-request.txt \
833834
--out page-reply.txt --ipaddr 127.0.0.1 --localauth
834835
test blob-too-large-request {$CODE == 1 && $RESULT eq "out of memory\n" &&
@@ -887,11 +888,10 @@
887888
--clean "" --ignore "*" --keep "" clean-1.tmp clean-2.tmp
888889
set left [lsort [glob -nocomplain clean-*.tmp]]
889890
file delete clean-1.tmp clean-2.tmp
890891
return $left
891892
}
892
-fossil_raw clean --help
893893
foreach {blobName blobAnswer blobLeft} {
894894
lower-n n {clean-1.tmp clean-2.tmp}
895895
upper-n N {clean-1.tmp clean-2.tmp}
896896
word-no no {clean-1.tmp clean-2.tmp}
897897
lower-y y {}
@@ -914,12 +914,12 @@
914914
empty {}
915915
brace \{
916916
tilde ~
917917
letter-q q
918918
} {
919
- test blob-clean-prompt-$blobName \
920
- {[blob_clean $blobAnswer] eq {clean-1.tmp clean-2.tmp}} knownBug
919
+ test_eq blob-clean-prompt-$blobName [blob_clean $blobAnswer] \
920
+ {clean-1.tmp clean-2.tmp} knownBug
921921
}
922922
923923
###############################################################################
924924
# A comment is broken into lines at a space, or after a hyphen that
925925
# follows a letter. Each row: the character before the hyphen in
@@ -973,12 +973,13 @@
973973
[regexp {<<<<<<<[^\n]*\nONE\n#######} $blobMerged] &&
974974
[regexp {=======[^\n]*\nTWO\n>>>>>>>} $blobMerged]}
975975
976976
# One side changes a line and the other adds a line after the last one,
977977
# which had no line end. The added line is a line of its own.
978
-test blob-merge-no-final-newline-append \
979
- {[blob_merge "a\nb\nc" "a\nB\nc" "a\nb\nc\nd"] eq "a\nB\nc\nd"} knownBug
978
+test_eq blob-merge-no-final-newline-append \
979
+ [blob_merge "a\nb\nc" "a\nB\nc" "a\nb\nc\nd"] \
980
+ "a\nB\nc\nd" knownBug
980981
981982
###############################################################################
982983
# With the allow-symlinks setting on, a symbolic link is checked in as the
983984
# name it points to. With the setting off, the file it points to is
984985
# checked in.
985986
--- test/blob.test
+++ test/blob.test
@@ -7,15 +7,12 @@
7 # through other commands: the string literals of "diff --json" and
8 # "diff --tcl", and the conversions that a commit offers for a file in
9 # another encoding.
10 #
11
12 # These tests run only in a long pass: -assurance stress.
13 if {[test_assurance] ne "stress"} {
14 test_skip "runs only with -assurance stress"
15 }
16
17 require_no_open_checkout
18
19 test_setup
20
21 # The bytes that the hexadecimal digits in $hex stand for.
@@ -33,11 +30,11 @@
33
34 ###############################################################################
35 # test-isspace checks fossil_isspace() against every byte value.
36
37 fossil test-isspace
38 test blob-isspace-1 {[string trim $RESULT] eq "All 256 characters OK"}
39
40 ###############################################################################
41 # test-atoi prints, for each argument, whether it is a non-negative
42 # integer of 32 bits and of 64 bits, and the value. Each row: the
43 # argument, then the two answers and values that must be printed.
@@ -147,13 +144,15 @@
147 [string length [lindex [split $RESULT \n] 0]] == $blobWide}
148 }
149
150 # The command takes exactly one file.
151 fossil_raw test-strip-comment-lines
152 test blob-strip-usage-none {$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
 
153 fossil_raw test-strip-comment-lines strip-sbs.txt strip-sbs.txt
154 test blob-strip-usage-two {$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
 
155
156 ###############################################################################
157 # Reading a file. A file that is not there and a file that cannot be
158 # opened are errors that name the file.
159
@@ -268,13 +267,16 @@
268 # Each of the three commands wants an exact number of file names.
269 foreach {blobName blobCommand blobUsage} {
270 compress-0 {test-compress} "INPUTFILE OUTPUTFILE"
271 compress-1 {test-compress z-text.in} "INPUTFILE OUTPUTFILE"
272 compress-3 {test-compress z-text.in a b} "INPUTFILE OUTPUTFILE"
273 compress2-0 {test-compress-2} "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
274 compress2-2 {test-compress-2 z-text.in a} "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
275 compress2-4 {test-compress-2 z-text.in a b c} "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
 
 
 
276 uncompress-0 {test-uncompress} "INPUTFILE OUTPUTFILE"
277 uncompress-1 {test-uncompress z-text.z} "INPUTFILE OUTPUTFILE"
278 uncompress-3 {test-uncompress z-text.z a b} "INPUTFILE OUTPUTFILE"
279 } {
280 fossil_raw {*}$blobCommand
@@ -289,11 +291,12 @@
289 # that cannot be made is an error that names it.
290
291 fossil_raw test-compress z-text.in -
292 test blob-write-stdout-dash {$CODE == 0 && $RESULT eq [read_file z-text.z]}
293 fossil_raw test-compress z-text.in {}
294 test blob-write-stdout-empty-name {$CODE == 0 && $RESULT eq [read_file z-text.z]}
 
295 fossil_raw test-uncompress z-empty.z -
296 test blob-write-stdout-nothing {$CODE == 0 && $RESULT eq ""}
297 fossil_raw test-uncompress z-empty.z write-empty.out
298 test blob-write-empty-file {$CODE == 0 && [file exists write-empty.out] &&
299 [file size write-empty.out] == 0}
@@ -314,10 +317,14 @@
314 test blob-write-closed-directory {$CODE == 1 &&
315 [string match "*unable to open file \"write-closed/out.z\" for writing*" \
316 $RESULT]}
317 file attributes write-closed -permissions 0755
318 }
 
 
 
 
319
320 ###############################################################################
321 # test-escaped-arg quotes each argument for the shell, shows the command
322 # line it made, and runs "fossil test-echo" with it, which prints the
323 # argument as it arrived. With --hex the argument is given as hexadecimal
@@ -364,22 +371,23 @@
364 mixed 61c3a962e282ac63 {'a<c3a9>b<e282ac>c'} {'a<c3a9>b<e282ac>c'}
365 two-byte-quote c3a927 {\<c3a9>\'} {\<c3a9>\'}
366 dash-two-byte 2dc3a9 {'./-<c3a9>'} {'-<c3a9>'}
367 } {
368 set blobArg [blob_bytes $blobArgHex]
369 foreach {blobKind blobFlag blobQuoted} [list file 1 $blobFile other 0 $blobOther] {
 
370 while {[regexp {<([0-9a-f]+)>} $blobQuoted -> blobPart]} {
371 regsub {<[0-9a-f]+>} $blobQuoted [blob_bytes $blobPart] blobQuoted
372 }
373 set blobArrives $blobArg
374 if {$blobFlag && [string index $blobArg 0] eq "-"} {
375 set blobArrives ./$blobArg
376 }
377 blob_escaped $blobFlag $blobArgHex
378 test blob-escaped-$blobName-$blobKind {$CODE == 0 &&
379 [string first " test-echo $blobQuoted\n" $RESULT] >= 0 &&
380 [string first "argv\[2\] = \[$blobArrives\]\n" $RESULT] >= 0}
381 }
382 }
383 }
384
385 # An argument that holds a control character, a byte that can only
@@ -414,12 +422,11 @@
414 late-control 616263202701 "ascii 0x01"
415 } {
416 foreach blobFlag {1 0} {
417 blob_escaped $blobFlag $blobArgHex
418 test blob-escaped-refused-$blobName-$blobFlag {$CODE == 1 &&
419 [string first $blobWhy $RESULT] >= 0 &&
420 [string first "argv\[" $RESULT] < 0}
421 }
422 }
423
424 if {$::tcl_platform(platform) eq "unix"} {
425 # Several arguments make several command lines, numbered by their place
@@ -427,13 +434,12 @@
427 # kinds of argument. A --filename-args that ends the command line is
428 # skipped.
429 fossil_raw test-escaped-arg -a --filename-args no -b --filename-args yes -c \
430 --filename-args
431 test blob-escaped-several {$CODE == 0 &&
432 [string first "argv\[2\] = \[./-a\]" $RESULT] >= 0 &&
433 [string first "argv\[2\] = \[-b\]" $RESULT] >= 0 &&
434 [string first "argv\[2\] = \[./-c\]" $RESULT] >= 0 &&
435 [regexp -line {^ 2 \[-a\]: } $RESULT] &&
436 [regexp -line {^ 5 \[-b\]: } $RESULT] &&
437 [regexp -line {^ 8 \[-c\]: } $RESULT] &&
438 [regexp -all {argv\[2\]} $RESULT] == 3}
439
@@ -444,12 +450,12 @@
444 test blob-escaped-bare$blobOption {$CODE == 0 &&
445 [string first "argv\[2\] = \[./$blobOption\]" $RESULT] >= 0}
446 }
447 fossil_raw test-escaped-arg --compare 61
448 test blob-escaped-bare--compare {$CODE == 0 &&
449 [string first "argv\[2\] = \[./--compare\]" $RESULT] >= 0 &&
450 [string first "argv\[2\] = \[61\]" $RESULT] >= 0}
451 }
452
453 # --hex takes up to 196 digits.
454 set blobDigits [string repeat 41 98]
455 fossil_raw test-escaped-arg --hex $blobDigits
@@ -463,11 +469,12 @@
463 # HEX stands for. A "./" before a TEXT whose bytes begin with "-" is not
464 # counted.
465 set blobDot [expr {$::tcl_platform(platform) eq "windows" ? ".\\" : "./"}]
466 foreach {blobName blobHex blobText blobCode blobSays} {
467 same 616263 abc 0 {}
468 differs 616263 abd 1 "argument disagree: \"abc\" (616263) versus \"abd\""
 
469 shorter 616263 ab 1 "argument disagree"
470 dash-prefixed 2d61 ./-a 0 {}
471 dash-bare 2d61 -a 1 "filename argument \"-a\" begins with \"-\""
472 dot-slash-kept 61 ./a 1 "argument disagree: \"a\" (61)"
473 dash-dot-only 2d61 .-a 1 "argument disagree"
@@ -513,15 +520,19 @@
513 return 610d62 {"a\rb"} {"a\rb"}
514 tab 610962 {"a\tb"} {"a<09>b"}
515 backspace 610862 {"a\bb"} {"a<08>b"}
516 formfeed 610c62 {"a\fb"} {"a<0c>b"}
517 ctl-01 0161 {"\u0001a"} {"<01>a"}
518 ctl-02-07 020304050607 {"\u0002\u0003\u0004\u0005\u0006\u0007"} {"<020304050607>"}
 
519 ctl-0b 0b {"\u000b"} {"<0b>"}
520 ctl-0e-0f 0e0f {"\u000e\u000f"} {"<0e0f>"}
521 ctl-10-19 10111213141516171819 {"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019"} {"<10111213141516171819>"}
522 ctl-1a-1f 1a1b1c1d1e1f {"\u001a\u001b\u001c\u001d\u001e\u001f"} {"<1a1b1c1d1e1f>"}
 
 
 
523 delete 7f {"<7f>"} {"<7f>"}
524 two-byte c3a9 {"<c3a9>"} {"<c3a9>"}
525 empty {} {""} {""}
526 } {
527 foreach blobVar {blobJson blobTcl} {
@@ -546,19 +557,18 @@
546 test blob-tcl-literal-filenames {$CODE == 0 &&
547 [string first {FILE "lit \[n\]\$.1" "lit \[n\]\$.2"} $RESULT] >= 0}
548
549 # In a checkout "diff --tcl" prints the same literals without collecting
550 # them first.
551 write_file lit-checkout.txt "first\n"
552 fossil add lit-checkout.txt
553 fossil commit -m "lit checkout" --no-warnings lit-checkout.txt
554 write_file lit-checkout.txt "\[second\] \$x\n"
555 fossil_raw diff --tcl lit-checkout.txt
556 test blob-tcl-literal-checkout {$CODE == 0 &&
557 [string first "FILE \"lit-checkout.txt\" \"lit-checkout.txt\"\n" \
558 $RESULT] >= 0 &&
559 [string first {EDIT "" "first" "\[second\] \$x"} $RESULT] >= 0}
560 fossil revert lit-checkout.txt
561
562 # "diff --webpage" without --side-by-side builds four columns at once:
563 # the line numbers of each file, the marks, and the text.
564 write_file web.1 "one\ntwo\nthree\n"
@@ -573,13 +583,11 @@
573 # or --convert-eol-windows it gives the content the line ends of that
574 # system first; with --convert-eol-inherit it gives it the line ends of
575 # the version before. Each row: the option, the content before, the
576 # content given, and the content that must be checked in.
577
578 write_file eol.txt "start\n"
579 fossil add eol.txt
580 fossil commit -m "eol start" --no-warnings
581
582 # Check in eol.txt with the content $before, then with $given and the
583 # option $option. Returns the content of eol.txt in the last check-in.
584 proc blob_eol {before given option} {
585 global RESULT
@@ -605,18 +613,19 @@
605 "x\ny\nz\n"
606 inherit-windows --convert-eol-inherit "p\r\nq\r\n" "x\ny\nz\n"
607 "x\r\ny\r\nz\r\n"
608 inherit-same --convert-eol-inherit "p\nq\n" "x\ny\n" "x\ny\n"
609 } {
610 test blob-eol-$blobName \
611 {[blob_eol $blobBefore $blobGiven $blobOption] eq $blobStored}
612 }
613
614 # Content with a zero byte after its lines keeps the bytes that follow
615 # the zero byte.
616 test blob-eol-to-unix-nul {[blob_eol "s\n" "x\r\ny\r\n\x00tail\r\nmore\r\n" \
617 --convert-eol-unix] eq "x\ny\n\x00tail\nmore\n"} knownBug
 
618
619 # test-ci-mini leaves the checkout as it was.
620 fossil revert eol.txt
621 fossil update tip
622
@@ -637,11 +646,12 @@
637 foreach {blobName blobBefore blobAfter} {
638 utf16-le fffe6800e9000d000a00ac200a00 efbbbf68c3a90ae282ac0a
639 utf16-be feff006800e9000d000a20ac000a efbbbf68c3a90ae282ac0a
640 utf16-le-short fffe6800 efbbbf68
641 utf16-be-short feff0068 efbbbf68
642 cp1252 63e920802081209920a020ff0d0a61 63c3a920e282ac20c28120e284a220c2a020c3bf0a61
 
643 cp1252-9f 9f8a0a c5b8c5a00a
644 cp1252-plain e90a c3a90a
645 cp1252-long __long__ __long__
646 } {
647 if {$blobBefore eq "__long__"} {
@@ -664,13 +674,12 @@
664 # byte-order mark is taken off, UTF-16 with a mark is converted, and
665 # bytes that are not UTF-8 are read as code page 1252. Each row: the
666 # bytes of the file and the bytes of the comment that must be stored,
667 # both in hexadecimal.
668
669 write_file comment-subject.txt "0\n"
670 fossil add comment-subject.txt
671 fossil commit -m "comment subject" --no-warnings comment-subject.txt
672 foreach {blobName blobFile blobComment} {
673 ascii 706c61696e 706c61696e
674 utf8 636166c3a920e282ac 636166c3a920e282ac
675 utf8-bom efbbbf636166c3a9 636166c3a9
676 utf16-le fffe63006100e900 6361c3a9
@@ -683,18 +692,17 @@
683 write_file comment-subject.txt "$blobName\n"
684 fossil commit -M comment-$blobName.txt --no-warnings \
685 --no-verify-comment comment-subject.txt
686 fossil sql "SELECT lower(hex(comment)) FROM event
687 ORDER BY mtime DESC, objid DESC LIMIT 1"
688 test blob-comment-file-$blobName {[string trim $RESULT] eq $blobComment}
689 }
690
691 # A comment typed in an editor is converted in the same way, after it
692 # is cut at a row of ten "#". The editor here is a script that writes
693 # the given bytes as the comment.
694 fossil settings editor "[info nameofexecutable]\
695 [file join $::testfiledir fake-editor.tcl]"
696 foreach {blobName blobTyped blobComment} {
697 utf8 636166c3a90a 636166c3a9
698 cp1252 636166e920800a 636166c3a920e282ac
699 cp1252-cut 63e90a232323232323232323232063757420800a 63c3a9
700 utf8-cut 63c3a90a232323232323232323232063757420800a 63c3a9
@@ -703,23 +711,21 @@
703 set ::env(FAKE_EDITOR_SCRIPT) [list set data [blob_bytes $blobTyped]]
704 fossil commit --no-warnings --no-verify-comment comment-subject.txt
705 unset ::env(FAKE_EDITOR_SCRIPT)
706 fossil sql "SELECT lower(hex(comment)) FROM event
707 ORDER BY mtime DESC, objid DESC LIMIT 1"
708 test blob-comment-editor-$blobName {[string trim $RESULT] eq $blobComment}
709 }
710 fossil unset editor
711
712 ###############################################################################
713 # A diff does not show a byte-order mark, and reads UTF-16 text that has
714 # one. Each row: the bytes of the second file, in hexadecimal. The first
715 # file is "one" and "two" on two lines, and the diff must say that "2"
716 # replaces the second line.
717
718 write_file bom-plain.txt "one\ntwo\n"
719 fossil add bom-plain.txt
720 fossil commit -m "bom plain" --no-warnings bom-plain.txt
721 foreach {blobName blobSecond} {
722 none 6f6e650a320a
723 utf8 efbbbf6f6e650a320a
724 utf16-le fffe6f006e0065000a0032000a00
725 utf16-be feff006f006e0065000a0032000a
@@ -755,18 +761,12 @@
755 ###############################################################################
756 # Web pages. The page PATH of the repository of this checkout, asked for
757 # by a local administrator with the header lines in HEADERS.
758
759 proc blob_page {path {headers {}}} {
760 set text "GET $path HTTP/1.1\r\nHost: x\r\n"
761 foreach line $headers { append text $line "\r\n" }
762 write_file page-request.txt "$text\r\n"
763 file delete page-reply.txt
764 fossil_raw http .rep.fossil --in page-request.txt --out page-reply.txt \
765 --ipaddr 127.0.0.1 --localauth
766 if {[file exists page-reply.txt]} { return [read_file page-reply.txt] }
767 return ""
768 }
769
770 # /test-bgcolor takes a colour as "#" and three or six hexadecimal
771 # digits in lower case. Each row: what follows the "#" and whether it is
772 # a colour.
@@ -824,11 +824,12 @@
824 test blob-xdigit-cookie-name-g {$CODE == 0 &&
825 [string first "This cookie was not generated by Fossil" $blobReply] >= 0}
826
827 # A request that announces more content than a buffer may hold is ended
828 # with "out of memory" before any of the content is read.
829 write_file page-request.txt "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type:\
 
830 text/plain\r\nContent-Length: 2147483647\r\n\r\nabc"
831 file delete page-reply.txt
832 fossil_raw -seconds 60 http .rep.fossil --in page-request.txt \
833 --out page-reply.txt --ipaddr 127.0.0.1 --localauth
834 test blob-too-large-request {$CODE == 1 && $RESULT eq "out of memory\n" &&
@@ -887,11 +888,10 @@
887 --clean "" --ignore "*" --keep "" clean-1.tmp clean-2.tmp
888 set left [lsort [glob -nocomplain clean-*.tmp]]
889 file delete clean-1.tmp clean-2.tmp
890 return $left
891 }
892 fossil_raw clean --help
893 foreach {blobName blobAnswer blobLeft} {
894 lower-n n {clean-1.tmp clean-2.tmp}
895 upper-n N {clean-1.tmp clean-2.tmp}
896 word-no no {clean-1.tmp clean-2.tmp}
897 lower-y y {}
@@ -914,12 +914,12 @@
914 empty {}
915 brace \{
916 tilde ~
917 letter-q q
918 } {
919 test blob-clean-prompt-$blobName \
920 {[blob_clean $blobAnswer] eq {clean-1.tmp clean-2.tmp}} knownBug
921 }
922
923 ###############################################################################
924 # A comment is broken into lines at a space, or after a hyphen that
925 # follows a letter. Each row: the character before the hyphen in
@@ -973,12 +973,13 @@
973 [regexp {<<<<<<<[^\n]*\nONE\n#######} $blobMerged] &&
974 [regexp {=======[^\n]*\nTWO\n>>>>>>>} $blobMerged]}
975
976 # One side changes a line and the other adds a line after the last one,
977 # which had no line end. The added line is a line of its own.
978 test blob-merge-no-final-newline-append \
979 {[blob_merge "a\nb\nc" "a\nB\nc" "a\nb\nc\nd"] eq "a\nB\nc\nd"} knownBug
 
980
981 ###############################################################################
982 # With the allow-symlinks setting on, a symbolic link is checked in as the
983 # name it points to. With the setting off, the file it points to is
984 # checked in.
985
--- test/blob.test
+++ test/blob.test
@@ -7,15 +7,12 @@
7 # through other commands: the string literals of "diff --json" and
8 # "diff --tcl", and the conversions that a commit offers for a file in
9 # another encoding.
10 #
11
12 # The first sections run at every level, and the rest need
13 # -assurance stress.
 
 
 
14 require_no_open_checkout
15
16 test_setup
17
18 # The bytes that the hexadecimal digits in $hex stand for.
@@ -33,11 +30,11 @@
30
31 ###############################################################################
32 # test-isspace checks fossil_isspace() against every byte value.
33
34 fossil test-isspace
35 test_eq blob-isspace-1 [string trim $RESULT] "All 256 characters OK"
36
37 ###############################################################################
38 # test-atoi prints, for each argument, whether it is a non-negative
39 # integer of 32 bits and of 64 bits, and the value. Each row: the
40 # argument, then the two answers and values that must be printed.
@@ -147,13 +144,15 @@
144 [string length [lindex [split $RESULT \n] 0]] == $blobWide}
145 }
146
147 # The command takes exactly one file.
148 fossil_raw test-strip-comment-lines
149 test blob-strip-usage-none \
150 {$CODE == 1 && [string match "Usage:*INPUTFILE*" $RESULT]}
151 fossil_raw test-strip-comment-lines strip-sbs.txt strip-sbs.txt
152 test blob-strip-usage-two {$CODE == 1 && [string match "Usage:*INPUTFILE*" \
153 $RESULT]}
154
155 ###############################################################################
156 # Reading a file. A file that is not there and a file that cannot be
157 # opened are errors that name the file.
158
@@ -268,13 +267,16 @@
267 # Each of the three commands wants an exact number of file names.
268 foreach {blobName blobCommand blobUsage} {
269 compress-0 {test-compress} "INPUTFILE OUTPUTFILE"
270 compress-1 {test-compress z-text.in} "INPUTFILE OUTPUTFILE"
271 compress-3 {test-compress z-text.in a b} "INPUTFILE OUTPUTFILE"
272 compress2-0 {test-compress-2}
273 "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
274 compress2-2 {test-compress-2 z-text.in a}
275 "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
276 compress2-4 {test-compress-2 z-text.in a b c}
277 "INPUTFILE1 INPUTFILE2 OUTPUTFILE"
278 uncompress-0 {test-uncompress} "INPUTFILE OUTPUTFILE"
279 uncompress-1 {test-uncompress z-text.z} "INPUTFILE OUTPUTFILE"
280 uncompress-3 {test-uncompress z-text.z a b} "INPUTFILE OUTPUTFILE"
281 } {
282 fossil_raw {*}$blobCommand
@@ -289,11 +291,12 @@
291 # that cannot be made is an error that names it.
292
293 fossil_raw test-compress z-text.in -
294 test blob-write-stdout-dash {$CODE == 0 && $RESULT eq [read_file z-text.z]}
295 fossil_raw test-compress z-text.in {}
296 test blob-write-stdout-empty-name \
297 {$CODE == 0 && $RESULT eq [read_file z-text.z]}
298 fossil_raw test-uncompress z-empty.z -
299 test blob-write-stdout-nothing {$CODE == 0 && $RESULT eq ""}
300 fossil_raw test-uncompress z-empty.z write-empty.out
301 test blob-write-empty-file {$CODE == 0 && [file exists write-empty.out] &&
302 [file size write-empty.out] == 0}
@@ -314,10 +317,14 @@
317 test blob-write-closed-directory {$CODE == 1 &&
318 [string match "*unable to open file \"write-closed/out.z\" for writing*" \
319 $RESULT]}
320 file attributes write-closed -permissions 0755
321 }
322
323 if {[test_assurance] ne "stress"} {
324 test_skip "the tests after the first sections need -assurance stress"
325 }
326
327 ###############################################################################
328 # test-escaped-arg quotes each argument for the shell, shows the command
329 # line it made, and runs "fossil test-echo" with it, which prints the
330 # argument as it arrived. With --hex the argument is given as hexadecimal
@@ -364,22 +371,23 @@
371 mixed 61c3a962e282ac63 {'a<c3a9>b<e282ac>c'} {'a<c3a9>b<e282ac>c'}
372 two-byte-quote c3a927 {\<c3a9>\'} {\<c3a9>\'}
373 dash-two-byte 2dc3a9 {'./-<c3a9>'} {'-<c3a9>'}
374 } {
375 set blobArg [blob_bytes $blobArgHex]
376 foreach {blobKind blobFlag blobQuoted} \
377 [list file 1 $blobFile other 0 $blobOther] {
378 while {[regexp {<([0-9a-f]+)>} $blobQuoted -> blobPart]} {
379 regsub {<[0-9a-f]+>} $blobQuoted [blob_bytes $blobPart] blobQuoted
380 }
381 set blobArrives $blobArg
382 if {$blobFlag && [string index $blobArg 0] eq "-"} {
383 set blobArrives ./$blobArg
384 }
385 blob_escaped $blobFlag $blobArgHex
386 test blob-escaped-$blobName-$blobKind {$CODE == 0 &&
387 [holds_strings $RESULT [list " test-echo $blobQuoted\n" \
388 "argv\[2\] = \[$blobArrives\]\n"]]}
389 }
390 }
391 }
392
393 # An argument that holds a control character, a byte that can only
@@ -414,12 +422,11 @@
422 late-control 616263202701 "ascii 0x01"
423 } {
424 foreach blobFlag {1 0} {
425 blob_escaped $blobFlag $blobArgHex
426 test blob-escaped-refused-$blobName-$blobFlag {$CODE == 1 &&
427 [holds_strings $RESULT [list $blobWhy "!argv\["]]}
 
428 }
429 }
430
431 if {$::tcl_platform(platform) eq "unix"} {
432 # Several arguments make several command lines, numbered by their place
@@ -427,13 +434,12 @@
434 # kinds of argument. A --filename-args that ends the command line is
435 # skipped.
436 fossil_raw test-escaped-arg -a --filename-args no -b --filename-args yes -c \
437 --filename-args
438 test blob-escaped-several {$CODE == 0 &&
439 [holds_strings $RESULT [list "argv\[2\] = \[./-a\]" \
440 "argv\[2\] = \[-b\]" "argv\[2\] = \[./-c\]"]] &&
 
441 [regexp -line {^ 2 \[-a\]: } $RESULT] &&
442 [regexp -line {^ 5 \[-b\]: } $RESULT] &&
443 [regexp -line {^ 8 \[-c\]: } $RESULT] &&
444 [regexp -all {argv\[2\]} $RESULT] == 3}
445
@@ -444,12 +450,12 @@
450 test blob-escaped-bare$blobOption {$CODE == 0 &&
451 [string first "argv\[2\] = \[./$blobOption\]" $RESULT] >= 0}
452 }
453 fossil_raw test-escaped-arg --compare 61
454 test blob-escaped-bare--compare {$CODE == 0 &&
455 [holds_strings $RESULT [list "argv\[2\] = \[./--compare\]" \
456 "argv\[2\] = \[61\]"]]}
457 }
458
459 # --hex takes up to 196 digits.
460 set blobDigits [string repeat 41 98]
461 fossil_raw test-escaped-arg --hex $blobDigits
@@ -463,11 +469,12 @@
469 # HEX stands for. A "./" before a TEXT whose bytes begin with "-" is not
470 # counted.
471 set blobDot [expr {$::tcl_platform(platform) eq "windows" ? ".\\" : "./"}]
472 foreach {blobName blobHex blobText blobCode blobSays} {
473 same 616263 abc 0 {}
474 differs 616263 abd 1
475 "argument disagree: \"abc\" (616263) versus \"abd\""
476 shorter 616263 ab 1 "argument disagree"
477 dash-prefixed 2d61 ./-a 0 {}
478 dash-bare 2d61 -a 1 "filename argument \"-a\" begins with \"-\""
479 dot-slash-kept 61 ./a 1 "argument disagree: \"a\" (61)"
480 dash-dot-only 2d61 .-a 1 "argument disagree"
@@ -513,15 +520,19 @@
520 return 610d62 {"a\rb"} {"a\rb"}
521 tab 610962 {"a\tb"} {"a<09>b"}
522 backspace 610862 {"a\bb"} {"a<08>b"}
523 formfeed 610c62 {"a\fb"} {"a<0c>b"}
524 ctl-01 0161 {"\u0001a"} {"<01>a"}
525 ctl-02-07 020304050607 {"\u0002\u0003\u0004\u0005\u0006\u0007"}
526 {"<020304050607>"}
527 ctl-0b 0b {"\u000b"} {"<0b>"}
528 ctl-0e-0f 0e0f {"\u000e\u000f"} {"<0e0f>"}
529 ctl-10-19 10111213141516171819
530 {"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019"}
531 {"<10111213141516171819>"}
532 ctl-1a-1f 1a1b1c1d1e1f {"\u001a\u001b\u001c\u001d\u001e\u001f"}
533 {"<1a1b1c1d1e1f>"}
534 delete 7f {"<7f>"} {"<7f>"}
535 two-byte c3a9 {"<c3a9>"} {"<c3a9>"}
536 empty {} {""} {""}
537 } {
538 foreach blobVar {blobJson blobTcl} {
@@ -546,19 +557,18 @@
557 test blob-tcl-literal-filenames {$CODE == 0 &&
558 [string first {FILE "lit \[n\]\$.1" "lit \[n\]\$.2"} $RESULT] >= 0}
559
560 # In a checkout "diff --tcl" prints the same literals without collecting
561 # them first.
562 commit_file lit-checkout.txt "first\n" "lit checkout" --no-warnings \
563 lit-checkout.txt
 
564 write_file lit-checkout.txt "\[second\] \$x\n"
565 fossil_raw diff --tcl lit-checkout.txt
566 test blob-tcl-literal-checkout {$CODE == 0 &&
567 [holds_strings $RESULT [list \
568 "FILE \"lit-checkout.txt\" \"lit-checkout.txt\"\n" \
569 {EDIT "" "first" "\[second\] \$x"}]]}
570 fossil revert lit-checkout.txt
571
572 # "diff --webpage" without --side-by-side builds four columns at once:
573 # the line numbers of each file, the marks, and the text.
574 write_file web.1 "one\ntwo\nthree\n"
@@ -573,13 +583,11 @@
583 # or --convert-eol-windows it gives the content the line ends of that
584 # system first; with --convert-eol-inherit it gives it the line ends of
585 # the version before. Each row: the option, the content before, the
586 # content given, and the content that must be checked in.
587
588 commit_file eol.txt "start\n" "eol start" --no-warnings
 
 
589
590 # Check in eol.txt with the content $before, then with $given and the
591 # option $option. Returns the content of eol.txt in the last check-in.
592 proc blob_eol {before given option} {
593 global RESULT
@@ -605,18 +613,19 @@
613 "x\ny\nz\n"
614 inherit-windows --convert-eol-inherit "p\r\nq\r\n" "x\ny\nz\n"
615 "x\r\ny\r\nz\r\n"
616 inherit-same --convert-eol-inherit "p\nq\n" "x\ny\n" "x\ny\n"
617 } {
618 test_eq blob-eol-$blobName [blob_eol $blobBefore $blobGiven $blobOption] \
619 $blobStored
620 }
621
622 # Content with a zero byte after its lines keeps the bytes that follow
623 # the zero byte.
624 test_eq blob-eol-to-unix-nul [blob_eol "s\n" "x\r\ny\r\n\x00tail\r\nmore\r\n" \
625 --convert-eol-unix] \
626 "x\ny\n\x00tail\nmore\n" knownBug
627
628 # test-ci-mini leaves the checkout as it was.
629 fossil revert eol.txt
630 fossil update tip
631
@@ -637,11 +646,12 @@
646 foreach {blobName blobBefore blobAfter} {
647 utf16-le fffe6800e9000d000a00ac200a00 efbbbf68c3a90ae282ac0a
648 utf16-be feff006800e9000d000a20ac000a efbbbf68c3a90ae282ac0a
649 utf16-le-short fffe6800 efbbbf68
650 utf16-be-short feff0068 efbbbf68
651 cp1252 63e920802081209920a020ff0d0a61
652 63c3a920e282ac20c28120e284a220c2a020c3bf0a61
653 cp1252-9f 9f8a0a c5b8c5a00a
654 cp1252-plain e90a c3a90a
655 cp1252-long __long__ __long__
656 } {
657 if {$blobBefore eq "__long__"} {
@@ -664,13 +674,12 @@
674 # byte-order mark is taken off, UTF-16 with a mark is converted, and
675 # bytes that are not UTF-8 are read as code page 1252. Each row: the
676 # bytes of the file and the bytes of the comment that must be stored,
677 # both in hexadecimal.
678
679 commit_file comment-subject.txt "0\n" "comment subject" --no-warnings \
680 comment-subject.txt
 
681 foreach {blobName blobFile blobComment} {
682 ascii 706c61696e 706c61696e
683 utf8 636166c3a920e282ac 636166c3a920e282ac
684 utf8-bom efbbbf636166c3a9 636166c3a9
685 utf16-le fffe63006100e900 6361c3a9
@@ -683,18 +692,17 @@
692 write_file comment-subject.txt "$blobName\n"
693 fossil commit -M comment-$blobName.txt --no-warnings \
694 --no-verify-comment comment-subject.txt
695 fossil sql "SELECT lower(hex(comment)) FROM event
696 ORDER BY mtime DESC, objid DESC LIMIT 1"
697 test_eq blob-comment-file-$blobName [string trim $RESULT] $blobComment
698 }
699
700 # A comment typed in an editor is converted in the same way, after it
701 # is cut at a row of ten "#". The editor here is a script that writes
702 # the given bytes as the comment.
703 fossil settings editor [fake_editor_command]
 
704 foreach {blobName blobTyped blobComment} {
705 utf8 636166c3a90a 636166c3a9
706 cp1252 636166e920800a 636166c3a920e282ac
707 cp1252-cut 63e90a232323232323232323232063757420800a 63c3a9
708 utf8-cut 63c3a90a232323232323232323232063757420800a 63c3a9
@@ -703,23 +711,21 @@
711 set ::env(FAKE_EDITOR_SCRIPT) [list set data [blob_bytes $blobTyped]]
712 fossil commit --no-warnings --no-verify-comment comment-subject.txt
713 unset ::env(FAKE_EDITOR_SCRIPT)
714 fossil sql "SELECT lower(hex(comment)) FROM event
715 ORDER BY mtime DESC, objid DESC LIMIT 1"
716 test_eq blob-comment-editor-$blobName [string trim $RESULT] $blobComment
717 }
718 fossil unset editor
719
720 ###############################################################################
721 # A diff does not show a byte-order mark, and reads UTF-16 text that has
722 # one. Each row: the bytes of the second file, in hexadecimal. The first
723 # file is "one" and "two" on two lines, and the diff must say that "2"
724 # replaces the second line.
725
726 commit_file bom-plain.txt "one\ntwo\n" "bom plain" --no-warnings bom-plain.txt
 
 
727 foreach {blobName blobSecond} {
728 none 6f6e650a320a
729 utf8 efbbbf6f6e650a320a
730 utf16-le fffe6f006e0065000a0032000a00
731 utf16-be feff006f006e0065000a0032000a
@@ -755,18 +761,12 @@
761 ###############################################################################
762 # Web pages. The page PATH of the repository of this checkout, asked for
763 # by a local administrator with the header lines in HEADERS.
764
765 proc blob_page {path {headers {}}} {
766 return [fossil_http .rep.fossil [request_get $path $headers] \
767 --ipaddr 127.0.0.1 --localauth]
 
 
 
 
 
 
768 }
769
770 # /test-bgcolor takes a colour as "#" and three or six hexadecimal
771 # digits in lower case. Each row: what follows the "#" and whether it is
772 # a colour.
@@ -824,11 +824,12 @@
824 test blob-xdigit-cookie-name-g {$CODE == 0 &&
825 [string first "This cookie was not generated by Fossil" $blobReply] >= 0}
826
827 # A request that announces more content than a buffer may hold is ended
828 # with "out of memory" before any of the content is read.
829 write_file page-request.txt \
830 "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type:\
831 text/plain\r\nContent-Length: 2147483647\r\n\r\nabc"
832 file delete page-reply.txt
833 fossil_raw -seconds 60 http .rep.fossil --in page-request.txt \
834 --out page-reply.txt --ipaddr 127.0.0.1 --localauth
835 test blob-too-large-request {$CODE == 1 && $RESULT eq "out of memory\n" &&
@@ -887,11 +888,10 @@
888 --clean "" --ignore "*" --keep "" clean-1.tmp clean-2.tmp
889 set left [lsort [glob -nocomplain clean-*.tmp]]
890 file delete clean-1.tmp clean-2.tmp
891 return $left
892 }
 
893 foreach {blobName blobAnswer blobLeft} {
894 lower-n n {clean-1.tmp clean-2.tmp}
895 upper-n N {clean-1.tmp clean-2.tmp}
896 word-no no {clean-1.tmp clean-2.tmp}
897 lower-y y {}
@@ -914,12 +914,12 @@
914 empty {}
915 brace \{
916 tilde ~
917 letter-q q
918 } {
919 test_eq blob-clean-prompt-$blobName [blob_clean $blobAnswer] \
920 {clean-1.tmp clean-2.tmp} knownBug
921 }
922
923 ###############################################################################
924 # A comment is broken into lines at a space, or after a hyphen that
925 # follows a letter. Each row: the character before the hyphen in
@@ -973,12 +973,13 @@
973 [regexp {<<<<<<<[^\n]*\nONE\n#######} $blobMerged] &&
974 [regexp {=======[^\n]*\nTWO\n>>>>>>>} $blobMerged]}
975
976 # One side changes a line and the other adds a line after the last one,
977 # which had no line end. The added line is a line of its own.
978 test_eq blob-merge-no-final-newline-append \
979 [blob_merge "a\nb\nc" "a\nB\nc" "a\nb\nc\nd"] \
980 "a\nB\nc\nd" knownBug
981
982 ###############################################################################
983 # With the allow-symlinks setting on, a symbolic link is checked in as the
984 # name it points to. With the setting off, the file it points to is
985 # checked in.
986
+482 -323
--- test/cgi.test
+++ test/cgi.test
@@ -5,15 +5,10 @@
55
# the parameters the server read from the request.
66
#
77
# Plain HTTP, the same request arriving over ssh, and SCGI.
88
#
99
10
-# These tests run only in a long pass: -assurance stress.
11
-if {[test_assurance] ne "stress"} {
12
- test_skip "runs only with -assurance stress"
13
-}
14
-
1510
test_setup
1611
1712
write_file a.txt "an unversioned file\n"
1813
fossil uv add a.txt
1914
set cgiRepo [file join [pwd] .rep.fossil]
@@ -20,28 +15,18 @@
2015
2116
# Send the request in TEXT, a string of bytes, to the server and return
2217
# the reply. ARGS are more options for "fossil http".
2318
#
2419
proc cgi_send {text args} {
25
- global cgiRepo
26
- write_file request.txt $text
27
- file delete reply.txt
28
- fossil_raw http $cgiRepo --in request.txt --out reply.txt {*}$args
29
- if {[file exists reply.txt]} { return [read_file reply.txt] }
30
- return ""
20
+ return [fossil_http $::cgiRepo $text {*}$args]
3121
}
3222
3323
# The same, as a local administrator.
3424
proc cgi_admin {text args} {
3525
return [cgi_send $text --ipaddr 127.0.0.1 --localauth {*}$args]
3626
}
3727
38
-# The status line of a reply.
39
-proc cgi_status {reply} {
40
- return [string trim [lindex [split $reply \n] 0]]
41
-}
42
-
4328
# The value of parameter NAME as /test-env shows it, or "-" if it does
4429
# not show it.
4530
proc cgi_param {reply name} {
4631
set start [string first "\n$name = " $reply]
4732
if {$start < 0} { return - }
@@ -49,47 +34,29 @@
4934
set end [string first " <br>" $reply $start]
5035
if {$end < 0} { return - }
5136
return [string range $reply $start [expr {$end - 1}]]
5237
}
5338
54
-# The value of header NAME in a reply, or "-" if the reply has no such
55
-# header.
56
-proc cgi_header {reply name} {
57
- set end [string first "\r\n\r\n" $reply]
58
- foreach line [split [string range $reply 0 $end] \n] {
59
- if {[string match -nocase "$name: *" $line]} {
60
- return [string trim [string range $line [string length $name]+1 end]]
61
- }
62
- }
63
- return -
64
-}
65
-
66
-# The content of a reply: what follows its headers.
67
-proc cgi_body {reply} {
68
- set end [string first "\r\n\r\n" $reply]
69
- if {$end < 0} { return "" }
70
- return [string range $reply $end+4 end]
71
-}
72
-
73
-# A GET request for PATH with the header lines in HEADERS, a list.
74
-proc cgi_get {path {headers {}} {method GET}} {
75
- set text "$method $path HTTP/1.1\r\nHost: x\r\n"
76
- foreach line $headers { append text $line "\r\n" }
77
- return "$text\r\n"
78
-}
79
-
80
-# A POST request with BODY as its content.
81
-proc cgi_post {type body {path /test-env}} {
82
- return "POST $path HTTP/1.1\r\nHost: x\r\nContent-Type: $type\r\nContent-Length: [string length $body]\r\n\r\n$body"
39
+# A POST request with BODY as its content, of the type TYPE, and the
40
+# header lines in HEADERS, a list.
41
+proc cgi_post {type body {path /test-env} {headers {}}} {
42
+ return [request_post $path $body $headers $type]
43
+}
44
+
45
+# A POST of the form data BODY to PATH, sent from the page REFERER.
46
+proc cgi_post_from {referer path body} {
47
+ return [cgi_post application/x-www-form-urlencoded $body $path \
48
+ [list "Referer: $referer"]]
8349
}
8450
8551
###############################################################################
8652
# Plain HTTP.
8753
88
-set cgiReply [cgi_admin "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"]
54
+set cgiReply [cgi_admin \
55
+ "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"]
8956
test cgi-get {$CODE == 0}
90
-test_eq cgi-get-status [cgi_status $cgiReply] "HTTP/1.0 200 OK"
57
+test_eq cgi-get-status [reply_status $cgiReply] "HTTP/1.0 200 OK"
9158
test_eq cgi-get-plain [cgi_param $cgiReply a] 1
9259
test_eq cgi-get-plus [cgi_param $cgiReply b] "two words"
9360
test_eq cgi-get-escape [cgi_param $cgiReply c] AB
9461
test_eq cgi-get-empty [cgi_param $cgiReply d] ""
9562
test_eq cgi-get-no-value [cgi_param $cgiReply e] ""
@@ -104,22 +71,26 @@
10471
no-method "\r\n\r\n" \
10572
bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \
10673
] {
10774
set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1]
10875
test cgi-malformed-$cgiName \
109
- {[string match "HTTP/1.0 40*" [cgi_status $cgiReply]]}
76
+ {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]}
11077
}
11178
11279
# A request line with no path is a request for the home page.
11380
set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1]
114
-test_eq cgi-no-path [cgi_status $cgiReply] "HTTP/1.0 302 Moved Temporarily"
81
+test_eq cgi-no-path [reply_status $cgiReply] "HTTP/1.0 302 Moved Temporarily"
11582
11683
###############################################################################
11784
# Form data in several parts, as a browser sends an upload.
11885
11986
proc cgi_part {name body {extra ""}} {
120
- return "--XB\r\nContent-Disposition: form-data; name=\"$name\"$extra\r\n\r\n$body\r\n"
87
+ return \
88
+ [join [list \
89
+ "--XB\r\n" \
90
+ "Content-Disposition: form-data; " \
91
+ "name=\"$name\"$extra\r\n\r\n$body\r\n"] ""]
12192
}
12293
set cgiType "multipart/form-data; boundary=XB"
12394
12495
set cgiReply [cgi_admin [cgi_post $cgiType \
12596
"[cgi_part alpha {first value}][cgi_part upload {file body} \
@@ -128,11 +99,16 @@
12899
test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body"
129100
test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt
130101
test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9
131102
132103
set cgiReply [cgi_admin [cgi_post $cgiType \
133
- "--XB\r\nContent-Disposition: form-data; name=\"t\"; filename=\"t.bin\"\r\nContent-Type: application/octet-stream\r\n\r\nxyz\r\n--XB--\r\n"]]
104
+ [join [list \
105
+ "--XB\r\n" \
106
+ "Content-Disposition: form-data; name=\"t\"; " \
107
+ "filename=\"t.bin\"\r\n" \
108
+ "Content-Type: application/octet-stream\r\n\r\nxyz\r\n" \
109
+ "--XB--\r\n"] ""]]]
134110
test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \
135111
application/octet-stream
136112
137113
# A name that begins with a capital is taken in lower case.
138114
set cgiReply [cgi_admin [cgi_post $cgiType \
@@ -146,11 +122,14 @@
146122
test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value
147123
148124
# A part with no closing boundary after a long one ends at the end of the
149125
# request, and every part is read within the request.
150126
set cgiReply [cgi_admin [cgi_post $cgiType \
151
- "[cgi_part alpha [string repeat x 3000]]--XB\r\nContent-Disposition: form-data; name=\"beta\"\r\n\r\nno closing boundary"]]
127
+ [join [list \
128
+ "[cgi_part alpha [string repeat x 3000]]--XB\r\n" \
129
+ "Content-Disposition: form-data; name=\"beta\"\r\n\r\n" \
130
+ "no closing boundary"] ""]]]
152131
test cgi-multipart-unclosed {$CODE == 0}
153132
test_eq cgi-multipart-unclosed-first \
154133
[string length [cgi_param $cgiReply alpha]] 3000
155134
test_eq cgi-multipart-unclosed-second [cgi_param $cgiReply beta] \
156135
"no closing boundary"
@@ -163,19 +142,36 @@
163142
"--XB" \
164143
"--XB\r\n" \
165144
"--XB\r\n\r\nno name here\r\n--XB--\r\n" \
166145
"--XB\r\nContent-Disposition: form-data; name=\"a\"" \
167146
"[cgi_part a "one\000two"]--XB--\r\n" \
168
- "--XB\r\nContent-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n--XB--\r\n" \
169
- "--[string repeat B 3000]\r\nContent-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n" \
170
- "[cgi_part a [string repeat x 2000]]--XB\r\nContent-Disposition: form-data; name=\"b\"" \
147
+ [join [list \
148
+ "--XB\r\n" \
149
+ "Content-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n" \
150
+ "--XB--\r\n"] ""] \
151
+ [join [list \
152
+ "--[string repeat B 3000]\r\n" \
153
+ "Content-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n"] ""] \
154
+ [join [list \
155
+ "[cgi_part a [string repeat x 2000]]--XB\r\n" \
156
+ "Content-Disposition: form-data; name=\"b\""] ""] \
171157
"[cgi_part {} v]--XB--\r\n" \
172
- "--XB\r\nContent-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n--XB--\r\n" \
173
- "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\nv\r\n--XB--\r\n" \
158
+ [join [list \
159
+ "--XB\r\n" \
160
+ "Content-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n" \
161
+ "--XB--\r\n"] ""] \
162
+ [join [list \
163
+ "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\n" \
164
+ "v\r\n--XB--\r\n"] ""] \
174165
"--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \
175
- "--XB\r\nContent-Disposition: form-data; name=\"a\"; filename=\r\n\r\nv\r\n--XB--\r\n" \
176
- "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\ncontent-type:\r\n\r\nv\r\n--XB--\r\n" \
166
+ [join [list \
167
+ "--XB\r\n" \
168
+ "Content-Disposition: form-data; name=\"a\"; " \
169
+ "filename=\r\n\r\nv\r\n--XB--\r\n"] ""] \
170
+ [join [list \
171
+ "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\n" \
172
+ "content-type:\r\n\r\nv\r\n--XB--\r\n"] ""] \
177173
"[cgi_part a "\n--X"]--XB--\r\n" \
178174
] {
179175
incr cgiI
180176
cgi_admin [cgi_post $cgiType $cgiBody]
181177
test cgi-multipart-odd-$cgiI {$CODE == 0}
@@ -190,12 +186,14 @@
190186
###############################################################################
191187
# The date in an If-Modified-Since header. A file that has not changed
192188
# since that date is not sent again.
193189
194190
proc cgi_since {date} {
195
- set reply [cgi_send "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" --ipaddr 127.0.0.1]
196
- return [cgi_status $reply]
191
+ set reply [cgi_send \
192
+ "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" \
193
+ --ipaddr 127.0.0.1]
194
+ return [reply_status $reply]
197195
}
198196
test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \
199197
"HTTP/1.0 304 Not Modified"
200198
test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \
201199
"HTTP/1.0 200 OK"
@@ -220,24 +218,29 @@
220218
g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1
221219
g.ico 1 g.png 0 g.zip 0 g.pdf 0
222220
} {
223221
write_file $cgiName [string repeat "content to compress\n" 50]
224222
fossil uv add $cgiName
225
- set cgiReply [cgi_send "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\nAccept-Encoding: gzip, deflate\r\n\r\n" --ipaddr 127.0.0.1]
223
+ set cgiReply [cgi_send \
224
+ [join [list \
225
+ "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\n" \
226
+ "Accept-Encoding: gzip, deflate\r\n\r\n"] ""] --ipaddr 127.0.0.1]
226227
test_eq cgi-gzip-$cgiName \
227228
[string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip
228229
}
229
-set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" --ipaddr 127.0.0.1]
230
-test cgi-gzip-not-accepted {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
230
+set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" \
231
+ --ipaddr 127.0.0.1]
232
+test cgi-gzip-not-accepted {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
231233
&& ![string match "*Content-Encoding*" $cgiReply]}
232234
233235
###############################################################################
234236
# A POST whose Referer is another site is not taken as safe from forgery,
235237
# and is written to the error log.
236238
237239
proc cgi_logout {referer} {
238
- return [cgi_send "POST /login HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 5\r\n\r\nout=1" --ipaddr 10.0.0.1 --errorlog [file join [pwd] err.log]]
240
+ return [cgi_send [cgi_post_from $referer /login "out=1"] --ipaddr 10.0.0.1 \
241
+ --errorlog [file join [pwd] err.log]]
239242
}
240243
file delete err.log
241244
cgi_logout http://x/login
242245
test cgi-same-origin-not-logged {![file exists err.log]
243246
|| ![string match "*different origin*" [read_file err.log]]}
@@ -257,11 +260,11 @@
257260
set cgiReply [cgi_send [cgi_scgi {
258261
CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1
259262
PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80
260263
REMOTE_ADDR 127.0.0.1
261264
}] --scgi --localauth]
262
-test_eq cgi-scgi [cgi_status $cgiReply] "HTTP/1.0 200 OK"
265
+test_eq cgi-scgi [reply_status $cgiReply] "HTTP/1.0 200 OK"
263266
test_eq cgi-scgi-param [cgi_param $cgiReply s] 1
264267
265268
foreach {cgiName cgiRequest} [list \
266269
too-short "15:CONTENT_LENGTH\0000\000," \
267270
cut-short "40:CONTENT_LENGTH\0000\000," \
@@ -268,20 +271,21 @@
268271
no-zero "20:CONTENT_LENGTH0000000000," \
269272
huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \
270273
] {
271274
set cgiReply [cgi_send $cgiRequest --scgi]
272275
test cgi-scgi-$cgiName {$CODE == 0 &&
273
- [string match "HTTP/1.0 400*" [cgi_status $cgiReply]]}
276
+ [string match "HTTP/1.0 400*" [reply_status $cgiReply]]}
274277
}
275278
276279
###############################################################################
277280
# The same reader for a request that arrives over ssh, which the server
278281
# knows from SSH_CONNECTION. It reads the client's probes first.
279282
280283
set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
281
-set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" --localauth]
282
-test_eq cgi-ssh [cgi_status $cgiReply] "HTTP/1.0 200 OK"
284
+set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" \
285
+ --localauth]
286
+test_eq cgi-ssh [reply_status $cgiReply] "HTTP/1.0 200 OK"
283287
test_eq cgi-ssh-param [cgi_param $cgiReply q] 1
284288
test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1
285289
286290
set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \
287291
"p=posted"] --localauth]
@@ -288,11 +292,14 @@
288292
test_eq cgi-ssh-post [cgi_param $cgiReply p] posted
289293
290294
# An older client opens the connection with "echo" probes, each of which
291295
# the server answers with the word it was given, and then names the
292296
# command it ran. Any other word in a probe is refused.
293
-set cgiReply [cgi_send "echo test1\necho probe-2\nfossil\nGET /test-env?q=3 HTTP/1.1\r\nHost: x\r\n\r\n" --localauth]
297
+set cgiReply [cgi_send \
298
+ [join [list \
299
+ "echo test1\necho probe-2\nfossil\n" \
300
+ "GET /test-env?q=3 HTTP/1.1\r\nHost: x\r\n\r\n"] ""] --localauth]
294301
test cgi-ssh-probes {[string match "test1\nprobe-2\n*" $cgiReply]
295302
&& [string match "*\nHTTP/1.0 200 OK*" $cgiReply]}
296303
test_eq cgi-ssh-probes-param [cgi_param $cgiReply q] 3
297304
foreach {cgiName cgiRequest} [list \
298305
probe-word "echo hello\n" \
@@ -312,18 +319,26 @@
312319
] {
313320
cgi_send $cgiRequest
314321
test cgi-ssh-$cgiName {$CODE == 0 || $CODE == 1}
315322
}
316323
unset ::env(SSH_CONNECTION)
324
+
325
+###############################################################################
326
+# The tests above try each kind of request once. The tests below aim
327
+# at every branch of cgi.c.
328
+
329
+if {[test_assurance] eq "smoke"} {
330
+ test_skip "the tests of each branch need -assurance ci or stress"
331
+}
317332
318333
###############################################################################
319334
# Names and values in a query string and in a Cookie header. A name is
320335
# taken when it begins with a letter and holds only letters, digits,
321336
# "_" and "-"; of two values with one name the first is kept; a value
322337
# from the query string that holds a control character is dropped.
323338
324
-set cgiReply [cgi_admin [cgi_get \
339
+set cgiReply [cgi_admin [request_get \
325340
"/test-env?e&a=1&=5&&a\$b=6&c=%01x&1a=2&_u=3&a=second&Up=4&zz" \
326341
[list "Cookie: ck=1; sp=2; fossil-x=9; Big=3"]]]
327342
foreach {cgiName cgiParam cgiValue} {
328343
no-value-first e ""
329344
plain a 1
@@ -342,11 +357,11 @@
342357
} {
343358
test_eq cgi-names-$cgiName [cgi_param $cgiReply $cgiParam] $cgiValue
344359
}
345360
346361
# With "showall" the page shows the cookies as well.
347
-set cgiReply [cgi_admin [cgi_get /test-env?showall \
362
+set cgiReply [cgi_admin [request_get /test-env?showall \
348363
[list "Cookie: ck=1; fossil-x=9"]]]
349364
test_eq cgi-showall-cookie [cgi_param $cgiReply fossil-x] 9
350365
test_eq cgi-showall-header [cgi_param $cgiReply HTTP_COOKIE] "ck=1; fossil-x=9"
351366
352367
# A value in a form may hold a control character.
@@ -362,11 +377,16 @@
362377
&& [string match "*Too many query parameters*" $cgiReply$RESULT]}
363378
364379
###############################################################################
365380
# The request line and the header lines.
366381
367
-set cgiReply [cgi_admin "GET /test-env?showall HTTP/1.1\r\nHOST: named.example:8080\r\nIf-None-Match: tag\r\nAuthorization: Basic eDp5\r\nAccept-Language: de \r\nUser-Agent: Agent/1\r\nUnknown-Header: ignored\r\n\r\n"]
382
+set cgiReply [cgi_admin \
383
+ [join [list \
384
+ "GET /test-env?showall HTTP/1.1\r\n" \
385
+ "HOST: named.example:8080\r\nIf-None-Match: tag\r\n" \
386
+ "Authorization: Basic eDp5\r\nAccept-Language: de \r\n" \
387
+ "User-Agent: Agent/1\r\nUnknown-Header: ignored\r\n\r\n"] ""]]
368388
foreach {cgiParam cgiValue} {
369389
HTTP_HOST named.example:8080
370390
SERVER_NAME named.example
371391
HTTP_IF_NONE_MATCH tag
372392
HTTP_AUTHORIZATION {Basic eDp5}
@@ -378,12 +398,12 @@
378398
test_eq cgi-header-$cgiParam [cgi_param $cgiReply $cgiParam] $cgiValue
379399
}
380400
381401
# An "Https:" header says that the request came by https, so the reply
382402
# sends a local user to the https login page.
383
-set cgiReply [cgi_admin [cgi_get /test-env [list "Https: on"]]]
384
-test_eq cgi-header-https [cgi_header $cgiReply Location] \
403
+set cgiReply [cgi_admin [request_get /test-env [list "Https: on"]]]
404
+test_eq cgi-header-https [reply_header $cgiReply Location] \
385405
https://x/login?g=test-env
386406
387407
# X-Forwarded-For names the client when the request comes from this
388408
# machine: the last address in it is taken. From any other machine the
389409
# header is ignored. Only a local client sees /test-env here.
@@ -394,34 +414,44 @@
394414
mapped 127.0.0.1 ::ffff:127.0.0.1 ::ffff:127.0.0.1
395415
remote 127.0.0.1 {127.0.0.1, 9.9.9.9} -
396416
empty 127.0.0.1 {} -
397417
not-local 10.0.0.1 127.0.0.1 -
398418
} {
399
- set cgiReply [cgi_send [cgi_get /test-env \
419
+ set cgiReply [cgi_send [request_get /test-env \
400420
[list "X-Forwarded-For: $cgiForwarded"]] --ipaddr $cgiFrom --localauth]
401421
test_eq cgi-forwarded-$cgiName [cgi_param $cgiReply REMOTE_ADDR] $cgiAddr
402422
}
403423
404424
# HEAD gets the headers of the reply to GET and no content.
405
-set cgiReply [cgi_send [cgi_get /uv/g.png {} HEAD] --ipaddr 127.0.0.1]
406
-test_eq cgi-head-status [cgi_status $cgiReply] "HTTP/1.0 200 OK"
407
-test_eq cgi-head-length [cgi_header $cgiReply Content-Length] 1000
408
-test_eq cgi-head-body [cgi_body $cgiReply] ""
425
+set cgiReply [cgi_send [request_get /uv/g.png {} HEAD] --ipaddr 127.0.0.1]
426
+test_eq cgi-head-status [reply_status $cgiReply] "HTTP/1.0 200 OK"
427
+test_eq cgi-head-length [reply_header $cgiReply Content-Length] 1000
428
+test_eq cgi-head-body [reply_body $cgiReply] ""
409429
410430
# A POST must say how long its content is, and send that much.
411431
set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\n\r\n"]
412
-test cgi-post-no-length {[cgi_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
432
+test cgi-post-no-length {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
413433
&& [string match "*missing CONTENT_LENGTH on a POST method*" $cgiReply]}
414
-set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 50\r\n\r\na=1"]
415
-test cgi-post-short {[cgi_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
434
+set cgiReply [cgi_admin \
435
+ [join [list \
436
+ "POST /test-env HTTP/1.1\r\nHost: x\r\n" \
437
+ "Content-Type: application/x-www-form-urlencoded\r\n" \
438
+ "Content-Length: 50\r\n\r\na=1"] ""]]
439
+test cgi-post-short {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
416440
&& [string match "*Wanted 50 bytes but got only 3*" $cgiReply]}
417441
# Content with no type is not read.
418
-set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\n\r\na=1"]
419
-test cgi-post-no-type {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
442
+set cgiReply [cgi_admin \
443
+ "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\n\r\na=1"]
444
+test cgi-post-no-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
420445
&& [cgi_param $cgiReply a] eq "-"}
421
-foreach {cgiName cgiLength} {negative -5 zero 0 word abc huge 99999999999999999999} {
422
- set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $cgiLength\r\n\r\na=1"]
446
+foreach {cgiName cgiLength} \
447
+ {negative -5 zero 0 word abc huge 99999999999999999999} {
448
+ set cgiReply [cgi_admin \
449
+ [join [list \
450
+ "POST /test-env HTTP/1.1\r\nHost: x\r\n" \
451
+ "Content-Type: application/x-www-form-urlencoded\r\n" \
452
+ "Content-Length: $cgiLength\r\n\r\na=1"] ""]]
423453
test cgi-post-length-$cgiName {$CODE == 0
424454
&& [regexp {^HTTP/1.0 (200|400) } $cgiReply]}
425455
}
426456
427457
###############################################################################
@@ -429,22 +459,22 @@
429459
# asked for, not compressed, with status 206.
430460
431461
write_file r.css 0123456789abcdefghij
432462
fossil uv add r.css
433463
proc cgi_range {range {method GET} {file r.css}} {
434
- return [cgi_send [cgi_get /uv/$file \
464
+ return [cgi_send [request_get /uv/$file \
435465
[list "Range: $range" "Accept-Encoding: gzip"] $method] \
436466
--ipaddr 127.0.0.1]
437467
}
438468
set cgiReply [cgi_range bytes=2-5]
439
-test_eq cgi-range-status [cgi_status $cgiReply] "HTTP/1.0 206 Partial Content"
440
-test_eq cgi-range-header [cgi_header $cgiReply Content-Range] "bytes 2-5/20"
441
-test_eq cgi-range-length [cgi_header $cgiReply Content-Length] 4
442
-test_eq cgi-range-encoding [cgi_header $cgiReply Content-Encoding] -
443
-test_eq cgi-range-body [cgi_body $cgiReply] 2345
469
+test_eq cgi-range-status [reply_status $cgiReply] "HTTP/1.0 206 Partial Content"
470
+test_eq cgi-range-header [reply_header $cgiReply Content-Range] "bytes 2-5/20"
471
+test_eq cgi-range-length [reply_header $cgiReply Content-Length] 4
472
+test_eq cgi-range-encoding [reply_header $cgiReply Content-Encoding] -
473
+test_eq cgi-range-body [reply_body $cgiReply] 2345
444474
set cgiReply [cgi_range bytes=0-0]
445
-test_eq cgi-range-first-byte [cgi_body $cgiReply] 0
475
+test_eq cgi-range-first-byte [reply_body $cgiReply] 0
446476
# A range that is not two numbers in order is ignored.
447477
foreach {cgiName cgiRange} {
448478
word bytes=abc
449479
one-number bytes=5-
450480
negative bytes=-5-10
@@ -451,36 +481,36 @@
451481
backwards bytes=9-3
452482
other-unit lines=1-2
453483
} {
454484
set cgiReply [cgi_range $cgiRange]
455485
test cgi-range-ignored-$cgiName {
456
- [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
457
- && [cgi_header $cgiReply Content-Encoding] eq "gzip"}
486
+ [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
487
+ && [reply_header $cgiReply Content-Encoding] eq "gzip"}
458488
}
459489
# A range that runs past the end of the file stops at the end.
460490
set cgiReply [cgi_range bytes=15-2147483646]
461
-test_eq cgi-range-past-end [cgi_body $cgiReply] fghij
462
-test_eq cgi-range-past-end-header [cgi_header $cgiReply Content-Range] \
491
+test_eq cgi-range-past-end [reply_body $cgiReply] fghij
492
+test_eq cgi-range-past-end-header [reply_header $cgiReply Content-Range] \
463493
"bytes 15-19/20"
464
-test_eq cgi-range-past-end-length [cgi_header $cgiReply Content-Length] 5
494
+test_eq cgi-range-past-end-length [reply_header $cgiReply Content-Length] 5
465495
# A range that starts at or after the end gets 416 and no content.
466496
foreach {cgiName cgiRange} {at-end bytes=20-20 after-end bytes=25-30} {
467497
set cgiReply [cgi_range $cgiRange]
468498
test cgi-range-unsatisfiable-$cgiName {
469
- [cgi_status $cgiReply] eq "HTTP/1.0 416 Range Not Satisfiable"
470
- && [cgi_header $cgiReply Content-Range] eq "bytes */20"
471
- && [cgi_header $cgiReply Content-Length] eq "0"}
499
+ [reply_status $cgiReply] eq "HTTP/1.0 416 Range Not Satisfiable"
500
+ && [reply_header $cgiReply Content-Range] eq "bytes */20"
501
+ && [reply_header $cgiReply Content-Length] eq "0"}
472502
}
473503
# A number too large for an int is not taken as a smaller one.
474504
set cgiReply [cgi_range bytes=0-4294967299]
475
-test cgi-range-too-large {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"}
505
+test_eq cgi-range-too-large [reply_status $cgiReply] "HTTP/1.0 200 OK"
476506
# A reply other than 206 is sent whole, whatever range was asked for.
477
-set cgiReply [cgi_send [cgi_get /uv/nosuch.css [list "Range: bytes=3-9"]] \
507
+set cgiReply [cgi_send [request_get /uv/nosuch.css [list "Range: bytes=3-9"]] \
478508
--ipaddr 127.0.0.1]
479509
test cgi-range-not-found {
480
- [string match "HTTP/1.0 404 *" [cgi_status $cgiReply]]
481
- && [string match "<!DOCTYPE*" [cgi_body $cgiReply]]}
510
+ [string match "HTTP/1.0 404 *" [reply_status $cgiReply]]
511
+ && [string match "<!DOCTYPE*" [reply_body $cgiReply]]}
482512
483513
###############################################################################
484514
# More shapes of form data in several parts.
485515
486516
proc cgi_form {body} {
@@ -497,58 +527,87 @@
497527
set cgiReply [cgi_form "[cgi_part Shout loud]--XB--\r\n"]
498528
test_eq cgi-multipart-upper-plain [cgi_param $cgiReply shout] loud
499529
test_eq cgi-multipart-upper-no-bytes [cgi_param $cgiReply shout:bytes] -
500530
501531
# A name in capitals with a type of content.
502
-set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; name=\"Typed\"; filename=\"t\"\r\nContent-Type: text/x-test\r\n\r\nv\r\n--XB--\r\n"]
532
+set cgiReply [cgi_form \
533
+ [join [list \
534
+ "--XB\r\n" \
535
+ "Content-Disposition: form-data; name=\"Typed\"; " \
536
+ "filename=\"t\"\r\nContent-Type: text/x-test\r\n\r\nv\r\n" \
537
+ "--XB--\r\n"] ""]]
503538
test_eq cgi-multipart-upper-mimetype [cgi_param $cgiReply typed:mimetype] \
504539
text/x-test
505540
test_eq cgi-multipart-upper-bytes [cgi_param $cgiReply typed:bytes] 1
506541
507542
# A name that does not begin with a letter is not taken, with or without
508543
# a file name or a type.
509
-set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; name=\"1st\"; filename=\"f\"\r\nContent-Type: text/plain\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"]
544
+set cgiReply [cgi_form \
545
+ [join [list \
546
+ "--XB\r\n" \
547
+ "Content-Disposition: form-data; name=\"1st\"; " \
548
+ "filename=\"f\"\r\nContent-Type: text/plain\r\n\r\nv\r\n" \
549
+ "[cgi_part after ok]--XB--\r\n"] ""]]
510550
test_eq cgi-multipart-digit-name [cgi_param $cgiReply 1st] -
511551
test_eq cgi-multipart-digit-filename [cgi_param $cgiReply 1st:filename] -
512552
test_eq cgi-multipart-digit-mimetype [cgi_param $cgiReply 1st:mimetype] -
513553
test_eq cgi-multipart-digit-next [cgi_param $cgiReply after] ok
514554
515555
# A type or a file name given before the name belongs to no parameter.
516
-set cgiReply [cgi_form "--XB\r\nContent-Type: text/early\r\nContent-Disposition: form-data; filename=\"early\"; name=\"late\"\r\n\r\nv\r\n--XB--\r\n"]
556
+set cgiReply [cgi_form \
557
+ [join [list \
558
+ "--XB\r\nContent-Type: text/early\r\n" \
559
+ "Content-Disposition: form-data; filename=\"early\"; " \
560
+ "name=\"late\"\r\n\r\nv\r\n--XB--\r\n"] ""]]
517561
test_eq cgi-multipart-type-first-value [cgi_param $cgiReply late] v
518562
test_eq cgi-multipart-type-first-mimetype [cgi_param $cgiReply late:mimetype] -
519563
test_eq cgi-multipart-type-first-filename [cgi_param $cgiReply late:filename] -
520564
521565
# Words in a header line that the reader does not know are passed over.
522
-set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; nonce=1; foo=2; charset=3; xyz; name=\"known\"\r\n\r\nv\r\n--XB--\r\n"]
566
+set cgiReply [cgi_form \
567
+ [join [list \
568
+ "--XB\r\n" \
569
+ "Content-Disposition: form-data; nonce=1; foo=2; charset=3; " \
570
+ "xyz; name=\"known\"\r\n\r\nv\r\n--XB--\r\n"] ""]]
523571
test_eq cgi-multipart-unknown-words [cgi_param $cgiReply known] v
524572
525573
# A quoted word that reaches the end of a header line without a closing
526574
# quote. The request must be answered within the time limit.
527
-set cgiBody "--XB\r\nContent-Disposition: form-data; name=\"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"
575
+set cgiBody \
576
+ [join [list \
577
+ "--XB\r\nContent-Disposition: form-data; name=\"\r\n\r\nv\r\n" \
578
+ "[cgi_part after ok]--XB--\r\n"] ""]
528579
write_file request.txt [cgi_post $cgiType $cgiBody]
529580
file delete reply.txt
530581
fossil_raw -seconds 15 http $cgiRepo --in request.txt --out reply.txt \
531582
--ipaddr 127.0.0.1 --localauth
532583
test cgi-multipart-lone-quote {$CODE == 0}
533584
534585
# Only the first 49 words of a header line are read.
535586
set cgiWords ""
536
-for {set cgiI 0} {$cgiI < 30} {incr cgiI} { append cgiWords " w$cgiI \"q$cgiI\";" }
537
-set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data;$cgiWords name=\"far\"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"]
587
+for {set cgiI 0} {$cgiI < 30} {incr cgiI} \
588
+ { append cgiWords " w$cgiI \"q$cgiI\";" }
589
+set cgiReply [cgi_form \
590
+ [join [list \
591
+ "--XB\r\n" \
592
+ "Content-Disposition: form-data;$cgiWords " \
593
+ "name=\"far\"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"] ""]]
538594
test_eq cgi-multipart-many-words [cgi_param $cgiReply far] -
539595
test_eq cgi-multipart-many-words-next [cgi_param $cgiReply after] ok
540596
541597
# A quote that ends a header line after a space is a word of no
542598
# characters, so the part has no name.
543
-set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; name= \"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"]
544
-test {cgi-multipart-quote-alone} {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
599
+set cgiReply [cgi_form \
600
+ [join [list \
601
+ "--XB\r\nContent-Disposition: form-data; name= \"\r\n\r\n" \
602
+ "v\r\n[cgi_part after ok]--XB--\r\n"] ""]]
603
+test {cgi-multipart-quote-alone} {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
545604
&& [cgi_param $cgiReply after] eq "ok"}
546605
547606
# Content that begins with a zero byte has no parts.
548607
set cgiReply [cgi_form "\000--XB\r\n[cgi_part a v]--XB--\r\n"]
549
-test cgi-multipart-zero-first {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
608
+test cgi-multipart-zero-first {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
550609
&& [cgi_param $cgiReply a] eq "-"}
551610
552611
###############################################################################
553612
# More dates in If-Modified-Since. The file is given the time that the
554613
# date stands for and is then not sent again; one second newer and it is.
@@ -557,13 +616,14 @@
557616
fossil uv add d.bin
558617
proc cgi_since_exact {date seconds} {
559618
set result ""
560619
foreach mtime [list $seconds [expr {$seconds + 1}]] {
561620
fossil sql "UPDATE unversioned SET mtime=$mtime WHERE name='d.bin'"
562
- set reply [cgi_send [cgi_get /uv/d.bin [list "If-Modified-Since: $date"]] \
621
+ set reply [cgi_send [request_get /uv/d.bin \
622
+ [list "If-Modified-Since: $date"]] \
563623
--ipaddr 127.0.0.1]
564
- lappend result [lindex [cgi_status $reply] 1]
624
+ lappend result [lindex [reply_status $reply] 1]
565625
}
566626
return $result
567627
}
568628
foreach {cgiName cgiDate cgiSeconds} {
569629
epoch-year "Thu, 01 Jan 1970 00:00:10 GMT" 10
@@ -594,13 +654,13 @@
594654
second-61 "Mon, 01 Jan 2026 00:00:61 GMT"
595655
month "Mon, 01 Foo 2026 00:00:00 GMT"
596656
short "Mon, 01 Jan 2026"
597657
empty ""
598658
} {
599
- set cgiReply [cgi_send [cgi_get /uv/d.bin \
659
+ set cgiReply [cgi_send [request_get /uv/d.bin \
600660
[list "If-Modified-Since: $cgiDate"]] --ipaddr 127.0.0.1]
601
- test_eq cgi-since-not-a-date-$cgiName [cgi_status $cgiReply] \
661
+ test_eq cgi-since-not-a-date-$cgiName [reply_status $cgiReply] \
602662
"HTTP/1.0 200 OK"
603663
}
604664
605665
###############################################################################
606666
# Redirects. A redirect to an absolute URL is sent as it is; a redirect
@@ -610,12 +670,12 @@
610670
# the user-edit cancel button.
611671
612672
proc cgi_redirect_to {query {referer none}} {
613673
set headers {}
614674
if {$referer ne "none"} { lappend headers "Referer: $referer" }
615
- set reply [cgi_admin [cgi_get "/setup_uedit?$query" $headers]]
616
- return [cgi_header $reply Location]
675
+ set reply [cgi_admin [request_get "/setup_uedit?$query" $headers]]
676
+ return [reply_header $reply Location]
617677
}
618678
# The cancel button redirects to the referer.
619679
test_eq cgi-redirect-absolute-http [cgi_redirect_to can=1 http://other/p] \
620680
http://other/p
621681
test_eq cgi-redirect-absolute-https [cgi_redirect_to can=1 https://other/p] \
@@ -639,63 +699,64 @@
639699
proc cgi_csrf_level {reply} {
640700
if {[regexp {CSRF safety = ([^<]*)} $reply all level]} { return $level }
641701
return -
642702
}
643703
set cgiToken ""
644
-set cgiReply [cgi_admin [cgi_get /setup_uedit?id=0]]
704
+set cgiReply [cgi_admin [request_get /setup_uedit?id=0]]
645705
regexp {name="csrf" value="([^"]*)"} $cgiReply all cgiToken
646706
647
-set cgiReply [cgi_admin [cgi_get /test-env [list "Referer: http://x/prev"]]]
707
+set cgiReply [cgi_admin [request_get /test-env [list "Referer: http://x/prev"]]]
648708
test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin"
649709
proc cgi_env_post {body {referer http://x/prev}} {
650
- return [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body"]
710
+ return [cgi_admin [cgi_post_from $referer /test-env $body]]
651711
}
652712
set cgiReply [cgi_env_post "csrf=$cgiToken"]
653
-test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] "Same origin, POST, CSRF token"
713
+test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] \
714
+ "Same origin, POST, CSRF token"
654715
set cgiReply [cgi_env_post "csrf=wrong"]
655716
test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST"
656717
set cgiReply [cgi_env_post "x=1" http://elsewhere/p]
657718
test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe"
658719
659720
# A page that consults the check more than once. A cross-origin POST to
660721
# the user-edit page, which asks twice, is ignored without error.
661
-set cgiReply [cgi_admin "POST /setup_uedit HTTP/1.1\r\nHost: x\r\nReferer: http://elsewhere/p\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 14\r\n\r\nid=0&delete=1&"]
662
-test cgi-csrf-twice-cross {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"}
722
+set cgiReply [cgi_admin [cgi_post_from http://elsewhere/p /setup_uedit \
723
+ "id=0&delete=1&"]]
724
+test_eq cgi-csrf-twice-cross [reply_status $cgiReply] "HTTP/1.0 200 OK"
663725
# A valid same-origin POST with the token creates the user.
664726
set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken"
665
-set cgiReply [cgi_admin "POST /setup_uedit HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_uedit\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiBody]\r\n\r\n$cgiBody"]
666
-test cgi-csrf-verify-accepts {[string match "HTTP/1.0 302*" [cgi_status $cgiReply]]}
667
-test cgi-csrf-user-created {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1}
727
+set cgiReply [cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit \
728
+ $cgiBody]]
729
+test cgi-csrf-verify-accepts \
730
+ {[string match "HTTP/1.0 302*" [reply_status $cgiReply]]}
731
+test cgi-csrf-user-created \
732
+ {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1}
668733
669734
# The user-edit page needs "login", "info", "pw" and "apply" to make a
670735
# change. A request with "login" alone changes nothing.
671736
set cgiBody "id=0&login=cgighost&csrf=$cgiToken"
672
-cgi_admin "POST /setup_uedit HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_uedit\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiBody]\r\n\r\n$cgiBody"
737
+cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit $cgiBody]
673738
test cgi-all-needs-every-field \
674739
{[fossil sql "SELECT count(*) FROM user WHERE login='cgighost'"] == 0}
675740
676741
###############################################################################
677742
# Request methods and the same reader over ssh.
678743
679
-# A POST over ssh reaches the parameter decoder.
680744
set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
681
-set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \
682
- "posted=yes"] --localauth]
683
-test_eq cgi-ssh-post-value [cgi_param $cgiReply posted] yes
684745
# A HEAD over ssh.
685
-set cgiReply [cgi_send [cgi_get /test-env?q=9 {} HEAD] --localauth]
686
-test_eq cgi-ssh-head [cgi_status $cgiReply] "HTTP/1.0 200 OK"
746
+set cgiReply [cgi_send [request_get /test-env?q=9 {} HEAD] --localauth]
747
+test_eq cgi-ssh-head [reply_status $cgiReply] "HTTP/1.0 200 OK"
687748
unset ::env(SSH_CONNECTION)
688749
689750
###############################################################################
690751
# cgi_from_mobile, used by /forum to pick a default display order. An
691752
# iPad is not treated as mobile; another phone is; no agent is not.
692753
proc cgi_forum_order {agent} {
693754
set headers {}
694755
if {$agent ne ""} { lappend headers "User-Agent: $agent" }
695
- set reply [cgi_admin [cgi_get /forum?t=a $headers]]
696
- return [cgi_status $reply]
756
+ set reply [cgi_admin [request_get /forum?t=a $headers]]
757
+ return [reply_status $reply]
697758
}
698759
foreach {cgiName cgiAgent} {
699760
phone "Mozilla/5.0 (iPhone; Mobile) Safari"
700761
ipad "Mozilla/5.0 (iPad) Safari"
701762
none ""
@@ -709,47 +770,44 @@
709770
# and a note in the error log. The whole request environment is written
710771
# to the log.
711772
712773
proc cgi_attack {value} {
713774
global cgiRepo
714
- write_file request.txt "GET /timeline?inj=$value HTTP/1.1\r\nHost: x\r\nCookie: fossil-x=secret\r\n\r\n"
775
+ write_file request.txt \
776
+ [join [list \
777
+ "GET /timeline?inj=$value HTTP/1.1\r\nHost: x\r\n" \
778
+ "Cookie: fossil-x=secret\r\n\r\n"] ""]
715779
file delete reply.txt attack.log
716780
fossil_raw http $cgiRepo --in request.txt --out reply.txt \
717781
--ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log]
718782
return [expr {[file exists reply.txt] ? [read_file reply.txt] : ""}]
719783
}
720784
set cgiReply [cgi_attack "1;select"]
721
-test_eq cgi-attack-status [cgi_status $cgiReply] "HTTP/1.0 418 I'm a teapot"
785
+test_eq cgi-attack-status [reply_status $cgiReply] "HTTP/1.0 418 I'm a teapot"
722786
test cgi-attack-logged {[file exists attack.log]
723787
&& [string match "*possible hack attempt*" [read_file attack.log]]
724788
&& [string match "*QUERY_STRING = inj=1;select*" [read_file attack.log]]}
725789
# A value longer than 100 characters is shortened in the log.
726790
set cgiReply [cgi_attack "[string repeat a 200];x"]
727
-test cgi-attack-long {[cgi_status $cgiReply] eq "HTTP/1.0 418 I'm a teapot"
791
+test cgi-attack-long {[reply_status $cgiReply] eq "HTTP/1.0 418 I'm a teapot"
728792
&& [string match "*aaa...*" [read_file attack.log]]}
729793
# A logged-in request with the same value is not stopped.
730
-set cgiReply [cgi_admin [cgi_get "/timeline?inj=1;select"]]
731
-test_eq cgi-attack-admin-ok [cgi_status $cgiReply] "HTTP/1.0 200 OK"
794
+set cgiReply [cgi_admin [request_get "/timeline?inj=1;select"]]
795
+test_eq cgi-attack-admin-ok [reply_status $cgiReply] "HTTP/1.0 200 OK"
732796
733797
###############################################################################
734798
# The same-origin test with crafted Referer headers. The base URL here
735799
# is "http://x". A Referer that shares the base but has more path after
736800
# it with no "/" boundary is a different origin. A Referer with a "%"
737801
# escape is decoded before the comparison. The /test-env page reports
738802
# the result.
739803
740
-proc cgi_origin {referer {method GET} {body ""}} {
741
- set req "$method /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\n"
742
- if {$method eq "POST"} {
743
- append req "Content-Type: application/x-www-form-urlencoded\r\n"
744
- append req "Content-Length: [string length $body]\r\n"
745
- }
746
- append req "\r\n$body"
804
+proc cgi_origin {referer} {
805
+ set req "GET /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\n\r\n"
747806
set reply [cgi_admin $req]
748807
return [cgi_csrf_level $reply]
749808
}
750
-test_eq cgi-origin-same [cgi_origin http://x/page] "Same origin"
751809
test_eq cgi-origin-boundary [cgi_origin http://xtra/page] unsafe
752810
test_eq cgi-origin-escaped [cgi_origin http://x/a%2Fb] "Same origin"
753811
# A different-origin GET reaches the method test in the same-origin check
754812
# without writing a warning (the warning is for POST only).
755813
test_eq cgi-origin-get-other [cgi_origin http://elsewhere/p] unsafe
@@ -756,36 +814,37 @@
756814
757815
###############################################################################
758816
# cgi_parameter_name walks every parameter: the ticket-entry page copies
759817
# each into its interpreter.
760818
761
-set cgiReply [cgi_admin [cgi_get "/tktnew?username=someone&extra=1"]]
762
-test_eq cgi-param-name-page [cgi_status $cgiReply] "HTTP/1.0 200 OK"
819
+set cgiReply [cgi_admin [request_get "/tktnew?username=someone&extra=1"]]
820
+test_eq cgi-param-name-page [reply_status $cgiReply] "HTTP/1.0 200 OK"
763821
764822
###############################################################################
765823
# cgi_param_info walks the parameters for the /cookies page.
766824
767
-set cgiReply [cgi_admin [cgi_get /cookies \
825
+set cgiReply [cgi_admin [request_get /cookies \
768826
[list "Cookie: fossil_display_settings=x; extra=y"]]]
769
-test cgi-param-info-page {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
827
+test cgi-param-info-page {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
770828
&& [string match "*fossil_display_settings*" $cgiReply]}
771829
772830
###############################################################################
773831
# Two more destinations for cgi_print_all. With --cgitrace the whole
774832
# parameter set is traced before the page runs.
775833
776
-write_file request.txt [cgi_get "/test-env?traced=1"]
834
+write_file request.txt [request_get "/test-env?traced=1"]
777835
file delete reply.txt
778836
fossil_raw http $cgiRepo --in request.txt --out reply.txt \
779837
--ipaddr 127.0.0.1 --localauth --cgitrace
780838
test cgi-cgitrace {$CODE == 0
781839
&& [string match "*Calling*" $RESULT]
782840
&& [string match "*traced = 1*" $RESULT]}
783841
784842
# A CGI control file with "cgi-debug:" writes the environment to a debug
785843
# file as the control file is read.
786
-write_file cgi.ctl "repository: [file nativename $cgiRepo]\ncgi-debug: debug.txt\n"
844
+write_file cgi.ctl \
845
+ "repository: [file nativename $cgiRepo]\ncgi-debug: debug.txt\n"
787846
file delete debug.txt
788847
set ::env(REQUEST_METHOD) GET
789848
set ::env(SCRIPT_NAME) ""
790849
set ::env(PATH_INFO) /test-env
791850
set ::env(QUERY_STRING) "dbg=1"
@@ -802,37 +861,49 @@
802861
# email-alert subscription page. The page exists once email is enabled
803862
# and its tables are built.
804863
805864
fossil settings email-send-method db
806865
set cgiNotifyBody "submit=Refresh&esm=db&csrf=$cgiToken"
807
-cgi_admin "POST /setup_notification HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_notification\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiNotifyBody]\r\n\r\n$cgiNotifyBody"
866
+cgi_admin [cgi_post_from http://x/setup_notification /setup_notification \
867
+ $cgiNotifyBody]
808868
test cgi-alert-tables-built \
809
- {[fossil sql "SELECT count(*) FROM sqlite_schema WHERE name='subscriber'"] == 1}
869
+ {[fossil sql "SELECT count(*) FROM sqlite_schema WHERE name='subscriber'"]
870
+ == 1}
810871
811872
# The form renders the "checked" state of the checkboxes.
812
-set cgiReply [cgi_admin [cgi_get /subscribe]]
813
-test cgi-subscribe-form {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
873
+set cgiReply [cgi_admin [request_get /subscribe]]
874
+test cgi-subscribe-form {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
814875
&& [string match "*checkbox*" $cgiReply]}
815876
816877
# A submitted subscription: the name is trimmed and the boxes are read as
817878
# booleans. A leading and trailing space on the name is removed.
818
-set cgiSubBody "submit=1&[email protected]&suname= trimmed &sa=1&sc=on&csrf=$cgiToken"
819
-cgi_admin "POST /subscribe HTTP/1.1\r\nHost: x\r\nReferer: http://x/subscribe\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiSubBody]\r\n\r\n$cgiSubBody"
820
-test cgi-subscribe-trimmed-name \
821
- {[fossil sql "SELECT suname FROM subscriber WHERE semail='[email protected]'"] eq "trimmed"}
879
+set cgiSubBody \
880
+ [join [list \
881
+ "submit=1&[email protected]&suname= trimmed " \
882
+ "&sa=1&sc=on&csrf=$cgiToken"] ""]
883
+cgi_admin [cgi_post_from http://x/subscribe /subscribe $cgiSubBody]
884
+test_eq cgi-subscribe-trimmed-name \
885
+ [fossil sql \
886
+ "SELECT suname FROM subscriber WHERE semail='[email protected]'"] \
887
+ "trimmed"
822888
test cgi-subscribe-boolean-alert \
823
- {[string match "*a*" [fossil sql "SELECT ssub FROM subscriber WHERE semail='[email protected]'"]]}
889
+ {[string match "*a*" [fossil sql \
890
+ "SELECT ssub FROM subscriber WHERE semail='[email protected]'"]]}
824891
825892
###############################################################################
826893
# The HTTP reader is called in a loop for a request arriving over ssh.
827894
# When the first request announces the Fossil ssh transport, the reader
828895
# is called again for a second request in the same connection, and the
829896
# later request updates the parameters that the first one set.
830897
831898
set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
832899
write_file request.txt \
833
- "GET /test-env?first=1 HTTP/1.1\r\nHost: x\r\nX-Fossil-Transport: ssh\r\nContent-Length: 0\r\n\r\nGET /test-env?second=2 HTTP/1.1\r\nHost: x\r\nUser-Agent: Later\r\n\r\n"
900
+ [join [list \
901
+ "GET /test-env?first=1 HTTP/1.1\r\nHost: x\r\n" \
902
+ "X-Fossil-Transport: ssh\r\nContent-Length: 0\r\n\r\n" \
903
+ "GET /test-env?second=2 HTTP/1.1\r\nHost: x\r\n" \
904
+ "User-Agent: Later\r\n\r\n"] ""]
834905
file delete reply.txt
835906
fossil_raw http $cgiRepo --in request.txt --out reply.txt --localauth
836907
set cgiReply [read_file reply.txt]
837908
test cgi-ssh-transport-first {[string match "*first = 1*" $cgiReply]}
838909
test cgi-ssh-transport-second {[string match "*second = 2*" $cgiReply]}
@@ -841,24 +912,25 @@
841912
###############################################################################
842913
# The skin query parameter sets a cookie with a default path, and marks
843914
# the request "udc" unless "once" is present. A cookie carrying a login
844915
# card is taken out of the parameters.
845916
846
-set cgiReply [cgi_admin [cgi_get /test-env?skin=darkmode]]
917
+set cgiReply [cgi_admin [request_get /test-env?skin=darkmode]]
847918
test cgi-skin-cookie {[string match "*Set-Cookie: fossil_display_settings=*" \
848919
$cgiReply] && [cgi_param $cgiReply udc] eq 1}
849920
# With "once" the cookie is not written and "udc" is not forced.
850
-set cgiReply [cgi_admin [cgi_get {/test-env?skin=darkmode&once=1}]]
921
+set cgiReply [cgi_admin [request_get {/test-env?skin=darkmode&once=1}]]
851922
test cgi-skin-once {![string match "*Set-Cookie: fossil_display_settings=*" \
852923
$cgiReply] && [cgi_param $cgiReply udc] eq "-"}
853924
# A skin cookie is honoured as well as a skin query parameter.
854
-set cgiReply [cgi_admin [cgi_get /test-env \
925
+set cgiReply [cgi_admin [request_get /test-env \
855926
[list "Cookie: fossil_display_settings=skin=ardoise"]]]
856927
test_eq cgi-skin-from-cookie [cgi_param $cgiReply fossil_display_settings] \
857928
skin=ardoise
858929
# A login-card cookie is removed from the visible parameters.
859
-set cgiReply [cgi_admin [cgi_get /test-env [list "Cookie: x-f-l-c=card-value"]]]
930
+set cgiReply [cgi_admin [request_get /test-env \
931
+ [list "Cookie: x-f-l-c=card-value"]]]
860932
test_eq cgi-login-card-hidden [cgi_param $cgiReply x-f-l-c] -
861933
862934
###############################################################################
863935
# The reply content type for an unversioned file comes from the
864936
# "mimetypes" setting. Parsing of the type stops at the first character
@@ -865,19 +937,19 @@
865937
# outside the range "+" through "z", and a text type is compressed.
866938
867939
fossil settings mimetypes "zw text/x|y"
868940
write_file f.zw "other text to send"
869941
fossil uv add f.zw
870
-set cgiReply [cgi_send [cgi_get /uv/f.zw] --ipaddr 127.0.0.1]
942
+set cgiReply [cgi_send [request_get /uv/f.zw] --ipaddr 127.0.0.1]
871943
test cgi-content-type-stops \
872
- {[string match "text/x;*" [cgi_header $cgiReply Content-Type]]}
944
+ {[string match "text/x;*" [reply_header $cgiReply Content-Type]]}
873945
874946
###############################################################################
875947
# A skin name that is not a known skin produces an error, so the cookie
876948
# is not written.
877949
878
-set cgiReply [cgi_admin [cgi_get /test-env?skin=no_such_skin_here]]
950
+set cgiReply [cgi_admin [request_get /test-env?skin=no_such_skin_here]]
879951
test cgi-skin-unknown {![string match "*Set-Cookie: fossil_display_settings=*" \
880952
$cgiReply] && [cgi_param $cgiReply skin] eq "no_such_skin_here"}
881953
882954
###############################################################################
883955
# Deleting a cookie: the reply carries a Set-Cookie with a value of
@@ -913,13 +985,13 @@
913985
fossil commit -m "add art" --no-warnings
914986
set cgiArt [fossil sql \
915987
"SELECT uuid FROM blob WHERE rid=(SELECT max(rid) FROM blob)"]
916988
proc cgi_raw_type {mime} {
917989
global cgiArt
918
- set reply [cgi_send [cgi_get /raw/$cgiArt?m=$mime \
990
+ set reply [cgi_send [request_get /raw/$cgiArt?m=$mime \
919991
[list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth]
920
- return [cgi_header $reply Content-Encoding]
992
+ return [reply_header $reply Content-Encoding]
921993
}
922994
foreach {cgiName cgiMime} {
923995
javascript application/javascript
924996
json application/json
925997
wasm application/wasm
@@ -945,46 +1017,48 @@
9451017
}
9461018
# With --nocompress nothing is compressed.
9471019
set cgiFile [fossil sql "SELECT uuid FROM blob, mlink, filename
9481020
WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
9491021
AND filename.name='art.txt'"]
950
-set cgiReply [cgi_send [cgi_get /raw/$cgiFile?m=text/plain \
1022
+set cgiReply [cgi_send [request_get /raw/$cgiFile?m=text/plain \
9511023
[list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth --nocompress]
952
-test cgi-nocompress {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
953
- && [cgi_header $cgiReply Content-Encoding] eq "-"
954
- && [cgi_body $cgiReply] eq "the quick brown fox jumps over the lazy dog\n"}
1024
+test cgi-nocompress {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1025
+ && [reply_header $cgiReply Content-Encoding] eq "-"
1026
+ && [reply_body $cgiReply] eq
1027
+ "the quick brown fox jumps over the lazy dog\n"}
9551028
9561029
###############################################################################
9571030
# More about ranges. A Range header counts only for GET, and not for
9581031
# content of the type that a sync uses. Part of an artifact named by its
9591032
# full hash, sent to a visitor who is not logged in, may be kept by the
9601033
# client for ever.
9611034
9621035
set cgiReply [cgi_range bytes=2-5 HEAD]
963
-test cgi-range-head {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
964
- && [cgi_header $cgiReply Content-Range] eq "-"}
1036
+test cgi-range-head {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1037
+ && [reply_header $cgiReply Content-Range] eq "-"}
9651038
set cgiReply [cgi_range bytes=5]
966
-test cgi-range-ignored-no-dash {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
967
- && [cgi_header $cgiReply Content-Range] eq "-"}
968
-set cgiReply [cgi_send [cgi_get /raw/$cgiArt?m=application/x-fossil \
1039
+test cgi-range-ignored-no-dash {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1040
+ && [reply_header $cgiReply Content-Range] eq "-"}
1041
+set cgiReply [cgi_send [request_get /raw/$cgiArt?m=application/x-fossil \
9691042
[list "Range: bytes=1-3"]] --ipaddr 127.0.0.1 --localauth]
970
-test cgi-range-sync-type {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
971
- && [cgi_header $cgiReply Content-Range] eq "-"}
972
-set cgiReply [cgi_send [cgi_get /raw/$cgiFile?m=text/plain \
1043
+test cgi-range-sync-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1044
+ && [reply_header $cgiReply Content-Range] eq "-"}
1045
+set cgiReply [cgi_send [request_get /raw/$cgiFile?m=text/plain \
9731046
[list "Range: bytes=4-8"]] --ipaddr 9.9.9.9]
974
-test_eq cgi-range-artifact [cgi_body $cgiReply] quick
975
-test_eq cgi-range-artifact-cache [cgi_header $cgiReply Cache-Control] \
1047
+test_eq cgi-range-artifact [reply_body $cgiReply] quick
1048
+test_eq cgi-range-artifact-cache [reply_header $cgiReply Cache-Control] \
9761049
"max-age=315360000, immutable"
9771050
9781051
###############################################################################
9791052
# The "at" parameter of /raw names the file for the client to save the
9801053
# content in. Only its last path element is used, and every character
9811054
# in it other than a letter, a digit, "." and "-" becomes "_".
9821055
983
-set cgiReply [cgi_send [cgi_get "/raw/$cgiArt?at=some/dir/my%20file-1%3B.txt"] \
1056
+set cgiReply [cgi_send [request_get \
1057
+ "/raw/$cgiArt?at=some/dir/my%20file-1%3B.txt"] \
9841058
--ipaddr 127.0.0.1 --localauth]
985
-test_eq cgi-attachment-name [cgi_header $cgiReply Content-Disposition] \
1059
+test_eq cgi-attachment-name [reply_header $cgiReply Content-Disposition] \
9861060
{attachment; filename="my_file-1_.txt";}
9871061
9881062
###############################################################################
9891063
# A request that is refused before any repository is open: the server is
9901064
# given a directory, and the request has a method it does not know.
@@ -993,11 +1067,11 @@
9931067
write_file request.txt "DELETE /x HTTP/1.1\r\nHost: x\r\n\r\n"
9941068
file delete reply.txt
9951069
fossil_raw http [file join [pwd] norepo] --in request.txt --out reply.txt \
9961070
--ipaddr 127.0.0.1
9971071
test cgi-no-repository-bad-method {$CODE == 0
998
- && [cgi_status [read_file reply.txt]] eq "HTTP/1.0 400 Bad Request"}
1072
+ && [reply_status [read_file reply.txt]] eq "HTTP/1.0 400 Bad Request"}
9991073
10001074
###############################################################################
10011075
# More of the same-origin test: a Referer that is the base URL and
10021076
# nothing more is the same origin.
10031077
@@ -1007,19 +1081,18 @@
10071081
# With --httptrace the server reports each parameter as it is set and
10081082
# copies the request into a file named httplog-NNNNN.txt in the current
10091083
# directory. If it cannot make that file it says so and goes on.
10101084
10111085
foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog }
1012
-write_file request.txt [cgi_get /test-env?traced=2]
1086
+write_file request.txt [request_get /test-env?traced=2]
10131087
file delete reply.txt
10141088
fossil_raw http $cgiRepo --in request.txt --out reply.txt \
10151089
--ipaddr 127.0.0.1 --localauth --httptrace
10161090
set cgiLogs [glob -nocomplain httplog-*.txt]
1017
-test cgi-httptrace {$CODE == 0
1018
- && [string first "# cgi: traced = \[2\]" $RESULT] >= 0
1019
- && [string first "# open log on httplog-" $RESULT] >= 0
1020
- && [llength $cgiLogs] == 1}
1091
+test cgi-httptrace {$CODE == 0 &&
1092
+ [holds_strings $RESULT [list "# cgi: traced = \[2\]" \
1093
+ "# open log on httplog-"]] && [llength $cgiLogs] == 1}
10211094
if {[llength $cgiLogs] == 1} {
10221095
set cgiLogText [read_file [lindex $cgiLogs 0]]
10231096
test cgi-httptrace-log {
10241097
[string match "GET /test-env?traced=2 HTTP/1.1*Host: x*" $cgiLogText]}
10251098
file delete [lindex $cgiLogs 0]
@@ -1035,11 +1108,11 @@
10351108
file delete $cgiLog
10361109
}
10371110
test cgi-httptrace-post-content {[string match "*body=sent" $cgiLogText]}
10381111
test cgi-httptrace-post-header \
10391112
{[string match "POST /test-env HTTP/1.1*" $cgiLogText]}
1040
-write_file request.txt [cgi_get /test-env?traced=2]
1113
+write_file request.txt [request_get /test-env?traced=2]
10411114
if {$::tcl_platform(platform) eq "unix"} {
10421115
set cgiHere [pwd]
10431116
file mkdir readonly
10441117
file attributes readonly -permissions 0555
10451118
cd readonly
@@ -1048,54 +1121,55 @@
10481121
--ipaddr 127.0.0.1 --localauth --httptrace
10491122
cd $cgiHere
10501123
file attributes readonly -permissions 0755
10511124
test cgi-httptrace-no-log {$CODE == 0
10521125
&& [string first "# failed to open httplog-" $RESULT] >= 0
1053
- && [cgi_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"}
1126
+ && [reply_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"}
10541127
}
10551128
10561129
###############################################################################
10571130
# A request for the top of the site is sent on to the index page. A
10581131
# login-card cookie in such a request is taken once.
10591132
1060
-set cgiReply [cgi_admin [cgi_get / [list "Cookie: x-f-l-c=card-value"]]]
1061
-test_eq cgi-login-card-home [cgi_header $cgiReply Location] http://x/index
1133
+set cgiReply [cgi_admin [request_get / [list "Cookie: x-f-l-c=card-value"]]]
1134
+test_eq cgi-login-card-home [reply_header $cgiReply Location] http://x/index
10621135
10631136
###############################################################################
10641137
# The honeypot page offers a visitor who is not logged in a captcha, and
10651138
# keeps the URL that was asked for, with its query parameters, in a
10661139
# cookie.
10671140
1068
-set cgiReply [cgi_send [cgi_get "/honeypot?a=1&b&c=two"] --ipaddr 9.9.9.9]
1141
+set cgiReply [cgi_send [request_get "/honeypot?a=1&b&c=two"] --ipaddr 9.9.9.9]
10691142
test cgi-original-url {[string first \
10701143
"Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fa%3D1%26b%26c%3Dtwo;" \
10711144
$cgiReply] >= 0}
10721145
10731146
###############################################################################
10741147
# The "ss" parameter of /timeline is checked for an attack as soon as it
10751148
# is read, for a visitor who is not logged in.
10761149
1077
-write_file request.txt [cgi_get "/timeline?ss=1;select"]
1150
+write_file request.txt [request_get "/timeline?ss=1;select"]
10781151
file delete reply.txt attack.log
10791152
fossil_raw http $cgiRepo --in request.txt --out reply.txt \
10801153
--ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log]
10811154
test cgi-attack-read-parameter {
1082
- [cgi_status [read_file reply.txt]] eq "HTTP/1.0 418 I'm a teapot"
1155
+ [reply_status [read_file reply.txt]] eq "HTTP/1.0 418 I'm a teapot"
10831156
&& [string match "*418 response on \"ss\"*" [read_file attack.log]]}
1084
-set cgiReply [cgi_admin [cgi_get "/timeline?ss=m"]]
1085
-test_eq cgi-attack-read-parameter-admin [cgi_status $cgiReply] "HTTP/1.0 200 OK"
1157
+set cgiReply [cgi_admin [request_get "/timeline?ss=m"]]
1158
+test_eq cgi-attack-read-parameter-admin [reply_status $cgiReply] \
1159
+ "HTTP/1.0 200 OK"
10861160
10871161
###############################################################################
10881162
# SSH_CONNECTION names the client only when it holds an address followed
10891163
# by a space. Otherwise the request is read as plain HTTP from an
10901164
# unknown address, which --localauth does not log in.
10911165
10921166
foreach {cgiName cgiValue} {empty "" one-word nospace} {
10931167
set ::env(SSH_CONNECTION) $cgiValue
1094
- set cgiReply [cgi_send [cgi_get /test-env] --localauth]
1168
+ set cgiReply [cgi_send [request_get /test-env] --localauth]
10951169
unset ::env(SSH_CONNECTION)
1096
- test_eq cgi-ssh-connection-$cgiName [cgi_header $cgiReply Location] \
1170
+ test_eq cgi-ssh-connection-$cgiName [reply_header $cgiReply Location] \
10971171
http://x/login?g=test-env
10981172
}
10991173
11001174
###############################################################################
11011175
# SCGI: SCRIPT_NAME, PATH_INFO and REQUEST_URI. The server needs
@@ -1111,13 +1185,13 @@
11111185
proc cgi_scgi_names {pairs} {
11121186
set reply [cgi_send [cgi_scgi [concat {
11131187
CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SERVER_NAME x SERVER_PORT 80
11141188
REMOTE_ADDR 127.0.0.1
11151189
} $pairs]] --scgi --localauth]
1116
- set status [lindex [cgi_status $reply] 1]
1190
+ set status [lindex [reply_status $reply] 1]
11171191
if {$status eq "400"} {
1118
- return [list 400 [string trim [cgi_body $reply]]]
1192
+ return [list 400 [string trim [reply_body $reply]]]
11191193
}
11201194
if {$status ne "200"} { return $status }
11211195
return [list 200 [cgi_param $reply SCRIPT_NAME] [cgi_param $reply PATH_INFO] \
11221196
[cgi_param $reply REQUEST_URI]]
11231197
}
@@ -1171,29 +1245,33 @@
11711245
empty "" "SCGI header too short" \
11721246
length-only "20" "cannot read entire SCGI header" \
11731247
] {
11741248
set cgiReply [cgi_send $cgiRequest --scgi]
11751249
test cgi-scgi-$cgiName {$CODE == 0
1176
- && [cgi_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
1250
+ && [reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
11771251
&& [string match "*$cgiError*" $cgiReply]}
11781252
}
11791253
11801254
###############################################################################
11811255
# Page aliases. An alias in the configuration names a page and query
11821256
# parameters for it: "NAME=VALUE" sets a parameter, replacing one of the
11831257
# same name in the request; a name in capitals is taken in lower case;
11841258
# "NAME!" removes a parameter of the request.
11851259
1186
-fossil sql "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias','/test-env?a=new&Bb=2&gone!&absent!&fresh',0)"
1187
-fossil sql "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias2','/test-env?zz!',0)"
1188
-set cgiReply [cgi_admin [cgi_get "/cgialias?a=old&gone=1&keep=3"]]
1260
+fossil sql \
1261
+ "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias','/test-env?a=new&Bb=2&gone!&absent!&fresh',0)"
1262
+fossil sql \
1263
+ [join [list \
1264
+ "REPLACE INTO config(name,value,mtime) " \
1265
+ "VALUES('walias:/cgialias2','/test-env?zz!',0)"] ""]
1266
+set cgiReply [cgi_admin [request_get "/cgialias?a=old&gone=1&keep=3"]]
11891267
test_eq cgi-alias-replace [cgi_param $cgiReply a] new
11901268
test_eq cgi-alias-upper [cgi_param $cgiReply bb] 2
11911269
test_eq cgi-alias-delete [cgi_param $cgiReply gone] -
11921270
test_eq cgi-alias-add [cgi_param $cgiReply fresh] ""
11931271
test_eq cgi-alias-keep [cgi_param $cgiReply keep] 3
1194
-set cgiReply [cgi_admin [cgi_get "/cgialias2?m=1&zz=9"]]
1272
+set cgiReply [cgi_admin [request_get "/cgialias2?m=1&zz=9"]]
11951273
test {cgi-alias-delete-last} {[cgi_param $cgiReply zz] eq "-"
11961274
&& [cgi_param $cgiReply m] eq "1"}
11971275
11981276
###############################################################################
11991277
# The configuration page saves the text given for the main menu, unless
@@ -1201,12 +1279,13 @@
12011279
# removed and the text is not looked at.
12021280
12031281
proc cgi_menu_post {fields} {
12041282
global cgiToken
12051283
set body "$fields&csrf=$cgiToken"
1206
- set reply [cgi_admin "POST /setup_config HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_config\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body"]
1207
- return [list [lindex [cgi_status $reply] 1] \
1284
+ set reply [cgi_admin [cgi_post_from http://x/setup_config /setup_config \
1285
+ $body]]
1286
+ return [list [lindex [reply_status $reply] 1] \
12081287
[fossil sql "SELECT value FROM config WHERE name='mainmenu'"]]
12091288
}
12101289
test_eq cgi-menu-saved [cgi_menu_post "mmenu=cgi-menu-text&zlast=1"] \
12111290
{200 cgi-menu-text}
12121291
test_eq cgi-menu-reset [cgi_menu_post "mmenu=other-text&resetMenu=1&zlast=1"] \
@@ -1220,22 +1299,23 @@
12201299
# empty value is on, and one with the value "off" is off.
12211300
12221301
proc cgi_subscribe {email fields} {
12231302
global cgiToken
12241303
set body "submit=1&e=$email&$fields&csrf=$cgiToken"
1225
- cgi_admin "POST /subscribe HTTP/1.1\r\nHost: x\r\nReferer: http://x/subscribe\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body"
1226
- return [fossil sql "SELECT hex(suname), ssub FROM subscriber WHERE semail='$email'"]
1304
+ cgi_admin [cgi_post_from http://x/subscribe /subscribe $body]
1305
+ return [fossil sql \
1306
+ "SELECT hex(suname), ssub FROM subscriber WHERE semail='$email'"]
12271307
}
12281308
test_eq cgi-subscribe-no-name [cgi_subscribe [email protected] "sa=&sc=off"] \
12291309
"|a"
12301310
test_eq cgi-subscribe-blank-name \
12311311
[cgi_subscribe [email protected] "suname=+++&sa=0&sc=1"] "|c"
12321312
test_eq cgi-subscribe-line-ends \
12331313
[cgi_subscribe [email protected] "suname=+one%0D%0Atwo%0Dend&sa=1"] \
12341314
"6F6E650A74776F0D656E64|a"
12351315
# The form shows a box as checked for a value that is a word for "true".
1236
-set cgiReply [cgi_admin [cgi_get "/subscribe?submit=1&sa=on&sc=off&st=2"]]
1316
+set cgiReply [cgi_admin [request_get "/subscribe?submit=1&sa=on&sc=off&st=2"]]
12371317
test cgi-subscribe-checked-word {
12381318
[string match "*name=\"sa\" checked>*" $cgiReply]
12391319
&& [string match "*name=\"sc\" >*" $cgiReply]
12401320
&& [string match "*name=\"st\" >*" $cgiReply]}
12411321
@@ -1256,22 +1336,29 @@
12561336
return $RESULT
12571337
}
12581338
set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env
12591339
REMOTE_ADDR 127.0.0.1}]
12601340
test cgi-cgi-refused {[string match "Status: 400 Bad Request*" $cgiReply]
1261
- && [string match "*\nBad CGI Request: missing CONTENT_LENGTH on a POST method*" $cgiReply]}
1341
+ && [string match \
1342
+ "*\nBad CGI Request: missing CONTENT_LENGTH on a POST method*" \
1343
+ $cgiReply]}
12621344
set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env
12631345
REMOTE_ADDR 127.0.0.1 SERVER_SOFTWARE TestServer/1}]
12641346
test cgi-cgi-refused-server-named {
1265
- [string match "*\nBad CGI Request from \"TestServer/1\": missing CONTENT_LENGTH*" $cgiReply]}
1347
+ [string match \
1348
+ "*\nBad CGI Request from \"TestServer/1\": missing CONTENT_LENGTH*" \
1349
+ $cgiReply]}
12661350
set cgiReply [cgi_cgi {SCRIPT_NAME /s PATH_INFO /test-env REMOTE_ADDR 127.0.0.1
12671351
HTTP_HOST x HTTP_REFERER http://x/s/prev}]
12681352
test_eq cgi-cgi-no-method [cgi_csrf_level $cgiReply] "Same origin"
12691353
12701354
# A control file that names a debug file which cannot be opened is used
12711355
# all the same.
1272
-write_file cgi3.ctl "repository: [file nativename $cgiRepo]\nlocalauth\ncgi-debug: [file join [pwd] nosuchdir debug.txt]\n"
1356
+write_file cgi3.ctl \
1357
+ [join [list \
1358
+ "repository: [file nativename $cgiRepo]\nlocalauth\n" \
1359
+ "cgi-debug: [file join [pwd] nosuchdir debug.txt]\n"] ""]
12731360
set ::env(REQUEST_METHOD) GET
12741361
set ::env(SCRIPT_NAME) /s
12751362
set ::env(PATH_INFO) /test-env
12761363
set ::env(QUERY_STRING) "nodebug=1"
12771364
set ::env(REMOTE_ADDR) 127.0.0.1
@@ -1296,31 +1383,40 @@
12961383
test cgi-json-post-$cgiName-exit {$CODE == 0}
12971384
test cgi-json-post-$cgiName-reply \
12981385
{[string match "*FOSSIL-1101*" $cgiReply]}
12991386
}
13001387
set cgiReply [cgi_admin [cgi_post text/x-other {[1]} /json/version]]
1301
- test cgi-json-post-other-type {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1388
+ test cgi-json-post-other-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
13021389
&& [string match "*jsonApiVersion*" $cgiReply]}
13031390
set cgiReply [cgi_send [cgi_scgi {
13041391
CONTENT_LENGTH 8 CONTENT_TYPE application/json SCGI 1 REQUEST_METHOD POST
13051392
SCRIPT_NAME {} PATH_INFO /json/version SERVER_NAME x SERVER_PORT 80
13061393
REMOTE_ADDR 127.0.0.1 no_json 1
13071394
} "not json"] --scgi --localauth]
1308
- test cgi-json-no-json {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1395
+ test cgi-json-no-json {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
13091396
&& [string match "*jsonApiVersion*" $cgiReply]}
13101397
}
13111398
13121399
###############################################################################
13131400
# More of a connection over ssh. An older client, after its probes,
13141401
# sends a blank line twice and the command again before each further
13151402
# request. A request may name the repository file before the page.
13161403
13171404
set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
1318
-set cgiFirst "echo test1\nfossil\nGET /test-env?first=1 HTTP/1.1\r\nHost: x\r\nUser-Agent: First\r\nX-Fossil-Transport: other\r\n\r\n"
1319
-set cgiReply [cgi_send "$cgiFirst\n\nfossil\nGET /test-env?second=2 HTTP/1.1\r\nHost: x\r\nContent-Length: 0\r\nContent-Type: text/plain\r\nX-Fossil-Transport: ssh\r\n\r\n" --localauth]
1405
+set cgiFirst \
1406
+ [join [list \
1407
+ "echo test1\nfossil\nGET /test-env?first=1 HTTP/1.1\r\n" \
1408
+ "Host: x\r\nUser-Agent: First\r\n" \
1409
+ "X-Fossil-Transport: other\r\n\r\n"] ""]
1410
+set cgiReply [cgi_send \
1411
+ [join [list \
1412
+ "$cgiFirst\n\nfossil\nGET /test-env?second=2 HTTP/1.1\r\n" \
1413
+ "Host: x\r\nContent-Length: 0\r\nContent-Type: text/plain\r\n" \
1414
+ "X-Fossil-Transport: ssh\r\n\r\n"] ""] --localauth]
13201415
test cgi-ssh-flip {[string match "test1\n*" $cgiReply]
1321
- && [string match "*HTTP_USER_AGENT = First*first = 1*second = 2*" $cgiReply]}
1416
+ && [string match "*HTTP_USER_AGENT = First*first = 1*second = 2*" \
1417
+ $cgiReply]}
13221418
foreach {cgiName cgiMore cgiError} [list \
13231419
cut-short "\n" "incorrect transport_flip" \
13241420
not-blank "\nxyz\n" "transport_flip failed" \
13251421
other-command "\n\nother\n" "transport_open failed" \
13261422
no-request "\n\nfossil\n" "missing HTTP header" \
@@ -1335,52 +1431,72 @@
13351431
&& ![string match "*400 Bad Request*" $cgiReply]}
13361432
foreach {cgiName cgiRequest cgiError} [list \
13371433
probes-only "echo test1\nfossil\n" "missing HTTP header" \
13381434
blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \
13391435
"unsupported HTTP method" \
1340
- empty-command "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\nHost: x\r\n\r\n\n\nfossil\n" \
1436
+ empty-command \
1437
+ [join [list \
1438
+ "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\n" \
1439
+ "Host: x\r\n\r\n\n\nfossil\n"] ""] \
13411440
"transport_open failed" \
13421441
repository-only "GET $cgiRepo HTTP/1.1\r\nHost: x\r\n\r\n" \
13431442
"malformed URL in HTTP header" \
13441443
] {
13451444
set cgiReply [cgi_send $cgiRequest --localauth]
13461445
test cgi-ssh-$cgiName {$CODE == 0
13471446
&& [string match "*400 Bad Request*$cgiError*" $cgiReply]}
13481447
}
1349
-set cgiReply [cgi_send [cgi_get $cgiRepo/test-env?named=1] --localauth]
1448
+set cgiReply [cgi_send [request_get $cgiRepo/test-env?named=1] --localauth]
13501449
test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1"
13511450
&& [cgi_param $cgiReply PATH_INFO] eq "/test-env"}
13521451
# The name is taken off only when a "/" or the end follows it, and only
13531452
# for GET.
1354
-set cgiReply [cgi_send [cgi_get ${cgiRepo}x/test-env] --localauth]
1453
+set cgiReply [cgi_send [request_get ${cgiRepo}x/test-env] --localauth]
13551454
test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] -
1356
-set cgiReply [cgi_send [cgi_get $cgiRepo/test-env [list "Content-Length: 0"] \
1455
+set cgiReply [cgi_send [request_get $cgiRepo/test-env \
1456
+ [list "Content-Length: 0"] \
13571457
POST] --localauth]
13581458
test_eq cgi-ssh-repository-post [cgi_param $cgiReply PATH_INFO] -
13591459
# Later requests on one ssh connection: the second sends Content-Length
13601460
# before a longer header line and must get its length and body; the third
13611461
# is a GET with no Content-Length and must be served with a length of 0.
1362
-set cgiFirst "POST /test-env HTTP/1.1\r\nX-Fossil-Transport: SSH\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 3\r\n\r\na=1"
1363
-set cgiSecond "POST /test-env HTTP/1.1\r\nContent-Length: 3\r\nContent-Type: application/x-www-form-urlencoded-and-more\r\n\r\nb=2"
1462
+set cgiFirst \
1463
+ [join [list \
1464
+ "POST /test-env HTTP/1.1\r\nX-Fossil-Transport: SSH\r\n" \
1465
+ "Content-Type: application/x-www-form-urlencoded\r\n" \
1466
+ "Content-Length: 3\r\n\r\na=1"] ""]
1467
+set cgiSecond \
1468
+ [join [list \
1469
+ "POST /test-env HTTP/1.1\r\nContent-Length: 3\r\n" \
1470
+ "Content-Type: " \
1471
+ "application/x-www-form-urlencoded-and-more\r\n\r\nb=2"] ""]
13641472
set cgiThird "GET /test-env?c=3 HTTP/1.1\r\nHost: x\r\n\r\n"
13651473
set cgiReply [cgi_send $cgiFirst$cgiSecond$cgiThird --localauth]
13661474
test cgi-ssh-later-content-length {$CODE == 0 && [string match \
1367
- "*CONTENT_LENGTH = 3*a = 1*CONTENT_LENGTH = 3*b = 2*CONTENT_LENGTH = 0*c = 3*" \
1475
+ [join [list \
1476
+ "*CONTENT_LENGTH = 3*a = 1*CONTENT_LENGTH = 3*b = " \
1477
+ "2*CONTENT_LENGTH = 0*c = 3*"] ""] \
13681478
[regsub -all {<[^>]*>} $cgiReply {}]]}
13691479
unset ::env(SSH_CONNECTION)
13701480
13711481
###############################################################################
13721482
# A visitor who is not logged in reaches a page that is closed to robots
13731483
# with a token, and gets a cookie that opens the page afterwards. The
13741484
# same value given as a query parameter does not.
13751485
1376
-fossil sql "REPLACE INTO config(name,value,mtime) VALUES('robot-restrict','timeline',0)"
1377
-fossil sql "REPLACE INTO config(name,value,mtime) VALUES('token-cgitoken','{\"user\":\"someone\"}',0)"
1486
+fossil sql \
1487
+ [join [list \
1488
+ "REPLACE INTO config(name,value,mtime) " \
1489
+ "VALUES('robot-restrict','timeline',0)"] ""]
1490
+fossil sql \
1491
+ [join [list \
1492
+ "REPLACE INTO config(name,value,mtime) " \
1493
+ "VALUES('token-cgitoken','{\"user\":\"someone\"}',0)"] ""]
13781494
proc cgi_robot {path {cookie ""}} {
13791495
set headers [list "User-Agent: Agent/1"]
13801496
if {$cookie ne ""} { lappend headers "Cookie: $cookie" }
1381
- return [cgi_send [cgi_get $path $headers] --ipaddr 9.9.9.9]
1497
+ return [cgi_send [request_get $path $headers] --ipaddr 9.9.9.9]
13821498
}
13831499
set cgiRobot "*Checking to see if you are a robot*"
13841500
test cgi-robot-stopped {[string match $cgiRobot [cgi_robot /timeline]]}
13851501
set cgiReply [cgi_robot /timeline?token=cgitoken]
13861502
set cgiProof ""
@@ -1401,28 +1517,30 @@
14011517
###############################################################################
14021518
# A forum thread is shown in order of time to a phone and as a hierarchy
14031519
# to anything else, an iPad included. The page offers the other order.
14041520
14051521
set cgiFd [open post.txt wb]
1406
-puts -nonewline $cgiFd "D 2026-01-04T10:00:01.000\nH Cgi\\sthread\nU alice\nW 5\nhello\n"
1522
+puts -nonewline $cgiFd \
1523
+ "D 2026-01-04T10:00:01.000\nH Cgi\\sthread\nU alice\nW 5\nhello\n"
14071524
close $cgiFd
14081525
fossil md5sum post.txt
14091526
set cgiSum [lindex $RESULT 0]
14101527
set cgiFd [open post.txt ab]
14111528
puts -nonewline $cgiFd "Z $cgiSum\n"
14121529
close $cgiFd
14131530
fossil test-content-put --crosslink post.txt
1414
-set cgiPost [fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT fpid FROM forumpost LIMIT 1)"]
1531
+set cgiPost [fossil sql \
1532
+ "SELECT uuid FROM blob WHERE rid=(SELECT fpid FROM forumpost LIMIT 1)"]
14151533
foreach {cgiName cgiAgent cgiOther} {
14161534
phone "Mozilla/5.0 (iPhone; Mobile) Safari" Hierarchical
14171535
ipad "Mozilla/5.0 (iPad; Mobile) Safari" Chronological
14181536
desk "Mozilla/5.0 (X11; Linux)" Chronological
14191537
none "" Chronological
14201538
} {
14211539
set cgiHeaders {}
14221540
if {$cgiAgent ne ""} { lappend cgiHeaders "User-Agent: $cgiAgent" }
1423
- set cgiReply [cgi_admin [cgi_get /forumthread/$cgiPost?t=a $cgiHeaders]]
1541
+ set cgiReply [cgi_admin [request_get /forumthread/$cgiPost?t=a $cgiHeaders]]
14241542
test cgi-forum-order-$cgiName {[string match "*>Cgi thread<*" $cgiReply]
14251543
&& [string match "*?t=?\">$cgiOther</a>*" $cgiReply]}
14261544
}
14271545
14281546
###############################################################################
@@ -1431,28 +1549,34 @@
14311549
14321550
fossil user new cgiuser contact userpw
14331551
fossil user capabilities cgiuser o
14341552
proc cgi_login {fields} {
14351553
set body "u=cgiuser&p=userpw&in=Login&$fields"
1436
- return [cgi_send "POST /login HTTP/1.1\r\nHost: x\r\nReferer: http://x/login\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body" --ipaddr 9.9.9.9]
1554
+ return [cgi_send [cgi_post_from http://x/login /login $body] --ipaddr 9.9.9.9]
14371555
}
1438
-set cgiCookie [cgi_header [cgi_login x=1] Set-Cookie]
1439
-test cgi-login-session-cookie {[string match "fossil-*=*cgiuser; Path=*; HttpOnly;*" $cgiCookie]
1556
+set cgiCookie [reply_header [cgi_login x=1] Set-Cookie]
1557
+test cgi-login-session-cookie \
1558
+ {[string match "fossil-*=*cgiuser; Path=*; HttpOnly;*" $cgiCookie]
14401559
&& ![string match "*max-age*" $cgiCookie]}
1441
-set cgiCookie [cgi_header [cgi_login remember=1] Set-Cookie]
1442
-test cgi-login-lasting-cookie {[string match "fossil-*=*cgiuser; Path=*; max-age=*" $cgiCookie]}
1560
+set cgiCookie [reply_header [cgi_login remember=1] Set-Cookie]
1561
+test cgi-login-lasting-cookie \
1562
+ {[string match "fossil-*=*cgiuser; Path=*; max-age=*" $cgiCookie]}
14431563
14441564
###############################################################################
14451565
# A program under /ext that gives a status of 0 gets the usual "200 OK".
14461566
14471567
if {$::tcl_platform(platform) eq "unix"} {
14481568
file mkdir extroot
1449
- write_file extroot/status0.sh "#!/bin/sh\nprintf 'Status: 0 Nothing\\r\\nContent-Type: text/plain\\r\\n\\r\\nfrom the program\\n'\n"
1569
+ write_file extroot/status0.sh \
1570
+ [join [list \
1571
+ "#!/bin/sh\n" \
1572
+ "printf 'Status: 0 Nothing\\r\\nContent-Type: " \
1573
+ "text/plain\\r\\n\\r\\nfrom the program\\n'\n"] ""]
14501574
file attributes extroot/status0.sh -permissions 0755
1451
- set cgiReply [cgi_admin [cgi_get /ext/status0.sh] \
1575
+ set cgiReply [cgi_admin [request_get /ext/status0.sh] \
14521576
--extroot [file join [pwd] extroot]]
1453
- test cgi-ext-status-zero {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1577
+ test cgi-ext-status-zero {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
14541578
&& [string match "*from the program*" $cgiReply]
14551579
&& ![string match "*printf*" $cgiReply]}
14561580
}
14571581
14581582
###############################################################################
@@ -1481,11 +1605,12 @@
14811605
cgi cgi5.ctl]
14821606
cd $cgiHere
14831607
file delete -force $cgiDir
14841608
test cgi-cgi-no-repository {$CODE == 1
14851609
&& [string match "Status: 500 Internal Server Error*" $cgiReply]
1486
- && [string match "*Unable to find or open the project repository" $cgiReply]}
1610
+ && [string match "*Unable to find or open the project repository" \
1611
+ $cgiReply]}
14871612
set cgiReply [cgi_run_with {GATEWAY_INTERFACE CGI/1.1 REQUEST_METHOD GET
14881613
SCRIPT_NAME /s PATH_INFO /home}]
14891614
test cgi-cgi-no-control-file {$CODE == 1
14901615
&& [string match "Status: 500 Internal Server Error*" $cgiReply]
14911616
&& [string match "*No CGI control file specified" $cgiReply]}
@@ -1497,24 +1622,24 @@
14971622
write_file cgi6.ctl "#!/usr/bin/fossil\nredirect: * $cgiTarget\n"
14981623
set cgiReply [cgi_run_with {REQUEST_METHOD GET HTTP_HOST x SCRIPT_NAME /s
14991624
PATH_INFO /abc QUERY_STRING q=1} cgi cgi6.ctl]
15001625
test cgi-cgi-redirect-$cgiName {$CODE == 0
15011626
&& [string match "Status: 301 Moved Permanently*" $cgiReply]
1502
- && [cgi_header "$cgiReply\r\n\r\n" Location] eq $cgiLocation}
1627
+ && [reply_header "$cgiReply\r\n\r\n" Location] eq $cgiLocation}
15031628
}
15041629
15051630
###############################################################################
15061631
# The setup page warns of a page header that has no "base" element, and
15071632
# does not when the header has one, as the built-in header does.
15081633
1509
-set cgiReply [cgi_admin [cgi_get /setup]]
1510
-test cgi-setup-base-present {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1634
+set cgiReply [cgi_admin [request_get /setup]]
1635
+test cgi-setup-base-present {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
15111636
&& ![string match "*Configuration Error*" $cgiReply]}
15121637
fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header',
15131638
'<html><head><title>plain</title></head><body>',now())"
1514
-set cgiReply [cgi_admin [cgi_get /setup]]
1515
-test cgi-setup-base-missing {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1639
+set cgiReply [cgi_admin [request_get /setup]]
1640
+test cgi-setup-base-missing {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
15161641
&& [string match "*Configuration Error*base href=*" $cgiReply]}
15171642
15181643
# The TH1 command "redirect" in a page header sends the client to
15191644
# another page: with "302", or with "307" when its second argument is
15201645
# true, which tells the client to repeat the request as it made it.
@@ -1522,13 +1647,13 @@
15221647
plain {redirect /stat} {HTTP/1.0 302 Moved Temporarily}
15231648
method {redirect /stat 1} {HTTP/1.0 307 Temporary Redirect}
15241649
} {
15251650
fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header',
15261651
'<html><head></head><body><th1>$cgiScript</th1>',now())"
1527
- set cgiReply [cgi_admin [cgi_get /timeline]]
1528
- test cgi-th1-redirect-$cgiName {[cgi_status $cgiReply] eq $cgiStatus
1529
- && [cgi_header $cgiReply Location] eq "http://x/stat"}
1652
+ set cgiReply [cgi_admin [request_get /timeline]]
1653
+ test cgi-th1-redirect-$cgiName {[reply_status $cgiReply] eq $cgiStatus
1654
+ && [reply_header $cgiReply Location] eq "http://x/stat"}
15301655
}
15311656
fossil sql "DELETE FROM config WHERE name='header'"
15321657
15331658
# The same command run from the command line, where there is no request
15341659
# to answer, is an error.
@@ -1555,14 +1680,14 @@
15551680
# and has no table in its content; a page with a table gets the ad unit
15561681
# for the top of the page.
15571682
15581683
fossil sql "REPLACE INTO config(name,value,mtime) VALUES
15591684
('adunit-right','<b>ADRIGHT</b>',now()),('adunit','<b>ADTOP</b>',now())"
1560
-set cgiReply [cgi_admin [cgi_get /sitemap]]
1685
+set cgiReply [cgi_admin [request_get /sitemap]]
15611686
test cgi-adunit-right {[string match "*ADRIGHT*" $cgiReply]
15621687
&& ![string match "*ADTOP*" $cgiReply]}
1563
-set cgiReply [cgi_admin [cgi_get /brlist]]
1688
+set cgiReply [cgi_admin [request_get /brlist]]
15641689
test cgi-adunit-top-with-table {[string match "*ADTOP*" $cgiReply]
15651690
&& ![string match "*ADRIGHT*" $cgiReply]}
15661691
fossil sql "DELETE FROM config WHERE name IN ('adunit-right','adunit')"
15671692
15681693
###############################################################################
@@ -1570,16 +1695,16 @@
15701695
# /file with no file name lists the files of the check-in "tip", and
15711696
# its links carry "ci=tip". /timeline with "r=BRANCH" shows the branch
15721697
# and what is related to it, and its form keeps that as "t=BRANCH" and
15731698
# "rel".
15741699
1575
-set cgiReply [cgi_admin [cgi_get /file]]
1576
-test cgi-file-no-name {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1700
+set cgiReply [cgi_admin [request_get /file]]
1701
+test cgi-file-no-name {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
15771702
&& [string match "*Top-level Files of tip*" $cgiReply]
15781703
&& [string match "*ci=tip*" $cgiReply]}
1579
-set cgiReply [cgi_admin [cgi_get /timeline?r=trunk]]
1580
-test cgi-timeline-r {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1704
+set cgiReply [cgi_admin [request_get /timeline?r=trunk]]
1705
+test cgi-timeline-r {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
15811706
&& [string match "*name=\"rel\" value=\"1\"*" $cgiReply]
15821707
&& [string match "*name=\"t\" value=\"trunk\"*" $cgiReply]}
15831708
15841709
###############################################################################
15851710
# An unversioned file whose time of change is too far in the future to
@@ -1588,15 +1713,15 @@
15881713
15891714
write_file late.css "p{}\n"
15901715
fossil uv add late.css
15911716
fossil sql "UPDATE unversioned SET mtime=1000000000000000000
15921717
WHERE name='late.css'"
1593
-set cgiReply [cgi_send [cgi_get /uv/late.css] --ipaddr 127.0.0.1]
1718
+set cgiReply [cgi_send [request_get /uv/late.css] --ipaddr 127.0.0.1]
15941719
test cgi-last-modified-out-of-range {
1595
- [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1720
+ [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
15961721
&& [string match "*\r\nLast-Modified: \r\n*" $cgiReply]
1597
- && [cgi_body $cgiReply] eq "p{}\n"}
1722
+ && [reply_body $cgiReply] eq "p{}\n"}
15981723
fossil uv rm late.css
15991724
16001725
###############################################################################
16011726
# "fossil server" itself, where it listens with its own code (not on
16021727
# Windows). A server that cannot listen where it was told says why and
@@ -1624,11 +1749,13 @@
16241749
bad-ipv6 {--port {[zz::1]:8111}} \
16251750
"not a valid IPv6 address: zz::1" \
16261751
other-ipv4 {--port 192.0.2.1:8111} \
16271752
"cannot open a listening socket on 192.0.2.1:8111" \
16281753
other-ipv6 {--port {[2001:db8::1]:8111}} \
1629
- "cannot open a listening socket on \\\[2001:db8::1\\\]:8111" \
1754
+ [join [list \
1755
+ "cannot open a listening socket on " \
1756
+ "\\\[2001:db8::1\\\]:8111"] ""] \
16301757
port-in-use [list --localhost --port $cgiPort] \
16311758
"no available TCP ports in the range $cgiPort..$cgiPort" \
16321759
socket-name-long [list --socket-name [string repeat s 200]] \
16331760
"name of unix socket too big" \
16341761
socket-name-taken {--socket-name notsocket} \
@@ -1638,75 +1765,102 @@
16381765
test cgi-server-refused-$cgiName {$CODE == 1
16391766
&& [string match "*$cgiError*" $RESULT]}
16401767
}
16411768
close $cgiListener
16421769
1770
+ # Run SCRIPT every ten milliseconds until it returns true, for at most
1771
+ # five seconds, and return what it last returned.
1772
+ proc cgi_wait {script} {
1773
+ for {set i 0} {$i < 500} {incr i} {
1774
+ if {[uplevel 1 $script]} {return 1}
1775
+ after 10
1776
+ }
1777
+ return 0
1778
+ }
1779
+ # True if the process PID has not ended.
1780
+ proc cgi_running {pid} {
1781
+ return [expr {![catch {exec kill -0 $pid}]}]
1782
+ }
1783
+ # Wait for the server PID to print that it listens, and return true
1784
+ # once it has. A server that ends without listening ends the wait.
1785
+ proc cgi_listening {pid} {
1786
+ cgi_wait {expr {[string match "*Listening for*" [read_file server.out]]
1787
+ || ![cgi_running $pid]}}
1788
+ return [string match "*Listening for*" [read_file server.out]]
1789
+ }
1790
+ # Connect to HOST and PORT and return the socket. A server prints
1791
+ # that it listens before it accepts connections, so a connection that
1792
+ # fails is tried again.
1793
+ proc cgi_connect {host port} {
1794
+ cgi_wait {expr {![catch {socket $host $port} sock]}}
1795
+ fconfigure $sock -translation binary
1796
+ return $sock
1797
+ }
16431798
# Send REQUEST to HOST and PORT and return the reply, waiting at most
16441799
# ten seconds for the end of it. With "unix" for HOST, PORT is the
16451800
# name of a unix socket, and the program "nc" carries the request.
16461801
proc cgi_client {host port request} {
16471802
if {$host eq "unix"} {
1648
- return [exec nc -w 10 -U $port << $request]
1803
+ cgi_wait {expr {![catch {exec nc -w 10 -U $port << $request} reply]
1804
+ || ![string match "*refused*" $reply]}}
1805
+ return $reply
16491806
}
1650
- set sock [socket $host $port]
1651
- fconfigure $sock -translation binary -blocking 0
1807
+ set sock [cgi_connect $host $port]
1808
+ fconfigure $sock -blocking 0
16521809
puts -nonewline $sock $request
16531810
flush $sock
16541811
set reply ""
1655
- for {set i 0} {$i < 200 && ![eof $sock]} {incr i} {
1656
- append reply [read $sock]
1657
- after 50
1812
+ for {set i 0} {$i < 2000 && ![eof $sock]} {incr i} {
1813
+ set part [read $sock]
1814
+ append reply $part
1815
+ if {$part eq ""} {after 5}
16581816
}
16591817
close $sock
16601818
return $reply
16611819
}
16621820
# Start a server with OPTIONS that answers one request and stops, send
16631821
# it REQUEST at HOST and PORT, and return what the server printed and
16641822
# the reply. The server is killed if it has not stopped by itself.
1665
- proc cgi_serve_once {options host port request {command server}} {
1823
+ # The request is sent IDLE milliseconds after the server starts to
1824
+ # listen.
1825
+ proc cgi_serve_once {options host port request {command server} {idle 0}} {
16661826
global fossilexe cgiRepo
16671827
file delete server.out
16681828
set pid [exec $fossilexe $command --debug-nofork --localauth {*}$options \
16691829
$cgiRepo >& server.out &]
16701830
set reply ""
1671
- for {set i 0} {$i < 100} {incr i} {
1672
- after 100
1673
- if {[string match "*Listening for*" [read_file server.out]]} {
1674
- after 300
1675
- catch {set reply [cgi_client $host $port $request]}
1676
- break
1677
- }
1678
- }
1679
- for {set i 0} {$i < 50 && ![catch {exec kill -0 $pid}]} {incr i} {
1680
- after 100
1681
- }
1831
+ if {[cgi_listening $pid]} {
1832
+ after $idle
1833
+ catch {set reply [cgi_client $host $port $request]}
1834
+ }
1835
+ cgi_wait {expr {![cgi_running $pid]}}
16821836
catch {exec kill -9 $pid}
16831837
return [list [string trim [read_file server.out]] $reply]
16841838
}
16851839
16861840
# An IPv4 address, by number and as "localhost".
16871841
foreach {cgiName cgiHost} {ipv4 127.0.0.1 localhost localhost} {
16881842
set cgiPort [cgi_free_port]
16891843
lassign [cgi_serve_once [list --port $cgiHost:$cgiPort] 127.0.0.1 \
1690
- $cgiPort [cgi_get /test-env]] cgiPrinted cgiReply
1844
+ $cgiPort [request_get /test-env]] cgiPrinted cgiReply
16911845
test_eq cgi-server-$cgiName-printed $cgiPrinted \
16921846
"Listening for HTTP requests on TCP port 127.0.0.1:$cgiPort"
16931847
test cgi-server-$cgiName-reply {
1694
- [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1848
+ [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
16951849
&& [cgi_param $cgiReply REMOTE_ADDR] eq "127.0.0.1"}
16961850
}
16971851
# "fossil ui" starts the browser on the address it listens on. The
16981852
# browser here is "echo".
16991853
fossil settings web-browser echo
17001854
fossil settings web-browser
17011855
if {[string match "*echo*" $RESULT]} {
17021856
set cgiPort [cgi_free_port]
17031857
lassign [cgi_serve_once [list --port 127.0.0.1:$cgiPort] 127.0.0.1 \
1704
- $cgiPort [cgi_get /test-env] ui] cgiPrinted cgiReply
1858
+ $cgiPort [request_get /test-env] ui] cgiPrinted cgiReply
17051859
test cgi-server-ui-browser {
17061860
[string match "*\nhttp://127.0.0.1:$cgiPort/*" \n$cgiPrinted]
1707
- && [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"}
1861
+ && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"}
17081862
}
17091863
# SCGI in place of HTTP.
17101864
set cgiPort [cgi_free_port]
17111865
lassign [cgi_serve_once [list --scgi --port 127.0.0.1:$cgiPort] 127.0.0.1 \
17121866
$cgiPort [cgi_scgi {
@@ -1721,38 +1875,44 @@
17211875
if {![catch {cgi_busy_port ::1} cgiBusy]} {
17221876
close [lindex $cgiBusy 0]
17231877
# An IPv6 address.
17241878
set cgiPort [cgi_free_port]
17251879
lassign [cgi_serve_once [list --port \[::1\]:$cgiPort] ::1 $cgiPort \
1726
- [cgi_get /test-env]] cgiPrinted cgiReply
1880
+ [request_get /test-env]] cgiPrinted cgiReply
17271881
test_eq cgi-server-ipv6-printed $cgiPrinted \
17281882
"Listening for HTTP requests on \[::1\]:$cgiPort"
1729
- test cgi-server-ipv6-reply {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1883
+ test cgi-server-ipv6-reply {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
17301884
&& [cgi_param $cgiReply REMOTE_ADDR] eq "::1"}
17311885
# With no address the server listens on both kinds of loopback
1732
- # address, or on IPv4 alone if the port is taken for IPv6.
1886
+ # address, or on IPv4 alone if the port is taken for IPv6. The
1887
+ # server waits a tenth of a second at a time for a connection, and
1888
+ # this request leaves it waiting for two of them with none.
17331889
set cgiPort [cgi_free_port]
17341890
lassign [cgi_serve_once [list --localhost --port \[\]:$cgiPort] ::1 \
1735
- $cgiPort [cgi_get /test-env]] cgiPrinted cgiReply
1891
+ $cgiPort [request_get /test-env] server 200] cgiPrinted cgiReply
17361892
test_eq cgi-server-both-printed $cgiPrinted \
1737
- "Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 and IPv6"
1893
+ [join [list \
1894
+ "Listening for HTTP requests on TCP port " \
1895
+ "localhost:$cgiPort, IPv4 and IPv6"] ""]
17381896
test_eq cgi-server-both-reply [cgi_param $cgiReply REMOTE_ADDR] ::1
17391897
lassign [cgi_busy_port ::1] cgiListener cgiPort
17401898
lassign [cgi_serve_once [list --localhost --port $cgiPort] 127.0.0.1 \
1741
- $cgiPort [cgi_get /test-env]] cgiPrinted cgiReply
1899
+ $cgiPort [request_get /test-env]] cgiPrinted cgiReply
17421900
close $cgiListener
17431901
test_eq cgi-server-ipv4-only-printed $cgiPrinted \
17441902
"Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 only"
1745
- test_eq cgi-server-ipv4-only-reply [cgi_status $cgiReply] "HTTP/1.0 200 OK"
1903
+ test_eq cgi-server-ipv4-only-reply [reply_status $cgiReply] \
1904
+ "HTTP/1.0 200 OK"
17461905
# With a port and neither an address nor --localhost the server
17471906
# listens on every address of the machine.
17481907
set cgiPort [cgi_free_port]
17491908
lassign [cgi_serve_once [list --port $cgiPort] 127.0.0.1 \
1750
- $cgiPort [cgi_get /login]] cgiPrinted cgiReply
1909
+ $cgiPort [request_get /login]] cgiPrinted cgiReply
17511910
test_eq cgi-server-any-address-printed $cgiPrinted \
17521911
"Listening for HTTP requests on TCP port $cgiPort, IPv4 and IPv6"
1753
- test_eq cgi-server-any-address-reply [cgi_status $cgiReply] "HTTP/1.0 200 OK"
1912
+ test_eq cgi-server-any-address-reply [reply_status $cgiReply] \
1913
+ "HTTP/1.0 200 OK"
17541914
}
17551915
17561916
# A unix socket in place of a port. The server makes the socket, and
17571917
# takes the place of a socket of the same name that is left from an
17581918
# earlier server. --socket-owner names the owner of the socket.
@@ -1762,15 +1922,15 @@
17621922
foreach {cgiName cgiOptions} [list \
17631923
new {--socket-name sock1} \
17641924
replaced {--socket-name sock1} \
17651925
owner [list --socket-owner $cgiUser --socket-name sock1] \
17661926
] {
1767
- lassign [cgi_serve_once $cgiOptions unix sock1 [cgi_get /login]] \
1927
+ lassign [cgi_serve_once $cgiOptions unix sock1 [request_get /login]] \
17681928
cgiPrinted cgiReply
17691929
test cgi-server-unix-$cgiName {
17701930
$cgiPrinted eq "Listening for HTTP requests on unix socket sock1"
1771
- && [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1931
+ && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
17721932
&& [file type sock1] eq "socket"
17731933
&& [file attributes sock1 -owner] eq $cgiUser}
17741934
}
17751935
# --socket-mode gives the permissions of the socket; without it they
17761936
# are 0660.
@@ -1777,15 +1937,15 @@
17771937
foreach {cgiName cgiOptions cgiMode} {
17781938
mode {--socket-mode 0600 --socket-name sock2} 600
17791939
default {--socket-name sock2} 660
17801940
} {
17811941
file delete sock2
1782
- lassign [cgi_serve_once $cgiOptions unix sock2 [cgi_get /login]] \
1942
+ lassign [cgi_serve_once $cgiOptions unix sock2 [request_get /login]] \
17831943
cgiPrinted cgiReply
17841944
test cgi-server-unix-$cgiName {
17851945
$cgiPrinted eq "Listening for HTTP requests on unix socket sock2"
1786
- && [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1946
+ && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
17871947
&& [format %o [expr {[file attributes sock2 -permissions] & 0o777}]]
17881948
eq $cgiMode}
17891949
}
17901950
fossil_raw -seconds 30 server --socket-mode rw --socket-name sock3 $cgiRepo
17911951
test cgi-server-unix-mode-not-a-number {$CODE == 1 && [string match \
@@ -1801,25 +1961,25 @@
18011961
proc cgi_serve_start {options {command server} {wrap {}}} {
18021962
global fossilexe cgiRepo
18031963
file delete server.out server.err
18041964
set pid [exec {*}$wrap $fossilexe $command --localauth {*}$options \
18051965
$cgiRepo > server.out 2> server.err &]
1806
- for {set i 0} {$i < 100} {incr i} {
1807
- after 100
1808
- if {[string match "*Listening for*" [read_file server.out]]} break
1809
- }
1810
- after 300
1966
+ cgi_listening $pid
18111967
return $pid
18121968
}
18131969
# Stop the server with process id PID: ask it to end, and kill it if
18141970
# it has not ended after five seconds.
18151971
proc cgi_serve_stop {pid} {
18161972
catch {exec kill $pid}
1817
- for {set i 0} {$i < 50 && ![catch {exec kill -0 $pid}]} {incr i} {
1818
- after 100
1819
- }
1973
+ cgi_wait {expr {![cgi_running $pid]}}
18201974
catch {exec kill -9 $pid}
1975
+ }
1976
+ # The process ids of the processes that the server PID has started
1977
+ # for requests and has not yet found to have ended.
1978
+ proc cgi_children {pid} {
1979
+ if {[catch {exec pgrep -P $pid} children]} {return {}}
1980
+ return $children
18211981
}
18221982
18231983
# A process that handles a request is killed before the request is
18241984
# complete. The server goes on to answer the next request, and one
18251985
# that traces its work reports the signal that ended the process.
@@ -1831,28 +1991,27 @@
18311991
set cgiPort [cgi_free_port]
18321992
set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort \
18331993
{*}$cgiOptions]]
18341994
set cgiReply ""
18351995
catch {
1836
- set cgiSock [socket 127.0.0.1 $cgiPort]
1837
- fconfigure $cgiSock -translation binary
1996
+ set cgiSock [cgi_connect 127.0.0.1 $cgiPort]
18381997
puts -nonewline $cgiSock "GET /login HTTP/1.1\r\n"
18391998
flush $cgiSock
1840
- after 500
1841
- exec kill -9 {*}[exec pgrep -P $cgiPid]
1842
- after 500
1999
+ cgi_wait {llength [cgi_children $cgiPid]}
2000
+ exec kill -9 {*}[cgi_children $cgiPid]
2001
+ cgi_wait {expr {[cgi_children $cgiPid] eq ""}}
18432002
close $cgiSock
1844
- set cgiReply [cgi_client 127.0.0.1 $cgiPort [cgi_get /login]]
2003
+ set cgiReply [cgi_client 127.0.0.1 $cgiPort [request_get /login]]
2004
+ cgi_wait {expr {[cgi_children $cgiPid] eq ""}}
18452005
}
18462006
cgi_serve_stop $cgiPid
18472007
test cgi-server-child-killed-$cgiName {
1848
- [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
2008
+ [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
18492009
&& ($cgiReport eq ""
18502010
? ![string match "*exited on signal*" [read_file server.err]]
18512011
: [string match $cgiReport [read_file server.err]])}
18522012
}
1853
- foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog }
18542013
} else {
18552014
test_skip_part "no pgrep program: the killed server process tests"
18562015
}
18572016
18582017
# A server that is not allowed another process cannot start the
@@ -1864,11 +2023,11 @@
18642023
&& [auto_execok bash] ne ""} {
18652024
set cgiPort [cgi_free_port]
18662025
set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort] ui \
18672026
[list bash -c {ulimit -u 1 && exec "$@"} bash]]
18682027
set cgiReply unset
1869
- catch {set cgiReply [cgi_client 127.0.0.1 $cgiPort [cgi_get /login]]}
2028
+ catch {set cgiReply [cgi_client 127.0.0.1 $cgiPort [request_get /login]]}
18702029
set cgiAlive [expr {![catch {exec kill -0 $cgiPid}]}]
18712030
cgi_serve_stop $cgiPid
18722031
test cgi-server-no-process-browser {[string match \
18732032
"*cannot start browser: echo*" [read_file server.err]]}
18742033
test cgi-server-no-process-request {$cgiReply eq "" && $cgiAlive}
18752034
--- test/cgi.test
+++ test/cgi.test
@@ -5,15 +5,10 @@
5 # the parameters the server read from the request.
6 #
7 # Plain HTTP, the same request arriving over ssh, and SCGI.
8 #
9
10 # These tests run only in a long pass: -assurance stress.
11 if {[test_assurance] ne "stress"} {
12 test_skip "runs only with -assurance stress"
13 }
14
15 test_setup
16
17 write_file a.txt "an unversioned file\n"
18 fossil uv add a.txt
19 set cgiRepo [file join [pwd] .rep.fossil]
@@ -20,28 +15,18 @@
20
21 # Send the request in TEXT, a string of bytes, to the server and return
22 # the reply. ARGS are more options for "fossil http".
23 #
24 proc cgi_send {text args} {
25 global cgiRepo
26 write_file request.txt $text
27 file delete reply.txt
28 fossil_raw http $cgiRepo --in request.txt --out reply.txt {*}$args
29 if {[file exists reply.txt]} { return [read_file reply.txt] }
30 return ""
31 }
32
33 # The same, as a local administrator.
34 proc cgi_admin {text args} {
35 return [cgi_send $text --ipaddr 127.0.0.1 --localauth {*}$args]
36 }
37
38 # The status line of a reply.
39 proc cgi_status {reply} {
40 return [string trim [lindex [split $reply \n] 0]]
41 }
42
43 # The value of parameter NAME as /test-env shows it, or "-" if it does
44 # not show it.
45 proc cgi_param {reply name} {
46 set start [string first "\n$name = " $reply]
47 if {$start < 0} { return - }
@@ -49,47 +34,29 @@
49 set end [string first " <br>" $reply $start]
50 if {$end < 0} { return - }
51 return [string range $reply $start [expr {$end - 1}]]
52 }
53
54 # The value of header NAME in a reply, or "-" if the reply has no such
55 # header.
56 proc cgi_header {reply name} {
57 set end [string first "\r\n\r\n" $reply]
58 foreach line [split [string range $reply 0 $end] \n] {
59 if {[string match -nocase "$name: *" $line]} {
60 return [string trim [string range $line [string length $name]+1 end]]
61 }
62 }
63 return -
64 }
65
66 # The content of a reply: what follows its headers.
67 proc cgi_body {reply} {
68 set end [string first "\r\n\r\n" $reply]
69 if {$end < 0} { return "" }
70 return [string range $reply $end+4 end]
71 }
72
73 # A GET request for PATH with the header lines in HEADERS, a list.
74 proc cgi_get {path {headers {}} {method GET}} {
75 set text "$method $path HTTP/1.1\r\nHost: x\r\n"
76 foreach line $headers { append text $line "\r\n" }
77 return "$text\r\n"
78 }
79
80 # A POST request with BODY as its content.
81 proc cgi_post {type body {path /test-env}} {
82 return "POST $path HTTP/1.1\r\nHost: x\r\nContent-Type: $type\r\nContent-Length: [string length $body]\r\n\r\n$body"
83 }
84
85 ###############################################################################
86 # Plain HTTP.
87
88 set cgiReply [cgi_admin "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"]
 
89 test cgi-get {$CODE == 0}
90 test_eq cgi-get-status [cgi_status $cgiReply] "HTTP/1.0 200 OK"
91 test_eq cgi-get-plain [cgi_param $cgiReply a] 1
92 test_eq cgi-get-plus [cgi_param $cgiReply b] "two words"
93 test_eq cgi-get-escape [cgi_param $cgiReply c] AB
94 test_eq cgi-get-empty [cgi_param $cgiReply d] ""
95 test_eq cgi-get-no-value [cgi_param $cgiReply e] ""
@@ -104,22 +71,26 @@
104 no-method "\r\n\r\n" \
105 bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \
106 ] {
107 set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1]
108 test cgi-malformed-$cgiName \
109 {[string match "HTTP/1.0 40*" [cgi_status $cgiReply]]}
110 }
111
112 # A request line with no path is a request for the home page.
113 set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1]
114 test_eq cgi-no-path [cgi_status $cgiReply] "HTTP/1.0 302 Moved Temporarily"
115
116 ###############################################################################
117 # Form data in several parts, as a browser sends an upload.
118
119 proc cgi_part {name body {extra ""}} {
120 return "--XB\r\nContent-Disposition: form-data; name=\"$name\"$extra\r\n\r\n$body\r\n"
 
 
 
 
121 }
122 set cgiType "multipart/form-data; boundary=XB"
123
124 set cgiReply [cgi_admin [cgi_post $cgiType \
125 "[cgi_part alpha {first value}][cgi_part upload {file body} \
@@ -128,11 +99,16 @@
128 test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body"
129 test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt
130 test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9
131
132 set cgiReply [cgi_admin [cgi_post $cgiType \
133 "--XB\r\nContent-Disposition: form-data; name=\"t\"; filename=\"t.bin\"\r\nContent-Type: application/octet-stream\r\n\r\nxyz\r\n--XB--\r\n"]]
 
 
 
 
 
134 test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \
135 application/octet-stream
136
137 # A name that begins with a capital is taken in lower case.
138 set cgiReply [cgi_admin [cgi_post $cgiType \
@@ -146,11 +122,14 @@
146 test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value
147
148 # A part with no closing boundary after a long one ends at the end of the
149 # request, and every part is read within the request.
150 set cgiReply [cgi_admin [cgi_post $cgiType \
151 "[cgi_part alpha [string repeat x 3000]]--XB\r\nContent-Disposition: form-data; name=\"beta\"\r\n\r\nno closing boundary"]]
 
 
 
152 test cgi-multipart-unclosed {$CODE == 0}
153 test_eq cgi-multipart-unclosed-first \
154 [string length [cgi_param $cgiReply alpha]] 3000
155 test_eq cgi-multipart-unclosed-second [cgi_param $cgiReply beta] \
156 "no closing boundary"
@@ -163,19 +142,36 @@
163 "--XB" \
164 "--XB\r\n" \
165 "--XB\r\n\r\nno name here\r\n--XB--\r\n" \
166 "--XB\r\nContent-Disposition: form-data; name=\"a\"" \
167 "[cgi_part a "one\000two"]--XB--\r\n" \
168 "--XB\r\nContent-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n--XB--\r\n" \
169 "--[string repeat B 3000]\r\nContent-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n" \
170 "[cgi_part a [string repeat x 2000]]--XB\r\nContent-Disposition: form-data; name=\"b\"" \
 
 
 
 
 
 
 
171 "[cgi_part {} v]--XB--\r\n" \
172 "--XB\r\nContent-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n--XB--\r\n" \
173 "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\nv\r\n--XB--\r\n" \
 
 
 
 
 
174 "--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \
175 "--XB\r\nContent-Disposition: form-data; name=\"a\"; filename=\r\n\r\nv\r\n--XB--\r\n" \
176 "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\ncontent-type:\r\n\r\nv\r\n--XB--\r\n" \
 
 
 
 
 
177 "[cgi_part a "\n--X"]--XB--\r\n" \
178 ] {
179 incr cgiI
180 cgi_admin [cgi_post $cgiType $cgiBody]
181 test cgi-multipart-odd-$cgiI {$CODE == 0}
@@ -190,12 +186,14 @@
190 ###############################################################################
191 # The date in an If-Modified-Since header. A file that has not changed
192 # since that date is not sent again.
193
194 proc cgi_since {date} {
195 set reply [cgi_send "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" --ipaddr 127.0.0.1]
196 return [cgi_status $reply]
 
 
197 }
198 test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \
199 "HTTP/1.0 304 Not Modified"
200 test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \
201 "HTTP/1.0 200 OK"
@@ -220,24 +218,29 @@
220 g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1
221 g.ico 1 g.png 0 g.zip 0 g.pdf 0
222 } {
223 write_file $cgiName [string repeat "content to compress\n" 50]
224 fossil uv add $cgiName
225 set cgiReply [cgi_send "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\nAccept-Encoding: gzip, deflate\r\n\r\n" --ipaddr 127.0.0.1]
 
 
 
226 test_eq cgi-gzip-$cgiName \
227 [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip
228 }
229 set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" --ipaddr 127.0.0.1]
230 test cgi-gzip-not-accepted {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
 
231 && ![string match "*Content-Encoding*" $cgiReply]}
232
233 ###############################################################################
234 # A POST whose Referer is another site is not taken as safe from forgery,
235 # and is written to the error log.
236
237 proc cgi_logout {referer} {
238 return [cgi_send "POST /login HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 5\r\n\r\nout=1" --ipaddr 10.0.0.1 --errorlog [file join [pwd] err.log]]
 
239 }
240 file delete err.log
241 cgi_logout http://x/login
242 test cgi-same-origin-not-logged {![file exists err.log]
243 || ![string match "*different origin*" [read_file err.log]]}
@@ -257,11 +260,11 @@
257 set cgiReply [cgi_send [cgi_scgi {
258 CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1
259 PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80
260 REMOTE_ADDR 127.0.0.1
261 }] --scgi --localauth]
262 test_eq cgi-scgi [cgi_status $cgiReply] "HTTP/1.0 200 OK"
263 test_eq cgi-scgi-param [cgi_param $cgiReply s] 1
264
265 foreach {cgiName cgiRequest} [list \
266 too-short "15:CONTENT_LENGTH\0000\000," \
267 cut-short "40:CONTENT_LENGTH\0000\000," \
@@ -268,20 +271,21 @@
268 no-zero "20:CONTENT_LENGTH0000000000," \
269 huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \
270 ] {
271 set cgiReply [cgi_send $cgiRequest --scgi]
272 test cgi-scgi-$cgiName {$CODE == 0 &&
273 [string match "HTTP/1.0 400*" [cgi_status $cgiReply]]}
274 }
275
276 ###############################################################################
277 # The same reader for a request that arrives over ssh, which the server
278 # knows from SSH_CONNECTION. It reads the client's probes first.
279
280 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
281 set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" --localauth]
282 test_eq cgi-ssh [cgi_status $cgiReply] "HTTP/1.0 200 OK"
 
283 test_eq cgi-ssh-param [cgi_param $cgiReply q] 1
284 test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1
285
286 set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \
287 "p=posted"] --localauth]
@@ -288,11 +292,14 @@
288 test_eq cgi-ssh-post [cgi_param $cgiReply p] posted
289
290 # An older client opens the connection with "echo" probes, each of which
291 # the server answers with the word it was given, and then names the
292 # command it ran. Any other word in a probe is refused.
293 set cgiReply [cgi_send "echo test1\necho probe-2\nfossil\nGET /test-env?q=3 HTTP/1.1\r\nHost: x\r\n\r\n" --localauth]
 
 
 
294 test cgi-ssh-probes {[string match "test1\nprobe-2\n*" $cgiReply]
295 && [string match "*\nHTTP/1.0 200 OK*" $cgiReply]}
296 test_eq cgi-ssh-probes-param [cgi_param $cgiReply q] 3
297 foreach {cgiName cgiRequest} [list \
298 probe-word "echo hello\n" \
@@ -312,18 +319,26 @@
312 ] {
313 cgi_send $cgiRequest
314 test cgi-ssh-$cgiName {$CODE == 0 || $CODE == 1}
315 }
316 unset ::env(SSH_CONNECTION)
 
 
 
 
 
 
 
 
317
318 ###############################################################################
319 # Names and values in a query string and in a Cookie header. A name is
320 # taken when it begins with a letter and holds only letters, digits,
321 # "_" and "-"; of two values with one name the first is kept; a value
322 # from the query string that holds a control character is dropped.
323
324 set cgiReply [cgi_admin [cgi_get \
325 "/test-env?e&a=1&=5&&a\$b=6&c=%01x&1a=2&_u=3&a=second&Up=4&zz" \
326 [list "Cookie: ck=1; sp=2; fossil-x=9; Big=3"]]]
327 foreach {cgiName cgiParam cgiValue} {
328 no-value-first e ""
329 plain a 1
@@ -342,11 +357,11 @@
342 } {
343 test_eq cgi-names-$cgiName [cgi_param $cgiReply $cgiParam] $cgiValue
344 }
345
346 # With "showall" the page shows the cookies as well.
347 set cgiReply [cgi_admin [cgi_get /test-env?showall \
348 [list "Cookie: ck=1; fossil-x=9"]]]
349 test_eq cgi-showall-cookie [cgi_param $cgiReply fossil-x] 9
350 test_eq cgi-showall-header [cgi_param $cgiReply HTTP_COOKIE] "ck=1; fossil-x=9"
351
352 # A value in a form may hold a control character.
@@ -362,11 +377,16 @@
362 && [string match "*Too many query parameters*" $cgiReply$RESULT]}
363
364 ###############################################################################
365 # The request line and the header lines.
366
367 set cgiReply [cgi_admin "GET /test-env?showall HTTP/1.1\r\nHOST: named.example:8080\r\nIf-None-Match: tag\r\nAuthorization: Basic eDp5\r\nAccept-Language: de \r\nUser-Agent: Agent/1\r\nUnknown-Header: ignored\r\n\r\n"]
 
 
 
 
 
368 foreach {cgiParam cgiValue} {
369 HTTP_HOST named.example:8080
370 SERVER_NAME named.example
371 HTTP_IF_NONE_MATCH tag
372 HTTP_AUTHORIZATION {Basic eDp5}
@@ -378,12 +398,12 @@
378 test_eq cgi-header-$cgiParam [cgi_param $cgiReply $cgiParam] $cgiValue
379 }
380
381 # An "Https:" header says that the request came by https, so the reply
382 # sends a local user to the https login page.
383 set cgiReply [cgi_admin [cgi_get /test-env [list "Https: on"]]]
384 test_eq cgi-header-https [cgi_header $cgiReply Location] \
385 https://x/login?g=test-env
386
387 # X-Forwarded-For names the client when the request comes from this
388 # machine: the last address in it is taken. From any other machine the
389 # header is ignored. Only a local client sees /test-env here.
@@ -394,34 +414,44 @@
394 mapped 127.0.0.1 ::ffff:127.0.0.1 ::ffff:127.0.0.1
395 remote 127.0.0.1 {127.0.0.1, 9.9.9.9} -
396 empty 127.0.0.1 {} -
397 not-local 10.0.0.1 127.0.0.1 -
398 } {
399 set cgiReply [cgi_send [cgi_get /test-env \
400 [list "X-Forwarded-For: $cgiForwarded"]] --ipaddr $cgiFrom --localauth]
401 test_eq cgi-forwarded-$cgiName [cgi_param $cgiReply REMOTE_ADDR] $cgiAddr
402 }
403
404 # HEAD gets the headers of the reply to GET and no content.
405 set cgiReply [cgi_send [cgi_get /uv/g.png {} HEAD] --ipaddr 127.0.0.1]
406 test_eq cgi-head-status [cgi_status $cgiReply] "HTTP/1.0 200 OK"
407 test_eq cgi-head-length [cgi_header $cgiReply Content-Length] 1000
408 test_eq cgi-head-body [cgi_body $cgiReply] ""
409
410 # A POST must say how long its content is, and send that much.
411 set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\n\r\n"]
412 test cgi-post-no-length {[cgi_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
413 && [string match "*missing CONTENT_LENGTH on a POST method*" $cgiReply]}
414 set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 50\r\n\r\na=1"]
415 test cgi-post-short {[cgi_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
 
 
 
 
416 && [string match "*Wanted 50 bytes but got only 3*" $cgiReply]}
417 # Content with no type is not read.
418 set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\n\r\na=1"]
419 test cgi-post-no-type {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
 
420 && [cgi_param $cgiReply a] eq "-"}
421 foreach {cgiName cgiLength} {negative -5 zero 0 word abc huge 99999999999999999999} {
422 set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: $cgiLength\r\n\r\na=1"]
 
 
 
 
 
423 test cgi-post-length-$cgiName {$CODE == 0
424 && [regexp {^HTTP/1.0 (200|400) } $cgiReply]}
425 }
426
427 ###############################################################################
@@ -429,22 +459,22 @@
429 # asked for, not compressed, with status 206.
430
431 write_file r.css 0123456789abcdefghij
432 fossil uv add r.css
433 proc cgi_range {range {method GET} {file r.css}} {
434 return [cgi_send [cgi_get /uv/$file \
435 [list "Range: $range" "Accept-Encoding: gzip"] $method] \
436 --ipaddr 127.0.0.1]
437 }
438 set cgiReply [cgi_range bytes=2-5]
439 test_eq cgi-range-status [cgi_status $cgiReply] "HTTP/1.0 206 Partial Content"
440 test_eq cgi-range-header [cgi_header $cgiReply Content-Range] "bytes 2-5/20"
441 test_eq cgi-range-length [cgi_header $cgiReply Content-Length] 4
442 test_eq cgi-range-encoding [cgi_header $cgiReply Content-Encoding] -
443 test_eq cgi-range-body [cgi_body $cgiReply] 2345
444 set cgiReply [cgi_range bytes=0-0]
445 test_eq cgi-range-first-byte [cgi_body $cgiReply] 0
446 # A range that is not two numbers in order is ignored.
447 foreach {cgiName cgiRange} {
448 word bytes=abc
449 one-number bytes=5-
450 negative bytes=-5-10
@@ -451,36 +481,36 @@
451 backwards bytes=9-3
452 other-unit lines=1-2
453 } {
454 set cgiReply [cgi_range $cgiRange]
455 test cgi-range-ignored-$cgiName {
456 [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
457 && [cgi_header $cgiReply Content-Encoding] eq "gzip"}
458 }
459 # A range that runs past the end of the file stops at the end.
460 set cgiReply [cgi_range bytes=15-2147483646]
461 test_eq cgi-range-past-end [cgi_body $cgiReply] fghij
462 test_eq cgi-range-past-end-header [cgi_header $cgiReply Content-Range] \
463 "bytes 15-19/20"
464 test_eq cgi-range-past-end-length [cgi_header $cgiReply Content-Length] 5
465 # A range that starts at or after the end gets 416 and no content.
466 foreach {cgiName cgiRange} {at-end bytes=20-20 after-end bytes=25-30} {
467 set cgiReply [cgi_range $cgiRange]
468 test cgi-range-unsatisfiable-$cgiName {
469 [cgi_status $cgiReply] eq "HTTP/1.0 416 Range Not Satisfiable"
470 && [cgi_header $cgiReply Content-Range] eq "bytes */20"
471 && [cgi_header $cgiReply Content-Length] eq "0"}
472 }
473 # A number too large for an int is not taken as a smaller one.
474 set cgiReply [cgi_range bytes=0-4294967299]
475 test cgi-range-too-large {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"}
476 # A reply other than 206 is sent whole, whatever range was asked for.
477 set cgiReply [cgi_send [cgi_get /uv/nosuch.css [list "Range: bytes=3-9"]] \
478 --ipaddr 127.0.0.1]
479 test cgi-range-not-found {
480 [string match "HTTP/1.0 404 *" [cgi_status $cgiReply]]
481 && [string match "<!DOCTYPE*" [cgi_body $cgiReply]]}
482
483 ###############################################################################
484 # More shapes of form data in several parts.
485
486 proc cgi_form {body} {
@@ -497,58 +527,87 @@
497 set cgiReply [cgi_form "[cgi_part Shout loud]--XB--\r\n"]
498 test_eq cgi-multipart-upper-plain [cgi_param $cgiReply shout] loud
499 test_eq cgi-multipart-upper-no-bytes [cgi_param $cgiReply shout:bytes] -
500
501 # A name in capitals with a type of content.
502 set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; name=\"Typed\"; filename=\"t\"\r\nContent-Type: text/x-test\r\n\r\nv\r\n--XB--\r\n"]
 
 
 
 
 
503 test_eq cgi-multipart-upper-mimetype [cgi_param $cgiReply typed:mimetype] \
504 text/x-test
505 test_eq cgi-multipart-upper-bytes [cgi_param $cgiReply typed:bytes] 1
506
507 # A name that does not begin with a letter is not taken, with or without
508 # a file name or a type.
509 set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; name=\"1st\"; filename=\"f\"\r\nContent-Type: text/plain\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"]
 
 
 
 
 
510 test_eq cgi-multipart-digit-name [cgi_param $cgiReply 1st] -
511 test_eq cgi-multipart-digit-filename [cgi_param $cgiReply 1st:filename] -
512 test_eq cgi-multipart-digit-mimetype [cgi_param $cgiReply 1st:mimetype] -
513 test_eq cgi-multipart-digit-next [cgi_param $cgiReply after] ok
514
515 # A type or a file name given before the name belongs to no parameter.
516 set cgiReply [cgi_form "--XB\r\nContent-Type: text/early\r\nContent-Disposition: form-data; filename=\"early\"; name=\"late\"\r\n\r\nv\r\n--XB--\r\n"]
 
 
 
 
517 test_eq cgi-multipart-type-first-value [cgi_param $cgiReply late] v
518 test_eq cgi-multipart-type-first-mimetype [cgi_param $cgiReply late:mimetype] -
519 test_eq cgi-multipart-type-first-filename [cgi_param $cgiReply late:filename] -
520
521 # Words in a header line that the reader does not know are passed over.
522 set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; nonce=1; foo=2; charset=3; xyz; name=\"known\"\r\n\r\nv\r\n--XB--\r\n"]
 
 
 
 
523 test_eq cgi-multipart-unknown-words [cgi_param $cgiReply known] v
524
525 # A quoted word that reaches the end of a header line without a closing
526 # quote. The request must be answered within the time limit.
527 set cgiBody "--XB\r\nContent-Disposition: form-data; name=\"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"
 
 
 
528 write_file request.txt [cgi_post $cgiType $cgiBody]
529 file delete reply.txt
530 fossil_raw -seconds 15 http $cgiRepo --in request.txt --out reply.txt \
531 --ipaddr 127.0.0.1 --localauth
532 test cgi-multipart-lone-quote {$CODE == 0}
533
534 # Only the first 49 words of a header line are read.
535 set cgiWords ""
536 for {set cgiI 0} {$cgiI < 30} {incr cgiI} { append cgiWords " w$cgiI \"q$cgiI\";" }
537 set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data;$cgiWords name=\"far\"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"]
 
 
 
 
 
538 test_eq cgi-multipart-many-words [cgi_param $cgiReply far] -
539 test_eq cgi-multipart-many-words-next [cgi_param $cgiReply after] ok
540
541 # A quote that ends a header line after a space is a word of no
542 # characters, so the part has no name.
543 set cgiReply [cgi_form "--XB\r\nContent-Disposition: form-data; name= \"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"]
544 test {cgi-multipart-quote-alone} {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
 
 
 
545 && [cgi_param $cgiReply after] eq "ok"}
546
547 # Content that begins with a zero byte has no parts.
548 set cgiReply [cgi_form "\000--XB\r\n[cgi_part a v]--XB--\r\n"]
549 test cgi-multipart-zero-first {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
550 && [cgi_param $cgiReply a] eq "-"}
551
552 ###############################################################################
553 # More dates in If-Modified-Since. The file is given the time that the
554 # date stands for and is then not sent again; one second newer and it is.
@@ -557,13 +616,14 @@
557 fossil uv add d.bin
558 proc cgi_since_exact {date seconds} {
559 set result ""
560 foreach mtime [list $seconds [expr {$seconds + 1}]] {
561 fossil sql "UPDATE unversioned SET mtime=$mtime WHERE name='d.bin'"
562 set reply [cgi_send [cgi_get /uv/d.bin [list "If-Modified-Since: $date"]] \
 
563 --ipaddr 127.0.0.1]
564 lappend result [lindex [cgi_status $reply] 1]
565 }
566 return $result
567 }
568 foreach {cgiName cgiDate cgiSeconds} {
569 epoch-year "Thu, 01 Jan 1970 00:00:10 GMT" 10
@@ -594,13 +654,13 @@
594 second-61 "Mon, 01 Jan 2026 00:00:61 GMT"
595 month "Mon, 01 Foo 2026 00:00:00 GMT"
596 short "Mon, 01 Jan 2026"
597 empty ""
598 } {
599 set cgiReply [cgi_send [cgi_get /uv/d.bin \
600 [list "If-Modified-Since: $cgiDate"]] --ipaddr 127.0.0.1]
601 test_eq cgi-since-not-a-date-$cgiName [cgi_status $cgiReply] \
602 "HTTP/1.0 200 OK"
603 }
604
605 ###############################################################################
606 # Redirects. A redirect to an absolute URL is sent as it is; a redirect
@@ -610,12 +670,12 @@
610 # the user-edit cancel button.
611
612 proc cgi_redirect_to {query {referer none}} {
613 set headers {}
614 if {$referer ne "none"} { lappend headers "Referer: $referer" }
615 set reply [cgi_admin [cgi_get "/setup_uedit?$query" $headers]]
616 return [cgi_header $reply Location]
617 }
618 # The cancel button redirects to the referer.
619 test_eq cgi-redirect-absolute-http [cgi_redirect_to can=1 http://other/p] \
620 http://other/p
621 test_eq cgi-redirect-absolute-https [cgi_redirect_to can=1 https://other/p] \
@@ -639,63 +699,64 @@
639 proc cgi_csrf_level {reply} {
640 if {[regexp {CSRF safety = ([^<]*)} $reply all level]} { return $level }
641 return -
642 }
643 set cgiToken ""
644 set cgiReply [cgi_admin [cgi_get /setup_uedit?id=0]]
645 regexp {name="csrf" value="([^"]*)"} $cgiReply all cgiToken
646
647 set cgiReply [cgi_admin [cgi_get /test-env [list "Referer: http://x/prev"]]]
648 test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin"
649 proc cgi_env_post {body {referer http://x/prev}} {
650 return [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body"]
651 }
652 set cgiReply [cgi_env_post "csrf=$cgiToken"]
653 test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] "Same origin, POST, CSRF token"
 
654 set cgiReply [cgi_env_post "csrf=wrong"]
655 test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST"
656 set cgiReply [cgi_env_post "x=1" http://elsewhere/p]
657 test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe"
658
659 # A page that consults the check more than once. A cross-origin POST to
660 # the user-edit page, which asks twice, is ignored without error.
661 set cgiReply [cgi_admin "POST /setup_uedit HTTP/1.1\r\nHost: x\r\nReferer: http://elsewhere/p\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 14\r\n\r\nid=0&delete=1&"]
662 test cgi-csrf-twice-cross {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"}
 
663 # A valid same-origin POST with the token creates the user.
664 set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken"
665 set cgiReply [cgi_admin "POST /setup_uedit HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_uedit\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiBody]\r\n\r\n$cgiBody"]
666 test cgi-csrf-verify-accepts {[string match "HTTP/1.0 302*" [cgi_status $cgiReply]]}
667 test cgi-csrf-user-created {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1}
 
 
 
668
669 # The user-edit page needs "login", "info", "pw" and "apply" to make a
670 # change. A request with "login" alone changes nothing.
671 set cgiBody "id=0&login=cgighost&csrf=$cgiToken"
672 cgi_admin "POST /setup_uedit HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_uedit\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiBody]\r\n\r\n$cgiBody"
673 test cgi-all-needs-every-field \
674 {[fossil sql "SELECT count(*) FROM user WHERE login='cgighost'"] == 0}
675
676 ###############################################################################
677 # Request methods and the same reader over ssh.
678
679 # A POST over ssh reaches the parameter decoder.
680 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
681 set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \
682 "posted=yes"] --localauth]
683 test_eq cgi-ssh-post-value [cgi_param $cgiReply posted] yes
684 # A HEAD over ssh.
685 set cgiReply [cgi_send [cgi_get /test-env?q=9 {} HEAD] --localauth]
686 test_eq cgi-ssh-head [cgi_status $cgiReply] "HTTP/1.0 200 OK"
687 unset ::env(SSH_CONNECTION)
688
689 ###############################################################################
690 # cgi_from_mobile, used by /forum to pick a default display order. An
691 # iPad is not treated as mobile; another phone is; no agent is not.
692 proc cgi_forum_order {agent} {
693 set headers {}
694 if {$agent ne ""} { lappend headers "User-Agent: $agent" }
695 set reply [cgi_admin [cgi_get /forum?t=a $headers]]
696 return [cgi_status $reply]
697 }
698 foreach {cgiName cgiAgent} {
699 phone "Mozilla/5.0 (iPhone; Mobile) Safari"
700 ipad "Mozilla/5.0 (iPad) Safari"
701 none ""
@@ -709,47 +770,44 @@
709 # and a note in the error log. The whole request environment is written
710 # to the log.
711
712 proc cgi_attack {value} {
713 global cgiRepo
714 write_file request.txt "GET /timeline?inj=$value HTTP/1.1\r\nHost: x\r\nCookie: fossil-x=secret\r\n\r\n"
 
 
 
715 file delete reply.txt attack.log
716 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
717 --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log]
718 return [expr {[file exists reply.txt] ? [read_file reply.txt] : ""}]
719 }
720 set cgiReply [cgi_attack "1;select"]
721 test_eq cgi-attack-status [cgi_status $cgiReply] "HTTP/1.0 418 I'm a teapot"
722 test cgi-attack-logged {[file exists attack.log]
723 && [string match "*possible hack attempt*" [read_file attack.log]]
724 && [string match "*QUERY_STRING = inj=1;select*" [read_file attack.log]]}
725 # A value longer than 100 characters is shortened in the log.
726 set cgiReply [cgi_attack "[string repeat a 200];x"]
727 test cgi-attack-long {[cgi_status $cgiReply] eq "HTTP/1.0 418 I'm a teapot"
728 && [string match "*aaa...*" [read_file attack.log]]}
729 # A logged-in request with the same value is not stopped.
730 set cgiReply [cgi_admin [cgi_get "/timeline?inj=1;select"]]
731 test_eq cgi-attack-admin-ok [cgi_status $cgiReply] "HTTP/1.0 200 OK"
732
733 ###############################################################################
734 # The same-origin test with crafted Referer headers. The base URL here
735 # is "http://x". A Referer that shares the base but has more path after
736 # it with no "/" boundary is a different origin. A Referer with a "%"
737 # escape is decoded before the comparison. The /test-env page reports
738 # the result.
739
740 proc cgi_origin {referer {method GET} {body ""}} {
741 set req "$method /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\n"
742 if {$method eq "POST"} {
743 append req "Content-Type: application/x-www-form-urlencoded\r\n"
744 append req "Content-Length: [string length $body]\r\n"
745 }
746 append req "\r\n$body"
747 set reply [cgi_admin $req]
748 return [cgi_csrf_level $reply]
749 }
750 test_eq cgi-origin-same [cgi_origin http://x/page] "Same origin"
751 test_eq cgi-origin-boundary [cgi_origin http://xtra/page] unsafe
752 test_eq cgi-origin-escaped [cgi_origin http://x/a%2Fb] "Same origin"
753 # A different-origin GET reaches the method test in the same-origin check
754 # without writing a warning (the warning is for POST only).
755 test_eq cgi-origin-get-other [cgi_origin http://elsewhere/p] unsafe
@@ -756,36 +814,37 @@
756
757 ###############################################################################
758 # cgi_parameter_name walks every parameter: the ticket-entry page copies
759 # each into its interpreter.
760
761 set cgiReply [cgi_admin [cgi_get "/tktnew?username=someone&extra=1"]]
762 test_eq cgi-param-name-page [cgi_status $cgiReply] "HTTP/1.0 200 OK"
763
764 ###############################################################################
765 # cgi_param_info walks the parameters for the /cookies page.
766
767 set cgiReply [cgi_admin [cgi_get /cookies \
768 [list "Cookie: fossil_display_settings=x; extra=y"]]]
769 test cgi-param-info-page {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
770 && [string match "*fossil_display_settings*" $cgiReply]}
771
772 ###############################################################################
773 # Two more destinations for cgi_print_all. With --cgitrace the whole
774 # parameter set is traced before the page runs.
775
776 write_file request.txt [cgi_get "/test-env?traced=1"]
777 file delete reply.txt
778 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
779 --ipaddr 127.0.0.1 --localauth --cgitrace
780 test cgi-cgitrace {$CODE == 0
781 && [string match "*Calling*" $RESULT]
782 && [string match "*traced = 1*" $RESULT]}
783
784 # A CGI control file with "cgi-debug:" writes the environment to a debug
785 # file as the control file is read.
786 write_file cgi.ctl "repository: [file nativename $cgiRepo]\ncgi-debug: debug.txt\n"
 
787 file delete debug.txt
788 set ::env(REQUEST_METHOD) GET
789 set ::env(SCRIPT_NAME) ""
790 set ::env(PATH_INFO) /test-env
791 set ::env(QUERY_STRING) "dbg=1"
@@ -802,37 +861,49 @@
802 # email-alert subscription page. The page exists once email is enabled
803 # and its tables are built.
804
805 fossil settings email-send-method db
806 set cgiNotifyBody "submit=Refresh&esm=db&csrf=$cgiToken"
807 cgi_admin "POST /setup_notification HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_notification\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiNotifyBody]\r\n\r\n$cgiNotifyBody"
 
808 test cgi-alert-tables-built \
809 {[fossil sql "SELECT count(*) FROM sqlite_schema WHERE name='subscriber'"] == 1}
 
810
811 # The form renders the "checked" state of the checkboxes.
812 set cgiReply [cgi_admin [cgi_get /subscribe]]
813 test cgi-subscribe-form {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
814 && [string match "*checkbox*" $cgiReply]}
815
816 # A submitted subscription: the name is trimmed and the boxes are read as
817 # booleans. A leading and trailing space on the name is removed.
818 set cgiSubBody "submit=1&[email protected]&suname= trimmed &sa=1&sc=on&csrf=$cgiToken"
819 cgi_admin "POST /subscribe HTTP/1.1\r\nHost: x\r\nReferer: http://x/subscribe\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $cgiSubBody]\r\n\r\n$cgiSubBody"
820 test cgi-subscribe-trimmed-name \
821 {[fossil sql "SELECT suname FROM subscriber WHERE semail='[email protected]'"] eq "trimmed"}
 
 
 
 
 
822 test cgi-subscribe-boolean-alert \
823 {[string match "*a*" [fossil sql "SELECT ssub FROM subscriber WHERE semail='[email protected]'"]]}
 
824
825 ###############################################################################
826 # The HTTP reader is called in a loop for a request arriving over ssh.
827 # When the first request announces the Fossil ssh transport, the reader
828 # is called again for a second request in the same connection, and the
829 # later request updates the parameters that the first one set.
830
831 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
832 write_file request.txt \
833 "GET /test-env?first=1 HTTP/1.1\r\nHost: x\r\nX-Fossil-Transport: ssh\r\nContent-Length: 0\r\n\r\nGET /test-env?second=2 HTTP/1.1\r\nHost: x\r\nUser-Agent: Later\r\n\r\n"
 
 
 
 
834 file delete reply.txt
835 fossil_raw http $cgiRepo --in request.txt --out reply.txt --localauth
836 set cgiReply [read_file reply.txt]
837 test cgi-ssh-transport-first {[string match "*first = 1*" $cgiReply]}
838 test cgi-ssh-transport-second {[string match "*second = 2*" $cgiReply]}
@@ -841,24 +912,25 @@
841 ###############################################################################
842 # The skin query parameter sets a cookie with a default path, and marks
843 # the request "udc" unless "once" is present. A cookie carrying a login
844 # card is taken out of the parameters.
845
846 set cgiReply [cgi_admin [cgi_get /test-env?skin=darkmode]]
847 test cgi-skin-cookie {[string match "*Set-Cookie: fossil_display_settings=*" \
848 $cgiReply] && [cgi_param $cgiReply udc] eq 1}
849 # With "once" the cookie is not written and "udc" is not forced.
850 set cgiReply [cgi_admin [cgi_get {/test-env?skin=darkmode&once=1}]]
851 test cgi-skin-once {![string match "*Set-Cookie: fossil_display_settings=*" \
852 $cgiReply] && [cgi_param $cgiReply udc] eq "-"}
853 # A skin cookie is honoured as well as a skin query parameter.
854 set cgiReply [cgi_admin [cgi_get /test-env \
855 [list "Cookie: fossil_display_settings=skin=ardoise"]]]
856 test_eq cgi-skin-from-cookie [cgi_param $cgiReply fossil_display_settings] \
857 skin=ardoise
858 # A login-card cookie is removed from the visible parameters.
859 set cgiReply [cgi_admin [cgi_get /test-env [list "Cookie: x-f-l-c=card-value"]]]
 
860 test_eq cgi-login-card-hidden [cgi_param $cgiReply x-f-l-c] -
861
862 ###############################################################################
863 # The reply content type for an unversioned file comes from the
864 # "mimetypes" setting. Parsing of the type stops at the first character
@@ -865,19 +937,19 @@
865 # outside the range "+" through "z", and a text type is compressed.
866
867 fossil settings mimetypes "zw text/x|y"
868 write_file f.zw "other text to send"
869 fossil uv add f.zw
870 set cgiReply [cgi_send [cgi_get /uv/f.zw] --ipaddr 127.0.0.1]
871 test cgi-content-type-stops \
872 {[string match "text/x;*" [cgi_header $cgiReply Content-Type]]}
873
874 ###############################################################################
875 # A skin name that is not a known skin produces an error, so the cookie
876 # is not written.
877
878 set cgiReply [cgi_admin [cgi_get /test-env?skin=no_such_skin_here]]
879 test cgi-skin-unknown {![string match "*Set-Cookie: fossil_display_settings=*" \
880 $cgiReply] && [cgi_param $cgiReply skin] eq "no_such_skin_here"}
881
882 ###############################################################################
883 # Deleting a cookie: the reply carries a Set-Cookie with a value of
@@ -913,13 +985,13 @@
913 fossil commit -m "add art" --no-warnings
914 set cgiArt [fossil sql \
915 "SELECT uuid FROM blob WHERE rid=(SELECT max(rid) FROM blob)"]
916 proc cgi_raw_type {mime} {
917 global cgiArt
918 set reply [cgi_send [cgi_get /raw/$cgiArt?m=$mime \
919 [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth]
920 return [cgi_header $reply Content-Encoding]
921 }
922 foreach {cgiName cgiMime} {
923 javascript application/javascript
924 json application/json
925 wasm application/wasm
@@ -945,46 +1017,48 @@
945 }
946 # With --nocompress nothing is compressed.
947 set cgiFile [fossil sql "SELECT uuid FROM blob, mlink, filename
948 WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
949 AND filename.name='art.txt'"]
950 set cgiReply [cgi_send [cgi_get /raw/$cgiFile?m=text/plain \
951 [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth --nocompress]
952 test cgi-nocompress {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
953 && [cgi_header $cgiReply Content-Encoding] eq "-"
954 && [cgi_body $cgiReply] eq "the quick brown fox jumps over the lazy dog\n"}
 
955
956 ###############################################################################
957 # More about ranges. A Range header counts only for GET, and not for
958 # content of the type that a sync uses. Part of an artifact named by its
959 # full hash, sent to a visitor who is not logged in, may be kept by the
960 # client for ever.
961
962 set cgiReply [cgi_range bytes=2-5 HEAD]
963 test cgi-range-head {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
964 && [cgi_header $cgiReply Content-Range] eq "-"}
965 set cgiReply [cgi_range bytes=5]
966 test cgi-range-ignored-no-dash {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
967 && [cgi_header $cgiReply Content-Range] eq "-"}
968 set cgiReply [cgi_send [cgi_get /raw/$cgiArt?m=application/x-fossil \
969 [list "Range: bytes=1-3"]] --ipaddr 127.0.0.1 --localauth]
970 test cgi-range-sync-type {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
971 && [cgi_header $cgiReply Content-Range] eq "-"}
972 set cgiReply [cgi_send [cgi_get /raw/$cgiFile?m=text/plain \
973 [list "Range: bytes=4-8"]] --ipaddr 9.9.9.9]
974 test_eq cgi-range-artifact [cgi_body $cgiReply] quick
975 test_eq cgi-range-artifact-cache [cgi_header $cgiReply Cache-Control] \
976 "max-age=315360000, immutable"
977
978 ###############################################################################
979 # The "at" parameter of /raw names the file for the client to save the
980 # content in. Only its last path element is used, and every character
981 # in it other than a letter, a digit, "." and "-" becomes "_".
982
983 set cgiReply [cgi_send [cgi_get "/raw/$cgiArt?at=some/dir/my%20file-1%3B.txt"] \
 
984 --ipaddr 127.0.0.1 --localauth]
985 test_eq cgi-attachment-name [cgi_header $cgiReply Content-Disposition] \
986 {attachment; filename="my_file-1_.txt";}
987
988 ###############################################################################
989 # A request that is refused before any repository is open: the server is
990 # given a directory, and the request has a method it does not know.
@@ -993,11 +1067,11 @@
993 write_file request.txt "DELETE /x HTTP/1.1\r\nHost: x\r\n\r\n"
994 file delete reply.txt
995 fossil_raw http [file join [pwd] norepo] --in request.txt --out reply.txt \
996 --ipaddr 127.0.0.1
997 test cgi-no-repository-bad-method {$CODE == 0
998 && [cgi_status [read_file reply.txt]] eq "HTTP/1.0 400 Bad Request"}
999
1000 ###############################################################################
1001 # More of the same-origin test: a Referer that is the base URL and
1002 # nothing more is the same origin.
1003
@@ -1007,19 +1081,18 @@
1007 # With --httptrace the server reports each parameter as it is set and
1008 # copies the request into a file named httplog-NNNNN.txt in the current
1009 # directory. If it cannot make that file it says so and goes on.
1010
1011 foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog }
1012 write_file request.txt [cgi_get /test-env?traced=2]
1013 file delete reply.txt
1014 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
1015 --ipaddr 127.0.0.1 --localauth --httptrace
1016 set cgiLogs [glob -nocomplain httplog-*.txt]
1017 test cgi-httptrace {$CODE == 0
1018 && [string first "# cgi: traced = \[2\]" $RESULT] >= 0
1019 && [string first "# open log on httplog-" $RESULT] >= 0
1020 && [llength $cgiLogs] == 1}
1021 if {[llength $cgiLogs] == 1} {
1022 set cgiLogText [read_file [lindex $cgiLogs 0]]
1023 test cgi-httptrace-log {
1024 [string match "GET /test-env?traced=2 HTTP/1.1*Host: x*" $cgiLogText]}
1025 file delete [lindex $cgiLogs 0]
@@ -1035,11 +1108,11 @@
1035 file delete $cgiLog
1036 }
1037 test cgi-httptrace-post-content {[string match "*body=sent" $cgiLogText]}
1038 test cgi-httptrace-post-header \
1039 {[string match "POST /test-env HTTP/1.1*" $cgiLogText]}
1040 write_file request.txt [cgi_get /test-env?traced=2]
1041 if {$::tcl_platform(platform) eq "unix"} {
1042 set cgiHere [pwd]
1043 file mkdir readonly
1044 file attributes readonly -permissions 0555
1045 cd readonly
@@ -1048,54 +1121,55 @@
1048 --ipaddr 127.0.0.1 --localauth --httptrace
1049 cd $cgiHere
1050 file attributes readonly -permissions 0755
1051 test cgi-httptrace-no-log {$CODE == 0
1052 && [string first "# failed to open httplog-" $RESULT] >= 0
1053 && [cgi_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"}
1054 }
1055
1056 ###############################################################################
1057 # A request for the top of the site is sent on to the index page. A
1058 # login-card cookie in such a request is taken once.
1059
1060 set cgiReply [cgi_admin [cgi_get / [list "Cookie: x-f-l-c=card-value"]]]
1061 test_eq cgi-login-card-home [cgi_header $cgiReply Location] http://x/index
1062
1063 ###############################################################################
1064 # The honeypot page offers a visitor who is not logged in a captcha, and
1065 # keeps the URL that was asked for, with its query parameters, in a
1066 # cookie.
1067
1068 set cgiReply [cgi_send [cgi_get "/honeypot?a=1&b&c=two"] --ipaddr 9.9.9.9]
1069 test cgi-original-url {[string first \
1070 "Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fa%3D1%26b%26c%3Dtwo;" \
1071 $cgiReply] >= 0}
1072
1073 ###############################################################################
1074 # The "ss" parameter of /timeline is checked for an attack as soon as it
1075 # is read, for a visitor who is not logged in.
1076
1077 write_file request.txt [cgi_get "/timeline?ss=1;select"]
1078 file delete reply.txt attack.log
1079 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
1080 --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log]
1081 test cgi-attack-read-parameter {
1082 [cgi_status [read_file reply.txt]] eq "HTTP/1.0 418 I'm a teapot"
1083 && [string match "*418 response on \"ss\"*" [read_file attack.log]]}
1084 set cgiReply [cgi_admin [cgi_get "/timeline?ss=m"]]
1085 test_eq cgi-attack-read-parameter-admin [cgi_status $cgiReply] "HTTP/1.0 200 OK"
 
1086
1087 ###############################################################################
1088 # SSH_CONNECTION names the client only when it holds an address followed
1089 # by a space. Otherwise the request is read as plain HTTP from an
1090 # unknown address, which --localauth does not log in.
1091
1092 foreach {cgiName cgiValue} {empty "" one-word nospace} {
1093 set ::env(SSH_CONNECTION) $cgiValue
1094 set cgiReply [cgi_send [cgi_get /test-env] --localauth]
1095 unset ::env(SSH_CONNECTION)
1096 test_eq cgi-ssh-connection-$cgiName [cgi_header $cgiReply Location] \
1097 http://x/login?g=test-env
1098 }
1099
1100 ###############################################################################
1101 # SCGI: SCRIPT_NAME, PATH_INFO and REQUEST_URI. The server needs
@@ -1111,13 +1185,13 @@
1111 proc cgi_scgi_names {pairs} {
1112 set reply [cgi_send [cgi_scgi [concat {
1113 CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SERVER_NAME x SERVER_PORT 80
1114 REMOTE_ADDR 127.0.0.1
1115 } $pairs]] --scgi --localauth]
1116 set status [lindex [cgi_status $reply] 1]
1117 if {$status eq "400"} {
1118 return [list 400 [string trim [cgi_body $reply]]]
1119 }
1120 if {$status ne "200"} { return $status }
1121 return [list 200 [cgi_param $reply SCRIPT_NAME] [cgi_param $reply PATH_INFO] \
1122 [cgi_param $reply REQUEST_URI]]
1123 }
@@ -1171,29 +1245,33 @@
1171 empty "" "SCGI header too short" \
1172 length-only "20" "cannot read entire SCGI header" \
1173 ] {
1174 set cgiReply [cgi_send $cgiRequest --scgi]
1175 test cgi-scgi-$cgiName {$CODE == 0
1176 && [cgi_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
1177 && [string match "*$cgiError*" $cgiReply]}
1178 }
1179
1180 ###############################################################################
1181 # Page aliases. An alias in the configuration names a page and query
1182 # parameters for it: "NAME=VALUE" sets a parameter, replacing one of the
1183 # same name in the request; a name in capitals is taken in lower case;
1184 # "NAME!" removes a parameter of the request.
1185
1186 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias','/test-env?a=new&Bb=2&gone!&absent!&fresh',0)"
1187 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias2','/test-env?zz!',0)"
1188 set cgiReply [cgi_admin [cgi_get "/cgialias?a=old&gone=1&keep=3"]]
 
 
 
 
1189 test_eq cgi-alias-replace [cgi_param $cgiReply a] new
1190 test_eq cgi-alias-upper [cgi_param $cgiReply bb] 2
1191 test_eq cgi-alias-delete [cgi_param $cgiReply gone] -
1192 test_eq cgi-alias-add [cgi_param $cgiReply fresh] ""
1193 test_eq cgi-alias-keep [cgi_param $cgiReply keep] 3
1194 set cgiReply [cgi_admin [cgi_get "/cgialias2?m=1&zz=9"]]
1195 test {cgi-alias-delete-last} {[cgi_param $cgiReply zz] eq "-"
1196 && [cgi_param $cgiReply m] eq "1"}
1197
1198 ###############################################################################
1199 # The configuration page saves the text given for the main menu, unless
@@ -1201,12 +1279,13 @@
1201 # removed and the text is not looked at.
1202
1203 proc cgi_menu_post {fields} {
1204 global cgiToken
1205 set body "$fields&csrf=$cgiToken"
1206 set reply [cgi_admin "POST /setup_config HTTP/1.1\r\nHost: x\r\nReferer: http://x/setup_config\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body"]
1207 return [list [lindex [cgi_status $reply] 1] \
 
1208 [fossil sql "SELECT value FROM config WHERE name='mainmenu'"]]
1209 }
1210 test_eq cgi-menu-saved [cgi_menu_post "mmenu=cgi-menu-text&zlast=1"] \
1211 {200 cgi-menu-text}
1212 test_eq cgi-menu-reset [cgi_menu_post "mmenu=other-text&resetMenu=1&zlast=1"] \
@@ -1220,22 +1299,23 @@
1220 # empty value is on, and one with the value "off" is off.
1221
1222 proc cgi_subscribe {email fields} {
1223 global cgiToken
1224 set body "submit=1&e=$email&$fields&csrf=$cgiToken"
1225 cgi_admin "POST /subscribe HTTP/1.1\r\nHost: x\r\nReferer: http://x/subscribe\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body"
1226 return [fossil sql "SELECT hex(suname), ssub FROM subscriber WHERE semail='$email'"]
 
1227 }
1228 test_eq cgi-subscribe-no-name [cgi_subscribe [email protected] "sa=&sc=off"] \
1229 "|a"
1230 test_eq cgi-subscribe-blank-name \
1231 [cgi_subscribe [email protected] "suname=+++&sa=0&sc=1"] "|c"
1232 test_eq cgi-subscribe-line-ends \
1233 [cgi_subscribe [email protected] "suname=+one%0D%0Atwo%0Dend&sa=1"] \
1234 "6F6E650A74776F0D656E64|a"
1235 # The form shows a box as checked for a value that is a word for "true".
1236 set cgiReply [cgi_admin [cgi_get "/subscribe?submit=1&sa=on&sc=off&st=2"]]
1237 test cgi-subscribe-checked-word {
1238 [string match "*name=\"sa\" checked>*" $cgiReply]
1239 && [string match "*name=\"sc\" >*" $cgiReply]
1240 && [string match "*name=\"st\" >*" $cgiReply]}
1241
@@ -1256,22 +1336,29 @@
1256 return $RESULT
1257 }
1258 set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env
1259 REMOTE_ADDR 127.0.0.1}]
1260 test cgi-cgi-refused {[string match "Status: 400 Bad Request*" $cgiReply]
1261 && [string match "*\nBad CGI Request: missing CONTENT_LENGTH on a POST method*" $cgiReply]}
 
 
1262 set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env
1263 REMOTE_ADDR 127.0.0.1 SERVER_SOFTWARE TestServer/1}]
1264 test cgi-cgi-refused-server-named {
1265 [string match "*\nBad CGI Request from \"TestServer/1\": missing CONTENT_LENGTH*" $cgiReply]}
 
 
1266 set cgiReply [cgi_cgi {SCRIPT_NAME /s PATH_INFO /test-env REMOTE_ADDR 127.0.0.1
1267 HTTP_HOST x HTTP_REFERER http://x/s/prev}]
1268 test_eq cgi-cgi-no-method [cgi_csrf_level $cgiReply] "Same origin"
1269
1270 # A control file that names a debug file which cannot be opened is used
1271 # all the same.
1272 write_file cgi3.ctl "repository: [file nativename $cgiRepo]\nlocalauth\ncgi-debug: [file join [pwd] nosuchdir debug.txt]\n"
 
 
 
1273 set ::env(REQUEST_METHOD) GET
1274 set ::env(SCRIPT_NAME) /s
1275 set ::env(PATH_INFO) /test-env
1276 set ::env(QUERY_STRING) "nodebug=1"
1277 set ::env(REMOTE_ADDR) 127.0.0.1
@@ -1296,31 +1383,40 @@
1296 test cgi-json-post-$cgiName-exit {$CODE == 0}
1297 test cgi-json-post-$cgiName-reply \
1298 {[string match "*FOSSIL-1101*" $cgiReply]}
1299 }
1300 set cgiReply [cgi_admin [cgi_post text/x-other {[1]} /json/version]]
1301 test cgi-json-post-other-type {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1302 && [string match "*jsonApiVersion*" $cgiReply]}
1303 set cgiReply [cgi_send [cgi_scgi {
1304 CONTENT_LENGTH 8 CONTENT_TYPE application/json SCGI 1 REQUEST_METHOD POST
1305 SCRIPT_NAME {} PATH_INFO /json/version SERVER_NAME x SERVER_PORT 80
1306 REMOTE_ADDR 127.0.0.1 no_json 1
1307 } "not json"] --scgi --localauth]
1308 test cgi-json-no-json {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1309 && [string match "*jsonApiVersion*" $cgiReply]}
1310 }
1311
1312 ###############################################################################
1313 # More of a connection over ssh. An older client, after its probes,
1314 # sends a blank line twice and the command again before each further
1315 # request. A request may name the repository file before the page.
1316
1317 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
1318 set cgiFirst "echo test1\nfossil\nGET /test-env?first=1 HTTP/1.1\r\nHost: x\r\nUser-Agent: First\r\nX-Fossil-Transport: other\r\n\r\n"
1319 set cgiReply [cgi_send "$cgiFirst\n\nfossil\nGET /test-env?second=2 HTTP/1.1\r\nHost: x\r\nContent-Length: 0\r\nContent-Type: text/plain\r\nX-Fossil-Transport: ssh\r\n\r\n" --localauth]
 
 
 
 
 
 
 
 
1320 test cgi-ssh-flip {[string match "test1\n*" $cgiReply]
1321 && [string match "*HTTP_USER_AGENT = First*first = 1*second = 2*" $cgiReply]}
 
1322 foreach {cgiName cgiMore cgiError} [list \
1323 cut-short "\n" "incorrect transport_flip" \
1324 not-blank "\nxyz\n" "transport_flip failed" \
1325 other-command "\n\nother\n" "transport_open failed" \
1326 no-request "\n\nfossil\n" "missing HTTP header" \
@@ -1335,52 +1431,72 @@
1335 && ![string match "*400 Bad Request*" $cgiReply]}
1336 foreach {cgiName cgiRequest cgiError} [list \
1337 probes-only "echo test1\nfossil\n" "missing HTTP header" \
1338 blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \
1339 "unsupported HTTP method" \
1340 empty-command "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\nHost: x\r\n\r\n\n\nfossil\n" \
 
 
 
1341 "transport_open failed" \
1342 repository-only "GET $cgiRepo HTTP/1.1\r\nHost: x\r\n\r\n" \
1343 "malformed URL in HTTP header" \
1344 ] {
1345 set cgiReply [cgi_send $cgiRequest --localauth]
1346 test cgi-ssh-$cgiName {$CODE == 0
1347 && [string match "*400 Bad Request*$cgiError*" $cgiReply]}
1348 }
1349 set cgiReply [cgi_send [cgi_get $cgiRepo/test-env?named=1] --localauth]
1350 test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1"
1351 && [cgi_param $cgiReply PATH_INFO] eq "/test-env"}
1352 # The name is taken off only when a "/" or the end follows it, and only
1353 # for GET.
1354 set cgiReply [cgi_send [cgi_get ${cgiRepo}x/test-env] --localauth]
1355 test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] -
1356 set cgiReply [cgi_send [cgi_get $cgiRepo/test-env [list "Content-Length: 0"] \
 
1357 POST] --localauth]
1358 test_eq cgi-ssh-repository-post [cgi_param $cgiReply PATH_INFO] -
1359 # Later requests on one ssh connection: the second sends Content-Length
1360 # before a longer header line and must get its length and body; the third
1361 # is a GET with no Content-Length and must be served with a length of 0.
1362 set cgiFirst "POST /test-env HTTP/1.1\r\nX-Fossil-Transport: SSH\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 3\r\n\r\na=1"
1363 set cgiSecond "POST /test-env HTTP/1.1\r\nContent-Length: 3\r\nContent-Type: application/x-www-form-urlencoded-and-more\r\n\r\nb=2"
 
 
 
 
 
 
 
 
1364 set cgiThird "GET /test-env?c=3 HTTP/1.1\r\nHost: x\r\n\r\n"
1365 set cgiReply [cgi_send $cgiFirst$cgiSecond$cgiThird --localauth]
1366 test cgi-ssh-later-content-length {$CODE == 0 && [string match \
1367 "*CONTENT_LENGTH = 3*a = 1*CONTENT_LENGTH = 3*b = 2*CONTENT_LENGTH = 0*c = 3*" \
 
 
1368 [regsub -all {<[^>]*>} $cgiReply {}]]}
1369 unset ::env(SSH_CONNECTION)
1370
1371 ###############################################################################
1372 # A visitor who is not logged in reaches a page that is closed to robots
1373 # with a token, and gets a cookie that opens the page afterwards. The
1374 # same value given as a query parameter does not.
1375
1376 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('robot-restrict','timeline',0)"
1377 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('token-cgitoken','{\"user\":\"someone\"}',0)"
 
 
 
 
 
 
1378 proc cgi_robot {path {cookie ""}} {
1379 set headers [list "User-Agent: Agent/1"]
1380 if {$cookie ne ""} { lappend headers "Cookie: $cookie" }
1381 return [cgi_send [cgi_get $path $headers] --ipaddr 9.9.9.9]
1382 }
1383 set cgiRobot "*Checking to see if you are a robot*"
1384 test cgi-robot-stopped {[string match $cgiRobot [cgi_robot /timeline]]}
1385 set cgiReply [cgi_robot /timeline?token=cgitoken]
1386 set cgiProof ""
@@ -1401,28 +1517,30 @@
1401 ###############################################################################
1402 # A forum thread is shown in order of time to a phone and as a hierarchy
1403 # to anything else, an iPad included. The page offers the other order.
1404
1405 set cgiFd [open post.txt wb]
1406 puts -nonewline $cgiFd "D 2026-01-04T10:00:01.000\nH Cgi\\sthread\nU alice\nW 5\nhello\n"
 
1407 close $cgiFd
1408 fossil md5sum post.txt
1409 set cgiSum [lindex $RESULT 0]
1410 set cgiFd [open post.txt ab]
1411 puts -nonewline $cgiFd "Z $cgiSum\n"
1412 close $cgiFd
1413 fossil test-content-put --crosslink post.txt
1414 set cgiPost [fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT fpid FROM forumpost LIMIT 1)"]
 
1415 foreach {cgiName cgiAgent cgiOther} {
1416 phone "Mozilla/5.0 (iPhone; Mobile) Safari" Hierarchical
1417 ipad "Mozilla/5.0 (iPad; Mobile) Safari" Chronological
1418 desk "Mozilla/5.0 (X11; Linux)" Chronological
1419 none "" Chronological
1420 } {
1421 set cgiHeaders {}
1422 if {$cgiAgent ne ""} { lappend cgiHeaders "User-Agent: $cgiAgent" }
1423 set cgiReply [cgi_admin [cgi_get /forumthread/$cgiPost?t=a $cgiHeaders]]
1424 test cgi-forum-order-$cgiName {[string match "*>Cgi thread<*" $cgiReply]
1425 && [string match "*?t=?\">$cgiOther</a>*" $cgiReply]}
1426 }
1427
1428 ###############################################################################
@@ -1431,28 +1549,34 @@
1431
1432 fossil user new cgiuser contact userpw
1433 fossil user capabilities cgiuser o
1434 proc cgi_login {fields} {
1435 set body "u=cgiuser&p=userpw&in=Login&$fields"
1436 return [cgi_send "POST /login HTTP/1.1\r\nHost: x\r\nReferer: http://x/login\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $body]\r\n\r\n$body" --ipaddr 9.9.9.9]
1437 }
1438 set cgiCookie [cgi_header [cgi_login x=1] Set-Cookie]
1439 test cgi-login-session-cookie {[string match "fossil-*=*cgiuser; Path=*; HttpOnly;*" $cgiCookie]
 
1440 && ![string match "*max-age*" $cgiCookie]}
1441 set cgiCookie [cgi_header [cgi_login remember=1] Set-Cookie]
1442 test cgi-login-lasting-cookie {[string match "fossil-*=*cgiuser; Path=*; max-age=*" $cgiCookie]}
 
1443
1444 ###############################################################################
1445 # A program under /ext that gives a status of 0 gets the usual "200 OK".
1446
1447 if {$::tcl_platform(platform) eq "unix"} {
1448 file mkdir extroot
1449 write_file extroot/status0.sh "#!/bin/sh\nprintf 'Status: 0 Nothing\\r\\nContent-Type: text/plain\\r\\n\\r\\nfrom the program\\n'\n"
 
 
 
 
1450 file attributes extroot/status0.sh -permissions 0755
1451 set cgiReply [cgi_admin [cgi_get /ext/status0.sh] \
1452 --extroot [file join [pwd] extroot]]
1453 test cgi-ext-status-zero {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1454 && [string match "*from the program*" $cgiReply]
1455 && ![string match "*printf*" $cgiReply]}
1456 }
1457
1458 ###############################################################################
@@ -1481,11 +1605,12 @@
1481 cgi cgi5.ctl]
1482 cd $cgiHere
1483 file delete -force $cgiDir
1484 test cgi-cgi-no-repository {$CODE == 1
1485 && [string match "Status: 500 Internal Server Error*" $cgiReply]
1486 && [string match "*Unable to find or open the project repository" $cgiReply]}
 
1487 set cgiReply [cgi_run_with {GATEWAY_INTERFACE CGI/1.1 REQUEST_METHOD GET
1488 SCRIPT_NAME /s PATH_INFO /home}]
1489 test cgi-cgi-no-control-file {$CODE == 1
1490 && [string match "Status: 500 Internal Server Error*" $cgiReply]
1491 && [string match "*No CGI control file specified" $cgiReply]}
@@ -1497,24 +1622,24 @@
1497 write_file cgi6.ctl "#!/usr/bin/fossil\nredirect: * $cgiTarget\n"
1498 set cgiReply [cgi_run_with {REQUEST_METHOD GET HTTP_HOST x SCRIPT_NAME /s
1499 PATH_INFO /abc QUERY_STRING q=1} cgi cgi6.ctl]
1500 test cgi-cgi-redirect-$cgiName {$CODE == 0
1501 && [string match "Status: 301 Moved Permanently*" $cgiReply]
1502 && [cgi_header "$cgiReply\r\n\r\n" Location] eq $cgiLocation}
1503 }
1504
1505 ###############################################################################
1506 # The setup page warns of a page header that has no "base" element, and
1507 # does not when the header has one, as the built-in header does.
1508
1509 set cgiReply [cgi_admin [cgi_get /setup]]
1510 test cgi-setup-base-present {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1511 && ![string match "*Configuration Error*" $cgiReply]}
1512 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header',
1513 '<html><head><title>plain</title></head><body>',now())"
1514 set cgiReply [cgi_admin [cgi_get /setup]]
1515 test cgi-setup-base-missing {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1516 && [string match "*Configuration Error*base href=*" $cgiReply]}
1517
1518 # The TH1 command "redirect" in a page header sends the client to
1519 # another page: with "302", or with "307" when its second argument is
1520 # true, which tells the client to repeat the request as it made it.
@@ -1522,13 +1647,13 @@
1522 plain {redirect /stat} {HTTP/1.0 302 Moved Temporarily}
1523 method {redirect /stat 1} {HTTP/1.0 307 Temporary Redirect}
1524 } {
1525 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header',
1526 '<html><head></head><body><th1>$cgiScript</th1>',now())"
1527 set cgiReply [cgi_admin [cgi_get /timeline]]
1528 test cgi-th1-redirect-$cgiName {[cgi_status $cgiReply] eq $cgiStatus
1529 && [cgi_header $cgiReply Location] eq "http://x/stat"}
1530 }
1531 fossil sql "DELETE FROM config WHERE name='header'"
1532
1533 # The same command run from the command line, where there is no request
1534 # to answer, is an error.
@@ -1555,14 +1680,14 @@
1555 # and has no table in its content; a page with a table gets the ad unit
1556 # for the top of the page.
1557
1558 fossil sql "REPLACE INTO config(name,value,mtime) VALUES
1559 ('adunit-right','<b>ADRIGHT</b>',now()),('adunit','<b>ADTOP</b>',now())"
1560 set cgiReply [cgi_admin [cgi_get /sitemap]]
1561 test cgi-adunit-right {[string match "*ADRIGHT*" $cgiReply]
1562 && ![string match "*ADTOP*" $cgiReply]}
1563 set cgiReply [cgi_admin [cgi_get /brlist]]
1564 test cgi-adunit-top-with-table {[string match "*ADTOP*" $cgiReply]
1565 && ![string match "*ADRIGHT*" $cgiReply]}
1566 fossil sql "DELETE FROM config WHERE name IN ('adunit-right','adunit')"
1567
1568 ###############################################################################
@@ -1570,16 +1695,16 @@
1570 # /file with no file name lists the files of the check-in "tip", and
1571 # its links carry "ci=tip". /timeline with "r=BRANCH" shows the branch
1572 # and what is related to it, and its form keeps that as "t=BRANCH" and
1573 # "rel".
1574
1575 set cgiReply [cgi_admin [cgi_get /file]]
1576 test cgi-file-no-name {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1577 && [string match "*Top-level Files of tip*" $cgiReply]
1578 && [string match "*ci=tip*" $cgiReply]}
1579 set cgiReply [cgi_admin [cgi_get /timeline?r=trunk]]
1580 test cgi-timeline-r {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1581 && [string match "*name=\"rel\" value=\"1\"*" $cgiReply]
1582 && [string match "*name=\"t\" value=\"trunk\"*" $cgiReply]}
1583
1584 ###############################################################################
1585 # An unversioned file whose time of change is too far in the future to
@@ -1588,15 +1713,15 @@
1588
1589 write_file late.css "p{}\n"
1590 fossil uv add late.css
1591 fossil sql "UPDATE unversioned SET mtime=1000000000000000000
1592 WHERE name='late.css'"
1593 set cgiReply [cgi_send [cgi_get /uv/late.css] --ipaddr 127.0.0.1]
1594 test cgi-last-modified-out-of-range {
1595 [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1596 && [string match "*\r\nLast-Modified: \r\n*" $cgiReply]
1597 && [cgi_body $cgiReply] eq "p{}\n"}
1598 fossil uv rm late.css
1599
1600 ###############################################################################
1601 # "fossil server" itself, where it listens with its own code (not on
1602 # Windows). A server that cannot listen where it was told says why and
@@ -1624,11 +1749,13 @@
1624 bad-ipv6 {--port {[zz::1]:8111}} \
1625 "not a valid IPv6 address: zz::1" \
1626 other-ipv4 {--port 192.0.2.1:8111} \
1627 "cannot open a listening socket on 192.0.2.1:8111" \
1628 other-ipv6 {--port {[2001:db8::1]:8111}} \
1629 "cannot open a listening socket on \\\[2001:db8::1\\\]:8111" \
 
 
1630 port-in-use [list --localhost --port $cgiPort] \
1631 "no available TCP ports in the range $cgiPort..$cgiPort" \
1632 socket-name-long [list --socket-name [string repeat s 200]] \
1633 "name of unix socket too big" \
1634 socket-name-taken {--socket-name notsocket} \
@@ -1638,75 +1765,102 @@
1638 test cgi-server-refused-$cgiName {$CODE == 1
1639 && [string match "*$cgiError*" $RESULT]}
1640 }
1641 close $cgiListener
1642
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1643 # Send REQUEST to HOST and PORT and return the reply, waiting at most
1644 # ten seconds for the end of it. With "unix" for HOST, PORT is the
1645 # name of a unix socket, and the program "nc" carries the request.
1646 proc cgi_client {host port request} {
1647 if {$host eq "unix"} {
1648 return [exec nc -w 10 -U $port << $request]
 
 
1649 }
1650 set sock [socket $host $port]
1651 fconfigure $sock -translation binary -blocking 0
1652 puts -nonewline $sock $request
1653 flush $sock
1654 set reply ""
1655 for {set i 0} {$i < 200 && ![eof $sock]} {incr i} {
1656 append reply [read $sock]
1657 after 50
 
1658 }
1659 close $sock
1660 return $reply
1661 }
1662 # Start a server with OPTIONS that answers one request and stops, send
1663 # it REQUEST at HOST and PORT, and return what the server printed and
1664 # the reply. The server is killed if it has not stopped by itself.
1665 proc cgi_serve_once {options host port request {command server}} {
 
 
1666 global fossilexe cgiRepo
1667 file delete server.out
1668 set pid [exec $fossilexe $command --debug-nofork --localauth {*}$options \
1669 $cgiRepo >& server.out &]
1670 set reply ""
1671 for {set i 0} {$i < 100} {incr i} {
1672 after 100
1673 if {[string match "*Listening for*" [read_file server.out]]} {
1674 after 300
1675 catch {set reply [cgi_client $host $port $request]}
1676 break
1677 }
1678 }
1679 for {set i 0} {$i < 50 && ![catch {exec kill -0 $pid}]} {incr i} {
1680 after 100
1681 }
1682 catch {exec kill -9 $pid}
1683 return [list [string trim [read_file server.out]] $reply]
1684 }
1685
1686 # An IPv4 address, by number and as "localhost".
1687 foreach {cgiName cgiHost} {ipv4 127.0.0.1 localhost localhost} {
1688 set cgiPort [cgi_free_port]
1689 lassign [cgi_serve_once [list --port $cgiHost:$cgiPort] 127.0.0.1 \
1690 $cgiPort [cgi_get /test-env]] cgiPrinted cgiReply
1691 test_eq cgi-server-$cgiName-printed $cgiPrinted \
1692 "Listening for HTTP requests on TCP port 127.0.0.1:$cgiPort"
1693 test cgi-server-$cgiName-reply {
1694 [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1695 && [cgi_param $cgiReply REMOTE_ADDR] eq "127.0.0.1"}
1696 }
1697 # "fossil ui" starts the browser on the address it listens on. The
1698 # browser here is "echo".
1699 fossil settings web-browser echo
1700 fossil settings web-browser
1701 if {[string match "*echo*" $RESULT]} {
1702 set cgiPort [cgi_free_port]
1703 lassign [cgi_serve_once [list --port 127.0.0.1:$cgiPort] 127.0.0.1 \
1704 $cgiPort [cgi_get /test-env] ui] cgiPrinted cgiReply
1705 test cgi-server-ui-browser {
1706 [string match "*\nhttp://127.0.0.1:$cgiPort/*" \n$cgiPrinted]
1707 && [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"}
1708 }
1709 # SCGI in place of HTTP.
1710 set cgiPort [cgi_free_port]
1711 lassign [cgi_serve_once [list --scgi --port 127.0.0.1:$cgiPort] 127.0.0.1 \
1712 $cgiPort [cgi_scgi {
@@ -1721,38 +1875,44 @@
1721 if {![catch {cgi_busy_port ::1} cgiBusy]} {
1722 close [lindex $cgiBusy 0]
1723 # An IPv6 address.
1724 set cgiPort [cgi_free_port]
1725 lassign [cgi_serve_once [list --port \[::1\]:$cgiPort] ::1 $cgiPort \
1726 [cgi_get /test-env]] cgiPrinted cgiReply
1727 test_eq cgi-server-ipv6-printed $cgiPrinted \
1728 "Listening for HTTP requests on \[::1\]:$cgiPort"
1729 test cgi-server-ipv6-reply {[cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1730 && [cgi_param $cgiReply REMOTE_ADDR] eq "::1"}
1731 # With no address the server listens on both kinds of loopback
1732 # address, or on IPv4 alone if the port is taken for IPv6.
 
 
1733 set cgiPort [cgi_free_port]
1734 lassign [cgi_serve_once [list --localhost --port \[\]:$cgiPort] ::1 \
1735 $cgiPort [cgi_get /test-env]] cgiPrinted cgiReply
1736 test_eq cgi-server-both-printed $cgiPrinted \
1737 "Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 and IPv6"
 
 
1738 test_eq cgi-server-both-reply [cgi_param $cgiReply REMOTE_ADDR] ::1
1739 lassign [cgi_busy_port ::1] cgiListener cgiPort
1740 lassign [cgi_serve_once [list --localhost --port $cgiPort] 127.0.0.1 \
1741 $cgiPort [cgi_get /test-env]] cgiPrinted cgiReply
1742 close $cgiListener
1743 test_eq cgi-server-ipv4-only-printed $cgiPrinted \
1744 "Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 only"
1745 test_eq cgi-server-ipv4-only-reply [cgi_status $cgiReply] "HTTP/1.0 200 OK"
 
1746 # With a port and neither an address nor --localhost the server
1747 # listens on every address of the machine.
1748 set cgiPort [cgi_free_port]
1749 lassign [cgi_serve_once [list --port $cgiPort] 127.0.0.1 \
1750 $cgiPort [cgi_get /login]] cgiPrinted cgiReply
1751 test_eq cgi-server-any-address-printed $cgiPrinted \
1752 "Listening for HTTP requests on TCP port $cgiPort, IPv4 and IPv6"
1753 test_eq cgi-server-any-address-reply [cgi_status $cgiReply] "HTTP/1.0 200 OK"
 
1754 }
1755
1756 # A unix socket in place of a port. The server makes the socket, and
1757 # takes the place of a socket of the same name that is left from an
1758 # earlier server. --socket-owner names the owner of the socket.
@@ -1762,15 +1922,15 @@
1762 foreach {cgiName cgiOptions} [list \
1763 new {--socket-name sock1} \
1764 replaced {--socket-name sock1} \
1765 owner [list --socket-owner $cgiUser --socket-name sock1] \
1766 ] {
1767 lassign [cgi_serve_once $cgiOptions unix sock1 [cgi_get /login]] \
1768 cgiPrinted cgiReply
1769 test cgi-server-unix-$cgiName {
1770 $cgiPrinted eq "Listening for HTTP requests on unix socket sock1"
1771 && [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1772 && [file type sock1] eq "socket"
1773 && [file attributes sock1 -owner] eq $cgiUser}
1774 }
1775 # --socket-mode gives the permissions of the socket; without it they
1776 # are 0660.
@@ -1777,15 +1937,15 @@
1777 foreach {cgiName cgiOptions cgiMode} {
1778 mode {--socket-mode 0600 --socket-name sock2} 600
1779 default {--socket-name sock2} 660
1780 } {
1781 file delete sock2
1782 lassign [cgi_serve_once $cgiOptions unix sock2 [cgi_get /login]] \
1783 cgiPrinted cgiReply
1784 test cgi-server-unix-$cgiName {
1785 $cgiPrinted eq "Listening for HTTP requests on unix socket sock2"
1786 && [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1787 && [format %o [expr {[file attributes sock2 -permissions] & 0o777}]]
1788 eq $cgiMode}
1789 }
1790 fossil_raw -seconds 30 server --socket-mode rw --socket-name sock3 $cgiRepo
1791 test cgi-server-unix-mode-not-a-number {$CODE == 1 && [string match \
@@ -1801,25 +1961,25 @@
1801 proc cgi_serve_start {options {command server} {wrap {}}} {
1802 global fossilexe cgiRepo
1803 file delete server.out server.err
1804 set pid [exec {*}$wrap $fossilexe $command --localauth {*}$options \
1805 $cgiRepo > server.out 2> server.err &]
1806 for {set i 0} {$i < 100} {incr i} {
1807 after 100
1808 if {[string match "*Listening for*" [read_file server.out]]} break
1809 }
1810 after 300
1811 return $pid
1812 }
1813 # Stop the server with process id PID: ask it to end, and kill it if
1814 # it has not ended after five seconds.
1815 proc cgi_serve_stop {pid} {
1816 catch {exec kill $pid}
1817 for {set i 0} {$i < 50 && ![catch {exec kill -0 $pid}]} {incr i} {
1818 after 100
1819 }
1820 catch {exec kill -9 $pid}
 
 
 
 
 
 
1821 }
1822
1823 # A process that handles a request is killed before the request is
1824 # complete. The server goes on to answer the next request, and one
1825 # that traces its work reports the signal that ended the process.
@@ -1831,28 +1991,27 @@
1831 set cgiPort [cgi_free_port]
1832 set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort \
1833 {*}$cgiOptions]]
1834 set cgiReply ""
1835 catch {
1836 set cgiSock [socket 127.0.0.1 $cgiPort]
1837 fconfigure $cgiSock -translation binary
1838 puts -nonewline $cgiSock "GET /login HTTP/1.1\r\n"
1839 flush $cgiSock
1840 after 500
1841 exec kill -9 {*}[exec pgrep -P $cgiPid]
1842 after 500
1843 close $cgiSock
1844 set cgiReply [cgi_client 127.0.0.1 $cgiPort [cgi_get /login]]
 
1845 }
1846 cgi_serve_stop $cgiPid
1847 test cgi-server-child-killed-$cgiName {
1848 [cgi_status $cgiReply] eq "HTTP/1.0 200 OK"
1849 && ($cgiReport eq ""
1850 ? ![string match "*exited on signal*" [read_file server.err]]
1851 : [string match $cgiReport [read_file server.err]])}
1852 }
1853 foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog }
1854 } else {
1855 test_skip_part "no pgrep program: the killed server process tests"
1856 }
1857
1858 # A server that is not allowed another process cannot start the
@@ -1864,11 +2023,11 @@
1864 && [auto_execok bash] ne ""} {
1865 set cgiPort [cgi_free_port]
1866 set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort] ui \
1867 [list bash -c {ulimit -u 1 && exec "$@"} bash]]
1868 set cgiReply unset
1869 catch {set cgiReply [cgi_client 127.0.0.1 $cgiPort [cgi_get /login]]}
1870 set cgiAlive [expr {![catch {exec kill -0 $cgiPid}]}]
1871 cgi_serve_stop $cgiPid
1872 test cgi-server-no-process-browser {[string match \
1873 "*cannot start browser: echo*" [read_file server.err]]}
1874 test cgi-server-no-process-request {$cgiReply eq "" && $cgiAlive}
1875
--- test/cgi.test
+++ test/cgi.test
@@ -5,15 +5,10 @@
5 # the parameters the server read from the request.
6 #
7 # Plain HTTP, the same request arriving over ssh, and SCGI.
8 #
9
 
 
 
 
 
10 test_setup
11
12 write_file a.txt "an unversioned file\n"
13 fossil uv add a.txt
14 set cgiRepo [file join [pwd] .rep.fossil]
@@ -20,28 +15,18 @@
15
16 # Send the request in TEXT, a string of bytes, to the server and return
17 # the reply. ARGS are more options for "fossil http".
18 #
19 proc cgi_send {text args} {
20 return [fossil_http $::cgiRepo $text {*}$args]
 
 
 
 
 
21 }
22
23 # The same, as a local administrator.
24 proc cgi_admin {text args} {
25 return [cgi_send $text --ipaddr 127.0.0.1 --localauth {*}$args]
26 }
27
 
 
 
 
 
28 # The value of parameter NAME as /test-env shows it, or "-" if it does
29 # not show it.
30 proc cgi_param {reply name} {
31 set start [string first "\n$name = " $reply]
32 if {$start < 0} { return - }
@@ -49,47 +34,29 @@
34 set end [string first " <br>" $reply $start]
35 if {$end < 0} { return - }
36 return [string range $reply $start [expr {$end - 1}]]
37 }
38
39 # A POST request with BODY as its content, of the type TYPE, and the
40 # header lines in HEADERS, a list.
41 proc cgi_post {type body {path /test-env} {headers {}}} {
42 return [request_post $path $body $headers $type]
43 }
44
45 # A POST of the form data BODY to PATH, sent from the page REFERER.
46 proc cgi_post_from {referer path body} {
47 return [cgi_post application/x-www-form-urlencoded $body $path \
48 [list "Referer: $referer"]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49 }
50
51 ###############################################################################
52 # Plain HTTP.
53
54 set cgiReply [cgi_admin \
55 "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"]
56 test cgi-get {$CODE == 0}
57 test_eq cgi-get-status [reply_status $cgiReply] "HTTP/1.0 200 OK"
58 test_eq cgi-get-plain [cgi_param $cgiReply a] 1
59 test_eq cgi-get-plus [cgi_param $cgiReply b] "two words"
60 test_eq cgi-get-escape [cgi_param $cgiReply c] AB
61 test_eq cgi-get-empty [cgi_param $cgiReply d] ""
62 test_eq cgi-get-no-value [cgi_param $cgiReply e] ""
@@ -104,22 +71,26 @@
71 no-method "\r\n\r\n" \
72 bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \
73 ] {
74 set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1]
75 test cgi-malformed-$cgiName \
76 {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]}
77 }
78
79 # A request line with no path is a request for the home page.
80 set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1]
81 test_eq cgi-no-path [reply_status $cgiReply] "HTTP/1.0 302 Moved Temporarily"
82
83 ###############################################################################
84 # Form data in several parts, as a browser sends an upload.
85
86 proc cgi_part {name body {extra ""}} {
87 return \
88 [join [list \
89 "--XB\r\n" \
90 "Content-Disposition: form-data; " \
91 "name=\"$name\"$extra\r\n\r\n$body\r\n"] ""]
92 }
93 set cgiType "multipart/form-data; boundary=XB"
94
95 set cgiReply [cgi_admin [cgi_post $cgiType \
96 "[cgi_part alpha {first value}][cgi_part upload {file body} \
@@ -128,11 +99,16 @@
99 test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body"
100 test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt
101 test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9
102
103 set cgiReply [cgi_admin [cgi_post $cgiType \
104 [join [list \
105 "--XB\r\n" \
106 "Content-Disposition: form-data; name=\"t\"; " \
107 "filename=\"t.bin\"\r\n" \
108 "Content-Type: application/octet-stream\r\n\r\nxyz\r\n" \
109 "--XB--\r\n"] ""]]]
110 test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \
111 application/octet-stream
112
113 # A name that begins with a capital is taken in lower case.
114 set cgiReply [cgi_admin [cgi_post $cgiType \
@@ -146,11 +122,14 @@
122 test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value
123
124 # A part with no closing boundary after a long one ends at the end of the
125 # request, and every part is read within the request.
126 set cgiReply [cgi_admin [cgi_post $cgiType \
127 [join [list \
128 "[cgi_part alpha [string repeat x 3000]]--XB\r\n" \
129 "Content-Disposition: form-data; name=\"beta\"\r\n\r\n" \
130 "no closing boundary"] ""]]]
131 test cgi-multipart-unclosed {$CODE == 0}
132 test_eq cgi-multipart-unclosed-first \
133 [string length [cgi_param $cgiReply alpha]] 3000
134 test_eq cgi-multipart-unclosed-second [cgi_param $cgiReply beta] \
135 "no closing boundary"
@@ -163,19 +142,36 @@
142 "--XB" \
143 "--XB\r\n" \
144 "--XB\r\n\r\nno name here\r\n--XB--\r\n" \
145 "--XB\r\nContent-Disposition: form-data; name=\"a\"" \
146 "[cgi_part a "one\000two"]--XB--\r\n" \
147 [join [list \
148 "--XB\r\n" \
149 "Content-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n" \
150 "--XB--\r\n"] ""] \
151 [join [list \
152 "--[string repeat B 3000]\r\n" \
153 "Content-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n"] ""] \
154 [join [list \
155 "[cgi_part a [string repeat x 2000]]--XB\r\n" \
156 "Content-Disposition: form-data; name=\"b\""] ""] \
157 "[cgi_part {} v]--XB--\r\n" \
158 [join [list \
159 "--XB\r\n" \
160 "Content-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n" \
161 "--XB--\r\n"] ""] \
162 [join [list \
163 "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\n" \
164 "v\r\n--XB--\r\n"] ""] \
165 "--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \
166 [join [list \
167 "--XB\r\n" \
168 "Content-Disposition: form-data; name=\"a\"; " \
169 "filename=\r\n\r\nv\r\n--XB--\r\n"] ""] \
170 [join [list \
171 "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\n" \
172 "content-type:\r\n\r\nv\r\n--XB--\r\n"] ""] \
173 "[cgi_part a "\n--X"]--XB--\r\n" \
174 ] {
175 incr cgiI
176 cgi_admin [cgi_post $cgiType $cgiBody]
177 test cgi-multipart-odd-$cgiI {$CODE == 0}
@@ -190,12 +186,14 @@
186 ###############################################################################
187 # The date in an If-Modified-Since header. A file that has not changed
188 # since that date is not sent again.
189
190 proc cgi_since {date} {
191 set reply [cgi_send \
192 "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" \
193 --ipaddr 127.0.0.1]
194 return [reply_status $reply]
195 }
196 test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \
197 "HTTP/1.0 304 Not Modified"
198 test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \
199 "HTTP/1.0 200 OK"
@@ -220,24 +218,29 @@
218 g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1
219 g.ico 1 g.png 0 g.zip 0 g.pdf 0
220 } {
221 write_file $cgiName [string repeat "content to compress\n" 50]
222 fossil uv add $cgiName
223 set cgiReply [cgi_send \
224 [join [list \
225 "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\n" \
226 "Accept-Encoding: gzip, deflate\r\n\r\n"] ""] --ipaddr 127.0.0.1]
227 test_eq cgi-gzip-$cgiName \
228 [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip
229 }
230 set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" \
231 --ipaddr 127.0.0.1]
232 test cgi-gzip-not-accepted {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
233 && ![string match "*Content-Encoding*" $cgiReply]}
234
235 ###############################################################################
236 # A POST whose Referer is another site is not taken as safe from forgery,
237 # and is written to the error log.
238
239 proc cgi_logout {referer} {
240 return [cgi_send [cgi_post_from $referer /login "out=1"] --ipaddr 10.0.0.1 \
241 --errorlog [file join [pwd] err.log]]
242 }
243 file delete err.log
244 cgi_logout http://x/login
245 test cgi-same-origin-not-logged {![file exists err.log]
246 || ![string match "*different origin*" [read_file err.log]]}
@@ -257,11 +260,11 @@
260 set cgiReply [cgi_send [cgi_scgi {
261 CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1
262 PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80
263 REMOTE_ADDR 127.0.0.1
264 }] --scgi --localauth]
265 test_eq cgi-scgi [reply_status $cgiReply] "HTTP/1.0 200 OK"
266 test_eq cgi-scgi-param [cgi_param $cgiReply s] 1
267
268 foreach {cgiName cgiRequest} [list \
269 too-short "15:CONTENT_LENGTH\0000\000," \
270 cut-short "40:CONTENT_LENGTH\0000\000," \
@@ -268,20 +271,21 @@
271 no-zero "20:CONTENT_LENGTH0000000000," \
272 huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \
273 ] {
274 set cgiReply [cgi_send $cgiRequest --scgi]
275 test cgi-scgi-$cgiName {$CODE == 0 &&
276 [string match "HTTP/1.0 400*" [reply_status $cgiReply]]}
277 }
278
279 ###############################################################################
280 # The same reader for a request that arrives over ssh, which the server
281 # knows from SSH_CONNECTION. It reads the client's probes first.
282
283 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
284 set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" \
285 --localauth]
286 test_eq cgi-ssh [reply_status $cgiReply] "HTTP/1.0 200 OK"
287 test_eq cgi-ssh-param [cgi_param $cgiReply q] 1
288 test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1
289
290 set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \
291 "p=posted"] --localauth]
@@ -288,11 +292,14 @@
292 test_eq cgi-ssh-post [cgi_param $cgiReply p] posted
293
294 # An older client opens the connection with "echo" probes, each of which
295 # the server answers with the word it was given, and then names the
296 # command it ran. Any other word in a probe is refused.
297 set cgiReply [cgi_send \
298 [join [list \
299 "echo test1\necho probe-2\nfossil\n" \
300 "GET /test-env?q=3 HTTP/1.1\r\nHost: x\r\n\r\n"] ""] --localauth]
301 test cgi-ssh-probes {[string match "test1\nprobe-2\n*" $cgiReply]
302 && [string match "*\nHTTP/1.0 200 OK*" $cgiReply]}
303 test_eq cgi-ssh-probes-param [cgi_param $cgiReply q] 3
304 foreach {cgiName cgiRequest} [list \
305 probe-word "echo hello\n" \
@@ -312,18 +319,26 @@
319 ] {
320 cgi_send $cgiRequest
321 test cgi-ssh-$cgiName {$CODE == 0 || $CODE == 1}
322 }
323 unset ::env(SSH_CONNECTION)
324
325 ###############################################################################
326 # The tests above try each kind of request once. The tests below aim
327 # at every branch of cgi.c.
328
329 if {[test_assurance] eq "smoke"} {
330 test_skip "the tests of each branch need -assurance ci or stress"
331 }
332
333 ###############################################################################
334 # Names and values in a query string and in a Cookie header. A name is
335 # taken when it begins with a letter and holds only letters, digits,
336 # "_" and "-"; of two values with one name the first is kept; a value
337 # from the query string that holds a control character is dropped.
338
339 set cgiReply [cgi_admin [request_get \
340 "/test-env?e&a=1&=5&&a\$b=6&c=%01x&1a=2&_u=3&a=second&Up=4&zz" \
341 [list "Cookie: ck=1; sp=2; fossil-x=9; Big=3"]]]
342 foreach {cgiName cgiParam cgiValue} {
343 no-value-first e ""
344 plain a 1
@@ -342,11 +357,11 @@
357 } {
358 test_eq cgi-names-$cgiName [cgi_param $cgiReply $cgiParam] $cgiValue
359 }
360
361 # With "showall" the page shows the cookies as well.
362 set cgiReply [cgi_admin [request_get /test-env?showall \
363 [list "Cookie: ck=1; fossil-x=9"]]]
364 test_eq cgi-showall-cookie [cgi_param $cgiReply fossil-x] 9
365 test_eq cgi-showall-header [cgi_param $cgiReply HTTP_COOKIE] "ck=1; fossil-x=9"
366
367 # A value in a form may hold a control character.
@@ -362,11 +377,16 @@
377 && [string match "*Too many query parameters*" $cgiReply$RESULT]}
378
379 ###############################################################################
380 # The request line and the header lines.
381
382 set cgiReply [cgi_admin \
383 [join [list \
384 "GET /test-env?showall HTTP/1.1\r\n" \
385 "HOST: named.example:8080\r\nIf-None-Match: tag\r\n" \
386 "Authorization: Basic eDp5\r\nAccept-Language: de \r\n" \
387 "User-Agent: Agent/1\r\nUnknown-Header: ignored\r\n\r\n"] ""]]
388 foreach {cgiParam cgiValue} {
389 HTTP_HOST named.example:8080
390 SERVER_NAME named.example
391 HTTP_IF_NONE_MATCH tag
392 HTTP_AUTHORIZATION {Basic eDp5}
@@ -378,12 +398,12 @@
398 test_eq cgi-header-$cgiParam [cgi_param $cgiReply $cgiParam] $cgiValue
399 }
400
401 # An "Https:" header says that the request came by https, so the reply
402 # sends a local user to the https login page.
403 set cgiReply [cgi_admin [request_get /test-env [list "Https: on"]]]
404 test_eq cgi-header-https [reply_header $cgiReply Location] \
405 https://x/login?g=test-env
406
407 # X-Forwarded-For names the client when the request comes from this
408 # machine: the last address in it is taken. From any other machine the
409 # header is ignored. Only a local client sees /test-env here.
@@ -394,34 +414,44 @@
414 mapped 127.0.0.1 ::ffff:127.0.0.1 ::ffff:127.0.0.1
415 remote 127.0.0.1 {127.0.0.1, 9.9.9.9} -
416 empty 127.0.0.1 {} -
417 not-local 10.0.0.1 127.0.0.1 -
418 } {
419 set cgiReply [cgi_send [request_get /test-env \
420 [list "X-Forwarded-For: $cgiForwarded"]] --ipaddr $cgiFrom --localauth]
421 test_eq cgi-forwarded-$cgiName [cgi_param $cgiReply REMOTE_ADDR] $cgiAddr
422 }
423
424 # HEAD gets the headers of the reply to GET and no content.
425 set cgiReply [cgi_send [request_get /uv/g.png {} HEAD] --ipaddr 127.0.0.1]
426 test_eq cgi-head-status [reply_status $cgiReply] "HTTP/1.0 200 OK"
427 test_eq cgi-head-length [reply_header $cgiReply Content-Length] 1000
428 test_eq cgi-head-body [reply_body $cgiReply] ""
429
430 # A POST must say how long its content is, and send that much.
431 set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\n\r\n"]
432 test cgi-post-no-length {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
433 && [string match "*missing CONTENT_LENGTH on a POST method*" $cgiReply]}
434 set cgiReply [cgi_admin \
435 [join [list \
436 "POST /test-env HTTP/1.1\r\nHost: x\r\n" \
437 "Content-Type: application/x-www-form-urlencoded\r\n" \
438 "Content-Length: 50\r\n\r\na=1"] ""]]
439 test cgi-post-short {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
440 && [string match "*Wanted 50 bytes but got only 3*" $cgiReply]}
441 # Content with no type is not read.
442 set cgiReply [cgi_admin \
443 "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\n\r\na=1"]
444 test cgi-post-no-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
445 && [cgi_param $cgiReply a] eq "-"}
446 foreach {cgiName cgiLength} \
447 {negative -5 zero 0 word abc huge 99999999999999999999} {
448 set cgiReply [cgi_admin \
449 [join [list \
450 "POST /test-env HTTP/1.1\r\nHost: x\r\n" \
451 "Content-Type: application/x-www-form-urlencoded\r\n" \
452 "Content-Length: $cgiLength\r\n\r\na=1"] ""]]
453 test cgi-post-length-$cgiName {$CODE == 0
454 && [regexp {^HTTP/1.0 (200|400) } $cgiReply]}
455 }
456
457 ###############################################################################
@@ -429,22 +459,22 @@
459 # asked for, not compressed, with status 206.
460
461 write_file r.css 0123456789abcdefghij
462 fossil uv add r.css
463 proc cgi_range {range {method GET} {file r.css}} {
464 return [cgi_send [request_get /uv/$file \
465 [list "Range: $range" "Accept-Encoding: gzip"] $method] \
466 --ipaddr 127.0.0.1]
467 }
468 set cgiReply [cgi_range bytes=2-5]
469 test_eq cgi-range-status [reply_status $cgiReply] "HTTP/1.0 206 Partial Content"
470 test_eq cgi-range-header [reply_header $cgiReply Content-Range] "bytes 2-5/20"
471 test_eq cgi-range-length [reply_header $cgiReply Content-Length] 4
472 test_eq cgi-range-encoding [reply_header $cgiReply Content-Encoding] -
473 test_eq cgi-range-body [reply_body $cgiReply] 2345
474 set cgiReply [cgi_range bytes=0-0]
475 test_eq cgi-range-first-byte [reply_body $cgiReply] 0
476 # A range that is not two numbers in order is ignored.
477 foreach {cgiName cgiRange} {
478 word bytes=abc
479 one-number bytes=5-
480 negative bytes=-5-10
@@ -451,36 +481,36 @@
481 backwards bytes=9-3
482 other-unit lines=1-2
483 } {
484 set cgiReply [cgi_range $cgiRange]
485 test cgi-range-ignored-$cgiName {
486 [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
487 && [reply_header $cgiReply Content-Encoding] eq "gzip"}
488 }
489 # A range that runs past the end of the file stops at the end.
490 set cgiReply [cgi_range bytes=15-2147483646]
491 test_eq cgi-range-past-end [reply_body $cgiReply] fghij
492 test_eq cgi-range-past-end-header [reply_header $cgiReply Content-Range] \
493 "bytes 15-19/20"
494 test_eq cgi-range-past-end-length [reply_header $cgiReply Content-Length] 5
495 # A range that starts at or after the end gets 416 and no content.
496 foreach {cgiName cgiRange} {at-end bytes=20-20 after-end bytes=25-30} {
497 set cgiReply [cgi_range $cgiRange]
498 test cgi-range-unsatisfiable-$cgiName {
499 [reply_status $cgiReply] eq "HTTP/1.0 416 Range Not Satisfiable"
500 && [reply_header $cgiReply Content-Range] eq "bytes */20"
501 && [reply_header $cgiReply Content-Length] eq "0"}
502 }
503 # A number too large for an int is not taken as a smaller one.
504 set cgiReply [cgi_range bytes=0-4294967299]
505 test_eq cgi-range-too-large [reply_status $cgiReply] "HTTP/1.0 200 OK"
506 # A reply other than 206 is sent whole, whatever range was asked for.
507 set cgiReply [cgi_send [request_get /uv/nosuch.css [list "Range: bytes=3-9"]] \
508 --ipaddr 127.0.0.1]
509 test cgi-range-not-found {
510 [string match "HTTP/1.0 404 *" [reply_status $cgiReply]]
511 && [string match "<!DOCTYPE*" [reply_body $cgiReply]]}
512
513 ###############################################################################
514 # More shapes of form data in several parts.
515
516 proc cgi_form {body} {
@@ -497,58 +527,87 @@
527 set cgiReply [cgi_form "[cgi_part Shout loud]--XB--\r\n"]
528 test_eq cgi-multipart-upper-plain [cgi_param $cgiReply shout] loud
529 test_eq cgi-multipart-upper-no-bytes [cgi_param $cgiReply shout:bytes] -
530
531 # A name in capitals with a type of content.
532 set cgiReply [cgi_form \
533 [join [list \
534 "--XB\r\n" \
535 "Content-Disposition: form-data; name=\"Typed\"; " \
536 "filename=\"t\"\r\nContent-Type: text/x-test\r\n\r\nv\r\n" \
537 "--XB--\r\n"] ""]]
538 test_eq cgi-multipart-upper-mimetype [cgi_param $cgiReply typed:mimetype] \
539 text/x-test
540 test_eq cgi-multipart-upper-bytes [cgi_param $cgiReply typed:bytes] 1
541
542 # A name that does not begin with a letter is not taken, with or without
543 # a file name or a type.
544 set cgiReply [cgi_form \
545 [join [list \
546 "--XB\r\n" \
547 "Content-Disposition: form-data; name=\"1st\"; " \
548 "filename=\"f\"\r\nContent-Type: text/plain\r\n\r\nv\r\n" \
549 "[cgi_part after ok]--XB--\r\n"] ""]]
550 test_eq cgi-multipart-digit-name [cgi_param $cgiReply 1st] -
551 test_eq cgi-multipart-digit-filename [cgi_param $cgiReply 1st:filename] -
552 test_eq cgi-multipart-digit-mimetype [cgi_param $cgiReply 1st:mimetype] -
553 test_eq cgi-multipart-digit-next [cgi_param $cgiReply after] ok
554
555 # A type or a file name given before the name belongs to no parameter.
556 set cgiReply [cgi_form \
557 [join [list \
558 "--XB\r\nContent-Type: text/early\r\n" \
559 "Content-Disposition: form-data; filename=\"early\"; " \
560 "name=\"late\"\r\n\r\nv\r\n--XB--\r\n"] ""]]
561 test_eq cgi-multipart-type-first-value [cgi_param $cgiReply late] v
562 test_eq cgi-multipart-type-first-mimetype [cgi_param $cgiReply late:mimetype] -
563 test_eq cgi-multipart-type-first-filename [cgi_param $cgiReply late:filename] -
564
565 # Words in a header line that the reader does not know are passed over.
566 set cgiReply [cgi_form \
567 [join [list \
568 "--XB\r\n" \
569 "Content-Disposition: form-data; nonce=1; foo=2; charset=3; " \
570 "xyz; name=\"known\"\r\n\r\nv\r\n--XB--\r\n"] ""]]
571 test_eq cgi-multipart-unknown-words [cgi_param $cgiReply known] v
572
573 # A quoted word that reaches the end of a header line without a closing
574 # quote. The request must be answered within the time limit.
575 set cgiBody \
576 [join [list \
577 "--XB\r\nContent-Disposition: form-data; name=\"\r\n\r\nv\r\n" \
578 "[cgi_part after ok]--XB--\r\n"] ""]
579 write_file request.txt [cgi_post $cgiType $cgiBody]
580 file delete reply.txt
581 fossil_raw -seconds 15 http $cgiRepo --in request.txt --out reply.txt \
582 --ipaddr 127.0.0.1 --localauth
583 test cgi-multipart-lone-quote {$CODE == 0}
584
585 # Only the first 49 words of a header line are read.
586 set cgiWords ""
587 for {set cgiI 0} {$cgiI < 30} {incr cgiI} \
588 { append cgiWords " w$cgiI \"q$cgiI\";" }
589 set cgiReply [cgi_form \
590 [join [list \
591 "--XB\r\n" \
592 "Content-Disposition: form-data;$cgiWords " \
593 "name=\"far\"\r\n\r\nv\r\n[cgi_part after ok]--XB--\r\n"] ""]]
594 test_eq cgi-multipart-many-words [cgi_param $cgiReply far] -
595 test_eq cgi-multipart-many-words-next [cgi_param $cgiReply after] ok
596
597 # A quote that ends a header line after a space is a word of no
598 # characters, so the part has no name.
599 set cgiReply [cgi_form \
600 [join [list \
601 "--XB\r\nContent-Disposition: form-data; name= \"\r\n\r\n" \
602 "v\r\n[cgi_part after ok]--XB--\r\n"] ""]]
603 test {cgi-multipart-quote-alone} {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
604 && [cgi_param $cgiReply after] eq "ok"}
605
606 # Content that begins with a zero byte has no parts.
607 set cgiReply [cgi_form "\000--XB\r\n[cgi_part a v]--XB--\r\n"]
608 test cgi-multipart-zero-first {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
609 && [cgi_param $cgiReply a] eq "-"}
610
611 ###############################################################################
612 # More dates in If-Modified-Since. The file is given the time that the
613 # date stands for and is then not sent again; one second newer and it is.
@@ -557,13 +616,14 @@
616 fossil uv add d.bin
617 proc cgi_since_exact {date seconds} {
618 set result ""
619 foreach mtime [list $seconds [expr {$seconds + 1}]] {
620 fossil sql "UPDATE unversioned SET mtime=$mtime WHERE name='d.bin'"
621 set reply [cgi_send [request_get /uv/d.bin \
622 [list "If-Modified-Since: $date"]] \
623 --ipaddr 127.0.0.1]
624 lappend result [lindex [reply_status $reply] 1]
625 }
626 return $result
627 }
628 foreach {cgiName cgiDate cgiSeconds} {
629 epoch-year "Thu, 01 Jan 1970 00:00:10 GMT" 10
@@ -594,13 +654,13 @@
654 second-61 "Mon, 01 Jan 2026 00:00:61 GMT"
655 month "Mon, 01 Foo 2026 00:00:00 GMT"
656 short "Mon, 01 Jan 2026"
657 empty ""
658 } {
659 set cgiReply [cgi_send [request_get /uv/d.bin \
660 [list "If-Modified-Since: $cgiDate"]] --ipaddr 127.0.0.1]
661 test_eq cgi-since-not-a-date-$cgiName [reply_status $cgiReply] \
662 "HTTP/1.0 200 OK"
663 }
664
665 ###############################################################################
666 # Redirects. A redirect to an absolute URL is sent as it is; a redirect
@@ -610,12 +670,12 @@
670 # the user-edit cancel button.
671
672 proc cgi_redirect_to {query {referer none}} {
673 set headers {}
674 if {$referer ne "none"} { lappend headers "Referer: $referer" }
675 set reply [cgi_admin [request_get "/setup_uedit?$query" $headers]]
676 return [reply_header $reply Location]
677 }
678 # The cancel button redirects to the referer.
679 test_eq cgi-redirect-absolute-http [cgi_redirect_to can=1 http://other/p] \
680 http://other/p
681 test_eq cgi-redirect-absolute-https [cgi_redirect_to can=1 https://other/p] \
@@ -639,63 +699,64 @@
699 proc cgi_csrf_level {reply} {
700 if {[regexp {CSRF safety = ([^<]*)} $reply all level]} { return $level }
701 return -
702 }
703 set cgiToken ""
704 set cgiReply [cgi_admin [request_get /setup_uedit?id=0]]
705 regexp {name="csrf" value="([^"]*)"} $cgiReply all cgiToken
706
707 set cgiReply [cgi_admin [request_get /test-env [list "Referer: http://x/prev"]]]
708 test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin"
709 proc cgi_env_post {body {referer http://x/prev}} {
710 return [cgi_admin [cgi_post_from $referer /test-env $body]]
711 }
712 set cgiReply [cgi_env_post "csrf=$cgiToken"]
713 test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] \
714 "Same origin, POST, CSRF token"
715 set cgiReply [cgi_env_post "csrf=wrong"]
716 test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST"
717 set cgiReply [cgi_env_post "x=1" http://elsewhere/p]
718 test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe"
719
720 # A page that consults the check more than once. A cross-origin POST to
721 # the user-edit page, which asks twice, is ignored without error.
722 set cgiReply [cgi_admin [cgi_post_from http://elsewhere/p /setup_uedit \
723 "id=0&delete=1&"]]
724 test_eq cgi-csrf-twice-cross [reply_status $cgiReply] "HTTP/1.0 200 OK"
725 # A valid same-origin POST with the token creates the user.
726 set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken"
727 set cgiReply [cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit \
728 $cgiBody]]
729 test cgi-csrf-verify-accepts \
730 {[string match "HTTP/1.0 302*" [reply_status $cgiReply]]}
731 test cgi-csrf-user-created \
732 {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1}
733
734 # The user-edit page needs "login", "info", "pw" and "apply" to make a
735 # change. A request with "login" alone changes nothing.
736 set cgiBody "id=0&login=cgighost&csrf=$cgiToken"
737 cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit $cgiBody]
738 test cgi-all-needs-every-field \
739 {[fossil sql "SELECT count(*) FROM user WHERE login='cgighost'"] == 0}
740
741 ###############################################################################
742 # Request methods and the same reader over ssh.
743
 
744 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
 
 
 
745 # A HEAD over ssh.
746 set cgiReply [cgi_send [request_get /test-env?q=9 {} HEAD] --localauth]
747 test_eq cgi-ssh-head [reply_status $cgiReply] "HTTP/1.0 200 OK"
748 unset ::env(SSH_CONNECTION)
749
750 ###############################################################################
751 # cgi_from_mobile, used by /forum to pick a default display order. An
752 # iPad is not treated as mobile; another phone is; no agent is not.
753 proc cgi_forum_order {agent} {
754 set headers {}
755 if {$agent ne ""} { lappend headers "User-Agent: $agent" }
756 set reply [cgi_admin [request_get /forum?t=a $headers]]
757 return [reply_status $reply]
758 }
759 foreach {cgiName cgiAgent} {
760 phone "Mozilla/5.0 (iPhone; Mobile) Safari"
761 ipad "Mozilla/5.0 (iPad) Safari"
762 none ""
@@ -709,47 +770,44 @@
770 # and a note in the error log. The whole request environment is written
771 # to the log.
772
773 proc cgi_attack {value} {
774 global cgiRepo
775 write_file request.txt \
776 [join [list \
777 "GET /timeline?inj=$value HTTP/1.1\r\nHost: x\r\n" \
778 "Cookie: fossil-x=secret\r\n\r\n"] ""]
779 file delete reply.txt attack.log
780 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
781 --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log]
782 return [expr {[file exists reply.txt] ? [read_file reply.txt] : ""}]
783 }
784 set cgiReply [cgi_attack "1;select"]
785 test_eq cgi-attack-status [reply_status $cgiReply] "HTTP/1.0 418 I'm a teapot"
786 test cgi-attack-logged {[file exists attack.log]
787 && [string match "*possible hack attempt*" [read_file attack.log]]
788 && [string match "*QUERY_STRING = inj=1;select*" [read_file attack.log]]}
789 # A value longer than 100 characters is shortened in the log.
790 set cgiReply [cgi_attack "[string repeat a 200];x"]
791 test cgi-attack-long {[reply_status $cgiReply] eq "HTTP/1.0 418 I'm a teapot"
792 && [string match "*aaa...*" [read_file attack.log]]}
793 # A logged-in request with the same value is not stopped.
794 set cgiReply [cgi_admin [request_get "/timeline?inj=1;select"]]
795 test_eq cgi-attack-admin-ok [reply_status $cgiReply] "HTTP/1.0 200 OK"
796
797 ###############################################################################
798 # The same-origin test with crafted Referer headers. The base URL here
799 # is "http://x". A Referer that shares the base but has more path after
800 # it with no "/" boundary is a different origin. A Referer with a "%"
801 # escape is decoded before the comparison. The /test-env page reports
802 # the result.
803
804 proc cgi_origin {referer} {
805 set req "GET /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\n\r\n"
 
 
 
 
 
806 set reply [cgi_admin $req]
807 return [cgi_csrf_level $reply]
808 }
 
809 test_eq cgi-origin-boundary [cgi_origin http://xtra/page] unsafe
810 test_eq cgi-origin-escaped [cgi_origin http://x/a%2Fb] "Same origin"
811 # A different-origin GET reaches the method test in the same-origin check
812 # without writing a warning (the warning is for POST only).
813 test_eq cgi-origin-get-other [cgi_origin http://elsewhere/p] unsafe
@@ -756,36 +814,37 @@
814
815 ###############################################################################
816 # cgi_parameter_name walks every parameter: the ticket-entry page copies
817 # each into its interpreter.
818
819 set cgiReply [cgi_admin [request_get "/tktnew?username=someone&extra=1"]]
820 test_eq cgi-param-name-page [reply_status $cgiReply] "HTTP/1.0 200 OK"
821
822 ###############################################################################
823 # cgi_param_info walks the parameters for the /cookies page.
824
825 set cgiReply [cgi_admin [request_get /cookies \
826 [list "Cookie: fossil_display_settings=x; extra=y"]]]
827 test cgi-param-info-page {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
828 && [string match "*fossil_display_settings*" $cgiReply]}
829
830 ###############################################################################
831 # Two more destinations for cgi_print_all. With --cgitrace the whole
832 # parameter set is traced before the page runs.
833
834 write_file request.txt [request_get "/test-env?traced=1"]
835 file delete reply.txt
836 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
837 --ipaddr 127.0.0.1 --localauth --cgitrace
838 test cgi-cgitrace {$CODE == 0
839 && [string match "*Calling*" $RESULT]
840 && [string match "*traced = 1*" $RESULT]}
841
842 # A CGI control file with "cgi-debug:" writes the environment to a debug
843 # file as the control file is read.
844 write_file cgi.ctl \
845 "repository: [file nativename $cgiRepo]\ncgi-debug: debug.txt\n"
846 file delete debug.txt
847 set ::env(REQUEST_METHOD) GET
848 set ::env(SCRIPT_NAME) ""
849 set ::env(PATH_INFO) /test-env
850 set ::env(QUERY_STRING) "dbg=1"
@@ -802,37 +861,49 @@
861 # email-alert subscription page. The page exists once email is enabled
862 # and its tables are built.
863
864 fossil settings email-send-method db
865 set cgiNotifyBody "submit=Refresh&esm=db&csrf=$cgiToken"
866 cgi_admin [cgi_post_from http://x/setup_notification /setup_notification \
867 $cgiNotifyBody]
868 test cgi-alert-tables-built \
869 {[fossil sql "SELECT count(*) FROM sqlite_schema WHERE name='subscriber'"]
870 == 1}
871
872 # The form renders the "checked" state of the checkboxes.
873 set cgiReply [cgi_admin [request_get /subscribe]]
874 test cgi-subscribe-form {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
875 && [string match "*checkbox*" $cgiReply]}
876
877 # A submitted subscription: the name is trimmed and the boxes are read as
878 # booleans. A leading and trailing space on the name is removed.
879 set cgiSubBody \
880 [join [list \
881 "submit=1&[email protected]&suname= trimmed " \
882 "&sa=1&sc=on&csrf=$cgiToken"] ""]
883 cgi_admin [cgi_post_from http://x/subscribe /subscribe $cgiSubBody]
884 test_eq cgi-subscribe-trimmed-name \
885 [fossil sql \
886 "SELECT suname FROM subscriber WHERE semail='[email protected]'"] \
887 "trimmed"
888 test cgi-subscribe-boolean-alert \
889 {[string match "*a*" [fossil sql \
890 "SELECT ssub FROM subscriber WHERE semail='[email protected]'"]]}
891
892 ###############################################################################
893 # The HTTP reader is called in a loop for a request arriving over ssh.
894 # When the first request announces the Fossil ssh transport, the reader
895 # is called again for a second request in the same connection, and the
896 # later request updates the parameters that the first one set.
897
898 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
899 write_file request.txt \
900 [join [list \
901 "GET /test-env?first=1 HTTP/1.1\r\nHost: x\r\n" \
902 "X-Fossil-Transport: ssh\r\nContent-Length: 0\r\n\r\n" \
903 "GET /test-env?second=2 HTTP/1.1\r\nHost: x\r\n" \
904 "User-Agent: Later\r\n\r\n"] ""]
905 file delete reply.txt
906 fossil_raw http $cgiRepo --in request.txt --out reply.txt --localauth
907 set cgiReply [read_file reply.txt]
908 test cgi-ssh-transport-first {[string match "*first = 1*" $cgiReply]}
909 test cgi-ssh-transport-second {[string match "*second = 2*" $cgiReply]}
@@ -841,24 +912,25 @@
912 ###############################################################################
913 # The skin query parameter sets a cookie with a default path, and marks
914 # the request "udc" unless "once" is present. A cookie carrying a login
915 # card is taken out of the parameters.
916
917 set cgiReply [cgi_admin [request_get /test-env?skin=darkmode]]
918 test cgi-skin-cookie {[string match "*Set-Cookie: fossil_display_settings=*" \
919 $cgiReply] && [cgi_param $cgiReply udc] eq 1}
920 # With "once" the cookie is not written and "udc" is not forced.
921 set cgiReply [cgi_admin [request_get {/test-env?skin=darkmode&once=1}]]
922 test cgi-skin-once {![string match "*Set-Cookie: fossil_display_settings=*" \
923 $cgiReply] && [cgi_param $cgiReply udc] eq "-"}
924 # A skin cookie is honoured as well as a skin query parameter.
925 set cgiReply [cgi_admin [request_get /test-env \
926 [list "Cookie: fossil_display_settings=skin=ardoise"]]]
927 test_eq cgi-skin-from-cookie [cgi_param $cgiReply fossil_display_settings] \
928 skin=ardoise
929 # A login-card cookie is removed from the visible parameters.
930 set cgiReply [cgi_admin [request_get /test-env \
931 [list "Cookie: x-f-l-c=card-value"]]]
932 test_eq cgi-login-card-hidden [cgi_param $cgiReply x-f-l-c] -
933
934 ###############################################################################
935 # The reply content type for an unversioned file comes from the
936 # "mimetypes" setting. Parsing of the type stops at the first character
@@ -865,19 +937,19 @@
937 # outside the range "+" through "z", and a text type is compressed.
938
939 fossil settings mimetypes "zw text/x|y"
940 write_file f.zw "other text to send"
941 fossil uv add f.zw
942 set cgiReply [cgi_send [request_get /uv/f.zw] --ipaddr 127.0.0.1]
943 test cgi-content-type-stops \
944 {[string match "text/x;*" [reply_header $cgiReply Content-Type]]}
945
946 ###############################################################################
947 # A skin name that is not a known skin produces an error, so the cookie
948 # is not written.
949
950 set cgiReply [cgi_admin [request_get /test-env?skin=no_such_skin_here]]
951 test cgi-skin-unknown {![string match "*Set-Cookie: fossil_display_settings=*" \
952 $cgiReply] && [cgi_param $cgiReply skin] eq "no_such_skin_here"}
953
954 ###############################################################################
955 # Deleting a cookie: the reply carries a Set-Cookie with a value of
@@ -913,13 +985,13 @@
985 fossil commit -m "add art" --no-warnings
986 set cgiArt [fossil sql \
987 "SELECT uuid FROM blob WHERE rid=(SELECT max(rid) FROM blob)"]
988 proc cgi_raw_type {mime} {
989 global cgiArt
990 set reply [cgi_send [request_get /raw/$cgiArt?m=$mime \
991 [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth]
992 return [reply_header $reply Content-Encoding]
993 }
994 foreach {cgiName cgiMime} {
995 javascript application/javascript
996 json application/json
997 wasm application/wasm
@@ -945,46 +1017,48 @@
1017 }
1018 # With --nocompress nothing is compressed.
1019 set cgiFile [fossil sql "SELECT uuid FROM blob, mlink, filename
1020 WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
1021 AND filename.name='art.txt'"]
1022 set cgiReply [cgi_send [request_get /raw/$cgiFile?m=text/plain \
1023 [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth --nocompress]
1024 test cgi-nocompress {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1025 && [reply_header $cgiReply Content-Encoding] eq "-"
1026 && [reply_body $cgiReply] eq
1027 "the quick brown fox jumps over the lazy dog\n"}
1028
1029 ###############################################################################
1030 # More about ranges. A Range header counts only for GET, and not for
1031 # content of the type that a sync uses. Part of an artifact named by its
1032 # full hash, sent to a visitor who is not logged in, may be kept by the
1033 # client for ever.
1034
1035 set cgiReply [cgi_range bytes=2-5 HEAD]
1036 test cgi-range-head {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1037 && [reply_header $cgiReply Content-Range] eq "-"}
1038 set cgiReply [cgi_range bytes=5]
1039 test cgi-range-ignored-no-dash {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1040 && [reply_header $cgiReply Content-Range] eq "-"}
1041 set cgiReply [cgi_send [request_get /raw/$cgiArt?m=application/x-fossil \
1042 [list "Range: bytes=1-3"]] --ipaddr 127.0.0.1 --localauth]
1043 test cgi-range-sync-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1044 && [reply_header $cgiReply Content-Range] eq "-"}
1045 set cgiReply [cgi_send [request_get /raw/$cgiFile?m=text/plain \
1046 [list "Range: bytes=4-8"]] --ipaddr 9.9.9.9]
1047 test_eq cgi-range-artifact [reply_body $cgiReply] quick
1048 test_eq cgi-range-artifact-cache [reply_header $cgiReply Cache-Control] \
1049 "max-age=315360000, immutable"
1050
1051 ###############################################################################
1052 # The "at" parameter of /raw names the file for the client to save the
1053 # content in. Only its last path element is used, and every character
1054 # in it other than a letter, a digit, "." and "-" becomes "_".
1055
1056 set cgiReply [cgi_send [request_get \
1057 "/raw/$cgiArt?at=some/dir/my%20file-1%3B.txt"] \
1058 --ipaddr 127.0.0.1 --localauth]
1059 test_eq cgi-attachment-name [reply_header $cgiReply Content-Disposition] \
1060 {attachment; filename="my_file-1_.txt";}
1061
1062 ###############################################################################
1063 # A request that is refused before any repository is open: the server is
1064 # given a directory, and the request has a method it does not know.
@@ -993,11 +1067,11 @@
1067 write_file request.txt "DELETE /x HTTP/1.1\r\nHost: x\r\n\r\n"
1068 file delete reply.txt
1069 fossil_raw http [file join [pwd] norepo] --in request.txt --out reply.txt \
1070 --ipaddr 127.0.0.1
1071 test cgi-no-repository-bad-method {$CODE == 0
1072 && [reply_status [read_file reply.txt]] eq "HTTP/1.0 400 Bad Request"}
1073
1074 ###############################################################################
1075 # More of the same-origin test: a Referer that is the base URL and
1076 # nothing more is the same origin.
1077
@@ -1007,19 +1081,18 @@
1081 # With --httptrace the server reports each parameter as it is set and
1082 # copies the request into a file named httplog-NNNNN.txt in the current
1083 # directory. If it cannot make that file it says so and goes on.
1084
1085 foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog }
1086 write_file request.txt [request_get /test-env?traced=2]
1087 file delete reply.txt
1088 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
1089 --ipaddr 127.0.0.1 --localauth --httptrace
1090 set cgiLogs [glob -nocomplain httplog-*.txt]
1091 test cgi-httptrace {$CODE == 0 &&
1092 [holds_strings $RESULT [list "# cgi: traced = \[2\]" \
1093 "# open log on httplog-"]] && [llength $cgiLogs] == 1}
 
1094 if {[llength $cgiLogs] == 1} {
1095 set cgiLogText [read_file [lindex $cgiLogs 0]]
1096 test cgi-httptrace-log {
1097 [string match "GET /test-env?traced=2 HTTP/1.1*Host: x*" $cgiLogText]}
1098 file delete [lindex $cgiLogs 0]
@@ -1035,11 +1108,11 @@
1108 file delete $cgiLog
1109 }
1110 test cgi-httptrace-post-content {[string match "*body=sent" $cgiLogText]}
1111 test cgi-httptrace-post-header \
1112 {[string match "POST /test-env HTTP/1.1*" $cgiLogText]}
1113 write_file request.txt [request_get /test-env?traced=2]
1114 if {$::tcl_platform(platform) eq "unix"} {
1115 set cgiHere [pwd]
1116 file mkdir readonly
1117 file attributes readonly -permissions 0555
1118 cd readonly
@@ -1048,54 +1121,55 @@
1121 --ipaddr 127.0.0.1 --localauth --httptrace
1122 cd $cgiHere
1123 file attributes readonly -permissions 0755
1124 test cgi-httptrace-no-log {$CODE == 0
1125 && [string first "# failed to open httplog-" $RESULT] >= 0
1126 && [reply_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"}
1127 }
1128
1129 ###############################################################################
1130 # A request for the top of the site is sent on to the index page. A
1131 # login-card cookie in such a request is taken once.
1132
1133 set cgiReply [cgi_admin [request_get / [list "Cookie: x-f-l-c=card-value"]]]
1134 test_eq cgi-login-card-home [reply_header $cgiReply Location] http://x/index
1135
1136 ###############################################################################
1137 # The honeypot page offers a visitor who is not logged in a captcha, and
1138 # keeps the URL that was asked for, with its query parameters, in a
1139 # cookie.
1140
1141 set cgiReply [cgi_send [request_get "/honeypot?a=1&b&c=two"] --ipaddr 9.9.9.9]
1142 test cgi-original-url {[string first \
1143 "Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fa%3D1%26b%26c%3Dtwo;" \
1144 $cgiReply] >= 0}
1145
1146 ###############################################################################
1147 # The "ss" parameter of /timeline is checked for an attack as soon as it
1148 # is read, for a visitor who is not logged in.
1149
1150 write_file request.txt [request_get "/timeline?ss=1;select"]
1151 file delete reply.txt attack.log
1152 fossil_raw http $cgiRepo --in request.txt --out reply.txt \
1153 --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log]
1154 test cgi-attack-read-parameter {
1155 [reply_status [read_file reply.txt]] eq "HTTP/1.0 418 I'm a teapot"
1156 && [string match "*418 response on \"ss\"*" [read_file attack.log]]}
1157 set cgiReply [cgi_admin [request_get "/timeline?ss=m"]]
1158 test_eq cgi-attack-read-parameter-admin [reply_status $cgiReply] \
1159 "HTTP/1.0 200 OK"
1160
1161 ###############################################################################
1162 # SSH_CONNECTION names the client only when it holds an address followed
1163 # by a space. Otherwise the request is read as plain HTTP from an
1164 # unknown address, which --localauth does not log in.
1165
1166 foreach {cgiName cgiValue} {empty "" one-word nospace} {
1167 set ::env(SSH_CONNECTION) $cgiValue
1168 set cgiReply [cgi_send [request_get /test-env] --localauth]
1169 unset ::env(SSH_CONNECTION)
1170 test_eq cgi-ssh-connection-$cgiName [reply_header $cgiReply Location] \
1171 http://x/login?g=test-env
1172 }
1173
1174 ###############################################################################
1175 # SCGI: SCRIPT_NAME, PATH_INFO and REQUEST_URI. The server needs
@@ -1111,13 +1185,13 @@
1185 proc cgi_scgi_names {pairs} {
1186 set reply [cgi_send [cgi_scgi [concat {
1187 CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SERVER_NAME x SERVER_PORT 80
1188 REMOTE_ADDR 127.0.0.1
1189 } $pairs]] --scgi --localauth]
1190 set status [lindex [reply_status $reply] 1]
1191 if {$status eq "400"} {
1192 return [list 400 [string trim [reply_body $reply]]]
1193 }
1194 if {$status ne "200"} { return $status }
1195 return [list 200 [cgi_param $reply SCRIPT_NAME] [cgi_param $reply PATH_INFO] \
1196 [cgi_param $reply REQUEST_URI]]
1197 }
@@ -1171,29 +1245,33 @@
1245 empty "" "SCGI header too short" \
1246 length-only "20" "cannot read entire SCGI header" \
1247 ] {
1248 set cgiReply [cgi_send $cgiRequest --scgi]
1249 test cgi-scgi-$cgiName {$CODE == 0
1250 && [reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request"
1251 && [string match "*$cgiError*" $cgiReply]}
1252 }
1253
1254 ###############################################################################
1255 # Page aliases. An alias in the configuration names a page and query
1256 # parameters for it: "NAME=VALUE" sets a parameter, replacing one of the
1257 # same name in the request; a name in capitals is taken in lower case;
1258 # "NAME!" removes a parameter of the request.
1259
1260 fossil sql \
1261 "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias','/test-env?a=new&Bb=2&gone!&absent!&fresh',0)"
1262 fossil sql \
1263 [join [list \
1264 "REPLACE INTO config(name,value,mtime) " \
1265 "VALUES('walias:/cgialias2','/test-env?zz!',0)"] ""]
1266 set cgiReply [cgi_admin [request_get "/cgialias?a=old&gone=1&keep=3"]]
1267 test_eq cgi-alias-replace [cgi_param $cgiReply a] new
1268 test_eq cgi-alias-upper [cgi_param $cgiReply bb] 2
1269 test_eq cgi-alias-delete [cgi_param $cgiReply gone] -
1270 test_eq cgi-alias-add [cgi_param $cgiReply fresh] ""
1271 test_eq cgi-alias-keep [cgi_param $cgiReply keep] 3
1272 set cgiReply [cgi_admin [request_get "/cgialias2?m=1&zz=9"]]
1273 test {cgi-alias-delete-last} {[cgi_param $cgiReply zz] eq "-"
1274 && [cgi_param $cgiReply m] eq "1"}
1275
1276 ###############################################################################
1277 # The configuration page saves the text given for the main menu, unless
@@ -1201,12 +1279,13 @@
1279 # removed and the text is not looked at.
1280
1281 proc cgi_menu_post {fields} {
1282 global cgiToken
1283 set body "$fields&csrf=$cgiToken"
1284 set reply [cgi_admin [cgi_post_from http://x/setup_config /setup_config \
1285 $body]]
1286 return [list [lindex [reply_status $reply] 1] \
1287 [fossil sql "SELECT value FROM config WHERE name='mainmenu'"]]
1288 }
1289 test_eq cgi-menu-saved [cgi_menu_post "mmenu=cgi-menu-text&zlast=1"] \
1290 {200 cgi-menu-text}
1291 test_eq cgi-menu-reset [cgi_menu_post "mmenu=other-text&resetMenu=1&zlast=1"] \
@@ -1220,22 +1299,23 @@
1299 # empty value is on, and one with the value "off" is off.
1300
1301 proc cgi_subscribe {email fields} {
1302 global cgiToken
1303 set body "submit=1&e=$email&$fields&csrf=$cgiToken"
1304 cgi_admin [cgi_post_from http://x/subscribe /subscribe $body]
1305 return [fossil sql \
1306 "SELECT hex(suname), ssub FROM subscriber WHERE semail='$email'"]
1307 }
1308 test_eq cgi-subscribe-no-name [cgi_subscribe [email protected] "sa=&sc=off"] \
1309 "|a"
1310 test_eq cgi-subscribe-blank-name \
1311 [cgi_subscribe [email protected] "suname=+++&sa=0&sc=1"] "|c"
1312 test_eq cgi-subscribe-line-ends \
1313 [cgi_subscribe [email protected] "suname=+one%0D%0Atwo%0Dend&sa=1"] \
1314 "6F6E650A74776F0D656E64|a"
1315 # The form shows a box as checked for a value that is a word for "true".
1316 set cgiReply [cgi_admin [request_get "/subscribe?submit=1&sa=on&sc=off&st=2"]]
1317 test cgi-subscribe-checked-word {
1318 [string match "*name=\"sa\" checked>*" $cgiReply]
1319 && [string match "*name=\"sc\" >*" $cgiReply]
1320 && [string match "*name=\"st\" >*" $cgiReply]}
1321
@@ -1256,22 +1336,29 @@
1336 return $RESULT
1337 }
1338 set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env
1339 REMOTE_ADDR 127.0.0.1}]
1340 test cgi-cgi-refused {[string match "Status: 400 Bad Request*" $cgiReply]
1341 && [string match \
1342 "*\nBad CGI Request: missing CONTENT_LENGTH on a POST method*" \
1343 $cgiReply]}
1344 set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env
1345 REMOTE_ADDR 127.0.0.1 SERVER_SOFTWARE TestServer/1}]
1346 test cgi-cgi-refused-server-named {
1347 [string match \
1348 "*\nBad CGI Request from \"TestServer/1\": missing CONTENT_LENGTH*" \
1349 $cgiReply]}
1350 set cgiReply [cgi_cgi {SCRIPT_NAME /s PATH_INFO /test-env REMOTE_ADDR 127.0.0.1
1351 HTTP_HOST x HTTP_REFERER http://x/s/prev}]
1352 test_eq cgi-cgi-no-method [cgi_csrf_level $cgiReply] "Same origin"
1353
1354 # A control file that names a debug file which cannot be opened is used
1355 # all the same.
1356 write_file cgi3.ctl \
1357 [join [list \
1358 "repository: [file nativename $cgiRepo]\nlocalauth\n" \
1359 "cgi-debug: [file join [pwd] nosuchdir debug.txt]\n"] ""]
1360 set ::env(REQUEST_METHOD) GET
1361 set ::env(SCRIPT_NAME) /s
1362 set ::env(PATH_INFO) /test-env
1363 set ::env(QUERY_STRING) "nodebug=1"
1364 set ::env(REMOTE_ADDR) 127.0.0.1
@@ -1296,31 +1383,40 @@
1383 test cgi-json-post-$cgiName-exit {$CODE == 0}
1384 test cgi-json-post-$cgiName-reply \
1385 {[string match "*FOSSIL-1101*" $cgiReply]}
1386 }
1387 set cgiReply [cgi_admin [cgi_post text/x-other {[1]} /json/version]]
1388 test cgi-json-post-other-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1389 && [string match "*jsonApiVersion*" $cgiReply]}
1390 set cgiReply [cgi_send [cgi_scgi {
1391 CONTENT_LENGTH 8 CONTENT_TYPE application/json SCGI 1 REQUEST_METHOD POST
1392 SCRIPT_NAME {} PATH_INFO /json/version SERVER_NAME x SERVER_PORT 80
1393 REMOTE_ADDR 127.0.0.1 no_json 1
1394 } "not json"] --scgi --localauth]
1395 test cgi-json-no-json {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1396 && [string match "*jsonApiVersion*" $cgiReply]}
1397 }
1398
1399 ###############################################################################
1400 # More of a connection over ssh. An older client, after its probes,
1401 # sends a blank line twice and the command again before each further
1402 # request. A request may name the repository file before the page.
1403
1404 set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22"
1405 set cgiFirst \
1406 [join [list \
1407 "echo test1\nfossil\nGET /test-env?first=1 HTTP/1.1\r\n" \
1408 "Host: x\r\nUser-Agent: First\r\n" \
1409 "X-Fossil-Transport: other\r\n\r\n"] ""]
1410 set cgiReply [cgi_send \
1411 [join [list \
1412 "$cgiFirst\n\nfossil\nGET /test-env?second=2 HTTP/1.1\r\n" \
1413 "Host: x\r\nContent-Length: 0\r\nContent-Type: text/plain\r\n" \
1414 "X-Fossil-Transport: ssh\r\n\r\n"] ""] --localauth]
1415 test cgi-ssh-flip {[string match "test1\n*" $cgiReply]
1416 && [string match "*HTTP_USER_AGENT = First*first = 1*second = 2*" \
1417 $cgiReply]}
1418 foreach {cgiName cgiMore cgiError} [list \
1419 cut-short "\n" "incorrect transport_flip" \
1420 not-blank "\nxyz\n" "transport_flip failed" \
1421 other-command "\n\nother\n" "transport_open failed" \
1422 no-request "\n\nfossil\n" "missing HTTP header" \
@@ -1335,52 +1431,72 @@
1431 && ![string match "*400 Bad Request*" $cgiReply]}
1432 foreach {cgiName cgiRequest cgiError} [list \
1433 probes-only "echo test1\nfossil\n" "missing HTTP header" \
1434 blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \
1435 "unsupported HTTP method" \
1436 empty-command \
1437 [join [list \
1438 "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\n" \
1439 "Host: x\r\n\r\n\n\nfossil\n"] ""] \
1440 "transport_open failed" \
1441 repository-only "GET $cgiRepo HTTP/1.1\r\nHost: x\r\n\r\n" \
1442 "malformed URL in HTTP header" \
1443 ] {
1444 set cgiReply [cgi_send $cgiRequest --localauth]
1445 test cgi-ssh-$cgiName {$CODE == 0
1446 && [string match "*400 Bad Request*$cgiError*" $cgiReply]}
1447 }
1448 set cgiReply [cgi_send [request_get $cgiRepo/test-env?named=1] --localauth]
1449 test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1"
1450 && [cgi_param $cgiReply PATH_INFO] eq "/test-env"}
1451 # The name is taken off only when a "/" or the end follows it, and only
1452 # for GET.
1453 set cgiReply [cgi_send [request_get ${cgiRepo}x/test-env] --localauth]
1454 test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] -
1455 set cgiReply [cgi_send [request_get $cgiRepo/test-env \
1456 [list "Content-Length: 0"] \
1457 POST] --localauth]
1458 test_eq cgi-ssh-repository-post [cgi_param $cgiReply PATH_INFO] -
1459 # Later requests on one ssh connection: the second sends Content-Length
1460 # before a longer header line and must get its length and body; the third
1461 # is a GET with no Content-Length and must be served with a length of 0.
1462 set cgiFirst \
1463 [join [list \
1464 "POST /test-env HTTP/1.1\r\nX-Fossil-Transport: SSH\r\n" \
1465 "Content-Type: application/x-www-form-urlencoded\r\n" \
1466 "Content-Length: 3\r\n\r\na=1"] ""]
1467 set cgiSecond \
1468 [join [list \
1469 "POST /test-env HTTP/1.1\r\nContent-Length: 3\r\n" \
1470 "Content-Type: " \
1471 "application/x-www-form-urlencoded-and-more\r\n\r\nb=2"] ""]
1472 set cgiThird "GET /test-env?c=3 HTTP/1.1\r\nHost: x\r\n\r\n"
1473 set cgiReply [cgi_send $cgiFirst$cgiSecond$cgiThird --localauth]
1474 test cgi-ssh-later-content-length {$CODE == 0 && [string match \
1475 [join [list \
1476 "*CONTENT_LENGTH = 3*a = 1*CONTENT_LENGTH = 3*b = " \
1477 "2*CONTENT_LENGTH = 0*c = 3*"] ""] \
1478 [regsub -all {<[^>]*>} $cgiReply {}]]}
1479 unset ::env(SSH_CONNECTION)
1480
1481 ###############################################################################
1482 # A visitor who is not logged in reaches a page that is closed to robots
1483 # with a token, and gets a cookie that opens the page afterwards. The
1484 # same value given as a query parameter does not.
1485
1486 fossil sql \
1487 [join [list \
1488 "REPLACE INTO config(name,value,mtime) " \
1489 "VALUES('robot-restrict','timeline',0)"] ""]
1490 fossil sql \
1491 [join [list \
1492 "REPLACE INTO config(name,value,mtime) " \
1493 "VALUES('token-cgitoken','{\"user\":\"someone\"}',0)"] ""]
1494 proc cgi_robot {path {cookie ""}} {
1495 set headers [list "User-Agent: Agent/1"]
1496 if {$cookie ne ""} { lappend headers "Cookie: $cookie" }
1497 return [cgi_send [request_get $path $headers] --ipaddr 9.9.9.9]
1498 }
1499 set cgiRobot "*Checking to see if you are a robot*"
1500 test cgi-robot-stopped {[string match $cgiRobot [cgi_robot /timeline]]}
1501 set cgiReply [cgi_robot /timeline?token=cgitoken]
1502 set cgiProof ""
@@ -1401,28 +1517,30 @@
1517 ###############################################################################
1518 # A forum thread is shown in order of time to a phone and as a hierarchy
1519 # to anything else, an iPad included. The page offers the other order.
1520
1521 set cgiFd [open post.txt wb]
1522 puts -nonewline $cgiFd \
1523 "D 2026-01-04T10:00:01.000\nH Cgi\\sthread\nU alice\nW 5\nhello\n"
1524 close $cgiFd
1525 fossil md5sum post.txt
1526 set cgiSum [lindex $RESULT 0]
1527 set cgiFd [open post.txt ab]
1528 puts -nonewline $cgiFd "Z $cgiSum\n"
1529 close $cgiFd
1530 fossil test-content-put --crosslink post.txt
1531 set cgiPost [fossil sql \
1532 "SELECT uuid FROM blob WHERE rid=(SELECT fpid FROM forumpost LIMIT 1)"]
1533 foreach {cgiName cgiAgent cgiOther} {
1534 phone "Mozilla/5.0 (iPhone; Mobile) Safari" Hierarchical
1535 ipad "Mozilla/5.0 (iPad; Mobile) Safari" Chronological
1536 desk "Mozilla/5.0 (X11; Linux)" Chronological
1537 none "" Chronological
1538 } {
1539 set cgiHeaders {}
1540 if {$cgiAgent ne ""} { lappend cgiHeaders "User-Agent: $cgiAgent" }
1541 set cgiReply [cgi_admin [request_get /forumthread/$cgiPost?t=a $cgiHeaders]]
1542 test cgi-forum-order-$cgiName {[string match "*>Cgi thread<*" $cgiReply]
1543 && [string match "*?t=?\">$cgiOther</a>*" $cgiReply]}
1544 }
1545
1546 ###############################################################################
@@ -1431,28 +1549,34 @@
1549
1550 fossil user new cgiuser contact userpw
1551 fossil user capabilities cgiuser o
1552 proc cgi_login {fields} {
1553 set body "u=cgiuser&p=userpw&in=Login&$fields"
1554 return [cgi_send [cgi_post_from http://x/login /login $body] --ipaddr 9.9.9.9]
1555 }
1556 set cgiCookie [reply_header [cgi_login x=1] Set-Cookie]
1557 test cgi-login-session-cookie \
1558 {[string match "fossil-*=*cgiuser; Path=*; HttpOnly;*" $cgiCookie]
1559 && ![string match "*max-age*" $cgiCookie]}
1560 set cgiCookie [reply_header [cgi_login remember=1] Set-Cookie]
1561 test cgi-login-lasting-cookie \
1562 {[string match "fossil-*=*cgiuser; Path=*; max-age=*" $cgiCookie]}
1563
1564 ###############################################################################
1565 # A program under /ext that gives a status of 0 gets the usual "200 OK".
1566
1567 if {$::tcl_platform(platform) eq "unix"} {
1568 file mkdir extroot
1569 write_file extroot/status0.sh \
1570 [join [list \
1571 "#!/bin/sh\n" \
1572 "printf 'Status: 0 Nothing\\r\\nContent-Type: " \
1573 "text/plain\\r\\n\\r\\nfrom the program\\n'\n"] ""]
1574 file attributes extroot/status0.sh -permissions 0755
1575 set cgiReply [cgi_admin [request_get /ext/status0.sh] \
1576 --extroot [file join [pwd] extroot]]
1577 test cgi-ext-status-zero {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1578 && [string match "*from the program*" $cgiReply]
1579 && ![string match "*printf*" $cgiReply]}
1580 }
1581
1582 ###############################################################################
@@ -1481,11 +1605,12 @@
1605 cgi cgi5.ctl]
1606 cd $cgiHere
1607 file delete -force $cgiDir
1608 test cgi-cgi-no-repository {$CODE == 1
1609 && [string match "Status: 500 Internal Server Error*" $cgiReply]
1610 && [string match "*Unable to find or open the project repository" \
1611 $cgiReply]}
1612 set cgiReply [cgi_run_with {GATEWAY_INTERFACE CGI/1.1 REQUEST_METHOD GET
1613 SCRIPT_NAME /s PATH_INFO /home}]
1614 test cgi-cgi-no-control-file {$CODE == 1
1615 && [string match "Status: 500 Internal Server Error*" $cgiReply]
1616 && [string match "*No CGI control file specified" $cgiReply]}
@@ -1497,24 +1622,24 @@
1622 write_file cgi6.ctl "#!/usr/bin/fossil\nredirect: * $cgiTarget\n"
1623 set cgiReply [cgi_run_with {REQUEST_METHOD GET HTTP_HOST x SCRIPT_NAME /s
1624 PATH_INFO /abc QUERY_STRING q=1} cgi cgi6.ctl]
1625 test cgi-cgi-redirect-$cgiName {$CODE == 0
1626 && [string match "Status: 301 Moved Permanently*" $cgiReply]
1627 && [reply_header "$cgiReply\r\n\r\n" Location] eq $cgiLocation}
1628 }
1629
1630 ###############################################################################
1631 # The setup page warns of a page header that has no "base" element, and
1632 # does not when the header has one, as the built-in header does.
1633
1634 set cgiReply [cgi_admin [request_get /setup]]
1635 test cgi-setup-base-present {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1636 && ![string match "*Configuration Error*" $cgiReply]}
1637 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header',
1638 '<html><head><title>plain</title></head><body>',now())"
1639 set cgiReply [cgi_admin [request_get /setup]]
1640 test cgi-setup-base-missing {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1641 && [string match "*Configuration Error*base href=*" $cgiReply]}
1642
1643 # The TH1 command "redirect" in a page header sends the client to
1644 # another page: with "302", or with "307" when its second argument is
1645 # true, which tells the client to repeat the request as it made it.
@@ -1522,13 +1647,13 @@
1647 plain {redirect /stat} {HTTP/1.0 302 Moved Temporarily}
1648 method {redirect /stat 1} {HTTP/1.0 307 Temporary Redirect}
1649 } {
1650 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header',
1651 '<html><head></head><body><th1>$cgiScript</th1>',now())"
1652 set cgiReply [cgi_admin [request_get /timeline]]
1653 test cgi-th1-redirect-$cgiName {[reply_status $cgiReply] eq $cgiStatus
1654 && [reply_header $cgiReply Location] eq "http://x/stat"}
1655 }
1656 fossil sql "DELETE FROM config WHERE name='header'"
1657
1658 # The same command run from the command line, where there is no request
1659 # to answer, is an error.
@@ -1555,14 +1680,14 @@
1680 # and has no table in its content; a page with a table gets the ad unit
1681 # for the top of the page.
1682
1683 fossil sql "REPLACE INTO config(name,value,mtime) VALUES
1684 ('adunit-right','<b>ADRIGHT</b>',now()),('adunit','<b>ADTOP</b>',now())"
1685 set cgiReply [cgi_admin [request_get /sitemap]]
1686 test cgi-adunit-right {[string match "*ADRIGHT*" $cgiReply]
1687 && ![string match "*ADTOP*" $cgiReply]}
1688 set cgiReply [cgi_admin [request_get /brlist]]
1689 test cgi-adunit-top-with-table {[string match "*ADTOP*" $cgiReply]
1690 && ![string match "*ADRIGHT*" $cgiReply]}
1691 fossil sql "DELETE FROM config WHERE name IN ('adunit-right','adunit')"
1692
1693 ###############################################################################
@@ -1570,16 +1695,16 @@
1695 # /file with no file name lists the files of the check-in "tip", and
1696 # its links carry "ci=tip". /timeline with "r=BRANCH" shows the branch
1697 # and what is related to it, and its form keeps that as "t=BRANCH" and
1698 # "rel".
1699
1700 set cgiReply [cgi_admin [request_get /file]]
1701 test cgi-file-no-name {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1702 && [string match "*Top-level Files of tip*" $cgiReply]
1703 && [string match "*ci=tip*" $cgiReply]}
1704 set cgiReply [cgi_admin [request_get /timeline?r=trunk]]
1705 test cgi-timeline-r {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1706 && [string match "*name=\"rel\" value=\"1\"*" $cgiReply]
1707 && [string match "*name=\"t\" value=\"trunk\"*" $cgiReply]}
1708
1709 ###############################################################################
1710 # An unversioned file whose time of change is too far in the future to
@@ -1588,15 +1713,15 @@
1713
1714 write_file late.css "p{}\n"
1715 fossil uv add late.css
1716 fossil sql "UPDATE unversioned SET mtime=1000000000000000000
1717 WHERE name='late.css'"
1718 set cgiReply [cgi_send [request_get /uv/late.css] --ipaddr 127.0.0.1]
1719 test cgi-last-modified-out-of-range {
1720 [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1721 && [string match "*\r\nLast-Modified: \r\n*" $cgiReply]
1722 && [reply_body $cgiReply] eq "p{}\n"}
1723 fossil uv rm late.css
1724
1725 ###############################################################################
1726 # "fossil server" itself, where it listens with its own code (not on
1727 # Windows). A server that cannot listen where it was told says why and
@@ -1624,11 +1749,13 @@
1749 bad-ipv6 {--port {[zz::1]:8111}} \
1750 "not a valid IPv6 address: zz::1" \
1751 other-ipv4 {--port 192.0.2.1:8111} \
1752 "cannot open a listening socket on 192.0.2.1:8111" \
1753 other-ipv6 {--port {[2001:db8::1]:8111}} \
1754 [join [list \
1755 "cannot open a listening socket on " \
1756 "\\\[2001:db8::1\\\]:8111"] ""] \
1757 port-in-use [list --localhost --port $cgiPort] \
1758 "no available TCP ports in the range $cgiPort..$cgiPort" \
1759 socket-name-long [list --socket-name [string repeat s 200]] \
1760 "name of unix socket too big" \
1761 socket-name-taken {--socket-name notsocket} \
@@ -1638,75 +1765,102 @@
1765 test cgi-server-refused-$cgiName {$CODE == 1
1766 && [string match "*$cgiError*" $RESULT]}
1767 }
1768 close $cgiListener
1769
1770 # Run SCRIPT every ten milliseconds until it returns true, for at most
1771 # five seconds, and return what it last returned.
1772 proc cgi_wait {script} {
1773 for {set i 0} {$i < 500} {incr i} {
1774 if {[uplevel 1 $script]} {return 1}
1775 after 10
1776 }
1777 return 0
1778 }
1779 # True if the process PID has not ended.
1780 proc cgi_running {pid} {
1781 return [expr {![catch {exec kill -0 $pid}]}]
1782 }
1783 # Wait for the server PID to print that it listens, and return true
1784 # once it has. A server that ends without listening ends the wait.
1785 proc cgi_listening {pid} {
1786 cgi_wait {expr {[string match "*Listening for*" [read_file server.out]]
1787 || ![cgi_running $pid]}}
1788 return [string match "*Listening for*" [read_file server.out]]
1789 }
1790 # Connect to HOST and PORT and return the socket. A server prints
1791 # that it listens before it accepts connections, so a connection that
1792 # fails is tried again.
1793 proc cgi_connect {host port} {
1794 cgi_wait {expr {![catch {socket $host $port} sock]}}
1795 fconfigure $sock -translation binary
1796 return $sock
1797 }
1798 # Send REQUEST to HOST and PORT and return the reply, waiting at most
1799 # ten seconds for the end of it. With "unix" for HOST, PORT is the
1800 # name of a unix socket, and the program "nc" carries the request.
1801 proc cgi_client {host port request} {
1802 if {$host eq "unix"} {
1803 cgi_wait {expr {![catch {exec nc -w 10 -U $port << $request} reply]
1804 || ![string match "*refused*" $reply]}}
1805 return $reply
1806 }
1807 set sock [cgi_connect $host $port]
1808 fconfigure $sock -blocking 0
1809 puts -nonewline $sock $request
1810 flush $sock
1811 set reply ""
1812 for {set i 0} {$i < 2000 && ![eof $sock]} {incr i} {
1813 set part [read $sock]
1814 append reply $part
1815 if {$part eq ""} {after 5}
1816 }
1817 close $sock
1818 return $reply
1819 }
1820 # Start a server with OPTIONS that answers one request and stops, send
1821 # it REQUEST at HOST and PORT, and return what the server printed and
1822 # the reply. The server is killed if it has not stopped by itself.
1823 # The request is sent IDLE milliseconds after the server starts to
1824 # listen.
1825 proc cgi_serve_once {options host port request {command server} {idle 0}} {
1826 global fossilexe cgiRepo
1827 file delete server.out
1828 set pid [exec $fossilexe $command --debug-nofork --localauth {*}$options \
1829 $cgiRepo >& server.out &]
1830 set reply ""
1831 if {[cgi_listening $pid]} {
1832 after $idle
1833 catch {set reply [cgi_client $host $port $request]}
1834 }
1835 cgi_wait {expr {![cgi_running $pid]}}
 
 
 
 
 
 
1836 catch {exec kill -9 $pid}
1837 return [list [string trim [read_file server.out]] $reply]
1838 }
1839
1840 # An IPv4 address, by number and as "localhost".
1841 foreach {cgiName cgiHost} {ipv4 127.0.0.1 localhost localhost} {
1842 set cgiPort [cgi_free_port]
1843 lassign [cgi_serve_once [list --port $cgiHost:$cgiPort] 127.0.0.1 \
1844 $cgiPort [request_get /test-env]] cgiPrinted cgiReply
1845 test_eq cgi-server-$cgiName-printed $cgiPrinted \
1846 "Listening for HTTP requests on TCP port 127.0.0.1:$cgiPort"
1847 test cgi-server-$cgiName-reply {
1848 [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1849 && [cgi_param $cgiReply REMOTE_ADDR] eq "127.0.0.1"}
1850 }
1851 # "fossil ui" starts the browser on the address it listens on. The
1852 # browser here is "echo".
1853 fossil settings web-browser echo
1854 fossil settings web-browser
1855 if {[string match "*echo*" $RESULT]} {
1856 set cgiPort [cgi_free_port]
1857 lassign [cgi_serve_once [list --port 127.0.0.1:$cgiPort] 127.0.0.1 \
1858 $cgiPort [request_get /test-env] ui] cgiPrinted cgiReply
1859 test cgi-server-ui-browser {
1860 [string match "*\nhttp://127.0.0.1:$cgiPort/*" \n$cgiPrinted]
1861 && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"}
1862 }
1863 # SCGI in place of HTTP.
1864 set cgiPort [cgi_free_port]
1865 lassign [cgi_serve_once [list --scgi --port 127.0.0.1:$cgiPort] 127.0.0.1 \
1866 $cgiPort [cgi_scgi {
@@ -1721,38 +1875,44 @@
1875 if {![catch {cgi_busy_port ::1} cgiBusy]} {
1876 close [lindex $cgiBusy 0]
1877 # An IPv6 address.
1878 set cgiPort [cgi_free_port]
1879 lassign [cgi_serve_once [list --port \[::1\]:$cgiPort] ::1 $cgiPort \
1880 [request_get /test-env]] cgiPrinted cgiReply
1881 test_eq cgi-server-ipv6-printed $cgiPrinted \
1882 "Listening for HTTP requests on \[::1\]:$cgiPort"
1883 test cgi-server-ipv6-reply {[reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1884 && [cgi_param $cgiReply REMOTE_ADDR] eq "::1"}
1885 # With no address the server listens on both kinds of loopback
1886 # address, or on IPv4 alone if the port is taken for IPv6. The
1887 # server waits a tenth of a second at a time for a connection, and
1888 # this request leaves it waiting for two of them with none.
1889 set cgiPort [cgi_free_port]
1890 lassign [cgi_serve_once [list --localhost --port \[\]:$cgiPort] ::1 \
1891 $cgiPort [request_get /test-env] server 200] cgiPrinted cgiReply
1892 test_eq cgi-server-both-printed $cgiPrinted \
1893 [join [list \
1894 "Listening for HTTP requests on TCP port " \
1895 "localhost:$cgiPort, IPv4 and IPv6"] ""]
1896 test_eq cgi-server-both-reply [cgi_param $cgiReply REMOTE_ADDR] ::1
1897 lassign [cgi_busy_port ::1] cgiListener cgiPort
1898 lassign [cgi_serve_once [list --localhost --port $cgiPort] 127.0.0.1 \
1899 $cgiPort [request_get /test-env]] cgiPrinted cgiReply
1900 close $cgiListener
1901 test_eq cgi-server-ipv4-only-printed $cgiPrinted \
1902 "Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 only"
1903 test_eq cgi-server-ipv4-only-reply [reply_status $cgiReply] \
1904 "HTTP/1.0 200 OK"
1905 # With a port and neither an address nor --localhost the server
1906 # listens on every address of the machine.
1907 set cgiPort [cgi_free_port]
1908 lassign [cgi_serve_once [list --port $cgiPort] 127.0.0.1 \
1909 $cgiPort [request_get /login]] cgiPrinted cgiReply
1910 test_eq cgi-server-any-address-printed $cgiPrinted \
1911 "Listening for HTTP requests on TCP port $cgiPort, IPv4 and IPv6"
1912 test_eq cgi-server-any-address-reply [reply_status $cgiReply] \
1913 "HTTP/1.0 200 OK"
1914 }
1915
1916 # A unix socket in place of a port. The server makes the socket, and
1917 # takes the place of a socket of the same name that is left from an
1918 # earlier server. --socket-owner names the owner of the socket.
@@ -1762,15 +1922,15 @@
1922 foreach {cgiName cgiOptions} [list \
1923 new {--socket-name sock1} \
1924 replaced {--socket-name sock1} \
1925 owner [list --socket-owner $cgiUser --socket-name sock1] \
1926 ] {
1927 lassign [cgi_serve_once $cgiOptions unix sock1 [request_get /login]] \
1928 cgiPrinted cgiReply
1929 test cgi-server-unix-$cgiName {
1930 $cgiPrinted eq "Listening for HTTP requests on unix socket sock1"
1931 && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1932 && [file type sock1] eq "socket"
1933 && [file attributes sock1 -owner] eq $cgiUser}
1934 }
1935 # --socket-mode gives the permissions of the socket; without it they
1936 # are 0660.
@@ -1777,15 +1937,15 @@
1937 foreach {cgiName cgiOptions cgiMode} {
1938 mode {--socket-mode 0600 --socket-name sock2} 600
1939 default {--socket-name sock2} 660
1940 } {
1941 file delete sock2
1942 lassign [cgi_serve_once $cgiOptions unix sock2 [request_get /login]] \
1943 cgiPrinted cgiReply
1944 test cgi-server-unix-$cgiName {
1945 $cgiPrinted eq "Listening for HTTP requests on unix socket sock2"
1946 && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
1947 && [format %o [expr {[file attributes sock2 -permissions] & 0o777}]]
1948 eq $cgiMode}
1949 }
1950 fossil_raw -seconds 30 server --socket-mode rw --socket-name sock3 $cgiRepo
1951 test cgi-server-unix-mode-not-a-number {$CODE == 1 && [string match \
@@ -1801,25 +1961,25 @@
1961 proc cgi_serve_start {options {command server} {wrap {}}} {
1962 global fossilexe cgiRepo
1963 file delete server.out server.err
1964 set pid [exec {*}$wrap $fossilexe $command --localauth {*}$options \
1965 $cgiRepo > server.out 2> server.err &]
1966 cgi_listening $pid
 
 
 
 
1967 return $pid
1968 }
1969 # Stop the server with process id PID: ask it to end, and kill it if
1970 # it has not ended after five seconds.
1971 proc cgi_serve_stop {pid} {
1972 catch {exec kill $pid}
1973 cgi_wait {expr {![cgi_running $pid]}}
 
 
1974 catch {exec kill -9 $pid}
1975 }
1976 # The process ids of the processes that the server PID has started
1977 # for requests and has not yet found to have ended.
1978 proc cgi_children {pid} {
1979 if {[catch {exec pgrep -P $pid} children]} {return {}}
1980 return $children
1981 }
1982
1983 # A process that handles a request is killed before the request is
1984 # complete. The server goes on to answer the next request, and one
1985 # that traces its work reports the signal that ended the process.
@@ -1831,28 +1991,27 @@
1991 set cgiPort [cgi_free_port]
1992 set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort \
1993 {*}$cgiOptions]]
1994 set cgiReply ""
1995 catch {
1996 set cgiSock [cgi_connect 127.0.0.1 $cgiPort]
 
1997 puts -nonewline $cgiSock "GET /login HTTP/1.1\r\n"
1998 flush $cgiSock
1999 cgi_wait {llength [cgi_children $cgiPid]}
2000 exec kill -9 {*}[cgi_children $cgiPid]
2001 cgi_wait {expr {[cgi_children $cgiPid] eq ""}}
2002 close $cgiSock
2003 set cgiReply [cgi_client 127.0.0.1 $cgiPort [request_get /login]]
2004 cgi_wait {expr {[cgi_children $cgiPid] eq ""}}
2005 }
2006 cgi_serve_stop $cgiPid
2007 test cgi-server-child-killed-$cgiName {
2008 [reply_status $cgiReply] eq "HTTP/1.0 200 OK"
2009 && ($cgiReport eq ""
2010 ? ![string match "*exited on signal*" [read_file server.err]]
2011 : [string match $cgiReport [read_file server.err]])}
2012 }
 
2013 } else {
2014 test_skip_part "no pgrep program: the killed server process tests"
2015 }
2016
2017 # A server that is not allowed another process cannot start the
@@ -1864,11 +2023,11 @@
2023 && [auto_execok bash] ne ""} {
2024 set cgiPort [cgi_free_port]
2025 set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort] ui \
2026 [list bash -c {ulimit -u 1 && exec "$@"} bash]]
2027 set cgiReply unset
2028 catch {set cgiReply [cgi_client 127.0.0.1 $cgiPort [request_get /login]]}
2029 set cgiAlive [expr {![catch {exec kill -0 $cgiPid}]}]
2030 cgi_serve_stop $cgiPid
2031 test cgi-server-no-process-browser {[string match \
2032 "*cannot start browser: echo*" [read_file server.err]]}
2033 test cgi-server-no-process-request {$cgiReply eq "" && $cgiAlive}
2034
+127 -122
--- test/config.test
+++ test/config.test
@@ -6,15 +6,12 @@
66
# asks for. After each command the configuration of the area must be what
77
# the command is documented to leave, and the rest of the repository must
88
# be as it was.
99
#
1010
11
-# These tests run only in a long pass: -assurance stress.
12
-if {[test_assurance] ne "stress"} {
13
- test_skip "runs only with -assurance stress"
14
-}
15
-
11
+# The first sections run at every level, and the rest need
12
+# -assurance ci or stress.
1613
require_no_open_checkout
1714
1815
test_setup ""
1916
set configDir [pwd]
2017
set ::env(FOSSIL_USER) tester
@@ -23,12 +20,11 @@
2320
# Helpers.
2421
2522
# Run SQL in repository REPO and return its output without the final
2623
# newline.
2724
proc configSql {repo sql} {
28
- fossil sql -R $repo $sql
29
- return [string trim $::RESULT]
25
+ return [fossil_sql $sql $repo]
3026
}
3127
3228
# Make an empty repository FILE and give its settings a time long before
3329
# any that the tests write, so that a test sees only what it set.
3430
proc configNew {file} {
@@ -116,14 +112,21 @@
116112
117113
# A setting that is empty or absent has no time that a test can know: the
118114
# repository makes a new "hash-policy" when it is opened. MASK hides its time.
119115
# The SQL that lists what repository holds in the tables TABLES. With
120116
# EXPORTED set, only the rows that an export sends: those with a time of
121
-# last change, and the verified subscribers.
117
+# last change, and the verified subscribers. A repository that has no
118
+# SUBSCRIBER table has no subscribers: the statement then reads an empty
119
+# table of that name in a database attached after the repository.
122120
proc configTableSql {tables exported} {
123121
set m [expr {$exported ? "WHERE mtime IS NOT NULL" : ""}]
124122
set sql ""
123
+ if {"sub" in $tables} {
124
+ append sql "ATTACH ':memory:' AS nosub;
125
+ CREATE TABLE nosub.subscriber(semail, suname, sdigest, sdonotcall,
126
+ ssub, sctime, smip, mtime, sverified);"
127
+ }
125128
foreach t $tables {
126129
switch -- $t {
127130
rpt {append sql "SELECT 'rpt', owner, title, mtime, quote(cols),
128131
quote(sqlcode), quote(ifnull(jx,'{}')) FROM reportfmt $m ORDER BY title;"}
129132
usr {append sql "SELECT 'usr', login, quote(pw), quote(cap),
@@ -149,19 +152,11 @@
149152
global configTables
150153
set t [expr {$mask ? "CASE WHEN name='hash-policy' THEN 0 ELSE mtime END"
151154
: "mtime"}]
152155
set sql "SELECT 'cfg', name, quote(value), $t FROM config
153156
WHERE [configCond $area] ORDER BY name;"
154
- if {$area eq "subscriber" && ![configHasTable $repo subscriber]} {
155
- set tables {}
156
- } else {
157
- set tables $configTables($area)
158
- }
159
- if {"sub" in $tables && ![configHasTable $repo subscriber]} {
160
- set tables [lsearch -all -inline -not -exact $tables sub]
161
- }
162
- append sql [configTableSql $tables $exported]
157
+ append sql [configTableSql $configTables($area) $exported]
163158
return [configSql $repo $sql]
164159
}
165160
166161
# What REPO holds outside AREA, to see that a command left it alone.
167162
proc configOutside {repo area} {
@@ -170,22 +165,14 @@
170165
WHERE NOT [configCond $area] ORDER BY name;"
171166
set tables {}
172167
foreach t {rpt usr cnc shn sub} {
173168
if {$t ni $configTables($area)} {lappend tables $t}
174169
}
175
- if {![configHasTable $repo subscriber]} {
176
- set tables [lsearch -all -inline -not -exact $tables sub]
177
- }
178170
append sql [configTableSql $tables 0]
179171
return [configSql $repo $sql]
180172
}
181173
182
-proc configHasTable {repo table} {
183
- return [configSql $repo "SELECT count(*) FROM sqlite_schema
184
- WHERE name='$table' AND type='table'"]
185
-}
186
-
187174
# The kinds of card that an export file holds, in order and without
188175
# repeats.
189176
proc configKinds {file} {
190177
set kinds {}
191178
foreach line [split [read_file $file] \n] {
@@ -382,16 +369,22 @@
382369
set configFile export-$configArea.cfg
383370
configRun configuration export $configArea $configFile -R a.fossil
384371
test config-export-$configArea {$CODE == 0 && $RESULT eq ""}
385372
set configText [read_file $configFile]
386373
test_match config-export-$configArea-header $configText \
387
- "^# The \"$configArea\" configuration exported from\n# repository \"a.fossil\"\n# on \[0-9-\]+ \[0-9:\]+\n"
374
+ [join [list \
375
+ "^# The \"$configArea\" configuration exported from\n" \
376
+ "# repository \"a.fossil\"\n# on \[0-9-\]+ \[0-9:\]+\n"] ""]
388377
test_eq config-export-$configArea-cards [configKinds $configFile] \
389378
[lsort $configKindsOf($configArea)]
390379
}
391380
test_eq config-export-changes-nothing [configSql a.fossil "SELECT 'c',name,mtime
392381
FROM config ORDER BY name"] $configBefore
382
+
383
+if {[test_assurance] eq "smoke"} {
384
+ test_skip "the tests after the first sections need -assurance ci or stress"
385
+}
393386
394387
###############################################################################
395388
# Import: an area exported from one repository and imported into another
396389
# makes the second hold what the first holds, in that area, with the times
397390
# of last change. The tables of the area are replaced, so that a row that
@@ -445,12 +438,14 @@
445438
set configExp [configState a.fossil $configArea 1]
446439
test config-$configArea-has-content {$configExp ne ""}
447440
448441
configRun configuration import export-$configArea.cfg -R $configB
449442
test config-import-$configArea {$CODE == 0 && $RESULT eq ""}
450
- test_eq config-import-$configArea-same [configState $configB $configArea] $configExp
451
- test_eq config-import-$configArea-outside [configOutside $configB $configArea] $configOut
443
+ test_eq config-import-$configArea-same [configState $configB $configArea] \
444
+ $configExp
445
+ test_eq config-import-$configArea-outside \
446
+ [configOutside $configB $configArea] $configOut
452447
if {$configArea eq "ticket" || $configArea eq "all"} {
453448
# The ticket tables are rebuilt from the imported ticket-table.
454449
test_eq config-import-$configArea-ticket-table [configSql $configB "SELECT
455450
count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 1
456451
}
@@ -462,37 +457,44 @@
462457
set configOut [configOutside $configB $configArea]
463458
configRun configuration reset $configArea -R $configB
464459
test config-reset-$configArea {$CODE == 0 &&
465460
[string first "Configuration reset to factory defaults." $RESULT] >= 0}
466461
set configResetOut $RESULT
467
- test_eq config-reset-$configArea-outside [configOutside $configB $configArea] $configOut
462
+ test_eq config-reset-$configArea-outside \
463
+ [configOutside $configB $configArea] $configOut
464
+ unset -nocomplain configBackup
468465
regexp {import (config-backup-[0-9.]+)} $configResetOut -> configBackup
469466
test config-reset-$configArea-backup {[info exists configBackup] &&
470467
[file exists $configBackup]}
471468
if {$configArea eq "user" || $configArea eq "all"} {
472469
# The default users come back, and the user who ran the command is
473470
# their administrator.
474
- test_eq config-reset-$configArea-users [configSql $configB "SELECT login, cap, mtime
471
+ test_eq config-reset-$configArea-users \
472
+ [configSql $configB "SELECT login, cap, mtime
475473
FROM user ORDER BY login"] \
476474
"anonymous|hz|\ndeveloper|ei|\nnobody|gjorz|\nreader|kptw|\ntester|s|"
477475
}
478476
if {$configArea ni {alias interwiki all user}} {
479
- test_eq config-reset-$configArea-state [configState $configB $configArea 0 1] \
477
+ test_eq config-reset-$configArea-state \
478
+ [configState $configB $configArea 0 1] \
480479
[configDefaults $configArea]
481480
}
482481
if {$configArea eq "ticket" || $configArea eq "all"} {
483482
test_eq config-reset-$configArea-ticket-table [configSql $configB "SELECT
484483
count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 0
485484
}
486485
if {$configArea eq "subscriber" || $configArea eq "all"} {
487
- test_eq config-reset-$configArea-subscribers [configSql $configB "SELECT count(*)
486
+ test_eq config-reset-$configArea-subscribers \
487
+ [configSql $configB "SELECT count(*)
488488
FROM subscriber"] 0
489489
}
490490
configRun configuration import $configBackup -R $configB
491491
test config-reset-$configArea-recover {$CODE == 0}
492
- test_eq config-reset-$configArea-recovered [configState $configB $configArea] $configPre
493
- test_eq config-reset-$configArea-recovered-outside [configOutside $configB $configArea] \
492
+ test_eq config-reset-$configArea-recovered \
493
+ [configState $configB $configArea] $configPre
494
+ test_eq config-reset-$configArea-recovered-outside \
495
+ [configOutside $configB $configArea] \
494496
$configOut
495497
}
496498
497499
498500
###############################################################################
@@ -500,12 +502,13 @@
500502
501503
foreach configArea {alias interwiki} {
502504
configNew r-$configArea.fossil
503505
configFill r-$configArea.fossil
504506
configRun configuration reset $configArea -R r-$configArea.fossil
505
- test config-reset-$configArea-removes {[configState r-$configArea.fossil $configArea 0 1] eq
506
- [configDefaults $configArea]}
507
+ test_eq config-reset-$configArea-removes \
508
+ [configState r-$configArea.fossil $configArea 0 1] \
509
+ [configDefaults $configArea]
507510
}
508511
configNew r-all.fossil
509512
configFill r-all.fossil
510513
configRun configuration reset all -R r-all.fossil
511514
test config-reset-all-removes-aliases {[configSql r-all.fossil "SELECT count(*)
@@ -569,11 +572,12 @@
569572
570573
###############################################################################
571574
# Names of areas and methods: an abbreviation that starts the name is
572575
# enough. An unknown area lists the areas and writes nothing.
573576
574
-foreach {configAbbrev configArea} {sk skin pro project t ticket u user e email sh shun
577
+foreach {configAbbrev configArea} \
578
+ {sk skin pro project t ticket u user e email sh shun
575579
a alias al alias all all su subscriber i interwiki
576580
x xfer c css} {
577581
file delete abbrev.cfg
578582
configRun configuration export $configAbbrev abbrev.cfg -R a.fossil
579583
test config-area-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]}
@@ -584,14 +588,14 @@
584588
}
585589
file delete abbrev.cfg
586590
foreach configBad {nosuch skinx ALL Skin} {
587591
configRun configuration export $configBad abbrev.cfg -R a.fossil
588592
test config-area-unknown-$configBad {$CODE == 1 &&
589
- [string first "no such configuration area: \"$configBad\"" $RESULT] >= 0 &&
590
- [string first "Available configuration areas:" $RESULT] >= 0 &&
591
- [string first " skin Web interface appearance settings" \
592
- $RESULT] >= 0 &&
593
+ [holds_strings $RESULT [list \
594
+ "no such configuration area: \"$configBad\"" \
595
+ "Available configuration areas:" \
596
+ " skin Web interface appearance settings"]] &&
593597
![file exists abbrev.cfg]}
594598
}
595599
foreach configMethod {reset pull push sync} {
596600
configRun configuration $configMethod nosuch -R a.fossil
597601
test config-area-unknown-$configMethod {$CODE == 1 &&
@@ -600,14 +604,16 @@
600604
601605
# The methods accept abbreviations too.
602606
foreach {configAbbrev configFull} {exp export e export ex export} {
603607
file delete abbrev.cfg
604608
configRun configuration $configAbbrev skin abbrev.cfg -R a.fossil
605
- test config-method-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]}
609
+ test config-method-abbrev-$configAbbrev \
610
+ {$CODE == 0 && [file exists abbrev.cfg]}
606611
}
607612
configNew m-abbrev.fossil
608
-foreach {configAbbrev configTag} {i import im import imp import m merge me merge mer merge} {
613
+foreach {configAbbrev configTag} \
614
+ {i import im import imp import m merge me merge mer merge} {
609615
configRun configuration $configAbbrev export-skin.cfg -R m-abbrev.fossil
610616
test config-method-abbrev-$configAbbrev {$CODE == 0 &&
611617
[configSql m-abbrev.fossil "SELECT value FROM config
612618
WHERE name='css'"] eq "body { color: #123; }"}
613619
fossil sql -R m-abbrev.fossil "DELETE FROM config WHERE name='css'"
@@ -635,18 +641,18 @@
635641
pull-too-many {pull skin a b}
636642
push-none {push}
637643
sync-none {sync}
638644
} {
639645
configRun configuration {*}$configArgs -R a.fossil
640
- test config-usage-$configNm {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
646
+ test config-usage-$configNm \
647
+ {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
641648
}
642649
configRun configuration frobnicate -R a.fossil
643650
test config-method-unknown {$CODE == 1 &&
644
- [string first "METHOD should be one of: export import merge pull push reset"\
651
+ [string first \
652
+ "METHOD should be one of: export import merge pull push reset"\
645653
$RESULT] >= 0}
646
-configRun configuration -R a.fossil
647
-test config-method-missing {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
648654
configRun configuration import nosuchfile.cfg -R a.fossil
649655
test config-import-no-file {$CODE == 1}
650656
651657
652658
###############################################################################
@@ -691,11 +697,12 @@
691697
test_eq config-merge-$name [configSql m.fossil $sql] $expected
692698
}
693699
configMergeCheck newer-local-kept "SELECT value FROM config WHERE name='css'" \
694700
local-css
695701
configMergeCheck older-local-replaced "SELECT value||'|'||mtime FROM config
696
- WHERE name='header'" "<html>\n<head><title>It's \"quoted\"</title></head>\n|1700000001"
702
+ WHERE name='header'" \
703
+ "<html>\n<head><title>It's \"quoted\"</title></head>\n|1700000001"
697704
configMergeCheck equal-time-local-kept "SELECT value FROM config
698705
WHERE name='mainmenu'" local-menu
699706
configMergeCheck absent-added "SELECT value FROM config WHERE name='js'" \
700707
"var a = 'b';"
701708
configMergeCheck alias-newer-local-kept "SELECT value FROM config
@@ -746,29 +753,28 @@
746753
test_eq config-merge-twice [configState m.fossil all] $configMerged
747754
748755
# Merge into an empty repository is import.
749756
configNew m2.fossil
750757
configRun configuration merge export-all.cfg -R m2.fossil
751
-foreach configArea {skin project ticket xfer alias interwiki email shun subscriber} {
758
+foreach configArea {skin project ticket xfer alias interwiki email shun
759
+ subscriber} {
752760
test_eq config-merge-empty-$configArea [configState m2.fossil $configArea] \
753761
[configState a.fossil $configArea 1]
754762
}
755763
756764
# Import and merge write only inside one transaction: a file that stops the
757765
# command leaves the repository as it was. A file with a card that SQLite
758766
# cannot take (a repeated column) is such a file.
759767
configNew t.fossil
760768
configPut t.fossil {css {'kept'}} 1700000000
761
-set configTx [configState t.fossil all]
762
-set configTxCard "1700000100 'x' value 'v'"
763
-set configTxCard2 "1700000100 'alice' pw 'a' pw 'b' pw 'c' pw 'd' pw 'e' pw 'f' pw 'g'
769
+set configTxCard2 \
770
+ "1700000100 'alice' pw 'a' pw 'b' pw 'c' pw 'd' pw 'e' pw 'f' pw 'g'
764771
pw 'h' pw 'i' pw 'j' pw 'k' pw 'l' pw 'm' pw 'n'"
765772
write_file tx.cfg "[configCard config "1700000100 'css' value 'changed'"]\
766773
[configCard user $configTxCard2]"
767774
configRun configuration merge tx.cfg -R t.fossil
768775
set configTxCode $CODE
769
-set configTxOut $RESULT
770776
test config-card-many-fields {$configTxCode == 0 || $configTxCode == 1}
771777
fossil test-integrity -R t.fossil
772778
test config-card-many-fields-integrity {$CODE == 0}
773779
774780
###############################################################################
@@ -817,11 +823,12 @@
817823
string-lone {'}
818824
null-prefix {NULLx}
819825
not-null {NUL}
820826
} {
821827
fossil sql -R l.fossil "DELETE FROM config WHERE name='header'"
822
- write_file lit.cfg [configCard config "1700000000 'header' value $configValue"]
828
+ write_file lit.cfg [configCard config \
829
+ "1700000000 'header' value $configValue"]
823830
configRun configuration merge lit.cfg -R l.fossil
824831
test config-literal-refused-$configNm {$CODE == 0 &&
825832
[configSql l.fossil "SELECT count(*) FROM config
826833
WHERE name='header'"] == 0}
827834
}
@@ -833,45 +840,40 @@
833840
# if it were not there. Nothing is written that the card did not name.
834841
835842
# Everything that REPO holds, settings and tables, except the two settings
836843
# that a server of the repository writes for its own use.
837844
proc configDump {repo} {
838
- global configTables
839845
set sql "SELECT 'cfg', name, quote(value), mtime FROM config
840846
WHERE name<>'backoffice' AND name NOT GLOB 'baseurl:*'
841847
ORDER BY name;"
842
- set tables {rpt usr cnc shn}
843
- if {[configHasTable $repo subscriber]} {lappend tables sub}
844
- append sql [configTableSql $tables 0]
848
+ append sql [configTableSql {rpt usr cnc shn sub} 0]
845849
return [configSql $repo $sql]
846850
}
847851
848852
configNew c.fossil
849853
configPut c.fossil {css {'old'} js {'old'}} 1700000000
854
+set configStart [configDump c.fossil]
850855
set configGood [configCard config "1700000500 'footer' value 'good'"]
851
-set configCases 0
852856
853857
# Run import and merge of TEXT into a copy of c.fossil. Both must leave
854858
# the repository as it was, except that the card "footer" at the end of the
855859
# file, when GOOD is true, is read.
856860
proc configMalformed {name text good {code 0}} {
857
- global configGood configCases
861
+ global configGood configStart
858862
foreach method {merge import} {
859863
set repo c-$method.fossil
860864
file copy -force c.fossil $repo
861
- set before [configDump $repo]
862865
write_file bad.cfg [expr {$good ? "$text$configGood" : $text}]
863866
configRun configuration $method bad.cfg -R $repo
864
- set after [configDump $repo]
865867
test config-malformed-$name-$method-exit {$::CODE == $code}
866868
if {$good} {
867
- set want [configSql $repo "SELECT value FROM config WHERE name='footer'"]
869
+ set want [configSql $repo "SELECT value FROM config WHERE name='footer';
870
+ DELETE FROM config WHERE name='footer'"]
868871
test_eq config-malformed-$name-$method-next-card $want good
869
- fossil sql -R $repo "DELETE FROM config WHERE name='footer'"
870
- set after [configDump $repo]
871872
}
872
- test_eq config-malformed-$name-$method-unchanged $after $before
873
+ test_eq config-malformed-$name-$method-unchanged [configDump $repo] \
874
+ $configStart
873875
}
874876
}
875877
set configBody "1700000600 'css' value 'new'\n"
876878
set configLen [string length $configBody]
877879
@@ -889,16 +891,19 @@
889891
configMalformed negative-size "config /config -5\n$configBody\n" 1
890892
configMalformed size-letters "config /config 12ab\n$configBody\n" 1
891893
configMalformed size-plus "config /config +$configLen\n$configBody\n" 1
892894
configMalformed size-hex "config /config 0x10\n$configBody\n" 1
893895
configMalformed size-float "config /config 1.5\n$configBody\n" 1
894
-configMalformed size-too-big-for-int "config /config 99999999999\n$configBody\n" 1
895
-configMalformed size-extra-token "config /config $configLen extra\n$configBody\n" 1
896
+configMalformed size-too-big-for-int \
897
+ "config /config 99999999999\n$configBody\n" 1
898
+configMalformed size-extra-token \
899
+ "config /config $configLen extra\n$configBody\n" 1
896900
configMalformed size-zero "config /config 0\n\n" 1
897901
configMalformed size-short "config /config 10\n$configBody\n" 1
898902
configMalformed truncated-key "config /config 40\n1700000600 'cs" 0
899
-configMalformed truncated-literal "config /config 40\n1700000600 'css' value 'ne\n" 0
903
+configMalformed truncated-literal \
904
+ "config /config 40\n1700000600 'css' value 'ne\n" 0
900905
foreach {configNm configCardBody} {
901906
missing-mtime "'css' value 'x'\n"
902907
bare-name "1700000600 css value 'x'\n"
903908
name-only "1700000600\n"
904909
empty-card "\n"
@@ -906,14 +911,16 @@
906911
zero-byte-time "\0001700000600 'css' value 'x'\n"
907912
zero-byte-name "1700000600 \000'css' value 'x'\n"
908913
} {
909914
configMalformed $configNm [configCard config $configCardBody] 1
910915
}
911
-foreach {configNm configMtime} {letters abc fraction 1.5 negative -5 hex 0x10 blank-sign +5
916
+foreach {configNm configMtime} \
917
+ {letters abc fraction 1.5 negative -5 hex 0x10 blank-sign +5
912918
exponent 1e3 quoted '5'} {
913919
set configCardBody "$configMtime 'css' value 'new'\n"
914
- configMalformed mtime-$configNm "config /config [string length $configCardBody]\n$configCardBody\n" 1
920
+ configMalformed mtime-$configNm \
921
+ "config /config [string length $configCardBody]\n$configCardBody\n" 1
915922
}
916923
917924
# A size that is larger than the rest of the file takes the rest.
918925
foreach configMethod {merge import} {
919926
file copy -force c.fossil c-$configMethod.fossil
@@ -927,25 +934,28 @@
927934
# A field that is not a column of the table is skipped; one that would
928935
# set a column that nothing outside may set is among them.
929936
configNew k.fossil
930937
fossil sql -R k.fossil "INSERT INTO user(login,pw,cap,mtime)
931938
VALUES('carol','pw','o',5)"
932
-set configCardBody "1700000600 'carol' cap 'oj' cookie 'stolen' ipaddr '1.2.3.4'\
939
+set configCardBody \
940
+ "1700000600 'carol' cap 'oj' cookie 'stolen' ipaddr '1.2.3.4'\
933941
cexpire 1 uid 77 login 'mallory' bogus 'x' info 'Carol'\n"
934942
write_file fields.cfg [configCard user $configCardBody]
935943
configRun configuration merge fields.cfg -R k.fossil
936944
test config-field-skipped {$CODE == 0}
937945
test_eq config-field-skipped-row [configSql k.fossil "SELECT login, cap, info,
938946
quote(cookie), quote(ipaddr), quote(cexpire), mtime FROM user
939
- WHERE login IN ('carol','mallory')"] "carol|oj|Carol|NULL|NULL|NULL|1700000600"
947
+ WHERE login IN ('carol','mallory')"] \
948
+ "carol|oj|Carol|NULL|NULL|NULL|1700000600"
940949
test_eq config-field-skipped-uid [configSql k.fossil "SELECT count(*) FROM user
941950
WHERE uid=77"] 0
942951
943952
# A card that holds more field pairs than the command keeps is read up to
944953
# the eleventh field, and the later ones are dropped.
945954
set configCardBody "1700000600 'carol'"
946
-for {set configI 0} {$configI < 14} {incr configI} {append configCardBody " info 'v$configI'"}
955
+for {set configI 0} {$configI < 14} {incr configI} \
956
+ {append configCardBody " info 'v$configI'"}
947957
write_file many.cfg [configCard user "$configCardBody\n"]
948958
configRun configuration merge many.cfg -R k.fossil
949959
test config-fields-many {$CODE == 0 &&
950960
[configSql k.fossil "SELECT info FROM user WHERE login='carol'"] eq "Carol"}
951961
fossil sql -R k.fossil "UPDATE user SET mtime=5 WHERE login='carol'"
@@ -973,12 +983,10 @@
973983
# identity of the repository and its schema), and those that carry commands
974984
# and are never exported.
975985
976986
configNew n.fossil
977987
set configNBefore [configDump n.fossil]
978
-set configNProject [configSql n.fossil "SELECT value FROM config
979
- WHERE name='project-code'"]
980988
foreach configNm {project-code server-code content-schema aux-schema rebuilt
981989
th1-setup tcl-setup email-send-command diff-command editor
982990
ssh-command nosuch head headers Header walias:docs interwiki
983991
ticket_table} {
984992
set configCardBody "1700000600 '$configNm' value 'x'\n"
@@ -988,12 +996,10 @@
988996
[string first "Skipping non-exportable setting: '$configNm' = 'x'" \
989997
$RESULT] >= 0}
990998
test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \
991999
$configNBefore
9921000
}
993
-test_eq config-not-exportable-project-code [configSql n.fossil "SELECT value
994
- FROM config WHERE name='project-code'"] $configNProject
9951001
foreach {configNm configCardBody} {
9961002
number "1700000600 12 value 'x'\n"
9971003
empty "1700000600 '' value 'x'\n"
9981004
blob "1700000600 x'6373' value 'x'\n"
9991005
null "1700000600 NULL value 'x'\n"
@@ -1062,24 +1068,27 @@
10621068
set configOut [configOutside $configC $configArea]
10631069
set configPre [configDump $configC]
10641070
configRun configuration pull $configArea $configSrv -R $configC
10651071
test config-pull-$configArea {$CODE == 0}
10661072
test config-pull-$configArea-changed {[configDump $configC] ne $configPre}
1067
- test_eq config-pull-$configArea-outside [configOutside $configC $configArea] $configOut
1073
+ test_eq config-pull-$configArea-outside [configOutside $configC $configArea] \
1074
+ $configOut
10681075
configSameAs config-pull-$configArea-same $configC $configArea a.fossil
10691076
fossil test-integrity -R $configC
10701077
test config-pull-$configArea-integrity {$CODE == 0}
10711078
10721079
# Push.
10731080
set configD srv-push-$configArea.fossil
10741081
configNew $configD
10751082
set configOut [configOutside $configD $configArea]
10761083
set configPre [configDump $configD]
1077
- configRun configuration push $configArea [file join $configDir $configD] -R a.fossil
1084
+ configRun configuration push $configArea [file join $configDir $configD] \
1085
+ -R a.fossil
10781086
test config-push-$configArea {$CODE == 0}
10791087
test config-push-$configArea-changed {[configDump $configD] ne $configPre}
1080
- test_eq config-push-$configArea-outside [configOutside $configD $configArea] $configOut
1088
+ test_eq config-push-$configArea-outside [configOutside $configD $configArea] \
1089
+ $configOut
10811090
configSameAs config-push-$configArea-same $configD $configArea a.fossil
10821091
fossil test-integrity -R $configD
10831092
test config-push-$configArea-integrity {$CODE == 0}
10841093
}
10851094
@@ -1104,29 +1113,38 @@
11041113
test config-sync {$CODE == 0}
11051114
set configAliasSql "SELECT name,value,mtime FROM config
11061115
WHERE name GLOB 'walias:/*' ORDER BY name"
11071116
# A value with the same time on both sides stays as each side has it.
11081117
test_eq config-sync-same [configSql s1.fossil $configAliasSql] \
1109
- "walias:/both|new-2|1700000200\nwalias:/only1|one|1700000000\nwalias:/only2|two|1700000000\nwalias:/tie|tie-1|1700000300"
1118
+ [join [list \
1119
+ "walias:/both|new-2|1700000200\n" \
1120
+ "walias:/only1|one|1700000000\nwalias:/only2|two|1700000000\n" \
1121
+ "walias:/tie|tie-1|1700000300"] ""]
11101122
test_eq config-sync-same-other [configSql s2.fossil $configAliasSql] \
1111
- "walias:/both|new-2|1700000200\nwalias:/only1|one|1700000000\nwalias:/only2|two|1700000000\nwalias:/tie|tie-2|1700000300"
1123
+ [join [list \
1124
+ "walias:/both|new-2|1700000200\n" \
1125
+ "walias:/only1|one|1700000000\nwalias:/only2|two|1700000000\n" \
1126
+ "walias:/tie|tie-2|1700000300"] ""]
11121127
11131128
# Pull with --overwrite replaces the tables of the area, so a user that only
11141129
# this side has is gone; without it the user stays.
11151130
configNew o1.fossil
11161131
configNew o2.fossil
1117
-fossil sql -R o1.fossil "INSERT INTO user(login,cap,mtime) VALUES('local','o',7)"
1118
-fossil sql -R o2.fossil "INSERT INTO user(login,cap,mtime) VALUES('remote','o',8)"
1132
+fossil sql -R o1.fossil \
1133
+ "INSERT INTO user(login,cap,mtime) VALUES('local','o',7)"
1134
+fossil sql -R o2.fossil \
1135
+ "INSERT INTO user(login,cap,mtime) VALUES('remote','o',8)"
11191136
fossil sql -R o1.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x1',7,'l')"
11201137
fossil sql -R o2.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x2',8,'r')"
11211138
configRun configuration pull shun [file join $configDir o2.fossil] -R o1.fossil
11221139
test_eq config-pull-keeps-rows [configSql o1.fossil "SELECT group_concat(uuid)
11231140
FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x1,x2"
11241141
configRun configuration pull shun --overwrite [file join $configDir o2.fossil] \
11251142
-R o1.fossil
11261143
test config-pull-overwrite {$CODE == 0}
1127
-test_eq config-pull-overwrite-shun [configSql o1.fossil "SELECT group_concat(uuid)
1144
+test_eq config-pull-overwrite-shun \
1145
+ [configSql o1.fossil "SELECT group_concat(uuid)
11281146
FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x2"
11291147
configRun configuration pull user --overwrite [file join $configDir o2.fossil] \
11301148
-R o1.fossil
11311149
test config-pull-overwrite-user {$CODE == 0 && [configSql o1.fossil "SELECT
11321150
group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] ne ""}
@@ -1155,16 +1173,18 @@
11551173
fossil remote file://[file join $configDir a.fossil] -R u1.fossil
11561174
configRun configuration pull skin -R u1.fossil
11571175
test config-pull-default-server {$CODE == 0 &&
11581176
[configSql u1.fossil "SELECT value FROM config WHERE name='css'"] eq
11591177
"body { color: #123; }"}
1160
-configRun configuration pull project --proxy off [file join $configDir a.fossil] \
1178
+configRun configuration pull project --proxy off \
1179
+ [file join $configDir a.fossil] \
11611180
-R u1.fossil
11621181
test config-pull-proxy-off {$CODE == 0 &&
11631182
[configSql u1.fossil "SELECT value FROM config
11641183
WHERE name='project-name'"] eq "Alpha"}
1165
-configRun configuration pull skin [file join $configDir nosuch.fossil] -R u1.fossil
1184
+configRun configuration pull skin [file join $configDir nosuch.fossil] \
1185
+ -R u1.fossil
11661186
test config-pull-no-such-repository {$CODE == 1}
11671187
11681188
11691189
###############################################################################################################################################
11701190
# The configuration that a server sends on request: an area it does not know
@@ -1173,13 +1193,13 @@
11731193
configNew sv.fossil
11741194
configPut sv.fossil {css {'hello'} header {'h'}} 1700000000
11751195
write_file req.txt "$CLIENT_VERSION_CARD\
11761196
reqconfig /nosuch\nreqconfig /css\nreqconfig css\nreqconfig /nosuch2\n"
11771197
fossil_raw test-xfer -R sv.fossil req.txt
1178
-test config-request {$CODE == 0 && [regexp -all {config /config } $RESULT] == 1 &&
1179
- [string first "'css' value 'hello'" $RESULT] >= 0 &&
1180
- [string first "'header'" $RESULT] < 0 && [string first "errors 0" $RESULT] >= 0}
1198
+test config-request {$CODE == 0 && [regexp -all {config /config } $RESULT] == 1
1199
+ &&
1200
+ [holds_strings $RESULT {"'css' value 'hello'" !'header' "errors 0"}]}
11811201
11821202
###############################################################################
11831203
# A repository whose user and ticket report tables do not have the column
11841204
# for JSON data exports them without it, and takes the cards that have no
11851205
# such field.
@@ -1213,11 +1233,12 @@
12131233
write_file in.txt "from a file\nwith two lines\n"
12141234
fossil test-var-set beta --file in.txt -R v.fossil
12151235
fossil test-var-get beta -R v.fossil
12161236
test_eq config-var-set-file $RESULT "from a file\nwith two lines"
12171237
fossil test-var-get beta out2.txt -R v.fossil
1218
-test_eq config-var-set-file-exact [read_file out2.txt] "from a file\nwith two lines\n"
1238
+test_eq config-var-set-file-exact [read_file out2.txt] \
1239
+ "from a file\nwith two lines\n"
12191240
set configBlob "\x00\x01\xff\xfe\x80binary"
12201241
write_file blob.bin $configBlob
12211242
fossil test-var-set gamma --blob blob.bin -R v.fossil
12221243
fossil test-var-get gamma out3.bin -R v.fossil
12231244
test_eq config-var-set-blob [read_file out3.bin] $configBlob
@@ -1228,24 +1249,25 @@
12281249
test_eq config-var-set-stdin-value [configSql v.fossil "SELECT length(value)
12291250
FROM config WHERE name='delta'"] 9
12301251
fossil_raw test-var-set -R v.fossil
12311252
test config-var-set-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
12321253
fossil_raw test-var-set epsilon -R v.fossil
1233
-test config-var-set-no-value {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1254
+test config-var-set-no-value \
1255
+ {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
12341256
fossil_raw test-var-set epsilon --file in.txt --blob blob.bin -R v.fossil
12351257
test config-var-set-both {$CODE == 1 &&
12361258
[string first "cannot do both" $RESULT] >= 0}
12371259
fossil_raw test-var-set epsilon --file nosuch.txt -R v.fossil
12381260
test config-var-set-no-file {$CODE == 1}
12391261
test_eq config-var-set-none-made [configSql v.fossil "SELECT count(*) FROM
12401262
config WHERE name='epsilon'"] 0
12411263
fossil_raw test-var-get nosuch -R v.fossil
1242
-test config-var-get-none {$CODE == 1 && [string first "no match for" $RESULT] >= 0}
1264
+test config-var-get-none {$CODE == 1 && [string first "no match for" $RESULT] >=
1265
+ 0}
12431266
fossil_raw test-var-get {[abg]*} -R v.fossil
12441267
test config-var-get-many {$CODE == 1 &&
1245
- [string first "multiple matches:" $RESULT] >= 0 &&
1246
- [string first "'alpha'" $RESULT] >= 0 && [string first "'beta'" $RESULT] >= 0}
1268
+ [holds_strings $RESULT {"multiple matches:" 'alpha' 'beta'}]}
12471269
fossil_raw test-var-get -R v.fossil
12481270
test config-var-get-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
12491271
fossil test-var-get {alph?} -R v.fossil
12501272
test_eq config-var-get-glob $RESULT hello
12511273
@@ -1273,11 +1295,12 @@
12731295
proc configListLine {name value pad} {
12741296
return "$name:[string repeat { } [expr {$pad - [string length $name]}]]$value"
12751297
}
12761298
configRun test-var-list -R w.fossil
12771299
set configList $RESULT
1278
-test config-var-list-short {[string first "[configListLine a-short plain 27]\n" \
1300
+test config-var-list-short \
1301
+ {[string first "[configListLine a-short plain 27]\n" \
12791302
$configList] >= 0}
12801303
test config-var-list-escapes {[string first \
12811304
"[configListLine a-ctl {x\n\r\t\001y} 27]\n" $configList] >= 0}
12821305
test config-var-list-long-value {[string first \
12831306
"[configListLine a-long [string range $configLongValue 0 39]...+20 27]\n" \
@@ -1405,11 +1428,12 @@
14051428
configShareProject $configC
14061429
set configPre [configDump $configC]
14071430
configNetRun pull $configArea $configC $configPort $configUser
14081431
test config-pull-$configLabel-$configArea {$CODE == 0}
14091432
foreach configPart [configParts $configArea] {
1410
- configHasPart config-pull-$configLabel-$configArea-has $configC $configPart \
1433
+ configHasPart config-pull-$configLabel-$configArea-has $configC \
1434
+ $configPart \
14111435
[configMayPull $configUser $configPart]
14121436
}
14131437
if {$configUser ne "blind" && $configLabel ne "nobody"} {
14141438
test config-pull-$configLabel-$configArea-changed \
14151439
{[configDump $configC] ne $configPre}
@@ -1452,31 +1476,12 @@
14521476
# Cards that a server sends for configuration that was not asked for are
14531477
# dropped by the client, those it asked for are kept. A server made here
14541478
# answers the first request with a prepared reply and every later one with a
14551479
# bare timestamp.
14561480
1457
-set configFakeReply ""
1458
-set configFakeCount 0
1459
-set configFakeRequests {}
1460
-proc configFakeAccept {chan address port} {
1461
- fconfigure $chan -translation binary -blocking 0
1462
- set ::configFakeBuf($chan) ""
1463
- fileevent $chan readable [list configFakeRead $chan]
1464
-}
1465
-proc configFakeRead {chan} {
1466
- append ::configFakeBuf($chan) [read $chan]
1467
- set request $::configFakeBuf($chan)
1481
+proc configFakeRead {chan request} {
14681482
set end [string first "\r\n\r\n" $request]
1469
- set length 0
1470
- regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
1471
- if {![eof $chan] &&
1472
- ($end < 0 || [string length $request] < $end + 4 + $length)} {
1473
- return
1474
- }
1475
- unset ::configFakeBuf($chan)
1476
- fileevent $chan readable {}
1477
- fconfigure $chan -blocking 1
14781483
# The request is the text of the cards, after four bytes of size when it
14791484
# is compressed.
14801485
set body [string range $request [expr {$end+4}] end]
14811486
if {[regexp -nocase {content-type:\s*application/x-fossil\s} $request]} {
14821487
set body [zlib decompress [string range $body 4 end]]
@@ -1492,12 +1497,11 @@
14921497
application/x-fossil-uncompressed\r\nContent-Length:\
14931498
[string length $reply]\r\n\r\n$reply"
14941499
close $chan
14951500
}
14961501
}
1497
-set configFakeServer [socket -server configFakeAccept -myaddr 127.0.0.1 0]
1498
-set configFakePort [lindex [fconfigure $configFakeServer -sockname] 2]
1502
+set configFakePort [test_listen configFakeRead]
14991503
15001504
proc configReply {verb area reply} {
15011505
global configFakePort configFakeReply configFakeCount configFakeRequests
15021506
set configFakeReply $reply
15031507
set configFakeCount 0
@@ -1517,11 +1521,12 @@
15171521
test_eq config-reply-asked [configSql rp.fossil "SELECT group_concat(name)
15181522
FROM (SELECT name FROM config WHERE name IN ('header','adunit',
15191523
'project-name') ORDER BY name)"] "adunit,header"
15201524
test_eq config-reply-unasked-user [configSql rp.fossil "SELECT count(*) FROM
15211525
user WHERE login='zed'"] 0
1522
-test config-reply-request-skin {[string first "reqconfig /skin\nreqconfig /css\n" \
1526
+test config-reply-request-skin \
1527
+ {[string first "reqconfig /skin\nreqconfig /css\n" \
15231528
[lindex $configFakeRequests 0]] >= 0}
15241529
configReply pull css $configRpReply
15251530
test_eq config-reply-css-only [configSql rp.fossil "SELECT count(*) FROM
15261531
config WHERE name='project-name'"] 0
15271532
# How many "reqconfig" cards the first request holds.
@@ -1539,11 +1544,11 @@
15391544
configReply pull ticket ""
15401545
test config-reply-request-ticket {[string first "reqconfig /ticket\n" \
15411546
[lindex $configFakeRequests 0]] >= 0}
15421547
configReply pull user "config /user 0\n\n"
15431548
test config-reply-empty-card {$CODE == 0}
1544
-close $configFakeServer
1549
+test_listen_stop
15451550
15461551
###############################################################################
15471552
# "fossil init --template" copies the settings of another repository,
15481553
# those of every area and the aliases among them, and leaves out the names
15491554
# of the project and any setting that belongs to no area.
15501555
--- test/config.test
+++ test/config.test
@@ -6,15 +6,12 @@
6 # asks for. After each command the configuration of the area must be what
7 # the command is documented to leave, and the rest of the repository must
8 # be as it was.
9 #
10
11 # These tests run only in a long pass: -assurance stress.
12 if {[test_assurance] ne "stress"} {
13 test_skip "runs only with -assurance stress"
14 }
15
16 require_no_open_checkout
17
18 test_setup ""
19 set configDir [pwd]
20 set ::env(FOSSIL_USER) tester
@@ -23,12 +20,11 @@
23 # Helpers.
24
25 # Run SQL in repository REPO and return its output without the final
26 # newline.
27 proc configSql {repo sql} {
28 fossil sql -R $repo $sql
29 return [string trim $::RESULT]
30 }
31
32 # Make an empty repository FILE and give its settings a time long before
33 # any that the tests write, so that a test sees only what it set.
34 proc configNew {file} {
@@ -116,14 +112,21 @@
116
117 # A setting that is empty or absent has no time that a test can know: the
118 # repository makes a new "hash-policy" when it is opened. MASK hides its time.
119 # The SQL that lists what repository holds in the tables TABLES. With
120 # EXPORTED set, only the rows that an export sends: those with a time of
121 # last change, and the verified subscribers.
 
 
122 proc configTableSql {tables exported} {
123 set m [expr {$exported ? "WHERE mtime IS NOT NULL" : ""}]
124 set sql ""
 
 
 
 
 
125 foreach t $tables {
126 switch -- $t {
127 rpt {append sql "SELECT 'rpt', owner, title, mtime, quote(cols),
128 quote(sqlcode), quote(ifnull(jx,'{}')) FROM reportfmt $m ORDER BY title;"}
129 usr {append sql "SELECT 'usr', login, quote(pw), quote(cap),
@@ -149,19 +152,11 @@
149 global configTables
150 set t [expr {$mask ? "CASE WHEN name='hash-policy' THEN 0 ELSE mtime END"
151 : "mtime"}]
152 set sql "SELECT 'cfg', name, quote(value), $t FROM config
153 WHERE [configCond $area] ORDER BY name;"
154 if {$area eq "subscriber" && ![configHasTable $repo subscriber]} {
155 set tables {}
156 } else {
157 set tables $configTables($area)
158 }
159 if {"sub" in $tables && ![configHasTable $repo subscriber]} {
160 set tables [lsearch -all -inline -not -exact $tables sub]
161 }
162 append sql [configTableSql $tables $exported]
163 return [configSql $repo $sql]
164 }
165
166 # What REPO holds outside AREA, to see that a command left it alone.
167 proc configOutside {repo area} {
@@ -170,22 +165,14 @@
170 WHERE NOT [configCond $area] ORDER BY name;"
171 set tables {}
172 foreach t {rpt usr cnc shn sub} {
173 if {$t ni $configTables($area)} {lappend tables $t}
174 }
175 if {![configHasTable $repo subscriber]} {
176 set tables [lsearch -all -inline -not -exact $tables sub]
177 }
178 append sql [configTableSql $tables 0]
179 return [configSql $repo $sql]
180 }
181
182 proc configHasTable {repo table} {
183 return [configSql $repo "SELECT count(*) FROM sqlite_schema
184 WHERE name='$table' AND type='table'"]
185 }
186
187 # The kinds of card that an export file holds, in order and without
188 # repeats.
189 proc configKinds {file} {
190 set kinds {}
191 foreach line [split [read_file $file] \n] {
@@ -382,16 +369,22 @@
382 set configFile export-$configArea.cfg
383 configRun configuration export $configArea $configFile -R a.fossil
384 test config-export-$configArea {$CODE == 0 && $RESULT eq ""}
385 set configText [read_file $configFile]
386 test_match config-export-$configArea-header $configText \
387 "^# The \"$configArea\" configuration exported from\n# repository \"a.fossil\"\n# on \[0-9-\]+ \[0-9:\]+\n"
 
 
388 test_eq config-export-$configArea-cards [configKinds $configFile] \
389 [lsort $configKindsOf($configArea)]
390 }
391 test_eq config-export-changes-nothing [configSql a.fossil "SELECT 'c',name,mtime
392 FROM config ORDER BY name"] $configBefore
 
 
 
 
393
394 ###############################################################################
395 # Import: an area exported from one repository and imported into another
396 # makes the second hold what the first holds, in that area, with the times
397 # of last change. The tables of the area are replaced, so that a row that
@@ -445,12 +438,14 @@
445 set configExp [configState a.fossil $configArea 1]
446 test config-$configArea-has-content {$configExp ne ""}
447
448 configRun configuration import export-$configArea.cfg -R $configB
449 test config-import-$configArea {$CODE == 0 && $RESULT eq ""}
450 test_eq config-import-$configArea-same [configState $configB $configArea] $configExp
451 test_eq config-import-$configArea-outside [configOutside $configB $configArea] $configOut
 
 
452 if {$configArea eq "ticket" || $configArea eq "all"} {
453 # The ticket tables are rebuilt from the imported ticket-table.
454 test_eq config-import-$configArea-ticket-table [configSql $configB "SELECT
455 count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 1
456 }
@@ -462,37 +457,44 @@
462 set configOut [configOutside $configB $configArea]
463 configRun configuration reset $configArea -R $configB
464 test config-reset-$configArea {$CODE == 0 &&
465 [string first "Configuration reset to factory defaults." $RESULT] >= 0}
466 set configResetOut $RESULT
467 test_eq config-reset-$configArea-outside [configOutside $configB $configArea] $configOut
 
 
468 regexp {import (config-backup-[0-9.]+)} $configResetOut -> configBackup
469 test config-reset-$configArea-backup {[info exists configBackup] &&
470 [file exists $configBackup]}
471 if {$configArea eq "user" || $configArea eq "all"} {
472 # The default users come back, and the user who ran the command is
473 # their administrator.
474 test_eq config-reset-$configArea-users [configSql $configB "SELECT login, cap, mtime
 
475 FROM user ORDER BY login"] \
476 "anonymous|hz|\ndeveloper|ei|\nnobody|gjorz|\nreader|kptw|\ntester|s|"
477 }
478 if {$configArea ni {alias interwiki all user}} {
479 test_eq config-reset-$configArea-state [configState $configB $configArea 0 1] \
 
480 [configDefaults $configArea]
481 }
482 if {$configArea eq "ticket" || $configArea eq "all"} {
483 test_eq config-reset-$configArea-ticket-table [configSql $configB "SELECT
484 count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 0
485 }
486 if {$configArea eq "subscriber" || $configArea eq "all"} {
487 test_eq config-reset-$configArea-subscribers [configSql $configB "SELECT count(*)
 
488 FROM subscriber"] 0
489 }
490 configRun configuration import $configBackup -R $configB
491 test config-reset-$configArea-recover {$CODE == 0}
492 test_eq config-reset-$configArea-recovered [configState $configB $configArea] $configPre
493 test_eq config-reset-$configArea-recovered-outside [configOutside $configB $configArea] \
 
 
494 $configOut
495 }
496
497
498 ###############################################################################
@@ -500,12 +502,13 @@
500
501 foreach configArea {alias interwiki} {
502 configNew r-$configArea.fossil
503 configFill r-$configArea.fossil
504 configRun configuration reset $configArea -R r-$configArea.fossil
505 test config-reset-$configArea-removes {[configState r-$configArea.fossil $configArea 0 1] eq
506 [configDefaults $configArea]}
 
507 }
508 configNew r-all.fossil
509 configFill r-all.fossil
510 configRun configuration reset all -R r-all.fossil
511 test config-reset-all-removes-aliases {[configSql r-all.fossil "SELECT count(*)
@@ -569,11 +572,12 @@
569
570 ###############################################################################
571 # Names of areas and methods: an abbreviation that starts the name is
572 # enough. An unknown area lists the areas and writes nothing.
573
574 foreach {configAbbrev configArea} {sk skin pro project t ticket u user e email sh shun
 
575 a alias al alias all all su subscriber i interwiki
576 x xfer c css} {
577 file delete abbrev.cfg
578 configRun configuration export $configAbbrev abbrev.cfg -R a.fossil
579 test config-area-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]}
@@ -584,14 +588,14 @@
584 }
585 file delete abbrev.cfg
586 foreach configBad {nosuch skinx ALL Skin} {
587 configRun configuration export $configBad abbrev.cfg -R a.fossil
588 test config-area-unknown-$configBad {$CODE == 1 &&
589 [string first "no such configuration area: \"$configBad\"" $RESULT] >= 0 &&
590 [string first "Available configuration areas:" $RESULT] >= 0 &&
591 [string first " skin Web interface appearance settings" \
592 $RESULT] >= 0 &&
593 ![file exists abbrev.cfg]}
594 }
595 foreach configMethod {reset pull push sync} {
596 configRun configuration $configMethod nosuch -R a.fossil
597 test config-area-unknown-$configMethod {$CODE == 1 &&
@@ -600,14 +604,16 @@
600
601 # The methods accept abbreviations too.
602 foreach {configAbbrev configFull} {exp export e export ex export} {
603 file delete abbrev.cfg
604 configRun configuration $configAbbrev skin abbrev.cfg -R a.fossil
605 test config-method-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]}
 
606 }
607 configNew m-abbrev.fossil
608 foreach {configAbbrev configTag} {i import im import imp import m merge me merge mer merge} {
 
609 configRun configuration $configAbbrev export-skin.cfg -R m-abbrev.fossil
610 test config-method-abbrev-$configAbbrev {$CODE == 0 &&
611 [configSql m-abbrev.fossil "SELECT value FROM config
612 WHERE name='css'"] eq "body { color: #123; }"}
613 fossil sql -R m-abbrev.fossil "DELETE FROM config WHERE name='css'"
@@ -635,18 +641,18 @@
635 pull-too-many {pull skin a b}
636 push-none {push}
637 sync-none {sync}
638 } {
639 configRun configuration {*}$configArgs -R a.fossil
640 test config-usage-$configNm {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
 
641 }
642 configRun configuration frobnicate -R a.fossil
643 test config-method-unknown {$CODE == 1 &&
644 [string first "METHOD should be one of: export import merge pull push reset"\
 
645 $RESULT] >= 0}
646 configRun configuration -R a.fossil
647 test config-method-missing {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
648 configRun configuration import nosuchfile.cfg -R a.fossil
649 test config-import-no-file {$CODE == 1}
650
651
652 ###############################################################################
@@ -691,11 +697,12 @@
691 test_eq config-merge-$name [configSql m.fossil $sql] $expected
692 }
693 configMergeCheck newer-local-kept "SELECT value FROM config WHERE name='css'" \
694 local-css
695 configMergeCheck older-local-replaced "SELECT value||'|'||mtime FROM config
696 WHERE name='header'" "<html>\n<head><title>It's \"quoted\"</title></head>\n|1700000001"
 
697 configMergeCheck equal-time-local-kept "SELECT value FROM config
698 WHERE name='mainmenu'" local-menu
699 configMergeCheck absent-added "SELECT value FROM config WHERE name='js'" \
700 "var a = 'b';"
701 configMergeCheck alias-newer-local-kept "SELECT value FROM config
@@ -746,29 +753,28 @@
746 test_eq config-merge-twice [configState m.fossil all] $configMerged
747
748 # Merge into an empty repository is import.
749 configNew m2.fossil
750 configRun configuration merge export-all.cfg -R m2.fossil
751 foreach configArea {skin project ticket xfer alias interwiki email shun subscriber} {
 
752 test_eq config-merge-empty-$configArea [configState m2.fossil $configArea] \
753 [configState a.fossil $configArea 1]
754 }
755
756 # Import and merge write only inside one transaction: a file that stops the
757 # command leaves the repository as it was. A file with a card that SQLite
758 # cannot take (a repeated column) is such a file.
759 configNew t.fossil
760 configPut t.fossil {css {'kept'}} 1700000000
761 set configTx [configState t.fossil all]
762 set configTxCard "1700000100 'x' value 'v'"
763 set configTxCard2 "1700000100 'alice' pw 'a' pw 'b' pw 'c' pw 'd' pw 'e' pw 'f' pw 'g'
764 pw 'h' pw 'i' pw 'j' pw 'k' pw 'l' pw 'm' pw 'n'"
765 write_file tx.cfg "[configCard config "1700000100 'css' value 'changed'"]\
766 [configCard user $configTxCard2]"
767 configRun configuration merge tx.cfg -R t.fossil
768 set configTxCode $CODE
769 set configTxOut $RESULT
770 test config-card-many-fields {$configTxCode == 0 || $configTxCode == 1}
771 fossil test-integrity -R t.fossil
772 test config-card-many-fields-integrity {$CODE == 0}
773
774 ###############################################################################
@@ -817,11 +823,12 @@
817 string-lone {'}
818 null-prefix {NULLx}
819 not-null {NUL}
820 } {
821 fossil sql -R l.fossil "DELETE FROM config WHERE name='header'"
822 write_file lit.cfg [configCard config "1700000000 'header' value $configValue"]
 
823 configRun configuration merge lit.cfg -R l.fossil
824 test config-literal-refused-$configNm {$CODE == 0 &&
825 [configSql l.fossil "SELECT count(*) FROM config
826 WHERE name='header'"] == 0}
827 }
@@ -833,45 +840,40 @@
833 # if it were not there. Nothing is written that the card did not name.
834
835 # Everything that REPO holds, settings and tables, except the two settings
836 # that a server of the repository writes for its own use.
837 proc configDump {repo} {
838 global configTables
839 set sql "SELECT 'cfg', name, quote(value), mtime FROM config
840 WHERE name<>'backoffice' AND name NOT GLOB 'baseurl:*'
841 ORDER BY name;"
842 set tables {rpt usr cnc shn}
843 if {[configHasTable $repo subscriber]} {lappend tables sub}
844 append sql [configTableSql $tables 0]
845 return [configSql $repo $sql]
846 }
847
848 configNew c.fossil
849 configPut c.fossil {css {'old'} js {'old'}} 1700000000
 
850 set configGood [configCard config "1700000500 'footer' value 'good'"]
851 set configCases 0
852
853 # Run import and merge of TEXT into a copy of c.fossil. Both must leave
854 # the repository as it was, except that the card "footer" at the end of the
855 # file, when GOOD is true, is read.
856 proc configMalformed {name text good {code 0}} {
857 global configGood configCases
858 foreach method {merge import} {
859 set repo c-$method.fossil
860 file copy -force c.fossil $repo
861 set before [configDump $repo]
862 write_file bad.cfg [expr {$good ? "$text$configGood" : $text}]
863 configRun configuration $method bad.cfg -R $repo
864 set after [configDump $repo]
865 test config-malformed-$name-$method-exit {$::CODE == $code}
866 if {$good} {
867 set want [configSql $repo "SELECT value FROM config WHERE name='footer'"]
 
868 test_eq config-malformed-$name-$method-next-card $want good
869 fossil sql -R $repo "DELETE FROM config WHERE name='footer'"
870 set after [configDump $repo]
871 }
872 test_eq config-malformed-$name-$method-unchanged $after $before
 
873 }
874 }
875 set configBody "1700000600 'css' value 'new'\n"
876 set configLen [string length $configBody]
877
@@ -889,16 +891,19 @@
889 configMalformed negative-size "config /config -5\n$configBody\n" 1
890 configMalformed size-letters "config /config 12ab\n$configBody\n" 1
891 configMalformed size-plus "config /config +$configLen\n$configBody\n" 1
892 configMalformed size-hex "config /config 0x10\n$configBody\n" 1
893 configMalformed size-float "config /config 1.5\n$configBody\n" 1
894 configMalformed size-too-big-for-int "config /config 99999999999\n$configBody\n" 1
895 configMalformed size-extra-token "config /config $configLen extra\n$configBody\n" 1
 
 
896 configMalformed size-zero "config /config 0\n\n" 1
897 configMalformed size-short "config /config 10\n$configBody\n" 1
898 configMalformed truncated-key "config /config 40\n1700000600 'cs" 0
899 configMalformed truncated-literal "config /config 40\n1700000600 'css' value 'ne\n" 0
 
900 foreach {configNm configCardBody} {
901 missing-mtime "'css' value 'x'\n"
902 bare-name "1700000600 css value 'x'\n"
903 name-only "1700000600\n"
904 empty-card "\n"
@@ -906,14 +911,16 @@
906 zero-byte-time "\0001700000600 'css' value 'x'\n"
907 zero-byte-name "1700000600 \000'css' value 'x'\n"
908 } {
909 configMalformed $configNm [configCard config $configCardBody] 1
910 }
911 foreach {configNm configMtime} {letters abc fraction 1.5 negative -5 hex 0x10 blank-sign +5
 
912 exponent 1e3 quoted '5'} {
913 set configCardBody "$configMtime 'css' value 'new'\n"
914 configMalformed mtime-$configNm "config /config [string length $configCardBody]\n$configCardBody\n" 1
 
915 }
916
917 # A size that is larger than the rest of the file takes the rest.
918 foreach configMethod {merge import} {
919 file copy -force c.fossil c-$configMethod.fossil
@@ -927,25 +934,28 @@
927 # A field that is not a column of the table is skipped; one that would
928 # set a column that nothing outside may set is among them.
929 configNew k.fossil
930 fossil sql -R k.fossil "INSERT INTO user(login,pw,cap,mtime)
931 VALUES('carol','pw','o',5)"
932 set configCardBody "1700000600 'carol' cap 'oj' cookie 'stolen' ipaddr '1.2.3.4'\
 
933 cexpire 1 uid 77 login 'mallory' bogus 'x' info 'Carol'\n"
934 write_file fields.cfg [configCard user $configCardBody]
935 configRun configuration merge fields.cfg -R k.fossil
936 test config-field-skipped {$CODE == 0}
937 test_eq config-field-skipped-row [configSql k.fossil "SELECT login, cap, info,
938 quote(cookie), quote(ipaddr), quote(cexpire), mtime FROM user
939 WHERE login IN ('carol','mallory')"] "carol|oj|Carol|NULL|NULL|NULL|1700000600"
 
940 test_eq config-field-skipped-uid [configSql k.fossil "SELECT count(*) FROM user
941 WHERE uid=77"] 0
942
943 # A card that holds more field pairs than the command keeps is read up to
944 # the eleventh field, and the later ones are dropped.
945 set configCardBody "1700000600 'carol'"
946 for {set configI 0} {$configI < 14} {incr configI} {append configCardBody " info 'v$configI'"}
 
947 write_file many.cfg [configCard user "$configCardBody\n"]
948 configRun configuration merge many.cfg -R k.fossil
949 test config-fields-many {$CODE == 0 &&
950 [configSql k.fossil "SELECT info FROM user WHERE login='carol'"] eq "Carol"}
951 fossil sql -R k.fossil "UPDATE user SET mtime=5 WHERE login='carol'"
@@ -973,12 +983,10 @@
973 # identity of the repository and its schema), and those that carry commands
974 # and are never exported.
975
976 configNew n.fossil
977 set configNBefore [configDump n.fossil]
978 set configNProject [configSql n.fossil "SELECT value FROM config
979 WHERE name='project-code'"]
980 foreach configNm {project-code server-code content-schema aux-schema rebuilt
981 th1-setup tcl-setup email-send-command diff-command editor
982 ssh-command nosuch head headers Header walias:docs interwiki
983 ticket_table} {
984 set configCardBody "1700000600 '$configNm' value 'x'\n"
@@ -988,12 +996,10 @@
988 [string first "Skipping non-exportable setting: '$configNm' = 'x'" \
989 $RESULT] >= 0}
990 test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \
991 $configNBefore
992 }
993 test_eq config-not-exportable-project-code [configSql n.fossil "SELECT value
994 FROM config WHERE name='project-code'"] $configNProject
995 foreach {configNm configCardBody} {
996 number "1700000600 12 value 'x'\n"
997 empty "1700000600 '' value 'x'\n"
998 blob "1700000600 x'6373' value 'x'\n"
999 null "1700000600 NULL value 'x'\n"
@@ -1062,24 +1068,27 @@
1062 set configOut [configOutside $configC $configArea]
1063 set configPre [configDump $configC]
1064 configRun configuration pull $configArea $configSrv -R $configC
1065 test config-pull-$configArea {$CODE == 0}
1066 test config-pull-$configArea-changed {[configDump $configC] ne $configPre}
1067 test_eq config-pull-$configArea-outside [configOutside $configC $configArea] $configOut
 
1068 configSameAs config-pull-$configArea-same $configC $configArea a.fossil
1069 fossil test-integrity -R $configC
1070 test config-pull-$configArea-integrity {$CODE == 0}
1071
1072 # Push.
1073 set configD srv-push-$configArea.fossil
1074 configNew $configD
1075 set configOut [configOutside $configD $configArea]
1076 set configPre [configDump $configD]
1077 configRun configuration push $configArea [file join $configDir $configD] -R a.fossil
 
1078 test config-push-$configArea {$CODE == 0}
1079 test config-push-$configArea-changed {[configDump $configD] ne $configPre}
1080 test_eq config-push-$configArea-outside [configOutside $configD $configArea] $configOut
 
1081 configSameAs config-push-$configArea-same $configD $configArea a.fossil
1082 fossil test-integrity -R $configD
1083 test config-push-$configArea-integrity {$CODE == 0}
1084 }
1085
@@ -1104,29 +1113,38 @@
1104 test config-sync {$CODE == 0}
1105 set configAliasSql "SELECT name,value,mtime FROM config
1106 WHERE name GLOB 'walias:/*' ORDER BY name"
1107 # A value with the same time on both sides stays as each side has it.
1108 test_eq config-sync-same [configSql s1.fossil $configAliasSql] \
1109 "walias:/both|new-2|1700000200\nwalias:/only1|one|1700000000\nwalias:/only2|two|1700000000\nwalias:/tie|tie-1|1700000300"
 
 
 
1110 test_eq config-sync-same-other [configSql s2.fossil $configAliasSql] \
1111 "walias:/both|new-2|1700000200\nwalias:/only1|one|1700000000\nwalias:/only2|two|1700000000\nwalias:/tie|tie-2|1700000300"
 
 
 
1112
1113 # Pull with --overwrite replaces the tables of the area, so a user that only
1114 # this side has is gone; without it the user stays.
1115 configNew o1.fossil
1116 configNew o2.fossil
1117 fossil sql -R o1.fossil "INSERT INTO user(login,cap,mtime) VALUES('local','o',7)"
1118 fossil sql -R o2.fossil "INSERT INTO user(login,cap,mtime) VALUES('remote','o',8)"
 
 
1119 fossil sql -R o1.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x1',7,'l')"
1120 fossil sql -R o2.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x2',8,'r')"
1121 configRun configuration pull shun [file join $configDir o2.fossil] -R o1.fossil
1122 test_eq config-pull-keeps-rows [configSql o1.fossil "SELECT group_concat(uuid)
1123 FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x1,x2"
1124 configRun configuration pull shun --overwrite [file join $configDir o2.fossil] \
1125 -R o1.fossil
1126 test config-pull-overwrite {$CODE == 0}
1127 test_eq config-pull-overwrite-shun [configSql o1.fossil "SELECT group_concat(uuid)
 
1128 FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x2"
1129 configRun configuration pull user --overwrite [file join $configDir o2.fossil] \
1130 -R o1.fossil
1131 test config-pull-overwrite-user {$CODE == 0 && [configSql o1.fossil "SELECT
1132 group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] ne ""}
@@ -1155,16 +1173,18 @@
1155 fossil remote file://[file join $configDir a.fossil] -R u1.fossil
1156 configRun configuration pull skin -R u1.fossil
1157 test config-pull-default-server {$CODE == 0 &&
1158 [configSql u1.fossil "SELECT value FROM config WHERE name='css'"] eq
1159 "body { color: #123; }"}
1160 configRun configuration pull project --proxy off [file join $configDir a.fossil] \
 
1161 -R u1.fossil
1162 test config-pull-proxy-off {$CODE == 0 &&
1163 [configSql u1.fossil "SELECT value FROM config
1164 WHERE name='project-name'"] eq "Alpha"}
1165 configRun configuration pull skin [file join $configDir nosuch.fossil] -R u1.fossil
 
1166 test config-pull-no-such-repository {$CODE == 1}
1167
1168
1169 ###############################################################################################################################################
1170 # The configuration that a server sends on request: an area it does not know
@@ -1173,13 +1193,13 @@
1173 configNew sv.fossil
1174 configPut sv.fossil {css {'hello'} header {'h'}} 1700000000
1175 write_file req.txt "$CLIENT_VERSION_CARD\
1176 reqconfig /nosuch\nreqconfig /css\nreqconfig css\nreqconfig /nosuch2\n"
1177 fossil_raw test-xfer -R sv.fossil req.txt
1178 test config-request {$CODE == 0 && [regexp -all {config /config } $RESULT] == 1 &&
1179 [string first "'css' value 'hello'" $RESULT] >= 0 &&
1180 [string first "'header'" $RESULT] < 0 && [string first "errors 0" $RESULT] >= 0}
1181
1182 ###############################################################################
1183 # A repository whose user and ticket report tables do not have the column
1184 # for JSON data exports them without it, and takes the cards that have no
1185 # such field.
@@ -1213,11 +1233,12 @@
1213 write_file in.txt "from a file\nwith two lines\n"
1214 fossil test-var-set beta --file in.txt -R v.fossil
1215 fossil test-var-get beta -R v.fossil
1216 test_eq config-var-set-file $RESULT "from a file\nwith two lines"
1217 fossil test-var-get beta out2.txt -R v.fossil
1218 test_eq config-var-set-file-exact [read_file out2.txt] "from a file\nwith two lines\n"
 
1219 set configBlob "\x00\x01\xff\xfe\x80binary"
1220 write_file blob.bin $configBlob
1221 fossil test-var-set gamma --blob blob.bin -R v.fossil
1222 fossil test-var-get gamma out3.bin -R v.fossil
1223 test_eq config-var-set-blob [read_file out3.bin] $configBlob
@@ -1228,24 +1249,25 @@
1228 test_eq config-var-set-stdin-value [configSql v.fossil "SELECT length(value)
1229 FROM config WHERE name='delta'"] 9
1230 fossil_raw test-var-set -R v.fossil
1231 test config-var-set-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1232 fossil_raw test-var-set epsilon -R v.fossil
1233 test config-var-set-no-value {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
 
1234 fossil_raw test-var-set epsilon --file in.txt --blob blob.bin -R v.fossil
1235 test config-var-set-both {$CODE == 1 &&
1236 [string first "cannot do both" $RESULT] >= 0}
1237 fossil_raw test-var-set epsilon --file nosuch.txt -R v.fossil
1238 test config-var-set-no-file {$CODE == 1}
1239 test_eq config-var-set-none-made [configSql v.fossil "SELECT count(*) FROM
1240 config WHERE name='epsilon'"] 0
1241 fossil_raw test-var-get nosuch -R v.fossil
1242 test config-var-get-none {$CODE == 1 && [string first "no match for" $RESULT] >= 0}
 
1243 fossil_raw test-var-get {[abg]*} -R v.fossil
1244 test config-var-get-many {$CODE == 1 &&
1245 [string first "multiple matches:" $RESULT] >= 0 &&
1246 [string first "'alpha'" $RESULT] >= 0 && [string first "'beta'" $RESULT] >= 0}
1247 fossil_raw test-var-get -R v.fossil
1248 test config-var-get-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1249 fossil test-var-get {alph?} -R v.fossil
1250 test_eq config-var-get-glob $RESULT hello
1251
@@ -1273,11 +1295,12 @@
1273 proc configListLine {name value pad} {
1274 return "$name:[string repeat { } [expr {$pad - [string length $name]}]]$value"
1275 }
1276 configRun test-var-list -R w.fossil
1277 set configList $RESULT
1278 test config-var-list-short {[string first "[configListLine a-short plain 27]\n" \
 
1279 $configList] >= 0}
1280 test config-var-list-escapes {[string first \
1281 "[configListLine a-ctl {x\n\r\t\001y} 27]\n" $configList] >= 0}
1282 test config-var-list-long-value {[string first \
1283 "[configListLine a-long [string range $configLongValue 0 39]...+20 27]\n" \
@@ -1405,11 +1428,12 @@
1405 configShareProject $configC
1406 set configPre [configDump $configC]
1407 configNetRun pull $configArea $configC $configPort $configUser
1408 test config-pull-$configLabel-$configArea {$CODE == 0}
1409 foreach configPart [configParts $configArea] {
1410 configHasPart config-pull-$configLabel-$configArea-has $configC $configPart \
 
1411 [configMayPull $configUser $configPart]
1412 }
1413 if {$configUser ne "blind" && $configLabel ne "nobody"} {
1414 test config-pull-$configLabel-$configArea-changed \
1415 {[configDump $configC] ne $configPre}
@@ -1452,31 +1476,12 @@
1452 # Cards that a server sends for configuration that was not asked for are
1453 # dropped by the client, those it asked for are kept. A server made here
1454 # answers the first request with a prepared reply and every later one with a
1455 # bare timestamp.
1456
1457 set configFakeReply ""
1458 set configFakeCount 0
1459 set configFakeRequests {}
1460 proc configFakeAccept {chan address port} {
1461 fconfigure $chan -translation binary -blocking 0
1462 set ::configFakeBuf($chan) ""
1463 fileevent $chan readable [list configFakeRead $chan]
1464 }
1465 proc configFakeRead {chan} {
1466 append ::configFakeBuf($chan) [read $chan]
1467 set request $::configFakeBuf($chan)
1468 set end [string first "\r\n\r\n" $request]
1469 set length 0
1470 regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
1471 if {![eof $chan] &&
1472 ($end < 0 || [string length $request] < $end + 4 + $length)} {
1473 return
1474 }
1475 unset ::configFakeBuf($chan)
1476 fileevent $chan readable {}
1477 fconfigure $chan -blocking 1
1478 # The request is the text of the cards, after four bytes of size when it
1479 # is compressed.
1480 set body [string range $request [expr {$end+4}] end]
1481 if {[regexp -nocase {content-type:\s*application/x-fossil\s} $request]} {
1482 set body [zlib decompress [string range $body 4 end]]
@@ -1492,12 +1497,11 @@
1492 application/x-fossil-uncompressed\r\nContent-Length:\
1493 [string length $reply]\r\n\r\n$reply"
1494 close $chan
1495 }
1496 }
1497 set configFakeServer [socket -server configFakeAccept -myaddr 127.0.0.1 0]
1498 set configFakePort [lindex [fconfigure $configFakeServer -sockname] 2]
1499
1500 proc configReply {verb area reply} {
1501 global configFakePort configFakeReply configFakeCount configFakeRequests
1502 set configFakeReply $reply
1503 set configFakeCount 0
@@ -1517,11 +1521,12 @@
1517 test_eq config-reply-asked [configSql rp.fossil "SELECT group_concat(name)
1518 FROM (SELECT name FROM config WHERE name IN ('header','adunit',
1519 'project-name') ORDER BY name)"] "adunit,header"
1520 test_eq config-reply-unasked-user [configSql rp.fossil "SELECT count(*) FROM
1521 user WHERE login='zed'"] 0
1522 test config-reply-request-skin {[string first "reqconfig /skin\nreqconfig /css\n" \
 
1523 [lindex $configFakeRequests 0]] >= 0}
1524 configReply pull css $configRpReply
1525 test_eq config-reply-css-only [configSql rp.fossil "SELECT count(*) FROM
1526 config WHERE name='project-name'"] 0
1527 # How many "reqconfig" cards the first request holds.
@@ -1539,11 +1544,11 @@
1539 configReply pull ticket ""
1540 test config-reply-request-ticket {[string first "reqconfig /ticket\n" \
1541 [lindex $configFakeRequests 0]] >= 0}
1542 configReply pull user "config /user 0\n\n"
1543 test config-reply-empty-card {$CODE == 0}
1544 close $configFakeServer
1545
1546 ###############################################################################
1547 # "fossil init --template" copies the settings of another repository,
1548 # those of every area and the aliases among them, and leaves out the names
1549 # of the project and any setting that belongs to no area.
1550
--- test/config.test
+++ test/config.test
@@ -6,15 +6,12 @@
6 # asks for. After each command the configuration of the area must be what
7 # the command is documented to leave, and the rest of the repository must
8 # be as it was.
9 #
10
11 # The first sections run at every level, and the rest need
12 # -assurance ci or stress.
 
 
 
13 require_no_open_checkout
14
15 test_setup ""
16 set configDir [pwd]
17 set ::env(FOSSIL_USER) tester
@@ -23,12 +20,11 @@
20 # Helpers.
21
22 # Run SQL in repository REPO and return its output without the final
23 # newline.
24 proc configSql {repo sql} {
25 return [fossil_sql $sql $repo]
 
26 }
27
28 # Make an empty repository FILE and give its settings a time long before
29 # any that the tests write, so that a test sees only what it set.
30 proc configNew {file} {
@@ -116,14 +112,21 @@
112
113 # A setting that is empty or absent has no time that a test can know: the
114 # repository makes a new "hash-policy" when it is opened. MASK hides its time.
115 # The SQL that lists what repository holds in the tables TABLES. With
116 # EXPORTED set, only the rows that an export sends: those with a time of
117 # last change, and the verified subscribers. A repository that has no
118 # SUBSCRIBER table has no subscribers: the statement then reads an empty
119 # table of that name in a database attached after the repository.
120 proc configTableSql {tables exported} {
121 set m [expr {$exported ? "WHERE mtime IS NOT NULL" : ""}]
122 set sql ""
123 if {"sub" in $tables} {
124 append sql "ATTACH ':memory:' AS nosub;
125 CREATE TABLE nosub.subscriber(semail, suname, sdigest, sdonotcall,
126 ssub, sctime, smip, mtime, sverified);"
127 }
128 foreach t $tables {
129 switch -- $t {
130 rpt {append sql "SELECT 'rpt', owner, title, mtime, quote(cols),
131 quote(sqlcode), quote(ifnull(jx,'{}')) FROM reportfmt $m ORDER BY title;"}
132 usr {append sql "SELECT 'usr', login, quote(pw), quote(cap),
@@ -149,19 +152,11 @@
152 global configTables
153 set t [expr {$mask ? "CASE WHEN name='hash-policy' THEN 0 ELSE mtime END"
154 : "mtime"}]
155 set sql "SELECT 'cfg', name, quote(value), $t FROM config
156 WHERE [configCond $area] ORDER BY name;"
157 append sql [configTableSql $configTables($area) $exported]
 
 
 
 
 
 
 
 
158 return [configSql $repo $sql]
159 }
160
161 # What REPO holds outside AREA, to see that a command left it alone.
162 proc configOutside {repo area} {
@@ -170,22 +165,14 @@
165 WHERE NOT [configCond $area] ORDER BY name;"
166 set tables {}
167 foreach t {rpt usr cnc shn sub} {
168 if {$t ni $configTables($area)} {lappend tables $t}
169 }
 
 
 
170 append sql [configTableSql $tables 0]
171 return [configSql $repo $sql]
172 }
173
 
 
 
 
 
174 # The kinds of card that an export file holds, in order and without
175 # repeats.
176 proc configKinds {file} {
177 set kinds {}
178 foreach line [split [read_file $file] \n] {
@@ -382,16 +369,22 @@
369 set configFile export-$configArea.cfg
370 configRun configuration export $configArea $configFile -R a.fossil
371 test config-export-$configArea {$CODE == 0 && $RESULT eq ""}
372 set configText [read_file $configFile]
373 test_match config-export-$configArea-header $configText \
374 [join [list \
375 "^# The \"$configArea\" configuration exported from\n" \
376 "# repository \"a.fossil\"\n# on \[0-9-\]+ \[0-9:\]+\n"] ""]
377 test_eq config-export-$configArea-cards [configKinds $configFile] \
378 [lsort $configKindsOf($configArea)]
379 }
380 test_eq config-export-changes-nothing [configSql a.fossil "SELECT 'c',name,mtime
381 FROM config ORDER BY name"] $configBefore
382
383 if {[test_assurance] eq "smoke"} {
384 test_skip "the tests after the first sections need -assurance ci or stress"
385 }
386
387 ###############################################################################
388 # Import: an area exported from one repository and imported into another
389 # makes the second hold what the first holds, in that area, with the times
390 # of last change. The tables of the area are replaced, so that a row that
@@ -445,12 +438,14 @@
438 set configExp [configState a.fossil $configArea 1]
439 test config-$configArea-has-content {$configExp ne ""}
440
441 configRun configuration import export-$configArea.cfg -R $configB
442 test config-import-$configArea {$CODE == 0 && $RESULT eq ""}
443 test_eq config-import-$configArea-same [configState $configB $configArea] \
444 $configExp
445 test_eq config-import-$configArea-outside \
446 [configOutside $configB $configArea] $configOut
447 if {$configArea eq "ticket" || $configArea eq "all"} {
448 # The ticket tables are rebuilt from the imported ticket-table.
449 test_eq config-import-$configArea-ticket-table [configSql $configB "SELECT
450 count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 1
451 }
@@ -462,37 +457,44 @@
457 set configOut [configOutside $configB $configArea]
458 configRun configuration reset $configArea -R $configB
459 test config-reset-$configArea {$CODE == 0 &&
460 [string first "Configuration reset to factory defaults." $RESULT] >= 0}
461 set configResetOut $RESULT
462 test_eq config-reset-$configArea-outside \
463 [configOutside $configB $configArea] $configOut
464 unset -nocomplain configBackup
465 regexp {import (config-backup-[0-9.]+)} $configResetOut -> configBackup
466 test config-reset-$configArea-backup {[info exists configBackup] &&
467 [file exists $configBackup]}
468 if {$configArea eq "user" || $configArea eq "all"} {
469 # The default users come back, and the user who ran the command is
470 # their administrator.
471 test_eq config-reset-$configArea-users \
472 [configSql $configB "SELECT login, cap, mtime
473 FROM user ORDER BY login"] \
474 "anonymous|hz|\ndeveloper|ei|\nnobody|gjorz|\nreader|kptw|\ntester|s|"
475 }
476 if {$configArea ni {alias interwiki all user}} {
477 test_eq config-reset-$configArea-state \
478 [configState $configB $configArea 0 1] \
479 [configDefaults $configArea]
480 }
481 if {$configArea eq "ticket" || $configArea eq "all"} {
482 test_eq config-reset-$configArea-ticket-table [configSql $configB "SELECT
483 count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 0
484 }
485 if {$configArea eq "subscriber" || $configArea eq "all"} {
486 test_eq config-reset-$configArea-subscribers \
487 [configSql $configB "SELECT count(*)
488 FROM subscriber"] 0
489 }
490 configRun configuration import $configBackup -R $configB
491 test config-reset-$configArea-recover {$CODE == 0}
492 test_eq config-reset-$configArea-recovered \
493 [configState $configB $configArea] $configPre
494 test_eq config-reset-$configArea-recovered-outside \
495 [configOutside $configB $configArea] \
496 $configOut
497 }
498
499
500 ###############################################################################
@@ -500,12 +502,13 @@
502
503 foreach configArea {alias interwiki} {
504 configNew r-$configArea.fossil
505 configFill r-$configArea.fossil
506 configRun configuration reset $configArea -R r-$configArea.fossil
507 test_eq config-reset-$configArea-removes \
508 [configState r-$configArea.fossil $configArea 0 1] \
509 [configDefaults $configArea]
510 }
511 configNew r-all.fossil
512 configFill r-all.fossil
513 configRun configuration reset all -R r-all.fossil
514 test config-reset-all-removes-aliases {[configSql r-all.fossil "SELECT count(*)
@@ -569,11 +572,12 @@
572
573 ###############################################################################
574 # Names of areas and methods: an abbreviation that starts the name is
575 # enough. An unknown area lists the areas and writes nothing.
576
577 foreach {configAbbrev configArea} \
578 {sk skin pro project t ticket u user e email sh shun
579 a alias al alias all all su subscriber i interwiki
580 x xfer c css} {
581 file delete abbrev.cfg
582 configRun configuration export $configAbbrev abbrev.cfg -R a.fossil
583 test config-area-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]}
@@ -584,14 +588,14 @@
588 }
589 file delete abbrev.cfg
590 foreach configBad {nosuch skinx ALL Skin} {
591 configRun configuration export $configBad abbrev.cfg -R a.fossil
592 test config-area-unknown-$configBad {$CODE == 1 &&
593 [holds_strings $RESULT [list \
594 "no such configuration area: \"$configBad\"" \
595 "Available configuration areas:" \
596 " skin Web interface appearance settings"]] &&
597 ![file exists abbrev.cfg]}
598 }
599 foreach configMethod {reset pull push sync} {
600 configRun configuration $configMethod nosuch -R a.fossil
601 test config-area-unknown-$configMethod {$CODE == 1 &&
@@ -600,14 +604,16 @@
604
605 # The methods accept abbreviations too.
606 foreach {configAbbrev configFull} {exp export e export ex export} {
607 file delete abbrev.cfg
608 configRun configuration $configAbbrev skin abbrev.cfg -R a.fossil
609 test config-method-abbrev-$configAbbrev \
610 {$CODE == 0 && [file exists abbrev.cfg]}
611 }
612 configNew m-abbrev.fossil
613 foreach {configAbbrev configTag} \
614 {i import im import imp import m merge me merge mer merge} {
615 configRun configuration $configAbbrev export-skin.cfg -R m-abbrev.fossil
616 test config-method-abbrev-$configAbbrev {$CODE == 0 &&
617 [configSql m-abbrev.fossil "SELECT value FROM config
618 WHERE name='css'"] eq "body { color: #123; }"}
619 fossil sql -R m-abbrev.fossil "DELETE FROM config WHERE name='css'"
@@ -635,18 +641,18 @@
641 pull-too-many {pull skin a b}
642 push-none {push}
643 sync-none {sync}
644 } {
645 configRun configuration {*}$configArgs -R a.fossil
646 test config-usage-$configNm \
647 {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
648 }
649 configRun configuration frobnicate -R a.fossil
650 test config-method-unknown {$CODE == 1 &&
651 [string first \
652 "METHOD should be one of: export import merge pull push reset"\
653 $RESULT] >= 0}
 
 
654 configRun configuration import nosuchfile.cfg -R a.fossil
655 test config-import-no-file {$CODE == 1}
656
657
658 ###############################################################################
@@ -691,11 +697,12 @@
697 test_eq config-merge-$name [configSql m.fossil $sql] $expected
698 }
699 configMergeCheck newer-local-kept "SELECT value FROM config WHERE name='css'" \
700 local-css
701 configMergeCheck older-local-replaced "SELECT value||'|'||mtime FROM config
702 WHERE name='header'" \
703 "<html>\n<head><title>It's \"quoted\"</title></head>\n|1700000001"
704 configMergeCheck equal-time-local-kept "SELECT value FROM config
705 WHERE name='mainmenu'" local-menu
706 configMergeCheck absent-added "SELECT value FROM config WHERE name='js'" \
707 "var a = 'b';"
708 configMergeCheck alias-newer-local-kept "SELECT value FROM config
@@ -746,29 +753,28 @@
753 test_eq config-merge-twice [configState m.fossil all] $configMerged
754
755 # Merge into an empty repository is import.
756 configNew m2.fossil
757 configRun configuration merge export-all.cfg -R m2.fossil
758 foreach configArea {skin project ticket xfer alias interwiki email shun
759 subscriber} {
760 test_eq config-merge-empty-$configArea [configState m2.fossil $configArea] \
761 [configState a.fossil $configArea 1]
762 }
763
764 # Import and merge write only inside one transaction: a file that stops the
765 # command leaves the repository as it was. A file with a card that SQLite
766 # cannot take (a repeated column) is such a file.
767 configNew t.fossil
768 configPut t.fossil {css {'kept'}} 1700000000
769 set configTxCard2 \
770 "1700000100 'alice' pw 'a' pw 'b' pw 'c' pw 'd' pw 'e' pw 'f' pw 'g'
 
771 pw 'h' pw 'i' pw 'j' pw 'k' pw 'l' pw 'm' pw 'n'"
772 write_file tx.cfg "[configCard config "1700000100 'css' value 'changed'"]\
773 [configCard user $configTxCard2]"
774 configRun configuration merge tx.cfg -R t.fossil
775 set configTxCode $CODE
 
776 test config-card-many-fields {$configTxCode == 0 || $configTxCode == 1}
777 fossil test-integrity -R t.fossil
778 test config-card-many-fields-integrity {$CODE == 0}
779
780 ###############################################################################
@@ -817,11 +823,12 @@
823 string-lone {'}
824 null-prefix {NULLx}
825 not-null {NUL}
826 } {
827 fossil sql -R l.fossil "DELETE FROM config WHERE name='header'"
828 write_file lit.cfg [configCard config \
829 "1700000000 'header' value $configValue"]
830 configRun configuration merge lit.cfg -R l.fossil
831 test config-literal-refused-$configNm {$CODE == 0 &&
832 [configSql l.fossil "SELECT count(*) FROM config
833 WHERE name='header'"] == 0}
834 }
@@ -833,45 +840,40 @@
840 # if it were not there. Nothing is written that the card did not name.
841
842 # Everything that REPO holds, settings and tables, except the two settings
843 # that a server of the repository writes for its own use.
844 proc configDump {repo} {
 
845 set sql "SELECT 'cfg', name, quote(value), mtime FROM config
846 WHERE name<>'backoffice' AND name NOT GLOB 'baseurl:*'
847 ORDER BY name;"
848 append sql [configTableSql {rpt usr cnc shn sub} 0]
 
 
849 return [configSql $repo $sql]
850 }
851
852 configNew c.fossil
853 configPut c.fossil {css {'old'} js {'old'}} 1700000000
854 set configStart [configDump c.fossil]
855 set configGood [configCard config "1700000500 'footer' value 'good'"]
 
856
857 # Run import and merge of TEXT into a copy of c.fossil. Both must leave
858 # the repository as it was, except that the card "footer" at the end of the
859 # file, when GOOD is true, is read.
860 proc configMalformed {name text good {code 0}} {
861 global configGood configStart
862 foreach method {merge import} {
863 set repo c-$method.fossil
864 file copy -force c.fossil $repo
 
865 write_file bad.cfg [expr {$good ? "$text$configGood" : $text}]
866 configRun configuration $method bad.cfg -R $repo
 
867 test config-malformed-$name-$method-exit {$::CODE == $code}
868 if {$good} {
869 set want [configSql $repo "SELECT value FROM config WHERE name='footer';
870 DELETE FROM config WHERE name='footer'"]
871 test_eq config-malformed-$name-$method-next-card $want good
 
 
872 }
873 test_eq config-malformed-$name-$method-unchanged [configDump $repo] \
874 $configStart
875 }
876 }
877 set configBody "1700000600 'css' value 'new'\n"
878 set configLen [string length $configBody]
879
@@ -889,16 +891,19 @@
891 configMalformed negative-size "config /config -5\n$configBody\n" 1
892 configMalformed size-letters "config /config 12ab\n$configBody\n" 1
893 configMalformed size-plus "config /config +$configLen\n$configBody\n" 1
894 configMalformed size-hex "config /config 0x10\n$configBody\n" 1
895 configMalformed size-float "config /config 1.5\n$configBody\n" 1
896 configMalformed size-too-big-for-int \
897 "config /config 99999999999\n$configBody\n" 1
898 configMalformed size-extra-token \
899 "config /config $configLen extra\n$configBody\n" 1
900 configMalformed size-zero "config /config 0\n\n" 1
901 configMalformed size-short "config /config 10\n$configBody\n" 1
902 configMalformed truncated-key "config /config 40\n1700000600 'cs" 0
903 configMalformed truncated-literal \
904 "config /config 40\n1700000600 'css' value 'ne\n" 0
905 foreach {configNm configCardBody} {
906 missing-mtime "'css' value 'x'\n"
907 bare-name "1700000600 css value 'x'\n"
908 name-only "1700000600\n"
909 empty-card "\n"
@@ -906,14 +911,16 @@
911 zero-byte-time "\0001700000600 'css' value 'x'\n"
912 zero-byte-name "1700000600 \000'css' value 'x'\n"
913 } {
914 configMalformed $configNm [configCard config $configCardBody] 1
915 }
916 foreach {configNm configMtime} \
917 {letters abc fraction 1.5 negative -5 hex 0x10 blank-sign +5
918 exponent 1e3 quoted '5'} {
919 set configCardBody "$configMtime 'css' value 'new'\n"
920 configMalformed mtime-$configNm \
921 "config /config [string length $configCardBody]\n$configCardBody\n" 1
922 }
923
924 # A size that is larger than the rest of the file takes the rest.
925 foreach configMethod {merge import} {
926 file copy -force c.fossil c-$configMethod.fossil
@@ -927,25 +934,28 @@
934 # A field that is not a column of the table is skipped; one that would
935 # set a column that nothing outside may set is among them.
936 configNew k.fossil
937 fossil sql -R k.fossil "INSERT INTO user(login,pw,cap,mtime)
938 VALUES('carol','pw','o',5)"
939 set configCardBody \
940 "1700000600 'carol' cap 'oj' cookie 'stolen' ipaddr '1.2.3.4'\
941 cexpire 1 uid 77 login 'mallory' bogus 'x' info 'Carol'\n"
942 write_file fields.cfg [configCard user $configCardBody]
943 configRun configuration merge fields.cfg -R k.fossil
944 test config-field-skipped {$CODE == 0}
945 test_eq config-field-skipped-row [configSql k.fossil "SELECT login, cap, info,
946 quote(cookie), quote(ipaddr), quote(cexpire), mtime FROM user
947 WHERE login IN ('carol','mallory')"] \
948 "carol|oj|Carol|NULL|NULL|NULL|1700000600"
949 test_eq config-field-skipped-uid [configSql k.fossil "SELECT count(*) FROM user
950 WHERE uid=77"] 0
951
952 # A card that holds more field pairs than the command keeps is read up to
953 # the eleventh field, and the later ones are dropped.
954 set configCardBody "1700000600 'carol'"
955 for {set configI 0} {$configI < 14} {incr configI} \
956 {append configCardBody " info 'v$configI'"}
957 write_file many.cfg [configCard user "$configCardBody\n"]
958 configRun configuration merge many.cfg -R k.fossil
959 test config-fields-many {$CODE == 0 &&
960 [configSql k.fossil "SELECT info FROM user WHERE login='carol'"] eq "Carol"}
961 fossil sql -R k.fossil "UPDATE user SET mtime=5 WHERE login='carol'"
@@ -973,12 +983,10 @@
983 # identity of the repository and its schema), and those that carry commands
984 # and are never exported.
985
986 configNew n.fossil
987 set configNBefore [configDump n.fossil]
 
 
988 foreach configNm {project-code server-code content-schema aux-schema rebuilt
989 th1-setup tcl-setup email-send-command diff-command editor
990 ssh-command nosuch head headers Header walias:docs interwiki
991 ticket_table} {
992 set configCardBody "1700000600 '$configNm' value 'x'\n"
@@ -988,12 +996,10 @@
996 [string first "Skipping non-exportable setting: '$configNm' = 'x'" \
997 $RESULT] >= 0}
998 test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \
999 $configNBefore
1000 }
 
 
1001 foreach {configNm configCardBody} {
1002 number "1700000600 12 value 'x'\n"
1003 empty "1700000600 '' value 'x'\n"
1004 blob "1700000600 x'6373' value 'x'\n"
1005 null "1700000600 NULL value 'x'\n"
@@ -1062,24 +1068,27 @@
1068 set configOut [configOutside $configC $configArea]
1069 set configPre [configDump $configC]
1070 configRun configuration pull $configArea $configSrv -R $configC
1071 test config-pull-$configArea {$CODE == 0}
1072 test config-pull-$configArea-changed {[configDump $configC] ne $configPre}
1073 test_eq config-pull-$configArea-outside [configOutside $configC $configArea] \
1074 $configOut
1075 configSameAs config-pull-$configArea-same $configC $configArea a.fossil
1076 fossil test-integrity -R $configC
1077 test config-pull-$configArea-integrity {$CODE == 0}
1078
1079 # Push.
1080 set configD srv-push-$configArea.fossil
1081 configNew $configD
1082 set configOut [configOutside $configD $configArea]
1083 set configPre [configDump $configD]
1084 configRun configuration push $configArea [file join $configDir $configD] \
1085 -R a.fossil
1086 test config-push-$configArea {$CODE == 0}
1087 test config-push-$configArea-changed {[configDump $configD] ne $configPre}
1088 test_eq config-push-$configArea-outside [configOutside $configD $configArea] \
1089 $configOut
1090 configSameAs config-push-$configArea-same $configD $configArea a.fossil
1091 fossil test-integrity -R $configD
1092 test config-push-$configArea-integrity {$CODE == 0}
1093 }
1094
@@ -1104,29 +1113,38 @@
1113 test config-sync {$CODE == 0}
1114 set configAliasSql "SELECT name,value,mtime FROM config
1115 WHERE name GLOB 'walias:/*' ORDER BY name"
1116 # A value with the same time on both sides stays as each side has it.
1117 test_eq config-sync-same [configSql s1.fossil $configAliasSql] \
1118 [join [list \
1119 "walias:/both|new-2|1700000200\n" \
1120 "walias:/only1|one|1700000000\nwalias:/only2|two|1700000000\n" \
1121 "walias:/tie|tie-1|1700000300"] ""]
1122 test_eq config-sync-same-other [configSql s2.fossil $configAliasSql] \
1123 [join [list \
1124 "walias:/both|new-2|1700000200\n" \
1125 "walias:/only1|one|1700000000\nwalias:/only2|two|1700000000\n" \
1126 "walias:/tie|tie-2|1700000300"] ""]
1127
1128 # Pull with --overwrite replaces the tables of the area, so a user that only
1129 # this side has is gone; without it the user stays.
1130 configNew o1.fossil
1131 configNew o2.fossil
1132 fossil sql -R o1.fossil \
1133 "INSERT INTO user(login,cap,mtime) VALUES('local','o',7)"
1134 fossil sql -R o2.fossil \
1135 "INSERT INTO user(login,cap,mtime) VALUES('remote','o',8)"
1136 fossil sql -R o1.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x1',7,'l')"
1137 fossil sql -R o2.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x2',8,'r')"
1138 configRun configuration pull shun [file join $configDir o2.fossil] -R o1.fossil
1139 test_eq config-pull-keeps-rows [configSql o1.fossil "SELECT group_concat(uuid)
1140 FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x1,x2"
1141 configRun configuration pull shun --overwrite [file join $configDir o2.fossil] \
1142 -R o1.fossil
1143 test config-pull-overwrite {$CODE == 0}
1144 test_eq config-pull-overwrite-shun \
1145 [configSql o1.fossil "SELECT group_concat(uuid)
1146 FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x2"
1147 configRun configuration pull user --overwrite [file join $configDir o2.fossil] \
1148 -R o1.fossil
1149 test config-pull-overwrite-user {$CODE == 0 && [configSql o1.fossil "SELECT
1150 group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] ne ""}
@@ -1155,16 +1173,18 @@
1173 fossil remote file://[file join $configDir a.fossil] -R u1.fossil
1174 configRun configuration pull skin -R u1.fossil
1175 test config-pull-default-server {$CODE == 0 &&
1176 [configSql u1.fossil "SELECT value FROM config WHERE name='css'"] eq
1177 "body { color: #123; }"}
1178 configRun configuration pull project --proxy off \
1179 [file join $configDir a.fossil] \
1180 -R u1.fossil
1181 test config-pull-proxy-off {$CODE == 0 &&
1182 [configSql u1.fossil "SELECT value FROM config
1183 WHERE name='project-name'"] eq "Alpha"}
1184 configRun configuration pull skin [file join $configDir nosuch.fossil] \
1185 -R u1.fossil
1186 test config-pull-no-such-repository {$CODE == 1}
1187
1188
1189 ###############################################################################################################################################
1190 # The configuration that a server sends on request: an area it does not know
@@ -1173,13 +1193,13 @@
1193 configNew sv.fossil
1194 configPut sv.fossil {css {'hello'} header {'h'}} 1700000000
1195 write_file req.txt "$CLIENT_VERSION_CARD\
1196 reqconfig /nosuch\nreqconfig /css\nreqconfig css\nreqconfig /nosuch2\n"
1197 fossil_raw test-xfer -R sv.fossil req.txt
1198 test config-request {$CODE == 0 && [regexp -all {config /config } $RESULT] == 1
1199 &&
1200 [holds_strings $RESULT {"'css' value 'hello'" !'header' "errors 0"}]}
1201
1202 ###############################################################################
1203 # A repository whose user and ticket report tables do not have the column
1204 # for JSON data exports them without it, and takes the cards that have no
1205 # such field.
@@ -1213,11 +1233,12 @@
1233 write_file in.txt "from a file\nwith two lines\n"
1234 fossil test-var-set beta --file in.txt -R v.fossil
1235 fossil test-var-get beta -R v.fossil
1236 test_eq config-var-set-file $RESULT "from a file\nwith two lines"
1237 fossil test-var-get beta out2.txt -R v.fossil
1238 test_eq config-var-set-file-exact [read_file out2.txt] \
1239 "from a file\nwith two lines\n"
1240 set configBlob "\x00\x01\xff\xfe\x80binary"
1241 write_file blob.bin $configBlob
1242 fossil test-var-set gamma --blob blob.bin -R v.fossil
1243 fossil test-var-get gamma out3.bin -R v.fossil
1244 test_eq config-var-set-blob [read_file out3.bin] $configBlob
@@ -1228,24 +1249,25 @@
1249 test_eq config-var-set-stdin-value [configSql v.fossil "SELECT length(value)
1250 FROM config WHERE name='delta'"] 9
1251 fossil_raw test-var-set -R v.fossil
1252 test config-var-set-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1253 fossil_raw test-var-set epsilon -R v.fossil
1254 test config-var-set-no-value \
1255 {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1256 fossil_raw test-var-set epsilon --file in.txt --blob blob.bin -R v.fossil
1257 test config-var-set-both {$CODE == 1 &&
1258 [string first "cannot do both" $RESULT] >= 0}
1259 fossil_raw test-var-set epsilon --file nosuch.txt -R v.fossil
1260 test config-var-set-no-file {$CODE == 1}
1261 test_eq config-var-set-none-made [configSql v.fossil "SELECT count(*) FROM
1262 config WHERE name='epsilon'"] 0
1263 fossil_raw test-var-get nosuch -R v.fossil
1264 test config-var-get-none {$CODE == 1 && [string first "no match for" $RESULT] >=
1265 0}
1266 fossil_raw test-var-get {[abg]*} -R v.fossil
1267 test config-var-get-many {$CODE == 1 &&
1268 [holds_strings $RESULT {"multiple matches:" 'alpha' 'beta'}]}
 
1269 fossil_raw test-var-get -R v.fossil
1270 test config-var-get-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0}
1271 fossil test-var-get {alph?} -R v.fossil
1272 test_eq config-var-get-glob $RESULT hello
1273
@@ -1273,11 +1295,12 @@
1295 proc configListLine {name value pad} {
1296 return "$name:[string repeat { } [expr {$pad - [string length $name]}]]$value"
1297 }
1298 configRun test-var-list -R w.fossil
1299 set configList $RESULT
1300 test config-var-list-short \
1301 {[string first "[configListLine a-short plain 27]\n" \
1302 $configList] >= 0}
1303 test config-var-list-escapes {[string first \
1304 "[configListLine a-ctl {x\n\r\t\001y} 27]\n" $configList] >= 0}
1305 test config-var-list-long-value {[string first \
1306 "[configListLine a-long [string range $configLongValue 0 39]...+20 27]\n" \
@@ -1405,11 +1428,12 @@
1428 configShareProject $configC
1429 set configPre [configDump $configC]
1430 configNetRun pull $configArea $configC $configPort $configUser
1431 test config-pull-$configLabel-$configArea {$CODE == 0}
1432 foreach configPart [configParts $configArea] {
1433 configHasPart config-pull-$configLabel-$configArea-has $configC \
1434 $configPart \
1435 [configMayPull $configUser $configPart]
1436 }
1437 if {$configUser ne "blind" && $configLabel ne "nobody"} {
1438 test config-pull-$configLabel-$configArea-changed \
1439 {[configDump $configC] ne $configPre}
@@ -1452,31 +1476,12 @@
1476 # Cards that a server sends for configuration that was not asked for are
1477 # dropped by the client, those it asked for are kept. A server made here
1478 # answers the first request with a prepared reply and every later one with a
1479 # bare timestamp.
1480
1481 proc configFakeRead {chan request} {
 
 
 
 
 
 
 
 
 
 
1482 set end [string first "\r\n\r\n" $request]
 
 
 
 
 
 
 
 
 
1483 # The request is the text of the cards, after four bytes of size when it
1484 # is compressed.
1485 set body [string range $request [expr {$end+4}] end]
1486 if {[regexp -nocase {content-type:\s*application/x-fossil\s} $request]} {
1487 set body [zlib decompress [string range $body 4 end]]
@@ -1492,12 +1497,11 @@
1497 application/x-fossil-uncompressed\r\nContent-Length:\
1498 [string length $reply]\r\n\r\n$reply"
1499 close $chan
1500 }
1501 }
1502 set configFakePort [test_listen configFakeRead]
 
1503
1504 proc configReply {verb area reply} {
1505 global configFakePort configFakeReply configFakeCount configFakeRequests
1506 set configFakeReply $reply
1507 set configFakeCount 0
@@ -1517,11 +1521,12 @@
1521 test_eq config-reply-asked [configSql rp.fossil "SELECT group_concat(name)
1522 FROM (SELECT name FROM config WHERE name IN ('header','adunit',
1523 'project-name') ORDER BY name)"] "adunit,header"
1524 test_eq config-reply-unasked-user [configSql rp.fossil "SELECT count(*) FROM
1525 user WHERE login='zed'"] 0
1526 test config-reply-request-skin \
1527 {[string first "reqconfig /skin\nreqconfig /css\n" \
1528 [lindex $configFakeRequests 0]] >= 0}
1529 configReply pull css $configRpReply
1530 test_eq config-reply-css-only [configSql rp.fossil "SELECT count(*) FROM
1531 config WHERE name='project-name'"] 0
1532 # How many "reqconfig" cards the first request holds.
@@ -1539,11 +1544,11 @@
1544 configReply pull ticket ""
1545 test config-reply-request-ticket {[string first "reqconfig /ticket\n" \
1546 [lindex $configFakeRequests 0]] >= 0}
1547 configReply pull user "config /user 0\n\n"
1548 test config-reply-empty-card {$CODE == 0}
1549 test_listen_stop
1550
1551 ###############################################################################
1552 # "fossil init --template" copies the settings of another repository,
1553 # those of every area and the aliases among them, and leaves out the names
1554 # of the project and any setting that belongs to no area.
1555
+164 -181
--- test/content.test
+++ test/content.test
@@ -6,39 +6,18 @@
66
#
77
# integrity.test damages a repository and requires the damage to be
88
# found. This file covers what is left.
99
#
1010
11
-# These tests run only in a long pass: -assurance stress.
12
-if {[test_assurance] ne "stress"} {
13
- test_skip "runs only with -assurance stress"
14
-}
15
-
1611
require_no_open_checkout
1712
1813
test_setup
1914
20
-# The answer of one SQL statement, trimmed.
21
-#
22
-proc content_sql {sql} {
23
- global RESULT
24
- fossil sql $sql
25
- return [string trim $RESULT]
26
-}
27
-
2815
# The record number of the artifact with the given hash.
2916
#
3017
proc content_rid {hash} {
31
- return [content_sql "SELECT rid FROM blob WHERE uuid='$hash'"]
32
-}
33
-
34
-# The hash that Fossil gives the content of a file.
35
-#
36
-proc content_hash {filename} {
37
- global RESULT
38
- fossil sha3sum $filename
39
- return [lindex $RESULT 0]
18
+ return [fossil_sql "SELECT rid FROM blob WHERE uuid='$hash'"]
4019
}
4120
4221
# Write a file that holds the cards $body and the Z card for them.
4322
#
4423
proc content_artifact {filename body} {
@@ -67,20 +46,20 @@
6746
write_file long.txt $contentText
6847
if {$contentI == 1} {fossil add long.txt}
6948
fossil commit -m "content-v$contentI" --no-warnings
7049
lappend contentVersions $contentText
7150
}
72
-set contentFirst [content_sql "SELECT uuid FROM blob, mlink, event
51
+set contentFirst [fossil_sql "SELECT uuid FROM blob, mlink, event
7352
WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
7453
AND event.comment='content-v1'"]
75
-set contentLast [content_sql "SELECT uuid FROM blob, mlink, event
54
+set contentLast [fossil_sql "SELECT uuid FROM blob, mlink, event
7655
WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
7756
AND event.comment='content-v30'"]
7857
test content-setup {$contentFirst ne "" && $contentLast ne ""}
7958
8059
proc content_chain {rid} {
81
- return [content_sql "WITH RECURSIVE c(rid,n) AS (SELECT $rid, 0
60
+ return [fossil_sql "WITH RECURSIVE c(rid,n) AS (SELECT $rid, 0
8261
UNION ALL SELECT srcid, n+1 FROM delta, c WHERE delta.rid=c.rid)
8362
SELECT max(n) FROM c"]
8463
}
8564
test_eq content-chain-length [content_chain [content_rid $contentFirst]] 29
8665
@@ -110,11 +89,11 @@
11089
fossil test-content-rawget -expectError
11190
test content-rawget-usage {$CODE != 0}
11291
11392
fossil test-content-undelta $contentRid
11493
test content-undelta {$CODE == 0}
115
-test_eq content-undelta-no-delta-row [content_sql \
94
+test_eq content-undelta-no-delta-row [fossil_sql \
11695
"SELECT count(*) FROM delta WHERE rid=$contentRid"] 0
11796
fossil test-content-rawget $contentFirst raw.out
11897
test_eq content-undelta-stored-whole [read_file raw.out] \
11998
[lindex $contentVersions 0]
12099
fossil test-content-undelta $contentRid
@@ -123,36 +102,36 @@
123102
test content-undelta-usage {$CODE != 0}
124103
125104
###############################################################################
126105
# Turning content into a delta.
127106
128
-set contentSecond [content_sql "SELECT blob.rid FROM blob, mlink, event
107
+set contentSecond [fossil_sql "SELECT blob.rid FROM blob, mlink, event
129108
WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
130109
AND event.comment='content-v2'"]
131
-set contentThird [content_sql "SELECT blob.rid FROM blob, mlink, event
110
+set contentThird [fossil_sql "SELECT blob.rid FROM blob, mlink, event
132111
WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
133112
AND event.comment='content-v3'"]
134113
set contentLastRid [content_rid $contentLast]
135114
136115
# The artifact itself and an artifact that is a delta from it are not
137116
# used as sources. Of the two that remain, one is taken.
138117
fossil test-content-deltify $contentRid $contentRid $contentLastRid \
139118
$contentSecond
140119
test content-deltify {$CODE == 0}
141
-test content-deltify-source {[content_sql "SELECT srcid FROM delta
120
+test content-deltify-source {[fossil_sql "SELECT srcid FROM delta
142121
WHERE rid=$contentRid"] in [list $contentLastRid $contentSecond]}
143122
fossil artifact $contentFirst first.out
144123
test_eq content-deltify-same-content [read_file first.out] \
145124
[lindex $contentVersions 0]
146125
147126
# Already a delta: left alone without --force, done again with it.
148
-set contentSrc [content_sql "SELECT srcid FROM delta WHERE rid=$contentRid"]
127
+set contentSrc [fossil_sql "SELECT srcid FROM delta WHERE rid=$contentRid"]
149128
fossil test-content-deltify $contentRid $contentThird
150
-test_eq content-deltify-not-forced [content_sql "SELECT srcid FROM delta
129
+test_eq content-deltify-not-forced [fossil_sql "SELECT srcid FROM delta
151130
WHERE rid=$contentRid"] $contentSrc
152131
fossil test-content-deltify --force $contentRid $contentThird
153
-test_eq content-deltify-forced [content_sql "SELECT srcid FROM delta
132
+test_eq content-deltify-forced [fossil_sql "SELECT srcid FROM delta
154133
WHERE rid=$contentRid"] $contentThird
155134
fossil artifact $contentFirst first.out
156135
test_eq content-deltify-forced-same-content [read_file first.out] \
157136
[lindex $contentVersions 0]
158137
@@ -168,38 +147,38 @@
168147
# Content of less than 50 bytes is never made a delta, nor used as the
169148
# source of one.
170149
write_file small.txt "small\n"
171150
write_file small2.txt "small too\n"
172151
fossil test-content-put small.txt small2.txt
173
-set contentSmall [content_rid [content_hash small.txt]]
174
-set contentSmall2 [content_rid [content_hash small2.txt]]
152
+set contentSmall [content_rid [sha3_file small.txt]]
153
+set contentSmall2 [content_rid [sha3_file small2.txt]]
175154
fossil test-content-deltify $contentSmall $contentSmall2
176
-test_eq content-deltify-small [content_sql "SELECT count(*) FROM delta
155
+test_eq content-deltify-small [fossil_sql "SELECT count(*) FROM delta
177156
WHERE rid=$contentSmall"] 0
178157
fossil test-content-undelta $contentRid
179158
fossil test-content-deltify $contentRid $contentSmall
180
-test_eq content-deltify-small-source [content_sql "SELECT count(*) FROM delta
159
+test_eq content-deltify-small-source [fossil_sql "SELECT count(*) FROM delta
181160
WHERE rid=$contentRid"] 0
182161
183162
# Unrelated content is not worth a delta.
184163
write_file other.txt [string repeat "nothing in common with the file\n" 40]
185164
fossil test-content-put other.txt
186
-fossil test-content-deltify $contentRid [content_rid [content_hash other.txt]]
187
-test_eq content-deltify-unrelated [content_sql "SELECT count(*) FROM delta
165
+fossil test-content-deltify $contentRid [content_rid [sha3_file other.txt]]
166
+test_eq content-deltify-unrelated [fossil_sql "SELECT count(*) FROM delta
188167
WHERE rid=$contentRid"] 0
189168
190169
# Public content is not made a delta from private content.
191170
write_file private.txt "${contentText}and one private line\n"
192171
fossil test-content-put private.txt
193
-set contentPrivate [content_rid [content_hash private.txt]]
172
+set contentPrivate [content_rid [sha3_file private.txt]]
194173
fossil sql "INSERT INTO private(rid) VALUES($contentPrivate)"
195174
fossil test-content-deltify $contentRid $contentPrivate
196
-test_eq content-deltify-private-source [content_sql "SELECT count(*) FROM delta
175
+test_eq content-deltify-private-source [fossil_sql "SELECT count(*) FROM delta
197176
WHERE rid=$contentRid"] 0
198177
fossil sql "DELETE FROM private WHERE rid=$contentPrivate"
199178
fossil test-content-deltify $contentRid $contentPrivate
200
-test_eq content-deltify-once-public [content_sql "SELECT srcid FROM delta
179
+test_eq content-deltify-once-public [fossil_sql "SELECT srcid FROM delta
201180
WHERE rid=$contentRid"] $contentPrivate
202181
fossil test-content-undelta $contentRid
203182
204183
# Of two sources that both make a worthwhile delta, the one that makes
205184
# the smaller is taken, whichever comes first.
@@ -210,31 +189,31 @@
210189
write_file two-target.txt $contentBase
211190
write_file two-near.txt "${contentBase}one more line\n"
212191
write_file two-far.txt "[string range $contentBase 0 1500][string repeat \
213192
"a line that the target does not have\n" 30]"
214193
fossil test-content-put two-target.txt two-near.txt two-far.txt
215
-set contentTarget [content_rid [content_hash two-target.txt]]
216
-set contentNear [content_rid [content_hash two-near.txt]]
217
-set contentFar [content_rid [content_hash two-far.txt]]
194
+set contentTarget [content_rid [sha3_file two-target.txt]]
195
+set contentNear [content_rid [sha3_file two-near.txt]]
196
+set contentFar [content_rid [sha3_file two-far.txt]]
218197
fossil test-content-deltify $contentTarget $contentFar $contentNear
219
-test_eq content-deltify-better-source-last [content_sql "SELECT srcid
198
+test_eq content-deltify-better-source-last [fossil_sql "SELECT srcid
220199
FROM delta WHERE rid=$contentTarget"] $contentNear
221200
fossil test-content-undelta $contentTarget
222201
fossil test-content-deltify $contentTarget $contentNear $contentFar
223
-test_eq content-deltify-better-source-first [content_sql "SELECT srcid
202
+test_eq content-deltify-better-source-first [fossil_sql "SELECT srcid
224203
FROM delta WHERE rid=$contentTarget"] $contentNear
225204
fossil test-content-undelta $contentTarget
226205
fossil test-content-deltify $contentTarget $contentFar
227
-test_eq content-deltify-far-source-alone [content_sql "SELECT srcid
206
+test_eq content-deltify-far-source-alone [fossil_sql "SELECT srcid
228207
FROM delta WHERE rid=$contentTarget"] $contentFar
229208
fossil test-content-undelta $contentTarget
230209
231210
# Private content may be a delta from private content.
232211
fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentPrivate)"
233212
fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentRid)"
234213
fossil test-content-deltify $contentRid $contentPrivate
235
-test_eq content-deltify-private-from-private [content_sql "SELECT srcid
214
+test_eq content-deltify-private-from-private [fossil_sql "SELECT srcid
236215
FROM delta WHERE rid=$contentRid"] $contentPrivate
237216
fossil test-content-undelta $contentRid
238217
fossil sql "DELETE FROM private WHERE rid IN ($contentPrivate,$contentRid)"
239218
240219
fossil test-content-deltify -expectError
@@ -247,33 +226,33 @@
247226
# test-content-put with --moderate.
248227
249228
write_file moderated.txt "content awaiting moderation\n"
250229
fossil test-content-put --moderate moderated.txt
251230
test content-put-moderate {$CODE == 0}
252
-test_eq content-put-moderate-row [content_sql "SELECT count(*) FROM modreq
253
- WHERE objid=[content_rid [content_hash moderated.txt]]"] 1
231
+test_eq content-put-moderate-row [fossil_sql "SELECT count(*) FROM modreq
232
+ WHERE objid=[content_rid [sha3_file moderated.txt]]"] 1
254233
255234
###############################################################################
256235
# Content that arrives after it was asked for. A check-in names a file
257236
# that is not in the repository; when the file is stored, the check-in
258237
# has it. A delta manifest is stored before its baseline; when the
259238
# baseline arrives, the delta manifest becomes a check-in.
260239
261240
write_file late.txt "this file arrives late\n"
262
-set contentLate [content_hash late.txt]
241
+set contentLate [sha3_file late.txt]
263242
content_artifact ci-late.txt "C content-late
264243
D 2026-03-01T10:00:00.000
265244
F late.txt $contentLate
266245
U alice
267246
"
268247
fossil test-content-put --crosslink ci-late.txt
269
-test_eq content-phantom-made [content_sql "SELECT size FROM blob
248
+test_eq content-phantom-made [fossil_sql "SELECT size FROM blob
270249
WHERE uuid='$contentLate'"] -1
271250
fossil artifact $contentLate
272251
test content-phantom-has-no-content {$CODE == 0 && $RESULT eq ""}
273252
fossil test-content-put late.txt
274
-test_eq content-phantom-filled [content_sql "SELECT size FROM blob
253
+test_eq content-phantom-filled [fossil_sql "SELECT size FROM blob
275254
WHERE uuid='$contentLate'"] [file size late.txt]
276255
fossil artifact $contentLate late.out
277256
test content-phantom-filled-content {[same_file late.txt late.out]}
278257
279258
content_artifact ci-base.txt "C content-base
@@ -280,29 +259,29 @@
280259
D 2026-03-02T10:00:00.000
281260
F a.txt $contentLate
282261
F b.txt $contentLate
283262
U alice
284263
"
285
-set contentBase [content_hash ci-base.txt]
264
+set contentBase [sha3_file ci-base.txt]
286265
content_artifact ci-delta.txt "B $contentBase
287266
C content-delta
288267
D 2026-03-02T11:00:00.000
289268
F b.txt
290269
F c.txt $contentLate
291270
P $contentBase
292271
U alice
293272
"
294273
fossil test-content-put --crosslink ci-delta.txt
295
-test_eq content-orphan-not-a-checkin [content_sql "SELECT count(*) FROM event
274
+test_eq content-orphan-not-a-checkin [fossil_sql "SELECT count(*) FROM event
296275
WHERE comment='content-delta'"] 0
297
-test_eq content-orphan-recorded [content_sql "SELECT count(*) FROM orphan"] 1
276
+test_eq content-orphan-recorded [fossil_sql "SELECT count(*) FROM orphan"] 1
298277
fossil test-content-put --crosslink ci-base.txt
299278
test content-orphan-baseline-arrives {$CODE == 0}
300
-test_eq content-orphan-now-a-checkin [content_sql "SELECT count(*) FROM event
279
+test_eq content-orphan-now-a-checkin [fossil_sql "SELECT count(*) FROM event
301280
WHERE comment IN ('content-delta','content-base')"] 2
302
-test_eq content-orphan-cleared [content_sql "SELECT count(*) FROM orphan"] 0
303
-fossil ls -r [content_hash ci-delta.txt]
281
+test_eq content-orphan-cleared [fossil_sql "SELECT count(*) FROM orphan"] 0
282
+fossil ls -r [sha3_file ci-delta.txt]
304283
test_eq content-orphan-files [normalize_result] "a.txt\nc.txt"
305284
306285
###############################################################################
307286
# test-integrity: the options that check the database only, and --parse
308287
# on content that looks like an artifact and is not one.
@@ -319,45 +298,47 @@
319298
write_file looks5.txt "D 2026-03-03T10:00:00.000\nno newline at the end"
320299
# Content that does not begin with a card at all, content whose first line
321300
# holds a zero byte, and content whose first line is very long.
322301
write_file looks6.txt "1 begins with a digit, which no card does\n"
323302
write_file looks7.txt "AB has no space after its first letter\n"
324
-write_file looks8.txt "C a first line\x00with a zero byte in it\nand a second line\n"
303
+write_file looks8.txt \
304
+ "C a first line\x00with a zero byte in it\nand a second line\n"
325305
write_file looks9.txt "C [string repeat x 500]\nand a second line\n"
326306
# Content that is the first line of a signed message and nothing more,
327307
# with no end of line.
328308
write_file looks10.txt "-----BEGIN PGP SIGNED MESSAGE-----"
329309
fossil test-content-put looks1.txt looks2.txt looks3.txt looks4.txt looks5.txt \
330310
looks6.txt looks7.txt looks8.txt looks9.txt looks10.txt
331
-set contentLooks10 [content_hash looks10.txt]
311
+set contentLooks10 [sha3_file looks10.txt]
332312
fossil test-integrity --parse
333313
test content-integrity-parse {$CODE == 0}
334314
test content-integrity-parse-counts \
335
- {[regexp {(\d+) control artifacts failed to parse} $RESULT all n] && $n == 6}
315
+ {[regexp {(\d+) control artifacts failed to parse} $RESULT all n] && $n ==
316
+ 6}
336317
test content-integrity-parse-one-line-signed \
337318
{[string first "manifest_parse failed for $contentLooks10:" $RESULT] >= 0}
338319
test content-integrity-parse-first-line \
339320
{[string first "\"C this looks like a card\"" $RESULT] >= 0}
340321
341322
# The same content is an error once the repository has it down as a
342323
# wiki page.
343324
fossil sql "INSERT INTO event(type,mtime,objid,user,comment)
344
- VALUES('w',2461000.5,[content_rid [content_hash looks1.txt]],'alice','+x')"
325
+ VALUES('w',2461000.5,[content_rid [sha3_file looks1.txt]],'alice','+x')"
345326
fossil test-integrity --parse -expectError
346327
test content-integrity-parse-listed-artifact {$CODE != 0}
347328
fossil sql "DELETE FROM event
348
- WHERE objid=[content_rid [content_hash looks1.txt]]"
329
+ WHERE objid=[content_rid [sha3_file looks1.txt]]"
349330
350331
###############################################################################
351332
# test-orphans lists content that nothing refers to.
352333
353334
fossil test-orphans
354335
test content-orphans {$CODE == 0}
355336
test content-orphans-count \
356337
{[regexp {(\d+) orphans} $RESULT all n] && $n >= 9}
357338
test content-orphans-lists-one \
358
- {[string first [content_hash other.txt] $RESULT] >= 0}
339
+ {[string first [sha3_file other.txt] $RESULT] >= 0}
359340
360341
###############################################################################
361342
# test-missing reports each kind of reference to content that is not
362343
# there.
363344
@@ -368,32 +349,52 @@
368349
fossil test-missing --quiet
369350
test_eq content-missing-none-quiet [string trim $RESULT] ""
370351
371352
set contentGone [string repeat 0123456789 4]
372353
set contentGone2 [string repeat 9876543210 4]
373
-set contentCi [content_sql "SELECT uuid FROM blob, event
354
+set contentCi [fossil_sql "SELECT uuid FROM blob, event
374355
WHERE rid=objid AND comment='content-v30'"]
375
-foreach {contentName contentBody contentWant} [list \
376
- file "C content-missing-file\nD 2026-03-04T10:00:00.000\nF gone.txt $contentGone\nU alice\n" \
356
+foreach {contentName contentCount contentBody contentWant} [list \
357
+ file 1 \
358
+ [join [list \
359
+ "C content-missing-file\nD 2026-03-04T10:00:00.000\n" \
360
+ "F gone.txt $contentGone\nU alice\n"] ""] \
377361
"MISSING: $contentGone\n*file of check-in *\n*gone.txt" \
378
- parent "D 2026-03-04T11:00:00.000\nL Missing\\sparent\nP $contentGone\nU alice\nW 1\nx\n" \
362
+ parent 2 \
363
+ [join [list \
364
+ "D 2026-03-04T11:00:00.000\nL Missing\\sparent\n" \
365
+ "P $contentGone\nU alice\nW 1\nx\n"] ""] \
379366
"MISSING: $contentGone\n*parent of wiki *" \
380
- cherrypick "C content-missing-pick\nD 2026-03-04T12:00:00.000\nP $contentCi\nQ +$contentGone $contentGone2\nU alice\n" \
381
- "MISSING: $contentGone\n*cherry-pick target of check-in *MISSING: $contentGone2\n*cherry-pick baseline of check-in *" \
382
- technote "D 2026-03-04T12:30:00.000\nE 2026-03-04T09:00:00 [string repeat ab 20]\nP $contentGone\nU alice\nW 1\nx\n" \
367
+ cherrypick 4 \
368
+ [join [list \
369
+ "C content-missing-pick\nD 2026-03-04T12:00:00.000\n" \
370
+ "P $contentCi\nQ +$contentGone $contentGone2\nU alice\n"] ""] \
371
+ [join [list \
372
+ "MISSING: $contentGone\n" \
373
+ "*cherry-pick target of check-in *MISSING: $contentGone2\n" \
374
+ "*cherry-pick baseline of check-in *"] ""] \
375
+ technote 5 \
376
+ [join [list \
377
+ "D 2026-03-04T12:30:00.000\n" \
378
+ "E 2026-03-04T09:00:00 [string repeat ab 20]\nP $contentGone\n" \
379
+ "U alice\nW 1\nx\n"] ""] \
383380
"MISSING: $contentGone\n*parent of event *" \
384
- tag "D 2026-03-04T13:00:00.000\nT +sym-missing $contentGone\nU alice\n" \
381
+ tag 6 "D 2026-03-04T13:00:00.000\nT +sym-missing $contentGone\nU alice\n" \
385382
"MISSING: $contentGone\n*target of tag *" \
386
- attachment "A f.txt Missing\\sparent $contentGone\nD 2026-03-04T14:00:00.000\nU alice\n" \
383
+ attachment 7 \
384
+ [join [list \
385
+ "A f.txt Missing\\sparent $contentGone\n" \
386
+ "D 2026-03-04T14:00:00.000\nU alice\n"] ""] \
387387
"MISSING: $contentGone\n*file of attachment *" \
388
- cluster "M $contentGone\nM $contentGone2\n" \
388
+ cluster 9 "M $contentGone\nM $contentGone2\n" \
389389
"MISSING: $contentGone\n*in cluster *" \
390390
] {
391391
content_artifact missing-$contentName.txt $contentBody
392392
fossil test-content-put --crosslink missing-$contentName.txt
393393
fossil test-missing -expectError
394
- test content-missing-$contentName {$CODE != 0}
394
+ test content-missing-$contentName {$CODE != 0 && [string match \
395
+ "*\n$contentCount missing or shunned references *" $RESULT]}
395396
test content-missing-$contentName-text \
396397
{[string match "*$contentWant*" $RESULT]}
397398
}
398399
# An attachment that takes a file away names none, and is not counted.
399400
content_artifact missing-detach.txt \
@@ -408,13 +409,12 @@
408409
# A missing artifact that is shunned is reported as shunned, or not at
409410
# all with --notshunned.
410411
fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$contentGone',0),
411412
('$contentGone2',0)"
412413
fossil test-missing -expectError
413
-test content-missing-shunned \
414
- {$CODE != 0 && [string first "SHUNNED: $contentGone" $RESULT] >= 0
415
- && [string first MISSING $RESULT] < 0}
414
+test content-missing-shunned {$CODE != 0 &&
415
+ [holds_strings $RESULT [list "SHUNNED: $contentGone" !MISSING]]}
416416
fossil test-missing --notshunned
417417
test content-missing-notshunned {$CODE == 0}
418418
test_match content-missing-notshunned-text $RESULT \
419419
{^0 missing or shunned references}
420420
fossil sql "DELETE FROM shun"
@@ -423,29 +423,29 @@
423423
# test-content-erase asks first. Erasing content that others are deltas
424424
# from stores those whole.
425425
426426
fossil test-content-undelta $contentRid
427427
fossil test-content-deltify --force $contentThird $contentRid
428
-test_eq content-erase-setup [content_sql "SELECT count(*) FROM delta
428
+test_eq content-erase-setup [fossil_sql "SELECT count(*) FROM delta
429429
WHERE srcid=$contentRid"] 1
430430
fossil_raw -input "n\n" test-content-erase $contentRid
431
-test_eq content-erase-declined [content_sql "SELECT count(*) FROM blob
431
+test_eq content-erase-declined [fossil_sql "SELECT count(*) FROM blob
432432
WHERE rid=$contentRid"] 1
433433
fossil_raw -input "Y\n" test-content-erase $contentRid
434434
test content-erase {$CODE == 0}
435
-test_eq content-erase-gone [content_sql "SELECT count(*) FROM blob
435
+test_eq content-erase-gone [fossil_sql "SELECT count(*) FROM blob
436436
WHERE rid=$contentRid"] 0
437
-test_eq content-erase-no-delta-left [content_sql "SELECT count(*) FROM delta
437
+test_eq content-erase-no-delta-left [fossil_sql "SELECT count(*) FROM delta
438438
WHERE srcid=$contentRid OR rid=$contentRid"] 0
439
-fossil artifact [content_sql "SELECT uuid FROM blob WHERE rid=$contentThird"] \
439
+fossil artifact [fossil_sql "SELECT uuid FROM blob WHERE rid=$contentThird"] \
440440
third.out
441441
test_eq content-erase-dependent-still-whole [read_file third.out] \
442442
[lindex $contentVersions 2]
443443
444444
# The answer may be in either case.
445445
fossil_raw -input "y\n" test-content-erase $contentSmall
446
-test_eq content-erase-lower-case-answer [content_sql "SELECT count(*) FROM blob
446
+test_eq content-erase-lower-case-answer [fossil_sql "SELECT count(*) FROM blob
447447
WHERE rid=$contentSmall"] 0
448448
449449
###############################################################################
450450
# A "parent" tag on a private check-in is itself private, and so is the
451451
# placeholder for a parent that the repository does not have.
@@ -454,22 +454,22 @@
454454
D 2026-03-05T10:00:00.000
455455
F late.txt $contentLate
456456
U alice
457457
"
458458
fossil test-content-put --crosslink ci-private.txt
459
-set contentPriv [content_hash ci-private.txt]
459
+set contentPriv [sha3_file ci-private.txt]
460460
fossil sql "INSERT INTO private(rid) VALUES([content_rid $contentPriv])"
461461
set contentAbsent [string repeat 4d 20]
462462
fossil tag add --raw parent $contentPriv $contentAbsent
463463
test content-private-placeholder-tag {$CODE == 0}
464
-test_eq content-private-placeholder [content_sql "SELECT count(*)
464
+test_eq content-private-placeholder [fossil_sql "SELECT count(*)
465465
FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentAbsent'
466466
AND size<0"] 1
467
-test_eq content-private-placeholder-not-unclustered [content_sql "SELECT count(*)
467
+test_eq content-private-placeholder-not-unclustered [fossil_sql "SELECT count(*)
468468
FROM unclustered, blob WHERE unclustered.rid=blob.rid
469469
AND uuid='$contentAbsent'"] 0
470
-test_eq content-private-placeholder-is-parent [content_sql "SELECT count(*)
470
+test_eq content-private-placeholder-is-parent [fossil_sql "SELECT count(*)
471471
FROM plink WHERE cid=[content_rid $contentPriv]
472472
AND pid=[content_rid $contentAbsent]"] 1
473473
474474
###############################################################################
475475
# Content that arrives in a sync message, sent to the server side through
@@ -490,15 +490,10 @@
490490
}
491491
proc content_x {sql} {
492492
fossil sql -R x.fossil $sql
493493
return [string trim $::RESULT]
494494
}
495
-proc content_sha1 {text} {
496
- write_file sha1-me.txt $text
497
- fossil sha1sum sha1-me.txt
498
- return [lindex $::RESULT 0]
499
-}
500495
proc content_sha3 {text} {
501496
write_file sha3-me.txt $text
502497
fossil sha3sum sha3-me.txt
503498
return [lindex $::RESULT 0]
504499
}
@@ -515,16 +510,17 @@
515510
global contentYcode CLIENT_VERSION_CARD
516511
write_file msg.txt "${CLIENT_VERSION_CARD}push x $contentYcode\n$body"
517512
fossil_raw test-xfer -R y.fossil msg.txt
518513
}
519514
set contentA "an artifact with a SHA1 name\n"
520
-content_push_y "file [content_sha1 $contentA] [string length $contentA]\n$contentA"
515
+content_push_y "file [sha1_text $contentA] [string length $contentA]\n$contentA"
521516
test content-policy-sha1-name-accepted {$CODE == 0}
522517
fossil hash-policy -R y.fossil
523518
test_eq content-policy-still-auto [string trim $RESULT] auto
524519
set contentB "an artifact with a SHA3 name\n"
525
-content_push_y "file [content_sha3 $contentB] [string length $contentB]\n$contentB"
520
+content_push_y \
521
+ "file [content_sha3 $contentB] [string length $contentB]\n$contentB"
526522
fossil hash-policy -R y.fossil
527523
test_eq content-policy-now-sha3 [string trim $RESULT] sha3
528524
529525
# An artifact that the server has only heard of is a phantom. It is
530526
# filled when its content arrives as a compressed delta from content the
@@ -554,11 +550,12 @@
554550
555551
# A phantom that is filled by a private card becomes private.
556552
set contentP "content that arrives marked private\n"
557553
set contentPHash [content_sha3 $contentP]
558554
content_push "igot $contentPHash\n"
559
-content_push "private\nfile $contentPHash [string length $contentP]\n$contentP" \
555
+content_push \
556
+ "private\nfile $contentPHash [string length $contentP]\n$contentP" \
560557
"login tester 0 0\n"
561558
test content-sync-private-fill {$CODE == 0}
562559
test_eq content-sync-private-fill-marked [content_x "SELECT count(*)
563560
FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentPHash'
564561
AND size>=0"] 1
@@ -612,93 +609,79 @@
612609
fossil test-integrity -R x.fossil
613610
test content-sync-integrity {$CODE == 0}
614611
615612
###############################################################################
616613
# The cache of reconstructed artifacts keeps every eighth artifact along a
617
-# delta chain and drops the oldest entry once it holds more than 2,000.
618
-# A chain of 18,000 deltas is stored and read back in one process, so the
619
-# cache fills and entries are dropped while the chain is read; each version
620
-# read afterwards, through dropped and kept entries, must still be right.
621
-
622
-fossil new cache.fossil
623
-fossil sql -R cache.fossil {
624
- CREATE TEMP TABLE v(k INTEGER PRIMARY KEY, t BLOB);
625
- WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<17999)
626
- INSERT INTO v SELECT k, CAST(printf('common text%.100c version %d', '.', k)
627
- AS BLOB) FROM c;
628
- INSERT INTO blob(rid,rcvid,size,uuid,content)
629
- SELECT 100000+k, 0, length(t), printf('%064d', k),
630
- compress(CASE WHEN k=0 THEN t
631
- ELSE delta_create((SELECT t FROM v p WHERE p.k=v.k-1), t) END)
632
- FROM v;
633
- INSERT INTO delta(rid,srcid) SELECT 100000+k, 100000+k-1 FROM v WHERE k>0;
634
- SELECT content('rid:117999')=(SELECT t FROM v WHERE k=17999);
635
- SELECT count(*) FROM v WHERE k%997=0 AND content('rid:'||(100000+k))=t;
636
-}
637
-test content-cache-expire {$CODE == 0}
638
-test_eq content-cache-expire-reads [string trim $RESULT] "1\n19"
639
-
640
-# The cache also drops its oldest entries while it holds more than 256 MB,
641
-# as many as it takes. Each version here is a longer prefix of one random
642
-# text, up to 18 MB, so the oldest entries are the smallest and dropping
643
-# one is not always enough.
644
-
645
-fossil new cache-size.fossil
646
-fossil sql -R cache-size.fossil {
647
- CREATE TEMP TABLE r(x BLOB);
648
- INSERT INTO r VALUES(hex(randomblob(9000000)));
649
- CREATE TEMP TABLE n(k INTEGER PRIMARY KEY);
650
- WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<299)
651
- INSERT INTO n SELECT k FROM c;
652
- INSERT INTO blob(rid,rcvid,size,uuid,content)
653
- SELECT 200000+k, 0, (k+1)*60000, printf('%064d', k),
654
- compress(CASE WHEN k=0 THEN substr((SELECT x FROM r), 1, 60000)
655
- ELSE delta_create(substr((SELECT x FROM r), 1, k*60000),
656
- substr((SELECT x FROM r), 1, (k+1)*60000))
657
- END)
658
- FROM n;
659
- INSERT INTO delta(rid,srcid) SELECT 200000+k, 200000+k-1 FROM n WHERE k>0;
660
- SELECT content('rid:200299')
661
- =CAST(substr((SELECT x FROM r), 1, 300*60000) AS BLOB);
662
- SELECT count(*) FROM n WHERE k%37=0 AND content('rid:'||(200000+k))
663
- =CAST(substr((SELECT x FROM r), 1, (k+1)*60000) AS BLOB);
664
-}
665
-test content-cache-size {$CODE == 0}
666
-test_eq content-cache-size-reads [string trim $RESULT] "1\n9"
667
-file delete cache-size.fossil
668
-
669
-# When the oldest entry is an artifact of no bytes, dropping it frees
670
-# nothing and the cache stays over 256 MB for one more entry. Version 7
671
-# of this chain is empty and every other version is the same 30 MB; each
672
-# version read afterwards must still be right.
673
-
674
-fossil new cache-empty.fossil
675
-fossil sql -R cache-empty.fossil {
676
- CREATE TEMP TABLE r(x BLOB);
677
- INSERT INTO r VALUES(CAST(hex(randomblob(15000000)) AS BLOB));
678
- CREATE TEMP TABLE d(same BLOB, toempty BLOB, fromempty BLOB);
679
- INSERT INTO d SELECT delta_create(x, x), delta_create(x, x''),
680
- delta_create(x'', x) FROM r;
681
- CREATE TEMP TABLE n(k INTEGER PRIMARY KEY);
682
- WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<88)
683
- INSERT INTO n SELECT k FROM c;
684
- INSERT INTO blob(rid,rcvid,size,uuid,content)
685
- SELECT 300000+k, 0, CASE WHEN k=7 THEN 0 ELSE 30000000 END,
686
- printf('%064d', k),
687
- compress(CASE WHEN k=0 THEN (SELECT x FROM r)
688
- WHEN k=7 THEN (SELECT toempty FROM d)
689
- WHEN k=8 THEN (SELECT fromempty FROM d)
690
- ELSE (SELECT same FROM d) END)
691
- FROM n;
692
- INSERT INTO delta(rid,srcid) SELECT 300000+k, 300000+k-1 FROM n WHERE k>0;
693
- SELECT content('rid:300088')=(SELECT x FROM r);
694
- SELECT length(content('rid:300007'));
695
- SELECT count(*) FROM n WHERE k IN (6,8,15,50,87)
696
- AND content('rid:'||(300000+k))=(SELECT x FROM r);
697
-}
698
-test content-cache-empty-oldest {$CODE == 0}
699
-test_eq content-cache-empty-oldest-reads [string trim $RESULT] "1\n0\n5"
700
-file delete cache-empty.fossil
614
+# delta chain. It drops its oldest entry once it holds more than 2,000
615
+# entries, and its oldest entries, as many as it takes, while it holds
616
+# more than 256 MB. Both limits are constants in content.c, so a test
617
+# has to store enough to exceed them. If Fossil gets a setting for the
618
+# size of this cache, set it far lower here, at least for -assurance
619
+# smoke, and run these tests at every level.
620
+
621
+if {[test_assurance] eq "smoke"} {
622
+ test_skip_part "the content cache limits need -assurance ci or stress"
623
+} else {
624
+ # A chain of 18,000 deltas is stored and read back in one process, so
625
+ # the cache holds more than 2,000 entries and drops the oldest while
626
+ # the chain is read; each version read afterwards, through dropped and
627
+ # kept entries, must still be right.
628
+ fossil new cache.fossil
629
+ fossil sql -R cache.fossil {
630
+ CREATE TEMP TABLE v(k INTEGER PRIMARY KEY, t BLOB);
631
+ WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<17999)
632
+ INSERT INTO v SELECT k, CAST(printf('common text%.100c version %d', '.', k)
633
+ AS BLOB) FROM c;
634
+ INSERT INTO blob(rid,rcvid,size,uuid,content)
635
+ SELECT 100000+k, 0, length(t), printf('%064d', k),
636
+ compress(CASE WHEN k=0 THEN t
637
+ ELSE delta_create((SELECT t FROM v p WHERE p.k=v.k-1), t)
638
+ END)
639
+ FROM v;
640
+ INSERT INTO delta(rid,srcid) SELECT 100000+k, 100000+k-1 FROM v WHERE k>0;
641
+ SELECT content('rid:117999')=(SELECT t FROM v WHERE k=17999);
642
+ SELECT count(*) FROM v WHERE k%997=0 AND content('rid:'||(100000+k))=t;
643
+ }
644
+ test content-cache-expire {$CODE == 0}
645
+ test_eq content-cache-expire-reads [string trim $RESULT] "1\n19"
646
+
647
+ # A chain of 104 versions takes the cache over 256 MB. Only every
648
+ # eighth version is cached, so those are 30 MB each and the versions
649
+ # between them are a few bytes, which makes the chain quick to store
650
+ # and to read. The two oldest cached versions are small (version 7)
651
+ # and empty (version 15). When the cache first exceeds the limit,
652
+ # dropping version 7 is not enough, and dropping version 15 frees
653
+ # nothing, which leaves the cache over the limit. The next entry
654
+ # drops two 30 MB versions. Each version read afterwards must still
655
+ # be right.
656
+ fossil new cache-size.fossil
657
+ fossil sql -R cache-size.fossil {
658
+ CREATE TEMP TABLE c(kind INTEGER PRIMARY KEY, t BLOB);
659
+ INSERT INTO c VALUES(0, CAST('a small version' AS BLOB)),
660
+ (1, zeroblob(30000000)), (2, x'');
661
+ CREATE TEMP TABLE d(src, dst, z BLOB, PRIMARY KEY(src, dst));
662
+ INSERT INTO d SELECT a.kind, b.kind, compress(delta_create(a.t, b.t))
663
+ FROM c a, c b WHERE a.kind=0 OR b.kind=0;
664
+ CREATE TEMP TABLE n(k INTEGER PRIMARY KEY, kind);
665
+ WITH RECURSIVE s(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM s WHERE k<103)
666
+ INSERT INTO n SELECT k, CASE WHEN k=15 THEN 2 WHEN k%8=7 AND k>15 THEN 1
667
+ ELSE 0 END FROM s;
668
+ INSERT INTO blob(rid,rcvid,size,uuid,content)
669
+ SELECT 200000+k, 0, (SELECT length(t) FROM c WHERE c.kind=n.kind),
670
+ printf('%064d', k),
671
+ CASE WHEN k=0 THEN (SELECT compress(t) FROM c WHERE c.kind=n.kind)
672
+ ELSE (SELECT z FROM d WHERE dst=n.kind
673
+ AND src=(SELECT kind FROM n p WHERE p.k=n.k-1)) END
674
+ FROM n;
675
+ INSERT INTO delta(rid,srcid) SELECT 200000+k, 200000+k-1 FROM n WHERE k>0;
676
+ SELECT content('rid:200103')=(SELECT t FROM c WHERE kind=1);
677
+ SELECT length(content('rid:200015'));
678
+ SELECT count(*) FROM n WHERE k IN (0,7,14,16,23,31,39,95,102,103)
679
+ AND content('rid:'||(200000+k))=(SELECT t FROM c WHERE c.kind=n.kind);
680
+ }
681
+ test content-cache-size {$CODE == 0}
682
+ test_eq content-cache-size-reads [string trim $RESULT] "1\n0\n10"
683
+}
701684
702685
###############################################################################
703686
704687
test_cleanup
705688
--- test/content.test
+++ test/content.test
@@ -6,39 +6,18 @@
6 #
7 # integrity.test damages a repository and requires the damage to be
8 # found. This file covers what is left.
9 #
10
11 # These tests run only in a long pass: -assurance stress.
12 if {[test_assurance] ne "stress"} {
13 test_skip "runs only with -assurance stress"
14 }
15
16 require_no_open_checkout
17
18 test_setup
19
20 # The answer of one SQL statement, trimmed.
21 #
22 proc content_sql {sql} {
23 global RESULT
24 fossil sql $sql
25 return [string trim $RESULT]
26 }
27
28 # The record number of the artifact with the given hash.
29 #
30 proc content_rid {hash} {
31 return [content_sql "SELECT rid FROM blob WHERE uuid='$hash'"]
32 }
33
34 # The hash that Fossil gives the content of a file.
35 #
36 proc content_hash {filename} {
37 global RESULT
38 fossil sha3sum $filename
39 return [lindex $RESULT 0]
40 }
41
42 # Write a file that holds the cards $body and the Z card for them.
43 #
44 proc content_artifact {filename body} {
@@ -67,20 +46,20 @@
67 write_file long.txt $contentText
68 if {$contentI == 1} {fossil add long.txt}
69 fossil commit -m "content-v$contentI" --no-warnings
70 lappend contentVersions $contentText
71 }
72 set contentFirst [content_sql "SELECT uuid FROM blob, mlink, event
73 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
74 AND event.comment='content-v1'"]
75 set contentLast [content_sql "SELECT uuid FROM blob, mlink, event
76 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
77 AND event.comment='content-v30'"]
78 test content-setup {$contentFirst ne "" && $contentLast ne ""}
79
80 proc content_chain {rid} {
81 return [content_sql "WITH RECURSIVE c(rid,n) AS (SELECT $rid, 0
82 UNION ALL SELECT srcid, n+1 FROM delta, c WHERE delta.rid=c.rid)
83 SELECT max(n) FROM c"]
84 }
85 test_eq content-chain-length [content_chain [content_rid $contentFirst]] 29
86
@@ -110,11 +89,11 @@
110 fossil test-content-rawget -expectError
111 test content-rawget-usage {$CODE != 0}
112
113 fossil test-content-undelta $contentRid
114 test content-undelta {$CODE == 0}
115 test_eq content-undelta-no-delta-row [content_sql \
116 "SELECT count(*) FROM delta WHERE rid=$contentRid"] 0
117 fossil test-content-rawget $contentFirst raw.out
118 test_eq content-undelta-stored-whole [read_file raw.out] \
119 [lindex $contentVersions 0]
120 fossil test-content-undelta $contentRid
@@ -123,36 +102,36 @@
123 test content-undelta-usage {$CODE != 0}
124
125 ###############################################################################
126 # Turning content into a delta.
127
128 set contentSecond [content_sql "SELECT blob.rid FROM blob, mlink, event
129 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
130 AND event.comment='content-v2'"]
131 set contentThird [content_sql "SELECT blob.rid FROM blob, mlink, event
132 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
133 AND event.comment='content-v3'"]
134 set contentLastRid [content_rid $contentLast]
135
136 # The artifact itself and an artifact that is a delta from it are not
137 # used as sources. Of the two that remain, one is taken.
138 fossil test-content-deltify $contentRid $contentRid $contentLastRid \
139 $contentSecond
140 test content-deltify {$CODE == 0}
141 test content-deltify-source {[content_sql "SELECT srcid FROM delta
142 WHERE rid=$contentRid"] in [list $contentLastRid $contentSecond]}
143 fossil artifact $contentFirst first.out
144 test_eq content-deltify-same-content [read_file first.out] \
145 [lindex $contentVersions 0]
146
147 # Already a delta: left alone without --force, done again with it.
148 set contentSrc [content_sql "SELECT srcid FROM delta WHERE rid=$contentRid"]
149 fossil test-content-deltify $contentRid $contentThird
150 test_eq content-deltify-not-forced [content_sql "SELECT srcid FROM delta
151 WHERE rid=$contentRid"] $contentSrc
152 fossil test-content-deltify --force $contentRid $contentThird
153 test_eq content-deltify-forced [content_sql "SELECT srcid FROM delta
154 WHERE rid=$contentRid"] $contentThird
155 fossil artifact $contentFirst first.out
156 test_eq content-deltify-forced-same-content [read_file first.out] \
157 [lindex $contentVersions 0]
158
@@ -168,38 +147,38 @@
168 # Content of less than 50 bytes is never made a delta, nor used as the
169 # source of one.
170 write_file small.txt "small\n"
171 write_file small2.txt "small too\n"
172 fossil test-content-put small.txt small2.txt
173 set contentSmall [content_rid [content_hash small.txt]]
174 set contentSmall2 [content_rid [content_hash small2.txt]]
175 fossil test-content-deltify $contentSmall $contentSmall2
176 test_eq content-deltify-small [content_sql "SELECT count(*) FROM delta
177 WHERE rid=$contentSmall"] 0
178 fossil test-content-undelta $contentRid
179 fossil test-content-deltify $contentRid $contentSmall
180 test_eq content-deltify-small-source [content_sql "SELECT count(*) FROM delta
181 WHERE rid=$contentRid"] 0
182
183 # Unrelated content is not worth a delta.
184 write_file other.txt [string repeat "nothing in common with the file\n" 40]
185 fossil test-content-put other.txt
186 fossil test-content-deltify $contentRid [content_rid [content_hash other.txt]]
187 test_eq content-deltify-unrelated [content_sql "SELECT count(*) FROM delta
188 WHERE rid=$contentRid"] 0
189
190 # Public content is not made a delta from private content.
191 write_file private.txt "${contentText}and one private line\n"
192 fossil test-content-put private.txt
193 set contentPrivate [content_rid [content_hash private.txt]]
194 fossil sql "INSERT INTO private(rid) VALUES($contentPrivate)"
195 fossil test-content-deltify $contentRid $contentPrivate
196 test_eq content-deltify-private-source [content_sql "SELECT count(*) FROM delta
197 WHERE rid=$contentRid"] 0
198 fossil sql "DELETE FROM private WHERE rid=$contentPrivate"
199 fossil test-content-deltify $contentRid $contentPrivate
200 test_eq content-deltify-once-public [content_sql "SELECT srcid FROM delta
201 WHERE rid=$contentRid"] $contentPrivate
202 fossil test-content-undelta $contentRid
203
204 # Of two sources that both make a worthwhile delta, the one that makes
205 # the smaller is taken, whichever comes first.
@@ -210,31 +189,31 @@
210 write_file two-target.txt $contentBase
211 write_file two-near.txt "${contentBase}one more line\n"
212 write_file two-far.txt "[string range $contentBase 0 1500][string repeat \
213 "a line that the target does not have\n" 30]"
214 fossil test-content-put two-target.txt two-near.txt two-far.txt
215 set contentTarget [content_rid [content_hash two-target.txt]]
216 set contentNear [content_rid [content_hash two-near.txt]]
217 set contentFar [content_rid [content_hash two-far.txt]]
218 fossil test-content-deltify $contentTarget $contentFar $contentNear
219 test_eq content-deltify-better-source-last [content_sql "SELECT srcid
220 FROM delta WHERE rid=$contentTarget"] $contentNear
221 fossil test-content-undelta $contentTarget
222 fossil test-content-deltify $contentTarget $contentNear $contentFar
223 test_eq content-deltify-better-source-first [content_sql "SELECT srcid
224 FROM delta WHERE rid=$contentTarget"] $contentNear
225 fossil test-content-undelta $contentTarget
226 fossil test-content-deltify $contentTarget $contentFar
227 test_eq content-deltify-far-source-alone [content_sql "SELECT srcid
228 FROM delta WHERE rid=$contentTarget"] $contentFar
229 fossil test-content-undelta $contentTarget
230
231 # Private content may be a delta from private content.
232 fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentPrivate)"
233 fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentRid)"
234 fossil test-content-deltify $contentRid $contentPrivate
235 test_eq content-deltify-private-from-private [content_sql "SELECT srcid
236 FROM delta WHERE rid=$contentRid"] $contentPrivate
237 fossil test-content-undelta $contentRid
238 fossil sql "DELETE FROM private WHERE rid IN ($contentPrivate,$contentRid)"
239
240 fossil test-content-deltify -expectError
@@ -247,33 +226,33 @@
247 # test-content-put with --moderate.
248
249 write_file moderated.txt "content awaiting moderation\n"
250 fossil test-content-put --moderate moderated.txt
251 test content-put-moderate {$CODE == 0}
252 test_eq content-put-moderate-row [content_sql "SELECT count(*) FROM modreq
253 WHERE objid=[content_rid [content_hash moderated.txt]]"] 1
254
255 ###############################################################################
256 # Content that arrives after it was asked for. A check-in names a file
257 # that is not in the repository; when the file is stored, the check-in
258 # has it. A delta manifest is stored before its baseline; when the
259 # baseline arrives, the delta manifest becomes a check-in.
260
261 write_file late.txt "this file arrives late\n"
262 set contentLate [content_hash late.txt]
263 content_artifact ci-late.txt "C content-late
264 D 2026-03-01T10:00:00.000
265 F late.txt $contentLate
266 U alice
267 "
268 fossil test-content-put --crosslink ci-late.txt
269 test_eq content-phantom-made [content_sql "SELECT size FROM blob
270 WHERE uuid='$contentLate'"] -1
271 fossil artifact $contentLate
272 test content-phantom-has-no-content {$CODE == 0 && $RESULT eq ""}
273 fossil test-content-put late.txt
274 test_eq content-phantom-filled [content_sql "SELECT size FROM blob
275 WHERE uuid='$contentLate'"] [file size late.txt]
276 fossil artifact $contentLate late.out
277 test content-phantom-filled-content {[same_file late.txt late.out]}
278
279 content_artifact ci-base.txt "C content-base
@@ -280,29 +259,29 @@
280 D 2026-03-02T10:00:00.000
281 F a.txt $contentLate
282 F b.txt $contentLate
283 U alice
284 "
285 set contentBase [content_hash ci-base.txt]
286 content_artifact ci-delta.txt "B $contentBase
287 C content-delta
288 D 2026-03-02T11:00:00.000
289 F b.txt
290 F c.txt $contentLate
291 P $contentBase
292 U alice
293 "
294 fossil test-content-put --crosslink ci-delta.txt
295 test_eq content-orphan-not-a-checkin [content_sql "SELECT count(*) FROM event
296 WHERE comment='content-delta'"] 0
297 test_eq content-orphan-recorded [content_sql "SELECT count(*) FROM orphan"] 1
298 fossil test-content-put --crosslink ci-base.txt
299 test content-orphan-baseline-arrives {$CODE == 0}
300 test_eq content-orphan-now-a-checkin [content_sql "SELECT count(*) FROM event
301 WHERE comment IN ('content-delta','content-base')"] 2
302 test_eq content-orphan-cleared [content_sql "SELECT count(*) FROM orphan"] 0
303 fossil ls -r [content_hash ci-delta.txt]
304 test_eq content-orphan-files [normalize_result] "a.txt\nc.txt"
305
306 ###############################################################################
307 # test-integrity: the options that check the database only, and --parse
308 # on content that looks like an artifact and is not one.
@@ -319,45 +298,47 @@
319 write_file looks5.txt "D 2026-03-03T10:00:00.000\nno newline at the end"
320 # Content that does not begin with a card at all, content whose first line
321 # holds a zero byte, and content whose first line is very long.
322 write_file looks6.txt "1 begins with a digit, which no card does\n"
323 write_file looks7.txt "AB has no space after its first letter\n"
324 write_file looks8.txt "C a first line\x00with a zero byte in it\nand a second line\n"
 
325 write_file looks9.txt "C [string repeat x 500]\nand a second line\n"
326 # Content that is the first line of a signed message and nothing more,
327 # with no end of line.
328 write_file looks10.txt "-----BEGIN PGP SIGNED MESSAGE-----"
329 fossil test-content-put looks1.txt looks2.txt looks3.txt looks4.txt looks5.txt \
330 looks6.txt looks7.txt looks8.txt looks9.txt looks10.txt
331 set contentLooks10 [content_hash looks10.txt]
332 fossil test-integrity --parse
333 test content-integrity-parse {$CODE == 0}
334 test content-integrity-parse-counts \
335 {[regexp {(\d+) control artifacts failed to parse} $RESULT all n] && $n == 6}
 
336 test content-integrity-parse-one-line-signed \
337 {[string first "manifest_parse failed for $contentLooks10:" $RESULT] >= 0}
338 test content-integrity-parse-first-line \
339 {[string first "\"C this looks like a card\"" $RESULT] >= 0}
340
341 # The same content is an error once the repository has it down as a
342 # wiki page.
343 fossil sql "INSERT INTO event(type,mtime,objid,user,comment)
344 VALUES('w',2461000.5,[content_rid [content_hash looks1.txt]],'alice','+x')"
345 fossil test-integrity --parse -expectError
346 test content-integrity-parse-listed-artifact {$CODE != 0}
347 fossil sql "DELETE FROM event
348 WHERE objid=[content_rid [content_hash looks1.txt]]"
349
350 ###############################################################################
351 # test-orphans lists content that nothing refers to.
352
353 fossil test-orphans
354 test content-orphans {$CODE == 0}
355 test content-orphans-count \
356 {[regexp {(\d+) orphans} $RESULT all n] && $n >= 9}
357 test content-orphans-lists-one \
358 {[string first [content_hash other.txt] $RESULT] >= 0}
359
360 ###############################################################################
361 # test-missing reports each kind of reference to content that is not
362 # there.
363
@@ -368,32 +349,52 @@
368 fossil test-missing --quiet
369 test_eq content-missing-none-quiet [string trim $RESULT] ""
370
371 set contentGone [string repeat 0123456789 4]
372 set contentGone2 [string repeat 9876543210 4]
373 set contentCi [content_sql "SELECT uuid FROM blob, event
374 WHERE rid=objid AND comment='content-v30'"]
375 foreach {contentName contentBody contentWant} [list \
376 file "C content-missing-file\nD 2026-03-04T10:00:00.000\nF gone.txt $contentGone\nU alice\n" \
 
 
 
377 "MISSING: $contentGone\n*file of check-in *\n*gone.txt" \
378 parent "D 2026-03-04T11:00:00.000\nL Missing\\sparent\nP $contentGone\nU alice\nW 1\nx\n" \
 
 
 
379 "MISSING: $contentGone\n*parent of wiki *" \
380 cherrypick "C content-missing-pick\nD 2026-03-04T12:00:00.000\nP $contentCi\nQ +$contentGone $contentGone2\nU alice\n" \
381 "MISSING: $contentGone\n*cherry-pick target of check-in *MISSING: $contentGone2\n*cherry-pick baseline of check-in *" \
382 technote "D 2026-03-04T12:30:00.000\nE 2026-03-04T09:00:00 [string repeat ab 20]\nP $contentGone\nU alice\nW 1\nx\n" \
 
 
 
 
 
 
 
 
 
 
383 "MISSING: $contentGone\n*parent of event *" \
384 tag "D 2026-03-04T13:00:00.000\nT +sym-missing $contentGone\nU alice\n" \
385 "MISSING: $contentGone\n*target of tag *" \
386 attachment "A f.txt Missing\\sparent $contentGone\nD 2026-03-04T14:00:00.000\nU alice\n" \
 
 
 
387 "MISSING: $contentGone\n*file of attachment *" \
388 cluster "M $contentGone\nM $contentGone2\n" \
389 "MISSING: $contentGone\n*in cluster *" \
390 ] {
391 content_artifact missing-$contentName.txt $contentBody
392 fossil test-content-put --crosslink missing-$contentName.txt
393 fossil test-missing -expectError
394 test content-missing-$contentName {$CODE != 0}
 
395 test content-missing-$contentName-text \
396 {[string match "*$contentWant*" $RESULT]}
397 }
398 # An attachment that takes a file away names none, and is not counted.
399 content_artifact missing-detach.txt \
@@ -408,13 +409,12 @@
408 # A missing artifact that is shunned is reported as shunned, or not at
409 # all with --notshunned.
410 fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$contentGone',0),
411 ('$contentGone2',0)"
412 fossil test-missing -expectError
413 test content-missing-shunned \
414 {$CODE != 0 && [string first "SHUNNED: $contentGone" $RESULT] >= 0
415 && [string first MISSING $RESULT] < 0}
416 fossil test-missing --notshunned
417 test content-missing-notshunned {$CODE == 0}
418 test_match content-missing-notshunned-text $RESULT \
419 {^0 missing or shunned references}
420 fossil sql "DELETE FROM shun"
@@ -423,29 +423,29 @@
423 # test-content-erase asks first. Erasing content that others are deltas
424 # from stores those whole.
425
426 fossil test-content-undelta $contentRid
427 fossil test-content-deltify --force $contentThird $contentRid
428 test_eq content-erase-setup [content_sql "SELECT count(*) FROM delta
429 WHERE srcid=$contentRid"] 1
430 fossil_raw -input "n\n" test-content-erase $contentRid
431 test_eq content-erase-declined [content_sql "SELECT count(*) FROM blob
432 WHERE rid=$contentRid"] 1
433 fossil_raw -input "Y\n" test-content-erase $contentRid
434 test content-erase {$CODE == 0}
435 test_eq content-erase-gone [content_sql "SELECT count(*) FROM blob
436 WHERE rid=$contentRid"] 0
437 test_eq content-erase-no-delta-left [content_sql "SELECT count(*) FROM delta
438 WHERE srcid=$contentRid OR rid=$contentRid"] 0
439 fossil artifact [content_sql "SELECT uuid FROM blob WHERE rid=$contentThird"] \
440 third.out
441 test_eq content-erase-dependent-still-whole [read_file third.out] \
442 [lindex $contentVersions 2]
443
444 # The answer may be in either case.
445 fossil_raw -input "y\n" test-content-erase $contentSmall
446 test_eq content-erase-lower-case-answer [content_sql "SELECT count(*) FROM blob
447 WHERE rid=$contentSmall"] 0
448
449 ###############################################################################
450 # A "parent" tag on a private check-in is itself private, and so is the
451 # placeholder for a parent that the repository does not have.
@@ -454,22 +454,22 @@
454 D 2026-03-05T10:00:00.000
455 F late.txt $contentLate
456 U alice
457 "
458 fossil test-content-put --crosslink ci-private.txt
459 set contentPriv [content_hash ci-private.txt]
460 fossil sql "INSERT INTO private(rid) VALUES([content_rid $contentPriv])"
461 set contentAbsent [string repeat 4d 20]
462 fossil tag add --raw parent $contentPriv $contentAbsent
463 test content-private-placeholder-tag {$CODE == 0}
464 test_eq content-private-placeholder [content_sql "SELECT count(*)
465 FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentAbsent'
466 AND size<0"] 1
467 test_eq content-private-placeholder-not-unclustered [content_sql "SELECT count(*)
468 FROM unclustered, blob WHERE unclustered.rid=blob.rid
469 AND uuid='$contentAbsent'"] 0
470 test_eq content-private-placeholder-is-parent [content_sql "SELECT count(*)
471 FROM plink WHERE cid=[content_rid $contentPriv]
472 AND pid=[content_rid $contentAbsent]"] 1
473
474 ###############################################################################
475 # Content that arrives in a sync message, sent to the server side through
@@ -490,15 +490,10 @@
490 }
491 proc content_x {sql} {
492 fossil sql -R x.fossil $sql
493 return [string trim $::RESULT]
494 }
495 proc content_sha1 {text} {
496 write_file sha1-me.txt $text
497 fossil sha1sum sha1-me.txt
498 return [lindex $::RESULT 0]
499 }
500 proc content_sha3 {text} {
501 write_file sha3-me.txt $text
502 fossil sha3sum sha3-me.txt
503 return [lindex $::RESULT 0]
504 }
@@ -515,16 +510,17 @@
515 global contentYcode CLIENT_VERSION_CARD
516 write_file msg.txt "${CLIENT_VERSION_CARD}push x $contentYcode\n$body"
517 fossil_raw test-xfer -R y.fossil msg.txt
518 }
519 set contentA "an artifact with a SHA1 name\n"
520 content_push_y "file [content_sha1 $contentA] [string length $contentA]\n$contentA"
521 test content-policy-sha1-name-accepted {$CODE == 0}
522 fossil hash-policy -R y.fossil
523 test_eq content-policy-still-auto [string trim $RESULT] auto
524 set contentB "an artifact with a SHA3 name\n"
525 content_push_y "file [content_sha3 $contentB] [string length $contentB]\n$contentB"
 
526 fossil hash-policy -R y.fossil
527 test_eq content-policy-now-sha3 [string trim $RESULT] sha3
528
529 # An artifact that the server has only heard of is a phantom. It is
530 # filled when its content arrives as a compressed delta from content the
@@ -554,11 +550,12 @@
554
555 # A phantom that is filled by a private card becomes private.
556 set contentP "content that arrives marked private\n"
557 set contentPHash [content_sha3 $contentP]
558 content_push "igot $contentPHash\n"
559 content_push "private\nfile $contentPHash [string length $contentP]\n$contentP" \
 
560 "login tester 0 0\n"
561 test content-sync-private-fill {$CODE == 0}
562 test_eq content-sync-private-fill-marked [content_x "SELECT count(*)
563 FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentPHash'
564 AND size>=0"] 1
@@ -612,93 +609,79 @@
612 fossil test-integrity -R x.fossil
613 test content-sync-integrity {$CODE == 0}
614
615 ###############################################################################
616 # The cache of reconstructed artifacts keeps every eighth artifact along a
617 # delta chain and drops the oldest entry once it holds more than 2,000.
618 # A chain of 18,000 deltas is stored and read back in one process, so the
619 # cache fills and entries are dropped while the chain is read; each version
620 # read afterwards, through dropped and kept entries, must still be right.
621
622 fossil new cache.fossil
623 fossil sql -R cache.fossil {
624 CREATE TEMP TABLE v(k INTEGER PRIMARY KEY, t BLOB);
625 WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<17999)
626 INSERT INTO v SELECT k, CAST(printf('common text%.100c version %d', '.', k)
627 AS BLOB) FROM c;
628 INSERT INTO blob(rid,rcvid,size,uuid,content)
629 SELECT 100000+k, 0, length(t), printf('%064d', k),
630 compress(CASE WHEN k=0 THEN t
631 ELSE delta_create((SELECT t FROM v p WHERE p.k=v.k-1), t) END)
632 FROM v;
633 INSERT INTO delta(rid,srcid) SELECT 100000+k, 100000+k-1 FROM v WHERE k>0;
634 SELECT content('rid:117999')=(SELECT t FROM v WHERE k=17999);
635 SELECT count(*) FROM v WHERE k%997=0 AND content('rid:'||(100000+k))=t;
636 }
637 test content-cache-expire {$CODE == 0}
638 test_eq content-cache-expire-reads [string trim $RESULT] "1\n19"
639
640 # The cache also drops its oldest entries while it holds more than 256 MB,
641 # as many as it takes. Each version here is a longer prefix of one random
642 # text, up to 18 MB, so the oldest entries are the smallest and dropping
643 # one is not always enough.
644
645 fossil new cache-size.fossil
646 fossil sql -R cache-size.fossil {
647 CREATE TEMP TABLE r(x BLOB);
648 INSERT INTO r VALUES(hex(randomblob(9000000)));
649 CREATE TEMP TABLE n(k INTEGER PRIMARY KEY);
650 WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<299)
651 INSERT INTO n SELECT k FROM c;
652 INSERT INTO blob(rid,rcvid,size,uuid,content)
653 SELECT 200000+k, 0, (k+1)*60000, printf('%064d', k),
654 compress(CASE WHEN k=0 THEN substr((SELECT x FROM r), 1, 60000)
655 ELSE delta_create(substr((SELECT x FROM r), 1, k*60000),
656 substr((SELECT x FROM r), 1, (k+1)*60000))
657 END)
658 FROM n;
659 INSERT INTO delta(rid,srcid) SELECT 200000+k, 200000+k-1 FROM n WHERE k>0;
660 SELECT content('rid:200299')
661 =CAST(substr((SELECT x FROM r), 1, 300*60000) AS BLOB);
662 SELECT count(*) FROM n WHERE k%37=0 AND content('rid:'||(200000+k))
663 =CAST(substr((SELECT x FROM r), 1, (k+1)*60000) AS BLOB);
664 }
665 test content-cache-size {$CODE == 0}
666 test_eq content-cache-size-reads [string trim $RESULT] "1\n9"
667 file delete cache-size.fossil
668
669 # When the oldest entry is an artifact of no bytes, dropping it frees
670 # nothing and the cache stays over 256 MB for one more entry. Version 7
671 # of this chain is empty and every other version is the same 30 MB; each
672 # version read afterwards must still be right.
673
674 fossil new cache-empty.fossil
675 fossil sql -R cache-empty.fossil {
676 CREATE TEMP TABLE r(x BLOB);
677 INSERT INTO r VALUES(CAST(hex(randomblob(15000000)) AS BLOB));
678 CREATE TEMP TABLE d(same BLOB, toempty BLOB, fromempty BLOB);
679 INSERT INTO d SELECT delta_create(x, x), delta_create(x, x''),
680 delta_create(x'', x) FROM r;
681 CREATE TEMP TABLE n(k INTEGER PRIMARY KEY);
682 WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<88)
683 INSERT INTO n SELECT k FROM c;
684 INSERT INTO blob(rid,rcvid,size,uuid,content)
685 SELECT 300000+k, 0, CASE WHEN k=7 THEN 0 ELSE 30000000 END,
686 printf('%064d', k),
687 compress(CASE WHEN k=0 THEN (SELECT x FROM r)
688 WHEN k=7 THEN (SELECT toempty FROM d)
689 WHEN k=8 THEN (SELECT fromempty FROM d)
690 ELSE (SELECT same FROM d) END)
691 FROM n;
692 INSERT INTO delta(rid,srcid) SELECT 300000+k, 300000+k-1 FROM n WHERE k>0;
693 SELECT content('rid:300088')=(SELECT x FROM r);
694 SELECT length(content('rid:300007'));
695 SELECT count(*) FROM n WHERE k IN (6,8,15,50,87)
696 AND content('rid:'||(300000+k))=(SELECT x FROM r);
697 }
698 test content-cache-empty-oldest {$CODE == 0}
699 test_eq content-cache-empty-oldest-reads [string trim $RESULT] "1\n0\n5"
700 file delete cache-empty.fossil
701
702 ###############################################################################
703
704 test_cleanup
705
--- test/content.test
+++ test/content.test
@@ -6,39 +6,18 @@
6 #
7 # integrity.test damages a repository and requires the damage to be
8 # found. This file covers what is left.
9 #
10
 
 
 
 
 
11 require_no_open_checkout
12
13 test_setup
14
 
 
 
 
 
 
 
 
15 # The record number of the artifact with the given hash.
16 #
17 proc content_rid {hash} {
18 return [fossil_sql "SELECT rid FROM blob WHERE uuid='$hash'"]
 
 
 
 
 
 
 
 
19 }
20
21 # Write a file that holds the cards $body and the Z card for them.
22 #
23 proc content_artifact {filename body} {
@@ -67,20 +46,20 @@
46 write_file long.txt $contentText
47 if {$contentI == 1} {fossil add long.txt}
48 fossil commit -m "content-v$contentI" --no-warnings
49 lappend contentVersions $contentText
50 }
51 set contentFirst [fossil_sql "SELECT uuid FROM blob, mlink, event
52 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
53 AND event.comment='content-v1'"]
54 set contentLast [fossil_sql "SELECT uuid FROM blob, mlink, event
55 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
56 AND event.comment='content-v30'"]
57 test content-setup {$contentFirst ne "" && $contentLast ne ""}
58
59 proc content_chain {rid} {
60 return [fossil_sql "WITH RECURSIVE c(rid,n) AS (SELECT $rid, 0
61 UNION ALL SELECT srcid, n+1 FROM delta, c WHERE delta.rid=c.rid)
62 SELECT max(n) FROM c"]
63 }
64 test_eq content-chain-length [content_chain [content_rid $contentFirst]] 29
65
@@ -110,11 +89,11 @@
89 fossil test-content-rawget -expectError
90 test content-rawget-usage {$CODE != 0}
91
92 fossil test-content-undelta $contentRid
93 test content-undelta {$CODE == 0}
94 test_eq content-undelta-no-delta-row [fossil_sql \
95 "SELECT count(*) FROM delta WHERE rid=$contentRid"] 0
96 fossil test-content-rawget $contentFirst raw.out
97 test_eq content-undelta-stored-whole [read_file raw.out] \
98 [lindex $contentVersions 0]
99 fossil test-content-undelta $contentRid
@@ -123,36 +102,36 @@
102 test content-undelta-usage {$CODE != 0}
103
104 ###############################################################################
105 # Turning content into a delta.
106
107 set contentSecond [fossil_sql "SELECT blob.rid FROM blob, mlink, event
108 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
109 AND event.comment='content-v2'"]
110 set contentThird [fossil_sql "SELECT blob.rid FROM blob, mlink, event
111 WHERE blob.rid=mlink.fid AND mlink.mid=event.objid
112 AND event.comment='content-v3'"]
113 set contentLastRid [content_rid $contentLast]
114
115 # The artifact itself and an artifact that is a delta from it are not
116 # used as sources. Of the two that remain, one is taken.
117 fossil test-content-deltify $contentRid $contentRid $contentLastRid \
118 $contentSecond
119 test content-deltify {$CODE == 0}
120 test content-deltify-source {[fossil_sql "SELECT srcid FROM delta
121 WHERE rid=$contentRid"] in [list $contentLastRid $contentSecond]}
122 fossil artifact $contentFirst first.out
123 test_eq content-deltify-same-content [read_file first.out] \
124 [lindex $contentVersions 0]
125
126 # Already a delta: left alone without --force, done again with it.
127 set contentSrc [fossil_sql "SELECT srcid FROM delta WHERE rid=$contentRid"]
128 fossil test-content-deltify $contentRid $contentThird
129 test_eq content-deltify-not-forced [fossil_sql "SELECT srcid FROM delta
130 WHERE rid=$contentRid"] $contentSrc
131 fossil test-content-deltify --force $contentRid $contentThird
132 test_eq content-deltify-forced [fossil_sql "SELECT srcid FROM delta
133 WHERE rid=$contentRid"] $contentThird
134 fossil artifact $contentFirst first.out
135 test_eq content-deltify-forced-same-content [read_file first.out] \
136 [lindex $contentVersions 0]
137
@@ -168,38 +147,38 @@
147 # Content of less than 50 bytes is never made a delta, nor used as the
148 # source of one.
149 write_file small.txt "small\n"
150 write_file small2.txt "small too\n"
151 fossil test-content-put small.txt small2.txt
152 set contentSmall [content_rid [sha3_file small.txt]]
153 set contentSmall2 [content_rid [sha3_file small2.txt]]
154 fossil test-content-deltify $contentSmall $contentSmall2
155 test_eq content-deltify-small [fossil_sql "SELECT count(*) FROM delta
156 WHERE rid=$contentSmall"] 0
157 fossil test-content-undelta $contentRid
158 fossil test-content-deltify $contentRid $contentSmall
159 test_eq content-deltify-small-source [fossil_sql "SELECT count(*) FROM delta
160 WHERE rid=$contentRid"] 0
161
162 # Unrelated content is not worth a delta.
163 write_file other.txt [string repeat "nothing in common with the file\n" 40]
164 fossil test-content-put other.txt
165 fossil test-content-deltify $contentRid [content_rid [sha3_file other.txt]]
166 test_eq content-deltify-unrelated [fossil_sql "SELECT count(*) FROM delta
167 WHERE rid=$contentRid"] 0
168
169 # Public content is not made a delta from private content.
170 write_file private.txt "${contentText}and one private line\n"
171 fossil test-content-put private.txt
172 set contentPrivate [content_rid [sha3_file private.txt]]
173 fossil sql "INSERT INTO private(rid) VALUES($contentPrivate)"
174 fossil test-content-deltify $contentRid $contentPrivate
175 test_eq content-deltify-private-source [fossil_sql "SELECT count(*) FROM delta
176 WHERE rid=$contentRid"] 0
177 fossil sql "DELETE FROM private WHERE rid=$contentPrivate"
178 fossil test-content-deltify $contentRid $contentPrivate
179 test_eq content-deltify-once-public [fossil_sql "SELECT srcid FROM delta
180 WHERE rid=$contentRid"] $contentPrivate
181 fossil test-content-undelta $contentRid
182
183 # Of two sources that both make a worthwhile delta, the one that makes
184 # the smaller is taken, whichever comes first.
@@ -210,31 +189,31 @@
189 write_file two-target.txt $contentBase
190 write_file two-near.txt "${contentBase}one more line\n"
191 write_file two-far.txt "[string range $contentBase 0 1500][string repeat \
192 "a line that the target does not have\n" 30]"
193 fossil test-content-put two-target.txt two-near.txt two-far.txt
194 set contentTarget [content_rid [sha3_file two-target.txt]]
195 set contentNear [content_rid [sha3_file two-near.txt]]
196 set contentFar [content_rid [sha3_file two-far.txt]]
197 fossil test-content-deltify $contentTarget $contentFar $contentNear
198 test_eq content-deltify-better-source-last [fossil_sql "SELECT srcid
199 FROM delta WHERE rid=$contentTarget"] $contentNear
200 fossil test-content-undelta $contentTarget
201 fossil test-content-deltify $contentTarget $contentNear $contentFar
202 test_eq content-deltify-better-source-first [fossil_sql "SELECT srcid
203 FROM delta WHERE rid=$contentTarget"] $contentNear
204 fossil test-content-undelta $contentTarget
205 fossil test-content-deltify $contentTarget $contentFar
206 test_eq content-deltify-far-source-alone [fossil_sql "SELECT srcid
207 FROM delta WHERE rid=$contentTarget"] $contentFar
208 fossil test-content-undelta $contentTarget
209
210 # Private content may be a delta from private content.
211 fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentPrivate)"
212 fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentRid)"
213 fossil test-content-deltify $contentRid $contentPrivate
214 test_eq content-deltify-private-from-private [fossil_sql "SELECT srcid
215 FROM delta WHERE rid=$contentRid"] $contentPrivate
216 fossil test-content-undelta $contentRid
217 fossil sql "DELETE FROM private WHERE rid IN ($contentPrivate,$contentRid)"
218
219 fossil test-content-deltify -expectError
@@ -247,33 +226,33 @@
226 # test-content-put with --moderate.
227
228 write_file moderated.txt "content awaiting moderation\n"
229 fossil test-content-put --moderate moderated.txt
230 test content-put-moderate {$CODE == 0}
231 test_eq content-put-moderate-row [fossil_sql "SELECT count(*) FROM modreq
232 WHERE objid=[content_rid [sha3_file moderated.txt]]"] 1
233
234 ###############################################################################
235 # Content that arrives after it was asked for. A check-in names a file
236 # that is not in the repository; when the file is stored, the check-in
237 # has it. A delta manifest is stored before its baseline; when the
238 # baseline arrives, the delta manifest becomes a check-in.
239
240 write_file late.txt "this file arrives late\n"
241 set contentLate [sha3_file late.txt]
242 content_artifact ci-late.txt "C content-late
243 D 2026-03-01T10:00:00.000
244 F late.txt $contentLate
245 U alice
246 "
247 fossil test-content-put --crosslink ci-late.txt
248 test_eq content-phantom-made [fossil_sql "SELECT size FROM blob
249 WHERE uuid='$contentLate'"] -1
250 fossil artifact $contentLate
251 test content-phantom-has-no-content {$CODE == 0 && $RESULT eq ""}
252 fossil test-content-put late.txt
253 test_eq content-phantom-filled [fossil_sql "SELECT size FROM blob
254 WHERE uuid='$contentLate'"] [file size late.txt]
255 fossil artifact $contentLate late.out
256 test content-phantom-filled-content {[same_file late.txt late.out]}
257
258 content_artifact ci-base.txt "C content-base
@@ -280,29 +259,29 @@
259 D 2026-03-02T10:00:00.000
260 F a.txt $contentLate
261 F b.txt $contentLate
262 U alice
263 "
264 set contentBase [sha3_file ci-base.txt]
265 content_artifact ci-delta.txt "B $contentBase
266 C content-delta
267 D 2026-03-02T11:00:00.000
268 F b.txt
269 F c.txt $contentLate
270 P $contentBase
271 U alice
272 "
273 fossil test-content-put --crosslink ci-delta.txt
274 test_eq content-orphan-not-a-checkin [fossil_sql "SELECT count(*) FROM event
275 WHERE comment='content-delta'"] 0
276 test_eq content-orphan-recorded [fossil_sql "SELECT count(*) FROM orphan"] 1
277 fossil test-content-put --crosslink ci-base.txt
278 test content-orphan-baseline-arrives {$CODE == 0}
279 test_eq content-orphan-now-a-checkin [fossil_sql "SELECT count(*) FROM event
280 WHERE comment IN ('content-delta','content-base')"] 2
281 test_eq content-orphan-cleared [fossil_sql "SELECT count(*) FROM orphan"] 0
282 fossil ls -r [sha3_file ci-delta.txt]
283 test_eq content-orphan-files [normalize_result] "a.txt\nc.txt"
284
285 ###############################################################################
286 # test-integrity: the options that check the database only, and --parse
287 # on content that looks like an artifact and is not one.
@@ -319,45 +298,47 @@
298 write_file looks5.txt "D 2026-03-03T10:00:00.000\nno newline at the end"
299 # Content that does not begin with a card at all, content whose first line
300 # holds a zero byte, and content whose first line is very long.
301 write_file looks6.txt "1 begins with a digit, which no card does\n"
302 write_file looks7.txt "AB has no space after its first letter\n"
303 write_file looks8.txt \
304 "C a first line\x00with a zero byte in it\nand a second line\n"
305 write_file looks9.txt "C [string repeat x 500]\nand a second line\n"
306 # Content that is the first line of a signed message and nothing more,
307 # with no end of line.
308 write_file looks10.txt "-----BEGIN PGP SIGNED MESSAGE-----"
309 fossil test-content-put looks1.txt looks2.txt looks3.txt looks4.txt looks5.txt \
310 looks6.txt looks7.txt looks8.txt looks9.txt looks10.txt
311 set contentLooks10 [sha3_file looks10.txt]
312 fossil test-integrity --parse
313 test content-integrity-parse {$CODE == 0}
314 test content-integrity-parse-counts \
315 {[regexp {(\d+) control artifacts failed to parse} $RESULT all n] && $n ==
316 6}
317 test content-integrity-parse-one-line-signed \
318 {[string first "manifest_parse failed for $contentLooks10:" $RESULT] >= 0}
319 test content-integrity-parse-first-line \
320 {[string first "\"C this looks like a card\"" $RESULT] >= 0}
321
322 # The same content is an error once the repository has it down as a
323 # wiki page.
324 fossil sql "INSERT INTO event(type,mtime,objid,user,comment)
325 VALUES('w',2461000.5,[content_rid [sha3_file looks1.txt]],'alice','+x')"
326 fossil test-integrity --parse -expectError
327 test content-integrity-parse-listed-artifact {$CODE != 0}
328 fossil sql "DELETE FROM event
329 WHERE objid=[content_rid [sha3_file looks1.txt]]"
330
331 ###############################################################################
332 # test-orphans lists content that nothing refers to.
333
334 fossil test-orphans
335 test content-orphans {$CODE == 0}
336 test content-orphans-count \
337 {[regexp {(\d+) orphans} $RESULT all n] && $n >= 9}
338 test content-orphans-lists-one \
339 {[string first [sha3_file other.txt] $RESULT] >= 0}
340
341 ###############################################################################
342 # test-missing reports each kind of reference to content that is not
343 # there.
344
@@ -368,32 +349,52 @@
349 fossil test-missing --quiet
350 test_eq content-missing-none-quiet [string trim $RESULT] ""
351
352 set contentGone [string repeat 0123456789 4]
353 set contentGone2 [string repeat 9876543210 4]
354 set contentCi [fossil_sql "SELECT uuid FROM blob, event
355 WHERE rid=objid AND comment='content-v30'"]
356 foreach {contentName contentCount contentBody contentWant} [list \
357 file 1 \
358 [join [list \
359 "C content-missing-file\nD 2026-03-04T10:00:00.000\n" \
360 "F gone.txt $contentGone\nU alice\n"] ""] \
361 "MISSING: $contentGone\n*file of check-in *\n*gone.txt" \
362 parent 2 \
363 [join [list \
364 "D 2026-03-04T11:00:00.000\nL Missing\\sparent\n" \
365 "P $contentGone\nU alice\nW 1\nx\n"] ""] \
366 "MISSING: $contentGone\n*parent of wiki *" \
367 cherrypick 4 \
368 [join [list \
369 "C content-missing-pick\nD 2026-03-04T12:00:00.000\n" \
370 "P $contentCi\nQ +$contentGone $contentGone2\nU alice\n"] ""] \
371 [join [list \
372 "MISSING: $contentGone\n" \
373 "*cherry-pick target of check-in *MISSING: $contentGone2\n" \
374 "*cherry-pick baseline of check-in *"] ""] \
375 technote 5 \
376 [join [list \
377 "D 2026-03-04T12:30:00.000\n" \
378 "E 2026-03-04T09:00:00 [string repeat ab 20]\nP $contentGone\n" \
379 "U alice\nW 1\nx\n"] ""] \
380 "MISSING: $contentGone\n*parent of event *" \
381 tag 6 "D 2026-03-04T13:00:00.000\nT +sym-missing $contentGone\nU alice\n" \
382 "MISSING: $contentGone\n*target of tag *" \
383 attachment 7 \
384 [join [list \
385 "A f.txt Missing\\sparent $contentGone\n" \
386 "D 2026-03-04T14:00:00.000\nU alice\n"] ""] \
387 "MISSING: $contentGone\n*file of attachment *" \
388 cluster 9 "M $contentGone\nM $contentGone2\n" \
389 "MISSING: $contentGone\n*in cluster *" \
390 ] {
391 content_artifact missing-$contentName.txt $contentBody
392 fossil test-content-put --crosslink missing-$contentName.txt
393 fossil test-missing -expectError
394 test content-missing-$contentName {$CODE != 0 && [string match \
395 "*\n$contentCount missing or shunned references *" $RESULT]}
396 test content-missing-$contentName-text \
397 {[string match "*$contentWant*" $RESULT]}
398 }
399 # An attachment that takes a file away names none, and is not counted.
400 content_artifact missing-detach.txt \
@@ -408,13 +409,12 @@
409 # A missing artifact that is shunned is reported as shunned, or not at
410 # all with --notshunned.
411 fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$contentGone',0),
412 ('$contentGone2',0)"
413 fossil test-missing -expectError
414 test content-missing-shunned {$CODE != 0 &&
415 [holds_strings $RESULT [list "SHUNNED: $contentGone" !MISSING]]}
 
416 fossil test-missing --notshunned
417 test content-missing-notshunned {$CODE == 0}
418 test_match content-missing-notshunned-text $RESULT \
419 {^0 missing or shunned references}
420 fossil sql "DELETE FROM shun"
@@ -423,29 +423,29 @@
423 # test-content-erase asks first. Erasing content that others are deltas
424 # from stores those whole.
425
426 fossil test-content-undelta $contentRid
427 fossil test-content-deltify --force $contentThird $contentRid
428 test_eq content-erase-setup [fossil_sql "SELECT count(*) FROM delta
429 WHERE srcid=$contentRid"] 1
430 fossil_raw -input "n\n" test-content-erase $contentRid
431 test_eq content-erase-declined [fossil_sql "SELECT count(*) FROM blob
432 WHERE rid=$contentRid"] 1
433 fossil_raw -input "Y\n" test-content-erase $contentRid
434 test content-erase {$CODE == 0}
435 test_eq content-erase-gone [fossil_sql "SELECT count(*) FROM blob
436 WHERE rid=$contentRid"] 0
437 test_eq content-erase-no-delta-left [fossil_sql "SELECT count(*) FROM delta
438 WHERE srcid=$contentRid OR rid=$contentRid"] 0
439 fossil artifact [fossil_sql "SELECT uuid FROM blob WHERE rid=$contentThird"] \
440 third.out
441 test_eq content-erase-dependent-still-whole [read_file third.out] \
442 [lindex $contentVersions 2]
443
444 # The answer may be in either case.
445 fossil_raw -input "y\n" test-content-erase $contentSmall
446 test_eq content-erase-lower-case-answer [fossil_sql "SELECT count(*) FROM blob
447 WHERE rid=$contentSmall"] 0
448
449 ###############################################################################
450 # A "parent" tag on a private check-in is itself private, and so is the
451 # placeholder for a parent that the repository does not have.
@@ -454,22 +454,22 @@
454 D 2026-03-05T10:00:00.000
455 F late.txt $contentLate
456 U alice
457 "
458 fossil test-content-put --crosslink ci-private.txt
459 set contentPriv [sha3_file ci-private.txt]
460 fossil sql "INSERT INTO private(rid) VALUES([content_rid $contentPriv])"
461 set contentAbsent [string repeat 4d 20]
462 fossil tag add --raw parent $contentPriv $contentAbsent
463 test content-private-placeholder-tag {$CODE == 0}
464 test_eq content-private-placeholder [fossil_sql "SELECT count(*)
465 FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentAbsent'
466 AND size<0"] 1
467 test_eq content-private-placeholder-not-unclustered [fossil_sql "SELECT count(*)
468 FROM unclustered, blob WHERE unclustered.rid=blob.rid
469 AND uuid='$contentAbsent'"] 0
470 test_eq content-private-placeholder-is-parent [fossil_sql "SELECT count(*)
471 FROM plink WHERE cid=[content_rid $contentPriv]
472 AND pid=[content_rid $contentAbsent]"] 1
473
474 ###############################################################################
475 # Content that arrives in a sync message, sent to the server side through
@@ -490,15 +490,10 @@
490 }
491 proc content_x {sql} {
492 fossil sql -R x.fossil $sql
493 return [string trim $::RESULT]
494 }
 
 
 
 
 
495 proc content_sha3 {text} {
496 write_file sha3-me.txt $text
497 fossil sha3sum sha3-me.txt
498 return [lindex $::RESULT 0]
499 }
@@ -515,16 +510,17 @@
510 global contentYcode CLIENT_VERSION_CARD
511 write_file msg.txt "${CLIENT_VERSION_CARD}push x $contentYcode\n$body"
512 fossil_raw test-xfer -R y.fossil msg.txt
513 }
514 set contentA "an artifact with a SHA1 name\n"
515 content_push_y "file [sha1_text $contentA] [string length $contentA]\n$contentA"
516 test content-policy-sha1-name-accepted {$CODE == 0}
517 fossil hash-policy -R y.fossil
518 test_eq content-policy-still-auto [string trim $RESULT] auto
519 set contentB "an artifact with a SHA3 name\n"
520 content_push_y \
521 "file [content_sha3 $contentB] [string length $contentB]\n$contentB"
522 fossil hash-policy -R y.fossil
523 test_eq content-policy-now-sha3 [string trim $RESULT] sha3
524
525 # An artifact that the server has only heard of is a phantom. It is
526 # filled when its content arrives as a compressed delta from content the
@@ -554,11 +550,12 @@
550
551 # A phantom that is filled by a private card becomes private.
552 set contentP "content that arrives marked private\n"
553 set contentPHash [content_sha3 $contentP]
554 content_push "igot $contentPHash\n"
555 content_push \
556 "private\nfile $contentPHash [string length $contentP]\n$contentP" \
557 "login tester 0 0\n"
558 test content-sync-private-fill {$CODE == 0}
559 test_eq content-sync-private-fill-marked [content_x "SELECT count(*)
560 FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentPHash'
561 AND size>=0"] 1
@@ -612,93 +609,79 @@
609 fossil test-integrity -R x.fossil
610 test content-sync-integrity {$CODE == 0}
611
612 ###############################################################################
613 # The cache of reconstructed artifacts keeps every eighth artifact along a
614 # delta chain. It drops its oldest entry once it holds more than 2,000
615 # entries, and its oldest entries, as many as it takes, while it holds
616 # more than 256 MB. Both limits are constants in content.c, so a test
617 # has to store enough to exceed them. If Fossil gets a setting for the
618 # size of this cache, set it far lower here, at least for -assurance
619 # smoke, and run these tests at every level.
620
621 if {[test_assurance] eq "smoke"} {
622 test_skip_part "the content cache limits need -assurance ci or stress"
623 } else {
624 # A chain of 18,000 deltas is stored and read back in one process, so
625 # the cache holds more than 2,000 entries and drops the oldest while
626 # the chain is read; each version read afterwards, through dropped and
627 # kept entries, must still be right.
628 fossil new cache.fossil
629 fossil sql -R cache.fossil {
630 CREATE TEMP TABLE v(k INTEGER PRIMARY KEY, t BLOB);
631 WITH RECURSIVE c(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM c WHERE k<17999)
632 INSERT INTO v SELECT k, CAST(printf('common text%.100c version %d', '.', k)
633 AS BLOB) FROM c;
634 INSERT INTO blob(rid,rcvid,size,uuid,content)
635 SELECT 100000+k, 0, length(t), printf('%064d', k),
636 compress(CASE WHEN k=0 THEN t
637 ELSE delta_create((SELECT t FROM v p WHERE p.k=v.k-1), t)
638 END)
639 FROM v;
640 INSERT INTO delta(rid,srcid) SELECT 100000+k, 100000+k-1 FROM v WHERE k>0;
641 SELECT content('rid:117999')=(SELECT t FROM v WHERE k=17999);
642 SELECT count(*) FROM v WHERE k%997=0 AND content('rid:'||(100000+k))=t;
643 }
644 test content-cache-expire {$CODE == 0}
645 test_eq content-cache-expire-reads [string trim $RESULT] "1\n19"
646
647 # A chain of 104 versions takes the cache over 256 MB. Only every
648 # eighth version is cached, so those are 30 MB each and the versions
649 # between them are a few bytes, which makes the chain quick to store
650 # and to read. The two oldest cached versions are small (version 7)
651 # and empty (version 15). When the cache first exceeds the limit,
652 # dropping version 7 is not enough, and dropping version 15 frees
653 # nothing, which leaves the cache over the limit. The next entry
654 # drops two 30 MB versions. Each version read afterwards must still
655 # be right.
656 fossil new cache-size.fossil
657 fossil sql -R cache-size.fossil {
658 CREATE TEMP TABLE c(kind INTEGER PRIMARY KEY, t BLOB);
659 INSERT INTO c VALUES(0, CAST('a small version' AS BLOB)),
660 (1, zeroblob(30000000)), (2, x'');
661 CREATE TEMP TABLE d(src, dst, z BLOB, PRIMARY KEY(src, dst));
662 INSERT INTO d SELECT a.kind, b.kind, compress(delta_create(a.t, b.t))
663 FROM c a, c b WHERE a.kind=0 OR b.kind=0;
664 CREATE TEMP TABLE n(k INTEGER PRIMARY KEY, kind);
665 WITH RECURSIVE s(k) AS (SELECT 0 UNION ALL SELECT k+1 FROM s WHERE k<103)
666 INSERT INTO n SELECT k, CASE WHEN k=15 THEN 2 WHEN k%8=7 AND k>15 THEN 1
667 ELSE 0 END FROM s;
668 INSERT INTO blob(rid,rcvid,size,uuid,content)
669 SELECT 200000+k, 0, (SELECT length(t) FROM c WHERE c.kind=n.kind),
670 printf('%064d', k),
671 CASE WHEN k=0 THEN (SELECT compress(t) FROM c WHERE c.kind=n.kind)
672 ELSE (SELECT z FROM d WHERE dst=n.kind
673 AND src=(SELECT kind FROM n p WHERE p.k=n.k-1)) END
674 FROM n;
675 INSERT INTO delta(rid,srcid) SELECT 200000+k, 200000+k-1 FROM n WHERE k>0;
676 SELECT content('rid:200103')=(SELECT t FROM c WHERE kind=1);
677 SELECT length(content('rid:200015'));
678 SELECT count(*) FROM n WHERE k IN (0,7,14,16,23,31,39,95,102,103)
679 AND content('rid:'||(200000+k))=(SELECT t FROM c WHERE c.kind=n.kind);
680 }
681 test content-cache-size {$CODE == 0}
682 test_eq content-cache-size-reads [string trim $RESULT] "1\n0\n10"
683 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
685 ###############################################################################
686
687 test_cleanup
688
+167 -144
--- test/crosslink.test
+++ test/crosslink.test
@@ -8,15 +8,12 @@
88
# the ordinary commands never produce: a reply to a forum post, an
99
# attachment whose target is not in the repository, a check-in whose
1010
# baseline is missing.
1111
#
1212
13
-# These tests run only in a long pass: -assurance stress.
14
-if {[test_assurance] ne "stress"} {
15
- test_skip "runs only with -assurance stress"
16
-}
17
-
13
+# The first sections run at every level, and the rest need
14
+# -assurance stress.
1815
require_no_open_checkout
1916
2017
test_setup
2118
2219
set crosslinkSeq 0
@@ -40,18 +37,14 @@
4037
4138
# Store the artifact whose cards, without the Z card, are $body. Return
4239
# its hash, or an empty string if it was not stored. CODE and RESULT are
4340
# those of test-content-put.
4441
#
45
-proc crosslink_put {body {options --crosslink}} {
42
+proc crosslink_put {body} {
4643
global RESULT CODE
4744
set fn [crosslink_file $body]
48
- if {$options eq ""} {
49
- fossil test-content-put $fn
50
- } else {
51
- fossil test-content-put $options $fn
52
- }
45
+ fossil test-content-put --crosslink $fn
5346
set code $CODE
5447
set result $RESULT
5548
set hash ""
5649
if {[regexp {inserted as record (\d+)} $result all rid]} {
5750
fossil sql "SELECT uuid FROM blob WHERE rid=$rid"
@@ -73,22 +66,14 @@
7366
proc crosslink_match {name actual pattern {constraints ""}} {
7467
if {[string match $pattern $actual]} {set pattern $actual}
7568
test_eq $name $actual $pattern $constraints
7669
}
7770
78
-# The answer of one SQL statement, trimmed.
79
-#
80
-proc crosslink_sql {sql} {
81
- global RESULT
82
- fossil sql $sql
83
- return [string trim $RESULT]
84
-}
85
-
8671
# The timeline text of the artifact with the given hash.
8772
#
8873
proc crosslink_event {hash} {
89
- return [crosslink_sql "SELECT type || ' ' || comment FROM event, blob\
74
+ return [fossil_sql "SELECT type || ' ' || comment FROM event, blob\
9075
WHERE objid=rid AND uuid='$hash'"]
9176
}
9277
9378
set crosslinkNone [string repeat 0123456789 4]
9479
set crosslinkNone2 [string repeat 9876543210 4]
@@ -101,11 +86,11 @@
10186
U alice
10287
[crosslink_w {first text}]"]
10388
test crosslink-wiki-new {$CODE == 0 && $crosslinkW1 ne ""}
10489
test_eq crosslink-wiki-new-event [crosslink_event $crosslinkW1] \
10590
{w +Crosslink Page}
106
-test_eq crosslink-wiki-new-tag [crosslink_sql "SELECT value FROM tagxref, tag
91
+test_eq crosslink-wiki-new-tag [fossil_sql "SELECT value FROM tagxref, tag
10792
WHERE tag.tagid=tagxref.tagid AND tagname='wiki-Crosslink Page'"] {10}
10893
10994
set crosslinkW2 [crosslink_put "D 2026-01-01T11:00:00.000
11095
L Crosslink\\sPage
11196
N text/x-markdown
@@ -112,11 +97,11 @@
11297
P $crosslinkW1
11398
U alice
11499
[crosslink_w {second text}]"]
115100
test_eq crosslink-wiki-edit-event [crosslink_event $crosslinkW2] \
116101
{w :Crosslink Page}
117
-test_eq crosslink-wiki-edit-plink [crosslink_sql "SELECT count(*) FROM plink
102
+test_eq crosslink-wiki-edit-plink [fossil_sql "SELECT count(*) FROM plink
118103
WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkW2')
119104
AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
120105
121106
set crosslinkW3 [crosslink_put "D 2026-01-01T12:00:00.000
122107
L Crosslink\\sPage
@@ -147,29 +132,29 @@
147132
T +bgcolor * #abcdef
148133
T +sym-noted *
149134
U alice
150135
[crosslink_w {note}]"]
151136
test crosslink-technote-new {$CODE == 0 && $crosslinkE1 ne ""}
152
-test_eq crosslink-technote-new-event [crosslink_sql "SELECT type, comment,
137
+test_eq crosslink-technote-new-event [fossil_sql "SELECT type, comment,
153138
bgcolor FROM event, blob WHERE objid=rid AND uuid='$crosslinkE1'"] \
154139
{e|First note|#abcdef}
155140
156141
set crosslinkE2 [crosslink_put "C Second\\snote
157142
D 2026-01-02T11:00:00.000
158143
E 2026-01-02T09:00:00 $crosslinkEid
159144
P $crosslinkE1
160145
U alice
161146
[crosslink_w {note2}]"]
162
-test_eq crosslink-technote-edit-only-latest [crosslink_sql "SELECT comment
147
+test_eq crosslink-technote-edit-only-latest [fossil_sql "SELECT comment
163148
FROM event WHERE type='e'"] {Second note}
164149
165
-set crosslinkE0 [crosslink_put "C Earlier\\snote
150
+crosslink_put "C Earlier\\snote
166151
D 2026-01-02T08:00:00.000
167152
E 2026-01-02T09:00:00 $crosslinkEid
168153
U alice
169
-[crosslink_w {note0}]"]
170
-test_eq crosslink-technote-older-arrives-last [crosslink_sql "SELECT comment
154
+[crosslink_w {note0}]"
155
+test_eq crosslink-technote-older-arrives-last [fossil_sql "SELECT comment
171156
FROM event WHERE type='e'"] {Second note}
172157
173158
###############################################################################
174159
# Tickets: a new ticket, a change of status with other fields, a change
175160
# without the status, and one with a single field.
@@ -182,30 +167,32 @@
182167
U alice
183168
"]
184169
test crosslink-ticket-new {$CODE == 0 && $crosslinkT1 ne ""}
185170
crosslink_match crosslink-ticket-new-event [crosslink_event $crosslinkT1] \
186171
{t New ticket *Crosslink ticket*}
187
-test_eq crosslink-ticket-new-row [crosslink_sql "SELECT status, title
172
+test_eq crosslink-ticket-new-row [fossil_sql "SELECT status, title
188173
FROM ticket WHERE tkt_uuid='$crosslinkTkt'"] {Open|Crosslink ticket}
189174
190175
set crosslinkT2 [crosslink_put "D 2026-01-03T11:00:00.000
191176
J priority High
192177
J severity Minor
193178
J status Fixed
194179
K $crosslinkTkt
195180
U alice
196181
"]
197
-crosslink_match crosslink-ticket-status-plus-two [crosslink_event $crosslinkT2] \
182
+crosslink_match crosslink-ticket-status-plus-two \
183
+ [crosslink_event $crosslinkT2] \
198184
{t Fixed ticket * plus 2 other changes}
199185
200186
set crosslinkT3 [crosslink_put "D 2026-01-03T12:00:00.000
201187
J priority Low
202188
J status Closed
203189
K $crosslinkTkt
204190
U alice
205191
"]
206
-crosslink_match crosslink-ticket-status-plus-one [crosslink_event $crosslinkT3] \
192
+crosslink_match crosslink-ticket-status-plus-one \
193
+ [crosslink_event $crosslinkT3] \
207194
{t Closed ticket * plus 1 other change}
208195
209196
set crosslinkT4 [crosslink_put "D 2026-01-03T13:00:00.000
210197
J priority Medium
211198
J severity Severe
@@ -230,11 +217,11 @@
230217
"]
231218
crosslink_match crosslink-ticket-status-only [crosslink_event $crosslinkT6] \
232219
{t Verified ticket *}
233220
test {crosslink-ticket-status-only-no-plus} \
234221
{![string match *plus* [crosslink_event $crosslinkT6]]}
235
-test_eq crosslink-ticket-events [crosslink_sql "SELECT count(*) FROM event
222
+test_eq crosslink-ticket-events [fossil_sql "SELECT count(*) FROM event
236223
WHERE type='t'"] 6
237224
238225
###############################################################################
239226
# Forum posts: a thread, an edit of its first post, a reply, an edit of
240227
# the reply, a deleted reply, and an older edit of the first post that
@@ -246,11 +233,11 @@
246233
U alice
247234
[crosslink_w $crosslinkFtext]"]
248235
test crosslink-forum-post {$CODE == 0 && $crosslinkF1 ne ""}
249236
test_eq crosslink-forum-post-event [crosslink_event $crosslinkF1] \
250237
{f Post: Crosslink thread}
251
-test_eq crosslink-forum-post-backlink [crosslink_sql "SELECT count(*)
238
+test_eq crosslink-forum-post-backlink [fossil_sql "SELECT count(*)
252239
FROM backlink WHERE srctype=4
253240
AND srcid=(SELECT rid FROM blob WHERE uuid='$crosslinkF1')"] 1
254241
255242
set crosslinkF2 [crosslink_put "D 2026-01-04T11:00:00.000
256243
G $crosslinkF1
@@ -258,11 +245,11 @@
258245
N text/x-markdown
259246
U bob
260247
[crosslink_w {reply}]"]
261248
test_eq crosslink-forum-reply-event [crosslink_event $crosslinkF2] \
262249
{f Reply: Crosslink thread}
263
-test_eq crosslink-forum-reply-row [crosslink_sql "SELECT
250
+test_eq crosslink-forum-reply-row [fossil_sql "SELECT
264251
froot=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'),
265252
firt=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'), fprev IS NULL
266253
FROM forumpost WHERE fpid=(SELECT rid FROM blob
267254
WHERE uuid='$crosslinkF2')"] {1|1|1}
268255
@@ -323,10 +310,14 @@
323310
I $crosslinkNone
324311
U bob
325312
[crosslink_w {reply}]"]
326313
test_eq crosslink-forum-reply-unknown-thread [crosslink_event $crosslinkF8] \
327314
{f Reply: <i>Unknown</i>}
315
+
316
+if {[test_assurance] ne "stress"} {
317
+ test_skip "the tests after the first sections need -assurance stress"
318
+}
328319
329320
###############################################################################
330321
# Attachments, added to and deleted from each kind of target.
331322
332323
set crosslinkSrc [string repeat ef 20]
@@ -355,35 +346,35 @@
355346
U alice
356347
"]
357348
set crosslinkEv [crosslink_event $crosslinkA]
358349
crosslink_match crosslink-attach-$crosslinkKind-delete-event $crosslinkEv \
359350
"$crosslinkType Delete attachment $crosslinkDel"
360
- test_eq crosslink-attach-$crosslinkKind-latest [crosslink_sql "SELECT
351
+ test_eq crosslink-attach-$crosslinkKind-latest [fossil_sql "SELECT
361352
group_concat(isLatest,'') FROM (SELECT isLatest FROM attachment
362353
WHERE target='[string map {\\s { }} $crosslinkTarget]' ORDER BY mtime)"] \
363354
{01}
364355
}
365
-test_eq crosslink-attach-rows [crosslink_sql \
356
+test_eq crosslink-attach-rows [fossil_sql \
366357
"SELECT count(*) FROM attachment"] 10
367358
368359
# A later change to a ticket or a tech note rewrites the timeline text of
369360
# its attachments.
370
-set crosslinkT7 [crosslink_put "D 2026-01-05T12:00:00.000
361
+crosslink_put "D 2026-01-05T12:00:00.000
371362
J status Open
372363
K $crosslinkTkt
373364
U alice
374
-"]
375
-test_eq crosslink-ticket-rewrites-attachments [crosslink_sql "SELECT count(*)
365
+"
366
+test_eq crosslink-ticket-rewrites-attachments [fossil_sql "SELECT count(*)
376367
FROM event WHERE type='t' AND (comment LIKE 'Add attachment % to ticket %'
377368
OR comment LIKE 'Delete attachment % from ticket %')"] 2
378
-set crosslinkE3 [crosslink_put "C Third\\snote
369
+crosslink_put "C Third\\snote
379370
D 2026-01-05T12:00:00.000
380371
E 2026-01-02T09:00:00 $crosslinkEid
381372
P $crosslinkE2
382373
U alice
383
-[crosslink_w {note3}]"]
384
-test_eq crosslink-technote-rewrites-attachments [crosslink_sql "SELECT
374
+[crosslink_w {note3}]"
375
+test_eq crosslink-technote-rewrites-attachments [fossil_sql "SELECT
385376
count(*) FROM event WHERE type='e'
386377
AND (comment LIKE 'Add attachment % to tech note %'
387378
OR comment LIKE 'Delete attachment % from tech note %')"] 2
388379
389380
###############################################################################
@@ -391,33 +382,37 @@
391382
392383
write_file a.txt "a\n"
393384
write_file b.txt "b\n"
394385
fossil add a.txt b.txt
395386
fossil commit -m "crosslink-c1" --no-warnings
396
-set crosslinkC1 [crosslink_sql "SELECT uuid FROM blob, event
387
+set crosslinkC1 [fossil_sql "SELECT uuid FROM blob, event
397388
WHERE rid=objid AND comment='crosslink-c1'"]
398389
set crosslinkC1 [string trim $crosslinkC1 ']
399
-set crosslinkFa [string trim [crosslink_sql "SELECT uuid FROM blob, mlink,
390
+set crosslinkFa [string trim [fossil_sql "SELECT uuid FROM blob, mlink,
400391
filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
401392
AND name='a.txt'"] ']
402
-set crosslinkFb [string trim [crosslink_sql "SELECT uuid FROM blob, mlink,
393
+set crosslinkFb [string trim [fossil_sql "SELECT uuid FROM blob, mlink,
403394
filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
404395
AND name='b.txt'"] ']
405396
test crosslink-setup-checkin \
406397
{$crosslinkC1 ne "" && $crosslinkFa ne "" && $crosslinkFb ne ""}
407398
408399
# Every kind of tag that has its own wording in the timeline.
409400
foreach {crosslinkName crosslinkCard crosslinkWant} [list \
410401
branch "*branch * other" {*Move to branch*other*} \
411
- bgcolor-prop "*bgcolor * #112233" {*Change branch background color to "#112233".*} \
412
- bgcolor "+bgcolor * #445566" {*Change background color to "#445566".*} \
402
+ bgcolor-prop "*bgcolor * #112233" \
403
+ {*Change branch background color to "#112233".*} \
404
+ bgcolor "+bgcolor * #445566" \
405
+ {*Change background color to "#445566".*} \
413406
bgcolor-off "-bgcolor *" {*Cancel background color.*} \
414407
comment "+comment * new\\stext" {*Edit check-in comment.*} \
415408
user "+user * carol" {*Change user to "carol".*} \
416
- date "+date * 2026-01-06\\s09:00:00" {*Timestamp 2026-01-06 09:00:00.*} \
409
+ date "+date * 2026-01-06\\s09:00:00" \
410
+ {*Timestamp 2026-01-06 09:00:00.*} \
417411
sym-add "+sym-one *" {*Add tag "one".*} \
418
- sym-add-note "+sym-two * a\\snote" {*Add tag "two" with note "a note".*} \
412
+ sym-add-note "+sym-two * a\\snote" \
413
+ {*Add tag "two" with note "a note".*} \
419414
sym-prop "*sym-three *" {*Add propagating tag "three".*} \
420415
sym-cancel "-sym-one *" {*Cancel tag "one".*} \
421416
closed "+closed *" {*Mark "Closed".*} \
422417
closed-off "-closed *" {*Remove the "Closed" mark.*} \
423418
other-add "+thing *" {*Add "thing".*} \
@@ -436,16 +431,15 @@
436431
"]
437432
test crosslink-tag-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
438433
crosslink_match crosslink-tag-$crosslinkName-event \
439434
[crosslink_event $crosslinkG] "g Edit *:$crosslinkWant"
440435
}
441
-test_eq crosslink-tag-comment-applied [crosslink_sql "SELECT ecomment, euser
436
+test_eq crosslink-tag-comment-applied [fossil_sql "SELECT ecomment, euser
442437
FROM event WHERE objid=(SELECT rid FROM blob WHERE uuid='$crosslinkC1')"] \
443438
{new text|carol}
444439
445440
# A branch move with its symbolic tags says only that the branch moved.
446
-# Tags for two check-ins in one artifact are listed for each.
447441
set crosslinkG [crosslink_put "D 2026-01-06T11:00:00.000
448442
T *branch $crosslinkC1 moved
449443
T *sym-moved $crosslinkC1
450444
T -sym-other $crosslinkC1
451445
U alice
@@ -490,16 +484,16 @@
490484
U alice
491485
"]
492486
test crosslink-checkin {$CODE == 0 && $crosslinkM1 ne ""}
493487
test_eq crosslink-checkin-event [crosslink_event $crosslinkM1] \
494488
{ci crosslink-c2}
495
-test_eq crosslink-checkin-mlink [crosslink_sql "SELECT group_concat(
489
+test_eq crosslink-checkin-mlink [fossil_sql "SELECT group_concat(
496490
name || ':' || mperm || ':' || (pfnid>0), ' ') FROM (SELECT name, mperm,
497491
pfnid FROM mlink, filename WHERE mlink.fnid=filename.fnid
498492
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')
499493
ORDER BY name)"] {a.txt:1:0 b.txt:0:0 c.txt:0:1 l.txt:2:0}
500
-test_eq crosslink-checkin-cherrypick [crosslink_sql "SELECT count(*)
494
+test_eq crosslink-checkin-cherrypick [fossil_sql "SELECT count(*)
501495
FROM cherrypick WHERE childid=(SELECT rid FROM blob
502496
WHERE uuid='$crosslinkM1')"] 1
503497
504498
# A delta manifest, a second one on the same baseline, and an ordinary
505499
# check-in after them. The second does not repeat the removal of a.txt,
@@ -511,16 +505,16 @@
511505
F d.txt $crosslinkFb
512506
P $crosslinkM1
513507
U alice
514508
"]
515509
test crosslink-delta-checkin {$CODE == 0 && $crosslinkM2 ne ""}
516
-test_eq crosslink-delta-checkin-mlink [crosslink_sql "SELECT group_concat(
510
+test_eq crosslink-delta-checkin-mlink [fossil_sql "SELECT group_concat(
517511
name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
518512
WHERE mlink.fnid=filename.fnid
519513
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM2')
520514
ORDER BY name)"] {a.txt:0 d.txt:1}
521
-test_eq crosslink-delta-seen [crosslink_sql "SELECT value FROM config
515
+test_eq crosslink-delta-seen [fossil_sql "SELECT value FROM config
522516
WHERE name='seen-delta-manifest'"] 1
523517
524518
set crosslinkM3 [crosslink_put "B $crosslinkM1
525519
C crosslink-c4
526520
D 2026-01-07T12:00:00.000
@@ -528,11 +522,11 @@
528522
F d.txt $crosslinkFa
529523
F e.txt $crosslinkFa
530524
P $crosslinkM2
531525
U alice
532526
"]
533
-test_eq crosslink-delta-to-delta-mlink [crosslink_sql "SELECT group_concat(
527
+test_eq crosslink-delta-to-delta-mlink [fossil_sql "SELECT group_concat(
534528
name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
535529
WHERE mlink.fnid=filename.fnid
536530
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM3')
537531
ORDER BY name)"] {a.txt:1 c.txt:0 d.txt:1 e.txt:1}
538532
@@ -541,11 +535,11 @@
541535
F a.txt $crosslinkFa
542536
F e.txt $crosslinkFb
543537
P $crosslinkM3
544538
U alice
545539
"]
546
-test_eq crosslink-full-after-delta-mlink [crosslink_sql "SELECT group_concat(
540
+test_eq crosslink-full-after-delta-mlink [fossil_sql "SELECT group_concat(
547541
name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
548542
WHERE mlink.fnid=filename.fnid
549543
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')
550544
ORDER BY name)"] {a.txt:1 d.txt:0 e.txt:1 l.txt:0}
551545
@@ -584,11 +578,11 @@
584578
F a.txt $crosslinkFa
585579
P $crosslinkM1
586580
U alice
587581
"]
588582
test crosslink-missing-baseline {$CODE == 0 && $crosslinkBad ne ""}
589
-test_eq crosslink-missing-baseline-no-event [crosslink_sql "SELECT count(*)
583
+test_eq crosslink-missing-baseline-no-event [fossil_sql "SELECT count(*)
590584
FROM event WHERE comment='crosslink-no-baseline'"] 0
591585
592586
# A check-in whose parent is that one is still shown; its files cannot be
593587
# compared with the parent's.
594588
set crosslinkM6 [crosslink_put "C crosslink-child-of-no-baseline
@@ -599,33 +593,33 @@
599593
"]
600594
test_eq crosslink-child-of-missing-baseline [crosslink_event $crosslinkM6] \
601595
{ci crosslink-child-of-no-baseline}
602596
603597
write_file not-an-artifact.txt "This is a file.\n"
604
-set crosslinkEvents [crosslink_sql "SELECT count(*) FROM event"]
598
+set crosslinkEvents [fossil_sql "SELECT count(*) FROM event"]
605599
fossil test-content-put --crosslink not-an-artifact.txt
606600
test crosslink-not-an-artifact {$CODE == 0}
607601
test_eq crosslink-not-an-artifact-no-event \
608
- [crosslink_sql "SELECT count(*) FROM event"] $crosslinkEvents
602
+ [fossil_sql "SELECT count(*) FROM event"] $crosslinkEvents
609603
610604
###############################################################################
611605
# The "parent" tag gives a check-in other parents; a bad value is ignored.
612606
613607
fossil reparent $crosslinkM4 $crosslinkC1 $crosslinkM2
614608
test crosslink-reparent {$CODE == 0}
615
-test_eq crosslink-reparent-plink [crosslink_sql "SELECT count(*) FROM plink
609
+test_eq crosslink-reparent-plink [fossil_sql "SELECT count(*) FROM plink
616610
WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')"] 2
617
-test_eq crosslink-reparent-primary [crosslink_sql "SELECT uuid FROM plink,
611
+test_eq crosslink-reparent-primary [fossil_sql "SELECT uuid FROM plink,
618612
blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
619613
WHERE uuid='$crosslinkM4')"] $crosslinkC1
620614
621
-set crosslinkG [crosslink_put "D 2026-01-08T10:00:00.000
615
+crosslink_put "D 2026-01-08T10:00:00.000
622616
T +parent $crosslinkM3 not-a-hash
623617
U alice
624
-"]
618
+"
625619
test crosslink-reparent-bad-value {$CODE == 0}
626
-test_eq crosslink-reparent-bad-value-ignored [crosslink_sql "SELECT uuid
620
+test_eq crosslink-reparent-bad-value-ignored [fossil_sql "SELECT uuid
627621
FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
628622
WHERE uuid='$crosslinkM3')"] $crosslinkM2
629623
630624
# A value of good hashes followed by a short word is ignored as a whole,
631625
# both when the tag arrives and when a rebuild reads it again.
@@ -638,54 +632,57 @@
638632
set crosslinkG [crosslink_put "D 2026-01-08T10:0[incr crosslinkI]:00.000
639633
T +parent $crosslinkM3 $crosslinkValue
640634
U alice
641635
"]
642636
test crosslink-reparent-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
643
- test_eq crosslink-reparent-$crosslinkName-ignored [crosslink_sql "SELECT
637
+ test_eq crosslink-reparent-$crosslinkName-ignored [fossil_sql "SELECT
644638
uuid FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid
645639
FROM blob WHERE uuid='$crosslinkM3')"] $crosslinkM2
646640
}
647641
fossil rebuild
648642
test crosslink-reparent-short-rebuild {$CODE == 0}
649
-test_eq crosslink-reparent-short-rebuild-ignored [crosslink_sql "SELECT uuid
643
+test_eq crosslink-reparent-short-rebuild-ignored [fossil_sql "SELECT uuid
650644
FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
651645
WHERE uuid='$crosslinkM3')"] $crosslinkM2
652646
653647
###############################################################################
654648
# A cluster removes its members from the list of unclustered artifacts.
655649
656
-set crosslinkBefore [crosslink_sql "SELECT count(*) FROM unclustered"]
650
+set crosslinkBefore [fossil_sql "SELECT count(*) FROM unclustered"]
657651
set crosslinkCl ""
658652
foreach crosslinkHash [lsort [list $crosslinkC1 $crosslinkM1 $crosslinkNone2]] {
659653
append crosslinkCl "M $crosslinkHash\n"
660654
}
661655
set crosslinkCl [crosslink_put $crosslinkCl]
662656
test crosslink-cluster {$CODE == 0 && $crosslinkCl ne ""}
663
-test_eq crosslink-cluster-tag [crosslink_sql "SELECT count(*) FROM tagxref
657
+test_eq crosslink-cluster-tag [fossil_sql "SELECT count(*) FROM tagxref
664658
WHERE tagid=(SELECT tagid FROM tag WHERE tagname='cluster')
665659
AND rid=(SELECT rid FROM blob WHERE uuid='$crosslinkCl')"] 1
666660
test crosslink-cluster-unclustered \
667
- {[crosslink_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1}
661
+ {[fossil_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1}
668662
669663
###############################################################################
670664
# The JSON form of each kind of artifact.
671665
672666
foreach {crosslinkKind crosslinkHash crosslinkWant} [list \
673
- wiki $crosslinkW2 {*"type":"wiki"*"L":"Crosslink Page"*"N":"text/x-markdown"*"P":*"W":*} \
674
- technote $crosslinkE1 {*"type":"technote"*"C":"First note"*"E":*"T":*"W":*} \
667
+ wiki $crosslinkW2 \
668
+ {*"type":"wiki"*"L":"Crosslink Page"*"N":"text/x-markdown"*"P":*"W":*} \
669
+ technote $crosslinkE1 \
670
+ {*"type":"technote"*"C":"First note"*"E":*"T":*"W":*} \
675671
ticket $crosslinkT5 {*"type":"ticket"*"J":*"append":true*"K":*} \
676672
ticket2 $crosslinkT2 {*"type":"ticket"*"J":*"append":false*} \
677673
forum $crosslinkF3 {*"type":"forumpost"*"G":*"I":*"P":*"W":*} \
678674
forum2 $crosslinkF5 {*"type":"forumpost"*"H":"New title"*} \
679675
attachment "" {*"type":"attachment"*"A":*} \
680676
tag $crosslinkG {*"type":"tag"*"T":*} \
681
- checkin $crosslinkM1 {*"type":"checkin"*"C":"crosslink-c2"*"F":*"perm":"x"*"P":*"Q":*"T":*"U":"alice"*} \
677
+ checkin $crosslinkM1 \
678
+ {*"type":"checkin"*"C":"crosslink-c2"*"F":*"perm":"x"*"P":*"Q":*"T":*"U":"alice"*} \
682679
delta $crosslinkM2 {*"type":"checkin"*"B":*"F":*} \
683680
cluster $crosslinkCl {*"type":"cluster"*"M":*} \
684681
] {
685682
if {$crosslinkHash eq ""} {
686
- set crosslinkHash [string trim [crosslink_sql "SELECT uuid FROM blob,
683
+ set crosslinkHash [string trim [fossil_sql "SELECT uuid FROM blob,
687684
attachment WHERE rid=attachid ORDER BY rid LIMIT 1"] ']
688685
}
689686
fossil test-artifact-to-json $crosslinkHash
690687
test crosslink-json-$crosslinkKind {$CODE == 0}
691688
crosslink_match crosslink-json-$crosslinkKind-text $RESULT $crosslinkWant
@@ -703,23 +700,23 @@
703700
fossil test-artifact-to-json $crosslinkFa no-such-name -expectError
704701
test crosslink-json-not-artifact {$CODE != 0}
705702
706703
# The same through SQL: by hash, by record number, and with arguments
707704
# that name nothing.
708
-crosslink_match crosslink-json-sql-name [crosslink_sql \
705
+crosslink_match crosslink-json-sql-name [fossil_sql \
709706
"SELECT artifact_to_json('$crosslinkW1')"] {*"type":"wiki"*}
710
-crosslink_match crosslink-json-sql-rid [crosslink_sql "SELECT artifact_to_json(
707
+crosslink_match crosslink-json-sql-rid [fossil_sql "SELECT artifact_to_json(
711708
(SELECT rid FROM blob WHERE uuid='$crosslinkW1'))"] {*"type":"wiki"*}
712
-test_eq crosslink-json-sql-data [crosslink_sql \
709
+test_eq crosslink-json-sql-data [fossil_sql \
713710
"SELECT artifact_to_json('$crosslinkFa') IS NULL"] 1
714711
fossil sql "SELECT artifact_to_json(NULL)" -expectError
715712
test crosslink-json-sql-null {$CODE != 0}
716713
crosslink_match crosslink-json-sql-null-message $RESULT \
717714
{*Expecting one argument*}
718715
fossil sql "SELECT artifact_to_json(1.5)" -expectError
719716
test crosslink-json-sql-float {$CODE != 0}
720
-test_eq crosslink-json-sql-zero [crosslink_sql \
717
+test_eq crosslink-json-sql-zero [fossil_sql \
721718
"SELECT artifact_to_json(0) IS NULL"] 1
722719
fossil sql "SELECT artifact_to_json()" -expectError
723720
test crosslink-json-sql-no-argument {$CODE != 0}
724721
725722
###############################################################################
@@ -734,20 +731,30 @@
734731
first-line-not-a-card "1 x\nD 2026-02-01T10:00:00.000\n" \
735732
{*line 1 not recognized*} \
736733
control-tags-itself "D 2026-02-01T10:00:00.000\nT +sym-x *\nU alice\n" \
737734
{*self-referential T-card in control artifact*} \
738735
technote-tags-another \
739
- "D 2026-02-01T10:00:00.000\nE 2026-02-01T09:00:00 $crosslinkH40\nT +sym-x $crosslinkH40\nU alice\nW 1\nx\n" \
736
+ [join [list \
737
+ "D 2026-02-01T10:00:00.000\n" \
738
+ "E 2026-02-01T09:00:00 $crosslinkH40\n" \
739
+ "T +sym-x $crosslinkH40\nU alice\nW 1\nx\n"] ""] \
740740
{*non-self-referential T-card in technote*} \
741741
technote-propagating-tag \
742
- "D 2026-02-01T10:00:00.000\nE 2026-02-01T09:00:00 $crosslinkH40\nT *sym-x *\nU alice\nW 1\nx\n" \
742
+ [join [list \
743
+ "D 2026-02-01T10:00:00.000\n" \
744
+ "E 2026-02-01T09:00:00 $crosslinkH40\nT *sym-x *\nU alice\n" \
745
+ "W 1\nx\n"] ""] \
743746
{*T-card with '\*' or '-' in technote*} \
744747
forum-title-on-reply \
745
- "D 2026-02-01T10:00:00.000\nG $crosslinkH40\nH title\nI $crosslinkH40\nU alice\nW 1\nx\n" \
748
+ [join [list \
749
+ "D 2026-02-01T10:00:00.000\nG $crosslinkH40\nH title\n" \
750
+ "I $crosslinkH40\nU alice\nW 1\nx\n"] ""] \
746751
{*cannot have I-card and H-card in a forum post*} \
747752
forum-two-parents \
748
- "D 2026-02-01T10:00:00.000\nG $crosslinkH40\nP $crosslinkH40 $crosslinkNone\nU alice\nW 1\nx\n" \
753
+ [join [list \
754
+ "D 2026-02-01T10:00:00.000\nG $crosslinkH40\n" \
755
+ "P $crosslinkH40 $crosslinkNone\nU alice\nW 1\nx\n"] ""] \
749756
{*too many arguments to P-card*} \
750757
] {
751758
fossil test-parse-manifest [crosslink_file $crosslinkBody]
752759
test crosslink-refuse-$crosslinkName {$CODE == 0}
753760
crosslink_match crosslink-refuse-$crosslinkName-reason $RESULT \
@@ -775,14 +782,19 @@
775782
{*manifest_parse() worked*}
776783
777784
# A tech note may have its N card after its P card, as old versions of
778785
# Fossil wrote it. A file with a reserved name in a check-in is left out.
779786
fossil test-parse-manifest [crosslink_file \
780
- "D 2026-02-01T10:00:00.000\nE 2026-02-01T09:00:00 $crosslinkH40\nP $crosslinkH40\nN text/plain\nU alice\nW 1\nx\n"]
787
+ [join [list \
788
+ "D 2026-02-01T10:00:00.000\n" \
789
+ "E 2026-02-01T09:00:00 $crosslinkH40\nP $crosslinkH40\n" \
790
+ "N text/plain\nU alice\nW 1\nx\n"] ""]]
781791
crosslink_match crosslink-technote-n-after-p $RESULT {*manifest_parse() worked*}
782792
fossil test-parse-manifest [crosslink_file \
783
- "C reserved\nD 2026-02-01T10:00:00.000\nF _FOSSIL_ $crosslinkH40\nF a.txt $crosslinkH40\nU alice\n"] 2
793
+ [join [list \
794
+ "C reserved\nD 2026-02-01T10:00:00.000\n" \
795
+ "F _FOSSIL_ $crosslinkH40\nF a.txt $crosslinkH40\nU alice\n"] ""]] 2
784796
crosslink_match crosslink-reserved-name-ignored $RESULT \
785797
{*manifest_parse() worked*}
786798
787799
# Content that is not an artifact but begins like one. The quick check
788800
# and the parser must agree about each.
@@ -792,11 +804,11 @@
792804
no-newline "D 2026-02-01T10:00:00.000 and no end of line" \
793805
one-card "D x\n" \
794806
short "D\n" \
795807
second-lower "D 2026-02-01T10:00:00.000\nlower case\n" \
796808
second-earlier "D 2026-02-01T10:00:00.000\nC comment\nmore text here\n" \
797
- no-space "D 2026-02-01T10:00:00.000\nUalice and more\n" \
809
+ second-no-space "D 2026-02-01T10:00:00.000\nUalice and more\n" \
798810
late-letter "N text/plain\nU alice and more\n" \
799811
] {
800812
write_file wf-$crosslinkName.txt $crosslinkText
801813
fossil test-content-put wf-$crosslinkName.txt
802814
test crosslink-not-wellformed-$crosslinkName {$CODE == 0}
@@ -810,23 +822,23 @@
810822
crosslink_match crosslink-wiki-is-not-a-checkin-message $RESULT \
811823
{*not a valid check-in*}
812824
813825
# Wiki text and a tech note that begin with blank space, and crosslinking
814826
# with SQL tracing on.
815
-set crosslinkW5 [crosslink_put "D 2026-02-02T10:00:00.000
827
+crosslink_put "D 2026-02-02T10:00:00.000
816828
L Indented
817829
U alice
818
-[crosslink_w "\n\n indented"]"]
819
-test_eq crosslink-wiki-leading-space-length [crosslink_sql "SELECT value
830
+[crosslink_w "\n\n indented"]"
831
+test_eq crosslink-wiki-leading-space-length [fossil_sql "SELECT value
820832
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
821833
AND tagname='wiki-Indented'"] 8
822
-set crosslinkE4 [crosslink_put "C Indented\\snote
834
+crosslink_put "C Indented\\snote
823835
D 2026-02-02T11:00:00.000
824836
E 2026-02-02T09:00:00 [string repeat 12 20]
825837
U alice
826
-[crosslink_w "\n note"]"]
827
-test_eq crosslink-technote-leading-space-length [crosslink_sql "SELECT value
838
+[crosslink_w "\n note"]"
839
+test_eq crosslink-technote-leading-space-length [fossil_sql "SELECT value
828840
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
829841
AND tagname='event-[string repeat 12 20]'"] 4
830842
fossil_raw test-crosslink $crosslinkW1 --sqltrace
831843
test crosslink-sqltrace {$CODE == 0}
832844
crosslink_match crosslink-sqltrace-text $RESULT {*-- manifest_crosslink(*}
@@ -853,19 +865,20 @@
853865
crosslink_match crosslink-parse-all-text $RESULT {*tests with 0 errors*}
854866
fossil test-parse-all-blobs --limit 3
855867
crosslink_match crosslink-parse-all-limit $RESULT {*3 tests with 0 errors*}
856868
fossil test-parse-all-blobs --wellformed
857869
test crosslink-parse-all-wellformed {$CODE == 0}
858
-crosslink_match crosslink-parse-all-wellformed-text $RESULT {*tests with 0 errors*}
870
+crosslink_match crosslink-parse-all-wellformed-text $RESULT \
871
+ {*tests with 0 errors*}
859872
860873
# Crosslinking an artifact a second time changes nothing.
861
-set crosslinkEvents [crosslink_sql "SELECT count(*) FROM event"]
874
+set crosslinkEvents [fossil_sql "SELECT count(*) FROM event"]
862875
fossil test-crosslink $crosslinkM1
863876
test crosslink-again {$CODE == 0}
864877
fossil test-crosslink $crosslinkW1
865878
test crosslink-again-wiki {$CODE == 0}
866
-test_eq crosslink-again-events [crosslink_sql "SELECT count(*) FROM event"] \
879
+test_eq crosslink-again-events [fossil_sql "SELECT count(*) FROM event"] \
867880
$crosslinkEvents
868881
fossil test-crosslink -expectError
869882
test crosslink-usage {$CODE != 0}
870883
871884
###############################################################################
@@ -875,18 +888,18 @@
875888
(SELECT count(*) FROM attachment) || ' ' ||
876889
(SELECT count(*) FROM forumpost) || ' ' ||
877890
(SELECT count(*) FROM plink) || ' ' ||
878891
(SELECT count(*) FROM mlink) || ' ' ||
879892
(SELECT count(*) FROM ticket)}
880
-set crosslinkBefore [crosslink_sql $crosslinkState]
881
-set crosslinkText [crosslink_sql "SELECT group_concat(x, char(10)) FROM
893
+set crosslinkBefore [fossil_sql $crosslinkState]
894
+set crosslinkText [fossil_sql "SELECT group_concat(x, char(10)) FROM
882895
(SELECT type || ' ' || comment AS x FROM event ORDER BY type, objid)"]
883896
fossil rebuild
884897
test crosslink-rebuild {$CODE == 0}
885
-test_eq crosslink-rebuild-same-counts [crosslink_sql $crosslinkState] \
898
+test_eq crosslink-rebuild-same-counts [fossil_sql $crosslinkState] \
886899
$crosslinkBefore
887
-test_eq crosslink-rebuild-same-events [crosslink_sql "SELECT
900
+test_eq crosslink-rebuild-same-events [fossil_sql "SELECT
888901
group_concat(x, char(10)) FROM (SELECT type || ' ' || comment AS x
889902
FROM event ORDER BY type, objid)"] $crosslinkText
890903
fossil test-integrity
891904
test crosslink-integrity {$CODE == 0}
892905
@@ -903,11 +916,11 @@
903916
none "D 2026-03-01T10:03:00.000\nT +sym-kind-test $crosslinkC1\nU alice\n" \
904917
control \
905918
] {
906919
set crosslinkHash [crosslink_put $crosslinkBody]
907920
test crosslink-mcdc-kind-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
908
- test_eq crosslink-mcdc-kind-$crosslinkName-event [crosslink_sql "SELECT
921
+ test_eq crosslink-mcdc-kind-$crosslinkName-event [fossil_sql "SELECT
909922
count(*) FROM event, blob WHERE objid=rid AND uuid='$crosslinkHash'
910923
AND type='ci'"] [expr {$crosslinkKind eq "ci" ? 1 : 0}]
911924
fossil test-parse-manifest [crosslink_file $crosslinkBody]
912925
crosslink_match crosslink-mcdc-kind-$crosslinkName-parse $RESULT \
913926
{*manifest_parse() worked*}
@@ -920,25 +933,29 @@
920933
# first parent arrives. A merge parent that arrives while the first
921934
# parent is present adds them at once.
922935
923936
# The hash a check-in with the cards BODY will have, without storing it.
924937
proc crosslink_hash {body} {
925
- global RESULT
926
- fossil sha3sum [crosslink_file $body]
927
- return [lindex $RESULT 0]
938
+ return [sha3_file [crosslink_file $body]]
928939
}
929940
930941
# The number of file links that join the check-in CHILD to its parent
931942
# PARENT.
932943
proc crosslink_links {child parent} {
933
- return [crosslink_sql "SELECT count(*) FROM mlink WHERE
944
+ return [fossil_sql "SELECT count(*) FROM mlink WHERE
934945
mid=(SELECT rid FROM blob WHERE uuid='$child')
935946
AND pmid=(SELECT rid FROM blob WHERE uuid='$parent')"]
936947
}
937948
938
-set crosslinkPA [crosslink_hash "C first\\sparent\nD 2026-03-02T10:00:00.000\nF a.txt $crosslinkFa\nU alice\n"]
939
-set crosslinkPB [crosslink_hash "C second\\sparent\nD 2026-03-02T10:01:00.000\nF a.txt $crosslinkFb\nU alice\n"]
949
+set crosslinkPA [crosslink_hash \
950
+ [join [list \
951
+ "C first\\sparent\nD 2026-03-02T10:00:00.000\n" \
952
+ "F a.txt $crosslinkFa\nU alice\n"] ""]]
953
+set crosslinkPB [crosslink_hash \
954
+ [join [list \
955
+ "C second\\sparent\nD 2026-03-02T10:01:00.000\n" \
956
+ "F a.txt $crosslinkFb\nU alice\n"] ""]]
940957
set crosslinkKid [crosslink_put "C merge\\skid
941958
D 2026-03-02T11:00:00.000
942959
F a.txt $crosslinkNone
943960
P $crosslinkPA $crosslinkPB
944961
U alice
@@ -967,12 +984,18 @@
967984
test_eq crosslink-mcdc-merge-parent-second-links \
968985
[list [crosslink_links $crosslinkKid $crosslinkPA] \
969986
[crosslink_links $crosslinkKid $crosslinkPB]] {1 1}
970987
971988
# The first parent present, the second arriving later.
972
-set crosslinkQA [crosslink_hash "C other\\sfirst\nD 2026-03-02T12:00:00.000\nF a.txt $crosslinkFa\nU alice\n"]
973
-set crosslinkQB [crosslink_hash "C other\\ssecond\nD 2026-03-02T12:01:00.000\nF a.txt $crosslinkFb\nU alice\n"]
989
+set crosslinkQA [crosslink_hash \
990
+ [join [list \
991
+ "C other\\sfirst\nD 2026-03-02T12:00:00.000\n" \
992
+ "F a.txt $crosslinkFa\nU alice\n"] ""]]
993
+set crosslinkQB [crosslink_hash \
994
+ [join [list \
995
+ "C other\\ssecond\nD 2026-03-02T12:01:00.000\n" \
996
+ "F a.txt $crosslinkFb\nU alice\n"] ""]]
974997
crosslink_put "C other\\sfirst
975998
D 2026-03-02T12:00:00.000
976999
F a.txt $crosslinkFa
9771000
U alice
9781001
"
@@ -998,15 +1021,17 @@
9981021
# An empty title on the first post of a forum thread is shown as deleted,
9991022
# and an empty title or page text is null in the JSON form. Each row
10001023
# differs from the one before in a single card.
10011024
10021025
foreach {crosslinkName crosslinkBody crosslinkWant crosslinkJson} [list \
1003
- title "D 2026-03-03T10:00:00.000\nH Some\\stitle\nU alice\n[crosslink_w {x}]" \
1026
+ title \
1027
+ "D 2026-03-03T10:00:00.000\nH Some\\stitle\nU alice\n[crosslink_w {x}]" \
10041028
{f Post: Some title} {*"H":"Some title"*"W":"x"*} \
10051029
empty-title "D 2026-03-03T10:01:00.000\nH \nU alice\n[crosslink_w {x}]" \
10061030
{f Post: (Deleted)} {*"H":null*"W":"x"*} \
1007
- empty-text "D 2026-03-03T10:02:00.000\nH Some\\stitle\nU alice\n[crosslink_w {}]" \
1031
+ empty-text \
1032
+ "D 2026-03-03T10:02:00.000\nH Some\\stitle\nU alice\n[crosslink_w {}]" \
10081033
{f Post: Some title} {*"H":"Some title"*"W":null*} \
10091034
] {
10101035
set crosslinkHash [crosslink_put $crosslinkBody]
10111036
test crosslink-mcdc-forum-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
10121037
test_eq crosslink-mcdc-forum-$crosslinkName-event \
@@ -1016,11 +1041,12 @@
10161041
$crosslinkJson
10171042
}
10181043
10191044
# A wiki page with no text has a null W card in JSON.
10201045
fossil test-artifact-to-json $crosslinkW3
1021
-crosslink_match crosslink-mcdc-json-empty-wiki $RESULT {*"type":"wiki"*"W":null*}
1046
+crosslink_match crosslink-mcdc-json-empty-wiki $RESULT \
1047
+ {*"type":"wiki"*"W":null*}
10221048
10231049
###############################################################################
10241050
# A tag card whose value is empty reads like one with no value.
10251051
10261052
set crosslinkMin 10
@@ -1055,25 +1081,21 @@
10551081
"]
10561082
test crosslink-mcdc-cherry-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
10571083
test_eq crosslink-mcdc-cherry-$crosslinkName-event \
10581084
[crosslink_event $crosslinkHash] "ci cherry-$crosslinkName"
10591085
}
1060
-test_eq crosslink-mcdc-cherry-unseen-not-stored [crosslink_sql "SELECT count(*)
1086
+test_eq crosslink-mcdc-cherry-unseen-not-stored [fossil_sql "SELECT count(*)
10611087
FROM blob WHERE uuid='$crosslinkUnseen'"] 0
10621088
10631089
###############################################################################
10641090
# The information page of a wiki page, asked for by the name of something
10651091
# that is not a wiki page: a check-in, a ticket, a forum post, a file, and
10661092
# a hash that names nothing.
10671093
10681094
proc crosslink_get {path} {
1069
- write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n"
1070
- file delete reply.txt
1071
- fossil_raw http [file join [pwd] .rep.fossil] --in request.txt \
1072
- --out reply.txt --ipaddr 127.0.0.1 --localauth
1073
- if {[file exists reply.txt]} { return [read_file reply.txt] }
1074
- return ""
1095
+ return [fossil_http [file join [pwd] .rep.fossil] [request_get $path] \
1096
+ --ipaddr 127.0.0.1 --localauth]
10751097
}
10761098
10771099
foreach {crosslinkName crosslinkHash crosslinkIs} [list \
10781100
wiki $crosslinkW1 1 \
10791101
checkin $crosslinkC1 0 \
@@ -1102,11 +1124,11 @@
11021124
F l.txt $crosslinkFa l
11031125
P $crosslinkM2
11041126
U alice
11051127
"]
11061128
test crosslink-mcdc-back-after-delta {$CODE == 0 && $crosslinkBack ne ""}
1107
-test_eq crosslink-mcdc-back-after-delta-mlink [crosslink_sql "SELECT
1129
+test_eq crosslink-mcdc-back-after-delta-mlink [fossil_sql "SELECT
11081130
group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
11091131
pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
11101132
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkBack')
11111133
ORDER BY name)"] {a.txt:0:1 c.txt:1:0 d.txt:1:0}
11121134
@@ -1129,11 +1151,11 @@
11291151
D 2026-03-07T10:01:00.000
11301152
F a.txt $crosslinkFa x
11311153
P $crosslinkGhost
11321154
U alice
11331155
"]
1134
-test_eq crosslink-mcdc-delta-removes-unknown-child-mlink [crosslink_sql "SELECT
1156
+test_eq crosslink-mcdc-delta-removes-unknown-child-mlink [fossil_sql "SELECT
11351157
group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
11361158
pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
11371159
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
11381160
ORDER BY name)"] {c.txt:1:0 l.txt:1:0}
11391161
@@ -1155,11 +1177,11 @@
11551177
set crosslinkG [crosslink_put "D 2026-03-07T11:01:00.000
11561178
T +parent $crosslinkKid3 $crosslinkM1
11571179
U alice
11581180
"]
11591181
test crosslink-mcdc-reparent-no-baseline-tag {$CODE == 0 && $crosslinkG ne ""}
1160
-test_eq crosslink-mcdc-reparent-no-baseline-plink [crosslink_sql "SELECT count(*)
1182
+test_eq crosslink-mcdc-reparent-no-baseline-plink [fossil_sql "SELECT count(*)
11611183
FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkKid3')
11621184
AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')"] 1
11631185
test_eq crosslink-mcdc-reparent-no-baseline-no-links \
11641186
[crosslink_links $crosslinkKid3 $crosslinkM1] 0
11651187
@@ -1181,25 +1203,26 @@
11811203
P $crosslinkC1
11821204
U alice
11831205
"]
11841206
fossil test-content-put --crosslink $crosslinkOnWiki $crosslinkBasedOnWiki
11851207
test crosslink-mcdc-wiki-baseline {$CODE == 0}
1186
-test_eq crosslink-mcdc-wiki-baseline-events [crosslink_sql "SELECT
1208
+test_eq crosslink-mcdc-wiki-baseline-events [fossil_sql "SELECT
11871209
group_concat(comment, ' ') FROM event WHERE type='ci'
11881210
AND comment IN ('child-of-wiki-page','based-on-wiki-page')"] \
11891211
{child-of-wiki-page}
11901212
fossil sha3sum $crosslinkBasedOnWiki
1191
-test_eq crosslink-mcdc-wiki-baseline-waiting [crosslink_sql "SELECT count(*)
1213
+test_eq crosslink-mcdc-wiki-baseline-waiting [fossil_sql "SELECT count(*)
11921214
FROM orphan WHERE rid=(SELECT rid FROM blob
11931215
WHERE uuid='[lindex $RESULT 0]')
11941216
AND baseline=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
11951217
11961218
###############################################################################
11971219
# Scripts that run when artifacts are stored by a command.
11981220
#
11991221
# A script for check-ins can ask for the JSON form of the parent of a
1200
-# check-in that "branch new" makes. A common script that fails makes "ticket add"
1222
+# check-in that "branch new" makes. A common script that fails makes "ticket
1223
+# add"
12011224
# fail, after the ticket has been entered. A tag put on a wiki page by
12021225
# "tag add" is recorded like a tag on a check-in.
12031226
12041227
proc crosslink_script {name script} {
12051228
if {$script eq ""} {
@@ -1214,32 +1237,32 @@
12141237
FROM plink, blob WHERE cid=blob.rid AND blob.uuid=$uuid} {puts "PARENT $j"}}
12151238
fossil branch new scripted $crosslinkM1
12161239
test crosslink-mcdc-script-branch {$CODE == 0}
12171240
crosslink_match crosslink-mcdc-script-branch-parent-json $RESULT \
12181241
{*PARENT *&quot;type&quot;:&quot;checkin&quot;*&quot;C&quot;:&quot;crosslink-c2&quot;*}
1219
-test_eq crosslink-mcdc-script-branch-made [crosslink_sql "SELECT count(*)
1242
+test_eq crosslink-mcdc-script-branch-made [fossil_sql "SELECT count(*)
12201243
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
12211244
AND tagname='sym-scripted'"] 1
12221245
crosslink_script xfer-commit-script ""
12231246
1224
-set crosslinkTickets [crosslink_sql "SELECT count(*) FROM ticket"]
1247
+set crosslinkTickets [fossil_sql "SELECT count(*) FROM ticket"]
12251248
crosslink_script xfer-common-script {error common-script-says-no}
12261249
fossil ticket add title Scripted status Open -expectError
12271250
test crosslink-mcdc-script-ticket-fails {$CODE != 0}
12281251
crosslink_match crosslink-mcdc-script-ticket-message $RESULT \
12291252
{*common-script-says-no*}
1230
-test_eq crosslink-mcdc-script-ticket-entered [crosslink_sql "SELECT count(*)
1253
+test_eq crosslink-mcdc-script-ticket-entered [fossil_sql "SELECT count(*)
12311254
FROM ticket WHERE title='Scripted'"] 1
12321255
crosslink_script xfer-common-script ""
12331256
fossil ticket add title Unscripted status Open
12341257
test crosslink-mcdc-no-script-ticket {$CODE == 0}
1235
-test_eq crosslink-mcdc-no-script-ticket-count [crosslink_sql "SELECT count(*)
1258
+test_eq crosslink-mcdc-no-script-ticket-count [fossil_sql "SELECT count(*)
12361259
FROM ticket"] [expr {$crosslinkTickets + 2}]
12371260
12381261
fossil tag add on-a-wiki-page $crosslinkW1
12391262
test crosslink-mcdc-tag-add-wiki {$CODE == 0}
1240
-crosslink_match crosslink-mcdc-tag-add-wiki-event [crosslink_sql "SELECT comment
1263
+crosslink_match crosslink-mcdc-tag-add-wiki-event [fossil_sql "SELECT comment
12411264
FROM event WHERE type='g' AND comment LIKE '%on-a-wiki-page%'"] \
12421265
"Edit \\\[[string range $crosslinkW1 0 15]|*\\\]: Add *\"on-a-wiki-page\"."
12431266
12441267
###############################################################################
12451268
# A repository made before cherrypicks were recorded has no table for
@@ -1255,15 +1278,15 @@
12551278
U alice
12561279
"]
12571280
test crosslink-mcdc-cherry-no-table {$CODE == 0 && $crosslinkHash ne ""}
12581281
test_eq crosslink-mcdc-cherry-no-table-event [crosslink_event $crosslinkHash] \
12591282
{ci cherry-no-table}
1260
-test_eq crosslink-mcdc-cherry-no-table-still-none [crosslink_sql "SELECT count(*)
1283
+test_eq crosslink-mcdc-cherry-no-table-still-none [fossil_sql "SELECT count(*)
12611284
FROM sqlite_schema WHERE name='cherrypick'"] 0
12621285
fossil rebuild
12631286
test crosslink-mcdc-cherry-rebuild {$CODE == 0}
1264
-test_eq crosslink-mcdc-cherry-rebuild-recorded [crosslink_sql "SELECT count(*)
1287
+test_eq crosslink-mcdc-cherry-rebuild-recorded [fossil_sql "SELECT count(*)
12651288
FROM cherrypick WHERE childid=(SELECT rid FROM blob
12661289
WHERE uuid='$crosslinkHash')"] 1
12671290
12681291
###############################################################################
12691292
# The quick check for an artifact and the parser must agree.
@@ -1331,11 +1354,11 @@
13311354
{$crosslinkR1 ne "" && $crosslinkR2 ne "" && $crosslinkR3 ne ""}
13321355
13331356
# The primary parent of the check-in with the given hash.
13341357
#
13351358
proc crosslink_primary {hash} {
1336
- return [crosslink_sql "SELECT uuid FROM plink, blob WHERE pid=rid
1359
+ return [fossil_sql "SELECT uuid FROM plink, blob WHERE pid=rid
13371360
AND isprim AND cid=(SELECT rid FROM blob WHERE uuid='$hash')"]
13381361
}
13391362
13401363
crosslink_put "D 2026-04-01T11:00:00.000
13411364
T +parent $crosslinkR3 $crosslinkR1\\s
@@ -1360,11 +1383,11 @@
13601383
crosslink_put "D 2026-04-01T11:03:00.000
13611384
T +parent $crosslinkHash $crosslinkR1
13621385
U alice
13631386
"
13641387
test crosslink-reparent-wiki-page {$CODE == 0}
1365
-test_eq crosslink-reparent-wiki-page-no-links [crosslink_sql "SELECT count(*)
1388
+test_eq crosslink-reparent-wiki-page-no-links [fossil_sql "SELECT count(*)
13661389
FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')"] 0
13671390
13681391
###############################################################################
13691392
# A check-in with two parents lists both in its JSON form.
13701393
@@ -1371,11 +1394,11 @@
13711394
set crosslinkHash [crosslink_put "C two-parents-json
13721395
D 2026-04-01T12:00:00.000
13731396
P $crosslinkR3 $crosslinkR1
13741397
U alice
13751398
"]
1376
-test_eq crosslink-json-second-parent [crosslink_sql "SELECT
1399
+test_eq crosslink-json-second-parent [fossil_sql "SELECT
13771400
json_extract(artifact_to_json('$crosslinkHash'), '\$.P\[1\]')"] \
13781401
$crosslinkR1
13791402
13801403
###############################################################################
13811404
# A wiki page with two parents: both are linked, the first as the
@@ -1393,11 +1416,11 @@
13931416
L Two\\sParents
13941417
P $crosslinkWa $crosslinkWb
13951418
U alice
13961419
[crosslink_w {both}]"]
13971420
test crosslink-wiki-two-parents {$CODE == 0 && $crosslinkHash ne ""}
1398
-test_eq crosslink-wiki-two-parents-plink [crosslink_sql "SELECT
1421
+test_eq crosslink-wiki-two-parents-plink [fossil_sql "SELECT
13991422
group_concat(uuid || ':' || isprim, ' ') FROM (SELECT uuid, isprim
14001423
FROM plink, blob WHERE pid=rid AND cid=(SELECT rid FROM blob
14011424
WHERE uuid='$crosslinkHash') ORDER BY isprim DESC)"] \
14021425
"$crosslinkWa:1 $crosslinkWb:0"
14031426
@@ -1410,13 +1433,13 @@
14101433
U alice
14111434
[crosslink_w {text}]Z [string repeat 0 32]\n"
14121435
fossil test-content-put --crosslink bad-z.txt
14131436
test crosslink-bad-z-stored \
14141437
{$CODE == 0 && [regexp {inserted as record (\d+)} $RESULT all crosslinkRid]}
1415
-test_eq crosslink-bad-z-no-event [crosslink_sql "SELECT count(*) FROM event
1438
+test_eq crosslink-bad-z-no-event [fossil_sql "SELECT count(*) FROM event
14161439
WHERE objid=$crosslinkRid"] 0
1417
-test_eq crosslink-bad-z-no-page [crosslink_sql "SELECT count(*) FROM tag
1440
+test_eq crosslink-bad-z-no-page [fossil_sql "SELECT count(*) FROM tag
14181441
WHERE tagname='wiki-Bad Sum'"] 0
14191442
14201443
###############################################################################
14211444
# A version of a tech note that arrives after a later version of the same
14221445
# note, and names the first version as its parent, does not replace the
@@ -1439,11 +1462,11 @@
14391462
E 2026-04-03T09:00:00 $crosslinkEid2
14401463
P $crosslinkHash
14411464
U alice
14421465
[crosslink_w {middle}]"
14431466
test crosslink-technote-middle-arrives-last {$CODE == 0}
1444
-test_eq crosslink-technote-middle-arrives-last-event [crosslink_sql "SELECT
1467
+test_eq crosslink-technote-middle-arrives-last-event [fossil_sql "SELECT
14451468
comment FROM event WHERE type='e' AND comment LIKE 'note-%'"] {note-last}
14461469
14471470
###############################################################################
14481471
# Two delta manifests on one baseline, the second a child of the first.
14491472
# The first changes a.txt, removes b.txt and adds x.txt. The second
@@ -1473,11 +1496,11 @@
14731496
U alice
14741497
"]
14751498
test crosslink-two-deltas {$CODE == 0 && $crosslinkHash ne ""}
14761499
test_eq crosslink-two-deltas-event [crosslink_event $crosslinkHash] \
14771500
{ci two-deltas-child}
1478
-test_eq crosslink-two-deltas-mlink [crosslink_sql "SELECT
1501
+test_eq crosslink-two-deltas-mlink [fossil_sql "SELECT
14791502
group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
14801503
pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
14811504
AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
14821505
ORDER BY name)"] {a.txt:1:1}
14831506
@@ -1497,16 +1520,16 @@
14971520
set crosslinkPrev [lindex $RESULT 0]
14981521
lappend crosslinkFiles $crosslinkFn
14991522
}
15001523
fossil test-content-put --crosslink {*}$crosslinkFiles
15011524
test crosslink-same-second {$CODE == 0}
1502
-test_eq crosslink-same-second-events [crosslink_sql "SELECT count(*)
1525
+test_eq crosslink-same-second-events [fossil_sql "SELECT count(*)
15031526
FROM event WHERE comment LIKE 'same-second-%'"] 33
1504
-test_eq crosslink-same-second-order [crosslink_sql "SELECT count(*)
1527
+test_eq crosslink-same-second-order [fossil_sql "SELECT count(*)
15051528
FROM plink, event AS p, event AS c WHERE p.objid=pid AND c.objid=cid
15061529
AND c.comment LIKE 'same-second-%' AND p.mtime<c.mtime"] 30
1507
-test_eq crosslink-same-second-tip-time [crosslink_sql "SELECT
1530
+test_eq crosslink-same-second-tip-time [fossil_sql "SELECT
15081531
strftime('%Y-%m-%d %H:%M:%f', mtime) FROM event
15091532
WHERE comment='same-second-32'"] {2026-04-05 10:00:00.000}
15101533
15111534
###############################################################################
15121535
# A delta manifest whose baseline is missing, received by a pull: it is
@@ -1543,16 +1566,16 @@
15431566
fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$crosslinkShun',0)"
15441567
set crosslinkHash [crosslink_put "C shun-clustered
15451568
D 2026-04-07T10:00:00.000
15461569
U alice
15471570
"]
1548
-test_eq crosslink-shun-unclustered-before [crosslink_sql "SELECT count(*)
1571
+test_eq crosslink-shun-unclustered-before [fossil_sql "SELECT count(*)
15491572
FROM unclustered, blob WHERE unclustered.rid=blob.rid
15501573
AND uuid='$crosslinkHash'"] 1
15511574
crosslink_put [join [lsort [list "M $crosslinkShun" "M $crosslinkHash"]] \n]\n
15521575
test crosslink-shun-cluster {$CODE == 0}
1553
-test_eq crosslink-shun-cluster-clears-other [crosslink_sql "SELECT count(*)
1576
+test_eq crosslink-shun-cluster-clears-other [fossil_sql "SELECT count(*)
15541577
FROM unclustered, blob WHERE unclustered.rid=blob.rid
15551578
AND uuid='$crosslinkHash'"] 0
15561579
15571580
set crosslinkG [crosslink_put "D 2026-04-07T10:01:00.000
15581581
T +sym-on-shunned $crosslinkShun
@@ -1559,11 +1582,11 @@
15591582
U alice
15601583
"]
15611584
test crosslink-shun-tag {$CODE == 0 && $crosslinkG ne ""}
15621585
crosslink_match crosslink-shun-tag-event [crosslink_event $crosslinkG] \
15631586
{g Edit \[5e5e5e5e5e5e5e5e|5e5e5e5e5e\]: Add tag "on-shunned".}
1564
-test_eq crosslink-shun-tag-tags-nothing [crosslink_sql "SELECT count(*)
1587
+test_eq crosslink-shun-tag-tags-nothing [fossil_sql "SELECT count(*)
15651588
FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
15661589
AND tagname='sym-on-shunned'"] 0
15671590
15681591
set crosslinkKid [crosslink_put "C shun-merge-kid
15691592
D 2026-04-07T11:00:00.000
@@ -1572,11 +1595,11 @@
15721595
U alice
15731596
"]
15741597
test crosslink-shun-merge-parent {$CODE == 0 && $crosslinkKid ne ""}
15751598
test_eq crosslink-shun-merge-parent-links \
15761599
[crosslink_links $crosslinkKid $crosslinkR1] 1
1577
-test_eq crosslink-shun-no-placeholder [crosslink_sql "SELECT count(*)
1600
+test_eq crosslink-shun-no-placeholder [fossil_sql "SELECT count(*)
15781601
FROM blob WHERE uuid='$crosslinkShun'"] 0
15791602
fossil sql "DELETE FROM shun WHERE uuid='$crosslinkShun'"
15801603
15811604
###############################################################################
15821605
# A common script that fails makes "branch new" fail.
15831606
--- test/crosslink.test
+++ test/crosslink.test
@@ -8,15 +8,12 @@
8 # the ordinary commands never produce: a reply to a forum post, an
9 # attachment whose target is not in the repository, a check-in whose
10 # baseline is missing.
11 #
12
13 # These tests run only in a long pass: -assurance stress.
14 if {[test_assurance] ne "stress"} {
15 test_skip "runs only with -assurance stress"
16 }
17
18 require_no_open_checkout
19
20 test_setup
21
22 set crosslinkSeq 0
@@ -40,18 +37,14 @@
40
41 # Store the artifact whose cards, without the Z card, are $body. Return
42 # its hash, or an empty string if it was not stored. CODE and RESULT are
43 # those of test-content-put.
44 #
45 proc crosslink_put {body {options --crosslink}} {
46 global RESULT CODE
47 set fn [crosslink_file $body]
48 if {$options eq ""} {
49 fossil test-content-put $fn
50 } else {
51 fossil test-content-put $options $fn
52 }
53 set code $CODE
54 set result $RESULT
55 set hash ""
56 if {[regexp {inserted as record (\d+)} $result all rid]} {
57 fossil sql "SELECT uuid FROM blob WHERE rid=$rid"
@@ -73,22 +66,14 @@
73 proc crosslink_match {name actual pattern {constraints ""}} {
74 if {[string match $pattern $actual]} {set pattern $actual}
75 test_eq $name $actual $pattern $constraints
76 }
77
78 # The answer of one SQL statement, trimmed.
79 #
80 proc crosslink_sql {sql} {
81 global RESULT
82 fossil sql $sql
83 return [string trim $RESULT]
84 }
85
86 # The timeline text of the artifact with the given hash.
87 #
88 proc crosslink_event {hash} {
89 return [crosslink_sql "SELECT type || ' ' || comment FROM event, blob\
90 WHERE objid=rid AND uuid='$hash'"]
91 }
92
93 set crosslinkNone [string repeat 0123456789 4]
94 set crosslinkNone2 [string repeat 9876543210 4]
@@ -101,11 +86,11 @@
101 U alice
102 [crosslink_w {first text}]"]
103 test crosslink-wiki-new {$CODE == 0 && $crosslinkW1 ne ""}
104 test_eq crosslink-wiki-new-event [crosslink_event $crosslinkW1] \
105 {w +Crosslink Page}
106 test_eq crosslink-wiki-new-tag [crosslink_sql "SELECT value FROM tagxref, tag
107 WHERE tag.tagid=tagxref.tagid AND tagname='wiki-Crosslink Page'"] {10}
108
109 set crosslinkW2 [crosslink_put "D 2026-01-01T11:00:00.000
110 L Crosslink\\sPage
111 N text/x-markdown
@@ -112,11 +97,11 @@
112 P $crosslinkW1
113 U alice
114 [crosslink_w {second text}]"]
115 test_eq crosslink-wiki-edit-event [crosslink_event $crosslinkW2] \
116 {w :Crosslink Page}
117 test_eq crosslink-wiki-edit-plink [crosslink_sql "SELECT count(*) FROM plink
118 WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkW2')
119 AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
120
121 set crosslinkW3 [crosslink_put "D 2026-01-01T12:00:00.000
122 L Crosslink\\sPage
@@ -147,29 +132,29 @@
147 T +bgcolor * #abcdef
148 T +sym-noted *
149 U alice
150 [crosslink_w {note}]"]
151 test crosslink-technote-new {$CODE == 0 && $crosslinkE1 ne ""}
152 test_eq crosslink-technote-new-event [crosslink_sql "SELECT type, comment,
153 bgcolor FROM event, blob WHERE objid=rid AND uuid='$crosslinkE1'"] \
154 {e|First note|#abcdef}
155
156 set crosslinkE2 [crosslink_put "C Second\\snote
157 D 2026-01-02T11:00:00.000
158 E 2026-01-02T09:00:00 $crosslinkEid
159 P $crosslinkE1
160 U alice
161 [crosslink_w {note2}]"]
162 test_eq crosslink-technote-edit-only-latest [crosslink_sql "SELECT comment
163 FROM event WHERE type='e'"] {Second note}
164
165 set crosslinkE0 [crosslink_put "C Earlier\\snote
166 D 2026-01-02T08:00:00.000
167 E 2026-01-02T09:00:00 $crosslinkEid
168 U alice
169 [crosslink_w {note0}]"]
170 test_eq crosslink-technote-older-arrives-last [crosslink_sql "SELECT comment
171 FROM event WHERE type='e'"] {Second note}
172
173 ###############################################################################
174 # Tickets: a new ticket, a change of status with other fields, a change
175 # without the status, and one with a single field.
@@ -182,30 +167,32 @@
182 U alice
183 "]
184 test crosslink-ticket-new {$CODE == 0 && $crosslinkT1 ne ""}
185 crosslink_match crosslink-ticket-new-event [crosslink_event $crosslinkT1] \
186 {t New ticket *Crosslink ticket*}
187 test_eq crosslink-ticket-new-row [crosslink_sql "SELECT status, title
188 FROM ticket WHERE tkt_uuid='$crosslinkTkt'"] {Open|Crosslink ticket}
189
190 set crosslinkT2 [crosslink_put "D 2026-01-03T11:00:00.000
191 J priority High
192 J severity Minor
193 J status Fixed
194 K $crosslinkTkt
195 U alice
196 "]
197 crosslink_match crosslink-ticket-status-plus-two [crosslink_event $crosslinkT2] \
 
198 {t Fixed ticket * plus 2 other changes}
199
200 set crosslinkT3 [crosslink_put "D 2026-01-03T12:00:00.000
201 J priority Low
202 J status Closed
203 K $crosslinkTkt
204 U alice
205 "]
206 crosslink_match crosslink-ticket-status-plus-one [crosslink_event $crosslinkT3] \
 
207 {t Closed ticket * plus 1 other change}
208
209 set crosslinkT4 [crosslink_put "D 2026-01-03T13:00:00.000
210 J priority Medium
211 J severity Severe
@@ -230,11 +217,11 @@
230 "]
231 crosslink_match crosslink-ticket-status-only [crosslink_event $crosslinkT6] \
232 {t Verified ticket *}
233 test {crosslink-ticket-status-only-no-plus} \
234 {![string match *plus* [crosslink_event $crosslinkT6]]}
235 test_eq crosslink-ticket-events [crosslink_sql "SELECT count(*) FROM event
236 WHERE type='t'"] 6
237
238 ###############################################################################
239 # Forum posts: a thread, an edit of its first post, a reply, an edit of
240 # the reply, a deleted reply, and an older edit of the first post that
@@ -246,11 +233,11 @@
246 U alice
247 [crosslink_w $crosslinkFtext]"]
248 test crosslink-forum-post {$CODE == 0 && $crosslinkF1 ne ""}
249 test_eq crosslink-forum-post-event [crosslink_event $crosslinkF1] \
250 {f Post: Crosslink thread}
251 test_eq crosslink-forum-post-backlink [crosslink_sql "SELECT count(*)
252 FROM backlink WHERE srctype=4
253 AND srcid=(SELECT rid FROM blob WHERE uuid='$crosslinkF1')"] 1
254
255 set crosslinkF2 [crosslink_put "D 2026-01-04T11:00:00.000
256 G $crosslinkF1
@@ -258,11 +245,11 @@
258 N text/x-markdown
259 U bob
260 [crosslink_w {reply}]"]
261 test_eq crosslink-forum-reply-event [crosslink_event $crosslinkF2] \
262 {f Reply: Crosslink thread}
263 test_eq crosslink-forum-reply-row [crosslink_sql "SELECT
264 froot=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'),
265 firt=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'), fprev IS NULL
266 FROM forumpost WHERE fpid=(SELECT rid FROM blob
267 WHERE uuid='$crosslinkF2')"] {1|1|1}
268
@@ -323,10 +310,14 @@
323 I $crosslinkNone
324 U bob
325 [crosslink_w {reply}]"]
326 test_eq crosslink-forum-reply-unknown-thread [crosslink_event $crosslinkF8] \
327 {f Reply: <i>Unknown</i>}
 
 
 
 
328
329 ###############################################################################
330 # Attachments, added to and deleted from each kind of target.
331
332 set crosslinkSrc [string repeat ef 20]
@@ -355,35 +346,35 @@
355 U alice
356 "]
357 set crosslinkEv [crosslink_event $crosslinkA]
358 crosslink_match crosslink-attach-$crosslinkKind-delete-event $crosslinkEv \
359 "$crosslinkType Delete attachment $crosslinkDel"
360 test_eq crosslink-attach-$crosslinkKind-latest [crosslink_sql "SELECT
361 group_concat(isLatest,'') FROM (SELECT isLatest FROM attachment
362 WHERE target='[string map {\\s { }} $crosslinkTarget]' ORDER BY mtime)"] \
363 {01}
364 }
365 test_eq crosslink-attach-rows [crosslink_sql \
366 "SELECT count(*) FROM attachment"] 10
367
368 # A later change to a ticket or a tech note rewrites the timeline text of
369 # its attachments.
370 set crosslinkT7 [crosslink_put "D 2026-01-05T12:00:00.000
371 J status Open
372 K $crosslinkTkt
373 U alice
374 "]
375 test_eq crosslink-ticket-rewrites-attachments [crosslink_sql "SELECT count(*)
376 FROM event WHERE type='t' AND (comment LIKE 'Add attachment % to ticket %'
377 OR comment LIKE 'Delete attachment % from ticket %')"] 2
378 set crosslinkE3 [crosslink_put "C Third\\snote
379 D 2026-01-05T12:00:00.000
380 E 2026-01-02T09:00:00 $crosslinkEid
381 P $crosslinkE2
382 U alice
383 [crosslink_w {note3}]"]
384 test_eq crosslink-technote-rewrites-attachments [crosslink_sql "SELECT
385 count(*) FROM event WHERE type='e'
386 AND (comment LIKE 'Add attachment % to tech note %'
387 OR comment LIKE 'Delete attachment % from tech note %')"] 2
388
389 ###############################################################################
@@ -391,33 +382,37 @@
391
392 write_file a.txt "a\n"
393 write_file b.txt "b\n"
394 fossil add a.txt b.txt
395 fossil commit -m "crosslink-c1" --no-warnings
396 set crosslinkC1 [crosslink_sql "SELECT uuid FROM blob, event
397 WHERE rid=objid AND comment='crosslink-c1'"]
398 set crosslinkC1 [string trim $crosslinkC1 ']
399 set crosslinkFa [string trim [crosslink_sql "SELECT uuid FROM blob, mlink,
400 filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
401 AND name='a.txt'"] ']
402 set crosslinkFb [string trim [crosslink_sql "SELECT uuid FROM blob, mlink,
403 filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
404 AND name='b.txt'"] ']
405 test crosslink-setup-checkin \
406 {$crosslinkC1 ne "" && $crosslinkFa ne "" && $crosslinkFb ne ""}
407
408 # Every kind of tag that has its own wording in the timeline.
409 foreach {crosslinkName crosslinkCard crosslinkWant} [list \
410 branch "*branch * other" {*Move to branch*other*} \
411 bgcolor-prop "*bgcolor * #112233" {*Change branch background color to "#112233".*} \
412 bgcolor "+bgcolor * #445566" {*Change background color to "#445566".*} \
 
 
413 bgcolor-off "-bgcolor *" {*Cancel background color.*} \
414 comment "+comment * new\\stext" {*Edit check-in comment.*} \
415 user "+user * carol" {*Change user to "carol".*} \
416 date "+date * 2026-01-06\\s09:00:00" {*Timestamp 2026-01-06 09:00:00.*} \
 
417 sym-add "+sym-one *" {*Add tag "one".*} \
418 sym-add-note "+sym-two * a\\snote" {*Add tag "two" with note "a note".*} \
 
419 sym-prop "*sym-three *" {*Add propagating tag "three".*} \
420 sym-cancel "-sym-one *" {*Cancel tag "one".*} \
421 closed "+closed *" {*Mark "Closed".*} \
422 closed-off "-closed *" {*Remove the "Closed" mark.*} \
423 other-add "+thing *" {*Add "thing".*} \
@@ -436,16 +431,15 @@
436 "]
437 test crosslink-tag-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
438 crosslink_match crosslink-tag-$crosslinkName-event \
439 [crosslink_event $crosslinkG] "g Edit *:$crosslinkWant"
440 }
441 test_eq crosslink-tag-comment-applied [crosslink_sql "SELECT ecomment, euser
442 FROM event WHERE objid=(SELECT rid FROM blob WHERE uuid='$crosslinkC1')"] \
443 {new text|carol}
444
445 # A branch move with its symbolic tags says only that the branch moved.
446 # Tags for two check-ins in one artifact are listed for each.
447 set crosslinkG [crosslink_put "D 2026-01-06T11:00:00.000
448 T *branch $crosslinkC1 moved
449 T *sym-moved $crosslinkC1
450 T -sym-other $crosslinkC1
451 U alice
@@ -490,16 +484,16 @@
490 U alice
491 "]
492 test crosslink-checkin {$CODE == 0 && $crosslinkM1 ne ""}
493 test_eq crosslink-checkin-event [crosslink_event $crosslinkM1] \
494 {ci crosslink-c2}
495 test_eq crosslink-checkin-mlink [crosslink_sql "SELECT group_concat(
496 name || ':' || mperm || ':' || (pfnid>0), ' ') FROM (SELECT name, mperm,
497 pfnid FROM mlink, filename WHERE mlink.fnid=filename.fnid
498 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')
499 ORDER BY name)"] {a.txt:1:0 b.txt:0:0 c.txt:0:1 l.txt:2:0}
500 test_eq crosslink-checkin-cherrypick [crosslink_sql "SELECT count(*)
501 FROM cherrypick WHERE childid=(SELECT rid FROM blob
502 WHERE uuid='$crosslinkM1')"] 1
503
504 # A delta manifest, a second one on the same baseline, and an ordinary
505 # check-in after them. The second does not repeat the removal of a.txt,
@@ -511,16 +505,16 @@
511 F d.txt $crosslinkFb
512 P $crosslinkM1
513 U alice
514 "]
515 test crosslink-delta-checkin {$CODE == 0 && $crosslinkM2 ne ""}
516 test_eq crosslink-delta-checkin-mlink [crosslink_sql "SELECT group_concat(
517 name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
518 WHERE mlink.fnid=filename.fnid
519 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM2')
520 ORDER BY name)"] {a.txt:0 d.txt:1}
521 test_eq crosslink-delta-seen [crosslink_sql "SELECT value FROM config
522 WHERE name='seen-delta-manifest'"] 1
523
524 set crosslinkM3 [crosslink_put "B $crosslinkM1
525 C crosslink-c4
526 D 2026-01-07T12:00:00.000
@@ -528,11 +522,11 @@
528 F d.txt $crosslinkFa
529 F e.txt $crosslinkFa
530 P $crosslinkM2
531 U alice
532 "]
533 test_eq crosslink-delta-to-delta-mlink [crosslink_sql "SELECT group_concat(
534 name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
535 WHERE mlink.fnid=filename.fnid
536 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM3')
537 ORDER BY name)"] {a.txt:1 c.txt:0 d.txt:1 e.txt:1}
538
@@ -541,11 +535,11 @@
541 F a.txt $crosslinkFa
542 F e.txt $crosslinkFb
543 P $crosslinkM3
544 U alice
545 "]
546 test_eq crosslink-full-after-delta-mlink [crosslink_sql "SELECT group_concat(
547 name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
548 WHERE mlink.fnid=filename.fnid
549 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')
550 ORDER BY name)"] {a.txt:1 d.txt:0 e.txt:1 l.txt:0}
551
@@ -584,11 +578,11 @@
584 F a.txt $crosslinkFa
585 P $crosslinkM1
586 U alice
587 "]
588 test crosslink-missing-baseline {$CODE == 0 && $crosslinkBad ne ""}
589 test_eq crosslink-missing-baseline-no-event [crosslink_sql "SELECT count(*)
590 FROM event WHERE comment='crosslink-no-baseline'"] 0
591
592 # A check-in whose parent is that one is still shown; its files cannot be
593 # compared with the parent's.
594 set crosslinkM6 [crosslink_put "C crosslink-child-of-no-baseline
@@ -599,33 +593,33 @@
599 "]
600 test_eq crosslink-child-of-missing-baseline [crosslink_event $crosslinkM6] \
601 {ci crosslink-child-of-no-baseline}
602
603 write_file not-an-artifact.txt "This is a file.\n"
604 set crosslinkEvents [crosslink_sql "SELECT count(*) FROM event"]
605 fossil test-content-put --crosslink not-an-artifact.txt
606 test crosslink-not-an-artifact {$CODE == 0}
607 test_eq crosslink-not-an-artifact-no-event \
608 [crosslink_sql "SELECT count(*) FROM event"] $crosslinkEvents
609
610 ###############################################################################
611 # The "parent" tag gives a check-in other parents; a bad value is ignored.
612
613 fossil reparent $crosslinkM4 $crosslinkC1 $crosslinkM2
614 test crosslink-reparent {$CODE == 0}
615 test_eq crosslink-reparent-plink [crosslink_sql "SELECT count(*) FROM plink
616 WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')"] 2
617 test_eq crosslink-reparent-primary [crosslink_sql "SELECT uuid FROM plink,
618 blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
619 WHERE uuid='$crosslinkM4')"] $crosslinkC1
620
621 set crosslinkG [crosslink_put "D 2026-01-08T10:00:00.000
622 T +parent $crosslinkM3 not-a-hash
623 U alice
624 "]
625 test crosslink-reparent-bad-value {$CODE == 0}
626 test_eq crosslink-reparent-bad-value-ignored [crosslink_sql "SELECT uuid
627 FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
628 WHERE uuid='$crosslinkM3')"] $crosslinkM2
629
630 # A value of good hashes followed by a short word is ignored as a whole,
631 # both when the tag arrives and when a rebuild reads it again.
@@ -638,54 +632,57 @@
638 set crosslinkG [crosslink_put "D 2026-01-08T10:0[incr crosslinkI]:00.000
639 T +parent $crosslinkM3 $crosslinkValue
640 U alice
641 "]
642 test crosslink-reparent-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
643 test_eq crosslink-reparent-$crosslinkName-ignored [crosslink_sql "SELECT
644 uuid FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid
645 FROM blob WHERE uuid='$crosslinkM3')"] $crosslinkM2
646 }
647 fossil rebuild
648 test crosslink-reparent-short-rebuild {$CODE == 0}
649 test_eq crosslink-reparent-short-rebuild-ignored [crosslink_sql "SELECT uuid
650 FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
651 WHERE uuid='$crosslinkM3')"] $crosslinkM2
652
653 ###############################################################################
654 # A cluster removes its members from the list of unclustered artifacts.
655
656 set crosslinkBefore [crosslink_sql "SELECT count(*) FROM unclustered"]
657 set crosslinkCl ""
658 foreach crosslinkHash [lsort [list $crosslinkC1 $crosslinkM1 $crosslinkNone2]] {
659 append crosslinkCl "M $crosslinkHash\n"
660 }
661 set crosslinkCl [crosslink_put $crosslinkCl]
662 test crosslink-cluster {$CODE == 0 && $crosslinkCl ne ""}
663 test_eq crosslink-cluster-tag [crosslink_sql "SELECT count(*) FROM tagxref
664 WHERE tagid=(SELECT tagid FROM tag WHERE tagname='cluster')
665 AND rid=(SELECT rid FROM blob WHERE uuid='$crosslinkCl')"] 1
666 test crosslink-cluster-unclustered \
667 {[crosslink_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1}
668
669 ###############################################################################
670 # The JSON form of each kind of artifact.
671
672 foreach {crosslinkKind crosslinkHash crosslinkWant} [list \
673 wiki $crosslinkW2 {*"type":"wiki"*"L":"Crosslink Page"*"N":"text/x-markdown"*"P":*"W":*} \
674 technote $crosslinkE1 {*"type":"technote"*"C":"First note"*"E":*"T":*"W":*} \
 
 
675 ticket $crosslinkT5 {*"type":"ticket"*"J":*"append":true*"K":*} \
676 ticket2 $crosslinkT2 {*"type":"ticket"*"J":*"append":false*} \
677 forum $crosslinkF3 {*"type":"forumpost"*"G":*"I":*"P":*"W":*} \
678 forum2 $crosslinkF5 {*"type":"forumpost"*"H":"New title"*} \
679 attachment "" {*"type":"attachment"*"A":*} \
680 tag $crosslinkG {*"type":"tag"*"T":*} \
681 checkin $crosslinkM1 {*"type":"checkin"*"C":"crosslink-c2"*"F":*"perm":"x"*"P":*"Q":*"T":*"U":"alice"*} \
 
682 delta $crosslinkM2 {*"type":"checkin"*"B":*"F":*} \
683 cluster $crosslinkCl {*"type":"cluster"*"M":*} \
684 ] {
685 if {$crosslinkHash eq ""} {
686 set crosslinkHash [string trim [crosslink_sql "SELECT uuid FROM blob,
687 attachment WHERE rid=attachid ORDER BY rid LIMIT 1"] ']
688 }
689 fossil test-artifact-to-json $crosslinkHash
690 test crosslink-json-$crosslinkKind {$CODE == 0}
691 crosslink_match crosslink-json-$crosslinkKind-text $RESULT $crosslinkWant
@@ -703,23 +700,23 @@
703 fossil test-artifact-to-json $crosslinkFa no-such-name -expectError
704 test crosslink-json-not-artifact {$CODE != 0}
705
706 # The same through SQL: by hash, by record number, and with arguments
707 # that name nothing.
708 crosslink_match crosslink-json-sql-name [crosslink_sql \
709 "SELECT artifact_to_json('$crosslinkW1')"] {*"type":"wiki"*}
710 crosslink_match crosslink-json-sql-rid [crosslink_sql "SELECT artifact_to_json(
711 (SELECT rid FROM blob WHERE uuid='$crosslinkW1'))"] {*"type":"wiki"*}
712 test_eq crosslink-json-sql-data [crosslink_sql \
713 "SELECT artifact_to_json('$crosslinkFa') IS NULL"] 1
714 fossil sql "SELECT artifact_to_json(NULL)" -expectError
715 test crosslink-json-sql-null {$CODE != 0}
716 crosslink_match crosslink-json-sql-null-message $RESULT \
717 {*Expecting one argument*}
718 fossil sql "SELECT artifact_to_json(1.5)" -expectError
719 test crosslink-json-sql-float {$CODE != 0}
720 test_eq crosslink-json-sql-zero [crosslink_sql \
721 "SELECT artifact_to_json(0) IS NULL"] 1
722 fossil sql "SELECT artifact_to_json()" -expectError
723 test crosslink-json-sql-no-argument {$CODE != 0}
724
725 ###############################################################################
@@ -734,20 +731,30 @@
734 first-line-not-a-card "1 x\nD 2026-02-01T10:00:00.000\n" \
735 {*line 1 not recognized*} \
736 control-tags-itself "D 2026-02-01T10:00:00.000\nT +sym-x *\nU alice\n" \
737 {*self-referential T-card in control artifact*} \
738 technote-tags-another \
739 "D 2026-02-01T10:00:00.000\nE 2026-02-01T09:00:00 $crosslinkH40\nT +sym-x $crosslinkH40\nU alice\nW 1\nx\n" \
 
 
 
740 {*non-self-referential T-card in technote*} \
741 technote-propagating-tag \
742 "D 2026-02-01T10:00:00.000\nE 2026-02-01T09:00:00 $crosslinkH40\nT *sym-x *\nU alice\nW 1\nx\n" \
 
 
 
743 {*T-card with '\*' or '-' in technote*} \
744 forum-title-on-reply \
745 "D 2026-02-01T10:00:00.000\nG $crosslinkH40\nH title\nI $crosslinkH40\nU alice\nW 1\nx\n" \
 
 
746 {*cannot have I-card and H-card in a forum post*} \
747 forum-two-parents \
748 "D 2026-02-01T10:00:00.000\nG $crosslinkH40\nP $crosslinkH40 $crosslinkNone\nU alice\nW 1\nx\n" \
 
 
749 {*too many arguments to P-card*} \
750 ] {
751 fossil test-parse-manifest [crosslink_file $crosslinkBody]
752 test crosslink-refuse-$crosslinkName {$CODE == 0}
753 crosslink_match crosslink-refuse-$crosslinkName-reason $RESULT \
@@ -775,14 +782,19 @@
775 {*manifest_parse() worked*}
776
777 # A tech note may have its N card after its P card, as old versions of
778 # Fossil wrote it. A file with a reserved name in a check-in is left out.
779 fossil test-parse-manifest [crosslink_file \
780 "D 2026-02-01T10:00:00.000\nE 2026-02-01T09:00:00 $crosslinkH40\nP $crosslinkH40\nN text/plain\nU alice\nW 1\nx\n"]
 
 
 
781 crosslink_match crosslink-technote-n-after-p $RESULT {*manifest_parse() worked*}
782 fossil test-parse-manifest [crosslink_file \
783 "C reserved\nD 2026-02-01T10:00:00.000\nF _FOSSIL_ $crosslinkH40\nF a.txt $crosslinkH40\nU alice\n"] 2
 
 
784 crosslink_match crosslink-reserved-name-ignored $RESULT \
785 {*manifest_parse() worked*}
786
787 # Content that is not an artifact but begins like one. The quick check
788 # and the parser must agree about each.
@@ -792,11 +804,11 @@
792 no-newline "D 2026-02-01T10:00:00.000 and no end of line" \
793 one-card "D x\n" \
794 short "D\n" \
795 second-lower "D 2026-02-01T10:00:00.000\nlower case\n" \
796 second-earlier "D 2026-02-01T10:00:00.000\nC comment\nmore text here\n" \
797 no-space "D 2026-02-01T10:00:00.000\nUalice and more\n" \
798 late-letter "N text/plain\nU alice and more\n" \
799 ] {
800 write_file wf-$crosslinkName.txt $crosslinkText
801 fossil test-content-put wf-$crosslinkName.txt
802 test crosslink-not-wellformed-$crosslinkName {$CODE == 0}
@@ -810,23 +822,23 @@
810 crosslink_match crosslink-wiki-is-not-a-checkin-message $RESULT \
811 {*not a valid check-in*}
812
813 # Wiki text and a tech note that begin with blank space, and crosslinking
814 # with SQL tracing on.
815 set crosslinkW5 [crosslink_put "D 2026-02-02T10:00:00.000
816 L Indented
817 U alice
818 [crosslink_w "\n\n indented"]"]
819 test_eq crosslink-wiki-leading-space-length [crosslink_sql "SELECT value
820 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
821 AND tagname='wiki-Indented'"] 8
822 set crosslinkE4 [crosslink_put "C Indented\\snote
823 D 2026-02-02T11:00:00.000
824 E 2026-02-02T09:00:00 [string repeat 12 20]
825 U alice
826 [crosslink_w "\n note"]"]
827 test_eq crosslink-technote-leading-space-length [crosslink_sql "SELECT value
828 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
829 AND tagname='event-[string repeat 12 20]'"] 4
830 fossil_raw test-crosslink $crosslinkW1 --sqltrace
831 test crosslink-sqltrace {$CODE == 0}
832 crosslink_match crosslink-sqltrace-text $RESULT {*-- manifest_crosslink(*}
@@ -853,19 +865,20 @@
853 crosslink_match crosslink-parse-all-text $RESULT {*tests with 0 errors*}
854 fossil test-parse-all-blobs --limit 3
855 crosslink_match crosslink-parse-all-limit $RESULT {*3 tests with 0 errors*}
856 fossil test-parse-all-blobs --wellformed
857 test crosslink-parse-all-wellformed {$CODE == 0}
858 crosslink_match crosslink-parse-all-wellformed-text $RESULT {*tests with 0 errors*}
 
859
860 # Crosslinking an artifact a second time changes nothing.
861 set crosslinkEvents [crosslink_sql "SELECT count(*) FROM event"]
862 fossil test-crosslink $crosslinkM1
863 test crosslink-again {$CODE == 0}
864 fossil test-crosslink $crosslinkW1
865 test crosslink-again-wiki {$CODE == 0}
866 test_eq crosslink-again-events [crosslink_sql "SELECT count(*) FROM event"] \
867 $crosslinkEvents
868 fossil test-crosslink -expectError
869 test crosslink-usage {$CODE != 0}
870
871 ###############################################################################
@@ -875,18 +888,18 @@
875 (SELECT count(*) FROM attachment) || ' ' ||
876 (SELECT count(*) FROM forumpost) || ' ' ||
877 (SELECT count(*) FROM plink) || ' ' ||
878 (SELECT count(*) FROM mlink) || ' ' ||
879 (SELECT count(*) FROM ticket)}
880 set crosslinkBefore [crosslink_sql $crosslinkState]
881 set crosslinkText [crosslink_sql "SELECT group_concat(x, char(10)) FROM
882 (SELECT type || ' ' || comment AS x FROM event ORDER BY type, objid)"]
883 fossil rebuild
884 test crosslink-rebuild {$CODE == 0}
885 test_eq crosslink-rebuild-same-counts [crosslink_sql $crosslinkState] \
886 $crosslinkBefore
887 test_eq crosslink-rebuild-same-events [crosslink_sql "SELECT
888 group_concat(x, char(10)) FROM (SELECT type || ' ' || comment AS x
889 FROM event ORDER BY type, objid)"] $crosslinkText
890 fossil test-integrity
891 test crosslink-integrity {$CODE == 0}
892
@@ -903,11 +916,11 @@
903 none "D 2026-03-01T10:03:00.000\nT +sym-kind-test $crosslinkC1\nU alice\n" \
904 control \
905 ] {
906 set crosslinkHash [crosslink_put $crosslinkBody]
907 test crosslink-mcdc-kind-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
908 test_eq crosslink-mcdc-kind-$crosslinkName-event [crosslink_sql "SELECT
909 count(*) FROM event, blob WHERE objid=rid AND uuid='$crosslinkHash'
910 AND type='ci'"] [expr {$crosslinkKind eq "ci" ? 1 : 0}]
911 fossil test-parse-manifest [crosslink_file $crosslinkBody]
912 crosslink_match crosslink-mcdc-kind-$crosslinkName-parse $RESULT \
913 {*manifest_parse() worked*}
@@ -920,25 +933,29 @@
920 # first parent arrives. A merge parent that arrives while the first
921 # parent is present adds them at once.
922
923 # The hash a check-in with the cards BODY will have, without storing it.
924 proc crosslink_hash {body} {
925 global RESULT
926 fossil sha3sum [crosslink_file $body]
927 return [lindex $RESULT 0]
928 }
929
930 # The number of file links that join the check-in CHILD to its parent
931 # PARENT.
932 proc crosslink_links {child parent} {
933 return [crosslink_sql "SELECT count(*) FROM mlink WHERE
934 mid=(SELECT rid FROM blob WHERE uuid='$child')
935 AND pmid=(SELECT rid FROM blob WHERE uuid='$parent')"]
936 }
937
938 set crosslinkPA [crosslink_hash "C first\\sparent\nD 2026-03-02T10:00:00.000\nF a.txt $crosslinkFa\nU alice\n"]
939 set crosslinkPB [crosslink_hash "C second\\sparent\nD 2026-03-02T10:01:00.000\nF a.txt $crosslinkFb\nU alice\n"]
 
 
 
 
 
 
940 set crosslinkKid [crosslink_put "C merge\\skid
941 D 2026-03-02T11:00:00.000
942 F a.txt $crosslinkNone
943 P $crosslinkPA $crosslinkPB
944 U alice
@@ -967,12 +984,18 @@
967 test_eq crosslink-mcdc-merge-parent-second-links \
968 [list [crosslink_links $crosslinkKid $crosslinkPA] \
969 [crosslink_links $crosslinkKid $crosslinkPB]] {1 1}
970
971 # The first parent present, the second arriving later.
972 set crosslinkQA [crosslink_hash "C other\\sfirst\nD 2026-03-02T12:00:00.000\nF a.txt $crosslinkFa\nU alice\n"]
973 set crosslinkQB [crosslink_hash "C other\\ssecond\nD 2026-03-02T12:01:00.000\nF a.txt $crosslinkFb\nU alice\n"]
 
 
 
 
 
 
974 crosslink_put "C other\\sfirst
975 D 2026-03-02T12:00:00.000
976 F a.txt $crosslinkFa
977 U alice
978 "
@@ -998,15 +1021,17 @@
998 # An empty title on the first post of a forum thread is shown as deleted,
999 # and an empty title or page text is null in the JSON form. Each row
1000 # differs from the one before in a single card.
1001
1002 foreach {crosslinkName crosslinkBody crosslinkWant crosslinkJson} [list \
1003 title "D 2026-03-03T10:00:00.000\nH Some\\stitle\nU alice\n[crosslink_w {x}]" \
 
1004 {f Post: Some title} {*"H":"Some title"*"W":"x"*} \
1005 empty-title "D 2026-03-03T10:01:00.000\nH \nU alice\n[crosslink_w {x}]" \
1006 {f Post: (Deleted)} {*"H":null*"W":"x"*} \
1007 empty-text "D 2026-03-03T10:02:00.000\nH Some\\stitle\nU alice\n[crosslink_w {}]" \
 
1008 {f Post: Some title} {*"H":"Some title"*"W":null*} \
1009 ] {
1010 set crosslinkHash [crosslink_put $crosslinkBody]
1011 test crosslink-mcdc-forum-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1012 test_eq crosslink-mcdc-forum-$crosslinkName-event \
@@ -1016,11 +1041,12 @@
1016 $crosslinkJson
1017 }
1018
1019 # A wiki page with no text has a null W card in JSON.
1020 fossil test-artifact-to-json $crosslinkW3
1021 crosslink_match crosslink-mcdc-json-empty-wiki $RESULT {*"type":"wiki"*"W":null*}
 
1022
1023 ###############################################################################
1024 # A tag card whose value is empty reads like one with no value.
1025
1026 set crosslinkMin 10
@@ -1055,25 +1081,21 @@
1055 "]
1056 test crosslink-mcdc-cherry-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1057 test_eq crosslink-mcdc-cherry-$crosslinkName-event \
1058 [crosslink_event $crosslinkHash] "ci cherry-$crosslinkName"
1059 }
1060 test_eq crosslink-mcdc-cherry-unseen-not-stored [crosslink_sql "SELECT count(*)
1061 FROM blob WHERE uuid='$crosslinkUnseen'"] 0
1062
1063 ###############################################################################
1064 # The information page of a wiki page, asked for by the name of something
1065 # that is not a wiki page: a check-in, a ticket, a forum post, a file, and
1066 # a hash that names nothing.
1067
1068 proc crosslink_get {path} {
1069 write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n"
1070 file delete reply.txt
1071 fossil_raw http [file join [pwd] .rep.fossil] --in request.txt \
1072 --out reply.txt --ipaddr 127.0.0.1 --localauth
1073 if {[file exists reply.txt]} { return [read_file reply.txt] }
1074 return ""
1075 }
1076
1077 foreach {crosslinkName crosslinkHash crosslinkIs} [list \
1078 wiki $crosslinkW1 1 \
1079 checkin $crosslinkC1 0 \
@@ -1102,11 +1124,11 @@
1102 F l.txt $crosslinkFa l
1103 P $crosslinkM2
1104 U alice
1105 "]
1106 test crosslink-mcdc-back-after-delta {$CODE == 0 && $crosslinkBack ne ""}
1107 test_eq crosslink-mcdc-back-after-delta-mlink [crosslink_sql "SELECT
1108 group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1109 pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1110 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkBack')
1111 ORDER BY name)"] {a.txt:0:1 c.txt:1:0 d.txt:1:0}
1112
@@ -1129,11 +1151,11 @@
1129 D 2026-03-07T10:01:00.000
1130 F a.txt $crosslinkFa x
1131 P $crosslinkGhost
1132 U alice
1133 "]
1134 test_eq crosslink-mcdc-delta-removes-unknown-child-mlink [crosslink_sql "SELECT
1135 group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1136 pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1137 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
1138 ORDER BY name)"] {c.txt:1:0 l.txt:1:0}
1139
@@ -1155,11 +1177,11 @@
1155 set crosslinkG [crosslink_put "D 2026-03-07T11:01:00.000
1156 T +parent $crosslinkKid3 $crosslinkM1
1157 U alice
1158 "]
1159 test crosslink-mcdc-reparent-no-baseline-tag {$CODE == 0 && $crosslinkG ne ""}
1160 test_eq crosslink-mcdc-reparent-no-baseline-plink [crosslink_sql "SELECT count(*)
1161 FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkKid3')
1162 AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')"] 1
1163 test_eq crosslink-mcdc-reparent-no-baseline-no-links \
1164 [crosslink_links $crosslinkKid3 $crosslinkM1] 0
1165
@@ -1181,25 +1203,26 @@
1181 P $crosslinkC1
1182 U alice
1183 "]
1184 fossil test-content-put --crosslink $crosslinkOnWiki $crosslinkBasedOnWiki
1185 test crosslink-mcdc-wiki-baseline {$CODE == 0}
1186 test_eq crosslink-mcdc-wiki-baseline-events [crosslink_sql "SELECT
1187 group_concat(comment, ' ') FROM event WHERE type='ci'
1188 AND comment IN ('child-of-wiki-page','based-on-wiki-page')"] \
1189 {child-of-wiki-page}
1190 fossil sha3sum $crosslinkBasedOnWiki
1191 test_eq crosslink-mcdc-wiki-baseline-waiting [crosslink_sql "SELECT count(*)
1192 FROM orphan WHERE rid=(SELECT rid FROM blob
1193 WHERE uuid='[lindex $RESULT 0]')
1194 AND baseline=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
1195
1196 ###############################################################################
1197 # Scripts that run when artifacts are stored by a command.
1198 #
1199 # A script for check-ins can ask for the JSON form of the parent of a
1200 # check-in that "branch new" makes. A common script that fails makes "ticket add"
 
1201 # fail, after the ticket has been entered. A tag put on a wiki page by
1202 # "tag add" is recorded like a tag on a check-in.
1203
1204 proc crosslink_script {name script} {
1205 if {$script eq ""} {
@@ -1214,32 +1237,32 @@
1214 FROM plink, blob WHERE cid=blob.rid AND blob.uuid=$uuid} {puts "PARENT $j"}}
1215 fossil branch new scripted $crosslinkM1
1216 test crosslink-mcdc-script-branch {$CODE == 0}
1217 crosslink_match crosslink-mcdc-script-branch-parent-json $RESULT \
1218 {*PARENT *&quot;type&quot;:&quot;checkin&quot;*&quot;C&quot;:&quot;crosslink-c2&quot;*}
1219 test_eq crosslink-mcdc-script-branch-made [crosslink_sql "SELECT count(*)
1220 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
1221 AND tagname='sym-scripted'"] 1
1222 crosslink_script xfer-commit-script ""
1223
1224 set crosslinkTickets [crosslink_sql "SELECT count(*) FROM ticket"]
1225 crosslink_script xfer-common-script {error common-script-says-no}
1226 fossil ticket add title Scripted status Open -expectError
1227 test crosslink-mcdc-script-ticket-fails {$CODE != 0}
1228 crosslink_match crosslink-mcdc-script-ticket-message $RESULT \
1229 {*common-script-says-no*}
1230 test_eq crosslink-mcdc-script-ticket-entered [crosslink_sql "SELECT count(*)
1231 FROM ticket WHERE title='Scripted'"] 1
1232 crosslink_script xfer-common-script ""
1233 fossil ticket add title Unscripted status Open
1234 test crosslink-mcdc-no-script-ticket {$CODE == 0}
1235 test_eq crosslink-mcdc-no-script-ticket-count [crosslink_sql "SELECT count(*)
1236 FROM ticket"] [expr {$crosslinkTickets + 2}]
1237
1238 fossil tag add on-a-wiki-page $crosslinkW1
1239 test crosslink-mcdc-tag-add-wiki {$CODE == 0}
1240 crosslink_match crosslink-mcdc-tag-add-wiki-event [crosslink_sql "SELECT comment
1241 FROM event WHERE type='g' AND comment LIKE '%on-a-wiki-page%'"] \
1242 "Edit \\\[[string range $crosslinkW1 0 15]|*\\\]: Add *\"on-a-wiki-page\"."
1243
1244 ###############################################################################
1245 # A repository made before cherrypicks were recorded has no table for
@@ -1255,15 +1278,15 @@
1255 U alice
1256 "]
1257 test crosslink-mcdc-cherry-no-table {$CODE == 0 && $crosslinkHash ne ""}
1258 test_eq crosslink-mcdc-cherry-no-table-event [crosslink_event $crosslinkHash] \
1259 {ci cherry-no-table}
1260 test_eq crosslink-mcdc-cherry-no-table-still-none [crosslink_sql "SELECT count(*)
1261 FROM sqlite_schema WHERE name='cherrypick'"] 0
1262 fossil rebuild
1263 test crosslink-mcdc-cherry-rebuild {$CODE == 0}
1264 test_eq crosslink-mcdc-cherry-rebuild-recorded [crosslink_sql "SELECT count(*)
1265 FROM cherrypick WHERE childid=(SELECT rid FROM blob
1266 WHERE uuid='$crosslinkHash')"] 1
1267
1268 ###############################################################################
1269 # The quick check for an artifact and the parser must agree.
@@ -1331,11 +1354,11 @@
1331 {$crosslinkR1 ne "" && $crosslinkR2 ne "" && $crosslinkR3 ne ""}
1332
1333 # The primary parent of the check-in with the given hash.
1334 #
1335 proc crosslink_primary {hash} {
1336 return [crosslink_sql "SELECT uuid FROM plink, blob WHERE pid=rid
1337 AND isprim AND cid=(SELECT rid FROM blob WHERE uuid='$hash')"]
1338 }
1339
1340 crosslink_put "D 2026-04-01T11:00:00.000
1341 T +parent $crosslinkR3 $crosslinkR1\\s
@@ -1360,11 +1383,11 @@
1360 crosslink_put "D 2026-04-01T11:03:00.000
1361 T +parent $crosslinkHash $crosslinkR1
1362 U alice
1363 "
1364 test crosslink-reparent-wiki-page {$CODE == 0}
1365 test_eq crosslink-reparent-wiki-page-no-links [crosslink_sql "SELECT count(*)
1366 FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')"] 0
1367
1368 ###############################################################################
1369 # A check-in with two parents lists both in its JSON form.
1370
@@ -1371,11 +1394,11 @@
1371 set crosslinkHash [crosslink_put "C two-parents-json
1372 D 2026-04-01T12:00:00.000
1373 P $crosslinkR3 $crosslinkR1
1374 U alice
1375 "]
1376 test_eq crosslink-json-second-parent [crosslink_sql "SELECT
1377 json_extract(artifact_to_json('$crosslinkHash'), '\$.P\[1\]')"] \
1378 $crosslinkR1
1379
1380 ###############################################################################
1381 # A wiki page with two parents: both are linked, the first as the
@@ -1393,11 +1416,11 @@
1393 L Two\\sParents
1394 P $crosslinkWa $crosslinkWb
1395 U alice
1396 [crosslink_w {both}]"]
1397 test crosslink-wiki-two-parents {$CODE == 0 && $crosslinkHash ne ""}
1398 test_eq crosslink-wiki-two-parents-plink [crosslink_sql "SELECT
1399 group_concat(uuid || ':' || isprim, ' ') FROM (SELECT uuid, isprim
1400 FROM plink, blob WHERE pid=rid AND cid=(SELECT rid FROM blob
1401 WHERE uuid='$crosslinkHash') ORDER BY isprim DESC)"] \
1402 "$crosslinkWa:1 $crosslinkWb:0"
1403
@@ -1410,13 +1433,13 @@
1410 U alice
1411 [crosslink_w {text}]Z [string repeat 0 32]\n"
1412 fossil test-content-put --crosslink bad-z.txt
1413 test crosslink-bad-z-stored \
1414 {$CODE == 0 && [regexp {inserted as record (\d+)} $RESULT all crosslinkRid]}
1415 test_eq crosslink-bad-z-no-event [crosslink_sql "SELECT count(*) FROM event
1416 WHERE objid=$crosslinkRid"] 0
1417 test_eq crosslink-bad-z-no-page [crosslink_sql "SELECT count(*) FROM tag
1418 WHERE tagname='wiki-Bad Sum'"] 0
1419
1420 ###############################################################################
1421 # A version of a tech note that arrives after a later version of the same
1422 # note, and names the first version as its parent, does not replace the
@@ -1439,11 +1462,11 @@
1439 E 2026-04-03T09:00:00 $crosslinkEid2
1440 P $crosslinkHash
1441 U alice
1442 [crosslink_w {middle}]"
1443 test crosslink-technote-middle-arrives-last {$CODE == 0}
1444 test_eq crosslink-technote-middle-arrives-last-event [crosslink_sql "SELECT
1445 comment FROM event WHERE type='e' AND comment LIKE 'note-%'"] {note-last}
1446
1447 ###############################################################################
1448 # Two delta manifests on one baseline, the second a child of the first.
1449 # The first changes a.txt, removes b.txt and adds x.txt. The second
@@ -1473,11 +1496,11 @@
1473 U alice
1474 "]
1475 test crosslink-two-deltas {$CODE == 0 && $crosslinkHash ne ""}
1476 test_eq crosslink-two-deltas-event [crosslink_event $crosslinkHash] \
1477 {ci two-deltas-child}
1478 test_eq crosslink-two-deltas-mlink [crosslink_sql "SELECT
1479 group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1480 pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1481 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
1482 ORDER BY name)"] {a.txt:1:1}
1483
@@ -1497,16 +1520,16 @@
1497 set crosslinkPrev [lindex $RESULT 0]
1498 lappend crosslinkFiles $crosslinkFn
1499 }
1500 fossil test-content-put --crosslink {*}$crosslinkFiles
1501 test crosslink-same-second {$CODE == 0}
1502 test_eq crosslink-same-second-events [crosslink_sql "SELECT count(*)
1503 FROM event WHERE comment LIKE 'same-second-%'"] 33
1504 test_eq crosslink-same-second-order [crosslink_sql "SELECT count(*)
1505 FROM plink, event AS p, event AS c WHERE p.objid=pid AND c.objid=cid
1506 AND c.comment LIKE 'same-second-%' AND p.mtime<c.mtime"] 30
1507 test_eq crosslink-same-second-tip-time [crosslink_sql "SELECT
1508 strftime('%Y-%m-%d %H:%M:%f', mtime) FROM event
1509 WHERE comment='same-second-32'"] {2026-04-05 10:00:00.000}
1510
1511 ###############################################################################
1512 # A delta manifest whose baseline is missing, received by a pull: it is
@@ -1543,16 +1566,16 @@
1543 fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$crosslinkShun',0)"
1544 set crosslinkHash [crosslink_put "C shun-clustered
1545 D 2026-04-07T10:00:00.000
1546 U alice
1547 "]
1548 test_eq crosslink-shun-unclustered-before [crosslink_sql "SELECT count(*)
1549 FROM unclustered, blob WHERE unclustered.rid=blob.rid
1550 AND uuid='$crosslinkHash'"] 1
1551 crosslink_put [join [lsort [list "M $crosslinkShun" "M $crosslinkHash"]] \n]\n
1552 test crosslink-shun-cluster {$CODE == 0}
1553 test_eq crosslink-shun-cluster-clears-other [crosslink_sql "SELECT count(*)
1554 FROM unclustered, blob WHERE unclustered.rid=blob.rid
1555 AND uuid='$crosslinkHash'"] 0
1556
1557 set crosslinkG [crosslink_put "D 2026-04-07T10:01:00.000
1558 T +sym-on-shunned $crosslinkShun
@@ -1559,11 +1582,11 @@
1559 U alice
1560 "]
1561 test crosslink-shun-tag {$CODE == 0 && $crosslinkG ne ""}
1562 crosslink_match crosslink-shun-tag-event [crosslink_event $crosslinkG] \
1563 {g Edit \[5e5e5e5e5e5e5e5e|5e5e5e5e5e\]: Add tag "on-shunned".}
1564 test_eq crosslink-shun-tag-tags-nothing [crosslink_sql "SELECT count(*)
1565 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
1566 AND tagname='sym-on-shunned'"] 0
1567
1568 set crosslinkKid [crosslink_put "C shun-merge-kid
1569 D 2026-04-07T11:00:00.000
@@ -1572,11 +1595,11 @@
1572 U alice
1573 "]
1574 test crosslink-shun-merge-parent {$CODE == 0 && $crosslinkKid ne ""}
1575 test_eq crosslink-shun-merge-parent-links \
1576 [crosslink_links $crosslinkKid $crosslinkR1] 1
1577 test_eq crosslink-shun-no-placeholder [crosslink_sql "SELECT count(*)
1578 FROM blob WHERE uuid='$crosslinkShun'"] 0
1579 fossil sql "DELETE FROM shun WHERE uuid='$crosslinkShun'"
1580
1581 ###############################################################################
1582 # A common script that fails makes "branch new" fail.
1583
--- test/crosslink.test
+++ test/crosslink.test
@@ -8,15 +8,12 @@
8 # the ordinary commands never produce: a reply to a forum post, an
9 # attachment whose target is not in the repository, a check-in whose
10 # baseline is missing.
11 #
12
13 # The first sections run at every level, and the rest need
14 # -assurance stress.
 
 
 
15 require_no_open_checkout
16
17 test_setup
18
19 set crosslinkSeq 0
@@ -40,18 +37,14 @@
37
38 # Store the artifact whose cards, without the Z card, are $body. Return
39 # its hash, or an empty string if it was not stored. CODE and RESULT are
40 # those of test-content-put.
41 #
42 proc crosslink_put {body} {
43 global RESULT CODE
44 set fn [crosslink_file $body]
45 fossil test-content-put --crosslink $fn
 
 
 
 
46 set code $CODE
47 set result $RESULT
48 set hash ""
49 if {[regexp {inserted as record (\d+)} $result all rid]} {
50 fossil sql "SELECT uuid FROM blob WHERE rid=$rid"
@@ -73,22 +66,14 @@
66 proc crosslink_match {name actual pattern {constraints ""}} {
67 if {[string match $pattern $actual]} {set pattern $actual}
68 test_eq $name $actual $pattern $constraints
69 }
70
 
 
 
 
 
 
 
 
71 # The timeline text of the artifact with the given hash.
72 #
73 proc crosslink_event {hash} {
74 return [fossil_sql "SELECT type || ' ' || comment FROM event, blob\
75 WHERE objid=rid AND uuid='$hash'"]
76 }
77
78 set crosslinkNone [string repeat 0123456789 4]
79 set crosslinkNone2 [string repeat 9876543210 4]
@@ -101,11 +86,11 @@
86 U alice
87 [crosslink_w {first text}]"]
88 test crosslink-wiki-new {$CODE == 0 && $crosslinkW1 ne ""}
89 test_eq crosslink-wiki-new-event [crosslink_event $crosslinkW1] \
90 {w +Crosslink Page}
91 test_eq crosslink-wiki-new-tag [fossil_sql "SELECT value FROM tagxref, tag
92 WHERE tag.tagid=tagxref.tagid AND tagname='wiki-Crosslink Page'"] {10}
93
94 set crosslinkW2 [crosslink_put "D 2026-01-01T11:00:00.000
95 L Crosslink\\sPage
96 N text/x-markdown
@@ -112,11 +97,11 @@
97 P $crosslinkW1
98 U alice
99 [crosslink_w {second text}]"]
100 test_eq crosslink-wiki-edit-event [crosslink_event $crosslinkW2] \
101 {w :Crosslink Page}
102 test_eq crosslink-wiki-edit-plink [fossil_sql "SELECT count(*) FROM plink
103 WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkW2')
104 AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
105
106 set crosslinkW3 [crosslink_put "D 2026-01-01T12:00:00.000
107 L Crosslink\\sPage
@@ -147,29 +132,29 @@
132 T +bgcolor * #abcdef
133 T +sym-noted *
134 U alice
135 [crosslink_w {note}]"]
136 test crosslink-technote-new {$CODE == 0 && $crosslinkE1 ne ""}
137 test_eq crosslink-technote-new-event [fossil_sql "SELECT type, comment,
138 bgcolor FROM event, blob WHERE objid=rid AND uuid='$crosslinkE1'"] \
139 {e|First note|#abcdef}
140
141 set crosslinkE2 [crosslink_put "C Second\\snote
142 D 2026-01-02T11:00:00.000
143 E 2026-01-02T09:00:00 $crosslinkEid
144 P $crosslinkE1
145 U alice
146 [crosslink_w {note2}]"]
147 test_eq crosslink-technote-edit-only-latest [fossil_sql "SELECT comment
148 FROM event WHERE type='e'"] {Second note}
149
150 crosslink_put "C Earlier\\snote
151 D 2026-01-02T08:00:00.000
152 E 2026-01-02T09:00:00 $crosslinkEid
153 U alice
154 [crosslink_w {note0}]"
155 test_eq crosslink-technote-older-arrives-last [fossil_sql "SELECT comment
156 FROM event WHERE type='e'"] {Second note}
157
158 ###############################################################################
159 # Tickets: a new ticket, a change of status with other fields, a change
160 # without the status, and one with a single field.
@@ -182,30 +167,32 @@
167 U alice
168 "]
169 test crosslink-ticket-new {$CODE == 0 && $crosslinkT1 ne ""}
170 crosslink_match crosslink-ticket-new-event [crosslink_event $crosslinkT1] \
171 {t New ticket *Crosslink ticket*}
172 test_eq crosslink-ticket-new-row [fossil_sql "SELECT status, title
173 FROM ticket WHERE tkt_uuid='$crosslinkTkt'"] {Open|Crosslink ticket}
174
175 set crosslinkT2 [crosslink_put "D 2026-01-03T11:00:00.000
176 J priority High
177 J severity Minor
178 J status Fixed
179 K $crosslinkTkt
180 U alice
181 "]
182 crosslink_match crosslink-ticket-status-plus-two \
183 [crosslink_event $crosslinkT2] \
184 {t Fixed ticket * plus 2 other changes}
185
186 set crosslinkT3 [crosslink_put "D 2026-01-03T12:00:00.000
187 J priority Low
188 J status Closed
189 K $crosslinkTkt
190 U alice
191 "]
192 crosslink_match crosslink-ticket-status-plus-one \
193 [crosslink_event $crosslinkT3] \
194 {t Closed ticket * plus 1 other change}
195
196 set crosslinkT4 [crosslink_put "D 2026-01-03T13:00:00.000
197 J priority Medium
198 J severity Severe
@@ -230,11 +217,11 @@
217 "]
218 crosslink_match crosslink-ticket-status-only [crosslink_event $crosslinkT6] \
219 {t Verified ticket *}
220 test {crosslink-ticket-status-only-no-plus} \
221 {![string match *plus* [crosslink_event $crosslinkT6]]}
222 test_eq crosslink-ticket-events [fossil_sql "SELECT count(*) FROM event
223 WHERE type='t'"] 6
224
225 ###############################################################################
226 # Forum posts: a thread, an edit of its first post, a reply, an edit of
227 # the reply, a deleted reply, and an older edit of the first post that
@@ -246,11 +233,11 @@
233 U alice
234 [crosslink_w $crosslinkFtext]"]
235 test crosslink-forum-post {$CODE == 0 && $crosslinkF1 ne ""}
236 test_eq crosslink-forum-post-event [crosslink_event $crosslinkF1] \
237 {f Post: Crosslink thread}
238 test_eq crosslink-forum-post-backlink [fossil_sql "SELECT count(*)
239 FROM backlink WHERE srctype=4
240 AND srcid=(SELECT rid FROM blob WHERE uuid='$crosslinkF1')"] 1
241
242 set crosslinkF2 [crosslink_put "D 2026-01-04T11:00:00.000
243 G $crosslinkF1
@@ -258,11 +245,11 @@
245 N text/x-markdown
246 U bob
247 [crosslink_w {reply}]"]
248 test_eq crosslink-forum-reply-event [crosslink_event $crosslinkF2] \
249 {f Reply: Crosslink thread}
250 test_eq crosslink-forum-reply-row [fossil_sql "SELECT
251 froot=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'),
252 firt=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'), fprev IS NULL
253 FROM forumpost WHERE fpid=(SELECT rid FROM blob
254 WHERE uuid='$crosslinkF2')"] {1|1|1}
255
@@ -323,10 +310,14 @@
310 I $crosslinkNone
311 U bob
312 [crosslink_w {reply}]"]
313 test_eq crosslink-forum-reply-unknown-thread [crosslink_event $crosslinkF8] \
314 {f Reply: <i>Unknown</i>}
315
316 if {[test_assurance] ne "stress"} {
317 test_skip "the tests after the first sections need -assurance stress"
318 }
319
320 ###############################################################################
321 # Attachments, added to and deleted from each kind of target.
322
323 set crosslinkSrc [string repeat ef 20]
@@ -355,35 +346,35 @@
346 U alice
347 "]
348 set crosslinkEv [crosslink_event $crosslinkA]
349 crosslink_match crosslink-attach-$crosslinkKind-delete-event $crosslinkEv \
350 "$crosslinkType Delete attachment $crosslinkDel"
351 test_eq crosslink-attach-$crosslinkKind-latest [fossil_sql "SELECT
352 group_concat(isLatest,'') FROM (SELECT isLatest FROM attachment
353 WHERE target='[string map {\\s { }} $crosslinkTarget]' ORDER BY mtime)"] \
354 {01}
355 }
356 test_eq crosslink-attach-rows [fossil_sql \
357 "SELECT count(*) FROM attachment"] 10
358
359 # A later change to a ticket or a tech note rewrites the timeline text of
360 # its attachments.
361 crosslink_put "D 2026-01-05T12:00:00.000
362 J status Open
363 K $crosslinkTkt
364 U alice
365 "
366 test_eq crosslink-ticket-rewrites-attachments [fossil_sql "SELECT count(*)
367 FROM event WHERE type='t' AND (comment LIKE 'Add attachment % to ticket %'
368 OR comment LIKE 'Delete attachment % from ticket %')"] 2
369 crosslink_put "C Third\\snote
370 D 2026-01-05T12:00:00.000
371 E 2026-01-02T09:00:00 $crosslinkEid
372 P $crosslinkE2
373 U alice
374 [crosslink_w {note3}]"
375 test_eq crosslink-technote-rewrites-attachments [fossil_sql "SELECT
376 count(*) FROM event WHERE type='e'
377 AND (comment LIKE 'Add attachment % to tech note %'
378 OR comment LIKE 'Delete attachment % from tech note %')"] 2
379
380 ###############################################################################
@@ -391,33 +382,37 @@
382
383 write_file a.txt "a\n"
384 write_file b.txt "b\n"
385 fossil add a.txt b.txt
386 fossil commit -m "crosslink-c1" --no-warnings
387 set crosslinkC1 [fossil_sql "SELECT uuid FROM blob, event
388 WHERE rid=objid AND comment='crosslink-c1'"]
389 set crosslinkC1 [string trim $crosslinkC1 ']
390 set crosslinkFa [string trim [fossil_sql "SELECT uuid FROM blob, mlink,
391 filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
392 AND name='a.txt'"] ']
393 set crosslinkFb [string trim [fossil_sql "SELECT uuid FROM blob, mlink,
394 filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid
395 AND name='b.txt'"] ']
396 test crosslink-setup-checkin \
397 {$crosslinkC1 ne "" && $crosslinkFa ne "" && $crosslinkFb ne ""}
398
399 # Every kind of tag that has its own wording in the timeline.
400 foreach {crosslinkName crosslinkCard crosslinkWant} [list \
401 branch "*branch * other" {*Move to branch*other*} \
402 bgcolor-prop "*bgcolor * #112233" \
403 {*Change branch background color to "#112233".*} \
404 bgcolor "+bgcolor * #445566" \
405 {*Change background color to "#445566".*} \
406 bgcolor-off "-bgcolor *" {*Cancel background color.*} \
407 comment "+comment * new\\stext" {*Edit check-in comment.*} \
408 user "+user * carol" {*Change user to "carol".*} \
409 date "+date * 2026-01-06\\s09:00:00" \
410 {*Timestamp 2026-01-06 09:00:00.*} \
411 sym-add "+sym-one *" {*Add tag "one".*} \
412 sym-add-note "+sym-two * a\\snote" \
413 {*Add tag "two" with note "a note".*} \
414 sym-prop "*sym-three *" {*Add propagating tag "three".*} \
415 sym-cancel "-sym-one *" {*Cancel tag "one".*} \
416 closed "+closed *" {*Mark "Closed".*} \
417 closed-off "-closed *" {*Remove the "Closed" mark.*} \
418 other-add "+thing *" {*Add "thing".*} \
@@ -436,16 +431,15 @@
431 "]
432 test crosslink-tag-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
433 crosslink_match crosslink-tag-$crosslinkName-event \
434 [crosslink_event $crosslinkG] "g Edit *:$crosslinkWant"
435 }
436 test_eq crosslink-tag-comment-applied [fossil_sql "SELECT ecomment, euser
437 FROM event WHERE objid=(SELECT rid FROM blob WHERE uuid='$crosslinkC1')"] \
438 {new text|carol}
439
440 # A branch move with its symbolic tags says only that the branch moved.
 
441 set crosslinkG [crosslink_put "D 2026-01-06T11:00:00.000
442 T *branch $crosslinkC1 moved
443 T *sym-moved $crosslinkC1
444 T -sym-other $crosslinkC1
445 U alice
@@ -490,16 +484,16 @@
484 U alice
485 "]
486 test crosslink-checkin {$CODE == 0 && $crosslinkM1 ne ""}
487 test_eq crosslink-checkin-event [crosslink_event $crosslinkM1] \
488 {ci crosslink-c2}
489 test_eq crosslink-checkin-mlink [fossil_sql "SELECT group_concat(
490 name || ':' || mperm || ':' || (pfnid>0), ' ') FROM (SELECT name, mperm,
491 pfnid FROM mlink, filename WHERE mlink.fnid=filename.fnid
492 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')
493 ORDER BY name)"] {a.txt:1:0 b.txt:0:0 c.txt:0:1 l.txt:2:0}
494 test_eq crosslink-checkin-cherrypick [fossil_sql "SELECT count(*)
495 FROM cherrypick WHERE childid=(SELECT rid FROM blob
496 WHERE uuid='$crosslinkM1')"] 1
497
498 # A delta manifest, a second one on the same baseline, and an ordinary
499 # check-in after them. The second does not repeat the removal of a.txt,
@@ -511,16 +505,16 @@
505 F d.txt $crosslinkFb
506 P $crosslinkM1
507 U alice
508 "]
509 test crosslink-delta-checkin {$CODE == 0 && $crosslinkM2 ne ""}
510 test_eq crosslink-delta-checkin-mlink [fossil_sql "SELECT group_concat(
511 name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
512 WHERE mlink.fnid=filename.fnid
513 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM2')
514 ORDER BY name)"] {a.txt:0 d.txt:1}
515 test_eq crosslink-delta-seen [fossil_sql "SELECT value FROM config
516 WHERE name='seen-delta-manifest'"] 1
517
518 set crosslinkM3 [crosslink_put "B $crosslinkM1
519 C crosslink-c4
520 D 2026-01-07T12:00:00.000
@@ -528,11 +522,11 @@
522 F d.txt $crosslinkFa
523 F e.txt $crosslinkFa
524 P $crosslinkM2
525 U alice
526 "]
527 test_eq crosslink-delta-to-delta-mlink [fossil_sql "SELECT group_concat(
528 name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
529 WHERE mlink.fnid=filename.fnid
530 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM3')
531 ORDER BY name)"] {a.txt:1 c.txt:0 d.txt:1 e.txt:1}
532
@@ -541,11 +535,11 @@
535 F a.txt $crosslinkFa
536 F e.txt $crosslinkFb
537 P $crosslinkM3
538 U alice
539 "]
540 test_eq crosslink-full-after-delta-mlink [fossil_sql "SELECT group_concat(
541 name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename
542 WHERE mlink.fnid=filename.fnid
543 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')
544 ORDER BY name)"] {a.txt:1 d.txt:0 e.txt:1 l.txt:0}
545
@@ -584,11 +578,11 @@
578 F a.txt $crosslinkFa
579 P $crosslinkM1
580 U alice
581 "]
582 test crosslink-missing-baseline {$CODE == 0 && $crosslinkBad ne ""}
583 test_eq crosslink-missing-baseline-no-event [fossil_sql "SELECT count(*)
584 FROM event WHERE comment='crosslink-no-baseline'"] 0
585
586 # A check-in whose parent is that one is still shown; its files cannot be
587 # compared with the parent's.
588 set crosslinkM6 [crosslink_put "C crosslink-child-of-no-baseline
@@ -599,33 +593,33 @@
593 "]
594 test_eq crosslink-child-of-missing-baseline [crosslink_event $crosslinkM6] \
595 {ci crosslink-child-of-no-baseline}
596
597 write_file not-an-artifact.txt "This is a file.\n"
598 set crosslinkEvents [fossil_sql "SELECT count(*) FROM event"]
599 fossil test-content-put --crosslink not-an-artifact.txt
600 test crosslink-not-an-artifact {$CODE == 0}
601 test_eq crosslink-not-an-artifact-no-event \
602 [fossil_sql "SELECT count(*) FROM event"] $crosslinkEvents
603
604 ###############################################################################
605 # The "parent" tag gives a check-in other parents; a bad value is ignored.
606
607 fossil reparent $crosslinkM4 $crosslinkC1 $crosslinkM2
608 test crosslink-reparent {$CODE == 0}
609 test_eq crosslink-reparent-plink [fossil_sql "SELECT count(*) FROM plink
610 WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4')"] 2
611 test_eq crosslink-reparent-primary [fossil_sql "SELECT uuid FROM plink,
612 blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
613 WHERE uuid='$crosslinkM4')"] $crosslinkC1
614
615 crosslink_put "D 2026-01-08T10:00:00.000
616 T +parent $crosslinkM3 not-a-hash
617 U alice
618 "
619 test crosslink-reparent-bad-value {$CODE == 0}
620 test_eq crosslink-reparent-bad-value-ignored [fossil_sql "SELECT uuid
621 FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
622 WHERE uuid='$crosslinkM3')"] $crosslinkM2
623
624 # A value of good hashes followed by a short word is ignored as a whole,
625 # both when the tag arrives and when a rebuild reads it again.
@@ -638,54 +632,57 @@
632 set crosslinkG [crosslink_put "D 2026-01-08T10:0[incr crosslinkI]:00.000
633 T +parent $crosslinkM3 $crosslinkValue
634 U alice
635 "]
636 test crosslink-reparent-$crosslinkName {$CODE == 0 && $crosslinkG ne ""}
637 test_eq crosslink-reparent-$crosslinkName-ignored [fossil_sql "SELECT
638 uuid FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid
639 FROM blob WHERE uuid='$crosslinkM3')"] $crosslinkM2
640 }
641 fossil rebuild
642 test crosslink-reparent-short-rebuild {$CODE == 0}
643 test_eq crosslink-reparent-short-rebuild-ignored [fossil_sql "SELECT uuid
644 FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob
645 WHERE uuid='$crosslinkM3')"] $crosslinkM2
646
647 ###############################################################################
648 # A cluster removes its members from the list of unclustered artifacts.
649
650 set crosslinkBefore [fossil_sql "SELECT count(*) FROM unclustered"]
651 set crosslinkCl ""
652 foreach crosslinkHash [lsort [list $crosslinkC1 $crosslinkM1 $crosslinkNone2]] {
653 append crosslinkCl "M $crosslinkHash\n"
654 }
655 set crosslinkCl [crosslink_put $crosslinkCl]
656 test crosslink-cluster {$CODE == 0 && $crosslinkCl ne ""}
657 test_eq crosslink-cluster-tag [fossil_sql "SELECT count(*) FROM tagxref
658 WHERE tagid=(SELECT tagid FROM tag WHERE tagname='cluster')
659 AND rid=(SELECT rid FROM blob WHERE uuid='$crosslinkCl')"] 1
660 test crosslink-cluster-unclustered \
661 {[fossil_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1}
662
663 ###############################################################################
664 # The JSON form of each kind of artifact.
665
666 foreach {crosslinkKind crosslinkHash crosslinkWant} [list \
667 wiki $crosslinkW2 \
668 {*"type":"wiki"*"L":"Crosslink Page"*"N":"text/x-markdown"*"P":*"W":*} \
669 technote $crosslinkE1 \
670 {*"type":"technote"*"C":"First note"*"E":*"T":*"W":*} \
671 ticket $crosslinkT5 {*"type":"ticket"*"J":*"append":true*"K":*} \
672 ticket2 $crosslinkT2 {*"type":"ticket"*"J":*"append":false*} \
673 forum $crosslinkF3 {*"type":"forumpost"*"G":*"I":*"P":*"W":*} \
674 forum2 $crosslinkF5 {*"type":"forumpost"*"H":"New title"*} \
675 attachment "" {*"type":"attachment"*"A":*} \
676 tag $crosslinkG {*"type":"tag"*"T":*} \
677 checkin $crosslinkM1 \
678 {*"type":"checkin"*"C":"crosslink-c2"*"F":*"perm":"x"*"P":*"Q":*"T":*"U":"alice"*} \
679 delta $crosslinkM2 {*"type":"checkin"*"B":*"F":*} \
680 cluster $crosslinkCl {*"type":"cluster"*"M":*} \
681 ] {
682 if {$crosslinkHash eq ""} {
683 set crosslinkHash [string trim [fossil_sql "SELECT uuid FROM blob,
684 attachment WHERE rid=attachid ORDER BY rid LIMIT 1"] ']
685 }
686 fossil test-artifact-to-json $crosslinkHash
687 test crosslink-json-$crosslinkKind {$CODE == 0}
688 crosslink_match crosslink-json-$crosslinkKind-text $RESULT $crosslinkWant
@@ -703,23 +700,23 @@
700 fossil test-artifact-to-json $crosslinkFa no-such-name -expectError
701 test crosslink-json-not-artifact {$CODE != 0}
702
703 # The same through SQL: by hash, by record number, and with arguments
704 # that name nothing.
705 crosslink_match crosslink-json-sql-name [fossil_sql \
706 "SELECT artifact_to_json('$crosslinkW1')"] {*"type":"wiki"*}
707 crosslink_match crosslink-json-sql-rid [fossil_sql "SELECT artifact_to_json(
708 (SELECT rid FROM blob WHERE uuid='$crosslinkW1'))"] {*"type":"wiki"*}
709 test_eq crosslink-json-sql-data [fossil_sql \
710 "SELECT artifact_to_json('$crosslinkFa') IS NULL"] 1
711 fossil sql "SELECT artifact_to_json(NULL)" -expectError
712 test crosslink-json-sql-null {$CODE != 0}
713 crosslink_match crosslink-json-sql-null-message $RESULT \
714 {*Expecting one argument*}
715 fossil sql "SELECT artifact_to_json(1.5)" -expectError
716 test crosslink-json-sql-float {$CODE != 0}
717 test_eq crosslink-json-sql-zero [fossil_sql \
718 "SELECT artifact_to_json(0) IS NULL"] 1
719 fossil sql "SELECT artifact_to_json()" -expectError
720 test crosslink-json-sql-no-argument {$CODE != 0}
721
722 ###############################################################################
@@ -734,20 +731,30 @@
731 first-line-not-a-card "1 x\nD 2026-02-01T10:00:00.000\n" \
732 {*line 1 not recognized*} \
733 control-tags-itself "D 2026-02-01T10:00:00.000\nT +sym-x *\nU alice\n" \
734 {*self-referential T-card in control artifact*} \
735 technote-tags-another \
736 [join [list \
737 "D 2026-02-01T10:00:00.000\n" \
738 "E 2026-02-01T09:00:00 $crosslinkH40\n" \
739 "T +sym-x $crosslinkH40\nU alice\nW 1\nx\n"] ""] \
740 {*non-self-referential T-card in technote*} \
741 technote-propagating-tag \
742 [join [list \
743 "D 2026-02-01T10:00:00.000\n" \
744 "E 2026-02-01T09:00:00 $crosslinkH40\nT *sym-x *\nU alice\n" \
745 "W 1\nx\n"] ""] \
746 {*T-card with '\*' or '-' in technote*} \
747 forum-title-on-reply \
748 [join [list \
749 "D 2026-02-01T10:00:00.000\nG $crosslinkH40\nH title\n" \
750 "I $crosslinkH40\nU alice\nW 1\nx\n"] ""] \
751 {*cannot have I-card and H-card in a forum post*} \
752 forum-two-parents \
753 [join [list \
754 "D 2026-02-01T10:00:00.000\nG $crosslinkH40\n" \
755 "P $crosslinkH40 $crosslinkNone\nU alice\nW 1\nx\n"] ""] \
756 {*too many arguments to P-card*} \
757 ] {
758 fossil test-parse-manifest [crosslink_file $crosslinkBody]
759 test crosslink-refuse-$crosslinkName {$CODE == 0}
760 crosslink_match crosslink-refuse-$crosslinkName-reason $RESULT \
@@ -775,14 +782,19 @@
782 {*manifest_parse() worked*}
783
784 # A tech note may have its N card after its P card, as old versions of
785 # Fossil wrote it. A file with a reserved name in a check-in is left out.
786 fossil test-parse-manifest [crosslink_file \
787 [join [list \
788 "D 2026-02-01T10:00:00.000\n" \
789 "E 2026-02-01T09:00:00 $crosslinkH40\nP $crosslinkH40\n" \
790 "N text/plain\nU alice\nW 1\nx\n"] ""]]
791 crosslink_match crosslink-technote-n-after-p $RESULT {*manifest_parse() worked*}
792 fossil test-parse-manifest [crosslink_file \
793 [join [list \
794 "C reserved\nD 2026-02-01T10:00:00.000\n" \
795 "F _FOSSIL_ $crosslinkH40\nF a.txt $crosslinkH40\nU alice\n"] ""]] 2
796 crosslink_match crosslink-reserved-name-ignored $RESULT \
797 {*manifest_parse() worked*}
798
799 # Content that is not an artifact but begins like one. The quick check
800 # and the parser must agree about each.
@@ -792,11 +804,11 @@
804 no-newline "D 2026-02-01T10:00:00.000 and no end of line" \
805 one-card "D x\n" \
806 short "D\n" \
807 second-lower "D 2026-02-01T10:00:00.000\nlower case\n" \
808 second-earlier "D 2026-02-01T10:00:00.000\nC comment\nmore text here\n" \
809 second-no-space "D 2026-02-01T10:00:00.000\nUalice and more\n" \
810 late-letter "N text/plain\nU alice and more\n" \
811 ] {
812 write_file wf-$crosslinkName.txt $crosslinkText
813 fossil test-content-put wf-$crosslinkName.txt
814 test crosslink-not-wellformed-$crosslinkName {$CODE == 0}
@@ -810,23 +822,23 @@
822 crosslink_match crosslink-wiki-is-not-a-checkin-message $RESULT \
823 {*not a valid check-in*}
824
825 # Wiki text and a tech note that begin with blank space, and crosslinking
826 # with SQL tracing on.
827 crosslink_put "D 2026-02-02T10:00:00.000
828 L Indented
829 U alice
830 [crosslink_w "\n\n indented"]"
831 test_eq crosslink-wiki-leading-space-length [fossil_sql "SELECT value
832 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
833 AND tagname='wiki-Indented'"] 8
834 crosslink_put "C Indented\\snote
835 D 2026-02-02T11:00:00.000
836 E 2026-02-02T09:00:00 [string repeat 12 20]
837 U alice
838 [crosslink_w "\n note"]"
839 test_eq crosslink-technote-leading-space-length [fossil_sql "SELECT value
840 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
841 AND tagname='event-[string repeat 12 20]'"] 4
842 fossil_raw test-crosslink $crosslinkW1 --sqltrace
843 test crosslink-sqltrace {$CODE == 0}
844 crosslink_match crosslink-sqltrace-text $RESULT {*-- manifest_crosslink(*}
@@ -853,19 +865,20 @@
865 crosslink_match crosslink-parse-all-text $RESULT {*tests with 0 errors*}
866 fossil test-parse-all-blobs --limit 3
867 crosslink_match crosslink-parse-all-limit $RESULT {*3 tests with 0 errors*}
868 fossil test-parse-all-blobs --wellformed
869 test crosslink-parse-all-wellformed {$CODE == 0}
870 crosslink_match crosslink-parse-all-wellformed-text $RESULT \
871 {*tests with 0 errors*}
872
873 # Crosslinking an artifact a second time changes nothing.
874 set crosslinkEvents [fossil_sql "SELECT count(*) FROM event"]
875 fossil test-crosslink $crosslinkM1
876 test crosslink-again {$CODE == 0}
877 fossil test-crosslink $crosslinkW1
878 test crosslink-again-wiki {$CODE == 0}
879 test_eq crosslink-again-events [fossil_sql "SELECT count(*) FROM event"] \
880 $crosslinkEvents
881 fossil test-crosslink -expectError
882 test crosslink-usage {$CODE != 0}
883
884 ###############################################################################
@@ -875,18 +888,18 @@
888 (SELECT count(*) FROM attachment) || ' ' ||
889 (SELECT count(*) FROM forumpost) || ' ' ||
890 (SELECT count(*) FROM plink) || ' ' ||
891 (SELECT count(*) FROM mlink) || ' ' ||
892 (SELECT count(*) FROM ticket)}
893 set crosslinkBefore [fossil_sql $crosslinkState]
894 set crosslinkText [fossil_sql "SELECT group_concat(x, char(10)) FROM
895 (SELECT type || ' ' || comment AS x FROM event ORDER BY type, objid)"]
896 fossil rebuild
897 test crosslink-rebuild {$CODE == 0}
898 test_eq crosslink-rebuild-same-counts [fossil_sql $crosslinkState] \
899 $crosslinkBefore
900 test_eq crosslink-rebuild-same-events [fossil_sql "SELECT
901 group_concat(x, char(10)) FROM (SELECT type || ' ' || comment AS x
902 FROM event ORDER BY type, objid)"] $crosslinkText
903 fossil test-integrity
904 test crosslink-integrity {$CODE == 0}
905
@@ -903,11 +916,11 @@
916 none "D 2026-03-01T10:03:00.000\nT +sym-kind-test $crosslinkC1\nU alice\n" \
917 control \
918 ] {
919 set crosslinkHash [crosslink_put $crosslinkBody]
920 test crosslink-mcdc-kind-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
921 test_eq crosslink-mcdc-kind-$crosslinkName-event [fossil_sql "SELECT
922 count(*) FROM event, blob WHERE objid=rid AND uuid='$crosslinkHash'
923 AND type='ci'"] [expr {$crosslinkKind eq "ci" ? 1 : 0}]
924 fossil test-parse-manifest [crosslink_file $crosslinkBody]
925 crosslink_match crosslink-mcdc-kind-$crosslinkName-parse $RESULT \
926 {*manifest_parse() worked*}
@@ -920,25 +933,29 @@
933 # first parent arrives. A merge parent that arrives while the first
934 # parent is present adds them at once.
935
936 # The hash a check-in with the cards BODY will have, without storing it.
937 proc crosslink_hash {body} {
938 return [sha3_file [crosslink_file $body]]
 
 
939 }
940
941 # The number of file links that join the check-in CHILD to its parent
942 # PARENT.
943 proc crosslink_links {child parent} {
944 return [fossil_sql "SELECT count(*) FROM mlink WHERE
945 mid=(SELECT rid FROM blob WHERE uuid='$child')
946 AND pmid=(SELECT rid FROM blob WHERE uuid='$parent')"]
947 }
948
949 set crosslinkPA [crosslink_hash \
950 [join [list \
951 "C first\\sparent\nD 2026-03-02T10:00:00.000\n" \
952 "F a.txt $crosslinkFa\nU alice\n"] ""]]
953 set crosslinkPB [crosslink_hash \
954 [join [list \
955 "C second\\sparent\nD 2026-03-02T10:01:00.000\n" \
956 "F a.txt $crosslinkFb\nU alice\n"] ""]]
957 set crosslinkKid [crosslink_put "C merge\\skid
958 D 2026-03-02T11:00:00.000
959 F a.txt $crosslinkNone
960 P $crosslinkPA $crosslinkPB
961 U alice
@@ -967,12 +984,18 @@
984 test_eq crosslink-mcdc-merge-parent-second-links \
985 [list [crosslink_links $crosslinkKid $crosslinkPA] \
986 [crosslink_links $crosslinkKid $crosslinkPB]] {1 1}
987
988 # The first parent present, the second arriving later.
989 set crosslinkQA [crosslink_hash \
990 [join [list \
991 "C other\\sfirst\nD 2026-03-02T12:00:00.000\n" \
992 "F a.txt $crosslinkFa\nU alice\n"] ""]]
993 set crosslinkQB [crosslink_hash \
994 [join [list \
995 "C other\\ssecond\nD 2026-03-02T12:01:00.000\n" \
996 "F a.txt $crosslinkFb\nU alice\n"] ""]]
997 crosslink_put "C other\\sfirst
998 D 2026-03-02T12:00:00.000
999 F a.txt $crosslinkFa
1000 U alice
1001 "
@@ -998,15 +1021,17 @@
1021 # An empty title on the first post of a forum thread is shown as deleted,
1022 # and an empty title or page text is null in the JSON form. Each row
1023 # differs from the one before in a single card.
1024
1025 foreach {crosslinkName crosslinkBody crosslinkWant crosslinkJson} [list \
1026 title \
1027 "D 2026-03-03T10:00:00.000\nH Some\\stitle\nU alice\n[crosslink_w {x}]" \
1028 {f Post: Some title} {*"H":"Some title"*"W":"x"*} \
1029 empty-title "D 2026-03-03T10:01:00.000\nH \nU alice\n[crosslink_w {x}]" \
1030 {f Post: (Deleted)} {*"H":null*"W":"x"*} \
1031 empty-text \
1032 "D 2026-03-03T10:02:00.000\nH Some\\stitle\nU alice\n[crosslink_w {}]" \
1033 {f Post: Some title} {*"H":"Some title"*"W":null*} \
1034 ] {
1035 set crosslinkHash [crosslink_put $crosslinkBody]
1036 test crosslink-mcdc-forum-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1037 test_eq crosslink-mcdc-forum-$crosslinkName-event \
@@ -1016,11 +1041,12 @@
1041 $crosslinkJson
1042 }
1043
1044 # A wiki page with no text has a null W card in JSON.
1045 fossil test-artifact-to-json $crosslinkW3
1046 crosslink_match crosslink-mcdc-json-empty-wiki $RESULT \
1047 {*"type":"wiki"*"W":null*}
1048
1049 ###############################################################################
1050 # A tag card whose value is empty reads like one with no value.
1051
1052 set crosslinkMin 10
@@ -1055,25 +1081,21 @@
1081 "]
1082 test crosslink-mcdc-cherry-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""}
1083 test_eq crosslink-mcdc-cherry-$crosslinkName-event \
1084 [crosslink_event $crosslinkHash] "ci cherry-$crosslinkName"
1085 }
1086 test_eq crosslink-mcdc-cherry-unseen-not-stored [fossil_sql "SELECT count(*)
1087 FROM blob WHERE uuid='$crosslinkUnseen'"] 0
1088
1089 ###############################################################################
1090 # The information page of a wiki page, asked for by the name of something
1091 # that is not a wiki page: a check-in, a ticket, a forum post, a file, and
1092 # a hash that names nothing.
1093
1094 proc crosslink_get {path} {
1095 return [fossil_http [file join [pwd] .rep.fossil] [request_get $path] \
1096 --ipaddr 127.0.0.1 --localauth]
 
 
 
 
1097 }
1098
1099 foreach {crosslinkName crosslinkHash crosslinkIs} [list \
1100 wiki $crosslinkW1 1 \
1101 checkin $crosslinkC1 0 \
@@ -1102,11 +1124,11 @@
1124 F l.txt $crosslinkFa l
1125 P $crosslinkM2
1126 U alice
1127 "]
1128 test crosslink-mcdc-back-after-delta {$CODE == 0 && $crosslinkBack ne ""}
1129 test_eq crosslink-mcdc-back-after-delta-mlink [fossil_sql "SELECT
1130 group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1131 pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1132 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkBack')
1133 ORDER BY name)"] {a.txt:0:1 c.txt:1:0 d.txt:1:0}
1134
@@ -1129,11 +1151,11 @@
1151 D 2026-03-07T10:01:00.000
1152 F a.txt $crosslinkFa x
1153 P $crosslinkGhost
1154 U alice
1155 "]
1156 test_eq crosslink-mcdc-delta-removes-unknown-child-mlink [fossil_sql "SELECT
1157 group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1158 pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1159 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
1160 ORDER BY name)"] {c.txt:1:0 l.txt:1:0}
1161
@@ -1155,11 +1177,11 @@
1177 set crosslinkG [crosslink_put "D 2026-03-07T11:01:00.000
1178 T +parent $crosslinkKid3 $crosslinkM1
1179 U alice
1180 "]
1181 test crosslink-mcdc-reparent-no-baseline-tag {$CODE == 0 && $crosslinkG ne ""}
1182 test_eq crosslink-mcdc-reparent-no-baseline-plink [fossil_sql "SELECT count(*)
1183 FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkKid3')
1184 AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')"] 1
1185 test_eq crosslink-mcdc-reparent-no-baseline-no-links \
1186 [crosslink_links $crosslinkKid3 $crosslinkM1] 0
1187
@@ -1181,25 +1203,26 @@
1203 P $crosslinkC1
1204 U alice
1205 "]
1206 fossil test-content-put --crosslink $crosslinkOnWiki $crosslinkBasedOnWiki
1207 test crosslink-mcdc-wiki-baseline {$CODE == 0}
1208 test_eq crosslink-mcdc-wiki-baseline-events [fossil_sql "SELECT
1209 group_concat(comment, ' ') FROM event WHERE type='ci'
1210 AND comment IN ('child-of-wiki-page','based-on-wiki-page')"] \
1211 {child-of-wiki-page}
1212 fossil sha3sum $crosslinkBasedOnWiki
1213 test_eq crosslink-mcdc-wiki-baseline-waiting [fossil_sql "SELECT count(*)
1214 FROM orphan WHERE rid=(SELECT rid FROM blob
1215 WHERE uuid='[lindex $RESULT 0]')
1216 AND baseline=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1
1217
1218 ###############################################################################
1219 # Scripts that run when artifacts are stored by a command.
1220 #
1221 # A script for check-ins can ask for the JSON form of the parent of a
1222 # check-in that "branch new" makes. A common script that fails makes "ticket
1223 # add"
1224 # fail, after the ticket has been entered. A tag put on a wiki page by
1225 # "tag add" is recorded like a tag on a check-in.
1226
1227 proc crosslink_script {name script} {
1228 if {$script eq ""} {
@@ -1214,32 +1237,32 @@
1237 FROM plink, blob WHERE cid=blob.rid AND blob.uuid=$uuid} {puts "PARENT $j"}}
1238 fossil branch new scripted $crosslinkM1
1239 test crosslink-mcdc-script-branch {$CODE == 0}
1240 crosslink_match crosslink-mcdc-script-branch-parent-json $RESULT \
1241 {*PARENT *&quot;type&quot;:&quot;checkin&quot;*&quot;C&quot;:&quot;crosslink-c2&quot;*}
1242 test_eq crosslink-mcdc-script-branch-made [fossil_sql "SELECT count(*)
1243 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
1244 AND tagname='sym-scripted'"] 1
1245 crosslink_script xfer-commit-script ""
1246
1247 set crosslinkTickets [fossil_sql "SELECT count(*) FROM ticket"]
1248 crosslink_script xfer-common-script {error common-script-says-no}
1249 fossil ticket add title Scripted status Open -expectError
1250 test crosslink-mcdc-script-ticket-fails {$CODE != 0}
1251 crosslink_match crosslink-mcdc-script-ticket-message $RESULT \
1252 {*common-script-says-no*}
1253 test_eq crosslink-mcdc-script-ticket-entered [fossil_sql "SELECT count(*)
1254 FROM ticket WHERE title='Scripted'"] 1
1255 crosslink_script xfer-common-script ""
1256 fossil ticket add title Unscripted status Open
1257 test crosslink-mcdc-no-script-ticket {$CODE == 0}
1258 test_eq crosslink-mcdc-no-script-ticket-count [fossil_sql "SELECT count(*)
1259 FROM ticket"] [expr {$crosslinkTickets + 2}]
1260
1261 fossil tag add on-a-wiki-page $crosslinkW1
1262 test crosslink-mcdc-tag-add-wiki {$CODE == 0}
1263 crosslink_match crosslink-mcdc-tag-add-wiki-event [fossil_sql "SELECT comment
1264 FROM event WHERE type='g' AND comment LIKE '%on-a-wiki-page%'"] \
1265 "Edit \\\[[string range $crosslinkW1 0 15]|*\\\]: Add *\"on-a-wiki-page\"."
1266
1267 ###############################################################################
1268 # A repository made before cherrypicks were recorded has no table for
@@ -1255,15 +1278,15 @@
1278 U alice
1279 "]
1280 test crosslink-mcdc-cherry-no-table {$CODE == 0 && $crosslinkHash ne ""}
1281 test_eq crosslink-mcdc-cherry-no-table-event [crosslink_event $crosslinkHash] \
1282 {ci cherry-no-table}
1283 test_eq crosslink-mcdc-cherry-no-table-still-none [fossil_sql "SELECT count(*)
1284 FROM sqlite_schema WHERE name='cherrypick'"] 0
1285 fossil rebuild
1286 test crosslink-mcdc-cherry-rebuild {$CODE == 0}
1287 test_eq crosslink-mcdc-cherry-rebuild-recorded [fossil_sql "SELECT count(*)
1288 FROM cherrypick WHERE childid=(SELECT rid FROM blob
1289 WHERE uuid='$crosslinkHash')"] 1
1290
1291 ###############################################################################
1292 # The quick check for an artifact and the parser must agree.
@@ -1331,11 +1354,11 @@
1354 {$crosslinkR1 ne "" && $crosslinkR2 ne "" && $crosslinkR3 ne ""}
1355
1356 # The primary parent of the check-in with the given hash.
1357 #
1358 proc crosslink_primary {hash} {
1359 return [fossil_sql "SELECT uuid FROM plink, blob WHERE pid=rid
1360 AND isprim AND cid=(SELECT rid FROM blob WHERE uuid='$hash')"]
1361 }
1362
1363 crosslink_put "D 2026-04-01T11:00:00.000
1364 T +parent $crosslinkR3 $crosslinkR1\\s
@@ -1360,11 +1383,11 @@
1383 crosslink_put "D 2026-04-01T11:03:00.000
1384 T +parent $crosslinkHash $crosslinkR1
1385 U alice
1386 "
1387 test crosslink-reparent-wiki-page {$CODE == 0}
1388 test_eq crosslink-reparent-wiki-page-no-links [fossil_sql "SELECT count(*)
1389 FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')"] 0
1390
1391 ###############################################################################
1392 # A check-in with two parents lists both in its JSON form.
1393
@@ -1371,11 +1394,11 @@
1394 set crosslinkHash [crosslink_put "C two-parents-json
1395 D 2026-04-01T12:00:00.000
1396 P $crosslinkR3 $crosslinkR1
1397 U alice
1398 "]
1399 test_eq crosslink-json-second-parent [fossil_sql "SELECT
1400 json_extract(artifact_to_json('$crosslinkHash'), '\$.P\[1\]')"] \
1401 $crosslinkR1
1402
1403 ###############################################################################
1404 # A wiki page with two parents: both are linked, the first as the
@@ -1393,11 +1416,11 @@
1416 L Two\\sParents
1417 P $crosslinkWa $crosslinkWb
1418 U alice
1419 [crosslink_w {both}]"]
1420 test crosslink-wiki-two-parents {$CODE == 0 && $crosslinkHash ne ""}
1421 test_eq crosslink-wiki-two-parents-plink [fossil_sql "SELECT
1422 group_concat(uuid || ':' || isprim, ' ') FROM (SELECT uuid, isprim
1423 FROM plink, blob WHERE pid=rid AND cid=(SELECT rid FROM blob
1424 WHERE uuid='$crosslinkHash') ORDER BY isprim DESC)"] \
1425 "$crosslinkWa:1 $crosslinkWb:0"
1426
@@ -1410,13 +1433,13 @@
1433 U alice
1434 [crosslink_w {text}]Z [string repeat 0 32]\n"
1435 fossil test-content-put --crosslink bad-z.txt
1436 test crosslink-bad-z-stored \
1437 {$CODE == 0 && [regexp {inserted as record (\d+)} $RESULT all crosslinkRid]}
1438 test_eq crosslink-bad-z-no-event [fossil_sql "SELECT count(*) FROM event
1439 WHERE objid=$crosslinkRid"] 0
1440 test_eq crosslink-bad-z-no-page [fossil_sql "SELECT count(*) FROM tag
1441 WHERE tagname='wiki-Bad Sum'"] 0
1442
1443 ###############################################################################
1444 # A version of a tech note that arrives after a later version of the same
1445 # note, and names the first version as its parent, does not replace the
@@ -1439,11 +1462,11 @@
1462 E 2026-04-03T09:00:00 $crosslinkEid2
1463 P $crosslinkHash
1464 U alice
1465 [crosslink_w {middle}]"
1466 test crosslink-technote-middle-arrives-last {$CODE == 0}
1467 test_eq crosslink-technote-middle-arrives-last-event [fossil_sql "SELECT
1468 comment FROM event WHERE type='e' AND comment LIKE 'note-%'"] {note-last}
1469
1470 ###############################################################################
1471 # Two delta manifests on one baseline, the second a child of the first.
1472 # The first changes a.txt, removes b.txt and adds x.txt. The second
@@ -1473,11 +1496,11 @@
1496 U alice
1497 "]
1498 test crosslink-two-deltas {$CODE == 0 && $crosslinkHash ne ""}
1499 test_eq crosslink-two-deltas-event [crosslink_event $crosslinkHash] \
1500 {ci two-deltas-child}
1501 test_eq crosslink-two-deltas-mlink [fossil_sql "SELECT
1502 group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name,
1503 pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid
1504 AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')
1505 ORDER BY name)"] {a.txt:1:1}
1506
@@ -1497,16 +1520,16 @@
1520 set crosslinkPrev [lindex $RESULT 0]
1521 lappend crosslinkFiles $crosslinkFn
1522 }
1523 fossil test-content-put --crosslink {*}$crosslinkFiles
1524 test crosslink-same-second {$CODE == 0}
1525 test_eq crosslink-same-second-events [fossil_sql "SELECT count(*)
1526 FROM event WHERE comment LIKE 'same-second-%'"] 33
1527 test_eq crosslink-same-second-order [fossil_sql "SELECT count(*)
1528 FROM plink, event AS p, event AS c WHERE p.objid=pid AND c.objid=cid
1529 AND c.comment LIKE 'same-second-%' AND p.mtime<c.mtime"] 30
1530 test_eq crosslink-same-second-tip-time [fossil_sql "SELECT
1531 strftime('%Y-%m-%d %H:%M:%f', mtime) FROM event
1532 WHERE comment='same-second-32'"] {2026-04-05 10:00:00.000}
1533
1534 ###############################################################################
1535 # A delta manifest whose baseline is missing, received by a pull: it is
@@ -1543,16 +1566,16 @@
1566 fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$crosslinkShun',0)"
1567 set crosslinkHash [crosslink_put "C shun-clustered
1568 D 2026-04-07T10:00:00.000
1569 U alice
1570 "]
1571 test_eq crosslink-shun-unclustered-before [fossil_sql "SELECT count(*)
1572 FROM unclustered, blob WHERE unclustered.rid=blob.rid
1573 AND uuid='$crosslinkHash'"] 1
1574 crosslink_put [join [lsort [list "M $crosslinkShun" "M $crosslinkHash"]] \n]\n
1575 test crosslink-shun-cluster {$CODE == 0}
1576 test_eq crosslink-shun-cluster-clears-other [fossil_sql "SELECT count(*)
1577 FROM unclustered, blob WHERE unclustered.rid=blob.rid
1578 AND uuid='$crosslinkHash'"] 0
1579
1580 set crosslinkG [crosslink_put "D 2026-04-07T10:01:00.000
1581 T +sym-on-shunned $crosslinkShun
@@ -1559,11 +1582,11 @@
1582 U alice
1583 "]
1584 test crosslink-shun-tag {$CODE == 0 && $crosslinkG ne ""}
1585 crosslink_match crosslink-shun-tag-event [crosslink_event $crosslinkG] \
1586 {g Edit \[5e5e5e5e5e5e5e5e|5e5e5e5e5e\]: Add tag "on-shunned".}
1587 test_eq crosslink-shun-tag-tags-nothing [fossil_sql "SELECT count(*)
1588 FROM tagxref, tag WHERE tag.tagid=tagxref.tagid
1589 AND tagname='sym-on-shunned'"] 0
1590
1591 set crosslinkKid [crosslink_put "C shun-merge-kid
1592 D 2026-04-07T11:00:00.000
@@ -1572,11 +1595,11 @@
1595 U alice
1596 "]
1597 test crosslink-shun-merge-parent {$CODE == 0 && $crosslinkKid ne ""}
1598 test_eq crosslink-shun-merge-parent-links \
1599 [crosslink_links $crosslinkKid $crosslinkR1] 1
1600 test_eq crosslink-shun-no-placeholder [fossil_sql "SELECT count(*)
1601 FROM blob WHERE uuid='$crosslinkShun'"] 0
1602 fossil sql "DELETE FROM shun WHERE uuid='$crosslinkShun'"
1603
1604 ###############################################################################
1605 # A common script that fails makes "branch new" fail.
1606
+2 -8
--- test/fuzz.test
+++ test/fuzz.test
@@ -5,15 +5,10 @@
55
#
66
# The scenario inputs are not inputs to "test-fuzz". They are read by
77
# scenario.test.
88
#
99
10
-# These tests run only in a long pass: -assurance stress.
11
-if {[test_assurance] ne "stress"} {
12
- test_skip "runs only with -assurance stress"
13
-}
14
-
1510
require_no_open_checkout
1611
1712
test_setup
1813
1914
source [file join $::testfiledir corpus.tcl]
@@ -28,11 +23,12 @@
2823
fossil test-fuzz $fuzzDir
2924
test fuzz-corpus-$fuzzType {$CODE == 0}
3025
}
3126
3227
foreach {fuzzType fuzzGlob} {wiki *.wiki markdown *.md wiki2 *.md} {
33
- foreach fuzzF [lsort [glob -nocomplain [file join $::testfiledir $fuzzGlob]]] {
28
+ foreach fuzzF [lsort [glob \
29
+ -nocomplain [file join $::testfiledir $fuzzGlob]]] {
3430
fossil test-fuzz --fuzztype $fuzzType $fuzzF
3531
test fuzz-$fuzzType-[file tail $fuzzF] {$CODE == 0}
3632
}
3733
}
3834
@@ -74,8 +70,6 @@
7470
file mkdir not-a-fuzz-type
7571
write_file [file join not-a-fuzz-type x] "x\n"
7672
fossil test-fuzz not-a-fuzz-type -expectError
7773
test fuzz-misnamed-directory {$CODE != 0}
7874
79
-###############################################################################
80
-
8175
test_cleanup
8276
--- test/fuzz.test
+++ test/fuzz.test
@@ -5,15 +5,10 @@
5 #
6 # The scenario inputs are not inputs to "test-fuzz". They are read by
7 # scenario.test.
8 #
9
10 # These tests run only in a long pass: -assurance stress.
11 if {[test_assurance] ne "stress"} {
12 test_skip "runs only with -assurance stress"
13 }
14
15 require_no_open_checkout
16
17 test_setup
18
19 source [file join $::testfiledir corpus.tcl]
@@ -28,11 +23,12 @@
28 fossil test-fuzz $fuzzDir
29 test fuzz-corpus-$fuzzType {$CODE == 0}
30 }
31
32 foreach {fuzzType fuzzGlob} {wiki *.wiki markdown *.md wiki2 *.md} {
33 foreach fuzzF [lsort [glob -nocomplain [file join $::testfiledir $fuzzGlob]]] {
 
34 fossil test-fuzz --fuzztype $fuzzType $fuzzF
35 test fuzz-$fuzzType-[file tail $fuzzF] {$CODE == 0}
36 }
37 }
38
@@ -74,8 +70,6 @@
74 file mkdir not-a-fuzz-type
75 write_file [file join not-a-fuzz-type x] "x\n"
76 fossil test-fuzz not-a-fuzz-type -expectError
77 test fuzz-misnamed-directory {$CODE != 0}
78
79 ###############################################################################
80
81 test_cleanup
82
--- test/fuzz.test
+++ test/fuzz.test
@@ -5,15 +5,10 @@
5 #
6 # The scenario inputs are not inputs to "test-fuzz". They are read by
7 # scenario.test.
8 #
9
 
 
 
 
 
10 require_no_open_checkout
11
12 test_setup
13
14 source [file join $::testfiledir corpus.tcl]
@@ -28,11 +23,12 @@
23 fossil test-fuzz $fuzzDir
24 test fuzz-corpus-$fuzzType {$CODE == 0}
25 }
26
27 foreach {fuzzType fuzzGlob} {wiki *.wiki markdown *.md wiki2 *.md} {
28 foreach fuzzF [lsort [glob \
29 -nocomplain [file join $::testfiledir $fuzzGlob]]] {
30 fossil test-fuzz --fuzztype $fuzzType $fuzzF
31 test fuzz-$fuzzType-[file tail $fuzzF] {$CODE == 0}
32 }
33 }
34
@@ -74,8 +70,6 @@
70 file mkdir not-a-fuzz-type
71 write_file [file join not-a-fuzz-type x] "x\n"
72 fossil test-fuzz not-a-fuzz-type -expectError
73 test fuzz-misnamed-directory {$CODE != 0}
74
 
 
75 test_cleanup
76
+157 -69
--- test/import.test
+++ test/import.test
@@ -4,15 +4,12 @@
44
# are svndiff0 deltas (Text-delta: true), as "svnadmin dump --deltas"
55
# writes them, then git streams, then dumps of whole histories. Where
66
# Subversion or git is installed, a history that it wrote is imported too.
77
#
88
9
-# These tests run only in a long pass: -assurance stress.
10
-if {[test_assurance] ne "stress"} {
11
- test_skip "runs only with -assurance stress"
12
-}
13
-
9
+# The first sections run at every level, and the rest need
10
+# -assurance stress.
1411
test_setup
1512
1613
# A number in the variable-length form of svndiff0: seven bits a byte,
1714
# most significant first, the high bit set on every byte but the last.
1815
#
@@ -29,11 +26,12 @@
2926
# One window: source offset and length, target length, instructions and
3027
# new data. INSTR is a list of byte values.
3128
#
3229
proc import_window {srcoff srclen tgtlen instr data} {
3330
set i [binary format c* $instr]
34
- return "[import_varint $srcoff][import_varint $srclen][import_varint $tgtlen][import_varint [string length $i]][import_varint [string length $data]]$i$data"
31
+ return \
32
+ "[import_varint $srcoff][import_varint $srclen][import_varint $tgtlen][import_varint [string length $i]][import_varint [string length $data]]$i$data"
3533
}
3634
3735
proc import_props {pairs} {
3836
set b ""
3937
foreach {k v} $pairs {
@@ -44,11 +42,14 @@
4442
4543
proc import_rev {n log} {
4644
set p [import_props [list svn:log $log svn:author dan \
4745
svn:date 2026-01-0[expr {$n+1}]T00:00:00.000000Z]]
4846
set len [string length $p]
49
- return "Revision-number: $n\nProp-content-length: $len\nContent-length: $len\n\n$p\n"
47
+ return \
48
+ [join [list \
49
+ "Revision-number: $n\nProp-content-length: $len\n" \
50
+ "Content-length: $len\n\n$p\n"] ""]
5051
}
5152
5253
proc import_node {path kind action {text ""} {delta 0}} {
5354
set p "PROPS-END\n"
5455
set h "Node-path: $path\nNode-kind: $kind\nNode-action: $action\n"
@@ -55,18 +56,24 @@
5556
if {$kind eq "dir"} {
5657
return "${h}Prop-content-length: 10\nContent-length: 10\n\n$p\n\n"
5758
}
5859
if {$delta} { append h "Text-delta: true\n" }
5960
set n [string length $text]
60
- return "${h}Prop-content-length: 10\nText-content-length: $n\nContent-length: [expr {$n+10}]\n\n$p$text\n\n"
61
+ return \
62
+ [join [list \
63
+ "${h}Prop-content-length: 10\nText-content-length: $n\n" \
64
+ "Content-length: [expr {$n+10}]\n\n$p$text\n\n"] ""]
6165
}
6266
6367
# Revision 1 adds trunk/a.txt, "hello world\n", as a delta from nothing.
6468
# Revision 2 changes it by the delta in WINDOWS.
6569
#
6670
proc import_dump {windows {magic "SVN\000"}} {
67
- set d "SVN-fs-dump-format-version: 3\n\nUUID: 00000000-0000-0000-0000-000000000000\n\n"
71
+ set d \
72
+ [join [list \
73
+ "SVN-fs-dump-format-version: 3\n\n" \
74
+ "UUID: 00000000-0000-0000-0000-000000000000\n\n"] ""]
6875
append d [import_rev 0 zero]
6976
append d [import_rev 1 one]
7077
append d [import_node trunk dir add]
7178
append d [import_node trunk/a.txt file add \
7279
"SVN\000[import_window 0 0 12 {0x8c} "hello world\n"]" 1]
@@ -121,12 +128,14 @@
121128
bad-instruction [import_window 0 12 1 {0xc1 0} {}] \
122129
source-window [import_window 1000 12 10 {0x0a 0} {}] \
123130
target-offset [import_window 0 12 10 {0x82 0x48 0x87 0x68} ab] \
124131
target-unwritten [import_window 0 12 4 {0x44 0} {}] \
125132
data-past-end [import_window 0 12 50 {0xb2} abcde] \
126
- huge-instr-len "[import_varint 0][import_varint 12][import_varint 5][import_varint 100000][import_varint 5]\x85abcde" \
127
- huge-data-len "[import_varint 0][import_varint 12][import_varint 5][import_varint 1][import_varint 100000]\x85abcde" \
133
+ huge-instr-len \
134
+ "[import_varint 0][import_varint 12][import_varint 5][import_varint 100000][import_varint 5]\x85abcde" \
135
+ huge-data-len \
136
+ "[import_varint 0][import_varint 12][import_varint 5][import_varint 1][import_varint 100000]\x85abcde" \
128137
truncated-varint "\x80\x80" \
129138
truncated-length [binary format c* {0 12 5 1 5 0x80}] \
130139
target-unfilled [import_window 0 12 4000 {0x85} abcde] \
131140
] {
132141
set importResult [import_try $importName $importWindows]
@@ -135,32 +144,41 @@
135144
}
136145
137146
# Not an svndiff0 delta at all.
138147
test import-svn-not-svndiff {[string match "*Invalid svndiff0*" \
139148
[import_try not abc "XYZ\000"]]}
149
+
150
+if {[test_assurance] ne "stress"} {
151
+ test_skip "the tests after the first sections need -assurance stress"
152
+}
140153
141154
###############################################################################
142155
# A dump written by Subversion itself, with deltas of several windows.
143156
# Every version that Fossil imports must be byte for byte the one that
144157
# Subversion holds.
145158
146
-if {[catch {exec svnadmin --version --quiet}] || [catch {exec svn --version --quiet}]} {
159
+if {[catch {exec svnadmin --version --quiet}] || [catch \
160
+ {exec svn --version --quiet}]} {
147161
test_skip_part "svnadmin and svn are not installed"
148162
} else {
149163
set importRepo [file join [pwd] svnrepo]
150164
exec svnadmin create $importRepo
151165
exec svn checkout -q file://$importRepo svnwc
152166
file mkdir svnwc/trunk
153167
set importBase ""
154168
for {set importI 0} {$importI < 6000} {incr importI} {
155
- append importBase "line $importI of a file that spans several delta windows\n"
169
+ append importBase \
170
+ "line $importI of a file that spans several delta windows\n"
156171
}
157172
set importVersions [list $importBase]
158173
set importNext ""
159
- for {set importI 0} {$importI < [string length $importBase]} {incr importI 20000} {
160
- append importNext [string range $importBase $importI [expr {$importI+19999}]]
161
- append importNext [string repeat x 3000] [string repeat "pattern $importI " 300]
174
+ for {set importI 0} {$importI < [string length $importBase]} \
175
+ {incr importI 20000} {
176
+ append importNext [string range $importBase $importI \
177
+ [expr {$importI+19999}]]
178
+ append importNext [string repeat x 3000] \
179
+ [string repeat "pattern $importI " 300]
162180
}
163181
lappend importVersions $importNext
164182
lappend importVersions "[string repeat {repeated line of text} 20000]\n"
165183
write_file svnwc/trunk/a.txt [lindex $importVersions 0]
166184
exec svn add -q svnwc/trunk
@@ -189,11 +207,12 @@
189207
# Fossil check-in artifact, one whose second card is a P card that names no
190208
# parent. The file is imported as a file: the repository holds one
191209
# check-in, the imported commit, and the file reads back with a line added
192210
# at its end that stops it being an artifact.
193211
194
-set importArt "D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"
212
+set importArt \
213
+ "D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"
195214
append importArt "T *branch * planted\nT *sym-planted *\nU mallory\n"
196215
write_file git-artifact-body.txt $importArt
197216
fossil md5sum git-artifact-body.txt
198217
append importArt "Z [lindex $RESULT 0]\n"
199218
set importStream "blob\nmark :1\ndata [string length $importArt]\n$importArt\n"
@@ -208,31 +227,43 @@
208227
fossil sql -R git-artifact.fossil \
209228
"SELECT count(*) FROM tag WHERE tagname='sym-planted'"
210229
test_eq import-git-artifact-no-branch [string trim $RESULT] 0
211230
fossil_raw cat f.txt -R git-artifact.fossil -r trunk
212231
test_eq import-git-artifact-content $RESULT \
213
- "${importArt}# Remove this line to create a well-formed Fossil control artifact.\n"
232
+ [join [list \
233
+ "${importArt}# Remove this line to create a well-formed " \
234
+ "Fossil control artifact.\n"] ""]
214235
215236
###############################################################################
216237
# Input that "fossil import" must refuse with an error and exit code 1.
217238
218239
# Each row: a git stream. The length of a data command is negative, too
219240
# large to hold, or not a number; the time of a committer is past the
220
-# year 9999, has thirteen digits, or has no space before it; a commit
221
-# names a ref of 992 bytes with no slash and no newline.
241
+# year 9999, has thirteen digits, or has no space before it.
222242
#
223243
set importWho "committer C <[email protected]>"
224244
foreach {importName importStream} [list \
225
- data-negative "blob\nmark :1\ndata -1\nhello world, and more than one byte\n" \
245
+ data-negative \
246
+ "blob\nmark :1\ndata -1\nhello world, and more than one byte\n" \
226247
data-huge "blob\nmark :1\ndata 2147483647\nhello\n" \
227248
data-not-number "blob\nmark :1\ndata <<EOF\nhello\nEOF\n" \
228
- time-past-9999 "commit refs/heads/master\nmark :1\n$importWho 253402300800 +0000\ndata 1\nx\n" \
229
- time-13-digits "commit refs/heads/master\nmark :1\n$importWho 9999999999999 +0000\ndata 1\nx\n" \
230
- time-no-space "commit refs/heads/master\nmark :1\n${importWho}1700000000 +0000\ndata 1\nx\n" \
249
+ time-past-9999 \
250
+ [join [list \
251
+ "commit refs/heads/master\nmark :1\n" \
252
+ "$importWho 253402300800 +0000\ndata 1\nx\n"] ""] \
253
+ time-13-digits \
254
+ [join [list \
255
+ "commit refs/heads/master\nmark :1\n" \
256
+ "$importWho 9999999999999 +0000\ndata 1\nx\n"] ""] \
257
+ time-no-space \
258
+ [join [list \
259
+ "commit refs/heads/master\nmark :1\n" \
260
+ "${importWho}1700000000 +0000\ndata 1\nx\n"] ""] \
231261
] {
232262
write_file refuse-$importName.fi $importStream
233
- fossil_raw -seconds 60 import --git refuse-$importName.fossil refuse-$importName.fi
263
+ fossil_raw -seconds 60 import --git refuse-$importName.fossil \
264
+ refuse-$importName.fi
234265
test import-refuse-git-$importName {$CODE == 1 &&
235266
[string first "bad fast-import line" $RESULT] >= 0}
236267
}
237268
238269
# A commit command whose name is 992 bytes long, with no slash after its
@@ -251,32 +282,45 @@
251282
append importStart "Revision-number: 1\nProp-content-length: 10\n"
252283
append importStart "Content-length: 10\n\nPROPS-END\n\n"
253284
foreach {importName importDump} [list \
254285
header-cut "SVN-fs-dump-format-version: 2\nUUID: 0000" \
255286
header-zero "SVN-fs-dump-format-version: 2\nUUID: 00\00000\n\n" \
256
- header-long "SVN-fs-dump-format-version: 2\nUUID: [string repeat 0 1200]\n\n" \
257
- no-action "${importStart}Node-path: trunk/a\nNode-kind: file\nText-content-length: 1\nContent-length: 1\n\nx\n\n" \
287
+ header-long \
288
+ "SVN-fs-dump-format-version: 2\nUUID: [string repeat 0 1200]\n\n" \
289
+ no-action \
290
+ [join [list \
291
+ "${importStart}Node-path: trunk/a\nNode-kind: file\n" \
292
+ "Text-content-length: 1\nContent-length: 1\n\nx\n\n"] ""] \
258293
] {
259294
write_file refuse-$importName.dump $importDump
260
- fossil_raw -seconds 60 import --svn refuse-$importName.fossil refuse-$importName.dump
295
+ fossil_raw -seconds 60 import --svn refuse-$importName.fossil \
296
+ refuse-$importName.dump
261297
test import-refuse-svn-$importName {$CODE == 1 &&
262298
[string first "svn-dump data format broken" $RESULT] >= 0}
263299
}
264300
265301
# A file outside trunk, branches and tags is passed over even when it has
266302
# no Node-action.
267303
#
268
-write_file outside.dump "${importStart}Node-path: other/a\nNode-kind: file\nText-content-length: 1\nContent-length: 1\n\nx\n\n"
304
+write_file outside.dump \
305
+ [join [list \
306
+ "${importStart}Node-path: other/a\nNode-kind: file\n" \
307
+ "Text-content-length: 1\nContent-length: 1\n\nx\n\n"] ""]
269308
fossil_raw -seconds 60 import --svn outside.fossil outside.dump
270309
test import-svn-outside-no-action {$CODE == 0}
271310
272311
# An empty --trunk, --branches or --tags is refused unless --base names a
273312
# directory; with one, an empty --trunk makes the base itself the trunk.
274313
#
275
-write_file base.dump "${importStart}Node-path: proj/a\nNode-kind: file\nNode-action: add\nText-content-length: 1\nContent-length: 1\n\nx\n\n"
314
+write_file base.dump \
315
+ [join [list \
316
+ "${importStart}Node-path: proj/a\nNode-kind: file\n" \
317
+ "Node-action: add\nText-content-length: 1\n" \
318
+ "Content-length: 1\n\nx\n\n"] ""]
276319
foreach importName {trunk branches tags} {
277
- fossil_raw -seconds 60 import --svn --$importName "" refuse-$importName.fossil base.dump
320
+ fossil_raw -seconds 60 import --svn --$importName "" \
321
+ refuse-$importName.fossil base.dump
278322
test import-refuse-svn-empty-$importName {$CODE == 1 && [string first \
279323
"may be empty only with a non-empty --base" $RESULT] >= 0}
280324
}
281325
fossil_raw -seconds 60 import --svn --base proj --trunk "" base.fossil base.dump
282326
test import-svn-base-empty-trunk {$CODE == 0}
@@ -295,11 +339,15 @@
295339
# minutes after 2023-11-14 22:13:20 UTC. BODY is the lines that follow
296340
# the comment.
297341
#
298342
proc import_commit {ref mark comment {body ""}} {
299343
set when [expr {1700000000+60*$mark}]
300
- return "commit $ref\nmark :$mark\ncommitter C <[email protected]> $when +0000\ndata [string length $comment]\n$comment\n$body\n"
344
+ return \
345
+ [join [list \
346
+ "commit $ref\nmark :$mark\n" \
347
+ "committer C <[email protected]> $when +0000\n" \
348
+ "data [string length $comment]\n$comment\n$body\n"] ""]
301349
}
302350
303351
proc import_git {name stream args} {
304352
write_file $name.fi $stream
305353
fossil_raw -seconds 60 import --git {*}$args $name.fossil $name.fi
@@ -306,19 +354,19 @@
306354
}
307355
308356
# What repository NAME answers to QUERY.
309357
#
310358
proc import_sql {name query} {
311
- fossil sql -R $name.fossil $query
312
- return [string trim $::RESULT]
359
+ return [fossil_sql $query $name.fossil]
313360
}
314361
315362
# The files of the check-in of NAME whose comment is COMMENT, in name
316363
# order: the name, the permission and the former name of each.
317364
#
318365
proc import_files {name comment} {
319
- return [import_sql $name "SELECT group_concat(trim(f.filename||' '||coalesce(f.perm,'')||' '||coalesce(f.previousName,'')), ', ')
366
+ return [import_sql $name \
367
+ "SELECT group_concat(trim(f.filename||' '||coalesce(f.perm,'')||' '||coalesce(f.previousName,'')), ', ')
320368
FROM event e, blob b, files_of_checkin(b.uuid) f
321369
WHERE e.type='ci' AND e.comment='$comment' AND b.rid=e.objid"]
322370
}
323371
324372
# The branch and tag names that hold for the check-in with comment COMMENT.
@@ -368,11 +416,12 @@
368416
append importStream "M 100644 :1 a.txt\nM 100755 :3 run.sh\nM 120000 :1 link\n"
369417
append importStream "M 100644 :2 empty\n"
370418
append importStream "M 100644 inline in.txt\ndata 7\ninline\n\n"
371419
append importStream "M 100644 :99 missing.txt\n"
372420
append importStream "M 100644 :1 dir/x\nM 100644 :1 dir/y\n"
373
-append importStream "M 100644 :1 tmp/p\nM 100644 :1 tmp/q\nM 100644 :1 tmpfile\n"
421
+append importStream \
422
+ "M 100644 :1 tmp/p\nM 100644 :1 tmp/q\nM 100644 :1 tmpfile\n"
374423
append importStream "M 100644\nN :1 :10\ncheckpoint\n"
375424
append importStream [import_commit refs/heads/master 11 two \
376425
"D run.sh\nD tmp\nC a.txt b.txt\nR link link2\n"]
377426
append importStream [import_commit refs/heads/dev 12 three \
378427
"M 100644 :1 d.txt\n"]
@@ -390,28 +439,36 @@
390439
append importStream "tag unknown\nfrom :97\n$importTagger\n"
391440
append importStream "tag v4\n$importTagger\nfrom :13"
392441
393442
import_git all $importStream
394443
test import-git-all {$CODE == 0}
395
-test import-git-all-progress {[holds_strings $RESULT {"halfway there" 2023-11-14}]}
396
-test_eq import-git-all-checkins [import_checkins all] "one two three four five six"
444
+test import-git-all-progress \
445
+ {[holds_strings $RESULT {"halfway there" 2023-11-14}]}
446
+test_eq import-git-all-checkins [import_checkins all] \
447
+ "one two three four five six"
397448
test_eq import-git-all-user [import_sql all \
398449
"SELECT user||' '||date(mtime) FROM event WHERE comment='one'"] \
399450
"[email protected] 2023-11-14"
400451
test_eq import-git-all-one [import_files all one] \
401
- "a.txt w, dir/x w, dir/y w, empty w, in.txt w, link l, run.sh x, tmp/p w, tmp/q w, tmpfile w"
452
+ [join [list \
453
+ "a.txt w, dir/x w, dir/y w, empty w, in.txt w, link l, " \
454
+ "run.sh x, tmp/p w, tmp/q w, tmpfile w"] ""]
402455
fossil_raw cat in.txt -R all.fossil -r [import_sql all \
403456
"SELECT uuid FROM blob, event WHERE rid=objid AND comment='one'"]
404457
test_eq import-git-all-inline $RESULT "inline\n"
405458
test_eq import-git-all-two [import_files all two] \
406
- "a.txt w, b.txt w, dir/x w, dir/y w, empty w, in.txt w, link2 l link, tmpfile w"
459
+ [join [list \
460
+ "a.txt w, b.txt w, dir/x w, dir/y w, empty w, in.txt w, " \
461
+ "link2 l link, tmpfile w"] ""]
407462
test_eq import-git-all-two-parent [import_parents all two] one
408463
test_eq import-git-all-two-tags [import_tags all two] "master trunk"
409464
test_eq import-git-all-three-parent [import_parents all three] ""
410465
test_eq import-git-all-three-tags [import_tags all three] "dev trunk"
411466
test_eq import-git-all-four [import_files all four] \
412
- "a.txt w, b.txt w, dir2/x w, dir2/y w, dir3/x w dir/x, dir3/y w dir/y, empty w, in.txt w, link2 l, tmpfile w"
467
+ [join [list \
468
+ "a.txt w, b.txt w, dir2/x w, dir2/y w, dir3/x w dir/x, " \
469
+ "dir3/y w dir/y, empty w, in.txt w, link2 l, tmpfile w"] ""]
413470
test_eq import-git-all-four-parents [import_parents all four] "two one three"
414471
test_eq import-git-all-four-tags [import_tags all four] "dev trunk v2 v3 v4"
415472
test_eq import-git-all-tag-comment [import_sql all "SELECT value FROM tagxref
416473
WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-v2')"] "the tag"
417474
test_eq import-git-all-five-tags [import_tags all five] "dev trunk"
@@ -456,11 +513,12 @@
456513
append importStream [import_commit refs/heads/master 2 names $importBody]
457514
append importStream [import_commit refs/heads/master 3 fewer \
458515
"D \"oct\\303\\251\"\nD plain name\n"]
459516
import_git names $importStream
460517
test import-git-names {$CODE == 0}
461
-test_eq import-git-names-files [import_sql names "SELECT group_concat(lower(hex(f.filename)), ' ')
518
+test_eq import-git-names-files \
519
+ [import_sql names "SELECT group_concat(lower(hex(f.filename)), ' ')
462520
FROM event e, blob b, files_of_checkin(b.uuid) f
463521
WHERE e.comment='names' AND b.rid=e.objid"] [lsort $importWant]
464522
test_eq import-git-names-deleted [import_sql names "SELECT count(*)
465523
FROM event e, blob b, files_of_checkin(b.uuid) f
466524
WHERE e.comment='fewer' AND b.rid=e.objid"] 9
@@ -482,11 +540,12 @@
482540
append importStream [import_commit refs/heads/ 2 slash "M 100644 :1 a\n"]
483541
append importStream [import_commit refs/x 3 short "M 100644 :1 a\n"]
484542
append importStream [import_commit refs/heads/master 4 nick \
485543
"property branch-nick 7 nicked\nproperty rebase-of abc\nM 100644 :1 a\n"]
486544
import_git refs $importStream
487
-test_eq import-git-refs [import_sql refs "SELECT group_concat(comment||'='||value, ' ')
545
+test_eq import-git-refs [import_sql refs \
546
+ "SELECT group_concat(comment||'='||value, ' ')
488547
FROM (SELECT comment, value FROM event, tagxref
489548
WHERE rid=objid AND tagxref.tagid=8 ORDER BY event.mtime)"] \
490549
"slash=refs/heads/ short=refs/x nick=nicked"
491550
492551
# A commit on a tag ref that has no parent gets no tag, and a commit with
@@ -566,11 +625,12 @@
566625
#
567626
foreach {importName importStream importError} [list \
568627
unknown-command "bogus line\n" {bad fast-import line: [bogus line]} \
569628
no-angle-bracket "commit refs/heads/master\ncommitter C 1700000000 +0000\n" \
570629
{bad fast-import line: [committer C 1700000000 +0000]} \
571
- no-open-bracket "commit refs/heads/master\ncommitter C [email protected]> 17 +0000\n" \
630
+ no-open-bracket \
631
+ "commit refs/heads/master\ncommitter C [email protected]> 17 +0000\n" \
572632
{bad fast-import line: [committer C [email protected]>} \
573633
short-data "blob\nmark :1\ndata 50\nabc" \
574634
{short read: got 3 of 50 bytes} \
575635
] {
576636
import_git bad-$importName $importStream
@@ -696,13 +756,11 @@
696756
697757
# Marks may name a check-in made by "fossil commit", whose files carry no
698758
# permission, and the files of such a parent are kept. A commit whose
699759
# "from" is the mark of a file keeps nothing from it.
700760
#
701
-write_file plain.txt "plain\n"
702
-fossil add plain.txt
703
-fossil commit -m committed
761
+commit_file plain.txt "plain\n" committed
704762
fossil sql "SELECT 'c'||rid||' :7 '||uuid FROM blob
705763
WHERE rid=(SELECT objid FROM event WHERE comment='committed')"
706764
set importMarks "$RESULT\n"
707765
fossil sql "SELECT 'b'||rid||' :8 '||uuid FROM blob
708766
WHERE rid=(SELECT fid FROM mlink)"
@@ -750,11 +808,13 @@
750808
# A file command acts on a file that an earlier line of the same commit
751809
# made: D removes it, C copies it and R renames it.
752810
#
753811
set importStream [import_blob 1 "hello\n"]
754812
append importStream [import_commit refs/heads/master 2 ordered \
755
- "M 100644 :1 gone\nD gone\nM 100644 :1 src\nC src dst\nM 100644 :1 old\nR old new\n"]
813
+ [join [list \
814
+ "M 100644 :1 gone\nD gone\nM 100644 :1 src\nC src dst\n" \
815
+ "M 100644 :1 old\nR old new\n"] ""]]
756816
import_git ordered $importStream
757817
test_eq import-git-ordered [import_files ordered ordered] \
758818
"dst w, new w, src w" knownBug
759819
760820
###############################################################################
@@ -781,11 +841,12 @@
781841
782842
# Revision N, made by dan on day N+1 of 2026, with LOG as its comment.
783843
#
784844
proc import_r {n log} {
785845
return [import_record [list Revision-number $n] [list svn:log $log \
786
- svn:author dan svn:date [format 2026-01-%02dT00:00:00.000000Z [expr {$n+1}]]]]
846
+ svn:author dan svn:date [format 2026-01-%02dT00:00:00.000000Z \
847
+ [expr {$n+1}]]]]
787848
}
788849
proc import_file {action path text {props -}} {
789850
return [import_record \
790851
[list Node-path $path Node-kind file Node-action $action] $props $text]
791852
}
@@ -842,11 +903,12 @@
842903
[import_file change trunk/a.txt "alpha2\n"] \
843904
[import_file change trunk/run.sh "run2\n"] \
844905
[import_record {Node-path trunk Node-kind dir Node-action change} - xyz] \
845906
[import_file change trunk/sub/s.txt - {svn:eol-style native}]
846907
append importDump [import_r 3 three] [import_copy dir branches/b1 trunk 2]
847
-append importDump [import_r 4 four] [import_file change branches/b1/a.txt "beta\n"]
908
+append importDump [import_r 4 four] \
909
+ [import_file change branches/b1/a.txt "beta\n"]
848910
append importDump [import_r 5 five] [import_copy dir tags/v1 trunk 4] \
849911
[import_copy dir tags/v2 trunk 4]
850912
append importDump [import_r 6 six] \
851913
[import_copy file trunk/b-copy.txt branches/b1/a.txt 4] \
852914
[import_copy file trunk/a2.txt trunk/a.txt 2] \
@@ -891,31 +953,36 @@
891953
test_eq import-svn-layout-two [import_files layout "(no comment)"] \
892954
"a.txt, link l, run.sh x, sub/s.txt"
893955
test_eq import-svn-layout-two-content \
894956
"[import_cat layout {(no comment)} a.txt][import_cat layout {(no comment)} run.sh]" \
895957
"alpha2\nrun2\n"
896
-test_eq import-svn-layout-two-tags [import_tags layout "(no comment)"] "trunk v2"
958
+test_eq import-svn-layout-two-tags [import_tags layout "(no comment)"] \
959
+ "trunk v2"
897960
test_eq import-svn-layout-three [import_files layout three] \
898961
"a.txt, link l, run.sh x, sub/s.txt"
899
-test_eq import-svn-layout-three-parent [import_parents layout three] "(no comment)"
962
+test_eq import-svn-layout-three-parent [import_parents layout three] \
963
+ "(no comment)"
900964
test_eq import-svn-layout-three-tags [import_tags layout three] b1
901965
test_eq import-svn-layout-four [import_cat layout four a.txt] "beta\n"
902966
test_eq import-svn-layout-four-tags [import_tags layout four] b1
903967
test_eq import-svn-layout-six [import_files layout six] \
904968
"a.txt, a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh x, sub/s.txt"
905
-test_eq import-svn-layout-six-content "[import_cat layout six b-copy.txt][import_cat \
969
+test_eq import-svn-layout-six-content \
970
+ "[import_cat layout six b-copy.txt][import_cat \
906971
layout six a2.txt][import_cat layout six d.txt][import_cat layout six e.txt]" \
907972
"beta\nalpha2\nalpha2\nmore\nfresh\n"
908973
test_eq import-svn-layout-six-parents [import_parents layout six] \
909974
"(no comment) four"
910975
test_eq import-svn-layout-seven [import_files layout seven] \
911976
"a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh"
912
-test_eq import-svn-layout-seven-content [import_cat layout seven run.sh] "new run\n"
977
+test_eq import-svn-layout-seven-content [import_cat layout seven run.sh] \
978
+ "new run\n"
913979
test_eq import-svn-layout-eight [import_files layout eight] "a.txt, link l,\
914980
run.sh x, sub/s.txt, sub2/s.txt, tcopy/a2.txt, tcopy/b-copy.txt,\
915981
tcopy/d.txt, tcopy/e.txt, tcopy/link l, tcopy/run.sh"
916
-test_eq import-svn-layout-eight-parents [import_parents layout eight] "four seven"
982
+test_eq import-svn-layout-eight-parents [import_parents layout eight] \
983
+ "four seven"
917984
test_eq import-svn-layout-nine [import_files layout nine] s.txt
918985
test_eq import-svn-layout-nine-parent [import_parents layout nine] six
919986
test_eq import-svn-layout-nine-tags [import_tags layout nine] b2
920987
test_eq import-svn-layout-nine-closed [import_sql layout "SELECT count(*)
921988
FROM tagxref, tag, event WHERE tag.tagid=tagxref.tagid AND tagname='closed'
@@ -1021,11 +1088,12 @@
10211088
group_concat(DISTINCT value) FROM tagxref WHERE tagid=8"] trunk knownBug
10221089
10231090
# A revision that copies a directory to another place on the same branch,
10241091
# and does nothing else, is a check-in with the files of the copy.
10251092
#
1026
-import_svn dircopy "$importHead[import_r 1 one][import_file add trunk/d/f "f\n"][import_r \
1093
+import_svn dircopy \
1094
+ "$importHead[import_r 1 one][import_file add trunk/d/f "f\n"][import_r \
10271095
2 two][import_copy dir trunk/d2 trunk/d 1]"
10281096
test import-svn-dir-copy {$CODE == 0}
10291097
test_eq import-svn-dir-copy-files [import_files dircopy two] "d/f, d2/f"
10301098
10311099
# --ignore-tree leaves out a directory and what is in it, on the trunk
@@ -1048,13 +1116,15 @@
10481116
10491117
# --incremental adds to a repository that exists, and tags each new
10501118
# check-in with its revision number unless --no-rev-tags is given.
10511119
#
10521120
import_svn sincr "$importHead[import_r 1 one][import_file add trunk/a "a\n"]"
1053
-write_file sincr2.dump "$importHead[import_r 2 two][import_file add trunk/b "b\n"]"
1121
+write_file sincr2.dump \
1122
+ "$importHead[import_r 2 two][import_file add trunk/b "b\n"]"
10541123
fossil_raw -seconds 60 import --svn --incremental sincr.fossil sincr2.dump
1055
-test import-svn-incremental {$CODE == 0 && [holds_strings $RESULT {!project-id}]}
1124
+test import-svn-incremental \
1125
+ {$CODE == 0 && [holds_strings $RESULT {!project-id}]}
10561126
fossil_raw -seconds 60 -input \
10571127
"$importHead[import_r 3 three][import_file add trunk/c "c\n"]" \
10581128
import --svn --incremental --no-rev-tags sincr.fossil
10591129
test import-svn-incremental-no-rev-tags {$CODE == 0}
10601130
test_eq import-svn-incremental-checkins [import_checkins sincr] "one two three"
@@ -1068,11 +1138,12 @@
10681138
#
10691139
set importProps "D 3\nfoo\nK 7\nsvn:log\nV 7\nundated\nPROPS-END\n"
10701140
set importDump "SVN-fs-dump-format-version: 3\n\nOther: 1\n\n"
10711141
append importDump "Revision-number: 1\n"
10721142
append importDump "Prop-content-length: [string length $importProps]\n"
1073
-append importDump "Content-length: [string length $importProps]\n\n$importProps\n"
1143
+append importDump \
1144
+ "Content-length: [string length $importProps]\n\n$importProps\n"
10741145
append importDump [import_file add trunk/a "a\n"]
10751146
import_svn undated $importDump
10761147
test import-svn-undated {$CODE == 0}
10771148
test_eq import-svn-undated-checkin [import_sql undated "SELECT comment||' '||
10781149
(mtime>julianday('now','-1 day')) FROM event"] "undated 1"
@@ -1093,17 +1164,25 @@
10931164
version-4 "SVN-fs-dump-format-version: 4\n\n" \
10941165
"Unknown svn-dump format version: 4" \
10951166
no-colon "${importHead}no colon here\n\n" {bad header line: [no colon here]} \
10961167
ends-in-headers "${importHead}Revision-number: 1\n" \
10971168
"svn-dump data ended unexpectedly" \
1098
- props-short "${importHead}Revision-number: 1\nProp-content-length: 50\n\nPROPS-END\n" \
1169
+ props-short \
1170
+ "${importHead}Revision-number: 1\nProp-content-length: 50\n\nPROPS-END\n" \
10991171
"short read: got 10 of 50 bytes" \
1100
- props-no-end "${importHead}Revision-number: 1\nProp-content-length: 12\n\nK 1\na\nV 1\nb\n" \
1172
+ props-no-end \
1173
+ [join [list \
1174
+ "${importHead}Revision-number: 1\nProp-content-length: 12\n\n" \
1175
+ "K 1\na\nV 1\nb\n"] ""] \
11011176
"svn-dump data ended unexpectedly" \
1102
- props-negative "${importHead}Revision-number: 1\nProp-content-length: -5\n\n" \
1177
+ props-negative \
1178
+ "${importHead}Revision-number: 1\nProp-content-length: -5\n\n" \
11031179
"svn-dump data format broken" \
1104
- text-short "${importR1}Node-path: trunk/a\nNode-kind: file\nNode-action: add\nText-content-length: 9\n\nabc" \
1180
+ text-short \
1181
+ [join [list \
1182
+ "${importR1}Node-path: trunk/a\nNode-kind: file\n" \
1183
+ "Node-action: add\nText-content-length: 9\n\nabc"] ""] \
11051184
"short read: got 3 of 9 bytes" \
11061185
unknown-record "${importHead}Other: 1\n\n" "Unknown record type" \
11071186
rev-over-31-bits "$importHead[import_record {Revision-number 2147483648}]" \
11081187
"svn-dump data format broken" \
11091188
rev-eleven-digits "$importHead[import_record {Revision-number 21474836480}]" \
@@ -1112,13 +1191,15 @@
11121191
"svn-dump data format broken" \
11131192
no-copyfrom-rev "$importA[import_record {Node-path trunk/b Node-kind file
11141193
Node-action add Node-copyfrom-path trunk/a}]" "Missing copyfrom-rev" \
11151194
copy-from-outside "$importA[import_copy file trunk/b other/a 1]" \
11161195
"Copy from path outside the import paths" \
1117
- add-no-kind "$importR1[import_record {Node-path trunk/a Node-action add} - x]" \
1196
+ add-no-kind \
1197
+ "$importR1[import_record {Node-path trunk/a Node-action add} - x]" \
11181198
"Missing Node-kind" \
1119
- change-no-kind "$importA[import_record {Node-path trunk/a Node-action change} - x]" \
1199
+ change-no-kind \
1200
+ "$importA[import_record {Node-path trunk/a Node-action change} - x]" \
11201201
"Missing Node-kind" \
11211202
unknown-action "$importR1[import_record {Node-path trunk/a Node-kind file
11221203
Node-action frobnicate}]" "Unknown Node-action" \
11231204
short-link "$importR1[import_file add trunk/l "link " {svn:special *}]" \
11241205
"Too short symbolic link path" \
@@ -1157,11 +1238,15 @@
11571238
v-no-newline "K 1\na\nV 1" \
11581239
v-no-end "K 1\na\nV 1\nbcd\n" \
11591240
] {
11601241
append importProps "PROPS-END\n"
11611242
set importLength [string length $importProps]
1162
- import_svn props-$importName "${importHead}Revision-number: 1\nProp-content-length: $importLength\nContent-length: $importLength\n\n$importProps\n"
1243
+ import_svn props-$importName \
1244
+ [join [list \
1245
+ "${importHead}Revision-number: 1\n" \
1246
+ "Prop-content-length: $importLength\n" \
1247
+ "Content-length: $importLength\n\n$importProps\n"] ""]
11631248
test import-svn-props-$importName {$CODE == 1 &&
11641249
[string first "svn-dump data format broken" $RESULT] >= 0}
11651250
}
11661251
11671252
# A history with nodes that make no check-in of their own.
@@ -1244,11 +1329,12 @@
12441329
# executable and a link on the trunk, a branch and a tag copied from it,
12451330
# a change, a renamed file, and the branch deleted.
12461331
12471332
if {$::is_windows} {
12481333
test_skip_part "the history made by Subversion needs links and file modes"
1249
-} elseif {[catch {exec svnadmin --version --quiet}] || [catch {exec svn --version --quiet}]} {
1334
+} elseif {[catch {exec svnadmin --version --quiet}] || [catch \
1335
+ {exec svn --version --quiet}]} {
12501336
test_skip_part "svnadmin and svn are not installed"
12511337
} else {
12521338
set importRepo [file join [pwd] svnrepo2]
12531339
set importUrl file://$importRepo
12541340
exec svnadmin create $importRepo
@@ -1267,11 +1353,12 @@
12671353
exec svn move -q svnwc2/run.sh svnwc2/moved.sh
12681354
exec svn commit -q -m four svnwc2
12691355
exec svn delete -q -m five $importUrl/branches/b1
12701356
foreach {importName importOption} {plain {} deltas --deltas} {
12711357
exec svnadmin dump -q {*}$importOption $importRepo > svn-$importName.dump
1272
- fossil_raw -seconds 60 import --svn svn-$importName.fossil svn-$importName.dump
1358
+ fossil_raw -seconds 60 import --svn svn-$importName.fossil \
1359
+ svn-$importName.dump
12731360
test import-svn-made-$importName {$CODE == 0}
12741361
set importName svn-$importName
12751362
test_eq import-$importName-checkins [import_checkins $importName] \
12761363
"one two four"
12771364
test_eq import-$importName-one "[import_files $importName one];\
@@ -1309,11 +1396,12 @@
13091396
-c [email protected] {*}$args 2>@1]
13101397
unset ::env(GIT_AUTHOR_DATE) ::env(GIT_COMMITTER_DATE)
13111398
return $out
13121399
}
13131400
exec git -c init.defaultBranch=master init -q gitrepo 2>@1
1314
- foreach importName [list a.txt run.sh "sp ace.txt" "q\"uote.txt" "t\tab.txt"] {
1401
+ foreach importName [list a.txt run.sh "sp ace.txt" "q\"uote.txt" \
1402
+ "t\tab.txt"] {
13151403
write_file [file join gitrepo $importName] "content of $importName\n"
13161404
}
13171405
file attributes gitrepo/run.sh -permissions 0755
13181406
file link -symbolic gitrepo/link a.txt
13191407
import_git_run 1 add -A
13201408
--- test/import.test
+++ test/import.test
@@ -4,15 +4,12 @@
4 # are svndiff0 deltas (Text-delta: true), as "svnadmin dump --deltas"
5 # writes them, then git streams, then dumps of whole histories. Where
6 # Subversion or git is installed, a history that it wrote is imported too.
7 #
8
9 # These tests run only in a long pass: -assurance stress.
10 if {[test_assurance] ne "stress"} {
11 test_skip "runs only with -assurance stress"
12 }
13
14 test_setup
15
16 # A number in the variable-length form of svndiff0: seven bits a byte,
17 # most significant first, the high bit set on every byte but the last.
18 #
@@ -29,11 +26,12 @@
29 # One window: source offset and length, target length, instructions and
30 # new data. INSTR is a list of byte values.
31 #
32 proc import_window {srcoff srclen tgtlen instr data} {
33 set i [binary format c* $instr]
34 return "[import_varint $srcoff][import_varint $srclen][import_varint $tgtlen][import_varint [string length $i]][import_varint [string length $data]]$i$data"
 
35 }
36
37 proc import_props {pairs} {
38 set b ""
39 foreach {k v} $pairs {
@@ -44,11 +42,14 @@
44
45 proc import_rev {n log} {
46 set p [import_props [list svn:log $log svn:author dan \
47 svn:date 2026-01-0[expr {$n+1}]T00:00:00.000000Z]]
48 set len [string length $p]
49 return "Revision-number: $n\nProp-content-length: $len\nContent-length: $len\n\n$p\n"
 
 
 
50 }
51
52 proc import_node {path kind action {text ""} {delta 0}} {
53 set p "PROPS-END\n"
54 set h "Node-path: $path\nNode-kind: $kind\nNode-action: $action\n"
@@ -55,18 +56,24 @@
55 if {$kind eq "dir"} {
56 return "${h}Prop-content-length: 10\nContent-length: 10\n\n$p\n\n"
57 }
58 if {$delta} { append h "Text-delta: true\n" }
59 set n [string length $text]
60 return "${h}Prop-content-length: 10\nText-content-length: $n\nContent-length: [expr {$n+10}]\n\n$p$text\n\n"
 
 
 
61 }
62
63 # Revision 1 adds trunk/a.txt, "hello world\n", as a delta from nothing.
64 # Revision 2 changes it by the delta in WINDOWS.
65 #
66 proc import_dump {windows {magic "SVN\000"}} {
67 set d "SVN-fs-dump-format-version: 3\n\nUUID: 00000000-0000-0000-0000-000000000000\n\n"
 
 
 
68 append d [import_rev 0 zero]
69 append d [import_rev 1 one]
70 append d [import_node trunk dir add]
71 append d [import_node trunk/a.txt file add \
72 "SVN\000[import_window 0 0 12 {0x8c} "hello world\n"]" 1]
@@ -121,12 +128,14 @@
121 bad-instruction [import_window 0 12 1 {0xc1 0} {}] \
122 source-window [import_window 1000 12 10 {0x0a 0} {}] \
123 target-offset [import_window 0 12 10 {0x82 0x48 0x87 0x68} ab] \
124 target-unwritten [import_window 0 12 4 {0x44 0} {}] \
125 data-past-end [import_window 0 12 50 {0xb2} abcde] \
126 huge-instr-len "[import_varint 0][import_varint 12][import_varint 5][import_varint 100000][import_varint 5]\x85abcde" \
127 huge-data-len "[import_varint 0][import_varint 12][import_varint 5][import_varint 1][import_varint 100000]\x85abcde" \
 
 
128 truncated-varint "\x80\x80" \
129 truncated-length [binary format c* {0 12 5 1 5 0x80}] \
130 target-unfilled [import_window 0 12 4000 {0x85} abcde] \
131 ] {
132 set importResult [import_try $importName $importWindows]
@@ -135,32 +144,41 @@
135 }
136
137 # Not an svndiff0 delta at all.
138 test import-svn-not-svndiff {[string match "*Invalid svndiff0*" \
139 [import_try not abc "XYZ\000"]]}
 
 
 
 
140
141 ###############################################################################
142 # A dump written by Subversion itself, with deltas of several windows.
143 # Every version that Fossil imports must be byte for byte the one that
144 # Subversion holds.
145
146 if {[catch {exec svnadmin --version --quiet}] || [catch {exec svn --version --quiet}]} {
 
147 test_skip_part "svnadmin and svn are not installed"
148 } else {
149 set importRepo [file join [pwd] svnrepo]
150 exec svnadmin create $importRepo
151 exec svn checkout -q file://$importRepo svnwc
152 file mkdir svnwc/trunk
153 set importBase ""
154 for {set importI 0} {$importI < 6000} {incr importI} {
155 append importBase "line $importI of a file that spans several delta windows\n"
 
156 }
157 set importVersions [list $importBase]
158 set importNext ""
159 for {set importI 0} {$importI < [string length $importBase]} {incr importI 20000} {
160 append importNext [string range $importBase $importI [expr {$importI+19999}]]
161 append importNext [string repeat x 3000] [string repeat "pattern $importI " 300]
 
 
 
162 }
163 lappend importVersions $importNext
164 lappend importVersions "[string repeat {repeated line of text} 20000]\n"
165 write_file svnwc/trunk/a.txt [lindex $importVersions 0]
166 exec svn add -q svnwc/trunk
@@ -189,11 +207,12 @@
189 # Fossil check-in artifact, one whose second card is a P card that names no
190 # parent. The file is imported as a file: the repository holds one
191 # check-in, the imported commit, and the file reads back with a line added
192 # at its end that stops it being an artifact.
193
194 set importArt "D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"
 
195 append importArt "T *branch * planted\nT *sym-planted *\nU mallory\n"
196 write_file git-artifact-body.txt $importArt
197 fossil md5sum git-artifact-body.txt
198 append importArt "Z [lindex $RESULT 0]\n"
199 set importStream "blob\nmark :1\ndata [string length $importArt]\n$importArt\n"
@@ -208,31 +227,43 @@
208 fossil sql -R git-artifact.fossil \
209 "SELECT count(*) FROM tag WHERE tagname='sym-planted'"
210 test_eq import-git-artifact-no-branch [string trim $RESULT] 0
211 fossil_raw cat f.txt -R git-artifact.fossil -r trunk
212 test_eq import-git-artifact-content $RESULT \
213 "${importArt}# Remove this line to create a well-formed Fossil control artifact.\n"
 
 
214
215 ###############################################################################
216 # Input that "fossil import" must refuse with an error and exit code 1.
217
218 # Each row: a git stream. The length of a data command is negative, too
219 # large to hold, or not a number; the time of a committer is past the
220 # year 9999, has thirteen digits, or has no space before it; a commit
221 # names a ref of 992 bytes with no slash and no newline.
222 #
223 set importWho "committer C <[email protected]>"
224 foreach {importName importStream} [list \
225 data-negative "blob\nmark :1\ndata -1\nhello world, and more than one byte\n" \
 
226 data-huge "blob\nmark :1\ndata 2147483647\nhello\n" \
227 data-not-number "blob\nmark :1\ndata <<EOF\nhello\nEOF\n" \
228 time-past-9999 "commit refs/heads/master\nmark :1\n$importWho 253402300800 +0000\ndata 1\nx\n" \
229 time-13-digits "commit refs/heads/master\nmark :1\n$importWho 9999999999999 +0000\ndata 1\nx\n" \
230 time-no-space "commit refs/heads/master\nmark :1\n${importWho}1700000000 +0000\ndata 1\nx\n" \
 
 
 
 
 
 
 
 
 
231 ] {
232 write_file refuse-$importName.fi $importStream
233 fossil_raw -seconds 60 import --git refuse-$importName.fossil refuse-$importName.fi
 
234 test import-refuse-git-$importName {$CODE == 1 &&
235 [string first "bad fast-import line" $RESULT] >= 0}
236 }
237
238 # A commit command whose name is 992 bytes long, with no slash after its
@@ -251,32 +282,45 @@
251 append importStart "Revision-number: 1\nProp-content-length: 10\n"
252 append importStart "Content-length: 10\n\nPROPS-END\n\n"
253 foreach {importName importDump} [list \
254 header-cut "SVN-fs-dump-format-version: 2\nUUID: 0000" \
255 header-zero "SVN-fs-dump-format-version: 2\nUUID: 00\00000\n\n" \
256 header-long "SVN-fs-dump-format-version: 2\nUUID: [string repeat 0 1200]\n\n" \
257 no-action "${importStart}Node-path: trunk/a\nNode-kind: file\nText-content-length: 1\nContent-length: 1\n\nx\n\n" \
 
 
 
 
258 ] {
259 write_file refuse-$importName.dump $importDump
260 fossil_raw -seconds 60 import --svn refuse-$importName.fossil refuse-$importName.dump
 
261 test import-refuse-svn-$importName {$CODE == 1 &&
262 [string first "svn-dump data format broken" $RESULT] >= 0}
263 }
264
265 # A file outside trunk, branches and tags is passed over even when it has
266 # no Node-action.
267 #
268 write_file outside.dump "${importStart}Node-path: other/a\nNode-kind: file\nText-content-length: 1\nContent-length: 1\n\nx\n\n"
 
 
 
269 fossil_raw -seconds 60 import --svn outside.fossil outside.dump
270 test import-svn-outside-no-action {$CODE == 0}
271
272 # An empty --trunk, --branches or --tags is refused unless --base names a
273 # directory; with one, an empty --trunk makes the base itself the trunk.
274 #
275 write_file base.dump "${importStart}Node-path: proj/a\nNode-kind: file\nNode-action: add\nText-content-length: 1\nContent-length: 1\n\nx\n\n"
 
 
 
 
276 foreach importName {trunk branches tags} {
277 fossil_raw -seconds 60 import --svn --$importName "" refuse-$importName.fossil base.dump
 
278 test import-refuse-svn-empty-$importName {$CODE == 1 && [string first \
279 "may be empty only with a non-empty --base" $RESULT] >= 0}
280 }
281 fossil_raw -seconds 60 import --svn --base proj --trunk "" base.fossil base.dump
282 test import-svn-base-empty-trunk {$CODE == 0}
@@ -295,11 +339,15 @@
295 # minutes after 2023-11-14 22:13:20 UTC. BODY is the lines that follow
296 # the comment.
297 #
298 proc import_commit {ref mark comment {body ""}} {
299 set when [expr {1700000000+60*$mark}]
300 return "commit $ref\nmark :$mark\ncommitter C <[email protected]> $when +0000\ndata [string length $comment]\n$comment\n$body\n"
 
 
 
 
301 }
302
303 proc import_git {name stream args} {
304 write_file $name.fi $stream
305 fossil_raw -seconds 60 import --git {*}$args $name.fossil $name.fi
@@ -306,19 +354,19 @@
306 }
307
308 # What repository NAME answers to QUERY.
309 #
310 proc import_sql {name query} {
311 fossil sql -R $name.fossil $query
312 return [string trim $::RESULT]
313 }
314
315 # The files of the check-in of NAME whose comment is COMMENT, in name
316 # order: the name, the permission and the former name of each.
317 #
318 proc import_files {name comment} {
319 return [import_sql $name "SELECT group_concat(trim(f.filename||' '||coalesce(f.perm,'')||' '||coalesce(f.previousName,'')), ', ')
 
320 FROM event e, blob b, files_of_checkin(b.uuid) f
321 WHERE e.type='ci' AND e.comment='$comment' AND b.rid=e.objid"]
322 }
323
324 # The branch and tag names that hold for the check-in with comment COMMENT.
@@ -368,11 +416,12 @@
368 append importStream "M 100644 :1 a.txt\nM 100755 :3 run.sh\nM 120000 :1 link\n"
369 append importStream "M 100644 :2 empty\n"
370 append importStream "M 100644 inline in.txt\ndata 7\ninline\n\n"
371 append importStream "M 100644 :99 missing.txt\n"
372 append importStream "M 100644 :1 dir/x\nM 100644 :1 dir/y\n"
373 append importStream "M 100644 :1 tmp/p\nM 100644 :1 tmp/q\nM 100644 :1 tmpfile\n"
 
374 append importStream "M 100644\nN :1 :10\ncheckpoint\n"
375 append importStream [import_commit refs/heads/master 11 two \
376 "D run.sh\nD tmp\nC a.txt b.txt\nR link link2\n"]
377 append importStream [import_commit refs/heads/dev 12 three \
378 "M 100644 :1 d.txt\n"]
@@ -390,28 +439,36 @@
390 append importStream "tag unknown\nfrom :97\n$importTagger\n"
391 append importStream "tag v4\n$importTagger\nfrom :13"
392
393 import_git all $importStream
394 test import-git-all {$CODE == 0}
395 test import-git-all-progress {[holds_strings $RESULT {"halfway there" 2023-11-14}]}
396 test_eq import-git-all-checkins [import_checkins all] "one two three four five six"
 
 
397 test_eq import-git-all-user [import_sql all \
398 "SELECT user||' '||date(mtime) FROM event WHERE comment='one'"] \
399 "[email protected] 2023-11-14"
400 test_eq import-git-all-one [import_files all one] \
401 "a.txt w, dir/x w, dir/y w, empty w, in.txt w, link l, run.sh x, tmp/p w, tmp/q w, tmpfile w"
 
 
402 fossil_raw cat in.txt -R all.fossil -r [import_sql all \
403 "SELECT uuid FROM blob, event WHERE rid=objid AND comment='one'"]
404 test_eq import-git-all-inline $RESULT "inline\n"
405 test_eq import-git-all-two [import_files all two] \
406 "a.txt w, b.txt w, dir/x w, dir/y w, empty w, in.txt w, link2 l link, tmpfile w"
 
 
407 test_eq import-git-all-two-parent [import_parents all two] one
408 test_eq import-git-all-two-tags [import_tags all two] "master trunk"
409 test_eq import-git-all-three-parent [import_parents all three] ""
410 test_eq import-git-all-three-tags [import_tags all three] "dev trunk"
411 test_eq import-git-all-four [import_files all four] \
412 "a.txt w, b.txt w, dir2/x w, dir2/y w, dir3/x w dir/x, dir3/y w dir/y, empty w, in.txt w, link2 l, tmpfile w"
 
 
413 test_eq import-git-all-four-parents [import_parents all four] "two one three"
414 test_eq import-git-all-four-tags [import_tags all four] "dev trunk v2 v3 v4"
415 test_eq import-git-all-tag-comment [import_sql all "SELECT value FROM tagxref
416 WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-v2')"] "the tag"
417 test_eq import-git-all-five-tags [import_tags all five] "dev trunk"
@@ -456,11 +513,12 @@
456 append importStream [import_commit refs/heads/master 2 names $importBody]
457 append importStream [import_commit refs/heads/master 3 fewer \
458 "D \"oct\\303\\251\"\nD plain name\n"]
459 import_git names $importStream
460 test import-git-names {$CODE == 0}
461 test_eq import-git-names-files [import_sql names "SELECT group_concat(lower(hex(f.filename)), ' ')
 
462 FROM event e, blob b, files_of_checkin(b.uuid) f
463 WHERE e.comment='names' AND b.rid=e.objid"] [lsort $importWant]
464 test_eq import-git-names-deleted [import_sql names "SELECT count(*)
465 FROM event e, blob b, files_of_checkin(b.uuid) f
466 WHERE e.comment='fewer' AND b.rid=e.objid"] 9
@@ -482,11 +540,12 @@
482 append importStream [import_commit refs/heads/ 2 slash "M 100644 :1 a\n"]
483 append importStream [import_commit refs/x 3 short "M 100644 :1 a\n"]
484 append importStream [import_commit refs/heads/master 4 nick \
485 "property branch-nick 7 nicked\nproperty rebase-of abc\nM 100644 :1 a\n"]
486 import_git refs $importStream
487 test_eq import-git-refs [import_sql refs "SELECT group_concat(comment||'='||value, ' ')
 
488 FROM (SELECT comment, value FROM event, tagxref
489 WHERE rid=objid AND tagxref.tagid=8 ORDER BY event.mtime)"] \
490 "slash=refs/heads/ short=refs/x nick=nicked"
491
492 # A commit on a tag ref that has no parent gets no tag, and a commit with
@@ -566,11 +625,12 @@
566 #
567 foreach {importName importStream importError} [list \
568 unknown-command "bogus line\n" {bad fast-import line: [bogus line]} \
569 no-angle-bracket "commit refs/heads/master\ncommitter C 1700000000 +0000\n" \
570 {bad fast-import line: [committer C 1700000000 +0000]} \
571 no-open-bracket "commit refs/heads/master\ncommitter C [email protected]> 17 +0000\n" \
 
572 {bad fast-import line: [committer C [email protected]>} \
573 short-data "blob\nmark :1\ndata 50\nabc" \
574 {short read: got 3 of 50 bytes} \
575 ] {
576 import_git bad-$importName $importStream
@@ -696,13 +756,11 @@
696
697 # Marks may name a check-in made by "fossil commit", whose files carry no
698 # permission, and the files of such a parent are kept. A commit whose
699 # "from" is the mark of a file keeps nothing from it.
700 #
701 write_file plain.txt "plain\n"
702 fossil add plain.txt
703 fossil commit -m committed
704 fossil sql "SELECT 'c'||rid||' :7 '||uuid FROM blob
705 WHERE rid=(SELECT objid FROM event WHERE comment='committed')"
706 set importMarks "$RESULT\n"
707 fossil sql "SELECT 'b'||rid||' :8 '||uuid FROM blob
708 WHERE rid=(SELECT fid FROM mlink)"
@@ -750,11 +808,13 @@
750 # A file command acts on a file that an earlier line of the same commit
751 # made: D removes it, C copies it and R renames it.
752 #
753 set importStream [import_blob 1 "hello\n"]
754 append importStream [import_commit refs/heads/master 2 ordered \
755 "M 100644 :1 gone\nD gone\nM 100644 :1 src\nC src dst\nM 100644 :1 old\nR old new\n"]
 
 
756 import_git ordered $importStream
757 test_eq import-git-ordered [import_files ordered ordered] \
758 "dst w, new w, src w" knownBug
759
760 ###############################################################################
@@ -781,11 +841,12 @@
781
782 # Revision N, made by dan on day N+1 of 2026, with LOG as its comment.
783 #
784 proc import_r {n log} {
785 return [import_record [list Revision-number $n] [list svn:log $log \
786 svn:author dan svn:date [format 2026-01-%02dT00:00:00.000000Z [expr {$n+1}]]]]
 
787 }
788 proc import_file {action path text {props -}} {
789 return [import_record \
790 [list Node-path $path Node-kind file Node-action $action] $props $text]
791 }
@@ -842,11 +903,12 @@
842 [import_file change trunk/a.txt "alpha2\n"] \
843 [import_file change trunk/run.sh "run2\n"] \
844 [import_record {Node-path trunk Node-kind dir Node-action change} - xyz] \
845 [import_file change trunk/sub/s.txt - {svn:eol-style native}]
846 append importDump [import_r 3 three] [import_copy dir branches/b1 trunk 2]
847 append importDump [import_r 4 four] [import_file change branches/b1/a.txt "beta\n"]
 
848 append importDump [import_r 5 five] [import_copy dir tags/v1 trunk 4] \
849 [import_copy dir tags/v2 trunk 4]
850 append importDump [import_r 6 six] \
851 [import_copy file trunk/b-copy.txt branches/b1/a.txt 4] \
852 [import_copy file trunk/a2.txt trunk/a.txt 2] \
@@ -891,31 +953,36 @@
891 test_eq import-svn-layout-two [import_files layout "(no comment)"] \
892 "a.txt, link l, run.sh x, sub/s.txt"
893 test_eq import-svn-layout-two-content \
894 "[import_cat layout {(no comment)} a.txt][import_cat layout {(no comment)} run.sh]" \
895 "alpha2\nrun2\n"
896 test_eq import-svn-layout-two-tags [import_tags layout "(no comment)"] "trunk v2"
 
897 test_eq import-svn-layout-three [import_files layout three] \
898 "a.txt, link l, run.sh x, sub/s.txt"
899 test_eq import-svn-layout-three-parent [import_parents layout three] "(no comment)"
 
900 test_eq import-svn-layout-three-tags [import_tags layout three] b1
901 test_eq import-svn-layout-four [import_cat layout four a.txt] "beta\n"
902 test_eq import-svn-layout-four-tags [import_tags layout four] b1
903 test_eq import-svn-layout-six [import_files layout six] \
904 "a.txt, a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh x, sub/s.txt"
905 test_eq import-svn-layout-six-content "[import_cat layout six b-copy.txt][import_cat \
 
906 layout six a2.txt][import_cat layout six d.txt][import_cat layout six e.txt]" \
907 "beta\nalpha2\nalpha2\nmore\nfresh\n"
908 test_eq import-svn-layout-six-parents [import_parents layout six] \
909 "(no comment) four"
910 test_eq import-svn-layout-seven [import_files layout seven] \
911 "a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh"
912 test_eq import-svn-layout-seven-content [import_cat layout seven run.sh] "new run\n"
 
913 test_eq import-svn-layout-eight [import_files layout eight] "a.txt, link l,\
914 run.sh x, sub/s.txt, sub2/s.txt, tcopy/a2.txt, tcopy/b-copy.txt,\
915 tcopy/d.txt, tcopy/e.txt, tcopy/link l, tcopy/run.sh"
916 test_eq import-svn-layout-eight-parents [import_parents layout eight] "four seven"
 
917 test_eq import-svn-layout-nine [import_files layout nine] s.txt
918 test_eq import-svn-layout-nine-parent [import_parents layout nine] six
919 test_eq import-svn-layout-nine-tags [import_tags layout nine] b2
920 test_eq import-svn-layout-nine-closed [import_sql layout "SELECT count(*)
921 FROM tagxref, tag, event WHERE tag.tagid=tagxref.tagid AND tagname='closed'
@@ -1021,11 +1088,12 @@
1021 group_concat(DISTINCT value) FROM tagxref WHERE tagid=8"] trunk knownBug
1022
1023 # A revision that copies a directory to another place on the same branch,
1024 # and does nothing else, is a check-in with the files of the copy.
1025 #
1026 import_svn dircopy "$importHead[import_r 1 one][import_file add trunk/d/f "f\n"][import_r \
 
1027 2 two][import_copy dir trunk/d2 trunk/d 1]"
1028 test import-svn-dir-copy {$CODE == 0}
1029 test_eq import-svn-dir-copy-files [import_files dircopy two] "d/f, d2/f"
1030
1031 # --ignore-tree leaves out a directory and what is in it, on the trunk
@@ -1048,13 +1116,15 @@
1048
1049 # --incremental adds to a repository that exists, and tags each new
1050 # check-in with its revision number unless --no-rev-tags is given.
1051 #
1052 import_svn sincr "$importHead[import_r 1 one][import_file add trunk/a "a\n"]"
1053 write_file sincr2.dump "$importHead[import_r 2 two][import_file add trunk/b "b\n"]"
 
1054 fossil_raw -seconds 60 import --svn --incremental sincr.fossil sincr2.dump
1055 test import-svn-incremental {$CODE == 0 && [holds_strings $RESULT {!project-id}]}
 
1056 fossil_raw -seconds 60 -input \
1057 "$importHead[import_r 3 three][import_file add trunk/c "c\n"]" \
1058 import --svn --incremental --no-rev-tags sincr.fossil
1059 test import-svn-incremental-no-rev-tags {$CODE == 0}
1060 test_eq import-svn-incremental-checkins [import_checkins sincr] "one two three"
@@ -1068,11 +1138,12 @@
1068 #
1069 set importProps "D 3\nfoo\nK 7\nsvn:log\nV 7\nundated\nPROPS-END\n"
1070 set importDump "SVN-fs-dump-format-version: 3\n\nOther: 1\n\n"
1071 append importDump "Revision-number: 1\n"
1072 append importDump "Prop-content-length: [string length $importProps]\n"
1073 append importDump "Content-length: [string length $importProps]\n\n$importProps\n"
 
1074 append importDump [import_file add trunk/a "a\n"]
1075 import_svn undated $importDump
1076 test import-svn-undated {$CODE == 0}
1077 test_eq import-svn-undated-checkin [import_sql undated "SELECT comment||' '||
1078 (mtime>julianday('now','-1 day')) FROM event"] "undated 1"
@@ -1093,17 +1164,25 @@
1093 version-4 "SVN-fs-dump-format-version: 4\n\n" \
1094 "Unknown svn-dump format version: 4" \
1095 no-colon "${importHead}no colon here\n\n" {bad header line: [no colon here]} \
1096 ends-in-headers "${importHead}Revision-number: 1\n" \
1097 "svn-dump data ended unexpectedly" \
1098 props-short "${importHead}Revision-number: 1\nProp-content-length: 50\n\nPROPS-END\n" \
 
1099 "short read: got 10 of 50 bytes" \
1100 props-no-end "${importHead}Revision-number: 1\nProp-content-length: 12\n\nK 1\na\nV 1\nb\n" \
 
 
 
1101 "svn-dump data ended unexpectedly" \
1102 props-negative "${importHead}Revision-number: 1\nProp-content-length: -5\n\n" \
 
1103 "svn-dump data format broken" \
1104 text-short "${importR1}Node-path: trunk/a\nNode-kind: file\nNode-action: add\nText-content-length: 9\n\nabc" \
 
 
 
1105 "short read: got 3 of 9 bytes" \
1106 unknown-record "${importHead}Other: 1\n\n" "Unknown record type" \
1107 rev-over-31-bits "$importHead[import_record {Revision-number 2147483648}]" \
1108 "svn-dump data format broken" \
1109 rev-eleven-digits "$importHead[import_record {Revision-number 21474836480}]" \
@@ -1112,13 +1191,15 @@
1112 "svn-dump data format broken" \
1113 no-copyfrom-rev "$importA[import_record {Node-path trunk/b Node-kind file
1114 Node-action add Node-copyfrom-path trunk/a}]" "Missing copyfrom-rev" \
1115 copy-from-outside "$importA[import_copy file trunk/b other/a 1]" \
1116 "Copy from path outside the import paths" \
1117 add-no-kind "$importR1[import_record {Node-path trunk/a Node-action add} - x]" \
 
1118 "Missing Node-kind" \
1119 change-no-kind "$importA[import_record {Node-path trunk/a Node-action change} - x]" \
 
1120 "Missing Node-kind" \
1121 unknown-action "$importR1[import_record {Node-path trunk/a Node-kind file
1122 Node-action frobnicate}]" "Unknown Node-action" \
1123 short-link "$importR1[import_file add trunk/l "link " {svn:special *}]" \
1124 "Too short symbolic link path" \
@@ -1157,11 +1238,15 @@
1157 v-no-newline "K 1\na\nV 1" \
1158 v-no-end "K 1\na\nV 1\nbcd\n" \
1159 ] {
1160 append importProps "PROPS-END\n"
1161 set importLength [string length $importProps]
1162 import_svn props-$importName "${importHead}Revision-number: 1\nProp-content-length: $importLength\nContent-length: $importLength\n\n$importProps\n"
 
 
 
 
1163 test import-svn-props-$importName {$CODE == 1 &&
1164 [string first "svn-dump data format broken" $RESULT] >= 0}
1165 }
1166
1167 # A history with nodes that make no check-in of their own.
@@ -1244,11 +1329,12 @@
1244 # executable and a link on the trunk, a branch and a tag copied from it,
1245 # a change, a renamed file, and the branch deleted.
1246
1247 if {$::is_windows} {
1248 test_skip_part "the history made by Subversion needs links and file modes"
1249 } elseif {[catch {exec svnadmin --version --quiet}] || [catch {exec svn --version --quiet}]} {
 
1250 test_skip_part "svnadmin and svn are not installed"
1251 } else {
1252 set importRepo [file join [pwd] svnrepo2]
1253 set importUrl file://$importRepo
1254 exec svnadmin create $importRepo
@@ -1267,11 +1353,12 @@
1267 exec svn move -q svnwc2/run.sh svnwc2/moved.sh
1268 exec svn commit -q -m four svnwc2
1269 exec svn delete -q -m five $importUrl/branches/b1
1270 foreach {importName importOption} {plain {} deltas --deltas} {
1271 exec svnadmin dump -q {*}$importOption $importRepo > svn-$importName.dump
1272 fossil_raw -seconds 60 import --svn svn-$importName.fossil svn-$importName.dump
 
1273 test import-svn-made-$importName {$CODE == 0}
1274 set importName svn-$importName
1275 test_eq import-$importName-checkins [import_checkins $importName] \
1276 "one two four"
1277 test_eq import-$importName-one "[import_files $importName one];\
@@ -1309,11 +1396,12 @@
1309 -c [email protected] {*}$args 2>@1]
1310 unset ::env(GIT_AUTHOR_DATE) ::env(GIT_COMMITTER_DATE)
1311 return $out
1312 }
1313 exec git -c init.defaultBranch=master init -q gitrepo 2>@1
1314 foreach importName [list a.txt run.sh "sp ace.txt" "q\"uote.txt" "t\tab.txt"] {
 
1315 write_file [file join gitrepo $importName] "content of $importName\n"
1316 }
1317 file attributes gitrepo/run.sh -permissions 0755
1318 file link -symbolic gitrepo/link a.txt
1319 import_git_run 1 add -A
1320
--- test/import.test
+++ test/import.test
@@ -4,15 +4,12 @@
4 # are svndiff0 deltas (Text-delta: true), as "svnadmin dump --deltas"
5 # writes them, then git streams, then dumps of whole histories. Where
6 # Subversion or git is installed, a history that it wrote is imported too.
7 #
8
9 # The first sections run at every level, and the rest need
10 # -assurance stress.
 
 
 
11 test_setup
12
13 # A number in the variable-length form of svndiff0: seven bits a byte,
14 # most significant first, the high bit set on every byte but the last.
15 #
@@ -29,11 +26,12 @@
26 # One window: source offset and length, target length, instructions and
27 # new data. INSTR is a list of byte values.
28 #
29 proc import_window {srcoff srclen tgtlen instr data} {
30 set i [binary format c* $instr]
31 return \
32 "[import_varint $srcoff][import_varint $srclen][import_varint $tgtlen][import_varint [string length $i]][import_varint [string length $data]]$i$data"
33 }
34
35 proc import_props {pairs} {
36 set b ""
37 foreach {k v} $pairs {
@@ -44,11 +42,14 @@
42
43 proc import_rev {n log} {
44 set p [import_props [list svn:log $log svn:author dan \
45 svn:date 2026-01-0[expr {$n+1}]T00:00:00.000000Z]]
46 set len [string length $p]
47 return \
48 [join [list \
49 "Revision-number: $n\nProp-content-length: $len\n" \
50 "Content-length: $len\n\n$p\n"] ""]
51 }
52
53 proc import_node {path kind action {text ""} {delta 0}} {
54 set p "PROPS-END\n"
55 set h "Node-path: $path\nNode-kind: $kind\nNode-action: $action\n"
@@ -55,18 +56,24 @@
56 if {$kind eq "dir"} {
57 return "${h}Prop-content-length: 10\nContent-length: 10\n\n$p\n\n"
58 }
59 if {$delta} { append h "Text-delta: true\n" }
60 set n [string length $text]
61 return \
62 [join [list \
63 "${h}Prop-content-length: 10\nText-content-length: $n\n" \
64 "Content-length: [expr {$n+10}]\n\n$p$text\n\n"] ""]
65 }
66
67 # Revision 1 adds trunk/a.txt, "hello world\n", as a delta from nothing.
68 # Revision 2 changes it by the delta in WINDOWS.
69 #
70 proc import_dump {windows {magic "SVN\000"}} {
71 set d \
72 [join [list \
73 "SVN-fs-dump-format-version: 3\n\n" \
74 "UUID: 00000000-0000-0000-0000-000000000000\n\n"] ""]
75 append d [import_rev 0 zero]
76 append d [import_rev 1 one]
77 append d [import_node trunk dir add]
78 append d [import_node trunk/a.txt file add \
79 "SVN\000[import_window 0 0 12 {0x8c} "hello world\n"]" 1]
@@ -121,12 +128,14 @@
128 bad-instruction [import_window 0 12 1 {0xc1 0} {}] \
129 source-window [import_window 1000 12 10 {0x0a 0} {}] \
130 target-offset [import_window 0 12 10 {0x82 0x48 0x87 0x68} ab] \
131 target-unwritten [import_window 0 12 4 {0x44 0} {}] \
132 data-past-end [import_window 0 12 50 {0xb2} abcde] \
133 huge-instr-len \
134 "[import_varint 0][import_varint 12][import_varint 5][import_varint 100000][import_varint 5]\x85abcde" \
135 huge-data-len \
136 "[import_varint 0][import_varint 12][import_varint 5][import_varint 1][import_varint 100000]\x85abcde" \
137 truncated-varint "\x80\x80" \
138 truncated-length [binary format c* {0 12 5 1 5 0x80}] \
139 target-unfilled [import_window 0 12 4000 {0x85} abcde] \
140 ] {
141 set importResult [import_try $importName $importWindows]
@@ -135,32 +144,41 @@
144 }
145
146 # Not an svndiff0 delta at all.
147 test import-svn-not-svndiff {[string match "*Invalid svndiff0*" \
148 [import_try not abc "XYZ\000"]]}
149
150 if {[test_assurance] ne "stress"} {
151 test_skip "the tests after the first sections need -assurance stress"
152 }
153
154 ###############################################################################
155 # A dump written by Subversion itself, with deltas of several windows.
156 # Every version that Fossil imports must be byte for byte the one that
157 # Subversion holds.
158
159 if {[catch {exec svnadmin --version --quiet}] || [catch \
160 {exec svn --version --quiet}]} {
161 test_skip_part "svnadmin and svn are not installed"
162 } else {
163 set importRepo [file join [pwd] svnrepo]
164 exec svnadmin create $importRepo
165 exec svn checkout -q file://$importRepo svnwc
166 file mkdir svnwc/trunk
167 set importBase ""
168 for {set importI 0} {$importI < 6000} {incr importI} {
169 append importBase \
170 "line $importI of a file that spans several delta windows\n"
171 }
172 set importVersions [list $importBase]
173 set importNext ""
174 for {set importI 0} {$importI < [string length $importBase]} \
175 {incr importI 20000} {
176 append importNext [string range $importBase $importI \
177 [expr {$importI+19999}]]
178 append importNext [string repeat x 3000] \
179 [string repeat "pattern $importI " 300]
180 }
181 lappend importVersions $importNext
182 lappend importVersions "[string repeat {repeated line of text} 20000]\n"
183 write_file svnwc/trunk/a.txt [lindex $importVersions 0]
184 exec svn add -q svnwc/trunk
@@ -189,11 +207,12 @@
207 # Fossil check-in artifact, one whose second card is a P card that names no
208 # parent. The file is imported as a file: the repository holds one
209 # check-in, the imported commit, and the file reads back with a line added
210 # at its end that stops it being an artifact.
211
212 set importArt \
213 "D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"
214 append importArt "T *branch * planted\nT *sym-planted *\nU mallory\n"
215 write_file git-artifact-body.txt $importArt
216 fossil md5sum git-artifact-body.txt
217 append importArt "Z [lindex $RESULT 0]\n"
218 set importStream "blob\nmark :1\ndata [string length $importArt]\n$importArt\n"
@@ -208,31 +227,43 @@
227 fossil sql -R git-artifact.fossil \
228 "SELECT count(*) FROM tag WHERE tagname='sym-planted'"
229 test_eq import-git-artifact-no-branch [string trim $RESULT] 0
230 fossil_raw cat f.txt -R git-artifact.fossil -r trunk
231 test_eq import-git-artifact-content $RESULT \
232 [join [list \
233 "${importArt}# Remove this line to create a well-formed " \
234 "Fossil control artifact.\n"] ""]
235
236 ###############################################################################
237 # Input that "fossil import" must refuse with an error and exit code 1.
238
239 # Each row: a git stream. The length of a data command is negative, too
240 # large to hold, or not a number; the time of a committer is past the
241 # year 9999, has thirteen digits, or has no space before it.
 
242 #
243 set importWho "committer C <[email protected]>"
244 foreach {importName importStream} [list \
245 data-negative \
246 "blob\nmark :1\ndata -1\nhello world, and more than one byte\n" \
247 data-huge "blob\nmark :1\ndata 2147483647\nhello\n" \
248 data-not-number "blob\nmark :1\ndata <<EOF\nhello\nEOF\n" \
249 time-past-9999 \
250 [join [list \
251 "commit refs/heads/master\nmark :1\n" \
252 "$importWho 253402300800 +0000\ndata 1\nx\n"] ""] \
253 time-13-digits \
254 [join [list \
255 "commit refs/heads/master\nmark :1\n" \
256 "$importWho 9999999999999 +0000\ndata 1\nx\n"] ""] \
257 time-no-space \
258 [join [list \
259 "commit refs/heads/master\nmark :1\n" \
260 "${importWho}1700000000 +0000\ndata 1\nx\n"] ""] \
261 ] {
262 write_file refuse-$importName.fi $importStream
263 fossil_raw -seconds 60 import --git refuse-$importName.fossil \
264 refuse-$importName.fi
265 test import-refuse-git-$importName {$CODE == 1 &&
266 [string first "bad fast-import line" $RESULT] >= 0}
267 }
268
269 # A commit command whose name is 992 bytes long, with no slash after its
@@ -251,32 +282,45 @@
282 append importStart "Revision-number: 1\nProp-content-length: 10\n"
283 append importStart "Content-length: 10\n\nPROPS-END\n\n"
284 foreach {importName importDump} [list \
285 header-cut "SVN-fs-dump-format-version: 2\nUUID: 0000" \
286 header-zero "SVN-fs-dump-format-version: 2\nUUID: 00\00000\n\n" \
287 header-long \
288 "SVN-fs-dump-format-version: 2\nUUID: [string repeat 0 1200]\n\n" \
289 no-action \
290 [join [list \
291 "${importStart}Node-path: trunk/a\nNode-kind: file\n" \
292 "Text-content-length: 1\nContent-length: 1\n\nx\n\n"] ""] \
293 ] {
294 write_file refuse-$importName.dump $importDump
295 fossil_raw -seconds 60 import --svn refuse-$importName.fossil \
296 refuse-$importName.dump
297 test import-refuse-svn-$importName {$CODE == 1 &&
298 [string first "svn-dump data format broken" $RESULT] >= 0}
299 }
300
301 # A file outside trunk, branches and tags is passed over even when it has
302 # no Node-action.
303 #
304 write_file outside.dump \
305 [join [list \
306 "${importStart}Node-path: other/a\nNode-kind: file\n" \
307 "Text-content-length: 1\nContent-length: 1\n\nx\n\n"] ""]
308 fossil_raw -seconds 60 import --svn outside.fossil outside.dump
309 test import-svn-outside-no-action {$CODE == 0}
310
311 # An empty --trunk, --branches or --tags is refused unless --base names a
312 # directory; with one, an empty --trunk makes the base itself the trunk.
313 #
314 write_file base.dump \
315 [join [list \
316 "${importStart}Node-path: proj/a\nNode-kind: file\n" \
317 "Node-action: add\nText-content-length: 1\n" \
318 "Content-length: 1\n\nx\n\n"] ""]
319 foreach importName {trunk branches tags} {
320 fossil_raw -seconds 60 import --svn --$importName "" \
321 refuse-$importName.fossil base.dump
322 test import-refuse-svn-empty-$importName {$CODE == 1 && [string first \
323 "may be empty only with a non-empty --base" $RESULT] >= 0}
324 }
325 fossil_raw -seconds 60 import --svn --base proj --trunk "" base.fossil base.dump
326 test import-svn-base-empty-trunk {$CODE == 0}
@@ -295,11 +339,15 @@
339 # minutes after 2023-11-14 22:13:20 UTC. BODY is the lines that follow
340 # the comment.
341 #
342 proc import_commit {ref mark comment {body ""}} {
343 set when [expr {1700000000+60*$mark}]
344 return \
345 [join [list \
346 "commit $ref\nmark :$mark\n" \
347 "committer C <[email protected]> $when +0000\n" \
348 "data [string length $comment]\n$comment\n$body\n"] ""]
349 }
350
351 proc import_git {name stream args} {
352 write_file $name.fi $stream
353 fossil_raw -seconds 60 import --git {*}$args $name.fossil $name.fi
@@ -306,19 +354,19 @@
354 }
355
356 # What repository NAME answers to QUERY.
357 #
358 proc import_sql {name query} {
359 return [fossil_sql $query $name.fossil]
 
360 }
361
362 # The files of the check-in of NAME whose comment is COMMENT, in name
363 # order: the name, the permission and the former name of each.
364 #
365 proc import_files {name comment} {
366 return [import_sql $name \
367 "SELECT group_concat(trim(f.filename||' '||coalesce(f.perm,'')||' '||coalesce(f.previousName,'')), ', ')
368 FROM event e, blob b, files_of_checkin(b.uuid) f
369 WHERE e.type='ci' AND e.comment='$comment' AND b.rid=e.objid"]
370 }
371
372 # The branch and tag names that hold for the check-in with comment COMMENT.
@@ -368,11 +416,12 @@
416 append importStream "M 100644 :1 a.txt\nM 100755 :3 run.sh\nM 120000 :1 link\n"
417 append importStream "M 100644 :2 empty\n"
418 append importStream "M 100644 inline in.txt\ndata 7\ninline\n\n"
419 append importStream "M 100644 :99 missing.txt\n"
420 append importStream "M 100644 :1 dir/x\nM 100644 :1 dir/y\n"
421 append importStream \
422 "M 100644 :1 tmp/p\nM 100644 :1 tmp/q\nM 100644 :1 tmpfile\n"
423 append importStream "M 100644\nN :1 :10\ncheckpoint\n"
424 append importStream [import_commit refs/heads/master 11 two \
425 "D run.sh\nD tmp\nC a.txt b.txt\nR link link2\n"]
426 append importStream [import_commit refs/heads/dev 12 three \
427 "M 100644 :1 d.txt\n"]
@@ -390,28 +439,36 @@
439 append importStream "tag unknown\nfrom :97\n$importTagger\n"
440 append importStream "tag v4\n$importTagger\nfrom :13"
441
442 import_git all $importStream
443 test import-git-all {$CODE == 0}
444 test import-git-all-progress \
445 {[holds_strings $RESULT {"halfway there" 2023-11-14}]}
446 test_eq import-git-all-checkins [import_checkins all] \
447 "one two three four five six"
448 test_eq import-git-all-user [import_sql all \
449 "SELECT user||' '||date(mtime) FROM event WHERE comment='one'"] \
450 "[email protected] 2023-11-14"
451 test_eq import-git-all-one [import_files all one] \
452 [join [list \
453 "a.txt w, dir/x w, dir/y w, empty w, in.txt w, link l, " \
454 "run.sh x, tmp/p w, tmp/q w, tmpfile w"] ""]
455 fossil_raw cat in.txt -R all.fossil -r [import_sql all \
456 "SELECT uuid FROM blob, event WHERE rid=objid AND comment='one'"]
457 test_eq import-git-all-inline $RESULT "inline\n"
458 test_eq import-git-all-two [import_files all two] \
459 [join [list \
460 "a.txt w, b.txt w, dir/x w, dir/y w, empty w, in.txt w, " \
461 "link2 l link, tmpfile w"] ""]
462 test_eq import-git-all-two-parent [import_parents all two] one
463 test_eq import-git-all-two-tags [import_tags all two] "master trunk"
464 test_eq import-git-all-three-parent [import_parents all three] ""
465 test_eq import-git-all-three-tags [import_tags all three] "dev trunk"
466 test_eq import-git-all-four [import_files all four] \
467 [join [list \
468 "a.txt w, b.txt w, dir2/x w, dir2/y w, dir3/x w dir/x, " \
469 "dir3/y w dir/y, empty w, in.txt w, link2 l, tmpfile w"] ""]
470 test_eq import-git-all-four-parents [import_parents all four] "two one three"
471 test_eq import-git-all-four-tags [import_tags all four] "dev trunk v2 v3 v4"
472 test_eq import-git-all-tag-comment [import_sql all "SELECT value FROM tagxref
473 WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-v2')"] "the tag"
474 test_eq import-git-all-five-tags [import_tags all five] "dev trunk"
@@ -456,11 +513,12 @@
513 append importStream [import_commit refs/heads/master 2 names $importBody]
514 append importStream [import_commit refs/heads/master 3 fewer \
515 "D \"oct\\303\\251\"\nD plain name\n"]
516 import_git names $importStream
517 test import-git-names {$CODE == 0}
518 test_eq import-git-names-files \
519 [import_sql names "SELECT group_concat(lower(hex(f.filename)), ' ')
520 FROM event e, blob b, files_of_checkin(b.uuid) f
521 WHERE e.comment='names' AND b.rid=e.objid"] [lsort $importWant]
522 test_eq import-git-names-deleted [import_sql names "SELECT count(*)
523 FROM event e, blob b, files_of_checkin(b.uuid) f
524 WHERE e.comment='fewer' AND b.rid=e.objid"] 9
@@ -482,11 +540,12 @@
540 append importStream [import_commit refs/heads/ 2 slash "M 100644 :1 a\n"]
541 append importStream [import_commit refs/x 3 short "M 100644 :1 a\n"]
542 append importStream [import_commit refs/heads/master 4 nick \
543 "property branch-nick 7 nicked\nproperty rebase-of abc\nM 100644 :1 a\n"]
544 import_git refs $importStream
545 test_eq import-git-refs [import_sql refs \
546 "SELECT group_concat(comment||'='||value, ' ')
547 FROM (SELECT comment, value FROM event, tagxref
548 WHERE rid=objid AND tagxref.tagid=8 ORDER BY event.mtime)"] \
549 "slash=refs/heads/ short=refs/x nick=nicked"
550
551 # A commit on a tag ref that has no parent gets no tag, and a commit with
@@ -566,11 +625,12 @@
625 #
626 foreach {importName importStream importError} [list \
627 unknown-command "bogus line\n" {bad fast-import line: [bogus line]} \
628 no-angle-bracket "commit refs/heads/master\ncommitter C 1700000000 +0000\n" \
629 {bad fast-import line: [committer C 1700000000 +0000]} \
630 no-open-bracket \
631 "commit refs/heads/master\ncommitter C [email protected]> 17 +0000\n" \
632 {bad fast-import line: [committer C [email protected]>} \
633 short-data "blob\nmark :1\ndata 50\nabc" \
634 {short read: got 3 of 50 bytes} \
635 ] {
636 import_git bad-$importName $importStream
@@ -696,13 +756,11 @@
756
757 # Marks may name a check-in made by "fossil commit", whose files carry no
758 # permission, and the files of such a parent are kept. A commit whose
759 # "from" is the mark of a file keeps nothing from it.
760 #
761 commit_file plain.txt "plain\n" committed
 
 
762 fossil sql "SELECT 'c'||rid||' :7 '||uuid FROM blob
763 WHERE rid=(SELECT objid FROM event WHERE comment='committed')"
764 set importMarks "$RESULT\n"
765 fossil sql "SELECT 'b'||rid||' :8 '||uuid FROM blob
766 WHERE rid=(SELECT fid FROM mlink)"
@@ -750,11 +808,13 @@
808 # A file command acts on a file that an earlier line of the same commit
809 # made: D removes it, C copies it and R renames it.
810 #
811 set importStream [import_blob 1 "hello\n"]
812 append importStream [import_commit refs/heads/master 2 ordered \
813 [join [list \
814 "M 100644 :1 gone\nD gone\nM 100644 :1 src\nC src dst\n" \
815 "M 100644 :1 old\nR old new\n"] ""]]
816 import_git ordered $importStream
817 test_eq import-git-ordered [import_files ordered ordered] \
818 "dst w, new w, src w" knownBug
819
820 ###############################################################################
@@ -781,11 +841,12 @@
841
842 # Revision N, made by dan on day N+1 of 2026, with LOG as its comment.
843 #
844 proc import_r {n log} {
845 return [import_record [list Revision-number $n] [list svn:log $log \
846 svn:author dan svn:date [format 2026-01-%02dT00:00:00.000000Z \
847 [expr {$n+1}]]]]
848 }
849 proc import_file {action path text {props -}} {
850 return [import_record \
851 [list Node-path $path Node-kind file Node-action $action] $props $text]
852 }
@@ -842,11 +903,12 @@
903 [import_file change trunk/a.txt "alpha2\n"] \
904 [import_file change trunk/run.sh "run2\n"] \
905 [import_record {Node-path trunk Node-kind dir Node-action change} - xyz] \
906 [import_file change trunk/sub/s.txt - {svn:eol-style native}]
907 append importDump [import_r 3 three] [import_copy dir branches/b1 trunk 2]
908 append importDump [import_r 4 four] \
909 [import_file change branches/b1/a.txt "beta\n"]
910 append importDump [import_r 5 five] [import_copy dir tags/v1 trunk 4] \
911 [import_copy dir tags/v2 trunk 4]
912 append importDump [import_r 6 six] \
913 [import_copy file trunk/b-copy.txt branches/b1/a.txt 4] \
914 [import_copy file trunk/a2.txt trunk/a.txt 2] \
@@ -891,31 +953,36 @@
953 test_eq import-svn-layout-two [import_files layout "(no comment)"] \
954 "a.txt, link l, run.sh x, sub/s.txt"
955 test_eq import-svn-layout-two-content \
956 "[import_cat layout {(no comment)} a.txt][import_cat layout {(no comment)} run.sh]" \
957 "alpha2\nrun2\n"
958 test_eq import-svn-layout-two-tags [import_tags layout "(no comment)"] \
959 "trunk v2"
960 test_eq import-svn-layout-three [import_files layout three] \
961 "a.txt, link l, run.sh x, sub/s.txt"
962 test_eq import-svn-layout-three-parent [import_parents layout three] \
963 "(no comment)"
964 test_eq import-svn-layout-three-tags [import_tags layout three] b1
965 test_eq import-svn-layout-four [import_cat layout four a.txt] "beta\n"
966 test_eq import-svn-layout-four-tags [import_tags layout four] b1
967 test_eq import-svn-layout-six [import_files layout six] \
968 "a.txt, a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh x, sub/s.txt"
969 test_eq import-svn-layout-six-content \
970 "[import_cat layout six b-copy.txt][import_cat \
971 layout six a2.txt][import_cat layout six d.txt][import_cat layout six e.txt]" \
972 "beta\nalpha2\nalpha2\nmore\nfresh\n"
973 test_eq import-svn-layout-six-parents [import_parents layout six] \
974 "(no comment) four"
975 test_eq import-svn-layout-seven [import_files layout seven] \
976 "a2.txt, b-copy.txt, d.txt, e.txt, link l, run.sh"
977 test_eq import-svn-layout-seven-content [import_cat layout seven run.sh] \
978 "new run\n"
979 test_eq import-svn-layout-eight [import_files layout eight] "a.txt, link l,\
980 run.sh x, sub/s.txt, sub2/s.txt, tcopy/a2.txt, tcopy/b-copy.txt,\
981 tcopy/d.txt, tcopy/e.txt, tcopy/link l, tcopy/run.sh"
982 test_eq import-svn-layout-eight-parents [import_parents layout eight] \
983 "four seven"
984 test_eq import-svn-layout-nine [import_files layout nine] s.txt
985 test_eq import-svn-layout-nine-parent [import_parents layout nine] six
986 test_eq import-svn-layout-nine-tags [import_tags layout nine] b2
987 test_eq import-svn-layout-nine-closed [import_sql layout "SELECT count(*)
988 FROM tagxref, tag, event WHERE tag.tagid=tagxref.tagid AND tagname='closed'
@@ -1021,11 +1088,12 @@
1088 group_concat(DISTINCT value) FROM tagxref WHERE tagid=8"] trunk knownBug
1089
1090 # A revision that copies a directory to another place on the same branch,
1091 # and does nothing else, is a check-in with the files of the copy.
1092 #
1093 import_svn dircopy \
1094 "$importHead[import_r 1 one][import_file add trunk/d/f "f\n"][import_r \
1095 2 two][import_copy dir trunk/d2 trunk/d 1]"
1096 test import-svn-dir-copy {$CODE == 0}
1097 test_eq import-svn-dir-copy-files [import_files dircopy two] "d/f, d2/f"
1098
1099 # --ignore-tree leaves out a directory and what is in it, on the trunk
@@ -1048,13 +1116,15 @@
1116
1117 # --incremental adds to a repository that exists, and tags each new
1118 # check-in with its revision number unless --no-rev-tags is given.
1119 #
1120 import_svn sincr "$importHead[import_r 1 one][import_file add trunk/a "a\n"]"
1121 write_file sincr2.dump \
1122 "$importHead[import_r 2 two][import_file add trunk/b "b\n"]"
1123 fossil_raw -seconds 60 import --svn --incremental sincr.fossil sincr2.dump
1124 test import-svn-incremental \
1125 {$CODE == 0 && [holds_strings $RESULT {!project-id}]}
1126 fossil_raw -seconds 60 -input \
1127 "$importHead[import_r 3 three][import_file add trunk/c "c\n"]" \
1128 import --svn --incremental --no-rev-tags sincr.fossil
1129 test import-svn-incremental-no-rev-tags {$CODE == 0}
1130 test_eq import-svn-incremental-checkins [import_checkins sincr] "one two three"
@@ -1068,11 +1138,12 @@
1138 #
1139 set importProps "D 3\nfoo\nK 7\nsvn:log\nV 7\nundated\nPROPS-END\n"
1140 set importDump "SVN-fs-dump-format-version: 3\n\nOther: 1\n\n"
1141 append importDump "Revision-number: 1\n"
1142 append importDump "Prop-content-length: [string length $importProps]\n"
1143 append importDump \
1144 "Content-length: [string length $importProps]\n\n$importProps\n"
1145 append importDump [import_file add trunk/a "a\n"]
1146 import_svn undated $importDump
1147 test import-svn-undated {$CODE == 0}
1148 test_eq import-svn-undated-checkin [import_sql undated "SELECT comment||' '||
1149 (mtime>julianday('now','-1 day')) FROM event"] "undated 1"
@@ -1093,17 +1164,25 @@
1164 version-4 "SVN-fs-dump-format-version: 4\n\n" \
1165 "Unknown svn-dump format version: 4" \
1166 no-colon "${importHead}no colon here\n\n" {bad header line: [no colon here]} \
1167 ends-in-headers "${importHead}Revision-number: 1\n" \
1168 "svn-dump data ended unexpectedly" \
1169 props-short \
1170 "${importHead}Revision-number: 1\nProp-content-length: 50\n\nPROPS-END\n" \
1171 "short read: got 10 of 50 bytes" \
1172 props-no-end \
1173 [join [list \
1174 "${importHead}Revision-number: 1\nProp-content-length: 12\n\n" \
1175 "K 1\na\nV 1\nb\n"] ""] \
1176 "svn-dump data ended unexpectedly" \
1177 props-negative \
1178 "${importHead}Revision-number: 1\nProp-content-length: -5\n\n" \
1179 "svn-dump data format broken" \
1180 text-short \
1181 [join [list \
1182 "${importR1}Node-path: trunk/a\nNode-kind: file\n" \
1183 "Node-action: add\nText-content-length: 9\n\nabc"] ""] \
1184 "short read: got 3 of 9 bytes" \
1185 unknown-record "${importHead}Other: 1\n\n" "Unknown record type" \
1186 rev-over-31-bits "$importHead[import_record {Revision-number 2147483648}]" \
1187 "svn-dump data format broken" \
1188 rev-eleven-digits "$importHead[import_record {Revision-number 21474836480}]" \
@@ -1112,13 +1191,15 @@
1191 "svn-dump data format broken" \
1192 no-copyfrom-rev "$importA[import_record {Node-path trunk/b Node-kind file
1193 Node-action add Node-copyfrom-path trunk/a}]" "Missing copyfrom-rev" \
1194 copy-from-outside "$importA[import_copy file trunk/b other/a 1]" \
1195 "Copy from path outside the import paths" \
1196 add-no-kind \
1197 "$importR1[import_record {Node-path trunk/a Node-action add} - x]" \
1198 "Missing Node-kind" \
1199 change-no-kind \
1200 "$importA[import_record {Node-path trunk/a Node-action change} - x]" \
1201 "Missing Node-kind" \
1202 unknown-action "$importR1[import_record {Node-path trunk/a Node-kind file
1203 Node-action frobnicate}]" "Unknown Node-action" \
1204 short-link "$importR1[import_file add trunk/l "link " {svn:special *}]" \
1205 "Too short symbolic link path" \
@@ -1157,11 +1238,15 @@
1238 v-no-newline "K 1\na\nV 1" \
1239 v-no-end "K 1\na\nV 1\nbcd\n" \
1240 ] {
1241 append importProps "PROPS-END\n"
1242 set importLength [string length $importProps]
1243 import_svn props-$importName \
1244 [join [list \
1245 "${importHead}Revision-number: 1\n" \
1246 "Prop-content-length: $importLength\n" \
1247 "Content-length: $importLength\n\n$importProps\n"] ""]
1248 test import-svn-props-$importName {$CODE == 1 &&
1249 [string first "svn-dump data format broken" $RESULT] >= 0}
1250 }
1251
1252 # A history with nodes that make no check-in of their own.
@@ -1244,11 +1329,12 @@
1329 # executable and a link on the trunk, a branch and a tag copied from it,
1330 # a change, a renamed file, and the branch deleted.
1331
1332 if {$::is_windows} {
1333 test_skip_part "the history made by Subversion needs links and file modes"
1334 } elseif {[catch {exec svnadmin --version --quiet}] || [catch \
1335 {exec svn --version --quiet}]} {
1336 test_skip_part "svnadmin and svn are not installed"
1337 } else {
1338 set importRepo [file join [pwd] svnrepo2]
1339 set importUrl file://$importRepo
1340 exec svnadmin create $importRepo
@@ -1267,11 +1353,12 @@
1353 exec svn move -q svnwc2/run.sh svnwc2/moved.sh
1354 exec svn commit -q -m four svnwc2
1355 exec svn delete -q -m five $importUrl/branches/b1
1356 foreach {importName importOption} {plain {} deltas --deltas} {
1357 exec svnadmin dump -q {*}$importOption $importRepo > svn-$importName.dump
1358 fossil_raw -seconds 60 import --svn svn-$importName.fossil \
1359 svn-$importName.dump
1360 test import-svn-made-$importName {$CODE == 0}
1361 set importName svn-$importName
1362 test_eq import-$importName-checkins [import_checkins $importName] \
1363 "one two four"
1364 test_eq import-$importName-one "[import_files $importName one];\
@@ -1309,11 +1396,12 @@
1396 -c [email protected] {*}$args 2>@1]
1397 unset ::env(GIT_AUTHOR_DATE) ::env(GIT_COMMITTER_DATE)
1398 return $out
1399 }
1400 exec git -c init.defaultBranch=master init -q gitrepo 2>@1
1401 foreach importName [list a.txt run.sh "sp ace.txt" "q\"uote.txt" \
1402 "t\tab.txt"] {
1403 write_file [file join gitrepo $importName] "content of $importName\n"
1404 }
1405 file attributes gitrepo/run.sh -permissions 0755
1406 file link -symbolic gitrepo/link a.txt
1407 import_git_run 1 add -A
1408
--- test/integrity.test
+++ test/integrity.test
@@ -9,15 +9,10 @@
99
# repository and fail, with a non-zero exit status, on each of nine
1010
# kinds of damage made with SQL; and "fossil rebuild" leaves the
1111
# tables derived from the artifacts as they were, or repairs them.
1212
#
1313
14
-# These tests run only in a long pass: -assurance stress.
15
-if {[test_assurance] ne "stress"} {
16
- test_skip "runs only with -assurance stress"
17
-}
18
-
1914
require_no_open_checkout
2015
2116
test_setup ""
2217
set ::env(FOSSIL_USER) tester
2318
@@ -144,11 +139,10 @@
144139
fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\
145140
JOIN filename USING(fnid) WHERE name='c.txt'"
146141
fossil artifact [normalize_result] -R r2.fossil
147142
test_eq integrity-artifact-readable [normalize_result] \
148143
"four\n[string repeat four 200]"
149
-file delete r2.fossil
150144
151145
###############################################################################
152146
# test-integrity and test-missing: exit 0 on a sound repository, non-zero
153147
# on each kind of damage. Each kind is made to a copy.
154148
@@ -200,11 +194,10 @@
200194
set integrityDamaged [file join [pwd] damaged.fossil]
201195
file copy -force r.fossil $integrityDamaged
202196
fossil sql -R $integrityDamaged $integritySql
203197
fossil {*}$integrityCmd -R $integrityDamaged -expectError
204198
test integrity-damage-$integrityName {$CODE != 0}
205
- file delete $integrityDamaged
206199
}
207200
208201
###############################################################################
209202
# Rebuild leaves the derived tables alone, or repairs a wrong one.
210203
@@ -211,18 +204,16 @@
211204
set integrityBefore [integrity_derived r.fossil]
212205
test integrity-derived-not-empty {[string length $integrityBefore] > 0}
213206
fossil rebuild r.fossil
214207
test_eq integrity-rebuild-same [integrity_derived r.fossil] $integrityBefore
215208
216
-set integrityDamaged [file join [pwd] damaged.fossil]
217209
file copy -force r.fossil $integrityDamaged
218210
fossil sql -R $integrityDamaged \
219211
"DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)"
220212
test integrity-missing-parent-link-shows \
221213
{[integrity_derived $integrityDamaged] ne $integrityBefore}
222214
fossil rebuild $integrityDamaged
223215
test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] \
224216
$integrityBefore
225
-file delete $integrityDamaged
226217
227218
test_cleanup
228219
unset ::env(FOSSIL_USER)
229220
--- test/integrity.test
+++ test/integrity.test
@@ -9,15 +9,10 @@
9 # repository and fail, with a non-zero exit status, on each of nine
10 # kinds of damage made with SQL; and "fossil rebuild" leaves the
11 # tables derived from the artifacts as they were, or repairs them.
12 #
13
14 # These tests run only in a long pass: -assurance stress.
15 if {[test_assurance] ne "stress"} {
16 test_skip "runs only with -assurance stress"
17 }
18
19 require_no_open_checkout
20
21 test_setup ""
22 set ::env(FOSSIL_USER) tester
23
@@ -144,11 +139,10 @@
144 fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\
145 JOIN filename USING(fnid) WHERE name='c.txt'"
146 fossil artifact [normalize_result] -R r2.fossil
147 test_eq integrity-artifact-readable [normalize_result] \
148 "four\n[string repeat four 200]"
149 file delete r2.fossil
150
151 ###############################################################################
152 # test-integrity and test-missing: exit 0 on a sound repository, non-zero
153 # on each kind of damage. Each kind is made to a copy.
154
@@ -200,11 +194,10 @@
200 set integrityDamaged [file join [pwd] damaged.fossil]
201 file copy -force r.fossil $integrityDamaged
202 fossil sql -R $integrityDamaged $integritySql
203 fossil {*}$integrityCmd -R $integrityDamaged -expectError
204 test integrity-damage-$integrityName {$CODE != 0}
205 file delete $integrityDamaged
206 }
207
208 ###############################################################################
209 # Rebuild leaves the derived tables alone, or repairs a wrong one.
210
@@ -211,18 +204,16 @@
211 set integrityBefore [integrity_derived r.fossil]
212 test integrity-derived-not-empty {[string length $integrityBefore] > 0}
213 fossil rebuild r.fossil
214 test_eq integrity-rebuild-same [integrity_derived r.fossil] $integrityBefore
215
216 set integrityDamaged [file join [pwd] damaged.fossil]
217 file copy -force r.fossil $integrityDamaged
218 fossil sql -R $integrityDamaged \
219 "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)"
220 test integrity-missing-parent-link-shows \
221 {[integrity_derived $integrityDamaged] ne $integrityBefore}
222 fossil rebuild $integrityDamaged
223 test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] \
224 $integrityBefore
225 file delete $integrityDamaged
226
227 test_cleanup
228 unset ::env(FOSSIL_USER)
229
--- test/integrity.test
+++ test/integrity.test
@@ -9,15 +9,10 @@
9 # repository and fail, with a non-zero exit status, on each of nine
10 # kinds of damage made with SQL; and "fossil rebuild" leaves the
11 # tables derived from the artifacts as they were, or repairs them.
12 #
13
 
 
 
 
 
14 require_no_open_checkout
15
16 test_setup ""
17 set ::env(FOSSIL_USER) tester
18
@@ -144,11 +139,10 @@
139 fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\
140 JOIN filename USING(fnid) WHERE name='c.txt'"
141 fossil artifact [normalize_result] -R r2.fossil
142 test_eq integrity-artifact-readable [normalize_result] \
143 "four\n[string repeat four 200]"
 
144
145 ###############################################################################
146 # test-integrity and test-missing: exit 0 on a sound repository, non-zero
147 # on each kind of damage. Each kind is made to a copy.
148
@@ -200,11 +194,10 @@
194 set integrityDamaged [file join [pwd] damaged.fossil]
195 file copy -force r.fossil $integrityDamaged
196 fossil sql -R $integrityDamaged $integritySql
197 fossil {*}$integrityCmd -R $integrityDamaged -expectError
198 test integrity-damage-$integrityName {$CODE != 0}
 
199 }
200
201 ###############################################################################
202 # Rebuild leaves the derived tables alone, or repairs a wrong one.
203
@@ -211,18 +204,16 @@
204 set integrityBefore [integrity_derived r.fossil]
205 test integrity-derived-not-empty {[string length $integrityBefore] > 0}
206 fossil rebuild r.fossil
207 test_eq integrity-rebuild-same [integrity_derived r.fossil] $integrityBefore
208
 
209 file copy -force r.fossil $integrityDamaged
210 fossil sql -R $integrityDamaged \
211 "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)"
212 test integrity-missing-parent-link-shows \
213 {[integrity_derived $integrityDamaged] ne $integrityBefore}
214 fossil rebuild $integrityDamaged
215 test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] \
216 $integrityBefore
 
217
218 test_cleanup
219 unset ::env(FOSSIL_USER)
220
+274 -200
--- test/login.test
+++ test/login.test
@@ -5,13 +5,17 @@
55
# test/cgi.test does. The /test-env page reports g.zLogin, g.isRobot and the
66
# capabilities the server granted. Several command-line test entry points in
77
# login.c are exercised directly.
88
#
99
10
-# These tests run only in a long pass: -assurance stress.
11
-if {[test_assurance] ne "stress"} {
12
- test_skip "runs only with -assurance stress"
10
+# Fossil sleeps for a second before it refuses a wrong password or a bad
11
+# password-reset link. Requests that are refused that way are sent
12
+# together with login_send_all, so that they wait at the same time, and
13
+# are left out at -assurance smoke.
14
+set loginWaits [expr {[test_assurance] ne "smoke"}]
15
+if {!$loginWaits} {
16
+ test_skip_part "the logins that Fossil delays need -assurance ci or stress"
1317
}
1418
1519
require_no_open_checkout
1620
1721
test_setup
@@ -30,51 +34,53 @@
3034
VALUES('test_env_enable','1',0)"
3135
3236
# Send TEXT (a byte string) to the server and return the whole reply. ARGS are
3337
# extra "fossil http" options.
3438
proc login_send {text args} {
35
- global loginRepo
36
- write_file lreq.txt $text
37
- file delete lreply.txt
38
- fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 9.9.9.9 \
39
- {*}$args
40
- if {[file exists lreply.txt]} { return [read_file lreply.txt] }
41
- return ""
39
+ return [fossil_http $::loginRepo $text --ipaddr 9.9.9.9 {*}$args]
40
+}
41
+
42
+# Send each request in TEXTS to a server of its own, all at the same
43
+# time, and return the list of replies in the same order.
44
+proc login_send_all {texts} {
45
+ global fossilexe loginRepo
46
+ set servers {}
47
+ foreach text $texts {
48
+ set n [llength $servers]
49
+ write_file lreq$n.txt $text
50
+ file delete lreply$n.txt
51
+ lappend servers [open |[list $fossilexe http $loginRepo --in lreq$n.txt \
52
+ --out lreply$n.txt --ipaddr 9.9.9.9]]
53
+ }
54
+ set replies {}
55
+ foreach server $servers {
56
+ set n [llength $replies]
57
+ catch {close $server}
58
+ if {[file exists lreply$n.txt]} {
59
+ lappend replies [read_file lreply$n.txt]
60
+ } else {
61
+ lappend replies ""
62
+ }
63
+ }
64
+ return $replies
4265
}
4366
4467
# A GET request for PATH carrying the header lines in HEADERS, a list.
4568
proc login_get {path {headers {}}} {
46
- set text "GET $path HTTP/1.1\r\nHost: x\r\n"
47
- foreach line $headers { append text $line "\r\n" }
48
- return [login_send "$text\r\n"]
69
+ return [login_send [request_get $path $headers]]
70
+}
71
+
72
+# The text of a POST of url-encoded BODY to PATH, with a Referer matching
73
+# the base URL so that the same-origin CSRF check passes.
74
+proc login_post_text {path body {headers {}}} {
75
+ return [request_post $path $body \
76
+ [list "Referer: http://x/login" {*}$headers]]
4977
}
5078
51
-# A POST of url-encoded BODY to PATH, with a Referer matching the base URL so
52
-# that the same-origin CSRF check passes.
79
+# A POST of url-encoded BODY to PATH.
5380
proc login_post {path body {headers {}}} {
54
- set text "POST $path HTTP/1.1\r\nHost: x\r\nReferer: http://x/login\r\n"
55
- append text "Content-Type: application/x-www-form-urlencoded\r\n"
56
- append text "Content-Length: [string length $body]\r\n"
57
- foreach line $headers { append text $line "\r\n" }
58
- append text "\r\n$body"
59
- return [login_send $text]
60
-}
61
-
62
-# The status line of a reply.
63
-proc login_status {reply} {
64
- return [string trim [lindex [split $reply \n] 0]]
65
-}
66
-
67
-# The value of the first header NAME in a reply, or "-" if there is none.
68
-proc login_header {reply name} {
69
- set end [string first "\r\n\r\n" $reply]
70
- foreach line [split [string range $reply 0 $end] \n] {
71
- if {[string match -nocase "$name: *" $line]} {
72
- return [string trim [string range $line [string length $name]+1 end]]
73
- }
74
- }
75
- return -
81
+ return [login_send [login_post_text $path $body $headers]]
7682
}
7783
7884
# The login name that /test-env reports for a reply. The server writes an
7985
# empty value for the "nobody" user, so report that as "nobody".
8086
proc login_who {reply} {
@@ -98,18 +104,21 @@
98104
# through to the "nobody" user.
99105
100106
fossil sql "REPLACE INTO config(name,value,mtime)
101107
VALUES('http_authentication_ok','1',0)"
102108
proc login_basic {creds} {
103
- return [login_get /test-env [list "Authorization: Basic [binary encode base64 $creds]"]]
109
+ return [login_get /test-env \
110
+ [list "Authorization: Basic [binary encode base64 $creds]"]]
104111
}
105112
106113
test_eq login-basic-good [login_who [login_basic loginbob:bobpw]] loginbob
107
-test login-basic-good-caps {[string match "*i*" [login_caps [login_basic loginbob:bobpw]]]}
114
+test login-basic-good-caps \
115
+ {[string match "*i*" [login_caps [login_basic loginbob:bobpw]]]}
108116
109117
set loginReply [login_basic loginbob:wrongpw]
110
-test login-basic-badpw {[string match "HTTP/1.0 401*" [login_status $loginReply]]}
118
+test login-basic-badpw {[string match "HTTP/1.0 401*" \
119
+ [reply_status $loginReply]]}
111120
112121
# A value with no colon names no password: the request is served as "nobody".
113122
test_eq login-basic-nocolon [login_who [login_basic nocolonhere]] nobody
114123
115124
# Header that does not begin with "Basic " is ignored.
@@ -150,51 +159,54 @@
150159
151160
proc login_form {user pw {extra ""}} {
152161
return [login_post /login "u=$user&p=$pw&in=Login&$extra"]
153162
}
154163
set loginReply [login_form loginbob bobpw]
155
-test login-form-status {[string match "HTTP/1.0 302*" [login_status $loginReply]]}
156
-set loginCookie [login_header $loginReply Set-Cookie]
157
-test login-form-cookie {[string match "fossil-*=*loginbob;*HttpOnly;*" $loginCookie]}
164
+test login-form-status {[string match "HTTP/1.0 302*" \
165
+ [reply_status $loginReply]]}
166
+set loginCookie [reply_header $loginReply Set-Cookie]
167
+test login-form-cookie {[string match "fossil-*=*loginbob;*HttpOnly;*" \
168
+ $loginCookie]}
158169
regexp {(fossil-[0-9a-f]+=[^;]+)} $loginCookie all loginCookiePair
159170
test_eq login-cookie-reuse \
160171
[login_who [login_get /test-env [list "Cookie: $loginCookiePair"]]] loginbob
161172
162
-set loginReply [login_form loginbob nope]
163
-test login-form-badpw {[string match "HTTP/1.0 401*" [login_status $loginReply]]}
164
-test login-form-badpw-nocookie {[login_header $loginReply Set-Cookie] eq "-"}
165
-
166
-# "remember me" controls whether the cookie is persistent (has max-age) or
167
-# lasts only for the browser session.
168
-set loginReply [login_form loginbob bobpw remember=1]
169
-test login-cookie-persistent \
170
- {[string match "*max-age=*" [login_header $loginReply Set-Cookie]]}
171
-set loginReply [login_form loginbob bobpw]
172
-test login-cookie-session \
173
- {![string match "*max-age=*" [login_header $loginReply Set-Cookie]]}
173
+# An email address with a wrong password is refused too.
174
+if {$loginWaits} {
175
+ lassign [login_send_all [list \
176
+ [login_post_text /login "u=loginbob&p=nope&in=Login&"] \
177
+ [login_post_text /login "[email protected]&p=wrongpw&in=Login&"]]] \
178
+ loginReply loginEmailReply
179
+ test login-form-badpw \
180
+ {[string match "HTTP/1.0 401*" [reply_status $loginReply]]}
181
+ test_eq login-form-badpw-nocookie [reply_header $loginReply Set-Cookie] "-"
182
+ test login-form-email-badpw \
183
+ {[string match "HTTP/1.0 401*" [reply_status $loginEmailReply]]}
184
+}
174185
175186
###############################################################################
176187
# The "g" goto parameter is always rendered relative to the repository root:
177188
# an absolute URL given in "g" is prefixed and so cannot leave the site.
178189
179190
set loginReply [login_form loginbob bobpw "g=/doc/trunk/x"]
180
-test_eq login-goto-relative [login_header $loginReply Location] http://x//doc/trunk/x
191
+test_eq login-goto-relative [reply_header $loginReply Location] \
192
+ http://x//doc/trunk/x
181193
182194
###############################################################################
183195
# Logout. A logged-in user who POSTs "out" with a matching Referer and the
184196
# Anti-CSRF token from the form has the login cookie cleared (an empty value
185197
# with a past expiry).
186198
187199
set loginReply [login_form loginbob bobpw]
188
-regexp {(fossil-[0-9a-f]+=[^;]+)} [login_header $loginReply Set-Cookie] \
200
+regexp {(fossil-[0-9a-f]+=[^;]+)} [reply_header $loginReply Set-Cookie] \
189201
all loginLogoutPair
190202
set loginReply [login_get /login [list "Cookie: $loginLogoutPair"]]
191203
regexp {name="csrf" value="([^"]+)"} $loginReply all loginCsrf
192204
set loginReply [login_post /login "out=Logout&csrf=$loginCsrf" \
193205
[list "Cookie: $loginLogoutPair"]]
194206
test login-logout-clears \
195
- {[string match "fossil-*=; *" [login_header $loginReply Set-Cookie]]}
207
+ {[string match "fossil-*=; *" [reply_header $loginReply Set-Cookie]]}
196208
197209
###############################################################################
198210
# Robot detection. With no login, g.isRobot is set from the User-Agent: a
199211
# self-identified bot is a robot, a current browser is not.
200212
@@ -205,11 +217,12 @@
205217
}
206218
test_eq login-robot-bot [login_isrobot "Googlebot/2.1"] 1
207219
test_eq login-robot-browser [login_isrobot "Mozilla/5.0 Firefox/122.0"] 0
208220
test_eq login-robot-noagent [login_isrobot ""] 1
209221
# The "isrobot" query parameter forces the robot flag on.
210
-set loginReply [login_get "/test-env?isrobot=1" {"User-Agent: Mozilla/5.0 Firefox/122.0"}]
222
+set loginReply [login_get "/test-env?isrobot=1" \
223
+ {"User-Agent: Mozilla/5.0 Firefox/122.0"}]
211224
test login-robot-forced {[regexp {g\.isRobot = 1<br>} $loginReply]}
212225
213226
###############################################################################
214227
# test-ishuman labels User-Agent strings read from standard input.
215228
@@ -236,29 +249,31 @@
236249
237250
###############################################################################
238251
# test-email-used reports which user owns an email address.
239252
240253
fossil test-email-used [email protected] [email protected]
241
-test login-email-used-known {[string match "*[email protected]: UID*loginbob*" $::RESULT]}
254
+test login-email-used-known \
255
+ {[string match "*[email protected]: UID*loginbob*" $::RESULT]}
242256
test login-email-used-unknown \
243257
{[string match "*[email protected]: not used*" $::RESULT]}
244258
245259
###############################################################################
246260
# Login groups. Two repositories are joined into a group, the membership is
247261
# shown, then one leaves.
248262
249263
set loginRepo2 [file join [pwd] grp2.fossil]
250264
fossil new $loginRepo2
251
-fossil user capabilities loginsue s
252265
fossil sql -R $loginRepo2 \
253266
"INSERT INTO user(login,pw,cap) VALUES('loginsue','suepw','s')"
254267
255268
test login-group-none-start \
256
- {![catch {fossil login-group} m] && [string match "*Not currently*" $::RESULT]}
269
+ {![catch {fossil login-group} m] && [string match "*Not currently*" \
270
+ $::RESULT]}
257271
fossil login-group join --name loggrp $loginRepo2
258272
fossil login-group
259
-test login-group-joined {[string match "*login-group \"loggrp\"*grp2.fossil*" $::RESULT]}
273
+test login-group-joined {[string match "*login-group \"loggrp\"*grp2.fossil*" \
274
+ $::RESULT]}
260275
test_eq login-group-name-fn [string trim [fossil sql \
261276
"SELECT value FROM config WHERE name='login-group-name'"]] loggrp
262277
fossil login-group leave
263278
fossil login-group
264279
test login-group-left {[string match "*Not currently*" $::RESULT]}
@@ -280,11 +295,11 @@
280295
VALUES('http_authentication_ok','1',0)"
281296
282297
# Log in as loginbob and return a two-element list {cookie-pair csrf-token}.
283298
proc login_session {user pw} {
284299
set reply [login_form $user $pw]
285
- regexp {(fossil-[0-9a-f]+=[^;]+)} [login_header $reply Set-Cookie] all pair
300
+ regexp {(fossil-[0-9a-f]+=[^;]+)} [reply_header $reply Set-Cookie] all pair
286301
set reply [login_get /login [list "Cookie: $pair"]]
287302
regexp {name="csrf" value="([^"]+)"} $reply all tok
288303
return [list $pair $tok]
289304
}
290305
@@ -291,24 +306,30 @@
291306
set loginSess [login_session loginbob bobpw]
292307
set loginPair [lindex $loginSess 0]
293308
set loginTok [lindex $loginSess 1]
294309
295310
set loginReply [login_post /login \
296
- "p=bobpw&n1=newbobpw&n2=newbobpw&csrf=$loginTok" [list "Cookie: $loginPair"]]
297
-test login-pwchange-ok {[string match "HTTP/1.0 302*" [login_status $loginReply]]}
311
+ "p=bobpw&n1=newbobpw&n2=newbobpw&csrf=$loginTok" \
312
+ [list "Cookie: $loginPair"]]
313
+test login-pwchange-ok {[string match "HTTP/1.0 302*" \
314
+ [reply_status $loginReply]]}
298315
test_eq login-pwchange-newpw-works \
299316
[login_who [login_basic loginbob:newbobpw]] loginbob
300317
test login-pwchange-oldpw-fails \
301
- {[string match "HTTP/1.0 401*" [login_status [login_basic loginbob:bobpw]]]}
318
+ {[string match "HTTP/1.0 401*" [reply_status [login_basic loginbob:bobpw]]]}
302319
303320
set loginReply [login_post /login \
304321
"p=newbobpw&n1=aaaaaa&n2=bbbbbb&csrf=$loginTok" [list "Cookie: $loginPair"]]
305322
test login-pwchange-mismatch {[string match "*do not match*" $loginReply]}
306323
307
-set loginReply [login_post /login \
308
- "p=totallywrong&n1=cccccc&n2=cccccc&csrf=$loginTok" [list "Cookie: $loginPair"]]
309
-test login-pwchange-badold {[string match "*incorrect old password*" $loginReply]}
324
+if {$loginWaits} {
325
+ set loginReply [login_post /login \
326
+ "p=totallywrong&n1=cccccc&n2=cccccc&csrf=$loginTok" \
327
+ [list "Cookie: $loginPair"]]
328
+ test login-pwchange-badold \
329
+ {[string match "*incorrect old password*" $loginReply]}
330
+}
310331
311332
###############################################################################
312333
# Self-registration through /register. The captcha answer is derived the same
313334
# way the server derives it: the first 8 hex digits of sha1("SECRET-SEEDHEX").
314335
# A complete, valid form creates the account; each validation rule rejects the
@@ -333,22 +354,26 @@
333354
}
334355
set loginRegTok [login_register_tokens]
335356
set loginSeed [lindex $loginRegTok 0]
336357
set loginCap [lindex $loginRegTok 1]
337358
set loginRCsrf [lindex $loginRegTok 2]
338
-set loginRegBase "new=1&captchaseed=$loginSeed&captcha=$loginCap&csrf=$loginRCsrf"
359
+set loginRegBase \
360
+ "new=1&captchaseed=$loginSeed&captcha=$loginCap&csrf=$loginRCsrf"
339361
340362
# POST a registration form whose user-supplied fields are FIELDS.
341363
proc login_register {fields} {
342364
global loginRegBase
343365
return [login_post /register "$loginRegBase&$fields"]
344366
}
345367
346
-set loginReply [login_register "u=realuser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]
347
-test login-register-ok {[string match "HTTP/1.0 302*" [login_status $loginReply]]}
348
-test login-register-created \
349
- {[string trim [fossil sql "SELECT login FROM user WHERE login='realuser'"]] eq "realuser"}
368
+set loginReply [login_register \
369
+ "u=realuser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]
370
+test login-register-ok {[string match "HTTP/1.0 302*" \
371
+ [reply_status $loginReply]]}
372
+test_eq login-register-created \
373
+ [string trim [fossil sql "SELECT login FROM user WHERE login='realuser'"]] \
374
+ "realuser"
350375
351376
test login-register-short-uid \
352377
{[string match "*User ID too short*" [login_register \
353378
"u=abc&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
354379
test login-register-reserved \
@@ -381,11 +406,12 @@
381406
# including the recursive inheritance of "reader" (u) and "developer" (v).
382407
383408
fossil sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')"
384409
fossil sql "UPDATE user SET cap='j' WHERE login='reader'"
385410
fossil sql "UPDATE user SET cap='b' WHERE login='developer'"
386
-fossil sql "REPLACE INTO config(name,value,mtime) VALUES('auto-hyperlink','0',0)"
411
+fossil sql \
412
+ "REPLACE INTO config(name,value,mtime) VALUES('auto-hyperlink','0',0)"
387413
proc login_capexpand {cap} {
388414
fossil sql "UPDATE user SET cap='$cap' WHERE login='loginbob'"
389415
return [login_caps [login_basic loginbob:newbobpw]]
390416
}
391417
test_eq login-cap-wiki [login_capexpand kv] bjkmL
@@ -416,11 +442,12 @@
416442
###############################################################################
417443
# Capability expansion for the privilege letters that grant many flags at once:
418444
# "s" (Setup) unlocks everything, and the forum digits accumulate.
419445
set loginSetupCaps [login_capexpand s]
420446
test login-cap-setup {[string match "*a*" $loginSetupCaps]
421
- && [string match "*s*" $loginSetupCaps] && [string match "*D*" $loginSetupCaps]}
447
+ && [string match "*s*" $loginSetupCaps] && [string match "*D*" \
448
+ $loginSetupCaps]}
422449
test_eq login-cap-forum6 [login_capexpand 6] 23456L
423450
test_eq login-cap-forum3 [login_capexpand 3] 23L
424451
425452
###############################################################################
426453
# Login cookies that are not of the form HASH/ARG/USER, or that name a user
@@ -432,17 +459,19 @@
432459
slash /
433460
end-slash abcdef/
434461
two-parts a/b/
435462
no-slash abcdef
436463
empty {}
437
- wrong-hash 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/loginbob
438
- special-user 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/nobody
464
+ wrong-hash
465
+ 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/loginbob
466
+ special-user
467
+ 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/nobody
439468
} {
440469
set loginReply [login_get /test-env \
441470
[list "Cookie: $loginCookieName=$loginCkValue"]]
442471
test login-cookie-bad-$loginCkName {$CODE == 0
443
- && [login_status $loginReply] eq "HTTP/1.0 200 OK"
472
+ && [reply_status $loginReply] eq "HTTP/1.0 200 OK"
444473
&& [login_who $loginReply] eq "nobody"}
445474
}
446475
447476
###############################################################################
448477
# Where a login goes afterwards when the request carries "fossil-goto", as a
@@ -450,11 +479,11 @@
450479
# site, and to the home page if it is anywhere else. A value that is not an
451480
# absolute http: or https: address, such as "timeline" or "//evil.example/",
452481
# is taken as a page of this site. The same holds for an
453482
# anonymous login and for the answer to the robot captcha at /ityaar.
454483
455
-set loginHome [login_header [login_form loginbob newbobpw] Location]
484
+set loginHome [reply_header [login_form loginbob newbobpw] Location]
456485
test login-goto-home {[string match "http://x/*" $loginHome]}
457486
fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
458487
set loginAnon "u=anonymous&p=$loginCap&cs=$loginSeed"
459488
set loginRobot "captchaseed=$loginSeed&captcha=$loginCap"
460489
@@ -465,40 +494,42 @@
465494
relative timeline http://x/timeline \
466495
same-site http://x/timeline http://x/timeline \
467496
] {
468497
set loginReply [login_get \
469498
"/login?u=loginbob&p=newbobpw&fossil-goto=$loginGoTarget"]
470
- test login-goto-query-$loginGoName \
471
- {[login_header $loginReply Location] eq $loginGoWant}
499
+ test_eq login-goto-query-$loginGoName [reply_header $loginReply Location] \
500
+ $loginGoWant
472501
set loginReply [login_form loginbob newbobpw "fossil-goto=$loginGoTarget"]
473
- test login-goto-form-$loginGoName \
474
- {[login_header $loginReply Location] eq $loginGoWant}
502
+ test_eq login-goto-form-$loginGoName [reply_header $loginReply Location] \
503
+ $loginGoWant
475504
set loginReply [login_post /login "u=loginbob&p=newbobpw&in=Login" \
476505
[list "Cookie: fossil-goto=$loginGoTarget"]]
477
- test login-goto-cookie-$loginGoName \
478
- {[login_header $loginReply Location] eq $loginGoWant}
506
+ test_eq login-goto-cookie-$loginGoName [reply_header $loginReply Location] \
507
+ $loginGoWant
479508
set loginReply [login_get "/login?$loginAnon&fossil-goto=$loginGoTarget"]
480509
test login-goto-anonymous-$loginGoName \
481
- {[string match "*anonymous*" [login_header $loginReply Set-Cookie]]
482
- && [login_header $loginReply Location] eq $loginGoWant}
510
+ {[string match "*anonymous*" [reply_header $loginReply Set-Cookie]]
511
+ && [reply_header $loginReply Location] eq $loginGoWant}
483512
set loginReply [login_get "/ityaar?$loginRobot&fossil-goto=$loginGoTarget"]
484
- test login-goto-ityaar-$loginGoName \
485
- {[login_header $loginReply Location] eq $loginGoWant}
513
+ test_eq login-goto-ityaar-$loginGoName [reply_header $loginReply Location] \
514
+ $loginGoWant
486515
}
487516
488517
# The captcha page at /honeypot remembers the address asked for in a
489518
# "fossil-goto" cookie, and a right answer sent with that cookie goes there.
490519
set loginReply [login_get /honeypot?x=1]
491520
test login-honeypot-cookie {[string match "*X-Robot: 1*" $loginReply]
492
- && [string match "*Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot*" $loginReply]}
521
+ && [string match "*Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot*" \
522
+ $loginReply]}
493523
set loginReply [login_get "/ityaar?$loginRobot" \
494524
{"Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fx%3D1"}]
495
-test_eq login-honeypot-return [login_header $loginReply Location] \
525
+test_eq login-honeypot-return [reply_header $loginReply Location] \
496526
http://x/honeypot?x=1
497527
# A wrong answer shows the captcha again.
498528
set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz"]
499
-test login-ityaar-wrong {[string match "*Prove that you are human*" $loginReply]}
529
+test login-ityaar-wrong {[string match "*Prove that you are human*" \
530
+ $loginReply]}
500531
501532
###############################################################################
502533
# Helpers for the cases below.
503534
504535
# A GET or POST to the repository REPO instead of the main one.
@@ -533,25 +564,18 @@
533564
return $m
534565
}
535566
return -
536567
}
537568
538
-# The SHA1 hash of TEXT, in lower-case hex.
539
-proc login_sha1 {text} {
540
- set fd [open sha1in.txt wb]
541
- puts -nonewline $fd $text
542
- close $fd
543
- fossil sha1sum sha1in.txt
544
- return [lindex $::RESULT 0]
545
-}
546569
547570
# Set the repository setting NAME to VALUE, or remove it when VALUE is "".
548571
proc login_config {name value} {
549572
if {$value eq ""} {
550573
fossil sql "DELETE FROM config WHERE name='$name'"
551574
} else {
552
- fossil sql "REPLACE INTO config(name,value,mtime) VALUES('$name','$value',0)"
575
+ fossil sql \
576
+ "REPLACE INTO config(name,value,mtime) VALUES('$name','$value',0)"
553577
}
554578
}
555579
556580
###############################################################################
557581
# The capability letters not shown above each grant their own capability.
@@ -593,11 +617,11 @@
593617
###############################################################################
594618
# With no user named "nobody", a request without credentials is served as
595619
# user id -1 with no capabilities.
596620
fossil sql "UPDATE user SET login='nobody-saved' WHERE login='nobody'"
597621
set loginReply [login_get /test-env]
598
-test login-no-nobody {[login_status $loginReply] eq "HTTP/1.0 200 OK"
622
+test login-no-nobody {[reply_status $loginReply] eq "HTTP/1.0 200 OK"
599623
&& [string match "*g.userUid = -1<br>*" $loginReply]
600624
&& [login_caps $loginReply] eq ""}
601625
fossil sql "UPDATE user SET login='nobody' WHERE login='nobody-saved'"
602626
603627
###############################################################################
@@ -654,11 +678,15 @@
654678
fossil unset localauth
655679
656680
###############################################################################
657681
# With --httptrace, the login and its capability string are written to
658682
# standard error.
659
-write_file lreq.txt "GET /test-env HTTP/1.1\r\nHost: x\r\nAuthorization: Basic [binary encode base64 loginbob:newbobpw]\r\n\r\n"
683
+write_file lreq.txt \
684
+ [join [list \
685
+ "GET /test-env HTTP/1.1\r\nHost: x\r\n" \
686
+ "Authorization: Basic " \
687
+ "[binary encode base64 loginbob:newbobpw]\r\n\r\n"] ""]
660688
fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 9.9.9.9 \
661689
--httptrace
662690
test login-httptrace \
663691
{[string first {# login: [loginbob] with capabilities [o]} $RESULT] >= 0}
664692
@@ -673,50 +701,59 @@
673701
set loginUA "User-Agent: $loginUAText"
674702
set loginReply [login_get "/login?$loginAnon" [list $loginUA]]
675703
set loginAnonPair [login_cookie_pair $loginReply]
676704
test login-anon-cookie {[string match "fossil-*=*%2Fanonymous" $loginAnonPair]}
677705
test login-anon-cookie-session \
678
- {![string match "*max-age=*" [login_header $loginReply Set-Cookie]]}
706
+ {![string match "*max-age=*" [reply_header $loginReply Set-Cookie]]}
679707
set loginReply [login_get /test-env [list "Cookie: $loginAnonPair" $loginUA]]
680708
test login-anon-cookie-reuse {[login_who $loginReply] eq "anonymous"
681709
&& [login_method $loginReply] eq "COOKIE"}
682710
test_eq login-anon-cookie-other-agent [login_who [login_get /test-env \
683711
[list "Cookie: $loginAnonPair" "User-Agent: Mozilla/5.0 Chrome/120.0"]]] \
684712
nobody
685713
set loginReply [login_get "/login?$loginAnon&remember=1"]
686714
test login-anon-cookie-persistent \
687
- {[string match "*%2Fanonymous;*max-age=*" [login_header $loginReply Set-Cookie]]}
715
+ {[string match "*%2Fanonymous;*max-age=*" \
716
+ [reply_header $loginReply Set-Cookie]]}
688717
689718
set loginSecret [string trim [fossil sql \
690719
"SELECT value FROM config WHERE name='captcha-secret'"]]
691720
fossil sql "REPLACE INTO config(name,value,mtime)
692721
VALUES('captcha-secret-1','oldsecret',unixepoch())"
693722
set loginNow [string trim [fossil sql "SELECT julianday('now')"]]
694
-set loginOldHash [login_sha1 "$loginNow/$loginUAText/oldsecret"]
723
+set loginOldHash [sha1_text "$loginNow/$loginUAText/oldsecret"]
695724
test_eq login-anon-cookie-old-secret [login_who [login_get /test-env \
696
- [list "Cookie: $loginCookieName=$loginOldHash/$loginNow/anonymous" $loginUA]]] \
725
+ [list "Cookie: $loginCookieName=$loginOldHash/$loginNow/anonymous" \
726
+ $loginUA]]] \
697727
anonymous
698
-set loginStaleHash [login_sha1 "2400000.5/$loginUAText/$loginSecret"]
728
+set loginStaleHash [sha1_text "2400000.5/$loginUAText/$loginSecret"]
699729
test_eq login-anon-cookie-expired [login_who [login_get /test-env \
700
- [list "Cookie: $loginCookieName=$loginStaleHash/2400000.5/anonymous" $loginUA]]] \
730
+ [list "Cookie: $loginCookieName=$loginStaleHash/2400000.5/anonymous" \
731
+ $loginUA]]] \
701732
nobody
702733
set loginOldPw [string range \
703
- [login_sha1 "oldsecret-[format %x $loginSeed]"] 0 7]
734
+ [sha1_text "oldsecret-[format %x $loginSeed]"] 0 7]
704735
set loginReply [login_get "/login?u=anonymous&p=$loginOldPw&cs=$loginSeed"]
705736
test login-anon-old-secret \
706
- {[string match "*%2Fanonymous*" [login_header $loginReply Set-Cookie]]}
707
-set loginReply [login_get "/login?u=anonymous&p=00000000&cs=$loginSeed"]
708
-test login-anon-wrong {[string match "HTTP/1.0 401*" [login_status $loginReply]]
709
- && [login_header $loginReply Set-Cookie] eq "-"}
737
+ {[string match "*%2Fanonymous*" [reply_header $loginReply Set-Cookie]]}
738
+if {$loginWaits} {
739
+ set loginReply [login_get "/login?u=anonymous&p=00000000&cs=$loginSeed"]
740
+ test login-anon-wrong {
741
+ [string match "HTTP/1.0 401*" [reply_status $loginReply]]
742
+ && [reply_header $loginReply Set-Cookie] eq "-"}
743
+}
710744
fossil sql "DELETE FROM config WHERE name='captcha-secret-1'"
711745
712746
login_config anon-cookie-lifespan 0
713747
test_eq login-anon-cookie-off [login_who [login_get /test-env \
714748
[list "Cookie: $loginAnonPair" $loginUA]]] nobody
715
-set loginReply [login_get "/login?$loginAnon"]
716
-test login-anon-login-off {[string match "HTTP/1.0 401*" [login_status $loginReply]]
717
- && [login_header $loginReply Set-Cookie] eq "-"}
749
+if {$loginWaits} {
750
+ set loginReply [login_get "/login?$loginAnon"]
751
+ test login-anon-login-off {
752
+ [string match "HTTP/1.0 401*" [reply_status $loginReply]]
753
+ && [reply_header $loginReply Set-Cookie] eq "-"}
754
+}
718755
login_config anon-cookie-lifespan ""
719756
720757
###############################################################################
721758
# The /login page. "anon=1" with "g" asks only for the captcha for an
722759
# anonymous login; "g" alone names the page asked for, without its query
@@ -728,47 +765,50 @@
728765
test login-page-anon {[string match {*name="anon" value="1"*} $loginReply]
729766
&& [string match "*Verify that you are human*" $loginReply]
730767
&& [string match "*Verify that I am human*" $loginReply]}
731768
set loginReply [login_get "/login?g=timeline%3fn=5"]
732769
test login-page-goto \
733
- {[string match "*Login as a named user to access page <b>timeline</b>*" $loginReply]}
770
+ {[string match "*Login as a named user to access page <b>timeline</b>*" \
771
+ $loginReply]}
734772
set loginSess [login_session loginbob newbobpw]
735773
set loginPair [lindex $loginSess 0]
736774
set loginReply [login_get "/login?g=timeline" [list "Cookie: $loginPair"]]
737775
test login-page-goto-loggedin {[string match \
738
- "*greater privilege than <b>loginbob</b>*to access <b>timeline</b>*" $loginReply]}
776
+ "*greater privilege than <b>loginbob</b>*to access <b>timeline</b>*" \
777
+ $loginReply]}
739778
set loginReply [login_get "/login?anon=2" [list "Cookie: $loginPair"]]
740779
test login-page-anon2 {![string match "*Currently logged in*" $loginReply]
741780
&& [string match "*Verify that I am human*" $loginReply]}
742781
set loginReply [login_get /login]
743782
test login-page-visitors {[string match "*Visitors may enter*" $loginReply]
744783
&& [string match "*Create A New Account*" $loginReply]}
745784
test login-page-noanon \
746785
{![string match "*Visitors may enter*" [login_get "/login?noanon=1"]]}
747
-test_eq login-page-self [login_header [login_get "/login?self=1"] Location] \
786
+test_eq login-page-self [reply_header [login_get "/login?self=1"] Location] \
748787
http://x/register
749788
750789
# A logout sent with "anon=2", which skips the login check, redirects and
751790
# clears no cookie.
752791
set loginReply [login_post /login "anon=2&out=Logout&csrf="]
753
-test login-logout-anon2 {[string match "HTTP/1.0 302*" [login_status $loginReply]]
754
- && [login_header $loginReply Set-Cookie] eq "-"}
792
+test login-logout-anon2 {[string match "HTTP/1.0 302*" \
793
+ [reply_status $loginReply]]
794
+ && [reply_header $loginReply Set-Cookie] eq "-"}
755795
756796
# With "https-login" on, the login form is sent to the https: address of
757797
# the site, unless the server is run with --nossl.
758798
login_config https-login 1
759799
test login-page-https \
760800
{[string match "*data-action='https://x/login'*" [login_get /login]]}
761
-write_file lreq.txt "GET /login HTTP/1.1\r\nHost: x\r\n\r\n"
762
-set loginReply [login_send [read_file lreq.txt] --nossl]
801
+set loginReply [login_send "GET /login HTTP/1.1\r\nHost: x\r\n\r\n" --nossl]
763802
test login-page-nossl {![string match "*'https://x/login'*" $loginReply]}
764803
login_config https-login ""
765804
766805
# With "auto-captcha" on, the page offers a button that fills in the
767806
# anonymous password.
768807
login_config auto-captcha 1
769
-test login-page-autocaptcha {[string match "*Fill out captcha*" [login_get /login]]}
808
+test login-page-autocaptcha \
809
+ {[string match "*Fill out captcha*" [login_get /login]]}
770810
login_config auto-captcha ""
771811
772812
# "nobody" with the Password capability is refused a password change.
773813
fossil sql "UPDATE user SET cap='p' WHERE login='nobody'"
774814
regexp {name="csrf" value="([^"]+)"} [login_get /login] all loginNbCsrf
@@ -787,18 +827,21 @@
787827
[login_register "u=bad+user1&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
788828
test login-register-no-email {[regexp {Email Address:.*Required} \
789829
[login_register "u=gooduser&dn=Real&ea=&p=longpw9&cp=longpw9"]]}
790830
login_config auth-sub-email *@ok.example
791831
test login-register-unauthorized {[string match "*Not an authorized email*" \
792
- [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
832
+ [login_register \
833
+ "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
793834
test login-register-authorized {[string match "*Passwords do not match*" \
794835
[login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
795836
login_config auth-sub-email ""
796
-test login-register-email-used {[string match "*already associated with a user*" \
837
+test login-register-email-used \
838
+ {[string match "*already associated with a user*" \
797839
[login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
798840
test login-register-goto \
799
- {[string match {*name="g" value="timeline"*} [login_get "/register?g=timeline"]]}
841
+ {[string match {*name="g" value="timeline"*} \
842
+ [login_get "/register?g=timeline"]]}
800843
login_config self-register ""
801844
test login-register-off \
802845
{[string match "*Registration not possible*" [login_get /register]]}
803846
login_config self-register 1
804847
@@ -837,11 +880,12 @@
837880
}
838881
proc login_ssub {email} {
839882
return [string trim [fossil sql \
840883
"SELECT ssub FROM subscriber WHERE semail='$email'"]]
841884
}
842
-set loginReply [login_register "u=verify1&dn=V&[email protected]&p=longpw9&cp=longpw9"]
885
+set loginReply [login_register \
886
+ "u=verify1&dn=V&[email protected]&p=longpw9&cp=longpw9"]
843887
test login-register-verify-noself {[string match "*Internal Error*" $loginReply]
844888
&& [login_user_cap verify1] eq "7" && [login_ssub [email protected]] eq "aw"}
845889
fossil settings email-self [email protected]
846890
login_config default-perms o2rj
847891
set loginReply [login_register \
@@ -852,17 +896,20 @@
852896
&& [login_mail_count] == 1 && [login_ssub [email protected]] eq "acftw"}
853897
login_config default-perms u
854898
# With alerts=0 there is no subscription and no email.
855899
set loginReply [login_register \
856900
"u=verify3&dn=V&[email protected]&p=longpw9&cp=longpw9&alerts=0"]
857
-test login-register-noalerts {[string match "HTTP/1.0 302*" [login_status $loginReply]]
901
+test login-register-noalerts \
902
+ {[string match "HTTP/1.0 302*" [reply_status $loginReply]]
858903
&& [login_ssub [email protected]] eq "" && [login_mail_count] == 1}
859904
# An address that is already a verified subscriber needs no verification.
860905
fossil sql "INSERT INTO subscriber(semail,sverified,sdonotcall,sdigest,ssub)
861906
VALUES('[email protected]',1,0,0,'a')"
862
-set loginReply [login_register "u=verify4&dn=V&[email protected]&p=longpw9&cp=longpw9"]
863
-test login-register-verified {[string match "HTTP/1.0 302*" [login_status $loginReply]]
907
+set loginReply [login_register \
908
+ "u=verify4&dn=V&[email protected]&p=longpw9&cp=longpw9"]
909
+test login-register-verified \
910
+ {[string match "HTTP/1.0 302*" [reply_status $loginReply]]
864911
&& [string trim [fossil sql \
865912
"SELECT suname FROM subscriber WHERE semail='[email protected]'"]] eq "verify4"
866913
&& [login_mail_count] == 1}
867914
login_config selfreg-verify ""
868915
@@ -887,11 +934,12 @@
887934
# user. Both test commands need an argument.
888935
889936
fossil sql "UPDATE user SET info='Sue <[email protected]>' WHERE login='loginsue'"
890937
fossil sql "UPDATE user SET info='Ann <[email protected]> <[email protected]>'
891938
WHERE login='verify3'"
892
-fossil sql "INSERT INTO subscriber(semail,suname,sverified,sdonotcall,sdigest,ssub)
939
+fossil sql \
940
+ "INSERT INTO subscriber(semail,suname,sverified,sdonotcall,sdigest,ssub)
893941
VALUES('[email protected]','verify2',1,0,0,'a'),
894942
('[email protected]','loginsue',1,0,0,'a'),
895943
('[email protected]','verify2',0,0,0,'a')"
896944
fossil test-email-used [email protected] [email protected] [email protected] [email protected] \
897945
[email protected]
@@ -921,13 +969,15 @@
921969
{[string match "*does not allow users to reset*" [login_get /reqpwreset]]}
922970
login_config self-pw-reset 1
923971
test login-reqpw-form \
924972
{[string match {*name="reqpwreset" value="1"*} [login_get /reqpwreset]]}
925973
test login-reqpw-from-login \
926
- {[string match {*name="reqpwreset" value="1"*} [login_get "/login?pwreset=1"]]}
974
+ {[string match {*name="reqpwreset" value="1"*} \
975
+ [login_get "/login?pwreset=1"]]}
927976
test login-reqpw-from-register \
928
- {[string match {*name="reqpwreset" value="1"*} [login_get "/register?pwreset=1"]]}
977
+ {[string match {*name="reqpwreset" value="1"*} \
978
+ [login_get "/register?pwreset=1"]]}
929979
test login-page-reset-button \
930980
{[string match "*Reset My Password*" [login_get /login]]}
931981
test login-register-reset-button {[string match "*Request Password Reset For*" \
932982
[login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
933983
@@ -935,11 +985,12 @@
935985
global loginSeed loginCap
936986
return [login_post /reqpwreset \
937987
"reqpwreset=1&captchaseed=$loginSeed&captcha=$loginCap&$fields"]
938988
}
939989
test login-reqpw-badcaptcha {[string match "*Incorrect CAPTCHA*" [login_post \
940
- /reqpwreset "reqpwreset=1&captchaseed=$loginSeed&captcha=00000000&[email protected]"]]}
990
+ /reqpwreset \
991
+ "reqpwreset=1&captchaseed=$loginSeed&captcha=00000000&[email protected]"]]}
941992
fossil sql "UPDATE user SET cap='vp' WHERE login='loginbob'"
942993
fossil sql "UPDATE user SET cap='a' WHERE login='developer'"
943994
foreach {loginRqName loginRqAddr loginRqWant} {
944995
empty {} {*Required*}
945996
invalid notmail {*Not a valid email*}
@@ -964,20 +1015,22 @@
9641015
fossil unset email-self
9651016
test login-reqpw-noself \
9661017
{[string match "*Internal Error*" [login_reqpw [email protected]]]}
9671018
fossil settings email-self [email protected]
9681019
set loginReply [login_reqpw [email protected]]
969
-test login-reqpw-sent {[string match {*has been sent to "[email protected]"*} $loginReply]
1020
+test login-reqpw-sent {[string match {*has been sent to "[email protected]"*} \
1021
+ $loginReply]
9701022
&& [login_mail_count] == 1}
9711023
set loginMail [read_file [lindex [glob -directory lmail *] 0]]
9721024
test login-reqpw-mail {[string match "*To: <[email protected]>*" $loginMail]
9731025
&& [string match "*Password reset for http://x*" $loginMail]}
9741026
9751027
###############################################################################
9761028
# /resetpw/UID-TIMESTAMP-HASH. A valid suffix gives a form that sets the
9771029
# user's password. A suffix that is malformed, names no user, is more than
978
-# an hour old or has the wrong hash is refused, and so is a valid suffix
1030
+# an hour old or has the wrong hash is refused, and so is a suffix whose
1031
+# first or second field ends in a character other than "-", and a valid suffix
9791032
# for "nobody", for a user with Setup capability or for a user without the
9801033
# Password capability.
9811034
9821035
proc login_reset_suffix {login} {
9831036
set uid [string trim [fossil sql "SELECT uid FROM user WHERE login='$login'"]]
@@ -984,33 +1037,44 @@
9841037
fossil test-resetpw-url $uid
9851038
regexp {/resetpw/([0-9a-f-]+)} $::RESULT all suffix
9861039
return $suffix
9871040
}
9881041
set loginRName [login_reset_suffix loginbob]
989
-test login-resetpw-form {[string match "*Change Password for user <b>loginbob</b>*" \
1042
+test login-resetpw-form {[string match \
1043
+ "*Change Password for user <b>loginbob</b>*" \
9901044
[login_get /resetpw/$loginRName]]}
9911045
test login-resetpw-mismatch {[string match "*do not match*" \
9921046
[login_post /resetpw "name=$loginRName&n1=aaaaaa&n2=bbbbbb"]]}
9931047
test login-resetpw-changed {[string match "*Password changed successfully*" \
9941048
[login_post /resetpw "name=$loginRName&n1=resetpw1&n2=resetpw1"]]}
9951049
test_eq login-resetpw-works [login_who [login_basic loginbob:resetpw1]] loginbob
9961050
997
-set loginBobUid [string trim [fossil sql \
998
- "SELECT uid FROM user WHERE login='loginbob'"]]
9991051
set loginHash [string repeat 0 64]
10001052
set loginNowHex [format %x [clock seconds]]
1053
+set loginBadTail [string repeat 0 70]
1054
+set loginRbNames {}
1055
+set loginRbRequests {}
10011056
foreach {loginRbName loginRbSuffix} [list \
10021057
short 1-2-3 \
10031058
no-uid [string repeat x 70] \
10041059
no-time "1--$loginHash$loginHash" \
10051060
uid-zero "0-$loginNowHex-$loginHash" \
10061061
no-user "ffff-$loginNowHex-$loginHash" \
1007
- expired "[format %x $loginBobUid]-1-$loginHash" \
1008
- wrong-hash "[format %x $loginBobUid]-$loginNowHex-$loginHash" \
1062
+ expired "[format %x $loginUid]-1-$loginHash" \
1063
+ wrong-hash "[format %x $loginUid]-$loginNowHex-$loginHash" \
1064
+ uid-end "1x$loginBadTail" \
1065
+ time-end "1-2x$loginBadTail" \
10091066
] {
1010
- test login-resetpw-bad-$loginRbName {[string match "*URL is invalid*" \
1011
- [login_get /resetpw/$loginRbSuffix]]}
1067
+ lappend loginRbNames $loginRbName
1068
+ lappend loginRbRequests [request_get /resetpw/$loginRbSuffix]
1069
+}
1070
+if {$loginWaits} {
1071
+ foreach loginRbName $loginRbNames \
1072
+ loginReply [login_send_all $loginRbRequests] {
1073
+ test login-resetpw-bad-$loginRbName \
1074
+ {[string match "*URL is invalid*" $loginReply]}
1075
+ }
10121076
}
10131077
foreach loginRrUser {loginsue nobody} {
10141078
test login-resetpw-refused-$loginRrUser {[string match \
10151079
"*Cannot change the password for user*" \
10161080
[login_get /resetpw/[login_reset_suffix $loginRrUser]]]}
@@ -1033,11 +1097,11 @@
10331097
set loginSess [login_session loginbob resetpw1]
10341098
set loginReply [login_post /login \
10351099
"p=resetpw1&n1=groupnew1&n2=groupnew1&csrf=[lindex $loginSess 1]" \
10361100
[list "Cookie: [lindex $loginSess 0]"]]
10371101
test login-group-pwchange-error {[string match "*ljunk.fossil: *" $loginReply]
1038
- && ![string match "HTTP/1.0 302*" [login_status $loginReply]]}
1102
+ && ![string match "HTTP/1.0 302*" [reply_status $loginReply]]}
10391103
test_eq login-group-gone-dropped [string trim [fossil sql \
10401104
"SELECT count(*) FROM config WHERE name GLOB 'peer-*-1111111111111111'"]] 0
10411105
set loginRName [login_reset_suffix loginbob]
10421106
test login-group-resetpw-error {[string match "*ljunk.fossil: *" \
10431107
[login_post /resetpw "name=$loginRName&n1=groupnew2&n2=groupnew2"]]}
@@ -1069,12 +1133,14 @@
10691133
set loginGoPair [login_cookie_pair $loginReply]
10701134
test_eq login-group-transfer-anon \
10711135
[login_who [login_get /test-env [list "Cookie: $loginGoPair"]]] anonymous
10721136
10731137
set loginWellFormed "$loginGrpCookie=[string repeat a 50]/x"
1074
-set loginReply [login_get "/ityaar?$loginRobot" [list "Cookie: $loginWellFormed"]]
1075
-test login-group-ityaar-keeps {[string match "HTTP/1.0 302*" [login_status $loginReply]]
1138
+set loginReply [login_get "/ityaar?$loginRobot" \
1139
+ [list "Cookie: $loginWellFormed"]]
1140
+test login-group-ityaar-keeps \
1141
+ {[string match "HTTP/1.0 302*" [reply_status $loginReply]]
10761142
&& ![string match "*%2Fanonymous*" $loginReply]}
10771143
set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \
10781144
[list "Cookie: $loginWellFormed"]]
10791145
test login-group-ityaar-no-captcha \
10801146
{![string match "*Prove that you are human*" $loginReply]}
@@ -1085,12 +1151,14 @@
10851151
# does not exist or is not a database, a wrong number of arguments.
10861152
foreach {loginLgName loginLgArgs loginLgWant} [list \
10871153
self [list join $loginRepo] {*same as this one*} \
10881154
missing [list join [file join [pwd] nosuch.fossil]] {*does not exist*} \
10891155
junk [list join [file join [pwd] ljunk.fossil]] {*not a database*} \
1090
- join-args [list join] {*unexpected argument count*} \
1091
- leave-args [list leave extra] {*unknown extra arguments*} \
1156
+ join-args [list join] \
1157
+ {*unexpected argument count*} \
1158
+ leave-args [list leave extra] \
1159
+ {*unknown extra arguments*} \
10921160
] {
10931161
fossil_raw login-group {*}$loginLgArgs
10941162
test login-group-err-$loginLgName {$CODE != 0
10951163
&& [string match $loginLgWant $RESULT]}
10961164
}
@@ -1113,15 +1181,14 @@
11131181
###############################################################################
11141182
# Pages that need a capability "nobody" lacks redirect to /login, naming
11151183
# the page and its query string, and adding "anon=1" when "anonymous" has
11161184
# the capability. With "redirect-to-https" set to 2 the redirect goes to
11171185
# the https: address.
1118
-fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
1119
-test_eq login-needed [login_header [login_get "/tktnew?x=1"] Location] \
1186
+test_eq login-needed [reply_header [login_get "/tktnew?x=1"] Location] \
11201187
http://x/login?g=tktnew%3fx%3D1
11211188
fossil sql "UPDATE user SET cap='hn' WHERE login='anonymous'"
1122
-test_eq login-needed-anon [login_header [login_get /tktnew] Location] \
1189
+test_eq login-needed-anon [reply_header [login_get /tktnew] Location] \
11231190
http://x/login?g=tktnew&anon=1
11241191
fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
11251192
11261193
# A page that shows hyperlinks only with the Hyperlink capability offers an
11271194
# anonymous login when "anonymous" has that capability.
@@ -1131,26 +1198,27 @@
11311198
11321199
# A page on the "robot-restrict" list asks a client without a login to
11331200
# show that it is not a robot.
11341201
login_config robot-restrict test-env
11351202
set loginReply [login_get /test-env [list "User-Agent: Googlebot/2.1"]]
1136
-test login-robot-restrict {[login_who $loginReply] eq "-"}
1203
+test_eq login-robot-restrict [login_who $loginReply] "-"
11371204
login_config robot-restrict ""
11381205
fossil sql "UPDATE user SET cap='' WHERE login='nobody'"
11391206
11401207
# With "redirect-to-https" set to 1, the redirect to /login for such a page
11411208
# goes to the https: address.
11421209
login_config redirect-to-https 1
1143
-test_eq login-needed-https [login_header [login_get /tktnew] Location] \
1210
+test_eq login-needed-https [reply_header [login_get /tktnew] Location] \
11441211
https://x/login?g=tktnew
11451212
login_config redirect-to-https ""
11461213
11471214
# A login cookie in a repository that is in no login group does not keep
11481215
# /ityaar from asking again after a wrong answer.
11491216
set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \
11501217
[list "Cookie: $loginCookieName=[string repeat a 50]/x"]]
1151
-test login-ityaar-nogroup {[string match "*Prove that you are human*" $loginReply]}
1218
+test login-ityaar-nogroup {[string match "*Prove that you are human*" \
1219
+ $loginReply]}
11521220
11531221
# A sync request whose login card names a user with a NULL capability
11541222
# column logs in with no capabilities: its pull is refused. The same
11551223
# request for that user with Read capability is answered.
11561224
fossil user new loginnocap [email protected] nocappw
@@ -1159,18 +1227,23 @@
11591227
"SELECT value FROM config WHERE name='project-code'"]]
11601228
set sc [string trim [fossil sql \
11611229
"SELECT value FROM config WHERE name='server-code'"]]
11621230
set pw [string trim [fossil sql "SELECT pw FROM user WHERE login='$user'"]]
11631231
set tail "pull $sc $pc\n"
1164
- set nonce [login_sha1 $tail]
1165
- set sig [login_sha1 "$nonce$pw"]
1232
+ set nonce [sha1_text $tail]
1233
+ set sig [sha1_text "$nonce$pw"]
11661234
set body "login $user $nonce $sig\n$tail"
1167
- return [login_send "POST /xfer HTTP/1.1\r\nHost: x\r\nContent-Type: application/x-fossil-uncompressed\r\nContent-Length: [string length $body]\r\n\r\n$body"]
1235
+ return [login_send \
1236
+ [join [list \
1237
+ "POST /xfer HTTP/1.1\r\nHost: x\r\n" \
1238
+ "Content-Type: application/x-fossil-uncompressed\r\n" \
1239
+ "Content-Length: [string length $body]\r\n\r\n$body"] ""]]
11681240
}
11691241
fossil sql "UPDATE user SET cap=NULL WHERE login='loginnocap'"
11701242
test login-xfer-null-cap \
1171
- {[string first {not\sauthorized\sto\sread} [login_xfer_pull loginnocap]] >= 0}
1243
+ {[string first {not\sauthorized\sto\sread} [login_xfer_pull loginnocap]] >=
1244
+ 0}
11721245
fossil sql "UPDATE user SET cap='o' WHERE login='loginnocap'"
11731246
set loginReply [login_xfer_pull loginnocap]
11741247
test login-xfer-read-cap {[string match "*igot *" $loginReply]
11751248
&& [string first {not\sauthorized} $loginReply] < 0}
11761249
@@ -1190,17 +1263,19 @@
11901263
login_config peer-repo-2222222222222222 [file join [pwd] lnoperm.fossil]
11911264
set loginSess [login_session loginbob groupnew2]
11921265
set loginReply [login_post /login \
11931266
"p=groupnew2&n1=groupnew3&n2=groupnew3&csrf=[lindex $loginSess 1]" \
11941267
[list "Cookie: [lindex $loginSess 0]"]]
1195
- test login-group-noperm-member {[string match "*lnoperm.fossil: *" $loginReply]}
1268
+ test login-group-noperm-member \
1269
+ {[string match "*lnoperm.fossil: *" $loginReply]}
11961270
login_config peer-repo-2222222222222222 ""
11971271
fossil_raw login-group join [file join [pwd] lnoperm.fossil]
11981272
test login-group-noperm-join {$CODE != 0
11991273
&& [string match "*unable to open*" $RESULT]}
12001274
} else {
1201
- test_skip_part "login-group-noperm-*: need a file the user running the tests cannot read"
1275
+ test_skip_part \
1276
+ "login-group-noperm-*: need a file the user running the tests cannot read"
12021277
}
12031278
file attributes lnoperm.fossil -permissions 0644
12041279
12051280
###############################################################################
12061281
# Pages that depend on the client. A request with a "Mobi" User-Agent is
@@ -1246,17 +1321,18 @@
12461321
empty {} $loginHome \
12471322
base http://x http://x \
12481323
base-more http://xy $loginHome \
12491324
other http://y/ $loginHome \
12501325
] {
1251
- test_eq login-goto-$loginFgName [login_header [login_get \
1326
+ test_eq login-goto-$loginFgName [reply_header [login_get \
12521327
"/login?u=loginbob&p=bobfinal&fossil-goto=$loginFgTarget"] Location] \
12531328
$loginFgWant
12541329
}
12551330
12561331
# A GET with "out" does not log out.
1257
-test login-logout-get {[string match "*Currently logged in as <b>loginbob</b>*" \
1332
+test login-logout-get {[string match \
1333
+ "*Currently logged in as <b>loginbob</b>*" \
12581334
[login_get "/login?out=1" [list "Cookie: $loginPair"]]]}
12591335
12601336
# A password change without the second copy of the new password, without
12611337
# the first, or without the Anti-CSRF token changes nothing.
12621338
foreach {loginPcName loginPcBody} [list \
@@ -1264,20 +1340,20 @@
12641340
no-n1 "p=bobfinal&n2=changed1&csrf=$loginTok" \
12651341
no-csrf "p=bobfinal&n1=changed1&n2=changed1" \
12661342
] {
12671343
set loginReply [login_post /login $loginPcBody [list "Cookie: $loginPair"]]
12681344
test login-pwchange-$loginPcName \
1269
- {![string match "HTTP/1.0 302*" [login_status $loginReply]]
1345
+ {![string match "HTTP/1.0 302*" [reply_status $loginReply]]
12701346
&& [login_who [login_basic loginbob:bobfinal]] eq "loginbob"}
12711347
}
12721348
12731349
# A user name with no password, or an empty password, shows the form and
12741350
# sets no cookie.
12751351
foreach {loginNpName loginNpQuery} {no-p u=loginbob empty-p u=loginbob&p=} {
12761352
set loginReply [login_get "/login?$loginNpQuery"]
1277
- test login-form-$loginNpName {[login_status $loginReply] eq "HTTP/1.0 200 OK"
1278
- && [login_header $loginReply Set-Cookie] eq "-"}
1353
+ test login-form-$loginNpName {[reply_status $loginReply] eq "HTTP/1.0 200 OK"
1354
+ && [reply_header $loginReply Set-Cookie] eq "-"}
12791355
}
12801356
12811357
# "g" with "noanon" does not name the page asked for.
12821358
test login-page-goto-noanon {![string match "*access page*" \
12831359
[login_get "/login?g=timeline&noanon=1"]]}
@@ -1312,21 +1388,24 @@
13121388
[login_get /login [list "Cookie: $loginPair"]]]}
13131389
fossil settings email-send-method dir
13141390
fossil sql "UPDATE user SET cap='op' WHERE login='loginbob'"
13151391
13161392
# An anonymous login is not offered a password change.
1317
-set loginAnonPair [login_cookie_pair [login_get "/login?$loginAnon" [list $loginUA]]]
1393
+set loginAnonPair [login_cookie_pair \
1394
+ [login_get "/login?$loginAnon" [list $loginUA]]]
13181395
set loginReply [login_get /login [list "Cookie: $loginAnonPair" $loginUA]]
1319
-test login-page-anonymous {[string match "*Currently logged in as <b>anonymous</b>*" $loginReply]
1396
+test login-page-anonymous {[string match \
1397
+ "*Currently logged in as <b>anonymous</b>*" $loginReply]
13201398
&& ![string match "*Change Password*" $loginReply]}
13211399
13221400
###############################################################################
13231401
# Further credential checks.
13241402
13251403
# "resid" without "token" logs no one in; "resid" naming a user with no
13261404
# password does not match any token.
1327
-test_eq login-resid-no-token [login_who [login_get "/test-env?resid=loginbob"]] nobody
1405
+test_eq login-resid-no-token \
1406
+ [login_who [login_get "/test-env?resid=loginbob"]] nobody
13281407
test_eq login-resid-no-pw \
13291408
[login_who [login_get "/test-env?resid=nobody&token=x"]] nobody
13301409
13311410
# A user whose login name is empty is served with that user's capabilities
13321411
# but without "L", the mark of a logged-in user.
@@ -1350,17 +1429,17 @@
13501429
test login-httptrace-no-nobody {[string first {# login:} $RESULT] < 0}
13511430
13521431
# A request from 127.0.0.1 without --localauth, or over https: with it, is
13531432
# not logged in. A request over the fossil ssh transport with --localauth
13541433
# is, whatever the client's address.
1355
-write_file lreq.txt "GET /test-env HTTP/1.1\r\nHost: x\r\n\r\n"
13561434
fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 127.0.0.1
13571435
test_eq login-loopback-no-localauth [login_who [read_file lreply.txt]] nobody
13581436
set ::env(REMOTE_HOST) 127.0.0.1
13591437
test_eq login-local-https [login_who [login_local $loginRepo --https]] nobody
13601438
unset ::env(REMOTE_HOST)
1361
-write_file lreq.txt "GET /test-env HTTP/1.1\r\nHost: x\r\nX-Fossil-Transport: SSH\r\n\r\n"
1439
+write_file lreq.txt \
1440
+ "GET /test-env HTTP/1.1\r\nHost: x\r\nX-Fossil-Transport: SSH\r\n\r\n"
13621441
set ::env(SSH_CONNECTION) "9.9.9.9 5000 127.0.0.1 22"
13631442
fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --localauth
13641443
unset ::env(SSH_CONNECTION)
13651444
set loginReply [read_file lreply.txt]
13661445
test login-local-ssh {[login_method $loginReply] eq "LOCAL"
@@ -1380,11 +1459,12 @@
13801459
13811460
# The offer of an anonymous login is not made when "anonymous" lacks the
13821461
# Hyperlink capability or anonymous logins are off.
13831462
fossil sql "UPDATE user SET cap='o' WHERE login='nobody'"
13841463
fossil sql "UPDATE user SET cap='' WHERE login='anonymous'"
1385
-test login-anonymous-available-nocap {![string match "*hyperlinks are disabled*" \
1464
+test login-anonymous-available-nocap \
1465
+ {![string match "*hyperlinks are disabled*" \
13861466
[login_get /leaves [list $loginUA]]]}
13871467
fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
13881468
login_config anon-cookie-lifespan 0
13891469
test login-anonymous-available-off {![string match "*hyperlinks are disabled*" \
13901470
[login_get /leaves [list $loginUA]]]}
@@ -1399,17 +1479,19 @@
13991479
foreach loginRsName {nobody1 reader1 developer1} {
14001480
test login-register-reserved-$loginRsName {[string match "*reserved*" \
14011481
[login_register "u=$loginRsName&dn=R&[email protected]&p=longpw9&cp=longpw9"]]}
14021482
}
14031483
# A GET with "new" shows the form and creates no user.
1404
-set loginReply [login_get "/register?$loginRegBase&u=getuser1&dn=G&[email protected]&p=longpw9&cp=longpw9"]
1484
+set loginReply [login_get \
1485
+ "/register?$loginRegBase&u=getuser1&dn=G&[email protected]&p=longpw9&cp=longpw9"]
14051486
test login-register-get {[string match {*name="captchaseed"*} $loginReply]
14061487
&& [login_user_cap getuser1] eq ""}
14071488
# An "auth-sub-email" setting that is empty allows any address.
14081489
fossil sql "REPLACE INTO config(name,value,mtime) VALUES('auth-sub-email','',0)"
14091490
test login-register-auth-empty {[string match "*Passwords do not match*" \
1410
- [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
1491
+ [login_register \
1492
+ "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
14111493
login_config auth-sub-email ""
14121494
14131495
login_config self-pw-reset 1
14141496
# The address of the "nobody" user is refused even with the Password
14151497
# capability.
@@ -1422,23 +1504,14 @@
14221504
"captchaseed=$loginSeed&captcha=$loginCap&[email protected]"]
14231505
test login-reqpw-no-flag {[string match {*name="reqpwreset"*} $loginReply]
14241506
&& ![string match "*has been sent*" $loginReply]}
14251507
14261508
###############################################################################
1427
-# Further /resetpw requests: a suffix whose first or second field ends in a
1428
-# character other than "-", a POST with only one copy of the password, and
1509
+# Further /resetpw requests: a POST with only one copy of the password, and
14291510
# valid suffixes for a user with Admin capability and for "nobody" with the
14301511
# Password capability.
14311512
1432
-set loginBadTail [string repeat 0 70]
1433
-foreach {loginRb2Name loginRb2Suffix} [list \
1434
- uid-end "1x$loginBadTail" \
1435
- time-end "1-2x$loginBadTail" \
1436
-] {
1437
- test login-resetpw-bad-$loginRb2Name {[string match "*URL is invalid*" \
1438
- [login_get /resetpw/$loginRb2Suffix]]}
1439
-}
14401513
set loginRName [login_reset_suffix loginbob]
14411514
test login-resetpw-one-copy {[string match "*Change Password for user*" \
14421515
[login_post /resetpw "name=$loginRName&n1=changed1"]]}
14431516
fossil sql "UPDATE user SET cap='a' WHERE login='verify3'"
14441517
test login-resetpw-refused-admin {[string match \
@@ -1457,11 +1530,12 @@
14571530
# hex digits, a slash and at least one more character.
14581531
14591532
login_config peer-repo-3333333333333333 [file join [pwd] ljunk.fossil]
14601533
login_config peer-repo-4444444444444444 $loginRepo2
14611534
set loginFakeHash [string repeat A 50]
1462
-foreach {loginPeName loginPeCode} {junk 3333333333333333 nocookie 4444444444444444} {
1535
+foreach {loginPeName loginPeCode} \
1536
+ {junk 3333333333333333 nocookie 4444444444444444} {
14631537
test_eq login-transfer-$loginPeName [login_who [login_get /test-env \
14641538
[list "Cookie: $loginCookieName=$loginFakeHash/$loginPeCode/loginsue"]]] \
14651539
nobody
14661540
}
14671541
login_config peer-repo-3333333333333333 ""
@@ -1482,40 +1556,40 @@
14821556
}
14831557
fossil login-group leave
14841558
14851559
# An empty login-group subcommand is unknown.
14861560
fossil_raw login-group ""
1487
-test login-group-err-empty {$CODE != 0 && [string match "*unknown command*" $RESULT]}
1561
+test login-group-err-empty \
1562
+ {$CODE != 0 && [string match "*unknown command*" $RESULT]}
14881563
14891564
###############################################################################
14901565
# Further cases, each varying one input of a case above.
14911566
1492
-# An email address with a wrong password is refused.
1493
-test login-form-email-badpw \
1494
- {[string match "HTTP/1.0 401*" [login_status [login_form [email protected] wrongpw]]]}
1495
-
14961567
# With "access-log" off, a login is not recorded.
14971568
login_config access-log 0
14981569
set loginLogCount [string trim [fossil sql "SELECT count(*) FROM accesslog"]]
14991570
login_form loginbob bobfinal
15001571
test_eq login-accesslog-off \
15011572
[string trim [fossil sql "SELECT count(*) FROM accesslog"]] $loginLogCount
15021573
login_config access-log ""
15031574
15041575
# A negative "anon-cookie-lifespan" turns anonymous logins off.
1505
-login_config anon-cookie-lifespan -5
1506
-set loginReply [login_get "/login?$loginAnon"]
1507
-test login-anon-negative-lifespan \
1508
- {[string match "HTTP/1.0 401*" [login_status $loginReply]]
1509
- && [login_header $loginReply Set-Cookie] eq "-"}
1510
-login_config anon-cookie-lifespan ""
1576
+if {$loginWaits} {
1577
+ login_config anon-cookie-lifespan -5
1578
+ set loginReply [login_get "/login?$loginAnon"]
1579
+ test login-anon-negative-lifespan \
1580
+ {[string match "HTTP/1.0 401*" [reply_status $loginReply]]
1581
+ && [reply_header $loginReply Set-Cookie] eq "-"}
1582
+ login_config anon-cookie-lifespan ""
1583
+}
15111584
15121585
# Login cookies that name the special users "developer" and "reader" are
15131586
# not accepted.
15141587
foreach loginSpUser {developer reader} {
15151588
test_eq login-cookie-special-$loginSpUser [login_who [login_get /test-env \
1516
- [list "Cookie: $loginCookieName=[string repeat A 50]/0123456789abcdef/$loginSpUser"]]] \
1589
+ [list \
1590
+ "Cookie: $loginCookieName=[string repeat A 50]/0123456789abcdef/$loginSpUser"]]] \
15171591
nobody
15181592
}
15191593
15201594
# The forum capabilities 5 and 4 grant those below them; "u" or "v" given
15211595
# twice inherits once.
15221596
--- test/login.test
+++ test/login.test
@@ -5,13 +5,17 @@
5 # test/cgi.test does. The /test-env page reports g.zLogin, g.isRobot and the
6 # capabilities the server granted. Several command-line test entry points in
7 # login.c are exercised directly.
8 #
9
10 # These tests run only in a long pass: -assurance stress.
11 if {[test_assurance] ne "stress"} {
12 test_skip "runs only with -assurance stress"
 
 
 
 
13 }
14
15 require_no_open_checkout
16
17 test_setup
@@ -30,51 +34,53 @@
30 VALUES('test_env_enable','1',0)"
31
32 # Send TEXT (a byte string) to the server and return the whole reply. ARGS are
33 # extra "fossil http" options.
34 proc login_send {text args} {
35 global loginRepo
36 write_file lreq.txt $text
37 file delete lreply.txt
38 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 9.9.9.9 \
39 {*}$args
40 if {[file exists lreply.txt]} { return [read_file lreply.txt] }
41 return ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42 }
43
44 # A GET request for PATH carrying the header lines in HEADERS, a list.
45 proc login_get {path {headers {}}} {
46 set text "GET $path HTTP/1.1\r\nHost: x\r\n"
47 foreach line $headers { append text $line "\r\n" }
48 return [login_send "$text\r\n"]
 
 
 
 
 
49 }
50
51 # A POST of url-encoded BODY to PATH, with a Referer matching the base URL so
52 # that the same-origin CSRF check passes.
53 proc login_post {path body {headers {}}} {
54 set text "POST $path HTTP/1.1\r\nHost: x\r\nReferer: http://x/login\r\n"
55 append text "Content-Type: application/x-www-form-urlencoded\r\n"
56 append text "Content-Length: [string length $body]\r\n"
57 foreach line $headers { append text $line "\r\n" }
58 append text "\r\n$body"
59 return [login_send $text]
60 }
61
62 # The status line of a reply.
63 proc login_status {reply} {
64 return [string trim [lindex [split $reply \n] 0]]
65 }
66
67 # The value of the first header NAME in a reply, or "-" if there is none.
68 proc login_header {reply name} {
69 set end [string first "\r\n\r\n" $reply]
70 foreach line [split [string range $reply 0 $end] \n] {
71 if {[string match -nocase "$name: *" $line]} {
72 return [string trim [string range $line [string length $name]+1 end]]
73 }
74 }
75 return -
76 }
77
78 # The login name that /test-env reports for a reply. The server writes an
79 # empty value for the "nobody" user, so report that as "nobody".
80 proc login_who {reply} {
@@ -98,18 +104,21 @@
98 # through to the "nobody" user.
99
100 fossil sql "REPLACE INTO config(name,value,mtime)
101 VALUES('http_authentication_ok','1',0)"
102 proc login_basic {creds} {
103 return [login_get /test-env [list "Authorization: Basic [binary encode base64 $creds]"]]
 
104 }
105
106 test_eq login-basic-good [login_who [login_basic loginbob:bobpw]] loginbob
107 test login-basic-good-caps {[string match "*i*" [login_caps [login_basic loginbob:bobpw]]]}
 
108
109 set loginReply [login_basic loginbob:wrongpw]
110 test login-basic-badpw {[string match "HTTP/1.0 401*" [login_status $loginReply]]}
 
111
112 # A value with no colon names no password: the request is served as "nobody".
113 test_eq login-basic-nocolon [login_who [login_basic nocolonhere]] nobody
114
115 # Header that does not begin with "Basic " is ignored.
@@ -150,51 +159,54 @@
150
151 proc login_form {user pw {extra ""}} {
152 return [login_post /login "u=$user&p=$pw&in=Login&$extra"]
153 }
154 set loginReply [login_form loginbob bobpw]
155 test login-form-status {[string match "HTTP/1.0 302*" [login_status $loginReply]]}
156 set loginCookie [login_header $loginReply Set-Cookie]
157 test login-form-cookie {[string match "fossil-*=*loginbob;*HttpOnly;*" $loginCookie]}
 
 
158 regexp {(fossil-[0-9a-f]+=[^;]+)} $loginCookie all loginCookiePair
159 test_eq login-cookie-reuse \
160 [login_who [login_get /test-env [list "Cookie: $loginCookiePair"]]] loginbob
161
162 set loginReply [login_form loginbob nope]
163 test login-form-badpw {[string match "HTTP/1.0 401*" [login_status $loginReply]]}
164 test login-form-badpw-nocookie {[login_header $loginReply Set-Cookie] eq "-"}
165
166 # "remember me" controls whether the cookie is persistent (has max-age) or
167 # lasts only for the browser session.
168 set loginReply [login_form loginbob bobpw remember=1]
169 test login-cookie-persistent \
170 {[string match "*max-age=*" [login_header $loginReply Set-Cookie]]}
171 set loginReply [login_form loginbob bobpw]
172 test login-cookie-session \
173 {![string match "*max-age=*" [login_header $loginReply Set-Cookie]]}
174
175 ###############################################################################
176 # The "g" goto parameter is always rendered relative to the repository root:
177 # an absolute URL given in "g" is prefixed and so cannot leave the site.
178
179 set loginReply [login_form loginbob bobpw "g=/doc/trunk/x"]
180 test_eq login-goto-relative [login_header $loginReply Location] http://x//doc/trunk/x
 
181
182 ###############################################################################
183 # Logout. A logged-in user who POSTs "out" with a matching Referer and the
184 # Anti-CSRF token from the form has the login cookie cleared (an empty value
185 # with a past expiry).
186
187 set loginReply [login_form loginbob bobpw]
188 regexp {(fossil-[0-9a-f]+=[^;]+)} [login_header $loginReply Set-Cookie] \
189 all loginLogoutPair
190 set loginReply [login_get /login [list "Cookie: $loginLogoutPair"]]
191 regexp {name="csrf" value="([^"]+)"} $loginReply all loginCsrf
192 set loginReply [login_post /login "out=Logout&csrf=$loginCsrf" \
193 [list "Cookie: $loginLogoutPair"]]
194 test login-logout-clears \
195 {[string match "fossil-*=; *" [login_header $loginReply Set-Cookie]]}
196
197 ###############################################################################
198 # Robot detection. With no login, g.isRobot is set from the User-Agent: a
199 # self-identified bot is a robot, a current browser is not.
200
@@ -205,11 +217,12 @@
205 }
206 test_eq login-robot-bot [login_isrobot "Googlebot/2.1"] 1
207 test_eq login-robot-browser [login_isrobot "Mozilla/5.0 Firefox/122.0"] 0
208 test_eq login-robot-noagent [login_isrobot ""] 1
209 # The "isrobot" query parameter forces the robot flag on.
210 set loginReply [login_get "/test-env?isrobot=1" {"User-Agent: Mozilla/5.0 Firefox/122.0"}]
 
211 test login-robot-forced {[regexp {g\.isRobot = 1<br>} $loginReply]}
212
213 ###############################################################################
214 # test-ishuman labels User-Agent strings read from standard input.
215
@@ -236,29 +249,31 @@
236
237 ###############################################################################
238 # test-email-used reports which user owns an email address.
239
240 fossil test-email-used [email protected] [email protected]
241 test login-email-used-known {[string match "*[email protected]: UID*loginbob*" $::RESULT]}
 
242 test login-email-used-unknown \
243 {[string match "*[email protected]: not used*" $::RESULT]}
244
245 ###############################################################################
246 # Login groups. Two repositories are joined into a group, the membership is
247 # shown, then one leaves.
248
249 set loginRepo2 [file join [pwd] grp2.fossil]
250 fossil new $loginRepo2
251 fossil user capabilities loginsue s
252 fossil sql -R $loginRepo2 \
253 "INSERT INTO user(login,pw,cap) VALUES('loginsue','suepw','s')"
254
255 test login-group-none-start \
256 {![catch {fossil login-group} m] && [string match "*Not currently*" $::RESULT]}
 
257 fossil login-group join --name loggrp $loginRepo2
258 fossil login-group
259 test login-group-joined {[string match "*login-group \"loggrp\"*grp2.fossil*" $::RESULT]}
 
260 test_eq login-group-name-fn [string trim [fossil sql \
261 "SELECT value FROM config WHERE name='login-group-name'"]] loggrp
262 fossil login-group leave
263 fossil login-group
264 test login-group-left {[string match "*Not currently*" $::RESULT]}
@@ -280,11 +295,11 @@
280 VALUES('http_authentication_ok','1',0)"
281
282 # Log in as loginbob and return a two-element list {cookie-pair csrf-token}.
283 proc login_session {user pw} {
284 set reply [login_form $user $pw]
285 regexp {(fossil-[0-9a-f]+=[^;]+)} [login_header $reply Set-Cookie] all pair
286 set reply [login_get /login [list "Cookie: $pair"]]
287 regexp {name="csrf" value="([^"]+)"} $reply all tok
288 return [list $pair $tok]
289 }
290
@@ -291,24 +306,30 @@
291 set loginSess [login_session loginbob bobpw]
292 set loginPair [lindex $loginSess 0]
293 set loginTok [lindex $loginSess 1]
294
295 set loginReply [login_post /login \
296 "p=bobpw&n1=newbobpw&n2=newbobpw&csrf=$loginTok" [list "Cookie: $loginPair"]]
297 test login-pwchange-ok {[string match "HTTP/1.0 302*" [login_status $loginReply]]}
 
 
298 test_eq login-pwchange-newpw-works \
299 [login_who [login_basic loginbob:newbobpw]] loginbob
300 test login-pwchange-oldpw-fails \
301 {[string match "HTTP/1.0 401*" [login_status [login_basic loginbob:bobpw]]]}
302
303 set loginReply [login_post /login \
304 "p=newbobpw&n1=aaaaaa&n2=bbbbbb&csrf=$loginTok" [list "Cookie: $loginPair"]]
305 test login-pwchange-mismatch {[string match "*do not match*" $loginReply]}
306
307 set loginReply [login_post /login \
308 "p=totallywrong&n1=cccccc&n2=cccccc&csrf=$loginTok" [list "Cookie: $loginPair"]]
309 test login-pwchange-badold {[string match "*incorrect old password*" $loginReply]}
 
 
 
 
310
311 ###############################################################################
312 # Self-registration through /register. The captcha answer is derived the same
313 # way the server derives it: the first 8 hex digits of sha1("SECRET-SEEDHEX").
314 # A complete, valid form creates the account; each validation rule rejects the
@@ -333,22 +354,26 @@
333 }
334 set loginRegTok [login_register_tokens]
335 set loginSeed [lindex $loginRegTok 0]
336 set loginCap [lindex $loginRegTok 1]
337 set loginRCsrf [lindex $loginRegTok 2]
338 set loginRegBase "new=1&captchaseed=$loginSeed&captcha=$loginCap&csrf=$loginRCsrf"
 
339
340 # POST a registration form whose user-supplied fields are FIELDS.
341 proc login_register {fields} {
342 global loginRegBase
343 return [login_post /register "$loginRegBase&$fields"]
344 }
345
346 set loginReply [login_register "u=realuser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]
347 test login-register-ok {[string match "HTTP/1.0 302*" [login_status $loginReply]]}
348 test login-register-created \
349 {[string trim [fossil sql "SELECT login FROM user WHERE login='realuser'"]] eq "realuser"}
 
 
 
350
351 test login-register-short-uid \
352 {[string match "*User ID too short*" [login_register \
353 "u=abc&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
354 test login-register-reserved \
@@ -381,11 +406,12 @@
381 # including the recursive inheritance of "reader" (u) and "developer" (v).
382
383 fossil sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')"
384 fossil sql "UPDATE user SET cap='j' WHERE login='reader'"
385 fossil sql "UPDATE user SET cap='b' WHERE login='developer'"
386 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('auto-hyperlink','0',0)"
 
387 proc login_capexpand {cap} {
388 fossil sql "UPDATE user SET cap='$cap' WHERE login='loginbob'"
389 return [login_caps [login_basic loginbob:newbobpw]]
390 }
391 test_eq login-cap-wiki [login_capexpand kv] bjkmL
@@ -416,11 +442,12 @@
416 ###############################################################################
417 # Capability expansion for the privilege letters that grant many flags at once:
418 # "s" (Setup) unlocks everything, and the forum digits accumulate.
419 set loginSetupCaps [login_capexpand s]
420 test login-cap-setup {[string match "*a*" $loginSetupCaps]
421 && [string match "*s*" $loginSetupCaps] && [string match "*D*" $loginSetupCaps]}
 
422 test_eq login-cap-forum6 [login_capexpand 6] 23456L
423 test_eq login-cap-forum3 [login_capexpand 3] 23L
424
425 ###############################################################################
426 # Login cookies that are not of the form HASH/ARG/USER, or that name a user
@@ -432,17 +459,19 @@
432 slash /
433 end-slash abcdef/
434 two-parts a/b/
435 no-slash abcdef
436 empty {}
437 wrong-hash 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/loginbob
438 special-user 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/nobody
 
 
439 } {
440 set loginReply [login_get /test-env \
441 [list "Cookie: $loginCookieName=$loginCkValue"]]
442 test login-cookie-bad-$loginCkName {$CODE == 0
443 && [login_status $loginReply] eq "HTTP/1.0 200 OK"
444 && [login_who $loginReply] eq "nobody"}
445 }
446
447 ###############################################################################
448 # Where a login goes afterwards when the request carries "fossil-goto", as a
@@ -450,11 +479,11 @@
450 # site, and to the home page if it is anywhere else. A value that is not an
451 # absolute http: or https: address, such as "timeline" or "//evil.example/",
452 # is taken as a page of this site. The same holds for an
453 # anonymous login and for the answer to the robot captcha at /ityaar.
454
455 set loginHome [login_header [login_form loginbob newbobpw] Location]
456 test login-goto-home {[string match "http://x/*" $loginHome]}
457 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
458 set loginAnon "u=anonymous&p=$loginCap&cs=$loginSeed"
459 set loginRobot "captchaseed=$loginSeed&captcha=$loginCap"
460
@@ -465,40 +494,42 @@
465 relative timeline http://x/timeline \
466 same-site http://x/timeline http://x/timeline \
467 ] {
468 set loginReply [login_get \
469 "/login?u=loginbob&p=newbobpw&fossil-goto=$loginGoTarget"]
470 test login-goto-query-$loginGoName \
471 {[login_header $loginReply Location] eq $loginGoWant}
472 set loginReply [login_form loginbob newbobpw "fossil-goto=$loginGoTarget"]
473 test login-goto-form-$loginGoName \
474 {[login_header $loginReply Location] eq $loginGoWant}
475 set loginReply [login_post /login "u=loginbob&p=newbobpw&in=Login" \
476 [list "Cookie: fossil-goto=$loginGoTarget"]]
477 test login-goto-cookie-$loginGoName \
478 {[login_header $loginReply Location] eq $loginGoWant}
479 set loginReply [login_get "/login?$loginAnon&fossil-goto=$loginGoTarget"]
480 test login-goto-anonymous-$loginGoName \
481 {[string match "*anonymous*" [login_header $loginReply Set-Cookie]]
482 && [login_header $loginReply Location] eq $loginGoWant}
483 set loginReply [login_get "/ityaar?$loginRobot&fossil-goto=$loginGoTarget"]
484 test login-goto-ityaar-$loginGoName \
485 {[login_header $loginReply Location] eq $loginGoWant}
486 }
487
488 # The captcha page at /honeypot remembers the address asked for in a
489 # "fossil-goto" cookie, and a right answer sent with that cookie goes there.
490 set loginReply [login_get /honeypot?x=1]
491 test login-honeypot-cookie {[string match "*X-Robot: 1*" $loginReply]
492 && [string match "*Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot*" $loginReply]}
 
493 set loginReply [login_get "/ityaar?$loginRobot" \
494 {"Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fx%3D1"}]
495 test_eq login-honeypot-return [login_header $loginReply Location] \
496 http://x/honeypot?x=1
497 # A wrong answer shows the captcha again.
498 set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz"]
499 test login-ityaar-wrong {[string match "*Prove that you are human*" $loginReply]}
 
500
501 ###############################################################################
502 # Helpers for the cases below.
503
504 # A GET or POST to the repository REPO instead of the main one.
@@ -533,25 +564,18 @@
533 return $m
534 }
535 return -
536 }
537
538 # The SHA1 hash of TEXT, in lower-case hex.
539 proc login_sha1 {text} {
540 set fd [open sha1in.txt wb]
541 puts -nonewline $fd $text
542 close $fd
543 fossil sha1sum sha1in.txt
544 return [lindex $::RESULT 0]
545 }
546
547 # Set the repository setting NAME to VALUE, or remove it when VALUE is "".
548 proc login_config {name value} {
549 if {$value eq ""} {
550 fossil sql "DELETE FROM config WHERE name='$name'"
551 } else {
552 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('$name','$value',0)"
 
553 }
554 }
555
556 ###############################################################################
557 # The capability letters not shown above each grant their own capability.
@@ -593,11 +617,11 @@
593 ###############################################################################
594 # With no user named "nobody", a request without credentials is served as
595 # user id -1 with no capabilities.
596 fossil sql "UPDATE user SET login='nobody-saved' WHERE login='nobody'"
597 set loginReply [login_get /test-env]
598 test login-no-nobody {[login_status $loginReply] eq "HTTP/1.0 200 OK"
599 && [string match "*g.userUid = -1<br>*" $loginReply]
600 && [login_caps $loginReply] eq ""}
601 fossil sql "UPDATE user SET login='nobody' WHERE login='nobody-saved'"
602
603 ###############################################################################
@@ -654,11 +678,15 @@
654 fossil unset localauth
655
656 ###############################################################################
657 # With --httptrace, the login and its capability string are written to
658 # standard error.
659 write_file lreq.txt "GET /test-env HTTP/1.1\r\nHost: x\r\nAuthorization: Basic [binary encode base64 loginbob:newbobpw]\r\n\r\n"
 
 
 
 
660 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 9.9.9.9 \
661 --httptrace
662 test login-httptrace \
663 {[string first {# login: [loginbob] with capabilities [o]} $RESULT] >= 0}
664
@@ -673,50 +701,59 @@
673 set loginUA "User-Agent: $loginUAText"
674 set loginReply [login_get "/login?$loginAnon" [list $loginUA]]
675 set loginAnonPair [login_cookie_pair $loginReply]
676 test login-anon-cookie {[string match "fossil-*=*%2Fanonymous" $loginAnonPair]}
677 test login-anon-cookie-session \
678 {![string match "*max-age=*" [login_header $loginReply Set-Cookie]]}
679 set loginReply [login_get /test-env [list "Cookie: $loginAnonPair" $loginUA]]
680 test login-anon-cookie-reuse {[login_who $loginReply] eq "anonymous"
681 && [login_method $loginReply] eq "COOKIE"}
682 test_eq login-anon-cookie-other-agent [login_who [login_get /test-env \
683 [list "Cookie: $loginAnonPair" "User-Agent: Mozilla/5.0 Chrome/120.0"]]] \
684 nobody
685 set loginReply [login_get "/login?$loginAnon&remember=1"]
686 test login-anon-cookie-persistent \
687 {[string match "*%2Fanonymous;*max-age=*" [login_header $loginReply Set-Cookie]]}
 
688
689 set loginSecret [string trim [fossil sql \
690 "SELECT value FROM config WHERE name='captcha-secret'"]]
691 fossil sql "REPLACE INTO config(name,value,mtime)
692 VALUES('captcha-secret-1','oldsecret',unixepoch())"
693 set loginNow [string trim [fossil sql "SELECT julianday('now')"]]
694 set loginOldHash [login_sha1 "$loginNow/$loginUAText/oldsecret"]
695 test_eq login-anon-cookie-old-secret [login_who [login_get /test-env \
696 [list "Cookie: $loginCookieName=$loginOldHash/$loginNow/anonymous" $loginUA]]] \
 
697 anonymous
698 set loginStaleHash [login_sha1 "2400000.5/$loginUAText/$loginSecret"]
699 test_eq login-anon-cookie-expired [login_who [login_get /test-env \
700 [list "Cookie: $loginCookieName=$loginStaleHash/2400000.5/anonymous" $loginUA]]] \
 
701 nobody
702 set loginOldPw [string range \
703 [login_sha1 "oldsecret-[format %x $loginSeed]"] 0 7]
704 set loginReply [login_get "/login?u=anonymous&p=$loginOldPw&cs=$loginSeed"]
705 test login-anon-old-secret \
706 {[string match "*%2Fanonymous*" [login_header $loginReply Set-Cookie]]}
707 set loginReply [login_get "/login?u=anonymous&p=00000000&cs=$loginSeed"]
708 test login-anon-wrong {[string match "HTTP/1.0 401*" [login_status $loginReply]]
709 && [login_header $loginReply Set-Cookie] eq "-"}
 
 
 
710 fossil sql "DELETE FROM config WHERE name='captcha-secret-1'"
711
712 login_config anon-cookie-lifespan 0
713 test_eq login-anon-cookie-off [login_who [login_get /test-env \
714 [list "Cookie: $loginAnonPair" $loginUA]]] nobody
715 set loginReply [login_get "/login?$loginAnon"]
716 test login-anon-login-off {[string match "HTTP/1.0 401*" [login_status $loginReply]]
717 && [login_header $loginReply Set-Cookie] eq "-"}
 
 
 
718 login_config anon-cookie-lifespan ""
719
720 ###############################################################################
721 # The /login page. "anon=1" with "g" asks only for the captcha for an
722 # anonymous login; "g" alone names the page asked for, without its query
@@ -728,47 +765,50 @@
728 test login-page-anon {[string match {*name="anon" value="1"*} $loginReply]
729 && [string match "*Verify that you are human*" $loginReply]
730 && [string match "*Verify that I am human*" $loginReply]}
731 set loginReply [login_get "/login?g=timeline%3fn=5"]
732 test login-page-goto \
733 {[string match "*Login as a named user to access page <b>timeline</b>*" $loginReply]}
 
734 set loginSess [login_session loginbob newbobpw]
735 set loginPair [lindex $loginSess 0]
736 set loginReply [login_get "/login?g=timeline" [list "Cookie: $loginPair"]]
737 test login-page-goto-loggedin {[string match \
738 "*greater privilege than <b>loginbob</b>*to access <b>timeline</b>*" $loginReply]}
 
739 set loginReply [login_get "/login?anon=2" [list "Cookie: $loginPair"]]
740 test login-page-anon2 {![string match "*Currently logged in*" $loginReply]
741 && [string match "*Verify that I am human*" $loginReply]}
742 set loginReply [login_get /login]
743 test login-page-visitors {[string match "*Visitors may enter*" $loginReply]
744 && [string match "*Create A New Account*" $loginReply]}
745 test login-page-noanon \
746 {![string match "*Visitors may enter*" [login_get "/login?noanon=1"]]}
747 test_eq login-page-self [login_header [login_get "/login?self=1"] Location] \
748 http://x/register
749
750 # A logout sent with "anon=2", which skips the login check, redirects and
751 # clears no cookie.
752 set loginReply [login_post /login "anon=2&out=Logout&csrf="]
753 test login-logout-anon2 {[string match "HTTP/1.0 302*" [login_status $loginReply]]
754 && [login_header $loginReply Set-Cookie] eq "-"}
 
755
756 # With "https-login" on, the login form is sent to the https: address of
757 # the site, unless the server is run with --nossl.
758 login_config https-login 1
759 test login-page-https \
760 {[string match "*data-action='https://x/login'*" [login_get /login]]}
761 write_file lreq.txt "GET /login HTTP/1.1\r\nHost: x\r\n\r\n"
762 set loginReply [login_send [read_file lreq.txt] --nossl]
763 test login-page-nossl {![string match "*'https://x/login'*" $loginReply]}
764 login_config https-login ""
765
766 # With "auto-captcha" on, the page offers a button that fills in the
767 # anonymous password.
768 login_config auto-captcha 1
769 test login-page-autocaptcha {[string match "*Fill out captcha*" [login_get /login]]}
 
770 login_config auto-captcha ""
771
772 # "nobody" with the Password capability is refused a password change.
773 fossil sql "UPDATE user SET cap='p' WHERE login='nobody'"
774 regexp {name="csrf" value="([^"]+)"} [login_get /login] all loginNbCsrf
@@ -787,18 +827,21 @@
787 [login_register "u=bad+user1&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
788 test login-register-no-email {[regexp {Email Address:.*Required} \
789 [login_register "u=gooduser&dn=Real&ea=&p=longpw9&cp=longpw9"]]}
790 login_config auth-sub-email *@ok.example
791 test login-register-unauthorized {[string match "*Not an authorized email*" \
792 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
 
793 test login-register-authorized {[string match "*Passwords do not match*" \
794 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
795 login_config auth-sub-email ""
796 test login-register-email-used {[string match "*already associated with a user*" \
 
797 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
798 test login-register-goto \
799 {[string match {*name="g" value="timeline"*} [login_get "/register?g=timeline"]]}
 
800 login_config self-register ""
801 test login-register-off \
802 {[string match "*Registration not possible*" [login_get /register]]}
803 login_config self-register 1
804
@@ -837,11 +880,12 @@
837 }
838 proc login_ssub {email} {
839 return [string trim [fossil sql \
840 "SELECT ssub FROM subscriber WHERE semail='$email'"]]
841 }
842 set loginReply [login_register "u=verify1&dn=V&[email protected]&p=longpw9&cp=longpw9"]
 
843 test login-register-verify-noself {[string match "*Internal Error*" $loginReply]
844 && [login_user_cap verify1] eq "7" && [login_ssub [email protected]] eq "aw"}
845 fossil settings email-self [email protected]
846 login_config default-perms o2rj
847 set loginReply [login_register \
@@ -852,17 +896,20 @@
852 && [login_mail_count] == 1 && [login_ssub [email protected]] eq "acftw"}
853 login_config default-perms u
854 # With alerts=0 there is no subscription and no email.
855 set loginReply [login_register \
856 "u=verify3&dn=V&[email protected]&p=longpw9&cp=longpw9&alerts=0"]
857 test login-register-noalerts {[string match "HTTP/1.0 302*" [login_status $loginReply]]
 
858 && [login_ssub [email protected]] eq "" && [login_mail_count] == 1}
859 # An address that is already a verified subscriber needs no verification.
860 fossil sql "INSERT INTO subscriber(semail,sverified,sdonotcall,sdigest,ssub)
861 VALUES('[email protected]',1,0,0,'a')"
862 set loginReply [login_register "u=verify4&dn=V&[email protected]&p=longpw9&cp=longpw9"]
863 test login-register-verified {[string match "HTTP/1.0 302*" [login_status $loginReply]]
 
 
864 && [string trim [fossil sql \
865 "SELECT suname FROM subscriber WHERE semail='[email protected]'"]] eq "verify4"
866 && [login_mail_count] == 1}
867 login_config selfreg-verify ""
868
@@ -887,11 +934,12 @@
887 # user. Both test commands need an argument.
888
889 fossil sql "UPDATE user SET info='Sue <[email protected]>' WHERE login='loginsue'"
890 fossil sql "UPDATE user SET info='Ann <[email protected]> <[email protected]>'
891 WHERE login='verify3'"
892 fossil sql "INSERT INTO subscriber(semail,suname,sverified,sdonotcall,sdigest,ssub)
 
893 VALUES('[email protected]','verify2',1,0,0,'a'),
894 ('[email protected]','loginsue',1,0,0,'a'),
895 ('[email protected]','verify2',0,0,0,'a')"
896 fossil test-email-used [email protected] [email protected] [email protected] [email protected] \
897 [email protected]
@@ -921,13 +969,15 @@
921 {[string match "*does not allow users to reset*" [login_get /reqpwreset]]}
922 login_config self-pw-reset 1
923 test login-reqpw-form \
924 {[string match {*name="reqpwreset" value="1"*} [login_get /reqpwreset]]}
925 test login-reqpw-from-login \
926 {[string match {*name="reqpwreset" value="1"*} [login_get "/login?pwreset=1"]]}
 
927 test login-reqpw-from-register \
928 {[string match {*name="reqpwreset" value="1"*} [login_get "/register?pwreset=1"]]}
 
929 test login-page-reset-button \
930 {[string match "*Reset My Password*" [login_get /login]]}
931 test login-register-reset-button {[string match "*Request Password Reset For*" \
932 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
933
@@ -935,11 +985,12 @@
935 global loginSeed loginCap
936 return [login_post /reqpwreset \
937 "reqpwreset=1&captchaseed=$loginSeed&captcha=$loginCap&$fields"]
938 }
939 test login-reqpw-badcaptcha {[string match "*Incorrect CAPTCHA*" [login_post \
940 /reqpwreset "reqpwreset=1&captchaseed=$loginSeed&captcha=00000000&[email protected]"]]}
 
941 fossil sql "UPDATE user SET cap='vp' WHERE login='loginbob'"
942 fossil sql "UPDATE user SET cap='a' WHERE login='developer'"
943 foreach {loginRqName loginRqAddr loginRqWant} {
944 empty {} {*Required*}
945 invalid notmail {*Not a valid email*}
@@ -964,20 +1015,22 @@
964 fossil unset email-self
965 test login-reqpw-noself \
966 {[string match "*Internal Error*" [login_reqpw [email protected]]]}
967 fossil settings email-self [email protected]
968 set loginReply [login_reqpw [email protected]]
969 test login-reqpw-sent {[string match {*has been sent to "[email protected]"*} $loginReply]
 
970 && [login_mail_count] == 1}
971 set loginMail [read_file [lindex [glob -directory lmail *] 0]]
972 test login-reqpw-mail {[string match "*To: <[email protected]>*" $loginMail]
973 && [string match "*Password reset for http://x*" $loginMail]}
974
975 ###############################################################################
976 # /resetpw/UID-TIMESTAMP-HASH. A valid suffix gives a form that sets the
977 # user's password. A suffix that is malformed, names no user, is more than
978 # an hour old or has the wrong hash is refused, and so is a valid suffix
 
979 # for "nobody", for a user with Setup capability or for a user without the
980 # Password capability.
981
982 proc login_reset_suffix {login} {
983 set uid [string trim [fossil sql "SELECT uid FROM user WHERE login='$login'"]]
@@ -984,33 +1037,44 @@
984 fossil test-resetpw-url $uid
985 regexp {/resetpw/([0-9a-f-]+)} $::RESULT all suffix
986 return $suffix
987 }
988 set loginRName [login_reset_suffix loginbob]
989 test login-resetpw-form {[string match "*Change Password for user <b>loginbob</b>*" \
 
990 [login_get /resetpw/$loginRName]]}
991 test login-resetpw-mismatch {[string match "*do not match*" \
992 [login_post /resetpw "name=$loginRName&n1=aaaaaa&n2=bbbbbb"]]}
993 test login-resetpw-changed {[string match "*Password changed successfully*" \
994 [login_post /resetpw "name=$loginRName&n1=resetpw1&n2=resetpw1"]]}
995 test_eq login-resetpw-works [login_who [login_basic loginbob:resetpw1]] loginbob
996
997 set loginBobUid [string trim [fossil sql \
998 "SELECT uid FROM user WHERE login='loginbob'"]]
999 set loginHash [string repeat 0 64]
1000 set loginNowHex [format %x [clock seconds]]
 
 
 
1001 foreach {loginRbName loginRbSuffix} [list \
1002 short 1-2-3 \
1003 no-uid [string repeat x 70] \
1004 no-time "1--$loginHash$loginHash" \
1005 uid-zero "0-$loginNowHex-$loginHash" \
1006 no-user "ffff-$loginNowHex-$loginHash" \
1007 expired "[format %x $loginBobUid]-1-$loginHash" \
1008 wrong-hash "[format %x $loginBobUid]-$loginNowHex-$loginHash" \
 
 
1009 ] {
1010 test login-resetpw-bad-$loginRbName {[string match "*URL is invalid*" \
1011 [login_get /resetpw/$loginRbSuffix]]}
 
 
 
 
 
 
 
1012 }
1013 foreach loginRrUser {loginsue nobody} {
1014 test login-resetpw-refused-$loginRrUser {[string match \
1015 "*Cannot change the password for user*" \
1016 [login_get /resetpw/[login_reset_suffix $loginRrUser]]]}
@@ -1033,11 +1097,11 @@
1033 set loginSess [login_session loginbob resetpw1]
1034 set loginReply [login_post /login \
1035 "p=resetpw1&n1=groupnew1&n2=groupnew1&csrf=[lindex $loginSess 1]" \
1036 [list "Cookie: [lindex $loginSess 0]"]]
1037 test login-group-pwchange-error {[string match "*ljunk.fossil: *" $loginReply]
1038 && ![string match "HTTP/1.0 302*" [login_status $loginReply]]}
1039 test_eq login-group-gone-dropped [string trim [fossil sql \
1040 "SELECT count(*) FROM config WHERE name GLOB 'peer-*-1111111111111111'"]] 0
1041 set loginRName [login_reset_suffix loginbob]
1042 test login-group-resetpw-error {[string match "*ljunk.fossil: *" \
1043 [login_post /resetpw "name=$loginRName&n1=groupnew2&n2=groupnew2"]]}
@@ -1069,12 +1133,14 @@
1069 set loginGoPair [login_cookie_pair $loginReply]
1070 test_eq login-group-transfer-anon \
1071 [login_who [login_get /test-env [list "Cookie: $loginGoPair"]]] anonymous
1072
1073 set loginWellFormed "$loginGrpCookie=[string repeat a 50]/x"
1074 set loginReply [login_get "/ityaar?$loginRobot" [list "Cookie: $loginWellFormed"]]
1075 test login-group-ityaar-keeps {[string match "HTTP/1.0 302*" [login_status $loginReply]]
 
 
1076 && ![string match "*%2Fanonymous*" $loginReply]}
1077 set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \
1078 [list "Cookie: $loginWellFormed"]]
1079 test login-group-ityaar-no-captcha \
1080 {![string match "*Prove that you are human*" $loginReply]}
@@ -1085,12 +1151,14 @@
1085 # does not exist or is not a database, a wrong number of arguments.
1086 foreach {loginLgName loginLgArgs loginLgWant} [list \
1087 self [list join $loginRepo] {*same as this one*} \
1088 missing [list join [file join [pwd] nosuch.fossil]] {*does not exist*} \
1089 junk [list join [file join [pwd] ljunk.fossil]] {*not a database*} \
1090 join-args [list join] {*unexpected argument count*} \
1091 leave-args [list leave extra] {*unknown extra arguments*} \
 
 
1092 ] {
1093 fossil_raw login-group {*}$loginLgArgs
1094 test login-group-err-$loginLgName {$CODE != 0
1095 && [string match $loginLgWant $RESULT]}
1096 }
@@ -1113,15 +1181,14 @@
1113 ###############################################################################
1114 # Pages that need a capability "nobody" lacks redirect to /login, naming
1115 # the page and its query string, and adding "anon=1" when "anonymous" has
1116 # the capability. With "redirect-to-https" set to 2 the redirect goes to
1117 # the https: address.
1118 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
1119 test_eq login-needed [login_header [login_get "/tktnew?x=1"] Location] \
1120 http://x/login?g=tktnew%3fx%3D1
1121 fossil sql "UPDATE user SET cap='hn' WHERE login='anonymous'"
1122 test_eq login-needed-anon [login_header [login_get /tktnew] Location] \
1123 http://x/login?g=tktnew&anon=1
1124 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
1125
1126 # A page that shows hyperlinks only with the Hyperlink capability offers an
1127 # anonymous login when "anonymous" has that capability.
@@ -1131,26 +1198,27 @@
1131
1132 # A page on the "robot-restrict" list asks a client without a login to
1133 # show that it is not a robot.
1134 login_config robot-restrict test-env
1135 set loginReply [login_get /test-env [list "User-Agent: Googlebot/2.1"]]
1136 test login-robot-restrict {[login_who $loginReply] eq "-"}
1137 login_config robot-restrict ""
1138 fossil sql "UPDATE user SET cap='' WHERE login='nobody'"
1139
1140 # With "redirect-to-https" set to 1, the redirect to /login for such a page
1141 # goes to the https: address.
1142 login_config redirect-to-https 1
1143 test_eq login-needed-https [login_header [login_get /tktnew] Location] \
1144 https://x/login?g=tktnew
1145 login_config redirect-to-https ""
1146
1147 # A login cookie in a repository that is in no login group does not keep
1148 # /ityaar from asking again after a wrong answer.
1149 set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \
1150 [list "Cookie: $loginCookieName=[string repeat a 50]/x"]]
1151 test login-ityaar-nogroup {[string match "*Prove that you are human*" $loginReply]}
 
1152
1153 # A sync request whose login card names a user with a NULL capability
1154 # column logs in with no capabilities: its pull is refused. The same
1155 # request for that user with Read capability is answered.
1156 fossil user new loginnocap [email protected] nocappw
@@ -1159,18 +1227,23 @@
1159 "SELECT value FROM config WHERE name='project-code'"]]
1160 set sc [string trim [fossil sql \
1161 "SELECT value FROM config WHERE name='server-code'"]]
1162 set pw [string trim [fossil sql "SELECT pw FROM user WHERE login='$user'"]]
1163 set tail "pull $sc $pc\n"
1164 set nonce [login_sha1 $tail]
1165 set sig [login_sha1 "$nonce$pw"]
1166 set body "login $user $nonce $sig\n$tail"
1167 return [login_send "POST /xfer HTTP/1.1\r\nHost: x\r\nContent-Type: application/x-fossil-uncompressed\r\nContent-Length: [string length $body]\r\n\r\n$body"]
 
 
 
 
1168 }
1169 fossil sql "UPDATE user SET cap=NULL WHERE login='loginnocap'"
1170 test login-xfer-null-cap \
1171 {[string first {not\sauthorized\sto\sread} [login_xfer_pull loginnocap]] >= 0}
 
1172 fossil sql "UPDATE user SET cap='o' WHERE login='loginnocap'"
1173 set loginReply [login_xfer_pull loginnocap]
1174 test login-xfer-read-cap {[string match "*igot *" $loginReply]
1175 && [string first {not\sauthorized} $loginReply] < 0}
1176
@@ -1190,17 +1263,19 @@
1190 login_config peer-repo-2222222222222222 [file join [pwd] lnoperm.fossil]
1191 set loginSess [login_session loginbob groupnew2]
1192 set loginReply [login_post /login \
1193 "p=groupnew2&n1=groupnew3&n2=groupnew3&csrf=[lindex $loginSess 1]" \
1194 [list "Cookie: [lindex $loginSess 0]"]]
1195 test login-group-noperm-member {[string match "*lnoperm.fossil: *" $loginReply]}
 
1196 login_config peer-repo-2222222222222222 ""
1197 fossil_raw login-group join [file join [pwd] lnoperm.fossil]
1198 test login-group-noperm-join {$CODE != 0
1199 && [string match "*unable to open*" $RESULT]}
1200 } else {
1201 test_skip_part "login-group-noperm-*: need a file the user running the tests cannot read"
 
1202 }
1203 file attributes lnoperm.fossil -permissions 0644
1204
1205 ###############################################################################
1206 # Pages that depend on the client. A request with a "Mobi" User-Agent is
@@ -1246,17 +1321,18 @@
1246 empty {} $loginHome \
1247 base http://x http://x \
1248 base-more http://xy $loginHome \
1249 other http://y/ $loginHome \
1250 ] {
1251 test_eq login-goto-$loginFgName [login_header [login_get \
1252 "/login?u=loginbob&p=bobfinal&fossil-goto=$loginFgTarget"] Location] \
1253 $loginFgWant
1254 }
1255
1256 # A GET with "out" does not log out.
1257 test login-logout-get {[string match "*Currently logged in as <b>loginbob</b>*" \
 
1258 [login_get "/login?out=1" [list "Cookie: $loginPair"]]]}
1259
1260 # A password change without the second copy of the new password, without
1261 # the first, or without the Anti-CSRF token changes nothing.
1262 foreach {loginPcName loginPcBody} [list \
@@ -1264,20 +1340,20 @@
1264 no-n1 "p=bobfinal&n2=changed1&csrf=$loginTok" \
1265 no-csrf "p=bobfinal&n1=changed1&n2=changed1" \
1266 ] {
1267 set loginReply [login_post /login $loginPcBody [list "Cookie: $loginPair"]]
1268 test login-pwchange-$loginPcName \
1269 {![string match "HTTP/1.0 302*" [login_status $loginReply]]
1270 && [login_who [login_basic loginbob:bobfinal]] eq "loginbob"}
1271 }
1272
1273 # A user name with no password, or an empty password, shows the form and
1274 # sets no cookie.
1275 foreach {loginNpName loginNpQuery} {no-p u=loginbob empty-p u=loginbob&p=} {
1276 set loginReply [login_get "/login?$loginNpQuery"]
1277 test login-form-$loginNpName {[login_status $loginReply] eq "HTTP/1.0 200 OK"
1278 && [login_header $loginReply Set-Cookie] eq "-"}
1279 }
1280
1281 # "g" with "noanon" does not name the page asked for.
1282 test login-page-goto-noanon {![string match "*access page*" \
1283 [login_get "/login?g=timeline&noanon=1"]]}
@@ -1312,21 +1388,24 @@
1312 [login_get /login [list "Cookie: $loginPair"]]]}
1313 fossil settings email-send-method dir
1314 fossil sql "UPDATE user SET cap='op' WHERE login='loginbob'"
1315
1316 # An anonymous login is not offered a password change.
1317 set loginAnonPair [login_cookie_pair [login_get "/login?$loginAnon" [list $loginUA]]]
 
1318 set loginReply [login_get /login [list "Cookie: $loginAnonPair" $loginUA]]
1319 test login-page-anonymous {[string match "*Currently logged in as <b>anonymous</b>*" $loginReply]
 
1320 && ![string match "*Change Password*" $loginReply]}
1321
1322 ###############################################################################
1323 # Further credential checks.
1324
1325 # "resid" without "token" logs no one in; "resid" naming a user with no
1326 # password does not match any token.
1327 test_eq login-resid-no-token [login_who [login_get "/test-env?resid=loginbob"]] nobody
 
1328 test_eq login-resid-no-pw \
1329 [login_who [login_get "/test-env?resid=nobody&token=x"]] nobody
1330
1331 # A user whose login name is empty is served with that user's capabilities
1332 # but without "L", the mark of a logged-in user.
@@ -1350,17 +1429,17 @@
1350 test login-httptrace-no-nobody {[string first {# login:} $RESULT] < 0}
1351
1352 # A request from 127.0.0.1 without --localauth, or over https: with it, is
1353 # not logged in. A request over the fossil ssh transport with --localauth
1354 # is, whatever the client's address.
1355 write_file lreq.txt "GET /test-env HTTP/1.1\r\nHost: x\r\n\r\n"
1356 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 127.0.0.1
1357 test_eq login-loopback-no-localauth [login_who [read_file lreply.txt]] nobody
1358 set ::env(REMOTE_HOST) 127.0.0.1
1359 test_eq login-local-https [login_who [login_local $loginRepo --https]] nobody
1360 unset ::env(REMOTE_HOST)
1361 write_file lreq.txt "GET /test-env HTTP/1.1\r\nHost: x\r\nX-Fossil-Transport: SSH\r\n\r\n"
 
1362 set ::env(SSH_CONNECTION) "9.9.9.9 5000 127.0.0.1 22"
1363 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --localauth
1364 unset ::env(SSH_CONNECTION)
1365 set loginReply [read_file lreply.txt]
1366 test login-local-ssh {[login_method $loginReply] eq "LOCAL"
@@ -1380,11 +1459,12 @@
1380
1381 # The offer of an anonymous login is not made when "anonymous" lacks the
1382 # Hyperlink capability or anonymous logins are off.
1383 fossil sql "UPDATE user SET cap='o' WHERE login='nobody'"
1384 fossil sql "UPDATE user SET cap='' WHERE login='anonymous'"
1385 test login-anonymous-available-nocap {![string match "*hyperlinks are disabled*" \
 
1386 [login_get /leaves [list $loginUA]]]}
1387 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
1388 login_config anon-cookie-lifespan 0
1389 test login-anonymous-available-off {![string match "*hyperlinks are disabled*" \
1390 [login_get /leaves [list $loginUA]]]}
@@ -1399,17 +1479,19 @@
1399 foreach loginRsName {nobody1 reader1 developer1} {
1400 test login-register-reserved-$loginRsName {[string match "*reserved*" \
1401 [login_register "u=$loginRsName&dn=R&[email protected]&p=longpw9&cp=longpw9"]]}
1402 }
1403 # A GET with "new" shows the form and creates no user.
1404 set loginReply [login_get "/register?$loginRegBase&u=getuser1&dn=G&[email protected]&p=longpw9&cp=longpw9"]
 
1405 test login-register-get {[string match {*name="captchaseed"*} $loginReply]
1406 && [login_user_cap getuser1] eq ""}
1407 # An "auth-sub-email" setting that is empty allows any address.
1408 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('auth-sub-email','',0)"
1409 test login-register-auth-empty {[string match "*Passwords do not match*" \
1410 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
 
1411 login_config auth-sub-email ""
1412
1413 login_config self-pw-reset 1
1414 # The address of the "nobody" user is refused even with the Password
1415 # capability.
@@ -1422,23 +1504,14 @@
1422 "captchaseed=$loginSeed&captcha=$loginCap&[email protected]"]
1423 test login-reqpw-no-flag {[string match {*name="reqpwreset"*} $loginReply]
1424 && ![string match "*has been sent*" $loginReply]}
1425
1426 ###############################################################################
1427 # Further /resetpw requests: a suffix whose first or second field ends in a
1428 # character other than "-", a POST with only one copy of the password, and
1429 # valid suffixes for a user with Admin capability and for "nobody" with the
1430 # Password capability.
1431
1432 set loginBadTail [string repeat 0 70]
1433 foreach {loginRb2Name loginRb2Suffix} [list \
1434 uid-end "1x$loginBadTail" \
1435 time-end "1-2x$loginBadTail" \
1436 ] {
1437 test login-resetpw-bad-$loginRb2Name {[string match "*URL is invalid*" \
1438 [login_get /resetpw/$loginRb2Suffix]]}
1439 }
1440 set loginRName [login_reset_suffix loginbob]
1441 test login-resetpw-one-copy {[string match "*Change Password for user*" \
1442 [login_post /resetpw "name=$loginRName&n1=changed1"]]}
1443 fossil sql "UPDATE user SET cap='a' WHERE login='verify3'"
1444 test login-resetpw-refused-admin {[string match \
@@ -1457,11 +1530,12 @@
1457 # hex digits, a slash and at least one more character.
1458
1459 login_config peer-repo-3333333333333333 [file join [pwd] ljunk.fossil]
1460 login_config peer-repo-4444444444444444 $loginRepo2
1461 set loginFakeHash [string repeat A 50]
1462 foreach {loginPeName loginPeCode} {junk 3333333333333333 nocookie 4444444444444444} {
 
1463 test_eq login-transfer-$loginPeName [login_who [login_get /test-env \
1464 [list "Cookie: $loginCookieName=$loginFakeHash/$loginPeCode/loginsue"]]] \
1465 nobody
1466 }
1467 login_config peer-repo-3333333333333333 ""
@@ -1482,40 +1556,40 @@
1482 }
1483 fossil login-group leave
1484
1485 # An empty login-group subcommand is unknown.
1486 fossil_raw login-group ""
1487 test login-group-err-empty {$CODE != 0 && [string match "*unknown command*" $RESULT]}
 
1488
1489 ###############################################################################
1490 # Further cases, each varying one input of a case above.
1491
1492 # An email address with a wrong password is refused.
1493 test login-form-email-badpw \
1494 {[string match "HTTP/1.0 401*" [login_status [login_form [email protected] wrongpw]]]}
1495
1496 # With "access-log" off, a login is not recorded.
1497 login_config access-log 0
1498 set loginLogCount [string trim [fossil sql "SELECT count(*) FROM accesslog"]]
1499 login_form loginbob bobfinal
1500 test_eq login-accesslog-off \
1501 [string trim [fossil sql "SELECT count(*) FROM accesslog"]] $loginLogCount
1502 login_config access-log ""
1503
1504 # A negative "anon-cookie-lifespan" turns anonymous logins off.
1505 login_config anon-cookie-lifespan -5
1506 set loginReply [login_get "/login?$loginAnon"]
1507 test login-anon-negative-lifespan \
1508 {[string match "HTTP/1.0 401*" [login_status $loginReply]]
1509 && [login_header $loginReply Set-Cookie] eq "-"}
1510 login_config anon-cookie-lifespan ""
 
 
1511
1512 # Login cookies that name the special users "developer" and "reader" are
1513 # not accepted.
1514 foreach loginSpUser {developer reader} {
1515 test_eq login-cookie-special-$loginSpUser [login_who [login_get /test-env \
1516 [list "Cookie: $loginCookieName=[string repeat A 50]/0123456789abcdef/$loginSpUser"]]] \
 
1517 nobody
1518 }
1519
1520 # The forum capabilities 5 and 4 grant those below them; "u" or "v" given
1521 # twice inherits once.
1522
--- test/login.test
+++ test/login.test
@@ -5,13 +5,17 @@
5 # test/cgi.test does. The /test-env page reports g.zLogin, g.isRobot and the
6 # capabilities the server granted. Several command-line test entry points in
7 # login.c are exercised directly.
8 #
9
10 # Fossil sleeps for a second before it refuses a wrong password or a bad
11 # password-reset link. Requests that are refused that way are sent
12 # together with login_send_all, so that they wait at the same time, and
13 # are left out at -assurance smoke.
14 set loginWaits [expr {[test_assurance] ne "smoke"}]
15 if {!$loginWaits} {
16 test_skip_part "the logins that Fossil delays need -assurance ci or stress"
17 }
18
19 require_no_open_checkout
20
21 test_setup
@@ -30,51 +34,53 @@
34 VALUES('test_env_enable','1',0)"
35
36 # Send TEXT (a byte string) to the server and return the whole reply. ARGS are
37 # extra "fossil http" options.
38 proc login_send {text args} {
39 return [fossil_http $::loginRepo $text --ipaddr 9.9.9.9 {*}$args]
40 }
41
42 # Send each request in TEXTS to a server of its own, all at the same
43 # time, and return the list of replies in the same order.
44 proc login_send_all {texts} {
45 global fossilexe loginRepo
46 set servers {}
47 foreach text $texts {
48 set n [llength $servers]
49 write_file lreq$n.txt $text
50 file delete lreply$n.txt
51 lappend servers [open |[list $fossilexe http $loginRepo --in lreq$n.txt \
52 --out lreply$n.txt --ipaddr 9.9.9.9]]
53 }
54 set replies {}
55 foreach server $servers {
56 set n [llength $replies]
57 catch {close $server}
58 if {[file exists lreply$n.txt]} {
59 lappend replies [read_file lreply$n.txt]
60 } else {
61 lappend replies ""
62 }
63 }
64 return $replies
65 }
66
67 # A GET request for PATH carrying the header lines in HEADERS, a list.
68 proc login_get {path {headers {}}} {
69 return [login_send [request_get $path $headers]]
70 }
71
72 # The text of a POST of url-encoded BODY to PATH, with a Referer matching
73 # the base URL so that the same-origin CSRF check passes.
74 proc login_post_text {path body {headers {}}} {
75 return [request_post $path $body \
76 [list "Referer: http://x/login" {*}$headers]]
77 }
78
79 # A POST of url-encoded BODY to PATH.
 
80 proc login_post {path body {headers {}}} {
81 return [login_send [login_post_text $path $body $headers]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82 }
83
84 # The login name that /test-env reports for a reply. The server writes an
85 # empty value for the "nobody" user, so report that as "nobody".
86 proc login_who {reply} {
@@ -98,18 +104,21 @@
104 # through to the "nobody" user.
105
106 fossil sql "REPLACE INTO config(name,value,mtime)
107 VALUES('http_authentication_ok','1',0)"
108 proc login_basic {creds} {
109 return [login_get /test-env \
110 [list "Authorization: Basic [binary encode base64 $creds]"]]
111 }
112
113 test_eq login-basic-good [login_who [login_basic loginbob:bobpw]] loginbob
114 test login-basic-good-caps \
115 {[string match "*i*" [login_caps [login_basic loginbob:bobpw]]]}
116
117 set loginReply [login_basic loginbob:wrongpw]
118 test login-basic-badpw {[string match "HTTP/1.0 401*" \
119 [reply_status $loginReply]]}
120
121 # A value with no colon names no password: the request is served as "nobody".
122 test_eq login-basic-nocolon [login_who [login_basic nocolonhere]] nobody
123
124 # Header that does not begin with "Basic " is ignored.
@@ -150,51 +159,54 @@
159
160 proc login_form {user pw {extra ""}} {
161 return [login_post /login "u=$user&p=$pw&in=Login&$extra"]
162 }
163 set loginReply [login_form loginbob bobpw]
164 test login-form-status {[string match "HTTP/1.0 302*" \
165 [reply_status $loginReply]]}
166 set loginCookie [reply_header $loginReply Set-Cookie]
167 test login-form-cookie {[string match "fossil-*=*loginbob;*HttpOnly;*" \
168 $loginCookie]}
169 regexp {(fossil-[0-9a-f]+=[^;]+)} $loginCookie all loginCookiePair
170 test_eq login-cookie-reuse \
171 [login_who [login_get /test-env [list "Cookie: $loginCookiePair"]]] loginbob
172
173 # An email address with a wrong password is refused too.
174 if {$loginWaits} {
175 lassign [login_send_all [list \
176 [login_post_text /login "u=loginbob&p=nope&in=Login&"] \
177 [login_post_text /login "[email protected]&p=wrongpw&in=Login&"]]] \
178 loginReply loginEmailReply
179 test login-form-badpw \
180 {[string match "HTTP/1.0 401*" [reply_status $loginReply]]}
181 test_eq login-form-badpw-nocookie [reply_header $loginReply Set-Cookie] "-"
182 test login-form-email-badpw \
183 {[string match "HTTP/1.0 401*" [reply_status $loginEmailReply]]}
184 }
185
186 ###############################################################################
187 # The "g" goto parameter is always rendered relative to the repository root:
188 # an absolute URL given in "g" is prefixed and so cannot leave the site.
189
190 set loginReply [login_form loginbob bobpw "g=/doc/trunk/x"]
191 test_eq login-goto-relative [reply_header $loginReply Location] \
192 http://x//doc/trunk/x
193
194 ###############################################################################
195 # Logout. A logged-in user who POSTs "out" with a matching Referer and the
196 # Anti-CSRF token from the form has the login cookie cleared (an empty value
197 # with a past expiry).
198
199 set loginReply [login_form loginbob bobpw]
200 regexp {(fossil-[0-9a-f]+=[^;]+)} [reply_header $loginReply Set-Cookie] \
201 all loginLogoutPair
202 set loginReply [login_get /login [list "Cookie: $loginLogoutPair"]]
203 regexp {name="csrf" value="([^"]+)"} $loginReply all loginCsrf
204 set loginReply [login_post /login "out=Logout&csrf=$loginCsrf" \
205 [list "Cookie: $loginLogoutPair"]]
206 test login-logout-clears \
207 {[string match "fossil-*=; *" [reply_header $loginReply Set-Cookie]]}
208
209 ###############################################################################
210 # Robot detection. With no login, g.isRobot is set from the User-Agent: a
211 # self-identified bot is a robot, a current browser is not.
212
@@ -205,11 +217,12 @@
217 }
218 test_eq login-robot-bot [login_isrobot "Googlebot/2.1"] 1
219 test_eq login-robot-browser [login_isrobot "Mozilla/5.0 Firefox/122.0"] 0
220 test_eq login-robot-noagent [login_isrobot ""] 1
221 # The "isrobot" query parameter forces the robot flag on.
222 set loginReply [login_get "/test-env?isrobot=1" \
223 {"User-Agent: Mozilla/5.0 Firefox/122.0"}]
224 test login-robot-forced {[regexp {g\.isRobot = 1<br>} $loginReply]}
225
226 ###############################################################################
227 # test-ishuman labels User-Agent strings read from standard input.
228
@@ -236,29 +249,31 @@
249
250 ###############################################################################
251 # test-email-used reports which user owns an email address.
252
253 fossil test-email-used [email protected] [email protected]
254 test login-email-used-known \
255 {[string match "*[email protected]: UID*loginbob*" $::RESULT]}
256 test login-email-used-unknown \
257 {[string match "*[email protected]: not used*" $::RESULT]}
258
259 ###############################################################################
260 # Login groups. Two repositories are joined into a group, the membership is
261 # shown, then one leaves.
262
263 set loginRepo2 [file join [pwd] grp2.fossil]
264 fossil new $loginRepo2
 
265 fossil sql -R $loginRepo2 \
266 "INSERT INTO user(login,pw,cap) VALUES('loginsue','suepw','s')"
267
268 test login-group-none-start \
269 {![catch {fossil login-group} m] && [string match "*Not currently*" \
270 $::RESULT]}
271 fossil login-group join --name loggrp $loginRepo2
272 fossil login-group
273 test login-group-joined {[string match "*login-group \"loggrp\"*grp2.fossil*" \
274 $::RESULT]}
275 test_eq login-group-name-fn [string trim [fossil sql \
276 "SELECT value FROM config WHERE name='login-group-name'"]] loggrp
277 fossil login-group leave
278 fossil login-group
279 test login-group-left {[string match "*Not currently*" $::RESULT]}
@@ -280,11 +295,11 @@
295 VALUES('http_authentication_ok','1',0)"
296
297 # Log in as loginbob and return a two-element list {cookie-pair csrf-token}.
298 proc login_session {user pw} {
299 set reply [login_form $user $pw]
300 regexp {(fossil-[0-9a-f]+=[^;]+)} [reply_header $reply Set-Cookie] all pair
301 set reply [login_get /login [list "Cookie: $pair"]]
302 regexp {name="csrf" value="([^"]+)"} $reply all tok
303 return [list $pair $tok]
304 }
305
@@ -291,24 +306,30 @@
306 set loginSess [login_session loginbob bobpw]
307 set loginPair [lindex $loginSess 0]
308 set loginTok [lindex $loginSess 1]
309
310 set loginReply [login_post /login \
311 "p=bobpw&n1=newbobpw&n2=newbobpw&csrf=$loginTok" \
312 [list "Cookie: $loginPair"]]
313 test login-pwchange-ok {[string match "HTTP/1.0 302*" \
314 [reply_status $loginReply]]}
315 test_eq login-pwchange-newpw-works \
316 [login_who [login_basic loginbob:newbobpw]] loginbob
317 test login-pwchange-oldpw-fails \
318 {[string match "HTTP/1.0 401*" [reply_status [login_basic loginbob:bobpw]]]}
319
320 set loginReply [login_post /login \
321 "p=newbobpw&n1=aaaaaa&n2=bbbbbb&csrf=$loginTok" [list "Cookie: $loginPair"]]
322 test login-pwchange-mismatch {[string match "*do not match*" $loginReply]}
323
324 if {$loginWaits} {
325 set loginReply [login_post /login \
326 "p=totallywrong&n1=cccccc&n2=cccccc&csrf=$loginTok" \
327 [list "Cookie: $loginPair"]]
328 test login-pwchange-badold \
329 {[string match "*incorrect old password*" $loginReply]}
330 }
331
332 ###############################################################################
333 # Self-registration through /register. The captcha answer is derived the same
334 # way the server derives it: the first 8 hex digits of sha1("SECRET-SEEDHEX").
335 # A complete, valid form creates the account; each validation rule rejects the
@@ -333,22 +354,26 @@
354 }
355 set loginRegTok [login_register_tokens]
356 set loginSeed [lindex $loginRegTok 0]
357 set loginCap [lindex $loginRegTok 1]
358 set loginRCsrf [lindex $loginRegTok 2]
359 set loginRegBase \
360 "new=1&captchaseed=$loginSeed&captcha=$loginCap&csrf=$loginRCsrf"
361
362 # POST a registration form whose user-supplied fields are FIELDS.
363 proc login_register {fields} {
364 global loginRegBase
365 return [login_post /register "$loginRegBase&$fields"]
366 }
367
368 set loginReply [login_register \
369 "u=realuser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]
370 test login-register-ok {[string match "HTTP/1.0 302*" \
371 [reply_status $loginReply]]}
372 test_eq login-register-created \
373 [string trim [fossil sql "SELECT login FROM user WHERE login='realuser'"]] \
374 "realuser"
375
376 test login-register-short-uid \
377 {[string match "*User ID too short*" [login_register \
378 "u=abc&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
379 test login-register-reserved \
@@ -381,11 +406,12 @@
406 # including the recursive inheritance of "reader" (u) and "developer" (v).
407
408 fossil sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')"
409 fossil sql "UPDATE user SET cap='j' WHERE login='reader'"
410 fossil sql "UPDATE user SET cap='b' WHERE login='developer'"
411 fossil sql \
412 "REPLACE INTO config(name,value,mtime) VALUES('auto-hyperlink','0',0)"
413 proc login_capexpand {cap} {
414 fossil sql "UPDATE user SET cap='$cap' WHERE login='loginbob'"
415 return [login_caps [login_basic loginbob:newbobpw]]
416 }
417 test_eq login-cap-wiki [login_capexpand kv] bjkmL
@@ -416,11 +442,12 @@
442 ###############################################################################
443 # Capability expansion for the privilege letters that grant many flags at once:
444 # "s" (Setup) unlocks everything, and the forum digits accumulate.
445 set loginSetupCaps [login_capexpand s]
446 test login-cap-setup {[string match "*a*" $loginSetupCaps]
447 && [string match "*s*" $loginSetupCaps] && [string match "*D*" \
448 $loginSetupCaps]}
449 test_eq login-cap-forum6 [login_capexpand 6] 23456L
450 test_eq login-cap-forum3 [login_capexpand 3] 23L
451
452 ###############################################################################
453 # Login cookies that are not of the form HASH/ARG/USER, or that name a user
@@ -432,17 +459,19 @@
459 slash /
460 end-slash abcdef/
461 two-parts a/b/
462 no-slash abcdef
463 empty {}
464 wrong-hash
465 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/loginbob
466 special-user
467 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF01/0123456789abcdef/nobody
468 } {
469 set loginReply [login_get /test-env \
470 [list "Cookie: $loginCookieName=$loginCkValue"]]
471 test login-cookie-bad-$loginCkName {$CODE == 0
472 && [reply_status $loginReply] eq "HTTP/1.0 200 OK"
473 && [login_who $loginReply] eq "nobody"}
474 }
475
476 ###############################################################################
477 # Where a login goes afterwards when the request carries "fossil-goto", as a
@@ -450,11 +479,11 @@
479 # site, and to the home page if it is anywhere else. A value that is not an
480 # absolute http: or https: address, such as "timeline" or "//evil.example/",
481 # is taken as a page of this site. The same holds for an
482 # anonymous login and for the answer to the robot captcha at /ityaar.
483
484 set loginHome [reply_header [login_form loginbob newbobpw] Location]
485 test login-goto-home {[string match "http://x/*" $loginHome]}
486 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
487 set loginAnon "u=anonymous&p=$loginCap&cs=$loginSeed"
488 set loginRobot "captchaseed=$loginSeed&captcha=$loginCap"
489
@@ -465,40 +494,42 @@
494 relative timeline http://x/timeline \
495 same-site http://x/timeline http://x/timeline \
496 ] {
497 set loginReply [login_get \
498 "/login?u=loginbob&p=newbobpw&fossil-goto=$loginGoTarget"]
499 test_eq login-goto-query-$loginGoName [reply_header $loginReply Location] \
500 $loginGoWant
501 set loginReply [login_form loginbob newbobpw "fossil-goto=$loginGoTarget"]
502 test_eq login-goto-form-$loginGoName [reply_header $loginReply Location] \
503 $loginGoWant
504 set loginReply [login_post /login "u=loginbob&p=newbobpw&in=Login" \
505 [list "Cookie: fossil-goto=$loginGoTarget"]]
506 test_eq login-goto-cookie-$loginGoName [reply_header $loginReply Location] \
507 $loginGoWant
508 set loginReply [login_get "/login?$loginAnon&fossil-goto=$loginGoTarget"]
509 test login-goto-anonymous-$loginGoName \
510 {[string match "*anonymous*" [reply_header $loginReply Set-Cookie]]
511 && [reply_header $loginReply Location] eq $loginGoWant}
512 set loginReply [login_get "/ityaar?$loginRobot&fossil-goto=$loginGoTarget"]
513 test_eq login-goto-ityaar-$loginGoName [reply_header $loginReply Location] \
514 $loginGoWant
515 }
516
517 # The captcha page at /honeypot remembers the address asked for in a
518 # "fossil-goto" cookie, and a right answer sent with that cookie goes there.
519 set loginReply [login_get /honeypot?x=1]
520 test login-honeypot-cookie {[string match "*X-Robot: 1*" $loginReply]
521 && [string match "*Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot*" \
522 $loginReply]}
523 set loginReply [login_get "/ityaar?$loginRobot" \
524 {"Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fx%3D1"}]
525 test_eq login-honeypot-return [reply_header $loginReply Location] \
526 http://x/honeypot?x=1
527 # A wrong answer shows the captcha again.
528 set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz"]
529 test login-ityaar-wrong {[string match "*Prove that you are human*" \
530 $loginReply]}
531
532 ###############################################################################
533 # Helpers for the cases below.
534
535 # A GET or POST to the repository REPO instead of the main one.
@@ -533,25 +564,18 @@
564 return $m
565 }
566 return -
567 }
568
 
 
 
 
 
 
 
 
569
570 # Set the repository setting NAME to VALUE, or remove it when VALUE is "".
571 proc login_config {name value} {
572 if {$value eq ""} {
573 fossil sql "DELETE FROM config WHERE name='$name'"
574 } else {
575 fossil sql \
576 "REPLACE INTO config(name,value,mtime) VALUES('$name','$value',0)"
577 }
578 }
579
580 ###############################################################################
581 # The capability letters not shown above each grant their own capability.
@@ -593,11 +617,11 @@
617 ###############################################################################
618 # With no user named "nobody", a request without credentials is served as
619 # user id -1 with no capabilities.
620 fossil sql "UPDATE user SET login='nobody-saved' WHERE login='nobody'"
621 set loginReply [login_get /test-env]
622 test login-no-nobody {[reply_status $loginReply] eq "HTTP/1.0 200 OK"
623 && [string match "*g.userUid = -1<br>*" $loginReply]
624 && [login_caps $loginReply] eq ""}
625 fossil sql "UPDATE user SET login='nobody' WHERE login='nobody-saved'"
626
627 ###############################################################################
@@ -654,11 +678,15 @@
678 fossil unset localauth
679
680 ###############################################################################
681 # With --httptrace, the login and its capability string are written to
682 # standard error.
683 write_file lreq.txt \
684 [join [list \
685 "GET /test-env HTTP/1.1\r\nHost: x\r\n" \
686 "Authorization: Basic " \
687 "[binary encode base64 loginbob:newbobpw]\r\n\r\n"] ""]
688 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 9.9.9.9 \
689 --httptrace
690 test login-httptrace \
691 {[string first {# login: [loginbob] with capabilities [o]} $RESULT] >= 0}
692
@@ -673,50 +701,59 @@
701 set loginUA "User-Agent: $loginUAText"
702 set loginReply [login_get "/login?$loginAnon" [list $loginUA]]
703 set loginAnonPair [login_cookie_pair $loginReply]
704 test login-anon-cookie {[string match "fossil-*=*%2Fanonymous" $loginAnonPair]}
705 test login-anon-cookie-session \
706 {![string match "*max-age=*" [reply_header $loginReply Set-Cookie]]}
707 set loginReply [login_get /test-env [list "Cookie: $loginAnonPair" $loginUA]]
708 test login-anon-cookie-reuse {[login_who $loginReply] eq "anonymous"
709 && [login_method $loginReply] eq "COOKIE"}
710 test_eq login-anon-cookie-other-agent [login_who [login_get /test-env \
711 [list "Cookie: $loginAnonPair" "User-Agent: Mozilla/5.0 Chrome/120.0"]]] \
712 nobody
713 set loginReply [login_get "/login?$loginAnon&remember=1"]
714 test login-anon-cookie-persistent \
715 {[string match "*%2Fanonymous;*max-age=*" \
716 [reply_header $loginReply Set-Cookie]]}
717
718 set loginSecret [string trim [fossil sql \
719 "SELECT value FROM config WHERE name='captcha-secret'"]]
720 fossil sql "REPLACE INTO config(name,value,mtime)
721 VALUES('captcha-secret-1','oldsecret',unixepoch())"
722 set loginNow [string trim [fossil sql "SELECT julianday('now')"]]
723 set loginOldHash [sha1_text "$loginNow/$loginUAText/oldsecret"]
724 test_eq login-anon-cookie-old-secret [login_who [login_get /test-env \
725 [list "Cookie: $loginCookieName=$loginOldHash/$loginNow/anonymous" \
726 $loginUA]]] \
727 anonymous
728 set loginStaleHash [sha1_text "2400000.5/$loginUAText/$loginSecret"]
729 test_eq login-anon-cookie-expired [login_who [login_get /test-env \
730 [list "Cookie: $loginCookieName=$loginStaleHash/2400000.5/anonymous" \
731 $loginUA]]] \
732 nobody
733 set loginOldPw [string range \
734 [sha1_text "oldsecret-[format %x $loginSeed]"] 0 7]
735 set loginReply [login_get "/login?u=anonymous&p=$loginOldPw&cs=$loginSeed"]
736 test login-anon-old-secret \
737 {[string match "*%2Fanonymous*" [reply_header $loginReply Set-Cookie]]}
738 if {$loginWaits} {
739 set loginReply [login_get "/login?u=anonymous&p=00000000&cs=$loginSeed"]
740 test login-anon-wrong {
741 [string match "HTTP/1.0 401*" [reply_status $loginReply]]
742 && [reply_header $loginReply Set-Cookie] eq "-"}
743 }
744 fossil sql "DELETE FROM config WHERE name='captcha-secret-1'"
745
746 login_config anon-cookie-lifespan 0
747 test_eq login-anon-cookie-off [login_who [login_get /test-env \
748 [list "Cookie: $loginAnonPair" $loginUA]]] nobody
749 if {$loginWaits} {
750 set loginReply [login_get "/login?$loginAnon"]
751 test login-anon-login-off {
752 [string match "HTTP/1.0 401*" [reply_status $loginReply]]
753 && [reply_header $loginReply Set-Cookie] eq "-"}
754 }
755 login_config anon-cookie-lifespan ""
756
757 ###############################################################################
758 # The /login page. "anon=1" with "g" asks only for the captcha for an
759 # anonymous login; "g" alone names the page asked for, without its query
@@ -728,47 +765,50 @@
765 test login-page-anon {[string match {*name="anon" value="1"*} $loginReply]
766 && [string match "*Verify that you are human*" $loginReply]
767 && [string match "*Verify that I am human*" $loginReply]}
768 set loginReply [login_get "/login?g=timeline%3fn=5"]
769 test login-page-goto \
770 {[string match "*Login as a named user to access page <b>timeline</b>*" \
771 $loginReply]}
772 set loginSess [login_session loginbob newbobpw]
773 set loginPair [lindex $loginSess 0]
774 set loginReply [login_get "/login?g=timeline" [list "Cookie: $loginPair"]]
775 test login-page-goto-loggedin {[string match \
776 "*greater privilege than <b>loginbob</b>*to access <b>timeline</b>*" \
777 $loginReply]}
778 set loginReply [login_get "/login?anon=2" [list "Cookie: $loginPair"]]
779 test login-page-anon2 {![string match "*Currently logged in*" $loginReply]
780 && [string match "*Verify that I am human*" $loginReply]}
781 set loginReply [login_get /login]
782 test login-page-visitors {[string match "*Visitors may enter*" $loginReply]
783 && [string match "*Create A New Account*" $loginReply]}
784 test login-page-noanon \
785 {![string match "*Visitors may enter*" [login_get "/login?noanon=1"]]}
786 test_eq login-page-self [reply_header [login_get "/login?self=1"] Location] \
787 http://x/register
788
789 # A logout sent with "anon=2", which skips the login check, redirects and
790 # clears no cookie.
791 set loginReply [login_post /login "anon=2&out=Logout&csrf="]
792 test login-logout-anon2 {[string match "HTTP/1.0 302*" \
793 [reply_status $loginReply]]
794 && [reply_header $loginReply Set-Cookie] eq "-"}
795
796 # With "https-login" on, the login form is sent to the https: address of
797 # the site, unless the server is run with --nossl.
798 login_config https-login 1
799 test login-page-https \
800 {[string match "*data-action='https://x/login'*" [login_get /login]]}
801 set loginReply [login_send "GET /login HTTP/1.1\r\nHost: x\r\n\r\n" --nossl]
 
802 test login-page-nossl {![string match "*'https://x/login'*" $loginReply]}
803 login_config https-login ""
804
805 # With "auto-captcha" on, the page offers a button that fills in the
806 # anonymous password.
807 login_config auto-captcha 1
808 test login-page-autocaptcha \
809 {[string match "*Fill out captcha*" [login_get /login]]}
810 login_config auto-captcha ""
811
812 # "nobody" with the Password capability is refused a password change.
813 fossil sql "UPDATE user SET cap='p' WHERE login='nobody'"
814 regexp {name="csrf" value="([^"]+)"} [login_get /login] all loginNbCsrf
@@ -787,18 +827,21 @@
827 [login_register "u=bad+user1&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
828 test login-register-no-email {[regexp {Email Address:.*Required} \
829 [login_register "u=gooduser&dn=Real&ea=&p=longpw9&cp=longpw9"]]}
830 login_config auth-sub-email *@ok.example
831 test login-register-unauthorized {[string match "*Not an authorized email*" \
832 [login_register \
833 "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
834 test login-register-authorized {[string match "*Passwords do not match*" \
835 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
836 login_config auth-sub-email ""
837 test login-register-email-used \
838 {[string match "*already associated with a user*" \
839 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
840 test login-register-goto \
841 {[string match {*name="g" value="timeline"*} \
842 [login_get "/register?g=timeline"]]}
843 login_config self-register ""
844 test login-register-off \
845 {[string match "*Registration not possible*" [login_get /register]]}
846 login_config self-register 1
847
@@ -837,11 +880,12 @@
880 }
881 proc login_ssub {email} {
882 return [string trim [fossil sql \
883 "SELECT ssub FROM subscriber WHERE semail='$email'"]]
884 }
885 set loginReply [login_register \
886 "u=verify1&dn=V&[email protected]&p=longpw9&cp=longpw9"]
887 test login-register-verify-noself {[string match "*Internal Error*" $loginReply]
888 && [login_user_cap verify1] eq "7" && [login_ssub [email protected]] eq "aw"}
889 fossil settings email-self [email protected]
890 login_config default-perms o2rj
891 set loginReply [login_register \
@@ -852,17 +896,20 @@
896 && [login_mail_count] == 1 && [login_ssub [email protected]] eq "acftw"}
897 login_config default-perms u
898 # With alerts=0 there is no subscription and no email.
899 set loginReply [login_register \
900 "u=verify3&dn=V&[email protected]&p=longpw9&cp=longpw9&alerts=0"]
901 test login-register-noalerts \
902 {[string match "HTTP/1.0 302*" [reply_status $loginReply]]
903 && [login_ssub [email protected]] eq "" && [login_mail_count] == 1}
904 # An address that is already a verified subscriber needs no verification.
905 fossil sql "INSERT INTO subscriber(semail,sverified,sdonotcall,sdigest,ssub)
906 VALUES('[email protected]',1,0,0,'a')"
907 set loginReply [login_register \
908 "u=verify4&dn=V&[email protected]&p=longpw9&cp=longpw9"]
909 test login-register-verified \
910 {[string match "HTTP/1.0 302*" [reply_status $loginReply]]
911 && [string trim [fossil sql \
912 "SELECT suname FROM subscriber WHERE semail='[email protected]'"]] eq "verify4"
913 && [login_mail_count] == 1}
914 login_config selfreg-verify ""
915
@@ -887,11 +934,12 @@
934 # user. Both test commands need an argument.
935
936 fossil sql "UPDATE user SET info='Sue <[email protected]>' WHERE login='loginsue'"
937 fossil sql "UPDATE user SET info='Ann <[email protected]> <[email protected]>'
938 WHERE login='verify3'"
939 fossil sql \
940 "INSERT INTO subscriber(semail,suname,sverified,sdonotcall,sdigest,ssub)
941 VALUES('[email protected]','verify2',1,0,0,'a'),
942 ('[email protected]','loginsue',1,0,0,'a'),
943 ('[email protected]','verify2',0,0,0,'a')"
944 fossil test-email-used [email protected] [email protected] [email protected] [email protected] \
945 [email protected]
@@ -921,13 +969,15 @@
969 {[string match "*does not allow users to reset*" [login_get /reqpwreset]]}
970 login_config self-pw-reset 1
971 test login-reqpw-form \
972 {[string match {*name="reqpwreset" value="1"*} [login_get /reqpwreset]]}
973 test login-reqpw-from-login \
974 {[string match {*name="reqpwreset" value="1"*} \
975 [login_get "/login?pwreset=1"]]}
976 test login-reqpw-from-register \
977 {[string match {*name="reqpwreset" value="1"*} \
978 [login_get "/register?pwreset=1"]]}
979 test login-page-reset-button \
980 {[string match "*Reset My Password*" [login_get /login]]}
981 test login-register-reset-button {[string match "*Request Password Reset For*" \
982 [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]}
983
@@ -935,11 +985,12 @@
985 global loginSeed loginCap
986 return [login_post /reqpwreset \
987 "reqpwreset=1&captchaseed=$loginSeed&captcha=$loginCap&$fields"]
988 }
989 test login-reqpw-badcaptcha {[string match "*Incorrect CAPTCHA*" [login_post \
990 /reqpwreset \
991 "reqpwreset=1&captchaseed=$loginSeed&captcha=00000000&[email protected]"]]}
992 fossil sql "UPDATE user SET cap='vp' WHERE login='loginbob'"
993 fossil sql "UPDATE user SET cap='a' WHERE login='developer'"
994 foreach {loginRqName loginRqAddr loginRqWant} {
995 empty {} {*Required*}
996 invalid notmail {*Not a valid email*}
@@ -964,20 +1015,22 @@
1015 fossil unset email-self
1016 test login-reqpw-noself \
1017 {[string match "*Internal Error*" [login_reqpw [email protected]]]}
1018 fossil settings email-self [email protected]
1019 set loginReply [login_reqpw [email protected]]
1020 test login-reqpw-sent {[string match {*has been sent to "[email protected]"*} \
1021 $loginReply]
1022 && [login_mail_count] == 1}
1023 set loginMail [read_file [lindex [glob -directory lmail *] 0]]
1024 test login-reqpw-mail {[string match "*To: <[email protected]>*" $loginMail]
1025 && [string match "*Password reset for http://x*" $loginMail]}
1026
1027 ###############################################################################
1028 # /resetpw/UID-TIMESTAMP-HASH. A valid suffix gives a form that sets the
1029 # user's password. A suffix that is malformed, names no user, is more than
1030 # an hour old or has the wrong hash is refused, and so is a suffix whose
1031 # first or second field ends in a character other than "-", and a valid suffix
1032 # for "nobody", for a user with Setup capability or for a user without the
1033 # Password capability.
1034
1035 proc login_reset_suffix {login} {
1036 set uid [string trim [fossil sql "SELECT uid FROM user WHERE login='$login'"]]
@@ -984,33 +1037,44 @@
1037 fossil test-resetpw-url $uid
1038 regexp {/resetpw/([0-9a-f-]+)} $::RESULT all suffix
1039 return $suffix
1040 }
1041 set loginRName [login_reset_suffix loginbob]
1042 test login-resetpw-form {[string match \
1043 "*Change Password for user <b>loginbob</b>*" \
1044 [login_get /resetpw/$loginRName]]}
1045 test login-resetpw-mismatch {[string match "*do not match*" \
1046 [login_post /resetpw "name=$loginRName&n1=aaaaaa&n2=bbbbbb"]]}
1047 test login-resetpw-changed {[string match "*Password changed successfully*" \
1048 [login_post /resetpw "name=$loginRName&n1=resetpw1&n2=resetpw1"]]}
1049 test_eq login-resetpw-works [login_who [login_basic loginbob:resetpw1]] loginbob
1050
 
 
1051 set loginHash [string repeat 0 64]
1052 set loginNowHex [format %x [clock seconds]]
1053 set loginBadTail [string repeat 0 70]
1054 set loginRbNames {}
1055 set loginRbRequests {}
1056 foreach {loginRbName loginRbSuffix} [list \
1057 short 1-2-3 \
1058 no-uid [string repeat x 70] \
1059 no-time "1--$loginHash$loginHash" \
1060 uid-zero "0-$loginNowHex-$loginHash" \
1061 no-user "ffff-$loginNowHex-$loginHash" \
1062 expired "[format %x $loginUid]-1-$loginHash" \
1063 wrong-hash "[format %x $loginUid]-$loginNowHex-$loginHash" \
1064 uid-end "1x$loginBadTail" \
1065 time-end "1-2x$loginBadTail" \
1066 ] {
1067 lappend loginRbNames $loginRbName
1068 lappend loginRbRequests [request_get /resetpw/$loginRbSuffix]
1069 }
1070 if {$loginWaits} {
1071 foreach loginRbName $loginRbNames \
1072 loginReply [login_send_all $loginRbRequests] {
1073 test login-resetpw-bad-$loginRbName \
1074 {[string match "*URL is invalid*" $loginReply]}
1075 }
1076 }
1077 foreach loginRrUser {loginsue nobody} {
1078 test login-resetpw-refused-$loginRrUser {[string match \
1079 "*Cannot change the password for user*" \
1080 [login_get /resetpw/[login_reset_suffix $loginRrUser]]]}
@@ -1033,11 +1097,11 @@
1097 set loginSess [login_session loginbob resetpw1]
1098 set loginReply [login_post /login \
1099 "p=resetpw1&n1=groupnew1&n2=groupnew1&csrf=[lindex $loginSess 1]" \
1100 [list "Cookie: [lindex $loginSess 0]"]]
1101 test login-group-pwchange-error {[string match "*ljunk.fossil: *" $loginReply]
1102 && ![string match "HTTP/1.0 302*" [reply_status $loginReply]]}
1103 test_eq login-group-gone-dropped [string trim [fossil sql \
1104 "SELECT count(*) FROM config WHERE name GLOB 'peer-*-1111111111111111'"]] 0
1105 set loginRName [login_reset_suffix loginbob]
1106 test login-group-resetpw-error {[string match "*ljunk.fossil: *" \
1107 [login_post /resetpw "name=$loginRName&n1=groupnew2&n2=groupnew2"]]}
@@ -1069,12 +1133,14 @@
1133 set loginGoPair [login_cookie_pair $loginReply]
1134 test_eq login-group-transfer-anon \
1135 [login_who [login_get /test-env [list "Cookie: $loginGoPair"]]] anonymous
1136
1137 set loginWellFormed "$loginGrpCookie=[string repeat a 50]/x"
1138 set loginReply [login_get "/ityaar?$loginRobot" \
1139 [list "Cookie: $loginWellFormed"]]
1140 test login-group-ityaar-keeps \
1141 {[string match "HTTP/1.0 302*" [reply_status $loginReply]]
1142 && ![string match "*%2Fanonymous*" $loginReply]}
1143 set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \
1144 [list "Cookie: $loginWellFormed"]]
1145 test login-group-ityaar-no-captcha \
1146 {![string match "*Prove that you are human*" $loginReply]}
@@ -1085,12 +1151,14 @@
1151 # does not exist or is not a database, a wrong number of arguments.
1152 foreach {loginLgName loginLgArgs loginLgWant} [list \
1153 self [list join $loginRepo] {*same as this one*} \
1154 missing [list join [file join [pwd] nosuch.fossil]] {*does not exist*} \
1155 junk [list join [file join [pwd] ljunk.fossil]] {*not a database*} \
1156 join-args [list join] \
1157 {*unexpected argument count*} \
1158 leave-args [list leave extra] \
1159 {*unknown extra arguments*} \
1160 ] {
1161 fossil_raw login-group {*}$loginLgArgs
1162 test login-group-err-$loginLgName {$CODE != 0
1163 && [string match $loginLgWant $RESULT]}
1164 }
@@ -1113,15 +1181,14 @@
1181 ###############################################################################
1182 # Pages that need a capability "nobody" lacks redirect to /login, naming
1183 # the page and its query string, and adding "anon=1" when "anonymous" has
1184 # the capability. With "redirect-to-https" set to 2 the redirect goes to
1185 # the https: address.
1186 test_eq login-needed [reply_header [login_get "/tktnew?x=1"] Location] \
 
1187 http://x/login?g=tktnew%3fx%3D1
1188 fossil sql "UPDATE user SET cap='hn' WHERE login='anonymous'"
1189 test_eq login-needed-anon [reply_header [login_get /tktnew] Location] \
1190 http://x/login?g=tktnew&anon=1
1191 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
1192
1193 # A page that shows hyperlinks only with the Hyperlink capability offers an
1194 # anonymous login when "anonymous" has that capability.
@@ -1131,26 +1198,27 @@
1198
1199 # A page on the "robot-restrict" list asks a client without a login to
1200 # show that it is not a robot.
1201 login_config robot-restrict test-env
1202 set loginReply [login_get /test-env [list "User-Agent: Googlebot/2.1"]]
1203 test_eq login-robot-restrict [login_who $loginReply] "-"
1204 login_config robot-restrict ""
1205 fossil sql "UPDATE user SET cap='' WHERE login='nobody'"
1206
1207 # With "redirect-to-https" set to 1, the redirect to /login for such a page
1208 # goes to the https: address.
1209 login_config redirect-to-https 1
1210 test_eq login-needed-https [reply_header [login_get /tktnew] Location] \
1211 https://x/login?g=tktnew
1212 login_config redirect-to-https ""
1213
1214 # A login cookie in a repository that is in no login group does not keep
1215 # /ityaar from asking again after a wrong answer.
1216 set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \
1217 [list "Cookie: $loginCookieName=[string repeat a 50]/x"]]
1218 test login-ityaar-nogroup {[string match "*Prove that you are human*" \
1219 $loginReply]}
1220
1221 # A sync request whose login card names a user with a NULL capability
1222 # column logs in with no capabilities: its pull is refused. The same
1223 # request for that user with Read capability is answered.
1224 fossil user new loginnocap [email protected] nocappw
@@ -1159,18 +1227,23 @@
1227 "SELECT value FROM config WHERE name='project-code'"]]
1228 set sc [string trim [fossil sql \
1229 "SELECT value FROM config WHERE name='server-code'"]]
1230 set pw [string trim [fossil sql "SELECT pw FROM user WHERE login='$user'"]]
1231 set tail "pull $sc $pc\n"
1232 set nonce [sha1_text $tail]
1233 set sig [sha1_text "$nonce$pw"]
1234 set body "login $user $nonce $sig\n$tail"
1235 return [login_send \
1236 [join [list \
1237 "POST /xfer HTTP/1.1\r\nHost: x\r\n" \
1238 "Content-Type: application/x-fossil-uncompressed\r\n" \
1239 "Content-Length: [string length $body]\r\n\r\n$body"] ""]]
1240 }
1241 fossil sql "UPDATE user SET cap=NULL WHERE login='loginnocap'"
1242 test login-xfer-null-cap \
1243 {[string first {not\sauthorized\sto\sread} [login_xfer_pull loginnocap]] >=
1244 0}
1245 fossil sql "UPDATE user SET cap='o' WHERE login='loginnocap'"
1246 set loginReply [login_xfer_pull loginnocap]
1247 test login-xfer-read-cap {[string match "*igot *" $loginReply]
1248 && [string first {not\sauthorized} $loginReply] < 0}
1249
@@ -1190,17 +1263,19 @@
1263 login_config peer-repo-2222222222222222 [file join [pwd] lnoperm.fossil]
1264 set loginSess [login_session loginbob groupnew2]
1265 set loginReply [login_post /login \
1266 "p=groupnew2&n1=groupnew3&n2=groupnew3&csrf=[lindex $loginSess 1]" \
1267 [list "Cookie: [lindex $loginSess 0]"]]
1268 test login-group-noperm-member \
1269 {[string match "*lnoperm.fossil: *" $loginReply]}
1270 login_config peer-repo-2222222222222222 ""
1271 fossil_raw login-group join [file join [pwd] lnoperm.fossil]
1272 test login-group-noperm-join {$CODE != 0
1273 && [string match "*unable to open*" $RESULT]}
1274 } else {
1275 test_skip_part \
1276 "login-group-noperm-*: need a file the user running the tests cannot read"
1277 }
1278 file attributes lnoperm.fossil -permissions 0644
1279
1280 ###############################################################################
1281 # Pages that depend on the client. A request with a "Mobi" User-Agent is
@@ -1246,17 +1321,18 @@
1321 empty {} $loginHome \
1322 base http://x http://x \
1323 base-more http://xy $loginHome \
1324 other http://y/ $loginHome \
1325 ] {
1326 test_eq login-goto-$loginFgName [reply_header [login_get \
1327 "/login?u=loginbob&p=bobfinal&fossil-goto=$loginFgTarget"] Location] \
1328 $loginFgWant
1329 }
1330
1331 # A GET with "out" does not log out.
1332 test login-logout-get {[string match \
1333 "*Currently logged in as <b>loginbob</b>*" \
1334 [login_get "/login?out=1" [list "Cookie: $loginPair"]]]}
1335
1336 # A password change without the second copy of the new password, without
1337 # the first, or without the Anti-CSRF token changes nothing.
1338 foreach {loginPcName loginPcBody} [list \
@@ -1264,20 +1340,20 @@
1340 no-n1 "p=bobfinal&n2=changed1&csrf=$loginTok" \
1341 no-csrf "p=bobfinal&n1=changed1&n2=changed1" \
1342 ] {
1343 set loginReply [login_post /login $loginPcBody [list "Cookie: $loginPair"]]
1344 test login-pwchange-$loginPcName \
1345 {![string match "HTTP/1.0 302*" [reply_status $loginReply]]
1346 && [login_who [login_basic loginbob:bobfinal]] eq "loginbob"}
1347 }
1348
1349 # A user name with no password, or an empty password, shows the form and
1350 # sets no cookie.
1351 foreach {loginNpName loginNpQuery} {no-p u=loginbob empty-p u=loginbob&p=} {
1352 set loginReply [login_get "/login?$loginNpQuery"]
1353 test login-form-$loginNpName {[reply_status $loginReply] eq "HTTP/1.0 200 OK"
1354 && [reply_header $loginReply Set-Cookie] eq "-"}
1355 }
1356
1357 # "g" with "noanon" does not name the page asked for.
1358 test login-page-goto-noanon {![string match "*access page*" \
1359 [login_get "/login?g=timeline&noanon=1"]]}
@@ -1312,21 +1388,24 @@
1388 [login_get /login [list "Cookie: $loginPair"]]]}
1389 fossil settings email-send-method dir
1390 fossil sql "UPDATE user SET cap='op' WHERE login='loginbob'"
1391
1392 # An anonymous login is not offered a password change.
1393 set loginAnonPair [login_cookie_pair \
1394 [login_get "/login?$loginAnon" [list $loginUA]]]
1395 set loginReply [login_get /login [list "Cookie: $loginAnonPair" $loginUA]]
1396 test login-page-anonymous {[string match \
1397 "*Currently logged in as <b>anonymous</b>*" $loginReply]
1398 && ![string match "*Change Password*" $loginReply]}
1399
1400 ###############################################################################
1401 # Further credential checks.
1402
1403 # "resid" without "token" logs no one in; "resid" naming a user with no
1404 # password does not match any token.
1405 test_eq login-resid-no-token \
1406 [login_who [login_get "/test-env?resid=loginbob"]] nobody
1407 test_eq login-resid-no-pw \
1408 [login_who [login_get "/test-env?resid=nobody&token=x"]] nobody
1409
1410 # A user whose login name is empty is served with that user's capabilities
1411 # but without "L", the mark of a logged-in user.
@@ -1350,17 +1429,17 @@
1429 test login-httptrace-no-nobody {[string first {# login:} $RESULT] < 0}
1430
1431 # A request from 127.0.0.1 without --localauth, or over https: with it, is
1432 # not logged in. A request over the fossil ssh transport with --localauth
1433 # is, whatever the client's address.
 
1434 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 127.0.0.1
1435 test_eq login-loopback-no-localauth [login_who [read_file lreply.txt]] nobody
1436 set ::env(REMOTE_HOST) 127.0.0.1
1437 test_eq login-local-https [login_who [login_local $loginRepo --https]] nobody
1438 unset ::env(REMOTE_HOST)
1439 write_file lreq.txt \
1440 "GET /test-env HTTP/1.1\r\nHost: x\r\nX-Fossil-Transport: SSH\r\n\r\n"
1441 set ::env(SSH_CONNECTION) "9.9.9.9 5000 127.0.0.1 22"
1442 fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --localauth
1443 unset ::env(SSH_CONNECTION)
1444 set loginReply [read_file lreply.txt]
1445 test login-local-ssh {[login_method $loginReply] eq "LOCAL"
@@ -1380,11 +1459,12 @@
1459
1460 # The offer of an anonymous login is not made when "anonymous" lacks the
1461 # Hyperlink capability or anonymous logins are off.
1462 fossil sql "UPDATE user SET cap='o' WHERE login='nobody'"
1463 fossil sql "UPDATE user SET cap='' WHERE login='anonymous'"
1464 test login-anonymous-available-nocap \
1465 {![string match "*hyperlinks are disabled*" \
1466 [login_get /leaves [list $loginUA]]]}
1467 fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'"
1468 login_config anon-cookie-lifespan 0
1469 test login-anonymous-available-off {![string match "*hyperlinks are disabled*" \
1470 [login_get /leaves [list $loginUA]]]}
@@ -1399,17 +1479,19 @@
1479 foreach loginRsName {nobody1 reader1 developer1} {
1480 test login-register-reserved-$loginRsName {[string match "*reserved*" \
1481 [login_register "u=$loginRsName&dn=R&[email protected]&p=longpw9&cp=longpw9"]]}
1482 }
1483 # A GET with "new" shows the form and creates no user.
1484 set loginReply [login_get \
1485 "/register?$loginRegBase&u=getuser1&dn=G&[email protected]&p=longpw9&cp=longpw9"]
1486 test login-register-get {[string match {*name="captchaseed"*} $loginReply]
1487 && [login_user_cap getuser1] eq ""}
1488 # An "auth-sub-email" setting that is empty allows any address.
1489 fossil sql "REPLACE INTO config(name,value,mtime) VALUES('auth-sub-email','',0)"
1490 test login-register-auth-empty {[string match "*Passwords do not match*" \
1491 [login_register \
1492 "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]}
1493 login_config auth-sub-email ""
1494
1495 login_config self-pw-reset 1
1496 # The address of the "nobody" user is refused even with the Password
1497 # capability.
@@ -1422,23 +1504,14 @@
1504 "captchaseed=$loginSeed&captcha=$loginCap&[email protected]"]
1505 test login-reqpw-no-flag {[string match {*name="reqpwreset"*} $loginReply]
1506 && ![string match "*has been sent*" $loginReply]}
1507
1508 ###############################################################################
1509 # Further /resetpw requests: a POST with only one copy of the password, and
 
1510 # valid suffixes for a user with Admin capability and for "nobody" with the
1511 # Password capability.
1512
 
 
 
 
 
 
 
 
1513 set loginRName [login_reset_suffix loginbob]
1514 test login-resetpw-one-copy {[string match "*Change Password for user*" \
1515 [login_post /resetpw "name=$loginRName&n1=changed1"]]}
1516 fossil sql "UPDATE user SET cap='a' WHERE login='verify3'"
1517 test login-resetpw-refused-admin {[string match \
@@ -1457,11 +1530,12 @@
1530 # hex digits, a slash and at least one more character.
1531
1532 login_config peer-repo-3333333333333333 [file join [pwd] ljunk.fossil]
1533 login_config peer-repo-4444444444444444 $loginRepo2
1534 set loginFakeHash [string repeat A 50]
1535 foreach {loginPeName loginPeCode} \
1536 {junk 3333333333333333 nocookie 4444444444444444} {
1537 test_eq login-transfer-$loginPeName [login_who [login_get /test-env \
1538 [list "Cookie: $loginCookieName=$loginFakeHash/$loginPeCode/loginsue"]]] \
1539 nobody
1540 }
1541 login_config peer-repo-3333333333333333 ""
@@ -1482,40 +1556,40 @@
1556 }
1557 fossil login-group leave
1558
1559 # An empty login-group subcommand is unknown.
1560 fossil_raw login-group ""
1561 test login-group-err-empty \
1562 {$CODE != 0 && [string match "*unknown command*" $RESULT]}
1563
1564 ###############################################################################
1565 # Further cases, each varying one input of a case above.
1566
 
 
 
 
1567 # With "access-log" off, a login is not recorded.
1568 login_config access-log 0
1569 set loginLogCount [string trim [fossil sql "SELECT count(*) FROM accesslog"]]
1570 login_form loginbob bobfinal
1571 test_eq login-accesslog-off \
1572 [string trim [fossil sql "SELECT count(*) FROM accesslog"]] $loginLogCount
1573 login_config access-log ""
1574
1575 # A negative "anon-cookie-lifespan" turns anonymous logins off.
1576 if {$loginWaits} {
1577 login_config anon-cookie-lifespan -5
1578 set loginReply [login_get "/login?$loginAnon"]
1579 test login-anon-negative-lifespan \
1580 {[string match "HTTP/1.0 401*" [reply_status $loginReply]]
1581 && [reply_header $loginReply Set-Cookie] eq "-"}
1582 login_config anon-cookie-lifespan ""
1583 }
1584
1585 # Login cookies that name the special users "developer" and "reader" are
1586 # not accepted.
1587 foreach loginSpUser {developer reader} {
1588 test_eq login-cookie-special-$loginSpUser [login_who [login_get /test-env \
1589 [list \
1590 "Cookie: $loginCookieName=[string repeat A 50]/0123456789abcdef/$loginSpUser"]]] \
1591 nobody
1592 }
1593
1594 # The forum capabilities 5 and 4 grant those below them; "u" or "v" given
1595 # twice inherits once.
1596
+20 -32
--- test/manifest.test
+++ test/manifest.test
@@ -3,41 +3,24 @@
33
# compared with "fossil diff --from --to", the /dir and /tree pages,
44
# delta manifests read through their baseline, a file named in another
55
# letter case, and artifact_to_json() for every kind of artifact.
66
#
77
8
-# These tests run only in a long pass: -assurance stress.
9
-if {[test_assurance] ne "stress"} {
10
- test_skip "runs only with -assurance stress"
11
-}
12
-
138
test_setup
149
15
-# The answer of one SQL statement, trimmed.
16
-#
17
-proc manifest_sql {sql} {
18
- global RESULT
19
- fossil sql $sql
20
- return [string trim $RESULT]
21
-}
22
-
2310
# The hash of the check-in with the comment COMMENT.
2411
#
2512
proc manifest_ci {comment} {
26
- return [manifest_sql "SELECT uuid FROM blob, event
13
+ return [fossil_sql "SELECT uuid FROM blob, event
2714
WHERE objid=rid AND type='ci' AND comment='$comment'"]
2815
}
2916
3017
# The reply of the server to a GET of PATH.
3118
#
3219
proc manifest_get {path} {
33
- write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n"
34
- file delete reply.txt
35
- fossil_raw http [file join [pwd] .rep.fossil] --in request.txt \
36
- --out reply.txt --ipaddr 127.0.0.1 --localauth
37
- if {[file exists reply.txt]} { return [read_file reply.txt] }
38
- return ""
20
+ return [fossil_http [file join [pwd] .rep.fossil] [request_get $path] \
21
+ --ipaddr 127.0.0.1 --localauth]
3922
}
4023
4124
write_file a.txt "one\n"
4225
write_file b.txt "bee\n"
4326
write_file keep.txt "kept\n"
@@ -54,11 +37,11 @@
5437
5538
fossil diff --from $manifestV1 --to $manifestV2
5639
test manifest-diff-versions {$CODE == 0 && [string match "*+two*" $RESULT]}
5740
5841
# A name that is not a check-in is refused before it is looked up.
59
-set manifestFile [manifest_sql "SELECT uuid FROM blob, mlink
42
+set manifestFile [fossil_sql "SELECT uuid FROM blob, mlink
6043
WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$manifestV2')
6144
AND fnid=(SELECT fnid FROM filename WHERE name='a.txt')"]
6245
fossil diff --from $manifestFile --to $manifestV2 -expectError
6346
test manifest-diff-not-checkin {$CODE != 0
6447
&& [string match "*cannot resolve name*" $RESULT]}
@@ -97,11 +80,11 @@
9780
fossil diff --from $manifestV2 --to $manifestV4
9881
test manifest-diff-delta {$CODE == 0 && [string match "*+three*" $RESULT]
9982
&& [string match "*DELETED keep.txt*" $RESULT]}
10083
10184
# The JSON form of a delta manifest names its baseline in a B field.
102
-test_eq manifest-delta-json-baseline [manifest_sql "SELECT
85
+test_eq manifest-delta-json-baseline [fossil_sql "SELECT
10386
json_extract(artifact_to_json('$manifestV3'), '\$.B') =
10487
(SELECT uuid FROM blob WHERE rid=(SELECT baseid FROM plink
10588
WHERE cid=(SELECT rid FROM blob WHERE uuid='$manifestV3')))"] 1
10689
10790
###############################################################################
@@ -145,15 +128,16 @@
145128
fossil attachment add Page c.txt
146129
test manifest-json-attachment {$CODE == 0}
147130
fossil ticket add title "A ticket" status Open
148131
fossil test-create-clusters
149132
150
-set manifestJson [manifest_sql "SELECT count(*), sum(json_valid(j))
133
+set manifestJson [fossil_sql "SELECT count(*), sum(json_valid(j))
151134
FROM (SELECT artifact_to_json(rid) AS j FROM blob WHERE size>=0)
152135
WHERE j IS NOT NULL"]
153136
set manifestJson [split $manifestJson |]
154
-test manifest-json-all-valid {[lindex $manifestJson 0] == [lindex $manifestJson 1]
137
+test manifest-json-all-valid \
138
+ {[lindex $manifestJson 0] == [lindex $manifestJson 1]
155139
&& [lindex $manifestJson 0] > 10}
156140
157141
foreach {manifestName manifestPath manifestWant} [list \
158142
exec "\$.F\[2\].perm" x \
159143
rename "\$.F\[1\].rename" b.txt \
@@ -163,41 +147,42 @@
163147
switch $manifestName {
164148
exec { set manifestOf [manifest_ci exec-set] }
165149
rename { set manifestOf $manifestV2 }
166150
cherrypick { set manifestOf [manifest_ci cherrypick] }
167151
tag {
168
- set manifestOf [manifest_sql "SELECT uuid FROM blob, tagxref, tag
152
+ set manifestOf [fossil_sql "SELECT uuid FROM blob, tagxref, tag
169153
WHERE blob.rid=srcid AND tag.tagid=tagxref.tagid
170154
AND tagname='sym-release'"]
171155
}
172156
}
173
- test_eq manifest-json-$manifestName [manifest_sql \
157
+ test_eq manifest-json-$manifestName [fossil_sql \
174158
"SELECT json_extract(artifact_to_json('$manifestOf'), '$manifestPath')"] \
175159
$manifestWant
176160
}
177161
178162
# Content that is not an artifact gives NULL, and a value that is neither
179163
# a record number nor a name is an error.
180
-test_eq manifest-json-not-artifact [manifest_sql \
164
+test_eq manifest-json-not-artifact [fossil_sql \
181165
"SELECT artifact_to_json('$manifestFile') IS NULL"] 1
182166
fossil sql "SELECT artifact_to_json(1.5)" -expectError
183
-test manifest-json-bad-argument {[string match "*Expecting one argument*" $RESULT]}
167
+test manifest-json-bad-argument \
168
+ {[string match "*Expecting one argument*" $RESULT]}
184169
185170
###############################################################################
186171
# "tag add --root" puts a tag on the first check-in of the line that a
187172
# check-in is on, and says so when it only tries.
188173
189
-set manifestRoot [manifest_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid
174
+set manifestRoot [fossil_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid
190175
FROM plink WHERE pid NOT IN (SELECT cid FROM plink) LIMIT 1)"]
191176
fossil tag add --root --dry-run rooted $manifestV2
192177
test manifest-tag-root-dry-run {$CODE == 0 && [string match \
193178
"*to root ancestor [string range $manifestRoot 0 9]*" $RESULT]}
194
-test_eq manifest-tag-root-dry-run-no-tag [manifest_sql "SELECT count(*)
179
+test_eq manifest-tag-root-dry-run-no-tag [fossil_sql "SELECT count(*)
195180
FROM tag WHERE tagname='sym-rooted'"] 0
196181
fossil tag add --root rooted $manifestV2
197182
test manifest-tag-root {$CODE == 0}
198
-test_eq manifest-tag-root-on-first [manifest_sql "SELECT tagtype FROM tagxref,
183
+test_eq manifest-tag-root-on-first [fossil_sql "SELECT tagtype FROM tagxref,
199184
tag, blob WHERE tag.tagid=tagxref.tagid AND tagname='sym-rooted'
200185
AND tagxref.rid=blob.rid AND tagxref.srcid>0
201186
AND uuid='$manifestRoot'"] 2
202187
fossil tag list --root $manifestV2
203188
test manifest-tag-root-list {$CODE == 0 && [string match "*rooted*" $RESULT]}
@@ -254,11 +239,14 @@
254239
test manifest-signed-stored {$CODE == 0 && $manifestSignedHash ne ""}
255240
fossil settings manifest on
256241
fossil update $manifestSignedHash
257242
test manifest-signed-update {$CODE == 0}
258243
test manifest-signed-manifest-file {[string match \
259
- "*\nZ *\n# Remove this line to create a well-formed Fossil manifest.\n-----BEGIN PGP SIGNATURE-----\n*" \
244
+ [join [list \
245
+ "*\nZ *\n" \
246
+ "# Remove this line to create a well-formed Fossil " \
247
+ "manifest.\n-----BEGIN PGP SIGNATURE-----\n*"] ""] \
260248
[read_file manifest]]}
261249
fossil diff --from prev --to current -expectError
262250
test manifest-prev-not-checkin {$CODE != 0
263251
&& [string match "*no such check-in: prev*" $RESULT]}
264252
fossil settings manifest off
265253
--- test/manifest.test
+++ test/manifest.test
@@ -3,41 +3,24 @@
3 # compared with "fossil diff --from --to", the /dir and /tree pages,
4 # delta manifests read through their baseline, a file named in another
5 # letter case, and artifact_to_json() for every kind of artifact.
6 #
7
8 # These tests run only in a long pass: -assurance stress.
9 if {[test_assurance] ne "stress"} {
10 test_skip "runs only with -assurance stress"
11 }
12
13 test_setup
14
15 # The answer of one SQL statement, trimmed.
16 #
17 proc manifest_sql {sql} {
18 global RESULT
19 fossil sql $sql
20 return [string trim $RESULT]
21 }
22
23 # The hash of the check-in with the comment COMMENT.
24 #
25 proc manifest_ci {comment} {
26 return [manifest_sql "SELECT uuid FROM blob, event
27 WHERE objid=rid AND type='ci' AND comment='$comment'"]
28 }
29
30 # The reply of the server to a GET of PATH.
31 #
32 proc manifest_get {path} {
33 write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n"
34 file delete reply.txt
35 fossil_raw http [file join [pwd] .rep.fossil] --in request.txt \
36 --out reply.txt --ipaddr 127.0.0.1 --localauth
37 if {[file exists reply.txt]} { return [read_file reply.txt] }
38 return ""
39 }
40
41 write_file a.txt "one\n"
42 write_file b.txt "bee\n"
43 write_file keep.txt "kept\n"
@@ -54,11 +37,11 @@
54
55 fossil diff --from $manifestV1 --to $manifestV2
56 test manifest-diff-versions {$CODE == 0 && [string match "*+two*" $RESULT]}
57
58 # A name that is not a check-in is refused before it is looked up.
59 set manifestFile [manifest_sql "SELECT uuid FROM blob, mlink
60 WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$manifestV2')
61 AND fnid=(SELECT fnid FROM filename WHERE name='a.txt')"]
62 fossil diff --from $manifestFile --to $manifestV2 -expectError
63 test manifest-diff-not-checkin {$CODE != 0
64 && [string match "*cannot resolve name*" $RESULT]}
@@ -97,11 +80,11 @@
97 fossil diff --from $manifestV2 --to $manifestV4
98 test manifest-diff-delta {$CODE == 0 && [string match "*+three*" $RESULT]
99 && [string match "*DELETED keep.txt*" $RESULT]}
100
101 # The JSON form of a delta manifest names its baseline in a B field.
102 test_eq manifest-delta-json-baseline [manifest_sql "SELECT
103 json_extract(artifact_to_json('$manifestV3'), '\$.B') =
104 (SELECT uuid FROM blob WHERE rid=(SELECT baseid FROM plink
105 WHERE cid=(SELECT rid FROM blob WHERE uuid='$manifestV3')))"] 1
106
107 ###############################################################################
@@ -145,15 +128,16 @@
145 fossil attachment add Page c.txt
146 test manifest-json-attachment {$CODE == 0}
147 fossil ticket add title "A ticket" status Open
148 fossil test-create-clusters
149
150 set manifestJson [manifest_sql "SELECT count(*), sum(json_valid(j))
151 FROM (SELECT artifact_to_json(rid) AS j FROM blob WHERE size>=0)
152 WHERE j IS NOT NULL"]
153 set manifestJson [split $manifestJson |]
154 test manifest-json-all-valid {[lindex $manifestJson 0] == [lindex $manifestJson 1]
 
155 && [lindex $manifestJson 0] > 10}
156
157 foreach {manifestName manifestPath manifestWant} [list \
158 exec "\$.F\[2\].perm" x \
159 rename "\$.F\[1\].rename" b.txt \
@@ -163,41 +147,42 @@
163 switch $manifestName {
164 exec { set manifestOf [manifest_ci exec-set] }
165 rename { set manifestOf $manifestV2 }
166 cherrypick { set manifestOf [manifest_ci cherrypick] }
167 tag {
168 set manifestOf [manifest_sql "SELECT uuid FROM blob, tagxref, tag
169 WHERE blob.rid=srcid AND tag.tagid=tagxref.tagid
170 AND tagname='sym-release'"]
171 }
172 }
173 test_eq manifest-json-$manifestName [manifest_sql \
174 "SELECT json_extract(artifact_to_json('$manifestOf'), '$manifestPath')"] \
175 $manifestWant
176 }
177
178 # Content that is not an artifact gives NULL, and a value that is neither
179 # a record number nor a name is an error.
180 test_eq manifest-json-not-artifact [manifest_sql \
181 "SELECT artifact_to_json('$manifestFile') IS NULL"] 1
182 fossil sql "SELECT artifact_to_json(1.5)" -expectError
183 test manifest-json-bad-argument {[string match "*Expecting one argument*" $RESULT]}
 
184
185 ###############################################################################
186 # "tag add --root" puts a tag on the first check-in of the line that a
187 # check-in is on, and says so when it only tries.
188
189 set manifestRoot [manifest_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid
190 FROM plink WHERE pid NOT IN (SELECT cid FROM plink) LIMIT 1)"]
191 fossil tag add --root --dry-run rooted $manifestV2
192 test manifest-tag-root-dry-run {$CODE == 0 && [string match \
193 "*to root ancestor [string range $manifestRoot 0 9]*" $RESULT]}
194 test_eq manifest-tag-root-dry-run-no-tag [manifest_sql "SELECT count(*)
195 FROM tag WHERE tagname='sym-rooted'"] 0
196 fossil tag add --root rooted $manifestV2
197 test manifest-tag-root {$CODE == 0}
198 test_eq manifest-tag-root-on-first [manifest_sql "SELECT tagtype FROM tagxref,
199 tag, blob WHERE tag.tagid=tagxref.tagid AND tagname='sym-rooted'
200 AND tagxref.rid=blob.rid AND tagxref.srcid>0
201 AND uuid='$manifestRoot'"] 2
202 fossil tag list --root $manifestV2
203 test manifest-tag-root-list {$CODE == 0 && [string match "*rooted*" $RESULT]}
@@ -254,11 +239,14 @@
254 test manifest-signed-stored {$CODE == 0 && $manifestSignedHash ne ""}
255 fossil settings manifest on
256 fossil update $manifestSignedHash
257 test manifest-signed-update {$CODE == 0}
258 test manifest-signed-manifest-file {[string match \
259 "*\nZ *\n# Remove this line to create a well-formed Fossil manifest.\n-----BEGIN PGP SIGNATURE-----\n*" \
 
 
 
260 [read_file manifest]]}
261 fossil diff --from prev --to current -expectError
262 test manifest-prev-not-checkin {$CODE != 0
263 && [string match "*no such check-in: prev*" $RESULT]}
264 fossil settings manifest off
265
--- test/manifest.test
+++ test/manifest.test
@@ -3,41 +3,24 @@
3 # compared with "fossil diff --from --to", the /dir and /tree pages,
4 # delta manifests read through their baseline, a file named in another
5 # letter case, and artifact_to_json() for every kind of artifact.
6 #
7
 
 
 
 
 
8 test_setup
9
 
 
 
 
 
 
 
 
10 # The hash of the check-in with the comment COMMENT.
11 #
12 proc manifest_ci {comment} {
13 return [fossil_sql "SELECT uuid FROM blob, event
14 WHERE objid=rid AND type='ci' AND comment='$comment'"]
15 }
16
17 # The reply of the server to a GET of PATH.
18 #
19 proc manifest_get {path} {
20 return [fossil_http [file join [pwd] .rep.fossil] [request_get $path] \
21 --ipaddr 127.0.0.1 --localauth]
 
 
 
 
22 }
23
24 write_file a.txt "one\n"
25 write_file b.txt "bee\n"
26 write_file keep.txt "kept\n"
@@ -54,11 +37,11 @@
37
38 fossil diff --from $manifestV1 --to $manifestV2
39 test manifest-diff-versions {$CODE == 0 && [string match "*+two*" $RESULT]}
40
41 # A name that is not a check-in is refused before it is looked up.
42 set manifestFile [fossil_sql "SELECT uuid FROM blob, mlink
43 WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$manifestV2')
44 AND fnid=(SELECT fnid FROM filename WHERE name='a.txt')"]
45 fossil diff --from $manifestFile --to $manifestV2 -expectError
46 test manifest-diff-not-checkin {$CODE != 0
47 && [string match "*cannot resolve name*" $RESULT]}
@@ -97,11 +80,11 @@
80 fossil diff --from $manifestV2 --to $manifestV4
81 test manifest-diff-delta {$CODE == 0 && [string match "*+three*" $RESULT]
82 && [string match "*DELETED keep.txt*" $RESULT]}
83
84 # The JSON form of a delta manifest names its baseline in a B field.
85 test_eq manifest-delta-json-baseline [fossil_sql "SELECT
86 json_extract(artifact_to_json('$manifestV3'), '\$.B') =
87 (SELECT uuid FROM blob WHERE rid=(SELECT baseid FROM plink
88 WHERE cid=(SELECT rid FROM blob WHERE uuid='$manifestV3')))"] 1
89
90 ###############################################################################
@@ -145,15 +128,16 @@
128 fossil attachment add Page c.txt
129 test manifest-json-attachment {$CODE == 0}
130 fossil ticket add title "A ticket" status Open
131 fossil test-create-clusters
132
133 set manifestJson [fossil_sql "SELECT count(*), sum(json_valid(j))
134 FROM (SELECT artifact_to_json(rid) AS j FROM blob WHERE size>=0)
135 WHERE j IS NOT NULL"]
136 set manifestJson [split $manifestJson |]
137 test manifest-json-all-valid \
138 {[lindex $manifestJson 0] == [lindex $manifestJson 1]
139 && [lindex $manifestJson 0] > 10}
140
141 foreach {manifestName manifestPath manifestWant} [list \
142 exec "\$.F\[2\].perm" x \
143 rename "\$.F\[1\].rename" b.txt \
@@ -163,41 +147,42 @@
147 switch $manifestName {
148 exec { set manifestOf [manifest_ci exec-set] }
149 rename { set manifestOf $manifestV2 }
150 cherrypick { set manifestOf [manifest_ci cherrypick] }
151 tag {
152 set manifestOf [fossil_sql "SELECT uuid FROM blob, tagxref, tag
153 WHERE blob.rid=srcid AND tag.tagid=tagxref.tagid
154 AND tagname='sym-release'"]
155 }
156 }
157 test_eq manifest-json-$manifestName [fossil_sql \
158 "SELECT json_extract(artifact_to_json('$manifestOf'), '$manifestPath')"] \
159 $manifestWant
160 }
161
162 # Content that is not an artifact gives NULL, and a value that is neither
163 # a record number nor a name is an error.
164 test_eq manifest-json-not-artifact [fossil_sql \
165 "SELECT artifact_to_json('$manifestFile') IS NULL"] 1
166 fossil sql "SELECT artifact_to_json(1.5)" -expectError
167 test manifest-json-bad-argument \
168 {[string match "*Expecting one argument*" $RESULT]}
169
170 ###############################################################################
171 # "tag add --root" puts a tag on the first check-in of the line that a
172 # check-in is on, and says so when it only tries.
173
174 set manifestRoot [fossil_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid
175 FROM plink WHERE pid NOT IN (SELECT cid FROM plink) LIMIT 1)"]
176 fossil tag add --root --dry-run rooted $manifestV2
177 test manifest-tag-root-dry-run {$CODE == 0 && [string match \
178 "*to root ancestor [string range $manifestRoot 0 9]*" $RESULT]}
179 test_eq manifest-tag-root-dry-run-no-tag [fossil_sql "SELECT count(*)
180 FROM tag WHERE tagname='sym-rooted'"] 0
181 fossil tag add --root rooted $manifestV2
182 test manifest-tag-root {$CODE == 0}
183 test_eq manifest-tag-root-on-first [fossil_sql "SELECT tagtype FROM tagxref,
184 tag, blob WHERE tag.tagid=tagxref.tagid AND tagname='sym-rooted'
185 AND tagxref.rid=blob.rid AND tagxref.srcid>0
186 AND uuid='$manifestRoot'"] 2
187 fossil tag list --root $manifestV2
188 test manifest-tag-root-list {$CODE == 0 && [string match "*rooted*" $RESULT]}
@@ -254,11 +239,14 @@
239 test manifest-signed-stored {$CODE == 0 && $manifestSignedHash ne ""}
240 fossil settings manifest on
241 fossil update $manifestSignedHash
242 test manifest-signed-update {$CODE == 0}
243 test manifest-signed-manifest-file {[string match \
244 [join [list \
245 "*\nZ *\n" \
246 "# Remove this line to create a well-formed Fossil " \
247 "manifest.\n-----BEGIN PGP SIGNATURE-----\n*"] ""] \
248 [read_file manifest]]}
249 fossil diff --from prev --to current -expectError
250 test manifest-prev-not-checkin {$CODE != 0
251 && [string match "*no such check-in: prev*" $RESULT]}
252 fossil settings manifest off
253
+71 -58
--- test/name.test
+++ test/name.test
@@ -6,15 +6,12 @@
66
# hashes begin alike. Every kind of name is then given to
77
# "fossil test-name-to-id", "fossil whatis" and other commands, and to
88
# web pages through "fossil http --in".
99
#
1010
11
-# These tests run only in a long pass: -assurance stress.
12
-if {[test_assurance] ne "stress"} {
13
- test_skip "runs only with -assurance stress"
14
-}
15
-
11
+# The first sections run at every level, and the rest need
12
+# -assurance stress.
1613
require_no_open_checkout
1714
1815
test_setup ""
1916
2017
set nameRepo [file join [pwd] name.fossil]
@@ -21,22 +18,14 @@
2118
fossil new --admin-user alice --date-override "2025-01-01 00:00:00" $nameRepo
2219
fossil open $nameRepo
2320
fossil user default alice
2421
fossil set mtime-changes off
2522
26
-# The answer of one SQL statement, trimmed.
27
-#
28
-proc name_sql {sql} {
29
- global RESULT
30
- fossil sql $sql
31
- return [string trim $RESULT]
32
-}
33
-
3423
# The hash of the check-in whose comment is COMMENT.
3524
#
3625
proc name_checkin {comment} {
37
- return [name_sql "SELECT uuid FROM event, blob
26
+ return [fossil_sql "SELECT uuid FROM event, blob
3827
WHERE objid=rid AND type='ci' AND comment='$comment'"]
3928
}
4029
4130
# Check in the checkout as it stands with COMMENT and DATE. ARGS are
4231
# more options. Return the hash of the check-in.
@@ -64,11 +53,11 @@
6453
puts -nonewline $fd "Z $sum\n"
6554
close $fd
6655
fossil test-content-put --crosslink $fn
6756
file delete $fn
6857
if {![regexp {inserted as record (\d+)} $RESULT all rid]} { return "" }
69
- return [name_sql "SELECT uuid FROM blob WHERE rid=$rid"]
58
+ return [fossil_sql "SELECT uuid FROM blob WHERE rid=$rid"]
7059
}
7160
7261
# The strings in WANTED that TEXT does not hold, and those that begin
7362
# with "!" that it does hold.
7463
#
@@ -105,11 +94,11 @@
10594
# 2025-01-06 b2 br, with c3 merged in
10695
# 2025-01-07 b3 br
10796
#
10897
# The checkout is left at c2.
10998
110
-set nameC0 [name_sql "SELECT uuid FROM event, blob
99
+set nameC0 [fossil_sql "SELECT uuid FROM event, blob
111100
WHERE objid=rid AND type='ci'"]
112101
113102
# The hashes of p.txt and q.txt begin with the same five characters.
114103
write_file f.txt "one\n"
115104
write_file p.txt "name collide 1177\n"
@@ -153,11 +142,11 @@
153142
--user-override alice
154143
fossil tag add gone $nameC1 --date-override "2025-01-08 11:00:00" \
155144
--user-override alice
156145
fossil tag cancel gone $nameC1 --date-override "2025-01-08 12:00:00" \
157146
--user-override alice
158
-set nameG1 [name_sql "SELECT uuid FROM event, blob
147
+set nameG1 [fossil_sql "SELECT uuid FROM event, blob
159148
WHERE objid=rid AND type='g' AND comment LIKE '%\"decade\"%'"]
160149
161150
test name-setup-checkins {[llength [lsort -unique [list $nameC0 $nameC1 \
162151
$nameC2 $nameC3 $nameB1 $nameB2 $nameB3 $nameG1]]] == 8
163152
&& [string length $nameG1] == 64}
@@ -324,13 +313,13 @@
324313
$nameGhostMember]] "\nM "]\n"]
325314
326315
test name-setup-more {[llength [lsort -unique [list $namePriv $nameA1 \
327316
$nameA2 $nameW3 $nameSide $nameG2 $nameCluster $nameAtt1 $nameAtt2]]] == 9
328317
&& [string length $nameCluster] == 64 && [string length $nameSha1] == 40
329
- && [name_sql "SELECT count(*) FROM phantom"] == 5
330
- && [name_sql "SELECT count(*) FROM delta"] > 0
331
- && [name_sql "SELECT count(*) FROM blob WHERE uuid='$nameSha1'"] == 1}
318
+ && [fossil_sql "SELECT count(*) FROM phantom"] == 5
319
+ && [fossil_sql "SELECT count(*) FROM delta"] > 0
320
+ && [fossil_sql "SELECT count(*) FROM blob WHERE uuid='$nameSha1'"] == 1}
332321
333322
test name-setup-artifacts {[llength [lsort -unique [list $nameW1 $nameW2 \
334323
$nameT1 $nameT2 $nameE1 $nameE2 $nameF1]]] == 7
335324
&& [string length $nameF1] == 64}
336325
@@ -343,11 +332,12 @@
343332
tip-wiki tip w {ERROR: cannot resolve name: tip} \
344333
current current {} $nameC2 \
345334
prev prev {} $nameC1 \
346335
previous previous ci $nameC1 \
347336
next next {} $nameC3 \
348
- current-wiki current w {ERROR: cannot resolve name: current} \
337
+ current-wiki current w \
338
+ {ERROR: cannot resolve name: current} \
349339
ckout ckout ci+ $nameC2 \
350340
ckout-ci ckout ci {ERROR: cannot resolve name: ckout} \
351341
ckout-any ckout {} {ERROR: cannot resolve name: ckout} \
352342
current-ciplus current ci+ $nameC2 \
353343
trunk-ciplus trunk ci+ $nameC3 \
@@ -358,11 +348,12 @@
358348
tag-prefix tag:rel1 {} $nameC1 \
359349
tag-hex decade {} $nameC1 \
360350
tag-hex-prefix tag:decade {} $nameC1 \
361351
tag-start tag:br br $nameB1 \
362352
tag-cancelled gone {} {ERROR: cannot resolve name: gone} \
363
- tag-none tag:nosuch {} {ERROR: cannot resolve name: tag:nosuch} \
353
+ tag-none tag:nosuch {} \
354
+ {ERROR: cannot resolve name: tag:nosuch} \
364355
tag-empty tag: {} {ERROR: cannot resolve name: tag:} \
365356
tag-percent tag:% {} {ERROR: cannot resolve name: tag:%} \
366357
tag-underscore re_1 {} {ERROR: cannot resolve name: re_1} \
367358
tag-star rel* {} {ERROR: cannot resolve name: rel*} \
368359
tag-wiki-type rel1 w {ERROR: cannot resolve name: rel1} \
@@ -374,17 +365,24 @@
374365
merge-in-trunk merge-in:trunk {} $nameC3 \
375366
root-first root:$nameC0 {} $nameC0 \
376367
merge-in-first merge-in:$nameC0 {} $nameC0 \
377368
merge-in-plain merge-in:$nameB1 {} $nameC2 \
378369
root-of-root root:root:br {} $nameC0 \
379
- root-none root:nosuch {} {ERROR: cannot resolve name: root:nosuch} \
380
- start-none start:nosuch {} {ERROR: cannot resolve name: start:nosuch} \
381
- merge-in-none merge-in:nosuch {} {ERROR: cannot resolve name: merge-in:nosuch} \
370
+ root-none root:nosuch {} \
371
+ {ERROR: cannot resolve name: root:nosuch} \
372
+ start-none start:nosuch {} \
373
+ {ERROR: cannot resolve name: start:nosuch} \
374
+ merge-in-none merge-in:nosuch {} \
375
+ {ERROR: cannot resolve name: merge-in:nosuch} \
382376
root-empty root: {} {ERROR: cannot resolve name: root:} \
383377
] {
384378
test_eq name-checkin-$nameCase [name_id $nameName $nameType] $nameWant
385379
}
380
+
381
+if {[test_assurance] ne "stress"} {
382
+ test_skip "the tests after the first sections need -assurance stress"
383
+}
386384
387385
###############################################################################
388386
# Dates. The timeline of the repository is in UTC. A date names the
389387
# latest artifact of the wanted kind at or before the end of the day,
390388
# minute, second or millisecond given.
@@ -478,11 +476,10 @@
478476
###############################################################################
479477
# Hashes and their beginnings, tags that look like hashes, record
480478
# numbers, and names with punctuation after them.
481479
482480
set nameC1x [string range $nameC1 0 9]
483
-set nameNone {ERROR: cannot resolve name: }
484481
set nameTwice {ERROR: ambiguous name: }
485482
foreach {nameCase nameName nameType nameWant} [list \
486483
full $nameC1 {} $nameC1 \
487484
prefix $nameC1x {} $nameC1 \
488485
upper [string toupper $nameC1x] {} $nameC1 \
@@ -508,11 +505,10 @@
508505
ticket [string range $nameT1 0 9] t $nameT1 \
509506
technote [string range $nameE1 0 9] e $nameE1 \
510507
forum [string range $nameF1 0 9] f $nameF1 \
511508
tag-change [string range $nameG1 0 9] g $nameG1 \
512509
tag-change-ci [string range $nameG1 0 9] ci - \
513
- empty-type $nameC1x "" $nameC1 \
514510
type-cx $nameC1x cx - \
515511
tip-type-cx tip cx - \
516512
rid rid:1 {} $nameC0 \
517513
rid-ci rid:1 ci $nameC0 \
518514
rid-wiki rid:1 w - \
@@ -537,11 +533,11 @@
537533
dash - {} - \
538534
long [string repeat x 5000] {} - \
539535
long-colons [string repeat : 5000] {} - \
540536
long-date date:[string repeat 9 5000] {} - \
541537
] {
542
- if {$nameWant eq "-"} { set nameWant $nameNone$nameName }
538
+ if {$nameWant eq "-"} { set nameWant $nameNoDate$nameName }
543539
if {$nameWant eq "="} { set nameWant $nameTwice$nameName }
544540
test_eq name-hash-$nameCase [name_id $nameName $nameType] $nameWant
545541
}
546542
547543
###############################################################################
@@ -557,20 +553,20 @@
557553
}
558554
559555
fossil whatis tip
560556
test_eq name-whatis-checkin $RESULT "name: tip
561557
artifact: $nameB3
562
-size: [name_sql "SELECT size FROM blob WHERE uuid='$nameB3'"] bytes
558
+size: [fossil_sql "SELECT size FROM blob WHERE uuid='$nameB3'"] bytes
563559
tags: br
564560
type: Check-in by alice on 2025-01-07 10:00:00
565561
comment: b3"
566562
fossil whatis -h tip
567563
test_eq name-whatis-hash-only $RESULT $nameB3
568564
fossil whatis -v -h tip
569565
test_eq name-whatis-hash-only-verbose $RESULT $nameB3
570566
571
-set nameRidC1 [name_sql "SELECT rid FROM blob WHERE uuid='$nameC1'"]
567
+set nameRidC1 [fossil_sql "SELECT rid FROM blob WHERE uuid='$nameC1'"]
572568
name_whatis verbose [list "artifact: $nameC1 ($nameRidC1)" \
573569
"received: " "tags: decade, rel, rel1, trunk"] -v rel1
574570
name_whatis raw-tags [list "tags: twins" "closed, hidden" \
575571
"Check-in by alice on 2025-01-06 13:00:00"] $nameCa
576572
name_whatis private [list "tags: private" "comment: hidden"] $namePriv
@@ -583,18 +579,18 @@
583579
name_whatis ticket-change [list "type: Ticket-change by alice on" \
584580
"ticket-id: $nameTktLike"] $nameT1
585581
name_whatis file [list "file: p.txt" \
586582
"part of \[[string range $nameC1 0 9]\] on branch trunk by alice on"] $nameP
587583
name_whatis file-on-branch [list "file: f.txt" "on branch br by alice" \
588
- "!on branch trunk"] [name_sql "SELECT uuid FROM blob, mlink
584
+ "!on branch trunk"] [fossil_sql "SELECT uuid FROM blob, mlink
589585
WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$nameB1')"]
590586
name_whatis attachment-wiki [list "attachment: att1.txt" \
591587
"attached to wiki WikiOne" "via $nameA1\n" \
592588
"by user alice on 2025-01-13 10:00:00" "on the page"] $nameAtt1
593589
name_whatis attachment-ticket [list "attachment: att2.txt" \
594590
"attached to ticket $nameTktOnly" \
595
- "via $nameA2 ([name_sql "SELECT rid FROM blob WHERE uuid='$nameA2'"])"] \
591
+ "via $nameA2 ([fossil_sql "SELECT rid FROM blob WHERE uuid='$nameA2'"])"] \
596592
-v $nameAtt2
597593
name_whatis cluster [list "artifact: $nameCluster" "cluster"] $nameCluster
598594
name_whatis sha1-name [list "hash: $nameSha1 (ambiguous)" \
599595
"artifact: $nameSha1" "artifact: $nameT3"] $nameSha1
600596
@@ -644,11 +640,12 @@
644640
# The file named, not the artifact named.
645641
name_whatis by-file [list "name: f.txt" "file: f.txt" \
646642
"on branch trunk"] -f f.txt
647643
name_whatis by-file-unknown [list "name: name.fossil" "unknown: "] \
648644
-f name.fossil
649
-name_whatis by-file-sha1 [list "name: sha1.txt\nhash: $nameSha1 (ambiguous)" \
645
+name_whatis by-file-sha1 [list \
646
+ "name: sha1.txt\nhash: $nameSha1 (ambiguous)" \
650647
"artifact: $nameSha1" "artifact: $nameT3"] -f sha1.txt
651648
name_whatis by-file-twin [list "name: p.txt" "artifact: $nameP" \
652649
"!ambiguous"] -f p.txt
653650
fossil whatis -f nosuchfile -expectError
654651
test name-whatis-by-file-missing {[string match "*no such file*" $RESULT]}
@@ -704,18 +701,19 @@
704701
[list "\"comment\":\"b3\"\}\n[string repeat - 79]\n\{\"unknown\""] \
705702
] {
706703
name_whatis json-$nameCase $nameWant --json {*}$nameArgs
707704
}
708705
709
-test_eq name-whatis-sql-name [name_sql "SELECT whatis('nosuch')"] \
706
+test_eq name-whatis-sql-name [fossil_sql "SELECT whatis('nosuch')"] \
710707
"\{\"unknown\":\"nosuch\"\}"
711708
test name-whatis-sql-rid {[holds_strings \
712
- [name_sql "SELECT whatis($nameRidC1)"] \
713
- [list "\{\"rid\":$nameRidC1,\"artifact\":\"$nameC1\"" "\"comment\":\"c1\"\}"]]}
714
-test_eq name-whatis-sql-rid-none [name_sql "SELECT whatis(99999)"] \
709
+ [fossil_sql "SELECT whatis($nameRidC1)"] \
710
+ [list "\{\"rid\":$nameRidC1,\"artifact\":\"$nameC1\"" \
711
+ "\"comment\":\"c1\"\}"]]}
712
+test_eq name-whatis-sql-rid-none [fossil_sql "SELECT whatis(99999)"] \
715713
"\{\"rid\":99999,\"artifact\":null\}"
716
-test_eq name-whatis-sql-other [name_sql "SELECT typeof(whatis(1.5))"] null
714
+test_eq name-whatis-sql-other [fossil_sql "SELECT typeof(whatis(1.5))"] null
717715
718716
###############################################################################
719717
# Other commands that take a name.
720718
721719
fossil test-name-to-id --type ci $nameCtwin
@@ -788,13 +786,19 @@
788786
789787
# One line for each artifact.
790788
fossil test-describe-artifacts
791789
set nameAll $RESULT
792790
test_eq name-command-describe [name_missing $nameAll [list \
793
- " [string range $nameC0 0 15] check-in to trunk by alice on 2025-01-01 00:00 " \
794
- " [string range $nameB3 0 15] check-in to br by alice on 2025-01-07 10:00 " \
795
- " [string range $namePriv 0 15] check-in to private by alice on 2025-01-07 09:00 (private)" \
791
+ [join [list \
792
+ " [string range $nameC0 0 15] check-in to trunk by alice " \
793
+ "on 2025-01-01 00:00 "] ""] \
794
+ [join [list \
795
+ " [string range $nameB3 0 15] check-in to br by alice on " \
796
+ "2025-01-07 10:00 "] ""] \
797
+ [join [list \
798
+ " [string range $namePriv 0 15] check-in to private by " \
799
+ "alice on 2025-01-07 09:00 (private)"] ""] \
796800
" [string range $nameP 0 15] file p.txt " \
797801
" [string range $nameG1 0 15] tag [string range $nameC1 0 15] " \
798802
" [string range $nameCluster 0 15] cluster " \
799803
" [string range $nameT1 0 15] ticket [string range $nameTktLike 0 20] " \
800804
" [string range $nameW3 0 15] wiki \"Orphan\" " \
@@ -804,14 +808,18 @@
804808
" [string range $nameF1 0 15] forum-post [string range $nameF1 0 13] " \
805809
" [string range $nameSha1 0 15] unknown " \
806810
" [string range $nameGhostParent 0 15] parent of check-in $nameW3" \
807811
" [string range $nameGhostMerge 0 15] merge parent of check-in $nameSide" \
808812
" [string range $nameGhostFile 0 15] file lost.txt " \
809
- " [string range $nameGhostTarget 0 15] check-in referenced by \"sym-ghost\" tag $nameG2" \
810
- " [string range $nameGhostMember 0 15] referenced by cluster $nameCluster"]] {}
813
+ [join [list \
814
+ " [string range $nameGhostTarget 0 15] check-in referenced " \
815
+ "by \"sym-ghost\" tag $nameG2"] ""] \
816
+ [join [list \
817
+ " [string range $nameGhostMember 0 15] referenced by " \
818
+ "cluster $nameCluster"] ""]]] {}
811819
test_eq name-command-describe-count [llength [split $nameAll \n]] \
812
- [name_sql "SELECT count(*) FROM blob"]
820
+ [fossil_sql "SELECT count(*) FROM blob"]
813821
fossil test-describe-artifacts --from 3 --count 2
814822
test_eq name-command-describe-range [llength [split $RESULT \n]] 2
815823
fossil test-unsent
816824
test name-command-unsent {[holds_strings $RESULT [list \
817825
" [string range $nameC1 0 15] check-in to trunk" \
@@ -837,11 +845,11 @@
837845
fossil test-whatis-all
838846
test name-command-whatis-all {[holds_strings $RESULT [list \
839847
"artifact: $nameC0 (1)" "artifact: $nameF1 (" \
840848
"file: q.txt" [string repeat - 79]]]
841849
&& [regexp -all {artifact: } $RESULT]
842
- == [name_sql "SELECT count(*) FROM blob WHERE size>=0"]}
850
+ == [fossil_sql "SELECT count(*) FROM blob WHERE size>=0"]}
843851
844852
# A repository with no phantoms.
845853
fossil new nophantom.fossil
846854
fossil test-phantoms -R nophantom.fossil --count
847855
test_eq name-command-phantoms-count-none $RESULT ""
@@ -865,15 +873,11 @@
865873
lappend options --localauth
866874
} elseif {$caps ne $nameCapsNow} {
867875
fossil sql -R $nameWeb "UPDATE user SET cap='$caps' WHERE login='nobody'"
868876
set nameCapsNow $caps
869877
}
870
- write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n"
871
- file delete reply.txt
872
- fossil_raw http $nameWeb --in request.txt --out reply.txt {*}$options
873
- if {[file exists reply.txt]} { return [read_file reply.txt] }
874
- return ""
878
+ return [fossil_http $nameWeb [request_get $path] {*}$options]
875879
}
876880
877881
# Test NAME passes if the reply to a request for PATH holds every string
878882
# in WANTED and none of those that begin with "!".
879883
#
@@ -989,11 +993,12 @@
989993
"!occurring around"] admin
990994
name_page timeline-back-to /timeline?p=tip&bt=rel1 [list "HTTP/1.0 200 OK" \
991995
c2 "!initial empty check-in"] admin
992996
name_page timeline-back-to-tag /timeline?p=tip&bt=tag:rel1 [list \
993997
"HTTP/1.0 200 OK" c2 "!initial empty check-in"] admin
994
-name_page timeline-back-to-hash "/timeline?p=tip&bt=[string range $nameC2 0 9]" \
998
+name_page timeline-back-to-hash \
999
+ "/timeline?p=tip&bt=[string range $nameC2 0 9]" \
9951000
[list "HTTP/1.0 200 OK" b1 "!>c1<"] admin
9961001
name_page timeline-forward-to /timeline?d=rel1&ft=br [list "HTTP/1.0 200 OK" \
9971002
"descendants of" ">br</a>"] admin
9981003
name_page timeline-forward-to-tag /timeline?d=rel1&ft=tag:br [list \
9991004
"HTTP/1.0 200 OK" "descendants of" ">tag:br</a>"] admin
@@ -1009,12 +1014,12 @@
10091014
10101015
###############################################################################
10111016
# Pages that list artifacts.
10121017
10131018
set nameHead {<tr><th>RID<th>Hash<th>Received<th>Description<th>Ref<th>Remarks}
1014
-set nameRidMax [name_sql "SELECT max(rid) FROM blob"]
1015
-set nameRidDelta [name_sql "SELECT rid FROM delta LIMIT 1"]
1019
+set nameRidMax [fossil_sql "SELECT max(rid) FROM blob"]
1020
+set nameRidDelta [fossil_sql "SELECT rid FROM delta LIMIT 1"]
10161021
10171022
# What each kind of user is shown.
10181023
foreach {nameCase namePath nameCaps nameWant} [list \
10191024
bloblist-admin /bloblist admin \
10201025
[list "HTTP/1.0 200 OK" $nameHead \
@@ -1045,20 +1050,22 @@
10451050
"<a href=\"/bloblist?s=1&amp;n=10\">\n1..10</a>" \
10461051
"<a href=\"/bloblist?s=11&amp;n=10\">\n11..20</a>" \
10471052
"..$nameRidMax</a>" "250 most recent</a>" "All unclustered</a>" \
10481053
"!$nameHead" "!href=\"bloblist\">"] \
10491054
bloblist-range /bloblist?s=11&n=10 admin \
1050
- [list $nameHead "<td align=\"right\">11</td>" "<td align=\"right\">20</td>" \
1055
+ [list $nameHead "<td align=\"right\">11</td>" \
1056
+ "<td align=\"right\">20</td>" \
10511057
"!<td align=\"right\">10</td>" "!<td align=\"right\">21</td>" \
10521058
"href=\"bloblist\">"] \
10531059
bloblist-private /bloblist?priv admin \
10541060
[list "<h2>Private Artifacts</h2>" "check-in to private" "file h.txt" \
10551061
"!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?priv\">"] \
10561062
bloblist-private-short /bloblist?priv&n=10 admin \
10571063
[list "<h2>Private Artifacts</h2>" "!Select a range"] \
10581064
bloblist-phantoms /bloblist?phan admin \
1059
- [list "<h2>Phantom Artifacts</h2>" "<td align=\"left\">parent of check-in</td>" \
1065
+ [list "<h2>Phantom Artifacts</h2>" \
1066
+ "<td align=\"left\">parent of check-in</td>" \
10601067
"<a href=\"/info/[string range $nameW3 0 15]\">" \
10611068
"<td align=\"left\">file lost.txt</td>\n<td>&nbsp;\n<td>&nbsp;\n</tr>" \
10621069
"!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?phan\">"] \
10631070
bloblist-phantoms-short /bloblist?phan&n=10 admin \
10641071
[list "<h2>Phantom Artifacts</h2>" "!Select a range"] \
@@ -1114,21 +1121,27 @@
11141121
[list "Delta Chain Containing Artifact 0"] \
11151122
delta-chain-no-read /deltachain/1 {} \
11161123
[list "HTTP/1.0 302 Moved Temporarily" "/login?g=deltachain"] \
11171124
collisions /hash-collisions admin \
11181125
[list "<h1>Hash Prefix Collisions on Check-ins</h1>" \
1119
- "<p>Collisions of length 4:\n<a href=\"/ambiguous/$nameCtwin\">$nameCtwin</a>" \
1126
+ [join [list \
1127
+ "<p>Collisions of length 4:\n" \
1128
+ "<a href=\"/ambiguous/$nameCtwin\">$nameCtwin</a>"] ""] \
11201129
"<h1>Hash Prefix Collisions on All Artifacts</h1>" \
1121
- "<p>Collisions of length 5:\n<a href=\"/ambiguous/$nameTwin\">$nameTwin</a>" \
1130
+ [join [list \
1131
+ "<p>Collisions of length 5:\n" \
1132
+ "<a href=\"/ambiguous/$nameTwin\">$nameTwin</a>"] ""] \
11221133
"<a href=\"/ambiguous/$nameWtwin\">$nameWtwin</a>" \
11231134
"<p>Total number of hashes: [expr {$nameRidMax}]</p>" \
11241135
"!First 25 collisions"] \
11251136
collisions-no-read /hash-collisions {} \
11261137
[list "HTTP/1.0 302 Moved Temporarily" "/login?g=hash-collisions"] \
11271138
clusters-admin /clusterlist admin \
11281139
[list "<th>Compressed&nbsp;Size\n<th>User<th>IP-Address" \
1129
- "<tr><td align=\"right\">1\n<td><a href=\"/info/[string range $nameCluster 0 9]\">" \
1140
+ [join [list \
1141
+ "<tr><td align=\"right\">1\n" \
1142
+ "<td><a href=\"/info/[string range $nameCluster 0 9]\">"] ""] \
11301143
"<td>alice\n<td>&nbsp;\n</tr>" "Total size of all clusters: " \
11311144
"href=\"rcvfromlist\">" "href=\"artifact_stats\">"] \
11321145
clusters-reader /clusterlist gjorz \
11331146
[list "<th>Compressed&nbsp;Size\n<tr>" "!<td>alice" \
11341147
"!href=\"rcvfromlist\">" "!href=\"artifact_stats\">"] \
11351148
--- test/name.test
+++ test/name.test
@@ -6,15 +6,12 @@
6 # hashes begin alike. Every kind of name is then given to
7 # "fossil test-name-to-id", "fossil whatis" and other commands, and to
8 # web pages through "fossil http --in".
9 #
10
11 # These tests run only in a long pass: -assurance stress.
12 if {[test_assurance] ne "stress"} {
13 test_skip "runs only with -assurance stress"
14 }
15
16 require_no_open_checkout
17
18 test_setup ""
19
20 set nameRepo [file join [pwd] name.fossil]
@@ -21,22 +18,14 @@
21 fossil new --admin-user alice --date-override "2025-01-01 00:00:00" $nameRepo
22 fossil open $nameRepo
23 fossil user default alice
24 fossil set mtime-changes off
25
26 # The answer of one SQL statement, trimmed.
27 #
28 proc name_sql {sql} {
29 global RESULT
30 fossil sql $sql
31 return [string trim $RESULT]
32 }
33
34 # The hash of the check-in whose comment is COMMENT.
35 #
36 proc name_checkin {comment} {
37 return [name_sql "SELECT uuid FROM event, blob
38 WHERE objid=rid AND type='ci' AND comment='$comment'"]
39 }
40
41 # Check in the checkout as it stands with COMMENT and DATE. ARGS are
42 # more options. Return the hash of the check-in.
@@ -64,11 +53,11 @@
64 puts -nonewline $fd "Z $sum\n"
65 close $fd
66 fossil test-content-put --crosslink $fn
67 file delete $fn
68 if {![regexp {inserted as record (\d+)} $RESULT all rid]} { return "" }
69 return [name_sql "SELECT uuid FROM blob WHERE rid=$rid"]
70 }
71
72 # The strings in WANTED that TEXT does not hold, and those that begin
73 # with "!" that it does hold.
74 #
@@ -105,11 +94,11 @@
105 # 2025-01-06 b2 br, with c3 merged in
106 # 2025-01-07 b3 br
107 #
108 # The checkout is left at c2.
109
110 set nameC0 [name_sql "SELECT uuid FROM event, blob
111 WHERE objid=rid AND type='ci'"]
112
113 # The hashes of p.txt and q.txt begin with the same five characters.
114 write_file f.txt "one\n"
115 write_file p.txt "name collide 1177\n"
@@ -153,11 +142,11 @@
153 --user-override alice
154 fossil tag add gone $nameC1 --date-override "2025-01-08 11:00:00" \
155 --user-override alice
156 fossil tag cancel gone $nameC1 --date-override "2025-01-08 12:00:00" \
157 --user-override alice
158 set nameG1 [name_sql "SELECT uuid FROM event, blob
159 WHERE objid=rid AND type='g' AND comment LIKE '%\"decade\"%'"]
160
161 test name-setup-checkins {[llength [lsort -unique [list $nameC0 $nameC1 \
162 $nameC2 $nameC3 $nameB1 $nameB2 $nameB3 $nameG1]]] == 8
163 && [string length $nameG1] == 64}
@@ -324,13 +313,13 @@
324 $nameGhostMember]] "\nM "]\n"]
325
326 test name-setup-more {[llength [lsort -unique [list $namePriv $nameA1 \
327 $nameA2 $nameW3 $nameSide $nameG2 $nameCluster $nameAtt1 $nameAtt2]]] == 9
328 && [string length $nameCluster] == 64 && [string length $nameSha1] == 40
329 && [name_sql "SELECT count(*) FROM phantom"] == 5
330 && [name_sql "SELECT count(*) FROM delta"] > 0
331 && [name_sql "SELECT count(*) FROM blob WHERE uuid='$nameSha1'"] == 1}
332
333 test name-setup-artifacts {[llength [lsort -unique [list $nameW1 $nameW2 \
334 $nameT1 $nameT2 $nameE1 $nameE2 $nameF1]]] == 7
335 && [string length $nameF1] == 64}
336
@@ -343,11 +332,12 @@
343 tip-wiki tip w {ERROR: cannot resolve name: tip} \
344 current current {} $nameC2 \
345 prev prev {} $nameC1 \
346 previous previous ci $nameC1 \
347 next next {} $nameC3 \
348 current-wiki current w {ERROR: cannot resolve name: current} \
 
349 ckout ckout ci+ $nameC2 \
350 ckout-ci ckout ci {ERROR: cannot resolve name: ckout} \
351 ckout-any ckout {} {ERROR: cannot resolve name: ckout} \
352 current-ciplus current ci+ $nameC2 \
353 trunk-ciplus trunk ci+ $nameC3 \
@@ -358,11 +348,12 @@
358 tag-prefix tag:rel1 {} $nameC1 \
359 tag-hex decade {} $nameC1 \
360 tag-hex-prefix tag:decade {} $nameC1 \
361 tag-start tag:br br $nameB1 \
362 tag-cancelled gone {} {ERROR: cannot resolve name: gone} \
363 tag-none tag:nosuch {} {ERROR: cannot resolve name: tag:nosuch} \
 
364 tag-empty tag: {} {ERROR: cannot resolve name: tag:} \
365 tag-percent tag:% {} {ERROR: cannot resolve name: tag:%} \
366 tag-underscore re_1 {} {ERROR: cannot resolve name: re_1} \
367 tag-star rel* {} {ERROR: cannot resolve name: rel*} \
368 tag-wiki-type rel1 w {ERROR: cannot resolve name: rel1} \
@@ -374,17 +365,24 @@
374 merge-in-trunk merge-in:trunk {} $nameC3 \
375 root-first root:$nameC0 {} $nameC0 \
376 merge-in-first merge-in:$nameC0 {} $nameC0 \
377 merge-in-plain merge-in:$nameB1 {} $nameC2 \
378 root-of-root root:root:br {} $nameC0 \
379 root-none root:nosuch {} {ERROR: cannot resolve name: root:nosuch} \
380 start-none start:nosuch {} {ERROR: cannot resolve name: start:nosuch} \
381 merge-in-none merge-in:nosuch {} {ERROR: cannot resolve name: merge-in:nosuch} \
 
 
 
382 root-empty root: {} {ERROR: cannot resolve name: root:} \
383 ] {
384 test_eq name-checkin-$nameCase [name_id $nameName $nameType] $nameWant
385 }
 
 
 
 
386
387 ###############################################################################
388 # Dates. The timeline of the repository is in UTC. A date names the
389 # latest artifact of the wanted kind at or before the end of the day,
390 # minute, second or millisecond given.
@@ -478,11 +476,10 @@
478 ###############################################################################
479 # Hashes and their beginnings, tags that look like hashes, record
480 # numbers, and names with punctuation after them.
481
482 set nameC1x [string range $nameC1 0 9]
483 set nameNone {ERROR: cannot resolve name: }
484 set nameTwice {ERROR: ambiguous name: }
485 foreach {nameCase nameName nameType nameWant} [list \
486 full $nameC1 {} $nameC1 \
487 prefix $nameC1x {} $nameC1 \
488 upper [string toupper $nameC1x] {} $nameC1 \
@@ -508,11 +505,10 @@
508 ticket [string range $nameT1 0 9] t $nameT1 \
509 technote [string range $nameE1 0 9] e $nameE1 \
510 forum [string range $nameF1 0 9] f $nameF1 \
511 tag-change [string range $nameG1 0 9] g $nameG1 \
512 tag-change-ci [string range $nameG1 0 9] ci - \
513 empty-type $nameC1x "" $nameC1 \
514 type-cx $nameC1x cx - \
515 tip-type-cx tip cx - \
516 rid rid:1 {} $nameC0 \
517 rid-ci rid:1 ci $nameC0 \
518 rid-wiki rid:1 w - \
@@ -537,11 +533,11 @@
537 dash - {} - \
538 long [string repeat x 5000] {} - \
539 long-colons [string repeat : 5000] {} - \
540 long-date date:[string repeat 9 5000] {} - \
541 ] {
542 if {$nameWant eq "-"} { set nameWant $nameNone$nameName }
543 if {$nameWant eq "="} { set nameWant $nameTwice$nameName }
544 test_eq name-hash-$nameCase [name_id $nameName $nameType] $nameWant
545 }
546
547 ###############################################################################
@@ -557,20 +553,20 @@
557 }
558
559 fossil whatis tip
560 test_eq name-whatis-checkin $RESULT "name: tip
561 artifact: $nameB3
562 size: [name_sql "SELECT size FROM blob WHERE uuid='$nameB3'"] bytes
563 tags: br
564 type: Check-in by alice on 2025-01-07 10:00:00
565 comment: b3"
566 fossil whatis -h tip
567 test_eq name-whatis-hash-only $RESULT $nameB3
568 fossil whatis -v -h tip
569 test_eq name-whatis-hash-only-verbose $RESULT $nameB3
570
571 set nameRidC1 [name_sql "SELECT rid FROM blob WHERE uuid='$nameC1'"]
572 name_whatis verbose [list "artifact: $nameC1 ($nameRidC1)" \
573 "received: " "tags: decade, rel, rel1, trunk"] -v rel1
574 name_whatis raw-tags [list "tags: twins" "closed, hidden" \
575 "Check-in by alice on 2025-01-06 13:00:00"] $nameCa
576 name_whatis private [list "tags: private" "comment: hidden"] $namePriv
@@ -583,18 +579,18 @@
583 name_whatis ticket-change [list "type: Ticket-change by alice on" \
584 "ticket-id: $nameTktLike"] $nameT1
585 name_whatis file [list "file: p.txt" \
586 "part of \[[string range $nameC1 0 9]\] on branch trunk by alice on"] $nameP
587 name_whatis file-on-branch [list "file: f.txt" "on branch br by alice" \
588 "!on branch trunk"] [name_sql "SELECT uuid FROM blob, mlink
589 WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$nameB1')"]
590 name_whatis attachment-wiki [list "attachment: att1.txt" \
591 "attached to wiki WikiOne" "via $nameA1\n" \
592 "by user alice on 2025-01-13 10:00:00" "on the page"] $nameAtt1
593 name_whatis attachment-ticket [list "attachment: att2.txt" \
594 "attached to ticket $nameTktOnly" \
595 "via $nameA2 ([name_sql "SELECT rid FROM blob WHERE uuid='$nameA2'"])"] \
596 -v $nameAtt2
597 name_whatis cluster [list "artifact: $nameCluster" "cluster"] $nameCluster
598 name_whatis sha1-name [list "hash: $nameSha1 (ambiguous)" \
599 "artifact: $nameSha1" "artifact: $nameT3"] $nameSha1
600
@@ -644,11 +640,12 @@
644 # The file named, not the artifact named.
645 name_whatis by-file [list "name: f.txt" "file: f.txt" \
646 "on branch trunk"] -f f.txt
647 name_whatis by-file-unknown [list "name: name.fossil" "unknown: "] \
648 -f name.fossil
649 name_whatis by-file-sha1 [list "name: sha1.txt\nhash: $nameSha1 (ambiguous)" \
 
650 "artifact: $nameSha1" "artifact: $nameT3"] -f sha1.txt
651 name_whatis by-file-twin [list "name: p.txt" "artifact: $nameP" \
652 "!ambiguous"] -f p.txt
653 fossil whatis -f nosuchfile -expectError
654 test name-whatis-by-file-missing {[string match "*no such file*" $RESULT]}
@@ -704,18 +701,19 @@
704 [list "\"comment\":\"b3\"\}\n[string repeat - 79]\n\{\"unknown\""] \
705 ] {
706 name_whatis json-$nameCase $nameWant --json {*}$nameArgs
707 }
708
709 test_eq name-whatis-sql-name [name_sql "SELECT whatis('nosuch')"] \
710 "\{\"unknown\":\"nosuch\"\}"
711 test name-whatis-sql-rid {[holds_strings \
712 [name_sql "SELECT whatis($nameRidC1)"] \
713 [list "\{\"rid\":$nameRidC1,\"artifact\":\"$nameC1\"" "\"comment\":\"c1\"\}"]]}
714 test_eq name-whatis-sql-rid-none [name_sql "SELECT whatis(99999)"] \
 
715 "\{\"rid\":99999,\"artifact\":null\}"
716 test_eq name-whatis-sql-other [name_sql "SELECT typeof(whatis(1.5))"] null
717
718 ###############################################################################
719 # Other commands that take a name.
720
721 fossil test-name-to-id --type ci $nameCtwin
@@ -788,13 +786,19 @@
788
789 # One line for each artifact.
790 fossil test-describe-artifacts
791 set nameAll $RESULT
792 test_eq name-command-describe [name_missing $nameAll [list \
793 " [string range $nameC0 0 15] check-in to trunk by alice on 2025-01-01 00:00 " \
794 " [string range $nameB3 0 15] check-in to br by alice on 2025-01-07 10:00 " \
795 " [string range $namePriv 0 15] check-in to private by alice on 2025-01-07 09:00 (private)" \
 
 
 
 
 
 
796 " [string range $nameP 0 15] file p.txt " \
797 " [string range $nameG1 0 15] tag [string range $nameC1 0 15] " \
798 " [string range $nameCluster 0 15] cluster " \
799 " [string range $nameT1 0 15] ticket [string range $nameTktLike 0 20] " \
800 " [string range $nameW3 0 15] wiki \"Orphan\" " \
@@ -804,14 +808,18 @@
804 " [string range $nameF1 0 15] forum-post [string range $nameF1 0 13] " \
805 " [string range $nameSha1 0 15] unknown " \
806 " [string range $nameGhostParent 0 15] parent of check-in $nameW3" \
807 " [string range $nameGhostMerge 0 15] merge parent of check-in $nameSide" \
808 " [string range $nameGhostFile 0 15] file lost.txt " \
809 " [string range $nameGhostTarget 0 15] check-in referenced by \"sym-ghost\" tag $nameG2" \
810 " [string range $nameGhostMember 0 15] referenced by cluster $nameCluster"]] {}
 
 
 
 
811 test_eq name-command-describe-count [llength [split $nameAll \n]] \
812 [name_sql "SELECT count(*) FROM blob"]
813 fossil test-describe-artifacts --from 3 --count 2
814 test_eq name-command-describe-range [llength [split $RESULT \n]] 2
815 fossil test-unsent
816 test name-command-unsent {[holds_strings $RESULT [list \
817 " [string range $nameC1 0 15] check-in to trunk" \
@@ -837,11 +845,11 @@
837 fossil test-whatis-all
838 test name-command-whatis-all {[holds_strings $RESULT [list \
839 "artifact: $nameC0 (1)" "artifact: $nameF1 (" \
840 "file: q.txt" [string repeat - 79]]]
841 && [regexp -all {artifact: } $RESULT]
842 == [name_sql "SELECT count(*) FROM blob WHERE size>=0"]}
843
844 # A repository with no phantoms.
845 fossil new nophantom.fossil
846 fossil test-phantoms -R nophantom.fossil --count
847 test_eq name-command-phantoms-count-none $RESULT ""
@@ -865,15 +873,11 @@
865 lappend options --localauth
866 } elseif {$caps ne $nameCapsNow} {
867 fossil sql -R $nameWeb "UPDATE user SET cap='$caps' WHERE login='nobody'"
868 set nameCapsNow $caps
869 }
870 write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n"
871 file delete reply.txt
872 fossil_raw http $nameWeb --in request.txt --out reply.txt {*}$options
873 if {[file exists reply.txt]} { return [read_file reply.txt] }
874 return ""
875 }
876
877 # Test NAME passes if the reply to a request for PATH holds every string
878 # in WANTED and none of those that begin with "!".
879 #
@@ -989,11 +993,12 @@
989 "!occurring around"] admin
990 name_page timeline-back-to /timeline?p=tip&bt=rel1 [list "HTTP/1.0 200 OK" \
991 c2 "!initial empty check-in"] admin
992 name_page timeline-back-to-tag /timeline?p=tip&bt=tag:rel1 [list \
993 "HTTP/1.0 200 OK" c2 "!initial empty check-in"] admin
994 name_page timeline-back-to-hash "/timeline?p=tip&bt=[string range $nameC2 0 9]" \
 
995 [list "HTTP/1.0 200 OK" b1 "!>c1<"] admin
996 name_page timeline-forward-to /timeline?d=rel1&ft=br [list "HTTP/1.0 200 OK" \
997 "descendants of" ">br</a>"] admin
998 name_page timeline-forward-to-tag /timeline?d=rel1&ft=tag:br [list \
999 "HTTP/1.0 200 OK" "descendants of" ">tag:br</a>"] admin
@@ -1009,12 +1014,12 @@
1009
1010 ###############################################################################
1011 # Pages that list artifacts.
1012
1013 set nameHead {<tr><th>RID<th>Hash<th>Received<th>Description<th>Ref<th>Remarks}
1014 set nameRidMax [name_sql "SELECT max(rid) FROM blob"]
1015 set nameRidDelta [name_sql "SELECT rid FROM delta LIMIT 1"]
1016
1017 # What each kind of user is shown.
1018 foreach {nameCase namePath nameCaps nameWant} [list \
1019 bloblist-admin /bloblist admin \
1020 [list "HTTP/1.0 200 OK" $nameHead \
@@ -1045,20 +1050,22 @@
1045 "<a href=\"/bloblist?s=1&amp;n=10\">\n1..10</a>" \
1046 "<a href=\"/bloblist?s=11&amp;n=10\">\n11..20</a>" \
1047 "..$nameRidMax</a>" "250 most recent</a>" "All unclustered</a>" \
1048 "!$nameHead" "!href=\"bloblist\">"] \
1049 bloblist-range /bloblist?s=11&n=10 admin \
1050 [list $nameHead "<td align=\"right\">11</td>" "<td align=\"right\">20</td>" \
 
1051 "!<td align=\"right\">10</td>" "!<td align=\"right\">21</td>" \
1052 "href=\"bloblist\">"] \
1053 bloblist-private /bloblist?priv admin \
1054 [list "<h2>Private Artifacts</h2>" "check-in to private" "file h.txt" \
1055 "!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?priv\">"] \
1056 bloblist-private-short /bloblist?priv&n=10 admin \
1057 [list "<h2>Private Artifacts</h2>" "!Select a range"] \
1058 bloblist-phantoms /bloblist?phan admin \
1059 [list "<h2>Phantom Artifacts</h2>" "<td align=\"left\">parent of check-in</td>" \
 
1060 "<a href=\"/info/[string range $nameW3 0 15]\">" \
1061 "<td align=\"left\">file lost.txt</td>\n<td>&nbsp;\n<td>&nbsp;\n</tr>" \
1062 "!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?phan\">"] \
1063 bloblist-phantoms-short /bloblist?phan&n=10 admin \
1064 [list "<h2>Phantom Artifacts</h2>" "!Select a range"] \
@@ -1114,21 +1121,27 @@
1114 [list "Delta Chain Containing Artifact 0"] \
1115 delta-chain-no-read /deltachain/1 {} \
1116 [list "HTTP/1.0 302 Moved Temporarily" "/login?g=deltachain"] \
1117 collisions /hash-collisions admin \
1118 [list "<h1>Hash Prefix Collisions on Check-ins</h1>" \
1119 "<p>Collisions of length 4:\n<a href=\"/ambiguous/$nameCtwin\">$nameCtwin</a>" \
 
 
1120 "<h1>Hash Prefix Collisions on All Artifacts</h1>" \
1121 "<p>Collisions of length 5:\n<a href=\"/ambiguous/$nameTwin\">$nameTwin</a>" \
 
 
1122 "<a href=\"/ambiguous/$nameWtwin\">$nameWtwin</a>" \
1123 "<p>Total number of hashes: [expr {$nameRidMax}]</p>" \
1124 "!First 25 collisions"] \
1125 collisions-no-read /hash-collisions {} \
1126 [list "HTTP/1.0 302 Moved Temporarily" "/login?g=hash-collisions"] \
1127 clusters-admin /clusterlist admin \
1128 [list "<th>Compressed&nbsp;Size\n<th>User<th>IP-Address" \
1129 "<tr><td align=\"right\">1\n<td><a href=\"/info/[string range $nameCluster 0 9]\">" \
 
 
1130 "<td>alice\n<td>&nbsp;\n</tr>" "Total size of all clusters: " \
1131 "href=\"rcvfromlist\">" "href=\"artifact_stats\">"] \
1132 clusters-reader /clusterlist gjorz \
1133 [list "<th>Compressed&nbsp;Size\n<tr>" "!<td>alice" \
1134 "!href=\"rcvfromlist\">" "!href=\"artifact_stats\">"] \
1135
--- test/name.test
+++ test/name.test
@@ -6,15 +6,12 @@
6 # hashes begin alike. Every kind of name is then given to
7 # "fossil test-name-to-id", "fossil whatis" and other commands, and to
8 # web pages through "fossil http --in".
9 #
10
11 # The first sections run at every level, and the rest need
12 # -assurance stress.
 
 
 
13 require_no_open_checkout
14
15 test_setup ""
16
17 set nameRepo [file join [pwd] name.fossil]
@@ -21,22 +18,14 @@
18 fossil new --admin-user alice --date-override "2025-01-01 00:00:00" $nameRepo
19 fossil open $nameRepo
20 fossil user default alice
21 fossil set mtime-changes off
22
 
 
 
 
 
 
 
 
23 # The hash of the check-in whose comment is COMMENT.
24 #
25 proc name_checkin {comment} {
26 return [fossil_sql "SELECT uuid FROM event, blob
27 WHERE objid=rid AND type='ci' AND comment='$comment'"]
28 }
29
30 # Check in the checkout as it stands with COMMENT and DATE. ARGS are
31 # more options. Return the hash of the check-in.
@@ -64,11 +53,11 @@
53 puts -nonewline $fd "Z $sum\n"
54 close $fd
55 fossil test-content-put --crosslink $fn
56 file delete $fn
57 if {![regexp {inserted as record (\d+)} $RESULT all rid]} { return "" }
58 return [fossil_sql "SELECT uuid FROM blob WHERE rid=$rid"]
59 }
60
61 # The strings in WANTED that TEXT does not hold, and those that begin
62 # with "!" that it does hold.
63 #
@@ -105,11 +94,11 @@
94 # 2025-01-06 b2 br, with c3 merged in
95 # 2025-01-07 b3 br
96 #
97 # The checkout is left at c2.
98
99 set nameC0 [fossil_sql "SELECT uuid FROM event, blob
100 WHERE objid=rid AND type='ci'"]
101
102 # The hashes of p.txt and q.txt begin with the same five characters.
103 write_file f.txt "one\n"
104 write_file p.txt "name collide 1177\n"
@@ -153,11 +142,11 @@
142 --user-override alice
143 fossil tag add gone $nameC1 --date-override "2025-01-08 11:00:00" \
144 --user-override alice
145 fossil tag cancel gone $nameC1 --date-override "2025-01-08 12:00:00" \
146 --user-override alice
147 set nameG1 [fossil_sql "SELECT uuid FROM event, blob
148 WHERE objid=rid AND type='g' AND comment LIKE '%\"decade\"%'"]
149
150 test name-setup-checkins {[llength [lsort -unique [list $nameC0 $nameC1 \
151 $nameC2 $nameC3 $nameB1 $nameB2 $nameB3 $nameG1]]] == 8
152 && [string length $nameG1] == 64}
@@ -324,13 +313,13 @@
313 $nameGhostMember]] "\nM "]\n"]
314
315 test name-setup-more {[llength [lsort -unique [list $namePriv $nameA1 \
316 $nameA2 $nameW3 $nameSide $nameG2 $nameCluster $nameAtt1 $nameAtt2]]] == 9
317 && [string length $nameCluster] == 64 && [string length $nameSha1] == 40
318 && [fossil_sql "SELECT count(*) FROM phantom"] == 5
319 && [fossil_sql "SELECT count(*) FROM delta"] > 0
320 && [fossil_sql "SELECT count(*) FROM blob WHERE uuid='$nameSha1'"] == 1}
321
322 test name-setup-artifacts {[llength [lsort -unique [list $nameW1 $nameW2 \
323 $nameT1 $nameT2 $nameE1 $nameE2 $nameF1]]] == 7
324 && [string length $nameF1] == 64}
325
@@ -343,11 +332,12 @@
332 tip-wiki tip w {ERROR: cannot resolve name: tip} \
333 current current {} $nameC2 \
334 prev prev {} $nameC1 \
335 previous previous ci $nameC1 \
336 next next {} $nameC3 \
337 current-wiki current w \
338 {ERROR: cannot resolve name: current} \
339 ckout ckout ci+ $nameC2 \
340 ckout-ci ckout ci {ERROR: cannot resolve name: ckout} \
341 ckout-any ckout {} {ERROR: cannot resolve name: ckout} \
342 current-ciplus current ci+ $nameC2 \
343 trunk-ciplus trunk ci+ $nameC3 \
@@ -358,11 +348,12 @@
348 tag-prefix tag:rel1 {} $nameC1 \
349 tag-hex decade {} $nameC1 \
350 tag-hex-prefix tag:decade {} $nameC1 \
351 tag-start tag:br br $nameB1 \
352 tag-cancelled gone {} {ERROR: cannot resolve name: gone} \
353 tag-none tag:nosuch {} \
354 {ERROR: cannot resolve name: tag:nosuch} \
355 tag-empty tag: {} {ERROR: cannot resolve name: tag:} \
356 tag-percent tag:% {} {ERROR: cannot resolve name: tag:%} \
357 tag-underscore re_1 {} {ERROR: cannot resolve name: re_1} \
358 tag-star rel* {} {ERROR: cannot resolve name: rel*} \
359 tag-wiki-type rel1 w {ERROR: cannot resolve name: rel1} \
@@ -374,17 +365,24 @@
365 merge-in-trunk merge-in:trunk {} $nameC3 \
366 root-first root:$nameC0 {} $nameC0 \
367 merge-in-first merge-in:$nameC0 {} $nameC0 \
368 merge-in-plain merge-in:$nameB1 {} $nameC2 \
369 root-of-root root:root:br {} $nameC0 \
370 root-none root:nosuch {} \
371 {ERROR: cannot resolve name: root:nosuch} \
372 start-none start:nosuch {} \
373 {ERROR: cannot resolve name: start:nosuch} \
374 merge-in-none merge-in:nosuch {} \
375 {ERROR: cannot resolve name: merge-in:nosuch} \
376 root-empty root: {} {ERROR: cannot resolve name: root:} \
377 ] {
378 test_eq name-checkin-$nameCase [name_id $nameName $nameType] $nameWant
379 }
380
381 if {[test_assurance] ne "stress"} {
382 test_skip "the tests after the first sections need -assurance stress"
383 }
384
385 ###############################################################################
386 # Dates. The timeline of the repository is in UTC. A date names the
387 # latest artifact of the wanted kind at or before the end of the day,
388 # minute, second or millisecond given.
@@ -478,11 +476,10 @@
476 ###############################################################################
477 # Hashes and their beginnings, tags that look like hashes, record
478 # numbers, and names with punctuation after them.
479
480 set nameC1x [string range $nameC1 0 9]
 
481 set nameTwice {ERROR: ambiguous name: }
482 foreach {nameCase nameName nameType nameWant} [list \
483 full $nameC1 {} $nameC1 \
484 prefix $nameC1x {} $nameC1 \
485 upper [string toupper $nameC1x] {} $nameC1 \
@@ -508,11 +505,10 @@
505 ticket [string range $nameT1 0 9] t $nameT1 \
506 technote [string range $nameE1 0 9] e $nameE1 \
507 forum [string range $nameF1 0 9] f $nameF1 \
508 tag-change [string range $nameG1 0 9] g $nameG1 \
509 tag-change-ci [string range $nameG1 0 9] ci - \
 
510 type-cx $nameC1x cx - \
511 tip-type-cx tip cx - \
512 rid rid:1 {} $nameC0 \
513 rid-ci rid:1 ci $nameC0 \
514 rid-wiki rid:1 w - \
@@ -537,11 +533,11 @@
533 dash - {} - \
534 long [string repeat x 5000] {} - \
535 long-colons [string repeat : 5000] {} - \
536 long-date date:[string repeat 9 5000] {} - \
537 ] {
538 if {$nameWant eq "-"} { set nameWant $nameNoDate$nameName }
539 if {$nameWant eq "="} { set nameWant $nameTwice$nameName }
540 test_eq name-hash-$nameCase [name_id $nameName $nameType] $nameWant
541 }
542
543 ###############################################################################
@@ -557,20 +553,20 @@
553 }
554
555 fossil whatis tip
556 test_eq name-whatis-checkin $RESULT "name: tip
557 artifact: $nameB3
558 size: [fossil_sql "SELECT size FROM blob WHERE uuid='$nameB3'"] bytes
559 tags: br
560 type: Check-in by alice on 2025-01-07 10:00:00
561 comment: b3"
562 fossil whatis -h tip
563 test_eq name-whatis-hash-only $RESULT $nameB3
564 fossil whatis -v -h tip
565 test_eq name-whatis-hash-only-verbose $RESULT $nameB3
566
567 set nameRidC1 [fossil_sql "SELECT rid FROM blob WHERE uuid='$nameC1'"]
568 name_whatis verbose [list "artifact: $nameC1 ($nameRidC1)" \
569 "received: " "tags: decade, rel, rel1, trunk"] -v rel1
570 name_whatis raw-tags [list "tags: twins" "closed, hidden" \
571 "Check-in by alice on 2025-01-06 13:00:00"] $nameCa
572 name_whatis private [list "tags: private" "comment: hidden"] $namePriv
@@ -583,18 +579,18 @@
579 name_whatis ticket-change [list "type: Ticket-change by alice on" \
580 "ticket-id: $nameTktLike"] $nameT1
581 name_whatis file [list "file: p.txt" \
582 "part of \[[string range $nameC1 0 9]\] on branch trunk by alice on"] $nameP
583 name_whatis file-on-branch [list "file: f.txt" "on branch br by alice" \
584 "!on branch trunk"] [fossil_sql "SELECT uuid FROM blob, mlink
585 WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$nameB1')"]
586 name_whatis attachment-wiki [list "attachment: att1.txt" \
587 "attached to wiki WikiOne" "via $nameA1\n" \
588 "by user alice on 2025-01-13 10:00:00" "on the page"] $nameAtt1
589 name_whatis attachment-ticket [list "attachment: att2.txt" \
590 "attached to ticket $nameTktOnly" \
591 "via $nameA2 ([fossil_sql "SELECT rid FROM blob WHERE uuid='$nameA2'"])"] \
592 -v $nameAtt2
593 name_whatis cluster [list "artifact: $nameCluster" "cluster"] $nameCluster
594 name_whatis sha1-name [list "hash: $nameSha1 (ambiguous)" \
595 "artifact: $nameSha1" "artifact: $nameT3"] $nameSha1
596
@@ -644,11 +640,12 @@
640 # The file named, not the artifact named.
641 name_whatis by-file [list "name: f.txt" "file: f.txt" \
642 "on branch trunk"] -f f.txt
643 name_whatis by-file-unknown [list "name: name.fossil" "unknown: "] \
644 -f name.fossil
645 name_whatis by-file-sha1 [list \
646 "name: sha1.txt\nhash: $nameSha1 (ambiguous)" \
647 "artifact: $nameSha1" "artifact: $nameT3"] -f sha1.txt
648 name_whatis by-file-twin [list "name: p.txt" "artifact: $nameP" \
649 "!ambiguous"] -f p.txt
650 fossil whatis -f nosuchfile -expectError
651 test name-whatis-by-file-missing {[string match "*no such file*" $RESULT]}
@@ -704,18 +701,19 @@
701 [list "\"comment\":\"b3\"\}\n[string repeat - 79]\n\{\"unknown\""] \
702 ] {
703 name_whatis json-$nameCase $nameWant --json {*}$nameArgs
704 }
705
706 test_eq name-whatis-sql-name [fossil_sql "SELECT whatis('nosuch')"] \
707 "\{\"unknown\":\"nosuch\"\}"
708 test name-whatis-sql-rid {[holds_strings \
709 [fossil_sql "SELECT whatis($nameRidC1)"] \
710 [list "\{\"rid\":$nameRidC1,\"artifact\":\"$nameC1\"" \
711 "\"comment\":\"c1\"\}"]]}
712 test_eq name-whatis-sql-rid-none [fossil_sql "SELECT whatis(99999)"] \
713 "\{\"rid\":99999,\"artifact\":null\}"
714 test_eq name-whatis-sql-other [fossil_sql "SELECT typeof(whatis(1.5))"] null
715
716 ###############################################################################
717 # Other commands that take a name.
718
719 fossil test-name-to-id --type ci $nameCtwin
@@ -788,13 +786,19 @@
786
787 # One line for each artifact.
788 fossil test-describe-artifacts
789 set nameAll $RESULT
790 test_eq name-command-describe [name_missing $nameAll [list \
791 [join [list \
792 " [string range $nameC0 0 15] check-in to trunk by alice " \
793 "on 2025-01-01 00:00 "] ""] \
794 [join [list \
795 " [string range $nameB3 0 15] check-in to br by alice on " \
796 "2025-01-07 10:00 "] ""] \
797 [join [list \
798 " [string range $namePriv 0 15] check-in to private by " \
799 "alice on 2025-01-07 09:00 (private)"] ""] \
800 " [string range $nameP 0 15] file p.txt " \
801 " [string range $nameG1 0 15] tag [string range $nameC1 0 15] " \
802 " [string range $nameCluster 0 15] cluster " \
803 " [string range $nameT1 0 15] ticket [string range $nameTktLike 0 20] " \
804 " [string range $nameW3 0 15] wiki \"Orphan\" " \
@@ -804,14 +808,18 @@
808 " [string range $nameF1 0 15] forum-post [string range $nameF1 0 13] " \
809 " [string range $nameSha1 0 15] unknown " \
810 " [string range $nameGhostParent 0 15] parent of check-in $nameW3" \
811 " [string range $nameGhostMerge 0 15] merge parent of check-in $nameSide" \
812 " [string range $nameGhostFile 0 15] file lost.txt " \
813 [join [list \
814 " [string range $nameGhostTarget 0 15] check-in referenced " \
815 "by \"sym-ghost\" tag $nameG2"] ""] \
816 [join [list \
817 " [string range $nameGhostMember 0 15] referenced by " \
818 "cluster $nameCluster"] ""]]] {}
819 test_eq name-command-describe-count [llength [split $nameAll \n]] \
820 [fossil_sql "SELECT count(*) FROM blob"]
821 fossil test-describe-artifacts --from 3 --count 2
822 test_eq name-command-describe-range [llength [split $RESULT \n]] 2
823 fossil test-unsent
824 test name-command-unsent {[holds_strings $RESULT [list \
825 " [string range $nameC1 0 15] check-in to trunk" \
@@ -837,11 +845,11 @@
845 fossil test-whatis-all
846 test name-command-whatis-all {[holds_strings $RESULT [list \
847 "artifact: $nameC0 (1)" "artifact: $nameF1 (" \
848 "file: q.txt" [string repeat - 79]]]
849 && [regexp -all {artifact: } $RESULT]
850 == [fossil_sql "SELECT count(*) FROM blob WHERE size>=0"]}
851
852 # A repository with no phantoms.
853 fossil new nophantom.fossil
854 fossil test-phantoms -R nophantom.fossil --count
855 test_eq name-command-phantoms-count-none $RESULT ""
@@ -865,15 +873,11 @@
873 lappend options --localauth
874 } elseif {$caps ne $nameCapsNow} {
875 fossil sql -R $nameWeb "UPDATE user SET cap='$caps' WHERE login='nobody'"
876 set nameCapsNow $caps
877 }
878 return [fossil_http $nameWeb [request_get $path] {*}$options]
 
 
 
 
879 }
880
881 # Test NAME passes if the reply to a request for PATH holds every string
882 # in WANTED and none of those that begin with "!".
883 #
@@ -989,11 +993,12 @@
993 "!occurring around"] admin
994 name_page timeline-back-to /timeline?p=tip&bt=rel1 [list "HTTP/1.0 200 OK" \
995 c2 "!initial empty check-in"] admin
996 name_page timeline-back-to-tag /timeline?p=tip&bt=tag:rel1 [list \
997 "HTTP/1.0 200 OK" c2 "!initial empty check-in"] admin
998 name_page timeline-back-to-hash \
999 "/timeline?p=tip&bt=[string range $nameC2 0 9]" \
1000 [list "HTTP/1.0 200 OK" b1 "!>c1<"] admin
1001 name_page timeline-forward-to /timeline?d=rel1&ft=br [list "HTTP/1.0 200 OK" \
1002 "descendants of" ">br</a>"] admin
1003 name_page timeline-forward-to-tag /timeline?d=rel1&ft=tag:br [list \
1004 "HTTP/1.0 200 OK" "descendants of" ">tag:br</a>"] admin
@@ -1009,12 +1014,12 @@
1014
1015 ###############################################################################
1016 # Pages that list artifacts.
1017
1018 set nameHead {<tr><th>RID<th>Hash<th>Received<th>Description<th>Ref<th>Remarks}
1019 set nameRidMax [fossil_sql "SELECT max(rid) FROM blob"]
1020 set nameRidDelta [fossil_sql "SELECT rid FROM delta LIMIT 1"]
1021
1022 # What each kind of user is shown.
1023 foreach {nameCase namePath nameCaps nameWant} [list \
1024 bloblist-admin /bloblist admin \
1025 [list "HTTP/1.0 200 OK" $nameHead \
@@ -1045,20 +1050,22 @@
1050 "<a href=\"/bloblist?s=1&amp;n=10\">\n1..10</a>" \
1051 "<a href=\"/bloblist?s=11&amp;n=10\">\n11..20</a>" \
1052 "..$nameRidMax</a>" "250 most recent</a>" "All unclustered</a>" \
1053 "!$nameHead" "!href=\"bloblist\">"] \
1054 bloblist-range /bloblist?s=11&n=10 admin \
1055 [list $nameHead "<td align=\"right\">11</td>" \
1056 "<td align=\"right\">20</td>" \
1057 "!<td align=\"right\">10</td>" "!<td align=\"right\">21</td>" \
1058 "href=\"bloblist\">"] \
1059 bloblist-private /bloblist?priv admin \
1060 [list "<h2>Private Artifacts</h2>" "check-in to private" "file h.txt" \
1061 "!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?priv\">"] \
1062 bloblist-private-short /bloblist?priv&n=10 admin \
1063 [list "<h2>Private Artifacts</h2>" "!Select a range"] \
1064 bloblist-phantoms /bloblist?phan admin \
1065 [list "<h2>Phantom Artifacts</h2>" \
1066 "<td align=\"left\">parent of check-in</td>" \
1067 "<a href=\"/info/[string range $nameW3 0 15]\">" \
1068 "<td align=\"left\">file lost.txt</td>\n<td>&nbsp;\n<td>&nbsp;\n</tr>" \
1069 "!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?phan\">"] \
1070 bloblist-phantoms-short /bloblist?phan&n=10 admin \
1071 [list "<h2>Phantom Artifacts</h2>" "!Select a range"] \
@@ -1114,21 +1121,27 @@
1121 [list "Delta Chain Containing Artifact 0"] \
1122 delta-chain-no-read /deltachain/1 {} \
1123 [list "HTTP/1.0 302 Moved Temporarily" "/login?g=deltachain"] \
1124 collisions /hash-collisions admin \
1125 [list "<h1>Hash Prefix Collisions on Check-ins</h1>" \
1126 [join [list \
1127 "<p>Collisions of length 4:\n" \
1128 "<a href=\"/ambiguous/$nameCtwin\">$nameCtwin</a>"] ""] \
1129 "<h1>Hash Prefix Collisions on All Artifacts</h1>" \
1130 [join [list \
1131 "<p>Collisions of length 5:\n" \
1132 "<a href=\"/ambiguous/$nameTwin\">$nameTwin</a>"] ""] \
1133 "<a href=\"/ambiguous/$nameWtwin\">$nameWtwin</a>" \
1134 "<p>Total number of hashes: [expr {$nameRidMax}]</p>" \
1135 "!First 25 collisions"] \
1136 collisions-no-read /hash-collisions {} \
1137 [list "HTTP/1.0 302 Moved Temporarily" "/login?g=hash-collisions"] \
1138 clusters-admin /clusterlist admin \
1139 [list "<th>Compressed&nbsp;Size\n<th>User<th>IP-Address" \
1140 [join [list \
1141 "<tr><td align=\"right\">1\n" \
1142 "<td><a href=\"/info/[string range $nameCluster 0 9]\">"] ""] \
1143 "<td>alice\n<td>&nbsp;\n</tr>" "Total size of all clusters: " \
1144 "href=\"rcvfromlist\">" "href=\"artifact_stats\">"] \
1145 clusters-reader /clusterlist gjorz \
1146 [list "<th>Compressed&nbsp;Size\n<tr>" "!<td>alice" \
1147 "!href=\"rcvfromlist\">" "!href=\"artifact_stats\">"] \
1148
+72 -131
--- test/purge.test
+++ test/purge.test
@@ -3,90 +3,26 @@
33
# its graveyard, undo and obliterate, and "fossil scrub". After each the
44
# repository must still be sound, and an undo must give back exactly what
55
# was removed.
66
#
77
8
-# These tests run only in a long pass: -assurance stress.
9
-if {[test_assurance] ne "stress"} {
10
- test_skip "runs only with -assurance stress"
11
-}
12
-
8
+# The first sections run at every level, and the rest need
9
+# -assurance stress.
1310
require_no_open_checkout
1411
1512
test_setup
1613
1714
proc purge_sql {sql {repo .rep.fossil}} {
18
- fossil sql -R $repo $sql
19
- return [string trim $::RESULT]
20
-}
21
-
22
-# What a repository holds, by hash rather than by record number, so that
23
-# two states can be compared after an undo has stored content again:
24
-# the artifacts with their private flag, the timeline, the parent links,
25
-# the files of each check-in, the leaves and the tags.
26
-#
27
-proc purge_state {{repo .rep.fossil}} {
28
- return [purge_sql {
29
- SELECT 'blob', uuid, rid IN private FROM blob WHERE size>=0
30
- UNION ALL
31
- SELECT 'event', b.uuid, e.type || ' ' || ifnull(e.comment,'')
32
- FROM event e JOIN blob b ON b.rid=e.objid
33
- UNION ALL
34
- SELECT 'plink', p.uuid, c.uuid FROM plink
35
- JOIN blob p ON p.rid=plink.pid JOIN blob c ON c.rid=plink.cid
36
- UNION ALL
37
- SELECT 'mlink', m.uuid, f.uuid || ' ' || fn.name FROM mlink
38
- JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
39
- JOIN filename fn ON fn.fnid=mlink.fnid
40
- UNION ALL
41
- SELECT 'leaf', uuid, '' FROM leaf JOIN blob USING(rid)
42
- UNION ALL
43
- SELECT 'tag', b.uuid, t.tagname || '=' || ifnull(x.value,'')
44
- FROM tagxref x JOIN tag t USING(tagid) JOIN blob b ON b.rid=x.rid
45
- WHERE x.tagtype>0
46
- ORDER BY 1, 2, 3
47
- } $repo]
48
-}
49
-
50
-# The rows that are in one state and not in the other, marked "-" for
51
-# the first and "+" for the second. Empty when the two are the same.
52
-#
53
-proc purge_diff {a b} {
54
- set la [split $a \n]
55
- set lb [split $b \n]
56
- set out {}
57
- foreach x $la { if {[lsearch -exact $lb $x] < 0} { lappend out "- $x" } }
58
- foreach x $lb { if {[lsearch -exact $la $x] < 0} { lappend out "+ $x" } }
59
- return [join $out \n]
60
-}
61
-
62
-proc purge_sound {name {repo .rep.fossil}} {
63
- fossil test-integrity -R $repo
64
- test $name-integrity {$::CODE == 0}
65
- fossil test-missing -R $repo
66
- test $name-missing {$::CODE == 0}
67
-}
68
-
69
-proc purge_hash {comment} {
70
- return [purge_sql "SELECT uuid FROM blob, event
71
- WHERE objid=rid AND comment='$comment'"]
72
-}
73
-
74
-# The hash of the version of FILE in check-in CHECKIN.
75
-proc purge_file_hash {checkin file} {
76
- return [purge_sql "SELECT f.uuid FROM mlink
77
- JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
78
- JOIN filename fn ON fn.fnid=mlink.fnid
79
- WHERE m.uuid='$checkin' AND fn.name='$file'"]
15
+ return [fossil_sql $sql $repo]
8016
}
8117
8218
proc purge_commit {file content comment args} {
8319
set new [expr {![file exists $file]}]
8420
write_file $file $content
8521
if {$new} {fossil add $file}
8622
fossil commit -m $comment --no-warnings {*}$args
87
- return [purge_hash $comment]
23
+ return [checkin_hash $comment]
8824
}
8925
9026
# The number of the newest purge event.
9127
proc purge_last_event {{repo .rep.fossil}} {
9228
return [purge_sql "SELECT max(peid) FROM purgeevent" $repo]
@@ -96,11 +32,11 @@
9632
return [purge_sql "SELECT count(*) FROM blob WHERE uuid='$hash'
9733
AND size>=0" $repo]
9834
}
9935
10036
# The number of file and parent links whose artifact is not in the
101
-# repository at all. purge_state compares the links by hash, which also
37
+# repository at all. repository_state compares the links by hash, which also
10238
# shows a link to the wrong artifact.
10339
proc purge_dangling {repo} {
10440
return [purge_sql "SELECT (SELECT count(*) FROM mlink
10541
WHERE fid>0 AND fid NOT IN (SELECT rid FROM blob))
10642
+ (SELECT count(*) FROM plink
@@ -128,25 +64,25 @@
12864
fossil branch new side current
12965
fossil update side
13066
set purgeSide1 [purge_commit a.txt "${purgeTrunkText(3)}on the side\n" \
13167
purge-side-1]
13268
set purgeSide2 [purge_commit b.txt "a file only the branch has\n" purge-side-2]
133
-set purgeSideB [purge_file_hash $purgeSide2 b.txt]
69
+set purgeSideB [checkin_file_hash $purgeSide2 b.txt]
13470
fossil update trunk
13571
136
-purge_sound purge-start
137
-set purgeStart [purge_state]
72
+repository_sound purge-start
73
+set purgeStart [repository_state]
13874
file copy .rep.fossil full.fossil
13975
14076
###############################################################################
14177
# A trial run changes nothing.
14278
14379
fossil purge checkins side --explain
14480
test purge-explain {$CODE == 0}
145
-test_eq purge-explain-no-change [purge_state] $purgeStart
81
+test_eq purge-explain-no-change [repository_state] $purgeStart
14682
fossil purge checkins side --dry-run
147
-test_eq purge-dry-run-no-change [purge_state] $purgeStart
83
+test_eq purge-dry-run-no-change [repository_state] $purgeStart
14884
14985
# Either option may be given twice, or both together, with the same result.
15086
foreach {purgeName purgeArgs} {
15187
explain-twice {--explain --explain}
15288
explain-dry {--explain --dry-run}
@@ -153,11 +89,11 @@
15389
dry-twice {--dry-run --dry-run}
15490
} {
15591
fossil_raw purge checkins side {*}$purgeArgs
15692
test purge-$purgeName {$CODE == 0 &&
15793
[string match "*check-in to side*file b.txt*" $RESULT]}
158
- test_eq purge-$purgeName-no-change [purge_state] $purgeStart
94
+ test_eq purge-$purgeName-no-change [repository_state] $purgeStart
15995
}
16096
fossil purge list
16197
test_eq purge-explain-no-graveyard [string trim $RESULT] ""
16298
16399
###############################################################################
@@ -171,11 +107,11 @@
171107
WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')"] 0
172108
test_eq purge-checkins-no-event [purge_sql "SELECT count(*) FROM event
173109
WHERE comment LIKE 'purge-side-%'"] 0
174110
test_eq purge-checkins-trunk-kept [purge_sql "SELECT count(*) FROM event
175111
WHERE comment LIKE 'purge-trunk-%'"] 5
176
-purge_sound purge-checkins
112
+repository_sound purge-checkins
177113
for {set purgeI 1} {$purgeI <= 5} {incr purgeI} {
178114
fossil cat a.txt -r [lindex $purgeTrunk [expr {$purgeI-1}]]
179115
test_eq purge-checkins-trunk-$purgeI "$RESULT\n" $purgeTrunkText($purgeI)
180116
}
181117
set purgeEvent [purge_last_event]
@@ -194,23 +130,24 @@
194130
fossil purge cat [purge_sql "SELECT uuid FROM purgeitem
195131
WHERE srcid IS NOT NULL LIMIT 1"]
196132
test purge-cat-delta {$CODE == 0}
197133
198134
# A trial run of the undo restores nothing and keeps the purge.
199
-set purgeBefore [purge_state]
135
+set purgeBefore [repository_state]
200136
fossil purge undo $purgeEvent --explain
201137
test purge-undo-explain {$CODE == 0}
202
-test_eq purge-undo-explain-no-change [purge_state] $purgeBefore
138
+test_eq purge-undo-explain-no-change [repository_state] $purgeBefore
203139
test_eq purge-undo-explain-event-kept [purge_last_event] $purgeEvent
204140
fossil purge undo $purgeEvent --dry-run
205141
test_eq purge-undo-dry-run-event-kept [purge_last_event] $purgeEvent
206142
207143
# Undo gives back exactly what was there.
208144
fossil purge undo $purgeEvent
209145
test purge-undo {$CODE == 0}
210
-test_eq purge-undo-state [purge_diff $purgeStart [purge_state]] ""
211
-purge_sound purge-undo
146
+test_eq purge-undo-state [repository_state_diff $purgeStart \
147
+ [repository_state]] ""
148
+repository_sound purge-undo
212149
fossil purge list
213150
test_eq purge-undo-graveyard-empty [string trim $RESULT] ""
214151
fossil cat b.txt -r $purgeSide2
215152
test_eq purge-undo-content [string trim $RESULT] "a file only the branch has"
216153
@@ -265,11 +202,11 @@
265202
test purge-current-checkout-link {$CODE != 0 &&
266203
[string match "*cannot purge the current check-out*" $RESULT]}
267204
file delete link.fossil
268205
}
269206
fossil update trunk
270
-test_eq purge-current-checkout-no-change [purge_state] $purgeStart
207
+test_eq purge-current-checkout-no-change [repository_state] $purgeStart
271208
272209
fossil purge cat [string repeat 0 40] -expectError
273210
test purge-cat-missing {$CODE != 0}
274211
fossil purge tickets x -expectError
275212
test purge-tickets-not-implemented {$CODE != 0}
@@ -289,19 +226,23 @@
289226
} {
290227
fossil purge {*}$purgeArgs -expectError
291228
test purge-usage-$purgeName {$CODE != 0 &&
292229
[string match "*Usage:*" $RESULT]}
293230
}
294
-test_eq purge-usage-no-change [purge_state] $purgeStart
231
+test_eq purge-usage-no-change [repository_state] $purgeStart
232
+
233
+if {[test_assurance] ne "stress"} {
234
+ test_skip "the tests after the first sections need -assurance stress"
235
+}
295236
296237
###############################################################################
297238
# Purging one file version that a kept version is a delta of, on a copy.
298239
# The kept version is stored whole first and can still be read.
299240
300241
file copy full.fossil p1.fossil
301
-set purgeV2 [purge_file_hash [lindex $purgeTrunk 1] a.txt]
302
-set purgeV3 [purge_file_hash [lindex $purgeTrunk 2] a.txt]
242
+set purgeV2 [checkin_file_hash [lindex $purgeTrunk 1] a.txt]
243
+set purgeV3 [checkin_file_hash [lindex $purgeTrunk 2] a.txt]
303244
test purge-delta-setup {[purge_sql "SELECT count(*) FROM delta
304245
WHERE srcid=(SELECT rid FROM blob WHERE uuid='$purgeV3')" p1.fossil] > 0}
305246
fossil purge artifacts $purgeV3 -R p1.fossil
306247
test purge-artifact {$CODE == 0}
307248
test_eq purge-artifact-gone [purge_has p1.fossil $purgeV3] 0
@@ -319,15 +260,15 @@
319260
fossil purge undo [purge_last_event p1.fossil] -R p1.fossil
320261
test purge-artifact-undo {$CODE == 0}
321262
test_eq purge-artifact-undo-back [purge_has p1.fossil $purgeV3] 1
322263
test_eq purge-artifact-undo-links [purge_dangling p1.fossil] 0
323264
test_eq purge-artifact-undo-state \
324
- [purge_diff $purgeStart [purge_state p1.fossil]] ""
325
-purge_sound purge-artifact-undo p1.fossil
265
+ [repository_state_diff $purgeStart [repository_state p1.fossil]] ""
266
+repository_sound purge-artifact-undo p1.fossil
326267
fossil rebuild p1.fossil
327268
test_eq purge-artifact-rebuild-state \
328
- [purge_diff $purgeStart [purge_state p1.fossil]] ""
269
+ [repository_state_diff $purgeStart [repository_state p1.fossil]] ""
329270
330271
# Every version of a file, by name, on another copy.
331272
file copy full.fossil p2.fossil
332273
fossil purge files a.txt -R p2.fossil
333274
test purge-files {$CODE == 0}
@@ -338,11 +279,11 @@
338279
test_eq purge-files-undo-back [purge_sql "SELECT count(*) FROM blob
339280
WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 2
340281
test_eq purge-files-undo-links [purge_dangling p2.fossil] 0
341282
fossil rebuild p2.fossil
342283
test_eq purge-files-rebuild-state \
343
- [purge_diff $purgeStart [purge_state p2.fossil]] ""
284
+ [repository_state_diff $purgeStart [repository_state p2.fossil]] ""
344285
345286
# Purging check-ins takes a repository named with -R, as every command
346287
# can.
347288
file copy full.fossil p3.fossil
348289
fossil_raw purge checkins side --explain -R p3.fossil
@@ -375,31 +316,31 @@
375316
[string match "*purge-trunk-5*" $RESULT] &&
376317
![string match "*purge-trunk-4*" $RESULT]}
377318
fossil purge undo [purge_last_event p4.fossil] -R p4.fossil
378319
test purge-middle-undo {$CODE == 0}
379320
test_eq purge-middle-undo-state \
380
- [purge_diff $purgeStart [purge_state p4.fossil]] ""
381
-purge_sound purge-middle-undo p4.fossil
321
+ [repository_state_diff $purgeStart [repository_state p4.fossil]] ""
322
+repository_sound purge-middle-undo p4.fossil
382323
383324
# A ticket change. The ticket goes with its only change and comes back
384325
# with the undo.
385326
fossil ticket add title "a ticket to purge" status Open -R p4.fossil
386327
set purgeTicket [purge_sql "SELECT uuid FROM blob
387328
WHERE rid=(SELECT tkt_rid FROM ticketchng)" p4.fossil]
388329
test purge-ticket-setup {[purge_sql "SELECT count(*) FROM ticket
389330
WHERE title='a ticket to purge'" p4.fossil] == 1}
390
-set purgeBefore [purge_state p4.fossil]
331
+set purgeBefore [repository_state p4.fossil]
391332
fossil purge artifacts $purgeTicket -R p4.fossil
392333
test purge-ticket {$CODE == 0}
393334
test_eq purge-ticket-gone [purge_sql "SELECT (SELECT count(*) FROM ticket)
394335
+ (SELECT count(*) FROM ticketchng)" p4.fossil] 0
395336
fossil purge undo [purge_last_event p4.fossil] -R p4.fossil
396337
test purge-ticket-undo {$CODE == 0}
397338
test_eq purge-ticket-undo-back [purge_sql "SELECT count(*) FROM ticket
398339
WHERE title='a ticket to purge'" p4.fossil] 1
399340
test_eq purge-ticket-undo-state \
400
- [purge_diff $purgeBefore [purge_state p4.fossil]] ""
341
+ [repository_state_diff $purgeBefore [repository_state p4.fossil]] ""
401342
402343
# A repository whose plink table has no baseid column, as one made before
403344
# the 2014-11-28 schema change that was never rebuilt; the column is
404345
# dropped here with SQL. A purge works on it; a rebuild adds the column,
405346
# and the undo then restores what was purged.
@@ -412,12 +353,12 @@
412353
test purge-old-plink-rebuild {$CODE == 0}
413354
fossil purge undo [purge_last_event p6.fossil] -R p6.fossil
414355
test purge-old-plink-undo {$CODE == 0}
415356
test_eq purge-old-plink-undo-back [purge_has p6.fossil $purgeMiddle] 1
416357
test_eq purge-old-plink-undo-state \
417
- [purge_diff $purgeStart [purge_state p6.fossil]] ""
418
-purge_sound purge-old-plink-undo p6.fossil
358
+ [repository_state_diff $purgeStart [repository_state p6.fossil]] ""
359
+repository_sound purge-old-plink-undo p6.fossil
419360
420361
# "fossil bundle purge" removes the check-ins of a bundle without a
421362
# graveyard: there is no purge event, nothing is said about an undo, and
422363
# importing the bundle brings the branch back.
423364
file copy full.fossil p7.fossil
@@ -433,11 +374,11 @@
433374
fossil test-integrity -R p7.fossil
434375
test purge-bundle-integrity {$CODE == 0}
435376
fossil bundle import side.bundle --publish -R p7.fossil
436377
test purge-bundle-import {$CODE == 0}
437378
test_eq purge-bundle-import-state \
438
- [purge_diff $purgeStart [purge_state p7.fossil]] ""
379
+ [repository_state_diff $purgeStart [repository_state p7.fossil]] ""
439380
440381
###############################################################################
441382
# A graveyard that has been damaged with SQL. Each command stops with a
442383
# message and restores nothing. In source-loop two items name each other
443384
# as delta source. In undo-record-zero the hash of an item is already in
@@ -482,15 +423,15 @@
482423
[list undo $purgeEvent8] \
483424
"*" \
484425
] {
485426
file copy -force p8.fossil damaged.fossil
486427
fossil sql -R damaged.fossil $purgeDamage
487
- set purgeBefore [purge_state damaged.fossil]
428
+ set purgeBefore [repository_state damaged.fossil]
488429
fossil_raw purge {*}$purgeArgs -R damaged.fossil
489430
test purge-damage-$purgeName {$CODE == 1 &&
490431
[string match $purgeMessage $RESULT]}
491
- test_eq purge-damage-$purgeName-no-change [purge_state damaged.fossil] \
432
+ test_eq purge-damage-$purgeName-no-change [repository_state damaged.fossil] \
492433
$purgeBefore
493434
test_eq purge-damage-$purgeName-event-kept \
494435
[purge_last_event damaged.fossil] $purgeEvent8
495436
}
496437
@@ -499,12 +440,12 @@
499440
fossil sql -R damaged.fossil "UPDATE purgeitem SET orid=NULL"
500441
fossil purge undo $purgeEvent8 -R damaged.fossil
501442
test purge-undo-no-record-number {$CODE == 0}
502443
fossil rebuild damaged.fossil
503444
test_eq purge-undo-no-record-number-state \
504
- [purge_diff $purgeStart [purge_state damaged.fossil]] ""
505
-purge_sound purge-undo-no-record-number damaged.fossil
445
+ [repository_state_diff $purgeStart [repository_state damaged.fossil]] ""
446
+repository_sound purge-undo-no-record-number damaged.fossil
506447
507448
# A check-in is purged and its child, which is kept, then loses its
508449
# content. The undo restores the purged check-in and does not link the
509450
# child to it.
510451
file copy -force full.fossil damaged.fossil
@@ -515,11 +456,10 @@
515456
test purge-undo-child-without-content {$CODE == 0}
516457
test_eq purge-undo-child-without-content-back \
517458
[purge_has damaged.fossil $purgeP] 1
518459
test_eq purge-undo-child-without-content-not-linked \
519460
[purge_parent_of damaged.fossil $purgeC] ""
520
-file delete damaged.fossil
521461
522462
###############################################################################
523463
# Obliterate. Asked first, unless --force; afterwards the purge cannot
524464
# be undone.
525465
@@ -532,11 +472,11 @@
532472
[string match "*a file only the branch has*" $RESULT]}
533473
test purge-cat-second-missing-named \
534474
{[string first [string repeat 0 40] $RESULT] >= 0}
535475
536476
fossil_raw -input "n\n" purge obliterate $purgeEvent
537
-test purge-obliterate-declined {$CODE != 0}
477
+test purge-obliterate-declined {$CODE == 1}
538478
test_eq purge-obliterate-declined-kept [purge_last_event] $purgeEvent
539479
fossil_raw -input "y\n" purge obliterate $purgeEvent
540480
test purge-obliterate {$CODE == 0}
541481
test_eq purge-obliterate-gone [purge_sql "SELECT count(*) FROM purgeitem"] 0
542482
# A capital Y is a yes too.
@@ -547,18 +487,18 @@
547487
test_eq purge-obliterate-capital-gone [purge_sql "SELECT count(*)
548488
FROM purgeevent WHERE peid=$purgeEvent4" p4.fossil] 0
549489
fossil purge obliterate $purgeEvent --force -expectError
550490
test purge-obliterate-again {$CODE != 0 &&
551491
[string match "*no such purge event*" $RESULT]}
552
-purge_sound purge-obliterate
492
+repository_sound purge-obliterate
553493
554494
# An undo of a purge that does not exist is refused, as an obliterate of
555495
# one is.
556
-set purgeBefore [purge_state]
496
+set purgeBefore [repository_state]
557497
fossil_raw purge undo $purgeEvent
558
-test purge-undo-missing-event {$CODE != 0}
559
-test_eq purge-undo-missing-event-no-change [purge_state] $purgeBefore
498
+test purge-undo-missing-event {$CODE == 1}
499
+test_eq purge-undo-missing-event-no-change [repository_state] $purgeBefore
560500
561501
# A repository that has never had a purge has no graveyard tables. Undo
562502
# and obliterate are refused there as for any unknown purge, the list is
563503
# empty, and a scrub of private content has nothing to take from it.
564504
fossil init nograve.fossil
@@ -586,12 +526,13 @@
586526
test purge-clone {$CODE == 0}
587527
test_eq purge-clone-lacks [purge_sql "SELECT count(*) FROM blob
588528
WHERE uuid='$purgeSide2'" c1.fossil] 0
589529
fossil pull [file join [pwd] full.fossil]
590530
test purge-pull-back {$CODE == 0}
591
-test_eq purge-pull-back-state [purge_diff $purgeStart [purge_state]] ""
592
-purge_sound purge-pull-back
531
+test_eq purge-pull-back-state \
532
+ [repository_state_diff $purgeStart [repository_state]] ""
533
+repository_sound purge-pull-back
593534
594535
###############################################################################
595536
# Scrub. A private branch, a password and a purge in the graveyard, then
596537
# each kind of scrub on its own copy.
597538
@@ -599,41 +540,37 @@
599540
for {set purgeI 0} {$purgeI < 60} {incr purgeI} {
600541
append purgeSecretText "line $purgeI of private content\n"
601542
}
602543
set purgeSecret [purge_commit secret.txt $purgeSecretText purge-secret \
603544
--private --branch secret]
604
-set purgeSecretFile [purge_file_hash $purgeSecret secret.txt]
545
+set purgeSecretFile [checkin_file_hash $purgeSecret secret.txt]
605546
fossil update trunk
606547
fossil user new scrubuser [email protected] hunter2
607
-fossil user password scrubuser hunter2
608548
set purgePublic [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid
609549
FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"]
610550
foreach purgeCopy {s1 s2 s3 s4 s5 s7} {
611551
file copy .rep.fossil $purgeCopy.fossil
612552
}
613553
proc purge_public {repo} {
614554
return [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid
615555
FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)" $repo]
616556
}
617
-proc purge_pw {repo} {
618
- return [purge_sql "SELECT count(*) FROM user WHERE pw<>''" $repo]
619
-}
620
-test purge-scrub-setup {[purge_pw s1.fossil] > 0 &&
557
+test purge-scrub-setup {[password_count s1.fossil] > 0 &&
621558
[purge_has s1.fossil $purgeSecret] == 1}
622559
623560
# Asked first; "n" changes nothing.
624561
fossil_raw -input "n\n" scrub s1.fossil
625
-test purge-scrub-declined {$CODE != 0}
626
-test purge-scrub-declined-kept {[purge_pw s1.fossil] > 0}
562
+test purge-scrub-declined {$CODE == 1}
563
+test purge-scrub-declined-kept {[password_count s1.fossil] > 0}
627564
628565
# By default only passwords go.
629566
fossil scrub --force s1.fossil
630567
test purge-scrub {$CODE == 0}
631
-test_eq purge-scrub-passwords [purge_pw s1.fossil] 0
568
+test_eq purge-scrub-passwords [password_count s1.fossil] 0
632569
test_eq purge-scrub-keeps-private [purge_has s1.fossil $purgeSecret] 1
633570
test_eq purge-scrub-keeps-public [purge_public s1.fossil] $purgePublic
634
-purge_sound purge-scrub s1.fossil
571
+repository_sound purge-scrub s1.fossil
635572
636573
# --private removes the private branch and nothing else.
637574
fossil scrub --private --force s2.fossil
638575
test purge-scrub-private {$CODE == 0}
639576
test_eq purge-scrub-private-gone [purge_has s2.fossil $purgeSecret] 0
@@ -641,12 +578,12 @@
641578
test_eq purge-scrub-private-none-left [purge_sql "SELECT count(*)
642579
FROM private" s2.fossil] 0
643580
test_eq purge-scrub-private-no-event [purge_sql "SELECT count(*) FROM event
644581
WHERE comment='purge-secret'" s2.fossil] 0
645582
test_eq purge-scrub-private-keeps-public [purge_public s2.fossil] $purgePublic
646
-test purge-scrub-private-keeps-passwords {[purge_pw s2.fossil] > 0}
647
-purge_sound purge-scrub-private s2.fossil
583
+test purge-scrub-private-keeps-passwords {[password_count s2.fossil] > 0}
584
+repository_sound purge-scrub-private s2.fossil
648585
649586
# A private branch that was purged before the scrub is in the graveyard.
650587
fossil purge artifacts $purgeSecret $purgeSecretFile -R s3.fossil
651588
test purge-scrub-graveyard-setup {$CODE == 0 &&
652589
[purge_has s3.fossil $purgeSecret] == 0}
@@ -657,32 +594,33 @@
657594
# Undo, on a copy, gives the private branch back, still private.
658595
file copy s3.fossil s8.fossil
659596
fossil purge undo [purge_last_event s8.fossil] -R s8.fossil
660597
test purge-undo-private {$CODE == 0}
661598
test_eq purge-undo-private-state \
662
- [purge_diff [purge_state s7.fossil] [purge_state s8.fossil]] ""
599
+ [repository_state_diff [repository_state s7.fossil] \
600
+ [repository_state s8.fossil]] ""
663601
test_eq purge-undo-private-still-private [purge_sql "SELECT count(*)
664602
FROM private JOIN blob USING(rid)
665603
WHERE uuid IN ('$purgeSecret','$purgeSecretFile')" s8.fossil] 2
666
-purge_sound purge-undo-private s8.fossil
604
+repository_sound purge-undo-private s8.fossil
667605
fossil scrub --private --force s3.fossil
668606
test purge-scrub-graveyard {$CODE == 0}
669607
# The private branch does not survive in the graveyard, so neither
670608
# "purge cat" nor "purge undo" can bring it back.
671609
test_eq purge-scrub-private-graveyard [purge_sql "SELECT count(*)
672610
FROM purgeitem WHERE isPrivate" s3.fossil] 0
673611
fossil_raw purge cat $purgeSecretFile -R s3.fossil
674
-test purge-scrub-private-graveyard-cat {$CODE != 0}
612
+test purge-scrub-private-graveyard-cat {$CODE == 1}
675613
676614
# A public item in the graveyard that is stored as a delta from a private
677615
# one is kept and can still be read. "fossil publish" leaves such deltas:
678616
# the older version of a file is stored as a delta from the newer, and
679617
# only the older is published.
680618
fossil update secret
681619
set purgeSecret2 [purge_commit secret.txt "${purgeSecretText}one more\n" \
682620
purge-secret-2]
683
-set purgeSecretFile2 [purge_file_hash $purgeSecret2 secret.txt]
621
+set purgeSecretFile2 [checkin_file_hash $purgeSecret2 secret.txt]
684622
fossil update trunk
685623
file copy .rep.fossil s6.fossil
686624
fossil publish $purgeSecret -R s6.fossil
687625
test purge-scrub-publish {$CODE == 0}
688626
test purge-scrub-public-from-private {[purge_sql "SELECT count(*) FROM delta
@@ -704,13 +642,13 @@
704642
fossil purge artifacts $purgeSecret $purgeSecretFile -R s4.fossil
705643
fossil scrub --verily --force s4.fossil
706644
test purge-scrub-verily {$CODE == 0}
707645
test_eq purge-scrub-verily-no-graveyard [purge_sql "SELECT count(*)
708646
FROM sqlite_schema WHERE name='purgeitem'" s4.fossil] 0
709
-test_eq purge-scrub-verily-passwords [purge_pw s4.fossil] 0
647
+test_eq purge-scrub-verily-passwords [password_count s4.fossil] 0
710648
test_eq purge-scrub-verily-keeps-public [purge_public s4.fossil] $purgePublic
711
-purge_sound purge-scrub-verily s4.fossil
649
+repository_sound purge-scrub-verily s4.fossil
712650
713651
# A scrubbed repository still clones.
714652
fossil clone s2.fossil c2.fossil
715653
test purge-scrub-clone {$CODE == 0}
716654
test_eq purge-scrub-clone-public [purge_public c2.fossil] $purgePublic
@@ -718,14 +656,16 @@
718656
###############################################################################
719657
# repack changes how content is stored, never what it is.
720658
721659
fossil repack s5.fossil
722660
test purge-repack {$CODE == 0}
723
-test_eq purge-repack-same [purge_state s5.fossil] [purge_state s5.fossil]
661
+test_eq purge-repack-same \
662
+ [repository_state_diff [repository_state s7.fossil] \
663
+ [repository_state s5.fossil]] ""
724664
test_eq purge-repack-public [purge_public s5.fossil] $purgePublic
725665
test_eq purge-repack-private [purge_has s5.fossil $purgeSecret] 1
726
-purge_sound purge-repack s5.fossil
666
+repository_sound purge-repack s5.fossil
727667
728668
###############################################################################
729669
# A delta manifest names its baseline. A purge of the baseline alone is
730670
# refused; with the delta manifest it goes through, and the undo restores
731671
# both.
@@ -736,22 +676,23 @@
736676
purge-delta-manifest --delta]
737677
test purge-baseline-setup {[purge_sql "SELECT count(*) FROM plink
738678
WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeDeltaM')
739679
AND baseid=(SELECT rid FROM blob WHERE uuid='$purgeBase')"] == 1}
740680
fossil update [lindex $purgeTrunk 3]
741
-set purgeBefore [purge_state]
681
+set purgeBefore [repository_state]
742682
fossil_raw purge artifacts $purgeBase
743683
test purge-baseline-alone-refused {$CODE ne "0" &&
744684
[string match "*attempt to purge a baseline manifest*" $RESULT]}
745
-test_eq purge-baseline-alone-no-change [purge_state] $purgeBefore
685
+test_eq purge-baseline-alone-no-change [repository_state] $purgeBefore
746686
fossil purge artifacts $purgeBase $purgeDeltaM
747687
test purge-baseline-with-delta {$CODE == 0}
748688
test_eq purge-baseline-with-delta-gone [purge_sql "SELECT count(*) FROM blob
749689
WHERE uuid IN ('$purgeBase','$purgeDeltaM')"] 0
750690
fossil purge undo [purge_last_event]
751691
test purge-baseline-undo {$CODE == 0}
752
-test_eq purge-baseline-undo-state [purge_diff $purgeBefore [purge_state]] ""
753
-purge_sound purge-baseline-undo
692
+test_eq purge-baseline-undo-state \
693
+ [repository_state_diff $purgeBefore [repository_state]] ""
694
+repository_sound purge-baseline-undo
754695
755696
###############################################################################
756697
757698
test_cleanup
758699
--- test/purge.test
+++ test/purge.test
@@ -3,90 +3,26 @@
3 # its graveyard, undo and obliterate, and "fossil scrub". After each the
4 # repository must still be sound, and an undo must give back exactly what
5 # was removed.
6 #
7
8 # These tests run only in a long pass: -assurance stress.
9 if {[test_assurance] ne "stress"} {
10 test_skip "runs only with -assurance stress"
11 }
12
13 require_no_open_checkout
14
15 test_setup
16
17 proc purge_sql {sql {repo .rep.fossil}} {
18 fossil sql -R $repo $sql
19 return [string trim $::RESULT]
20 }
21
22 # What a repository holds, by hash rather than by record number, so that
23 # two states can be compared after an undo has stored content again:
24 # the artifacts with their private flag, the timeline, the parent links,
25 # the files of each check-in, the leaves and the tags.
26 #
27 proc purge_state {{repo .rep.fossil}} {
28 return [purge_sql {
29 SELECT 'blob', uuid, rid IN private FROM blob WHERE size>=0
30 UNION ALL
31 SELECT 'event', b.uuid, e.type || ' ' || ifnull(e.comment,'')
32 FROM event e JOIN blob b ON b.rid=e.objid
33 UNION ALL
34 SELECT 'plink', p.uuid, c.uuid FROM plink
35 JOIN blob p ON p.rid=plink.pid JOIN blob c ON c.rid=plink.cid
36 UNION ALL
37 SELECT 'mlink', m.uuid, f.uuid || ' ' || fn.name FROM mlink
38 JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
39 JOIN filename fn ON fn.fnid=mlink.fnid
40 UNION ALL
41 SELECT 'leaf', uuid, '' FROM leaf JOIN blob USING(rid)
42 UNION ALL
43 SELECT 'tag', b.uuid, t.tagname || '=' || ifnull(x.value,'')
44 FROM tagxref x JOIN tag t USING(tagid) JOIN blob b ON b.rid=x.rid
45 WHERE x.tagtype>0
46 ORDER BY 1, 2, 3
47 } $repo]
48 }
49
50 # The rows that are in one state and not in the other, marked "-" for
51 # the first and "+" for the second. Empty when the two are the same.
52 #
53 proc purge_diff {a b} {
54 set la [split $a \n]
55 set lb [split $b \n]
56 set out {}
57 foreach x $la { if {[lsearch -exact $lb $x] < 0} { lappend out "- $x" } }
58 foreach x $lb { if {[lsearch -exact $la $x] < 0} { lappend out "+ $x" } }
59 return [join $out \n]
60 }
61
62 proc purge_sound {name {repo .rep.fossil}} {
63 fossil test-integrity -R $repo
64 test $name-integrity {$::CODE == 0}
65 fossil test-missing -R $repo
66 test $name-missing {$::CODE == 0}
67 }
68
69 proc purge_hash {comment} {
70 return [purge_sql "SELECT uuid FROM blob, event
71 WHERE objid=rid AND comment='$comment'"]
72 }
73
74 # The hash of the version of FILE in check-in CHECKIN.
75 proc purge_file_hash {checkin file} {
76 return [purge_sql "SELECT f.uuid FROM mlink
77 JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
78 JOIN filename fn ON fn.fnid=mlink.fnid
79 WHERE m.uuid='$checkin' AND fn.name='$file'"]
80 }
81
82 proc purge_commit {file content comment args} {
83 set new [expr {![file exists $file]}]
84 write_file $file $content
85 if {$new} {fossil add $file}
86 fossil commit -m $comment --no-warnings {*}$args
87 return [purge_hash $comment]
88 }
89
90 # The number of the newest purge event.
91 proc purge_last_event {{repo .rep.fossil}} {
92 return [purge_sql "SELECT max(peid) FROM purgeevent" $repo]
@@ -96,11 +32,11 @@
96 return [purge_sql "SELECT count(*) FROM blob WHERE uuid='$hash'
97 AND size>=0" $repo]
98 }
99
100 # The number of file and parent links whose artifact is not in the
101 # repository at all. purge_state compares the links by hash, which also
102 # shows a link to the wrong artifact.
103 proc purge_dangling {repo} {
104 return [purge_sql "SELECT (SELECT count(*) FROM mlink
105 WHERE fid>0 AND fid NOT IN (SELECT rid FROM blob))
106 + (SELECT count(*) FROM plink
@@ -128,25 +64,25 @@
128 fossil branch new side current
129 fossil update side
130 set purgeSide1 [purge_commit a.txt "${purgeTrunkText(3)}on the side\n" \
131 purge-side-1]
132 set purgeSide2 [purge_commit b.txt "a file only the branch has\n" purge-side-2]
133 set purgeSideB [purge_file_hash $purgeSide2 b.txt]
134 fossil update trunk
135
136 purge_sound purge-start
137 set purgeStart [purge_state]
138 file copy .rep.fossil full.fossil
139
140 ###############################################################################
141 # A trial run changes nothing.
142
143 fossil purge checkins side --explain
144 test purge-explain {$CODE == 0}
145 test_eq purge-explain-no-change [purge_state] $purgeStart
146 fossil purge checkins side --dry-run
147 test_eq purge-dry-run-no-change [purge_state] $purgeStart
148
149 # Either option may be given twice, or both together, with the same result.
150 foreach {purgeName purgeArgs} {
151 explain-twice {--explain --explain}
152 explain-dry {--explain --dry-run}
@@ -153,11 +89,11 @@
153 dry-twice {--dry-run --dry-run}
154 } {
155 fossil_raw purge checkins side {*}$purgeArgs
156 test purge-$purgeName {$CODE == 0 &&
157 [string match "*check-in to side*file b.txt*" $RESULT]}
158 test_eq purge-$purgeName-no-change [purge_state] $purgeStart
159 }
160 fossil purge list
161 test_eq purge-explain-no-graveyard [string trim $RESULT] ""
162
163 ###############################################################################
@@ -171,11 +107,11 @@
171 WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')"] 0
172 test_eq purge-checkins-no-event [purge_sql "SELECT count(*) FROM event
173 WHERE comment LIKE 'purge-side-%'"] 0
174 test_eq purge-checkins-trunk-kept [purge_sql "SELECT count(*) FROM event
175 WHERE comment LIKE 'purge-trunk-%'"] 5
176 purge_sound purge-checkins
177 for {set purgeI 1} {$purgeI <= 5} {incr purgeI} {
178 fossil cat a.txt -r [lindex $purgeTrunk [expr {$purgeI-1}]]
179 test_eq purge-checkins-trunk-$purgeI "$RESULT\n" $purgeTrunkText($purgeI)
180 }
181 set purgeEvent [purge_last_event]
@@ -194,23 +130,24 @@
194 fossil purge cat [purge_sql "SELECT uuid FROM purgeitem
195 WHERE srcid IS NOT NULL LIMIT 1"]
196 test purge-cat-delta {$CODE == 0}
197
198 # A trial run of the undo restores nothing and keeps the purge.
199 set purgeBefore [purge_state]
200 fossil purge undo $purgeEvent --explain
201 test purge-undo-explain {$CODE == 0}
202 test_eq purge-undo-explain-no-change [purge_state] $purgeBefore
203 test_eq purge-undo-explain-event-kept [purge_last_event] $purgeEvent
204 fossil purge undo $purgeEvent --dry-run
205 test_eq purge-undo-dry-run-event-kept [purge_last_event] $purgeEvent
206
207 # Undo gives back exactly what was there.
208 fossil purge undo $purgeEvent
209 test purge-undo {$CODE == 0}
210 test_eq purge-undo-state [purge_diff $purgeStart [purge_state]] ""
211 purge_sound purge-undo
 
212 fossil purge list
213 test_eq purge-undo-graveyard-empty [string trim $RESULT] ""
214 fossil cat b.txt -r $purgeSide2
215 test_eq purge-undo-content [string trim $RESULT] "a file only the branch has"
216
@@ -265,11 +202,11 @@
265 test purge-current-checkout-link {$CODE != 0 &&
266 [string match "*cannot purge the current check-out*" $RESULT]}
267 file delete link.fossil
268 }
269 fossil update trunk
270 test_eq purge-current-checkout-no-change [purge_state] $purgeStart
271
272 fossil purge cat [string repeat 0 40] -expectError
273 test purge-cat-missing {$CODE != 0}
274 fossil purge tickets x -expectError
275 test purge-tickets-not-implemented {$CODE != 0}
@@ -289,19 +226,23 @@
289 } {
290 fossil purge {*}$purgeArgs -expectError
291 test purge-usage-$purgeName {$CODE != 0 &&
292 [string match "*Usage:*" $RESULT]}
293 }
294 test_eq purge-usage-no-change [purge_state] $purgeStart
 
 
 
 
295
296 ###############################################################################
297 # Purging one file version that a kept version is a delta of, on a copy.
298 # The kept version is stored whole first and can still be read.
299
300 file copy full.fossil p1.fossil
301 set purgeV2 [purge_file_hash [lindex $purgeTrunk 1] a.txt]
302 set purgeV3 [purge_file_hash [lindex $purgeTrunk 2] a.txt]
303 test purge-delta-setup {[purge_sql "SELECT count(*) FROM delta
304 WHERE srcid=(SELECT rid FROM blob WHERE uuid='$purgeV3')" p1.fossil] > 0}
305 fossil purge artifacts $purgeV3 -R p1.fossil
306 test purge-artifact {$CODE == 0}
307 test_eq purge-artifact-gone [purge_has p1.fossil $purgeV3] 0
@@ -319,15 +260,15 @@
319 fossil purge undo [purge_last_event p1.fossil] -R p1.fossil
320 test purge-artifact-undo {$CODE == 0}
321 test_eq purge-artifact-undo-back [purge_has p1.fossil $purgeV3] 1
322 test_eq purge-artifact-undo-links [purge_dangling p1.fossil] 0
323 test_eq purge-artifact-undo-state \
324 [purge_diff $purgeStart [purge_state p1.fossil]] ""
325 purge_sound purge-artifact-undo p1.fossil
326 fossil rebuild p1.fossil
327 test_eq purge-artifact-rebuild-state \
328 [purge_diff $purgeStart [purge_state p1.fossil]] ""
329
330 # Every version of a file, by name, on another copy.
331 file copy full.fossil p2.fossil
332 fossil purge files a.txt -R p2.fossil
333 test purge-files {$CODE == 0}
@@ -338,11 +279,11 @@
338 test_eq purge-files-undo-back [purge_sql "SELECT count(*) FROM blob
339 WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 2
340 test_eq purge-files-undo-links [purge_dangling p2.fossil] 0
341 fossil rebuild p2.fossil
342 test_eq purge-files-rebuild-state \
343 [purge_diff $purgeStart [purge_state p2.fossil]] ""
344
345 # Purging check-ins takes a repository named with -R, as every command
346 # can.
347 file copy full.fossil p3.fossil
348 fossil_raw purge checkins side --explain -R p3.fossil
@@ -375,31 +316,31 @@
375 [string match "*purge-trunk-5*" $RESULT] &&
376 ![string match "*purge-trunk-4*" $RESULT]}
377 fossil purge undo [purge_last_event p4.fossil] -R p4.fossil
378 test purge-middle-undo {$CODE == 0}
379 test_eq purge-middle-undo-state \
380 [purge_diff $purgeStart [purge_state p4.fossil]] ""
381 purge_sound purge-middle-undo p4.fossil
382
383 # A ticket change. The ticket goes with its only change and comes back
384 # with the undo.
385 fossil ticket add title "a ticket to purge" status Open -R p4.fossil
386 set purgeTicket [purge_sql "SELECT uuid FROM blob
387 WHERE rid=(SELECT tkt_rid FROM ticketchng)" p4.fossil]
388 test purge-ticket-setup {[purge_sql "SELECT count(*) FROM ticket
389 WHERE title='a ticket to purge'" p4.fossil] == 1}
390 set purgeBefore [purge_state p4.fossil]
391 fossil purge artifacts $purgeTicket -R p4.fossil
392 test purge-ticket {$CODE == 0}
393 test_eq purge-ticket-gone [purge_sql "SELECT (SELECT count(*) FROM ticket)
394 + (SELECT count(*) FROM ticketchng)" p4.fossil] 0
395 fossil purge undo [purge_last_event p4.fossil] -R p4.fossil
396 test purge-ticket-undo {$CODE == 0}
397 test_eq purge-ticket-undo-back [purge_sql "SELECT count(*) FROM ticket
398 WHERE title='a ticket to purge'" p4.fossil] 1
399 test_eq purge-ticket-undo-state \
400 [purge_diff $purgeBefore [purge_state p4.fossil]] ""
401
402 # A repository whose plink table has no baseid column, as one made before
403 # the 2014-11-28 schema change that was never rebuilt; the column is
404 # dropped here with SQL. A purge works on it; a rebuild adds the column,
405 # and the undo then restores what was purged.
@@ -412,12 +353,12 @@
412 test purge-old-plink-rebuild {$CODE == 0}
413 fossil purge undo [purge_last_event p6.fossil] -R p6.fossil
414 test purge-old-plink-undo {$CODE == 0}
415 test_eq purge-old-plink-undo-back [purge_has p6.fossil $purgeMiddle] 1
416 test_eq purge-old-plink-undo-state \
417 [purge_diff $purgeStart [purge_state p6.fossil]] ""
418 purge_sound purge-old-plink-undo p6.fossil
419
420 # "fossil bundle purge" removes the check-ins of a bundle without a
421 # graveyard: there is no purge event, nothing is said about an undo, and
422 # importing the bundle brings the branch back.
423 file copy full.fossil p7.fossil
@@ -433,11 +374,11 @@
433 fossil test-integrity -R p7.fossil
434 test purge-bundle-integrity {$CODE == 0}
435 fossil bundle import side.bundle --publish -R p7.fossil
436 test purge-bundle-import {$CODE == 0}
437 test_eq purge-bundle-import-state \
438 [purge_diff $purgeStart [purge_state p7.fossil]] ""
439
440 ###############################################################################
441 # A graveyard that has been damaged with SQL. Each command stops with a
442 # message and restores nothing. In source-loop two items name each other
443 # as delta source. In undo-record-zero the hash of an item is already in
@@ -482,15 +423,15 @@
482 [list undo $purgeEvent8] \
483 "*" \
484 ] {
485 file copy -force p8.fossil damaged.fossil
486 fossil sql -R damaged.fossil $purgeDamage
487 set purgeBefore [purge_state damaged.fossil]
488 fossil_raw purge {*}$purgeArgs -R damaged.fossil
489 test purge-damage-$purgeName {$CODE == 1 &&
490 [string match $purgeMessage $RESULT]}
491 test_eq purge-damage-$purgeName-no-change [purge_state damaged.fossil] \
492 $purgeBefore
493 test_eq purge-damage-$purgeName-event-kept \
494 [purge_last_event damaged.fossil] $purgeEvent8
495 }
496
@@ -499,12 +440,12 @@
499 fossil sql -R damaged.fossil "UPDATE purgeitem SET orid=NULL"
500 fossil purge undo $purgeEvent8 -R damaged.fossil
501 test purge-undo-no-record-number {$CODE == 0}
502 fossil rebuild damaged.fossil
503 test_eq purge-undo-no-record-number-state \
504 [purge_diff $purgeStart [purge_state damaged.fossil]] ""
505 purge_sound purge-undo-no-record-number damaged.fossil
506
507 # A check-in is purged and its child, which is kept, then loses its
508 # content. The undo restores the purged check-in and does not link the
509 # child to it.
510 file copy -force full.fossil damaged.fossil
@@ -515,11 +456,10 @@
515 test purge-undo-child-without-content {$CODE == 0}
516 test_eq purge-undo-child-without-content-back \
517 [purge_has damaged.fossil $purgeP] 1
518 test_eq purge-undo-child-without-content-not-linked \
519 [purge_parent_of damaged.fossil $purgeC] ""
520 file delete damaged.fossil
521
522 ###############################################################################
523 # Obliterate. Asked first, unless --force; afterwards the purge cannot
524 # be undone.
525
@@ -532,11 +472,11 @@
532 [string match "*a file only the branch has*" $RESULT]}
533 test purge-cat-second-missing-named \
534 {[string first [string repeat 0 40] $RESULT] >= 0}
535
536 fossil_raw -input "n\n" purge obliterate $purgeEvent
537 test purge-obliterate-declined {$CODE != 0}
538 test_eq purge-obliterate-declined-kept [purge_last_event] $purgeEvent
539 fossil_raw -input "y\n" purge obliterate $purgeEvent
540 test purge-obliterate {$CODE == 0}
541 test_eq purge-obliterate-gone [purge_sql "SELECT count(*) FROM purgeitem"] 0
542 # A capital Y is a yes too.
@@ -547,18 +487,18 @@
547 test_eq purge-obliterate-capital-gone [purge_sql "SELECT count(*)
548 FROM purgeevent WHERE peid=$purgeEvent4" p4.fossil] 0
549 fossil purge obliterate $purgeEvent --force -expectError
550 test purge-obliterate-again {$CODE != 0 &&
551 [string match "*no such purge event*" $RESULT]}
552 purge_sound purge-obliterate
553
554 # An undo of a purge that does not exist is refused, as an obliterate of
555 # one is.
556 set purgeBefore [purge_state]
557 fossil_raw purge undo $purgeEvent
558 test purge-undo-missing-event {$CODE != 0}
559 test_eq purge-undo-missing-event-no-change [purge_state] $purgeBefore
560
561 # A repository that has never had a purge has no graveyard tables. Undo
562 # and obliterate are refused there as for any unknown purge, the list is
563 # empty, and a scrub of private content has nothing to take from it.
564 fossil init nograve.fossil
@@ -586,12 +526,13 @@
586 test purge-clone {$CODE == 0}
587 test_eq purge-clone-lacks [purge_sql "SELECT count(*) FROM blob
588 WHERE uuid='$purgeSide2'" c1.fossil] 0
589 fossil pull [file join [pwd] full.fossil]
590 test purge-pull-back {$CODE == 0}
591 test_eq purge-pull-back-state [purge_diff $purgeStart [purge_state]] ""
592 purge_sound purge-pull-back
 
593
594 ###############################################################################
595 # Scrub. A private branch, a password and a purge in the graveyard, then
596 # each kind of scrub on its own copy.
597
@@ -599,41 +540,37 @@
599 for {set purgeI 0} {$purgeI < 60} {incr purgeI} {
600 append purgeSecretText "line $purgeI of private content\n"
601 }
602 set purgeSecret [purge_commit secret.txt $purgeSecretText purge-secret \
603 --private --branch secret]
604 set purgeSecretFile [purge_file_hash $purgeSecret secret.txt]
605 fossil update trunk
606 fossil user new scrubuser [email protected] hunter2
607 fossil user password scrubuser hunter2
608 set purgePublic [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid
609 FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"]
610 foreach purgeCopy {s1 s2 s3 s4 s5 s7} {
611 file copy .rep.fossil $purgeCopy.fossil
612 }
613 proc purge_public {repo} {
614 return [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid
615 FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)" $repo]
616 }
617 proc purge_pw {repo} {
618 return [purge_sql "SELECT count(*) FROM user WHERE pw<>''" $repo]
619 }
620 test purge-scrub-setup {[purge_pw s1.fossil] > 0 &&
621 [purge_has s1.fossil $purgeSecret] == 1}
622
623 # Asked first; "n" changes nothing.
624 fossil_raw -input "n\n" scrub s1.fossil
625 test purge-scrub-declined {$CODE != 0}
626 test purge-scrub-declined-kept {[purge_pw s1.fossil] > 0}
627
628 # By default only passwords go.
629 fossil scrub --force s1.fossil
630 test purge-scrub {$CODE == 0}
631 test_eq purge-scrub-passwords [purge_pw s1.fossil] 0
632 test_eq purge-scrub-keeps-private [purge_has s1.fossil $purgeSecret] 1
633 test_eq purge-scrub-keeps-public [purge_public s1.fossil] $purgePublic
634 purge_sound purge-scrub s1.fossil
635
636 # --private removes the private branch and nothing else.
637 fossil scrub --private --force s2.fossil
638 test purge-scrub-private {$CODE == 0}
639 test_eq purge-scrub-private-gone [purge_has s2.fossil $purgeSecret] 0
@@ -641,12 +578,12 @@
641 test_eq purge-scrub-private-none-left [purge_sql "SELECT count(*)
642 FROM private" s2.fossil] 0
643 test_eq purge-scrub-private-no-event [purge_sql "SELECT count(*) FROM event
644 WHERE comment='purge-secret'" s2.fossil] 0
645 test_eq purge-scrub-private-keeps-public [purge_public s2.fossil] $purgePublic
646 test purge-scrub-private-keeps-passwords {[purge_pw s2.fossil] > 0}
647 purge_sound purge-scrub-private s2.fossil
648
649 # A private branch that was purged before the scrub is in the graveyard.
650 fossil purge artifacts $purgeSecret $purgeSecretFile -R s3.fossil
651 test purge-scrub-graveyard-setup {$CODE == 0 &&
652 [purge_has s3.fossil $purgeSecret] == 0}
@@ -657,32 +594,33 @@
657 # Undo, on a copy, gives the private branch back, still private.
658 file copy s3.fossil s8.fossil
659 fossil purge undo [purge_last_event s8.fossil] -R s8.fossil
660 test purge-undo-private {$CODE == 0}
661 test_eq purge-undo-private-state \
662 [purge_diff [purge_state s7.fossil] [purge_state s8.fossil]] ""
 
663 test_eq purge-undo-private-still-private [purge_sql "SELECT count(*)
664 FROM private JOIN blob USING(rid)
665 WHERE uuid IN ('$purgeSecret','$purgeSecretFile')" s8.fossil] 2
666 purge_sound purge-undo-private s8.fossil
667 fossil scrub --private --force s3.fossil
668 test purge-scrub-graveyard {$CODE == 0}
669 # The private branch does not survive in the graveyard, so neither
670 # "purge cat" nor "purge undo" can bring it back.
671 test_eq purge-scrub-private-graveyard [purge_sql "SELECT count(*)
672 FROM purgeitem WHERE isPrivate" s3.fossil] 0
673 fossil_raw purge cat $purgeSecretFile -R s3.fossil
674 test purge-scrub-private-graveyard-cat {$CODE != 0}
675
676 # A public item in the graveyard that is stored as a delta from a private
677 # one is kept and can still be read. "fossil publish" leaves such deltas:
678 # the older version of a file is stored as a delta from the newer, and
679 # only the older is published.
680 fossil update secret
681 set purgeSecret2 [purge_commit secret.txt "${purgeSecretText}one more\n" \
682 purge-secret-2]
683 set purgeSecretFile2 [purge_file_hash $purgeSecret2 secret.txt]
684 fossil update trunk
685 file copy .rep.fossil s6.fossil
686 fossil publish $purgeSecret -R s6.fossil
687 test purge-scrub-publish {$CODE == 0}
688 test purge-scrub-public-from-private {[purge_sql "SELECT count(*) FROM delta
@@ -704,13 +642,13 @@
704 fossil purge artifacts $purgeSecret $purgeSecretFile -R s4.fossil
705 fossil scrub --verily --force s4.fossil
706 test purge-scrub-verily {$CODE == 0}
707 test_eq purge-scrub-verily-no-graveyard [purge_sql "SELECT count(*)
708 FROM sqlite_schema WHERE name='purgeitem'" s4.fossil] 0
709 test_eq purge-scrub-verily-passwords [purge_pw s4.fossil] 0
710 test_eq purge-scrub-verily-keeps-public [purge_public s4.fossil] $purgePublic
711 purge_sound purge-scrub-verily s4.fossil
712
713 # A scrubbed repository still clones.
714 fossil clone s2.fossil c2.fossil
715 test purge-scrub-clone {$CODE == 0}
716 test_eq purge-scrub-clone-public [purge_public c2.fossil] $purgePublic
@@ -718,14 +656,16 @@
718 ###############################################################################
719 # repack changes how content is stored, never what it is.
720
721 fossil repack s5.fossil
722 test purge-repack {$CODE == 0}
723 test_eq purge-repack-same [purge_state s5.fossil] [purge_state s5.fossil]
 
 
724 test_eq purge-repack-public [purge_public s5.fossil] $purgePublic
725 test_eq purge-repack-private [purge_has s5.fossil $purgeSecret] 1
726 purge_sound purge-repack s5.fossil
727
728 ###############################################################################
729 # A delta manifest names its baseline. A purge of the baseline alone is
730 # refused; with the delta manifest it goes through, and the undo restores
731 # both.
@@ -736,22 +676,23 @@
736 purge-delta-manifest --delta]
737 test purge-baseline-setup {[purge_sql "SELECT count(*) FROM plink
738 WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeDeltaM')
739 AND baseid=(SELECT rid FROM blob WHERE uuid='$purgeBase')"] == 1}
740 fossil update [lindex $purgeTrunk 3]
741 set purgeBefore [purge_state]
742 fossil_raw purge artifacts $purgeBase
743 test purge-baseline-alone-refused {$CODE ne "0" &&
744 [string match "*attempt to purge a baseline manifest*" $RESULT]}
745 test_eq purge-baseline-alone-no-change [purge_state] $purgeBefore
746 fossil purge artifacts $purgeBase $purgeDeltaM
747 test purge-baseline-with-delta {$CODE == 0}
748 test_eq purge-baseline-with-delta-gone [purge_sql "SELECT count(*) FROM blob
749 WHERE uuid IN ('$purgeBase','$purgeDeltaM')"] 0
750 fossil purge undo [purge_last_event]
751 test purge-baseline-undo {$CODE == 0}
752 test_eq purge-baseline-undo-state [purge_diff $purgeBefore [purge_state]] ""
753 purge_sound purge-baseline-undo
 
754
755 ###############################################################################
756
757 test_cleanup
758
--- test/purge.test
+++ test/purge.test
@@ -3,90 +3,26 @@
3 # its graveyard, undo and obliterate, and "fossil scrub". After each the
4 # repository must still be sound, and an undo must give back exactly what
5 # was removed.
6 #
7
8 # The first sections run at every level, and the rest need
9 # -assurance stress.
 
 
 
10 require_no_open_checkout
11
12 test_setup
13
14 proc purge_sql {sql {repo .rep.fossil}} {
15 return [fossil_sql $sql $repo]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16 }
17
18 proc purge_commit {file content comment args} {
19 set new [expr {![file exists $file]}]
20 write_file $file $content
21 if {$new} {fossil add $file}
22 fossil commit -m $comment --no-warnings {*}$args
23 return [checkin_hash $comment]
24 }
25
26 # The number of the newest purge event.
27 proc purge_last_event {{repo .rep.fossil}} {
28 return [purge_sql "SELECT max(peid) FROM purgeevent" $repo]
@@ -96,11 +32,11 @@
32 return [purge_sql "SELECT count(*) FROM blob WHERE uuid='$hash'
33 AND size>=0" $repo]
34 }
35
36 # The number of file and parent links whose artifact is not in the
37 # repository at all. repository_state compares the links by hash, which also
38 # shows a link to the wrong artifact.
39 proc purge_dangling {repo} {
40 return [purge_sql "SELECT (SELECT count(*) FROM mlink
41 WHERE fid>0 AND fid NOT IN (SELECT rid FROM blob))
42 + (SELECT count(*) FROM plink
@@ -128,25 +64,25 @@
64 fossil branch new side current
65 fossil update side
66 set purgeSide1 [purge_commit a.txt "${purgeTrunkText(3)}on the side\n" \
67 purge-side-1]
68 set purgeSide2 [purge_commit b.txt "a file only the branch has\n" purge-side-2]
69 set purgeSideB [checkin_file_hash $purgeSide2 b.txt]
70 fossil update trunk
71
72 repository_sound purge-start
73 set purgeStart [repository_state]
74 file copy .rep.fossil full.fossil
75
76 ###############################################################################
77 # A trial run changes nothing.
78
79 fossil purge checkins side --explain
80 test purge-explain {$CODE == 0}
81 test_eq purge-explain-no-change [repository_state] $purgeStart
82 fossil purge checkins side --dry-run
83 test_eq purge-dry-run-no-change [repository_state] $purgeStart
84
85 # Either option may be given twice, or both together, with the same result.
86 foreach {purgeName purgeArgs} {
87 explain-twice {--explain --explain}
88 explain-dry {--explain --dry-run}
@@ -153,11 +89,11 @@
89 dry-twice {--dry-run --dry-run}
90 } {
91 fossil_raw purge checkins side {*}$purgeArgs
92 test purge-$purgeName {$CODE == 0 &&
93 [string match "*check-in to side*file b.txt*" $RESULT]}
94 test_eq purge-$purgeName-no-change [repository_state] $purgeStart
95 }
96 fossil purge list
97 test_eq purge-explain-no-graveyard [string trim $RESULT] ""
98
99 ###############################################################################
@@ -171,11 +107,11 @@
107 WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')"] 0
108 test_eq purge-checkins-no-event [purge_sql "SELECT count(*) FROM event
109 WHERE comment LIKE 'purge-side-%'"] 0
110 test_eq purge-checkins-trunk-kept [purge_sql "SELECT count(*) FROM event
111 WHERE comment LIKE 'purge-trunk-%'"] 5
112 repository_sound purge-checkins
113 for {set purgeI 1} {$purgeI <= 5} {incr purgeI} {
114 fossil cat a.txt -r [lindex $purgeTrunk [expr {$purgeI-1}]]
115 test_eq purge-checkins-trunk-$purgeI "$RESULT\n" $purgeTrunkText($purgeI)
116 }
117 set purgeEvent [purge_last_event]
@@ -194,23 +130,24 @@
130 fossil purge cat [purge_sql "SELECT uuid FROM purgeitem
131 WHERE srcid IS NOT NULL LIMIT 1"]
132 test purge-cat-delta {$CODE == 0}
133
134 # A trial run of the undo restores nothing and keeps the purge.
135 set purgeBefore [repository_state]
136 fossil purge undo $purgeEvent --explain
137 test purge-undo-explain {$CODE == 0}
138 test_eq purge-undo-explain-no-change [repository_state] $purgeBefore
139 test_eq purge-undo-explain-event-kept [purge_last_event] $purgeEvent
140 fossil purge undo $purgeEvent --dry-run
141 test_eq purge-undo-dry-run-event-kept [purge_last_event] $purgeEvent
142
143 # Undo gives back exactly what was there.
144 fossil purge undo $purgeEvent
145 test purge-undo {$CODE == 0}
146 test_eq purge-undo-state [repository_state_diff $purgeStart \
147 [repository_state]] ""
148 repository_sound purge-undo
149 fossil purge list
150 test_eq purge-undo-graveyard-empty [string trim $RESULT] ""
151 fossil cat b.txt -r $purgeSide2
152 test_eq purge-undo-content [string trim $RESULT] "a file only the branch has"
153
@@ -265,11 +202,11 @@
202 test purge-current-checkout-link {$CODE != 0 &&
203 [string match "*cannot purge the current check-out*" $RESULT]}
204 file delete link.fossil
205 }
206 fossil update trunk
207 test_eq purge-current-checkout-no-change [repository_state] $purgeStart
208
209 fossil purge cat [string repeat 0 40] -expectError
210 test purge-cat-missing {$CODE != 0}
211 fossil purge tickets x -expectError
212 test purge-tickets-not-implemented {$CODE != 0}
@@ -289,19 +226,23 @@
226 } {
227 fossil purge {*}$purgeArgs -expectError
228 test purge-usage-$purgeName {$CODE != 0 &&
229 [string match "*Usage:*" $RESULT]}
230 }
231 test_eq purge-usage-no-change [repository_state] $purgeStart
232
233 if {[test_assurance] ne "stress"} {
234 test_skip "the tests after the first sections need -assurance stress"
235 }
236
237 ###############################################################################
238 # Purging one file version that a kept version is a delta of, on a copy.
239 # The kept version is stored whole first and can still be read.
240
241 file copy full.fossil p1.fossil
242 set purgeV2 [checkin_file_hash [lindex $purgeTrunk 1] a.txt]
243 set purgeV3 [checkin_file_hash [lindex $purgeTrunk 2] a.txt]
244 test purge-delta-setup {[purge_sql "SELECT count(*) FROM delta
245 WHERE srcid=(SELECT rid FROM blob WHERE uuid='$purgeV3')" p1.fossil] > 0}
246 fossil purge artifacts $purgeV3 -R p1.fossil
247 test purge-artifact {$CODE == 0}
248 test_eq purge-artifact-gone [purge_has p1.fossil $purgeV3] 0
@@ -319,15 +260,15 @@
260 fossil purge undo [purge_last_event p1.fossil] -R p1.fossil
261 test purge-artifact-undo {$CODE == 0}
262 test_eq purge-artifact-undo-back [purge_has p1.fossil $purgeV3] 1
263 test_eq purge-artifact-undo-links [purge_dangling p1.fossil] 0
264 test_eq purge-artifact-undo-state \
265 [repository_state_diff $purgeStart [repository_state p1.fossil]] ""
266 repository_sound purge-artifact-undo p1.fossil
267 fossil rebuild p1.fossil
268 test_eq purge-artifact-rebuild-state \
269 [repository_state_diff $purgeStart [repository_state p1.fossil]] ""
270
271 # Every version of a file, by name, on another copy.
272 file copy full.fossil p2.fossil
273 fossil purge files a.txt -R p2.fossil
274 test purge-files {$CODE == 0}
@@ -338,11 +279,11 @@
279 test_eq purge-files-undo-back [purge_sql "SELECT count(*) FROM blob
280 WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 2
281 test_eq purge-files-undo-links [purge_dangling p2.fossil] 0
282 fossil rebuild p2.fossil
283 test_eq purge-files-rebuild-state \
284 [repository_state_diff $purgeStart [repository_state p2.fossil]] ""
285
286 # Purging check-ins takes a repository named with -R, as every command
287 # can.
288 file copy full.fossil p3.fossil
289 fossil_raw purge checkins side --explain -R p3.fossil
@@ -375,31 +316,31 @@
316 [string match "*purge-trunk-5*" $RESULT] &&
317 ![string match "*purge-trunk-4*" $RESULT]}
318 fossil purge undo [purge_last_event p4.fossil] -R p4.fossil
319 test purge-middle-undo {$CODE == 0}
320 test_eq purge-middle-undo-state \
321 [repository_state_diff $purgeStart [repository_state p4.fossil]] ""
322 repository_sound purge-middle-undo p4.fossil
323
324 # A ticket change. The ticket goes with its only change and comes back
325 # with the undo.
326 fossil ticket add title "a ticket to purge" status Open -R p4.fossil
327 set purgeTicket [purge_sql "SELECT uuid FROM blob
328 WHERE rid=(SELECT tkt_rid FROM ticketchng)" p4.fossil]
329 test purge-ticket-setup {[purge_sql "SELECT count(*) FROM ticket
330 WHERE title='a ticket to purge'" p4.fossil] == 1}
331 set purgeBefore [repository_state p4.fossil]
332 fossil purge artifacts $purgeTicket -R p4.fossil
333 test purge-ticket {$CODE == 0}
334 test_eq purge-ticket-gone [purge_sql "SELECT (SELECT count(*) FROM ticket)
335 + (SELECT count(*) FROM ticketchng)" p4.fossil] 0
336 fossil purge undo [purge_last_event p4.fossil] -R p4.fossil
337 test purge-ticket-undo {$CODE == 0}
338 test_eq purge-ticket-undo-back [purge_sql "SELECT count(*) FROM ticket
339 WHERE title='a ticket to purge'" p4.fossil] 1
340 test_eq purge-ticket-undo-state \
341 [repository_state_diff $purgeBefore [repository_state p4.fossil]] ""
342
343 # A repository whose plink table has no baseid column, as one made before
344 # the 2014-11-28 schema change that was never rebuilt; the column is
345 # dropped here with SQL. A purge works on it; a rebuild adds the column,
346 # and the undo then restores what was purged.
@@ -412,12 +353,12 @@
353 test purge-old-plink-rebuild {$CODE == 0}
354 fossil purge undo [purge_last_event p6.fossil] -R p6.fossil
355 test purge-old-plink-undo {$CODE == 0}
356 test_eq purge-old-plink-undo-back [purge_has p6.fossil $purgeMiddle] 1
357 test_eq purge-old-plink-undo-state \
358 [repository_state_diff $purgeStart [repository_state p6.fossil]] ""
359 repository_sound purge-old-plink-undo p6.fossil
360
361 # "fossil bundle purge" removes the check-ins of a bundle without a
362 # graveyard: there is no purge event, nothing is said about an undo, and
363 # importing the bundle brings the branch back.
364 file copy full.fossil p7.fossil
@@ -433,11 +374,11 @@
374 fossil test-integrity -R p7.fossil
375 test purge-bundle-integrity {$CODE == 0}
376 fossil bundle import side.bundle --publish -R p7.fossil
377 test purge-bundle-import {$CODE == 0}
378 test_eq purge-bundle-import-state \
379 [repository_state_diff $purgeStart [repository_state p7.fossil]] ""
380
381 ###############################################################################
382 # A graveyard that has been damaged with SQL. Each command stops with a
383 # message and restores nothing. In source-loop two items name each other
384 # as delta source. In undo-record-zero the hash of an item is already in
@@ -482,15 +423,15 @@
423 [list undo $purgeEvent8] \
424 "*" \
425 ] {
426 file copy -force p8.fossil damaged.fossil
427 fossil sql -R damaged.fossil $purgeDamage
428 set purgeBefore [repository_state damaged.fossil]
429 fossil_raw purge {*}$purgeArgs -R damaged.fossil
430 test purge-damage-$purgeName {$CODE == 1 &&
431 [string match $purgeMessage $RESULT]}
432 test_eq purge-damage-$purgeName-no-change [repository_state damaged.fossil] \
433 $purgeBefore
434 test_eq purge-damage-$purgeName-event-kept \
435 [purge_last_event damaged.fossil] $purgeEvent8
436 }
437
@@ -499,12 +440,12 @@
440 fossil sql -R damaged.fossil "UPDATE purgeitem SET orid=NULL"
441 fossil purge undo $purgeEvent8 -R damaged.fossil
442 test purge-undo-no-record-number {$CODE == 0}
443 fossil rebuild damaged.fossil
444 test_eq purge-undo-no-record-number-state \
445 [repository_state_diff $purgeStart [repository_state damaged.fossil]] ""
446 repository_sound purge-undo-no-record-number damaged.fossil
447
448 # A check-in is purged and its child, which is kept, then loses its
449 # content. The undo restores the purged check-in and does not link the
450 # child to it.
451 file copy -force full.fossil damaged.fossil
@@ -515,11 +456,10 @@
456 test purge-undo-child-without-content {$CODE == 0}
457 test_eq purge-undo-child-without-content-back \
458 [purge_has damaged.fossil $purgeP] 1
459 test_eq purge-undo-child-without-content-not-linked \
460 [purge_parent_of damaged.fossil $purgeC] ""
 
461
462 ###############################################################################
463 # Obliterate. Asked first, unless --force; afterwards the purge cannot
464 # be undone.
465
@@ -532,11 +472,11 @@
472 [string match "*a file only the branch has*" $RESULT]}
473 test purge-cat-second-missing-named \
474 {[string first [string repeat 0 40] $RESULT] >= 0}
475
476 fossil_raw -input "n\n" purge obliterate $purgeEvent
477 test purge-obliterate-declined {$CODE == 1}
478 test_eq purge-obliterate-declined-kept [purge_last_event] $purgeEvent
479 fossil_raw -input "y\n" purge obliterate $purgeEvent
480 test purge-obliterate {$CODE == 0}
481 test_eq purge-obliterate-gone [purge_sql "SELECT count(*) FROM purgeitem"] 0
482 # A capital Y is a yes too.
@@ -547,18 +487,18 @@
487 test_eq purge-obliterate-capital-gone [purge_sql "SELECT count(*)
488 FROM purgeevent WHERE peid=$purgeEvent4" p4.fossil] 0
489 fossil purge obliterate $purgeEvent --force -expectError
490 test purge-obliterate-again {$CODE != 0 &&
491 [string match "*no such purge event*" $RESULT]}
492 repository_sound purge-obliterate
493
494 # An undo of a purge that does not exist is refused, as an obliterate of
495 # one is.
496 set purgeBefore [repository_state]
497 fossil_raw purge undo $purgeEvent
498 test purge-undo-missing-event {$CODE == 1}
499 test_eq purge-undo-missing-event-no-change [repository_state] $purgeBefore
500
501 # A repository that has never had a purge has no graveyard tables. Undo
502 # and obliterate are refused there as for any unknown purge, the list is
503 # empty, and a scrub of private content has nothing to take from it.
504 fossil init nograve.fossil
@@ -586,12 +526,13 @@
526 test purge-clone {$CODE == 0}
527 test_eq purge-clone-lacks [purge_sql "SELECT count(*) FROM blob
528 WHERE uuid='$purgeSide2'" c1.fossil] 0
529 fossil pull [file join [pwd] full.fossil]
530 test purge-pull-back {$CODE == 0}
531 test_eq purge-pull-back-state \
532 [repository_state_diff $purgeStart [repository_state]] ""
533 repository_sound purge-pull-back
534
535 ###############################################################################
536 # Scrub. A private branch, a password and a purge in the graveyard, then
537 # each kind of scrub on its own copy.
538
@@ -599,41 +540,37 @@
540 for {set purgeI 0} {$purgeI < 60} {incr purgeI} {
541 append purgeSecretText "line $purgeI of private content\n"
542 }
543 set purgeSecret [purge_commit secret.txt $purgeSecretText purge-secret \
544 --private --branch secret]
545 set purgeSecretFile [checkin_file_hash $purgeSecret secret.txt]
546 fossil update trunk
547 fossil user new scrubuser [email protected] hunter2
 
548 set purgePublic [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid
549 FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"]
550 foreach purgeCopy {s1 s2 s3 s4 s5 s7} {
551 file copy .rep.fossil $purgeCopy.fossil
552 }
553 proc purge_public {repo} {
554 return [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid
555 FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)" $repo]
556 }
557 test purge-scrub-setup {[password_count s1.fossil] > 0 &&
 
 
 
558 [purge_has s1.fossil $purgeSecret] == 1}
559
560 # Asked first; "n" changes nothing.
561 fossil_raw -input "n\n" scrub s1.fossil
562 test purge-scrub-declined {$CODE == 1}
563 test purge-scrub-declined-kept {[password_count s1.fossil] > 0}
564
565 # By default only passwords go.
566 fossil scrub --force s1.fossil
567 test purge-scrub {$CODE == 0}
568 test_eq purge-scrub-passwords [password_count s1.fossil] 0
569 test_eq purge-scrub-keeps-private [purge_has s1.fossil $purgeSecret] 1
570 test_eq purge-scrub-keeps-public [purge_public s1.fossil] $purgePublic
571 repository_sound purge-scrub s1.fossil
572
573 # --private removes the private branch and nothing else.
574 fossil scrub --private --force s2.fossil
575 test purge-scrub-private {$CODE == 0}
576 test_eq purge-scrub-private-gone [purge_has s2.fossil $purgeSecret] 0
@@ -641,12 +578,12 @@
578 test_eq purge-scrub-private-none-left [purge_sql "SELECT count(*)
579 FROM private" s2.fossil] 0
580 test_eq purge-scrub-private-no-event [purge_sql "SELECT count(*) FROM event
581 WHERE comment='purge-secret'" s2.fossil] 0
582 test_eq purge-scrub-private-keeps-public [purge_public s2.fossil] $purgePublic
583 test purge-scrub-private-keeps-passwords {[password_count s2.fossil] > 0}
584 repository_sound purge-scrub-private s2.fossil
585
586 # A private branch that was purged before the scrub is in the graveyard.
587 fossil purge artifacts $purgeSecret $purgeSecretFile -R s3.fossil
588 test purge-scrub-graveyard-setup {$CODE == 0 &&
589 [purge_has s3.fossil $purgeSecret] == 0}
@@ -657,32 +594,33 @@
594 # Undo, on a copy, gives the private branch back, still private.
595 file copy s3.fossil s8.fossil
596 fossil purge undo [purge_last_event s8.fossil] -R s8.fossil
597 test purge-undo-private {$CODE == 0}
598 test_eq purge-undo-private-state \
599 [repository_state_diff [repository_state s7.fossil] \
600 [repository_state s8.fossil]] ""
601 test_eq purge-undo-private-still-private [purge_sql "SELECT count(*)
602 FROM private JOIN blob USING(rid)
603 WHERE uuid IN ('$purgeSecret','$purgeSecretFile')" s8.fossil] 2
604 repository_sound purge-undo-private s8.fossil
605 fossil scrub --private --force s3.fossil
606 test purge-scrub-graveyard {$CODE == 0}
607 # The private branch does not survive in the graveyard, so neither
608 # "purge cat" nor "purge undo" can bring it back.
609 test_eq purge-scrub-private-graveyard [purge_sql "SELECT count(*)
610 FROM purgeitem WHERE isPrivate" s3.fossil] 0
611 fossil_raw purge cat $purgeSecretFile -R s3.fossil
612 test purge-scrub-private-graveyard-cat {$CODE == 1}
613
614 # A public item in the graveyard that is stored as a delta from a private
615 # one is kept and can still be read. "fossil publish" leaves such deltas:
616 # the older version of a file is stored as a delta from the newer, and
617 # only the older is published.
618 fossil update secret
619 set purgeSecret2 [purge_commit secret.txt "${purgeSecretText}one more\n" \
620 purge-secret-2]
621 set purgeSecretFile2 [checkin_file_hash $purgeSecret2 secret.txt]
622 fossil update trunk
623 file copy .rep.fossil s6.fossil
624 fossil publish $purgeSecret -R s6.fossil
625 test purge-scrub-publish {$CODE == 0}
626 test purge-scrub-public-from-private {[purge_sql "SELECT count(*) FROM delta
@@ -704,13 +642,13 @@
642 fossil purge artifacts $purgeSecret $purgeSecretFile -R s4.fossil
643 fossil scrub --verily --force s4.fossil
644 test purge-scrub-verily {$CODE == 0}
645 test_eq purge-scrub-verily-no-graveyard [purge_sql "SELECT count(*)
646 FROM sqlite_schema WHERE name='purgeitem'" s4.fossil] 0
647 test_eq purge-scrub-verily-passwords [password_count s4.fossil] 0
648 test_eq purge-scrub-verily-keeps-public [purge_public s4.fossil] $purgePublic
649 repository_sound purge-scrub-verily s4.fossil
650
651 # A scrubbed repository still clones.
652 fossil clone s2.fossil c2.fossil
653 test purge-scrub-clone {$CODE == 0}
654 test_eq purge-scrub-clone-public [purge_public c2.fossil] $purgePublic
@@ -718,14 +656,16 @@
656 ###############################################################################
657 # repack changes how content is stored, never what it is.
658
659 fossil repack s5.fossil
660 test purge-repack {$CODE == 0}
661 test_eq purge-repack-same \
662 [repository_state_diff [repository_state s7.fossil] \
663 [repository_state s5.fossil]] ""
664 test_eq purge-repack-public [purge_public s5.fossil] $purgePublic
665 test_eq purge-repack-private [purge_has s5.fossil $purgeSecret] 1
666 repository_sound purge-repack s5.fossil
667
668 ###############################################################################
669 # A delta manifest names its baseline. A purge of the baseline alone is
670 # refused; with the delta manifest it goes through, and the undo restores
671 # both.
@@ -736,22 +676,23 @@
676 purge-delta-manifest --delta]
677 test purge-baseline-setup {[purge_sql "SELECT count(*) FROM plink
678 WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeDeltaM')
679 AND baseid=(SELECT rid FROM blob WHERE uuid='$purgeBase')"] == 1}
680 fossil update [lindex $purgeTrunk 3]
681 set purgeBefore [repository_state]
682 fossil_raw purge artifacts $purgeBase
683 test purge-baseline-alone-refused {$CODE ne "0" &&
684 [string match "*attempt to purge a baseline manifest*" $RESULT]}
685 test_eq purge-baseline-alone-no-change [repository_state] $purgeBefore
686 fossil purge artifacts $purgeBase $purgeDeltaM
687 test purge-baseline-with-delta {$CODE == 0}
688 test_eq purge-baseline-with-delta-gone [purge_sql "SELECT count(*) FROM blob
689 WHERE uuid IN ('$purgeBase','$purgeDeltaM')"] 0
690 fossil purge undo [purge_last_event]
691 test purge-baseline-undo {$CODE == 0}
692 test_eq purge-baseline-undo-state \
693 [repository_state_diff $purgeBefore [repository_state]] ""
694 repository_sound purge-baseline-undo
695
696 ###############################################################################
697
698 test_cleanup
699
+42 -111
--- test/rebuild.test
+++ test/rebuild.test
@@ -5,80 +5,18 @@
55
# what a repository holds: after each, the artifacts, the timeline and the
66
# links between check-ins and files are compared with what was there
77
# before, and the repository must still be sound.
88
#
99
10
-# These tests run only in a long pass: -assurance stress.
11
-if {[test_assurance] ne "stress"} {
12
- test_skip "runs only with -assurance stress"
13
-}
14
-
10
+# The first sections run at every level, and the rest need
11
+# -assurance stress.
1512
require_no_open_checkout
1613
1714
test_setup
1815
1916
proc rebuild_sql {sql {repo .rep.fossil}} {
20
- fossil sql -R $repo $sql
21
- return [string trim $::RESULT]
22
-}
23
-
24
-# What a repository holds, by hash rather than by record number: the
25
-# artifacts with their private flag, the timeline, the parent links, the
26
-# files of each check-in, the leaves and the tags.
27
-#
28
-proc rebuild_state {{repo .rep.fossil}} {
29
- return [rebuild_sql {
30
- SELECT 'blob', uuid, rid IN private FROM blob WHERE size>=0
31
- UNION ALL
32
- SELECT 'event', b.uuid, e.type || ' ' || ifnull(e.comment,'')
33
- FROM event e JOIN blob b ON b.rid=e.objid
34
- UNION ALL
35
- SELECT 'plink', p.uuid, c.uuid FROM plink
36
- JOIN blob p ON p.rid=plink.pid JOIN blob c ON c.rid=plink.cid
37
- UNION ALL
38
- SELECT 'mlink', m.uuid, f.uuid || ' ' || fn.name FROM mlink
39
- JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
40
- JOIN filename fn ON fn.fnid=mlink.fnid
41
- UNION ALL
42
- SELECT 'leaf', uuid, '' FROM leaf JOIN blob USING(rid)
43
- UNION ALL
44
- SELECT 'tag', b.uuid, t.tagname || '=' || ifnull(x.value,'')
45
- FROM tagxref x JOIN tag t USING(tagid) JOIN blob b ON b.rid=x.rid
46
- WHERE x.tagtype>0
47
- ORDER BY 1, 2, 3
48
- } $repo]
49
-}
50
-
51
-# The rows that are in one state and not in the other, marked "-" for
52
-# the first and "+" for the second. Empty when the two are the same.
53
-#
54
-proc rebuild_diff {a b} {
55
- set la [split $a \n]
56
- set lb [split $b \n]
57
- set out {}
58
- foreach x $la { if {[lsearch -exact $lb $x] < 0} { lappend out "- $x" } }
59
- foreach x $lb { if {[lsearch -exact $la $x] < 0} { lappend out "+ $x" } }
60
- return [join $out \n]
61
-}
62
-
63
-proc rebuild_sound {name {repo .rep.fossil}} {
64
- fossil test-integrity -R $repo
65
- test $name-integrity {$::CODE == 0}
66
- fossil test-missing -R $repo
67
- test $name-missing {$::CODE == 0}
68
-}
69
-
70
-proc rebuild_hash {comment} {
71
- return [rebuild_sql "SELECT uuid FROM blob, event
72
- WHERE objid=rid AND comment='$comment'"]
73
-}
74
-
75
-proc rebuild_file_hash {checkin file {repo .rep.fossil}} {
76
- return [rebuild_sql "SELECT f.uuid FROM mlink
77
- JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
78
- JOIN filename fn ON fn.fnid=mlink.fnid
79
- WHERE m.uuid='$checkin' AND fn.name='$file'" $repo]
17
+ return [fossil_sql $sql $repo]
8018
}
8119
8220
# The hashes of the artifacts a repository has the content of, in order;
8321
# WHERE narrows them.
8422
proc rebuild_hashes {repo {where 1}} {
@@ -139,42 +77,38 @@
13977
append rebuildText "version $rebuildI\n"
14078
write_file a.txt $rebuildText
14179
write_file n.txt [rebuild_noise $rebuildI 1500]
14280
if {$rebuildI == 1} {fossil add a.txt n.txt}
14381
fossil commit -m rebuild-trunk-$rebuildI --no-warnings
144
- lappend rebuildTrunk [rebuild_hash rebuild-trunk-$rebuildI]
145
- set rebuildTrunkText($rebuildI) $rebuildText
82
+ lappend rebuildTrunk [checkin_hash rebuild-trunk-$rebuildI]
14683
}
14784
fossil update [lindex $rebuildTrunk 2]
14885
fossil branch new side current
14986
fossil update side
150
-write_file b.txt "a file only the branch has\n"
151
-fossil add b.txt
152
-fossil commit -m rebuild-side-1 --no-warnings
153
-set rebuildSide [rebuild_hash rebuild-side-1]
87
+commit_file b.txt "a file only the branch has\n" rebuild-side-1 --no-warnings
88
+set rebuildSide [checkin_hash rebuild-side-1]
15489
fossil update trunk
15590
fossil tag add rebuild-tag [lindex $rebuildTrunk 1]
15691
write_file page.txt "A wiki page.\n"
15792
fossil wiki create RebuildPage page.txt
15893
fossil ticket add title "a ticket" status Open
15994
set rebuildSecretText ""
16095
for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} {
16196
append rebuildSecretText "line $rebuildI of private content\n"
16297
}
163
-write_file secret.txt $rebuildSecretText
164
-fossil add secret.txt
165
-fossil commit -m rebuild-secret-1 --no-warnings --private --branch secret
166
-set rebuildSecret1 [rebuild_hash rebuild-secret-1]
98
+commit_file secret.txt $rebuildSecretText rebuild-secret-1 --no-warnings \
99
+ --private --branch secret
100
+set rebuildSecret1 [checkin_hash rebuild-secret-1]
167101
write_file secret.txt "${rebuildSecretText}one more\n"
168102
fossil commit -m rebuild-secret-2 --no-warnings
169
-set rebuildSecret2 [rebuild_hash rebuild-secret-2]
170
-set rebuildSecretFile1 [rebuild_file_hash $rebuildSecret1 secret.txt]
171
-set rebuildSecretFile2 [rebuild_file_hash $rebuildSecret2 secret.txt]
103
+set rebuildSecret2 [checkin_hash rebuild-secret-2]
104
+set rebuildSecretFile1 [checkin_file_hash $rebuildSecret1 secret.txt]
105
+set rebuildSecretFile2 [checkin_file_hash $rebuildSecret2 secret.txt]
172106
fossil update trunk
173107
174
-rebuild_sound rebuild-start
175
-set rebuildStart [rebuild_state]
108
+repository_sound rebuild-start
109
+set rebuildStart [repository_state]
176110
set rebuildAll [rebuild_hashes .rep.fossil]
177111
set rebuildPublic [rebuild_hashes .rep.fossil "rid NOT IN private"]
178112
test rebuild-start-setup {[llength $rebuildAll] > [llength $rebuildPublic] &&
179113
[rebuild_sql "SELECT count(*) FROM delta"] > 0}
180114
file copy .rep.fossil full.fossil
@@ -234,12 +168,16 @@
234168
test rebuild-$rebuildName {$CODE == 0 &&
235169
[string match $rebuildOut $RESULT]}
236170
test_eq rebuild-$rebuildName-effect [rebuild_sql $rebuildQuery r.fossil] \
237171
$rebuildWant
238172
test_eq rebuild-$rebuildName-state \
239
- [rebuild_diff $rebuildStart [rebuild_state r.fossil]] ""
240
- rebuild_sound rebuild-$rebuildName r.fossil
173
+ [repository_state_diff $rebuildStart [repository_state r.fossil]] ""
174
+ repository_sound rebuild-$rebuildName r.fossil
175
+}
176
+
177
+if {[test_assurance] ne "stress"} {
178
+ test_skip "the tests after the first sections need -assurance stress"
241179
}
242180
243181
# --deanalyze removes the statistics that --analyze made. The file is
244182
# read with --no-repository, because a command that opens the repository
245183
# runs PRAGMA optimize when it closes it, which makes them again.
@@ -249,11 +187,11 @@
249187
test rebuild-deanalyze {$CODE == 0}
250188
fossil sql --no-repository r.fossil \
251189
"SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'"
252190
test_eq rebuild-deanalyze-effect [string trim $RESULT] 0
253191
test_eq rebuild-deanalyze-state \
254
- [rebuild_diff $rebuildStart [rebuild_state r.fossil]] ""
192
+ [repository_state_diff $rebuildStart [repository_state r.fossil]] ""
255193
256194
# --stats counts each kind of artifact.
257195
fossil rebuild r.fossil --stats
258196
set rebuildStats $RESULT
259197
foreach {rebuildName rebuildLabel rebuildType} {
@@ -296,19 +234,20 @@
296234
test_eq rebuild-ifneeded-needed-schema [rebuild_sql "SELECT value FROM config
297235
WHERE name='aux-schema'" r.fossil] $rebuildSchema
298236
test rebuild-ifneeded-needed-rebuilt {[rebuild_sql "SELECT mtime FROM config
299237
WHERE name='rebuilt'" r.fossil] > 1}
300238
test_eq rebuild-ifneeded-needed-state \
301
- [rebuild_diff $rebuildStart [rebuild_state r.fossil]] ""
239
+ [repository_state_diff $rebuildStart [repository_state r.fossil]] ""
302240
303241
# Two repository names are one too many. Without a name, the repository
304242
# of the check-out is rebuilt.
305243
fossil rebuild r.fossil full.fossil -expectError
306244
test rebuild-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]}
307245
fossil rebuild
308246
test rebuild-checkout {$CODE == 0}
309
-test_eq rebuild-checkout-state [rebuild_diff $rebuildStart [rebuild_state]] ""
247
+test_eq rebuild-checkout-state \
248
+ [repository_state_diff $rebuildStart [repository_state]] ""
310249
311250
###############################################################################
312251
# A repository with the table definitions of an old Fossil: no baseid in
313252
# plink (before 2014-11-28), no pmid and isaux in mlink (before
314253
# 2015-01-24), no mtime in user, config, shun, reportfmt and concealed
@@ -385,12 +324,12 @@
385324
test_eq rebuild-old-schema-reports-dated [rebuild_sql "SELECT count(*)
386325
FROM reportfmt WHERE mtime IS NULL" old.fossil] 0
387326
test_eq rebuild-old-schema-concealed [rebuild_sql "SELECT hash, content,
388327
mtime>1 FROM concealed" old.fossil] "abc|[email protected]|1"
389328
test_eq rebuild-old-schema-state \
390
- [rebuild_diff $rebuildStart [rebuild_state old.fossil]] ""
391
-rebuild_sound rebuild-old-schema old.fossil
329
+ [repository_state_diff $rebuildStart [repository_state old.fossil]] ""
330
+repository_sound rebuild-old-schema old.fossil
392331
393332
###############################################################################
394333
# When the main-branch setting names a branch that no check-in has,
395334
# rebuild puts the first check-in on it. Everything that was there stays.
396335
@@ -405,15 +344,15 @@
405344
test_eq rebuild-main-branch-tagged [rebuild_sql "SELECT count(*)
406345
FROM tagxref JOIN tag USING(tagid) JOIN blob USING(rid)
407346
WHERE tagname='sym-primary' AND tagtype=2 AND srcid>0
408347
AND uuid='$rebuildRoot'" main.fossil] 1
409348
# The two artifacts that carry the new tags are all that is added.
410
-set rebuildAdded [rebuild_diff [join $rebuildAll \n] \
349
+set rebuildAdded [repository_state_diff [join $rebuildAll \n] \
411350
[join [rebuild_hashes main.fossil] \n]]
412351
test rebuild-main-branch-kept {[regexp -all -line {^\+ } $rebuildAdded] == 2 &&
413352
[regexp -all -line {^- } $rebuildAdded] == 0}
414
-rebuild_sound rebuild-main-branch main.fossil
353
+repository_sound rebuild-main-branch main.fossil
415354
# A second rebuild finds the branch and adds nothing.
416355
set rebuildCount [rebuild_sql "SELECT count(*) FROM blob" main.fossil]
417356
fossil rebuild main.fossil
418357
test_eq rebuild-main-branch-once [rebuild_sql "SELECT count(*) FROM blob" \
419358
main.fossil] $rebuildCount
@@ -441,11 +380,11 @@
441380
FROM event WHERE type='ci'" damaged.fossil] $rebuildCheckins
442381
test_eq rebuild-damage-$rebuildName-phantoms [rebuild_sql "SELECT count(*)
443382
FROM phantom" damaged.fossil] 1
444383
fossil cat a.txt -r [lindex $rebuildTrunk 6] -R damaged.fossil
445384
test_eq rebuild-damage-$rebuildName-newest-readable "$RESULT\n" \
446
- $rebuildTrunkText(7)
385
+ $rebuildText
447386
}
448387
file delete damaged.fossil
449388
450389
###############################################################################
451390
# The full-text search index. Rebuild drops it and builds it again;
@@ -485,11 +424,11 @@
485424
[rebuild_indexed fts.fossil] $rebuildDocs
486425
fossil rebuild fts.fossil --noindex
487426
test rebuild-noindex {$CODE == 0}
488427
test_eq rebuild-noindex-gone [rebuild_indexed fts.fossil] none
489428
test_eq rebuild-index-state \
490
- [rebuild_diff $rebuildStart [rebuild_state fts.fossil]] ""
429
+ [repository_state_diff $rebuildStart [repository_state fts.fossil]] ""
491430
# --compress-only with --index on a repository that has no index makes one.
492431
fossil rebuild fts.fossil --compress-only --index
493432
test rebuild-compress-only-index-new {$CODE == 0 &&
494433
[rebuild_indexed fts.fossil] ne "none"}
495434
@@ -532,12 +471,12 @@
532471
test rebuild-$rebuildName {$CODE == 0 &&
533472
[string match $rebuildOut $RESULT]}
534473
test_eq rebuild-$rebuildName-deltas [rebuild_sql "SELECT count(*)
535474
FROM delta"] $rebuildDeltas
536475
test_eq rebuild-$rebuildName-state \
537
- [rebuild_diff $rebuildStart [rebuild_state]] ""
538
- rebuild_sound rebuild-$rebuildName
476
+ [repository_state_diff $rebuildStart [repository_state]] ""
477
+ repository_sound rebuild-$rebuildName
539478
}
540479
for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} {
541480
fossil cat n.txt -r [lindex $rebuildTrunk [expr {$rebuildI-1}]]
542481
test_eq rebuild-compress-content-$rebuildI "$RESULT\n" \
543482
[rebuild_noise $rebuildI 1500]
@@ -557,28 +496,24 @@
557496
test rebuild-detach-capital-new-code {[rebuild_sql "SELECT value FROM config
558497
WHERE name='project-code'" detach.fossil] ne $rebuildCode}
559498
test_eq rebuild-detach-capital-parent [rebuild_sql "SELECT value FROM config
560499
WHERE name='parent-project-code'" detach.fossil] $rebuildCode
561500
test_eq rebuild-detach-capital-state \
562
- [rebuild_diff $rebuildStart [rebuild_state detach.fossil]] ""
501
+ [repository_state_diff $rebuildStart [repository_state detach.fossil]] ""
563502
564503
###############################################################################
565504
# Scrub asks first. "y" and "Y" are both a yes.
566505
567
-proc rebuild_pw {repo} {
568
- return [rebuild_sql "SELECT count(*) FROM user WHERE pw<>''" $repo]
569
-}
570506
foreach {rebuildName rebuildAnswer} {small y capital Y} {
571507
file copy -force full.fossil scrub.fossil
572
- test rebuild-scrub-$rebuildName-setup {[rebuild_pw scrub.fossil] > 0}
508
+ test rebuild-scrub-$rebuildName-setup {[password_count scrub.fossil] > 0}
573509
fossil_raw -input "$rebuildAnswer\n" scrub scrub.fossil
574510
test rebuild-scrub-$rebuildName {$CODE == 0}
575
- test_eq rebuild-scrub-$rebuildName-passwords [rebuild_pw scrub.fossil] 0
511
+ test_eq rebuild-scrub-$rebuildName-passwords [password_count scrub.fossil] 0
576512
test_eq rebuild-scrub-$rebuildName-state \
577
- [rebuild_diff $rebuildStart [rebuild_state scrub.fossil]] ""
513
+ [repository_state_diff $rebuildStart [repository_state scrub.fossil]] ""
578514
}
579
-file delete scrub.fossil
580515
581516
###############################################################################
582517
# Deconstruct writes each artifact to a file named by its hash; private
583518
# ones only when asked. Reconstruct makes a repository of the same
584519
# artifacts from the files.
@@ -602,11 +537,11 @@
602537
$rebuildPublic
603538
test_eq rebuild-reconstruct-checkins [rebuild_sql "SELECT count(*) FROM event
604539
WHERE type='ci'" r-public.fossil] [expr {$rebuildCheckins - 2}]
605540
test_eq rebuild-reconstruct-none-private [rebuild_sql "SELECT count(*)
606541
FROM private" r-public.fossil] 0
607
-rebuild_sound rebuild-reconstruct r-public.fossil
542
+repository_sound rebuild-reconstruct r-public.fossil
608543
609544
# --quiet says nothing.
610545
file mkdir d-quiet
611546
fossil deconstruct -R full.fossil d-quiet --quiet
612547
test rebuild-deconstruct-quiet {$CODE == 0 && $RESULT eq ""}
@@ -645,24 +580,21 @@
645580
test_eq rebuild-reconstruct-keep-rid1 [rebuild_sql "SELECT uuid FROM blob
646581
WHERE rid=1" r-keep.fossil] $rebuildFirst
647582
test_eq rebuild-reconstruct-keep-private \
648583
[rebuild_hashes r-keep.fossil "rid IN private"] $rebuildPrivate
649584
test_eq rebuild-reconstruct-keep-state \
650
- [rebuild_diff $rebuildStart [rebuild_state r-keep.fossil]] ""
651
-fossil test-missing -R r-keep.fossil
652
-test rebuild-reconstruct-keep-missing {$CODE == 0}
653
-fossil test-integrity -R r-keep.fossil
654
-test rebuild-reconstruct-keep-integrity {$CODE == 0}
585
+ [repository_state_diff $rebuildStart [repository_state r-keep.fossil]] ""
586
+repository_sound rebuild-reconstruct-keep r-keep.fossil
655587
656588
# Without -P every artifact in the directory becomes public.
657589
fossil reconstruct r-private.fossil d-private
658590
test rebuild-reconstruct-private {$CODE == 0}
659591
test_eq rebuild-reconstruct-private-all [rebuild_hashes r-private.fossil] \
660592
$rebuildAll
661593
test_eq rebuild-reconstruct-private-none-private [rebuild_sql "SELECT count(*)
662594
FROM private" r-private.fossil] 0
663
-rebuild_sound rebuild-reconstruct-private r-private.fossil
595
+repository_sound rebuild-reconstruct-private r-private.fossil
664596
665597
# -L sets how many letters of the hash name the directory: none, or five.
666598
# With none, .rid1 names a file in the directory itself.
667599
file mkdir d-flat d-five
668600
fossil deconstruct -R full.fossil d-flat -L 0 -K
@@ -837,11 +769,10 @@
837769
lappend rebuildWant $rebuildH
838770
}
839771
}
840772
test_eq rebuild-deconstruct-damage-source-gone-files \
841773
[rebuild_names d-damaged] $rebuildWant
842
-file delete damaged.fossil
843774
844775
###############################################################################
845776
# Clusters. test-create-clusters makes one when a hundred or more
846777
# artifacts are in no cluster yet; test-clusters says whether every
847778
# artifact can be reached through them.
@@ -881,11 +812,11 @@
881812
fossil test-create-clusters .rep.fossil
882813
test_eq rebuild-create-clusters-two [rebuild_clusters] 2
883814
fossil test-clusters -R .rep.fossil
884815
test rebuild-clusters-two {$CODE == 0 &&
885816
[string match "*all artifacts reachable through clusters*" $RESULT]}
886
-rebuild_sound rebuild-clusters
817
+repository_sound rebuild-clusters
887818
888819
# When the newest cluster is purged, what it listed is in no cluster and
889820
# test-clusters lists each such artifact.
890821
set rebuildNewest [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT
891822
max(rid) FROM tagxref WHERE tagid=(SELECT tagid FROM tag
@@ -900,15 +831,15 @@
900831
[regexp -all -line {^ +\d+ [0-9a-f]{64}$} $RESULT] $rebuildCount
901832
902833
# A cluster whose content has been replaced with SQL by that of a file.
903834
file copy -force .rep.fossil cluster.fossil
904835
fossil sql -R cluster.fossil "UPDATE blob
905
- SET content=(SELECT content FROM blob WHERE uuid='[rebuild_file_hash \
836
+ SET content=(SELECT content FROM blob WHERE uuid='[checkin_file_hash \
906837
$rebuildSide b.txt]')
907838
WHERE uuid='$rebuildNewest'"
908839
fossil test-clusters -R cluster.fossil -expectError
909840
test rebuild-clusters-bad-cluster {$CODE != 0 &&
910841
[string match "*bad cluster: rid=*" $RESULT]}
911842
912843
###############################################################################
913844
914845
test_cleanup
915846
--- test/rebuild.test
+++ test/rebuild.test
@@ -5,80 +5,18 @@
5 # what a repository holds: after each, the artifacts, the timeline and the
6 # links between check-ins and files are compared with what was there
7 # before, and the repository must still be sound.
8 #
9
10 # These tests run only in a long pass: -assurance stress.
11 if {[test_assurance] ne "stress"} {
12 test_skip "runs only with -assurance stress"
13 }
14
15 require_no_open_checkout
16
17 test_setup
18
19 proc rebuild_sql {sql {repo .rep.fossil}} {
20 fossil sql -R $repo $sql
21 return [string trim $::RESULT]
22 }
23
24 # What a repository holds, by hash rather than by record number: the
25 # artifacts with their private flag, the timeline, the parent links, the
26 # files of each check-in, the leaves and the tags.
27 #
28 proc rebuild_state {{repo .rep.fossil}} {
29 return [rebuild_sql {
30 SELECT 'blob', uuid, rid IN private FROM blob WHERE size>=0
31 UNION ALL
32 SELECT 'event', b.uuid, e.type || ' ' || ifnull(e.comment,'')
33 FROM event e JOIN blob b ON b.rid=e.objid
34 UNION ALL
35 SELECT 'plink', p.uuid, c.uuid FROM plink
36 JOIN blob p ON p.rid=plink.pid JOIN blob c ON c.rid=plink.cid
37 UNION ALL
38 SELECT 'mlink', m.uuid, f.uuid || ' ' || fn.name FROM mlink
39 JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
40 JOIN filename fn ON fn.fnid=mlink.fnid
41 UNION ALL
42 SELECT 'leaf', uuid, '' FROM leaf JOIN blob USING(rid)
43 UNION ALL
44 SELECT 'tag', b.uuid, t.tagname || '=' || ifnull(x.value,'')
45 FROM tagxref x JOIN tag t USING(tagid) JOIN blob b ON b.rid=x.rid
46 WHERE x.tagtype>0
47 ORDER BY 1, 2, 3
48 } $repo]
49 }
50
51 # The rows that are in one state and not in the other, marked "-" for
52 # the first and "+" for the second. Empty when the two are the same.
53 #
54 proc rebuild_diff {a b} {
55 set la [split $a \n]
56 set lb [split $b \n]
57 set out {}
58 foreach x $la { if {[lsearch -exact $lb $x] < 0} { lappend out "- $x" } }
59 foreach x $lb { if {[lsearch -exact $la $x] < 0} { lappend out "+ $x" } }
60 return [join $out \n]
61 }
62
63 proc rebuild_sound {name {repo .rep.fossil}} {
64 fossil test-integrity -R $repo
65 test $name-integrity {$::CODE == 0}
66 fossil test-missing -R $repo
67 test $name-missing {$::CODE == 0}
68 }
69
70 proc rebuild_hash {comment} {
71 return [rebuild_sql "SELECT uuid FROM blob, event
72 WHERE objid=rid AND comment='$comment'"]
73 }
74
75 proc rebuild_file_hash {checkin file {repo .rep.fossil}} {
76 return [rebuild_sql "SELECT f.uuid FROM mlink
77 JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
78 JOIN filename fn ON fn.fnid=mlink.fnid
79 WHERE m.uuid='$checkin' AND fn.name='$file'" $repo]
80 }
81
82 # The hashes of the artifacts a repository has the content of, in order;
83 # WHERE narrows them.
84 proc rebuild_hashes {repo {where 1}} {
@@ -139,42 +77,38 @@
139 append rebuildText "version $rebuildI\n"
140 write_file a.txt $rebuildText
141 write_file n.txt [rebuild_noise $rebuildI 1500]
142 if {$rebuildI == 1} {fossil add a.txt n.txt}
143 fossil commit -m rebuild-trunk-$rebuildI --no-warnings
144 lappend rebuildTrunk [rebuild_hash rebuild-trunk-$rebuildI]
145 set rebuildTrunkText($rebuildI) $rebuildText
146 }
147 fossil update [lindex $rebuildTrunk 2]
148 fossil branch new side current
149 fossil update side
150 write_file b.txt "a file only the branch has\n"
151 fossil add b.txt
152 fossil commit -m rebuild-side-1 --no-warnings
153 set rebuildSide [rebuild_hash rebuild-side-1]
154 fossil update trunk
155 fossil tag add rebuild-tag [lindex $rebuildTrunk 1]
156 write_file page.txt "A wiki page.\n"
157 fossil wiki create RebuildPage page.txt
158 fossil ticket add title "a ticket" status Open
159 set rebuildSecretText ""
160 for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} {
161 append rebuildSecretText "line $rebuildI of private content\n"
162 }
163 write_file secret.txt $rebuildSecretText
164 fossil add secret.txt
165 fossil commit -m rebuild-secret-1 --no-warnings --private --branch secret
166 set rebuildSecret1 [rebuild_hash rebuild-secret-1]
167 write_file secret.txt "${rebuildSecretText}one more\n"
168 fossil commit -m rebuild-secret-2 --no-warnings
169 set rebuildSecret2 [rebuild_hash rebuild-secret-2]
170 set rebuildSecretFile1 [rebuild_file_hash $rebuildSecret1 secret.txt]
171 set rebuildSecretFile2 [rebuild_file_hash $rebuildSecret2 secret.txt]
172 fossil update trunk
173
174 rebuild_sound rebuild-start
175 set rebuildStart [rebuild_state]
176 set rebuildAll [rebuild_hashes .rep.fossil]
177 set rebuildPublic [rebuild_hashes .rep.fossil "rid NOT IN private"]
178 test rebuild-start-setup {[llength $rebuildAll] > [llength $rebuildPublic] &&
179 [rebuild_sql "SELECT count(*) FROM delta"] > 0}
180 file copy .rep.fossil full.fossil
@@ -234,12 +168,16 @@
234 test rebuild-$rebuildName {$CODE == 0 &&
235 [string match $rebuildOut $RESULT]}
236 test_eq rebuild-$rebuildName-effect [rebuild_sql $rebuildQuery r.fossil] \
237 $rebuildWant
238 test_eq rebuild-$rebuildName-state \
239 [rebuild_diff $rebuildStart [rebuild_state r.fossil]] ""
240 rebuild_sound rebuild-$rebuildName r.fossil
 
 
 
 
241 }
242
243 # --deanalyze removes the statistics that --analyze made. The file is
244 # read with --no-repository, because a command that opens the repository
245 # runs PRAGMA optimize when it closes it, which makes them again.
@@ -249,11 +187,11 @@
249 test rebuild-deanalyze {$CODE == 0}
250 fossil sql --no-repository r.fossil \
251 "SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'"
252 test_eq rebuild-deanalyze-effect [string trim $RESULT] 0
253 test_eq rebuild-deanalyze-state \
254 [rebuild_diff $rebuildStart [rebuild_state r.fossil]] ""
255
256 # --stats counts each kind of artifact.
257 fossil rebuild r.fossil --stats
258 set rebuildStats $RESULT
259 foreach {rebuildName rebuildLabel rebuildType} {
@@ -296,19 +234,20 @@
296 test_eq rebuild-ifneeded-needed-schema [rebuild_sql "SELECT value FROM config
297 WHERE name='aux-schema'" r.fossil] $rebuildSchema
298 test rebuild-ifneeded-needed-rebuilt {[rebuild_sql "SELECT mtime FROM config
299 WHERE name='rebuilt'" r.fossil] > 1}
300 test_eq rebuild-ifneeded-needed-state \
301 [rebuild_diff $rebuildStart [rebuild_state r.fossil]] ""
302
303 # Two repository names are one too many. Without a name, the repository
304 # of the check-out is rebuilt.
305 fossil rebuild r.fossil full.fossil -expectError
306 test rebuild-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]}
307 fossil rebuild
308 test rebuild-checkout {$CODE == 0}
309 test_eq rebuild-checkout-state [rebuild_diff $rebuildStart [rebuild_state]] ""
 
310
311 ###############################################################################
312 # A repository with the table definitions of an old Fossil: no baseid in
313 # plink (before 2014-11-28), no pmid and isaux in mlink (before
314 # 2015-01-24), no mtime in user, config, shun, reportfmt and concealed
@@ -385,12 +324,12 @@
385 test_eq rebuild-old-schema-reports-dated [rebuild_sql "SELECT count(*)
386 FROM reportfmt WHERE mtime IS NULL" old.fossil] 0
387 test_eq rebuild-old-schema-concealed [rebuild_sql "SELECT hash, content,
388 mtime>1 FROM concealed" old.fossil] "abc|[email protected]|1"
389 test_eq rebuild-old-schema-state \
390 [rebuild_diff $rebuildStart [rebuild_state old.fossil]] ""
391 rebuild_sound rebuild-old-schema old.fossil
392
393 ###############################################################################
394 # When the main-branch setting names a branch that no check-in has,
395 # rebuild puts the first check-in on it. Everything that was there stays.
396
@@ -405,15 +344,15 @@
405 test_eq rebuild-main-branch-tagged [rebuild_sql "SELECT count(*)
406 FROM tagxref JOIN tag USING(tagid) JOIN blob USING(rid)
407 WHERE tagname='sym-primary' AND tagtype=2 AND srcid>0
408 AND uuid='$rebuildRoot'" main.fossil] 1
409 # The two artifacts that carry the new tags are all that is added.
410 set rebuildAdded [rebuild_diff [join $rebuildAll \n] \
411 [join [rebuild_hashes main.fossil] \n]]
412 test rebuild-main-branch-kept {[regexp -all -line {^\+ } $rebuildAdded] == 2 &&
413 [regexp -all -line {^- } $rebuildAdded] == 0}
414 rebuild_sound rebuild-main-branch main.fossil
415 # A second rebuild finds the branch and adds nothing.
416 set rebuildCount [rebuild_sql "SELECT count(*) FROM blob" main.fossil]
417 fossil rebuild main.fossil
418 test_eq rebuild-main-branch-once [rebuild_sql "SELECT count(*) FROM blob" \
419 main.fossil] $rebuildCount
@@ -441,11 +380,11 @@
441 FROM event WHERE type='ci'" damaged.fossil] $rebuildCheckins
442 test_eq rebuild-damage-$rebuildName-phantoms [rebuild_sql "SELECT count(*)
443 FROM phantom" damaged.fossil] 1
444 fossil cat a.txt -r [lindex $rebuildTrunk 6] -R damaged.fossil
445 test_eq rebuild-damage-$rebuildName-newest-readable "$RESULT\n" \
446 $rebuildTrunkText(7)
447 }
448 file delete damaged.fossil
449
450 ###############################################################################
451 # The full-text search index. Rebuild drops it and builds it again;
@@ -485,11 +424,11 @@
485 [rebuild_indexed fts.fossil] $rebuildDocs
486 fossil rebuild fts.fossil --noindex
487 test rebuild-noindex {$CODE == 0}
488 test_eq rebuild-noindex-gone [rebuild_indexed fts.fossil] none
489 test_eq rebuild-index-state \
490 [rebuild_diff $rebuildStart [rebuild_state fts.fossil]] ""
491 # --compress-only with --index on a repository that has no index makes one.
492 fossil rebuild fts.fossil --compress-only --index
493 test rebuild-compress-only-index-new {$CODE == 0 &&
494 [rebuild_indexed fts.fossil] ne "none"}
495
@@ -532,12 +471,12 @@
532 test rebuild-$rebuildName {$CODE == 0 &&
533 [string match $rebuildOut $RESULT]}
534 test_eq rebuild-$rebuildName-deltas [rebuild_sql "SELECT count(*)
535 FROM delta"] $rebuildDeltas
536 test_eq rebuild-$rebuildName-state \
537 [rebuild_diff $rebuildStart [rebuild_state]] ""
538 rebuild_sound rebuild-$rebuildName
539 }
540 for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} {
541 fossil cat n.txt -r [lindex $rebuildTrunk [expr {$rebuildI-1}]]
542 test_eq rebuild-compress-content-$rebuildI "$RESULT\n" \
543 [rebuild_noise $rebuildI 1500]
@@ -557,28 +496,24 @@
557 test rebuild-detach-capital-new-code {[rebuild_sql "SELECT value FROM config
558 WHERE name='project-code'" detach.fossil] ne $rebuildCode}
559 test_eq rebuild-detach-capital-parent [rebuild_sql "SELECT value FROM config
560 WHERE name='parent-project-code'" detach.fossil] $rebuildCode
561 test_eq rebuild-detach-capital-state \
562 [rebuild_diff $rebuildStart [rebuild_state detach.fossil]] ""
563
564 ###############################################################################
565 # Scrub asks first. "y" and "Y" are both a yes.
566
567 proc rebuild_pw {repo} {
568 return [rebuild_sql "SELECT count(*) FROM user WHERE pw<>''" $repo]
569 }
570 foreach {rebuildName rebuildAnswer} {small y capital Y} {
571 file copy -force full.fossil scrub.fossil
572 test rebuild-scrub-$rebuildName-setup {[rebuild_pw scrub.fossil] > 0}
573 fossil_raw -input "$rebuildAnswer\n" scrub scrub.fossil
574 test rebuild-scrub-$rebuildName {$CODE == 0}
575 test_eq rebuild-scrub-$rebuildName-passwords [rebuild_pw scrub.fossil] 0
576 test_eq rebuild-scrub-$rebuildName-state \
577 [rebuild_diff $rebuildStart [rebuild_state scrub.fossil]] ""
578 }
579 file delete scrub.fossil
580
581 ###############################################################################
582 # Deconstruct writes each artifact to a file named by its hash; private
583 # ones only when asked. Reconstruct makes a repository of the same
584 # artifacts from the files.
@@ -602,11 +537,11 @@
602 $rebuildPublic
603 test_eq rebuild-reconstruct-checkins [rebuild_sql "SELECT count(*) FROM event
604 WHERE type='ci'" r-public.fossil] [expr {$rebuildCheckins - 2}]
605 test_eq rebuild-reconstruct-none-private [rebuild_sql "SELECT count(*)
606 FROM private" r-public.fossil] 0
607 rebuild_sound rebuild-reconstruct r-public.fossil
608
609 # --quiet says nothing.
610 file mkdir d-quiet
611 fossil deconstruct -R full.fossil d-quiet --quiet
612 test rebuild-deconstruct-quiet {$CODE == 0 && $RESULT eq ""}
@@ -645,24 +580,21 @@
645 test_eq rebuild-reconstruct-keep-rid1 [rebuild_sql "SELECT uuid FROM blob
646 WHERE rid=1" r-keep.fossil] $rebuildFirst
647 test_eq rebuild-reconstruct-keep-private \
648 [rebuild_hashes r-keep.fossil "rid IN private"] $rebuildPrivate
649 test_eq rebuild-reconstruct-keep-state \
650 [rebuild_diff $rebuildStart [rebuild_state r-keep.fossil]] ""
651 fossil test-missing -R r-keep.fossil
652 test rebuild-reconstruct-keep-missing {$CODE == 0}
653 fossil test-integrity -R r-keep.fossil
654 test rebuild-reconstruct-keep-integrity {$CODE == 0}
655
656 # Without -P every artifact in the directory becomes public.
657 fossil reconstruct r-private.fossil d-private
658 test rebuild-reconstruct-private {$CODE == 0}
659 test_eq rebuild-reconstruct-private-all [rebuild_hashes r-private.fossil] \
660 $rebuildAll
661 test_eq rebuild-reconstruct-private-none-private [rebuild_sql "SELECT count(*)
662 FROM private" r-private.fossil] 0
663 rebuild_sound rebuild-reconstruct-private r-private.fossil
664
665 # -L sets how many letters of the hash name the directory: none, or five.
666 # With none, .rid1 names a file in the directory itself.
667 file mkdir d-flat d-five
668 fossil deconstruct -R full.fossil d-flat -L 0 -K
@@ -837,11 +769,10 @@
837 lappend rebuildWant $rebuildH
838 }
839 }
840 test_eq rebuild-deconstruct-damage-source-gone-files \
841 [rebuild_names d-damaged] $rebuildWant
842 file delete damaged.fossil
843
844 ###############################################################################
845 # Clusters. test-create-clusters makes one when a hundred or more
846 # artifacts are in no cluster yet; test-clusters says whether every
847 # artifact can be reached through them.
@@ -881,11 +812,11 @@
881 fossil test-create-clusters .rep.fossil
882 test_eq rebuild-create-clusters-two [rebuild_clusters] 2
883 fossil test-clusters -R .rep.fossil
884 test rebuild-clusters-two {$CODE == 0 &&
885 [string match "*all artifacts reachable through clusters*" $RESULT]}
886 rebuild_sound rebuild-clusters
887
888 # When the newest cluster is purged, what it listed is in no cluster and
889 # test-clusters lists each such artifact.
890 set rebuildNewest [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT
891 max(rid) FROM tagxref WHERE tagid=(SELECT tagid FROM tag
@@ -900,15 +831,15 @@
900 [regexp -all -line {^ +\d+ [0-9a-f]{64}$} $RESULT] $rebuildCount
901
902 # A cluster whose content has been replaced with SQL by that of a file.
903 file copy -force .rep.fossil cluster.fossil
904 fossil sql -R cluster.fossil "UPDATE blob
905 SET content=(SELECT content FROM blob WHERE uuid='[rebuild_file_hash \
906 $rebuildSide b.txt]')
907 WHERE uuid='$rebuildNewest'"
908 fossil test-clusters -R cluster.fossil -expectError
909 test rebuild-clusters-bad-cluster {$CODE != 0 &&
910 [string match "*bad cluster: rid=*" $RESULT]}
911
912 ###############################################################################
913
914 test_cleanup
915
--- test/rebuild.test
+++ test/rebuild.test
@@ -5,80 +5,18 @@
5 # what a repository holds: after each, the artifacts, the timeline and the
6 # links between check-ins and files are compared with what was there
7 # before, and the repository must still be sound.
8 #
9
10 # The first sections run at every level, and the rest need
11 # -assurance stress.
 
 
 
12 require_no_open_checkout
13
14 test_setup
15
16 proc rebuild_sql {sql {repo .rep.fossil}} {
17 return [fossil_sql $sql $repo]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18 }
19
20 # The hashes of the artifacts a repository has the content of, in order;
21 # WHERE narrows them.
22 proc rebuild_hashes {repo {where 1}} {
@@ -139,42 +77,38 @@
77 append rebuildText "version $rebuildI\n"
78 write_file a.txt $rebuildText
79 write_file n.txt [rebuild_noise $rebuildI 1500]
80 if {$rebuildI == 1} {fossil add a.txt n.txt}
81 fossil commit -m rebuild-trunk-$rebuildI --no-warnings
82 lappend rebuildTrunk [checkin_hash rebuild-trunk-$rebuildI]
 
83 }
84 fossil update [lindex $rebuildTrunk 2]
85 fossil branch new side current
86 fossil update side
87 commit_file b.txt "a file only the branch has\n" rebuild-side-1 --no-warnings
88 set rebuildSide [checkin_hash rebuild-side-1]
 
 
89 fossil update trunk
90 fossil tag add rebuild-tag [lindex $rebuildTrunk 1]
91 write_file page.txt "A wiki page.\n"
92 fossil wiki create RebuildPage page.txt
93 fossil ticket add title "a ticket" status Open
94 set rebuildSecretText ""
95 for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} {
96 append rebuildSecretText "line $rebuildI of private content\n"
97 }
98 commit_file secret.txt $rebuildSecretText rebuild-secret-1 --no-warnings \
99 --private --branch secret
100 set rebuildSecret1 [checkin_hash rebuild-secret-1]
 
101 write_file secret.txt "${rebuildSecretText}one more\n"
102 fossil commit -m rebuild-secret-2 --no-warnings
103 set rebuildSecret2 [checkin_hash rebuild-secret-2]
104 set rebuildSecretFile1 [checkin_file_hash $rebuildSecret1 secret.txt]
105 set rebuildSecretFile2 [checkin_file_hash $rebuildSecret2 secret.txt]
106 fossil update trunk
107
108 repository_sound rebuild-start
109 set rebuildStart [repository_state]
110 set rebuildAll [rebuild_hashes .rep.fossil]
111 set rebuildPublic [rebuild_hashes .rep.fossil "rid NOT IN private"]
112 test rebuild-start-setup {[llength $rebuildAll] > [llength $rebuildPublic] &&
113 [rebuild_sql "SELECT count(*) FROM delta"] > 0}
114 file copy .rep.fossil full.fossil
@@ -234,12 +168,16 @@
168 test rebuild-$rebuildName {$CODE == 0 &&
169 [string match $rebuildOut $RESULT]}
170 test_eq rebuild-$rebuildName-effect [rebuild_sql $rebuildQuery r.fossil] \
171 $rebuildWant
172 test_eq rebuild-$rebuildName-state \
173 [repository_state_diff $rebuildStart [repository_state r.fossil]] ""
174 repository_sound rebuild-$rebuildName r.fossil
175 }
176
177 if {[test_assurance] ne "stress"} {
178 test_skip "the tests after the first sections need -assurance stress"
179 }
180
181 # --deanalyze removes the statistics that --analyze made. The file is
182 # read with --no-repository, because a command that opens the repository
183 # runs PRAGMA optimize when it closes it, which makes them again.
@@ -249,11 +187,11 @@
187 test rebuild-deanalyze {$CODE == 0}
188 fossil sql --no-repository r.fossil \
189 "SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'"
190 test_eq rebuild-deanalyze-effect [string trim $RESULT] 0
191 test_eq rebuild-deanalyze-state \
192 [repository_state_diff $rebuildStart [repository_state r.fossil]] ""
193
194 # --stats counts each kind of artifact.
195 fossil rebuild r.fossil --stats
196 set rebuildStats $RESULT
197 foreach {rebuildName rebuildLabel rebuildType} {
@@ -296,19 +234,20 @@
234 test_eq rebuild-ifneeded-needed-schema [rebuild_sql "SELECT value FROM config
235 WHERE name='aux-schema'" r.fossil] $rebuildSchema
236 test rebuild-ifneeded-needed-rebuilt {[rebuild_sql "SELECT mtime FROM config
237 WHERE name='rebuilt'" r.fossil] > 1}
238 test_eq rebuild-ifneeded-needed-state \
239 [repository_state_diff $rebuildStart [repository_state r.fossil]] ""
240
241 # Two repository names are one too many. Without a name, the repository
242 # of the check-out is rebuilt.
243 fossil rebuild r.fossil full.fossil -expectError
244 test rebuild-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]}
245 fossil rebuild
246 test rebuild-checkout {$CODE == 0}
247 test_eq rebuild-checkout-state \
248 [repository_state_diff $rebuildStart [repository_state]] ""
249
250 ###############################################################################
251 # A repository with the table definitions of an old Fossil: no baseid in
252 # plink (before 2014-11-28), no pmid and isaux in mlink (before
253 # 2015-01-24), no mtime in user, config, shun, reportfmt and concealed
@@ -385,12 +324,12 @@
324 test_eq rebuild-old-schema-reports-dated [rebuild_sql "SELECT count(*)
325 FROM reportfmt WHERE mtime IS NULL" old.fossil] 0
326 test_eq rebuild-old-schema-concealed [rebuild_sql "SELECT hash, content,
327 mtime>1 FROM concealed" old.fossil] "abc|[email protected]|1"
328 test_eq rebuild-old-schema-state \
329 [repository_state_diff $rebuildStart [repository_state old.fossil]] ""
330 repository_sound rebuild-old-schema old.fossil
331
332 ###############################################################################
333 # When the main-branch setting names a branch that no check-in has,
334 # rebuild puts the first check-in on it. Everything that was there stays.
335
@@ -405,15 +344,15 @@
344 test_eq rebuild-main-branch-tagged [rebuild_sql "SELECT count(*)
345 FROM tagxref JOIN tag USING(tagid) JOIN blob USING(rid)
346 WHERE tagname='sym-primary' AND tagtype=2 AND srcid>0
347 AND uuid='$rebuildRoot'" main.fossil] 1
348 # The two artifacts that carry the new tags are all that is added.
349 set rebuildAdded [repository_state_diff [join $rebuildAll \n] \
350 [join [rebuild_hashes main.fossil] \n]]
351 test rebuild-main-branch-kept {[regexp -all -line {^\+ } $rebuildAdded] == 2 &&
352 [regexp -all -line {^- } $rebuildAdded] == 0}
353 repository_sound rebuild-main-branch main.fossil
354 # A second rebuild finds the branch and adds nothing.
355 set rebuildCount [rebuild_sql "SELECT count(*) FROM blob" main.fossil]
356 fossil rebuild main.fossil
357 test_eq rebuild-main-branch-once [rebuild_sql "SELECT count(*) FROM blob" \
358 main.fossil] $rebuildCount
@@ -441,11 +380,11 @@
380 FROM event WHERE type='ci'" damaged.fossil] $rebuildCheckins
381 test_eq rebuild-damage-$rebuildName-phantoms [rebuild_sql "SELECT count(*)
382 FROM phantom" damaged.fossil] 1
383 fossil cat a.txt -r [lindex $rebuildTrunk 6] -R damaged.fossil
384 test_eq rebuild-damage-$rebuildName-newest-readable "$RESULT\n" \
385 $rebuildText
386 }
387 file delete damaged.fossil
388
389 ###############################################################################
390 # The full-text search index. Rebuild drops it and builds it again;
@@ -485,11 +424,11 @@
424 [rebuild_indexed fts.fossil] $rebuildDocs
425 fossil rebuild fts.fossil --noindex
426 test rebuild-noindex {$CODE == 0}
427 test_eq rebuild-noindex-gone [rebuild_indexed fts.fossil] none
428 test_eq rebuild-index-state \
429 [repository_state_diff $rebuildStart [repository_state fts.fossil]] ""
430 # --compress-only with --index on a repository that has no index makes one.
431 fossil rebuild fts.fossil --compress-only --index
432 test rebuild-compress-only-index-new {$CODE == 0 &&
433 [rebuild_indexed fts.fossil] ne "none"}
434
@@ -532,12 +471,12 @@
471 test rebuild-$rebuildName {$CODE == 0 &&
472 [string match $rebuildOut $RESULT]}
473 test_eq rebuild-$rebuildName-deltas [rebuild_sql "SELECT count(*)
474 FROM delta"] $rebuildDeltas
475 test_eq rebuild-$rebuildName-state \
476 [repository_state_diff $rebuildStart [repository_state]] ""
477 repository_sound rebuild-$rebuildName
478 }
479 for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} {
480 fossil cat n.txt -r [lindex $rebuildTrunk [expr {$rebuildI-1}]]
481 test_eq rebuild-compress-content-$rebuildI "$RESULT\n" \
482 [rebuild_noise $rebuildI 1500]
@@ -557,28 +496,24 @@
496 test rebuild-detach-capital-new-code {[rebuild_sql "SELECT value FROM config
497 WHERE name='project-code'" detach.fossil] ne $rebuildCode}
498 test_eq rebuild-detach-capital-parent [rebuild_sql "SELECT value FROM config
499 WHERE name='parent-project-code'" detach.fossil] $rebuildCode
500 test_eq rebuild-detach-capital-state \
501 [repository_state_diff $rebuildStart [repository_state detach.fossil]] ""
502
503 ###############################################################################
504 # Scrub asks first. "y" and "Y" are both a yes.
505
 
 
 
506 foreach {rebuildName rebuildAnswer} {small y capital Y} {
507 file copy -force full.fossil scrub.fossil
508 test rebuild-scrub-$rebuildName-setup {[password_count scrub.fossil] > 0}
509 fossil_raw -input "$rebuildAnswer\n" scrub scrub.fossil
510 test rebuild-scrub-$rebuildName {$CODE == 0}
511 test_eq rebuild-scrub-$rebuildName-passwords [password_count scrub.fossil] 0
512 test_eq rebuild-scrub-$rebuildName-state \
513 [repository_state_diff $rebuildStart [repository_state scrub.fossil]] ""
514 }
 
515
516 ###############################################################################
517 # Deconstruct writes each artifact to a file named by its hash; private
518 # ones only when asked. Reconstruct makes a repository of the same
519 # artifacts from the files.
@@ -602,11 +537,11 @@
537 $rebuildPublic
538 test_eq rebuild-reconstruct-checkins [rebuild_sql "SELECT count(*) FROM event
539 WHERE type='ci'" r-public.fossil] [expr {$rebuildCheckins - 2}]
540 test_eq rebuild-reconstruct-none-private [rebuild_sql "SELECT count(*)
541 FROM private" r-public.fossil] 0
542 repository_sound rebuild-reconstruct r-public.fossil
543
544 # --quiet says nothing.
545 file mkdir d-quiet
546 fossil deconstruct -R full.fossil d-quiet --quiet
547 test rebuild-deconstruct-quiet {$CODE == 0 && $RESULT eq ""}
@@ -645,24 +580,21 @@
580 test_eq rebuild-reconstruct-keep-rid1 [rebuild_sql "SELECT uuid FROM blob
581 WHERE rid=1" r-keep.fossil] $rebuildFirst
582 test_eq rebuild-reconstruct-keep-private \
583 [rebuild_hashes r-keep.fossil "rid IN private"] $rebuildPrivate
584 test_eq rebuild-reconstruct-keep-state \
585 [repository_state_diff $rebuildStart [repository_state r-keep.fossil]] ""
586 repository_sound rebuild-reconstruct-keep r-keep.fossil
 
 
 
587
588 # Without -P every artifact in the directory becomes public.
589 fossil reconstruct r-private.fossil d-private
590 test rebuild-reconstruct-private {$CODE == 0}
591 test_eq rebuild-reconstruct-private-all [rebuild_hashes r-private.fossil] \
592 $rebuildAll
593 test_eq rebuild-reconstruct-private-none-private [rebuild_sql "SELECT count(*)
594 FROM private" r-private.fossil] 0
595 repository_sound rebuild-reconstruct-private r-private.fossil
596
597 # -L sets how many letters of the hash name the directory: none, or five.
598 # With none, .rid1 names a file in the directory itself.
599 file mkdir d-flat d-five
600 fossil deconstruct -R full.fossil d-flat -L 0 -K
@@ -837,11 +769,10 @@
769 lappend rebuildWant $rebuildH
770 }
771 }
772 test_eq rebuild-deconstruct-damage-source-gone-files \
773 [rebuild_names d-damaged] $rebuildWant
 
774
775 ###############################################################################
776 # Clusters. test-create-clusters makes one when a hundred or more
777 # artifacts are in no cluster yet; test-clusters says whether every
778 # artifact can be reached through them.
@@ -881,11 +812,11 @@
812 fossil test-create-clusters .rep.fossil
813 test_eq rebuild-create-clusters-two [rebuild_clusters] 2
814 fossil test-clusters -R .rep.fossil
815 test rebuild-clusters-two {$CODE == 0 &&
816 [string match "*all artifacts reachable through clusters*" $RESULT]}
817 repository_sound rebuild-clusters
818
819 # When the newest cluster is purged, what it listed is in no cluster and
820 # test-clusters lists each such artifact.
821 set rebuildNewest [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT
822 max(rid) FROM tagxref WHERE tagid=(SELECT tagid FROM tag
@@ -900,15 +831,15 @@
831 [regexp -all -line {^ +\d+ [0-9a-f]{64}$} $RESULT] $rebuildCount
832
833 # A cluster whose content has been replaced with SQL by that of a file.
834 file copy -force .rep.fossil cluster.fossil
835 fossil sql -R cluster.fossil "UPDATE blob
836 SET content=(SELECT content FROM blob WHERE uuid='[checkin_file_hash \
837 $rebuildSide b.txt]')
838 WHERE uuid='$rebuildNewest'"
839 fossil test-clusters -R cluster.fossil -expectError
840 test rebuild-clusters-bad-cluster {$CODE != 0 &&
841 [string match "*bad cluster: rid=*" $RESULT]}
842
843 ###############################################################################
844
845 test_cleanup
846
--- test/regress.test
+++ test/regress.test
@@ -1,14 +1,9 @@
11
#
22
# Tests for faults that have been fixed, which have no better home.
33
#
44
5
-# These tests run only in a long pass: -assurance stress.
6
-if {[test_assurance] ne "stress"} {
7
- test_skip "runs only with -assurance stress"
8
-}
9
-
105
require_no_open_checkout
116
127
test_setup
138
149
write_file a.txt "a\n"
@@ -93,11 +88,10 @@
9388
$regressSvnHead[regress_svn_rev 0 $regressProps]
9489
fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
9590
svn-$regressName.dump
9691
test regress-svn-import-$regressName \
9792
{$CODE == 1 && [string match "*svn-dump data*" $RESULT]}
98
- file delete svn-$regressName.fossil
9993
}
10094
10195
set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z}
10296
set regressSvnSound $regressSvnHead
10397
append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]]
@@ -104,11 +98,10 @@
10498
append regressSvnSound [regress_svn_rev 1 [regress_svn_props \
10599
[concat {svn:log first svn:author dan} $regressSvnDate]]]
106100
write_file svn-sound.dump $regressSvnSound
107101
fossil import --svn svn-sound.fossil svn-sound.dump
108102
test regress-svn-import-sound {$CODE == 0}
109
-file delete svn-sound.fossil
110103
111104
###############################################################################
112105
# Two more malformed property blocks for "fossil import --svn": one with a
113106
# NUL byte in it, and one whose length is negative. Each is refused.
114107
@@ -120,11 +113,10 @@
120113
foreach regressName {nul-in-block negative-block} {
121114
fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
122115
svn-$regressName.dump
123116
test regress-svn-import-$regressName \
124117
{$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
125
- file delete svn-$regressName.fossil
126118
}
127119
128120
###############################################################################
129121
# A Markdown header that holds an HTML comment is read within its bounds
130122
# when its id is made. A fault here shows only in a build with run-time
@@ -252,11 +244,10 @@
252244
test regress-push-held-attachment {$CODE == 0
253245
&& ![string match "*UNIQUE constraint*" $RESULT]}
254246
fossil sql -R regress-attach-clone.fossil \
255247
"SELECT count(*) FROM attachment WHERE target='AttachPage'"
256248
test_eq regress-push-held-attachment-rows [string trim $RESULT] 1
257
-file delete regress-attach-clone.fossil
258249
259250
###############################################################################
260251
# The TH1 command styleHeader run from the command line writes the page
261252
# header, whatever the robot-restrict setting.
262253
@@ -278,8 +269,6 @@
278269
fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl
279270
test regress-baseurl-no-path-$regressName \
280271
{$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]}
281272
}
282273
283
-###############################################################################
284
-
285274
test_cleanup
286275
--- test/regress.test
+++ test/regress.test
@@ -1,14 +1,9 @@
1 #
2 # Tests for faults that have been fixed, which have no better home.
3 #
4
5 # These tests run only in a long pass: -assurance stress.
6 if {[test_assurance] ne "stress"} {
7 test_skip "runs only with -assurance stress"
8 }
9
10 require_no_open_checkout
11
12 test_setup
13
14 write_file a.txt "a\n"
@@ -93,11 +88,10 @@
93 $regressSvnHead[regress_svn_rev 0 $regressProps]
94 fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
95 svn-$regressName.dump
96 test regress-svn-import-$regressName \
97 {$CODE == 1 && [string match "*svn-dump data*" $RESULT]}
98 file delete svn-$regressName.fossil
99 }
100
101 set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z}
102 set regressSvnSound $regressSvnHead
103 append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]]
@@ -104,11 +98,10 @@
104 append regressSvnSound [regress_svn_rev 1 [regress_svn_props \
105 [concat {svn:log first svn:author dan} $regressSvnDate]]]
106 write_file svn-sound.dump $regressSvnSound
107 fossil import --svn svn-sound.fossil svn-sound.dump
108 test regress-svn-import-sound {$CODE == 0}
109 file delete svn-sound.fossil
110
111 ###############################################################################
112 # Two more malformed property blocks for "fossil import --svn": one with a
113 # NUL byte in it, and one whose length is negative. Each is refused.
114
@@ -120,11 +113,10 @@
120 foreach regressName {nul-in-block negative-block} {
121 fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
122 svn-$regressName.dump
123 test regress-svn-import-$regressName \
124 {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
125 file delete svn-$regressName.fossil
126 }
127
128 ###############################################################################
129 # A Markdown header that holds an HTML comment is read within its bounds
130 # when its id is made. A fault here shows only in a build with run-time
@@ -252,11 +244,10 @@
252 test regress-push-held-attachment {$CODE == 0
253 && ![string match "*UNIQUE constraint*" $RESULT]}
254 fossil sql -R regress-attach-clone.fossil \
255 "SELECT count(*) FROM attachment WHERE target='AttachPage'"
256 test_eq regress-push-held-attachment-rows [string trim $RESULT] 1
257 file delete regress-attach-clone.fossil
258
259 ###############################################################################
260 # The TH1 command styleHeader run from the command line writes the page
261 # header, whatever the robot-restrict setting.
262
@@ -278,8 +269,6 @@
278 fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl
279 test regress-baseurl-no-path-$regressName \
280 {$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]}
281 }
282
283 ###############################################################################
284
285 test_cleanup
286
--- test/regress.test
+++ test/regress.test
@@ -1,14 +1,9 @@
1 #
2 # Tests for faults that have been fixed, which have no better home.
3 #
4
 
 
 
 
 
5 require_no_open_checkout
6
7 test_setup
8
9 write_file a.txt "a\n"
@@ -93,11 +88,10 @@
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 }
94
95 set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z}
96 set regressSvnSound $regressSvnHead
97 append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]]
@@ -104,11 +98,10 @@
98 append regressSvnSound [regress_svn_rev 1 [regress_svn_props \
99 [concat {svn:log first svn:author dan} $regressSvnDate]]]
100 write_file svn-sound.dump $regressSvnSound
101 fossil import --svn svn-sound.fossil svn-sound.dump
102 test regress-svn-import-sound {$CODE == 0}
 
103
104 ###############################################################################
105 # Two more malformed property blocks for "fossil import --svn": one with a
106 # NUL byte in it, and one whose length is negative. Each is refused.
107
@@ -120,11 +113,10 @@
113 foreach regressName {nul-in-block negative-block} {
114 fossil_raw -seconds 60 import --svn svn-$regressName.fossil \
115 svn-$regressName.dump
116 test regress-svn-import-$regressName \
117 {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]}
 
118 }
119
120 ###############################################################################
121 # A Markdown header that holds an HTML comment is read within its bounds
122 # when its id is made. A fault here shows only in a build with run-time
@@ -252,11 +244,10 @@
244 test regress-push-held-attachment {$CODE == 0
245 && ![string match "*UNIQUE constraint*" $RESULT]}
246 fossil sql -R regress-attach-clone.fossil \
247 "SELECT count(*) FROM attachment WHERE target='AttachPage'"
248 test_eq regress-push-held-attachment-rows [string trim $RESULT] 1
 
249
250 ###############################################################################
251 # The TH1 command styleHeader run from the command line writes the page
252 # header, whatever the robot-restrict setting.
253
@@ -278,8 +269,6 @@
269 fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl
270 test regress-baseurl-no-path-$regressName \
271 {$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]}
272 }
273
 
 
274 test_cleanup
275
+12 -11
--- test/scenario.test
+++ test/scenario.test
@@ -26,15 +26,11 @@
2626
#
2727
# Every operation is a separate run of fossil, so this file takes about
2828
# a minute.
2929
#
3030
31
-# These tests run only in a long pass: -assurance stress.
32
-if {[test_assurance] ne "stress"} {
33
- test_skip "runs only with -assurance stress"
34
-}
35
-
31
+# One input runs at every level, and the rest need -assurance stress.
3632
require_no_open_checkout
3733
3834
test_setup ""
3935
4036
set scenarioTop [pwd]
@@ -195,11 +191,12 @@
195191
set msg [dict get $opts -errorinfo]
196192
}
197193
# The last three commands and the end of what each printed go into the
198194
# report; the directory does not last.
199195
foreach {cmd out} [lrange $scenarioLog end-5 end] {
200
- append msg \n$cmd\n[join [lrange [split [string trim $out] \n] end-5 end] \n]
196
+ append msg \n$cmd\n[join [lrange [split [string trim $out] \n] end-5 \
197
+ end] \n]
201198
}
202199
return $msg
203200
}
204201
205202
proc scenario_steps {data} {
@@ -393,13 +390,19 @@
393390
}
394391
}
395392
}
396393
397394
source [file join $::testfiledir corpus.tcl]
398
-corpus_unpack [file join $::testfiledir corpus corpus.pack] [file join [pwd] corpus]
399
-foreach scenarioF [lsort [glob -nocomplain \
400
- [file join [pwd] corpus scenario *]]] {
395
+corpus_unpack [file join $::testfiledir corpus corpus.pack] \
396
+ [file join [pwd] corpus]
397
+set scenarioFiles [lsort [glob -nocomplain \
398
+ [file join [pwd] corpus scenario *]]]
399
+if {[test_assurance] ne "stress"} {
400
+ test_skip_part "all but one scenario input need -assurance stress"
401
+ set scenarioFiles [lrange $scenarioFiles 0 0]
402
+}
403
+foreach scenarioF $scenarioFiles {
401404
set scenarioFd [open $scenarioF rb]
402405
set scenarioData [read $scenarioFd]
403406
close $scenarioFd
404407
test_eq scenario-[file tail $scenarioF] \
405408
[scenario_run [file tail $scenarioF] $scenarioData] ""
@@ -432,8 +435,6 @@
432435
} else {
433436
unset ::env($scenarioVar)
434437
}
435438
}
436439
437
-###############################################################################
438
-
439440
test_cleanup
440441
--- test/scenario.test
+++ test/scenario.test
@@ -26,15 +26,11 @@
26 #
27 # Every operation is a separate run of fossil, so this file takes about
28 # a minute.
29 #
30
31 # These tests run only in a long pass: -assurance stress.
32 if {[test_assurance] ne "stress"} {
33 test_skip "runs only with -assurance stress"
34 }
35
36 require_no_open_checkout
37
38 test_setup ""
39
40 set scenarioTop [pwd]
@@ -195,11 +191,12 @@
195 set msg [dict get $opts -errorinfo]
196 }
197 # The last three commands and the end of what each printed go into the
198 # report; the directory does not last.
199 foreach {cmd out} [lrange $scenarioLog end-5 end] {
200 append msg \n$cmd\n[join [lrange [split [string trim $out] \n] end-5 end] \n]
 
201 }
202 return $msg
203 }
204
205 proc scenario_steps {data} {
@@ -393,13 +390,19 @@
393 }
394 }
395 }
396
397 source [file join $::testfiledir corpus.tcl]
398 corpus_unpack [file join $::testfiledir corpus corpus.pack] [file join [pwd] corpus]
399 foreach scenarioF [lsort [glob -nocomplain \
400 [file join [pwd] corpus scenario *]]] {
 
 
 
 
 
 
401 set scenarioFd [open $scenarioF rb]
402 set scenarioData [read $scenarioFd]
403 close $scenarioFd
404 test_eq scenario-[file tail $scenarioF] \
405 [scenario_run [file tail $scenarioF] $scenarioData] ""
@@ -432,8 +435,6 @@
432 } else {
433 unset ::env($scenarioVar)
434 }
435 }
436
437 ###############################################################################
438
439 test_cleanup
440
--- test/scenario.test
+++ test/scenario.test
@@ -26,15 +26,11 @@
26 #
27 # Every operation is a separate run of fossil, so this file takes about
28 # a minute.
29 #
30
31 # One input runs at every level, and the rest need -assurance stress.
 
 
 
 
32 require_no_open_checkout
33
34 test_setup ""
35
36 set scenarioTop [pwd]
@@ -195,11 +191,12 @@
191 set msg [dict get $opts -errorinfo]
192 }
193 # The last three commands and the end of what each printed go into the
194 # report; the directory does not last.
195 foreach {cmd out} [lrange $scenarioLog end-5 end] {
196 append msg \n$cmd\n[join [lrange [split [string trim $out] \n] end-5 \
197 end] \n]
198 }
199 return $msg
200 }
201
202 proc scenario_steps {data} {
@@ -393,13 +390,19 @@
390 }
391 }
392 }
393
394 source [file join $::testfiledir corpus.tcl]
395 corpus_unpack [file join $::testfiledir corpus corpus.pack] \
396 [file join [pwd] corpus]
397 set scenarioFiles [lsort [glob -nocomplain \
398 [file join [pwd] corpus scenario *]]]
399 if {[test_assurance] ne "stress"} {
400 test_skip_part "all but one scenario input need -assurance stress"
401 set scenarioFiles [lrange $scenarioFiles 0 0]
402 }
403 foreach scenarioF $scenarioFiles {
404 set scenarioFd [open $scenarioF rb]
405 set scenarioData [read $scenarioFd]
406 close $scenarioFd
407 test_eq scenario-[file tail $scenarioF] \
408 [scenario_run [file tail $scenarioF] $scenarioData] ""
@@ -432,8 +435,6 @@
435 } else {
436 unset ::env($scenarioVar)
437 }
438 }
439
 
 
440 test_cleanup
441
+4 -12
--- test/ssh.test
+++ test/ssh.test
@@ -10,15 +10,10 @@
1010
# quoting for the local shell does not protect it. These tests require
1111
# that a value with a character special to a shell never reaches ssh,
1212
# and that ordinary values reach it unchanged.
1313
#
1414
15
-# These tests run only in a long pass: -assurance stress.
16
-if {[test_assurance] ne "stress"} {
17
- test_skip "runs only with -assurance stress"
18
-}
19
-
2015
require_no_open_checkout
2116
2217
if {$::tcl_platform(platform) eq "windows"} {
2318
test_skip "the stand-in for ssh is a shell script"
2419
}
@@ -35,11 +30,10 @@
3530
3631
# The stand-in must be what "ssh" means from here on. If it is not, run
3732
# nothing that could start the real one.
3833
if {[lindex [auto_execok ssh] 0] ne $sshStub} {
3934
set ::env(PATH) $sshSavedPath
40
- test_cleanup
4135
test_skip "cannot put a stand-in for ssh first on the PATH"
4236
}
4337
4438
# Run fossil with the arguments given. Sets RESULT to everything it
4539
# printed and sshArgs to the arguments the stand-in was given, one per
@@ -112,12 +106,12 @@
112106
###############################################################################
113107
# "fossil ui HOST:REPO" refuses such a repository name, and puts "--"
114108
# before the host.
115109
116110
ssh_run ui --nobrowser hh:dir/repo.fossil
117
-test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
118
- && [string first "<dir/repo.fossil>" $sshArgs] >= 0}
111
+test ssh-ui-plain \
112
+ {[holds_strings $sshArgs [list "<-->\n<hh>\n" "<dir/repo.fossil>"]]}
119113
ssh_run ui --nobrowser "hh:dir/a;b.fossil"
120114
test ssh-ui-refused-semicolon \
121115
{$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
122116
ssh_run ui --nobrowser "hh:dir/a b.fossil"
123117
test ssh-ui-refused-space \
@@ -140,13 +134,11 @@
140134
###############################################################################
141135
# An argument that begins with "~" is quoted, so that the shell does not
142136
# replace it with a home directory.
143137
144138
ssh_run test-escaped-arg ~ ~root/x
145
-test ssh-escaped-tilde {[string first {argv[2] = [~]} $RESULT] >= 0
146
- && [string first {argv[2] = [~root/x]} $RESULT] >= 0}
147
-
148
-###############################################################################
139
+test ssh-escaped-tilde \
140
+ {[holds_strings $RESULT {{argv[2] = [~]} {argv[2] = [~root/x]}}]}
149141
150142
set ::env(PATH) $sshSavedPath
151143
unset ::env(ARGS_LOG)
152144
test_cleanup
153145
--- test/ssh.test
+++ test/ssh.test
@@ -10,15 +10,10 @@
10 # quoting for the local shell does not protect it. These tests require
11 # that a value with a character special to a shell never reaches ssh,
12 # and that ordinary values reach it unchanged.
13 #
14
15 # These tests run only in a long pass: -assurance stress.
16 if {[test_assurance] ne "stress"} {
17 test_skip "runs only with -assurance stress"
18 }
19
20 require_no_open_checkout
21
22 if {$::tcl_platform(platform) eq "windows"} {
23 test_skip "the stand-in for ssh is a shell script"
24 }
@@ -35,11 +30,10 @@
35
36 # The stand-in must be what "ssh" means from here on. If it is not, run
37 # nothing that could start the real one.
38 if {[lindex [auto_execok ssh] 0] ne $sshStub} {
39 set ::env(PATH) $sshSavedPath
40 test_cleanup
41 test_skip "cannot put a stand-in for ssh first on the PATH"
42 }
43
44 # Run fossil with the arguments given. Sets RESULT to everything it
45 # printed and sshArgs to the arguments the stand-in was given, one per
@@ -112,12 +106,12 @@
112 ###############################################################################
113 # "fossil ui HOST:REPO" refuses such a repository name, and puts "--"
114 # before the host.
115
116 ssh_run ui --nobrowser hh:dir/repo.fossil
117 test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0
118 && [string first "<dir/repo.fossil>" $sshArgs] >= 0}
119 ssh_run ui --nobrowser "hh:dir/a;b.fossil"
120 test ssh-ui-refused-semicolon \
121 {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
122 ssh_run ui --nobrowser "hh:dir/a b.fossil"
123 test ssh-ui-refused-space \
@@ -140,13 +134,11 @@
140 ###############################################################################
141 # An argument that begins with "~" is quoted, so that the shell does not
142 # replace it with a home directory.
143
144 ssh_run test-escaped-arg ~ ~root/x
145 test ssh-escaped-tilde {[string first {argv[2] = [~]} $RESULT] >= 0
146 && [string first {argv[2] = [~root/x]} $RESULT] >= 0}
147
148 ###############################################################################
149
150 set ::env(PATH) $sshSavedPath
151 unset ::env(ARGS_LOG)
152 test_cleanup
153
--- test/ssh.test
+++ test/ssh.test
@@ -10,15 +10,10 @@
10 # quoting for the local shell does not protect it. These tests require
11 # that a value with a character special to a shell never reaches ssh,
12 # and that ordinary values reach it unchanged.
13 #
14
 
 
 
 
 
15 require_no_open_checkout
16
17 if {$::tcl_platform(platform) eq "windows"} {
18 test_skip "the stand-in for ssh is a shell script"
19 }
@@ -35,11 +30,10 @@
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.
33 if {[lindex [auto_execok ssh] 0] ne $sshStub} {
34 set ::env(PATH) $sshSavedPath
 
35 test_skip "cannot put a stand-in for ssh first on the PATH"
36 }
37
38 # Run fossil with the arguments given. Sets RESULT to everything it
39 # printed and sshArgs to the arguments the stand-in was given, one per
@@ -112,12 +106,12 @@
106 ###############################################################################
107 # "fossil ui HOST:REPO" refuses such a repository name, and puts "--"
108 # before the host.
109
110 ssh_run ui --nobrowser hh:dir/repo.fossil
111 test ssh-ui-plain \
112 {[holds_strings $sshArgs [list "<-->\n<hh>\n" "<dir/repo.fossil>"]]}
113 ssh_run ui --nobrowser "hh:dir/a;b.fossil"
114 test ssh-ui-refused-semicolon \
115 {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0}
116 ssh_run ui --nobrowser "hh:dir/a b.fossil"
117 test ssh-ui-refused-space \
@@ -140,13 +134,11 @@
134 ###############################################################################
135 # An argument that begins with "~" is quoted, so that the shell does not
136 # replace it with a home directory.
137
138 ssh_run test-escaped-arg ~ ~root/x
139 test ssh-escaped-tilde \
140 {[holds_strings $RESULT {{argv[2] = [~]} {argv[2] = [~root/x]}}]}
 
 
141
142 set ::env(PATH) $sshSavedPath
143 unset ::env(ARGS_LOG)
144 test_cleanup
145
+13 -14
--- test/sync.test
+++ test/sync.test
@@ -3,15 +3,12 @@
33
# "fossil server". After each operation, the repositories must hold the
44
# same artifacts, except for private ones, and pass "fossil
55
# test-integrity".
66
#
77
8
-# These tests run only in a long pass: -assurance stress.
9
-if {[test_assurance] ne "stress"} {
10
- test_skip "runs only with -assurance stress"
11
-}
12
-
8
+# The first sections run at every level, and the rest need
9
+# -assurance stress.
1310
require_no_open_checkout
1411
1512
test_setup ""
1613
set dir [pwd]
1714
set ::env(FOSSIL_USER) tester
@@ -143,12 +140,11 @@
143140
144141
set syncXferDir [pwd]
145142
set syncXferSrv [file join $syncXferDir srv.fossil]
146143
147144
proc sync_sql {repo sql} {
148
- fossil sql -R $repo $sql
149
- return [string trim $::RESULT]
145
+ return [fossil_sql $sql $repo]
150146
}
151147
152148
# How many timeline entries of REPO have the comment COMMENT.
153149
proc sync_has {repo comment} {
154150
return [sync_sql $repo "SELECT count(*) FROM event
@@ -227,10 +223,14 @@
227223
[sync_public .rep.fossil]
228224
test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0
229225
fossil cat big.txt -R c4.fossil -r $syncXferG1
230226
test_eq xfer-sync-clone-content $RESULT "${syncXferText}first"
231227
sync_integrity xfer-sync-clone-integrity c4.fossil
228
+
229
+if {[test_assurance] ne "stress"} {
230
+ test_skip "the tests after the first sections need -assurance stress"
231
+}
232232
233233
###############################################################################
234234
# Private check-ins go only when asked for, and stay private where they
235235
# arrive.
236236
@@ -295,12 +295,13 @@
295295
296296
write_file two.txt "a file added on the other side\n"
297297
fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00
298298
fossil uv sync -v $syncXferSrv
299299
test xfer-sync-uv-pull {$CODE == 0}
300
-test xfer-sync-uv-pull-said {[string first "UV-PULL: two.txt" $RESULT] >= 0
301
- && [string first "Unversioned-file received: two.txt" $RESULT] >= 0}
300
+test xfer-sync-uv-pull-said \
301
+ {[holds_strings $RESULT {"UV-PULL: two.txt"
302
+ "Unversioned-file received: two.txt"}]}
302303
fossil uv cat two.txt
303304
test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side"
304305
305306
# A trial run says what would go and sends nothing.
306307
write_file one.txt "the second version of one\n"
@@ -320,12 +321,12 @@
320321
write_file one.txt "the second version of one\n"
321322
fossil uv add one.txt --mtime 2026-01-03T00:00:00
322323
fossil uv sync -v $syncXferSrv
323324
test xfer-sync-uv-push-newer {$CODE == 0}
324325
test xfer-sync-uv-push-newer-said \
325
- {[string first "UV-PUSH: one.txt" $RESULT] >= 0
326
- && [string first "Unversioned-file sent: one.txt" $RESULT] >= 0}
326
+ {[holds_strings $RESULT {"UV-PUSH: one.txt"
327
+ "Unversioned-file sent: one.txt"}]}
327328
fossil uv cat one.txt -R srv.fossil
328329
test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one"
329330
330331
# A removal on the other side.
331332
fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00
@@ -602,11 +603,11 @@
602603
fossil sql -R d.fossil "UPDATE blob SET uuid='[string repeat 0 40]'\
603604
WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\
604605
WHERE name='f2.txt' LIMIT 1)"
605606
fossil test-integrity -R d.fossil -expectError
606607
test_match sync-bad-hash-integrity [normalize_result] {checked: 1 errors}
607
-test sync-bad-hash-integrity-status {$CODE != 0} knownBug
608
+test sync-bad-hash-integrity-status {$CODE != 0}
608609
test_stop_server $stopArg [lindex $server 0] [lindex $server 2]
609610
set server [test_start_server d.fossil stopArg]
610611
set url http://127.0.0.1:[lindex $server 1]
611612
fossil clone --proxy off $url e.fossil -expectError
612613
test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug
@@ -629,11 +630,10 @@
629630
fossil sync http://sync-test.invalid/x --once \
630631
--transport-command $syncWrapper --chdir nr -expectError
631632
test sync-no-reply-fails {$CODE != 0}
632633
test_match sync-no-reply-message [normalize_result] {empty reply}
633634
unset ::env(TRANSPORT_DIR)
634
- fossil close --chdir nr
635635
}
636636
637637
###############################################################################
638638
# An unversioned file pushed together with a commit that spans more than
639639
# one message must arrive.
@@ -653,9 +653,8 @@
653653
fossil uv add note.txt --chdir uvco
654654
fossil sync -u [file join $dir uva.fossil] --chdir uvco
655655
test sync-unversioned-with-large-commit {$CODE == 0}
656656
fossil uv list -R uva.fossil
657657
test_match sync-unversioned-arrived [normalize_result] {note\.txt}
658
-fossil close --chdir uvco
659658
660659
test_cleanup
661660
unset ::env(FOSSIL_USER)
662661
--- test/sync.test
+++ test/sync.test
@@ -3,15 +3,12 @@
3 # "fossil server". After each operation, the repositories must hold the
4 # same artifacts, except for private ones, and pass "fossil
5 # test-integrity".
6 #
7
8 # These tests run only in a long pass: -assurance stress.
9 if {[test_assurance] ne "stress"} {
10 test_skip "runs only with -assurance stress"
11 }
12
13 require_no_open_checkout
14
15 test_setup ""
16 set dir [pwd]
17 set ::env(FOSSIL_USER) tester
@@ -143,12 +140,11 @@
143
144 set syncXferDir [pwd]
145 set syncXferSrv [file join $syncXferDir srv.fossil]
146
147 proc sync_sql {repo sql} {
148 fossil sql -R $repo $sql
149 return [string trim $::RESULT]
150 }
151
152 # How many timeline entries of REPO have the comment COMMENT.
153 proc sync_has {repo comment} {
154 return [sync_sql $repo "SELECT count(*) FROM event
@@ -227,10 +223,14 @@
227 [sync_public .rep.fossil]
228 test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0
229 fossil cat big.txt -R c4.fossil -r $syncXferG1
230 test_eq xfer-sync-clone-content $RESULT "${syncXferText}first"
231 sync_integrity xfer-sync-clone-integrity c4.fossil
 
 
 
 
232
233 ###############################################################################
234 # Private check-ins go only when asked for, and stay private where they
235 # arrive.
236
@@ -295,12 +295,13 @@
295
296 write_file two.txt "a file added on the other side\n"
297 fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00
298 fossil uv sync -v $syncXferSrv
299 test xfer-sync-uv-pull {$CODE == 0}
300 test xfer-sync-uv-pull-said {[string first "UV-PULL: two.txt" $RESULT] >= 0
301 && [string first "Unversioned-file received: two.txt" $RESULT] >= 0}
 
302 fossil uv cat two.txt
303 test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side"
304
305 # A trial run says what would go and sends nothing.
306 write_file one.txt "the second version of one\n"
@@ -320,12 +321,12 @@
320 write_file one.txt "the second version of one\n"
321 fossil uv add one.txt --mtime 2026-01-03T00:00:00
322 fossil uv sync -v $syncXferSrv
323 test xfer-sync-uv-push-newer {$CODE == 0}
324 test xfer-sync-uv-push-newer-said \
325 {[string first "UV-PUSH: one.txt" $RESULT] >= 0
326 && [string first "Unversioned-file sent: one.txt" $RESULT] >= 0}
327 fossil uv cat one.txt -R srv.fossil
328 test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one"
329
330 # A removal on the other side.
331 fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00
@@ -602,11 +603,11 @@
602 fossil sql -R d.fossil "UPDATE blob SET uuid='[string repeat 0 40]'\
603 WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\
604 WHERE name='f2.txt' LIMIT 1)"
605 fossil test-integrity -R d.fossil -expectError
606 test_match sync-bad-hash-integrity [normalize_result] {checked: 1 errors}
607 test sync-bad-hash-integrity-status {$CODE != 0} knownBug
608 test_stop_server $stopArg [lindex $server 0] [lindex $server 2]
609 set server [test_start_server d.fossil stopArg]
610 set url http://127.0.0.1:[lindex $server 1]
611 fossil clone --proxy off $url e.fossil -expectError
612 test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug
@@ -629,11 +630,10 @@
629 fossil sync http://sync-test.invalid/x --once \
630 --transport-command $syncWrapper --chdir nr -expectError
631 test sync-no-reply-fails {$CODE != 0}
632 test_match sync-no-reply-message [normalize_result] {empty reply}
633 unset ::env(TRANSPORT_DIR)
634 fossil close --chdir nr
635 }
636
637 ###############################################################################
638 # An unversioned file pushed together with a commit that spans more than
639 # one message must arrive.
@@ -653,9 +653,8 @@
653 fossil uv add note.txt --chdir uvco
654 fossil sync -u [file join $dir uva.fossil] --chdir uvco
655 test sync-unversioned-with-large-commit {$CODE == 0}
656 fossil uv list -R uva.fossil
657 test_match sync-unversioned-arrived [normalize_result] {note\.txt}
658 fossil close --chdir uvco
659
660 test_cleanup
661 unset ::env(FOSSIL_USER)
662
--- test/sync.test
+++ test/sync.test
@@ -3,15 +3,12 @@
3 # "fossil server". After each operation, the repositories must hold the
4 # same artifacts, except for private ones, and pass "fossil
5 # test-integrity".
6 #
7
8 # The first sections run at every level, and the rest need
9 # -assurance stress.
 
 
 
10 require_no_open_checkout
11
12 test_setup ""
13 set dir [pwd]
14 set ::env(FOSSIL_USER) tester
@@ -143,12 +140,11 @@
140
141 set syncXferDir [pwd]
142 set syncXferSrv [file join $syncXferDir srv.fossil]
143
144 proc sync_sql {repo sql} {
145 return [fossil_sql $sql $repo]
 
146 }
147
148 # How many timeline entries of REPO have the comment COMMENT.
149 proc sync_has {repo comment} {
150 return [sync_sql $repo "SELECT count(*) FROM event
@@ -227,10 +223,14 @@
223 [sync_public .rep.fossil]
224 test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0
225 fossil cat big.txt -R c4.fossil -r $syncXferG1
226 test_eq xfer-sync-clone-content $RESULT "${syncXferText}first"
227 sync_integrity xfer-sync-clone-integrity c4.fossil
228
229 if {[test_assurance] ne "stress"} {
230 test_skip "the tests after the first sections need -assurance stress"
231 }
232
233 ###############################################################################
234 # Private check-ins go only when asked for, and stay private where they
235 # arrive.
236
@@ -295,12 +295,13 @@
295
296 write_file two.txt "a file added on the other side\n"
297 fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00
298 fossil uv sync -v $syncXferSrv
299 test xfer-sync-uv-pull {$CODE == 0}
300 test xfer-sync-uv-pull-said \
301 {[holds_strings $RESULT {"UV-PULL: two.txt"
302 "Unversioned-file received: two.txt"}]}
303 fossil uv cat two.txt
304 test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side"
305
306 # A trial run says what would go and sends nothing.
307 write_file one.txt "the second version of one\n"
@@ -320,12 +321,12 @@
321 write_file one.txt "the second version of one\n"
322 fossil uv add one.txt --mtime 2026-01-03T00:00:00
323 fossil uv sync -v $syncXferSrv
324 test xfer-sync-uv-push-newer {$CODE == 0}
325 test xfer-sync-uv-push-newer-said \
326 {[holds_strings $RESULT {"UV-PUSH: one.txt"
327 "Unversioned-file sent: one.txt"}]}
328 fossil uv cat one.txt -R srv.fossil
329 test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one"
330
331 # A removal on the other side.
332 fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00
@@ -602,11 +603,11 @@
603 fossil sql -R d.fossil "UPDATE blob SET uuid='[string repeat 0 40]'\
604 WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\
605 WHERE name='f2.txt' LIMIT 1)"
606 fossil test-integrity -R d.fossil -expectError
607 test_match sync-bad-hash-integrity [normalize_result] {checked: 1 errors}
608 test sync-bad-hash-integrity-status {$CODE != 0}
609 test_stop_server $stopArg [lindex $server 0] [lindex $server 2]
610 set server [test_start_server d.fossil stopArg]
611 set url http://127.0.0.1:[lindex $server 1]
612 fossil clone --proxy off $url e.fossil -expectError
613 test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug
@@ -629,11 +630,10 @@
630 fossil sync http://sync-test.invalid/x --once \
631 --transport-command $syncWrapper --chdir nr -expectError
632 test sync-no-reply-fails {$CODE != 0}
633 test_match sync-no-reply-message [normalize_result] {empty reply}
634 unset ::env(TRANSPORT_DIR)
 
635 }
636
637 ###############################################################################
638 # An unversioned file pushed together with a commit that spans more than
639 # one message must arrive.
@@ -653,9 +653,8 @@
653 fossil uv add note.txt --chdir uvco
654 fossil sync -u [file join $dir uva.fossil] --chdir uvco
655 test sync-unversioned-with-large-commit {$CODE == 0}
656 fossil uv list -R uva.fossil
657 test_match sync-unversioned-arrived [normalize_result] {note\.txt}
 
658
659 test_cleanup
660 unset ::env(FOSSIL_USER)
661
--- test/tester.tcl
+++ test/tester.tcl
@@ -345,10 +345,71 @@
345345
return 0
346346
}
347347
}
348348
return 1
349349
}
350
+
351
+# The text of an HTTP request for PATH, with "Host: x" and each line of
352
+# the list HEADERS.
353
+#
354
+proc request_get {path {headers {}} {method GET}} {
355
+ set text "$method $path HTTP/1.1\r\nHost: x\r\n"
356
+ foreach line $headers { append text $line "\r\n" }
357
+ return "$text\r\n"
358
+}
359
+
360
+# The text of an HTTP POST of BODY to PATH, with "Host: x", each line of
361
+# the list HEADERS, the content type TYPE and the length of BODY.
362
+#
363
+proc request_post {path body {headers {}}
364
+ {type application/x-www-form-urlencoded}} {
365
+ set text "POST $path HTTP/1.1\r\nHost: x\r\n"
366
+ foreach line $headers { append text $line "\r\n" }
367
+ append text "Content-Type: $type\r\n"
368
+ append text "Content-Length: [string length $body]\r\n\r\n$body"
369
+ return $text
370
+}
371
+
372
+# Give the request TEXT, a string of bytes, to "fossil http" for the
373
+# repository REPO, with ARGS as more options, and return the reply, or
374
+# an empty string if there is none. The request is written to
375
+# request.txt and the reply to reply.txt. CODE is the exit status.
376
+#
377
+proc fossil_http {repo text args} {
378
+ write_file request.txt $text
379
+ file delete reply.txt
380
+ fossil_raw http $repo --in request.txt --out reply.txt {*}$args
381
+ if {[file exists reply.txt]} { return [read_file reply.txt] }
382
+ return ""
383
+}
384
+
385
+# The status line of the HTTP reply REPLY.
386
+#
387
+proc reply_status {reply} {
388
+ return [string trim [lindex [split $reply \n] 0]]
389
+}
390
+
391
+# The value of the first header NAME in the HTTP reply REPLY, or "-" if
392
+# the reply has no such header.
393
+#
394
+proc reply_header {reply name} {
395
+ set end [string first "\r\n\r\n" $reply]
396
+ foreach line [split [string range $reply 0 $end] \n] {
397
+ if {[string match -nocase "$name: *" $line]} {
398
+ return [string trim [string range $line [string length $name]+1 end]]
399
+ }
400
+ }
401
+ return -
402
+}
403
+
404
+# The content of the HTTP reply REPLY: what follows its headers.
405
+#
406
+proc reply_body {reply} {
407
+ set end [string first "\r\n\r\n" $reply]
408
+ if {$end < 0} { return "" }
409
+ return [string range $reply $end+4 end]
410
+}
350411
351412
# Listens on a port on 127.0.0.1 that the system chooses, and returns
352413
# the port. Calls HANDLER with each connection and the request on it,
353414
# once the whole request has arrived or the client has closed its side,
354415
# and then closes the connection. The request is whole when it has its
@@ -526,10 +587,89 @@
526587
fossil timeline -t ci -n 0 -F {%H %c}
527588
regexp -line "^(\[0-9a-f\]+) [string map {. \\.} $comment]\$" \
528589
$::RESULT -> hash
529590
return $hash
530591
}
592
+
593
+# Runs SQL in the repository REPO, or in the repository of the open
594
+# checkout when REPO is empty, and returns the output, trimmed.
595
+#
596
+proc fossil_sql {sql {repo ""}} {
597
+ if {$repo eq ""} {
598
+ fossil sql $sql
599
+ } else {
600
+ fossil sql -R $repo $sql
601
+ }
602
+ return [string trim $::RESULT]
603
+}
604
+
605
+# Returns what the repository REPO holds, by hash and not by record
606
+# number, so that two states can be compared after content has been
607
+# stored again: the artifacts with their private flag, the timeline, the
608
+# parent links, the files of each check-in, the leaves and the tags.
609
+#
610
+proc repository_state {{repo .rep.fossil}} {
611
+ return [fossil_sql {
612
+ SELECT 'blob', uuid, rid IN private FROM blob WHERE size>=0
613
+ UNION ALL
614
+ SELECT 'event', b.uuid, e.type || ' ' || ifnull(e.comment,'')
615
+ FROM event e JOIN blob b ON b.rid=e.objid
616
+ UNION ALL
617
+ SELECT 'plink', p.uuid, c.uuid FROM plink
618
+ JOIN blob p ON p.rid=plink.pid JOIN blob c ON c.rid=plink.cid
619
+ UNION ALL
620
+ SELECT 'mlink', m.uuid, f.uuid || ' ' || fn.name FROM mlink
621
+ JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
622
+ JOIN filename fn ON fn.fnid=mlink.fnid
623
+ UNION ALL
624
+ SELECT 'leaf', uuid, '' FROM leaf JOIN blob USING(rid)
625
+ UNION ALL
626
+ SELECT 'tag', b.uuid, t.tagname || '=' || ifnull(x.value,'')
627
+ FROM tagxref x JOIN tag t USING(tagid) JOIN blob b ON b.rid=x.rid
628
+ WHERE x.tagtype>0
629
+ ORDER BY 1, 2, 3
630
+ } $repo]
631
+}
632
+
633
+# Returns the rows that are in one repository state and not in the
634
+# other, marked "-" for the first and "+" for the second. Empty when the
635
+# two are the same.
636
+#
637
+proc repository_state_diff {a b} {
638
+ set la [split $a \n]
639
+ set lb [split $b \n]
640
+ set out {}
641
+ foreach x $la { if {[lsearch -exact $lb $x] < 0} { lappend out "- $x" } }
642
+ foreach x $lb { if {[lsearch -exact $la $x] < 0} { lappend out "+ $x" } }
643
+ return [join $out \n]
644
+}
645
+
646
+# Tests NAME-integrity and NAME-missing: that test-integrity and
647
+# test-missing find nothing wrong with the repository REPO.
648
+#
649
+proc repository_sound {name {repo .rep.fossil}} {
650
+ fossil test-integrity -R $repo
651
+ test $name-integrity {$::CODE == 0}
652
+ fossil test-missing -R $repo
653
+ test $name-missing {$::CODE == 0}
654
+}
655
+
656
+# Returns the hash of the version of FILE in the check-in with the hash
657
+# CHECKIN, in the repository REPO.
658
+#
659
+proc checkin_file_hash {checkin file {repo .rep.fossil}} {
660
+ return [fossil_sql "SELECT f.uuid FROM mlink
661
+ JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
662
+ JOIN filename fn ON fn.fnid=mlink.fnid
663
+ WHERE m.uuid='$checkin' AND fn.name='$file'" $repo]
664
+}
665
+
666
+# Returns how many users of the repository REPO have a password.
667
+#
668
+proc password_count {repo} {
669
+ return [fossil_sql "SELECT count(*) FROM user WHERE pw<>''" $repo]
670
+}
531671
532672
# Returns the path of the repository of the open checkout, from
533673
# "fossil info", or an empty string when there is none.
534674
#
535675
proc repository_path {} {
@@ -559,10 +699,27 @@
559699
write_file $filename $txt
560700
set hash [sha1_file $filename]
561701
file delete $filename
562702
return $hash
563703
}
704
+
705
+# Returns the SHA3 hash of the file FILENAME, from "fossil sha3sum".
706
+#
707
+proc sha3_file {filename} {
708
+ fossil sha3sum $filename
709
+ return [lindex $::RESULT 0]
710
+}
711
+
712
+# Returns the SHA3 hash of the string TXT.
713
+#
714
+proc sha3_text {txt} {
715
+ set filename [file join $::tempPath sha3_text_[pid]]
716
+ write_file $filename $txt
717
+ set hash [sha3_file $filename]
718
+ file delete $filename
719
+ return $hash
720
+}
564721
565722
# Return true if two files are the same
566723
#
567724
proc same_file {a b} {
568725
set x [read_file $a]
569726
--- test/tester.tcl
+++ test/tester.tcl
@@ -345,10 +345,71 @@
345 return 0
346 }
347 }
348 return 1
349 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
351 # Listens on a port on 127.0.0.1 that the system chooses, and returns
352 # the port. Calls HANDLER with each connection and the request on it,
353 # once the whole request has arrived or the client has closed its side,
354 # and then closes the connection. The request is whole when it has its
@@ -526,10 +587,89 @@
526 fossil timeline -t ci -n 0 -F {%H %c}
527 regexp -line "^(\[0-9a-f\]+) [string map {. \\.} $comment]\$" \
528 $::RESULT -> hash
529 return $hash
530 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
532 # Returns the path of the repository of the open checkout, from
533 # "fossil info", or an empty string when there is none.
534 #
535 proc repository_path {} {
@@ -559,10 +699,27 @@
559 write_file $filename $txt
560 set hash [sha1_file $filename]
561 file delete $filename
562 return $hash
563 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
564
565 # Return true if two files are the same
566 #
567 proc same_file {a b} {
568 set x [read_file $a]
569
--- test/tester.tcl
+++ test/tester.tcl
@@ -345,10 +345,71 @@
345 return 0
346 }
347 }
348 return 1
349 }
350
351 # The text of an HTTP request for PATH, with "Host: x" and each line of
352 # the list HEADERS.
353 #
354 proc request_get {path {headers {}} {method GET}} {
355 set text "$method $path HTTP/1.1\r\nHost: x\r\n"
356 foreach line $headers { append text $line "\r\n" }
357 return "$text\r\n"
358 }
359
360 # The text of an HTTP POST of BODY to PATH, with "Host: x", each line of
361 # the list HEADERS, the content type TYPE and the length of BODY.
362 #
363 proc request_post {path body {headers {}}
364 {type application/x-www-form-urlencoded}} {
365 set text "POST $path HTTP/1.1\r\nHost: x\r\n"
366 foreach line $headers { append text $line "\r\n" }
367 append text "Content-Type: $type\r\n"
368 append text "Content-Length: [string length $body]\r\n\r\n$body"
369 return $text
370 }
371
372 # Give the request TEXT, a string of bytes, to "fossil http" for the
373 # repository REPO, with ARGS as more options, and return the reply, or
374 # an empty string if there is none. The request is written to
375 # request.txt and the reply to reply.txt. CODE is the exit status.
376 #
377 proc fossil_http {repo text args} {
378 write_file request.txt $text
379 file delete reply.txt
380 fossil_raw http $repo --in request.txt --out reply.txt {*}$args
381 if {[file exists reply.txt]} { return [read_file reply.txt] }
382 return ""
383 }
384
385 # The status line of the HTTP reply REPLY.
386 #
387 proc reply_status {reply} {
388 return [string trim [lindex [split $reply \n] 0]]
389 }
390
391 # The value of the first header NAME in the HTTP reply REPLY, or "-" if
392 # the reply has no such header.
393 #
394 proc reply_header {reply name} {
395 set end [string first "\r\n\r\n" $reply]
396 foreach line [split [string range $reply 0 $end] \n] {
397 if {[string match -nocase "$name: *" $line]} {
398 return [string trim [string range $line [string length $name]+1 end]]
399 }
400 }
401 return -
402 }
403
404 # The content of the HTTP reply REPLY: what follows its headers.
405 #
406 proc reply_body {reply} {
407 set end [string first "\r\n\r\n" $reply]
408 if {$end < 0} { return "" }
409 return [string range $reply $end+4 end]
410 }
411
412 # Listens on a port on 127.0.0.1 that the system chooses, and returns
413 # the port. Calls HANDLER with each connection and the request on it,
414 # once the whole request has arrived or the client has closed its side,
415 # and then closes the connection. The request is whole when it has its
@@ -526,10 +587,89 @@
587 fossil timeline -t ci -n 0 -F {%H %c}
588 regexp -line "^(\[0-9a-f\]+) [string map {. \\.} $comment]\$" \
589 $::RESULT -> hash
590 return $hash
591 }
592
593 # Runs SQL in the repository REPO, or in the repository of the open
594 # checkout when REPO is empty, and returns the output, trimmed.
595 #
596 proc fossil_sql {sql {repo ""}} {
597 if {$repo eq ""} {
598 fossil sql $sql
599 } else {
600 fossil sql -R $repo $sql
601 }
602 return [string trim $::RESULT]
603 }
604
605 # Returns what the repository REPO holds, by hash and not by record
606 # number, so that two states can be compared after content has been
607 # stored again: the artifacts with their private flag, the timeline, the
608 # parent links, the files of each check-in, the leaves and the tags.
609 #
610 proc repository_state {{repo .rep.fossil}} {
611 return [fossil_sql {
612 SELECT 'blob', uuid, rid IN private FROM blob WHERE size>=0
613 UNION ALL
614 SELECT 'event', b.uuid, e.type || ' ' || ifnull(e.comment,'')
615 FROM event e JOIN blob b ON b.rid=e.objid
616 UNION ALL
617 SELECT 'plink', p.uuid, c.uuid FROM plink
618 JOIN blob p ON p.rid=plink.pid JOIN blob c ON c.rid=plink.cid
619 UNION ALL
620 SELECT 'mlink', m.uuid, f.uuid || ' ' || fn.name FROM mlink
621 JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
622 JOIN filename fn ON fn.fnid=mlink.fnid
623 UNION ALL
624 SELECT 'leaf', uuid, '' FROM leaf JOIN blob USING(rid)
625 UNION ALL
626 SELECT 'tag', b.uuid, t.tagname || '=' || ifnull(x.value,'')
627 FROM tagxref x JOIN tag t USING(tagid) JOIN blob b ON b.rid=x.rid
628 WHERE x.tagtype>0
629 ORDER BY 1, 2, 3
630 } $repo]
631 }
632
633 # Returns the rows that are in one repository state and not in the
634 # other, marked "-" for the first and "+" for the second. Empty when the
635 # two are the same.
636 #
637 proc repository_state_diff {a b} {
638 set la [split $a \n]
639 set lb [split $b \n]
640 set out {}
641 foreach x $la { if {[lsearch -exact $lb $x] < 0} { lappend out "- $x" } }
642 foreach x $lb { if {[lsearch -exact $la $x] < 0} { lappend out "+ $x" } }
643 return [join $out \n]
644 }
645
646 # Tests NAME-integrity and NAME-missing: that test-integrity and
647 # test-missing find nothing wrong with the repository REPO.
648 #
649 proc repository_sound {name {repo .rep.fossil}} {
650 fossil test-integrity -R $repo
651 test $name-integrity {$::CODE == 0}
652 fossil test-missing -R $repo
653 test $name-missing {$::CODE == 0}
654 }
655
656 # Returns the hash of the version of FILE in the check-in with the hash
657 # CHECKIN, in the repository REPO.
658 #
659 proc checkin_file_hash {checkin file {repo .rep.fossil}} {
660 return [fossil_sql "SELECT f.uuid FROM mlink
661 JOIN blob m ON m.rid=mlink.mid JOIN blob f ON f.rid=mlink.fid
662 JOIN filename fn ON fn.fnid=mlink.fnid
663 WHERE m.uuid='$checkin' AND fn.name='$file'" $repo]
664 }
665
666 # Returns how many users of the repository REPO have a password.
667 #
668 proc password_count {repo} {
669 return [fossil_sql "SELECT count(*) FROM user WHERE pw<>''" $repo]
670 }
671
672 # Returns the path of the repository of the open checkout, from
673 # "fossil info", or an empty string when there is none.
674 #
675 proc repository_path {} {
@@ -559,10 +699,27 @@
699 write_file $filename $txt
700 set hash [sha1_file $filename]
701 file delete $filename
702 return $hash
703 }
704
705 # Returns the SHA3 hash of the file FILENAME, from "fossil sha3sum".
706 #
707 proc sha3_file {filename} {
708 fossil sha3sum $filename
709 return [lindex $::RESULT 0]
710 }
711
712 # Returns the SHA3 hash of the string TXT.
713 #
714 proc sha3_text {txt} {
715 set filename [file join $::tempPath sha3_text_[pid]]
716 write_file $filename $txt
717 set hash [sha3_file $filename]
718 file delete $filename
719 return $hash
720 }
721
722 # Return true if two files are the same
723 #
724 proc same_file {a b} {
725 set x [read_file $a]
726
+65 -37
--- test/th1main.test
+++ test/th1main.test
@@ -3,15 +3,12 @@
33
# Scripts are run with "fossil test-th-eval", templates with
44
# "fossil test-th-render" and "fossil test-th-source", and a ticket page
55
# that holds TH1 is asked for through "fossil http --in".
66
#
77
8
-# These tests run only in a long pass: -assurance stress.
9
-if {[test_assurance] ne "stress"} {
10
- test_skip "runs only with -assurance stress"
11
-}
12
-
8
+# The first sections run at every level, and the rest need
9
+# -assurance stress.
1310
test_setup
1411
1512
write_file a.txt "hello\n"
1613
write_file f83.txt "line 83\n"
1714
write_file f100.txt "line 100\n"
@@ -97,12 +94,14 @@
9794
tclready-many {tclReady a} {tclReady}
9895
anycap-few {anycap} {anycap STRING}
9996
anycap-many {anycap a b} {anycap STRING}
10097
combobox-few {combobox a b} {combobox NAME TEXT-LIST NUMLINES}
10198
combobox-many {combobox a b 1 d} {combobox NAME TEXT-LIST NUMLINES}
102
- copybtn-few {copybtn a 0} {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
103
- copybtn-many {copybtn a 0 c 1 e} {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
99
+ copybtn-few {copybtn a 0}
100
+ {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
101
+ copybtn-many {copybtn a 0 c 1 e}
102
+ {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
104103
linecount-few {linecount a 1} {linecount STRING MAX MIN}
105104
linecount-many {linecount a 1 2 3} {linecount STRING MAX MIN}
106105
repository-many {repository 1 2} {repository ?BOOLEAN?}
107106
checkout-many {checkout 1 2} {checkout ?BOOLEAN?}
108107
trace-few {trace} {trace STRING}
@@ -144,27 +143,38 @@
144143
query-option-many {query -nocomplain a b c} {query SQL CODE}
145144
setting-few {setting} {setting ?-strict? ?--? name}
146145
setting-many {setting a b c d} {setting ?-strict? ?--? name}
147146
setting-two {setting -- a b} {setting ?-strict? ?--? name}
148147
setting-strict-two {setting -strict -- a b} {setting ?-strict? ?--? name}
149
- glob-few {glob_match a} {glob_match ?-one? ?--? patternList string}
150
- glob-many {glob_match -one -- a b c} {glob_match ?-one? ?--? patternList string}
151
- glob-three {glob_match a b c} {glob_match ?-one? ?--? patternList string}
148
+ glob-few {glob_match a}
149
+ {glob_match ?-one? ?--? patternList string}
150
+ glob-many {glob_match -one -- a b c}
151
+ {glob_match ?-one? ?--? patternList string}
152
+ glob-three {glob_match a b c}
153
+ {glob_match ?-one? ?--? patternList string}
152154
regexp-few {regexp a} {regexp ?-nocase? ?--? exp string}
153155
regexp-many {regexp -nocase -- a b c} {regexp ?-nocase? ?--? exp string}
154156
regexp-three {regexp -- a b c} {regexp ?-nocase? ?--? exp string}
155157
regexp-one {regexp -nocase -- a} {regexp ?-nocase? ?--? exp string}
156
- http-few {http} {http ?-asynchronous? ?--? url ?payload?}
157
- http-many {http -asynchronous -- a b c} {http ?-asynchronous? ?--? url ?payload?}
158
- http-none {http --} {http ?-asynchronous? ?--? url ?payload?}
159
- http-three {http -- a b c} {http ?-asynchronous? ?--? url ?payload?}
158
+ http-few {http}
159
+ {http ?-asynchronous? ?--? url ?payload?}
160
+ http-many {http -asynchronous -- a b c}
161
+ {http ?-asynchronous? ?--? url ?payload?}
162
+ http-none {http --}
163
+ {http ?-asynchronous? ?--? url ?payload?}
164
+ http-three {http -- a b c}
165
+ {http ?-asynchronous? ?--? url ?payload?}
160166
capture-few {captureTh1} {captureTh1 STRING}
161167
capture-many {captureTh1 a b} {captureTh1 STRING}
162168
} {
163169
test_eq th1main-args-$th1mainName [th1main_eval $th1mainCall] \
164170
"TH_ERROR: wrong # args: should be \"$th1mainUsage\""
165171
}
172
+
173
+if {[test_assurance] ne "stress"} {
174
+ test_skip "the tests after the first sections need -assurance stress"
175
+}
166176
167177
###############################################################################
168178
# What the commands return and write. A script that writes ends with
169179
# "set x {}" so that only what it wrote is printed.
170180
@@ -486,12 +496,14 @@
486496
487497
# With timeline-utc off, "date -local" gives the time of the zone in TZ.
488498
fossil settings timeline-utc 0
489499
set th1mainSavedTz [expr {[info exists env(TZ)] ? $env(TZ) : ""}]
490500
set env(TZ) XXX-5
491
-set th1mainDates [split [th1main_eval {puts "[date]|[date -local]"; set x {}}] |]
492
-if {$th1mainSavedTz eq ""} { unset env(TZ) } else { set env(TZ) $th1mainSavedTz }
501
+set th1mainDates [split [th1main_eval {puts "[date]|[date -local]"; set x {}}] \
502
+ |]
503
+if {$th1mainSavedTz eq ""} { unset env(TZ) } else \
504
+ { set env(TZ) $th1mainSavedTz }
493505
fossil settings timeline-utc 1
494506
set th1mainDiff [expr {[clock scan [lindex $th1mainDates 1] -gmt 1]
495507
- [clock scan [lindex $th1mainDates 0] -gmt 1]}]
496508
test th1main-date-local {$th1mainDiff >= 17999 && $th1mainDiff <= 18001}
497509
@@ -551,11 +563,12 @@
551563
552564
# "setting -strict" and "http -asynchronous" with nothing after the
553565
# option, and "http" with an empty first argument, give a script error.
554566
foreach {th1mainName th1mainCall th1mainUsage} {
555567
setting-strict-alone {setting -strict} {setting ?-strict? ?--? name}
556
- http-option-alone {http -asynchronous} {http ?-asynchronous? ?--? url ?payload?}
568
+ http-option-alone {http -asynchronous}
569
+ {http ?-asynchronous? ?--? url ?payload?}
557570
http-empty {http {}} {http ?-asynchronous? ?--? url ?payload?}
558571
} {
559572
set th1mainGot [th1main_eval $th1mainCall]
560573
test th1main-args-$th1mainName {$CODE == 0 && [string match \
561574
"TH_ERROR: *" $th1mainGot]}
@@ -570,13 +583,16 @@
570583
foreach {th1mainName th1mainSql} {
571584
two {SELECT 1 AS a; SELECT 2 AS a}
572585
space {SELECT 1 AS a; }
573586
} {
574587
fossil_raw -seconds 10 test-th-eval \
575
- "set n 0; query {$th1mainSql} {set n \[expr {\$n+1}\]; if {\$n>50} {error endless}}; set n"
588
+ [join [list \
589
+ "set n 0; query {$th1mainSql} {set n \[expr {\$n+1}\]; if " \
590
+ "{\$n>50} {error endless}}; set n"] ""]
576591
test th1main-query-statements-$th1mainName \
577
- {$CODE == 0 && [string trim $RESULT] eq [dict get {two 2 space 1} $th1mainName]}
592
+ {$CODE == 0 && [string trim $RESULT] eq [dict get {two 2 space 1} \
593
+ $th1mainName]}
578594
}
579595
580596
# builtin_request_js with a name that is not a built-in file gives a
581597
# script error.
582598
set th1mainGot [th1main_eval {builtin_request_js nosuch.js}]
@@ -591,11 +607,12 @@
591607
set th1mainGot [th1main_eval {http not-a-url}]
592608
test th1main-http-not-url \
593609
{$CODE == 0 && [string match "TH_ERROR: *" $th1mainGot]}
594610
595611
# A phantom: an artifact whose content the repository does not hold.
596
-set th1mainPhantom abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789
612
+set th1mainPhantom \
613
+ abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789
597614
fossil sql "INSERT INTO blob(rcvid,size,uuid) VALUES(0,-1,'$th1mainPhantom');
598615
INSERT INTO phantom SELECT rid FROM blob WHERE size=-1;"
599616
test_match th1main-artifact-phantom \
600617
[th1main_eval "artifact $th1mainPhantom"] {^TH_ERROR: }
601618
@@ -659,11 +676,13 @@
659676
test th1main-http-get-request {[holds_strings $th1mainHeard [list \
660677
"GET /dir/page?a=b HTTP/1.0\r\n" "Host: $th1mainUrl\r\n" \
661678
"User-Agent: " "!Content-Length" "!Authorization"]]}
662679
663680
set th1mainGot [th1main_http \
664
- "http -asynchronous -- http://$th1mainUrl/post {some payload}; set x sent"]
681
+ [join [list \
682
+ "http -asynchronous -- http://$th1mainUrl/post {some " \
683
+ "payload}; set x sent"] ""]]
665684
test_eq th1main-http-post $th1mainGot sent
666685
test th1main-http-post-request {[holds_strings $th1mainHeard [list \
667686
"POST /post HTTP/1.0\r\n" "Content-Length: 12\r\n\r\nsome payload" \
668687
"Content-Type: application/x-www-form-urlencoded\r\n"]]}
669688
@@ -687,11 +706,10 @@
687706
close $th1mainServer
688707
# Nothing listens on the port any more.
689708
set th1mainGot [th1main_eval "http -asynchronous http://$th1mainUrl/x"]
690709
test_match th1main-http-refused $th1mainGot {^TH_ERROR: .}
691710
}
692
-fossil unset th1-uri-regexp
693711
694712
###############################################################################
695713
# Tracing: --th-trace prints a log of what the commands did.
696714
697715
foreach {th1mainName th1mainOpts th1mainScript th1mainWanted} {
@@ -742,33 +760,40 @@
742760
empty {} {} \
743761
script {a<th1>puts b</th1>c} abc \
744762
script-upper {<TH1>puts 1</TH1><Th1>puts 2</tH1><tH1>puts 3</Th1>} 123 \
745763
script-unclosed {a<th1>puts b} ab \
746764
script-empty-unclosed {a<th1>} a \
747
- script-half-closed {a<th1></th1} "a${th1mainErr}no such command: &lt;/th1</p>" \
765
+ script-half-closed {a<th1></th1} \
766
+ "a${th1mainErr}no such command: &lt;/th1</p>" \
748767
not-tags {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \
749768
{<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \
750769
end-tag-alone {a</th1>b} {a</th1>b} \
751770
end-tag-look-alikes {<th1>set y {<x </x </tx </thx </th1x}; puts $y</th1>} \
752771
{&lt;x &lt;/x &lt;/tx &lt;/thx &lt;/th1x} \
753772
dollar-end {a$} {a$} \
754773
dollar-bracket-end {a$<} {a$<} \
755774
dollar-bracket-unclosed {a$<v b} {a$<v b} \
756775
dollar-digit {a$1 $_ $: $:: $::1 $<1> ${v}} {a$1 $_ $: $:: $::1 $<1> ${v}} \
757
- variables {<th1>set v {<b>&}; set ::g G; set v_2 two</th1>[$v][$<v>][$::g][$<::g>][$v_2]} \
776
+ variables \
777
+ {<th1>set v {<b>&}; set ::g G; set v_2 two</th1>[$v][$<v>][$::g][$<::g>][$v_2]} \
758778
{[<b>&][&lt;b&gt;&amp;][G][G][two]} \
759779
variable-then-text {<th1>set v 1</th1>$v.$v-$<v>x} {1.1-1x} \
760
- variable-unknown {a$nosuch b} "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
761
- variable-unknown-escaped {a$<nosuch>b} "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
762
- variable-unknown-then-known {<th1>set v 1</th1>a$nosuch b$v c} "a${th1mainNoVar}nosuch b1 c" \
763
- variable-tainted {<th1>set t [taint <i>]</th1>[$t][$<t>]end} {[][&lt;i&gt;]end} \
764
- error {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \
780
+ variable-unknown {a$nosuch b} \
781
+ "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
782
+ variable-unknown-escaped {a$<nosuch>b} \
783
+ "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
784
+ variable-unknown-then-known {<th1>set v 1</th1>a$nosuch b$v c} \
785
+ "a${th1mainNoVar}nosuch b1 c" \
786
+ variable-tainted {<th1>set t [taint <i>]</th1>[$t][$<t>]end} \
787
+ {[][&lt;i&gt;]end} \
788
+ error-plain {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \
765789
error-escaped {<th1>error <b></th1>} "${th1mainErr}&lt;b&gt;</p>" \
766790
nested {<th1>set v 2; render {b$<v>|}; render {c$v}</th1>d} {b2|c2d} \
767791
nested-error {<th1>render {b$<v>|}; puts never</th1>d} \
768792
"b${th1mainNoVar}v${th1mainErr}no such variable: v</p>${th1mainErr}</p>" \
769
- output-off {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \
793
+ output-off \
794
+ {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \
770795
] {
771796
test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \
772797
$th1mainExpected
773798
test th1main-render-$th1mainName-exit {$CODE == 0}
774799
}
@@ -800,11 +825,12 @@
800825
test_eq th1main-render-anon-caps \
801826
[th1main_render {<th1>puts [anoncap s]</th1>} --set-anon-caps] 1
802827
set env(TH1_TEST_USER_CAPS) o
803828
set env(TH1_TEST_ANON_CAPS) h
804829
test_eq th1main-render-caps-from-environment \
805
- [th1main_render {<th1>puts [hascap o][hascap s][anoncap h][anoncap s]</th1>} \
830
+ [th1main_render \
831
+ {<th1>puts [hascap o][hascap s][anoncap h][anoncap s]</th1>} \
806832
--set-user-caps --set-anon-caps] 1010
807833
test_eq th1main-eval-caps-from-environment \
808834
[th1main_eval {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
809835
--set-user-caps --set-anon-caps] 1010
810836
unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS)
@@ -831,11 +857,12 @@
831857
[th1main_source {puts a; set x b} --no-print-result] a
832858
test_eq th1main-source-no-database \
833859
[th1main_source {query {SELECT 1 AS a} {puts $a}}] \
834860
{TH_ERROR: database is not open }
835861
test_eq th1main-source-no-database-quiet \
836
- [th1main_source {query -nocomplain {SELECT 1 AS a} {puts $a}; set x quiet}] \
862
+ [th1main_source \
863
+ {query -nocomplain {SELECT 1 AS a} {puts $a}; set x quiet}] \
837864
quiet
838865
test_eq th1main-source-no-repository [th1main_source {repository}] {}
839866
test_match th1main-source-repository [th1main_source {repository 1}] \
840867
{/\.rep\.fossil$}
841868
test_match th1main-source-checkout [th1main_source {checkout 1}] \
@@ -848,11 +875,12 @@
848875
test_eq th1main-source-anon-caps \
849876
[th1main_source {anoncap s} --set-anon-caps] 1
850877
set env(TH1_TEST_USER_CAPS) o
851878
set env(TH1_TEST_ANON_CAPS) h
852879
test_eq th1main-source-caps-from-environment \
853
- [th1main_source {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
880
+ [th1main_source \
881
+ {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
854882
--set-user-caps --set-anon-caps] 1010
855883
unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS)
856884
set th1mainGot [th1main_source {puts hello; set x {}} --cgi]
857885
test th1main-source-cgi {[holds_strings $th1mainGot [list \
858886
"Status: 200 OK\r\n" "\r\n\r\nhello"]]}
@@ -907,12 +935,11 @@
907935
return ""
908936
}
909937
910938
# The same for a GET of /tktnew with the query string QUERY.
911939
proc th1main_page {script {query ""} args} {
912
- return [th1main_request $script \
913
- "GET /tktnew$query HTTP/1.1\r\nHost: x\r\n\r\n" {*}$args]
940
+ return [th1main_request $script [request_get /tktnew$query] {*}$args]
914941
}
915942
916943
fossil fts-config enable cdtw
917944
set th1mainGot [th1main_page {<th1>
918945
puts "top=[globalState top none] user=[globalState user none]|"
@@ -1087,11 +1114,13 @@
10871114
# page goes on; a tainted query and a tainted redirect are refused.
10881115
fossil unset vuln-report
10891116
set th1mainGot [th1main_page {B=$title|C=$<title>|END} $th1mainTaintQuery]
10901117
test th1main-taint-block-inline {[holds_strings $th1mainGot \
10911118
{{B=|C=&lt;u&gt;|END}}]}
1092
-set th1mainGot [th1main_page {<th1>query "SELECT 1 AS n /* [getParameter p] */" {puts n=$n}</th1>END} $th1mainTaintQuery]
1119
+set th1mainGot [th1main_page \
1120
+ {<th1>query "SELECT 1 AS n /* [getParameter p] */" {puts n=$n}</th1>END} \
1121
+ $th1mainTaintQuery]
10931122
test th1main-taint-block-query {[holds_strings $th1mainGot \
10941123
{{ERROR: tainted query SQL: &quot;SELECT 1 AS n /* &lt;i&gt; */&quot;} !n=1}]}
10951124
set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \
10961125
"?u=/elsewhere"]
10971126
test th1main-taint-block-redirect {[holds_strings $th1mainGot \
@@ -1100,11 +1129,10 @@
11001129
fossil settings vuln-report off
11011130
set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \
11021131
"?u=/elsewhere"]
11031132
test th1main-taint-off-redirect {[holds_strings $th1mainGot [list \
11041133
"HTTP/1.0 302 " "\r\nLocation: http://x/elsewhere\r\n"]]}
1105
-fossil unset vuln-report
11061134
11071135
###############################################################################
11081136
# With no check-out and no repository.
11091137
11101138
fossil close --force
11111139
--- test/th1main.test
+++ test/th1main.test
@@ -3,15 +3,12 @@
3 # Scripts are run with "fossil test-th-eval", templates with
4 # "fossil test-th-render" and "fossil test-th-source", and a ticket page
5 # that holds TH1 is asked for through "fossil http --in".
6 #
7
8 # These tests run only in a long pass: -assurance stress.
9 if {[test_assurance] ne "stress"} {
10 test_skip "runs only with -assurance stress"
11 }
12
13 test_setup
14
15 write_file a.txt "hello\n"
16 write_file f83.txt "line 83\n"
17 write_file f100.txt "line 100\n"
@@ -97,12 +94,14 @@
97 tclready-many {tclReady a} {tclReady}
98 anycap-few {anycap} {anycap STRING}
99 anycap-many {anycap a b} {anycap STRING}
100 combobox-few {combobox a b} {combobox NAME TEXT-LIST NUMLINES}
101 combobox-many {combobox a b 1 d} {combobox NAME TEXT-LIST NUMLINES}
102 copybtn-few {copybtn a 0} {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
103 copybtn-many {copybtn a 0 c 1 e} {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
 
 
104 linecount-few {linecount a 1} {linecount STRING MAX MIN}
105 linecount-many {linecount a 1 2 3} {linecount STRING MAX MIN}
106 repository-many {repository 1 2} {repository ?BOOLEAN?}
107 checkout-many {checkout 1 2} {checkout ?BOOLEAN?}
108 trace-few {trace} {trace STRING}
@@ -144,27 +143,38 @@
144 query-option-many {query -nocomplain a b c} {query SQL CODE}
145 setting-few {setting} {setting ?-strict? ?--? name}
146 setting-many {setting a b c d} {setting ?-strict? ?--? name}
147 setting-two {setting -- a b} {setting ?-strict? ?--? name}
148 setting-strict-two {setting -strict -- a b} {setting ?-strict? ?--? name}
149 glob-few {glob_match a} {glob_match ?-one? ?--? patternList string}
150 glob-many {glob_match -one -- a b c} {glob_match ?-one? ?--? patternList string}
151 glob-three {glob_match a b c} {glob_match ?-one? ?--? patternList string}
 
 
 
152 regexp-few {regexp a} {regexp ?-nocase? ?--? exp string}
153 regexp-many {regexp -nocase -- a b c} {regexp ?-nocase? ?--? exp string}
154 regexp-three {regexp -- a b c} {regexp ?-nocase? ?--? exp string}
155 regexp-one {regexp -nocase -- a} {regexp ?-nocase? ?--? exp string}
156 http-few {http} {http ?-asynchronous? ?--? url ?payload?}
157 http-many {http -asynchronous -- a b c} {http ?-asynchronous? ?--? url ?payload?}
158 http-none {http --} {http ?-asynchronous? ?--? url ?payload?}
159 http-three {http -- a b c} {http ?-asynchronous? ?--? url ?payload?}
 
 
 
 
160 capture-few {captureTh1} {captureTh1 STRING}
161 capture-many {captureTh1 a b} {captureTh1 STRING}
162 } {
163 test_eq th1main-args-$th1mainName [th1main_eval $th1mainCall] \
164 "TH_ERROR: wrong # args: should be \"$th1mainUsage\""
165 }
 
 
 
 
166
167 ###############################################################################
168 # What the commands return and write. A script that writes ends with
169 # "set x {}" so that only what it wrote is printed.
170
@@ -486,12 +496,14 @@
486
487 # With timeline-utc off, "date -local" gives the time of the zone in TZ.
488 fossil settings timeline-utc 0
489 set th1mainSavedTz [expr {[info exists env(TZ)] ? $env(TZ) : ""}]
490 set env(TZ) XXX-5
491 set th1mainDates [split [th1main_eval {puts "[date]|[date -local]"; set x {}}] |]
492 if {$th1mainSavedTz eq ""} { unset env(TZ) } else { set env(TZ) $th1mainSavedTz }
 
 
493 fossil settings timeline-utc 1
494 set th1mainDiff [expr {[clock scan [lindex $th1mainDates 1] -gmt 1]
495 - [clock scan [lindex $th1mainDates 0] -gmt 1]}]
496 test th1main-date-local {$th1mainDiff >= 17999 && $th1mainDiff <= 18001}
497
@@ -551,11 +563,12 @@
551
552 # "setting -strict" and "http -asynchronous" with nothing after the
553 # option, and "http" with an empty first argument, give a script error.
554 foreach {th1mainName th1mainCall th1mainUsage} {
555 setting-strict-alone {setting -strict} {setting ?-strict? ?--? name}
556 http-option-alone {http -asynchronous} {http ?-asynchronous? ?--? url ?payload?}
 
557 http-empty {http {}} {http ?-asynchronous? ?--? url ?payload?}
558 } {
559 set th1mainGot [th1main_eval $th1mainCall]
560 test th1main-args-$th1mainName {$CODE == 0 && [string match \
561 "TH_ERROR: *" $th1mainGot]}
@@ -570,13 +583,16 @@
570 foreach {th1mainName th1mainSql} {
571 two {SELECT 1 AS a; SELECT 2 AS a}
572 space {SELECT 1 AS a; }
573 } {
574 fossil_raw -seconds 10 test-th-eval \
575 "set n 0; query {$th1mainSql} {set n \[expr {\$n+1}\]; if {\$n>50} {error endless}}; set n"
 
 
576 test th1main-query-statements-$th1mainName \
577 {$CODE == 0 && [string trim $RESULT] eq [dict get {two 2 space 1} $th1mainName]}
 
578 }
579
580 # builtin_request_js with a name that is not a built-in file gives a
581 # script error.
582 set th1mainGot [th1main_eval {builtin_request_js nosuch.js}]
@@ -591,11 +607,12 @@
591 set th1mainGot [th1main_eval {http not-a-url}]
592 test th1main-http-not-url \
593 {$CODE == 0 && [string match "TH_ERROR: *" $th1mainGot]}
594
595 # A phantom: an artifact whose content the repository does not hold.
596 set th1mainPhantom abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789
 
597 fossil sql "INSERT INTO blob(rcvid,size,uuid) VALUES(0,-1,'$th1mainPhantom');
598 INSERT INTO phantom SELECT rid FROM blob WHERE size=-1;"
599 test_match th1main-artifact-phantom \
600 [th1main_eval "artifact $th1mainPhantom"] {^TH_ERROR: }
601
@@ -659,11 +676,13 @@
659 test th1main-http-get-request {[holds_strings $th1mainHeard [list \
660 "GET /dir/page?a=b HTTP/1.0\r\n" "Host: $th1mainUrl\r\n" \
661 "User-Agent: " "!Content-Length" "!Authorization"]]}
662
663 set th1mainGot [th1main_http \
664 "http -asynchronous -- http://$th1mainUrl/post {some payload}; set x sent"]
 
 
665 test_eq th1main-http-post $th1mainGot sent
666 test th1main-http-post-request {[holds_strings $th1mainHeard [list \
667 "POST /post HTTP/1.0\r\n" "Content-Length: 12\r\n\r\nsome payload" \
668 "Content-Type: application/x-www-form-urlencoded\r\n"]]}
669
@@ -687,11 +706,10 @@
687 close $th1mainServer
688 # Nothing listens on the port any more.
689 set th1mainGot [th1main_eval "http -asynchronous http://$th1mainUrl/x"]
690 test_match th1main-http-refused $th1mainGot {^TH_ERROR: .}
691 }
692 fossil unset th1-uri-regexp
693
694 ###############################################################################
695 # Tracing: --th-trace prints a log of what the commands did.
696
697 foreach {th1mainName th1mainOpts th1mainScript th1mainWanted} {
@@ -742,33 +760,40 @@
742 empty {} {} \
743 script {a<th1>puts b</th1>c} abc \
744 script-upper {<TH1>puts 1</TH1><Th1>puts 2</tH1><tH1>puts 3</Th1>} 123 \
745 script-unclosed {a<th1>puts b} ab \
746 script-empty-unclosed {a<th1>} a \
747 script-half-closed {a<th1></th1} "a${th1mainErr}no such command: &lt;/th1</p>" \
 
748 not-tags {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \
749 {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \
750 end-tag-alone {a</th1>b} {a</th1>b} \
751 end-tag-look-alikes {<th1>set y {<x </x </tx </thx </th1x}; puts $y</th1>} \
752 {&lt;x &lt;/x &lt;/tx &lt;/thx &lt;/th1x} \
753 dollar-end {a$} {a$} \
754 dollar-bracket-end {a$<} {a$<} \
755 dollar-bracket-unclosed {a$<v b} {a$<v b} \
756 dollar-digit {a$1 $_ $: $:: $::1 $<1> ${v}} {a$1 $_ $: $:: $::1 $<1> ${v}} \
757 variables {<th1>set v {<b>&}; set ::g G; set v_2 two</th1>[$v][$<v>][$::g][$<::g>][$v_2]} \
 
758 {[<b>&][&lt;b&gt;&amp;][G][G][two]} \
759 variable-then-text {<th1>set v 1</th1>$v.$v-$<v>x} {1.1-1x} \
760 variable-unknown {a$nosuch b} "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
761 variable-unknown-escaped {a$<nosuch>b} "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
762 variable-unknown-then-known {<th1>set v 1</th1>a$nosuch b$v c} "a${th1mainNoVar}nosuch b1 c" \
763 variable-tainted {<th1>set t [taint <i>]</th1>[$t][$<t>]end} {[][&lt;i&gt;]end} \
764 error {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \
 
 
 
 
765 error-escaped {<th1>error <b></th1>} "${th1mainErr}&lt;b&gt;</p>" \
766 nested {<th1>set v 2; render {b$<v>|}; render {c$v}</th1>d} {b2|c2d} \
767 nested-error {<th1>render {b$<v>|}; puts never</th1>d} \
768 "b${th1mainNoVar}v${th1mainErr}no such variable: v</p>${th1mainErr}</p>" \
769 output-off {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \
 
770 ] {
771 test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \
772 $th1mainExpected
773 test th1main-render-$th1mainName-exit {$CODE == 0}
774 }
@@ -800,11 +825,12 @@
800 test_eq th1main-render-anon-caps \
801 [th1main_render {<th1>puts [anoncap s]</th1>} --set-anon-caps] 1
802 set env(TH1_TEST_USER_CAPS) o
803 set env(TH1_TEST_ANON_CAPS) h
804 test_eq th1main-render-caps-from-environment \
805 [th1main_render {<th1>puts [hascap o][hascap s][anoncap h][anoncap s]</th1>} \
 
806 --set-user-caps --set-anon-caps] 1010
807 test_eq th1main-eval-caps-from-environment \
808 [th1main_eval {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
809 --set-user-caps --set-anon-caps] 1010
810 unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS)
@@ -831,11 +857,12 @@
831 [th1main_source {puts a; set x b} --no-print-result] a
832 test_eq th1main-source-no-database \
833 [th1main_source {query {SELECT 1 AS a} {puts $a}}] \
834 {TH_ERROR: database is not open }
835 test_eq th1main-source-no-database-quiet \
836 [th1main_source {query -nocomplain {SELECT 1 AS a} {puts $a}; set x quiet}] \
 
837 quiet
838 test_eq th1main-source-no-repository [th1main_source {repository}] {}
839 test_match th1main-source-repository [th1main_source {repository 1}] \
840 {/\.rep\.fossil$}
841 test_match th1main-source-checkout [th1main_source {checkout 1}] \
@@ -848,11 +875,12 @@
848 test_eq th1main-source-anon-caps \
849 [th1main_source {anoncap s} --set-anon-caps] 1
850 set env(TH1_TEST_USER_CAPS) o
851 set env(TH1_TEST_ANON_CAPS) h
852 test_eq th1main-source-caps-from-environment \
853 [th1main_source {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
 
854 --set-user-caps --set-anon-caps] 1010
855 unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS)
856 set th1mainGot [th1main_source {puts hello; set x {}} --cgi]
857 test th1main-source-cgi {[holds_strings $th1mainGot [list \
858 "Status: 200 OK\r\n" "\r\n\r\nhello"]]}
@@ -907,12 +935,11 @@
907 return ""
908 }
909
910 # The same for a GET of /tktnew with the query string QUERY.
911 proc th1main_page {script {query ""} args} {
912 return [th1main_request $script \
913 "GET /tktnew$query HTTP/1.1\r\nHost: x\r\n\r\n" {*}$args]
914 }
915
916 fossil fts-config enable cdtw
917 set th1mainGot [th1main_page {<th1>
918 puts "top=[globalState top none] user=[globalState user none]|"
@@ -1087,11 +1114,13 @@
1087 # page goes on; a tainted query and a tainted redirect are refused.
1088 fossil unset vuln-report
1089 set th1mainGot [th1main_page {B=$title|C=$<title>|END} $th1mainTaintQuery]
1090 test th1main-taint-block-inline {[holds_strings $th1mainGot \
1091 {{B=|C=&lt;u&gt;|END}}]}
1092 set th1mainGot [th1main_page {<th1>query "SELECT 1 AS n /* [getParameter p] */" {puts n=$n}</th1>END} $th1mainTaintQuery]
 
 
1093 test th1main-taint-block-query {[holds_strings $th1mainGot \
1094 {{ERROR: tainted query SQL: &quot;SELECT 1 AS n /* &lt;i&gt; */&quot;} !n=1}]}
1095 set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \
1096 "?u=/elsewhere"]
1097 test th1main-taint-block-redirect {[holds_strings $th1mainGot \
@@ -1100,11 +1129,10 @@
1100 fossil settings vuln-report off
1101 set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \
1102 "?u=/elsewhere"]
1103 test th1main-taint-off-redirect {[holds_strings $th1mainGot [list \
1104 "HTTP/1.0 302 " "\r\nLocation: http://x/elsewhere\r\n"]]}
1105 fossil unset vuln-report
1106
1107 ###############################################################################
1108 # With no check-out and no repository.
1109
1110 fossil close --force
1111
--- test/th1main.test
+++ test/th1main.test
@@ -3,15 +3,12 @@
3 # Scripts are run with "fossil test-th-eval", templates with
4 # "fossil test-th-render" and "fossil test-th-source", and a ticket page
5 # that holds TH1 is asked for through "fossil http --in".
6 #
7
8 # The first sections run at every level, and the rest need
9 # -assurance stress.
 
 
 
10 test_setup
11
12 write_file a.txt "hello\n"
13 write_file f83.txt "line 83\n"
14 write_file f100.txt "line 100\n"
@@ -97,12 +94,14 @@
94 tclready-many {tclReady a} {tclReady}
95 anycap-few {anycap} {anycap STRING}
96 anycap-many {anycap a b} {anycap STRING}
97 combobox-few {combobox a b} {combobox NAME TEXT-LIST NUMLINES}
98 combobox-many {combobox a b 1 d} {combobox NAME TEXT-LIST NUMLINES}
99 copybtn-few {copybtn a 0}
100 {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
101 copybtn-many {copybtn a 0 c 1 e}
102 {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?}
103 linecount-few {linecount a 1} {linecount STRING MAX MIN}
104 linecount-many {linecount a 1 2 3} {linecount STRING MAX MIN}
105 repository-many {repository 1 2} {repository ?BOOLEAN?}
106 checkout-many {checkout 1 2} {checkout ?BOOLEAN?}
107 trace-few {trace} {trace STRING}
@@ -144,27 +143,38 @@
143 query-option-many {query -nocomplain a b c} {query SQL CODE}
144 setting-few {setting} {setting ?-strict? ?--? name}
145 setting-many {setting a b c d} {setting ?-strict? ?--? name}
146 setting-two {setting -- a b} {setting ?-strict? ?--? name}
147 setting-strict-two {setting -strict -- a b} {setting ?-strict? ?--? name}
148 glob-few {glob_match a}
149 {glob_match ?-one? ?--? patternList string}
150 glob-many {glob_match -one -- a b c}
151 {glob_match ?-one? ?--? patternList string}
152 glob-three {glob_match a b c}
153 {glob_match ?-one? ?--? patternList string}
154 regexp-few {regexp a} {regexp ?-nocase? ?--? exp string}
155 regexp-many {regexp -nocase -- a b c} {regexp ?-nocase? ?--? exp string}
156 regexp-three {regexp -- a b c} {regexp ?-nocase? ?--? exp string}
157 regexp-one {regexp -nocase -- a} {regexp ?-nocase? ?--? exp string}
158 http-few {http}
159 {http ?-asynchronous? ?--? url ?payload?}
160 http-many {http -asynchronous -- a b c}
161 {http ?-asynchronous? ?--? url ?payload?}
162 http-none {http --}
163 {http ?-asynchronous? ?--? url ?payload?}
164 http-three {http -- a b c}
165 {http ?-asynchronous? ?--? url ?payload?}
166 capture-few {captureTh1} {captureTh1 STRING}
167 capture-many {captureTh1 a b} {captureTh1 STRING}
168 } {
169 test_eq th1main-args-$th1mainName [th1main_eval $th1mainCall] \
170 "TH_ERROR: wrong # args: should be \"$th1mainUsage\""
171 }
172
173 if {[test_assurance] ne "stress"} {
174 test_skip "the tests after the first sections need -assurance stress"
175 }
176
177 ###############################################################################
178 # What the commands return and write. A script that writes ends with
179 # "set x {}" so that only what it wrote is printed.
180
@@ -486,12 +496,14 @@
496
497 # With timeline-utc off, "date -local" gives the time of the zone in TZ.
498 fossil settings timeline-utc 0
499 set th1mainSavedTz [expr {[info exists env(TZ)] ? $env(TZ) : ""}]
500 set env(TZ) XXX-5
501 set th1mainDates [split [th1main_eval {puts "[date]|[date -local]"; set x {}}] \
502 |]
503 if {$th1mainSavedTz eq ""} { unset env(TZ) } else \
504 { set env(TZ) $th1mainSavedTz }
505 fossil settings timeline-utc 1
506 set th1mainDiff [expr {[clock scan [lindex $th1mainDates 1] -gmt 1]
507 - [clock scan [lindex $th1mainDates 0] -gmt 1]}]
508 test th1main-date-local {$th1mainDiff >= 17999 && $th1mainDiff <= 18001}
509
@@ -551,11 +563,12 @@
563
564 # "setting -strict" and "http -asynchronous" with nothing after the
565 # option, and "http" with an empty first argument, give a script error.
566 foreach {th1mainName th1mainCall th1mainUsage} {
567 setting-strict-alone {setting -strict} {setting ?-strict? ?--? name}
568 http-option-alone {http -asynchronous}
569 {http ?-asynchronous? ?--? url ?payload?}
570 http-empty {http {}} {http ?-asynchronous? ?--? url ?payload?}
571 } {
572 set th1mainGot [th1main_eval $th1mainCall]
573 test th1main-args-$th1mainName {$CODE == 0 && [string match \
574 "TH_ERROR: *" $th1mainGot]}
@@ -570,13 +583,16 @@
583 foreach {th1mainName th1mainSql} {
584 two {SELECT 1 AS a; SELECT 2 AS a}
585 space {SELECT 1 AS a; }
586 } {
587 fossil_raw -seconds 10 test-th-eval \
588 [join [list \
589 "set n 0; query {$th1mainSql} {set n \[expr {\$n+1}\]; if " \
590 "{\$n>50} {error endless}}; set n"] ""]
591 test th1main-query-statements-$th1mainName \
592 {$CODE == 0 && [string trim $RESULT] eq [dict get {two 2 space 1} \
593 $th1mainName]}
594 }
595
596 # builtin_request_js with a name that is not a built-in file gives a
597 # script error.
598 set th1mainGot [th1main_eval {builtin_request_js nosuch.js}]
@@ -591,11 +607,12 @@
607 set th1mainGot [th1main_eval {http not-a-url}]
608 test th1main-http-not-url \
609 {$CODE == 0 && [string match "TH_ERROR: *" $th1mainGot]}
610
611 # A phantom: an artifact whose content the repository does not hold.
612 set th1mainPhantom \
613 abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789
614 fossil sql "INSERT INTO blob(rcvid,size,uuid) VALUES(0,-1,'$th1mainPhantom');
615 INSERT INTO phantom SELECT rid FROM blob WHERE size=-1;"
616 test_match th1main-artifact-phantom \
617 [th1main_eval "artifact $th1mainPhantom"] {^TH_ERROR: }
618
@@ -659,11 +676,13 @@
676 test th1main-http-get-request {[holds_strings $th1mainHeard [list \
677 "GET /dir/page?a=b HTTP/1.0\r\n" "Host: $th1mainUrl\r\n" \
678 "User-Agent: " "!Content-Length" "!Authorization"]]}
679
680 set th1mainGot [th1main_http \
681 [join [list \
682 "http -asynchronous -- http://$th1mainUrl/post {some " \
683 "payload}; set x sent"] ""]]
684 test_eq th1main-http-post $th1mainGot sent
685 test th1main-http-post-request {[holds_strings $th1mainHeard [list \
686 "POST /post HTTP/1.0\r\n" "Content-Length: 12\r\n\r\nsome payload" \
687 "Content-Type: application/x-www-form-urlencoded\r\n"]]}
688
@@ -687,11 +706,10 @@
706 close $th1mainServer
707 # Nothing listens on the port any more.
708 set th1mainGot [th1main_eval "http -asynchronous http://$th1mainUrl/x"]
709 test_match th1main-http-refused $th1mainGot {^TH_ERROR: .}
710 }
 
711
712 ###############################################################################
713 # Tracing: --th-trace prints a log of what the commands did.
714
715 foreach {th1mainName th1mainOpts th1mainScript th1mainWanted} {
@@ -742,33 +760,40 @@
760 empty {} {} \
761 script {a<th1>puts b</th1>c} abc \
762 script-upper {<TH1>puts 1</TH1><Th1>puts 2</tH1><tH1>puts 3</Th1>} 123 \
763 script-unclosed {a<th1>puts b} ab \
764 script-empty-unclosed {a<th1>} a \
765 script-half-closed {a<th1></th1} \
766 "a${th1mainErr}no such command: &lt;/th1</p>" \
767 not-tags {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \
768 {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \
769 end-tag-alone {a</th1>b} {a</th1>b} \
770 end-tag-look-alikes {<th1>set y {<x </x </tx </thx </th1x}; puts $y</th1>} \
771 {&lt;x &lt;/x &lt;/tx &lt;/thx &lt;/th1x} \
772 dollar-end {a$} {a$} \
773 dollar-bracket-end {a$<} {a$<} \
774 dollar-bracket-unclosed {a$<v b} {a$<v b} \
775 dollar-digit {a$1 $_ $: $:: $::1 $<1> ${v}} {a$1 $_ $: $:: $::1 $<1> ${v}} \
776 variables \
777 {<th1>set v {<b>&}; set ::g G; set v_2 two</th1>[$v][$<v>][$::g][$<::g>][$v_2]} \
778 {[<b>&][&lt;b&gt;&amp;][G][G][two]} \
779 variable-then-text {<th1>set v 1</th1>$v.$v-$<v>x} {1.1-1x} \
780 variable-unknown {a$nosuch b} \
781 "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
782 variable-unknown-escaped {a$<nosuch>b} \
783 "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \
784 variable-unknown-then-known {<th1>set v 1</th1>a$nosuch b$v c} \
785 "a${th1mainNoVar}nosuch b1 c" \
786 variable-tainted {<th1>set t [taint <i>]</th1>[$t][$<t>]end} \
787 {[][&lt;i&gt;]end} \
788 error-plain {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \
789 error-escaped {<th1>error <b></th1>} "${th1mainErr}&lt;b&gt;</p>" \
790 nested {<th1>set v 2; render {b$<v>|}; render {c$v}</th1>d} {b2|c2d} \
791 nested-error {<th1>render {b$<v>|}; puts never</th1>d} \
792 "b${th1mainNoVar}v${th1mainErr}no such variable: v</p>${th1mainErr}</p>" \
793 output-off \
794 {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \
795 ] {
796 test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \
797 $th1mainExpected
798 test th1main-render-$th1mainName-exit {$CODE == 0}
799 }
@@ -800,11 +825,12 @@
825 test_eq th1main-render-anon-caps \
826 [th1main_render {<th1>puts [anoncap s]</th1>} --set-anon-caps] 1
827 set env(TH1_TEST_USER_CAPS) o
828 set env(TH1_TEST_ANON_CAPS) h
829 test_eq th1main-render-caps-from-environment \
830 [th1main_render \
831 {<th1>puts [hascap o][hascap s][anoncap h][anoncap s]</th1>} \
832 --set-user-caps --set-anon-caps] 1010
833 test_eq th1main-eval-caps-from-environment \
834 [th1main_eval {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
835 --set-user-caps --set-anon-caps] 1010
836 unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS)
@@ -831,11 +857,12 @@
857 [th1main_source {puts a; set x b} --no-print-result] a
858 test_eq th1main-source-no-database \
859 [th1main_source {query {SELECT 1 AS a} {puts $a}}] \
860 {TH_ERROR: database is not open }
861 test_eq th1main-source-no-database-quiet \
862 [th1main_source \
863 {query -nocomplain {SELECT 1 AS a} {puts $a}; set x quiet}] \
864 quiet
865 test_eq th1main-source-no-repository [th1main_source {repository}] {}
866 test_match th1main-source-repository [th1main_source {repository 1}] \
867 {/\.rep\.fossil$}
868 test_match th1main-source-checkout [th1main_source {checkout 1}] \
@@ -848,11 +875,12 @@
875 test_eq th1main-source-anon-caps \
876 [th1main_source {anoncap s} --set-anon-caps] 1
877 set env(TH1_TEST_USER_CAPS) o
878 set env(TH1_TEST_ANON_CAPS) h
879 test_eq th1main-source-caps-from-environment \
880 [th1main_source \
881 {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \
882 --set-user-caps --set-anon-caps] 1010
883 unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS)
884 set th1mainGot [th1main_source {puts hello; set x {}} --cgi]
885 test th1main-source-cgi {[holds_strings $th1mainGot [list \
886 "Status: 200 OK\r\n" "\r\n\r\nhello"]]}
@@ -907,12 +935,11 @@
935 return ""
936 }
937
938 # The same for a GET of /tktnew with the query string QUERY.
939 proc th1main_page {script {query ""} args} {
940 return [th1main_request $script [request_get /tktnew$query] {*}$args]
 
941 }
942
943 fossil fts-config enable cdtw
944 set th1mainGot [th1main_page {<th1>
945 puts "top=[globalState top none] user=[globalState user none]|"
@@ -1087,11 +1114,13 @@
1114 # page goes on; a tainted query and a tainted redirect are refused.
1115 fossil unset vuln-report
1116 set th1mainGot [th1main_page {B=$title|C=$<title>|END} $th1mainTaintQuery]
1117 test th1main-taint-block-inline {[holds_strings $th1mainGot \
1118 {{B=|C=&lt;u&gt;|END}}]}
1119 set th1mainGot [th1main_page \
1120 {<th1>query "SELECT 1 AS n /* [getParameter p] */" {puts n=$n}</th1>END} \
1121 $th1mainTaintQuery]
1122 test th1main-taint-block-query {[holds_strings $th1mainGot \
1123 {{ERROR: tainted query SQL: &quot;SELECT 1 AS n /* &lt;i&gt; */&quot;} !n=1}]}
1124 set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \
1125 "?u=/elsewhere"]
1126 test th1main-taint-block-redirect {[holds_strings $th1mainGot \
@@ -1100,11 +1129,10 @@
1129 fossil settings vuln-report off
1130 set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \
1131 "?u=/elsewhere"]
1132 test th1main-taint-off-redirect {[holds_strings $th1mainGot [list \
1133 "HTTP/1.0 302 " "\r\nLocation: http://x/elsewhere\r\n"]]}
 
1134
1135 ###############################################################################
1136 # With no check-out and no repository.
1137
1138 fossil close --force
1139
+121 -94
--- test/url.test
+++ test/url.test
@@ -17,15 +17,12 @@
1717
#
1818
# http.test tests whole clones over HTTP and HTTPS. ssh.test tests what
1919
# goes on an ssh command line.
2020
#
2121
22
-# These tests run only in a long pass: -assurance stress.
23
-if {[test_assurance] ne "stress"} {
24
- test_skip "runs only with -assurance stress"
25
-}
26
-
22
+# The first sections run at every level, and the rest need
23
+# -assurance stress.
2724
require_no_open_checkout
2825
2926
if {![loopback_available]} {
3027
test_skip "the tests need a TCP connection over the loopback interface"
3128
}
@@ -437,10 +434,14 @@
437434
# The other network options of a sync command are accepted.
438435
#
439436
foreach urlOption {--nosync --ipv4 --ipv6 --accept-any-cert} {
440437
url_parse_test url-proxy-option$urlOption http://h/x $urlOption {name h}
441438
}
439
+
440
+if {[test_assurance] ne "stress"} {
441
+ test_skip "the tests after the first sections need -assurance stress"
442
+}
442443
443444
###############################################################################
444445
# The name for a clone of a URL.
445446
446447
foreach {urlName urlText urlExpected} {
@@ -475,56 +476,28 @@
475476
test_eq url-basename-none $RESULT ""
476477
477478
###############################################################################
478479
# The HTTP exchange.
479480
480
-set urlServers [list]
481
-set urlRequests [list]
482
-
483481
# Listens on a port on 127.0.0.1 that the system chooses, and returns
484482
# the port. Connection N is answered with item N of REPLIES, and the
485483
# last item answers every later connection. "PORT" in a reply stands for
486484
# the port. Each request is appended to the list urlRequests.
487485
#
488486
proc url_listen {replies} {
489487
set ::urlRequests [list]
490
- set server [socket -server [list url_accept $replies] -myaddr 127.0.0.1 0]
491
- lappend ::urlServers $server
492
- return [lindex [fconfigure $server -sockname] 2]
493
-}
494
-proc url_accept {replies chan address port} {
495
- fconfigure $chan -translation binary -blocking 0
496
- set ::urlRequest($chan) ""
497
- fileevent $chan readable [list url_receive $replies $chan]
498
-}
499
-proc url_receive {replies chan} {
500
- append ::urlRequest($chan) [read $chan]
501
- set request $::urlRequest($chan)
502
- set end [string first "\r\n\r\n" $request]
503
- set length 0
504
- regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
505
- if {![eof $chan] &&
506
- ($end < 0 || [string length $request] < $end + 4 + $length)} {
507
- return
508
- }
509
- unset ::urlRequest($chan)
510
- fileevent $chan readable {}
511
- fconfigure $chan -blocking 1
488
+ return [test_listen [list url_receive $replies]]
489
+}
490
+proc url_receive {replies chan request} {
512491
set number [llength $::urlRequests]
513492
lappend ::urlRequests $request
514493
if {$number >= [llength $replies]} {set number end}
515494
set port [lindex [fconfigure $chan -sockname] 2]
516495
catch {
517496
puts -nonewline $chan [string map [list PORT $port] \
518497
[lindex $replies $number]]
519498
}
520
- catch {close $chan}
521
-}
522
-proc url_listen_stop {} {
523
- update
524
- foreach urlServer $::urlServers {close $urlServer}
525
- set ::urlServers [list]
526499
}
527500
528501
# Returns TEXT with each line end changed to CR LF.
529502
proc url_crlf {text} {
530503
return [string map [list \n \r\n] $text]
@@ -556,11 +529,11 @@
556529
# with REPLIES, with the options and further arguments in ARGS.
557530
#
558531
proc url_httpmsg {replies args} {
559532
set port [url_listen $replies]
560533
fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x {*}$args
561
- url_listen_stop
534
+ test_listen_stop
562535
}
563536
564537
# Replies that are accepted. Each row is a name, the reply header, the
565538
# reply body and the body that test-httpmsg must print.
566539
#
@@ -595,26 +568,38 @@
595568
hello hello \
596569
content-type-other \
597570
"HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: 5\n\n" \
598571
hello hello \
599572
content-type-debug \
600
- "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-debug\nContent-Length: 5\n\n" \
573
+ [join [list \
574
+ "HTTP/1.1 200 OK\n" \
575
+ "Content-Type: application/x-fossil-debug\n" \
576
+ "Content-Length: 5\n\n"] ""] \
601577
hello hello \
602578
content-type-uncompressed \
603
- "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 5\n\n" \
579
+ [join [list \
580
+ "HTTP/1.1 200 OK\n" \
581
+ "Content-Type: application/x-fossil-uncompressed\n" \
582
+ "Content-Length: 5\n\n"] ""] \
604583
hello hello \
605584
interim-100 \
606585
"HTTP/1.1 100 Continue\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
607586
hello hello \
608587
interim-with-headers \
609
- "HTTP/1.1 103 Early Hints\nLink: </x>\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
588
+ [join [list \
589
+ "HTTP/1.1 103 Early Hints\nLink: </x>\n\nHTTP/1.1 200 OK\n" \
590
+ "Content-Length: 5\n\n"] ""] \
610591
hello hello \
611592
interim-twice \
612
- "HTTP/1.1 100 Continue\n\nHTTP/1.1 102 Processing\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
593
+ [join [list \
594
+ "HTTP/1.1 100 Continue\n\nHTTP/1.1 102 Processing\n\n" \
595
+ "HTTP/1.1 200 OK\nContent-Length: 5\n\n"] ""] \
613596
hello hello \
614597
interim-four-blank-lines \
615
- "HTTP/1.1 100 Continue\n\n\n\n\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
598
+ [join [list \
599
+ "HTTP/1.1 100 Continue\n\n\n\n\n\nHTTP/1.1 200 OK\n" \
600
+ "Content-Length: 5\n\n"] ""] \
616601
hello hello \
617602
chunked "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
618603
"3\r\nhel\r\n2\r\nlo\r\n0\r\n\r\n" hello \
619604
chunked-upper-case "HTTP/1.1 200 OK\nTransfer-Encoding:CHUNKED\n\n" \
620605
"A\r\n0123456789\r\n0\r\n\r\n" 0123456789 \
@@ -698,17 +683,23 @@
698683
"HTTP/1.1 200 OK\nTransfer-Encoding: chunked, gzip\n\n" \
699684
{unsupported transfer-encoding: chunked, gzip} \
700685
transfer-encoding-empty "HTTP/1.1 200 OK\nTransfer-Encoding:\n\n" \
701686
{unsupported transfer-encoding: } \
702687
transfer-encoding-twice \
703
- "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\nTransfer-Encoding: chunked\n\n0\n\n" \
688
+ [join [list \
689
+ "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n" \
690
+ "Transfer-Encoding: chunked\n\n0\n\n"] ""] \
704691
{server sent two transfer-encoding headers} \
705692
transfer-encoding-and-length \
706
- "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\nContent-Length: 5\n\n5\nhello\n0\n\n" \
693
+ [join [list \
694
+ "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n" \
695
+ "Content-Length: 5\n\n5\nhello\n0\n\n"] ""] \
707696
{reply has both content-length and transfer-encoding} \
708697
length-and-transfer-encoding \
709
- "HTTP/1.1 200 OK\nContent-Length: 0\nTransfer-Encoding: chunked\n\n0\n\n" \
698
+ [join [list \
699
+ "HTTP/1.1 200 OK\nContent-Length: 0\n" \
700
+ "Transfer-Encoding: chunked\n\n0\n\n"] ""] \
710701
{reply has both content-length and transfer-encoding} \
711702
chunk-no-body "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
712703
{chunked reply ended without terminator} \
713704
chunk-blank-line "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n\n" \
714705
{chunked reply ended without terminator} \
@@ -725,11 +716,13 @@
725716
{chunked reply: missing or malformed chunk size} \
726717
chunk-size-80000000 \
727718
"HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n80000000\nhello\n0\n\n" \
728719
{chunked reply: invalid chunk size} \
729720
chunk-size-twenty-digits \
730
- "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\nFFFFFFFFFFFFFFFFFFFF\nhello\n0\n\n" \
721
+ [join [list \
722
+ "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
723
+ "FFFFFFFFFFFFFFFFFFFF\nhello\n0\n\n"] ""] \
731724
{chunked reply: invalid chunk size} \
732725
chunk-size-then-text \
733726
"HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5 x\nhello\n0\n\n" \
734727
{chunked reply: malformed chunk size line} \
735728
chunk-extension-no-name \
@@ -777,11 +770,12 @@
777770
{unknown repository: \n} \
778771
status-401 "HTTP/1.1 401 Unauthorized\n\n" \
779772
{server says: 401 Unauthorized} \
780773
] {
781774
url_httpmsg [list [url_crlf $urlReply]] -v
782
- test_match url-http-refused-$urlName "$CODE $RESULT" "^1 (?:.*\n)*.*$urlMessage"
775
+ test_match url-http-refused-$urlName "$CODE $RESULT" \
776
+ "^1 (?:.*\n)*.*$urlMessage"
783777
url_httpmsg [list [url_crlf $urlReply]]
784778
test url-http-refused-quiet-$urlName {$CODE == 1}
785779
}
786780
787781
# A redirect to an ssh: URL with no path is refused.
@@ -804,11 +798,12 @@
804798
redirect-to-file "HTTP/1.1 302 Found\nLocation: file:///nosuchdir/r\n\n" \
805799
{cannot redirect to file:///nosuchdir/r} \
806800
] {
807801
file delete out.txt
808802
url_httpmsg [list [url_crlf $urlReply]] --out out.txt
809
- test url-http-message-$urlName {$CODE == 1 && [string first $urlMessage $RESULT] >= 0}
803
+ test url-http-message-$urlName \
804
+ {$CODE == 1 && [string first $urlMessage $RESULT] >= 0}
810805
url_httpmsg [list [url_crlf $urlReply]]
811806
test url-http-message-quiet-$urlName {$CODE == 1 && $RESULT eq ""}
812807
}
813808
814809
# A reply that is shorter than its Content-Length is an error, and only
@@ -818,49 +813,52 @@
818813
file delete out.txt
819814
url_httpmsg [list $urlShort] --out out.txt
820815
test url-http-message-truncated {$CODE == 1 &&
821816
[string first "response truncated: got 5 bytes of 6" $RESULT] >= 0}
822817
url_httpmsg [list $urlShort]
823
-test url-http-message-quiet-truncated {$CODE == 1}
824818
test url-http-truncated-bytes {$RESULT eq "hello"}
825819
826820
# A redirect is followed three times, with the same method and payload,
827821
# and the fourth is refused. 301, 302, 307 and 308 are followed. A
828822
# Location that ends in /xfer is used without that ending.
829823
#
830824
foreach urlStatus {301 302 307 308} {
831825
url_httpmsg [list \
832
- [url_crlf "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/b\n\n"] \
826
+ [url_crlf \
827
+ "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/b\n\n"] \
833828
[url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]]
834829
test url-http-redirect-$urlStatus {$CODE == 0 && $RESULT eq "hello" &&
835830
[url_request_line 0] eq "GET /x HTTP/1.1" &&
836831
[url_request_line 1] eq "GET /b HTTP/1.1"}
837832
}
838833
write_file payload.txt "payload text\n"
839834
url_httpmsg [list \
840835
[url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"] \
841836
[url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/c\n\n"] \
842
- [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer\n\n"] \
837
+ [url_crlf \
838
+ "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer\n\n"] \
843839
[url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] payload.txt
844840
test url-http-redirect-three {$CODE == 0 && $RESULT eq "hello" &&
845841
[llength $urlRequests] == 4 &&
846842
[url_request_line 3] eq "POST /d HTTP/1.1" &&
847843
[url_request_body 3] eq "payload text\n"}
848844
url_httpmsg [list \
849845
[url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"]]
850846
test url-http-redirect-four {$CODE == 1 && [llength $urlRequests] == 4}
851847
url_httpmsg [list \
852
- [url_crlf "HTTP/1.1 302 Found\nX-Other: 1\nLOCATION:http://127.0.0.1:PORT/b\n\n"] \
848
+ [url_crlf \
849
+ "HTTP/1.1 302 Found\nX-Other: 1\nLOCATION:http://127.0.0.1:PORT/b\n\n"] \
853850
[url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] -v
854851
test url-http-redirect-after-other-header {$CODE == 0 &&
855852
[string first "redirect with status 302 to http://127.0.0.1:" $RESULT] >= 0}
856853
857854
# A Location that ends in /xfer loses only the last one, so that a
858855
# repository whose own path ends in /xfer is still found.
859856
#
860857
url_httpmsg [list \
861
- [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer/xfer\n\n"] \
858
+ [url_crlf \
859
+ "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer/xfer\n\n"] \
862860
[url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]]
863861
test_eq url-http-redirect-xfer-twice [url_request_line 1] "GET /d/xfer HTTP/1.1"
864862
865863
# A 401 reply is asked for again twice, and then is an error. Standard
866864
# input is not a terminal, so fossil cannot ask for credentials.
@@ -891,11 +889,11 @@
891889
[url_request_header 0 Cookie] eq "(none)"}
892890
893891
set urlPort [url_listen [list $urlOk]]
894892
fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort
895893
test_eq url-request-no-path [url_request_line 0] "GET / HTTP/1.1"
896
-url_listen_stop
894
+test_listen_stop
897895
898896
url_httpmsg [list $urlOk] payload.txt
899897
test url-request-post {[url_request_line 0] eq "POST /x HTTP/1.1" &&
900898
[url_request_header 0 Content-Type] eq "text/plain" &&
901899
[url_request_header 0 Content-Length] eq "13" &&
@@ -913,11 +911,11 @@
913911
fossil_raw -seconds 60 -input "from standard input" \
914912
test-httpmsg http://127.0.0.1:$urlPort/x -
915913
test url-request-standard-input {
916914
[url_request_header 0 Content-Type] eq "application/x-unknown" &&
917915
[url_request_body 0] eq "from standard input"}
918
-url_listen_stop
916
+test_listen_stop
919917
920918
# --compress sends the payload compressed and expects a compressed
921919
# reply: four bytes of size and then a zlib stream.
922920
#
923921
proc url_compress {text} {
@@ -929,16 +927,18 @@
929927
}
930928
binary scan $bytes I size
931929
if {$size != [string length $text]} {return "(wrong size)"}
932930
return $text
933931
}
934
-set urlPort [url_listen [list [url_crlf "HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: [string length [url_compress "compressed reply"]]\n\n"][url_compress "compressed reply"]]]
932
+set urlPort [url_listen [list \
933
+ [url_crlf \
934
+ "HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: [string length [url_compress "compressed reply"]]\n\n"][url_compress "compressed reply"]]]
935935
fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort/x payload.txt \
936936
--compress
937937
test url-request-compress {$CODE == 0 && $RESULT eq "compressed reply" &&
938938
[url_uncompress [url_request_body 0]] eq "payload text\n"}
939
-url_listen_stop
939
+test_listen_stop
940940
941941
# The reply goes to the file named by --out or by the third argument,
942942
# but not by both.
943943
#
944944
file delete out.txt
@@ -952,13 +952,12 @@
952952
url_httpmsg [list $urlOk] payload.txt out.txt --out other.txt
953953
test url-request-out-twice {$CODE == 1 && ![file exists out.txt] &&
954954
[string first "output file specified twice" $RESULT] >= 0}
955955
url_httpmsg [list $urlOk] -v
956956
test url-request-verbose {$CODE == 0 &&
957
- [string first "Sending " $RESULT] >= 0 &&
958
- [string first "Read: \[HTTP/1.1 200 OK\]" $RESULT] >= 0 &&
959
- [string first "Reply received: 2 of 2 bytes" $RESULT] >= 0}
957
+ [holds_strings $RESULT [list "Sending " "Read: \[HTTP/1.1 200 OK\]" \
958
+ "Reply received: 2 of 2 bytes"]]}
960959
url_httpmsg [list [url_crlf "HTTP/1.1 200 OK\n\n"]hello] -v
961960
test url-request-verbose-no-length {$CODE == 0 && [string first \
962961
"Reply received: 5 bytes (w/o content-length)" $RESULT] >= 0}
963962
964963
foreach urlOption {--ipv4 --no-cert-verify} {
@@ -969,13 +968,15 @@
969968
# 127.0.0.1: macOS reaches it through a mapped address, Linux refuses it.
970969
url_httpmsg [list $urlOk] --ipv6
971970
test url-request-option--ipv6 {($CODE == 0 && $RESULT eq "ok") ||
972971
[string first "getaddrinfo() fails" $RESULT] >= 0}
973972
fossil_raw test-httpmsg
974
-test url-request-usage-none {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
973
+test url-request-usage-none \
974
+ {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
975975
fossil_raw test-httpmsg http://127.0.0.1:1/ a b c
976
-test url-request-usage-many {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
976
+test url-request-usage-many \
977
+ {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
977978
fossil_raw test-httpmsg file://$urlRepo
978979
test url-request-file-needs-subpath {$CODE == 1 && [string first \
979980
"the --subpath option is required for file://" $RESULT] >= 0}
980981
981982
# --httptrace writes each request and reply to a numbered file, and
@@ -1024,20 +1025,24 @@
10241025
# message BODY.
10251026
proc url_login_card {user secret body} {
10261027
set nonce [sha1_text $body]
10271028
return "login $user $nonce [sha1_text $nonce$secret]"
10281029
}
1029
-set urlSyncOk [url_crlf "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 2\n\n"]ok
1030
+set urlSyncOk [url_crlf \
1031
+ [join [list \
1032
+ "HTTP/1.1 200 OK\n" \
1033
+ "Content-Type: application/x-fossil-uncompressed\n" \
1034
+ "Content-Length: 2\n\n"] ""]]ok
10301035
set urlCard "[url_login_card bob secret "payload text\n"]\npayload text\n"
10311036
10321037
# Runs test-httpmsg --xfer for the user and password in USERINFO, which
10331038
# is empty or ends with "@", and further options in ARGS.
10341039
proc url_xfer {userinfo args} {
10351040
set port [url_listen [list $::urlSyncOk]]
10361041
fossil_raw -seconds 60 test-httpmsg http://${userinfo}127.0.0.1:$port/x \
10371042
payload.txt --xfer {*}$args
1038
- url_listen_stop
1043
+ test_listen_stop
10391044
}
10401045
10411046
url_xfer bob:secret@
10421047
test url-login-password {$CODE == 0 && $RESULT eq "ok" &&
10431048
[url_request_header 0 Content-Type] eq "application/x-fossil" &&
@@ -1072,11 +1077,15 @@
10721077
# already.
10731078
#
10741079
fossil sql "SELECT value FROM config WHERE name='project-code'"
10751080
set urlProject [string trim $RESULT]
10761081
set urlSecret [sha1_text $urlProject/bob/secret]
1077
-set urlPullOk [url_crlf "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 41\n\n"]
1082
+set urlPullOk [url_crlf \
1083
+ [join [list \
1084
+ "HTTP/1.1 200 OK\n" \
1085
+ "Content-Type: application/x-fossil-uncompressed\n" \
1086
+ "Content-Length: 41\n\n"] ""]]
10781087
append urlPullOk "# timestamp 2026-01-01T00:00:00 errors 0\n"
10791088
10801089
# Returns 1 if request NUMBER of the last exchange begins with the login
10811090
# card for USER and the shared secret SECRET, and 0 otherwise.
10821091
proc url_login_ok {number user secret} {
@@ -1091,11 +1100,11 @@
10911100
# text, and the options in ARGS, from the URL with USERINFO.
10921101
proc url_pull {userinfo args} {
10931102
set port [url_listen [list $::urlPullOk]]
10941103
fossil_raw -seconds 60 pull http://${userinfo}127.0.0.1:$port/repo \
10951104
--httptrace {*}$args
1096
- url_listen_stop
1105
+ test_listen_stop
10971106
file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
10981107
return $port
10991108
}
11001109
url_pull bob:secret@ --once
11011110
test url-login-project-code {$CODE == 0 && [url_login_ok 0 bob $urlSecret]}
@@ -1134,20 +1143,24 @@
11341143
fossil_raw -seconds 60 test-httpmsg http://bob:[email protected]:$urlPort/x \
11351144
--xfer --login-card-header
11361145
test url-login-cookie-no-payload {
11371146
[url_request_line 0] eq "GET /x HTTP/1.1" &&
11381147
[url_request_header 0 Cookie] eq "(none)"}
1139
-url_listen_stop
1148
+test_listen_stop
11401149
11411150
# A sync reply of another content type is an error message from the
11421151
# server. It is printed without its HTML tags.
11431152
#
11441153
proc url_xfer_reply {type body args} {
1145
- set port [url_listen [list [url_crlf "HTTP/1.1 200 OK\nContent-Type: $type\nContent-Length: [string length $body]\n\n"]$body]]
1154
+ set port [url_listen [list \
1155
+ [url_crlf \
1156
+ [join [list \
1157
+ "HTTP/1.1 200 OK\nContent-Type: $type\n" \
1158
+ "Content-Length: [string length $body]\n\n"] ""]]$body]]
11461159
fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x \
11471160
payload.txt --xfer {*}$args
1148
- url_listen_stop
1161
+ test_listen_stop
11491162
}
11501163
url_xfer_reply text/html "<p>no <b>such</b> page</p>" -v
11511164
test url-xfer-error-verbose {$CODE == 1 &&
11521165
[string first "server sends error: no such page" $RESULT] >= 0}
11531166
url_xfer_reply text/html "plain text, no tags" -v
@@ -1157,12 +1170,11 @@
11571170
test url-xfer-error-open-tag {$CODE == 1 &&
11581171
[string first "server sends error: cut short " $RESULT] >= 0}
11591172
file delete out.txt
11601173
url_xfer_reply text/html "<p>no such page</p>" --out out.txt
11611174
test url-xfer-error-to-file {$CODE == 1 &&
1162
- [string first "server sends error" $RESULT] >= 0 &&
1163
- [string first "no such page" $RESULT] < 0}
1175
+ [holds_strings $RESULT {"server sends error" "!no such page"}]}
11641176
url_xfer_reply text/html "<p>no such page</p>"
11651177
test url-xfer-error-quiet {$CODE == 1 &&
11661178
[string first "server sends error" $RESULT] < 0}
11671179
url_xfer_reply application/x-fossil-debug "debug reply"
11681180
test url-xfer-reply-debug {$CODE == 0 && $RESULT eq "debug reply"}
@@ -1175,12 +1187,11 @@
11751187
# The file: transport. test-httpmsg sends the request for the path
11761188
# given by --subpath to "fossil http" on the repository file.
11771189
11781190
fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /test-env
11791191
test url-file-page {$CODE == 0 &&
1180
- [string first "<title>" $RESULT] >= 0 &&
1181
- [string first "Environment Test" $RESULT] >= 0}
1192
+ [holds_strings $RESULT {<title> "Environment Test"}]}
11821193
fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /nosuchpage -v
11831194
test url-file-not-found {$CODE == 1 &&
11841195
[string first "server says: 404 Not Found" $RESULT] >= 0}
11851196
fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath / -v
11861197
test url-file-redirect {$CODE == 1 &&
@@ -1191,21 +1202,25 @@
11911202
###############################################################################
11921203
# Clone, pull and sync against the server of this file.
11931204
11941205
# Returns the reply header for a sync reply with the body BODY.
11951206
proc url_sync_reply {body} {
1196
- return [url_crlf "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: [string length $body]\n\n"]$body
1207
+ return [url_crlf \
1208
+ [join [list \
1209
+ "HTTP/1.1 200 OK\n" \
1210
+ "Content-Type: application/x-fossil-uncompressed\n" \
1211
+ "Content-Length: [string length $body]\n\n"] ""]]$body
11971212
}
11981213
set urlNotFound [url_crlf "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n"]
11991214
12001215
# Runs "fossil VERB URL" with the options in ARGS, where "PORT" in URL
12011216
# and in ARGS stands for the port of a server that answers with REPLIES.
12021217
proc url_sync {verb url replies args} {
12031218
set port [url_listen $replies]
12041219
set map [list PORT $port]
12051220
fossil_raw -seconds 60 $verb [string map $map $url] {*}[string map $map $args]
1206
- url_listen_stop
1221
+ test_listen_stop
12071222
return $port
12081223
}
12091224
12101225
# A proxy gets the whole URL in the request line and its own user and
12111226
# password in a Proxy-Authorization header.
@@ -1240,11 +1255,10 @@
12401255
12411256
# A proxy is an http: or https: URL. With any other value fossil must
12421257
# not talk to the repository that the value names in place of the
12431258
# remote.
12441259
#
1245
-file delete proxyclone.fossil
12461260
fossil_raw -seconds 60 clone http://example.invalid/repo proxyclone.fossil \
12471261
--proxy file://$urlRepo
12481262
test url-sync-proxy-file {$CODE == 1 && ![file exists proxyclone.fossil]}
12491263
file delete proxyclone.fossil
12501264
@@ -1290,11 +1304,12 @@
12901304
# that is redirected with 302 or 307 does not.
12911305
#
12921306
foreach {urlStatus urlRemembered} {301 1 308 1 302 0 307 0} {
12931307
fossil remote off
12941308
set urlPort [url_sync pull http://127.0.0.1:PORT/old [list \
1295
- [url_crlf "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/new\n\n"] \
1309
+ [url_crlf \
1310
+ "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/new\n\n"] \
12961311
$urlNotFound]]
12971312
fossil remote
12981313
test_eq url-sync-redirect-$urlStatus-remembered [string trim $RESULT] \
12991314
[expr {$urlRemembered ? "http://127.0.0.1:$urlPort/new" : "off"}]
13001315
}
@@ -1324,11 +1339,11 @@
13241339
url_parse_test url-sync-saved-password saved {--use-config --show-pw} \
13251340
{user bob passwd secret pwConfig sync-pw:saved}
13261341
set urlPort [url_listen [list $urlPullOk]]
13271342
url_config sync-url:saved 'http://[email protected]:$urlPort/repo'
13281343
fossil_raw -seconds 60 pull saved --once --httptrace
1329
-url_listen_stop
1344
+test_listen_stop
13301345
file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
13311346
test url-sync-saved-remote {$CODE == 0 && [url_login_ok 0 bob $urlSecret]}
13321347
url_parse_test url-sync-saved-password-hashed saved {--use-config --show-pw} \
13331348
[list user bob passwd $urlSecret]
13341349
fossil remote delete saved
@@ -1348,11 +1363,11 @@
13481363
fossil remote add saved http://bob:[email protected]:1/repo
13491364
set urlPort [url_listen [list $urlPullOk]]
13501365
url_config sync-url:saved 'http://[email protected]:$urlPort/repo'
13511366
url_config parent-project-code 'parentcode'
13521367
fossil_raw -seconds 60 pull saved --from-parent-project
1353
-url_listen_stop
1368
+test_listen_stop
13541369
url_parse_test url-sync-parent-remembered default {--use-parent --show-pw} \
13551370
[list name 127.0.0.1 port $urlPort user bob \
13561371
passwd [sha1_text parentcode/bob/secret] pwConfig parent-project-pw]
13571372
fossil remote
13581373
test_eq url-sync-parent-not-default [string trim $RESULT] off
@@ -1360,21 +1375,20 @@
13601375
fossil sql "DELETE FROM config WHERE name GLOB 'parent-project-*'"
13611376
13621377
# A clone that fails with --httptrace prints the last reply. When there
13631378
# is no reply it prints none.
13641379
#
1365
-file delete traceclone.fossil
13661380
url_sync clone http://127.0.0.1:PORT/repo [list \
13671381
[url_sync_reply "error not\\sallowed\\shere\n"]] traceclone.fossil \
13681382
--httptrace
13691383
test url-sync-clone-httptrace {$CODE == 1 &&
13701384
![file exists traceclone.fossil] &&
13711385
[string first "server returned an error - clone aborted" $RESULT] >= 0 &&
13721386
[regexp {clone aborted\s+HTTP/1.1 200 OK} $RESULT]}
13731387
file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
13741388
set urlPort [url_listen {}]
1375
-url_listen_stop
1389
+test_listen_stop
13761390
fossil_raw -seconds 60 clone http://127.0.0.1:$urlPort/repo traceclone.fossil \
13771391
--httptrace
13781392
test url-sync-clone-httptrace-no-reply {$CODE == 1 &&
13791393
![file exists traceclone.fossil] &&
13801394
[string first "cannot connect to host 127.0.0.1:$urlPort" $RESULT] >= 0}
@@ -1394,11 +1408,12 @@
13941408
[string first "Transport command failed: " $RESULT] >= 0 &&
13951409
[regexp -line {^RUN .*transport-fail.sh '?http://u:p@h:81/x'? } $RESULT]}
13961410
fossil_raw pull {http://u:p@[::1]/x} --once \
13971411
--transport-command [file join $urlDir transport-fail.sh] --httptrace
13981412
test url-transport-url-ipv6 {
1399
- [regexp -line {^RUN .*transport-fail.sh '?http://u:p@\[::1\]/x'? } $RESULT]}
1413
+ [regexp -line {^RUN .*transport-fail.sh '?http://u:p@\[::1\]/x'? } \
1414
+ $RESULT]}
14001415
fossil_raw pull file://$urlRepo --once \
14011416
--transport-command [file join $urlDir transport-fail.sh] --httptrace
14021417
test url-transport-url-file {[regexp -line \
14031418
"^RUN .*transport-fail.sh '?file://$urlRepo'? " $RESULT]}
14041419
}
@@ -1406,26 +1421,31 @@
14061421
###############################################################################
14071422
# The sync button of the /xfersetup page syncs with the saved remote. A
14081423
# remote with a user and no saved password gets a message, not a login
14091424
# card.
14101425
1411
-write_file xfersetup.txt [url_crlf "POST /xfersetup HTTP/1.0\nHost: localhost\nReferer: http://localhost/xfersetup\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 6\n\nsync=1"]
1426
+write_file xfersetup.txt [url_crlf \
1427
+ [join [list \
1428
+ "POST /xfersetup HTTP/1.0\nHost: localhost\n" \
1429
+ "Referer: http://localhost/xfersetup\n" \
1430
+ "Content-Type: application/x-www-form-urlencoded\n" \
1431
+ "Content-Length: 6\n\nsync=1"] ""]]
14121432
set urlPort [url_listen [list $urlPullOk]]
14131433
url_config last-sync-url 'http://[email protected]:$urlPort/repo'
14141434
url_config last-sync-pw obscure('secret')
14151435
fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \
14161436
--localauth
1417
-url_listen_stop
1437
+test_listen_stop
14181438
test url-web-sync {[string first "HTTP/1.0 200 OK" $RESULT] == 0 &&
14191439
[llength $urlRequests] == 1 &&
14201440
[string first "Sync done" $RESULT] >= 0}
14211441
set urlPort [url_listen [list $urlPullOk]]
14221442
fossil sql "DELETE FROM config WHERE name='last-sync-pw'"
14231443
url_config last-sync-url 'http://[email protected]:$urlPort/repo'
14241444
fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \
14251445
--localauth
1426
-url_listen_stop
1446
+test_listen_stop
14271447
test url-web-sync-no-password {[string first "HTTP/1.0 200 OK" $RESULT] == 0 &&
14281448
[string first "incorrect or missing password for user bob" $RESULT] >= 0}
14291449
fossil sql "DELETE FROM config WHERE name GLOB 'last-sync-*'"
14301450
14311451
###############################################################################
@@ -1561,11 +1581,12 @@
15611581
proc url_ssh_runs {} {
15621582
set file [file join $::urlSshDir count]
15631583
return [expr {[file exists $file] ? [string trim [read_file $file]] : 0}]
15641584
}
15651585
1566
- set urlSshOk [url_crlf "Status: 200 OK\nContent-Type: text/plain\nContent-Length: 5\n\n"]hello
1586
+ set urlSshOk [url_crlf \
1587
+ "Status: 200 OK\nContent-Type: text/plain\nContent-Length: 5\n\n"]hello
15671588
15681589
# The reply of "fossil test-http" on the server begins with a Status
15691590
# line. The request says that it comes over ssh.
15701591
#
15711592
url_ssh [list $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x
@@ -1577,11 +1598,12 @@
15771598
test-httpmsg ssh://hh/dir/r.fossil --subpath /x
15781599
test url-ssh-reply-http-status {$CODE == 0 && $RESULT eq "hello"}
15791600
url_ssh [list [url_crlf "STATUS: 200\ncontent-length: 5\n\n"]hello] \
15801601
test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x
15811602
test url-ssh-reply-upper-case-refused {$CODE == 1}
1582
- url_ssh [list [url_crlf "HTTP/1.1 200 OK\nStatus: 200 OK\nContent-Length: 5\n\n"]hello] \
1603
+ url_ssh [list [url_crlf \
1604
+ "HTTP/1.1 200 OK\nStatus: 200 OK\nContent-Length: 5\n\n"]hello] \
15831605
test-httpmsg ssh://hh/dir/r.fossil --subpath /x
15841606
test url-ssh-reply-both-status-lines {$CODE == 0 && $RESULT eq "hello"}
15851607
15861608
foreach {urlName urlReply urlMessage} [list \
15871609
status-500 "Status: 500 Server Error\n\n" {server says: 500 Server Error} \
@@ -1600,17 +1622,22 @@
16001622
url_ssh [list [url_crlf $urlReply]] \
16011623
test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x -v
16021624
test_match url-ssh-refused-$urlName "$CODE $RESULT" \
16031625
"^1 (?:.*\n)*.*$urlMessage"
16041626
}
1605
- url_ssh [list [url_crlf "Status: 302 Found\nLocation: http://127.0.0.1:1/x\n\n"]] \
1627
+ url_ssh [list [url_crlf \
1628
+ "Status: 302 Found\nLocation: http://127.0.0.1:1/x\n\n"]] \
16061629
test-httpmsg ssh://hh/dir/r.fossil --subpath /x
16071630
test url-ssh-redirect-quiet {$CODE == 1 && $RESULT eq ""}
16081631
16091632
# A sync request over ssh has no login card.
16101633
#
1611
- url_ssh [list [url_crlf "Status: 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 2\n\n"]ok] \
1634
+ url_ssh [list [url_crlf \
1635
+ [join [list \
1636
+ "Status: 200 OK\n" \
1637
+ "Content-Type: application/x-fossil-uncompressed\n" \
1638
+ "Content-Length: 2\n\n"] ""]]ok] \
16121639
test-httpmsg ssh://bob:secret@hh/dir/r.fossil --subpath /x \
16131640
payload.txt --xfer -v
16141641
test url-ssh-no-login-card {$CODE == 0 &&
16151642
[string first "13 byte payload" $RESULT] >= 0 &&
16161643
[string first "<bob@hh>" $urlSshArgs] >= 0}
@@ -1621,14 +1648,15 @@
16211648
#
16221649
url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \
16231650
--out out.txt
16241651
test url-ssh-retry-with-path {$CODE == 0 && [url_ssh_runs] == 2 &&
16251652
[read_file out.txt] eq "hello" &&
1626
- [string first "First attempt to run fossil on hh using SSH failed" \
1627
- $RESULT] >= 0 &&
1628
- [string first "Retrying with the PATH= argument" $RESULT] >= 0 &&
1629
- [regexp {<hh>\n<fossil>\n<test-http>\n(?:.*\n)*<hh>\n<PATH=[^\n]*>\n<fossil>\n<test-http>} \
1653
+ [holds_strings $RESULT \
1654
+ {"First attempt to run fossil on hh using SSH failed"
1655
+ "Retrying with the PATH= argument"}] &&
1656
+ [regexp \
1657
+ {<hh>\n<fossil>\n<test-http>\n(?:.*\n)*<hh>\n<PATH=[^\n]*>\n<fossil>\n<test-http>} \
16301658
$urlSshArgs]}
16311659
url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x
16321660
test url-ssh-retry-quiet {$CODE == 0 && [url_ssh_runs] == 2 &&
16331661
$RESULT eq "hello"}
16341662
url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \
@@ -1702,8 +1730,7 @@
17021730
unset env(URL_SSH_DIR)
17031731
}
17041732
17051733
###############################################################################
17061734
1707
-url_listen_stop
17081735
array set env [array get urlSavedEnv]
17091736
test_cleanup
17101737
--- test/url.test
+++ test/url.test
@@ -17,15 +17,12 @@
17 #
18 # http.test tests whole clones over HTTP and HTTPS. ssh.test tests what
19 # goes on an ssh command line.
20 #
21
22 # These tests run only in a long pass: -assurance stress.
23 if {[test_assurance] ne "stress"} {
24 test_skip "runs only with -assurance stress"
25 }
26
27 require_no_open_checkout
28
29 if {![loopback_available]} {
30 test_skip "the tests need a TCP connection over the loopback interface"
31 }
@@ -437,10 +434,14 @@
437 # The other network options of a sync command are accepted.
438 #
439 foreach urlOption {--nosync --ipv4 --ipv6 --accept-any-cert} {
440 url_parse_test url-proxy-option$urlOption http://h/x $urlOption {name h}
441 }
 
 
 
 
442
443 ###############################################################################
444 # The name for a clone of a URL.
445
446 foreach {urlName urlText urlExpected} {
@@ -475,56 +476,28 @@
475 test_eq url-basename-none $RESULT ""
476
477 ###############################################################################
478 # The HTTP exchange.
479
480 set urlServers [list]
481 set urlRequests [list]
482
483 # Listens on a port on 127.0.0.1 that the system chooses, and returns
484 # the port. Connection N is answered with item N of REPLIES, and the
485 # last item answers every later connection. "PORT" in a reply stands for
486 # the port. Each request is appended to the list urlRequests.
487 #
488 proc url_listen {replies} {
489 set ::urlRequests [list]
490 set server [socket -server [list url_accept $replies] -myaddr 127.0.0.1 0]
491 lappend ::urlServers $server
492 return [lindex [fconfigure $server -sockname] 2]
493 }
494 proc url_accept {replies chan address port} {
495 fconfigure $chan -translation binary -blocking 0
496 set ::urlRequest($chan) ""
497 fileevent $chan readable [list url_receive $replies $chan]
498 }
499 proc url_receive {replies chan} {
500 append ::urlRequest($chan) [read $chan]
501 set request $::urlRequest($chan)
502 set end [string first "\r\n\r\n" $request]
503 set length 0
504 regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
505 if {![eof $chan] &&
506 ($end < 0 || [string length $request] < $end + 4 + $length)} {
507 return
508 }
509 unset ::urlRequest($chan)
510 fileevent $chan readable {}
511 fconfigure $chan -blocking 1
512 set number [llength $::urlRequests]
513 lappend ::urlRequests $request
514 if {$number >= [llength $replies]} {set number end}
515 set port [lindex [fconfigure $chan -sockname] 2]
516 catch {
517 puts -nonewline $chan [string map [list PORT $port] \
518 [lindex $replies $number]]
519 }
520 catch {close $chan}
521 }
522 proc url_listen_stop {} {
523 update
524 foreach urlServer $::urlServers {close $urlServer}
525 set ::urlServers [list]
526 }
527
528 # Returns TEXT with each line end changed to CR LF.
529 proc url_crlf {text} {
530 return [string map [list \n \r\n] $text]
@@ -556,11 +529,11 @@
556 # with REPLIES, with the options and further arguments in ARGS.
557 #
558 proc url_httpmsg {replies args} {
559 set port [url_listen $replies]
560 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x {*}$args
561 url_listen_stop
562 }
563
564 # Replies that are accepted. Each row is a name, the reply header, the
565 # reply body and the body that test-httpmsg must print.
566 #
@@ -595,26 +568,38 @@
595 hello hello \
596 content-type-other \
597 "HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: 5\n\n" \
598 hello hello \
599 content-type-debug \
600 "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-debug\nContent-Length: 5\n\n" \
 
 
 
601 hello hello \
602 content-type-uncompressed \
603 "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 5\n\n" \
 
 
 
604 hello hello \
605 interim-100 \
606 "HTTP/1.1 100 Continue\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
607 hello hello \
608 interim-with-headers \
609 "HTTP/1.1 103 Early Hints\nLink: </x>\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
 
 
610 hello hello \
611 interim-twice \
612 "HTTP/1.1 100 Continue\n\nHTTP/1.1 102 Processing\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
 
 
613 hello hello \
614 interim-four-blank-lines \
615 "HTTP/1.1 100 Continue\n\n\n\n\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
 
 
616 hello hello \
617 chunked "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
618 "3\r\nhel\r\n2\r\nlo\r\n0\r\n\r\n" hello \
619 chunked-upper-case "HTTP/1.1 200 OK\nTransfer-Encoding:CHUNKED\n\n" \
620 "A\r\n0123456789\r\n0\r\n\r\n" 0123456789 \
@@ -698,17 +683,23 @@
698 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked, gzip\n\n" \
699 {unsupported transfer-encoding: chunked, gzip} \
700 transfer-encoding-empty "HTTP/1.1 200 OK\nTransfer-Encoding:\n\n" \
701 {unsupported transfer-encoding: } \
702 transfer-encoding-twice \
703 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\nTransfer-Encoding: chunked\n\n0\n\n" \
 
 
704 {server sent two transfer-encoding headers} \
705 transfer-encoding-and-length \
706 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\nContent-Length: 5\n\n5\nhello\n0\n\n" \
 
 
707 {reply has both content-length and transfer-encoding} \
708 length-and-transfer-encoding \
709 "HTTP/1.1 200 OK\nContent-Length: 0\nTransfer-Encoding: chunked\n\n0\n\n" \
 
 
710 {reply has both content-length and transfer-encoding} \
711 chunk-no-body "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
712 {chunked reply ended without terminator} \
713 chunk-blank-line "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n\n" \
714 {chunked reply ended without terminator} \
@@ -725,11 +716,13 @@
725 {chunked reply: missing or malformed chunk size} \
726 chunk-size-80000000 \
727 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n80000000\nhello\n0\n\n" \
728 {chunked reply: invalid chunk size} \
729 chunk-size-twenty-digits \
730 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\nFFFFFFFFFFFFFFFFFFFF\nhello\n0\n\n" \
 
 
731 {chunked reply: invalid chunk size} \
732 chunk-size-then-text \
733 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5 x\nhello\n0\n\n" \
734 {chunked reply: malformed chunk size line} \
735 chunk-extension-no-name \
@@ -777,11 +770,12 @@
777 {unknown repository: \n} \
778 status-401 "HTTP/1.1 401 Unauthorized\n\n" \
779 {server says: 401 Unauthorized} \
780 ] {
781 url_httpmsg [list [url_crlf $urlReply]] -v
782 test_match url-http-refused-$urlName "$CODE $RESULT" "^1 (?:.*\n)*.*$urlMessage"
 
783 url_httpmsg [list [url_crlf $urlReply]]
784 test url-http-refused-quiet-$urlName {$CODE == 1}
785 }
786
787 # A redirect to an ssh: URL with no path is refused.
@@ -804,11 +798,12 @@
804 redirect-to-file "HTTP/1.1 302 Found\nLocation: file:///nosuchdir/r\n\n" \
805 {cannot redirect to file:///nosuchdir/r} \
806 ] {
807 file delete out.txt
808 url_httpmsg [list [url_crlf $urlReply]] --out out.txt
809 test url-http-message-$urlName {$CODE == 1 && [string first $urlMessage $RESULT] >= 0}
 
810 url_httpmsg [list [url_crlf $urlReply]]
811 test url-http-message-quiet-$urlName {$CODE == 1 && $RESULT eq ""}
812 }
813
814 # A reply that is shorter than its Content-Length is an error, and only
@@ -818,49 +813,52 @@
818 file delete out.txt
819 url_httpmsg [list $urlShort] --out out.txt
820 test url-http-message-truncated {$CODE == 1 &&
821 [string first "response truncated: got 5 bytes of 6" $RESULT] >= 0}
822 url_httpmsg [list $urlShort]
823 test url-http-message-quiet-truncated {$CODE == 1}
824 test url-http-truncated-bytes {$RESULT eq "hello"}
825
826 # A redirect is followed three times, with the same method and payload,
827 # and the fourth is refused. 301, 302, 307 and 308 are followed. A
828 # Location that ends in /xfer is used without that ending.
829 #
830 foreach urlStatus {301 302 307 308} {
831 url_httpmsg [list \
832 [url_crlf "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/b\n\n"] \
 
833 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]]
834 test url-http-redirect-$urlStatus {$CODE == 0 && $RESULT eq "hello" &&
835 [url_request_line 0] eq "GET /x HTTP/1.1" &&
836 [url_request_line 1] eq "GET /b HTTP/1.1"}
837 }
838 write_file payload.txt "payload text\n"
839 url_httpmsg [list \
840 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"] \
841 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/c\n\n"] \
842 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer\n\n"] \
 
843 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] payload.txt
844 test url-http-redirect-three {$CODE == 0 && $RESULT eq "hello" &&
845 [llength $urlRequests] == 4 &&
846 [url_request_line 3] eq "POST /d HTTP/1.1" &&
847 [url_request_body 3] eq "payload text\n"}
848 url_httpmsg [list \
849 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"]]
850 test url-http-redirect-four {$CODE == 1 && [llength $urlRequests] == 4}
851 url_httpmsg [list \
852 [url_crlf "HTTP/1.1 302 Found\nX-Other: 1\nLOCATION:http://127.0.0.1:PORT/b\n\n"] \
 
853 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] -v
854 test url-http-redirect-after-other-header {$CODE == 0 &&
855 [string first "redirect with status 302 to http://127.0.0.1:" $RESULT] >= 0}
856
857 # A Location that ends in /xfer loses only the last one, so that a
858 # repository whose own path ends in /xfer is still found.
859 #
860 url_httpmsg [list \
861 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer/xfer\n\n"] \
 
862 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]]
863 test_eq url-http-redirect-xfer-twice [url_request_line 1] "GET /d/xfer HTTP/1.1"
864
865 # A 401 reply is asked for again twice, and then is an error. Standard
866 # input is not a terminal, so fossil cannot ask for credentials.
@@ -891,11 +889,11 @@
891 [url_request_header 0 Cookie] eq "(none)"}
892
893 set urlPort [url_listen [list $urlOk]]
894 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort
895 test_eq url-request-no-path [url_request_line 0] "GET / HTTP/1.1"
896 url_listen_stop
897
898 url_httpmsg [list $urlOk] payload.txt
899 test url-request-post {[url_request_line 0] eq "POST /x HTTP/1.1" &&
900 [url_request_header 0 Content-Type] eq "text/plain" &&
901 [url_request_header 0 Content-Length] eq "13" &&
@@ -913,11 +911,11 @@
913 fossil_raw -seconds 60 -input "from standard input" \
914 test-httpmsg http://127.0.0.1:$urlPort/x -
915 test url-request-standard-input {
916 [url_request_header 0 Content-Type] eq "application/x-unknown" &&
917 [url_request_body 0] eq "from standard input"}
918 url_listen_stop
919
920 # --compress sends the payload compressed and expects a compressed
921 # reply: four bytes of size and then a zlib stream.
922 #
923 proc url_compress {text} {
@@ -929,16 +927,18 @@
929 }
930 binary scan $bytes I size
931 if {$size != [string length $text]} {return "(wrong size)"}
932 return $text
933 }
934 set urlPort [url_listen [list [url_crlf "HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: [string length [url_compress "compressed reply"]]\n\n"][url_compress "compressed reply"]]]
 
 
935 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort/x payload.txt \
936 --compress
937 test url-request-compress {$CODE == 0 && $RESULT eq "compressed reply" &&
938 [url_uncompress [url_request_body 0]] eq "payload text\n"}
939 url_listen_stop
940
941 # The reply goes to the file named by --out or by the third argument,
942 # but not by both.
943 #
944 file delete out.txt
@@ -952,13 +952,12 @@
952 url_httpmsg [list $urlOk] payload.txt out.txt --out other.txt
953 test url-request-out-twice {$CODE == 1 && ![file exists out.txt] &&
954 [string first "output file specified twice" $RESULT] >= 0}
955 url_httpmsg [list $urlOk] -v
956 test url-request-verbose {$CODE == 0 &&
957 [string first "Sending " $RESULT] >= 0 &&
958 [string first "Read: \[HTTP/1.1 200 OK\]" $RESULT] >= 0 &&
959 [string first "Reply received: 2 of 2 bytes" $RESULT] >= 0}
960 url_httpmsg [list [url_crlf "HTTP/1.1 200 OK\n\n"]hello] -v
961 test url-request-verbose-no-length {$CODE == 0 && [string first \
962 "Reply received: 5 bytes (w/o content-length)" $RESULT] >= 0}
963
964 foreach urlOption {--ipv4 --no-cert-verify} {
@@ -969,13 +968,15 @@
969 # 127.0.0.1: macOS reaches it through a mapped address, Linux refuses it.
970 url_httpmsg [list $urlOk] --ipv6
971 test url-request-option--ipv6 {($CODE == 0 && $RESULT eq "ok") ||
972 [string first "getaddrinfo() fails" $RESULT] >= 0}
973 fossil_raw test-httpmsg
974 test url-request-usage-none {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
 
975 fossil_raw test-httpmsg http://127.0.0.1:1/ a b c
976 test url-request-usage-many {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
 
977 fossil_raw test-httpmsg file://$urlRepo
978 test url-request-file-needs-subpath {$CODE == 1 && [string first \
979 "the --subpath option is required for file://" $RESULT] >= 0}
980
981 # --httptrace writes each request and reply to a numbered file, and
@@ -1024,20 +1025,24 @@
1024 # message BODY.
1025 proc url_login_card {user secret body} {
1026 set nonce [sha1_text $body]
1027 return "login $user $nonce [sha1_text $nonce$secret]"
1028 }
1029 set urlSyncOk [url_crlf "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 2\n\n"]ok
 
 
 
 
1030 set urlCard "[url_login_card bob secret "payload text\n"]\npayload text\n"
1031
1032 # Runs test-httpmsg --xfer for the user and password in USERINFO, which
1033 # is empty or ends with "@", and further options in ARGS.
1034 proc url_xfer {userinfo args} {
1035 set port [url_listen [list $::urlSyncOk]]
1036 fossil_raw -seconds 60 test-httpmsg http://${userinfo}127.0.0.1:$port/x \
1037 payload.txt --xfer {*}$args
1038 url_listen_stop
1039 }
1040
1041 url_xfer bob:secret@
1042 test url-login-password {$CODE == 0 && $RESULT eq "ok" &&
1043 [url_request_header 0 Content-Type] eq "application/x-fossil" &&
@@ -1072,11 +1077,15 @@
1072 # already.
1073 #
1074 fossil sql "SELECT value FROM config WHERE name='project-code'"
1075 set urlProject [string trim $RESULT]
1076 set urlSecret [sha1_text $urlProject/bob/secret]
1077 set urlPullOk [url_crlf "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 41\n\n"]
 
 
 
 
1078 append urlPullOk "# timestamp 2026-01-01T00:00:00 errors 0\n"
1079
1080 # Returns 1 if request NUMBER of the last exchange begins with the login
1081 # card for USER and the shared secret SECRET, and 0 otherwise.
1082 proc url_login_ok {number user secret} {
@@ -1091,11 +1100,11 @@
1091 # text, and the options in ARGS, from the URL with USERINFO.
1092 proc url_pull {userinfo args} {
1093 set port [url_listen [list $::urlPullOk]]
1094 fossil_raw -seconds 60 pull http://${userinfo}127.0.0.1:$port/repo \
1095 --httptrace {*}$args
1096 url_listen_stop
1097 file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
1098 return $port
1099 }
1100 url_pull bob:secret@ --once
1101 test url-login-project-code {$CODE == 0 && [url_login_ok 0 bob $urlSecret]}
@@ -1134,20 +1143,24 @@
1134 fossil_raw -seconds 60 test-httpmsg http://bob:[email protected]:$urlPort/x \
1135 --xfer --login-card-header
1136 test url-login-cookie-no-payload {
1137 [url_request_line 0] eq "GET /x HTTP/1.1" &&
1138 [url_request_header 0 Cookie] eq "(none)"}
1139 url_listen_stop
1140
1141 # A sync reply of another content type is an error message from the
1142 # server. It is printed without its HTML tags.
1143 #
1144 proc url_xfer_reply {type body args} {
1145 set port [url_listen [list [url_crlf "HTTP/1.1 200 OK\nContent-Type: $type\nContent-Length: [string length $body]\n\n"]$body]]
 
 
 
 
1146 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x \
1147 payload.txt --xfer {*}$args
1148 url_listen_stop
1149 }
1150 url_xfer_reply text/html "<p>no <b>such</b> page</p>" -v
1151 test url-xfer-error-verbose {$CODE == 1 &&
1152 [string first "server sends error: no such page" $RESULT] >= 0}
1153 url_xfer_reply text/html "plain text, no tags" -v
@@ -1157,12 +1170,11 @@
1157 test url-xfer-error-open-tag {$CODE == 1 &&
1158 [string first "server sends error: cut short " $RESULT] >= 0}
1159 file delete out.txt
1160 url_xfer_reply text/html "<p>no such page</p>" --out out.txt
1161 test url-xfer-error-to-file {$CODE == 1 &&
1162 [string first "server sends error" $RESULT] >= 0 &&
1163 [string first "no such page" $RESULT] < 0}
1164 url_xfer_reply text/html "<p>no such page</p>"
1165 test url-xfer-error-quiet {$CODE == 1 &&
1166 [string first "server sends error" $RESULT] < 0}
1167 url_xfer_reply application/x-fossil-debug "debug reply"
1168 test url-xfer-reply-debug {$CODE == 0 && $RESULT eq "debug reply"}
@@ -1175,12 +1187,11 @@
1175 # The file: transport. test-httpmsg sends the request for the path
1176 # given by --subpath to "fossil http" on the repository file.
1177
1178 fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /test-env
1179 test url-file-page {$CODE == 0 &&
1180 [string first "<title>" $RESULT] >= 0 &&
1181 [string first "Environment Test" $RESULT] >= 0}
1182 fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /nosuchpage -v
1183 test url-file-not-found {$CODE == 1 &&
1184 [string first "server says: 404 Not Found" $RESULT] >= 0}
1185 fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath / -v
1186 test url-file-redirect {$CODE == 1 &&
@@ -1191,21 +1202,25 @@
1191 ###############################################################################
1192 # Clone, pull and sync against the server of this file.
1193
1194 # Returns the reply header for a sync reply with the body BODY.
1195 proc url_sync_reply {body} {
1196 return [url_crlf "HTTP/1.1 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: [string length $body]\n\n"]$body
 
 
 
 
1197 }
1198 set urlNotFound [url_crlf "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n"]
1199
1200 # Runs "fossil VERB URL" with the options in ARGS, where "PORT" in URL
1201 # and in ARGS stands for the port of a server that answers with REPLIES.
1202 proc url_sync {verb url replies args} {
1203 set port [url_listen $replies]
1204 set map [list PORT $port]
1205 fossil_raw -seconds 60 $verb [string map $map $url] {*}[string map $map $args]
1206 url_listen_stop
1207 return $port
1208 }
1209
1210 # A proxy gets the whole URL in the request line and its own user and
1211 # password in a Proxy-Authorization header.
@@ -1240,11 +1255,10 @@
1240
1241 # A proxy is an http: or https: URL. With any other value fossil must
1242 # not talk to the repository that the value names in place of the
1243 # remote.
1244 #
1245 file delete proxyclone.fossil
1246 fossil_raw -seconds 60 clone http://example.invalid/repo proxyclone.fossil \
1247 --proxy file://$urlRepo
1248 test url-sync-proxy-file {$CODE == 1 && ![file exists proxyclone.fossil]}
1249 file delete proxyclone.fossil
1250
@@ -1290,11 +1304,12 @@
1290 # that is redirected with 302 or 307 does not.
1291 #
1292 foreach {urlStatus urlRemembered} {301 1 308 1 302 0 307 0} {
1293 fossil remote off
1294 set urlPort [url_sync pull http://127.0.0.1:PORT/old [list \
1295 [url_crlf "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/new\n\n"] \
 
1296 $urlNotFound]]
1297 fossil remote
1298 test_eq url-sync-redirect-$urlStatus-remembered [string trim $RESULT] \
1299 [expr {$urlRemembered ? "http://127.0.0.1:$urlPort/new" : "off"}]
1300 }
@@ -1324,11 +1339,11 @@
1324 url_parse_test url-sync-saved-password saved {--use-config --show-pw} \
1325 {user bob passwd secret pwConfig sync-pw:saved}
1326 set urlPort [url_listen [list $urlPullOk]]
1327 url_config sync-url:saved 'http://[email protected]:$urlPort/repo'
1328 fossil_raw -seconds 60 pull saved --once --httptrace
1329 url_listen_stop
1330 file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
1331 test url-sync-saved-remote {$CODE == 0 && [url_login_ok 0 bob $urlSecret]}
1332 url_parse_test url-sync-saved-password-hashed saved {--use-config --show-pw} \
1333 [list user bob passwd $urlSecret]
1334 fossil remote delete saved
@@ -1348,11 +1363,11 @@
1348 fossil remote add saved http://bob:[email protected]:1/repo
1349 set urlPort [url_listen [list $urlPullOk]]
1350 url_config sync-url:saved 'http://[email protected]:$urlPort/repo'
1351 url_config parent-project-code 'parentcode'
1352 fossil_raw -seconds 60 pull saved --from-parent-project
1353 url_listen_stop
1354 url_parse_test url-sync-parent-remembered default {--use-parent --show-pw} \
1355 [list name 127.0.0.1 port $urlPort user bob \
1356 passwd [sha1_text parentcode/bob/secret] pwConfig parent-project-pw]
1357 fossil remote
1358 test_eq url-sync-parent-not-default [string trim $RESULT] off
@@ -1360,21 +1375,20 @@
1360 fossil sql "DELETE FROM config WHERE name GLOB 'parent-project-*'"
1361
1362 # A clone that fails with --httptrace prints the last reply. When there
1363 # is no reply it prints none.
1364 #
1365 file delete traceclone.fossil
1366 url_sync clone http://127.0.0.1:PORT/repo [list \
1367 [url_sync_reply "error not\\sallowed\\shere\n"]] traceclone.fossil \
1368 --httptrace
1369 test url-sync-clone-httptrace {$CODE == 1 &&
1370 ![file exists traceclone.fossil] &&
1371 [string first "server returned an error - clone aborted" $RESULT] >= 0 &&
1372 [regexp {clone aborted\s+HTTP/1.1 200 OK} $RESULT]}
1373 file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
1374 set urlPort [url_listen {}]
1375 url_listen_stop
1376 fossil_raw -seconds 60 clone http://127.0.0.1:$urlPort/repo traceclone.fossil \
1377 --httptrace
1378 test url-sync-clone-httptrace-no-reply {$CODE == 1 &&
1379 ![file exists traceclone.fossil] &&
1380 [string first "cannot connect to host 127.0.0.1:$urlPort" $RESULT] >= 0}
@@ -1394,11 +1408,12 @@
1394 [string first "Transport command failed: " $RESULT] >= 0 &&
1395 [regexp -line {^RUN .*transport-fail.sh '?http://u:p@h:81/x'? } $RESULT]}
1396 fossil_raw pull {http://u:p@[::1]/x} --once \
1397 --transport-command [file join $urlDir transport-fail.sh] --httptrace
1398 test url-transport-url-ipv6 {
1399 [regexp -line {^RUN .*transport-fail.sh '?http://u:p@\[::1\]/x'? } $RESULT]}
 
1400 fossil_raw pull file://$urlRepo --once \
1401 --transport-command [file join $urlDir transport-fail.sh] --httptrace
1402 test url-transport-url-file {[regexp -line \
1403 "^RUN .*transport-fail.sh '?file://$urlRepo'? " $RESULT]}
1404 }
@@ -1406,26 +1421,31 @@
1406 ###############################################################################
1407 # The sync button of the /xfersetup page syncs with the saved remote. A
1408 # remote with a user and no saved password gets a message, not a login
1409 # card.
1410
1411 write_file xfersetup.txt [url_crlf "POST /xfersetup HTTP/1.0\nHost: localhost\nReferer: http://localhost/xfersetup\nContent-Type: application/x-www-form-urlencoded\nContent-Length: 6\n\nsync=1"]
 
 
 
 
 
1412 set urlPort [url_listen [list $urlPullOk]]
1413 url_config last-sync-url 'http://[email protected]:$urlPort/repo'
1414 url_config last-sync-pw obscure('secret')
1415 fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \
1416 --localauth
1417 url_listen_stop
1418 test url-web-sync {[string first "HTTP/1.0 200 OK" $RESULT] == 0 &&
1419 [llength $urlRequests] == 1 &&
1420 [string first "Sync done" $RESULT] >= 0}
1421 set urlPort [url_listen [list $urlPullOk]]
1422 fossil sql "DELETE FROM config WHERE name='last-sync-pw'"
1423 url_config last-sync-url 'http://[email protected]:$urlPort/repo'
1424 fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \
1425 --localauth
1426 url_listen_stop
1427 test url-web-sync-no-password {[string first "HTTP/1.0 200 OK" $RESULT] == 0 &&
1428 [string first "incorrect or missing password for user bob" $RESULT] >= 0}
1429 fossil sql "DELETE FROM config WHERE name GLOB 'last-sync-*'"
1430
1431 ###############################################################################
@@ -1561,11 +1581,12 @@
1561 proc url_ssh_runs {} {
1562 set file [file join $::urlSshDir count]
1563 return [expr {[file exists $file] ? [string trim [read_file $file]] : 0}]
1564 }
1565
1566 set urlSshOk [url_crlf "Status: 200 OK\nContent-Type: text/plain\nContent-Length: 5\n\n"]hello
 
1567
1568 # The reply of "fossil test-http" on the server begins with a Status
1569 # line. The request says that it comes over ssh.
1570 #
1571 url_ssh [list $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x
@@ -1577,11 +1598,12 @@
1577 test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1578 test url-ssh-reply-http-status {$CODE == 0 && $RESULT eq "hello"}
1579 url_ssh [list [url_crlf "STATUS: 200\ncontent-length: 5\n\n"]hello] \
1580 test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x
1581 test url-ssh-reply-upper-case-refused {$CODE == 1}
1582 url_ssh [list [url_crlf "HTTP/1.1 200 OK\nStatus: 200 OK\nContent-Length: 5\n\n"]hello] \
 
1583 test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1584 test url-ssh-reply-both-status-lines {$CODE == 0 && $RESULT eq "hello"}
1585
1586 foreach {urlName urlReply urlMessage} [list \
1587 status-500 "Status: 500 Server Error\n\n" {server says: 500 Server Error} \
@@ -1600,17 +1622,22 @@
1600 url_ssh [list [url_crlf $urlReply]] \
1601 test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x -v
1602 test_match url-ssh-refused-$urlName "$CODE $RESULT" \
1603 "^1 (?:.*\n)*.*$urlMessage"
1604 }
1605 url_ssh [list [url_crlf "Status: 302 Found\nLocation: http://127.0.0.1:1/x\n\n"]] \
 
1606 test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1607 test url-ssh-redirect-quiet {$CODE == 1 && $RESULT eq ""}
1608
1609 # A sync request over ssh has no login card.
1610 #
1611 url_ssh [list [url_crlf "Status: 200 OK\nContent-Type: application/x-fossil-uncompressed\nContent-Length: 2\n\n"]ok] \
 
 
 
 
1612 test-httpmsg ssh://bob:secret@hh/dir/r.fossil --subpath /x \
1613 payload.txt --xfer -v
1614 test url-ssh-no-login-card {$CODE == 0 &&
1615 [string first "13 byte payload" $RESULT] >= 0 &&
1616 [string first "<bob@hh>" $urlSshArgs] >= 0}
@@ -1621,14 +1648,15 @@
1621 #
1622 url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \
1623 --out out.txt
1624 test url-ssh-retry-with-path {$CODE == 0 && [url_ssh_runs] == 2 &&
1625 [read_file out.txt] eq "hello" &&
1626 [string first "First attempt to run fossil on hh using SSH failed" \
1627 $RESULT] >= 0 &&
1628 [string first "Retrying with the PATH= argument" $RESULT] >= 0 &&
1629 [regexp {<hh>\n<fossil>\n<test-http>\n(?:.*\n)*<hh>\n<PATH=[^\n]*>\n<fossil>\n<test-http>} \
 
1630 $urlSshArgs]}
1631 url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1632 test url-ssh-retry-quiet {$CODE == 0 && [url_ssh_runs] == 2 &&
1633 $RESULT eq "hello"}
1634 url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \
@@ -1702,8 +1730,7 @@
1702 unset env(URL_SSH_DIR)
1703 }
1704
1705 ###############################################################################
1706
1707 url_listen_stop
1708 array set env [array get urlSavedEnv]
1709 test_cleanup
1710
--- test/url.test
+++ test/url.test
@@ -17,15 +17,12 @@
17 #
18 # http.test tests whole clones over HTTP and HTTPS. ssh.test tests what
19 # goes on an ssh command line.
20 #
21
22 # The first sections run at every level, and the rest need
23 # -assurance stress.
 
 
 
24 require_no_open_checkout
25
26 if {![loopback_available]} {
27 test_skip "the tests need a TCP connection over the loopback interface"
28 }
@@ -437,10 +434,14 @@
434 # The other network options of a sync command are accepted.
435 #
436 foreach urlOption {--nosync --ipv4 --ipv6 --accept-any-cert} {
437 url_parse_test url-proxy-option$urlOption http://h/x $urlOption {name h}
438 }
439
440 if {[test_assurance] ne "stress"} {
441 test_skip "the tests after the first sections need -assurance stress"
442 }
443
444 ###############################################################################
445 # The name for a clone of a URL.
446
447 foreach {urlName urlText urlExpected} {
@@ -475,56 +476,28 @@
476 test_eq url-basename-none $RESULT ""
477
478 ###############################################################################
479 # The HTTP exchange.
480
 
 
 
481 # Listens on a port on 127.0.0.1 that the system chooses, and returns
482 # the port. Connection N is answered with item N of REPLIES, and the
483 # last item answers every later connection. "PORT" in a reply stands for
484 # the port. Each request is appended to the list urlRequests.
485 #
486 proc url_listen {replies} {
487 set ::urlRequests [list]
488 return [test_listen [list url_receive $replies]]
489 }
490 proc url_receive {replies chan request} {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491 set number [llength $::urlRequests]
492 lappend ::urlRequests $request
493 if {$number >= [llength $replies]} {set number end}
494 set port [lindex [fconfigure $chan -sockname] 2]
495 catch {
496 puts -nonewline $chan [string map [list PORT $port] \
497 [lindex $replies $number]]
498 }
 
 
 
 
 
 
499 }
500
501 # Returns TEXT with each line end changed to CR LF.
502 proc url_crlf {text} {
503 return [string map [list \n \r\n] $text]
@@ -556,11 +529,11 @@
529 # with REPLIES, with the options and further arguments in ARGS.
530 #
531 proc url_httpmsg {replies args} {
532 set port [url_listen $replies]
533 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x {*}$args
534 test_listen_stop
535 }
536
537 # Replies that are accepted. Each row is a name, the reply header, the
538 # reply body and the body that test-httpmsg must print.
539 #
@@ -595,26 +568,38 @@
568 hello hello \
569 content-type-other \
570 "HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: 5\n\n" \
571 hello hello \
572 content-type-debug \
573 [join [list \
574 "HTTP/1.1 200 OK\n" \
575 "Content-Type: application/x-fossil-debug\n" \
576 "Content-Length: 5\n\n"] ""] \
577 hello hello \
578 content-type-uncompressed \
579 [join [list \
580 "HTTP/1.1 200 OK\n" \
581 "Content-Type: application/x-fossil-uncompressed\n" \
582 "Content-Length: 5\n\n"] ""] \
583 hello hello \
584 interim-100 \
585 "HTTP/1.1 100 Continue\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \
586 hello hello \
587 interim-with-headers \
588 [join [list \
589 "HTTP/1.1 103 Early Hints\nLink: </x>\n\nHTTP/1.1 200 OK\n" \
590 "Content-Length: 5\n\n"] ""] \
591 hello hello \
592 interim-twice \
593 [join [list \
594 "HTTP/1.1 100 Continue\n\nHTTP/1.1 102 Processing\n\n" \
595 "HTTP/1.1 200 OK\nContent-Length: 5\n\n"] ""] \
596 hello hello \
597 interim-four-blank-lines \
598 [join [list \
599 "HTTP/1.1 100 Continue\n\n\n\n\n\nHTTP/1.1 200 OK\n" \
600 "Content-Length: 5\n\n"] ""] \
601 hello hello \
602 chunked "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
603 "3\r\nhel\r\n2\r\nlo\r\n0\r\n\r\n" hello \
604 chunked-upper-case "HTTP/1.1 200 OK\nTransfer-Encoding:CHUNKED\n\n" \
605 "A\r\n0123456789\r\n0\r\n\r\n" 0123456789 \
@@ -698,17 +683,23 @@
683 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked, gzip\n\n" \
684 {unsupported transfer-encoding: chunked, gzip} \
685 transfer-encoding-empty "HTTP/1.1 200 OK\nTransfer-Encoding:\n\n" \
686 {unsupported transfer-encoding: } \
687 transfer-encoding-twice \
688 [join [list \
689 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n" \
690 "Transfer-Encoding: chunked\n\n0\n\n"] ""] \
691 {server sent two transfer-encoding headers} \
692 transfer-encoding-and-length \
693 [join [list \
694 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n" \
695 "Content-Length: 5\n\n5\nhello\n0\n\n"] ""] \
696 {reply has both content-length and transfer-encoding} \
697 length-and-transfer-encoding \
698 [join [list \
699 "HTTP/1.1 200 OK\nContent-Length: 0\n" \
700 "Transfer-Encoding: chunked\n\n0\n\n"] ""] \
701 {reply has both content-length and transfer-encoding} \
702 chunk-no-body "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
703 {chunked reply ended without terminator} \
704 chunk-blank-line "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n\n" \
705 {chunked reply ended without terminator} \
@@ -725,11 +716,13 @@
716 {chunked reply: missing or malformed chunk size} \
717 chunk-size-80000000 \
718 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n80000000\nhello\n0\n\n" \
719 {chunked reply: invalid chunk size} \
720 chunk-size-twenty-digits \
721 [join [list \
722 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \
723 "FFFFFFFFFFFFFFFFFFFF\nhello\n0\n\n"] ""] \
724 {chunked reply: invalid chunk size} \
725 chunk-size-then-text \
726 "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5 x\nhello\n0\n\n" \
727 {chunked reply: malformed chunk size line} \
728 chunk-extension-no-name \
@@ -777,11 +770,12 @@
770 {unknown repository: \n} \
771 status-401 "HTTP/1.1 401 Unauthorized\n\n" \
772 {server says: 401 Unauthorized} \
773 ] {
774 url_httpmsg [list [url_crlf $urlReply]] -v
775 test_match url-http-refused-$urlName "$CODE $RESULT" \
776 "^1 (?:.*\n)*.*$urlMessage"
777 url_httpmsg [list [url_crlf $urlReply]]
778 test url-http-refused-quiet-$urlName {$CODE == 1}
779 }
780
781 # A redirect to an ssh: URL with no path is refused.
@@ -804,11 +798,12 @@
798 redirect-to-file "HTTP/1.1 302 Found\nLocation: file:///nosuchdir/r\n\n" \
799 {cannot redirect to file:///nosuchdir/r} \
800 ] {
801 file delete out.txt
802 url_httpmsg [list [url_crlf $urlReply]] --out out.txt
803 test url-http-message-$urlName \
804 {$CODE == 1 && [string first $urlMessage $RESULT] >= 0}
805 url_httpmsg [list [url_crlf $urlReply]]
806 test url-http-message-quiet-$urlName {$CODE == 1 && $RESULT eq ""}
807 }
808
809 # A reply that is shorter than its Content-Length is an error, and only
@@ -818,49 +813,52 @@
813 file delete out.txt
814 url_httpmsg [list $urlShort] --out out.txt
815 test url-http-message-truncated {$CODE == 1 &&
816 [string first "response truncated: got 5 bytes of 6" $RESULT] >= 0}
817 url_httpmsg [list $urlShort]
 
818 test url-http-truncated-bytes {$RESULT eq "hello"}
819
820 # A redirect is followed three times, with the same method and payload,
821 # and the fourth is refused. 301, 302, 307 and 308 are followed. A
822 # Location that ends in /xfer is used without that ending.
823 #
824 foreach urlStatus {301 302 307 308} {
825 url_httpmsg [list \
826 [url_crlf \
827 "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/b\n\n"] \
828 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]]
829 test url-http-redirect-$urlStatus {$CODE == 0 && $RESULT eq "hello" &&
830 [url_request_line 0] eq "GET /x HTTP/1.1" &&
831 [url_request_line 1] eq "GET /b HTTP/1.1"}
832 }
833 write_file payload.txt "payload text\n"
834 url_httpmsg [list \
835 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"] \
836 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/c\n\n"] \
837 [url_crlf \
838 "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer\n\n"] \
839 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] payload.txt
840 test url-http-redirect-three {$CODE == 0 && $RESULT eq "hello" &&
841 [llength $urlRequests] == 4 &&
842 [url_request_line 3] eq "POST /d HTTP/1.1" &&
843 [url_request_body 3] eq "payload text\n"}
844 url_httpmsg [list \
845 [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"]]
846 test url-http-redirect-four {$CODE == 1 && [llength $urlRequests] == 4}
847 url_httpmsg [list \
848 [url_crlf \
849 "HTTP/1.1 302 Found\nX-Other: 1\nLOCATION:http://127.0.0.1:PORT/b\n\n"] \
850 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] -v
851 test url-http-redirect-after-other-header {$CODE == 0 &&
852 [string first "redirect with status 302 to http://127.0.0.1:" $RESULT] >= 0}
853
854 # A Location that ends in /xfer loses only the last one, so that a
855 # repository whose own path ends in /xfer is still found.
856 #
857 url_httpmsg [list \
858 [url_crlf \
859 "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/d/xfer/xfer\n\n"] \
860 [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]]
861 test_eq url-http-redirect-xfer-twice [url_request_line 1] "GET /d/xfer HTTP/1.1"
862
863 # A 401 reply is asked for again twice, and then is an error. Standard
864 # input is not a terminal, so fossil cannot ask for credentials.
@@ -891,11 +889,11 @@
889 [url_request_header 0 Cookie] eq "(none)"}
890
891 set urlPort [url_listen [list $urlOk]]
892 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort
893 test_eq url-request-no-path [url_request_line 0] "GET / HTTP/1.1"
894 test_listen_stop
895
896 url_httpmsg [list $urlOk] payload.txt
897 test url-request-post {[url_request_line 0] eq "POST /x HTTP/1.1" &&
898 [url_request_header 0 Content-Type] eq "text/plain" &&
899 [url_request_header 0 Content-Length] eq "13" &&
@@ -913,11 +911,11 @@
911 fossil_raw -seconds 60 -input "from standard input" \
912 test-httpmsg http://127.0.0.1:$urlPort/x -
913 test url-request-standard-input {
914 [url_request_header 0 Content-Type] eq "application/x-unknown" &&
915 [url_request_body 0] eq "from standard input"}
916 test_listen_stop
917
918 # --compress sends the payload compressed and expects a compressed
919 # reply: four bytes of size and then a zlib stream.
920 #
921 proc url_compress {text} {
@@ -929,16 +927,18 @@
927 }
928 binary scan $bytes I size
929 if {$size != [string length $text]} {return "(wrong size)"}
930 return $text
931 }
932 set urlPort [url_listen [list \
933 [url_crlf \
934 "HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: [string length [url_compress "compressed reply"]]\n\n"][url_compress "compressed reply"]]]
935 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort/x payload.txt \
936 --compress
937 test url-request-compress {$CODE == 0 && $RESULT eq "compressed reply" &&
938 [url_uncompress [url_request_body 0]] eq "payload text\n"}
939 test_listen_stop
940
941 # The reply goes to the file named by --out or by the third argument,
942 # but not by both.
943 #
944 file delete out.txt
@@ -952,13 +952,12 @@
952 url_httpmsg [list $urlOk] payload.txt out.txt --out other.txt
953 test url-request-out-twice {$CODE == 1 && ![file exists out.txt] &&
954 [string first "output file specified twice" $RESULT] >= 0}
955 url_httpmsg [list $urlOk] -v
956 test url-request-verbose {$CODE == 0 &&
957 [holds_strings $RESULT [list "Sending " "Read: \[HTTP/1.1 200 OK\]" \
958 "Reply received: 2 of 2 bytes"]]}
 
959 url_httpmsg [list [url_crlf "HTTP/1.1 200 OK\n\n"]hello] -v
960 test url-request-verbose-no-length {$CODE == 0 && [string first \
961 "Reply received: 5 bytes (w/o content-length)" $RESULT] >= 0}
962
963 foreach urlOption {--ipv4 --no-cert-verify} {
@@ -969,13 +968,15 @@
968 # 127.0.0.1: macOS reaches it through a mapped address, Linux refuses it.
969 url_httpmsg [list $urlOk] --ipv6
970 test url-request-option--ipv6 {($CODE == 0 && $RESULT eq "ok") ||
971 [string first "getaddrinfo() fails" $RESULT] >= 0}
972 fossil_raw test-httpmsg
973 test url-request-usage-none \
974 {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
975 fossil_raw test-httpmsg http://127.0.0.1:1/ a b c
976 test url-request-usage-many \
977 {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]}
978 fossil_raw test-httpmsg file://$urlRepo
979 test url-request-file-needs-subpath {$CODE == 1 && [string first \
980 "the --subpath option is required for file://" $RESULT] >= 0}
981
982 # --httptrace writes each request and reply to a numbered file, and
@@ -1024,20 +1025,24 @@
1025 # message BODY.
1026 proc url_login_card {user secret body} {
1027 set nonce [sha1_text $body]
1028 return "login $user $nonce [sha1_text $nonce$secret]"
1029 }
1030 set urlSyncOk [url_crlf \
1031 [join [list \
1032 "HTTP/1.1 200 OK\n" \
1033 "Content-Type: application/x-fossil-uncompressed\n" \
1034 "Content-Length: 2\n\n"] ""]]ok
1035 set urlCard "[url_login_card bob secret "payload text\n"]\npayload text\n"
1036
1037 # Runs test-httpmsg --xfer for the user and password in USERINFO, which
1038 # is empty or ends with "@", and further options in ARGS.
1039 proc url_xfer {userinfo args} {
1040 set port [url_listen [list $::urlSyncOk]]
1041 fossil_raw -seconds 60 test-httpmsg http://${userinfo}127.0.0.1:$port/x \
1042 payload.txt --xfer {*}$args
1043 test_listen_stop
1044 }
1045
1046 url_xfer bob:secret@
1047 test url-login-password {$CODE == 0 && $RESULT eq "ok" &&
1048 [url_request_header 0 Content-Type] eq "application/x-fossil" &&
@@ -1072,11 +1077,15 @@
1077 # already.
1078 #
1079 fossil sql "SELECT value FROM config WHERE name='project-code'"
1080 set urlProject [string trim $RESULT]
1081 set urlSecret [sha1_text $urlProject/bob/secret]
1082 set urlPullOk [url_crlf \
1083 [join [list \
1084 "HTTP/1.1 200 OK\n" \
1085 "Content-Type: application/x-fossil-uncompressed\n" \
1086 "Content-Length: 41\n\n"] ""]]
1087 append urlPullOk "# timestamp 2026-01-01T00:00:00 errors 0\n"
1088
1089 # Returns 1 if request NUMBER of the last exchange begins with the login
1090 # card for USER and the shared secret SECRET, and 0 otherwise.
1091 proc url_login_ok {number user secret} {
@@ -1091,11 +1100,11 @@
1100 # text, and the options in ARGS, from the URL with USERINFO.
1101 proc url_pull {userinfo args} {
1102 set port [url_listen [list $::urlPullOk]]
1103 fossil_raw -seconds 60 pull http://${userinfo}127.0.0.1:$port/repo \
1104 --httptrace {*}$args
1105 test_listen_stop
1106 file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
1107 return $port
1108 }
1109 url_pull bob:secret@ --once
1110 test url-login-project-code {$CODE == 0 && [url_login_ok 0 bob $urlSecret]}
@@ -1134,20 +1143,24 @@
1143 fossil_raw -seconds 60 test-httpmsg http://bob:[email protected]:$urlPort/x \
1144 --xfer --login-card-header
1145 test url-login-cookie-no-payload {
1146 [url_request_line 0] eq "GET /x HTTP/1.1" &&
1147 [url_request_header 0 Cookie] eq "(none)"}
1148 test_listen_stop
1149
1150 # A sync reply of another content type is an error message from the
1151 # server. It is printed without its HTML tags.
1152 #
1153 proc url_xfer_reply {type body args} {
1154 set port [url_listen [list \
1155 [url_crlf \
1156 [join [list \
1157 "HTTP/1.1 200 OK\nContent-Type: $type\n" \
1158 "Content-Length: [string length $body]\n\n"] ""]]$body]]
1159 fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x \
1160 payload.txt --xfer {*}$args
1161 test_listen_stop
1162 }
1163 url_xfer_reply text/html "<p>no <b>such</b> page</p>" -v
1164 test url-xfer-error-verbose {$CODE == 1 &&
1165 [string first "server sends error: no such page" $RESULT] >= 0}
1166 url_xfer_reply text/html "plain text, no tags" -v
@@ -1157,12 +1170,11 @@
1170 test url-xfer-error-open-tag {$CODE == 1 &&
1171 [string first "server sends error: cut short " $RESULT] >= 0}
1172 file delete out.txt
1173 url_xfer_reply text/html "<p>no such page</p>" --out out.txt
1174 test url-xfer-error-to-file {$CODE == 1 &&
1175 [holds_strings $RESULT {"server sends error" "!no such page"}]}
 
1176 url_xfer_reply text/html "<p>no such page</p>"
1177 test url-xfer-error-quiet {$CODE == 1 &&
1178 [string first "server sends error" $RESULT] < 0}
1179 url_xfer_reply application/x-fossil-debug "debug reply"
1180 test url-xfer-reply-debug {$CODE == 0 && $RESULT eq "debug reply"}
@@ -1175,12 +1187,11 @@
1187 # The file: transport. test-httpmsg sends the request for the path
1188 # given by --subpath to "fossil http" on the repository file.
1189
1190 fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /test-env
1191 test url-file-page {$CODE == 0 &&
1192 [holds_strings $RESULT {<title> "Environment Test"}]}
 
1193 fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /nosuchpage -v
1194 test url-file-not-found {$CODE == 1 &&
1195 [string first "server says: 404 Not Found" $RESULT] >= 0}
1196 fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath / -v
1197 test url-file-redirect {$CODE == 1 &&
@@ -1191,21 +1202,25 @@
1202 ###############################################################################
1203 # Clone, pull and sync against the server of this file.
1204
1205 # Returns the reply header for a sync reply with the body BODY.
1206 proc url_sync_reply {body} {
1207 return [url_crlf \
1208 [join [list \
1209 "HTTP/1.1 200 OK\n" \
1210 "Content-Type: application/x-fossil-uncompressed\n" \
1211 "Content-Length: [string length $body]\n\n"] ""]]$body
1212 }
1213 set urlNotFound [url_crlf "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n"]
1214
1215 # Runs "fossil VERB URL" with the options in ARGS, where "PORT" in URL
1216 # and in ARGS stands for the port of a server that answers with REPLIES.
1217 proc url_sync {verb url replies args} {
1218 set port [url_listen $replies]
1219 set map [list PORT $port]
1220 fossil_raw -seconds 60 $verb [string map $map $url] {*}[string map $map $args]
1221 test_listen_stop
1222 return $port
1223 }
1224
1225 # A proxy gets the whole URL in the request line and its own user and
1226 # password in a Proxy-Authorization header.
@@ -1240,11 +1255,10 @@
1255
1256 # A proxy is an http: or https: URL. With any other value fossil must
1257 # not talk to the repository that the value names in place of the
1258 # remote.
1259 #
 
1260 fossil_raw -seconds 60 clone http://example.invalid/repo proxyclone.fossil \
1261 --proxy file://$urlRepo
1262 test url-sync-proxy-file {$CODE == 1 && ![file exists proxyclone.fossil]}
1263 file delete proxyclone.fossil
1264
@@ -1290,11 +1304,12 @@
1304 # that is redirected with 302 or 307 does not.
1305 #
1306 foreach {urlStatus urlRemembered} {301 1 308 1 302 0 307 0} {
1307 fossil remote off
1308 set urlPort [url_sync pull http://127.0.0.1:PORT/old [list \
1309 [url_crlf \
1310 "HTTP/1.1 $urlStatus Moved\nLocation: http://127.0.0.1:PORT/new\n\n"] \
1311 $urlNotFound]]
1312 fossil remote
1313 test_eq url-sync-redirect-$urlStatus-remembered [string trim $RESULT] \
1314 [expr {$urlRemembered ? "http://127.0.0.1:$urlPort/new" : "off"}]
1315 }
@@ -1324,11 +1339,11 @@
1339 url_parse_test url-sync-saved-password saved {--use-config --show-pw} \
1340 {user bob passwd secret pwConfig sync-pw:saved}
1341 set urlPort [url_listen [list $urlPullOk]]
1342 url_config sync-url:saved 'http://[email protected]:$urlPort/repo'
1343 fossil_raw -seconds 60 pull saved --once --httptrace
1344 test_listen_stop
1345 file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
1346 test url-sync-saved-remote {$CODE == 0 && [url_login_ok 0 bob $urlSecret]}
1347 url_parse_test url-sync-saved-password-hashed saved {--use-config --show-pw} \
1348 [list user bob passwd $urlSecret]
1349 fossil remote delete saved
@@ -1348,11 +1363,11 @@
1363 fossil remote add saved http://bob:[email protected]:1/repo
1364 set urlPort [url_listen [list $urlPullOk]]
1365 url_config sync-url:saved 'http://[email protected]:$urlPort/repo'
1366 url_config parent-project-code 'parentcode'
1367 fossil_raw -seconds 60 pull saved --from-parent-project
1368 test_listen_stop
1369 url_parse_test url-sync-parent-remembered default {--use-parent --show-pw} \
1370 [list name 127.0.0.1 port $urlPort user bob \
1371 passwd [sha1_text parentcode/bob/secret] pwConfig parent-project-pw]
1372 fossil remote
1373 test_eq url-sync-parent-not-default [string trim $RESULT] off
@@ -1360,21 +1375,20 @@
1375 fossil sql "DELETE FROM config WHERE name GLOB 'parent-project-*'"
1376
1377 # A clone that fails with --httptrace prints the last reply. When there
1378 # is no reply it prints none.
1379 #
 
1380 url_sync clone http://127.0.0.1:PORT/repo [list \
1381 [url_sync_reply "error not\\sallowed\\shere\n"]] traceclone.fossil \
1382 --httptrace
1383 test url-sync-clone-httptrace {$CODE == 1 &&
1384 ![file exists traceclone.fossil] &&
1385 [string first "server returned an error - clone aborted" $RESULT] >= 0 &&
1386 [regexp {clone aborted\s+HTTP/1.1 200 OK} $RESULT]}
1387 file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt]
1388 set urlPort [url_listen {}]
1389 test_listen_stop
1390 fossil_raw -seconds 60 clone http://127.0.0.1:$urlPort/repo traceclone.fossil \
1391 --httptrace
1392 test url-sync-clone-httptrace-no-reply {$CODE == 1 &&
1393 ![file exists traceclone.fossil] &&
1394 [string first "cannot connect to host 127.0.0.1:$urlPort" $RESULT] >= 0}
@@ -1394,11 +1408,12 @@
1408 [string first "Transport command failed: " $RESULT] >= 0 &&
1409 [regexp -line {^RUN .*transport-fail.sh '?http://u:p@h:81/x'? } $RESULT]}
1410 fossil_raw pull {http://u:p@[::1]/x} --once \
1411 --transport-command [file join $urlDir transport-fail.sh] --httptrace
1412 test url-transport-url-ipv6 {
1413 [regexp -line {^RUN .*transport-fail.sh '?http://u:p@\[::1\]/x'? } \
1414 $RESULT]}
1415 fossil_raw pull file://$urlRepo --once \
1416 --transport-command [file join $urlDir transport-fail.sh] --httptrace
1417 test url-transport-url-file {[regexp -line \
1418 "^RUN .*transport-fail.sh '?file://$urlRepo'? " $RESULT]}
1419 }
@@ -1406,26 +1421,31 @@
1421 ###############################################################################
1422 # The sync button of the /xfersetup page syncs with the saved remote. A
1423 # remote with a user and no saved password gets a message, not a login
1424 # card.
1425
1426 write_file xfersetup.txt [url_crlf \
1427 [join [list \
1428 "POST /xfersetup HTTP/1.0\nHost: localhost\n" \
1429 "Referer: http://localhost/xfersetup\n" \
1430 "Content-Type: application/x-www-form-urlencoded\n" \
1431 "Content-Length: 6\n\nsync=1"] ""]]
1432 set urlPort [url_listen [list $urlPullOk]]
1433 url_config last-sync-url 'http://[email protected]:$urlPort/repo'
1434 url_config last-sync-pw obscure('secret')
1435 fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \
1436 --localauth
1437 test_listen_stop
1438 test url-web-sync {[string first "HTTP/1.0 200 OK" $RESULT] == 0 &&
1439 [llength $urlRequests] == 1 &&
1440 [string first "Sync done" $RESULT] >= 0}
1441 set urlPort [url_listen [list $urlPullOk]]
1442 fossil sql "DELETE FROM config WHERE name='last-sync-pw'"
1443 url_config last-sync-url 'http://[email protected]:$urlPort/repo'
1444 fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \
1445 --localauth
1446 test_listen_stop
1447 test url-web-sync-no-password {[string first "HTTP/1.0 200 OK" $RESULT] == 0 &&
1448 [string first "incorrect or missing password for user bob" $RESULT] >= 0}
1449 fossil sql "DELETE FROM config WHERE name GLOB 'last-sync-*'"
1450
1451 ###############################################################################
@@ -1561,11 +1581,12 @@
1581 proc url_ssh_runs {} {
1582 set file [file join $::urlSshDir count]
1583 return [expr {[file exists $file] ? [string trim [read_file $file]] : 0}]
1584 }
1585
1586 set urlSshOk [url_crlf \
1587 "Status: 200 OK\nContent-Type: text/plain\nContent-Length: 5\n\n"]hello
1588
1589 # The reply of "fossil test-http" on the server begins with a Status
1590 # line. The request says that it comes over ssh.
1591 #
1592 url_ssh [list $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x
@@ -1577,11 +1598,12 @@
1598 test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1599 test url-ssh-reply-http-status {$CODE == 0 && $RESULT eq "hello"}
1600 url_ssh [list [url_crlf "STATUS: 200\ncontent-length: 5\n\n"]hello] \
1601 test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x
1602 test url-ssh-reply-upper-case-refused {$CODE == 1}
1603 url_ssh [list [url_crlf \
1604 "HTTP/1.1 200 OK\nStatus: 200 OK\nContent-Length: 5\n\n"]hello] \
1605 test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1606 test url-ssh-reply-both-status-lines {$CODE == 0 && $RESULT eq "hello"}
1607
1608 foreach {urlName urlReply urlMessage} [list \
1609 status-500 "Status: 500 Server Error\n\n" {server says: 500 Server Error} \
@@ -1600,17 +1622,22 @@
1622 url_ssh [list [url_crlf $urlReply]] \
1623 test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x -v
1624 test_match url-ssh-refused-$urlName "$CODE $RESULT" \
1625 "^1 (?:.*\n)*.*$urlMessage"
1626 }
1627 url_ssh [list [url_crlf \
1628 "Status: 302 Found\nLocation: http://127.0.0.1:1/x\n\n"]] \
1629 test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1630 test url-ssh-redirect-quiet {$CODE == 1 && $RESULT eq ""}
1631
1632 # A sync request over ssh has no login card.
1633 #
1634 url_ssh [list [url_crlf \
1635 [join [list \
1636 "Status: 200 OK\n" \
1637 "Content-Type: application/x-fossil-uncompressed\n" \
1638 "Content-Length: 2\n\n"] ""]]ok] \
1639 test-httpmsg ssh://bob:secret@hh/dir/r.fossil --subpath /x \
1640 payload.txt --xfer -v
1641 test url-ssh-no-login-card {$CODE == 0 &&
1642 [string first "13 byte payload" $RESULT] >= 0 &&
1643 [string first "<bob@hh>" $urlSshArgs] >= 0}
@@ -1621,14 +1648,15 @@
1648 #
1649 url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \
1650 --out out.txt
1651 test url-ssh-retry-with-path {$CODE == 0 && [url_ssh_runs] == 2 &&
1652 [read_file out.txt] eq "hello" &&
1653 [holds_strings $RESULT \
1654 {"First attempt to run fossil on hh using SSH failed"
1655 "Retrying with the PATH= argument"}] &&
1656 [regexp \
1657 {<hh>\n<fossil>\n<test-http>\n(?:.*\n)*<hh>\n<PATH=[^\n]*>\n<fossil>\n<test-http>} \
1658 $urlSshArgs]}
1659 url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x
1660 test url-ssh-retry-quiet {$CODE == 0 && [url_ssh_runs] == 2 &&
1661 $RESULT eq "hello"}
1662 url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \
@@ -1702,8 +1730,7 @@
1730 unset env(URL_SSH_DIR)
1731 }
1732
1733 ###############################################################################
1734
 
1735 array set env [array get urlSavedEnv]
1736 test_cleanup
1737
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -7,15 +7,12 @@
77
# timestamp, which ends the sync.
88
#
99
# xfer-server.test tests the server side.
1010
#
1111
12
-# These tests run only in a long pass: -assurance stress.
13
-if {[test_assurance] ne "stress"} {
14
- test_skip "runs only with -assurance stress"
15
-}
16
-
12
+# The first sections run at every level, and the rest need
13
+# -assurance stress.
1714
require_no_open_checkout
1815
1916
if {$::tcl_platform(platform) eq "windows"} {
2017
test_skip "the stand-in for a server is a shell script"
2118
}
@@ -38,21 +35,11 @@
3835
# Run "fossil VERB" against the stand-in, which answers request N with
3936
# item N of the list REPLIES. Further arguments are options for the
4037
# command. Sets xferclientCode to the exit status, or to "crash", and
4138
# xferclientOut to what fossil printed.
4239
proc xferclient_sync {verb replies args} {
43
- global xferclientDir xferclientWire xferclientCode xferclientOut
44
- file delete {*}[glob -nocomplain -directory $xferclientDir \
45
- reply.* request.* count]
46
- set number 0
47
- foreach reply $replies {
48
- write_file [file join $xferclientDir reply.[incr number]] $reply
49
- }
50
- fossil_raw $verb http://localhost/x --once \
51
- --transport-command $xferclientWire {*}$args
52
- set xferclientCode $::CODE
53
- set xferclientOut $::RESULT
40
+ xferclient_sync_url $verb http://localhost/x $replies {*}$args
5441
}
5542
5643
# Like xferclient_sync, for the server at URL.
5744
proc xferclient_sync_url {verb url replies args} {
5845
global xferclientDir xferclientWire xferclientCode xferclientOut
@@ -201,10 +188,14 @@
201188
&& [regexp -line "^pull \\S+ $xferclientParentCode\$" \
202189
[xferclient_request 1]]}
203190
fossil sql "REPLACE INTO config(name,value,mtime)
204191
VALUES('project-code','$xferclientOwnCode',now())"
205192
fossil sql "DELETE FROM config WHERE name='parent-project-code'"
193
+
194
+if {[test_assurance] ne "stress"} {
195
+ test_skip "the tests after the first sections need -assurance stress"
196
+}
206197
207198
###############################################################################
208199
# igot and gimme. What the client asks for, or sends, shows in its
209200
# second request.
210201
@@ -335,21 +326,12 @@
335326
3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532
336327
xferclient_expect uvfile-refused-in-pull pull \
337328
"uvfile note.txt 2000000001 $xferclientAbcHash 3 0\nabc\n" 1 {} \
338329
"unknown command"
339330
fossil unversioned cat note.txt
340
-test xfer-client-uvfile-in-pull-changes-nothing \
341
- {[string trim $RESULT] eq "local note"}
342
-xferclient_expect uvigot-bad-mtime pull \
343
- "uvigot note.txt notint $xferclientUvHash 3\n" 1 {} "unknown command"
344
-xferclient_expect uvigot-bad-size pull \
345
- "uvigot note.txt 1700000000 $xferclientUvHash notint\n" 1 {} \
346
- "unknown command"
347
-xferclient_expect uvigot-bad-hash pull \
348
- "uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
349
-xferclient_expect uvigot-bad-name pull \
350
- "uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
331
+test_eq xfer-client-uvfile-in-pull-changes-nothing [string trim $RESULT] \
332
+ "local note"
351333
352334
###############################################################################
353335
# Each card that has a fixed number of words, and each word that selects a
354336
# card, decides alone whether the card is acted on. A card of the wrong
355337
# number of words, or with a first word that has the length of a card name
@@ -426,11 +408,10 @@
426408
xferclient_run pull $xferclientCard --share-links
427409
fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'"
428410
test_eq xfer-client-mcdc-link-$xferclientName \
429411
"$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
430412
}
431
-fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
432413
433414
###############################################################################
434415
# A "private" card makes the next file private. A client that does not sync
435416
# private content ignores that file, whatever its content; one that does
436417
# keeps it and marks it private.
@@ -724,57 +705,38 @@
724705
test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc
725706
xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
726707
"clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"]
727708
test xfer-client-mcdc-clone-stops-when-nothing-arrives \
728709
{$xferclientCode == 0 && [xferclient_requests] == 2}
729
-file delete clone.fossil
730710
731711
###############################################################################
732712
# What a sync with -v says at its end about the server. A server that
733713
# could not be reached is named as the URL names it, with no address. The
734714
# URLs here have no host; the one for ssh is given standin/log-args.sh as
735715
# its ssh command, which exits at once.
736716
737717
fossil_raw pull -v --once --proxy off http:///x
738
-test xfer-client-mcdc-remote-no-host {$CODE == 1
739
- && [string first "Pull done," $RESULT] >= 0
740
- && [string first "remote: \n" $RESULT] >= 0}
718
+test xfer-client-mcdc-remote-no-host {$CODE == 1 &&
719
+ [holds_strings $RESULT [list "Pull done," "remote: \n"]]}
741720
set xferclientSsh \
742721
[test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]]
743722
set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt]
744723
fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x
745
-test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1
746
- && [file exists $::env(ARGS_LOG)]
747
- && [string first "Pull done," $RESULT] >= 0
748
- && [string first "remote: \n" $RESULT] >= 0}
724
+test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1 &&
725
+ [file exists $::env(ARGS_LOG)] &&
726
+ [holds_strings $RESULT [list "Pull done," "remote: \n"]]}
749727
unset ::env(ARGS_LOG)
750728
751729
###############################################################################
752730
# What shows only when the client speaks HTTP. The server is made here: it
753731
# answers request N with item N of the list xferclientHttpReplies, or with
754732
# a bare timestamp where that is empty, and keeps the header and the cards
755733
# of each request in the list xferclientHttpRequests.
756734
757
-proc xferclient_http_accept {chan address port} {
758
- fconfigure $chan -translation binary -blocking 0
759
- set ::xferclientHttpBuf($chan) ""
760
- fileevent $chan readable [list xferclient_http_read $chan]
761
-}
762
-proc xferclient_http_read {chan} {
763
- global xferclientHttpBuf xferclientHttpRequests xferclientHttpReplies
764
- append xferclientHttpBuf($chan) [read $chan]
765
- set request $xferclientHttpBuf($chan)
735
+proc xferclient_http_read {chan request} {
736
+ global xferclientHttpRequests xferclientHttpReplies
766737
set end [string first "\r\n\r\n" $request]
767
- set length 0
768
- regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
769
- if {![eof $chan] &&
770
- ($end < 0 || [string length $request] < $end + 4 + $length)} {
771
- return
772
- }
773
- unset xferclientHttpBuf($chan)
774
- fileevent $chan readable {}
775
- fconfigure $chan -blocking 1
776738
# The cards follow four bytes of size when they are compressed.
777739
set header [string range $request 0 $end+1]
778740
set cards [string range $request $end+4 end]
779741
catch {set cards [zlib decompress [string range $cards 4 end]]}
780742
set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]]
@@ -802,13 +764,11 @@
802764
set xferclientCode $::CODE
803765
set xferclientOut $::RESULT
804766
}
805767
806768
if {[loopback_available]} {
807
- set xferclientHttpServer \
808
- [socket -server xferclient_http_accept -myaddr 127.0.0.1 0]
809
- set xferclientHttpPort [lindex [fconfigure $xferclientHttpServer -sockname] 2]
769
+ set xferclientHttpPort [test_listen xferclient_http_read]
810770
811771
# The login card goes in front of the cards of a request. Once the
812772
# server has said that it is of version 2.27 or later and was built at or
813773
# after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The
814774
# second request shows where the client puts it.
@@ -867,14 +827,12 @@
867827
test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0
868828
&& [string trim $RESULT] == 1
869829
&& [llength $xferclientHttpRequests] == 2
870830
&& [holds_strings $xferclientOut $xferclientSaid]}
871831
}
872
- fossil remote off
873
- fossil settings autosync off
874
- close $xferclientHttpServer
832
+ test_listen_stop
875833
}
876834
877835
###############################################################################
878836
879837
unset ::env(TRANSPORT_DIR)
880838
test_cleanup
881839
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -7,15 +7,12 @@
7 # timestamp, which ends the sync.
8 #
9 # xfer-server.test tests the server side.
10 #
11
12 # These tests run only in a long pass: -assurance stress.
13 if {[test_assurance] ne "stress"} {
14 test_skip "runs only with -assurance stress"
15 }
16
17 require_no_open_checkout
18
19 if {$::tcl_platform(platform) eq "windows"} {
20 test_skip "the stand-in for a server is a shell script"
21 }
@@ -38,21 +35,11 @@
38 # Run "fossil VERB" against the stand-in, which answers request N with
39 # item N of the list REPLIES. Further arguments are options for the
40 # command. Sets xferclientCode to the exit status, or to "crash", and
41 # xferclientOut to what fossil printed.
42 proc xferclient_sync {verb replies args} {
43 global xferclientDir xferclientWire xferclientCode xferclientOut
44 file delete {*}[glob -nocomplain -directory $xferclientDir \
45 reply.* request.* count]
46 set number 0
47 foreach reply $replies {
48 write_file [file join $xferclientDir reply.[incr number]] $reply
49 }
50 fossil_raw $verb http://localhost/x --once \
51 --transport-command $xferclientWire {*}$args
52 set xferclientCode $::CODE
53 set xferclientOut $::RESULT
54 }
55
56 # Like xferclient_sync, for the server at URL.
57 proc xferclient_sync_url {verb url replies args} {
58 global xferclientDir xferclientWire xferclientCode xferclientOut
@@ -201,10 +188,14 @@
201 && [regexp -line "^pull \\S+ $xferclientParentCode\$" \
202 [xferclient_request 1]]}
203 fossil sql "REPLACE INTO config(name,value,mtime)
204 VALUES('project-code','$xferclientOwnCode',now())"
205 fossil sql "DELETE FROM config WHERE name='parent-project-code'"
 
 
 
 
206
207 ###############################################################################
208 # igot and gimme. What the client asks for, or sends, shows in its
209 # second request.
210
@@ -335,21 +326,12 @@
335 3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532
336 xferclient_expect uvfile-refused-in-pull pull \
337 "uvfile note.txt 2000000001 $xferclientAbcHash 3 0\nabc\n" 1 {} \
338 "unknown command"
339 fossil unversioned cat note.txt
340 test xfer-client-uvfile-in-pull-changes-nothing \
341 {[string trim $RESULT] eq "local note"}
342 xferclient_expect uvigot-bad-mtime pull \
343 "uvigot note.txt notint $xferclientUvHash 3\n" 1 {} "unknown command"
344 xferclient_expect uvigot-bad-size pull \
345 "uvigot note.txt 1700000000 $xferclientUvHash notint\n" 1 {} \
346 "unknown command"
347 xferclient_expect uvigot-bad-hash pull \
348 "uvigot note.txt 1700000000 nothash 3\n" 1 {} "unknown command"
349 xferclient_expect uvigot-bad-name pull \
350 "uvigot ../x 1700000000 $xferclientUvHash 3\n" 1 {} "unknown command"
351
352 ###############################################################################
353 # Each card that has a fixed number of words, and each word that selects a
354 # card, decides alone whether the card is acted on. A card of the wrong
355 # number of words, or with a first word that has the length of a card name
@@ -426,11 +408,10 @@
426 xferclient_run pull $xferclientCard --share-links
427 fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'"
428 test_eq xfer-client-mcdc-link-$xferclientName \
429 "$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
430 }
431 fossil sql "DELETE FROM config WHERE name LIKE 'link:%'"
432
433 ###############################################################################
434 # A "private" card makes the next file private. A client that does not sync
435 # private content ignores that file, whatever its content; one that does
436 # keeps it and marks it private.
@@ -724,57 +705,38 @@
724 test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc
725 xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
726 "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"]
727 test xfer-client-mcdc-clone-stops-when-nothing-arrives \
728 {$xferclientCode == 0 && [xferclient_requests] == 2}
729 file delete clone.fossil
730
731 ###############################################################################
732 # What a sync with -v says at its end about the server. A server that
733 # could not be reached is named as the URL names it, with no address. The
734 # URLs here have no host; the one for ssh is given standin/log-args.sh as
735 # its ssh command, which exits at once.
736
737 fossil_raw pull -v --once --proxy off http:///x
738 test xfer-client-mcdc-remote-no-host {$CODE == 1
739 && [string first "Pull done," $RESULT] >= 0
740 && [string first "remote: \n" $RESULT] >= 0}
741 set xferclientSsh \
742 [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]]
743 set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt]
744 fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x
745 test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1
746 && [file exists $::env(ARGS_LOG)]
747 && [string first "Pull done," $RESULT] >= 0
748 && [string first "remote: \n" $RESULT] >= 0}
749 unset ::env(ARGS_LOG)
750
751 ###############################################################################
752 # What shows only when the client speaks HTTP. The server is made here: it
753 # answers request N with item N of the list xferclientHttpReplies, or with
754 # a bare timestamp where that is empty, and keeps the header and the cards
755 # of each request in the list xferclientHttpRequests.
756
757 proc xferclient_http_accept {chan address port} {
758 fconfigure $chan -translation binary -blocking 0
759 set ::xferclientHttpBuf($chan) ""
760 fileevent $chan readable [list xferclient_http_read $chan]
761 }
762 proc xferclient_http_read {chan} {
763 global xferclientHttpBuf xferclientHttpRequests xferclientHttpReplies
764 append xferclientHttpBuf($chan) [read $chan]
765 set request $xferclientHttpBuf($chan)
766 set end [string first "\r\n\r\n" $request]
767 set length 0
768 regexp -nocase -line {^content-length:\s*(\d+)} $request -> length
769 if {![eof $chan] &&
770 ($end < 0 || [string length $request] < $end + 4 + $length)} {
771 return
772 }
773 unset xferclientHttpBuf($chan)
774 fileevent $chan readable {}
775 fconfigure $chan -blocking 1
776 # The cards follow four bytes of size when they are compressed.
777 set header [string range $request 0 $end+1]
778 set cards [string range $request $end+4 end]
779 catch {set cards [zlib decompress [string range $cards 4 end]]}
780 set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]]
@@ -802,13 +764,11 @@
802 set xferclientCode $::CODE
803 set xferclientOut $::RESULT
804 }
805
806 if {[loopback_available]} {
807 set xferclientHttpServer \
808 [socket -server xferclient_http_accept -myaddr 127.0.0.1 0]
809 set xferclientHttpPort [lindex [fconfigure $xferclientHttpServer -sockname] 2]
810
811 # The login card goes in front of the cards of a request. Once the
812 # server has said that it is of version 2.27 or later and was built at or
813 # after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The
814 # second request shows where the client puts it.
@@ -867,14 +827,12 @@
867 test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0
868 && [string trim $RESULT] == 1
869 && [llength $xferclientHttpRequests] == 2
870 && [holds_strings $xferclientOut $xferclientSaid]}
871 }
872 fossil remote off
873 fossil settings autosync off
874 close $xferclientHttpServer
875 }
876
877 ###############################################################################
878
879 unset ::env(TRANSPORT_DIR)
880 test_cleanup
881
--- test/xfer-client.test
+++ test/xfer-client.test
@@ -7,15 +7,12 @@
7 # timestamp, which ends the sync.
8 #
9 # xfer-server.test tests the server side.
10 #
11
12 # The first sections run at every level, and the rest need
13 # -assurance stress.
 
 
 
14 require_no_open_checkout
15
16 if {$::tcl_platform(platform) eq "windows"} {
17 test_skip "the stand-in for a server is a shell script"
18 }
@@ -38,21 +35,11 @@
35 # Run "fossil VERB" against the stand-in, which answers request N with
36 # item N of the list REPLIES. Further arguments are options for the
37 # command. Sets xferclientCode to the exit status, or to "crash", and
38 # xferclientOut to what fossil printed.
39 proc xferclient_sync {verb replies args} {
40 xferclient_sync_url $verb http://localhost/x $replies {*}$args
 
 
 
 
 
 
 
 
 
 
41 }
42
43 # Like xferclient_sync, for the server at URL.
44 proc xferclient_sync_url {verb url replies args} {
45 global xferclientDir xferclientWire xferclientCode xferclientOut
@@ -201,10 +188,14 @@
188 && [regexp -line "^pull \\S+ $xferclientParentCode\$" \
189 [xferclient_request 1]]}
190 fossil sql "REPLACE INTO config(name,value,mtime)
191 VALUES('project-code','$xferclientOwnCode',now())"
192 fossil sql "DELETE FROM config WHERE name='parent-project-code'"
193
194 if {[test_assurance] ne "stress"} {
195 test_skip "the tests after the first sections need -assurance stress"
196 }
197
198 ###############################################################################
199 # igot and gimme. What the client asks for, or sends, shows in its
200 # second request.
201
@@ -335,21 +326,12 @@
326 3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532
327 xferclient_expect uvfile-refused-in-pull pull \
328 "uvfile note.txt 2000000001 $xferclientAbcHash 3 0\nabc\n" 1 {} \
329 "unknown command"
330 fossil unversioned cat note.txt
331 test_eq xfer-client-uvfile-in-pull-changes-nothing [string trim $RESULT] \
332 "local note"
 
 
 
 
 
 
 
 
 
333
334 ###############################################################################
335 # Each card that has a fixed number of words, and each word that selects a
336 # card, decides alone whether the card is acted on. A card of the wrong
337 # number of words, or with a first word that has the length of a card name
@@ -426,11 +408,10 @@
408 xferclient_run pull $xferclientCard --share-links
409 fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'"
410 test_eq xfer-client-mcdc-link-$xferclientName \
411 "$xferclientCode [string trim $RESULT]" "0 $xferclientKept"
412 }
 
413
414 ###############################################################################
415 # A "private" card makes the next file private. A client that does not sync
416 # private content ignores that file, whatever its content; one that does
417 # keeps it and marks it private.
@@ -724,57 +705,38 @@
705 test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc
706 xferclient_clone [list "clone_seqno 2\n$xferclientPush" \
707 "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"]
708 test xfer-client-mcdc-clone-stops-when-nothing-arrives \
709 {$xferclientCode == 0 && [xferclient_requests] == 2}
 
710
711 ###############################################################################
712 # What a sync with -v says at its end about the server. A server that
713 # could not be reached is named as the URL names it, with no address. The
714 # URLs here have no host; the one for ssh is given standin/log-args.sh as
715 # its ssh command, which exits at once.
716
717 fossil_raw pull -v --once --proxy off http:///x
718 test xfer-client-mcdc-remote-no-host {$CODE == 1 &&
719 [holds_strings $RESULT [list "Pull done," "remote: \n"]]}
 
720 set xferclientSsh \
721 [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]]
722 set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt]
723 fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x
724 test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1 &&
725 [file exists $::env(ARGS_LOG)] &&
726 [holds_strings $RESULT [list "Pull done," "remote: \n"]]}
 
727 unset ::env(ARGS_LOG)
728
729 ###############################################################################
730 # What shows only when the client speaks HTTP. The server is made here: it
731 # answers request N with item N of the list xferclientHttpReplies, or with
732 # a bare timestamp where that is empty, and keeps the header and the cards
733 # of each request in the list xferclientHttpRequests.
734
735 proc xferclient_http_read {chan request} {
736 global xferclientHttpRequests xferclientHttpReplies
 
 
 
 
 
 
 
737 set end [string first "\r\n\r\n" $request]
 
 
 
 
 
 
 
 
 
738 # The cards follow four bytes of size when they are compressed.
739 set header [string range $request 0 $end+1]
740 set cards [string range $request $end+4 end]
741 catch {set cards [zlib decompress [string range $cards 4 end]]}
742 set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]]
@@ -802,13 +764,11 @@
764 set xferclientCode $::CODE
765 set xferclientOut $::RESULT
766 }
767
768 if {[loopback_available]} {
769 set xferclientHttpPort [test_listen xferclient_http_read]
 
 
770
771 # The login card goes in front of the cards of a request. Once the
772 # server has said that it is of version 2.27 or later and was built at or
773 # after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The
774 # second request shows where the client puts it.
@@ -867,14 +827,12 @@
827 test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0
828 && [string trim $RESULT] == 1
829 && [llength $xferclientHttpRequests] == 2
830 && [holds_strings $xferclientOut $xferclientSaid]}
831 }
832 test_listen_stop
 
 
833 }
834
835 ###############################################################################
836
837 unset ::env(TRANSPORT_DIR)
838 test_cleanup
839
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -7,15 +7,12 @@
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
#
1111
12
-# These tests run only in a long pass: -assurance stress.
13
-if {[test_assurance] ne "stress"} {
14
- test_skip "runs only with -assurance stress"
15
-}
16
-
12
+# The first sections run at every level, and the rest need
13
+# -assurance stress.
1714
require_no_open_checkout
1815
1916
test_setup
2017
2118
write_file a.txt "hello world\n"
@@ -307,10 +304,14 @@
307304
"$xferserverLogin$xferserverPush$xferserverCard" \
308305
"!Database error" $xferserverWant
309306
}
310307
test_eq xfer-server-hash-zero-byte-nothing-stored \
311308
[xferserver_count "blob WHERE length(uuid)<40"] 0
309
+
310
+if {[test_assurance] ne "stress"} {
311
+ test_skip "the tests after the first sections need -assurance stress"
312
+}
312313
313314
# Clone, in each version of the protocol. A login card to test-xfer does
314315
# not grant the Clone permission, so "nobody" is given it and these
315316
# messages have no login card.
316317
xferserver_caps "g"
@@ -427,11 +428,12 @@
427428
xferserver_set gitpush:[email protected]:someone/other.git "{}"
428429
xferserver_send "${xferserverPull}pragma req-links\n"
429430
test xfer-server-read-req-links-git-address \
430431
{$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
431432
test xfer-server-read-req-links-git-https \
432
- {[string match "*pragma link https://git.example.org/someone/mirror.git*" $RESULT]}
433
+ {[string match "*pragma link https://git.example.org/someone/mirror.git*" \
434
+ $RESULT]}
433435
test xfer-server-read-req-links-git-other-left-out \
434436
{![string match "*other.git*" $RESULT]}
435437
xferserver_unset gitpush:*
436438
437439
# The address configuration is given only to a client that may read
@@ -528,12 +530,10 @@
528530
xferserver_enter cards
529531
530532
set xferserverCardsContent "hello world\n"
531533
set xferserverCardsSize [string length $xferserverCardsContent]
532534
write_file a.txt $xferserverCardsContent
533
-fossil add a.txt
534
-fossil commit -m one --no-warnings
535535
fossil sha3sum a.txt
536536
set xferserverCardsHash [lindex $RESULT 0]
537537
538538
fossil init tgt.fossil -A tester
539539
fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'"
@@ -578,18 +578,20 @@
578578
"file $xferserverCardsHash zz\
579579
$xferserverCardsSize\n$xferserverCardsContent" \
580580
size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \
581581
size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \
582582
size-at-end "file $xferserverCardsHash 5\n" \
583
- size-with-nul "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \
583
+ size-with-nul \
584
+ "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \
584585
content-wrong-hash \
585586
"file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \
586587
cfile-too-few "cfile $xferserverCardsHash\n" \
587588
cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \
588589
uvfile-too-few "uvfile note.txt\n" \
589590
uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \
590
- uvfile-mtime-nul "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \
591
+ uvfile-mtime-nul \
592
+ "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \
591593
uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \
592594
uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \
593595
uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \
594596
uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \
595597
uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \
@@ -598,27 +600,10 @@
598600
test xfer-cards-reject-$xferserverCardsName \
599601
{$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 &&
600602
$xferserverCardsStored == 0}
601603
}
602604
603
-# A client that does not send a version is treated as older than 2.0 and
604
-# cannot be sent a SHA3 hash. When such a client asks for an unversioned
605
-# file the server answers with an error; a current client gets the file.
606
-write_file note.txt "hi\n"
607
-fossil unversioned add note.txt -R tgt.fossil --user tester
608
-set xferserverCardsUvgimme \
609
- "login tester 0 0\npull x $xferserverCardsPcode\nuvgimme note.txt\n"
610
-write_file uvgimme.txt $xferserverCardsUvgimme
611
-fossil_raw test-xfer -R tgt.fossil uvgimme.txt
612
-test xfer-cards-uvgimme-old-client \
613
- {$CODE == 0
614
- && [holds_strings $RESULT [list {or\slater\srequired} "!uvfile note.txt"]]}
615
-write_file uvgimme.txt $CLIENT_VERSION_CARD$xferserverCardsUvgimme
616
-fossil_raw test-xfer -R tgt.fossil uvgimme.txt
617
-test xfer-cards-uvgimme-current-client \
618
- {$CODE == 0 && [string first "uvfile note.txt" $RESULT] >= 0}
619
-
620605
fossil sql -R tgt.fossil \
621606
"INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)"
622607
xferserver_cards_push "file $xferserverCardsHash\
623608
$xferserverCardsSize\n$xferserverCardsContent"
624609
test xfer-cards-reject-shunned \
@@ -630,23 +615,17 @@
630615
# More cards sent to the server side of the sync protocol through
631616
# "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme"
632617
# and "uvgimme" that xfer-cards.test and xfer-server.test do not send.
633618
# Each has a stated effect on the server's repository or on the reply,
634619
# and none may crash.
635
-#
636
-# The messages carry no login card, so they run with the permissions of
637
-# the user "nobody", which these tests set.
638
-#
639
-
640620
641621
xferserver_enter edge
642622
643623
# The answer of one SQL statement on the server, trimmed.
644624
#
645625
proc xferserver_sql {sql} {
646
- fossil sql -R srv.fossil $sql
647
- return [string trim $::RESULT]
626
+ return [fossil_sql $sql srv.fossil]
648627
}
649628
650629
# Send the cards BODY to the server after a client-version card and a
651630
# card of KIND, which is "push" or "pull". RESULT is the reply, as
652631
# bytes. xferserverEdgeErrors is the number of errors that the reply reports,
@@ -658,18 +637,10 @@
658637
fossil_raw test-xfer -R srv.fossil msg.txt
659638
set xferserverEdgeErrors -1
660639
regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors
661640
}
662641
663
-# The hash that Fossil gives TEXT.
664
-#
665
-proc xferserver_hash {text} {
666
- write_file hash-me.txt $text
667
- fossil sha3sum hash-me.txt
668
- return [lindex $::RESULT 0]
669
-}
670
-
671642
# Content as a "cfile" card carries it: the size, then the zlib stream.
672643
#
673644
proc xferserver_compress {text} {
674645
return [binary format I [string length $text]][zlib compress $text]
675646
}
@@ -716,11 +687,11 @@
716687
717688
###############################################################################
718689
# "file" cards.
719690
720691
set xferserverEdgeNew "content that the server does not have yet\n"
721
-set xferserverEdgeNewHash [xferserver_hash $xferserverEdgeNew]
692
+set xferserverEdgeNewHash [sha3_text $xferserverEdgeNew]
722693
set xferserverEdgeLen [string length $xferserverEdgeNew]
723694
724695
foreach {xferserverEdgeName xferserverEdgeCard} [list \
725696
too-many-tokens \
726697
"file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\
@@ -799,11 +770,11 @@
799770
[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
800771
test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0}
801772
test xfer-edge-cfile-wrong-hash-not-stored \
802773
{![xferserver_holds $xferserverEdgeAbsent]}
803774
set xferserverEdgeSized "content with the wrong size on its card\n"
804
-set xferserverEdgeSizedHash [xferserver_hash $xferserverEdgeSized]
775
+set xferserverEdgeSizedHash [sha3_text $xferserverEdgeSized]
805776
set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized]
806777
xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\
807778
[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
808779
test xfer-edge-cfile-wrong-size \
809780
{$CODE == 0 && $xferserverEdgeErrors > 0 &&
@@ -814,11 +785,11 @@
814785
{$CODE == 0 && $xferserverEdgeErrors > 0 &&
815786
![xferserver_holds $xferserverEdgeAbsent]}
816787
817788
# A shunned artifact is not stored.
818789
set xferserverEdgeShun "content that the server has shunned\n"
819
-set xferserverEdgeShunHash [xferserver_hash $xferserverEdgeShun]
790
+set xferserverEdgeShunHash [sha3_text $xferserverEdgeShun]
820791
xferserver_sql "INSERT INTO shun(uuid,mtime)\
821792
VALUES('$xferserverEdgeShunHash',0)"
822793
set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun]
823794
xferserver_edge_send push "cfile $xferserverEdgeShunHash\
824795
[string length $xferserverEdgeShun]\
@@ -831,11 +802,11 @@
831802
# does not make content of the size on the card is refused.
832803
set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4]
833804
write_file delta-src.txt $xferserverEdgeVersion(1)
834805
write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n"
835806
fossil test-delta-create delta-src.txt delta-tgt.txt delta.out
836
-set xferserverEdgeTgtHash [xferserver_hash [read_file delta-tgt.txt]]
807
+set xferserverEdgeTgtHash [sha3_text [read_file delta-tgt.txt]]
837808
set xferserverEdgeZ [xferserver_compress [read_file delta.out]]
838809
xferserver_edge_send push "cfile $xferserverEdgeTgtHash\
839810
$xferserverEdgeAbsent2 7777\
840811
[string length $xferserverEdgeZ]\n$xferserverEdgeZ"
841812
test xfer-edge-cfile-dangling-delta-wrong-size \
@@ -867,16 +838,16 @@
867838
868839
# A compressed delta whose source the server has is applied and checked.
869840
# One that does not apply, and one that makes content with another hash
870841
# than the card gives, are refused; one that makes the content that the
871842
# card names is stored.
872
-set xferserverEdgeSrcHash [xferserver_hash $xferserverEdgeVersion(1)]
843
+set xferserverEdgeSrcHash [sha3_text $xferserverEdgeVersion(1)]
873844
test xfer-edge-cfile-delta-setup-source-held \
874845
{[xferserver_holds $xferserverEdgeSrcHash] == 1}
875846
write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n"
876847
fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out
877
-set xferserverEdgeTgt2Hash [xferserver_hash [read_file delta-tgt2.txt]]
848
+set xferserverEdgeTgt2Hash [sha3_text [read_file delta-tgt2.txt]]
878849
set xferserverEdgeDelta [read_file delta2.out]
879850
# The same delta without the checksum that ends it.
880851
regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta
881852
test xfer-edge-cfile-delta-setup-cut \
882853
{[string length $xferserverEdgeBadDelta] > 0 &&
@@ -902,11 +873,11 @@
902873
903874
###############################################################################
904875
# "uvfile" cards.
905876
906877
set xferserverEdgeUv "an unversioned note\n"
907
-set xferserverEdgeUvHash [xferserver_hash $xferserverEdgeUv]
878
+set xferserverEdgeUvHash [sha3_text $xferserverEdgeUv]
908879
set xferserverEdgeUvLen [string length $xferserverEdgeUv]
909880
proc xferserver_uv {name} {
910881
return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL
911882
FROM unversioned WHERE name='$name'"]
912883
}
@@ -933,11 +904,11 @@
933904
test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \
934905
"1700000000|$xferserverEdgeUvLen|0|1"
935906
936907
# Content that compresses well is stored compressed.
937908
set xferserverEdgeBig [string repeat "the same line again and again\n" 200]
938
-set xferserverEdgeBigHash [xferserver_hash $xferserverEdgeBig]
909
+set xferserverEdgeBigHash [sha3_text $xferserverEdgeBig]
939910
xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\
940911
[string length $xferserverEdgeBig] 0\n$xferserverEdgeBig"
941912
test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \
942913
"1700000000|[string length $xferserverEdgeBig]|1|1"
943914
@@ -949,11 +920,11 @@
949920
"1700000500|$xferserverEdgeUvLen|0|1"
950921
951922
# Older content does not replace newer.
952923
set xferserverEdgeOld "an older note\n"
953924
xferserver_edge_send push "uvfile note.txt 1600000000\
954
-[xferserver_hash $xferserverEdgeOld]\
925
+[sha3_text $xferserverEdgeOld]\
955926
[string length $xferserverEdgeOld] 0\n$xferserverEdgeOld"
956927
test xfer-edge-uvfile-older {$CODE == 0}
957928
test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash
958929
FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash
959930
@@ -1307,12 +1278,11 @@
13071278
--ipaddr $address srv.fossil {*}$args
13081279
set reply ""
13091280
if {[file exists http-reply.txt]} {
13101281
set reply [read_file http-reply.txt]
13111282
}
1312
- set end [string first "\r\n\r\n" $reply]
1313
- set ::RESULT [expr {$end < 0 ? "" : [string range $reply $end+4 end]}]
1283
+ set ::RESULT [reply_body $reply]
13141284
}
13151285
13161286
# The login card of USER with PASSWORD for a message of the cards BODY,
13171287
# with the nonce made from the cards NONCEBODY.
13181288
#
@@ -1380,11 +1350,10 @@
13801350
VALUES('localauth',1,now())"
13811351
xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
13821352
test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \
13831353
{{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting}
13841354
"!igot "}]}
1385
-xferserver_sql "DELETE FROM config WHERE name='localauth'"
13861355
13871356
unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
13881357
unset ::env(SCN_PROJECT)
13891358
13901359
xferserver_leave
@@ -1402,31 +1371,22 @@
14021371
# artifact stored as a delta of another private one, and a public artifact
14031372
# stored as a delta of a public one.
14041373
14051374
xferserver_enter mcdc
14061375
1407
-proc xferserver_mcdc_sql {sql} {
1408
- fossil sql -R srv.fossil $sql
1409
- return [string trim $::RESULT]
1410
-}
1411
-
1412
-# Send MESSAGE to the server and set RESULT and CODE.
1413
-proc xferserver_mcdc_send {message} {
1414
- write_file msg.txt $message
1415
- fossil_raw test-xfer -R srv.fossil msg.txt
1416
-}
14171376
14181377
# Test NAME passes when the reply to MESSAGE holds each of the strings
14191378
# given, and none that begins with "!".
14201379
proc xferserver_mcdc_expect {name message args} {
1421
- xferserver_mcdc_send $message
1380
+ xferserver_send $message
14221381
test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
14231382
}
14241383
14251384
set xferserverMcdcText ""
14261385
for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} {
1427
- append xferserverMcdcText "line $xferserverMcdcI of a file that is worth a delta\n"
1386
+ append xferserverMcdcText \
1387
+ "line $xferserverMcdcI of a file that is worth a delta\n"
14281388
}
14291389
write_file a.txt $xferserverMcdcText
14301390
fossil add a.txt
14311391
fossil commit -m public-1 --no-warnings
14321392
foreach xferserverMcdcI {2 3 4} {
@@ -1446,40 +1406,40 @@
14461406
WHERE comment='private-2')"
14471407
fossil publish [string trim $RESULT]
14481408
fossil test-content-deltify [xferserverMcdc_fid public-1] \
14491409
[xferserverMcdc_fid private-2]
14501410
file copy .rep.fossil srv.fossil
1451
-set xferserverMcdcPcode [xferserver_mcdc_sql \
1411
+set xferserverMcdcPcode [xferserver_sql \
14521412
"SELECT value FROM config WHERE name='project-code'"]
1453
-set xferserverMcdcTip [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE rid=
1413
+set xferserverMcdcTip [xferserver_sql "SELECT uuid FROM blob WHERE rid=
14541414
(SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"]
14551415
set xferserverMcdcLogin "login tester 0 0\n"
14561416
set xferserverMcdcPull "pull x $xferserverMcdcPcode\n"
14571417
set xferserverMcdcPush "push x $xferserverMcdcPcode\n"
1458
-xferserver_mcdc_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'"
1418
+xferserver_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'"
14591419
# A public check-in, named by a SHA3 hash.
1460
-set xferserverMcdcPublic [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE
1420
+set xferserverMcdcPublic [xferserver_sql "SELECT uuid FROM blob WHERE
14611421
rid IN (SELECT objid FROM event WHERE type='ci')
14621422
AND rid NOT IN (SELECT rid FROM private) LIMIT 1"]
14631423
14641424
# A private artifact that is stored as a delta of another private artifact.
1465
-set xferserverMcdcDelta [xferserver_mcdc_sql "SELECT b.uuid FROM blob b, delta d,
1425
+set xferserverMcdcDelta [xferserver_sql "SELECT b.uuid FROM blob b, delta d,
14661426
private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN
14671427
(SELECT rid FROM private) LIMIT 1"]
14681428
test xfer-server-mcdc-setup-private-delta \
14691429
{[string length $xferserverMcdcDelta] >= 40}
14701430
foreach xferserverMcdcI {1 2} {
1471
- set xferserverMcdcFile($xferserverMcdcI) [xferserver_mcdc_sql \
1431
+ set xferserverMcdcFile($xferserverMcdcI) [xferserver_sql \
14721432
"SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \
14731433
[lindex {x public-1 private-2} $xferserverMcdcI]]"]
14741434
}
14751435
lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1
14761436
lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2
1477
-test xfer-server-mcdc-setup-public-from-private {[xferserver_mcdc_sql "SELECT
1437
+test xfer-server-mcdc-setup-public-from-private {[xferserver_sql "SELECT
14781438
count(*) FROM delta d, private p WHERE d.rid=
14791439
[xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1}
1480
-test xfer-server-mcdc-setup-public-from-public {[xferserver_mcdc_sql "SELECT
1440
+test xfer-server-mcdc-setup-public-from-public {[xferserver_sql "SELECT
14811441
count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1]
14821442
AND d.srcid=[xferserverMcdc_fid private-2]"] == 1}
14831443
14841444
###############################################################################
14851445
# A lock on a check-in is reported to a second client with the name of the
@@ -1492,19 +1452,19 @@
14921452
empty {json_object('login','','clientid',$A)} nobody
14931453
absent {json_object('clientid',$A)} nobody
14941454
} {
14951455
set xferserverMcdcValue [string map \
14961456
[list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue]
1497
- xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*';
1457
+ xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*';
14981458
REPLACE INTO config(name,value,mtime)
14991459
VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())"
15001460
xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \
15011461
"$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\
15021462
$xferserverMcdcTip $xferserverMcdcB\n" \
15031463
"pragma ci-lock-fail $xferserverMcdcWho "
15041464
}
1505
-xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
1465
+xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
15061466
15071467
###############################################################################
15081468
# A clone of a server that has private artifacts. A client that does not
15091469
# ask for private content is sent none, and one that does is sent each of
15101470
# them behind a "private" card, a delta of a private artifact as a delta.
@@ -1511,11 +1471,13 @@
15111471
15121472
xferserver_mcdc_expect clone-no-private \
15131473
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
15141474
"cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta"
15151475
xferserver_mcdc_expect clone-private \
1516
- "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 3 1\n" \
1476
+ [join [list \
1477
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma " \
1478
+ "send-private\nclone 3 1\n"] ""] \
15171479
"private\ncfile $xferserverMcdcDelta "
15181480
# A public artifact whose source is private is sent whole: the card names no
15191481
# source.
15201482
xferserver_mcdc_expect clone-public-from-private \
15211483
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
@@ -1528,11 +1490,13 @@
15281490
"file $xferserverMcdcHash2 $xferserverMcdcSize2\n"
15291491
xferserver_mcdc_expect clone-v2-public-from-public \
15301492
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
15311493
"file $xferserverMcdcHash1 $xferserverMcdcHash2 "
15321494
xferserver_mcdc_expect clone-v2-private \
1533
- "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 2 1\n" \
1495
+ [join [list \
1496
+ "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma " \
1497
+ "send-private\nclone 2 1\n"] ""] \
15341498
"private\nfile $xferserverMcdcDelta "
15351499
15361500
###############################################################################
15371501
# Artifacts named by a SHA1 hash. A client that does not state its version
15381502
# is taken to be older than 2.0: it is sent them, and gets an error in place
@@ -1543,37 +1507,39 @@
15431507
set xferserverMcdcSha1 [lindex $RESULT 0]
15441508
xferserver_mcdc_expect push-sha1 \
15451509
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\
15461510
$xferserverMcdcSha1 13\nsha1 content\n" "errors 0"
15471511
test xfer-server-mcdc-push-sha1-stored \
1548
- {[xferserver_mcdc_sql "SELECT count(*) FROM blob WHERE
1512
+ {[xferserver_sql "SELECT count(*) FROM blob WHERE
15491513
uuid='$xferserverMcdcSha1' AND size=13"] == 1}
15501514
xferserver_mcdc_expect old-client-gimme-sha1 \
15511515
"${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \
15521516
"file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil"
15531517
xferserver_mcdc_expect old-client-gimme-sha3 \
15541518
"${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \
1555
- {error Fossil\sversion\s2.0\sor\slater\srequired} "!file $xferserverMcdcPublic"
1519
+ {error Fossil\sversion\s2.0\sor\slater\srequired} \
1520
+ "!file $xferserverMcdcPublic"
15561521
xferserver_mcdc_expect old-client-clone-sha1 \
15571522
"${xferserverMcdcLogin}clone 3 1\n" \
1558
- "cfile $xferserverMcdcSha1 13 " {error Fossil\sversion\s2.0\sor\slater\srequired}
1523
+ "cfile $xferserverMcdcSha1 13 " \
1524
+ {error Fossil\sversion\s2.0\sor\slater\srequired}
15591525
15601526
###############################################################################
15611527
# A server whose send limit is reached stops sending files and tells the
15621528
# client in "igot" cards, and in "uvigot" cards for unversioned files.
15631529
15641530
write_file note.txt "hi\n"
15651531
fossil unversioned add note.txt -R srv.fossil
1566
-xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime)
1532
+xferserver_sql "REPLACE INTO config(name,value,mtime)
15671533
VALUES('max-download','1',now())"
15681534
xferserver_mcdc_expect uvgimme-limit \
15691535
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
15701536
note.txt\n" "uvigot note.txt " "!uvfile note.txt"
15711537
xferserver_mcdc_expect catalog-limit \
15721538
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\
15731539
send-catalog x\n" "igot " "errors 0"
1574
-xferserver_mcdc_sql "DELETE FROM config WHERE name='max-download'"
1540
+xferserver_sql "DELETE FROM config WHERE name='max-download'"
15751541
xferserver_mcdc_expect uvgimme-no-limit \
15761542
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
15771543
note.txt\n" "uvfile note.txt " "!uvigot"
15781544
15791545
# A client that does not state its version is sent an unversioned file
@@ -1581,11 +1547,11 @@
15811547
# a SHA3 hash.
15821548
fossil hash-policy sha1 -R srv.fossil
15831549
write_file old.txt "old\n"
15841550
fossil unversioned add old.txt -R srv.fossil
15851551
fossil hash-policy sha3 -R srv.fossil
1586
-test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_mcdc_sql "SELECT
1552
+test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_sql "SELECT
15871553
group_concat(length(hash)) FROM (SELECT hash FROM unversioned
15881554
WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40"
15891555
xferserver_mcdc_expect old-client-uvgimme-sha1 \
15901556
"${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \
15911557
"uvfile old.txt " "!error Fossil"
@@ -1595,30 +1561,40 @@
15951561
15961562
###############################################################################
15971563
# A server has the number of seconds in max-download-time to make a reply.
15981564
# Once they have passed it sends no more artifacts: a client that asks for
15991565
# one is told in an "igot" card that the server has it, and a clone is told
1600
-# to ask again from where it was. Here the script that the server runs
1601
-# before it reads the request keeps it busy for more than one second.
1566
+# to ask again from where it was. The limit is at least one second and
1567
+# the server counts whole seconds, so the script that the server runs
1568
+# before it reads the request keeps it busy until the date shows the next
1569
+# second, and for 20 ms more because the clock that the server reads can
1570
+# be a few milliseconds behind the date. The server runs the script
1571
+# again after the request, where the wait is left out.
16021572
16031573
xferserver_mcdc_expect gimme-in-time \
16041574
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
16051575
$xferserverMcdcPublic\n" "file $xferserverMcdcPublic "
1606
-set xferserverMcdcBusy {set s [expr {[utime]+[stime]}]}
1607
-append xferserverMcdcBusy \
1608
- {; for {set t $s} {$t-$s < 1100000} {set t [expr {[utime]+[stime]}]} {}}
1609
-xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime) VALUES
1576
+set xferserverMcdcBusy {
1577
+ if {![info exists waited]} {
1578
+ set waited 1
1579
+ set s [date]
1580
+ for {} {[string compare [date] $s] == 0} {} {}
1581
+ set t [utime]
1582
+ for {} {[utime]-$t < 20000} {} {}
1583
+ }
1584
+}
1585
+xferserver_sql "REPLACE INTO config(name,value,mtime) VALUES
16101586
('max-download-time','1',now()),
16111587
('xfer-common-script','$xferserverMcdcBusy',now())"
16121588
xferserver_mcdc_expect gimme-out-of-time \
16131589
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
16141590
$xferserverMcdcPublic\n" \
16151591
"igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0"
16161592
xferserver_mcdc_expect clone-out-of-time \
16171593
"${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
16181594
"clone_seqno 1\n" "!cfile " "errors 0"
1619
-xferserver_mcdc_sql "DELETE FROM config
1595
+xferserver_sql "DELETE FROM config
16201596
WHERE name IN ('max-download-time','xfer-common-script')"
16211597
16221598
###############################################################################
16231599
# A client that says where it can be reached is recorded when the address
16241600
# is an http or https one and does not name the local host.
@@ -1627,16 +1603,16 @@
16271603
http http://example.org/a 1
16281604
https https://example.org/b 1
16291605
localhost http://localhost/c 0
16301606
ssh ssh://example.org/d 0
16311607
} {
1632
- xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'"
1608
+ xferserver_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'"
16331609
xferserver_mcdc_expect client-url-$xferserverMcdcName \
16341610
"${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\
16351611
$xferserverMcdcUrl\n" "errors 0"
16361612
test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \
1637
- {[xferserver_mcdc_sql "SELECT count(*) FROM config
1613
+ {[xferserver_sql "SELECT count(*) FROM config
16381614
WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept}
16391615
}
16401616
16411617
###############################################################################
16421618
# "fossil test-xfer" reads the message from the file it is given, or from
16431619
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -7,15 +7,12 @@
7 # "fossil test-xfer" treats a login card as a grant of the Read, Write,
8 # Private and Admin permissions. A message without a login card runs
9 # with the permissions of the user "nobody", which these tests set.
10 #
11
12 # These tests run only in a long pass: -assurance stress.
13 if {[test_assurance] ne "stress"} {
14 test_skip "runs only with -assurance stress"
15 }
16
17 require_no_open_checkout
18
19 test_setup
20
21 write_file a.txt "hello world\n"
@@ -307,10 +304,14 @@
307 "$xferserverLogin$xferserverPush$xferserverCard" \
308 "!Database error" $xferserverWant
309 }
310 test_eq xfer-server-hash-zero-byte-nothing-stored \
311 [xferserver_count "blob WHERE length(uuid)<40"] 0
 
 
 
 
312
313 # Clone, in each version of the protocol. A login card to test-xfer does
314 # not grant the Clone permission, so "nobody" is given it and these
315 # messages have no login card.
316 xferserver_caps "g"
@@ -427,11 +428,12 @@
427 xferserver_set gitpush:[email protected]:someone/other.git "{}"
428 xferserver_send "${xferserverPull}pragma req-links\n"
429 test xfer-server-read-req-links-git-address \
430 {$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
431 test xfer-server-read-req-links-git-https \
432 {[string match "*pragma link https://git.example.org/someone/mirror.git*" $RESULT]}
 
433 test xfer-server-read-req-links-git-other-left-out \
434 {![string match "*other.git*" $RESULT]}
435 xferserver_unset gitpush:*
436
437 # The address configuration is given only to a client that may read
@@ -528,12 +530,10 @@
528 xferserver_enter cards
529
530 set xferserverCardsContent "hello world\n"
531 set xferserverCardsSize [string length $xferserverCardsContent]
532 write_file a.txt $xferserverCardsContent
533 fossil add a.txt
534 fossil commit -m one --no-warnings
535 fossil sha3sum a.txt
536 set xferserverCardsHash [lindex $RESULT 0]
537
538 fossil init tgt.fossil -A tester
539 fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'"
@@ -578,18 +578,20 @@
578 "file $xferserverCardsHash zz\
579 $xferserverCardsSize\n$xferserverCardsContent" \
580 size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \
581 size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \
582 size-at-end "file $xferserverCardsHash 5\n" \
583 size-with-nul "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \
 
584 content-wrong-hash \
585 "file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \
586 cfile-too-few "cfile $xferserverCardsHash\n" \
587 cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \
588 uvfile-too-few "uvfile note.txt\n" \
589 uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \
590 uvfile-mtime-nul "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \
 
591 uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \
592 uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \
593 uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \
594 uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \
595 uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \
@@ -598,27 +600,10 @@
598 test xfer-cards-reject-$xferserverCardsName \
599 {$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 &&
600 $xferserverCardsStored == 0}
601 }
602
603 # A client that does not send a version is treated as older than 2.0 and
604 # cannot be sent a SHA3 hash. When such a client asks for an unversioned
605 # file the server answers with an error; a current client gets the file.
606 write_file note.txt "hi\n"
607 fossil unversioned add note.txt -R tgt.fossil --user tester
608 set xferserverCardsUvgimme \
609 "login tester 0 0\npull x $xferserverCardsPcode\nuvgimme note.txt\n"
610 write_file uvgimme.txt $xferserverCardsUvgimme
611 fossil_raw test-xfer -R tgt.fossil uvgimme.txt
612 test xfer-cards-uvgimme-old-client \
613 {$CODE == 0
614 && [holds_strings $RESULT [list {or\slater\srequired} "!uvfile note.txt"]]}
615 write_file uvgimme.txt $CLIENT_VERSION_CARD$xferserverCardsUvgimme
616 fossil_raw test-xfer -R tgt.fossil uvgimme.txt
617 test xfer-cards-uvgimme-current-client \
618 {$CODE == 0 && [string first "uvfile note.txt" $RESULT] >= 0}
619
620 fossil sql -R tgt.fossil \
621 "INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)"
622 xferserver_cards_push "file $xferserverCardsHash\
623 $xferserverCardsSize\n$xferserverCardsContent"
624 test xfer-cards-reject-shunned \
@@ -630,23 +615,17 @@
630 # More cards sent to the server side of the sync protocol through
631 # "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme"
632 # and "uvgimme" that xfer-cards.test and xfer-server.test do not send.
633 # Each has a stated effect on the server's repository or on the reply,
634 # and none may crash.
635 #
636 # The messages carry no login card, so they run with the permissions of
637 # the user "nobody", which these tests set.
638 #
639
640
641 xferserver_enter edge
642
643 # The answer of one SQL statement on the server, trimmed.
644 #
645 proc xferserver_sql {sql} {
646 fossil sql -R srv.fossil $sql
647 return [string trim $::RESULT]
648 }
649
650 # Send the cards BODY to the server after a client-version card and a
651 # card of KIND, which is "push" or "pull". RESULT is the reply, as
652 # bytes. xferserverEdgeErrors is the number of errors that the reply reports,
@@ -658,18 +637,10 @@
658 fossil_raw test-xfer -R srv.fossil msg.txt
659 set xferserverEdgeErrors -1
660 regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors
661 }
662
663 # The hash that Fossil gives TEXT.
664 #
665 proc xferserver_hash {text} {
666 write_file hash-me.txt $text
667 fossil sha3sum hash-me.txt
668 return [lindex $::RESULT 0]
669 }
670
671 # Content as a "cfile" card carries it: the size, then the zlib stream.
672 #
673 proc xferserver_compress {text} {
674 return [binary format I [string length $text]][zlib compress $text]
675 }
@@ -716,11 +687,11 @@
716
717 ###############################################################################
718 # "file" cards.
719
720 set xferserverEdgeNew "content that the server does not have yet\n"
721 set xferserverEdgeNewHash [xferserver_hash $xferserverEdgeNew]
722 set xferserverEdgeLen [string length $xferserverEdgeNew]
723
724 foreach {xferserverEdgeName xferserverEdgeCard} [list \
725 too-many-tokens \
726 "file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\
@@ -799,11 +770,11 @@
799 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
800 test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0}
801 test xfer-edge-cfile-wrong-hash-not-stored \
802 {![xferserver_holds $xferserverEdgeAbsent]}
803 set xferserverEdgeSized "content with the wrong size on its card\n"
804 set xferserverEdgeSizedHash [xferserver_hash $xferserverEdgeSized]
805 set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized]
806 xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\
807 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
808 test xfer-edge-cfile-wrong-size \
809 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
@@ -814,11 +785,11 @@
814 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
815 ![xferserver_holds $xferserverEdgeAbsent]}
816
817 # A shunned artifact is not stored.
818 set xferserverEdgeShun "content that the server has shunned\n"
819 set xferserverEdgeShunHash [xferserver_hash $xferserverEdgeShun]
820 xferserver_sql "INSERT INTO shun(uuid,mtime)\
821 VALUES('$xferserverEdgeShunHash',0)"
822 set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun]
823 xferserver_edge_send push "cfile $xferserverEdgeShunHash\
824 [string length $xferserverEdgeShun]\
@@ -831,11 +802,11 @@
831 # does not make content of the size on the card is refused.
832 set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4]
833 write_file delta-src.txt $xferserverEdgeVersion(1)
834 write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n"
835 fossil test-delta-create delta-src.txt delta-tgt.txt delta.out
836 set xferserverEdgeTgtHash [xferserver_hash [read_file delta-tgt.txt]]
837 set xferserverEdgeZ [xferserver_compress [read_file delta.out]]
838 xferserver_edge_send push "cfile $xferserverEdgeTgtHash\
839 $xferserverEdgeAbsent2 7777\
840 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
841 test xfer-edge-cfile-dangling-delta-wrong-size \
@@ -867,16 +838,16 @@
867
868 # A compressed delta whose source the server has is applied and checked.
869 # One that does not apply, and one that makes content with another hash
870 # than the card gives, are refused; one that makes the content that the
871 # card names is stored.
872 set xferserverEdgeSrcHash [xferserver_hash $xferserverEdgeVersion(1)]
873 test xfer-edge-cfile-delta-setup-source-held \
874 {[xferserver_holds $xferserverEdgeSrcHash] == 1}
875 write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n"
876 fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out
877 set xferserverEdgeTgt2Hash [xferserver_hash [read_file delta-tgt2.txt]]
878 set xferserverEdgeDelta [read_file delta2.out]
879 # The same delta without the checksum that ends it.
880 regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta
881 test xfer-edge-cfile-delta-setup-cut \
882 {[string length $xferserverEdgeBadDelta] > 0 &&
@@ -902,11 +873,11 @@
902
903 ###############################################################################
904 # "uvfile" cards.
905
906 set xferserverEdgeUv "an unversioned note\n"
907 set xferserverEdgeUvHash [xferserver_hash $xferserverEdgeUv]
908 set xferserverEdgeUvLen [string length $xferserverEdgeUv]
909 proc xferserver_uv {name} {
910 return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL
911 FROM unversioned WHERE name='$name'"]
912 }
@@ -933,11 +904,11 @@
933 test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \
934 "1700000000|$xferserverEdgeUvLen|0|1"
935
936 # Content that compresses well is stored compressed.
937 set xferserverEdgeBig [string repeat "the same line again and again\n" 200]
938 set xferserverEdgeBigHash [xferserver_hash $xferserverEdgeBig]
939 xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\
940 [string length $xferserverEdgeBig] 0\n$xferserverEdgeBig"
941 test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \
942 "1700000000|[string length $xferserverEdgeBig]|1|1"
943
@@ -949,11 +920,11 @@
949 "1700000500|$xferserverEdgeUvLen|0|1"
950
951 # Older content does not replace newer.
952 set xferserverEdgeOld "an older note\n"
953 xferserver_edge_send push "uvfile note.txt 1600000000\
954 [xferserver_hash $xferserverEdgeOld]\
955 [string length $xferserverEdgeOld] 0\n$xferserverEdgeOld"
956 test xfer-edge-uvfile-older {$CODE == 0}
957 test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash
958 FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash
959
@@ -1307,12 +1278,11 @@
1307 --ipaddr $address srv.fossil {*}$args
1308 set reply ""
1309 if {[file exists http-reply.txt]} {
1310 set reply [read_file http-reply.txt]
1311 }
1312 set end [string first "\r\n\r\n" $reply]
1313 set ::RESULT [expr {$end < 0 ? "" : [string range $reply $end+4 end]}]
1314 }
1315
1316 # The login card of USER with PASSWORD for a message of the cards BODY,
1317 # with the nonce made from the cards NONCEBODY.
1318 #
@@ -1380,11 +1350,10 @@
1380 VALUES('localauth',1,now())"
1381 xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
1382 test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \
1383 {{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting}
1384 "!igot "}]}
1385 xferserver_sql "DELETE FROM config WHERE name='localauth'"
1386
1387 unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
1388 unset ::env(SCN_PROJECT)
1389
1390 xferserver_leave
@@ -1402,31 +1371,22 @@
1402 # artifact stored as a delta of another private one, and a public artifact
1403 # stored as a delta of a public one.
1404
1405 xferserver_enter mcdc
1406
1407 proc xferserver_mcdc_sql {sql} {
1408 fossil sql -R srv.fossil $sql
1409 return [string trim $::RESULT]
1410 }
1411
1412 # Send MESSAGE to the server and set RESULT and CODE.
1413 proc xferserver_mcdc_send {message} {
1414 write_file msg.txt $message
1415 fossil_raw test-xfer -R srv.fossil msg.txt
1416 }
1417
1418 # Test NAME passes when the reply to MESSAGE holds each of the strings
1419 # given, and none that begins with "!".
1420 proc xferserver_mcdc_expect {name message args} {
1421 xferserver_mcdc_send $message
1422 test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
1423 }
1424
1425 set xferserverMcdcText ""
1426 for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} {
1427 append xferserverMcdcText "line $xferserverMcdcI of a file that is worth a delta\n"
 
1428 }
1429 write_file a.txt $xferserverMcdcText
1430 fossil add a.txt
1431 fossil commit -m public-1 --no-warnings
1432 foreach xferserverMcdcI {2 3 4} {
@@ -1446,40 +1406,40 @@
1446 WHERE comment='private-2')"
1447 fossil publish [string trim $RESULT]
1448 fossil test-content-deltify [xferserverMcdc_fid public-1] \
1449 [xferserverMcdc_fid private-2]
1450 file copy .rep.fossil srv.fossil
1451 set xferserverMcdcPcode [xferserver_mcdc_sql \
1452 "SELECT value FROM config WHERE name='project-code'"]
1453 set xferserverMcdcTip [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE rid=
1454 (SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"]
1455 set xferserverMcdcLogin "login tester 0 0\n"
1456 set xferserverMcdcPull "pull x $xferserverMcdcPcode\n"
1457 set xferserverMcdcPush "push x $xferserverMcdcPcode\n"
1458 xferserver_mcdc_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'"
1459 # A public check-in, named by a SHA3 hash.
1460 set xferserverMcdcPublic [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE
1461 rid IN (SELECT objid FROM event WHERE type='ci')
1462 AND rid NOT IN (SELECT rid FROM private) LIMIT 1"]
1463
1464 # A private artifact that is stored as a delta of another private artifact.
1465 set xferserverMcdcDelta [xferserver_mcdc_sql "SELECT b.uuid FROM blob b, delta d,
1466 private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN
1467 (SELECT rid FROM private) LIMIT 1"]
1468 test xfer-server-mcdc-setup-private-delta \
1469 {[string length $xferserverMcdcDelta] >= 40}
1470 foreach xferserverMcdcI {1 2} {
1471 set xferserverMcdcFile($xferserverMcdcI) [xferserver_mcdc_sql \
1472 "SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \
1473 [lindex {x public-1 private-2} $xferserverMcdcI]]"]
1474 }
1475 lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1
1476 lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2
1477 test xfer-server-mcdc-setup-public-from-private {[xferserver_mcdc_sql "SELECT
1478 count(*) FROM delta d, private p WHERE d.rid=
1479 [xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1}
1480 test xfer-server-mcdc-setup-public-from-public {[xferserver_mcdc_sql "SELECT
1481 count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1]
1482 AND d.srcid=[xferserverMcdc_fid private-2]"] == 1}
1483
1484 ###############################################################################
1485 # A lock on a check-in is reported to a second client with the name of the
@@ -1492,19 +1452,19 @@
1492 empty {json_object('login','','clientid',$A)} nobody
1493 absent {json_object('clientid',$A)} nobody
1494 } {
1495 set xferserverMcdcValue [string map \
1496 [list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue]
1497 xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*';
1498 REPLACE INTO config(name,value,mtime)
1499 VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())"
1500 xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \
1501 "$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\
1502 $xferserverMcdcTip $xferserverMcdcB\n" \
1503 "pragma ci-lock-fail $xferserverMcdcWho "
1504 }
1505 xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
1506
1507 ###############################################################################
1508 # A clone of a server that has private artifacts. A client that does not
1509 # ask for private content is sent none, and one that does is sent each of
1510 # them behind a "private" card, a delta of a private artifact as a delta.
@@ -1511,11 +1471,13 @@
1511
1512 xferserver_mcdc_expect clone-no-private \
1513 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1514 "cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta"
1515 xferserver_mcdc_expect clone-private \
1516 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 3 1\n" \
 
 
1517 "private\ncfile $xferserverMcdcDelta "
1518 # A public artifact whose source is private is sent whole: the card names no
1519 # source.
1520 xferserver_mcdc_expect clone-public-from-private \
1521 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
@@ -1528,11 +1490,13 @@
1528 "file $xferserverMcdcHash2 $xferserverMcdcSize2\n"
1529 xferserver_mcdc_expect clone-v2-public-from-public \
1530 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
1531 "file $xferserverMcdcHash1 $xferserverMcdcHash2 "
1532 xferserver_mcdc_expect clone-v2-private \
1533 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 2 1\n" \
 
 
1534 "private\nfile $xferserverMcdcDelta "
1535
1536 ###############################################################################
1537 # Artifacts named by a SHA1 hash. A client that does not state its version
1538 # is taken to be older than 2.0: it is sent them, and gets an error in place
@@ -1543,37 +1507,39 @@
1543 set xferserverMcdcSha1 [lindex $RESULT 0]
1544 xferserver_mcdc_expect push-sha1 \
1545 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\
1546 $xferserverMcdcSha1 13\nsha1 content\n" "errors 0"
1547 test xfer-server-mcdc-push-sha1-stored \
1548 {[xferserver_mcdc_sql "SELECT count(*) FROM blob WHERE
1549 uuid='$xferserverMcdcSha1' AND size=13"] == 1}
1550 xferserver_mcdc_expect old-client-gimme-sha1 \
1551 "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \
1552 "file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil"
1553 xferserver_mcdc_expect old-client-gimme-sha3 \
1554 "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \
1555 {error Fossil\sversion\s2.0\sor\slater\srequired} "!file $xferserverMcdcPublic"
 
1556 xferserver_mcdc_expect old-client-clone-sha1 \
1557 "${xferserverMcdcLogin}clone 3 1\n" \
1558 "cfile $xferserverMcdcSha1 13 " {error Fossil\sversion\s2.0\sor\slater\srequired}
 
1559
1560 ###############################################################################
1561 # A server whose send limit is reached stops sending files and tells the
1562 # client in "igot" cards, and in "uvigot" cards for unversioned files.
1563
1564 write_file note.txt "hi\n"
1565 fossil unversioned add note.txt -R srv.fossil
1566 xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime)
1567 VALUES('max-download','1',now())"
1568 xferserver_mcdc_expect uvgimme-limit \
1569 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1570 note.txt\n" "uvigot note.txt " "!uvfile note.txt"
1571 xferserver_mcdc_expect catalog-limit \
1572 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\
1573 send-catalog x\n" "igot " "errors 0"
1574 xferserver_mcdc_sql "DELETE FROM config WHERE name='max-download'"
1575 xferserver_mcdc_expect uvgimme-no-limit \
1576 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1577 note.txt\n" "uvfile note.txt " "!uvigot"
1578
1579 # A client that does not state its version is sent an unversioned file
@@ -1581,11 +1547,11 @@
1581 # a SHA3 hash.
1582 fossil hash-policy sha1 -R srv.fossil
1583 write_file old.txt "old\n"
1584 fossil unversioned add old.txt -R srv.fossil
1585 fossil hash-policy sha3 -R srv.fossil
1586 test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_mcdc_sql "SELECT
1587 group_concat(length(hash)) FROM (SELECT hash FROM unversioned
1588 WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40"
1589 xferserver_mcdc_expect old-client-uvgimme-sha1 \
1590 "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \
1591 "uvfile old.txt " "!error Fossil"
@@ -1595,30 +1561,40 @@
1595
1596 ###############################################################################
1597 # A server has the number of seconds in max-download-time to make a reply.
1598 # Once they have passed it sends no more artifacts: a client that asks for
1599 # one is told in an "igot" card that the server has it, and a clone is told
1600 # to ask again from where it was. Here the script that the server runs
1601 # before it reads the request keeps it busy for more than one second.
 
 
 
 
1602
1603 xferserver_mcdc_expect gimme-in-time \
1604 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1605 $xferserverMcdcPublic\n" "file $xferserverMcdcPublic "
1606 set xferserverMcdcBusy {set s [expr {[utime]+[stime]}]}
1607 append xferserverMcdcBusy \
1608 {; for {set t $s} {$t-$s < 1100000} {set t [expr {[utime]+[stime]}]} {}}
1609 xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime) VALUES
 
 
 
 
 
 
1610 ('max-download-time','1',now()),
1611 ('xfer-common-script','$xferserverMcdcBusy',now())"
1612 xferserver_mcdc_expect gimme-out-of-time \
1613 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1614 $xferserverMcdcPublic\n" \
1615 "igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0"
1616 xferserver_mcdc_expect clone-out-of-time \
1617 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1618 "clone_seqno 1\n" "!cfile " "errors 0"
1619 xferserver_mcdc_sql "DELETE FROM config
1620 WHERE name IN ('max-download-time','xfer-common-script')"
1621
1622 ###############################################################################
1623 # A client that says where it can be reached is recorded when the address
1624 # is an http or https one and does not name the local host.
@@ -1627,16 +1603,16 @@
1627 http http://example.org/a 1
1628 https https://example.org/b 1
1629 localhost http://localhost/c 0
1630 ssh ssh://example.org/d 0
1631 } {
1632 xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'"
1633 xferserver_mcdc_expect client-url-$xferserverMcdcName \
1634 "${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\
1635 $xferserverMcdcUrl\n" "errors 0"
1636 test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \
1637 {[xferserver_mcdc_sql "SELECT count(*) FROM config
1638 WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept}
1639 }
1640
1641 ###############################################################################
1642 # "fossil test-xfer" reads the message from the file it is given, or from
1643
--- test/xfer-server.test
+++ test/xfer-server.test
@@ -7,15 +7,12 @@
7 # "fossil test-xfer" treats a login card as a grant of the Read, Write,
8 # Private and Admin permissions. A message without a login card runs
9 # with the permissions of the user "nobody", which these tests set.
10 #
11
12 # The first sections run at every level, and the rest need
13 # -assurance stress.
 
 
 
14 require_no_open_checkout
15
16 test_setup
17
18 write_file a.txt "hello world\n"
@@ -307,10 +304,14 @@
304 "$xferserverLogin$xferserverPush$xferserverCard" \
305 "!Database error" $xferserverWant
306 }
307 test_eq xfer-server-hash-zero-byte-nothing-stored \
308 [xferserver_count "blob WHERE length(uuid)<40"] 0
309
310 if {[test_assurance] ne "stress"} {
311 test_skip "the tests after the first sections need -assurance stress"
312 }
313
314 # Clone, in each version of the protocol. A login card to test-xfer does
315 # not grant the Clone permission, so "nobody" is given it and these
316 # messages have no login card.
317 xferserver_caps "g"
@@ -427,11 +428,12 @@
428 xferserver_set gitpush:[email protected]:someone/other.git "{}"
429 xferserver_send "${xferserverPull}pragma req-links\n"
430 test xfer-server-read-req-links-git-address \
431 {$CODE == 0 && [string first "errors 0" $RESULT] >= 0}
432 test xfer-server-read-req-links-git-https \
433 {[string match "*pragma link https://git.example.org/someone/mirror.git*" \
434 $RESULT]}
435 test xfer-server-read-req-links-git-other-left-out \
436 {![string match "*other.git*" $RESULT]}
437 xferserver_unset gitpush:*
438
439 # The address configuration is given only to a client that may read
@@ -528,12 +530,10 @@
530 xferserver_enter cards
531
532 set xferserverCardsContent "hello world\n"
533 set xferserverCardsSize [string length $xferserverCardsContent]
534 write_file a.txt $xferserverCardsContent
 
 
535 fossil sha3sum a.txt
536 set xferserverCardsHash [lindex $RESULT 0]
537
538 fossil init tgt.fossil -A tester
539 fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'"
@@ -578,18 +578,20 @@
578 "file $xferserverCardsHash zz\
579 $xferserverCardsSize\n$xferserverCardsContent" \
580 size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \
581 size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \
582 size-at-end "file $xferserverCardsHash 5\n" \
583 size-with-nul \
584 "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \
585 content-wrong-hash \
586 "file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \
587 cfile-too-few "cfile $xferserverCardsHash\n" \
588 cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \
589 uvfile-too-few "uvfile note.txt\n" \
590 uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \
591 uvfile-mtime-nul \
592 "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \
593 uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \
594 uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \
595 uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \
596 uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \
597 uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \
@@ -598,27 +600,10 @@
600 test xfer-cards-reject-$xferserverCardsName \
601 {$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 &&
602 $xferserverCardsStored == 0}
603 }
604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605 fossil sql -R tgt.fossil \
606 "INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)"
607 xferserver_cards_push "file $xferserverCardsHash\
608 $xferserverCardsSize\n$xferserverCardsContent"
609 test xfer-cards-reject-shunned \
@@ -630,23 +615,17 @@
615 # More cards sent to the server side of the sync protocol through
616 # "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme"
617 # and "uvgimme" that xfer-cards.test and xfer-server.test do not send.
618 # Each has a stated effect on the server's repository or on the reply,
619 # and none may crash.
 
 
 
 
 
620
621 xferserver_enter edge
622
623 # The answer of one SQL statement on the server, trimmed.
624 #
625 proc xferserver_sql {sql} {
626 return [fossil_sql $sql srv.fossil]
 
627 }
628
629 # Send the cards BODY to the server after a client-version card and a
630 # card of KIND, which is "push" or "pull". RESULT is the reply, as
631 # bytes. xferserverEdgeErrors is the number of errors that the reply reports,
@@ -658,18 +637,10 @@
637 fossil_raw test-xfer -R srv.fossil msg.txt
638 set xferserverEdgeErrors -1
639 regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors
640 }
641
 
 
 
 
 
 
 
 
642 # Content as a "cfile" card carries it: the size, then the zlib stream.
643 #
644 proc xferserver_compress {text} {
645 return [binary format I [string length $text]][zlib compress $text]
646 }
@@ -716,11 +687,11 @@
687
688 ###############################################################################
689 # "file" cards.
690
691 set xferserverEdgeNew "content that the server does not have yet\n"
692 set xferserverEdgeNewHash [sha3_text $xferserverEdgeNew]
693 set xferserverEdgeLen [string length $xferserverEdgeNew]
694
695 foreach {xferserverEdgeName xferserverEdgeCard} [list \
696 too-many-tokens \
697 "file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\
@@ -799,11 +770,11 @@
770 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
771 test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0}
772 test xfer-edge-cfile-wrong-hash-not-stored \
773 {![xferserver_holds $xferserverEdgeAbsent]}
774 set xferserverEdgeSized "content with the wrong size on its card\n"
775 set xferserverEdgeSizedHash [sha3_text $xferserverEdgeSized]
776 set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized]
777 xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\
778 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
779 test xfer-edge-cfile-wrong-size \
780 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
@@ -814,11 +785,11 @@
785 {$CODE == 0 && $xferserverEdgeErrors > 0 &&
786 ![xferserver_holds $xferserverEdgeAbsent]}
787
788 # A shunned artifact is not stored.
789 set xferserverEdgeShun "content that the server has shunned\n"
790 set xferserverEdgeShunHash [sha3_text $xferserverEdgeShun]
791 xferserver_sql "INSERT INTO shun(uuid,mtime)\
792 VALUES('$xferserverEdgeShunHash',0)"
793 set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun]
794 xferserver_edge_send push "cfile $xferserverEdgeShunHash\
795 [string length $xferserverEdgeShun]\
@@ -831,11 +802,11 @@
802 # does not make content of the size on the card is refused.
803 set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4]
804 write_file delta-src.txt $xferserverEdgeVersion(1)
805 write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n"
806 fossil test-delta-create delta-src.txt delta-tgt.txt delta.out
807 set xferserverEdgeTgtHash [sha3_text [read_file delta-tgt.txt]]
808 set xferserverEdgeZ [xferserver_compress [read_file delta.out]]
809 xferserver_edge_send push "cfile $xferserverEdgeTgtHash\
810 $xferserverEdgeAbsent2 7777\
811 [string length $xferserverEdgeZ]\n$xferserverEdgeZ"
812 test xfer-edge-cfile-dangling-delta-wrong-size \
@@ -867,16 +838,16 @@
838
839 # A compressed delta whose source the server has is applied and checked.
840 # One that does not apply, and one that makes content with another hash
841 # than the card gives, are refused; one that makes the content that the
842 # card names is stored.
843 set xferserverEdgeSrcHash [sha3_text $xferserverEdgeVersion(1)]
844 test xfer-edge-cfile-delta-setup-source-held \
845 {[xferserver_holds $xferserverEdgeSrcHash] == 1}
846 write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n"
847 fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out
848 set xferserverEdgeTgt2Hash [sha3_text [read_file delta-tgt2.txt]]
849 set xferserverEdgeDelta [read_file delta2.out]
850 # The same delta without the checksum that ends it.
851 regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta
852 test xfer-edge-cfile-delta-setup-cut \
853 {[string length $xferserverEdgeBadDelta] > 0 &&
@@ -902,11 +873,11 @@
873
874 ###############################################################################
875 # "uvfile" cards.
876
877 set xferserverEdgeUv "an unversioned note\n"
878 set xferserverEdgeUvHash [sha3_text $xferserverEdgeUv]
879 set xferserverEdgeUvLen [string length $xferserverEdgeUv]
880 proc xferserver_uv {name} {
881 return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL
882 FROM unversioned WHERE name='$name'"]
883 }
@@ -933,11 +904,11 @@
904 test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \
905 "1700000000|$xferserverEdgeUvLen|0|1"
906
907 # Content that compresses well is stored compressed.
908 set xferserverEdgeBig [string repeat "the same line again and again\n" 200]
909 set xferserverEdgeBigHash [sha3_text $xferserverEdgeBig]
910 xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\
911 [string length $xferserverEdgeBig] 0\n$xferserverEdgeBig"
912 test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \
913 "1700000000|[string length $xferserverEdgeBig]|1|1"
914
@@ -949,11 +920,11 @@
920 "1700000500|$xferserverEdgeUvLen|0|1"
921
922 # Older content does not replace newer.
923 set xferserverEdgeOld "an older note\n"
924 xferserver_edge_send push "uvfile note.txt 1600000000\
925 [sha3_text $xferserverEdgeOld]\
926 [string length $xferserverEdgeOld] 0\n$xferserverEdgeOld"
927 test xfer-edge-uvfile-older {$CODE == 0}
928 test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash
929 FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash
930
@@ -1307,12 +1278,11 @@
1278 --ipaddr $address srv.fossil {*}$args
1279 set reply ""
1280 if {[file exists http-reply.txt]} {
1281 set reply [read_file http-reply.txt]
1282 }
1283 set ::RESULT [reply_body $reply]
 
1284 }
1285
1286 # The login card of USER with PASSWORD for a message of the cards BODY,
1287 # with the nonce made from the cards NONCEBODY.
1288 #
@@ -1380,11 +1350,10 @@
1350 VALUES('localauth',1,now())"
1351 xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth
1352 test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \
1353 {{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting}
1354 "!igot "}]}
 
1355
1356 unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH)
1357 unset ::env(SCN_PROJECT)
1358
1359 xferserver_leave
@@ -1402,31 +1371,22 @@
1371 # artifact stored as a delta of another private one, and a public artifact
1372 # stored as a delta of a public one.
1373
1374 xferserver_enter mcdc
1375
 
 
 
 
 
 
 
 
 
 
1376
1377 # Test NAME passes when the reply to MESSAGE holds each of the strings
1378 # given, and none that begins with "!".
1379 proc xferserver_mcdc_expect {name message args} {
1380 xferserver_send $message
1381 test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]}
1382 }
1383
1384 set xferserverMcdcText ""
1385 for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} {
1386 append xferserverMcdcText \
1387 "line $xferserverMcdcI of a file that is worth a delta\n"
1388 }
1389 write_file a.txt $xferserverMcdcText
1390 fossil add a.txt
1391 fossil commit -m public-1 --no-warnings
1392 foreach xferserverMcdcI {2 3 4} {
@@ -1446,40 +1406,40 @@
1406 WHERE comment='private-2')"
1407 fossil publish [string trim $RESULT]
1408 fossil test-content-deltify [xferserverMcdc_fid public-1] \
1409 [xferserverMcdc_fid private-2]
1410 file copy .rep.fossil srv.fossil
1411 set xferserverMcdcPcode [xferserver_sql \
1412 "SELECT value FROM config WHERE name='project-code'"]
1413 set xferserverMcdcTip [xferserver_sql "SELECT uuid FROM blob WHERE rid=
1414 (SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"]
1415 set xferserverMcdcLogin "login tester 0 0\n"
1416 set xferserverMcdcPull "pull x $xferserverMcdcPcode\n"
1417 set xferserverMcdcPush "push x $xferserverMcdcPcode\n"
1418 xferserver_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'"
1419 # A public check-in, named by a SHA3 hash.
1420 set xferserverMcdcPublic [xferserver_sql "SELECT uuid FROM blob WHERE
1421 rid IN (SELECT objid FROM event WHERE type='ci')
1422 AND rid NOT IN (SELECT rid FROM private) LIMIT 1"]
1423
1424 # A private artifact that is stored as a delta of another private artifact.
1425 set xferserverMcdcDelta [xferserver_sql "SELECT b.uuid FROM blob b, delta d,
1426 private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN
1427 (SELECT rid FROM private) LIMIT 1"]
1428 test xfer-server-mcdc-setup-private-delta \
1429 {[string length $xferserverMcdcDelta] >= 40}
1430 foreach xferserverMcdcI {1 2} {
1431 set xferserverMcdcFile($xferserverMcdcI) [xferserver_sql \
1432 "SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \
1433 [lindex {x public-1 private-2} $xferserverMcdcI]]"]
1434 }
1435 lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1
1436 lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2
1437 test xfer-server-mcdc-setup-public-from-private {[xferserver_sql "SELECT
1438 count(*) FROM delta d, private p WHERE d.rid=
1439 [xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1}
1440 test xfer-server-mcdc-setup-public-from-public {[xferserver_sql "SELECT
1441 count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1]
1442 AND d.srcid=[xferserverMcdc_fid private-2]"] == 1}
1443
1444 ###############################################################################
1445 # A lock on a check-in is reported to a second client with the name of the
@@ -1492,19 +1452,19 @@
1452 empty {json_object('login','','clientid',$A)} nobody
1453 absent {json_object('clientid',$A)} nobody
1454 } {
1455 set xferserverMcdcValue [string map \
1456 [list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue]
1457 xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*';
1458 REPLACE INTO config(name,value,mtime)
1459 VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())"
1460 xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \
1461 "$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\
1462 $xferserverMcdcTip $xferserverMcdcB\n" \
1463 "pragma ci-lock-fail $xferserverMcdcWho "
1464 }
1465 xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'"
1466
1467 ###############################################################################
1468 # A clone of a server that has private artifacts. A client that does not
1469 # ask for private content is sent none, and one that does is sent each of
1470 # them behind a "private" card, a delta of a private artifact as a delta.
@@ -1511,11 +1471,13 @@
1471
1472 xferserver_mcdc_expect clone-no-private \
1473 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1474 "cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta"
1475 xferserver_mcdc_expect clone-private \
1476 [join [list \
1477 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma " \
1478 "send-private\nclone 3 1\n"] ""] \
1479 "private\ncfile $xferserverMcdcDelta "
1480 # A public artifact whose source is private is sent whole: the card names no
1481 # source.
1482 xferserver_mcdc_expect clone-public-from-private \
1483 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
@@ -1528,11 +1490,13 @@
1490 "file $xferserverMcdcHash2 $xferserverMcdcSize2\n"
1491 xferserver_mcdc_expect clone-v2-public-from-public \
1492 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \
1493 "file $xferserverMcdcHash1 $xferserverMcdcHash2 "
1494 xferserver_mcdc_expect clone-v2-private \
1495 [join [list \
1496 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma " \
1497 "send-private\nclone 2 1\n"] ""] \
1498 "private\nfile $xferserverMcdcDelta "
1499
1500 ###############################################################################
1501 # Artifacts named by a SHA1 hash. A client that does not state its version
1502 # is taken to be older than 2.0: it is sent them, and gets an error in place
@@ -1543,37 +1507,39 @@
1507 set xferserverMcdcSha1 [lindex $RESULT 0]
1508 xferserver_mcdc_expect push-sha1 \
1509 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\
1510 $xferserverMcdcSha1 13\nsha1 content\n" "errors 0"
1511 test xfer-server-mcdc-push-sha1-stored \
1512 {[xferserver_sql "SELECT count(*) FROM blob WHERE
1513 uuid='$xferserverMcdcSha1' AND size=13"] == 1}
1514 xferserver_mcdc_expect old-client-gimme-sha1 \
1515 "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \
1516 "file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil"
1517 xferserver_mcdc_expect old-client-gimme-sha3 \
1518 "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \
1519 {error Fossil\sversion\s2.0\sor\slater\srequired} \
1520 "!file $xferserverMcdcPublic"
1521 xferserver_mcdc_expect old-client-clone-sha1 \
1522 "${xferserverMcdcLogin}clone 3 1\n" \
1523 "cfile $xferserverMcdcSha1 13 " \
1524 {error Fossil\sversion\s2.0\sor\slater\srequired}
1525
1526 ###############################################################################
1527 # A server whose send limit is reached stops sending files and tells the
1528 # client in "igot" cards, and in "uvigot" cards for unversioned files.
1529
1530 write_file note.txt "hi\n"
1531 fossil unversioned add note.txt -R srv.fossil
1532 xferserver_sql "REPLACE INTO config(name,value,mtime)
1533 VALUES('max-download','1',now())"
1534 xferserver_mcdc_expect uvgimme-limit \
1535 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1536 note.txt\n" "uvigot note.txt " "!uvfile note.txt"
1537 xferserver_mcdc_expect catalog-limit \
1538 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\
1539 send-catalog x\n" "igot " "errors 0"
1540 xferserver_sql "DELETE FROM config WHERE name='max-download'"
1541 xferserver_mcdc_expect uvgimme-no-limit \
1542 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\
1543 note.txt\n" "uvfile note.txt " "!uvigot"
1544
1545 # A client that does not state its version is sent an unversioned file
@@ -1581,11 +1547,11 @@
1547 # a SHA3 hash.
1548 fossil hash-policy sha1 -R srv.fossil
1549 write_file old.txt "old\n"
1550 fossil unversioned add old.txt -R srv.fossil
1551 fossil hash-policy sha3 -R srv.fossil
1552 test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_sql "SELECT
1553 group_concat(length(hash)) FROM (SELECT hash FROM unversioned
1554 WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40"
1555 xferserver_mcdc_expect old-client-uvgimme-sha1 \
1556 "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \
1557 "uvfile old.txt " "!error Fossil"
@@ -1595,30 +1561,40 @@
1561
1562 ###############################################################################
1563 # A server has the number of seconds in max-download-time to make a reply.
1564 # Once they have passed it sends no more artifacts: a client that asks for
1565 # one is told in an "igot" card that the server has it, and a clone is told
1566 # to ask again from where it was. The limit is at least one second and
1567 # the server counts whole seconds, so the script that the server runs
1568 # before it reads the request keeps it busy until the date shows the next
1569 # second, and for 20 ms more because the clock that the server reads can
1570 # be a few milliseconds behind the date. The server runs the script
1571 # again after the request, where the wait is left out.
1572
1573 xferserver_mcdc_expect gimme-in-time \
1574 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1575 $xferserverMcdcPublic\n" "file $xferserverMcdcPublic "
1576 set xferserverMcdcBusy {
1577 if {![info exists waited]} {
1578 set waited 1
1579 set s [date]
1580 for {} {[string compare [date] $s] == 0} {} {}
1581 set t [utime]
1582 for {} {[utime]-$t < 20000} {} {}
1583 }
1584 }
1585 xferserver_sql "REPLACE INTO config(name,value,mtime) VALUES
1586 ('max-download-time','1',now()),
1587 ('xfer-common-script','$xferserverMcdcBusy',now())"
1588 xferserver_mcdc_expect gimme-out-of-time \
1589 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\
1590 $xferserverMcdcPublic\n" \
1591 "igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0"
1592 xferserver_mcdc_expect clone-out-of-time \
1593 "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \
1594 "clone_seqno 1\n" "!cfile " "errors 0"
1595 xferserver_sql "DELETE FROM config
1596 WHERE name IN ('max-download-time','xfer-common-script')"
1597
1598 ###############################################################################
1599 # A client that says where it can be reached is recorded when the address
1600 # is an http or https one and does not name the local host.
@@ -1627,16 +1603,16 @@
1603 http http://example.org/a 1
1604 https https://example.org/b 1
1605 localhost http://localhost/c 0
1606 ssh ssh://example.org/d 0
1607 } {
1608 xferserver_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'"
1609 xferserver_mcdc_expect client-url-$xferserverMcdcName \
1610 "${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\
1611 $xferserverMcdcUrl\n" "errors 0"
1612 test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \
1613 {[xferserver_sql "SELECT count(*) FROM config
1614 WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept}
1615 }
1616
1617 ###############################################################################
1618 # "fossil test-xfer" reads the message from the file it is given, or from
1619

Keyboard Shortcuts

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