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.
Commit
5aaa98564dccbae7e2b74b035ca0abb79f8045554262c05138da87a98c4c70f7
Parent
c6198f4645de0c6…
23 files changed
+59
-17
+65
-64
+482
-323
+127
-122
+164
-181
+167
-144
+2
-8
+157
-69
-9
+274
-200
+20
-32
+71
-58
+72
-131
+42
-111
-11
+12
-11
+4
-12
+13
-14
+157
+65
-37
+121
-94
+18
-60
+69
-93
~
test/README.md
~
test/blob.test
~
test/cgi.test
~
test/config.test
~
test/content.test
~
test/crosslink.test
~
test/fuzz.test
~
test/import.test
~
test/integrity.test
~
test/login.test
~
test/manifest.test
~
test/name.test
~
test/purge.test
~
test/rebuild.test
~
test/regress.test
~
test/scenario.test
~
test/ssh.test
~
test/sync.test
~
test/tester.tcl
~
test/th1main.test
~
test/url.test
~
test/xfer-client.test
~
test/xfer-server.test
+59
-17
| --- test/README.md | ||
| +++ test/README.md | ||
| @@ -46,23 +46,19 @@ | ||
| 46 | 46 | run per input kind. The default is 20 (5 for expensive `large` / |
| 47 | 47 | `repeats` inputs). Use `-trials 100` for the historical full fuzz. |
| 48 | 48 | This flag is only the fuzz loop count; it does not select |
| 49 | 49 | `-assurance` cases. |
| 50 | 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. | |
| 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. | |
| 64 | 60 | |
| 65 | 61 | `make test TESTFLAGS="-quiet update"` passes options and names via `make`. |
| 66 | 62 | |
| 67 | 63 | Assurance recipes: |
| 68 | 64 | |
| @@ -116,22 +112,57 @@ | ||
| 116 | 112 | | Area | Test files | Runs at | |
| 117 | 113 | | --- | --- | --- | |
| 118 | 114 | | Check-ins and the working tree | `amend`, `clean`, `commit-warning`, `mv-rm`, `revert`, `stash`, `symlinks`, `unicode-pathnames`, `update` | `smoke` | |
| 119 | 115 | | Branches and tags | `branch-tag` | `smoke` | |
| 120 | 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` | | |
| 121 | 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` | | |
| 122 | 125 | | Commands interrupted by a power loss or a killed process | `powerloss` | `ci` | |
| 123 | 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` | | |
| 124 | 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` | | |
| 125 | 143 | | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` | |
| 126 | 144 | | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` | |
| 127 | 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` | | |
| 128 | 147 | | JSON API | `json` | `smoke` | |
| 129 | 148 | | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` | |
| 130 | 149 | |
| 131 | 150 | ## Fuzz inputs and run-time checking |
| 132 | 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. | |
| 133 | 164 | |
| 134 | 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. |
| 135 | 166 | |
| 136 | 167 | ## Writing new tests |
| 137 | 168 | |
| @@ -178,14 +209,25 @@ | ||
| 178 | 209 | * standard input, with `-input TEXT` |
| 179 | 210 | * a time limit, with `-seconds N`. The default is 600. |
| 180 | 211 | * a server in the test's own Tcl. The Tcl event loop runs while the |
| 181 | 212 | command does, so a `socket -server` in your test file can answer it. |
| 182 | 213 | |
| 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` | |
| 187 | 229 | |
| 188 | 230 | ## Maintaining the tests |
| 189 | 231 | |
| 190 | 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. |
| 191 | 233 | |
| 192 | 234 |
| --- 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 @@ | ||
| 7 | 7 | # through other commands: the string literals of "diff --json" and |
| 8 | 8 | # "diff --tcl", and the conversions that a commit offers for a file in |
| 9 | 9 | # another encoding. |
| 10 | 10 | # |
| 11 | 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 | - | |
| 12 | +# The first sections run at every level, and the rest need | |
| 13 | +# -assurance stress. | |
| 17 | 14 | require_no_open_checkout |
| 18 | 15 | |
| 19 | 16 | test_setup |
| 20 | 17 | |
| 21 | 18 | # The bytes that the hexadecimal digits in $hex stand for. |
| @@ -33,11 +30,11 @@ | ||
| 33 | 30 | |
| 34 | 31 | ############################################################################### |
| 35 | 32 | # test-isspace checks fossil_isspace() against every byte value. |
| 36 | 33 | |
| 37 | 34 | 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" | |
| 39 | 36 | |
| 40 | 37 | ############################################################################### |
| 41 | 38 | # test-atoi prints, for each argument, whether it is a non-negative |
| 42 | 39 | # integer of 32 bits and of 64 bits, and the value. Each row: the |
| 43 | 40 | # argument, then the two answers and values that must be printed. |
| @@ -147,13 +144,15 @@ | ||
| 147 | 144 | [string length [lindex [split $RESULT \n] 0]] == $blobWide} |
| 148 | 145 | } |
| 149 | 146 | |
| 150 | 147 | # The command takes exactly one file. |
| 151 | 148 | 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]} | |
| 153 | 151 | 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]} | |
| 155 | 154 | |
| 156 | 155 | ############################################################################### |
| 157 | 156 | # Reading a file. A file that is not there and a file that cannot be |
| 158 | 157 | # opened are errors that name the file. |
| 159 | 158 | |
| @@ -268,13 +267,16 @@ | ||
| 268 | 267 | # Each of the three commands wants an exact number of file names. |
| 269 | 268 | foreach {blobName blobCommand blobUsage} { |
| 270 | 269 | compress-0 {test-compress} "INPUTFILE OUTPUTFILE" |
| 271 | 270 | compress-1 {test-compress z-text.in} "INPUTFILE OUTPUTFILE" |
| 272 | 271 | 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" | |
| 276 | 278 | uncompress-0 {test-uncompress} "INPUTFILE OUTPUTFILE" |
| 277 | 279 | uncompress-1 {test-uncompress z-text.z} "INPUTFILE OUTPUTFILE" |
| 278 | 280 | uncompress-3 {test-uncompress z-text.z a b} "INPUTFILE OUTPUTFILE" |
| 279 | 281 | } { |
| 280 | 282 | fossil_raw {*}$blobCommand |
| @@ -289,11 +291,12 @@ | ||
| 289 | 291 | # that cannot be made is an error that names it. |
| 290 | 292 | |
| 291 | 293 | fossil_raw test-compress z-text.in - |
| 292 | 294 | test blob-write-stdout-dash {$CODE == 0 && $RESULT eq [read_file z-text.z]} |
| 293 | 295 | 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]} | |
| 295 | 298 | fossil_raw test-uncompress z-empty.z - |
| 296 | 299 | test blob-write-stdout-nothing {$CODE == 0 && $RESULT eq ""} |
| 297 | 300 | fossil_raw test-uncompress z-empty.z write-empty.out |
| 298 | 301 | test blob-write-empty-file {$CODE == 0 && [file exists write-empty.out] && |
| 299 | 302 | [file size write-empty.out] == 0} |
| @@ -314,10 +317,14 @@ | ||
| 314 | 317 | test blob-write-closed-directory {$CODE == 1 && |
| 315 | 318 | [string match "*unable to open file \"write-closed/out.z\" for writing*" \ |
| 316 | 319 | $RESULT]} |
| 317 | 320 | file attributes write-closed -permissions 0755 |
| 318 | 321 | } |
| 322 | + | |
| 323 | +if {[test_assurance] ne "stress"} { | |
| 324 | + test_skip "the tests after the first sections need -assurance stress" | |
| 325 | +} | |
| 319 | 326 | |
| 320 | 327 | ############################################################################### |
| 321 | 328 | # test-escaped-arg quotes each argument for the shell, shows the command |
| 322 | 329 | # line it made, and runs "fossil test-echo" with it, which prints the |
| 323 | 330 | # argument as it arrived. With --hex the argument is given as hexadecimal |
| @@ -364,22 +371,23 @@ | ||
| 364 | 371 | mixed 61c3a962e282ac63 {'a<c3a9>b<e282ac>c'} {'a<c3a9>b<e282ac>c'} |
| 365 | 372 | two-byte-quote c3a927 {\<c3a9>\'} {\<c3a9>\'} |
| 366 | 373 | dash-two-byte 2dc3a9 {'./-<c3a9>'} {'-<c3a9>'} |
| 367 | 374 | } { |
| 368 | 375 | 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] { | |
| 370 | 378 | while {[regexp {<([0-9a-f]+)>} $blobQuoted -> blobPart]} { |
| 371 | 379 | regsub {<[0-9a-f]+>} $blobQuoted [blob_bytes $blobPart] blobQuoted |
| 372 | 380 | } |
| 373 | 381 | set blobArrives $blobArg |
| 374 | 382 | if {$blobFlag && [string index $blobArg 0] eq "-"} { |
| 375 | 383 | set blobArrives ./$blobArg |
| 376 | 384 | } |
| 377 | 385 | blob_escaped $blobFlag $blobArgHex |
| 378 | 386 | 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"]]} | |
| 381 | 389 | } |
| 382 | 390 | } |
| 383 | 391 | } |
| 384 | 392 | |
| 385 | 393 | # An argument that holds a control character, a byte that can only |
| @@ -414,12 +422,11 @@ | ||
| 414 | 422 | late-control 616263202701 "ascii 0x01" |
| 415 | 423 | } { |
| 416 | 424 | foreach blobFlag {1 0} { |
| 417 | 425 | blob_escaped $blobFlag $blobArgHex |
| 418 | 426 | 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\["]]} | |
| 421 | 428 | } |
| 422 | 429 | } |
| 423 | 430 | |
| 424 | 431 | if {$::tcl_platform(platform) eq "unix"} { |
| 425 | 432 | # Several arguments make several command lines, numbered by their place |
| @@ -427,13 +434,12 @@ | ||
| 427 | 434 | # kinds of argument. A --filename-args that ends the command line is |
| 428 | 435 | # skipped. |
| 429 | 436 | fossil_raw test-escaped-arg -a --filename-args no -b --filename-args yes -c \ |
| 430 | 437 | --filename-args |
| 431 | 438 | 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\]"]] && | |
| 435 | 441 | [regexp -line {^ 2 \[-a\]: } $RESULT] && |
| 436 | 442 | [regexp -line {^ 5 \[-b\]: } $RESULT] && |
| 437 | 443 | [regexp -line {^ 8 \[-c\]: } $RESULT] && |
| 438 | 444 | [regexp -all {argv\[2\]} $RESULT] == 3} |
| 439 | 445 | |
| @@ -444,12 +450,12 @@ | ||
| 444 | 450 | test blob-escaped-bare$blobOption {$CODE == 0 && |
| 445 | 451 | [string first "argv\[2\] = \[./$blobOption\]" $RESULT] >= 0} |
| 446 | 452 | } |
| 447 | 453 | fossil_raw test-escaped-arg --compare 61 |
| 448 | 454 | 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\]"]]} | |
| 451 | 457 | } |
| 452 | 458 | |
| 453 | 459 | # --hex takes up to 196 digits. |
| 454 | 460 | set blobDigits [string repeat 41 98] |
| 455 | 461 | fossil_raw test-escaped-arg --hex $blobDigits |
| @@ -463,11 +469,12 @@ | ||
| 463 | 469 | # HEX stands for. A "./" before a TEXT whose bytes begin with "-" is not |
| 464 | 470 | # counted. |
| 465 | 471 | set blobDot [expr {$::tcl_platform(platform) eq "windows" ? ".\\" : "./"}] |
| 466 | 472 | foreach {blobName blobHex blobText blobCode blobSays} { |
| 467 | 473 | 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\"" | |
| 469 | 476 | shorter 616263 ab 1 "argument disagree" |
| 470 | 477 | dash-prefixed 2d61 ./-a 0 {} |
| 471 | 478 | dash-bare 2d61 -a 1 "filename argument \"-a\" begins with \"-\"" |
| 472 | 479 | dot-slash-kept 61 ./a 1 "argument disagree: \"a\" (61)" |
| 473 | 480 | dash-dot-only 2d61 .-a 1 "argument disagree" |
| @@ -513,15 +520,19 @@ | ||
| 513 | 520 | return 610d62 {"a\rb"} {"a\rb"} |
| 514 | 521 | tab 610962 {"a\tb"} {"a<09>b"} |
| 515 | 522 | backspace 610862 {"a\bb"} {"a<08>b"} |
| 516 | 523 | formfeed 610c62 {"a\fb"} {"a<0c>b"} |
| 517 | 524 | 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>"} | |
| 519 | 527 | ctl-0b 0b {"\u000b"} {"<0b>"} |
| 520 | 528 | 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>"} | |
| 523 | 534 | delete 7f {"<7f>"} {"<7f>"} |
| 524 | 535 | two-byte c3a9 {"<c3a9>"} {"<c3a9>"} |
| 525 | 536 | empty {} {""} {""} |
| 526 | 537 | } { |
| 527 | 538 | foreach blobVar {blobJson blobTcl} { |
| @@ -546,19 +557,18 @@ | ||
| 546 | 557 | test blob-tcl-literal-filenames {$CODE == 0 && |
| 547 | 558 | [string first {FILE "lit \[n\]\$.1" "lit \[n\]\$.2"} $RESULT] >= 0} |
| 548 | 559 | |
| 549 | 560 | # In a checkout "diff --tcl" prints the same literals without collecting |
| 550 | 561 | # 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 | |
| 554 | 564 | write_file lit-checkout.txt "\[second\] \$x\n" |
| 555 | 565 | fossil_raw diff --tcl lit-checkout.txt |
| 556 | 566 | 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"}]]} | |
| 560 | 570 | fossil revert lit-checkout.txt |
| 561 | 571 | |
| 562 | 572 | # "diff --webpage" without --side-by-side builds four columns at once: |
| 563 | 573 | # the line numbers of each file, the marks, and the text. |
| 564 | 574 | write_file web.1 "one\ntwo\nthree\n" |
| @@ -573,13 +583,11 @@ | ||
| 573 | 583 | # or --convert-eol-windows it gives the content the line ends of that |
| 574 | 584 | # system first; with --convert-eol-inherit it gives it the line ends of |
| 575 | 585 | # the version before. Each row: the option, the content before, the |
| 576 | 586 | # content given, and the content that must be checked in. |
| 577 | 587 | |
| 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 | |
| 581 | 589 | |
| 582 | 590 | # Check in eol.txt with the content $before, then with $given and the |
| 583 | 591 | # option $option. Returns the content of eol.txt in the last check-in. |
| 584 | 592 | proc blob_eol {before given option} { |
| 585 | 593 | global RESULT |
| @@ -605,18 +613,19 @@ | ||
| 605 | 613 | "x\ny\nz\n" |
| 606 | 614 | inherit-windows --convert-eol-inherit "p\r\nq\r\n" "x\ny\nz\n" |
| 607 | 615 | "x\r\ny\r\nz\r\n" |
| 608 | 616 | inherit-same --convert-eol-inherit "p\nq\n" "x\ny\n" "x\ny\n" |
| 609 | 617 | } { |
| 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 | |
| 612 | 620 | } |
| 613 | 621 | |
| 614 | 622 | # Content with a zero byte after its lines keeps the bytes that follow |
| 615 | 623 | # 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 | |
| 618 | 627 | |
| 619 | 628 | # test-ci-mini leaves the checkout as it was. |
| 620 | 629 | fossil revert eol.txt |
| 621 | 630 | fossil update tip |
| 622 | 631 | |
| @@ -637,11 +646,12 @@ | ||
| 637 | 646 | foreach {blobName blobBefore blobAfter} { |
| 638 | 647 | utf16-le fffe6800e9000d000a00ac200a00 efbbbf68c3a90ae282ac0a |
| 639 | 648 | utf16-be feff006800e9000d000a20ac000a efbbbf68c3a90ae282ac0a |
| 640 | 649 | utf16-le-short fffe6800 efbbbf68 |
| 641 | 650 | utf16-be-short feff0068 efbbbf68 |
| 642 | - cp1252 63e920802081209920a020ff0d0a61 63c3a920e282ac20c28120e284a220c2a020c3bf0a61 | |
| 651 | + cp1252 63e920802081209920a020ff0d0a61 | |
| 652 | + 63c3a920e282ac20c28120e284a220c2a020c3bf0a61 | |
| 643 | 653 | cp1252-9f 9f8a0a c5b8c5a00a |
| 644 | 654 | cp1252-plain e90a c3a90a |
| 645 | 655 | cp1252-long __long__ __long__ |
| 646 | 656 | } { |
| 647 | 657 | if {$blobBefore eq "__long__"} { |
| @@ -664,13 +674,12 @@ | ||
| 664 | 674 | # byte-order mark is taken off, UTF-16 with a mark is converted, and |
| 665 | 675 | # bytes that are not UTF-8 are read as code page 1252. Each row: the |
| 666 | 676 | # bytes of the file and the bytes of the comment that must be stored, |
| 667 | 677 | # both in hexadecimal. |
| 668 | 678 | |
| 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 | |
| 672 | 681 | foreach {blobName blobFile blobComment} { |
| 673 | 682 | ascii 706c61696e 706c61696e |
| 674 | 683 | utf8 636166c3a920e282ac 636166c3a920e282ac |
| 675 | 684 | utf8-bom efbbbf636166c3a9 636166c3a9 |
| 676 | 685 | utf16-le fffe63006100e900 6361c3a9 |
| @@ -683,18 +692,17 @@ | ||
| 683 | 692 | write_file comment-subject.txt "$blobName\n" |
| 684 | 693 | fossil commit -M comment-$blobName.txt --no-warnings \ |
| 685 | 694 | --no-verify-comment comment-subject.txt |
| 686 | 695 | fossil sql "SELECT lower(hex(comment)) FROM event |
| 687 | 696 | 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 | |
| 689 | 698 | } |
| 690 | 699 | |
| 691 | 700 | # A comment typed in an editor is converted in the same way, after it |
| 692 | 701 | # is cut at a row of ten "#". The editor here is a script that writes |
| 693 | 702 | # 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] | |
| 696 | 704 | foreach {blobName blobTyped blobComment} { |
| 697 | 705 | utf8 636166c3a90a 636166c3a9 |
| 698 | 706 | cp1252 636166e920800a 636166c3a920e282ac |
| 699 | 707 | cp1252-cut 63e90a232323232323232323232063757420800a 63c3a9 |
| 700 | 708 | utf8-cut 63c3a90a232323232323232323232063757420800a 63c3a9 |
| @@ -703,23 +711,21 @@ | ||
| 703 | 711 | set ::env(FAKE_EDITOR_SCRIPT) [list set data [blob_bytes $blobTyped]] |
| 704 | 712 | fossil commit --no-warnings --no-verify-comment comment-subject.txt |
| 705 | 713 | unset ::env(FAKE_EDITOR_SCRIPT) |
| 706 | 714 | fossil sql "SELECT lower(hex(comment)) FROM event |
| 707 | 715 | 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 | |
| 709 | 717 | } |
| 710 | 718 | fossil unset editor |
| 711 | 719 | |
| 712 | 720 | ############################################################################### |
| 713 | 721 | # A diff does not show a byte-order mark, and reads UTF-16 text that has |
| 714 | 722 | # one. Each row: the bytes of the second file, in hexadecimal. The first |
| 715 | 723 | # file is "one" and "two" on two lines, and the diff must say that "2" |
| 716 | 724 | # replaces the second line. |
| 717 | 725 | |
| 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 | |
| 721 | 727 | foreach {blobName blobSecond} { |
| 722 | 728 | none 6f6e650a320a |
| 723 | 729 | utf8 efbbbf6f6e650a320a |
| 724 | 730 | utf16-le fffe6f006e0065000a0032000a00 |
| 725 | 731 | utf16-be feff006f006e0065000a0032000a |
| @@ -755,18 +761,12 @@ | ||
| 755 | 761 | ############################################################################### |
| 756 | 762 | # Web pages. The page PATH of the repository of this checkout, asked for |
| 757 | 763 | # by a local administrator with the header lines in HEADERS. |
| 758 | 764 | |
| 759 | 765 | 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] | |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | # /test-bgcolor takes a colour as "#" and three or six hexadecimal |
| 771 | 771 | # digits in lower case. Each row: what follows the "#" and whether it is |
| 772 | 772 | # a colour. |
| @@ -824,11 +824,12 @@ | ||
| 824 | 824 | test blob-xdigit-cookie-name-g {$CODE == 0 && |
| 825 | 825 | [string first "This cookie was not generated by Fossil" $blobReply] >= 0} |
| 826 | 826 | |
| 827 | 827 | # A request that announces more content than a buffer may hold is ended |
| 828 | 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:\ | |
| 829 | +write_file page-request.txt \ | |
| 830 | + "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Type:\ | |
| 830 | 831 | text/plain\r\nContent-Length: 2147483647\r\n\r\nabc" |
| 831 | 832 | file delete page-reply.txt |
| 832 | 833 | fossil_raw -seconds 60 http .rep.fossil --in page-request.txt \ |
| 833 | 834 | --out page-reply.txt --ipaddr 127.0.0.1 --localauth |
| 834 | 835 | test blob-too-large-request {$CODE == 1 && $RESULT eq "out of memory\n" && |
| @@ -887,11 +888,10 @@ | ||
| 887 | 888 | --clean "" --ignore "*" --keep "" clean-1.tmp clean-2.tmp |
| 888 | 889 | set left [lsort [glob -nocomplain clean-*.tmp]] |
| 889 | 890 | file delete clean-1.tmp clean-2.tmp |
| 890 | 891 | return $left |
| 891 | 892 | } |
| 892 | -fossil_raw clean --help | |
| 893 | 893 | foreach {blobName blobAnswer blobLeft} { |
| 894 | 894 | lower-n n {clean-1.tmp clean-2.tmp} |
| 895 | 895 | upper-n N {clean-1.tmp clean-2.tmp} |
| 896 | 896 | word-no no {clean-1.tmp clean-2.tmp} |
| 897 | 897 | lower-y y {} |
| @@ -914,12 +914,12 @@ | ||
| 914 | 914 | empty {} |
| 915 | 915 | brace \{ |
| 916 | 916 | tilde ~ |
| 917 | 917 | letter-q q |
| 918 | 918 | } { |
| 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 | |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | ############################################################################### |
| 924 | 924 | # A comment is broken into lines at a space, or after a hyphen that |
| 925 | 925 | # follows a letter. Each row: the character before the hyphen in |
| @@ -973,12 +973,13 @@ | ||
| 973 | 973 | [regexp {<<<<<<<[^\n]*\nONE\n#######} $blobMerged] && |
| 974 | 974 | [regexp {=======[^\n]*\nTWO\n>>>>>>>} $blobMerged]} |
| 975 | 975 | |
| 976 | 976 | # One side changes a line and the other adds a line after the last one, |
| 977 | 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 | |
| 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 | |
| 980 | 981 | |
| 981 | 982 | ############################################################################### |
| 982 | 983 | # With the allow-symlinks setting on, a symbolic link is checked in as the |
| 983 | 984 | # name it points to. With the setting off, the file it points to is |
| 984 | 985 | # checked in. |
| 985 | 986 |
| --- 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 @@ | ||
| 5 | 5 | # the parameters the server read from the request. |
| 6 | 6 | # |
| 7 | 7 | # Plain HTTP, the same request arriving over ssh, and SCGI. |
| 8 | 8 | # |
| 9 | 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 | 10 | test_setup |
| 16 | 11 | |
| 17 | 12 | write_file a.txt "an unversioned file\n" |
| 18 | 13 | fossil uv add a.txt |
| 19 | 14 | set cgiRepo [file join [pwd] .rep.fossil] |
| @@ -20,28 +15,18 @@ | ||
| 20 | 15 | |
| 21 | 16 | # Send the request in TEXT, a string of bytes, to the server and return |
| 22 | 17 | # the reply. ARGS are more options for "fossil http". |
| 23 | 18 | # |
| 24 | 19 | 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] | |
| 31 | 21 | } |
| 32 | 22 | |
| 33 | 23 | # The same, as a local administrator. |
| 34 | 24 | proc cgi_admin {text args} { |
| 35 | 25 | return [cgi_send $text --ipaddr 127.0.0.1 --localauth {*}$args] |
| 36 | 26 | } |
| 37 | 27 | |
| 38 | -# The status line of a reply. | |
| 39 | -proc cgi_status {reply} { | |
| 40 | - return [string trim [lindex [split $reply \n] 0]] | |
| 41 | -} | |
| 42 | - | |
| 43 | 28 | # The value of parameter NAME as /test-env shows it, or "-" if it does |
| 44 | 29 | # not show it. |
| 45 | 30 | proc cgi_param {reply name} { |
| 46 | 31 | set start [string first "\n$name = " $reply] |
| 47 | 32 | if {$start < 0} { return - } |
| @@ -49,47 +34,29 @@ | ||
| 49 | 34 | set end [string first " <br>" $reply $start] |
| 50 | 35 | if {$end < 0} { return - } |
| 51 | 36 | return [string range $reply $start [expr {$end - 1}]] |
| 52 | 37 | } |
| 53 | 38 | |
| 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"]] | |
| 83 | 49 | } |
| 84 | 50 | |
| 85 | 51 | ############################################################################### |
| 86 | 52 | # Plain HTTP. |
| 87 | 53 | |
| 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"] | |
| 89 | 56 | 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" | |
| 91 | 58 | test_eq cgi-get-plain [cgi_param $cgiReply a] 1 |
| 92 | 59 | test_eq cgi-get-plus [cgi_param $cgiReply b] "two words" |
| 93 | 60 | test_eq cgi-get-escape [cgi_param $cgiReply c] AB |
| 94 | 61 | test_eq cgi-get-empty [cgi_param $cgiReply d] "" |
| 95 | 62 | test_eq cgi-get-no-value [cgi_param $cgiReply e] "" |
| @@ -104,22 +71,26 @@ | ||
| 104 | 71 | no-method "\r\n\r\n" \ |
| 105 | 72 | bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 106 | 73 | ] { |
| 107 | 74 | set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1] |
| 108 | 75 | test cgi-malformed-$cgiName \ |
| 109 | - {[string match "HTTP/1.0 40*" [cgi_status $cgiReply]]} | |
| 76 | + {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]} | |
| 110 | 77 | } |
| 111 | 78 | |
| 112 | 79 | # A request line with no path is a request for the home page. |
| 113 | 80 | 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" | |
| 115 | 82 | |
| 116 | 83 | ############################################################################### |
| 117 | 84 | # Form data in several parts, as a browser sends an upload. |
| 118 | 85 | |
| 119 | 86 | 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"] ""] | |
| 121 | 92 | } |
| 122 | 93 | set cgiType "multipart/form-data; boundary=XB" |
| 123 | 94 | |
| 124 | 95 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 125 | 96 | "[cgi_part alpha {first value}][cgi_part upload {file body} \ |
| @@ -128,11 +99,16 @@ | ||
| 128 | 99 | test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body" |
| 129 | 100 | test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt |
| 130 | 101 | test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9 |
| 131 | 102 | |
| 132 | 103 | 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"] ""]]] | |
| 134 | 110 | test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \ |
| 135 | 111 | application/octet-stream |
| 136 | 112 | |
| 137 | 113 | # A name that begins with a capital is taken in lower case. |
| 138 | 114 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| @@ -146,11 +122,14 @@ | ||
| 146 | 122 | test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value |
| 147 | 123 | |
| 148 | 124 | # A part with no closing boundary after a long one ends at the end of the |
| 149 | 125 | # request, and every part is read within the request. |
| 150 | 126 | 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"] ""]]] | |
| 152 | 131 | test cgi-multipart-unclosed {$CODE == 0} |
| 153 | 132 | test_eq cgi-multipart-unclosed-first \ |
| 154 | 133 | [string length [cgi_param $cgiReply alpha]] 3000 |
| 155 | 134 | test_eq cgi-multipart-unclosed-second [cgi_param $cgiReply beta] \ |
| 156 | 135 | "no closing boundary" |
| @@ -163,19 +142,36 @@ | ||
| 163 | 142 | "--XB" \ |
| 164 | 143 | "--XB\r\n" \ |
| 165 | 144 | "--XB\r\n\r\nno name here\r\n--XB--\r\n" \ |
| 166 | 145 | "--XB\r\nContent-Disposition: form-data; name=\"a\"" \ |
| 167 | 146 | "[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\""] ""] \ | |
| 171 | 157 | "[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"] ""] \ | |
| 174 | 165 | "--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"] ""] \ | |
| 177 | 173 | "[cgi_part a "\n--X"]--XB--\r\n" \ |
| 178 | 174 | ] { |
| 179 | 175 | incr cgiI |
| 180 | 176 | cgi_admin [cgi_post $cgiType $cgiBody] |
| 181 | 177 | test cgi-multipart-odd-$cgiI {$CODE == 0} |
| @@ -190,12 +186,14 @@ | ||
| 190 | 186 | ############################################################################### |
| 191 | 187 | # The date in an If-Modified-Since header. A file that has not changed |
| 192 | 188 | # since that date is not sent again. |
| 193 | 189 | |
| 194 | 190 | 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] | |
| 197 | 195 | } |
| 198 | 196 | test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \ |
| 199 | 197 | "HTTP/1.0 304 Not Modified" |
| 200 | 198 | test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \ |
| 201 | 199 | "HTTP/1.0 200 OK" |
| @@ -220,24 +218,29 @@ | ||
| 220 | 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 |
| 221 | 219 | g.ico 1 g.png 0 g.zip 0 g.pdf 0 |
| 222 | 220 | } { |
| 223 | 221 | write_file $cgiName [string repeat "content to compress\n" 50] |
| 224 | 222 | 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] | |
| 226 | 227 | test_eq cgi-gzip-$cgiName \ |
| 227 | 228 | [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip |
| 228 | 229 | } |
| 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" | |
| 231 | 233 | && ![string match "*Content-Encoding*" $cgiReply]} |
| 232 | 234 | |
| 233 | 235 | ############################################################################### |
| 234 | 236 | # A POST whose Referer is another site is not taken as safe from forgery, |
| 235 | 237 | # and is written to the error log. |
| 236 | 238 | |
| 237 | 239 | 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]] | |
| 239 | 242 | } |
| 240 | 243 | file delete err.log |
| 241 | 244 | cgi_logout http://x/login |
| 242 | 245 | test cgi-same-origin-not-logged {![file exists err.log] |
| 243 | 246 | || ![string match "*different origin*" [read_file err.log]]} |
| @@ -257,11 +260,11 @@ | ||
| 257 | 260 | set cgiReply [cgi_send [cgi_scgi { |
| 258 | 261 | CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1 |
| 259 | 262 | PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80 |
| 260 | 263 | REMOTE_ADDR 127.0.0.1 |
| 261 | 264 | }] --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" | |
| 263 | 266 | test_eq cgi-scgi-param [cgi_param $cgiReply s] 1 |
| 264 | 267 | |
| 265 | 268 | foreach {cgiName cgiRequest} [list \ |
| 266 | 269 | too-short "15:CONTENT_LENGTH\0000\000," \ |
| 267 | 270 | cut-short "40:CONTENT_LENGTH\0000\000," \ |
| @@ -268,20 +271,21 @@ | ||
| 268 | 271 | no-zero "20:CONTENT_LENGTH0000000000," \ |
| 269 | 272 | huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \ |
| 270 | 273 | ] { |
| 271 | 274 | set cgiReply [cgi_send $cgiRequest --scgi] |
| 272 | 275 | 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]]} | |
| 274 | 277 | } |
| 275 | 278 | |
| 276 | 279 | ############################################################################### |
| 277 | 280 | # The same reader for a request that arrives over ssh, which the server |
| 278 | 281 | # knows from SSH_CONNECTION. It reads the client's probes first. |
| 279 | 282 | |
| 280 | 283 | 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" | |
| 283 | 287 | test_eq cgi-ssh-param [cgi_param $cgiReply q] 1 |
| 284 | 288 | test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1 |
| 285 | 289 | |
| 286 | 290 | set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \ |
| 287 | 291 | "p=posted"] --localauth] |
| @@ -288,11 +292,14 @@ | ||
| 288 | 292 | test_eq cgi-ssh-post [cgi_param $cgiReply p] posted |
| 289 | 293 | |
| 290 | 294 | # An older client opens the connection with "echo" probes, each of which |
| 291 | 295 | # the server answers with the word it was given, and then names the |
| 292 | 296 | # 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] | |
| 294 | 301 | test cgi-ssh-probes {[string match "test1\nprobe-2\n*" $cgiReply] |
| 295 | 302 | && [string match "*\nHTTP/1.0 200 OK*" $cgiReply]} |
| 296 | 303 | test_eq cgi-ssh-probes-param [cgi_param $cgiReply q] 3 |
| 297 | 304 | foreach {cgiName cgiRequest} [list \ |
| 298 | 305 | probe-word "echo hello\n" \ |
| @@ -312,18 +319,26 @@ | ||
| 312 | 319 | ] { |
| 313 | 320 | cgi_send $cgiRequest |
| 314 | 321 | test cgi-ssh-$cgiName {$CODE == 0 || $CODE == 1} |
| 315 | 322 | } |
| 316 | 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 | +} | |
| 317 | 332 | |
| 318 | 333 | ############################################################################### |
| 319 | 334 | # Names and values in a query string and in a Cookie header. A name is |
| 320 | 335 | # taken when it begins with a letter and holds only letters, digits, |
| 321 | 336 | # "_" and "-"; of two values with one name the first is kept; a value |
| 322 | 337 | # from the query string that holds a control character is dropped. |
| 323 | 338 | |
| 324 | -set cgiReply [cgi_admin [cgi_get \ | |
| 339 | +set cgiReply [cgi_admin [request_get \ | |
| 325 | 340 | "/test-env?e&a=1&=5&&a\$b=6&c=%01x&1a=2&_u=3&a=second&Up=4&zz" \ |
| 326 | 341 | [list "Cookie: ck=1; sp=2; fossil-x=9; Big=3"]]] |
| 327 | 342 | foreach {cgiName cgiParam cgiValue} { |
| 328 | 343 | no-value-first e "" |
| 329 | 344 | plain a 1 |
| @@ -342,11 +357,11 @@ | ||
| 342 | 357 | } { |
| 343 | 358 | test_eq cgi-names-$cgiName [cgi_param $cgiReply $cgiParam] $cgiValue |
| 344 | 359 | } |
| 345 | 360 | |
| 346 | 361 | # 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 \ | |
| 348 | 363 | [list "Cookie: ck=1; fossil-x=9"]]] |
| 349 | 364 | test_eq cgi-showall-cookie [cgi_param $cgiReply fossil-x] 9 |
| 350 | 365 | test_eq cgi-showall-header [cgi_param $cgiReply HTTP_COOKIE] "ck=1; fossil-x=9" |
| 351 | 366 | |
| 352 | 367 | # A value in a form may hold a control character. |
| @@ -362,11 +377,16 @@ | ||
| 362 | 377 | && [string match "*Too many query parameters*" $cgiReply$RESULT]} |
| 363 | 378 | |
| 364 | 379 | ############################################################################### |
| 365 | 380 | # The request line and the header lines. |
| 366 | 381 | |
| 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"] ""]] | |
| 368 | 388 | foreach {cgiParam cgiValue} { |
| 369 | 389 | HTTP_HOST named.example:8080 |
| 370 | 390 | SERVER_NAME named.example |
| 371 | 391 | HTTP_IF_NONE_MATCH tag |
| 372 | 392 | HTTP_AUTHORIZATION {Basic eDp5} |
| @@ -378,12 +398,12 @@ | ||
| 378 | 398 | test_eq cgi-header-$cgiParam [cgi_param $cgiReply $cgiParam] $cgiValue |
| 379 | 399 | } |
| 380 | 400 | |
| 381 | 401 | # An "Https:" header says that the request came by https, so the reply |
| 382 | 402 | # 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] \ | |
| 385 | 405 | https://x/login?g=test-env |
| 386 | 406 | |
| 387 | 407 | # X-Forwarded-For names the client when the request comes from this |
| 388 | 408 | # machine: the last address in it is taken. From any other machine the |
| 389 | 409 | # header is ignored. Only a local client sees /test-env here. |
| @@ -394,34 +414,44 @@ | ||
| 394 | 414 | mapped 127.0.0.1 ::ffff:127.0.0.1 ::ffff:127.0.0.1 |
| 395 | 415 | remote 127.0.0.1 {127.0.0.1, 9.9.9.9} - |
| 396 | 416 | empty 127.0.0.1 {} - |
| 397 | 417 | not-local 10.0.0.1 127.0.0.1 - |
| 398 | 418 | } { |
| 399 | - set cgiReply [cgi_send [cgi_get /test-env \ | |
| 419 | + set cgiReply [cgi_send [request_get /test-env \ | |
| 400 | 420 | [list "X-Forwarded-For: $cgiForwarded"]] --ipaddr $cgiFrom --localauth] |
| 401 | 421 | test_eq cgi-forwarded-$cgiName [cgi_param $cgiReply REMOTE_ADDR] $cgiAddr |
| 402 | 422 | } |
| 403 | 423 | |
| 404 | 424 | # 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] "" | |
| 409 | 429 | |
| 410 | 430 | # A POST must say how long its content is, and send that much. |
| 411 | 431 | 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" | |
| 413 | 433 | && [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" | |
| 416 | 440 | && [string match "*Wanted 50 bytes but got only 3*" $cgiReply]} |
| 417 | 441 | # 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" | |
| 420 | 445 | && [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"] ""]] | |
| 423 | 453 | test cgi-post-length-$cgiName {$CODE == 0 |
| 424 | 454 | && [regexp {^HTTP/1.0 (200|400) } $cgiReply]} |
| 425 | 455 | } |
| 426 | 456 | |
| 427 | 457 | ############################################################################### |
| @@ -429,22 +459,22 @@ | ||
| 429 | 459 | # asked for, not compressed, with status 206. |
| 430 | 460 | |
| 431 | 461 | write_file r.css 0123456789abcdefghij |
| 432 | 462 | fossil uv add r.css |
| 433 | 463 | 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 \ | |
| 435 | 465 | [list "Range: $range" "Accept-Encoding: gzip"] $method] \ |
| 436 | 466 | --ipaddr 127.0.0.1] |
| 437 | 467 | } |
| 438 | 468 | 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 | |
| 444 | 474 | 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 | |
| 446 | 476 | # A range that is not two numbers in order is ignored. |
| 447 | 477 | foreach {cgiName cgiRange} { |
| 448 | 478 | word bytes=abc |
| 449 | 479 | one-number bytes=5- |
| 450 | 480 | negative bytes=-5-10 |
| @@ -451,36 +481,36 @@ | ||
| 451 | 481 | backwards bytes=9-3 |
| 452 | 482 | other-unit lines=1-2 |
| 453 | 483 | } { |
| 454 | 484 | set cgiReply [cgi_range $cgiRange] |
| 455 | 485 | 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"} | |
| 458 | 488 | } |
| 459 | 489 | # A range that runs past the end of the file stops at the end. |
| 460 | 490 | 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] \ | |
| 463 | 493 | "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 | |
| 465 | 495 | # A range that starts at or after the end gets 416 and no content. |
| 466 | 496 | foreach {cgiName cgiRange} {at-end bytes=20-20 after-end bytes=25-30} { |
| 467 | 497 | set cgiReply [cgi_range $cgiRange] |
| 468 | 498 | 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"} | |
| 472 | 502 | } |
| 473 | 503 | # A number too large for an int is not taken as a smaller one. |
| 474 | 504 | 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" | |
| 476 | 506 | # 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"]] \ | |
| 478 | 508 | --ipaddr 127.0.0.1] |
| 479 | 509 | 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]]} | |
| 482 | 512 | |
| 483 | 513 | ############################################################################### |
| 484 | 514 | # More shapes of form data in several parts. |
| 485 | 515 | |
| 486 | 516 | proc cgi_form {body} { |
| @@ -497,58 +527,87 @@ | ||
| 497 | 527 | set cgiReply [cgi_form "[cgi_part Shout loud]--XB--\r\n"] |
| 498 | 528 | test_eq cgi-multipart-upper-plain [cgi_param $cgiReply shout] loud |
| 499 | 529 | test_eq cgi-multipart-upper-no-bytes [cgi_param $cgiReply shout:bytes] - |
| 500 | 530 | |
| 501 | 531 | # 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"] ""]] | |
| 503 | 538 | test_eq cgi-multipart-upper-mimetype [cgi_param $cgiReply typed:mimetype] \ |
| 504 | 539 | text/x-test |
| 505 | 540 | test_eq cgi-multipart-upper-bytes [cgi_param $cgiReply typed:bytes] 1 |
| 506 | 541 | |
| 507 | 542 | # A name that does not begin with a letter is not taken, with or without |
| 508 | 543 | # 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"] ""]] | |
| 510 | 550 | test_eq cgi-multipart-digit-name [cgi_param $cgiReply 1st] - |
| 511 | 551 | test_eq cgi-multipart-digit-filename [cgi_param $cgiReply 1st:filename] - |
| 512 | 552 | test_eq cgi-multipart-digit-mimetype [cgi_param $cgiReply 1st:mimetype] - |
| 513 | 553 | test_eq cgi-multipart-digit-next [cgi_param $cgiReply after] ok |
| 514 | 554 | |
| 515 | 555 | # 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"] ""]] | |
| 517 | 561 | test_eq cgi-multipart-type-first-value [cgi_param $cgiReply late] v |
| 518 | 562 | test_eq cgi-multipart-type-first-mimetype [cgi_param $cgiReply late:mimetype] - |
| 519 | 563 | test_eq cgi-multipart-type-first-filename [cgi_param $cgiReply late:filename] - |
| 520 | 564 | |
| 521 | 565 | # 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"] ""]] | |
| 523 | 571 | test_eq cgi-multipart-unknown-words [cgi_param $cgiReply known] v |
| 524 | 572 | |
| 525 | 573 | # A quoted word that reaches the end of a header line without a closing |
| 526 | 574 | # 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"] ""] | |
| 528 | 579 | write_file request.txt [cgi_post $cgiType $cgiBody] |
| 529 | 580 | file delete reply.txt |
| 530 | 581 | fossil_raw -seconds 15 http $cgiRepo --in request.txt --out reply.txt \ |
| 531 | 582 | --ipaddr 127.0.0.1 --localauth |
| 532 | 583 | test cgi-multipart-lone-quote {$CODE == 0} |
| 533 | 584 | |
| 534 | 585 | # Only the first 49 words of a header line are read. |
| 535 | 586 | 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"] ""]] | |
| 538 | 594 | test_eq cgi-multipart-many-words [cgi_param $cgiReply far] - |
| 539 | 595 | test_eq cgi-multipart-many-words-next [cgi_param $cgiReply after] ok |
| 540 | 596 | |
| 541 | 597 | # A quote that ends a header line after a space is a word of no |
| 542 | 598 | # 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" | |
| 545 | 604 | && [cgi_param $cgiReply after] eq "ok"} |
| 546 | 605 | |
| 547 | 606 | # Content that begins with a zero byte has no parts. |
| 548 | 607 | 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" | |
| 550 | 609 | && [cgi_param $cgiReply a] eq "-"} |
| 551 | 610 | |
| 552 | 611 | ############################################################################### |
| 553 | 612 | # More dates in If-Modified-Since. The file is given the time that the |
| 554 | 613 | # date stands for and is then not sent again; one second newer and it is. |
| @@ -557,13 +616,14 @@ | ||
| 557 | 616 | fossil uv add d.bin |
| 558 | 617 | proc cgi_since_exact {date seconds} { |
| 559 | 618 | set result "" |
| 560 | 619 | foreach mtime [list $seconds [expr {$seconds + 1}]] { |
| 561 | 620 | 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"]] \ | |
| 563 | 623 | --ipaddr 127.0.0.1] |
| 564 | - lappend result [lindex [cgi_status $reply] 1] | |
| 624 | + lappend result [lindex [reply_status $reply] 1] | |
| 565 | 625 | } |
| 566 | 626 | return $result |
| 567 | 627 | } |
| 568 | 628 | foreach {cgiName cgiDate cgiSeconds} { |
| 569 | 629 | epoch-year "Thu, 01 Jan 1970 00:00:10 GMT" 10 |
| @@ -594,13 +654,13 @@ | ||
| 594 | 654 | second-61 "Mon, 01 Jan 2026 00:00:61 GMT" |
| 595 | 655 | month "Mon, 01 Foo 2026 00:00:00 GMT" |
| 596 | 656 | short "Mon, 01 Jan 2026" |
| 597 | 657 | empty "" |
| 598 | 658 | } { |
| 599 | - set cgiReply [cgi_send [cgi_get /uv/d.bin \ | |
| 659 | + set cgiReply [cgi_send [request_get /uv/d.bin \ | |
| 600 | 660 | [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] \ | |
| 602 | 662 | "HTTP/1.0 200 OK" |
| 603 | 663 | } |
| 604 | 664 | |
| 605 | 665 | ############################################################################### |
| 606 | 666 | # Redirects. A redirect to an absolute URL is sent as it is; a redirect |
| @@ -610,12 +670,12 @@ | ||
| 610 | 670 | # the user-edit cancel button. |
| 611 | 671 | |
| 612 | 672 | proc cgi_redirect_to {query {referer none}} { |
| 613 | 673 | set headers {} |
| 614 | 674 | 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] | |
| 617 | 677 | } |
| 618 | 678 | # The cancel button redirects to the referer. |
| 619 | 679 | test_eq cgi-redirect-absolute-http [cgi_redirect_to can=1 http://other/p] \ |
| 620 | 680 | http://other/p |
| 621 | 681 | test_eq cgi-redirect-absolute-https [cgi_redirect_to can=1 https://other/p] \ |
| @@ -639,63 +699,64 @@ | ||
| 639 | 699 | proc cgi_csrf_level {reply} { |
| 640 | 700 | if {[regexp {CSRF safety = ([^<]*)} $reply all level]} { return $level } |
| 641 | 701 | return - |
| 642 | 702 | } |
| 643 | 703 | set cgiToken "" |
| 644 | -set cgiReply [cgi_admin [cgi_get /setup_uedit?id=0]] | |
| 704 | +set cgiReply [cgi_admin [request_get /setup_uedit?id=0]] | |
| 645 | 705 | regexp {name="csrf" value="([^"]*)"} $cgiReply all cgiToken |
| 646 | 706 | |
| 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"]]] | |
| 648 | 708 | test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin" |
| 649 | 709 | 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]] | |
| 651 | 711 | } |
| 652 | 712 | 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" | |
| 654 | 715 | set cgiReply [cgi_env_post "csrf=wrong"] |
| 655 | 716 | test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST" |
| 656 | 717 | set cgiReply [cgi_env_post "x=1" http://elsewhere/p] |
| 657 | 718 | test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe" |
| 658 | 719 | |
| 659 | 720 | # A page that consults the check more than once. A cross-origin POST to |
| 660 | 721 | # 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" | |
| 663 | 725 | # A valid same-origin POST with the token creates the user. |
| 664 | 726 | 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} | |
| 668 | 733 | |
| 669 | 734 | # The user-edit page needs "login", "info", "pw" and "apply" to make a |
| 670 | 735 | # change. A request with "login" alone changes nothing. |
| 671 | 736 | 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] | |
| 673 | 738 | test cgi-all-needs-every-field \ |
| 674 | 739 | {[fossil sql "SELECT count(*) FROM user WHERE login='cgighost'"] == 0} |
| 675 | 740 | |
| 676 | 741 | ############################################################################### |
| 677 | 742 | # Request methods and the same reader over ssh. |
| 678 | 743 | |
| 679 | -# A POST over ssh reaches the parameter decoder. | |
| 680 | 744 | 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 | 745 | # 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" | |
| 687 | 748 | unset ::env(SSH_CONNECTION) |
| 688 | 749 | |
| 689 | 750 | ############################################################################### |
| 690 | 751 | # cgi_from_mobile, used by /forum to pick a default display order. An |
| 691 | 752 | # iPad is not treated as mobile; another phone is; no agent is not. |
| 692 | 753 | proc cgi_forum_order {agent} { |
| 693 | 754 | set headers {} |
| 694 | 755 | 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] | |
| 697 | 758 | } |
| 698 | 759 | foreach {cgiName cgiAgent} { |
| 699 | 760 | phone "Mozilla/5.0 (iPhone; Mobile) Safari" |
| 700 | 761 | ipad "Mozilla/5.0 (iPad) Safari" |
| 701 | 762 | none "" |
| @@ -709,47 +770,44 @@ | ||
| 709 | 770 | # and a note in the error log. The whole request environment is written |
| 710 | 771 | # to the log. |
| 711 | 772 | |
| 712 | 773 | proc cgi_attack {value} { |
| 713 | 774 | 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"] ""] | |
| 715 | 779 | file delete reply.txt attack.log |
| 716 | 780 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 717 | 781 | --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log] |
| 718 | 782 | return [expr {[file exists reply.txt] ? [read_file reply.txt] : ""}] |
| 719 | 783 | } |
| 720 | 784 | 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" | |
| 722 | 786 | test cgi-attack-logged {[file exists attack.log] |
| 723 | 787 | && [string match "*possible hack attempt*" [read_file attack.log]] |
| 724 | 788 | && [string match "*QUERY_STRING = inj=1;select*" [read_file attack.log]]} |
| 725 | 789 | # A value longer than 100 characters is shortened in the log. |
| 726 | 790 | 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" | |
| 728 | 792 | && [string match "*aaa...*" [read_file attack.log]]} |
| 729 | 793 | # 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" | |
| 732 | 796 | |
| 733 | 797 | ############################################################################### |
| 734 | 798 | # The same-origin test with crafted Referer headers. The base URL here |
| 735 | 799 | # is "http://x". A Referer that shares the base but has more path after |
| 736 | 800 | # it with no "/" boundary is a different origin. A Referer with a "%" |
| 737 | 801 | # escape is decoded before the comparison. The /test-env page reports |
| 738 | 802 | # the result. |
| 739 | 803 | |
| 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" | |
| 747 | 806 | set reply [cgi_admin $req] |
| 748 | 807 | return [cgi_csrf_level $reply] |
| 749 | 808 | } |
| 750 | -test_eq cgi-origin-same [cgi_origin http://x/page] "Same origin" | |
| 751 | 809 | test_eq cgi-origin-boundary [cgi_origin http://xtra/page] unsafe |
| 752 | 810 | test_eq cgi-origin-escaped [cgi_origin http://x/a%2Fb] "Same origin" |
| 753 | 811 | # A different-origin GET reaches the method test in the same-origin check |
| 754 | 812 | # without writing a warning (the warning is for POST only). |
| 755 | 813 | test_eq cgi-origin-get-other [cgi_origin http://elsewhere/p] unsafe |
| @@ -756,36 +814,37 @@ | ||
| 756 | 814 | |
| 757 | 815 | ############################################################################### |
| 758 | 816 | # cgi_parameter_name walks every parameter: the ticket-entry page copies |
| 759 | 817 | # each into its interpreter. |
| 760 | 818 | |
| 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" | |
| 763 | 821 | |
| 764 | 822 | ############################################################################### |
| 765 | 823 | # cgi_param_info walks the parameters for the /cookies page. |
| 766 | 824 | |
| 767 | -set cgiReply [cgi_admin [cgi_get /cookies \ | |
| 825 | +set cgiReply [cgi_admin [request_get /cookies \ | |
| 768 | 826 | [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" | |
| 770 | 828 | && [string match "*fossil_display_settings*" $cgiReply]} |
| 771 | 829 | |
| 772 | 830 | ############################################################################### |
| 773 | 831 | # Two more destinations for cgi_print_all. With --cgitrace the whole |
| 774 | 832 | # parameter set is traced before the page runs. |
| 775 | 833 | |
| 776 | -write_file request.txt [cgi_get "/test-env?traced=1"] | |
| 834 | +write_file request.txt [request_get "/test-env?traced=1"] | |
| 777 | 835 | file delete reply.txt |
| 778 | 836 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 779 | 837 | --ipaddr 127.0.0.1 --localauth --cgitrace |
| 780 | 838 | test cgi-cgitrace {$CODE == 0 |
| 781 | 839 | && [string match "*Calling*" $RESULT] |
| 782 | 840 | && [string match "*traced = 1*" $RESULT]} |
| 783 | 841 | |
| 784 | 842 | # A CGI control file with "cgi-debug:" writes the environment to a debug |
| 785 | 843 | # 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" | |
| 787 | 846 | file delete debug.txt |
| 788 | 847 | set ::env(REQUEST_METHOD) GET |
| 789 | 848 | set ::env(SCRIPT_NAME) "" |
| 790 | 849 | set ::env(PATH_INFO) /test-env |
| 791 | 850 | set ::env(QUERY_STRING) "dbg=1" |
| @@ -802,37 +861,49 @@ | ||
| 802 | 861 | # email-alert subscription page. The page exists once email is enabled |
| 803 | 862 | # and its tables are built. |
| 804 | 863 | |
| 805 | 864 | fossil settings email-send-method db |
| 806 | 865 | 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] | |
| 808 | 868 | 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} | |
| 810 | 871 | |
| 811 | 872 | # 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" | |
| 814 | 875 | && [string match "*checkbox*" $cgiReply]} |
| 815 | 876 | |
| 816 | 877 | # A submitted subscription: the name is trimmed and the boxes are read as |
| 817 | 878 | # 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" | |
| 822 | 888 | 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]'"]]} | |
| 824 | 891 | |
| 825 | 892 | ############################################################################### |
| 826 | 893 | # The HTTP reader is called in a loop for a request arriving over ssh. |
| 827 | 894 | # When the first request announces the Fossil ssh transport, the reader |
| 828 | 895 | # is called again for a second request in the same connection, and the |
| 829 | 896 | # later request updates the parameters that the first one set. |
| 830 | 897 | |
| 831 | 898 | set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" |
| 832 | 899 | 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"] ""] | |
| 834 | 905 | file delete reply.txt |
| 835 | 906 | fossil_raw http $cgiRepo --in request.txt --out reply.txt --localauth |
| 836 | 907 | set cgiReply [read_file reply.txt] |
| 837 | 908 | test cgi-ssh-transport-first {[string match "*first = 1*" $cgiReply]} |
| 838 | 909 | test cgi-ssh-transport-second {[string match "*second = 2*" $cgiReply]} |
| @@ -841,24 +912,25 @@ | ||
| 841 | 912 | ############################################################################### |
| 842 | 913 | # The skin query parameter sets a cookie with a default path, and marks |
| 843 | 914 | # the request "udc" unless "once" is present. A cookie carrying a login |
| 844 | 915 | # card is taken out of the parameters. |
| 845 | 916 | |
| 846 | -set cgiReply [cgi_admin [cgi_get /test-env?skin=darkmode]] | |
| 917 | +set cgiReply [cgi_admin [request_get /test-env?skin=darkmode]] | |
| 847 | 918 | test cgi-skin-cookie {[string match "*Set-Cookie: fossil_display_settings=*" \ |
| 848 | 919 | $cgiReply] && [cgi_param $cgiReply udc] eq 1} |
| 849 | 920 | # 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}]] | |
| 851 | 922 | test cgi-skin-once {![string match "*Set-Cookie: fossil_display_settings=*" \ |
| 852 | 923 | $cgiReply] && [cgi_param $cgiReply udc] eq "-"} |
| 853 | 924 | # 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 \ | |
| 855 | 926 | [list "Cookie: fossil_display_settings=skin=ardoise"]]] |
| 856 | 927 | test_eq cgi-skin-from-cookie [cgi_param $cgiReply fossil_display_settings] \ |
| 857 | 928 | skin=ardoise |
| 858 | 929 | # 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"]]] | |
| 860 | 932 | test_eq cgi-login-card-hidden [cgi_param $cgiReply x-f-l-c] - |
| 861 | 933 | |
| 862 | 934 | ############################################################################### |
| 863 | 935 | # The reply content type for an unversioned file comes from the |
| 864 | 936 | # "mimetypes" setting. Parsing of the type stops at the first character |
| @@ -865,19 +937,19 @@ | ||
| 865 | 937 | # outside the range "+" through "z", and a text type is compressed. |
| 866 | 938 | |
| 867 | 939 | fossil settings mimetypes "zw text/x|y" |
| 868 | 940 | write_file f.zw "other text to send" |
| 869 | 941 | 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] | |
| 871 | 943 | 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]]} | |
| 873 | 945 | |
| 874 | 946 | ############################################################################### |
| 875 | 947 | # A skin name that is not a known skin produces an error, so the cookie |
| 876 | 948 | # is not written. |
| 877 | 949 | |
| 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]] | |
| 879 | 951 | test cgi-skin-unknown {![string match "*Set-Cookie: fossil_display_settings=*" \ |
| 880 | 952 | $cgiReply] && [cgi_param $cgiReply skin] eq "no_such_skin_here"} |
| 881 | 953 | |
| 882 | 954 | ############################################################################### |
| 883 | 955 | # Deleting a cookie: the reply carries a Set-Cookie with a value of |
| @@ -913,13 +985,13 @@ | ||
| 913 | 985 | fossil commit -m "add art" --no-warnings |
| 914 | 986 | set cgiArt [fossil sql \ |
| 915 | 987 | "SELECT uuid FROM blob WHERE rid=(SELECT max(rid) FROM blob)"] |
| 916 | 988 | proc cgi_raw_type {mime} { |
| 917 | 989 | global cgiArt |
| 918 | - set reply [cgi_send [cgi_get /raw/$cgiArt?m=$mime \ | |
| 990 | + set reply [cgi_send [request_get /raw/$cgiArt?m=$mime \ | |
| 919 | 991 | [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth] |
| 920 | - return [cgi_header $reply Content-Encoding] | |
| 992 | + return [reply_header $reply Content-Encoding] | |
| 921 | 993 | } |
| 922 | 994 | foreach {cgiName cgiMime} { |
| 923 | 995 | javascript application/javascript |
| 924 | 996 | json application/json |
| 925 | 997 | wasm application/wasm |
| @@ -945,46 +1017,48 @@ | ||
| 945 | 1017 | } |
| 946 | 1018 | # With --nocompress nothing is compressed. |
| 947 | 1019 | set cgiFile [fossil sql "SELECT uuid FROM blob, mlink, filename |
| 948 | 1020 | WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid |
| 949 | 1021 | 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 \ | |
| 951 | 1023 | [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"} | |
| 955 | 1028 | |
| 956 | 1029 | ############################################################################### |
| 957 | 1030 | # More about ranges. A Range header counts only for GET, and not for |
| 958 | 1031 | # content of the type that a sync uses. Part of an artifact named by its |
| 959 | 1032 | # full hash, sent to a visitor who is not logged in, may be kept by the |
| 960 | 1033 | # client for ever. |
| 961 | 1034 | |
| 962 | 1035 | 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 "-"} | |
| 965 | 1038 | 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 \ | |
| 969 | 1042 | [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 \ | |
| 973 | 1046 | [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] \ | |
| 976 | 1049 | "max-age=315360000, immutable" |
| 977 | 1050 | |
| 978 | 1051 | ############################################################################### |
| 979 | 1052 | # The "at" parameter of /raw names the file for the client to save the |
| 980 | 1053 | # content in. Only its last path element is used, and every character |
| 981 | 1054 | # in it other than a letter, a digit, "." and "-" becomes "_". |
| 982 | 1055 | |
| 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"] \ | |
| 984 | 1058 | --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] \ | |
| 986 | 1060 | {attachment; filename="my_file-1_.txt";} |
| 987 | 1061 | |
| 988 | 1062 | ############################################################################### |
| 989 | 1063 | # A request that is refused before any repository is open: the server is |
| 990 | 1064 | # given a directory, and the request has a method it does not know. |
| @@ -993,11 +1067,11 @@ | ||
| 993 | 1067 | write_file request.txt "DELETE /x HTTP/1.1\r\nHost: x\r\n\r\n" |
| 994 | 1068 | file delete reply.txt |
| 995 | 1069 | fossil_raw http [file join [pwd] norepo] --in request.txt --out reply.txt \ |
| 996 | 1070 | --ipaddr 127.0.0.1 |
| 997 | 1071 | 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"} | |
| 999 | 1073 | |
| 1000 | 1074 | ############################################################################### |
| 1001 | 1075 | # More of the same-origin test: a Referer that is the base URL and |
| 1002 | 1076 | # nothing more is the same origin. |
| 1003 | 1077 | |
| @@ -1007,19 +1081,18 @@ | ||
| 1007 | 1081 | # With --httptrace the server reports each parameter as it is set and |
| 1008 | 1082 | # copies the request into a file named httplog-NNNNN.txt in the current |
| 1009 | 1083 | # directory. If it cannot make that file it says so and goes on. |
| 1010 | 1084 | |
| 1011 | 1085 | 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] | |
| 1013 | 1087 | file delete reply.txt |
| 1014 | 1088 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 1015 | 1089 | --ipaddr 127.0.0.1 --localauth --httptrace |
| 1016 | 1090 | 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} | |
| 1021 | 1094 | if {[llength $cgiLogs] == 1} { |
| 1022 | 1095 | set cgiLogText [read_file [lindex $cgiLogs 0]] |
| 1023 | 1096 | test cgi-httptrace-log { |
| 1024 | 1097 | [string match "GET /test-env?traced=2 HTTP/1.1*Host: x*" $cgiLogText]} |
| 1025 | 1098 | file delete [lindex $cgiLogs 0] |
| @@ -1035,11 +1108,11 @@ | ||
| 1035 | 1108 | file delete $cgiLog |
| 1036 | 1109 | } |
| 1037 | 1110 | test cgi-httptrace-post-content {[string match "*body=sent" $cgiLogText]} |
| 1038 | 1111 | test cgi-httptrace-post-header \ |
| 1039 | 1112 | {[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] | |
| 1041 | 1114 | if {$::tcl_platform(platform) eq "unix"} { |
| 1042 | 1115 | set cgiHere [pwd] |
| 1043 | 1116 | file mkdir readonly |
| 1044 | 1117 | file attributes readonly -permissions 0555 |
| 1045 | 1118 | cd readonly |
| @@ -1048,54 +1121,55 @@ | ||
| 1048 | 1121 | --ipaddr 127.0.0.1 --localauth --httptrace |
| 1049 | 1122 | cd $cgiHere |
| 1050 | 1123 | file attributes readonly -permissions 0755 |
| 1051 | 1124 | test cgi-httptrace-no-log {$CODE == 0 |
| 1052 | 1125 | && [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"} | |
| 1054 | 1127 | } |
| 1055 | 1128 | |
| 1056 | 1129 | ############################################################################### |
| 1057 | 1130 | # A request for the top of the site is sent on to the index page. A |
| 1058 | 1131 | # login-card cookie in such a request is taken once. |
| 1059 | 1132 | |
| 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 | |
| 1062 | 1135 | |
| 1063 | 1136 | ############################################################################### |
| 1064 | 1137 | # The honeypot page offers a visitor who is not logged in a captcha, and |
| 1065 | 1138 | # keeps the URL that was asked for, with its query parameters, in a |
| 1066 | 1139 | # cookie. |
| 1067 | 1140 | |
| 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] | |
| 1069 | 1142 | test cgi-original-url {[string first \ |
| 1070 | 1143 | "Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fa%3D1%26b%26c%3Dtwo;" \ |
| 1071 | 1144 | $cgiReply] >= 0} |
| 1072 | 1145 | |
| 1073 | 1146 | ############################################################################### |
| 1074 | 1147 | # The "ss" parameter of /timeline is checked for an attack as soon as it |
| 1075 | 1148 | # is read, for a visitor who is not logged in. |
| 1076 | 1149 | |
| 1077 | -write_file request.txt [cgi_get "/timeline?ss=1;select"] | |
| 1150 | +write_file request.txt [request_get "/timeline?ss=1;select"] | |
| 1078 | 1151 | file delete reply.txt attack.log |
| 1079 | 1152 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 1080 | 1153 | --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log] |
| 1081 | 1154 | 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" | |
| 1083 | 1156 | && [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" | |
| 1086 | 1160 | |
| 1087 | 1161 | ############################################################################### |
| 1088 | 1162 | # SSH_CONNECTION names the client only when it holds an address followed |
| 1089 | 1163 | # by a space. Otherwise the request is read as plain HTTP from an |
| 1090 | 1164 | # unknown address, which --localauth does not log in. |
| 1091 | 1165 | |
| 1092 | 1166 | foreach {cgiName cgiValue} {empty "" one-word nospace} { |
| 1093 | 1167 | 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] | |
| 1095 | 1169 | 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] \ | |
| 1097 | 1171 | http://x/login?g=test-env |
| 1098 | 1172 | } |
| 1099 | 1173 | |
| 1100 | 1174 | ############################################################################### |
| 1101 | 1175 | # SCGI: SCRIPT_NAME, PATH_INFO and REQUEST_URI. The server needs |
| @@ -1111,13 +1185,13 @@ | ||
| 1111 | 1185 | proc cgi_scgi_names {pairs} { |
| 1112 | 1186 | set reply [cgi_send [cgi_scgi [concat { |
| 1113 | 1187 | CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SERVER_NAME x SERVER_PORT 80 |
| 1114 | 1188 | REMOTE_ADDR 127.0.0.1 |
| 1115 | 1189 | } $pairs]] --scgi --localauth] |
| 1116 | - set status [lindex [cgi_status $reply] 1] | |
| 1190 | + set status [lindex [reply_status $reply] 1] | |
| 1117 | 1191 | if {$status eq "400"} { |
| 1118 | - return [list 400 [string trim [cgi_body $reply]]] | |
| 1192 | + return [list 400 [string trim [reply_body $reply]]] | |
| 1119 | 1193 | } |
| 1120 | 1194 | if {$status ne "200"} { return $status } |
| 1121 | 1195 | return [list 200 [cgi_param $reply SCRIPT_NAME] [cgi_param $reply PATH_INFO] \ |
| 1122 | 1196 | [cgi_param $reply REQUEST_URI]] |
| 1123 | 1197 | } |
| @@ -1171,29 +1245,33 @@ | ||
| 1171 | 1245 | empty "" "SCGI header too short" \ |
| 1172 | 1246 | length-only "20" "cannot read entire SCGI header" \ |
| 1173 | 1247 | ] { |
| 1174 | 1248 | set cgiReply [cgi_send $cgiRequest --scgi] |
| 1175 | 1249 | 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" | |
| 1177 | 1251 | && [string match "*$cgiError*" $cgiReply]} |
| 1178 | 1252 | } |
| 1179 | 1253 | |
| 1180 | 1254 | ############################################################################### |
| 1181 | 1255 | # Page aliases. An alias in the configuration names a page and query |
| 1182 | 1256 | # parameters for it: "NAME=VALUE" sets a parameter, replacing one of the |
| 1183 | 1257 | # same name in the request; a name in capitals is taken in lower case; |
| 1184 | 1258 | # "NAME!" removes a parameter of the request. |
| 1185 | 1259 | |
| 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"]] | |
| 1189 | 1267 | test_eq cgi-alias-replace [cgi_param $cgiReply a] new |
| 1190 | 1268 | test_eq cgi-alias-upper [cgi_param $cgiReply bb] 2 |
| 1191 | 1269 | test_eq cgi-alias-delete [cgi_param $cgiReply gone] - |
| 1192 | 1270 | test_eq cgi-alias-add [cgi_param $cgiReply fresh] "" |
| 1193 | 1271 | 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"]] | |
| 1195 | 1273 | test {cgi-alias-delete-last} {[cgi_param $cgiReply zz] eq "-" |
| 1196 | 1274 | && [cgi_param $cgiReply m] eq "1"} |
| 1197 | 1275 | |
| 1198 | 1276 | ############################################################################### |
| 1199 | 1277 | # The configuration page saves the text given for the main menu, unless |
| @@ -1201,12 +1279,13 @@ | ||
| 1201 | 1279 | # removed and the text is not looked at. |
| 1202 | 1280 | |
| 1203 | 1281 | proc cgi_menu_post {fields} { |
| 1204 | 1282 | global cgiToken |
| 1205 | 1283 | 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] \ | |
| 1208 | 1287 | [fossil sql "SELECT value FROM config WHERE name='mainmenu'"]] |
| 1209 | 1288 | } |
| 1210 | 1289 | test_eq cgi-menu-saved [cgi_menu_post "mmenu=cgi-menu-text&zlast=1"] \ |
| 1211 | 1290 | {200 cgi-menu-text} |
| 1212 | 1291 | test_eq cgi-menu-reset [cgi_menu_post "mmenu=other-text&resetMenu=1&zlast=1"] \ |
| @@ -1220,22 +1299,23 @@ | ||
| 1220 | 1299 | # empty value is on, and one with the value "off" is off. |
| 1221 | 1300 | |
| 1222 | 1301 | proc cgi_subscribe {email fields} { |
| 1223 | 1302 | global cgiToken |
| 1224 | 1303 | 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'"] | |
| 1227 | 1307 | } |
| 1228 | 1308 | test_eq cgi-subscribe-no-name [cgi_subscribe [email protected] "sa=&sc=off"] \ |
| 1229 | 1309 | "|a" |
| 1230 | 1310 | test_eq cgi-subscribe-blank-name \ |
| 1231 | 1311 | [cgi_subscribe [email protected] "suname=+++&sa=0&sc=1"] "|c" |
| 1232 | 1312 | test_eq cgi-subscribe-line-ends \ |
| 1233 | 1313 | [cgi_subscribe [email protected] "suname=+one%0D%0Atwo%0Dend&sa=1"] \ |
| 1234 | 1314 | "6F6E650A74776F0D656E64|a" |
| 1235 | 1315 | # 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"]] | |
| 1237 | 1317 | test cgi-subscribe-checked-word { |
| 1238 | 1318 | [string match "*name=\"sa\" checked>*" $cgiReply] |
| 1239 | 1319 | && [string match "*name=\"sc\" >*" $cgiReply] |
| 1240 | 1320 | && [string match "*name=\"st\" >*" $cgiReply]} |
| 1241 | 1321 | |
| @@ -1256,22 +1336,29 @@ | ||
| 1256 | 1336 | return $RESULT |
| 1257 | 1337 | } |
| 1258 | 1338 | set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env |
| 1259 | 1339 | REMOTE_ADDR 127.0.0.1}] |
| 1260 | 1340 | 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]} | |
| 1262 | 1344 | set cgiReply [cgi_cgi {REQUEST_METHOD POST SCRIPT_NAME /s PATH_INFO /test-env |
| 1263 | 1345 | REMOTE_ADDR 127.0.0.1 SERVER_SOFTWARE TestServer/1}] |
| 1264 | 1346 | 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]} | |
| 1266 | 1350 | set cgiReply [cgi_cgi {SCRIPT_NAME /s PATH_INFO /test-env REMOTE_ADDR 127.0.0.1 |
| 1267 | 1351 | HTTP_HOST x HTTP_REFERER http://x/s/prev}] |
| 1268 | 1352 | test_eq cgi-cgi-no-method [cgi_csrf_level $cgiReply] "Same origin" |
| 1269 | 1353 | |
| 1270 | 1354 | # A control file that names a debug file which cannot be opened is used |
| 1271 | 1355 | # 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"] ""] | |
| 1273 | 1360 | set ::env(REQUEST_METHOD) GET |
| 1274 | 1361 | set ::env(SCRIPT_NAME) /s |
| 1275 | 1362 | set ::env(PATH_INFO) /test-env |
| 1276 | 1363 | set ::env(QUERY_STRING) "nodebug=1" |
| 1277 | 1364 | set ::env(REMOTE_ADDR) 127.0.0.1 |
| @@ -1296,31 +1383,40 @@ | ||
| 1296 | 1383 | test cgi-json-post-$cgiName-exit {$CODE == 0} |
| 1297 | 1384 | test cgi-json-post-$cgiName-reply \ |
| 1298 | 1385 | {[string match "*FOSSIL-1101*" $cgiReply]} |
| 1299 | 1386 | } |
| 1300 | 1387 | 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" | |
| 1302 | 1389 | && [string match "*jsonApiVersion*" $cgiReply]} |
| 1303 | 1390 | set cgiReply [cgi_send [cgi_scgi { |
| 1304 | 1391 | CONTENT_LENGTH 8 CONTENT_TYPE application/json SCGI 1 REQUEST_METHOD POST |
| 1305 | 1392 | SCRIPT_NAME {} PATH_INFO /json/version SERVER_NAME x SERVER_PORT 80 |
| 1306 | 1393 | REMOTE_ADDR 127.0.0.1 no_json 1 |
| 1307 | 1394 | } "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" | |
| 1309 | 1396 | && [string match "*jsonApiVersion*" $cgiReply]} |
| 1310 | 1397 | } |
| 1311 | 1398 | |
| 1312 | 1399 | ############################################################################### |
| 1313 | 1400 | # More of a connection over ssh. An older client, after its probes, |
| 1314 | 1401 | # sends a blank line twice and the command again before each further |
| 1315 | 1402 | # request. A request may name the repository file before the page. |
| 1316 | 1403 | |
| 1317 | 1404 | 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] | |
| 1320 | 1415 | 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]} | |
| 1322 | 1418 | foreach {cgiName cgiMore cgiError} [list \ |
| 1323 | 1419 | cut-short "\n" "incorrect transport_flip" \ |
| 1324 | 1420 | not-blank "\nxyz\n" "transport_flip failed" \ |
| 1325 | 1421 | other-command "\n\nother\n" "transport_open failed" \ |
| 1326 | 1422 | no-request "\n\nfossil\n" "missing HTTP header" \ |
| @@ -1335,52 +1431,72 @@ | ||
| 1335 | 1431 | && ![string match "*400 Bad Request*" $cgiReply]} |
| 1336 | 1432 | foreach {cgiName cgiRequest cgiError} [list \ |
| 1337 | 1433 | probes-only "echo test1\nfossil\n" "missing HTTP header" \ |
| 1338 | 1434 | blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1339 | 1435 | "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"] ""] \ | |
| 1341 | 1440 | "transport_open failed" \ |
| 1342 | 1441 | repository-only "GET $cgiRepo HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1343 | 1442 | "malformed URL in HTTP header" \ |
| 1344 | 1443 | ] { |
| 1345 | 1444 | set cgiReply [cgi_send $cgiRequest --localauth] |
| 1346 | 1445 | test cgi-ssh-$cgiName {$CODE == 0 |
| 1347 | 1446 | && [string match "*400 Bad Request*$cgiError*" $cgiReply]} |
| 1348 | 1447 | } |
| 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] | |
| 1350 | 1449 | test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1" |
| 1351 | 1450 | && [cgi_param $cgiReply PATH_INFO] eq "/test-env"} |
| 1352 | 1451 | # The name is taken off only when a "/" or the end follows it, and only |
| 1353 | 1452 | # 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] | |
| 1355 | 1454 | 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"] \ | |
| 1357 | 1457 | POST] --localauth] |
| 1358 | 1458 | test_eq cgi-ssh-repository-post [cgi_param $cgiReply PATH_INFO] - |
| 1359 | 1459 | # Later requests on one ssh connection: the second sends Content-Length |
| 1360 | 1460 | # before a longer header line and must get its length and body; the third |
| 1361 | 1461 | # 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"] ""] | |
| 1364 | 1472 | set cgiThird "GET /test-env?c=3 HTTP/1.1\r\nHost: x\r\n\r\n" |
| 1365 | 1473 | set cgiReply [cgi_send $cgiFirst$cgiSecond$cgiThird --localauth] |
| 1366 | 1474 | 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*"] ""] \ | |
| 1368 | 1478 | [regsub -all {<[^>]*>} $cgiReply {}]]} |
| 1369 | 1479 | unset ::env(SSH_CONNECTION) |
| 1370 | 1480 | |
| 1371 | 1481 | ############################################################################### |
| 1372 | 1482 | # A visitor who is not logged in reaches a page that is closed to robots |
| 1373 | 1483 | # with a token, and gets a cookie that opens the page afterwards. The |
| 1374 | 1484 | # same value given as a query parameter does not. |
| 1375 | 1485 | |
| 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)"] ""] | |
| 1378 | 1494 | proc cgi_robot {path {cookie ""}} { |
| 1379 | 1495 | set headers [list "User-Agent: Agent/1"] |
| 1380 | 1496 | 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] | |
| 1382 | 1498 | } |
| 1383 | 1499 | set cgiRobot "*Checking to see if you are a robot*" |
| 1384 | 1500 | test cgi-robot-stopped {[string match $cgiRobot [cgi_robot /timeline]]} |
| 1385 | 1501 | set cgiReply [cgi_robot /timeline?token=cgitoken] |
| 1386 | 1502 | set cgiProof "" |
| @@ -1401,28 +1517,30 @@ | ||
| 1401 | 1517 | ############################################################################### |
| 1402 | 1518 | # A forum thread is shown in order of time to a phone and as a hierarchy |
| 1403 | 1519 | # to anything else, an iPad included. The page offers the other order. |
| 1404 | 1520 | |
| 1405 | 1521 | 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" | |
| 1407 | 1524 | close $cgiFd |
| 1408 | 1525 | fossil md5sum post.txt |
| 1409 | 1526 | set cgiSum [lindex $RESULT 0] |
| 1410 | 1527 | set cgiFd [open post.txt ab] |
| 1411 | 1528 | puts -nonewline $cgiFd "Z $cgiSum\n" |
| 1412 | 1529 | close $cgiFd |
| 1413 | 1530 | 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)"] | |
| 1415 | 1533 | foreach {cgiName cgiAgent cgiOther} { |
| 1416 | 1534 | phone "Mozilla/5.0 (iPhone; Mobile) Safari" Hierarchical |
| 1417 | 1535 | ipad "Mozilla/5.0 (iPad; Mobile) Safari" Chronological |
| 1418 | 1536 | desk "Mozilla/5.0 (X11; Linux)" Chronological |
| 1419 | 1537 | none "" Chronological |
| 1420 | 1538 | } { |
| 1421 | 1539 | set cgiHeaders {} |
| 1422 | 1540 | 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]] | |
| 1424 | 1542 | test cgi-forum-order-$cgiName {[string match "*>Cgi thread<*" $cgiReply] |
| 1425 | 1543 | && [string match "*?t=?\">$cgiOther</a>*" $cgiReply]} |
| 1426 | 1544 | } |
| 1427 | 1545 | |
| 1428 | 1546 | ############################################################################### |
| @@ -1431,28 +1549,34 @@ | ||
| 1431 | 1549 | |
| 1432 | 1550 | fossil user new cgiuser contact userpw |
| 1433 | 1551 | fossil user capabilities cgiuser o |
| 1434 | 1552 | proc cgi_login {fields} { |
| 1435 | 1553 | 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] | |
| 1437 | 1555 | } |
| 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] | |
| 1440 | 1559 | && ![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]} | |
| 1443 | 1563 | |
| 1444 | 1564 | ############################################################################### |
| 1445 | 1565 | # A program under /ext that gives a status of 0 gets the usual "200 OK". |
| 1446 | 1566 | |
| 1447 | 1567 | if {$::tcl_platform(platform) eq "unix"} { |
| 1448 | 1568 | 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"] ""] | |
| 1450 | 1574 | 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] \ | |
| 1452 | 1576 | --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" | |
| 1454 | 1578 | && [string match "*from the program*" $cgiReply] |
| 1455 | 1579 | && ![string match "*printf*" $cgiReply]} |
| 1456 | 1580 | } |
| 1457 | 1581 | |
| 1458 | 1582 | ############################################################################### |
| @@ -1481,11 +1605,12 @@ | ||
| 1481 | 1605 | cgi cgi5.ctl] |
| 1482 | 1606 | cd $cgiHere |
| 1483 | 1607 | file delete -force $cgiDir |
| 1484 | 1608 | test cgi-cgi-no-repository {$CODE == 1 |
| 1485 | 1609 | && [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]} | |
| 1487 | 1612 | set cgiReply [cgi_run_with {GATEWAY_INTERFACE CGI/1.1 REQUEST_METHOD GET |
| 1488 | 1613 | SCRIPT_NAME /s PATH_INFO /home}] |
| 1489 | 1614 | test cgi-cgi-no-control-file {$CODE == 1 |
| 1490 | 1615 | && [string match "Status: 500 Internal Server Error*" $cgiReply] |
| 1491 | 1616 | && [string match "*No CGI control file specified" $cgiReply]} |
| @@ -1497,24 +1622,24 @@ | ||
| 1497 | 1622 | write_file cgi6.ctl "#!/usr/bin/fossil\nredirect: * $cgiTarget\n" |
| 1498 | 1623 | set cgiReply [cgi_run_with {REQUEST_METHOD GET HTTP_HOST x SCRIPT_NAME /s |
| 1499 | 1624 | PATH_INFO /abc QUERY_STRING q=1} cgi cgi6.ctl] |
| 1500 | 1625 | test cgi-cgi-redirect-$cgiName {$CODE == 0 |
| 1501 | 1626 | && [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} | |
| 1503 | 1628 | } |
| 1504 | 1629 | |
| 1505 | 1630 | ############################################################################### |
| 1506 | 1631 | # The setup page warns of a page header that has no "base" element, and |
| 1507 | 1632 | # does not when the header has one, as the built-in header does. |
| 1508 | 1633 | |
| 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" | |
| 1511 | 1636 | && ![string match "*Configuration Error*" $cgiReply]} |
| 1512 | 1637 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header', |
| 1513 | 1638 | '<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" | |
| 1516 | 1641 | && [string match "*Configuration Error*base href=*" $cgiReply]} |
| 1517 | 1642 | |
| 1518 | 1643 | # The TH1 command "redirect" in a page header sends the client to |
| 1519 | 1644 | # another page: with "302", or with "307" when its second argument is |
| 1520 | 1645 | # true, which tells the client to repeat the request as it made it. |
| @@ -1522,13 +1647,13 @@ | ||
| 1522 | 1647 | plain {redirect /stat} {HTTP/1.0 302 Moved Temporarily} |
| 1523 | 1648 | method {redirect /stat 1} {HTTP/1.0 307 Temporary Redirect} |
| 1524 | 1649 | } { |
| 1525 | 1650 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header', |
| 1526 | 1651 | '<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"} | |
| 1530 | 1655 | } |
| 1531 | 1656 | fossil sql "DELETE FROM config WHERE name='header'" |
| 1532 | 1657 | |
| 1533 | 1658 | # The same command run from the command line, where there is no request |
| 1534 | 1659 | # to answer, is an error. |
| @@ -1555,14 +1680,14 @@ | ||
| 1555 | 1680 | # and has no table in its content; a page with a table gets the ad unit |
| 1556 | 1681 | # for the top of the page. |
| 1557 | 1682 | |
| 1558 | 1683 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES |
| 1559 | 1684 | ('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]] | |
| 1561 | 1686 | test cgi-adunit-right {[string match "*ADRIGHT*" $cgiReply] |
| 1562 | 1687 | && ![string match "*ADTOP*" $cgiReply]} |
| 1563 | -set cgiReply [cgi_admin [cgi_get /brlist]] | |
| 1688 | +set cgiReply [cgi_admin [request_get /brlist]] | |
| 1564 | 1689 | test cgi-adunit-top-with-table {[string match "*ADTOP*" $cgiReply] |
| 1565 | 1690 | && ![string match "*ADRIGHT*" $cgiReply]} |
| 1566 | 1691 | fossil sql "DELETE FROM config WHERE name IN ('adunit-right','adunit')" |
| 1567 | 1692 | |
| 1568 | 1693 | ############################################################################### |
| @@ -1570,16 +1695,16 @@ | ||
| 1570 | 1695 | # /file with no file name lists the files of the check-in "tip", and |
| 1571 | 1696 | # its links carry "ci=tip". /timeline with "r=BRANCH" shows the branch |
| 1572 | 1697 | # and what is related to it, and its form keeps that as "t=BRANCH" and |
| 1573 | 1698 | # "rel". |
| 1574 | 1699 | |
| 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" | |
| 1577 | 1702 | && [string match "*Top-level Files of tip*" $cgiReply] |
| 1578 | 1703 | && [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" | |
| 1581 | 1706 | && [string match "*name=\"rel\" value=\"1\"*" $cgiReply] |
| 1582 | 1707 | && [string match "*name=\"t\" value=\"trunk\"*" $cgiReply]} |
| 1583 | 1708 | |
| 1584 | 1709 | ############################################################################### |
| 1585 | 1710 | # An unversioned file whose time of change is too far in the future to |
| @@ -1588,15 +1713,15 @@ | ||
| 1588 | 1713 | |
| 1589 | 1714 | write_file late.css "p{}\n" |
| 1590 | 1715 | fossil uv add late.css |
| 1591 | 1716 | fossil sql "UPDATE unversioned SET mtime=1000000000000000000 |
| 1592 | 1717 | 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] | |
| 1594 | 1719 | 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" | |
| 1596 | 1721 | && [string match "*\r\nLast-Modified: \r\n*" $cgiReply] |
| 1597 | - && [cgi_body $cgiReply] eq "p{}\n"} | |
| 1722 | + && [reply_body $cgiReply] eq "p{}\n"} | |
| 1598 | 1723 | fossil uv rm late.css |
| 1599 | 1724 | |
| 1600 | 1725 | ############################################################################### |
| 1601 | 1726 | # "fossil server" itself, where it listens with its own code (not on |
| 1602 | 1727 | # Windows). A server that cannot listen where it was told says why and |
| @@ -1624,11 +1749,13 @@ | ||
| 1624 | 1749 | bad-ipv6 {--port {[zz::1]:8111}} \ |
| 1625 | 1750 | "not a valid IPv6 address: zz::1" \ |
| 1626 | 1751 | other-ipv4 {--port 192.0.2.1:8111} \ |
| 1627 | 1752 | "cannot open a listening socket on 192.0.2.1:8111" \ |
| 1628 | 1753 | 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"] ""] \ | |
| 1630 | 1757 | port-in-use [list --localhost --port $cgiPort] \ |
| 1631 | 1758 | "no available TCP ports in the range $cgiPort..$cgiPort" \ |
| 1632 | 1759 | socket-name-long [list --socket-name [string repeat s 200]] \ |
| 1633 | 1760 | "name of unix socket too big" \ |
| 1634 | 1761 | socket-name-taken {--socket-name notsocket} \ |
| @@ -1638,75 +1765,102 @@ | ||
| 1638 | 1765 | test cgi-server-refused-$cgiName {$CODE == 1 |
| 1639 | 1766 | && [string match "*$cgiError*" $RESULT]} |
| 1640 | 1767 | } |
| 1641 | 1768 | close $cgiListener |
| 1642 | 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 | + } | |
| 1643 | 1798 | # Send REQUEST to HOST and PORT and return the reply, waiting at most |
| 1644 | 1799 | # ten seconds for the end of it. With "unix" for HOST, PORT is the |
| 1645 | 1800 | # name of a unix socket, and the program "nc" carries the request. |
| 1646 | 1801 | proc cgi_client {host port request} { |
| 1647 | 1802 | 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 | |
| 1649 | 1806 | } |
| 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 | |
| 1652 | 1809 | puts -nonewline $sock $request |
| 1653 | 1810 | flush $sock |
| 1654 | 1811 | 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} | |
| 1658 | 1816 | } |
| 1659 | 1817 | close $sock |
| 1660 | 1818 | return $reply |
| 1661 | 1819 | } |
| 1662 | 1820 | # Start a server with OPTIONS that answers one request and stops, send |
| 1663 | 1821 | # it REQUEST at HOST and PORT, and return what the server printed and |
| 1664 | 1822 | # 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}} { | |
| 1666 | 1826 | global fossilexe cgiRepo |
| 1667 | 1827 | file delete server.out |
| 1668 | 1828 | set pid [exec $fossilexe $command --debug-nofork --localauth {*}$options \ |
| 1669 | 1829 | $cgiRepo >& server.out &] |
| 1670 | 1830 | 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]}} | |
| 1682 | 1836 | catch {exec kill -9 $pid} |
| 1683 | 1837 | return [list [string trim [read_file server.out]] $reply] |
| 1684 | 1838 | } |
| 1685 | 1839 | |
| 1686 | 1840 | # An IPv4 address, by number and as "localhost". |
| 1687 | 1841 | foreach {cgiName cgiHost} {ipv4 127.0.0.1 localhost localhost} { |
| 1688 | 1842 | set cgiPort [cgi_free_port] |
| 1689 | 1843 | 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 | |
| 1691 | 1845 | test_eq cgi-server-$cgiName-printed $cgiPrinted \ |
| 1692 | 1846 | "Listening for HTTP requests on TCP port 127.0.0.1:$cgiPort" |
| 1693 | 1847 | 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" | |
| 1695 | 1849 | && [cgi_param $cgiReply REMOTE_ADDR] eq "127.0.0.1"} |
| 1696 | 1850 | } |
| 1697 | 1851 | # "fossil ui" starts the browser on the address it listens on. The |
| 1698 | 1852 | # browser here is "echo". |
| 1699 | 1853 | fossil settings web-browser echo |
| 1700 | 1854 | fossil settings web-browser |
| 1701 | 1855 | if {[string match "*echo*" $RESULT]} { |
| 1702 | 1856 | set cgiPort [cgi_free_port] |
| 1703 | 1857 | 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 | |
| 1705 | 1859 | test cgi-server-ui-browser { |
| 1706 | 1860 | [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"} | |
| 1708 | 1862 | } |
| 1709 | 1863 | # SCGI in place of HTTP. |
| 1710 | 1864 | set cgiPort [cgi_free_port] |
| 1711 | 1865 | lassign [cgi_serve_once [list --scgi --port 127.0.0.1:$cgiPort] 127.0.0.1 \ |
| 1712 | 1866 | $cgiPort [cgi_scgi { |
| @@ -1721,38 +1875,44 @@ | ||
| 1721 | 1875 | if {![catch {cgi_busy_port ::1} cgiBusy]} { |
| 1722 | 1876 | close [lindex $cgiBusy 0] |
| 1723 | 1877 | # An IPv6 address. |
| 1724 | 1878 | set cgiPort [cgi_free_port] |
| 1725 | 1879 | lassign [cgi_serve_once [list --port \[::1\]:$cgiPort] ::1 $cgiPort \ |
| 1726 | - [cgi_get /test-env]] cgiPrinted cgiReply | |
| 1880 | + [request_get /test-env]] cgiPrinted cgiReply | |
| 1727 | 1881 | test_eq cgi-server-ipv6-printed $cgiPrinted \ |
| 1728 | 1882 | "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" | |
| 1730 | 1884 | && [cgi_param $cgiReply REMOTE_ADDR] eq "::1"} |
| 1731 | 1885 | # 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. | |
| 1733 | 1889 | set cgiPort [cgi_free_port] |
| 1734 | 1890 | 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 | |
| 1736 | 1892 | 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"] ""] | |
| 1738 | 1896 | test_eq cgi-server-both-reply [cgi_param $cgiReply REMOTE_ADDR] ::1 |
| 1739 | 1897 | lassign [cgi_busy_port ::1] cgiListener cgiPort |
| 1740 | 1898 | 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 | |
| 1742 | 1900 | close $cgiListener |
| 1743 | 1901 | test_eq cgi-server-ipv4-only-printed $cgiPrinted \ |
| 1744 | 1902 | "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" | |
| 1746 | 1905 | # With a port and neither an address nor --localhost the server |
| 1747 | 1906 | # listens on every address of the machine. |
| 1748 | 1907 | set cgiPort [cgi_free_port] |
| 1749 | 1908 | 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 | |
| 1751 | 1910 | test_eq cgi-server-any-address-printed $cgiPrinted \ |
| 1752 | 1911 | "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" | |
| 1754 | 1914 | } |
| 1755 | 1915 | |
| 1756 | 1916 | # A unix socket in place of a port. The server makes the socket, and |
| 1757 | 1917 | # takes the place of a socket of the same name that is left from an |
| 1758 | 1918 | # earlier server. --socket-owner names the owner of the socket. |
| @@ -1762,15 +1922,15 @@ | ||
| 1762 | 1922 | foreach {cgiName cgiOptions} [list \ |
| 1763 | 1923 | new {--socket-name sock1} \ |
| 1764 | 1924 | replaced {--socket-name sock1} \ |
| 1765 | 1925 | owner [list --socket-owner $cgiUser --socket-name sock1] \ |
| 1766 | 1926 | ] { |
| 1767 | - lassign [cgi_serve_once $cgiOptions unix sock1 [cgi_get /login]] \ | |
| 1927 | + lassign [cgi_serve_once $cgiOptions unix sock1 [request_get /login]] \ | |
| 1768 | 1928 | cgiPrinted cgiReply |
| 1769 | 1929 | test cgi-server-unix-$cgiName { |
| 1770 | 1930 | $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" | |
| 1772 | 1932 | && [file type sock1] eq "socket" |
| 1773 | 1933 | && [file attributes sock1 -owner] eq $cgiUser} |
| 1774 | 1934 | } |
| 1775 | 1935 | # --socket-mode gives the permissions of the socket; without it they |
| 1776 | 1936 | # are 0660. |
| @@ -1777,15 +1937,15 @@ | ||
| 1777 | 1937 | foreach {cgiName cgiOptions cgiMode} { |
| 1778 | 1938 | mode {--socket-mode 0600 --socket-name sock2} 600 |
| 1779 | 1939 | default {--socket-name sock2} 660 |
| 1780 | 1940 | } { |
| 1781 | 1941 | 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]] \ | |
| 1783 | 1943 | cgiPrinted cgiReply |
| 1784 | 1944 | test cgi-server-unix-$cgiName { |
| 1785 | 1945 | $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" | |
| 1787 | 1947 | && [format %o [expr {[file attributes sock2 -permissions] & 0o777}]] |
| 1788 | 1948 | eq $cgiMode} |
| 1789 | 1949 | } |
| 1790 | 1950 | fossil_raw -seconds 30 server --socket-mode rw --socket-name sock3 $cgiRepo |
| 1791 | 1951 | test cgi-server-unix-mode-not-a-number {$CODE == 1 && [string match \ |
| @@ -1801,25 +1961,25 @@ | ||
| 1801 | 1961 | proc cgi_serve_start {options {command server} {wrap {}}} { |
| 1802 | 1962 | global fossilexe cgiRepo |
| 1803 | 1963 | file delete server.out server.err |
| 1804 | 1964 | set pid [exec {*}$wrap $fossilexe $command --localauth {*}$options \ |
| 1805 | 1965 | $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 | |
| 1811 | 1967 | return $pid |
| 1812 | 1968 | } |
| 1813 | 1969 | # Stop the server with process id PID: ask it to end, and kill it if |
| 1814 | 1970 | # it has not ended after five seconds. |
| 1815 | 1971 | proc cgi_serve_stop {pid} { |
| 1816 | 1972 | 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]}} | |
| 1820 | 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 | |
| 1821 | 1981 | } |
| 1822 | 1982 | |
| 1823 | 1983 | # A process that handles a request is killed before the request is |
| 1824 | 1984 | # complete. The server goes on to answer the next request, and one |
| 1825 | 1985 | # that traces its work reports the signal that ended the process. |
| @@ -1831,28 +1991,27 @@ | ||
| 1831 | 1991 | set cgiPort [cgi_free_port] |
| 1832 | 1992 | set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort \ |
| 1833 | 1993 | {*}$cgiOptions]] |
| 1834 | 1994 | set cgiReply "" |
| 1835 | 1995 | 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] | |
| 1838 | 1997 | puts -nonewline $cgiSock "GET /login HTTP/1.1\r\n" |
| 1839 | 1998 | 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 ""}} | |
| 1843 | 2002 | 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 ""}} | |
| 1845 | 2005 | } |
| 1846 | 2006 | cgi_serve_stop $cgiPid |
| 1847 | 2007 | 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" | |
| 1849 | 2009 | && ($cgiReport eq "" |
| 1850 | 2010 | ? ![string match "*exited on signal*" [read_file server.err]] |
| 1851 | 2011 | : [string match $cgiReport [read_file server.err]])} |
| 1852 | 2012 | } |
| 1853 | - foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog } | |
| 1854 | 2013 | } else { |
| 1855 | 2014 | test_skip_part "no pgrep program: the killed server process tests" |
| 1856 | 2015 | } |
| 1857 | 2016 | |
| 1858 | 2017 | # A server that is not allowed another process cannot start the |
| @@ -1864,11 +2023,11 @@ | ||
| 1864 | 2023 | && [auto_execok bash] ne ""} { |
| 1865 | 2024 | set cgiPort [cgi_free_port] |
| 1866 | 2025 | set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort] ui \ |
| 1867 | 2026 | [list bash -c {ulimit -u 1 && exec "$@"} bash]] |
| 1868 | 2027 | 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]]} | |
| 1870 | 2029 | set cgiAlive [expr {![catch {exec kill -0 $cgiPid}]}] |
| 1871 | 2030 | cgi_serve_stop $cgiPid |
| 1872 | 2031 | test cgi-server-no-process-browser {[string match \ |
| 1873 | 2032 | "*cannot start browser: echo*" [read_file server.err]]} |
| 1874 | 2033 | test cgi-server-no-process-request {$cgiReply eq "" && $cgiAlive} |
| 1875 | 2034 |
| --- 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 @@ | ||
| 6 | 6 | # asks for. After each command the configuration of the area must be what |
| 7 | 7 | # the command is documented to leave, and the rest of the repository must |
| 8 | 8 | # be as it was. |
| 9 | 9 | # |
| 10 | 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 | - | |
| 11 | +# The first sections run at every level, and the rest need | |
| 12 | +# -assurance ci or stress. | |
| 16 | 13 | require_no_open_checkout |
| 17 | 14 | |
| 18 | 15 | test_setup "" |
| 19 | 16 | set configDir [pwd] |
| 20 | 17 | set ::env(FOSSIL_USER) tester |
| @@ -23,12 +20,11 @@ | ||
| 23 | 20 | # Helpers. |
| 24 | 21 | |
| 25 | 22 | # Run SQL in repository REPO and return its output without the final |
| 26 | 23 | # newline. |
| 27 | 24 | proc configSql {repo sql} { |
| 28 | - fossil sql -R $repo $sql | |
| 29 | - return [string trim $::RESULT] | |
| 25 | + return [fossil_sql $sql $repo] | |
| 30 | 26 | } |
| 31 | 27 | |
| 32 | 28 | # Make an empty repository FILE and give its settings a time long before |
| 33 | 29 | # any that the tests write, so that a test sees only what it set. |
| 34 | 30 | proc configNew {file} { |
| @@ -116,14 +112,21 @@ | ||
| 116 | 112 | |
| 117 | 113 | # A setting that is empty or absent has no time that a test can know: the |
| 118 | 114 | # repository makes a new "hash-policy" when it is opened. MASK hides its time. |
| 119 | 115 | # The SQL that lists what repository holds in the tables TABLES. With |
| 120 | 116 | # 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. | |
| 122 | 120 | proc configTableSql {tables exported} { |
| 123 | 121 | set m [expr {$exported ? "WHERE mtime IS NOT NULL" : ""}] |
| 124 | 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 | + } | |
| 125 | 128 | foreach t $tables { |
| 126 | 129 | switch -- $t { |
| 127 | 130 | rpt {append sql "SELECT 'rpt', owner, title, mtime, quote(cols), |
| 128 | 131 | quote(sqlcode), quote(ifnull(jx,'{}')) FROM reportfmt $m ORDER BY title;"} |
| 129 | 132 | usr {append sql "SELECT 'usr', login, quote(pw), quote(cap), |
| @@ -149,19 +152,11 @@ | ||
| 149 | 152 | global configTables |
| 150 | 153 | set t [expr {$mask ? "CASE WHEN name='hash-policy' THEN 0 ELSE mtime END" |
| 151 | 154 | : "mtime"}] |
| 152 | 155 | set sql "SELECT 'cfg', name, quote(value), $t FROM config |
| 153 | 156 | 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] | |
| 163 | 158 | return [configSql $repo $sql] |
| 164 | 159 | } |
| 165 | 160 | |
| 166 | 161 | # What REPO holds outside AREA, to see that a command left it alone. |
| 167 | 162 | proc configOutside {repo area} { |
| @@ -170,22 +165,14 @@ | ||
| 170 | 165 | WHERE NOT [configCond $area] ORDER BY name;" |
| 171 | 166 | set tables {} |
| 172 | 167 | foreach t {rpt usr cnc shn sub} { |
| 173 | 168 | if {$t ni $configTables($area)} {lappend tables $t} |
| 174 | 169 | } |
| 175 | - if {![configHasTable $repo subscriber]} { | |
| 176 | - set tables [lsearch -all -inline -not -exact $tables sub] | |
| 177 | - } | |
| 178 | 170 | append sql [configTableSql $tables 0] |
| 179 | 171 | return [configSql $repo $sql] |
| 180 | 172 | } |
| 181 | 173 | |
| 182 | -proc configHasTable {repo table} { | |
| 183 | - return [configSql $repo "SELECT count(*) FROM sqlite_schema | |
| 184 | - WHERE name='$table' AND type='table'"] | |
| 185 | -} | |
| 186 | - | |
| 187 | 174 | # The kinds of card that an export file holds, in order and without |
| 188 | 175 | # repeats. |
| 189 | 176 | proc configKinds {file} { |
| 190 | 177 | set kinds {} |
| 191 | 178 | foreach line [split [read_file $file] \n] { |
| @@ -382,16 +369,22 @@ | ||
| 382 | 369 | set configFile export-$configArea.cfg |
| 383 | 370 | configRun configuration export $configArea $configFile -R a.fossil |
| 384 | 371 | test config-export-$configArea {$CODE == 0 && $RESULT eq ""} |
| 385 | 372 | set configText [read_file $configFile] |
| 386 | 373 | 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"] ""] | |
| 388 | 377 | test_eq config-export-$configArea-cards [configKinds $configFile] \ |
| 389 | 378 | [lsort $configKindsOf($configArea)] |
| 390 | 379 | } |
| 391 | 380 | test_eq config-export-changes-nothing [configSql a.fossil "SELECT 'c',name,mtime |
| 392 | 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 | +} | |
| 393 | 386 | |
| 394 | 387 | ############################################################################### |
| 395 | 388 | # Import: an area exported from one repository and imported into another |
| 396 | 389 | # makes the second hold what the first holds, in that area, with the times |
| 397 | 390 | # of last change. The tables of the area are replaced, so that a row that |
| @@ -445,12 +438,14 @@ | ||
| 445 | 438 | set configExp [configState a.fossil $configArea 1] |
| 446 | 439 | test config-$configArea-has-content {$configExp ne ""} |
| 447 | 440 | |
| 448 | 441 | configRun configuration import export-$configArea.cfg -R $configB |
| 449 | 442 | 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 | |
| 452 | 447 | if {$configArea eq "ticket" || $configArea eq "all"} { |
| 453 | 448 | # The ticket tables are rebuilt from the imported ticket-table. |
| 454 | 449 | test_eq config-import-$configArea-ticket-table [configSql $configB "SELECT |
| 455 | 450 | count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 1 |
| 456 | 451 | } |
| @@ -462,37 +457,44 @@ | ||
| 462 | 457 | set configOut [configOutside $configB $configArea] |
| 463 | 458 | configRun configuration reset $configArea -R $configB |
| 464 | 459 | test config-reset-$configArea {$CODE == 0 && |
| 465 | 460 | [string first "Configuration reset to factory defaults." $RESULT] >= 0} |
| 466 | 461 | 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 | |
| 468 | 465 | regexp {import (config-backup-[0-9.]+)} $configResetOut -> configBackup |
| 469 | 466 | test config-reset-$configArea-backup {[info exists configBackup] && |
| 470 | 467 | [file exists $configBackup]} |
| 471 | 468 | if {$configArea eq "user" || $configArea eq "all"} { |
| 472 | 469 | # The default users come back, and the user who ran the command is |
| 473 | 470 | # 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 | |
| 475 | 473 | FROM user ORDER BY login"] \ |
| 476 | 474 | "anonymous|hz|\ndeveloper|ei|\nnobody|gjorz|\nreader|kptw|\ntester|s|" |
| 477 | 475 | } |
| 478 | 476 | 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] \ | |
| 480 | 479 | [configDefaults $configArea] |
| 481 | 480 | } |
| 482 | 481 | if {$configArea eq "ticket" || $configArea eq "all"} { |
| 483 | 482 | test_eq config-reset-$configArea-ticket-table [configSql $configB "SELECT |
| 484 | 483 | count(*) FROM pragma_table_info('ticket') WHERE name='zzz'"] 0 |
| 485 | 484 | } |
| 486 | 485 | 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(*) | |
| 488 | 488 | FROM subscriber"] 0 |
| 489 | 489 | } |
| 490 | 490 | configRun configuration import $configBackup -R $configB |
| 491 | 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] \ | |
| 492 | + test_eq config-reset-$configArea-recovered \ | |
| 493 | + [configState $configB $configArea] $configPre | |
| 494 | + test_eq config-reset-$configArea-recovered-outside \ | |
| 495 | + [configOutside $configB $configArea] \ | |
| 494 | 496 | $configOut |
| 495 | 497 | } |
| 496 | 498 | |
| 497 | 499 | |
| 498 | 500 | ############################################################################### |
| @@ -500,12 +502,13 @@ | ||
| 500 | 502 | |
| 501 | 503 | foreach configArea {alias interwiki} { |
| 502 | 504 | configNew r-$configArea.fossil |
| 503 | 505 | configFill r-$configArea.fossil |
| 504 | 506 | 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] | |
| 507 | 510 | } |
| 508 | 511 | configNew r-all.fossil |
| 509 | 512 | configFill r-all.fossil |
| 510 | 513 | configRun configuration reset all -R r-all.fossil |
| 511 | 514 | test config-reset-all-removes-aliases {[configSql r-all.fossil "SELECT count(*) |
| @@ -569,11 +572,12 @@ | ||
| 569 | 572 | |
| 570 | 573 | ############################################################################### |
| 571 | 574 | # Names of areas and methods: an abbreviation that starts the name is |
| 572 | 575 | # enough. An unknown area lists the areas and writes nothing. |
| 573 | 576 | |
| 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 | |
| 575 | 579 | a alias al alias all all su subscriber i interwiki |
| 576 | 580 | x xfer c css} { |
| 577 | 581 | file delete abbrev.cfg |
| 578 | 582 | configRun configuration export $configAbbrev abbrev.cfg -R a.fossil |
| 579 | 583 | test config-area-abbrev-$configAbbrev {$CODE == 0 && [file exists abbrev.cfg]} |
| @@ -584,14 +588,14 @@ | ||
| 584 | 588 | } |
| 585 | 589 | file delete abbrev.cfg |
| 586 | 590 | foreach configBad {nosuch skinx ALL Skin} { |
| 587 | 591 | configRun configuration export $configBad abbrev.cfg -R a.fossil |
| 588 | 592 | 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"]] && | |
| 593 | 597 | ![file exists abbrev.cfg]} |
| 594 | 598 | } |
| 595 | 599 | foreach configMethod {reset pull push sync} { |
| 596 | 600 | configRun configuration $configMethod nosuch -R a.fossil |
| 597 | 601 | test config-area-unknown-$configMethod {$CODE == 1 && |
| @@ -600,14 +604,16 @@ | ||
| 600 | 604 | |
| 601 | 605 | # The methods accept abbreviations too. |
| 602 | 606 | foreach {configAbbrev configFull} {exp export e export ex export} { |
| 603 | 607 | file delete abbrev.cfg |
| 604 | 608 | 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]} | |
| 606 | 611 | } |
| 607 | 612 | 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} { | |
| 609 | 615 | configRun configuration $configAbbrev export-skin.cfg -R m-abbrev.fossil |
| 610 | 616 | test config-method-abbrev-$configAbbrev {$CODE == 0 && |
| 611 | 617 | [configSql m-abbrev.fossil "SELECT value FROM config |
| 612 | 618 | WHERE name='css'"] eq "body { color: #123; }"} |
| 613 | 619 | fossil sql -R m-abbrev.fossil "DELETE FROM config WHERE name='css'" |
| @@ -635,18 +641,18 @@ | ||
| 635 | 641 | pull-too-many {pull skin a b} |
| 636 | 642 | push-none {push} |
| 637 | 643 | sync-none {sync} |
| 638 | 644 | } { |
| 639 | 645 | 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} | |
| 641 | 648 | } |
| 642 | 649 | configRun configuration frobnicate -R a.fossil |
| 643 | 650 | 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"\ | |
| 645 | 653 | $RESULT] >= 0} |
| 646 | -configRun configuration -R a.fossil | |
| 647 | -test config-method-missing {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} | |
| 648 | 654 | configRun configuration import nosuchfile.cfg -R a.fossil |
| 649 | 655 | test config-import-no-file {$CODE == 1} |
| 650 | 656 | |
| 651 | 657 | |
| 652 | 658 | ############################################################################### |
| @@ -691,11 +697,12 @@ | ||
| 691 | 697 | test_eq config-merge-$name [configSql m.fossil $sql] $expected |
| 692 | 698 | } |
| 693 | 699 | configMergeCheck newer-local-kept "SELECT value FROM config WHERE name='css'" \ |
| 694 | 700 | local-css |
| 695 | 701 | 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" | |
| 697 | 704 | configMergeCheck equal-time-local-kept "SELECT value FROM config |
| 698 | 705 | WHERE name='mainmenu'" local-menu |
| 699 | 706 | configMergeCheck absent-added "SELECT value FROM config WHERE name='js'" \ |
| 700 | 707 | "var a = 'b';" |
| 701 | 708 | configMergeCheck alias-newer-local-kept "SELECT value FROM config |
| @@ -746,29 +753,28 @@ | ||
| 746 | 753 | test_eq config-merge-twice [configState m.fossil all] $configMerged |
| 747 | 754 | |
| 748 | 755 | # Merge into an empty repository is import. |
| 749 | 756 | configNew m2.fossil |
| 750 | 757 | 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} { | |
| 752 | 760 | test_eq config-merge-empty-$configArea [configState m2.fossil $configArea] \ |
| 753 | 761 | [configState a.fossil $configArea 1] |
| 754 | 762 | } |
| 755 | 763 | |
| 756 | 764 | # Import and merge write only inside one transaction: a file that stops the |
| 757 | 765 | # command leaves the repository as it was. A file with a card that SQLite |
| 758 | 766 | # cannot take (a repeated column) is such a file. |
| 759 | 767 | configNew t.fossil |
| 760 | 768 | 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' | |
| 764 | 771 | pw 'h' pw 'i' pw 'j' pw 'k' pw 'l' pw 'm' pw 'n'" |
| 765 | 772 | write_file tx.cfg "[configCard config "1700000100 'css' value 'changed'"]\ |
| 766 | 773 | [configCard user $configTxCard2]" |
| 767 | 774 | configRun configuration merge tx.cfg -R t.fossil |
| 768 | 775 | set configTxCode $CODE |
| 769 | -set configTxOut $RESULT | |
| 770 | 776 | test config-card-many-fields {$configTxCode == 0 || $configTxCode == 1} |
| 771 | 777 | fossil test-integrity -R t.fossil |
| 772 | 778 | test config-card-many-fields-integrity {$CODE == 0} |
| 773 | 779 | |
| 774 | 780 | ############################################################################### |
| @@ -817,11 +823,12 @@ | ||
| 817 | 823 | string-lone {'} |
| 818 | 824 | null-prefix {NULLx} |
| 819 | 825 | not-null {NUL} |
| 820 | 826 | } { |
| 821 | 827 | 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"] | |
| 823 | 830 | configRun configuration merge lit.cfg -R l.fossil |
| 824 | 831 | test config-literal-refused-$configNm {$CODE == 0 && |
| 825 | 832 | [configSql l.fossil "SELECT count(*) FROM config |
| 826 | 833 | WHERE name='header'"] == 0} |
| 827 | 834 | } |
| @@ -833,45 +840,40 @@ | ||
| 833 | 840 | # if it were not there. Nothing is written that the card did not name. |
| 834 | 841 | |
| 835 | 842 | # Everything that REPO holds, settings and tables, except the two settings |
| 836 | 843 | # that a server of the repository writes for its own use. |
| 837 | 844 | proc configDump {repo} { |
| 838 | - global configTables | |
| 839 | 845 | set sql "SELECT 'cfg', name, quote(value), mtime FROM config |
| 840 | 846 | WHERE name<>'backoffice' AND name NOT GLOB 'baseurl:*' |
| 841 | 847 | 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] | |
| 845 | 849 | return [configSql $repo $sql] |
| 846 | 850 | } |
| 847 | 851 | |
| 848 | 852 | configNew c.fossil |
| 849 | 853 | configPut c.fossil {css {'old'} js {'old'}} 1700000000 |
| 854 | +set configStart [configDump c.fossil] | |
| 850 | 855 | set configGood [configCard config "1700000500 'footer' value 'good'"] |
| 851 | -set configCases 0 | |
| 852 | 856 | |
| 853 | 857 | # Run import and merge of TEXT into a copy of c.fossil. Both must leave |
| 854 | 858 | # the repository as it was, except that the card "footer" at the end of the |
| 855 | 859 | # file, when GOOD is true, is read. |
| 856 | 860 | proc configMalformed {name text good {code 0}} { |
| 857 | - global configGood configCases | |
| 861 | + global configGood configStart | |
| 858 | 862 | foreach method {merge import} { |
| 859 | 863 | set repo c-$method.fossil |
| 860 | 864 | file copy -force c.fossil $repo |
| 861 | - set before [configDump $repo] | |
| 862 | 865 | write_file bad.cfg [expr {$good ? "$text$configGood" : $text}] |
| 863 | 866 | configRun configuration $method bad.cfg -R $repo |
| 864 | - set after [configDump $repo] | |
| 865 | 867 | test config-malformed-$name-$method-exit {$::CODE == $code} |
| 866 | 868 | 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'"] | |
| 868 | 871 | 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 | } |
| 872 | - test_eq config-malformed-$name-$method-unchanged $after $before | |
| 873 | + test_eq config-malformed-$name-$method-unchanged [configDump $repo] \ | |
| 874 | + $configStart | |
| 873 | 875 | } |
| 874 | 876 | } |
| 875 | 877 | set configBody "1700000600 'css' value 'new'\n" |
| 876 | 878 | set configLen [string length $configBody] |
| 877 | 879 | |
| @@ -889,16 +891,19 @@ | ||
| 889 | 891 | configMalformed negative-size "config /config -5\n$configBody\n" 1 |
| 890 | 892 | configMalformed size-letters "config /config 12ab\n$configBody\n" 1 |
| 891 | 893 | configMalformed size-plus "config /config +$configLen\n$configBody\n" 1 |
| 892 | 894 | configMalformed size-hex "config /config 0x10\n$configBody\n" 1 |
| 893 | 895 | 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 | |
| 896 | 900 | configMalformed size-zero "config /config 0\n\n" 1 |
| 897 | 901 | configMalformed size-short "config /config 10\n$configBody\n" 1 |
| 898 | 902 | 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 | |
| 900 | 905 | foreach {configNm configCardBody} { |
| 901 | 906 | missing-mtime "'css' value 'x'\n" |
| 902 | 907 | bare-name "1700000600 css value 'x'\n" |
| 903 | 908 | name-only "1700000600\n" |
| 904 | 909 | empty-card "\n" |
| @@ -906,14 +911,16 @@ | ||
| 906 | 911 | zero-byte-time "\0001700000600 'css' value 'x'\n" |
| 907 | 912 | zero-byte-name "1700000600 \000'css' value 'x'\n" |
| 908 | 913 | } { |
| 909 | 914 | configMalformed $configNm [configCard config $configCardBody] 1 |
| 910 | 915 | } |
| 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 | |
| 912 | 918 | exponent 1e3 quoted '5'} { |
| 913 | 919 | 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 | |
| 915 | 922 | } |
| 916 | 923 | |
| 917 | 924 | # A size that is larger than the rest of the file takes the rest. |
| 918 | 925 | foreach configMethod {merge import} { |
| 919 | 926 | file copy -force c.fossil c-$configMethod.fossil |
| @@ -927,25 +934,28 @@ | ||
| 927 | 934 | # A field that is not a column of the table is skipped; one that would |
| 928 | 935 | # set a column that nothing outside may set is among them. |
| 929 | 936 | configNew k.fossil |
| 930 | 937 | fossil sql -R k.fossil "INSERT INTO user(login,pw,cap,mtime) |
| 931 | 938 | 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'\ | |
| 933 | 941 | cexpire 1 uid 77 login 'mallory' bogus 'x' info 'Carol'\n" |
| 934 | 942 | write_file fields.cfg [configCard user $configCardBody] |
| 935 | 943 | configRun configuration merge fields.cfg -R k.fossil |
| 936 | 944 | test config-field-skipped {$CODE == 0} |
| 937 | 945 | test_eq config-field-skipped-row [configSql k.fossil "SELECT login, cap, info, |
| 938 | 946 | 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" | |
| 940 | 949 | test_eq config-field-skipped-uid [configSql k.fossil "SELECT count(*) FROM user |
| 941 | 950 | WHERE uid=77"] 0 |
| 942 | 951 | |
| 943 | 952 | # A card that holds more field pairs than the command keeps is read up to |
| 944 | 953 | # the eleventh field, and the later ones are dropped. |
| 945 | 954 | 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'"} | |
| 947 | 957 | write_file many.cfg [configCard user "$configCardBody\n"] |
| 948 | 958 | configRun configuration merge many.cfg -R k.fossil |
| 949 | 959 | test config-fields-many {$CODE == 0 && |
| 950 | 960 | [configSql k.fossil "SELECT info FROM user WHERE login='carol'"] eq "Carol"} |
| 951 | 961 | fossil sql -R k.fossil "UPDATE user SET mtime=5 WHERE login='carol'" |
| @@ -973,12 +983,10 @@ | ||
| 973 | 983 | # identity of the repository and its schema), and those that carry commands |
| 974 | 984 | # and are never exported. |
| 975 | 985 | |
| 976 | 986 | configNew n.fossil |
| 977 | 987 | set configNBefore [configDump n.fossil] |
| 978 | -set configNProject [configSql n.fossil "SELECT value FROM config | |
| 979 | - WHERE name='project-code'"] | |
| 980 | 988 | foreach configNm {project-code server-code content-schema aux-schema rebuilt |
| 981 | 989 | th1-setup tcl-setup email-send-command diff-command editor |
| 982 | 990 | ssh-command nosuch head headers Header walias:docs interwiki |
| 983 | 991 | ticket_table} { |
| 984 | 992 | set configCardBody "1700000600 '$configNm' value 'x'\n" |
| @@ -988,12 +996,10 @@ | ||
| 988 | 996 | [string first "Skipping non-exportable setting: '$configNm' = 'x'" \ |
| 989 | 997 | $RESULT] >= 0} |
| 990 | 998 | test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \ |
| 991 | 999 | $configNBefore |
| 992 | 1000 | } |
| 993 | -test_eq config-not-exportable-project-code [configSql n.fossil "SELECT value | |
| 994 | - FROM config WHERE name='project-code'"] $configNProject | |
| 995 | 1001 | foreach {configNm configCardBody} { |
| 996 | 1002 | number "1700000600 12 value 'x'\n" |
| 997 | 1003 | empty "1700000600 '' value 'x'\n" |
| 998 | 1004 | blob "1700000600 x'6373' value 'x'\n" |
| 999 | 1005 | null "1700000600 NULL value 'x'\n" |
| @@ -1062,24 +1068,27 @@ | ||
| 1062 | 1068 | set configOut [configOutside $configC $configArea] |
| 1063 | 1069 | set configPre [configDump $configC] |
| 1064 | 1070 | configRun configuration pull $configArea $configSrv -R $configC |
| 1065 | 1071 | test config-pull-$configArea {$CODE == 0} |
| 1066 | 1072 | 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 | |
| 1068 | 1075 | configSameAs config-pull-$configArea-same $configC $configArea a.fossil |
| 1069 | 1076 | fossil test-integrity -R $configC |
| 1070 | 1077 | test config-pull-$configArea-integrity {$CODE == 0} |
| 1071 | 1078 | |
| 1072 | 1079 | # Push. |
| 1073 | 1080 | set configD srv-push-$configArea.fossil |
| 1074 | 1081 | configNew $configD |
| 1075 | 1082 | set configOut [configOutside $configD $configArea] |
| 1076 | 1083 | 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 | |
| 1078 | 1086 | test config-push-$configArea {$CODE == 0} |
| 1079 | 1087 | 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 | |
| 1081 | 1090 | configSameAs config-push-$configArea-same $configD $configArea a.fossil |
| 1082 | 1091 | fossil test-integrity -R $configD |
| 1083 | 1092 | test config-push-$configArea-integrity {$CODE == 0} |
| 1084 | 1093 | } |
| 1085 | 1094 | |
| @@ -1104,29 +1113,38 @@ | ||
| 1104 | 1113 | test config-sync {$CODE == 0} |
| 1105 | 1114 | set configAliasSql "SELECT name,value,mtime FROM config |
| 1106 | 1115 | WHERE name GLOB 'walias:/*' ORDER BY name" |
| 1107 | 1116 | # A value with the same time on both sides stays as each side has it. |
| 1108 | 1117 | 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"] ""] | |
| 1110 | 1122 | 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"] ""] | |
| 1112 | 1127 | |
| 1113 | 1128 | # Pull with --overwrite replaces the tables of the area, so a user that only |
| 1114 | 1129 | # this side has is gone; without it the user stays. |
| 1115 | 1130 | configNew o1.fossil |
| 1116 | 1131 | 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)" | |
| 1119 | 1136 | fossil sql -R o1.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x1',7,'l')" |
| 1120 | 1137 | fossil sql -R o2.fossil "INSERT INTO shun(uuid,mtime,scom) VALUES('x2',8,'r')" |
| 1121 | 1138 | configRun configuration pull shun [file join $configDir o2.fossil] -R o1.fossil |
| 1122 | 1139 | test_eq config-pull-keeps-rows [configSql o1.fossil "SELECT group_concat(uuid) |
| 1123 | 1140 | FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x1,x2" |
| 1124 | 1141 | configRun configuration pull shun --overwrite [file join $configDir o2.fossil] \ |
| 1125 | 1142 | -R o1.fossil |
| 1126 | 1143 | 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) | |
| 1128 | 1146 | FROM (SELECT uuid FROM shun ORDER BY uuid)"] "x2" |
| 1129 | 1147 | configRun configuration pull user --overwrite [file join $configDir o2.fossil] \ |
| 1130 | 1148 | -R o1.fossil |
| 1131 | 1149 | test config-pull-overwrite-user {$CODE == 0 && [configSql o1.fossil "SELECT |
| 1132 | 1150 | group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] ne ""} |
| @@ -1155,16 +1173,18 @@ | ||
| 1155 | 1173 | fossil remote file://[file join $configDir a.fossil] -R u1.fossil |
| 1156 | 1174 | configRun configuration pull skin -R u1.fossil |
| 1157 | 1175 | test config-pull-default-server {$CODE == 0 && |
| 1158 | 1176 | [configSql u1.fossil "SELECT value FROM config WHERE name='css'"] eq |
| 1159 | 1177 | "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] \ | |
| 1161 | 1180 | -R u1.fossil |
| 1162 | 1181 | test config-pull-proxy-off {$CODE == 0 && |
| 1163 | 1182 | [configSql u1.fossil "SELECT value FROM config |
| 1164 | 1183 | 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 | |
| 1166 | 1186 | test config-pull-no-such-repository {$CODE == 1} |
| 1167 | 1187 | |
| 1168 | 1188 | |
| 1169 | 1189 | ############################################################################################################################################### |
| 1170 | 1190 | # The configuration that a server sends on request: an area it does not know |
| @@ -1173,13 +1193,13 @@ | ||
| 1173 | 1193 | configNew sv.fossil |
| 1174 | 1194 | configPut sv.fossil {css {'hello'} header {'h'}} 1700000000 |
| 1175 | 1195 | write_file req.txt "$CLIENT_VERSION_CARD\ |
| 1176 | 1196 | reqconfig /nosuch\nreqconfig /css\nreqconfig css\nreqconfig /nosuch2\n" |
| 1177 | 1197 | 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"}]} | |
| 1181 | 1201 | |
| 1182 | 1202 | ############################################################################### |
| 1183 | 1203 | # A repository whose user and ticket report tables do not have the column |
| 1184 | 1204 | # for JSON data exports them without it, and takes the cards that have no |
| 1185 | 1205 | # such field. |
| @@ -1213,11 +1233,12 @@ | ||
| 1213 | 1233 | write_file in.txt "from a file\nwith two lines\n" |
| 1214 | 1234 | fossil test-var-set beta --file in.txt -R v.fossil |
| 1215 | 1235 | fossil test-var-get beta -R v.fossil |
| 1216 | 1236 | test_eq config-var-set-file $RESULT "from a file\nwith two lines" |
| 1217 | 1237 | 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" | |
| 1219 | 1240 | set configBlob "\x00\x01\xff\xfe\x80binary" |
| 1220 | 1241 | write_file blob.bin $configBlob |
| 1221 | 1242 | fossil test-var-set gamma --blob blob.bin -R v.fossil |
| 1222 | 1243 | fossil test-var-get gamma out3.bin -R v.fossil |
| 1223 | 1244 | test_eq config-var-set-blob [read_file out3.bin] $configBlob |
| @@ -1228,24 +1249,25 @@ | ||
| 1228 | 1249 | test_eq config-var-set-stdin-value [configSql v.fossil "SELECT length(value) |
| 1229 | 1250 | FROM config WHERE name='delta'"] 9 |
| 1230 | 1251 | fossil_raw test-var-set -R v.fossil |
| 1231 | 1252 | test config-var-set-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} |
| 1232 | 1253 | 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} | |
| 1234 | 1256 | fossil_raw test-var-set epsilon --file in.txt --blob blob.bin -R v.fossil |
| 1235 | 1257 | test config-var-set-both {$CODE == 1 && |
| 1236 | 1258 | [string first "cannot do both" $RESULT] >= 0} |
| 1237 | 1259 | fossil_raw test-var-set epsilon --file nosuch.txt -R v.fossil |
| 1238 | 1260 | test config-var-set-no-file {$CODE == 1} |
| 1239 | 1261 | test_eq config-var-set-none-made [configSql v.fossil "SELECT count(*) FROM |
| 1240 | 1262 | config WHERE name='epsilon'"] 0 |
| 1241 | 1263 | 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} | |
| 1243 | 1266 | fossil_raw test-var-get {[abg]*} -R v.fossil |
| 1244 | 1267 | 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'}]} | |
| 1247 | 1269 | fossil_raw test-var-get -R v.fossil |
| 1248 | 1270 | test config-var-get-usage {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} |
| 1249 | 1271 | fossil test-var-get {alph?} -R v.fossil |
| 1250 | 1272 | test_eq config-var-get-glob $RESULT hello |
| 1251 | 1273 | |
| @@ -1273,11 +1295,12 @@ | ||
| 1273 | 1295 | proc configListLine {name value pad} { |
| 1274 | 1296 | return "$name:[string repeat { } [expr {$pad - [string length $name]}]]$value" |
| 1275 | 1297 | } |
| 1276 | 1298 | configRun test-var-list -R w.fossil |
| 1277 | 1299 | 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" \ | |
| 1279 | 1302 | $configList] >= 0} |
| 1280 | 1303 | test config-var-list-escapes {[string first \ |
| 1281 | 1304 | "[configListLine a-ctl {x\n\r\t\001y} 27]\n" $configList] >= 0} |
| 1282 | 1305 | test config-var-list-long-value {[string first \ |
| 1283 | 1306 | "[configListLine a-long [string range $configLongValue 0 39]...+20 27]\n" \ |
| @@ -1405,11 +1428,12 @@ | ||
| 1405 | 1428 | configShareProject $configC |
| 1406 | 1429 | set configPre [configDump $configC] |
| 1407 | 1430 | configNetRun pull $configArea $configC $configPort $configUser |
| 1408 | 1431 | test config-pull-$configLabel-$configArea {$CODE == 0} |
| 1409 | 1432 | foreach configPart [configParts $configArea] { |
| 1410 | - configHasPart config-pull-$configLabel-$configArea-has $configC $configPart \ | |
| 1433 | + configHasPart config-pull-$configLabel-$configArea-has $configC \ | |
| 1434 | + $configPart \ | |
| 1411 | 1435 | [configMayPull $configUser $configPart] |
| 1412 | 1436 | } |
| 1413 | 1437 | if {$configUser ne "blind" && $configLabel ne "nobody"} { |
| 1414 | 1438 | test config-pull-$configLabel-$configArea-changed \ |
| 1415 | 1439 | {[configDump $configC] ne $configPre} |
| @@ -1452,31 +1476,12 @@ | ||
| 1452 | 1476 | # Cards that a server sends for configuration that was not asked for are |
| 1453 | 1477 | # dropped by the client, those it asked for are kept. A server made here |
| 1454 | 1478 | # answers the first request with a prepared reply and every later one with a |
| 1455 | 1479 | # bare timestamp. |
| 1456 | 1480 | |
| 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} { | |
| 1468 | 1482 | 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 | 1483 | # The request is the text of the cards, after four bytes of size when it |
| 1479 | 1484 | # is compressed. |
| 1480 | 1485 | set body [string range $request [expr {$end+4}] end] |
| 1481 | 1486 | if {[regexp -nocase {content-type:\s*application/x-fossil\s} $request]} { |
| 1482 | 1487 | set body [zlib decompress [string range $body 4 end]] |
| @@ -1492,12 +1497,11 @@ | ||
| 1492 | 1497 | application/x-fossil-uncompressed\r\nContent-Length:\ |
| 1493 | 1498 | [string length $reply]\r\n\r\n$reply" |
| 1494 | 1499 | close $chan |
| 1495 | 1500 | } |
| 1496 | 1501 | } |
| 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] | |
| 1499 | 1503 | |
| 1500 | 1504 | proc configReply {verb area reply} { |
| 1501 | 1505 | global configFakePort configFakeReply configFakeCount configFakeRequests |
| 1502 | 1506 | set configFakeReply $reply |
| 1503 | 1507 | set configFakeCount 0 |
| @@ -1517,11 +1521,12 @@ | ||
| 1517 | 1521 | test_eq config-reply-asked [configSql rp.fossil "SELECT group_concat(name) |
| 1518 | 1522 | FROM (SELECT name FROM config WHERE name IN ('header','adunit', |
| 1519 | 1523 | 'project-name') ORDER BY name)"] "adunit,header" |
| 1520 | 1524 | test_eq config-reply-unasked-user [configSql rp.fossil "SELECT count(*) FROM |
| 1521 | 1525 | 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" \ | |
| 1523 | 1528 | [lindex $configFakeRequests 0]] >= 0} |
| 1524 | 1529 | configReply pull css $configRpReply |
| 1525 | 1530 | test_eq config-reply-css-only [configSql rp.fossil "SELECT count(*) FROM |
| 1526 | 1531 | config WHERE name='project-name'"] 0 |
| 1527 | 1532 | # How many "reqconfig" cards the first request holds. |
| @@ -1539,11 +1544,11 @@ | ||
| 1539 | 1544 | configReply pull ticket "" |
| 1540 | 1545 | test config-reply-request-ticket {[string first "reqconfig /ticket\n" \ |
| 1541 | 1546 | [lindex $configFakeRequests 0]] >= 0} |
| 1542 | 1547 | configReply pull user "config /user 0\n\n" |
| 1543 | 1548 | test config-reply-empty-card {$CODE == 0} |
| 1544 | -close $configFakeServer | |
| 1549 | +test_listen_stop | |
| 1545 | 1550 | |
| 1546 | 1551 | ############################################################################### |
| 1547 | 1552 | # "fossil init --template" copies the settings of another repository, |
| 1548 | 1553 | # those of every area and the aliases among them, and leaves out the names |
| 1549 | 1554 | # of the project and any setting that belongs to no area. |
| 1550 | 1555 |
| --- 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 @@ | ||
| 6 | 6 | # |
| 7 | 7 | # integrity.test damages a repository and requires the damage to be |
| 8 | 8 | # found. This file covers what is left. |
| 9 | 9 | # |
| 10 | 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 | 11 | require_no_open_checkout |
| 17 | 12 | |
| 18 | 13 | test_setup |
| 19 | 14 | |
| 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 | 15 | # The record number of the artifact with the given hash. |
| 29 | 16 | # |
| 30 | 17 | 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'"] | |
| 40 | 19 | } |
| 41 | 20 | |
| 42 | 21 | # Write a file that holds the cards $body and the Z card for them. |
| 43 | 22 | # |
| 44 | 23 | proc content_artifact {filename body} { |
| @@ -67,20 +46,20 @@ | ||
| 67 | 46 | write_file long.txt $contentText |
| 68 | 47 | if {$contentI == 1} {fossil add long.txt} |
| 69 | 48 | fossil commit -m "content-v$contentI" --no-warnings |
| 70 | 49 | lappend contentVersions $contentText |
| 71 | 50 | } |
| 72 | -set contentFirst [content_sql "SELECT uuid FROM blob, mlink, event | |
| 51 | +set contentFirst [fossil_sql "SELECT uuid FROM blob, mlink, event | |
| 73 | 52 | WHERE blob.rid=mlink.fid AND mlink.mid=event.objid |
| 74 | 53 | 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 | |
| 76 | 55 | WHERE blob.rid=mlink.fid AND mlink.mid=event.objid |
| 77 | 56 | AND event.comment='content-v30'"] |
| 78 | 57 | test content-setup {$contentFirst ne "" && $contentLast ne ""} |
| 79 | 58 | |
| 80 | 59 | 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 | |
| 82 | 61 | UNION ALL SELECT srcid, n+1 FROM delta, c WHERE delta.rid=c.rid) |
| 83 | 62 | SELECT max(n) FROM c"] |
| 84 | 63 | } |
| 85 | 64 | test_eq content-chain-length [content_chain [content_rid $contentFirst]] 29 |
| 86 | 65 | |
| @@ -110,11 +89,11 @@ | ||
| 110 | 89 | fossil test-content-rawget -expectError |
| 111 | 90 | test content-rawget-usage {$CODE != 0} |
| 112 | 91 | |
| 113 | 92 | fossil test-content-undelta $contentRid |
| 114 | 93 | 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 \ | |
| 116 | 95 | "SELECT count(*) FROM delta WHERE rid=$contentRid"] 0 |
| 117 | 96 | fossil test-content-rawget $contentFirst raw.out |
| 118 | 97 | test_eq content-undelta-stored-whole [read_file raw.out] \ |
| 119 | 98 | [lindex $contentVersions 0] |
| 120 | 99 | fossil test-content-undelta $contentRid |
| @@ -123,36 +102,36 @@ | ||
| 123 | 102 | test content-undelta-usage {$CODE != 0} |
| 124 | 103 | |
| 125 | 104 | ############################################################################### |
| 126 | 105 | # Turning content into a delta. |
| 127 | 106 | |
| 128 | -set contentSecond [content_sql "SELECT blob.rid FROM blob, mlink, event | |
| 107 | +set contentSecond [fossil_sql "SELECT blob.rid FROM blob, mlink, event | |
| 129 | 108 | WHERE blob.rid=mlink.fid AND mlink.mid=event.objid |
| 130 | 109 | 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 | |
| 132 | 111 | WHERE blob.rid=mlink.fid AND mlink.mid=event.objid |
| 133 | 112 | AND event.comment='content-v3'"] |
| 134 | 113 | set contentLastRid [content_rid $contentLast] |
| 135 | 114 | |
| 136 | 115 | # The artifact itself and an artifact that is a delta from it are not |
| 137 | 116 | # used as sources. Of the two that remain, one is taken. |
| 138 | 117 | fossil test-content-deltify $contentRid $contentRid $contentLastRid \ |
| 139 | 118 | $contentSecond |
| 140 | 119 | 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 | |
| 142 | 121 | WHERE rid=$contentRid"] in [list $contentLastRid $contentSecond]} |
| 143 | 122 | fossil artifact $contentFirst first.out |
| 144 | 123 | test_eq content-deltify-same-content [read_file first.out] \ |
| 145 | 124 | [lindex $contentVersions 0] |
| 146 | 125 | |
| 147 | 126 | # 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"] | |
| 149 | 128 | 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 | |
| 151 | 130 | WHERE rid=$contentRid"] $contentSrc |
| 152 | 131 | 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 | |
| 154 | 133 | WHERE rid=$contentRid"] $contentThird |
| 155 | 134 | fossil artifact $contentFirst first.out |
| 156 | 135 | test_eq content-deltify-forced-same-content [read_file first.out] \ |
| 157 | 136 | [lindex $contentVersions 0] |
| 158 | 137 | |
| @@ -168,38 +147,38 @@ | ||
| 168 | 147 | # Content of less than 50 bytes is never made a delta, nor used as the |
| 169 | 148 | # source of one. |
| 170 | 149 | write_file small.txt "small\n" |
| 171 | 150 | write_file small2.txt "small too\n" |
| 172 | 151 | 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]] | |
| 175 | 154 | 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 | |
| 177 | 156 | WHERE rid=$contentSmall"] 0 |
| 178 | 157 | fossil test-content-undelta $contentRid |
| 179 | 158 | 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 | |
| 181 | 160 | WHERE rid=$contentRid"] 0 |
| 182 | 161 | |
| 183 | 162 | # Unrelated content is not worth a delta. |
| 184 | 163 | write_file other.txt [string repeat "nothing in common with the file\n" 40] |
| 185 | 164 | 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 | |
| 188 | 167 | WHERE rid=$contentRid"] 0 |
| 189 | 168 | |
| 190 | 169 | # Public content is not made a delta from private content. |
| 191 | 170 | write_file private.txt "${contentText}and one private line\n" |
| 192 | 171 | fossil test-content-put private.txt |
| 193 | -set contentPrivate [content_rid [content_hash private.txt]] | |
| 172 | +set contentPrivate [content_rid [sha3_file private.txt]] | |
| 194 | 173 | fossil sql "INSERT INTO private(rid) VALUES($contentPrivate)" |
| 195 | 174 | 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 | |
| 197 | 176 | WHERE rid=$contentRid"] 0 |
| 198 | 177 | fossil sql "DELETE FROM private WHERE rid=$contentPrivate" |
| 199 | 178 | 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 | |
| 201 | 180 | WHERE rid=$contentRid"] $contentPrivate |
| 202 | 181 | fossil test-content-undelta $contentRid |
| 203 | 182 | |
| 204 | 183 | # Of two sources that both make a worthwhile delta, the one that makes |
| 205 | 184 | # the smaller is taken, whichever comes first. |
| @@ -210,31 +189,31 @@ | ||
| 210 | 189 | write_file two-target.txt $contentBase |
| 211 | 190 | write_file two-near.txt "${contentBase}one more line\n" |
| 212 | 191 | write_file two-far.txt "[string range $contentBase 0 1500][string repeat \ |
| 213 | 192 | "a line that the target does not have\n" 30]" |
| 214 | 193 | 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]] | |
| 218 | 197 | 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 | |
| 220 | 199 | FROM delta WHERE rid=$contentTarget"] $contentNear |
| 221 | 200 | fossil test-content-undelta $contentTarget |
| 222 | 201 | 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 | |
| 224 | 203 | FROM delta WHERE rid=$contentTarget"] $contentNear |
| 225 | 204 | fossil test-content-undelta $contentTarget |
| 226 | 205 | 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 | |
| 228 | 207 | FROM delta WHERE rid=$contentTarget"] $contentFar |
| 229 | 208 | fossil test-content-undelta $contentTarget |
| 230 | 209 | |
| 231 | 210 | # Private content may be a delta from private content. |
| 232 | 211 | fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentPrivate)" |
| 233 | 212 | fossil sql "INSERT OR IGNORE INTO private(rid) VALUES($contentRid)" |
| 234 | 213 | 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 | |
| 236 | 215 | FROM delta WHERE rid=$contentRid"] $contentPrivate |
| 237 | 216 | fossil test-content-undelta $contentRid |
| 238 | 217 | fossil sql "DELETE FROM private WHERE rid IN ($contentPrivate,$contentRid)" |
| 239 | 218 | |
| 240 | 219 | fossil test-content-deltify -expectError |
| @@ -247,33 +226,33 @@ | ||
| 247 | 226 | # test-content-put with --moderate. |
| 248 | 227 | |
| 249 | 228 | write_file moderated.txt "content awaiting moderation\n" |
| 250 | 229 | fossil test-content-put --moderate moderated.txt |
| 251 | 230 | 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 | |
| 254 | 233 | |
| 255 | 234 | ############################################################################### |
| 256 | 235 | # Content that arrives after it was asked for. A check-in names a file |
| 257 | 236 | # that is not in the repository; when the file is stored, the check-in |
| 258 | 237 | # has it. A delta manifest is stored before its baseline; when the |
| 259 | 238 | # baseline arrives, the delta manifest becomes a check-in. |
| 260 | 239 | |
| 261 | 240 | write_file late.txt "this file arrives late\n" |
| 262 | -set contentLate [content_hash late.txt] | |
| 241 | +set contentLate [sha3_file late.txt] | |
| 263 | 242 | content_artifact ci-late.txt "C content-late |
| 264 | 243 | D 2026-03-01T10:00:00.000 |
| 265 | 244 | F late.txt $contentLate |
| 266 | 245 | U alice |
| 267 | 246 | " |
| 268 | 247 | 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 | |
| 270 | 249 | WHERE uuid='$contentLate'"] -1 |
| 271 | 250 | fossil artifact $contentLate |
| 272 | 251 | test content-phantom-has-no-content {$CODE == 0 && $RESULT eq ""} |
| 273 | 252 | 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 | |
| 275 | 254 | WHERE uuid='$contentLate'"] [file size late.txt] |
| 276 | 255 | fossil artifact $contentLate late.out |
| 277 | 256 | test content-phantom-filled-content {[same_file late.txt late.out]} |
| 278 | 257 | |
| 279 | 258 | content_artifact ci-base.txt "C content-base |
| @@ -280,29 +259,29 @@ | ||
| 280 | 259 | D 2026-03-02T10:00:00.000 |
| 281 | 260 | F a.txt $contentLate |
| 282 | 261 | F b.txt $contentLate |
| 283 | 262 | U alice |
| 284 | 263 | " |
| 285 | -set contentBase [content_hash ci-base.txt] | |
| 264 | +set contentBase [sha3_file ci-base.txt] | |
| 286 | 265 | content_artifact ci-delta.txt "B $contentBase |
| 287 | 266 | C content-delta |
| 288 | 267 | D 2026-03-02T11:00:00.000 |
| 289 | 268 | F b.txt |
| 290 | 269 | F c.txt $contentLate |
| 291 | 270 | P $contentBase |
| 292 | 271 | U alice |
| 293 | 272 | " |
| 294 | 273 | 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 | |
| 296 | 275 | 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 | |
| 298 | 277 | fossil test-content-put --crosslink ci-base.txt |
| 299 | 278 | 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 | |
| 301 | 280 | 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] | |
| 304 | 283 | test_eq content-orphan-files [normalize_result] "a.txt\nc.txt" |
| 305 | 284 | |
| 306 | 285 | ############################################################################### |
| 307 | 286 | # test-integrity: the options that check the database only, and --parse |
| 308 | 287 | # on content that looks like an artifact and is not one. |
| @@ -319,45 +298,47 @@ | ||
| 319 | 298 | write_file looks5.txt "D 2026-03-03T10:00:00.000\nno newline at the end" |
| 320 | 299 | # Content that does not begin with a card at all, content whose first line |
| 321 | 300 | # holds a zero byte, and content whose first line is very long. |
| 322 | 301 | write_file looks6.txt "1 begins with a digit, which no card does\n" |
| 323 | 302 | 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" | |
| 325 | 305 | write_file looks9.txt "C [string repeat x 500]\nand a second line\n" |
| 326 | 306 | # Content that is the first line of a signed message and nothing more, |
| 327 | 307 | # with no end of line. |
| 328 | 308 | write_file looks10.txt "-----BEGIN PGP SIGNED MESSAGE-----" |
| 329 | 309 | fossil test-content-put looks1.txt looks2.txt looks3.txt looks4.txt looks5.txt \ |
| 330 | 310 | looks6.txt looks7.txt looks8.txt looks9.txt looks10.txt |
| 331 | -set contentLooks10 [content_hash looks10.txt] | |
| 311 | +set contentLooks10 [sha3_file looks10.txt] | |
| 332 | 312 | fossil test-integrity --parse |
| 333 | 313 | test content-integrity-parse {$CODE == 0} |
| 334 | 314 | 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} | |
| 336 | 317 | test content-integrity-parse-one-line-signed \ |
| 337 | 318 | {[string first "manifest_parse failed for $contentLooks10:" $RESULT] >= 0} |
| 338 | 319 | test content-integrity-parse-first-line \ |
| 339 | 320 | {[string first "\"C this looks like a card\"" $RESULT] >= 0} |
| 340 | 321 | |
| 341 | 322 | # The same content is an error once the repository has it down as a |
| 342 | 323 | # wiki page. |
| 343 | 324 | 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')" | |
| 345 | 326 | fossil test-integrity --parse -expectError |
| 346 | 327 | test content-integrity-parse-listed-artifact {$CODE != 0} |
| 347 | 328 | fossil sql "DELETE FROM event |
| 348 | - WHERE objid=[content_rid [content_hash looks1.txt]]" | |
| 329 | + WHERE objid=[content_rid [sha3_file looks1.txt]]" | |
| 349 | 330 | |
| 350 | 331 | ############################################################################### |
| 351 | 332 | # test-orphans lists content that nothing refers to. |
| 352 | 333 | |
| 353 | 334 | fossil test-orphans |
| 354 | 335 | test content-orphans {$CODE == 0} |
| 355 | 336 | test content-orphans-count \ |
| 356 | 337 | {[regexp {(\d+) orphans} $RESULT all n] && $n >= 9} |
| 357 | 338 | test content-orphans-lists-one \ |
| 358 | - {[string first [content_hash other.txt] $RESULT] >= 0} | |
| 339 | + {[string first [sha3_file other.txt] $RESULT] >= 0} | |
| 359 | 340 | |
| 360 | 341 | ############################################################################### |
| 361 | 342 | # test-missing reports each kind of reference to content that is not |
| 362 | 343 | # there. |
| 363 | 344 | |
| @@ -368,32 +349,52 @@ | ||
| 368 | 349 | fossil test-missing --quiet |
| 369 | 350 | test_eq content-missing-none-quiet [string trim $RESULT] "" |
| 370 | 351 | |
| 371 | 352 | set contentGone [string repeat 0123456789 4] |
| 372 | 353 | 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 | |
| 374 | 355 | 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"] ""] \ | |
| 377 | 361 | "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"] ""] \ | |
| 379 | 366 | "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"] ""] \ | |
| 383 | 380 | "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" \ | |
| 385 | 382 | "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"] ""] \ | |
| 387 | 387 | "MISSING: $contentGone\n*file of attachment *" \ |
| 388 | - cluster "M $contentGone\nM $contentGone2\n" \ | |
| 388 | + cluster 9 "M $contentGone\nM $contentGone2\n" \ | |
| 389 | 389 | "MISSING: $contentGone\n*in cluster *" \ |
| 390 | 390 | ] { |
| 391 | 391 | content_artifact missing-$contentName.txt $contentBody |
| 392 | 392 | fossil test-content-put --crosslink missing-$contentName.txt |
| 393 | 393 | 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]} | |
| 395 | 396 | test content-missing-$contentName-text \ |
| 396 | 397 | {[string match "*$contentWant*" $RESULT]} |
| 397 | 398 | } |
| 398 | 399 | # An attachment that takes a file away names none, and is not counted. |
| 399 | 400 | content_artifact missing-detach.txt \ |
| @@ -408,13 +409,12 @@ | ||
| 408 | 409 | # A missing artifact that is shunned is reported as shunned, or not at |
| 409 | 410 | # all with --notshunned. |
| 410 | 411 | fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$contentGone',0), |
| 411 | 412 | ('$contentGone2',0)" |
| 412 | 413 | 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]]} | |
| 416 | 416 | fossil test-missing --notshunned |
| 417 | 417 | test content-missing-notshunned {$CODE == 0} |
| 418 | 418 | test_match content-missing-notshunned-text $RESULT \ |
| 419 | 419 | {^0 missing or shunned references} |
| 420 | 420 | fossil sql "DELETE FROM shun" |
| @@ -423,29 +423,29 @@ | ||
| 423 | 423 | # test-content-erase asks first. Erasing content that others are deltas |
| 424 | 424 | # from stores those whole. |
| 425 | 425 | |
| 426 | 426 | fossil test-content-undelta $contentRid |
| 427 | 427 | 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 | |
| 429 | 429 | WHERE srcid=$contentRid"] 1 |
| 430 | 430 | 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 | |
| 432 | 432 | WHERE rid=$contentRid"] 1 |
| 433 | 433 | fossil_raw -input "Y\n" test-content-erase $contentRid |
| 434 | 434 | 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 | |
| 436 | 436 | 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 | |
| 438 | 438 | 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"] \ | |
| 440 | 440 | third.out |
| 441 | 441 | test_eq content-erase-dependent-still-whole [read_file third.out] \ |
| 442 | 442 | [lindex $contentVersions 2] |
| 443 | 443 | |
| 444 | 444 | # The answer may be in either case. |
| 445 | 445 | 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 | |
| 447 | 447 | WHERE rid=$contentSmall"] 0 |
| 448 | 448 | |
| 449 | 449 | ############################################################################### |
| 450 | 450 | # A "parent" tag on a private check-in is itself private, and so is the |
| 451 | 451 | # placeholder for a parent that the repository does not have. |
| @@ -454,22 +454,22 @@ | ||
| 454 | 454 | D 2026-03-05T10:00:00.000 |
| 455 | 455 | F late.txt $contentLate |
| 456 | 456 | U alice |
| 457 | 457 | " |
| 458 | 458 | fossil test-content-put --crosslink ci-private.txt |
| 459 | -set contentPriv [content_hash ci-private.txt] | |
| 459 | +set contentPriv [sha3_file ci-private.txt] | |
| 460 | 460 | fossil sql "INSERT INTO private(rid) VALUES([content_rid $contentPriv])" |
| 461 | 461 | set contentAbsent [string repeat 4d 20] |
| 462 | 462 | fossil tag add --raw parent $contentPriv $contentAbsent |
| 463 | 463 | 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(*) | |
| 465 | 465 | FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentAbsent' |
| 466 | 466 | 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(*) | |
| 468 | 468 | FROM unclustered, blob WHERE unclustered.rid=blob.rid |
| 469 | 469 | 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(*) | |
| 471 | 471 | FROM plink WHERE cid=[content_rid $contentPriv] |
| 472 | 472 | AND pid=[content_rid $contentAbsent]"] 1 |
| 473 | 473 | |
| 474 | 474 | ############################################################################### |
| 475 | 475 | # Content that arrives in a sync message, sent to the server side through |
| @@ -490,15 +490,10 @@ | ||
| 490 | 490 | } |
| 491 | 491 | proc content_x {sql} { |
| 492 | 492 | fossil sql -R x.fossil $sql |
| 493 | 493 | return [string trim $::RESULT] |
| 494 | 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 | 495 | proc content_sha3 {text} { |
| 501 | 496 | write_file sha3-me.txt $text |
| 502 | 497 | fossil sha3sum sha3-me.txt |
| 503 | 498 | return [lindex $::RESULT 0] |
| 504 | 499 | } |
| @@ -515,16 +510,17 @@ | ||
| 515 | 510 | global contentYcode CLIENT_VERSION_CARD |
| 516 | 511 | write_file msg.txt "${CLIENT_VERSION_CARD}push x $contentYcode\n$body" |
| 517 | 512 | fossil_raw test-xfer -R y.fossil msg.txt |
| 518 | 513 | } |
| 519 | 514 | 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" | |
| 521 | 516 | test content-policy-sha1-name-accepted {$CODE == 0} |
| 522 | 517 | fossil hash-policy -R y.fossil |
| 523 | 518 | test_eq content-policy-still-auto [string trim $RESULT] auto |
| 524 | 519 | 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" | |
| 526 | 522 | fossil hash-policy -R y.fossil |
| 527 | 523 | test_eq content-policy-now-sha3 [string trim $RESULT] sha3 |
| 528 | 524 | |
| 529 | 525 | # An artifact that the server has only heard of is a phantom. It is |
| 530 | 526 | # filled when its content arrives as a compressed delta from content the |
| @@ -554,11 +550,12 @@ | ||
| 554 | 550 | |
| 555 | 551 | # A phantom that is filled by a private card becomes private. |
| 556 | 552 | set contentP "content that arrives marked private\n" |
| 557 | 553 | set contentPHash [content_sha3 $contentP] |
| 558 | 554 | 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" \ | |
| 560 | 557 | "login tester 0 0\n" |
| 561 | 558 | test content-sync-private-fill {$CODE == 0} |
| 562 | 559 | test_eq content-sync-private-fill-marked [content_x "SELECT count(*) |
| 563 | 560 | FROM private, blob WHERE private.rid=blob.rid AND uuid='$contentPHash' |
| 564 | 561 | AND size>=0"] 1 |
| @@ -612,93 +609,79 @@ | ||
| 612 | 609 | fossil test-integrity -R x.fossil |
| 613 | 610 | test content-sync-integrity {$CODE == 0} |
| 614 | 611 | |
| 615 | 612 | ############################################################################### |
| 616 | 613 | # 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 | +} | |
| 701 | 684 | |
| 702 | 685 | ############################################################################### |
| 703 | 686 | |
| 704 | 687 | test_cleanup |
| 705 | 688 |
| --- 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 @@ | ||
| 8 | 8 | # the ordinary commands never produce: a reply to a forum post, an |
| 9 | 9 | # attachment whose target is not in the repository, a check-in whose |
| 10 | 10 | # baseline is missing. |
| 11 | 11 | # |
| 12 | 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 | - | |
| 13 | +# The first sections run at every level, and the rest need | |
| 14 | +# -assurance stress. | |
| 18 | 15 | require_no_open_checkout |
| 19 | 16 | |
| 20 | 17 | test_setup |
| 21 | 18 | |
| 22 | 19 | set crosslinkSeq 0 |
| @@ -40,18 +37,14 @@ | ||
| 40 | 37 | |
| 41 | 38 | # Store the artifact whose cards, without the Z card, are $body. Return |
| 42 | 39 | # its hash, or an empty string if it was not stored. CODE and RESULT are |
| 43 | 40 | # those of test-content-put. |
| 44 | 41 | # |
| 45 | -proc crosslink_put {body {options --crosslink}} { | |
| 42 | +proc crosslink_put {body} { | |
| 46 | 43 | global RESULT CODE |
| 47 | 44 | 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 | |
| 53 | 46 | set code $CODE |
| 54 | 47 | set result $RESULT |
| 55 | 48 | set hash "" |
| 56 | 49 | if {[regexp {inserted as record (\d+)} $result all rid]} { |
| 57 | 50 | fossil sql "SELECT uuid FROM blob WHERE rid=$rid" |
| @@ -73,22 +66,14 @@ | ||
| 73 | 66 | proc crosslink_match {name actual pattern {constraints ""}} { |
| 74 | 67 | if {[string match $pattern $actual]} {set pattern $actual} |
| 75 | 68 | test_eq $name $actual $pattern $constraints |
| 76 | 69 | } |
| 77 | 70 | |
| 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 | 71 | # The timeline text of the artifact with the given hash. |
| 87 | 72 | # |
| 88 | 73 | proc crosslink_event {hash} { |
| 89 | - return [crosslink_sql "SELECT type || ' ' || comment FROM event, blob\ | |
| 74 | + return [fossil_sql "SELECT type || ' ' || comment FROM event, blob\ | |
| 90 | 75 | WHERE objid=rid AND uuid='$hash'"] |
| 91 | 76 | } |
| 92 | 77 | |
| 93 | 78 | set crosslinkNone [string repeat 0123456789 4] |
| 94 | 79 | set crosslinkNone2 [string repeat 9876543210 4] |
| @@ -101,11 +86,11 @@ | ||
| 101 | 86 | U alice |
| 102 | 87 | [crosslink_w {first text}]"] |
| 103 | 88 | test crosslink-wiki-new {$CODE == 0 && $crosslinkW1 ne ""} |
| 104 | 89 | test_eq crosslink-wiki-new-event [crosslink_event $crosslinkW1] \ |
| 105 | 90 | {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 | |
| 107 | 92 | WHERE tag.tagid=tagxref.tagid AND tagname='wiki-Crosslink Page'"] {10} |
| 108 | 93 | |
| 109 | 94 | set crosslinkW2 [crosslink_put "D 2026-01-01T11:00:00.000 |
| 110 | 95 | L Crosslink\\sPage |
| 111 | 96 | N text/x-markdown |
| @@ -112,11 +97,11 @@ | ||
| 112 | 97 | P $crosslinkW1 |
| 113 | 98 | U alice |
| 114 | 99 | [crosslink_w {second text}]"] |
| 115 | 100 | test_eq crosslink-wiki-edit-event [crosslink_event $crosslinkW2] \ |
| 116 | 101 | {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 | |
| 118 | 103 | WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkW2') |
| 119 | 104 | AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1 |
| 120 | 105 | |
| 121 | 106 | set crosslinkW3 [crosslink_put "D 2026-01-01T12:00:00.000 |
| 122 | 107 | L Crosslink\\sPage |
| @@ -147,29 +132,29 @@ | ||
| 147 | 132 | T +bgcolor * #abcdef |
| 148 | 133 | T +sym-noted * |
| 149 | 134 | U alice |
| 150 | 135 | [crosslink_w {note}]"] |
| 151 | 136 | 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, | |
| 153 | 138 | bgcolor FROM event, blob WHERE objid=rid AND uuid='$crosslinkE1'"] \ |
| 154 | 139 | {e|First note|#abcdef} |
| 155 | 140 | |
| 156 | 141 | set crosslinkE2 [crosslink_put "C Second\\snote |
| 157 | 142 | D 2026-01-02T11:00:00.000 |
| 158 | 143 | E 2026-01-02T09:00:00 $crosslinkEid |
| 159 | 144 | P $crosslinkE1 |
| 160 | 145 | U alice |
| 161 | 146 | [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 | |
| 163 | 148 | FROM event WHERE type='e'"] {Second note} |
| 164 | 149 | |
| 165 | -set crosslinkE0 [crosslink_put "C Earlier\\snote | |
| 150 | +crosslink_put "C Earlier\\snote | |
| 166 | 151 | D 2026-01-02T08:00:00.000 |
| 167 | 152 | E 2026-01-02T09:00:00 $crosslinkEid |
| 168 | 153 | 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 | |
| 171 | 156 | FROM event WHERE type='e'"] {Second note} |
| 172 | 157 | |
| 173 | 158 | ############################################################################### |
| 174 | 159 | # Tickets: a new ticket, a change of status with other fields, a change |
| 175 | 160 | # without the status, and one with a single field. |
| @@ -182,30 +167,32 @@ | ||
| 182 | 167 | U alice |
| 183 | 168 | "] |
| 184 | 169 | test crosslink-ticket-new {$CODE == 0 && $crosslinkT1 ne ""} |
| 185 | 170 | crosslink_match crosslink-ticket-new-event [crosslink_event $crosslinkT1] \ |
| 186 | 171 | {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 | |
| 188 | 173 | FROM ticket WHERE tkt_uuid='$crosslinkTkt'"] {Open|Crosslink ticket} |
| 189 | 174 | |
| 190 | 175 | set crosslinkT2 [crosslink_put "D 2026-01-03T11:00:00.000 |
| 191 | 176 | J priority High |
| 192 | 177 | J severity Minor |
| 193 | 178 | J status Fixed |
| 194 | 179 | K $crosslinkTkt |
| 195 | 180 | U alice |
| 196 | 181 | "] |
| 197 | -crosslink_match crosslink-ticket-status-plus-two [crosslink_event $crosslinkT2] \ | |
| 182 | +crosslink_match crosslink-ticket-status-plus-two \ | |
| 183 | + [crosslink_event $crosslinkT2] \ | |
| 198 | 184 | {t Fixed ticket * plus 2 other changes} |
| 199 | 185 | |
| 200 | 186 | set crosslinkT3 [crosslink_put "D 2026-01-03T12:00:00.000 |
| 201 | 187 | J priority Low |
| 202 | 188 | J status Closed |
| 203 | 189 | K $crosslinkTkt |
| 204 | 190 | U alice |
| 205 | 191 | "] |
| 206 | -crosslink_match crosslink-ticket-status-plus-one [crosslink_event $crosslinkT3] \ | |
| 192 | +crosslink_match crosslink-ticket-status-plus-one \ | |
| 193 | + [crosslink_event $crosslinkT3] \ | |
| 207 | 194 | {t Closed ticket * plus 1 other change} |
| 208 | 195 | |
| 209 | 196 | set crosslinkT4 [crosslink_put "D 2026-01-03T13:00:00.000 |
| 210 | 197 | J priority Medium |
| 211 | 198 | J severity Severe |
| @@ -230,11 +217,11 @@ | ||
| 230 | 217 | "] |
| 231 | 218 | crosslink_match crosslink-ticket-status-only [crosslink_event $crosslinkT6] \ |
| 232 | 219 | {t Verified ticket *} |
| 233 | 220 | test {crosslink-ticket-status-only-no-plus} \ |
| 234 | 221 | {![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 | |
| 236 | 223 | WHERE type='t'"] 6 |
| 237 | 224 | |
| 238 | 225 | ############################################################################### |
| 239 | 226 | # Forum posts: a thread, an edit of its first post, a reply, an edit of |
| 240 | 227 | # the reply, a deleted reply, and an older edit of the first post that |
| @@ -246,11 +233,11 @@ | ||
| 246 | 233 | U alice |
| 247 | 234 | [crosslink_w $crosslinkFtext]"] |
| 248 | 235 | test crosslink-forum-post {$CODE == 0 && $crosslinkF1 ne ""} |
| 249 | 236 | test_eq crosslink-forum-post-event [crosslink_event $crosslinkF1] \ |
| 250 | 237 | {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(*) | |
| 252 | 239 | FROM backlink WHERE srctype=4 |
| 253 | 240 | AND srcid=(SELECT rid FROM blob WHERE uuid='$crosslinkF1')"] 1 |
| 254 | 241 | |
| 255 | 242 | set crosslinkF2 [crosslink_put "D 2026-01-04T11:00:00.000 |
| 256 | 243 | G $crosslinkF1 |
| @@ -258,11 +245,11 @@ | ||
| 258 | 245 | N text/x-markdown |
| 259 | 246 | U bob |
| 260 | 247 | [crosslink_w {reply}]"] |
| 261 | 248 | test_eq crosslink-forum-reply-event [crosslink_event $crosslinkF2] \ |
| 262 | 249 | {f Reply: Crosslink thread} |
| 263 | -test_eq crosslink-forum-reply-row [crosslink_sql "SELECT | |
| 250 | +test_eq crosslink-forum-reply-row [fossil_sql "SELECT | |
| 264 | 251 | froot=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'), |
| 265 | 252 | firt=(SELECT rid FROM blob WHERE uuid='$crosslinkF1'), fprev IS NULL |
| 266 | 253 | FROM forumpost WHERE fpid=(SELECT rid FROM blob |
| 267 | 254 | WHERE uuid='$crosslinkF2')"] {1|1|1} |
| 268 | 255 | |
| @@ -323,10 +310,14 @@ | ||
| 323 | 310 | I $crosslinkNone |
| 324 | 311 | U bob |
| 325 | 312 | [crosslink_w {reply}]"] |
| 326 | 313 | test_eq crosslink-forum-reply-unknown-thread [crosslink_event $crosslinkF8] \ |
| 327 | 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 | +} | |
| 328 | 319 | |
| 329 | 320 | ############################################################################### |
| 330 | 321 | # Attachments, added to and deleted from each kind of target. |
| 331 | 322 | |
| 332 | 323 | set crosslinkSrc [string repeat ef 20] |
| @@ -355,35 +346,35 @@ | ||
| 355 | 346 | U alice |
| 356 | 347 | "] |
| 357 | 348 | set crosslinkEv [crosslink_event $crosslinkA] |
| 358 | 349 | crosslink_match crosslink-attach-$crosslinkKind-delete-event $crosslinkEv \ |
| 359 | 350 | "$crosslinkType Delete attachment $crosslinkDel" |
| 360 | - test_eq crosslink-attach-$crosslinkKind-latest [crosslink_sql "SELECT | |
| 351 | + test_eq crosslink-attach-$crosslinkKind-latest [fossil_sql "SELECT | |
| 361 | 352 | group_concat(isLatest,'') FROM (SELECT isLatest FROM attachment |
| 362 | 353 | WHERE target='[string map {\\s { }} $crosslinkTarget]' ORDER BY mtime)"] \ |
| 363 | 354 | {01} |
| 364 | 355 | } |
| 365 | -test_eq crosslink-attach-rows [crosslink_sql \ | |
| 356 | +test_eq crosslink-attach-rows [fossil_sql \ | |
| 366 | 357 | "SELECT count(*) FROM attachment"] 10 |
| 367 | 358 | |
| 368 | 359 | # A later change to a ticket or a tech note rewrites the timeline text of |
| 369 | 360 | # its attachments. |
| 370 | -set crosslinkT7 [crosslink_put "D 2026-01-05T12:00:00.000 | |
| 361 | +crosslink_put "D 2026-01-05T12:00:00.000 | |
| 371 | 362 | J status Open |
| 372 | 363 | K $crosslinkTkt |
| 373 | 364 | 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(*) | |
| 376 | 367 | FROM event WHERE type='t' AND (comment LIKE 'Add attachment % to ticket %' |
| 377 | 368 | OR comment LIKE 'Delete attachment % from ticket %')"] 2 |
| 378 | -set crosslinkE3 [crosslink_put "C Third\\snote | |
| 369 | +crosslink_put "C Third\\snote | |
| 379 | 370 | D 2026-01-05T12:00:00.000 |
| 380 | 371 | E 2026-01-02T09:00:00 $crosslinkEid |
| 381 | 372 | P $crosslinkE2 |
| 382 | 373 | 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 | |
| 385 | 376 | count(*) FROM event WHERE type='e' |
| 386 | 377 | AND (comment LIKE 'Add attachment % to tech note %' |
| 387 | 378 | OR comment LIKE 'Delete attachment % from tech note %')"] 2 |
| 388 | 379 | |
| 389 | 380 | ############################################################################### |
| @@ -391,33 +382,37 @@ | ||
| 391 | 382 | |
| 392 | 383 | write_file a.txt "a\n" |
| 393 | 384 | write_file b.txt "b\n" |
| 394 | 385 | fossil add a.txt b.txt |
| 395 | 386 | 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 | |
| 397 | 388 | WHERE rid=objid AND comment='crosslink-c1'"] |
| 398 | 389 | 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, | |
| 400 | 391 | filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid |
| 401 | 392 | 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, | |
| 403 | 394 | filename WHERE blob.rid=mlink.fid AND mlink.fnid=filename.fnid |
| 404 | 395 | AND name='b.txt'"] '] |
| 405 | 396 | test crosslink-setup-checkin \ |
| 406 | 397 | {$crosslinkC1 ne "" && $crosslinkFa ne "" && $crosslinkFb ne ""} |
| 407 | 398 | |
| 408 | 399 | # Every kind of tag that has its own wording in the timeline. |
| 409 | 400 | foreach {crosslinkName crosslinkCard crosslinkWant} [list \ |
| 410 | 401 | 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".*} \ | |
| 413 | 406 | bgcolor-off "-bgcolor *" {*Cancel background color.*} \ |
| 414 | 407 | comment "+comment * new\\stext" {*Edit check-in comment.*} \ |
| 415 | 408 | 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.*} \ | |
| 417 | 411 | 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".*} \ | |
| 419 | 414 | sym-prop "*sym-three *" {*Add propagating tag "three".*} \ |
| 420 | 415 | sym-cancel "-sym-one *" {*Cancel tag "one".*} \ |
| 421 | 416 | closed "+closed *" {*Mark "Closed".*} \ |
| 422 | 417 | closed-off "-closed *" {*Remove the "Closed" mark.*} \ |
| 423 | 418 | other-add "+thing *" {*Add "thing".*} \ |
| @@ -436,16 +431,15 @@ | ||
| 436 | 431 | "] |
| 437 | 432 | test crosslink-tag-$crosslinkName {$CODE == 0 && $crosslinkG ne ""} |
| 438 | 433 | crosslink_match crosslink-tag-$crosslinkName-event \ |
| 439 | 434 | [crosslink_event $crosslinkG] "g Edit *:$crosslinkWant" |
| 440 | 435 | } |
| 441 | -test_eq crosslink-tag-comment-applied [crosslink_sql "SELECT ecomment, euser | |
| 436 | +test_eq crosslink-tag-comment-applied [fossil_sql "SELECT ecomment, euser | |
| 442 | 437 | FROM event WHERE objid=(SELECT rid FROM blob WHERE uuid='$crosslinkC1')"] \ |
| 443 | 438 | {new text|carol} |
| 444 | 439 | |
| 445 | 440 | # 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 | 441 | set crosslinkG [crosslink_put "D 2026-01-06T11:00:00.000 |
| 448 | 442 | T *branch $crosslinkC1 moved |
| 449 | 443 | T *sym-moved $crosslinkC1 |
| 450 | 444 | T -sym-other $crosslinkC1 |
| 451 | 445 | U alice |
| @@ -490,16 +484,16 @@ | ||
| 490 | 484 | U alice |
| 491 | 485 | "] |
| 492 | 486 | test crosslink-checkin {$CODE == 0 && $crosslinkM1 ne ""} |
| 493 | 487 | test_eq crosslink-checkin-event [crosslink_event $crosslinkM1] \ |
| 494 | 488 | {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( | |
| 496 | 490 | name || ':' || mperm || ':' || (pfnid>0), ' ') FROM (SELECT name, mperm, |
| 497 | 491 | pfnid FROM mlink, filename WHERE mlink.fnid=filename.fnid |
| 498 | 492 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1') |
| 499 | 493 | 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(*) | |
| 501 | 495 | FROM cherrypick WHERE childid=(SELECT rid FROM blob |
| 502 | 496 | WHERE uuid='$crosslinkM1')"] 1 |
| 503 | 497 | |
| 504 | 498 | # A delta manifest, a second one on the same baseline, and an ordinary |
| 505 | 499 | # check-in after them. The second does not repeat the removal of a.txt, |
| @@ -511,16 +505,16 @@ | ||
| 511 | 505 | F d.txt $crosslinkFb |
| 512 | 506 | P $crosslinkM1 |
| 513 | 507 | U alice |
| 514 | 508 | "] |
| 515 | 509 | 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( | |
| 517 | 511 | name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename |
| 518 | 512 | WHERE mlink.fnid=filename.fnid |
| 519 | 513 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM2') |
| 520 | 514 | 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 | |
| 522 | 516 | WHERE name='seen-delta-manifest'"] 1 |
| 523 | 517 | |
| 524 | 518 | set crosslinkM3 [crosslink_put "B $crosslinkM1 |
| 525 | 519 | C crosslink-c4 |
| 526 | 520 | D 2026-01-07T12:00:00.000 |
| @@ -528,11 +522,11 @@ | ||
| 528 | 522 | F d.txt $crosslinkFa |
| 529 | 523 | F e.txt $crosslinkFa |
| 530 | 524 | P $crosslinkM2 |
| 531 | 525 | U alice |
| 532 | 526 | "] |
| 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( | |
| 534 | 528 | name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename |
| 535 | 529 | WHERE mlink.fnid=filename.fnid |
| 536 | 530 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM3') |
| 537 | 531 | ORDER BY name)"] {a.txt:1 c.txt:0 d.txt:1 e.txt:1} |
| 538 | 532 | |
| @@ -541,11 +535,11 @@ | ||
| 541 | 535 | F a.txt $crosslinkFa |
| 542 | 536 | F e.txt $crosslinkFb |
| 543 | 537 | P $crosslinkM3 |
| 544 | 538 | U alice |
| 545 | 539 | "] |
| 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( | |
| 547 | 541 | name || ':' || (fid>0), ' ') FROM (SELECT name, fid FROM mlink, filename |
| 548 | 542 | WHERE mlink.fnid=filename.fnid |
| 549 | 543 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkM4') |
| 550 | 544 | ORDER BY name)"] {a.txt:1 d.txt:0 e.txt:1 l.txt:0} |
| 551 | 545 | |
| @@ -584,11 +578,11 @@ | ||
| 584 | 578 | F a.txt $crosslinkFa |
| 585 | 579 | P $crosslinkM1 |
| 586 | 580 | U alice |
| 587 | 581 | "] |
| 588 | 582 | 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(*) | |
| 590 | 584 | FROM event WHERE comment='crosslink-no-baseline'"] 0 |
| 591 | 585 | |
| 592 | 586 | # A check-in whose parent is that one is still shown; its files cannot be |
| 593 | 587 | # compared with the parent's. |
| 594 | 588 | set crosslinkM6 [crosslink_put "C crosslink-child-of-no-baseline |
| @@ -599,33 +593,33 @@ | ||
| 599 | 593 | "] |
| 600 | 594 | test_eq crosslink-child-of-missing-baseline [crosslink_event $crosslinkM6] \ |
| 601 | 595 | {ci crosslink-child-of-no-baseline} |
| 602 | 596 | |
| 603 | 597 | 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"] | |
| 605 | 599 | fossil test-content-put --crosslink not-an-artifact.txt |
| 606 | 600 | test crosslink-not-an-artifact {$CODE == 0} |
| 607 | 601 | test_eq crosslink-not-an-artifact-no-event \ |
| 608 | - [crosslink_sql "SELECT count(*) FROM event"] $crosslinkEvents | |
| 602 | + [fossil_sql "SELECT count(*) FROM event"] $crosslinkEvents | |
| 609 | 603 | |
| 610 | 604 | ############################################################################### |
| 611 | 605 | # The "parent" tag gives a check-in other parents; a bad value is ignored. |
| 612 | 606 | |
| 613 | 607 | fossil reparent $crosslinkM4 $crosslinkC1 $crosslinkM2 |
| 614 | 608 | 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 | |
| 616 | 610 | 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, | |
| 618 | 612 | blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob |
| 619 | 613 | WHERE uuid='$crosslinkM4')"] $crosslinkC1 |
| 620 | 614 | |
| 621 | -set crosslinkG [crosslink_put "D 2026-01-08T10:00:00.000 | |
| 615 | +crosslink_put "D 2026-01-08T10:00:00.000 | |
| 622 | 616 | T +parent $crosslinkM3 not-a-hash |
| 623 | 617 | U alice |
| 624 | -"] | |
| 618 | +" | |
| 625 | 619 | 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 | |
| 627 | 621 | FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob |
| 628 | 622 | WHERE uuid='$crosslinkM3')"] $crosslinkM2 |
| 629 | 623 | |
| 630 | 624 | # A value of good hashes followed by a short word is ignored as a whole, |
| 631 | 625 | # both when the tag arrives and when a rebuild reads it again. |
| @@ -638,54 +632,57 @@ | ||
| 638 | 632 | set crosslinkG [crosslink_put "D 2026-01-08T10:0[incr crosslinkI]:00.000 |
| 639 | 633 | T +parent $crosslinkM3 $crosslinkValue |
| 640 | 634 | U alice |
| 641 | 635 | "] |
| 642 | 636 | 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 | |
| 644 | 638 | uuid FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid |
| 645 | 639 | FROM blob WHERE uuid='$crosslinkM3')"] $crosslinkM2 |
| 646 | 640 | } |
| 647 | 641 | fossil rebuild |
| 648 | 642 | 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 | |
| 650 | 644 | FROM plink, blob WHERE pid=rid AND isprim AND cid=(SELECT rid FROM blob |
| 651 | 645 | WHERE uuid='$crosslinkM3')"] $crosslinkM2 |
| 652 | 646 | |
| 653 | 647 | ############################################################################### |
| 654 | 648 | # A cluster removes its members from the list of unclustered artifacts. |
| 655 | 649 | |
| 656 | -set crosslinkBefore [crosslink_sql "SELECT count(*) FROM unclustered"] | |
| 650 | +set crosslinkBefore [fossil_sql "SELECT count(*) FROM unclustered"] | |
| 657 | 651 | set crosslinkCl "" |
| 658 | 652 | foreach crosslinkHash [lsort [list $crosslinkC1 $crosslinkM1 $crosslinkNone2]] { |
| 659 | 653 | append crosslinkCl "M $crosslinkHash\n" |
| 660 | 654 | } |
| 661 | 655 | set crosslinkCl [crosslink_put $crosslinkCl] |
| 662 | 656 | 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 | |
| 664 | 658 | WHERE tagid=(SELECT tagid FROM tag WHERE tagname='cluster') |
| 665 | 659 | AND rid=(SELECT rid FROM blob WHERE uuid='$crosslinkCl')"] 1 |
| 666 | 660 | test crosslink-cluster-unclustered \ |
| 667 | - {[crosslink_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1} | |
| 661 | + {[fossil_sql "SELECT count(*) FROM unclustered"] == $crosslinkBefore - 1} | |
| 668 | 662 | |
| 669 | 663 | ############################################################################### |
| 670 | 664 | # The JSON form of each kind of artifact. |
| 671 | 665 | |
| 672 | 666 | 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":*} \ | |
| 675 | 671 | ticket $crosslinkT5 {*"type":"ticket"*"J":*"append":true*"K":*} \ |
| 676 | 672 | ticket2 $crosslinkT2 {*"type":"ticket"*"J":*"append":false*} \ |
| 677 | 673 | forum $crosslinkF3 {*"type":"forumpost"*"G":*"I":*"P":*"W":*} \ |
| 678 | 674 | forum2 $crosslinkF5 {*"type":"forumpost"*"H":"New title"*} \ |
| 679 | 675 | attachment "" {*"type":"attachment"*"A":*} \ |
| 680 | 676 | 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"*} \ | |
| 682 | 679 | delta $crosslinkM2 {*"type":"checkin"*"B":*"F":*} \ |
| 683 | 680 | cluster $crosslinkCl {*"type":"cluster"*"M":*} \ |
| 684 | 681 | ] { |
| 685 | 682 | 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, | |
| 687 | 684 | attachment WHERE rid=attachid ORDER BY rid LIMIT 1"] '] |
| 688 | 685 | } |
| 689 | 686 | fossil test-artifact-to-json $crosslinkHash |
| 690 | 687 | test crosslink-json-$crosslinkKind {$CODE == 0} |
| 691 | 688 | crosslink_match crosslink-json-$crosslinkKind-text $RESULT $crosslinkWant |
| @@ -703,23 +700,23 @@ | ||
| 703 | 700 | fossil test-artifact-to-json $crosslinkFa no-such-name -expectError |
| 704 | 701 | test crosslink-json-not-artifact {$CODE != 0} |
| 705 | 702 | |
| 706 | 703 | # The same through SQL: by hash, by record number, and with arguments |
| 707 | 704 | # that name nothing. |
| 708 | -crosslink_match crosslink-json-sql-name [crosslink_sql \ | |
| 705 | +crosslink_match crosslink-json-sql-name [fossil_sql \ | |
| 709 | 706 | "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( | |
| 711 | 708 | (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 \ | |
| 713 | 710 | "SELECT artifact_to_json('$crosslinkFa') IS NULL"] 1 |
| 714 | 711 | fossil sql "SELECT artifact_to_json(NULL)" -expectError |
| 715 | 712 | test crosslink-json-sql-null {$CODE != 0} |
| 716 | 713 | crosslink_match crosslink-json-sql-null-message $RESULT \ |
| 717 | 714 | {*Expecting one argument*} |
| 718 | 715 | fossil sql "SELECT artifact_to_json(1.5)" -expectError |
| 719 | 716 | 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 \ | |
| 721 | 718 | "SELECT artifact_to_json(0) IS NULL"] 1 |
| 722 | 719 | fossil sql "SELECT artifact_to_json()" -expectError |
| 723 | 720 | test crosslink-json-sql-no-argument {$CODE != 0} |
| 724 | 721 | |
| 725 | 722 | ############################################################################### |
| @@ -734,20 +731,30 @@ | ||
| 734 | 731 | first-line-not-a-card "1 x\nD 2026-02-01T10:00:00.000\n" \ |
| 735 | 732 | {*line 1 not recognized*} \ |
| 736 | 733 | control-tags-itself "D 2026-02-01T10:00:00.000\nT +sym-x *\nU alice\n" \ |
| 737 | 734 | {*self-referential T-card in control artifact*} \ |
| 738 | 735 | 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"] ""] \ | |
| 740 | 740 | {*non-self-referential T-card in technote*} \ |
| 741 | 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" \ | |
| 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"] ""] \ | |
| 743 | 746 | {*T-card with '\*' or '-' in technote*} \ |
| 744 | 747 | 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"] ""] \ | |
| 746 | 751 | {*cannot have I-card and H-card in a forum post*} \ |
| 747 | 752 | 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"] ""] \ | |
| 749 | 756 | {*too many arguments to P-card*} \ |
| 750 | 757 | ] { |
| 751 | 758 | fossil test-parse-manifest [crosslink_file $crosslinkBody] |
| 752 | 759 | test crosslink-refuse-$crosslinkName {$CODE == 0} |
| 753 | 760 | crosslink_match crosslink-refuse-$crosslinkName-reason $RESULT \ |
| @@ -775,14 +782,19 @@ | ||
| 775 | 782 | {*manifest_parse() worked*} |
| 776 | 783 | |
| 777 | 784 | # A tech note may have its N card after its P card, as old versions of |
| 778 | 785 | # Fossil wrote it. A file with a reserved name in a check-in is left out. |
| 779 | 786 | 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"] ""]] | |
| 781 | 791 | crosslink_match crosslink-technote-n-after-p $RESULT {*manifest_parse() worked*} |
| 782 | 792 | 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 | |
| 784 | 796 | crosslink_match crosslink-reserved-name-ignored $RESULT \ |
| 785 | 797 | {*manifest_parse() worked*} |
| 786 | 798 | |
| 787 | 799 | # Content that is not an artifact but begins like one. The quick check |
| 788 | 800 | # and the parser must agree about each. |
| @@ -792,11 +804,11 @@ | ||
| 792 | 804 | no-newline "D 2026-02-01T10:00:00.000 and no end of line" \ |
| 793 | 805 | one-card "D x\n" \ |
| 794 | 806 | short "D\n" \ |
| 795 | 807 | second-lower "D 2026-02-01T10:00:00.000\nlower case\n" \ |
| 796 | 808 | 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" \ | |
| 798 | 810 | late-letter "N text/plain\nU alice and more\n" \ |
| 799 | 811 | ] { |
| 800 | 812 | write_file wf-$crosslinkName.txt $crosslinkText |
| 801 | 813 | fossil test-content-put wf-$crosslinkName.txt |
| 802 | 814 | test crosslink-not-wellformed-$crosslinkName {$CODE == 0} |
| @@ -810,23 +822,23 @@ | ||
| 810 | 822 | crosslink_match crosslink-wiki-is-not-a-checkin-message $RESULT \ |
| 811 | 823 | {*not a valid check-in*} |
| 812 | 824 | |
| 813 | 825 | # Wiki text and a tech note that begin with blank space, and crosslinking |
| 814 | 826 | # 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 | |
| 816 | 828 | L Indented |
| 817 | 829 | 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 | |
| 820 | 832 | FROM tagxref, tag WHERE tag.tagid=tagxref.tagid |
| 821 | 833 | AND tagname='wiki-Indented'"] 8 |
| 822 | -set crosslinkE4 [crosslink_put "C Indented\\snote | |
| 834 | +crosslink_put "C Indented\\snote | |
| 823 | 835 | D 2026-02-02T11:00:00.000 |
| 824 | 836 | E 2026-02-02T09:00:00 [string repeat 12 20] |
| 825 | 837 | 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 | |
| 828 | 840 | FROM tagxref, tag WHERE tag.tagid=tagxref.tagid |
| 829 | 841 | AND tagname='event-[string repeat 12 20]'"] 4 |
| 830 | 842 | fossil_raw test-crosslink $crosslinkW1 --sqltrace |
| 831 | 843 | test crosslink-sqltrace {$CODE == 0} |
| 832 | 844 | crosslink_match crosslink-sqltrace-text $RESULT {*-- manifest_crosslink(*} |
| @@ -853,19 +865,20 @@ | ||
| 853 | 865 | crosslink_match crosslink-parse-all-text $RESULT {*tests with 0 errors*} |
| 854 | 866 | fossil test-parse-all-blobs --limit 3 |
| 855 | 867 | crosslink_match crosslink-parse-all-limit $RESULT {*3 tests with 0 errors*} |
| 856 | 868 | fossil test-parse-all-blobs --wellformed |
| 857 | 869 | 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*} | |
| 859 | 872 | |
| 860 | 873 | # 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"] | |
| 862 | 875 | fossil test-crosslink $crosslinkM1 |
| 863 | 876 | test crosslink-again {$CODE == 0} |
| 864 | 877 | fossil test-crosslink $crosslinkW1 |
| 865 | 878 | 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"] \ | |
| 867 | 880 | $crosslinkEvents |
| 868 | 881 | fossil test-crosslink -expectError |
| 869 | 882 | test crosslink-usage {$CODE != 0} |
| 870 | 883 | |
| 871 | 884 | ############################################################################### |
| @@ -875,18 +888,18 @@ | ||
| 875 | 888 | (SELECT count(*) FROM attachment) || ' ' || |
| 876 | 889 | (SELECT count(*) FROM forumpost) || ' ' || |
| 877 | 890 | (SELECT count(*) FROM plink) || ' ' || |
| 878 | 891 | (SELECT count(*) FROM mlink) || ' ' || |
| 879 | 892 | (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 | |
| 882 | 895 | (SELECT type || ' ' || comment AS x FROM event ORDER BY type, objid)"] |
| 883 | 896 | fossil rebuild |
| 884 | 897 | 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] \ | |
| 886 | 899 | $crosslinkBefore |
| 887 | -test_eq crosslink-rebuild-same-events [crosslink_sql "SELECT | |
| 900 | +test_eq crosslink-rebuild-same-events [fossil_sql "SELECT | |
| 888 | 901 | group_concat(x, char(10)) FROM (SELECT type || ' ' || comment AS x |
| 889 | 902 | FROM event ORDER BY type, objid)"] $crosslinkText |
| 890 | 903 | fossil test-integrity |
| 891 | 904 | test crosslink-integrity {$CODE == 0} |
| 892 | 905 | |
| @@ -903,11 +916,11 @@ | ||
| 903 | 916 | none "D 2026-03-01T10:03:00.000\nT +sym-kind-test $crosslinkC1\nU alice\n" \ |
| 904 | 917 | control \ |
| 905 | 918 | ] { |
| 906 | 919 | set crosslinkHash [crosslink_put $crosslinkBody] |
| 907 | 920 | 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 | |
| 909 | 922 | count(*) FROM event, blob WHERE objid=rid AND uuid='$crosslinkHash' |
| 910 | 923 | AND type='ci'"] [expr {$crosslinkKind eq "ci" ? 1 : 0}] |
| 911 | 924 | fossil test-parse-manifest [crosslink_file $crosslinkBody] |
| 912 | 925 | crosslink_match crosslink-mcdc-kind-$crosslinkName-parse $RESULT \ |
| 913 | 926 | {*manifest_parse() worked*} |
| @@ -920,25 +933,29 @@ | ||
| 920 | 933 | # first parent arrives. A merge parent that arrives while the first |
| 921 | 934 | # parent is present adds them at once. |
| 922 | 935 | |
| 923 | 936 | # The hash a check-in with the cards BODY will have, without storing it. |
| 924 | 937 | 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]] | |
| 928 | 939 | } |
| 929 | 940 | |
| 930 | 941 | # The number of file links that join the check-in CHILD to its parent |
| 931 | 942 | # PARENT. |
| 932 | 943 | proc crosslink_links {child parent} { |
| 933 | - return [crosslink_sql "SELECT count(*) FROM mlink WHERE | |
| 944 | + return [fossil_sql "SELECT count(*) FROM mlink WHERE | |
| 934 | 945 | mid=(SELECT rid FROM blob WHERE uuid='$child') |
| 935 | 946 | AND pmid=(SELECT rid FROM blob WHERE uuid='$parent')"] |
| 936 | 947 | } |
| 937 | 948 | |
| 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"] ""]] | |
| 940 | 957 | set crosslinkKid [crosslink_put "C merge\\skid |
| 941 | 958 | D 2026-03-02T11:00:00.000 |
| 942 | 959 | F a.txt $crosslinkNone |
| 943 | 960 | P $crosslinkPA $crosslinkPB |
| 944 | 961 | U alice |
| @@ -967,12 +984,18 @@ | ||
| 967 | 984 | test_eq crosslink-mcdc-merge-parent-second-links \ |
| 968 | 985 | [list [crosslink_links $crosslinkKid $crosslinkPA] \ |
| 969 | 986 | [crosslink_links $crosslinkKid $crosslinkPB]] {1 1} |
| 970 | 987 | |
| 971 | 988 | # 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"] ""]] | |
| 974 | 997 | crosslink_put "C other\\sfirst |
| 975 | 998 | D 2026-03-02T12:00:00.000 |
| 976 | 999 | F a.txt $crosslinkFa |
| 977 | 1000 | U alice |
| 978 | 1001 | " |
| @@ -998,15 +1021,17 @@ | ||
| 998 | 1021 | # An empty title on the first post of a forum thread is shown as deleted, |
| 999 | 1022 | # and an empty title or page text is null in the JSON form. Each row |
| 1000 | 1023 | # differs from the one before in a single card. |
| 1001 | 1024 | |
| 1002 | 1025 | 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}]" \ | |
| 1004 | 1028 | {f Post: Some title} {*"H":"Some title"*"W":"x"*} \ |
| 1005 | 1029 | empty-title "D 2026-03-03T10:01:00.000\nH \nU alice\n[crosslink_w {x}]" \ |
| 1006 | 1030 | {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 {}]" \ | |
| 1008 | 1033 | {f Post: Some title} {*"H":"Some title"*"W":null*} \ |
| 1009 | 1034 | ] { |
| 1010 | 1035 | set crosslinkHash [crosslink_put $crosslinkBody] |
| 1011 | 1036 | test crosslink-mcdc-forum-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""} |
| 1012 | 1037 | test_eq crosslink-mcdc-forum-$crosslinkName-event \ |
| @@ -1016,11 +1041,12 @@ | ||
| 1016 | 1041 | $crosslinkJson |
| 1017 | 1042 | } |
| 1018 | 1043 | |
| 1019 | 1044 | # A wiki page with no text has a null W card in JSON. |
| 1020 | 1045 | 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*} | |
| 1022 | 1048 | |
| 1023 | 1049 | ############################################################################### |
| 1024 | 1050 | # A tag card whose value is empty reads like one with no value. |
| 1025 | 1051 | |
| 1026 | 1052 | set crosslinkMin 10 |
| @@ -1055,25 +1081,21 @@ | ||
| 1055 | 1081 | "] |
| 1056 | 1082 | test crosslink-mcdc-cherry-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""} |
| 1057 | 1083 | test_eq crosslink-mcdc-cherry-$crosslinkName-event \ |
| 1058 | 1084 | [crosslink_event $crosslinkHash] "ci cherry-$crosslinkName" |
| 1059 | 1085 | } |
| 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(*) | |
| 1061 | 1087 | FROM blob WHERE uuid='$crosslinkUnseen'"] 0 |
| 1062 | 1088 | |
| 1063 | 1089 | ############################################################################### |
| 1064 | 1090 | # The information page of a wiki page, asked for by the name of something |
| 1065 | 1091 | # that is not a wiki page: a check-in, a ticket, a forum post, a file, and |
| 1066 | 1092 | # a hash that names nothing. |
| 1067 | 1093 | |
| 1068 | 1094 | 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] | |
| 1075 | 1097 | } |
| 1076 | 1098 | |
| 1077 | 1099 | foreach {crosslinkName crosslinkHash crosslinkIs} [list \ |
| 1078 | 1100 | wiki $crosslinkW1 1 \ |
| 1079 | 1101 | checkin $crosslinkC1 0 \ |
| @@ -1102,11 +1124,11 @@ | ||
| 1102 | 1124 | F l.txt $crosslinkFa l |
| 1103 | 1125 | P $crosslinkM2 |
| 1104 | 1126 | U alice |
| 1105 | 1127 | "] |
| 1106 | 1128 | 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 | |
| 1108 | 1130 | group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name, |
| 1109 | 1131 | pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid |
| 1110 | 1132 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkBack') |
| 1111 | 1133 | ORDER BY name)"] {a.txt:0:1 c.txt:1:0 d.txt:1:0} |
| 1112 | 1134 | |
| @@ -1129,11 +1151,11 @@ | ||
| 1129 | 1151 | D 2026-03-07T10:01:00.000 |
| 1130 | 1152 | F a.txt $crosslinkFa x |
| 1131 | 1153 | P $crosslinkGhost |
| 1132 | 1154 | U alice |
| 1133 | 1155 | "] |
| 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 | |
| 1135 | 1157 | group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name, |
| 1136 | 1158 | pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid |
| 1137 | 1159 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash') |
| 1138 | 1160 | ORDER BY name)"] {c.txt:1:0 l.txt:1:0} |
| 1139 | 1161 | |
| @@ -1155,11 +1177,11 @@ | ||
| 1155 | 1177 | set crosslinkG [crosslink_put "D 2026-03-07T11:01:00.000 |
| 1156 | 1178 | T +parent $crosslinkKid3 $crosslinkM1 |
| 1157 | 1179 | U alice |
| 1158 | 1180 | "] |
| 1159 | 1181 | 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(*) | |
| 1161 | 1183 | FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkKid3') |
| 1162 | 1184 | AND pid=(SELECT rid FROM blob WHERE uuid='$crosslinkM1')"] 1 |
| 1163 | 1185 | test_eq crosslink-mcdc-reparent-no-baseline-no-links \ |
| 1164 | 1186 | [crosslink_links $crosslinkKid3 $crosslinkM1] 0 |
| 1165 | 1187 | |
| @@ -1181,25 +1203,26 @@ | ||
| 1181 | 1203 | P $crosslinkC1 |
| 1182 | 1204 | U alice |
| 1183 | 1205 | "] |
| 1184 | 1206 | fossil test-content-put --crosslink $crosslinkOnWiki $crosslinkBasedOnWiki |
| 1185 | 1207 | 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 | |
| 1187 | 1209 | group_concat(comment, ' ') FROM event WHERE type='ci' |
| 1188 | 1210 | AND comment IN ('child-of-wiki-page','based-on-wiki-page')"] \ |
| 1189 | 1211 | {child-of-wiki-page} |
| 1190 | 1212 | 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(*) | |
| 1192 | 1214 | FROM orphan WHERE rid=(SELECT rid FROM blob |
| 1193 | 1215 | WHERE uuid='[lindex $RESULT 0]') |
| 1194 | 1216 | AND baseline=(SELECT rid FROM blob WHERE uuid='$crosslinkW1')"] 1 |
| 1195 | 1217 | |
| 1196 | 1218 | ############################################################################### |
| 1197 | 1219 | # Scripts that run when artifacts are stored by a command. |
| 1198 | 1220 | # |
| 1199 | 1221 | # 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" | |
| 1201 | 1224 | # fail, after the ticket has been entered. A tag put on a wiki page by |
| 1202 | 1225 | # "tag add" is recorded like a tag on a check-in. |
| 1203 | 1226 | |
| 1204 | 1227 | proc crosslink_script {name script} { |
| 1205 | 1228 | if {$script eq ""} { |
| @@ -1214,32 +1237,32 @@ | ||
| 1214 | 1237 | FROM plink, blob WHERE cid=blob.rid AND blob.uuid=$uuid} {puts "PARENT $j"}} |
| 1215 | 1238 | fossil branch new scripted $crosslinkM1 |
| 1216 | 1239 | test crosslink-mcdc-script-branch {$CODE == 0} |
| 1217 | 1240 | crosslink_match crosslink-mcdc-script-branch-parent-json $RESULT \ |
| 1218 | 1241 | {*PARENT *"type":"checkin"*"C":"crosslink-c2"*} |
| 1219 | -test_eq crosslink-mcdc-script-branch-made [crosslink_sql "SELECT count(*) | |
| 1242 | +test_eq crosslink-mcdc-script-branch-made [fossil_sql "SELECT count(*) | |
| 1220 | 1243 | FROM tagxref, tag WHERE tag.tagid=tagxref.tagid |
| 1221 | 1244 | AND tagname='sym-scripted'"] 1 |
| 1222 | 1245 | crosslink_script xfer-commit-script "" |
| 1223 | 1246 | |
| 1224 | -set crosslinkTickets [crosslink_sql "SELECT count(*) FROM ticket"] | |
| 1247 | +set crosslinkTickets [fossil_sql "SELECT count(*) FROM ticket"] | |
| 1225 | 1248 | crosslink_script xfer-common-script {error common-script-says-no} |
| 1226 | 1249 | fossil ticket add title Scripted status Open -expectError |
| 1227 | 1250 | test crosslink-mcdc-script-ticket-fails {$CODE != 0} |
| 1228 | 1251 | crosslink_match crosslink-mcdc-script-ticket-message $RESULT \ |
| 1229 | 1252 | {*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(*) | |
| 1231 | 1254 | FROM ticket WHERE title='Scripted'"] 1 |
| 1232 | 1255 | crosslink_script xfer-common-script "" |
| 1233 | 1256 | fossil ticket add title Unscripted status Open |
| 1234 | 1257 | 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(*) | |
| 1236 | 1259 | FROM ticket"] [expr {$crosslinkTickets + 2}] |
| 1237 | 1260 | |
| 1238 | 1261 | fossil tag add on-a-wiki-page $crosslinkW1 |
| 1239 | 1262 | 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 | |
| 1241 | 1264 | FROM event WHERE type='g' AND comment LIKE '%on-a-wiki-page%'"] \ |
| 1242 | 1265 | "Edit \\\[[string range $crosslinkW1 0 15]|*\\\]: Add *\"on-a-wiki-page\"." |
| 1243 | 1266 | |
| 1244 | 1267 | ############################################################################### |
| 1245 | 1268 | # A repository made before cherrypicks were recorded has no table for |
| @@ -1255,15 +1278,15 @@ | ||
| 1255 | 1278 | U alice |
| 1256 | 1279 | "] |
| 1257 | 1280 | test crosslink-mcdc-cherry-no-table {$CODE == 0 && $crosslinkHash ne ""} |
| 1258 | 1281 | test_eq crosslink-mcdc-cherry-no-table-event [crosslink_event $crosslinkHash] \ |
| 1259 | 1282 | {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(*) | |
| 1261 | 1284 | FROM sqlite_schema WHERE name='cherrypick'"] 0 |
| 1262 | 1285 | fossil rebuild |
| 1263 | 1286 | 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(*) | |
| 1265 | 1288 | FROM cherrypick WHERE childid=(SELECT rid FROM blob |
| 1266 | 1289 | WHERE uuid='$crosslinkHash')"] 1 |
| 1267 | 1290 | |
| 1268 | 1291 | ############################################################################### |
| 1269 | 1292 | # The quick check for an artifact and the parser must agree. |
| @@ -1331,11 +1354,11 @@ | ||
| 1331 | 1354 | {$crosslinkR1 ne "" && $crosslinkR2 ne "" && $crosslinkR3 ne ""} |
| 1332 | 1355 | |
| 1333 | 1356 | # The primary parent of the check-in with the given hash. |
| 1334 | 1357 | # |
| 1335 | 1358 | 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 | |
| 1337 | 1360 | AND isprim AND cid=(SELECT rid FROM blob WHERE uuid='$hash')"] |
| 1338 | 1361 | } |
| 1339 | 1362 | |
| 1340 | 1363 | crosslink_put "D 2026-04-01T11:00:00.000 |
| 1341 | 1364 | T +parent $crosslinkR3 $crosslinkR1\\s |
| @@ -1360,11 +1383,11 @@ | ||
| 1360 | 1383 | crosslink_put "D 2026-04-01T11:03:00.000 |
| 1361 | 1384 | T +parent $crosslinkHash $crosslinkR1 |
| 1362 | 1385 | U alice |
| 1363 | 1386 | " |
| 1364 | 1387 | 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(*) | |
| 1366 | 1389 | FROM plink WHERE cid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash')"] 0 |
| 1367 | 1390 | |
| 1368 | 1391 | ############################################################################### |
| 1369 | 1392 | # A check-in with two parents lists both in its JSON form. |
| 1370 | 1393 | |
| @@ -1371,11 +1394,11 @@ | ||
| 1371 | 1394 | set crosslinkHash [crosslink_put "C two-parents-json |
| 1372 | 1395 | D 2026-04-01T12:00:00.000 |
| 1373 | 1396 | P $crosslinkR3 $crosslinkR1 |
| 1374 | 1397 | U alice |
| 1375 | 1398 | "] |
| 1376 | -test_eq crosslink-json-second-parent [crosslink_sql "SELECT | |
| 1399 | +test_eq crosslink-json-second-parent [fossil_sql "SELECT | |
| 1377 | 1400 | json_extract(artifact_to_json('$crosslinkHash'), '\$.P\[1\]')"] \ |
| 1378 | 1401 | $crosslinkR1 |
| 1379 | 1402 | |
| 1380 | 1403 | ############################################################################### |
| 1381 | 1404 | # A wiki page with two parents: both are linked, the first as the |
| @@ -1393,11 +1416,11 @@ | ||
| 1393 | 1416 | L Two\\sParents |
| 1394 | 1417 | P $crosslinkWa $crosslinkWb |
| 1395 | 1418 | U alice |
| 1396 | 1419 | [crosslink_w {both}]"] |
| 1397 | 1420 | 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 | |
| 1399 | 1422 | group_concat(uuid || ':' || isprim, ' ') FROM (SELECT uuid, isprim |
| 1400 | 1423 | FROM plink, blob WHERE pid=rid AND cid=(SELECT rid FROM blob |
| 1401 | 1424 | WHERE uuid='$crosslinkHash') ORDER BY isprim DESC)"] \ |
| 1402 | 1425 | "$crosslinkWa:1 $crosslinkWb:0" |
| 1403 | 1426 | |
| @@ -1410,13 +1433,13 @@ | ||
| 1410 | 1433 | U alice |
| 1411 | 1434 | [crosslink_w {text}]Z [string repeat 0 32]\n" |
| 1412 | 1435 | fossil test-content-put --crosslink bad-z.txt |
| 1413 | 1436 | test crosslink-bad-z-stored \ |
| 1414 | 1437 | {$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 | |
| 1416 | 1439 | 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 | |
| 1418 | 1441 | WHERE tagname='wiki-Bad Sum'"] 0 |
| 1419 | 1442 | |
| 1420 | 1443 | ############################################################################### |
| 1421 | 1444 | # A version of a tech note that arrives after a later version of the same |
| 1422 | 1445 | # note, and names the first version as its parent, does not replace the |
| @@ -1439,11 +1462,11 @@ | ||
| 1439 | 1462 | E 2026-04-03T09:00:00 $crosslinkEid2 |
| 1440 | 1463 | P $crosslinkHash |
| 1441 | 1464 | U alice |
| 1442 | 1465 | [crosslink_w {middle}]" |
| 1443 | 1466 | 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 | |
| 1445 | 1468 | comment FROM event WHERE type='e' AND comment LIKE 'note-%'"] {note-last} |
| 1446 | 1469 | |
| 1447 | 1470 | ############################################################################### |
| 1448 | 1471 | # Two delta manifests on one baseline, the second a child of the first. |
| 1449 | 1472 | # The first changes a.txt, removes b.txt and adds x.txt. The second |
| @@ -1473,11 +1496,11 @@ | ||
| 1473 | 1496 | U alice |
| 1474 | 1497 | "] |
| 1475 | 1498 | test crosslink-two-deltas {$CODE == 0 && $crosslinkHash ne ""} |
| 1476 | 1499 | test_eq crosslink-two-deltas-event [crosslink_event $crosslinkHash] \ |
| 1477 | 1500 | {ci two-deltas-child} |
| 1478 | -test_eq crosslink-two-deltas-mlink [crosslink_sql "SELECT | |
| 1501 | +test_eq crosslink-two-deltas-mlink [fossil_sql "SELECT | |
| 1479 | 1502 | group_concat(name || ':' || (pid>0) || ':' || (fid>0), ' ') FROM (SELECT name, |
| 1480 | 1503 | pid, fid FROM mlink, filename WHERE mlink.fnid=filename.fnid |
| 1481 | 1504 | AND mid=(SELECT rid FROM blob WHERE uuid='$crosslinkHash') |
| 1482 | 1505 | ORDER BY name)"] {a.txt:1:1} |
| 1483 | 1506 | |
| @@ -1497,16 +1520,16 @@ | ||
| 1497 | 1520 | set crosslinkPrev [lindex $RESULT 0] |
| 1498 | 1521 | lappend crosslinkFiles $crosslinkFn |
| 1499 | 1522 | } |
| 1500 | 1523 | fossil test-content-put --crosslink {*}$crosslinkFiles |
| 1501 | 1524 | 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(*) | |
| 1503 | 1526 | 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(*) | |
| 1505 | 1528 | FROM plink, event AS p, event AS c WHERE p.objid=pid AND c.objid=cid |
| 1506 | 1529 | 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 | |
| 1508 | 1531 | strftime('%Y-%m-%d %H:%M:%f', mtime) FROM event |
| 1509 | 1532 | WHERE comment='same-second-32'"] {2026-04-05 10:00:00.000} |
| 1510 | 1533 | |
| 1511 | 1534 | ############################################################################### |
| 1512 | 1535 | # A delta manifest whose baseline is missing, received by a pull: it is |
| @@ -1543,16 +1566,16 @@ | ||
| 1543 | 1566 | fossil sql "INSERT INTO shun(uuid,mtime) VALUES('$crosslinkShun',0)" |
| 1544 | 1567 | set crosslinkHash [crosslink_put "C shun-clustered |
| 1545 | 1568 | D 2026-04-07T10:00:00.000 |
| 1546 | 1569 | U alice |
| 1547 | 1570 | "] |
| 1548 | -test_eq crosslink-shun-unclustered-before [crosslink_sql "SELECT count(*) | |
| 1571 | +test_eq crosslink-shun-unclustered-before [fossil_sql "SELECT count(*) | |
| 1549 | 1572 | FROM unclustered, blob WHERE unclustered.rid=blob.rid |
| 1550 | 1573 | AND uuid='$crosslinkHash'"] 1 |
| 1551 | 1574 | crosslink_put [join [lsort [list "M $crosslinkShun" "M $crosslinkHash"]] \n]\n |
| 1552 | 1575 | 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(*) | |
| 1554 | 1577 | FROM unclustered, blob WHERE unclustered.rid=blob.rid |
| 1555 | 1578 | AND uuid='$crosslinkHash'"] 0 |
| 1556 | 1579 | |
| 1557 | 1580 | set crosslinkG [crosslink_put "D 2026-04-07T10:01:00.000 |
| 1558 | 1581 | T +sym-on-shunned $crosslinkShun |
| @@ -1559,11 +1582,11 @@ | ||
| 1559 | 1582 | U alice |
| 1560 | 1583 | "] |
| 1561 | 1584 | test crosslink-shun-tag {$CODE == 0 && $crosslinkG ne ""} |
| 1562 | 1585 | crosslink_match crosslink-shun-tag-event [crosslink_event $crosslinkG] \ |
| 1563 | 1586 | {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(*) | |
| 1565 | 1588 | FROM tagxref, tag WHERE tag.tagid=tagxref.tagid |
| 1566 | 1589 | AND tagname='sym-on-shunned'"] 0 |
| 1567 | 1590 | |
| 1568 | 1591 | set crosslinkKid [crosslink_put "C shun-merge-kid |
| 1569 | 1592 | D 2026-04-07T11:00:00.000 |
| @@ -1572,11 +1595,11 @@ | ||
| 1572 | 1595 | U alice |
| 1573 | 1596 | "] |
| 1574 | 1597 | test crosslink-shun-merge-parent {$CODE == 0 && $crosslinkKid ne ""} |
| 1575 | 1598 | test_eq crosslink-shun-merge-parent-links \ |
| 1576 | 1599 | [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(*) | |
| 1578 | 1601 | FROM blob WHERE uuid='$crosslinkShun'"] 0 |
| 1579 | 1602 | fossil sql "DELETE FROM shun WHERE uuid='$crosslinkShun'" |
| 1580 | 1603 | |
| 1581 | 1604 | ############################################################################### |
| 1582 | 1605 | # A common script that fails makes "branch new" fail. |
| 1583 | 1606 |
| --- 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 *"type":"checkin"*"C":"crosslink-c2"*} |
| 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 *"type":"checkin"*"C":"crosslink-c2"*} |
| 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 @@ | ||
| 5 | 5 | # |
| 6 | 6 | # The scenario inputs are not inputs to "test-fuzz". They are read by |
| 7 | 7 | # scenario.test. |
| 8 | 8 | # |
| 9 | 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 | 10 | require_no_open_checkout |
| 16 | 11 | |
| 17 | 12 | test_setup |
| 18 | 13 | |
| 19 | 14 | source [file join $::testfiledir corpus.tcl] |
| @@ -28,11 +23,12 @@ | ||
| 28 | 23 | fossil test-fuzz $fuzzDir |
| 29 | 24 | test fuzz-corpus-$fuzzType {$CODE == 0} |
| 30 | 25 | } |
| 31 | 26 | |
| 32 | 27 | 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]]] { | |
| 34 | 30 | fossil test-fuzz --fuzztype $fuzzType $fuzzF |
| 35 | 31 | test fuzz-$fuzzType-[file tail $fuzzF] {$CODE == 0} |
| 36 | 32 | } |
| 37 | 33 | } |
| 38 | 34 | |
| @@ -74,8 +70,6 @@ | ||
| 74 | 70 | file mkdir not-a-fuzz-type |
| 75 | 71 | write_file [file join not-a-fuzz-type x] "x\n" |
| 76 | 72 | fossil test-fuzz not-a-fuzz-type -expectError |
| 77 | 73 | test fuzz-misnamed-directory {$CODE != 0} |
| 78 | 74 | |
| 79 | -############################################################################### | |
| 80 | - | |
| 81 | 75 | test_cleanup |
| 82 | 76 |
| --- 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 @@ | ||
| 4 | 4 | # are svndiff0 deltas (Text-delta: true), as "svnadmin dump --deltas" |
| 5 | 5 | # writes them, then git streams, then dumps of whole histories. Where |
| 6 | 6 | # Subversion or git is installed, a history that it wrote is imported too. |
| 7 | 7 | # |
| 8 | 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 | - | |
| 9 | +# The first sections run at every level, and the rest need | |
| 10 | +# -assurance stress. | |
| 14 | 11 | test_setup |
| 15 | 12 | |
| 16 | 13 | # A number in the variable-length form of svndiff0: seven bits a byte, |
| 17 | 14 | # most significant first, the high bit set on every byte but the last. |
| 18 | 15 | # |
| @@ -29,11 +26,12 @@ | ||
| 29 | 26 | # One window: source offset and length, target length, instructions and |
| 30 | 27 | # new data. INSTR is a list of byte values. |
| 31 | 28 | # |
| 32 | 29 | proc import_window {srcoff srclen tgtlen instr data} { |
| 33 | 30 | 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" | |
| 35 | 33 | } |
| 36 | 34 | |
| 37 | 35 | proc import_props {pairs} { |
| 38 | 36 | set b "" |
| 39 | 37 | foreach {k v} $pairs { |
| @@ -44,11 +42,14 @@ | ||
| 44 | 42 | |
| 45 | 43 | proc import_rev {n log} { |
| 46 | 44 | set p [import_props [list svn:log $log svn:author dan \ |
| 47 | 45 | svn:date 2026-01-0[expr {$n+1}]T00:00:00.000000Z]] |
| 48 | 46 | 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"] ""] | |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | 53 | proc import_node {path kind action {text ""} {delta 0}} { |
| 53 | 54 | set p "PROPS-END\n" |
| 54 | 55 | set h "Node-path: $path\nNode-kind: $kind\nNode-action: $action\n" |
| @@ -55,18 +56,24 @@ | ||
| 55 | 56 | if {$kind eq "dir"} { |
| 56 | 57 | return "${h}Prop-content-length: 10\nContent-length: 10\n\n$p\n\n" |
| 57 | 58 | } |
| 58 | 59 | if {$delta} { append h "Text-delta: true\n" } |
| 59 | 60 | 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"] ""] | |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | 67 | # Revision 1 adds trunk/a.txt, "hello world\n", as a delta from nothing. |
| 64 | 68 | # Revision 2 changes it by the delta in WINDOWS. |
| 65 | 69 | # |
| 66 | 70 | 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"] ""] | |
| 68 | 75 | append d [import_rev 0 zero] |
| 69 | 76 | append d [import_rev 1 one] |
| 70 | 77 | append d [import_node trunk dir add] |
| 71 | 78 | append d [import_node trunk/a.txt file add \ |
| 72 | 79 | "SVN\000[import_window 0 0 12 {0x8c} "hello world\n"]" 1] |
| @@ -121,12 +128,14 @@ | ||
| 121 | 128 | bad-instruction [import_window 0 12 1 {0xc1 0} {}] \ |
| 122 | 129 | source-window [import_window 1000 12 10 {0x0a 0} {}] \ |
| 123 | 130 | target-offset [import_window 0 12 10 {0x82 0x48 0x87 0x68} ab] \ |
| 124 | 131 | target-unwritten [import_window 0 12 4 {0x44 0} {}] \ |
| 125 | 132 | 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" \ | |
| 128 | 137 | truncated-varint "\x80\x80" \ |
| 129 | 138 | truncated-length [binary format c* {0 12 5 1 5 0x80}] \ |
| 130 | 139 | target-unfilled [import_window 0 12 4000 {0x85} abcde] \ |
| 131 | 140 | ] { |
| 132 | 141 | set importResult [import_try $importName $importWindows] |
| @@ -135,32 +144,41 @@ | ||
| 135 | 144 | } |
| 136 | 145 | |
| 137 | 146 | # Not an svndiff0 delta at all. |
| 138 | 147 | test import-svn-not-svndiff {[string match "*Invalid svndiff0*" \ |
| 139 | 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 | +} | |
| 140 | 153 | |
| 141 | 154 | ############################################################################### |
| 142 | 155 | # A dump written by Subversion itself, with deltas of several windows. |
| 143 | 156 | # Every version that Fossil imports must be byte for byte the one that |
| 144 | 157 | # Subversion holds. |
| 145 | 158 | |
| 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}]} { | |
| 147 | 161 | test_skip_part "svnadmin and svn are not installed" |
| 148 | 162 | } else { |
| 149 | 163 | set importRepo [file join [pwd] svnrepo] |
| 150 | 164 | exec svnadmin create $importRepo |
| 151 | 165 | exec svn checkout -q file://$importRepo svnwc |
| 152 | 166 | file mkdir svnwc/trunk |
| 153 | 167 | set importBase "" |
| 154 | 168 | 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" | |
| 156 | 171 | } |
| 157 | 172 | set importVersions [list $importBase] |
| 158 | 173 | 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] | |
| 162 | 180 | } |
| 163 | 181 | lappend importVersions $importNext |
| 164 | 182 | lappend importVersions "[string repeat {repeated line of text} 20000]\n" |
| 165 | 183 | write_file svnwc/trunk/a.txt [lindex $importVersions 0] |
| 166 | 184 | exec svn add -q svnwc/trunk |
| @@ -189,11 +207,12 @@ | ||
| 189 | 207 | # Fossil check-in artifact, one whose second card is a P card that names no |
| 190 | 208 | # parent. The file is imported as a file: the repository holds one |
| 191 | 209 | # check-in, the imported commit, and the file reads back with a line added |
| 192 | 210 | # at its end that stops it being an artifact. |
| 193 | 211 | |
| 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" | |
| 195 | 214 | append importArt "T *branch * planted\nT *sym-planted *\nU mallory\n" |
| 196 | 215 | write_file git-artifact-body.txt $importArt |
| 197 | 216 | fossil md5sum git-artifact-body.txt |
| 198 | 217 | append importArt "Z [lindex $RESULT 0]\n" |
| 199 | 218 | set importStream "blob\nmark :1\ndata [string length $importArt]\n$importArt\n" |
| @@ -208,31 +227,43 @@ | ||
| 208 | 227 | fossil sql -R git-artifact.fossil \ |
| 209 | 228 | "SELECT count(*) FROM tag WHERE tagname='sym-planted'" |
| 210 | 229 | test_eq import-git-artifact-no-branch [string trim $RESULT] 0 |
| 211 | 230 | fossil_raw cat f.txt -R git-artifact.fossil -r trunk |
| 212 | 231 | 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"] ""] | |
| 214 | 235 | |
| 215 | 236 | ############################################################################### |
| 216 | 237 | # Input that "fossil import" must refuse with an error and exit code 1. |
| 217 | 238 | |
| 218 | 239 | # Each row: a git stream. The length of a data command is negative, too |
| 219 | 240 | # 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. | |
| 222 | 242 | # |
| 223 | 243 | set importWho "committer C <[email protected]>" |
| 224 | 244 | 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" \ | |
| 226 | 247 | data-huge "blob\nmark :1\ndata 2147483647\nhello\n" \ |
| 227 | 248 | 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"] ""] \ | |
| 231 | 261 | ] { |
| 232 | 262 | 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 | |
| 234 | 265 | test import-refuse-git-$importName {$CODE == 1 && |
| 235 | 266 | [string first "bad fast-import line" $RESULT] >= 0} |
| 236 | 267 | } |
| 237 | 268 | |
| 238 | 269 | # A commit command whose name is 992 bytes long, with no slash after its |
| @@ -251,32 +282,45 @@ | ||
| 251 | 282 | append importStart "Revision-number: 1\nProp-content-length: 10\n" |
| 252 | 283 | append importStart "Content-length: 10\n\nPROPS-END\n\n" |
| 253 | 284 | foreach {importName importDump} [list \ |
| 254 | 285 | header-cut "SVN-fs-dump-format-version: 2\nUUID: 0000" \ |
| 255 | 286 | 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"] ""] \ | |
| 258 | 293 | ] { |
| 259 | 294 | 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 | |
| 261 | 297 | test import-refuse-svn-$importName {$CODE == 1 && |
| 262 | 298 | [string first "svn-dump data format broken" $RESULT] >= 0} |
| 263 | 299 | } |
| 264 | 300 | |
| 265 | 301 | # A file outside trunk, branches and tags is passed over even when it has |
| 266 | 302 | # no Node-action. |
| 267 | 303 | # |
| 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"] ""] | |
| 269 | 308 | fossil_raw -seconds 60 import --svn outside.fossil outside.dump |
| 270 | 309 | test import-svn-outside-no-action {$CODE == 0} |
| 271 | 310 | |
| 272 | 311 | # An empty --trunk, --branches or --tags is refused unless --base names a |
| 273 | 312 | # directory; with one, an empty --trunk makes the base itself the trunk. |
| 274 | 313 | # |
| 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"] ""] | |
| 276 | 319 | 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 | |
| 278 | 322 | test import-refuse-svn-empty-$importName {$CODE == 1 && [string first \ |
| 279 | 323 | "may be empty only with a non-empty --base" $RESULT] >= 0} |
| 280 | 324 | } |
| 281 | 325 | fossil_raw -seconds 60 import --svn --base proj --trunk "" base.fossil base.dump |
| 282 | 326 | test import-svn-base-empty-trunk {$CODE == 0} |
| @@ -295,11 +339,15 @@ | ||
| 295 | 339 | # minutes after 2023-11-14 22:13:20 UTC. BODY is the lines that follow |
| 296 | 340 | # the comment. |
| 297 | 341 | # |
| 298 | 342 | proc import_commit {ref mark comment {body ""}} { |
| 299 | 343 | 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"] ""] | |
| 301 | 349 | } |
| 302 | 350 | |
| 303 | 351 | proc import_git {name stream args} { |
| 304 | 352 | write_file $name.fi $stream |
| 305 | 353 | fossil_raw -seconds 60 import --git {*}$args $name.fossil $name.fi |
| @@ -306,19 +354,19 @@ | ||
| 306 | 354 | } |
| 307 | 355 | |
| 308 | 356 | # What repository NAME answers to QUERY. |
| 309 | 357 | # |
| 310 | 358 | proc import_sql {name query} { |
| 311 | - fossil sql -R $name.fossil $query | |
| 312 | - return [string trim $::RESULT] | |
| 359 | + return [fossil_sql $query $name.fossil] | |
| 313 | 360 | } |
| 314 | 361 | |
| 315 | 362 | # The files of the check-in of NAME whose comment is COMMENT, in name |
| 316 | 363 | # order: the name, the permission and the former name of each. |
| 317 | 364 | # |
| 318 | 365 | 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,'')), ', ') | |
| 320 | 368 | FROM event e, blob b, files_of_checkin(b.uuid) f |
| 321 | 369 | WHERE e.type='ci' AND e.comment='$comment' AND b.rid=e.objid"] |
| 322 | 370 | } |
| 323 | 371 | |
| 324 | 372 | # The branch and tag names that hold for the check-in with comment COMMENT. |
| @@ -368,11 +416,12 @@ | ||
| 368 | 416 | append importStream "M 100644 :1 a.txt\nM 100755 :3 run.sh\nM 120000 :1 link\n" |
| 369 | 417 | append importStream "M 100644 :2 empty\n" |
| 370 | 418 | append importStream "M 100644 inline in.txt\ndata 7\ninline\n\n" |
| 371 | 419 | append importStream "M 100644 :99 missing.txt\n" |
| 372 | 420 | 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" | |
| 374 | 423 | append importStream "M 100644\nN :1 :10\ncheckpoint\n" |
| 375 | 424 | append importStream [import_commit refs/heads/master 11 two \ |
| 376 | 425 | "D run.sh\nD tmp\nC a.txt b.txt\nR link link2\n"] |
| 377 | 426 | append importStream [import_commit refs/heads/dev 12 three \ |
| 378 | 427 | "M 100644 :1 d.txt\n"] |
| @@ -390,28 +439,36 @@ | ||
| 390 | 439 | append importStream "tag unknown\nfrom :97\n$importTagger\n" |
| 391 | 440 | append importStream "tag v4\n$importTagger\nfrom :13" |
| 392 | 441 | |
| 393 | 442 | import_git all $importStream |
| 394 | 443 | 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" | |
| 397 | 448 | test_eq import-git-all-user [import_sql all \ |
| 398 | 449 | "SELECT user||' '||date(mtime) FROM event WHERE comment='one'"] \ |
| 399 | 450 | "[email protected] 2023-11-14" |
| 400 | 451 | 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"] ""] | |
| 402 | 455 | fossil_raw cat in.txt -R all.fossil -r [import_sql all \ |
| 403 | 456 | "SELECT uuid FROM blob, event WHERE rid=objid AND comment='one'"] |
| 404 | 457 | test_eq import-git-all-inline $RESULT "inline\n" |
| 405 | 458 | 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"] ""] | |
| 407 | 462 | test_eq import-git-all-two-parent [import_parents all two] one |
| 408 | 463 | test_eq import-git-all-two-tags [import_tags all two] "master trunk" |
| 409 | 464 | test_eq import-git-all-three-parent [import_parents all three] "" |
| 410 | 465 | test_eq import-git-all-three-tags [import_tags all three] "dev trunk" |
| 411 | 466 | 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"] ""] | |
| 413 | 470 | test_eq import-git-all-four-parents [import_parents all four] "two one three" |
| 414 | 471 | test_eq import-git-all-four-tags [import_tags all four] "dev trunk v2 v3 v4" |
| 415 | 472 | test_eq import-git-all-tag-comment [import_sql all "SELECT value FROM tagxref |
| 416 | 473 | WHERE tagid=(SELECT tagid FROM tag WHERE tagname='sym-v2')"] "the tag" |
| 417 | 474 | test_eq import-git-all-five-tags [import_tags all five] "dev trunk" |
| @@ -456,11 +513,12 @@ | ||
| 456 | 513 | append importStream [import_commit refs/heads/master 2 names $importBody] |
| 457 | 514 | append importStream [import_commit refs/heads/master 3 fewer \ |
| 458 | 515 | "D \"oct\\303\\251\"\nD plain name\n"] |
| 459 | 516 | import_git names $importStream |
| 460 | 517 | 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)), ' ') | |
| 462 | 520 | FROM event e, blob b, files_of_checkin(b.uuid) f |
| 463 | 521 | WHERE e.comment='names' AND b.rid=e.objid"] [lsort $importWant] |
| 464 | 522 | test_eq import-git-names-deleted [import_sql names "SELECT count(*) |
| 465 | 523 | FROM event e, blob b, files_of_checkin(b.uuid) f |
| 466 | 524 | WHERE e.comment='fewer' AND b.rid=e.objid"] 9 |
| @@ -482,11 +540,12 @@ | ||
| 482 | 540 | append importStream [import_commit refs/heads/ 2 slash "M 100644 :1 a\n"] |
| 483 | 541 | append importStream [import_commit refs/x 3 short "M 100644 :1 a\n"] |
| 484 | 542 | append importStream [import_commit refs/heads/master 4 nick \ |
| 485 | 543 | "property branch-nick 7 nicked\nproperty rebase-of abc\nM 100644 :1 a\n"] |
| 486 | 544 | 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, ' ') | |
| 488 | 547 | FROM (SELECT comment, value FROM event, tagxref |
| 489 | 548 | WHERE rid=objid AND tagxref.tagid=8 ORDER BY event.mtime)"] \ |
| 490 | 549 | "slash=refs/heads/ short=refs/x nick=nicked" |
| 491 | 550 | |
| 492 | 551 | # A commit on a tag ref that has no parent gets no tag, and a commit with |
| @@ -566,11 +625,12 @@ | ||
| 566 | 625 | # |
| 567 | 626 | foreach {importName importStream importError} [list \ |
| 568 | 627 | unknown-command "bogus line\n" {bad fast-import line: [bogus line]} \ |
| 569 | 628 | no-angle-bracket "commit refs/heads/master\ncommitter C 1700000000 +0000\n" \ |
| 570 | 629 | {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" \ | |
| 572 | 632 | {bad fast-import line: [committer C [email protected]>} \ |
| 573 | 633 | short-data "blob\nmark :1\ndata 50\nabc" \ |
| 574 | 634 | {short read: got 3 of 50 bytes} \ |
| 575 | 635 | ] { |
| 576 | 636 | import_git bad-$importName $importStream |
| @@ -696,13 +756,11 @@ | ||
| 696 | 756 | |
| 697 | 757 | # Marks may name a check-in made by "fossil commit", whose files carry no |
| 698 | 758 | # permission, and the files of such a parent are kept. A commit whose |
| 699 | 759 | # "from" is the mark of a file keeps nothing from it. |
| 700 | 760 | # |
| 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 | |
| 704 | 762 | fossil sql "SELECT 'c'||rid||' :7 '||uuid FROM blob |
| 705 | 763 | WHERE rid=(SELECT objid FROM event WHERE comment='committed')" |
| 706 | 764 | set importMarks "$RESULT\n" |
| 707 | 765 | fossil sql "SELECT 'b'||rid||' :8 '||uuid FROM blob |
| 708 | 766 | WHERE rid=(SELECT fid FROM mlink)" |
| @@ -750,11 +808,13 @@ | ||
| 750 | 808 | # A file command acts on a file that an earlier line of the same commit |
| 751 | 809 | # made: D removes it, C copies it and R renames it. |
| 752 | 810 | # |
| 753 | 811 | set importStream [import_blob 1 "hello\n"] |
| 754 | 812 | 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"] ""]] | |
| 756 | 816 | import_git ordered $importStream |
| 757 | 817 | test_eq import-git-ordered [import_files ordered ordered] \ |
| 758 | 818 | "dst w, new w, src w" knownBug |
| 759 | 819 | |
| 760 | 820 | ############################################################################### |
| @@ -781,11 +841,12 @@ | ||
| 781 | 841 | |
| 782 | 842 | # Revision N, made by dan on day N+1 of 2026, with LOG as its comment. |
| 783 | 843 | # |
| 784 | 844 | proc import_r {n log} { |
| 785 | 845 | 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}]]]] | |
| 787 | 848 | } |
| 788 | 849 | proc import_file {action path text {props -}} { |
| 789 | 850 | return [import_record \ |
| 790 | 851 | [list Node-path $path Node-kind file Node-action $action] $props $text] |
| 791 | 852 | } |
| @@ -842,11 +903,12 @@ | ||
| 842 | 903 | [import_file change trunk/a.txt "alpha2\n"] \ |
| 843 | 904 | [import_file change trunk/run.sh "run2\n"] \ |
| 844 | 905 | [import_record {Node-path trunk Node-kind dir Node-action change} - xyz] \ |
| 845 | 906 | [import_file change trunk/sub/s.txt - {svn:eol-style native}] |
| 846 | 907 | 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"] | |
| 848 | 910 | append importDump [import_r 5 five] [import_copy dir tags/v1 trunk 4] \ |
| 849 | 911 | [import_copy dir tags/v2 trunk 4] |
| 850 | 912 | append importDump [import_r 6 six] \ |
| 851 | 913 | [import_copy file trunk/b-copy.txt branches/b1/a.txt 4] \ |
| 852 | 914 | [import_copy file trunk/a2.txt trunk/a.txt 2] \ |
| @@ -891,31 +953,36 @@ | ||
| 891 | 953 | test_eq import-svn-layout-two [import_files layout "(no comment)"] \ |
| 892 | 954 | "a.txt, link l, run.sh x, sub/s.txt" |
| 893 | 955 | test_eq import-svn-layout-two-content \ |
| 894 | 956 | "[import_cat layout {(no comment)} a.txt][import_cat layout {(no comment)} run.sh]" \ |
| 895 | 957 | "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" | |
| 897 | 960 | test_eq import-svn-layout-three [import_files layout three] \ |
| 898 | 961 | "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)" | |
| 900 | 964 | test_eq import-svn-layout-three-tags [import_tags layout three] b1 |
| 901 | 965 | test_eq import-svn-layout-four [import_cat layout four a.txt] "beta\n" |
| 902 | 966 | test_eq import-svn-layout-four-tags [import_tags layout four] b1 |
| 903 | 967 | test_eq import-svn-layout-six [import_files layout six] \ |
| 904 | 968 | "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 \ | |
| 906 | 971 | layout six a2.txt][import_cat layout six d.txt][import_cat layout six e.txt]" \ |
| 907 | 972 | "beta\nalpha2\nalpha2\nmore\nfresh\n" |
| 908 | 973 | test_eq import-svn-layout-six-parents [import_parents layout six] \ |
| 909 | 974 | "(no comment) four" |
| 910 | 975 | test_eq import-svn-layout-seven [import_files layout seven] \ |
| 911 | 976 | "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" | |
| 913 | 979 | test_eq import-svn-layout-eight [import_files layout eight] "a.txt, link l,\ |
| 914 | 980 | run.sh x, sub/s.txt, sub2/s.txt, tcopy/a2.txt, tcopy/b-copy.txt,\ |
| 915 | 981 | 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" | |
| 917 | 984 | test_eq import-svn-layout-nine [import_files layout nine] s.txt |
| 918 | 985 | test_eq import-svn-layout-nine-parent [import_parents layout nine] six |
| 919 | 986 | test_eq import-svn-layout-nine-tags [import_tags layout nine] b2 |
| 920 | 987 | test_eq import-svn-layout-nine-closed [import_sql layout "SELECT count(*) |
| 921 | 988 | FROM tagxref, tag, event WHERE tag.tagid=tagxref.tagid AND tagname='closed' |
| @@ -1021,11 +1088,12 @@ | ||
| 1021 | 1088 | group_concat(DISTINCT value) FROM tagxref WHERE tagid=8"] trunk knownBug |
| 1022 | 1089 | |
| 1023 | 1090 | # A revision that copies a directory to another place on the same branch, |
| 1024 | 1091 | # and does nothing else, is a check-in with the files of the copy. |
| 1025 | 1092 | # |
| 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 \ | |
| 1027 | 1095 | 2 two][import_copy dir trunk/d2 trunk/d 1]" |
| 1028 | 1096 | test import-svn-dir-copy {$CODE == 0} |
| 1029 | 1097 | test_eq import-svn-dir-copy-files [import_files dircopy two] "d/f, d2/f" |
| 1030 | 1098 | |
| 1031 | 1099 | # --ignore-tree leaves out a directory and what is in it, on the trunk |
| @@ -1048,13 +1116,15 @@ | ||
| 1048 | 1116 | |
| 1049 | 1117 | # --incremental adds to a repository that exists, and tags each new |
| 1050 | 1118 | # check-in with its revision number unless --no-rev-tags is given. |
| 1051 | 1119 | # |
| 1052 | 1120 | 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"]" | |
| 1054 | 1123 | 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}]} | |
| 1056 | 1126 | fossil_raw -seconds 60 -input \ |
| 1057 | 1127 | "$importHead[import_r 3 three][import_file add trunk/c "c\n"]" \ |
| 1058 | 1128 | import --svn --incremental --no-rev-tags sincr.fossil |
| 1059 | 1129 | test import-svn-incremental-no-rev-tags {$CODE == 0} |
| 1060 | 1130 | test_eq import-svn-incremental-checkins [import_checkins sincr] "one two three" |
| @@ -1068,11 +1138,12 @@ | ||
| 1068 | 1138 | # |
| 1069 | 1139 | set importProps "D 3\nfoo\nK 7\nsvn:log\nV 7\nundated\nPROPS-END\n" |
| 1070 | 1140 | set importDump "SVN-fs-dump-format-version: 3\n\nOther: 1\n\n" |
| 1071 | 1141 | append importDump "Revision-number: 1\n" |
| 1072 | 1142 | 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" | |
| 1074 | 1145 | append importDump [import_file add trunk/a "a\n"] |
| 1075 | 1146 | import_svn undated $importDump |
| 1076 | 1147 | test import-svn-undated {$CODE == 0} |
| 1077 | 1148 | test_eq import-svn-undated-checkin [import_sql undated "SELECT comment||' '|| |
| 1078 | 1149 | (mtime>julianday('now','-1 day')) FROM event"] "undated 1" |
| @@ -1093,17 +1164,25 @@ | ||
| 1093 | 1164 | version-4 "SVN-fs-dump-format-version: 4\n\n" \ |
| 1094 | 1165 | "Unknown svn-dump format version: 4" \ |
| 1095 | 1166 | no-colon "${importHead}no colon here\n\n" {bad header line: [no colon here]} \ |
| 1096 | 1167 | ends-in-headers "${importHead}Revision-number: 1\n" \ |
| 1097 | 1168 | "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" \ | |
| 1099 | 1171 | "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"] ""] \ | |
| 1101 | 1176 | "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" \ | |
| 1103 | 1179 | "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"] ""] \ | |
| 1105 | 1184 | "short read: got 3 of 9 bytes" \ |
| 1106 | 1185 | unknown-record "${importHead}Other: 1\n\n" "Unknown record type" \ |
| 1107 | 1186 | rev-over-31-bits "$importHead[import_record {Revision-number 2147483648}]" \ |
| 1108 | 1187 | "svn-dump data format broken" \ |
| 1109 | 1188 | rev-eleven-digits "$importHead[import_record {Revision-number 21474836480}]" \ |
| @@ -1112,13 +1191,15 @@ | ||
| 1112 | 1191 | "svn-dump data format broken" \ |
| 1113 | 1192 | no-copyfrom-rev "$importA[import_record {Node-path trunk/b Node-kind file |
| 1114 | 1193 | Node-action add Node-copyfrom-path trunk/a}]" "Missing copyfrom-rev" \ |
| 1115 | 1194 | copy-from-outside "$importA[import_copy file trunk/b other/a 1]" \ |
| 1116 | 1195 | "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]" \ | |
| 1118 | 1198 | "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]" \ | |
| 1120 | 1201 | "Missing Node-kind" \ |
| 1121 | 1202 | unknown-action "$importR1[import_record {Node-path trunk/a Node-kind file |
| 1122 | 1203 | Node-action frobnicate}]" "Unknown Node-action" \ |
| 1123 | 1204 | short-link "$importR1[import_file add trunk/l "link " {svn:special *}]" \ |
| 1124 | 1205 | "Too short symbolic link path" \ |
| @@ -1157,11 +1238,15 @@ | ||
| 1157 | 1238 | v-no-newline "K 1\na\nV 1" \ |
| 1158 | 1239 | v-no-end "K 1\na\nV 1\nbcd\n" \ |
| 1159 | 1240 | ] { |
| 1160 | 1241 | append importProps "PROPS-END\n" |
| 1161 | 1242 | 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"] ""] | |
| 1163 | 1248 | test import-svn-props-$importName {$CODE == 1 && |
| 1164 | 1249 | [string first "svn-dump data format broken" $RESULT] >= 0} |
| 1165 | 1250 | } |
| 1166 | 1251 | |
| 1167 | 1252 | # A history with nodes that make no check-in of their own. |
| @@ -1244,11 +1329,12 @@ | ||
| 1244 | 1329 | # executable and a link on the trunk, a branch and a tag copied from it, |
| 1245 | 1330 | # a change, a renamed file, and the branch deleted. |
| 1246 | 1331 | |
| 1247 | 1332 | if {$::is_windows} { |
| 1248 | 1333 | 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}]} { | |
| 1250 | 1336 | test_skip_part "svnadmin and svn are not installed" |
| 1251 | 1337 | } else { |
| 1252 | 1338 | set importRepo [file join [pwd] svnrepo2] |
| 1253 | 1339 | set importUrl file://$importRepo |
| 1254 | 1340 | exec svnadmin create $importRepo |
| @@ -1267,11 +1353,12 @@ | ||
| 1267 | 1353 | exec svn move -q svnwc2/run.sh svnwc2/moved.sh |
| 1268 | 1354 | exec svn commit -q -m four svnwc2 |
| 1269 | 1355 | exec svn delete -q -m five $importUrl/branches/b1 |
| 1270 | 1356 | foreach {importName importOption} {plain {} deltas --deltas} { |
| 1271 | 1357 | 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 | |
| 1273 | 1360 | test import-svn-made-$importName {$CODE == 0} |
| 1274 | 1361 | set importName svn-$importName |
| 1275 | 1362 | test_eq import-$importName-checkins [import_checkins $importName] \ |
| 1276 | 1363 | "one two four" |
| 1277 | 1364 | test_eq import-$importName-one "[import_files $importName one];\ |
| @@ -1309,11 +1396,12 @@ | ||
| 1309 | 1396 | -c [email protected] {*}$args 2>@1] |
| 1310 | 1397 | unset ::env(GIT_AUTHOR_DATE) ::env(GIT_COMMITTER_DATE) |
| 1311 | 1398 | return $out |
| 1312 | 1399 | } |
| 1313 | 1400 | 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"] { | |
| 1315 | 1403 | write_file [file join gitrepo $importName] "content of $importName\n" |
| 1316 | 1404 | } |
| 1317 | 1405 | file attributes gitrepo/run.sh -permissions 0755 |
| 1318 | 1406 | file link -symbolic gitrepo/link a.txt |
| 1319 | 1407 | import_git_run 1 add -A |
| 1320 | 1408 |
| --- 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 |
-9
| --- test/integrity.test | ||
| +++ test/integrity.test | ||
| @@ -9,15 +9,10 @@ | ||
| 9 | 9 | # repository and fail, with a non-zero exit status, on each of nine |
| 10 | 10 | # kinds of damage made with SQL; and "fossil rebuild" leaves the |
| 11 | 11 | # tables derived from the artifacts as they were, or repairs them. |
| 12 | 12 | # |
| 13 | 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 | 14 | require_no_open_checkout |
| 20 | 15 | |
| 21 | 16 | test_setup "" |
| 22 | 17 | set ::env(FOSSIL_USER) tester |
| 23 | 18 | |
| @@ -144,11 +139,10 @@ | ||
| 144 | 139 | fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\ |
| 145 | 140 | JOIN filename USING(fnid) WHERE name='c.txt'" |
| 146 | 141 | fossil artifact [normalize_result] -R r2.fossil |
| 147 | 142 | test_eq integrity-artifact-readable [normalize_result] \ |
| 148 | 143 | "four\n[string repeat four 200]" |
| 149 | -file delete r2.fossil | |
| 150 | 144 | |
| 151 | 145 | ############################################################################### |
| 152 | 146 | # test-integrity and test-missing: exit 0 on a sound repository, non-zero |
| 153 | 147 | # on each kind of damage. Each kind is made to a copy. |
| 154 | 148 | |
| @@ -200,11 +194,10 @@ | ||
| 200 | 194 | set integrityDamaged [file join [pwd] damaged.fossil] |
| 201 | 195 | file copy -force r.fossil $integrityDamaged |
| 202 | 196 | fossil sql -R $integrityDamaged $integritySql |
| 203 | 197 | fossil {*}$integrityCmd -R $integrityDamaged -expectError |
| 204 | 198 | test integrity-damage-$integrityName {$CODE != 0} |
| 205 | - file delete $integrityDamaged | |
| 206 | 199 | } |
| 207 | 200 | |
| 208 | 201 | ############################################################################### |
| 209 | 202 | # Rebuild leaves the derived tables alone, or repairs a wrong one. |
| 210 | 203 | |
| @@ -211,18 +204,16 @@ | ||
| 211 | 204 | set integrityBefore [integrity_derived r.fossil] |
| 212 | 205 | test integrity-derived-not-empty {[string length $integrityBefore] > 0} |
| 213 | 206 | fossil rebuild r.fossil |
| 214 | 207 | test_eq integrity-rebuild-same [integrity_derived r.fossil] $integrityBefore |
| 215 | 208 | |
| 216 | -set integrityDamaged [file join [pwd] damaged.fossil] | |
| 217 | 209 | file copy -force r.fossil $integrityDamaged |
| 218 | 210 | fossil sql -R $integrityDamaged \ |
| 219 | 211 | "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)" |
| 220 | 212 | test integrity-missing-parent-link-shows \ |
| 221 | 213 | {[integrity_derived $integrityDamaged] ne $integrityBefore} |
| 222 | 214 | fossil rebuild $integrityDamaged |
| 223 | 215 | test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] \ |
| 224 | 216 | $integrityBefore |
| 225 | -file delete $integrityDamaged | |
| 226 | 217 | |
| 227 | 218 | test_cleanup |
| 228 | 219 | unset ::env(FOSSIL_USER) |
| 229 | 220 |
| --- 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 @@ | ||
| 5 | 5 | # test/cgi.test does. The /test-env page reports g.zLogin, g.isRobot and the |
| 6 | 6 | # capabilities the server granted. Several command-line test entry points in |
| 7 | 7 | # login.c are exercised directly. |
| 8 | 8 | # |
| 9 | 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" | |
| 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" | |
| 13 | 17 | } |
| 14 | 18 | |
| 15 | 19 | require_no_open_checkout |
| 16 | 20 | |
| 17 | 21 | test_setup |
| @@ -30,51 +34,53 @@ | ||
| 30 | 34 | VALUES('test_env_enable','1',0)" |
| 31 | 35 | |
| 32 | 36 | # Send TEXT (a byte string) to the server and return the whole reply. ARGS are |
| 33 | 37 | # extra "fossil http" options. |
| 34 | 38 | 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 | |
| 42 | 65 | } |
| 43 | 66 | |
| 44 | 67 | # A GET request for PATH carrying the header lines in HEADERS, a list. |
| 45 | 68 | 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]] | |
| 49 | 77 | } |
| 50 | 78 | |
| 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. | |
| 53 | 80 | 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]] | |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | 84 | # The login name that /test-env reports for a reply. The server writes an |
| 79 | 85 | # empty value for the "nobody" user, so report that as "nobody". |
| 80 | 86 | proc login_who {reply} { |
| @@ -98,18 +104,21 @@ | ||
| 98 | 104 | # through to the "nobody" user. |
| 99 | 105 | |
| 100 | 106 | fossil sql "REPLACE INTO config(name,value,mtime) |
| 101 | 107 | VALUES('http_authentication_ok','1',0)" |
| 102 | 108 | 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]"]] | |
| 104 | 111 | } |
| 105 | 112 | |
| 106 | 113 | 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]]]} | |
| 108 | 116 | |
| 109 | 117 | 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]]} | |
| 111 | 120 | |
| 112 | 121 | # A value with no colon names no password: the request is served as "nobody". |
| 113 | 122 | test_eq login-basic-nocolon [login_who [login_basic nocolonhere]] nobody |
| 114 | 123 | |
| 115 | 124 | # Header that does not begin with "Basic " is ignored. |
| @@ -150,51 +159,54 @@ | ||
| 150 | 159 | |
| 151 | 160 | proc login_form {user pw {extra ""}} { |
| 152 | 161 | return [login_post /login "u=$user&p=$pw&in=Login&$extra"] |
| 153 | 162 | } |
| 154 | 163 | 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]} | |
| 158 | 169 | regexp {(fossil-[0-9a-f]+=[^;]+)} $loginCookie all loginCookiePair |
| 159 | 170 | test_eq login-cookie-reuse \ |
| 160 | 171 | [login_who [login_get /test-env [list "Cookie: $loginCookiePair"]]] loginbob |
| 161 | 172 | |
| 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 | +} | |
| 174 | 185 | |
| 175 | 186 | ############################################################################### |
| 176 | 187 | # The "g" goto parameter is always rendered relative to the repository root: |
| 177 | 188 | # an absolute URL given in "g" is prefixed and so cannot leave the site. |
| 178 | 189 | |
| 179 | 190 | 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 | |
| 181 | 193 | |
| 182 | 194 | ############################################################################### |
| 183 | 195 | # Logout. A logged-in user who POSTs "out" with a matching Referer and the |
| 184 | 196 | # Anti-CSRF token from the form has the login cookie cleared (an empty value |
| 185 | 197 | # with a past expiry). |
| 186 | 198 | |
| 187 | 199 | 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] \ | |
| 189 | 201 | all loginLogoutPair |
| 190 | 202 | set loginReply [login_get /login [list "Cookie: $loginLogoutPair"]] |
| 191 | 203 | regexp {name="csrf" value="([^"]+)"} $loginReply all loginCsrf |
| 192 | 204 | set loginReply [login_post /login "out=Logout&csrf=$loginCsrf" \ |
| 193 | 205 | [list "Cookie: $loginLogoutPair"]] |
| 194 | 206 | test login-logout-clears \ |
| 195 | - {[string match "fossil-*=; *" [login_header $loginReply Set-Cookie]]} | |
| 207 | + {[string match "fossil-*=; *" [reply_header $loginReply Set-Cookie]]} | |
| 196 | 208 | |
| 197 | 209 | ############################################################################### |
| 198 | 210 | # Robot detection. With no login, g.isRobot is set from the User-Agent: a |
| 199 | 211 | # self-identified bot is a robot, a current browser is not. |
| 200 | 212 | |
| @@ -205,11 +217,12 @@ | ||
| 205 | 217 | } |
| 206 | 218 | test_eq login-robot-bot [login_isrobot "Googlebot/2.1"] 1 |
| 207 | 219 | test_eq login-robot-browser [login_isrobot "Mozilla/5.0 Firefox/122.0"] 0 |
| 208 | 220 | test_eq login-robot-noagent [login_isrobot ""] 1 |
| 209 | 221 | # 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"}] | |
| 211 | 224 | test login-robot-forced {[regexp {g\.isRobot = 1<br>} $loginReply]} |
| 212 | 225 | |
| 213 | 226 | ############################################################################### |
| 214 | 227 | # test-ishuman labels User-Agent strings read from standard input. |
| 215 | 228 | |
| @@ -236,29 +249,31 @@ | ||
| 236 | 249 | |
| 237 | 250 | ############################################################################### |
| 238 | 251 | # test-email-used reports which user owns an email address. |
| 239 | 252 | |
| 240 | 253 | 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]} | |
| 242 | 256 | test login-email-used-unknown \ |
| 243 | 257 | {[string match "*[email protected]: not used*" $::RESULT]} |
| 244 | 258 | |
| 245 | 259 | ############################################################################### |
| 246 | 260 | # Login groups. Two repositories are joined into a group, the membership is |
| 247 | 261 | # shown, then one leaves. |
| 248 | 262 | |
| 249 | 263 | set loginRepo2 [file join [pwd] grp2.fossil] |
| 250 | 264 | fossil new $loginRepo2 |
| 251 | -fossil user capabilities loginsue s | |
| 252 | 265 | fossil sql -R $loginRepo2 \ |
| 253 | 266 | "INSERT INTO user(login,pw,cap) VALUES('loginsue','suepw','s')" |
| 254 | 267 | |
| 255 | 268 | 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]} | |
| 257 | 271 | fossil login-group join --name loggrp $loginRepo2 |
| 258 | 272 | 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]} | |
| 260 | 275 | test_eq login-group-name-fn [string trim [fossil sql \ |
| 261 | 276 | "SELECT value FROM config WHERE name='login-group-name'"]] loggrp |
| 262 | 277 | fossil login-group leave |
| 263 | 278 | fossil login-group |
| 264 | 279 | test login-group-left {[string match "*Not currently*" $::RESULT]} |
| @@ -280,11 +295,11 @@ | ||
| 280 | 295 | VALUES('http_authentication_ok','1',0)" |
| 281 | 296 | |
| 282 | 297 | # Log in as loginbob and return a two-element list {cookie-pair csrf-token}. |
| 283 | 298 | proc login_session {user pw} { |
| 284 | 299 | 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 | |
| 286 | 301 | set reply [login_get /login [list "Cookie: $pair"]] |
| 287 | 302 | regexp {name="csrf" value="([^"]+)"} $reply all tok |
| 288 | 303 | return [list $pair $tok] |
| 289 | 304 | } |
| 290 | 305 | |
| @@ -291,24 +306,30 @@ | ||
| 291 | 306 | set loginSess [login_session loginbob bobpw] |
| 292 | 307 | set loginPair [lindex $loginSess 0] |
| 293 | 308 | set loginTok [lindex $loginSess 1] |
| 294 | 309 | |
| 295 | 310 | 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]]} | |
| 298 | 315 | test_eq login-pwchange-newpw-works \ |
| 299 | 316 | [login_who [login_basic loginbob:newbobpw]] loginbob |
| 300 | 317 | 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]]]} | |
| 302 | 319 | |
| 303 | 320 | set loginReply [login_post /login \ |
| 304 | 321 | "p=newbobpw&n1=aaaaaa&n2=bbbbbb&csrf=$loginTok" [list "Cookie: $loginPair"]] |
| 305 | 322 | test login-pwchange-mismatch {[string match "*do not match*" $loginReply]} |
| 306 | 323 | |
| 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 | +} | |
| 310 | 331 | |
| 311 | 332 | ############################################################################### |
| 312 | 333 | # Self-registration through /register. The captcha answer is derived the same |
| 313 | 334 | # way the server derives it: the first 8 hex digits of sha1("SECRET-SEEDHEX"). |
| 314 | 335 | # A complete, valid form creates the account; each validation rule rejects the |
| @@ -333,22 +354,26 @@ | ||
| 333 | 354 | } |
| 334 | 355 | set loginRegTok [login_register_tokens] |
| 335 | 356 | set loginSeed [lindex $loginRegTok 0] |
| 336 | 357 | set loginCap [lindex $loginRegTok 1] |
| 337 | 358 | 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" | |
| 339 | 361 | |
| 340 | 362 | # POST a registration form whose user-supplied fields are FIELDS. |
| 341 | 363 | proc login_register {fields} { |
| 342 | 364 | global loginRegBase |
| 343 | 365 | return [login_post /register "$loginRegBase&$fields"] |
| 344 | 366 | } |
| 345 | 367 | |
| 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" | |
| 350 | 375 | |
| 351 | 376 | test login-register-short-uid \ |
| 352 | 377 | {[string match "*User ID too short*" [login_register \ |
| 353 | 378 | "u=abc&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]} |
| 354 | 379 | test login-register-reserved \ |
| @@ -381,11 +406,12 @@ | ||
| 381 | 406 | # including the recursive inheritance of "reader" (u) and "developer" (v). |
| 382 | 407 | |
| 383 | 408 | fossil sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')" |
| 384 | 409 | fossil sql "UPDATE user SET cap='j' WHERE login='reader'" |
| 385 | 410 | 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)" | |
| 387 | 413 | proc login_capexpand {cap} { |
| 388 | 414 | fossil sql "UPDATE user SET cap='$cap' WHERE login='loginbob'" |
| 389 | 415 | return [login_caps [login_basic loginbob:newbobpw]] |
| 390 | 416 | } |
| 391 | 417 | test_eq login-cap-wiki [login_capexpand kv] bjkmL |
| @@ -416,11 +442,12 @@ | ||
| 416 | 442 | ############################################################################### |
| 417 | 443 | # Capability expansion for the privilege letters that grant many flags at once: |
| 418 | 444 | # "s" (Setup) unlocks everything, and the forum digits accumulate. |
| 419 | 445 | set loginSetupCaps [login_capexpand s] |
| 420 | 446 | 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]} | |
| 422 | 449 | test_eq login-cap-forum6 [login_capexpand 6] 23456L |
| 423 | 450 | test_eq login-cap-forum3 [login_capexpand 3] 23L |
| 424 | 451 | |
| 425 | 452 | ############################################################################### |
| 426 | 453 | # Login cookies that are not of the form HASH/ARG/USER, or that name a user |
| @@ -432,17 +459,19 @@ | ||
| 432 | 459 | slash / |
| 433 | 460 | end-slash abcdef/ |
| 434 | 461 | two-parts a/b/ |
| 435 | 462 | no-slash abcdef |
| 436 | 463 | 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 | |
| 439 | 468 | } { |
| 440 | 469 | set loginReply [login_get /test-env \ |
| 441 | 470 | [list "Cookie: $loginCookieName=$loginCkValue"]] |
| 442 | 471 | 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" | |
| 444 | 473 | && [login_who $loginReply] eq "nobody"} |
| 445 | 474 | } |
| 446 | 475 | |
| 447 | 476 | ############################################################################### |
| 448 | 477 | # Where a login goes afterwards when the request carries "fossil-goto", as a |
| @@ -450,11 +479,11 @@ | ||
| 450 | 479 | # site, and to the home page if it is anywhere else. A value that is not an |
| 451 | 480 | # absolute http: or https: address, such as "timeline" or "//evil.example/", |
| 452 | 481 | # is taken as a page of this site. The same holds for an |
| 453 | 482 | # anonymous login and for the answer to the robot captcha at /ityaar. |
| 454 | 483 | |
| 455 | -set loginHome [login_header [login_form loginbob newbobpw] Location] | |
| 484 | +set loginHome [reply_header [login_form loginbob newbobpw] Location] | |
| 456 | 485 | test login-goto-home {[string match "http://x/*" $loginHome]} |
| 457 | 486 | fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'" |
| 458 | 487 | set loginAnon "u=anonymous&p=$loginCap&cs=$loginSeed" |
| 459 | 488 | set loginRobot "captchaseed=$loginSeed&captcha=$loginCap" |
| 460 | 489 | |
| @@ -465,40 +494,42 @@ | ||
| 465 | 494 | relative timeline http://x/timeline \ |
| 466 | 495 | same-site http://x/timeline http://x/timeline \ |
| 467 | 496 | ] { |
| 468 | 497 | set loginReply [login_get \ |
| 469 | 498 | "/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 | |
| 472 | 501 | 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 | |
| 475 | 504 | set loginReply [login_post /login "u=loginbob&p=newbobpw&in=Login" \ |
| 476 | 505 | [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 | |
| 479 | 508 | set loginReply [login_get "/login?$loginAnon&fossil-goto=$loginGoTarget"] |
| 480 | 509 | 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} | |
| 483 | 512 | 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 | |
| 486 | 515 | } |
| 487 | 516 | |
| 488 | 517 | # The captcha page at /honeypot remembers the address asked for in a |
| 489 | 518 | # "fossil-goto" cookie, and a right answer sent with that cookie goes there. |
| 490 | 519 | set loginReply [login_get /honeypot?x=1] |
| 491 | 520 | 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]} | |
| 493 | 523 | set loginReply [login_get "/ityaar?$loginRobot" \ |
| 494 | 524 | {"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] \ | |
| 496 | 526 | http://x/honeypot?x=1 |
| 497 | 527 | # A wrong answer shows the captcha again. |
| 498 | 528 | 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]} | |
| 500 | 531 | |
| 501 | 532 | ############################################################################### |
| 502 | 533 | # Helpers for the cases below. |
| 503 | 534 | |
| 504 | 535 | # A GET or POST to the repository REPO instead of the main one. |
| @@ -533,25 +564,18 @@ | ||
| 533 | 564 | return $m |
| 534 | 565 | } |
| 535 | 566 | return - |
| 536 | 567 | } |
| 537 | 568 | |
| 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 | 569 | |
| 547 | 570 | # Set the repository setting NAME to VALUE, or remove it when VALUE is "". |
| 548 | 571 | proc login_config {name value} { |
| 549 | 572 | if {$value eq ""} { |
| 550 | 573 | fossil sql "DELETE FROM config WHERE name='$name'" |
| 551 | 574 | } 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)" | |
| 553 | 577 | } |
| 554 | 578 | } |
| 555 | 579 | |
| 556 | 580 | ############################################################################### |
| 557 | 581 | # The capability letters not shown above each grant their own capability. |
| @@ -593,11 +617,11 @@ | ||
| 593 | 617 | ############################################################################### |
| 594 | 618 | # With no user named "nobody", a request without credentials is served as |
| 595 | 619 | # user id -1 with no capabilities. |
| 596 | 620 | fossil sql "UPDATE user SET login='nobody-saved' WHERE login='nobody'" |
| 597 | 621 | 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" | |
| 599 | 623 | && [string match "*g.userUid = -1<br>*" $loginReply] |
| 600 | 624 | && [login_caps $loginReply] eq ""} |
| 601 | 625 | fossil sql "UPDATE user SET login='nobody' WHERE login='nobody-saved'" |
| 602 | 626 | |
| 603 | 627 | ############################################################################### |
| @@ -654,11 +678,15 @@ | ||
| 654 | 678 | fossil unset localauth |
| 655 | 679 | |
| 656 | 680 | ############################################################################### |
| 657 | 681 | # With --httptrace, the login and its capability string are written to |
| 658 | 682 | # 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"] ""] | |
| 660 | 688 | fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 9.9.9.9 \ |
| 661 | 689 | --httptrace |
| 662 | 690 | test login-httptrace \ |
| 663 | 691 | {[string first {# login: [loginbob] with capabilities [o]} $RESULT] >= 0} |
| 664 | 692 | |
| @@ -673,50 +701,59 @@ | ||
| 673 | 701 | set loginUA "User-Agent: $loginUAText" |
| 674 | 702 | set loginReply [login_get "/login?$loginAnon" [list $loginUA]] |
| 675 | 703 | set loginAnonPair [login_cookie_pair $loginReply] |
| 676 | 704 | test login-anon-cookie {[string match "fossil-*=*%2Fanonymous" $loginAnonPair]} |
| 677 | 705 | 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]]} | |
| 679 | 707 | set loginReply [login_get /test-env [list "Cookie: $loginAnonPair" $loginUA]] |
| 680 | 708 | test login-anon-cookie-reuse {[login_who $loginReply] eq "anonymous" |
| 681 | 709 | && [login_method $loginReply] eq "COOKIE"} |
| 682 | 710 | test_eq login-anon-cookie-other-agent [login_who [login_get /test-env \ |
| 683 | 711 | [list "Cookie: $loginAnonPair" "User-Agent: Mozilla/5.0 Chrome/120.0"]]] \ |
| 684 | 712 | nobody |
| 685 | 713 | set loginReply [login_get "/login?$loginAnon&remember=1"] |
| 686 | 714 | 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]]} | |
| 688 | 717 | |
| 689 | 718 | set loginSecret [string trim [fossil sql \ |
| 690 | 719 | "SELECT value FROM config WHERE name='captcha-secret'"]] |
| 691 | 720 | fossil sql "REPLACE INTO config(name,value,mtime) |
| 692 | 721 | VALUES('captcha-secret-1','oldsecret',unixepoch())" |
| 693 | 722 | 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"] | |
| 695 | 724 | 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]]] \ | |
| 697 | 727 | anonymous |
| 698 | -set loginStaleHash [login_sha1 "2400000.5/$loginUAText/$loginSecret"] | |
| 728 | +set loginStaleHash [sha1_text "2400000.5/$loginUAText/$loginSecret"] | |
| 699 | 729 | 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]]] \ | |
| 701 | 732 | nobody |
| 702 | 733 | set loginOldPw [string range \ |
| 703 | - [login_sha1 "oldsecret-[format %x $loginSeed]"] 0 7] | |
| 734 | + [sha1_text "oldsecret-[format %x $loginSeed]"] 0 7] | |
| 704 | 735 | set loginReply [login_get "/login?u=anonymous&p=$loginOldPw&cs=$loginSeed"] |
| 705 | 736 | 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 | +} | |
| 710 | 744 | fossil sql "DELETE FROM config WHERE name='captcha-secret-1'" |
| 711 | 745 | |
| 712 | 746 | login_config anon-cookie-lifespan 0 |
| 713 | 747 | test_eq login-anon-cookie-off [login_who [login_get /test-env \ |
| 714 | 748 | [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 | +} | |
| 718 | 755 | login_config anon-cookie-lifespan "" |
| 719 | 756 | |
| 720 | 757 | ############################################################################### |
| 721 | 758 | # The /login page. "anon=1" with "g" asks only for the captcha for an |
| 722 | 759 | # anonymous login; "g" alone names the page asked for, without its query |
| @@ -728,47 +765,50 @@ | ||
| 728 | 765 | test login-page-anon {[string match {*name="anon" value="1"*} $loginReply] |
| 729 | 766 | && [string match "*Verify that you are human*" $loginReply] |
| 730 | 767 | && [string match "*Verify that I am human*" $loginReply]} |
| 731 | 768 | set loginReply [login_get "/login?g=timeline%3fn=5"] |
| 732 | 769 | 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]} | |
| 734 | 772 | set loginSess [login_session loginbob newbobpw] |
| 735 | 773 | set loginPair [lindex $loginSess 0] |
| 736 | 774 | set loginReply [login_get "/login?g=timeline" [list "Cookie: $loginPair"]] |
| 737 | 775 | 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]} | |
| 739 | 778 | set loginReply [login_get "/login?anon=2" [list "Cookie: $loginPair"]] |
| 740 | 779 | test login-page-anon2 {![string match "*Currently logged in*" $loginReply] |
| 741 | 780 | && [string match "*Verify that I am human*" $loginReply]} |
| 742 | 781 | set loginReply [login_get /login] |
| 743 | 782 | test login-page-visitors {[string match "*Visitors may enter*" $loginReply] |
| 744 | 783 | && [string match "*Create A New Account*" $loginReply]} |
| 745 | 784 | test login-page-noanon \ |
| 746 | 785 | {![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] \ | |
| 748 | 787 | http://x/register |
| 749 | 788 | |
| 750 | 789 | # A logout sent with "anon=2", which skips the login check, redirects and |
| 751 | 790 | # clears no cookie. |
| 752 | 791 | 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 "-"} | |
| 755 | 795 | |
| 756 | 796 | # With "https-login" on, the login form is sent to the https: address of |
| 757 | 797 | # the site, unless the server is run with --nossl. |
| 758 | 798 | login_config https-login 1 |
| 759 | 799 | test login-page-https \ |
| 760 | 800 | {[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] | |
| 763 | 802 | test login-page-nossl {![string match "*'https://x/login'*" $loginReply]} |
| 764 | 803 | login_config https-login "" |
| 765 | 804 | |
| 766 | 805 | # With "auto-captcha" on, the page offers a button that fills in the |
| 767 | 806 | # anonymous password. |
| 768 | 807 | 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]]} | |
| 770 | 810 | login_config auto-captcha "" |
| 771 | 811 | |
| 772 | 812 | # "nobody" with the Password capability is refused a password change. |
| 773 | 813 | fossil sql "UPDATE user SET cap='p' WHERE login='nobody'" |
| 774 | 814 | regexp {name="csrf" value="([^"]+)"} [login_get /login] all loginNbCsrf |
| @@ -787,18 +827,21 @@ | ||
| 787 | 827 | [login_register "u=bad+user1&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]} |
| 788 | 828 | test login-register-no-email {[regexp {Email Address:.*Required} \ |
| 789 | 829 | [login_register "u=gooduser&dn=Real&ea=&p=longpw9&cp=longpw9"]]} |
| 790 | 830 | login_config auth-sub-email *@ok.example |
| 791 | 831 | 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"]]} | |
| 793 | 834 | test login-register-authorized {[string match "*Passwords do not match*" \ |
| 794 | 835 | [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=other99"]]} |
| 795 | 836 | 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*" \ | |
| 797 | 839 | [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]} |
| 798 | 840 | 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"]]} | |
| 800 | 843 | login_config self-register "" |
| 801 | 844 | test login-register-off \ |
| 802 | 845 | {[string match "*Registration not possible*" [login_get /register]]} |
| 803 | 846 | login_config self-register 1 |
| 804 | 847 | |
| @@ -837,11 +880,12 @@ | ||
| 837 | 880 | } |
| 838 | 881 | proc login_ssub {email} { |
| 839 | 882 | return [string trim [fossil sql \ |
| 840 | 883 | "SELECT ssub FROM subscriber WHERE semail='$email'"]] |
| 841 | 884 | } |
| 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"] | |
| 843 | 887 | test login-register-verify-noself {[string match "*Internal Error*" $loginReply] |
| 844 | 888 | && [login_user_cap verify1] eq "7" && [login_ssub [email protected]] eq "aw"} |
| 845 | 889 | fossil settings email-self [email protected] |
| 846 | 890 | login_config default-perms o2rj |
| 847 | 891 | set loginReply [login_register \ |
| @@ -852,17 +896,20 @@ | ||
| 852 | 896 | && [login_mail_count] == 1 && [login_ssub [email protected]] eq "acftw"} |
| 853 | 897 | login_config default-perms u |
| 854 | 898 | # With alerts=0 there is no subscription and no email. |
| 855 | 899 | set loginReply [login_register \ |
| 856 | 900 | "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]] | |
| 858 | 903 | && [login_ssub [email protected]] eq "" && [login_mail_count] == 1} |
| 859 | 904 | # An address that is already a verified subscriber needs no verification. |
| 860 | 905 | fossil sql "INSERT INTO subscriber(semail,sverified,sdonotcall,sdigest,ssub) |
| 861 | 906 | 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]] | |
| 864 | 911 | && [string trim [fossil sql \ |
| 865 | 912 | "SELECT suname FROM subscriber WHERE semail='[email protected]'"]] eq "verify4" |
| 866 | 913 | && [login_mail_count] == 1} |
| 867 | 914 | login_config selfreg-verify "" |
| 868 | 915 | |
| @@ -887,11 +934,12 @@ | ||
| 887 | 934 | # user. Both test commands need an argument. |
| 888 | 935 | |
| 889 | 936 | fossil sql "UPDATE user SET info='Sue <[email protected]>' WHERE login='loginsue'" |
| 890 | 937 | fossil sql "UPDATE user SET info='Ann <[email protected]> <[email protected]>' |
| 891 | 938 | 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) | |
| 893 | 941 | VALUES('[email protected]','verify2',1,0,0,'a'), |
| 894 | 942 | ('[email protected]','loginsue',1,0,0,'a'), |
| 895 | 943 | ('[email protected]','verify2',0,0,0,'a')" |
| 896 | 944 | fossil test-email-used [email protected] [email protected] [email protected] [email protected] \ |
| 897 | 945 | [email protected] |
| @@ -921,13 +969,15 @@ | ||
| 921 | 969 | {[string match "*does not allow users to reset*" [login_get /reqpwreset]]} |
| 922 | 970 | login_config self-pw-reset 1 |
| 923 | 971 | test login-reqpw-form \ |
| 924 | 972 | {[string match {*name="reqpwreset" value="1"*} [login_get /reqpwreset]]} |
| 925 | 973 | 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"]]} | |
| 927 | 976 | 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"]]} | |
| 929 | 979 | test login-page-reset-button \ |
| 930 | 980 | {[string match "*Reset My Password*" [login_get /login]]} |
| 931 | 981 | test login-register-reset-button {[string match "*Request Password Reset For*" \ |
| 932 | 982 | [login_register "u=gooduser&dn=Real&[email protected]&p=longpw9&cp=longpw9"]]} |
| 933 | 983 | |
| @@ -935,11 +985,12 @@ | ||
| 935 | 985 | global loginSeed loginCap |
| 936 | 986 | return [login_post /reqpwreset \ |
| 937 | 987 | "reqpwreset=1&captchaseed=$loginSeed&captcha=$loginCap&$fields"] |
| 938 | 988 | } |
| 939 | 989 | 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]"]]} | |
| 941 | 992 | fossil sql "UPDATE user SET cap='vp' WHERE login='loginbob'" |
| 942 | 993 | fossil sql "UPDATE user SET cap='a' WHERE login='developer'" |
| 943 | 994 | foreach {loginRqName loginRqAddr loginRqWant} { |
| 944 | 995 | empty {} {*Required*} |
| 945 | 996 | invalid notmail {*Not a valid email*} |
| @@ -964,20 +1015,22 @@ | ||
| 964 | 1015 | fossil unset email-self |
| 965 | 1016 | test login-reqpw-noself \ |
| 966 | 1017 | {[string match "*Internal Error*" [login_reqpw [email protected]]]} |
| 967 | 1018 | fossil settings email-self [email protected] |
| 968 | 1019 | 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] | |
| 970 | 1022 | && [login_mail_count] == 1} |
| 971 | 1023 | set loginMail [read_file [lindex [glob -directory lmail *] 0]] |
| 972 | 1024 | test login-reqpw-mail {[string match "*To: <[email protected]>*" $loginMail] |
| 973 | 1025 | && [string match "*Password reset for http://x*" $loginMail]} |
| 974 | 1026 | |
| 975 | 1027 | ############################################################################### |
| 976 | 1028 | # /resetpw/UID-TIMESTAMP-HASH. A valid suffix gives a form that sets the |
| 977 | 1029 | # 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 | |
| 979 | 1032 | # for "nobody", for a user with Setup capability or for a user without the |
| 980 | 1033 | # Password capability. |
| 981 | 1034 | |
| 982 | 1035 | proc login_reset_suffix {login} { |
| 983 | 1036 | set uid [string trim [fossil sql "SELECT uid FROM user WHERE login='$login'"]] |
| @@ -984,33 +1037,44 @@ | ||
| 984 | 1037 | fossil test-resetpw-url $uid |
| 985 | 1038 | regexp {/resetpw/([0-9a-f-]+)} $::RESULT all suffix |
| 986 | 1039 | return $suffix |
| 987 | 1040 | } |
| 988 | 1041 | 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>*" \ | |
| 990 | 1044 | [login_get /resetpw/$loginRName]]} |
| 991 | 1045 | test login-resetpw-mismatch {[string match "*do not match*" \ |
| 992 | 1046 | [login_post /resetpw "name=$loginRName&n1=aaaaaa&n2=bbbbbb"]]} |
| 993 | 1047 | test login-resetpw-changed {[string match "*Password changed successfully*" \ |
| 994 | 1048 | [login_post /resetpw "name=$loginRName&n1=resetpw1&n2=resetpw1"]]} |
| 995 | 1049 | test_eq login-resetpw-works [login_who [login_basic loginbob:resetpw1]] loginbob |
| 996 | 1050 | |
| 997 | -set loginBobUid [string trim [fossil sql \ | |
| 998 | - "SELECT uid FROM user WHERE login='loginbob'"]] | |
| 999 | 1051 | set loginHash [string repeat 0 64] |
| 1000 | 1052 | set loginNowHex [format %x [clock seconds]] |
| 1053 | +set loginBadTail [string repeat 0 70] | |
| 1054 | +set loginRbNames {} | |
| 1055 | +set loginRbRequests {} | |
| 1001 | 1056 | foreach {loginRbName loginRbSuffix} [list \ |
| 1002 | 1057 | short 1-2-3 \ |
| 1003 | 1058 | no-uid [string repeat x 70] \ |
| 1004 | 1059 | no-time "1--$loginHash$loginHash" \ |
| 1005 | 1060 | uid-zero "0-$loginNowHex-$loginHash" \ |
| 1006 | 1061 | 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" \ | |
| 1009 | 1066 | ] { |
| 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 | + } | |
| 1012 | 1076 | } |
| 1013 | 1077 | foreach loginRrUser {loginsue nobody} { |
| 1014 | 1078 | test login-resetpw-refused-$loginRrUser {[string match \ |
| 1015 | 1079 | "*Cannot change the password for user*" \ |
| 1016 | 1080 | [login_get /resetpw/[login_reset_suffix $loginRrUser]]]} |
| @@ -1033,11 +1097,11 @@ | ||
| 1033 | 1097 | set loginSess [login_session loginbob resetpw1] |
| 1034 | 1098 | set loginReply [login_post /login \ |
| 1035 | 1099 | "p=resetpw1&n1=groupnew1&n2=groupnew1&csrf=[lindex $loginSess 1]" \ |
| 1036 | 1100 | [list "Cookie: [lindex $loginSess 0]"]] |
| 1037 | 1101 | 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]]} | |
| 1039 | 1103 | test_eq login-group-gone-dropped [string trim [fossil sql \ |
| 1040 | 1104 | "SELECT count(*) FROM config WHERE name GLOB 'peer-*-1111111111111111'"]] 0 |
| 1041 | 1105 | set loginRName [login_reset_suffix loginbob] |
| 1042 | 1106 | test login-group-resetpw-error {[string match "*ljunk.fossil: *" \ |
| 1043 | 1107 | [login_post /resetpw "name=$loginRName&n1=groupnew2&n2=groupnew2"]]} |
| @@ -1069,12 +1133,14 @@ | ||
| 1069 | 1133 | set loginGoPair [login_cookie_pair $loginReply] |
| 1070 | 1134 | test_eq login-group-transfer-anon \ |
| 1071 | 1135 | [login_who [login_get /test-env [list "Cookie: $loginGoPair"]]] anonymous |
| 1072 | 1136 | |
| 1073 | 1137 | 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]] | |
| 1076 | 1142 | && ![string match "*%2Fanonymous*" $loginReply]} |
| 1077 | 1143 | set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \ |
| 1078 | 1144 | [list "Cookie: $loginWellFormed"]] |
| 1079 | 1145 | test login-group-ityaar-no-captcha \ |
| 1080 | 1146 | {![string match "*Prove that you are human*" $loginReply]} |
| @@ -1085,12 +1151,14 @@ | ||
| 1085 | 1151 | # does not exist or is not a database, a wrong number of arguments. |
| 1086 | 1152 | foreach {loginLgName loginLgArgs loginLgWant} [list \ |
| 1087 | 1153 | self [list join $loginRepo] {*same as this one*} \ |
| 1088 | 1154 | missing [list join [file join [pwd] nosuch.fossil]] {*does not exist*} \ |
| 1089 | 1155 | 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*} \ | |
| 1092 | 1160 | ] { |
| 1093 | 1161 | fossil_raw login-group {*}$loginLgArgs |
| 1094 | 1162 | test login-group-err-$loginLgName {$CODE != 0 |
| 1095 | 1163 | && [string match $loginLgWant $RESULT]} |
| 1096 | 1164 | } |
| @@ -1113,15 +1181,14 @@ | ||
| 1113 | 1181 | ############################################################################### |
| 1114 | 1182 | # Pages that need a capability "nobody" lacks redirect to /login, naming |
| 1115 | 1183 | # the page and its query string, and adding "anon=1" when "anonymous" has |
| 1116 | 1184 | # the capability. With "redirect-to-https" set to 2 the redirect goes to |
| 1117 | 1185 | # 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] \ | |
| 1120 | 1187 | http://x/login?g=tktnew%3fx%3D1 |
| 1121 | 1188 | 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] \ | |
| 1123 | 1190 | http://x/login?g=tktnew&anon=1 |
| 1124 | 1191 | fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'" |
| 1125 | 1192 | |
| 1126 | 1193 | # A page that shows hyperlinks only with the Hyperlink capability offers an |
| 1127 | 1194 | # anonymous login when "anonymous" has that capability. |
| @@ -1131,26 +1198,27 @@ | ||
| 1131 | 1198 | |
| 1132 | 1199 | # A page on the "robot-restrict" list asks a client without a login to |
| 1133 | 1200 | # show that it is not a robot. |
| 1134 | 1201 | login_config robot-restrict test-env |
| 1135 | 1202 | 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] "-" | |
| 1137 | 1204 | login_config robot-restrict "" |
| 1138 | 1205 | fossil sql "UPDATE user SET cap='' WHERE login='nobody'" |
| 1139 | 1206 | |
| 1140 | 1207 | # With "redirect-to-https" set to 1, the redirect to /login for such a page |
| 1141 | 1208 | # goes to the https: address. |
| 1142 | 1209 | 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] \ | |
| 1144 | 1211 | https://x/login?g=tktnew |
| 1145 | 1212 | login_config redirect-to-https "" |
| 1146 | 1213 | |
| 1147 | 1214 | # A login cookie in a repository that is in no login group does not keep |
| 1148 | 1215 | # /ityaar from asking again after a wrong answer. |
| 1149 | 1216 | set loginReply [login_get "/ityaar?captchaseed=$loginSeed&captcha=zzzzzzzz" \ |
| 1150 | 1217 | [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]} | |
| 1152 | 1220 | |
| 1153 | 1221 | # A sync request whose login card names a user with a NULL capability |
| 1154 | 1222 | # column logs in with no capabilities: its pull is refused. The same |
| 1155 | 1223 | # request for that user with Read capability is answered. |
| 1156 | 1224 | fossil user new loginnocap [email protected] nocappw |
| @@ -1159,18 +1227,23 @@ | ||
| 1159 | 1227 | "SELECT value FROM config WHERE name='project-code'"]] |
| 1160 | 1228 | set sc [string trim [fossil sql \ |
| 1161 | 1229 | "SELECT value FROM config WHERE name='server-code'"]] |
| 1162 | 1230 | set pw [string trim [fossil sql "SELECT pw FROM user WHERE login='$user'"]] |
| 1163 | 1231 | 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"] | |
| 1166 | 1234 | 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"] ""]] | |
| 1168 | 1240 | } |
| 1169 | 1241 | fossil sql "UPDATE user SET cap=NULL WHERE login='loginnocap'" |
| 1170 | 1242 | 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} | |
| 1172 | 1245 | fossil sql "UPDATE user SET cap='o' WHERE login='loginnocap'" |
| 1173 | 1246 | set loginReply [login_xfer_pull loginnocap] |
| 1174 | 1247 | test login-xfer-read-cap {[string match "*igot *" $loginReply] |
| 1175 | 1248 | && [string first {not\sauthorized} $loginReply] < 0} |
| 1176 | 1249 | |
| @@ -1190,17 +1263,19 @@ | ||
| 1190 | 1263 | login_config peer-repo-2222222222222222 [file join [pwd] lnoperm.fossil] |
| 1191 | 1264 | set loginSess [login_session loginbob groupnew2] |
| 1192 | 1265 | set loginReply [login_post /login \ |
| 1193 | 1266 | "p=groupnew2&n1=groupnew3&n2=groupnew3&csrf=[lindex $loginSess 1]" \ |
| 1194 | 1267 | [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]} | |
| 1196 | 1270 | login_config peer-repo-2222222222222222 "" |
| 1197 | 1271 | fossil_raw login-group join [file join [pwd] lnoperm.fossil] |
| 1198 | 1272 | test login-group-noperm-join {$CODE != 0 |
| 1199 | 1273 | && [string match "*unable to open*" $RESULT]} |
| 1200 | 1274 | } 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" | |
| 1202 | 1277 | } |
| 1203 | 1278 | file attributes lnoperm.fossil -permissions 0644 |
| 1204 | 1279 | |
| 1205 | 1280 | ############################################################################### |
| 1206 | 1281 | # Pages that depend on the client. A request with a "Mobi" User-Agent is |
| @@ -1246,17 +1321,18 @@ | ||
| 1246 | 1321 | empty {} $loginHome \ |
| 1247 | 1322 | base http://x http://x \ |
| 1248 | 1323 | base-more http://xy $loginHome \ |
| 1249 | 1324 | other http://y/ $loginHome \ |
| 1250 | 1325 | ] { |
| 1251 | - test_eq login-goto-$loginFgName [login_header [login_get \ | |
| 1326 | + test_eq login-goto-$loginFgName [reply_header [login_get \ | |
| 1252 | 1327 | "/login?u=loginbob&p=bobfinal&fossil-goto=$loginFgTarget"] Location] \ |
| 1253 | 1328 | $loginFgWant |
| 1254 | 1329 | } |
| 1255 | 1330 | |
| 1256 | 1331 | # 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>*" \ | |
| 1258 | 1334 | [login_get "/login?out=1" [list "Cookie: $loginPair"]]]} |
| 1259 | 1335 | |
| 1260 | 1336 | # A password change without the second copy of the new password, without |
| 1261 | 1337 | # the first, or without the Anti-CSRF token changes nothing. |
| 1262 | 1338 | foreach {loginPcName loginPcBody} [list \ |
| @@ -1264,20 +1340,20 @@ | ||
| 1264 | 1340 | no-n1 "p=bobfinal&n2=changed1&csrf=$loginTok" \ |
| 1265 | 1341 | no-csrf "p=bobfinal&n1=changed1&n2=changed1" \ |
| 1266 | 1342 | ] { |
| 1267 | 1343 | set loginReply [login_post /login $loginPcBody [list "Cookie: $loginPair"]] |
| 1268 | 1344 | test login-pwchange-$loginPcName \ |
| 1269 | - {![string match "HTTP/1.0 302*" [login_status $loginReply]] | |
| 1345 | + {![string match "HTTP/1.0 302*" [reply_status $loginReply]] | |
| 1270 | 1346 | && [login_who [login_basic loginbob:bobfinal]] eq "loginbob"} |
| 1271 | 1347 | } |
| 1272 | 1348 | |
| 1273 | 1349 | # A user name with no password, or an empty password, shows the form and |
| 1274 | 1350 | # sets no cookie. |
| 1275 | 1351 | foreach {loginNpName loginNpQuery} {no-p u=loginbob empty-p u=loginbob&p=} { |
| 1276 | 1352 | 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 "-"} | |
| 1279 | 1355 | } |
| 1280 | 1356 | |
| 1281 | 1357 | # "g" with "noanon" does not name the page asked for. |
| 1282 | 1358 | test login-page-goto-noanon {![string match "*access page*" \ |
| 1283 | 1359 | [login_get "/login?g=timeline&noanon=1"]]} |
| @@ -1312,21 +1388,24 @@ | ||
| 1312 | 1388 | [login_get /login [list "Cookie: $loginPair"]]]} |
| 1313 | 1389 | fossil settings email-send-method dir |
| 1314 | 1390 | fossil sql "UPDATE user SET cap='op' WHERE login='loginbob'" |
| 1315 | 1391 | |
| 1316 | 1392 | # 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]]] | |
| 1318 | 1395 | 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] | |
| 1320 | 1398 | && ![string match "*Change Password*" $loginReply]} |
| 1321 | 1399 | |
| 1322 | 1400 | ############################################################################### |
| 1323 | 1401 | # Further credential checks. |
| 1324 | 1402 | |
| 1325 | 1403 | # "resid" without "token" logs no one in; "resid" naming a user with no |
| 1326 | 1404 | # 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 | |
| 1328 | 1407 | test_eq login-resid-no-pw \ |
| 1329 | 1408 | [login_who [login_get "/test-env?resid=nobody&token=x"]] nobody |
| 1330 | 1409 | |
| 1331 | 1410 | # A user whose login name is empty is served with that user's capabilities |
| 1332 | 1411 | # but without "L", the mark of a logged-in user. |
| @@ -1350,17 +1429,17 @@ | ||
| 1350 | 1429 | test login-httptrace-no-nobody {[string first {# login:} $RESULT] < 0} |
| 1351 | 1430 | |
| 1352 | 1431 | # A request from 127.0.0.1 without --localauth, or over https: with it, is |
| 1353 | 1432 | # not logged in. A request over the fossil ssh transport with --localauth |
| 1354 | 1433 | # 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 | 1434 | fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --ipaddr 127.0.0.1 |
| 1357 | 1435 | test_eq login-loopback-no-localauth [login_who [read_file lreply.txt]] nobody |
| 1358 | 1436 | set ::env(REMOTE_HOST) 127.0.0.1 |
| 1359 | 1437 | test_eq login-local-https [login_who [login_local $loginRepo --https]] nobody |
| 1360 | 1438 | 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" | |
| 1362 | 1441 | set ::env(SSH_CONNECTION) "9.9.9.9 5000 127.0.0.1 22" |
| 1363 | 1442 | fossil_raw http $loginRepo --in lreq.txt --out lreply.txt --localauth |
| 1364 | 1443 | unset ::env(SSH_CONNECTION) |
| 1365 | 1444 | set loginReply [read_file lreply.txt] |
| 1366 | 1445 | test login-local-ssh {[login_method $loginReply] eq "LOCAL" |
| @@ -1380,11 +1459,12 @@ | ||
| 1380 | 1459 | |
| 1381 | 1460 | # The offer of an anonymous login is not made when "anonymous" lacks the |
| 1382 | 1461 | # Hyperlink capability or anonymous logins are off. |
| 1383 | 1462 | fossil sql "UPDATE user SET cap='o' WHERE login='nobody'" |
| 1384 | 1463 | 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*" \ | |
| 1386 | 1466 | [login_get /leaves [list $loginUA]]]} |
| 1387 | 1467 | fossil sql "UPDATE user SET cap='h' WHERE login='anonymous'" |
| 1388 | 1468 | login_config anon-cookie-lifespan 0 |
| 1389 | 1469 | test login-anonymous-available-off {![string match "*hyperlinks are disabled*" \ |
| 1390 | 1470 | [login_get /leaves [list $loginUA]]]} |
| @@ -1399,17 +1479,19 @@ | ||
| 1399 | 1479 | foreach loginRsName {nobody1 reader1 developer1} { |
| 1400 | 1480 | test login-register-reserved-$loginRsName {[string match "*reserved*" \ |
| 1401 | 1481 | [login_register "u=$loginRsName&dn=R&[email protected]&p=longpw9&cp=longpw9"]]} |
| 1402 | 1482 | } |
| 1403 | 1483 | # 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"] | |
| 1405 | 1486 | test login-register-get {[string match {*name="captchaseed"*} $loginReply] |
| 1406 | 1487 | && [login_user_cap getuser1] eq ""} |
| 1407 | 1488 | # An "auth-sub-email" setting that is empty allows any address. |
| 1408 | 1489 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES('auth-sub-email','',0)" |
| 1409 | 1490 | 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"]]} | |
| 1411 | 1493 | login_config auth-sub-email "" |
| 1412 | 1494 | |
| 1413 | 1495 | login_config self-pw-reset 1 |
| 1414 | 1496 | # The address of the "nobody" user is refused even with the Password |
| 1415 | 1497 | # capability. |
| @@ -1422,23 +1504,14 @@ | ||
| 1422 | 1504 | "captchaseed=$loginSeed&captcha=$loginCap&[email protected]"] |
| 1423 | 1505 | test login-reqpw-no-flag {[string match {*name="reqpwreset"*} $loginReply] |
| 1424 | 1506 | && ![string match "*has been sent*" $loginReply]} |
| 1425 | 1507 | |
| 1426 | 1508 | ############################################################################### |
| 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 | |
| 1429 | 1510 | # valid suffixes for a user with Admin capability and for "nobody" with the |
| 1430 | 1511 | # Password capability. |
| 1431 | 1512 | |
| 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 | 1513 | set loginRName [login_reset_suffix loginbob] |
| 1441 | 1514 | test login-resetpw-one-copy {[string match "*Change Password for user*" \ |
| 1442 | 1515 | [login_post /resetpw "name=$loginRName&n1=changed1"]]} |
| 1443 | 1516 | fossil sql "UPDATE user SET cap='a' WHERE login='verify3'" |
| 1444 | 1517 | test login-resetpw-refused-admin {[string match \ |
| @@ -1457,11 +1530,12 @@ | ||
| 1457 | 1530 | # hex digits, a slash and at least one more character. |
| 1458 | 1531 | |
| 1459 | 1532 | login_config peer-repo-3333333333333333 [file join [pwd] ljunk.fossil] |
| 1460 | 1533 | login_config peer-repo-4444444444444444 $loginRepo2 |
| 1461 | 1534 | set loginFakeHash [string repeat A 50] |
| 1462 | -foreach {loginPeName loginPeCode} {junk 3333333333333333 nocookie 4444444444444444} { | |
| 1535 | +foreach {loginPeName loginPeCode} \ | |
| 1536 | + {junk 3333333333333333 nocookie 4444444444444444} { | |
| 1463 | 1537 | test_eq login-transfer-$loginPeName [login_who [login_get /test-env \ |
| 1464 | 1538 | [list "Cookie: $loginCookieName=$loginFakeHash/$loginPeCode/loginsue"]]] \ |
| 1465 | 1539 | nobody |
| 1466 | 1540 | } |
| 1467 | 1541 | login_config peer-repo-3333333333333333 "" |
| @@ -1482,40 +1556,40 @@ | ||
| 1482 | 1556 | } |
| 1483 | 1557 | fossil login-group leave |
| 1484 | 1558 | |
| 1485 | 1559 | # An empty login-group subcommand is unknown. |
| 1486 | 1560 | 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]} | |
| 1488 | 1563 | |
| 1489 | 1564 | ############################################################################### |
| 1490 | 1565 | # Further cases, each varying one input of a case above. |
| 1491 | 1566 | |
| 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 | 1567 | # With "access-log" off, a login is not recorded. |
| 1497 | 1568 | login_config access-log 0 |
| 1498 | 1569 | set loginLogCount [string trim [fossil sql "SELECT count(*) FROM accesslog"]] |
| 1499 | 1570 | login_form loginbob bobfinal |
| 1500 | 1571 | test_eq login-accesslog-off \ |
| 1501 | 1572 | [string trim [fossil sql "SELECT count(*) FROM accesslog"]] $loginLogCount |
| 1502 | 1573 | login_config access-log "" |
| 1503 | 1574 | |
| 1504 | 1575 | # 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 | +} | |
| 1511 | 1584 | |
| 1512 | 1585 | # Login cookies that name the special users "developer" and "reader" are |
| 1513 | 1586 | # not accepted. |
| 1514 | 1587 | foreach loginSpUser {developer reader} { |
| 1515 | 1588 | 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"]]] \ | |
| 1517 | 1591 | nobody |
| 1518 | 1592 | } |
| 1519 | 1593 | |
| 1520 | 1594 | # The forum capabilities 5 and 4 grant those below them; "u" or "v" given |
| 1521 | 1595 | # twice inherits once. |
| 1522 | 1596 |
| --- 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 @@ | ||
| 3 | 3 | # compared with "fossil diff --from --to", the /dir and /tree pages, |
| 4 | 4 | # delta manifests read through their baseline, a file named in another |
| 5 | 5 | # letter case, and artifact_to_json() for every kind of artifact. |
| 6 | 6 | # |
| 7 | 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 | 8 | test_setup |
| 14 | 9 | |
| 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 | 10 | # The hash of the check-in with the comment COMMENT. |
| 24 | 11 | # |
| 25 | 12 | proc manifest_ci {comment} { |
| 26 | - return [manifest_sql "SELECT uuid FROM blob, event | |
| 13 | + return [fossil_sql "SELECT uuid FROM blob, event | |
| 27 | 14 | WHERE objid=rid AND type='ci' AND comment='$comment'"] |
| 28 | 15 | } |
| 29 | 16 | |
| 30 | 17 | # The reply of the server to a GET of PATH. |
| 31 | 18 | # |
| 32 | 19 | 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] | |
| 39 | 22 | } |
| 40 | 23 | |
| 41 | 24 | write_file a.txt "one\n" |
| 42 | 25 | write_file b.txt "bee\n" |
| 43 | 26 | write_file keep.txt "kept\n" |
| @@ -54,11 +37,11 @@ | ||
| 54 | 37 | |
| 55 | 38 | fossil diff --from $manifestV1 --to $manifestV2 |
| 56 | 39 | test manifest-diff-versions {$CODE == 0 && [string match "*+two*" $RESULT]} |
| 57 | 40 | |
| 58 | 41 | # 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 | |
| 60 | 43 | WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$manifestV2') |
| 61 | 44 | AND fnid=(SELECT fnid FROM filename WHERE name='a.txt')"] |
| 62 | 45 | fossil diff --from $manifestFile --to $manifestV2 -expectError |
| 63 | 46 | test manifest-diff-not-checkin {$CODE != 0 |
| 64 | 47 | && [string match "*cannot resolve name*" $RESULT]} |
| @@ -97,11 +80,11 @@ | ||
| 97 | 80 | fossil diff --from $manifestV2 --to $manifestV4 |
| 98 | 81 | test manifest-diff-delta {$CODE == 0 && [string match "*+three*" $RESULT] |
| 99 | 82 | && [string match "*DELETED keep.txt*" $RESULT]} |
| 100 | 83 | |
| 101 | 84 | # 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 | |
| 103 | 86 | json_extract(artifact_to_json('$manifestV3'), '\$.B') = |
| 104 | 87 | (SELECT uuid FROM blob WHERE rid=(SELECT baseid FROM plink |
| 105 | 88 | WHERE cid=(SELECT rid FROM blob WHERE uuid='$manifestV3')))"] 1 |
| 106 | 89 | |
| 107 | 90 | ############################################################################### |
| @@ -145,15 +128,16 @@ | ||
| 145 | 128 | fossil attachment add Page c.txt |
| 146 | 129 | test manifest-json-attachment {$CODE == 0} |
| 147 | 130 | fossil ticket add title "A ticket" status Open |
| 148 | 131 | fossil test-create-clusters |
| 149 | 132 | |
| 150 | -set manifestJson [manifest_sql "SELECT count(*), sum(json_valid(j)) | |
| 133 | +set manifestJson [fossil_sql "SELECT count(*), sum(json_valid(j)) | |
| 151 | 134 | FROM (SELECT artifact_to_json(rid) AS j FROM blob WHERE size>=0) |
| 152 | 135 | WHERE j IS NOT NULL"] |
| 153 | 136 | 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] | |
| 155 | 139 | && [lindex $manifestJson 0] > 10} |
| 156 | 140 | |
| 157 | 141 | foreach {manifestName manifestPath manifestWant} [list \ |
| 158 | 142 | exec "\$.F\[2\].perm" x \ |
| 159 | 143 | rename "\$.F\[1\].rename" b.txt \ |
| @@ -163,41 +147,42 @@ | ||
| 163 | 147 | switch $manifestName { |
| 164 | 148 | exec { set manifestOf [manifest_ci exec-set] } |
| 165 | 149 | rename { set manifestOf $manifestV2 } |
| 166 | 150 | cherrypick { set manifestOf [manifest_ci cherrypick] } |
| 167 | 151 | tag { |
| 168 | - set manifestOf [manifest_sql "SELECT uuid FROM blob, tagxref, tag | |
| 152 | + set manifestOf [fossil_sql "SELECT uuid FROM blob, tagxref, tag | |
| 169 | 153 | WHERE blob.rid=srcid AND tag.tagid=tagxref.tagid |
| 170 | 154 | AND tagname='sym-release'"] |
| 171 | 155 | } |
| 172 | 156 | } |
| 173 | - test_eq manifest-json-$manifestName [manifest_sql \ | |
| 157 | + test_eq manifest-json-$manifestName [fossil_sql \ | |
| 174 | 158 | "SELECT json_extract(artifact_to_json('$manifestOf'), '$manifestPath')"] \ |
| 175 | 159 | $manifestWant |
| 176 | 160 | } |
| 177 | 161 | |
| 178 | 162 | # Content that is not an artifact gives NULL, and a value that is neither |
| 179 | 163 | # 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 \ | |
| 181 | 165 | "SELECT artifact_to_json('$manifestFile') IS NULL"] 1 |
| 182 | 166 | 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]} | |
| 184 | 169 | |
| 185 | 170 | ############################################################################### |
| 186 | 171 | # "tag add --root" puts a tag on the first check-in of the line that a |
| 187 | 172 | # check-in is on, and says so when it only tries. |
| 188 | 173 | |
| 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 | |
| 190 | 175 | FROM plink WHERE pid NOT IN (SELECT cid FROM plink) LIMIT 1)"] |
| 191 | 176 | fossil tag add --root --dry-run rooted $manifestV2 |
| 192 | 177 | test manifest-tag-root-dry-run {$CODE == 0 && [string match \ |
| 193 | 178 | "*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(*) | |
| 195 | 180 | FROM tag WHERE tagname='sym-rooted'"] 0 |
| 196 | 181 | fossil tag add --root rooted $manifestV2 |
| 197 | 182 | 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, | |
| 199 | 184 | tag, blob WHERE tag.tagid=tagxref.tagid AND tagname='sym-rooted' |
| 200 | 185 | AND tagxref.rid=blob.rid AND tagxref.srcid>0 |
| 201 | 186 | AND uuid='$manifestRoot'"] 2 |
| 202 | 187 | fossil tag list --root $manifestV2 |
| 203 | 188 | test manifest-tag-root-list {$CODE == 0 && [string match "*rooted*" $RESULT]} |
| @@ -254,11 +239,14 @@ | ||
| 254 | 239 | test manifest-signed-stored {$CODE == 0 && $manifestSignedHash ne ""} |
| 255 | 240 | fossil settings manifest on |
| 256 | 241 | fossil update $manifestSignedHash |
| 257 | 242 | test manifest-signed-update {$CODE == 0} |
| 258 | 243 | 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*"] ""] \ | |
| 260 | 248 | [read_file manifest]]} |
| 261 | 249 | fossil diff --from prev --to current -expectError |
| 262 | 250 | test manifest-prev-not-checkin {$CODE != 0 |
| 263 | 251 | && [string match "*no such check-in: prev*" $RESULT]} |
| 264 | 252 | fossil settings manifest off |
| 265 | 253 |
| --- 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 @@ | ||
| 6 | 6 | # hashes begin alike. Every kind of name is then given to |
| 7 | 7 | # "fossil test-name-to-id", "fossil whatis" and other commands, and to |
| 8 | 8 | # web pages through "fossil http --in". |
| 9 | 9 | # |
| 10 | 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 | - | |
| 11 | +# The first sections run at every level, and the rest need | |
| 12 | +# -assurance stress. | |
| 16 | 13 | require_no_open_checkout |
| 17 | 14 | |
| 18 | 15 | test_setup "" |
| 19 | 16 | |
| 20 | 17 | set nameRepo [file join [pwd] name.fossil] |
| @@ -21,22 +18,14 @@ | ||
| 21 | 18 | fossil new --admin-user alice --date-override "2025-01-01 00:00:00" $nameRepo |
| 22 | 19 | fossil open $nameRepo |
| 23 | 20 | fossil user default alice |
| 24 | 21 | fossil set mtime-changes off |
| 25 | 22 | |
| 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 | 23 | # The hash of the check-in whose comment is COMMENT. |
| 35 | 24 | # |
| 36 | 25 | proc name_checkin {comment} { |
| 37 | - return [name_sql "SELECT uuid FROM event, blob | |
| 26 | + return [fossil_sql "SELECT uuid FROM event, blob | |
| 38 | 27 | WHERE objid=rid AND type='ci' AND comment='$comment'"] |
| 39 | 28 | } |
| 40 | 29 | |
| 41 | 30 | # Check in the checkout as it stands with COMMENT and DATE. ARGS are |
| 42 | 31 | # more options. Return the hash of the check-in. |
| @@ -64,11 +53,11 @@ | ||
| 64 | 53 | puts -nonewline $fd "Z $sum\n" |
| 65 | 54 | close $fd |
| 66 | 55 | fossil test-content-put --crosslink $fn |
| 67 | 56 | file delete $fn |
| 68 | 57 | 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"] | |
| 70 | 59 | } |
| 71 | 60 | |
| 72 | 61 | # The strings in WANTED that TEXT does not hold, and those that begin |
| 73 | 62 | # with "!" that it does hold. |
| 74 | 63 | # |
| @@ -105,11 +94,11 @@ | ||
| 105 | 94 | # 2025-01-06 b2 br, with c3 merged in |
| 106 | 95 | # 2025-01-07 b3 br |
| 107 | 96 | # |
| 108 | 97 | # The checkout is left at c2. |
| 109 | 98 | |
| 110 | -set nameC0 [name_sql "SELECT uuid FROM event, blob | |
| 99 | +set nameC0 [fossil_sql "SELECT uuid FROM event, blob | |
| 111 | 100 | WHERE objid=rid AND type='ci'"] |
| 112 | 101 | |
| 113 | 102 | # The hashes of p.txt and q.txt begin with the same five characters. |
| 114 | 103 | write_file f.txt "one\n" |
| 115 | 104 | write_file p.txt "name collide 1177\n" |
| @@ -153,11 +142,11 @@ | ||
| 153 | 142 | --user-override alice |
| 154 | 143 | fossil tag add gone $nameC1 --date-override "2025-01-08 11:00:00" \ |
| 155 | 144 | --user-override alice |
| 156 | 145 | fossil tag cancel gone $nameC1 --date-override "2025-01-08 12:00:00" \ |
| 157 | 146 | --user-override alice |
| 158 | -set nameG1 [name_sql "SELECT uuid FROM event, blob | |
| 147 | +set nameG1 [fossil_sql "SELECT uuid FROM event, blob | |
| 159 | 148 | WHERE objid=rid AND type='g' AND comment LIKE '%\"decade\"%'"] |
| 160 | 149 | |
| 161 | 150 | test name-setup-checkins {[llength [lsort -unique [list $nameC0 $nameC1 \ |
| 162 | 151 | $nameC2 $nameC3 $nameB1 $nameB2 $nameB3 $nameG1]]] == 8 |
| 163 | 152 | && [string length $nameG1] == 64} |
| @@ -324,13 +313,13 @@ | ||
| 324 | 313 | $nameGhostMember]] "\nM "]\n"] |
| 325 | 314 | |
| 326 | 315 | test name-setup-more {[llength [lsort -unique [list $namePriv $nameA1 \ |
| 327 | 316 | $nameA2 $nameW3 $nameSide $nameG2 $nameCluster $nameAtt1 $nameAtt2]]] == 9 |
| 328 | 317 | && [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} | |
| 332 | 321 | |
| 333 | 322 | test name-setup-artifacts {[llength [lsort -unique [list $nameW1 $nameW2 \ |
| 334 | 323 | $nameT1 $nameT2 $nameE1 $nameE2 $nameF1]]] == 7 |
| 335 | 324 | && [string length $nameF1] == 64} |
| 336 | 325 | |
| @@ -343,11 +332,12 @@ | ||
| 343 | 332 | tip-wiki tip w {ERROR: cannot resolve name: tip} \ |
| 344 | 333 | current current {} $nameC2 \ |
| 345 | 334 | prev prev {} $nameC1 \ |
| 346 | 335 | previous previous ci $nameC1 \ |
| 347 | 336 | next next {} $nameC3 \ |
| 348 | - current-wiki current w {ERROR: cannot resolve name: current} \ | |
| 337 | + current-wiki current w \ | |
| 338 | + {ERROR: cannot resolve name: current} \ | |
| 349 | 339 | ckout ckout ci+ $nameC2 \ |
| 350 | 340 | ckout-ci ckout ci {ERROR: cannot resolve name: ckout} \ |
| 351 | 341 | ckout-any ckout {} {ERROR: cannot resolve name: ckout} \ |
| 352 | 342 | current-ciplus current ci+ $nameC2 \ |
| 353 | 343 | trunk-ciplus trunk ci+ $nameC3 \ |
| @@ -358,11 +348,12 @@ | ||
| 358 | 348 | tag-prefix tag:rel1 {} $nameC1 \ |
| 359 | 349 | tag-hex decade {} $nameC1 \ |
| 360 | 350 | tag-hex-prefix tag:decade {} $nameC1 \ |
| 361 | 351 | tag-start tag:br br $nameB1 \ |
| 362 | 352 | 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} \ | |
| 364 | 355 | tag-empty tag: {} {ERROR: cannot resolve name: tag:} \ |
| 365 | 356 | tag-percent tag:% {} {ERROR: cannot resolve name: tag:%} \ |
| 366 | 357 | tag-underscore re_1 {} {ERROR: cannot resolve name: re_1} \ |
| 367 | 358 | tag-star rel* {} {ERROR: cannot resolve name: rel*} \ |
| 368 | 359 | tag-wiki-type rel1 w {ERROR: cannot resolve name: rel1} \ |
| @@ -374,17 +365,24 @@ | ||
| 374 | 365 | merge-in-trunk merge-in:trunk {} $nameC3 \ |
| 375 | 366 | root-first root:$nameC0 {} $nameC0 \ |
| 376 | 367 | merge-in-first merge-in:$nameC0 {} $nameC0 \ |
| 377 | 368 | merge-in-plain merge-in:$nameB1 {} $nameC2 \ |
| 378 | 369 | 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} \ | |
| 382 | 376 | root-empty root: {} {ERROR: cannot resolve name: root:} \ |
| 383 | 377 | ] { |
| 384 | 378 | test_eq name-checkin-$nameCase [name_id $nameName $nameType] $nameWant |
| 385 | 379 | } |
| 380 | + | |
| 381 | +if {[test_assurance] ne "stress"} { | |
| 382 | + test_skip "the tests after the first sections need -assurance stress" | |
| 383 | +} | |
| 386 | 384 | |
| 387 | 385 | ############################################################################### |
| 388 | 386 | # Dates. The timeline of the repository is in UTC. A date names the |
| 389 | 387 | # latest artifact of the wanted kind at or before the end of the day, |
| 390 | 388 | # minute, second or millisecond given. |
| @@ -478,11 +476,10 @@ | ||
| 478 | 476 | ############################################################################### |
| 479 | 477 | # Hashes and their beginnings, tags that look like hashes, record |
| 480 | 478 | # numbers, and names with punctuation after them. |
| 481 | 479 | |
| 482 | 480 | set nameC1x [string range $nameC1 0 9] |
| 483 | -set nameNone {ERROR: cannot resolve name: } | |
| 484 | 481 | set nameTwice {ERROR: ambiguous name: } |
| 485 | 482 | foreach {nameCase nameName nameType nameWant} [list \ |
| 486 | 483 | full $nameC1 {} $nameC1 \ |
| 487 | 484 | prefix $nameC1x {} $nameC1 \ |
| 488 | 485 | upper [string toupper $nameC1x] {} $nameC1 \ |
| @@ -508,11 +505,10 @@ | ||
| 508 | 505 | ticket [string range $nameT1 0 9] t $nameT1 \ |
| 509 | 506 | technote [string range $nameE1 0 9] e $nameE1 \ |
| 510 | 507 | forum [string range $nameF1 0 9] f $nameF1 \ |
| 511 | 508 | tag-change [string range $nameG1 0 9] g $nameG1 \ |
| 512 | 509 | tag-change-ci [string range $nameG1 0 9] ci - \ |
| 513 | - empty-type $nameC1x "" $nameC1 \ | |
| 514 | 510 | type-cx $nameC1x cx - \ |
| 515 | 511 | tip-type-cx tip cx - \ |
| 516 | 512 | rid rid:1 {} $nameC0 \ |
| 517 | 513 | rid-ci rid:1 ci $nameC0 \ |
| 518 | 514 | rid-wiki rid:1 w - \ |
| @@ -537,11 +533,11 @@ | ||
| 537 | 533 | dash - {} - \ |
| 538 | 534 | long [string repeat x 5000] {} - \ |
| 539 | 535 | long-colons [string repeat : 5000] {} - \ |
| 540 | 536 | long-date date:[string repeat 9 5000] {} - \ |
| 541 | 537 | ] { |
| 542 | - if {$nameWant eq "-"} { set nameWant $nameNone$nameName } | |
| 538 | + if {$nameWant eq "-"} { set nameWant $nameNoDate$nameName } | |
| 543 | 539 | if {$nameWant eq "="} { set nameWant $nameTwice$nameName } |
| 544 | 540 | test_eq name-hash-$nameCase [name_id $nameName $nameType] $nameWant |
| 545 | 541 | } |
| 546 | 542 | |
| 547 | 543 | ############################################################################### |
| @@ -557,20 +553,20 @@ | ||
| 557 | 553 | } |
| 558 | 554 | |
| 559 | 555 | fossil whatis tip |
| 560 | 556 | test_eq name-whatis-checkin $RESULT "name: tip |
| 561 | 557 | 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 | |
| 563 | 559 | tags: br |
| 564 | 560 | type: Check-in by alice on 2025-01-07 10:00:00 |
| 565 | 561 | comment: b3" |
| 566 | 562 | fossil whatis -h tip |
| 567 | 563 | test_eq name-whatis-hash-only $RESULT $nameB3 |
| 568 | 564 | fossil whatis -v -h tip |
| 569 | 565 | test_eq name-whatis-hash-only-verbose $RESULT $nameB3 |
| 570 | 566 | |
| 571 | -set nameRidC1 [name_sql "SELECT rid FROM blob WHERE uuid='$nameC1'"] | |
| 567 | +set nameRidC1 [fossil_sql "SELECT rid FROM blob WHERE uuid='$nameC1'"] | |
| 572 | 568 | name_whatis verbose [list "artifact: $nameC1 ($nameRidC1)" \ |
| 573 | 569 | "received: " "tags: decade, rel, rel1, trunk"] -v rel1 |
| 574 | 570 | name_whatis raw-tags [list "tags: twins" "closed, hidden" \ |
| 575 | 571 | "Check-in by alice on 2025-01-06 13:00:00"] $nameCa |
| 576 | 572 | name_whatis private [list "tags: private" "comment: hidden"] $namePriv |
| @@ -583,18 +579,18 @@ | ||
| 583 | 579 | name_whatis ticket-change [list "type: Ticket-change by alice on" \ |
| 584 | 580 | "ticket-id: $nameTktLike"] $nameT1 |
| 585 | 581 | name_whatis file [list "file: p.txt" \ |
| 586 | 582 | "part of \[[string range $nameC1 0 9]\] on branch trunk by alice on"] $nameP |
| 587 | 583 | 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 | |
| 589 | 585 | WHERE rid=fid AND mid=(SELECT rid FROM blob WHERE uuid='$nameB1')"] |
| 590 | 586 | name_whatis attachment-wiki [list "attachment: att1.txt" \ |
| 591 | 587 | "attached to wiki WikiOne" "via $nameA1\n" \ |
| 592 | 588 | "by user alice on 2025-01-13 10:00:00" "on the page"] $nameAtt1 |
| 593 | 589 | name_whatis attachment-ticket [list "attachment: att2.txt" \ |
| 594 | 590 | "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'"])"] \ | |
| 596 | 592 | -v $nameAtt2 |
| 597 | 593 | name_whatis cluster [list "artifact: $nameCluster" "cluster"] $nameCluster |
| 598 | 594 | name_whatis sha1-name [list "hash: $nameSha1 (ambiguous)" \ |
| 599 | 595 | "artifact: $nameSha1" "artifact: $nameT3"] $nameSha1 |
| 600 | 596 | |
| @@ -644,11 +640,12 @@ | ||
| 644 | 640 | # The file named, not the artifact named. |
| 645 | 641 | name_whatis by-file [list "name: f.txt" "file: f.txt" \ |
| 646 | 642 | "on branch trunk"] -f f.txt |
| 647 | 643 | name_whatis by-file-unknown [list "name: name.fossil" "unknown: "] \ |
| 648 | 644 | -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)" \ | |
| 650 | 647 | "artifact: $nameSha1" "artifact: $nameT3"] -f sha1.txt |
| 651 | 648 | name_whatis by-file-twin [list "name: p.txt" "artifact: $nameP" \ |
| 652 | 649 | "!ambiguous"] -f p.txt |
| 653 | 650 | fossil whatis -f nosuchfile -expectError |
| 654 | 651 | test name-whatis-by-file-missing {[string match "*no such file*" $RESULT]} |
| @@ -704,18 +701,19 @@ | ||
| 704 | 701 | [list "\"comment\":\"b3\"\}\n[string repeat - 79]\n\{\"unknown\""] \ |
| 705 | 702 | ] { |
| 706 | 703 | name_whatis json-$nameCase $nameWant --json {*}$nameArgs |
| 707 | 704 | } |
| 708 | 705 | |
| 709 | -test_eq name-whatis-sql-name [name_sql "SELECT whatis('nosuch')"] \ | |
| 706 | +test_eq name-whatis-sql-name [fossil_sql "SELECT whatis('nosuch')"] \ | |
| 710 | 707 | "\{\"unknown\":\"nosuch\"\}" |
| 711 | 708 | 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)"] \ | |
| 715 | 713 | "\{\"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 | |
| 717 | 715 | |
| 718 | 716 | ############################################################################### |
| 719 | 717 | # Other commands that take a name. |
| 720 | 718 | |
| 721 | 719 | fossil test-name-to-id --type ci $nameCtwin |
| @@ -788,13 +786,19 @@ | ||
| 788 | 786 | |
| 789 | 787 | # One line for each artifact. |
| 790 | 788 | fossil test-describe-artifacts |
| 791 | 789 | set nameAll $RESULT |
| 792 | 790 | 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)"] ""] \ | |
| 796 | 800 | " [string range $nameP 0 15] file p.txt " \ |
| 797 | 801 | " [string range $nameG1 0 15] tag [string range $nameC1 0 15] " \ |
| 798 | 802 | " [string range $nameCluster 0 15] cluster " \ |
| 799 | 803 | " [string range $nameT1 0 15] ticket [string range $nameTktLike 0 20] " \ |
| 800 | 804 | " [string range $nameW3 0 15] wiki \"Orphan\" " \ |
| @@ -804,14 +808,18 @@ | ||
| 804 | 808 | " [string range $nameF1 0 15] forum-post [string range $nameF1 0 13] " \ |
| 805 | 809 | " [string range $nameSha1 0 15] unknown " \ |
| 806 | 810 | " [string range $nameGhostParent 0 15] parent of check-in $nameW3" \ |
| 807 | 811 | " [string range $nameGhostMerge 0 15] merge parent of check-in $nameSide" \ |
| 808 | 812 | " [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"] ""]]] {} | |
| 811 | 819 | test_eq name-command-describe-count [llength [split $nameAll \n]] \ |
| 812 | - [name_sql "SELECT count(*) FROM blob"] | |
| 820 | + [fossil_sql "SELECT count(*) FROM blob"] | |
| 813 | 821 | fossil test-describe-artifacts --from 3 --count 2 |
| 814 | 822 | test_eq name-command-describe-range [llength [split $RESULT \n]] 2 |
| 815 | 823 | fossil test-unsent |
| 816 | 824 | test name-command-unsent {[holds_strings $RESULT [list \ |
| 817 | 825 | " [string range $nameC1 0 15] check-in to trunk" \ |
| @@ -837,11 +845,11 @@ | ||
| 837 | 845 | fossil test-whatis-all |
| 838 | 846 | test name-command-whatis-all {[holds_strings $RESULT [list \ |
| 839 | 847 | "artifact: $nameC0 (1)" "artifact: $nameF1 (" \ |
| 840 | 848 | "file: q.txt" [string repeat - 79]]] |
| 841 | 849 | && [regexp -all {artifact: } $RESULT] |
| 842 | - == [name_sql "SELECT count(*) FROM blob WHERE size>=0"]} | |
| 850 | + == [fossil_sql "SELECT count(*) FROM blob WHERE size>=0"]} | |
| 843 | 851 | |
| 844 | 852 | # A repository with no phantoms. |
| 845 | 853 | fossil new nophantom.fossil |
| 846 | 854 | fossil test-phantoms -R nophantom.fossil --count |
| 847 | 855 | test_eq name-command-phantoms-count-none $RESULT "" |
| @@ -865,15 +873,11 @@ | ||
| 865 | 873 | lappend options --localauth |
| 866 | 874 | } elseif {$caps ne $nameCapsNow} { |
| 867 | 875 | fossil sql -R $nameWeb "UPDATE user SET cap='$caps' WHERE login='nobody'" |
| 868 | 876 | set nameCapsNow $caps |
| 869 | 877 | } |
| 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] | |
| 875 | 879 | } |
| 876 | 880 | |
| 877 | 881 | # Test NAME passes if the reply to a request for PATH holds every string |
| 878 | 882 | # in WANTED and none of those that begin with "!". |
| 879 | 883 | # |
| @@ -989,11 +993,12 @@ | ||
| 989 | 993 | "!occurring around"] admin |
| 990 | 994 | name_page timeline-back-to /timeline?p=tip&bt=rel1 [list "HTTP/1.0 200 OK" \ |
| 991 | 995 | c2 "!initial empty check-in"] admin |
| 992 | 996 | name_page timeline-back-to-tag /timeline?p=tip&bt=tag:rel1 [list \ |
| 993 | 997 | "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]" \ | |
| 995 | 1000 | [list "HTTP/1.0 200 OK" b1 "!>c1<"] admin |
| 996 | 1001 | name_page timeline-forward-to /timeline?d=rel1&ft=br [list "HTTP/1.0 200 OK" \ |
| 997 | 1002 | "descendants of" ">br</a>"] admin |
| 998 | 1003 | name_page timeline-forward-to-tag /timeline?d=rel1&ft=tag:br [list \ |
| 999 | 1004 | "HTTP/1.0 200 OK" "descendants of" ">tag:br</a>"] admin |
| @@ -1009,12 +1014,12 @@ | ||
| 1009 | 1014 | |
| 1010 | 1015 | ############################################################################### |
| 1011 | 1016 | # Pages that list artifacts. |
| 1012 | 1017 | |
| 1013 | 1018 | 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"] | |
| 1016 | 1021 | |
| 1017 | 1022 | # What each kind of user is shown. |
| 1018 | 1023 | foreach {nameCase namePath nameCaps nameWant} [list \ |
| 1019 | 1024 | bloblist-admin /bloblist admin \ |
| 1020 | 1025 | [list "HTTP/1.0 200 OK" $nameHead \ |
| @@ -1045,20 +1050,22 @@ | ||
| 1045 | 1050 | "<a href=\"/bloblist?s=1&n=10\">\n1..10</a>" \ |
| 1046 | 1051 | "<a href=\"/bloblist?s=11&n=10\">\n11..20</a>" \ |
| 1047 | 1052 | "..$nameRidMax</a>" "250 most recent</a>" "All unclustered</a>" \ |
| 1048 | 1053 | "!$nameHead" "!href=\"bloblist\">"] \ |
| 1049 | 1054 | 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>" \ | |
| 1051 | 1057 | "!<td align=\"right\">10</td>" "!<td align=\"right\">21</td>" \ |
| 1052 | 1058 | "href=\"bloblist\">"] \ |
| 1053 | 1059 | bloblist-private /bloblist?priv admin \ |
| 1054 | 1060 | [list "<h2>Private Artifacts</h2>" "check-in to private" "file h.txt" \ |
| 1055 | 1061 | "!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?priv\">"] \ |
| 1056 | 1062 | bloblist-private-short /bloblist?priv&n=10 admin \ |
| 1057 | 1063 | [list "<h2>Private Artifacts</h2>" "!Select a range"] \ |
| 1058 | 1064 | 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>" \ | |
| 1060 | 1067 | "<a href=\"/info/[string range $nameW3 0 15]\">" \ |
| 1061 | 1068 | "<td align=\"left\">file lost.txt</td>\n<td> \n<td> \n</tr>" \ |
| 1062 | 1069 | "!check-in to trunk" "href=\"bloblist\">" "!href=\"bloblist?phan\">"] \ |
| 1063 | 1070 | bloblist-phantoms-short /bloblist?phan&n=10 admin \ |
| 1064 | 1071 | [list "<h2>Phantom Artifacts</h2>" "!Select a range"] \ |
| @@ -1114,21 +1121,27 @@ | ||
| 1114 | 1121 | [list "Delta Chain Containing Artifact 0"] \ |
| 1115 | 1122 | delta-chain-no-read /deltachain/1 {} \ |
| 1116 | 1123 | [list "HTTP/1.0 302 Moved Temporarily" "/login?g=deltachain"] \ |
| 1117 | 1124 | collisions /hash-collisions admin \ |
| 1118 | 1125 | [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>"] ""] \ | |
| 1120 | 1129 | "<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>"] ""] \ | |
| 1122 | 1133 | "<a href=\"/ambiguous/$nameWtwin\">$nameWtwin</a>" \ |
| 1123 | 1134 | "<p>Total number of hashes: [expr {$nameRidMax}]</p>" \ |
| 1124 | 1135 | "!First 25 collisions"] \ |
| 1125 | 1136 | collisions-no-read /hash-collisions {} \ |
| 1126 | 1137 | [list "HTTP/1.0 302 Moved Temporarily" "/login?g=hash-collisions"] \ |
| 1127 | 1138 | clusters-admin /clusterlist admin \ |
| 1128 | 1139 | [list "<th>Compressed 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]\">"] ""] \ | |
| 1130 | 1143 | "<td>alice\n<td> \n</tr>" "Total size of all clusters: " \ |
| 1131 | 1144 | "href=\"rcvfromlist\">" "href=\"artifact_stats\">"] \ |
| 1132 | 1145 | clusters-reader /clusterlist gjorz \ |
| 1133 | 1146 | [list "<th>Compressed Size\n<tr>" "!<td>alice" \ |
| 1134 | 1147 | "!href=\"rcvfromlist\">" "!href=\"artifact_stats\">"] \ |
| 1135 | 1148 |
| --- 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&n=10\">\n1..10</a>" \ |
| 1046 | "<a href=\"/bloblist?s=11&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> \n<td> \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 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> \n</tr>" "Total size of all clusters: " \ |
| 1131 | "href=\"rcvfromlist\">" "href=\"artifact_stats\">"] \ |
| 1132 | clusters-reader /clusterlist gjorz \ |
| 1133 | [list "<th>Compressed 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&n=10\">\n1..10</a>" \ |
| 1051 | "<a href=\"/bloblist?s=11&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> \n<td> \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 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> \n</tr>" "Total size of all clusters: " \ |
| 1144 | "href=\"rcvfromlist\">" "href=\"artifact_stats\">"] \ |
| 1145 | clusters-reader /clusterlist gjorz \ |
| 1146 | [list "<th>Compressed Size\n<tr>" "!<td>alice" \ |
| 1147 | "!href=\"rcvfromlist\">" "!href=\"artifact_stats\">"] \ |
| 1148 |
+72
-131
| --- test/purge.test | ||
| +++ test/purge.test | ||
| @@ -3,90 +3,26 @@ | ||
| 3 | 3 | # its graveyard, undo and obliterate, and "fossil scrub". After each the |
| 4 | 4 | # repository must still be sound, and an undo must give back exactly what |
| 5 | 5 | # was removed. |
| 6 | 6 | # |
| 7 | 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 | - | |
| 8 | +# The first sections run at every level, and the rest need | |
| 9 | +# -assurance stress. | |
| 13 | 10 | require_no_open_checkout |
| 14 | 11 | |
| 15 | 12 | test_setup |
| 16 | 13 | |
| 17 | 14 | 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] | |
| 80 | 16 | } |
| 81 | 17 | |
| 82 | 18 | proc purge_commit {file content comment args} { |
| 83 | 19 | set new [expr {![file exists $file]}] |
| 84 | 20 | write_file $file $content |
| 85 | 21 | if {$new} {fossil add $file} |
| 86 | 22 | fossil commit -m $comment --no-warnings {*}$args |
| 87 | - return [purge_hash $comment] | |
| 23 | + return [checkin_hash $comment] | |
| 88 | 24 | } |
| 89 | 25 | |
| 90 | 26 | # The number of the newest purge event. |
| 91 | 27 | proc purge_last_event {{repo .rep.fossil}} { |
| 92 | 28 | return [purge_sql "SELECT max(peid) FROM purgeevent" $repo] |
| @@ -96,11 +32,11 @@ | ||
| 96 | 32 | return [purge_sql "SELECT count(*) FROM blob WHERE uuid='$hash' |
| 97 | 33 | AND size>=0" $repo] |
| 98 | 34 | } |
| 99 | 35 | |
| 100 | 36 | # 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 | |
| 102 | 38 | # shows a link to the wrong artifact. |
| 103 | 39 | proc purge_dangling {repo} { |
| 104 | 40 | return [purge_sql "SELECT (SELECT count(*) FROM mlink |
| 105 | 41 | WHERE fid>0 AND fid NOT IN (SELECT rid FROM blob)) |
| 106 | 42 | + (SELECT count(*) FROM plink |
| @@ -128,25 +64,25 @@ | ||
| 128 | 64 | fossil branch new side current |
| 129 | 65 | fossil update side |
| 130 | 66 | set purgeSide1 [purge_commit a.txt "${purgeTrunkText(3)}on the side\n" \ |
| 131 | 67 | purge-side-1] |
| 132 | 68 | 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] | |
| 134 | 70 | fossil update trunk |
| 135 | 71 | |
| 136 | -purge_sound purge-start | |
| 137 | -set purgeStart [purge_state] | |
| 72 | +repository_sound purge-start | |
| 73 | +set purgeStart [repository_state] | |
| 138 | 74 | file copy .rep.fossil full.fossil |
| 139 | 75 | |
| 140 | 76 | ############################################################################### |
| 141 | 77 | # A trial run changes nothing. |
| 142 | 78 | |
| 143 | 79 | fossil purge checkins side --explain |
| 144 | 80 | 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 | |
| 146 | 82 | 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 | |
| 148 | 84 | |
| 149 | 85 | # Either option may be given twice, or both together, with the same result. |
| 150 | 86 | foreach {purgeName purgeArgs} { |
| 151 | 87 | explain-twice {--explain --explain} |
| 152 | 88 | explain-dry {--explain --dry-run} |
| @@ -153,11 +89,11 @@ | ||
| 153 | 89 | dry-twice {--dry-run --dry-run} |
| 154 | 90 | } { |
| 155 | 91 | fossil_raw purge checkins side {*}$purgeArgs |
| 156 | 92 | test purge-$purgeName {$CODE == 0 && |
| 157 | 93 | [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 | |
| 159 | 95 | } |
| 160 | 96 | fossil purge list |
| 161 | 97 | test_eq purge-explain-no-graveyard [string trim $RESULT] "" |
| 162 | 98 | |
| 163 | 99 | ############################################################################### |
| @@ -171,11 +107,11 @@ | ||
| 171 | 107 | WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')"] 0 |
| 172 | 108 | test_eq purge-checkins-no-event [purge_sql "SELECT count(*) FROM event |
| 173 | 109 | WHERE comment LIKE 'purge-side-%'"] 0 |
| 174 | 110 | test_eq purge-checkins-trunk-kept [purge_sql "SELECT count(*) FROM event |
| 175 | 111 | WHERE comment LIKE 'purge-trunk-%'"] 5 |
| 176 | -purge_sound purge-checkins | |
| 112 | +repository_sound purge-checkins | |
| 177 | 113 | for {set purgeI 1} {$purgeI <= 5} {incr purgeI} { |
| 178 | 114 | fossil cat a.txt -r [lindex $purgeTrunk [expr {$purgeI-1}]] |
| 179 | 115 | test_eq purge-checkins-trunk-$purgeI "$RESULT\n" $purgeTrunkText($purgeI) |
| 180 | 116 | } |
| 181 | 117 | set purgeEvent [purge_last_event] |
| @@ -194,23 +130,24 @@ | ||
| 194 | 130 | fossil purge cat [purge_sql "SELECT uuid FROM purgeitem |
| 195 | 131 | WHERE srcid IS NOT NULL LIMIT 1"] |
| 196 | 132 | test purge-cat-delta {$CODE == 0} |
| 197 | 133 | |
| 198 | 134 | # A trial run of the undo restores nothing and keeps the purge. |
| 199 | -set purgeBefore [purge_state] | |
| 135 | +set purgeBefore [repository_state] | |
| 200 | 136 | fossil purge undo $purgeEvent --explain |
| 201 | 137 | 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 | |
| 203 | 139 | test_eq purge-undo-explain-event-kept [purge_last_event] $purgeEvent |
| 204 | 140 | fossil purge undo $purgeEvent --dry-run |
| 205 | 141 | test_eq purge-undo-dry-run-event-kept [purge_last_event] $purgeEvent |
| 206 | 142 | |
| 207 | 143 | # Undo gives back exactly what was there. |
| 208 | 144 | fossil purge undo $purgeEvent |
| 209 | 145 | 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 | |
| 212 | 149 | fossil purge list |
| 213 | 150 | test_eq purge-undo-graveyard-empty [string trim $RESULT] "" |
| 214 | 151 | fossil cat b.txt -r $purgeSide2 |
| 215 | 152 | test_eq purge-undo-content [string trim $RESULT] "a file only the branch has" |
| 216 | 153 | |
| @@ -265,11 +202,11 @@ | ||
| 265 | 202 | test purge-current-checkout-link {$CODE != 0 && |
| 266 | 203 | [string match "*cannot purge the current check-out*" $RESULT]} |
| 267 | 204 | file delete link.fossil |
| 268 | 205 | } |
| 269 | 206 | 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 | |
| 271 | 208 | |
| 272 | 209 | fossil purge cat [string repeat 0 40] -expectError |
| 273 | 210 | test purge-cat-missing {$CODE != 0} |
| 274 | 211 | fossil purge tickets x -expectError |
| 275 | 212 | test purge-tickets-not-implemented {$CODE != 0} |
| @@ -289,19 +226,23 @@ | ||
| 289 | 226 | } { |
| 290 | 227 | fossil purge {*}$purgeArgs -expectError |
| 291 | 228 | test purge-usage-$purgeName {$CODE != 0 && |
| 292 | 229 | [string match "*Usage:*" $RESULT]} |
| 293 | 230 | } |
| 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 | +} | |
| 295 | 236 | |
| 296 | 237 | ############################################################################### |
| 297 | 238 | # Purging one file version that a kept version is a delta of, on a copy. |
| 298 | 239 | # The kept version is stored whole first and can still be read. |
| 299 | 240 | |
| 300 | 241 | 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] | |
| 303 | 244 | test purge-delta-setup {[purge_sql "SELECT count(*) FROM delta |
| 304 | 245 | WHERE srcid=(SELECT rid FROM blob WHERE uuid='$purgeV3')" p1.fossil] > 0} |
| 305 | 246 | fossil purge artifacts $purgeV3 -R p1.fossil |
| 306 | 247 | test purge-artifact {$CODE == 0} |
| 307 | 248 | test_eq purge-artifact-gone [purge_has p1.fossil $purgeV3] 0 |
| @@ -319,15 +260,15 @@ | ||
| 319 | 260 | fossil purge undo [purge_last_event p1.fossil] -R p1.fossil |
| 320 | 261 | test purge-artifact-undo {$CODE == 0} |
| 321 | 262 | test_eq purge-artifact-undo-back [purge_has p1.fossil $purgeV3] 1 |
| 322 | 263 | test_eq purge-artifact-undo-links [purge_dangling p1.fossil] 0 |
| 323 | 264 | 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 | |
| 326 | 267 | fossil rebuild p1.fossil |
| 327 | 268 | test_eq purge-artifact-rebuild-state \ |
| 328 | - [purge_diff $purgeStart [purge_state p1.fossil]] "" | |
| 269 | + [repository_state_diff $purgeStart [repository_state p1.fossil]] "" | |
| 329 | 270 | |
| 330 | 271 | # Every version of a file, by name, on another copy. |
| 331 | 272 | file copy full.fossil p2.fossil |
| 332 | 273 | fossil purge files a.txt -R p2.fossil |
| 333 | 274 | test purge-files {$CODE == 0} |
| @@ -338,11 +279,11 @@ | ||
| 338 | 279 | test_eq purge-files-undo-back [purge_sql "SELECT count(*) FROM blob |
| 339 | 280 | WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 2 |
| 340 | 281 | test_eq purge-files-undo-links [purge_dangling p2.fossil] 0 |
| 341 | 282 | fossil rebuild p2.fossil |
| 342 | 283 | test_eq purge-files-rebuild-state \ |
| 343 | - [purge_diff $purgeStart [purge_state p2.fossil]] "" | |
| 284 | + [repository_state_diff $purgeStart [repository_state p2.fossil]] "" | |
| 344 | 285 | |
| 345 | 286 | # Purging check-ins takes a repository named with -R, as every command |
| 346 | 287 | # can. |
| 347 | 288 | file copy full.fossil p3.fossil |
| 348 | 289 | fossil_raw purge checkins side --explain -R p3.fossil |
| @@ -375,31 +316,31 @@ | ||
| 375 | 316 | [string match "*purge-trunk-5*" $RESULT] && |
| 376 | 317 | ![string match "*purge-trunk-4*" $RESULT]} |
| 377 | 318 | fossil purge undo [purge_last_event p4.fossil] -R p4.fossil |
| 378 | 319 | test purge-middle-undo {$CODE == 0} |
| 379 | 320 | 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 | |
| 382 | 323 | |
| 383 | 324 | # A ticket change. The ticket goes with its only change and comes back |
| 384 | 325 | # with the undo. |
| 385 | 326 | fossil ticket add title "a ticket to purge" status Open -R p4.fossil |
| 386 | 327 | set purgeTicket [purge_sql "SELECT uuid FROM blob |
| 387 | 328 | WHERE rid=(SELECT tkt_rid FROM ticketchng)" p4.fossil] |
| 388 | 329 | test purge-ticket-setup {[purge_sql "SELECT count(*) FROM ticket |
| 389 | 330 | WHERE title='a ticket to purge'" p4.fossil] == 1} |
| 390 | -set purgeBefore [purge_state p4.fossil] | |
| 331 | +set purgeBefore [repository_state p4.fossil] | |
| 391 | 332 | fossil purge artifacts $purgeTicket -R p4.fossil |
| 392 | 333 | test purge-ticket {$CODE == 0} |
| 393 | 334 | test_eq purge-ticket-gone [purge_sql "SELECT (SELECT count(*) FROM ticket) |
| 394 | 335 | + (SELECT count(*) FROM ticketchng)" p4.fossil] 0 |
| 395 | 336 | fossil purge undo [purge_last_event p4.fossil] -R p4.fossil |
| 396 | 337 | test purge-ticket-undo {$CODE == 0} |
| 397 | 338 | test_eq purge-ticket-undo-back [purge_sql "SELECT count(*) FROM ticket |
| 398 | 339 | WHERE title='a ticket to purge'" p4.fossil] 1 |
| 399 | 340 | test_eq purge-ticket-undo-state \ |
| 400 | - [purge_diff $purgeBefore [purge_state p4.fossil]] "" | |
| 341 | + [repository_state_diff $purgeBefore [repository_state p4.fossil]] "" | |
| 401 | 342 | |
| 402 | 343 | # A repository whose plink table has no baseid column, as one made before |
| 403 | 344 | # the 2014-11-28 schema change that was never rebuilt; the column is |
| 404 | 345 | # dropped here with SQL. A purge works on it; a rebuild adds the column, |
| 405 | 346 | # and the undo then restores what was purged. |
| @@ -412,12 +353,12 @@ | ||
| 412 | 353 | test purge-old-plink-rebuild {$CODE == 0} |
| 413 | 354 | fossil purge undo [purge_last_event p6.fossil] -R p6.fossil |
| 414 | 355 | test purge-old-plink-undo {$CODE == 0} |
| 415 | 356 | test_eq purge-old-plink-undo-back [purge_has p6.fossil $purgeMiddle] 1 |
| 416 | 357 | 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 | |
| 419 | 360 | |
| 420 | 361 | # "fossil bundle purge" removes the check-ins of a bundle without a |
| 421 | 362 | # graveyard: there is no purge event, nothing is said about an undo, and |
| 422 | 363 | # importing the bundle brings the branch back. |
| 423 | 364 | file copy full.fossil p7.fossil |
| @@ -433,11 +374,11 @@ | ||
| 433 | 374 | fossil test-integrity -R p7.fossil |
| 434 | 375 | test purge-bundle-integrity {$CODE == 0} |
| 435 | 376 | fossil bundle import side.bundle --publish -R p7.fossil |
| 436 | 377 | test purge-bundle-import {$CODE == 0} |
| 437 | 378 | test_eq purge-bundle-import-state \ |
| 438 | - [purge_diff $purgeStart [purge_state p7.fossil]] "" | |
| 379 | + [repository_state_diff $purgeStart [repository_state p7.fossil]] "" | |
| 439 | 380 | |
| 440 | 381 | ############################################################################### |
| 441 | 382 | # A graveyard that has been damaged with SQL. Each command stops with a |
| 442 | 383 | # message and restores nothing. In source-loop two items name each other |
| 443 | 384 | # as delta source. In undo-record-zero the hash of an item is already in |
| @@ -482,15 +423,15 @@ | ||
| 482 | 423 | [list undo $purgeEvent8] \ |
| 483 | 424 | "*" \ |
| 484 | 425 | ] { |
| 485 | 426 | file copy -force p8.fossil damaged.fossil |
| 486 | 427 | fossil sql -R damaged.fossil $purgeDamage |
| 487 | - set purgeBefore [purge_state damaged.fossil] | |
| 428 | + set purgeBefore [repository_state damaged.fossil] | |
| 488 | 429 | fossil_raw purge {*}$purgeArgs -R damaged.fossil |
| 489 | 430 | test purge-damage-$purgeName {$CODE == 1 && |
| 490 | 431 | [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] \ | |
| 492 | 433 | $purgeBefore |
| 493 | 434 | test_eq purge-damage-$purgeName-event-kept \ |
| 494 | 435 | [purge_last_event damaged.fossil] $purgeEvent8 |
| 495 | 436 | } |
| 496 | 437 | |
| @@ -499,12 +440,12 @@ | ||
| 499 | 440 | fossil sql -R damaged.fossil "UPDATE purgeitem SET orid=NULL" |
| 500 | 441 | fossil purge undo $purgeEvent8 -R damaged.fossil |
| 501 | 442 | test purge-undo-no-record-number {$CODE == 0} |
| 502 | 443 | fossil rebuild damaged.fossil |
| 503 | 444 | 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 | |
| 506 | 447 | |
| 507 | 448 | # A check-in is purged and its child, which is kept, then loses its |
| 508 | 449 | # content. The undo restores the purged check-in and does not link the |
| 509 | 450 | # child to it. |
| 510 | 451 | file copy -force full.fossil damaged.fossil |
| @@ -515,11 +456,10 @@ | ||
| 515 | 456 | test purge-undo-child-without-content {$CODE == 0} |
| 516 | 457 | test_eq purge-undo-child-without-content-back \ |
| 517 | 458 | [purge_has damaged.fossil $purgeP] 1 |
| 518 | 459 | test_eq purge-undo-child-without-content-not-linked \ |
| 519 | 460 | [purge_parent_of damaged.fossil $purgeC] "" |
| 520 | -file delete damaged.fossil | |
| 521 | 461 | |
| 522 | 462 | ############################################################################### |
| 523 | 463 | # Obliterate. Asked first, unless --force; afterwards the purge cannot |
| 524 | 464 | # be undone. |
| 525 | 465 | |
| @@ -532,11 +472,11 @@ | ||
| 532 | 472 | [string match "*a file only the branch has*" $RESULT]} |
| 533 | 473 | test purge-cat-second-missing-named \ |
| 534 | 474 | {[string first [string repeat 0 40] $RESULT] >= 0} |
| 535 | 475 | |
| 536 | 476 | fossil_raw -input "n\n" purge obliterate $purgeEvent |
| 537 | -test purge-obliterate-declined {$CODE != 0} | |
| 477 | +test purge-obliterate-declined {$CODE == 1} | |
| 538 | 478 | test_eq purge-obliterate-declined-kept [purge_last_event] $purgeEvent |
| 539 | 479 | fossil_raw -input "y\n" purge obliterate $purgeEvent |
| 540 | 480 | test purge-obliterate {$CODE == 0} |
| 541 | 481 | test_eq purge-obliterate-gone [purge_sql "SELECT count(*) FROM purgeitem"] 0 |
| 542 | 482 | # A capital Y is a yes too. |
| @@ -547,18 +487,18 @@ | ||
| 547 | 487 | test_eq purge-obliterate-capital-gone [purge_sql "SELECT count(*) |
| 548 | 488 | FROM purgeevent WHERE peid=$purgeEvent4" p4.fossil] 0 |
| 549 | 489 | fossil purge obliterate $purgeEvent --force -expectError |
| 550 | 490 | test purge-obliterate-again {$CODE != 0 && |
| 551 | 491 | [string match "*no such purge event*" $RESULT]} |
| 552 | -purge_sound purge-obliterate | |
| 492 | +repository_sound purge-obliterate | |
| 553 | 493 | |
| 554 | 494 | # An undo of a purge that does not exist is refused, as an obliterate of |
| 555 | 495 | # one is. |
| 556 | -set purgeBefore [purge_state] | |
| 496 | +set purgeBefore [repository_state] | |
| 557 | 497 | 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 | |
| 560 | 500 | |
| 561 | 501 | # A repository that has never had a purge has no graveyard tables. Undo |
| 562 | 502 | # and obliterate are refused there as for any unknown purge, the list is |
| 563 | 503 | # empty, and a scrub of private content has nothing to take from it. |
| 564 | 504 | fossil init nograve.fossil |
| @@ -586,12 +526,13 @@ | ||
| 586 | 526 | test purge-clone {$CODE == 0} |
| 587 | 527 | test_eq purge-clone-lacks [purge_sql "SELECT count(*) FROM blob |
| 588 | 528 | WHERE uuid='$purgeSide2'" c1.fossil] 0 |
| 589 | 529 | fossil pull [file join [pwd] full.fossil] |
| 590 | 530 | 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 | |
| 593 | 534 | |
| 594 | 535 | ############################################################################### |
| 595 | 536 | # Scrub. A private branch, a password and a purge in the graveyard, then |
| 596 | 537 | # each kind of scrub on its own copy. |
| 597 | 538 | |
| @@ -599,41 +540,37 @@ | ||
| 599 | 540 | for {set purgeI 0} {$purgeI < 60} {incr purgeI} { |
| 600 | 541 | append purgeSecretText "line $purgeI of private content\n" |
| 601 | 542 | } |
| 602 | 543 | set purgeSecret [purge_commit secret.txt $purgeSecretText purge-secret \ |
| 603 | 544 | --private --branch secret] |
| 604 | -set purgeSecretFile [purge_file_hash $purgeSecret secret.txt] | |
| 545 | +set purgeSecretFile [checkin_file_hash $purgeSecret secret.txt] | |
| 605 | 546 | fossil update trunk |
| 606 | 547 | fossil user new scrubuser [email protected] hunter2 |
| 607 | -fossil user password scrubuser hunter2 | |
| 608 | 548 | set purgePublic [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid |
| 609 | 549 | FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)"] |
| 610 | 550 | foreach purgeCopy {s1 s2 s3 s4 s5 s7} { |
| 611 | 551 | file copy .rep.fossil $purgeCopy.fossil |
| 612 | 552 | } |
| 613 | 553 | proc purge_public {repo} { |
| 614 | 554 | return [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid |
| 615 | 555 | FROM blob WHERE size>=0 AND rid NOT IN private ORDER BY uuid)" $repo] |
| 616 | 556 | } |
| 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 && | |
| 621 | 558 | [purge_has s1.fossil $purgeSecret] == 1} |
| 622 | 559 | |
| 623 | 560 | # Asked first; "n" changes nothing. |
| 624 | 561 | 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} | |
| 627 | 564 | |
| 628 | 565 | # By default only passwords go. |
| 629 | 566 | fossil scrub --force s1.fossil |
| 630 | 567 | 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 | |
| 632 | 569 | test_eq purge-scrub-keeps-private [purge_has s1.fossil $purgeSecret] 1 |
| 633 | 570 | 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 | |
| 635 | 572 | |
| 636 | 573 | # --private removes the private branch and nothing else. |
| 637 | 574 | fossil scrub --private --force s2.fossil |
| 638 | 575 | test purge-scrub-private {$CODE == 0} |
| 639 | 576 | test_eq purge-scrub-private-gone [purge_has s2.fossil $purgeSecret] 0 |
| @@ -641,12 +578,12 @@ | ||
| 641 | 578 | test_eq purge-scrub-private-none-left [purge_sql "SELECT count(*) |
| 642 | 579 | FROM private" s2.fossil] 0 |
| 643 | 580 | test_eq purge-scrub-private-no-event [purge_sql "SELECT count(*) FROM event |
| 644 | 581 | WHERE comment='purge-secret'" s2.fossil] 0 |
| 645 | 582 | 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 | |
| 648 | 585 | |
| 649 | 586 | # A private branch that was purged before the scrub is in the graveyard. |
| 650 | 587 | fossil purge artifacts $purgeSecret $purgeSecretFile -R s3.fossil |
| 651 | 588 | test purge-scrub-graveyard-setup {$CODE == 0 && |
| 652 | 589 | [purge_has s3.fossil $purgeSecret] == 0} |
| @@ -657,32 +594,33 @@ | ||
| 657 | 594 | # Undo, on a copy, gives the private branch back, still private. |
| 658 | 595 | file copy s3.fossil s8.fossil |
| 659 | 596 | fossil purge undo [purge_last_event s8.fossil] -R s8.fossil |
| 660 | 597 | test purge-undo-private {$CODE == 0} |
| 661 | 598 | 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]] "" | |
| 663 | 601 | test_eq purge-undo-private-still-private [purge_sql "SELECT count(*) |
| 664 | 602 | FROM private JOIN blob USING(rid) |
| 665 | 603 | WHERE uuid IN ('$purgeSecret','$purgeSecretFile')" s8.fossil] 2 |
| 666 | -purge_sound purge-undo-private s8.fossil | |
| 604 | +repository_sound purge-undo-private s8.fossil | |
| 667 | 605 | fossil scrub --private --force s3.fossil |
| 668 | 606 | test purge-scrub-graveyard {$CODE == 0} |
| 669 | 607 | # The private branch does not survive in the graveyard, so neither |
| 670 | 608 | # "purge cat" nor "purge undo" can bring it back. |
| 671 | 609 | test_eq purge-scrub-private-graveyard [purge_sql "SELECT count(*) |
| 672 | 610 | FROM purgeitem WHERE isPrivate" s3.fossil] 0 |
| 673 | 611 | 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} | |
| 675 | 613 | |
| 676 | 614 | # A public item in the graveyard that is stored as a delta from a private |
| 677 | 615 | # one is kept and can still be read. "fossil publish" leaves such deltas: |
| 678 | 616 | # the older version of a file is stored as a delta from the newer, and |
| 679 | 617 | # only the older is published. |
| 680 | 618 | fossil update secret |
| 681 | 619 | set purgeSecret2 [purge_commit secret.txt "${purgeSecretText}one more\n" \ |
| 682 | 620 | purge-secret-2] |
| 683 | -set purgeSecretFile2 [purge_file_hash $purgeSecret2 secret.txt] | |
| 621 | +set purgeSecretFile2 [checkin_file_hash $purgeSecret2 secret.txt] | |
| 684 | 622 | fossil update trunk |
| 685 | 623 | file copy .rep.fossil s6.fossil |
| 686 | 624 | fossil publish $purgeSecret -R s6.fossil |
| 687 | 625 | test purge-scrub-publish {$CODE == 0} |
| 688 | 626 | test purge-scrub-public-from-private {[purge_sql "SELECT count(*) FROM delta |
| @@ -704,13 +642,13 @@ | ||
| 704 | 642 | fossil purge artifacts $purgeSecret $purgeSecretFile -R s4.fossil |
| 705 | 643 | fossil scrub --verily --force s4.fossil |
| 706 | 644 | test purge-scrub-verily {$CODE == 0} |
| 707 | 645 | test_eq purge-scrub-verily-no-graveyard [purge_sql "SELECT count(*) |
| 708 | 646 | 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 | |
| 710 | 648 | 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 | |
| 712 | 650 | |
| 713 | 651 | # A scrubbed repository still clones. |
| 714 | 652 | fossil clone s2.fossil c2.fossil |
| 715 | 653 | test purge-scrub-clone {$CODE == 0} |
| 716 | 654 | test_eq purge-scrub-clone-public [purge_public c2.fossil] $purgePublic |
| @@ -718,14 +656,16 @@ | ||
| 718 | 656 | ############################################################################### |
| 719 | 657 | # repack changes how content is stored, never what it is. |
| 720 | 658 | |
| 721 | 659 | fossil repack s5.fossil |
| 722 | 660 | 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]] "" | |
| 724 | 664 | test_eq purge-repack-public [purge_public s5.fossil] $purgePublic |
| 725 | 665 | 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 | |
| 727 | 667 | |
| 728 | 668 | ############################################################################### |
| 729 | 669 | # A delta manifest names its baseline. A purge of the baseline alone is |
| 730 | 670 | # refused; with the delta manifest it goes through, and the undo restores |
| 731 | 671 | # both. |
| @@ -736,22 +676,23 @@ | ||
| 736 | 676 | purge-delta-manifest --delta] |
| 737 | 677 | test purge-baseline-setup {[purge_sql "SELECT count(*) FROM plink |
| 738 | 678 | WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeDeltaM') |
| 739 | 679 | AND baseid=(SELECT rid FROM blob WHERE uuid='$purgeBase')"] == 1} |
| 740 | 680 | fossil update [lindex $purgeTrunk 3] |
| 741 | -set purgeBefore [purge_state] | |
| 681 | +set purgeBefore [repository_state] | |
| 742 | 682 | fossil_raw purge artifacts $purgeBase |
| 743 | 683 | test purge-baseline-alone-refused {$CODE ne "0" && |
| 744 | 684 | [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 | |
| 746 | 686 | fossil purge artifacts $purgeBase $purgeDeltaM |
| 747 | 687 | test purge-baseline-with-delta {$CODE == 0} |
| 748 | 688 | test_eq purge-baseline-with-delta-gone [purge_sql "SELECT count(*) FROM blob |
| 749 | 689 | WHERE uuid IN ('$purgeBase','$purgeDeltaM')"] 0 |
| 750 | 690 | fossil purge undo [purge_last_event] |
| 751 | 691 | 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 | |
| 754 | 695 | |
| 755 | 696 | ############################################################################### |
| 756 | 697 | |
| 757 | 698 | test_cleanup |
| 758 | 699 |
| --- 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 @@ | ||
| 5 | 5 | # what a repository holds: after each, the artifacts, the timeline and the |
| 6 | 6 | # links between check-ins and files are compared with what was there |
| 7 | 7 | # before, and the repository must still be sound. |
| 8 | 8 | # |
| 9 | 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 | - | |
| 10 | +# The first sections run at every level, and the rest need | |
| 11 | +# -assurance stress. | |
| 15 | 12 | require_no_open_checkout |
| 16 | 13 | |
| 17 | 14 | test_setup |
| 18 | 15 | |
| 19 | 16 | 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] | |
| 80 | 18 | } |
| 81 | 19 | |
| 82 | 20 | # The hashes of the artifacts a repository has the content of, in order; |
| 83 | 21 | # WHERE narrows them. |
| 84 | 22 | proc rebuild_hashes {repo {where 1}} { |
| @@ -139,42 +77,38 @@ | ||
| 139 | 77 | append rebuildText "version $rebuildI\n" |
| 140 | 78 | write_file a.txt $rebuildText |
| 141 | 79 | write_file n.txt [rebuild_noise $rebuildI 1500] |
| 142 | 80 | if {$rebuildI == 1} {fossil add a.txt n.txt} |
| 143 | 81 | 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] | |
| 146 | 83 | } |
| 147 | 84 | fossil update [lindex $rebuildTrunk 2] |
| 148 | 85 | fossil branch new side current |
| 149 | 86 | 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] | |
| 154 | 89 | fossil update trunk |
| 155 | 90 | fossil tag add rebuild-tag [lindex $rebuildTrunk 1] |
| 156 | 91 | write_file page.txt "A wiki page.\n" |
| 157 | 92 | fossil wiki create RebuildPage page.txt |
| 158 | 93 | fossil ticket add title "a ticket" status Open |
| 159 | 94 | set rebuildSecretText "" |
| 160 | 95 | for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} { |
| 161 | 96 | append rebuildSecretText "line $rebuildI of private content\n" |
| 162 | 97 | } |
| 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] | |
| 167 | 101 | write_file secret.txt "${rebuildSecretText}one more\n" |
| 168 | 102 | 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] | |
| 172 | 106 | fossil update trunk |
| 173 | 107 | |
| 174 | -rebuild_sound rebuild-start | |
| 175 | -set rebuildStart [rebuild_state] | |
| 108 | +repository_sound rebuild-start | |
| 109 | +set rebuildStart [repository_state] | |
| 176 | 110 | set rebuildAll [rebuild_hashes .rep.fossil] |
| 177 | 111 | set rebuildPublic [rebuild_hashes .rep.fossil "rid NOT IN private"] |
| 178 | 112 | test rebuild-start-setup {[llength $rebuildAll] > [llength $rebuildPublic] && |
| 179 | 113 | [rebuild_sql "SELECT count(*) FROM delta"] > 0} |
| 180 | 114 | file copy .rep.fossil full.fossil |
| @@ -234,12 +168,16 @@ | ||
| 234 | 168 | test rebuild-$rebuildName {$CODE == 0 && |
| 235 | 169 | [string match $rebuildOut $RESULT]} |
| 236 | 170 | test_eq rebuild-$rebuildName-effect [rebuild_sql $rebuildQuery r.fossil] \ |
| 237 | 171 | $rebuildWant |
| 238 | 172 | 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" | |
| 241 | 179 | } |
| 242 | 180 | |
| 243 | 181 | # --deanalyze removes the statistics that --analyze made. The file is |
| 244 | 182 | # read with --no-repository, because a command that opens the repository |
| 245 | 183 | # runs PRAGMA optimize when it closes it, which makes them again. |
| @@ -249,11 +187,11 @@ | ||
| 249 | 187 | test rebuild-deanalyze {$CODE == 0} |
| 250 | 188 | fossil sql --no-repository r.fossil \ |
| 251 | 189 | "SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'" |
| 252 | 190 | test_eq rebuild-deanalyze-effect [string trim $RESULT] 0 |
| 253 | 191 | test_eq rebuild-deanalyze-state \ |
| 254 | - [rebuild_diff $rebuildStart [rebuild_state r.fossil]] "" | |
| 192 | + [repository_state_diff $rebuildStart [repository_state r.fossil]] "" | |
| 255 | 193 | |
| 256 | 194 | # --stats counts each kind of artifact. |
| 257 | 195 | fossil rebuild r.fossil --stats |
| 258 | 196 | set rebuildStats $RESULT |
| 259 | 197 | foreach {rebuildName rebuildLabel rebuildType} { |
| @@ -296,19 +234,20 @@ | ||
| 296 | 234 | test_eq rebuild-ifneeded-needed-schema [rebuild_sql "SELECT value FROM config |
| 297 | 235 | WHERE name='aux-schema'" r.fossil] $rebuildSchema |
| 298 | 236 | test rebuild-ifneeded-needed-rebuilt {[rebuild_sql "SELECT mtime FROM config |
| 299 | 237 | WHERE name='rebuilt'" r.fossil] > 1} |
| 300 | 238 | test_eq rebuild-ifneeded-needed-state \ |
| 301 | - [rebuild_diff $rebuildStart [rebuild_state r.fossil]] "" | |
| 239 | + [repository_state_diff $rebuildStart [repository_state r.fossil]] "" | |
| 302 | 240 | |
| 303 | 241 | # Two repository names are one too many. Without a name, the repository |
| 304 | 242 | # of the check-out is rebuilt. |
| 305 | 243 | fossil rebuild r.fossil full.fossil -expectError |
| 306 | 244 | test rebuild-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]} |
| 307 | 245 | fossil rebuild |
| 308 | 246 | 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]] "" | |
| 310 | 249 | |
| 311 | 250 | ############################################################################### |
| 312 | 251 | # A repository with the table definitions of an old Fossil: no baseid in |
| 313 | 252 | # plink (before 2014-11-28), no pmid and isaux in mlink (before |
| 314 | 253 | # 2015-01-24), no mtime in user, config, shun, reportfmt and concealed |
| @@ -385,12 +324,12 @@ | ||
| 385 | 324 | test_eq rebuild-old-schema-reports-dated [rebuild_sql "SELECT count(*) |
| 386 | 325 | FROM reportfmt WHERE mtime IS NULL" old.fossil] 0 |
| 387 | 326 | test_eq rebuild-old-schema-concealed [rebuild_sql "SELECT hash, content, |
| 388 | 327 | mtime>1 FROM concealed" old.fossil] "abc|[email protected]|1" |
| 389 | 328 | 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 | |
| 392 | 331 | |
| 393 | 332 | ############################################################################### |
| 394 | 333 | # When the main-branch setting names a branch that no check-in has, |
| 395 | 334 | # rebuild puts the first check-in on it. Everything that was there stays. |
| 396 | 335 | |
| @@ -405,15 +344,15 @@ | ||
| 405 | 344 | test_eq rebuild-main-branch-tagged [rebuild_sql "SELECT count(*) |
| 406 | 345 | FROM tagxref JOIN tag USING(tagid) JOIN blob USING(rid) |
| 407 | 346 | WHERE tagname='sym-primary' AND tagtype=2 AND srcid>0 |
| 408 | 347 | AND uuid='$rebuildRoot'" main.fossil] 1 |
| 409 | 348 | # 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] \ | |
| 411 | 350 | [join [rebuild_hashes main.fossil] \n]] |
| 412 | 351 | test rebuild-main-branch-kept {[regexp -all -line {^\+ } $rebuildAdded] == 2 && |
| 413 | 352 | [regexp -all -line {^- } $rebuildAdded] == 0} |
| 414 | -rebuild_sound rebuild-main-branch main.fossil | |
| 353 | +repository_sound rebuild-main-branch main.fossil | |
| 415 | 354 | # A second rebuild finds the branch and adds nothing. |
| 416 | 355 | set rebuildCount [rebuild_sql "SELECT count(*) FROM blob" main.fossil] |
| 417 | 356 | fossil rebuild main.fossil |
| 418 | 357 | test_eq rebuild-main-branch-once [rebuild_sql "SELECT count(*) FROM blob" \ |
| 419 | 358 | main.fossil] $rebuildCount |
| @@ -441,11 +380,11 @@ | ||
| 441 | 380 | FROM event WHERE type='ci'" damaged.fossil] $rebuildCheckins |
| 442 | 381 | test_eq rebuild-damage-$rebuildName-phantoms [rebuild_sql "SELECT count(*) |
| 443 | 382 | FROM phantom" damaged.fossil] 1 |
| 444 | 383 | fossil cat a.txt -r [lindex $rebuildTrunk 6] -R damaged.fossil |
| 445 | 384 | test_eq rebuild-damage-$rebuildName-newest-readable "$RESULT\n" \ |
| 446 | - $rebuildTrunkText(7) | |
| 385 | + $rebuildText | |
| 447 | 386 | } |
| 448 | 387 | file delete damaged.fossil |
| 449 | 388 | |
| 450 | 389 | ############################################################################### |
| 451 | 390 | # The full-text search index. Rebuild drops it and builds it again; |
| @@ -485,11 +424,11 @@ | ||
| 485 | 424 | [rebuild_indexed fts.fossil] $rebuildDocs |
| 486 | 425 | fossil rebuild fts.fossil --noindex |
| 487 | 426 | test rebuild-noindex {$CODE == 0} |
| 488 | 427 | test_eq rebuild-noindex-gone [rebuild_indexed fts.fossil] none |
| 489 | 428 | test_eq rebuild-index-state \ |
| 490 | - [rebuild_diff $rebuildStart [rebuild_state fts.fossil]] "" | |
| 429 | + [repository_state_diff $rebuildStart [repository_state fts.fossil]] "" | |
| 491 | 430 | # --compress-only with --index on a repository that has no index makes one. |
| 492 | 431 | fossil rebuild fts.fossil --compress-only --index |
| 493 | 432 | test rebuild-compress-only-index-new {$CODE == 0 && |
| 494 | 433 | [rebuild_indexed fts.fossil] ne "none"} |
| 495 | 434 | |
| @@ -532,12 +471,12 @@ | ||
| 532 | 471 | test rebuild-$rebuildName {$CODE == 0 && |
| 533 | 472 | [string match $rebuildOut $RESULT]} |
| 534 | 473 | test_eq rebuild-$rebuildName-deltas [rebuild_sql "SELECT count(*) |
| 535 | 474 | FROM delta"] $rebuildDeltas |
| 536 | 475 | 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 | |
| 539 | 478 | } |
| 540 | 479 | for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} { |
| 541 | 480 | fossil cat n.txt -r [lindex $rebuildTrunk [expr {$rebuildI-1}]] |
| 542 | 481 | test_eq rebuild-compress-content-$rebuildI "$RESULT\n" \ |
| 543 | 482 | [rebuild_noise $rebuildI 1500] |
| @@ -557,28 +496,24 @@ | ||
| 557 | 496 | test rebuild-detach-capital-new-code {[rebuild_sql "SELECT value FROM config |
| 558 | 497 | WHERE name='project-code'" detach.fossil] ne $rebuildCode} |
| 559 | 498 | test_eq rebuild-detach-capital-parent [rebuild_sql "SELECT value FROM config |
| 560 | 499 | WHERE name='parent-project-code'" detach.fossil] $rebuildCode |
| 561 | 500 | test_eq rebuild-detach-capital-state \ |
| 562 | - [rebuild_diff $rebuildStart [rebuild_state detach.fossil]] "" | |
| 501 | + [repository_state_diff $rebuildStart [repository_state detach.fossil]] "" | |
| 563 | 502 | |
| 564 | 503 | ############################################################################### |
| 565 | 504 | # Scrub asks first. "y" and "Y" are both a yes. |
| 566 | 505 | |
| 567 | -proc rebuild_pw {repo} { | |
| 568 | - return [rebuild_sql "SELECT count(*) FROM user WHERE pw<>''" $repo] | |
| 569 | -} | |
| 570 | 506 | foreach {rebuildName rebuildAnswer} {small y capital Y} { |
| 571 | 507 | 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} | |
| 573 | 509 | fossil_raw -input "$rebuildAnswer\n" scrub scrub.fossil |
| 574 | 510 | 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 | |
| 576 | 512 | test_eq rebuild-scrub-$rebuildName-state \ |
| 577 | - [rebuild_diff $rebuildStart [rebuild_state scrub.fossil]] "" | |
| 513 | + [repository_state_diff $rebuildStart [repository_state scrub.fossil]] "" | |
| 578 | 514 | } |
| 579 | -file delete scrub.fossil | |
| 580 | 515 | |
| 581 | 516 | ############################################################################### |
| 582 | 517 | # Deconstruct writes each artifact to a file named by its hash; private |
| 583 | 518 | # ones only when asked. Reconstruct makes a repository of the same |
| 584 | 519 | # artifacts from the files. |
| @@ -602,11 +537,11 @@ | ||
| 602 | 537 | $rebuildPublic |
| 603 | 538 | test_eq rebuild-reconstruct-checkins [rebuild_sql "SELECT count(*) FROM event |
| 604 | 539 | WHERE type='ci'" r-public.fossil] [expr {$rebuildCheckins - 2}] |
| 605 | 540 | test_eq rebuild-reconstruct-none-private [rebuild_sql "SELECT count(*) |
| 606 | 541 | FROM private" r-public.fossil] 0 |
| 607 | -rebuild_sound rebuild-reconstruct r-public.fossil | |
| 542 | +repository_sound rebuild-reconstruct r-public.fossil | |
| 608 | 543 | |
| 609 | 544 | # --quiet says nothing. |
| 610 | 545 | file mkdir d-quiet |
| 611 | 546 | fossil deconstruct -R full.fossil d-quiet --quiet |
| 612 | 547 | test rebuild-deconstruct-quiet {$CODE == 0 && $RESULT eq ""} |
| @@ -645,24 +580,21 @@ | ||
| 645 | 580 | test_eq rebuild-reconstruct-keep-rid1 [rebuild_sql "SELECT uuid FROM blob |
| 646 | 581 | WHERE rid=1" r-keep.fossil] $rebuildFirst |
| 647 | 582 | test_eq rebuild-reconstruct-keep-private \ |
| 648 | 583 | [rebuild_hashes r-keep.fossil "rid IN private"] $rebuildPrivate |
| 649 | 584 | 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 | |
| 655 | 587 | |
| 656 | 588 | # Without -P every artifact in the directory becomes public. |
| 657 | 589 | fossil reconstruct r-private.fossil d-private |
| 658 | 590 | test rebuild-reconstruct-private {$CODE == 0} |
| 659 | 591 | test_eq rebuild-reconstruct-private-all [rebuild_hashes r-private.fossil] \ |
| 660 | 592 | $rebuildAll |
| 661 | 593 | test_eq rebuild-reconstruct-private-none-private [rebuild_sql "SELECT count(*) |
| 662 | 594 | FROM private" r-private.fossil] 0 |
| 663 | -rebuild_sound rebuild-reconstruct-private r-private.fossil | |
| 595 | +repository_sound rebuild-reconstruct-private r-private.fossil | |
| 664 | 596 | |
| 665 | 597 | # -L sets how many letters of the hash name the directory: none, or five. |
| 666 | 598 | # With none, .rid1 names a file in the directory itself. |
| 667 | 599 | file mkdir d-flat d-five |
| 668 | 600 | fossil deconstruct -R full.fossil d-flat -L 0 -K |
| @@ -837,11 +769,10 @@ | ||
| 837 | 769 | lappend rebuildWant $rebuildH |
| 838 | 770 | } |
| 839 | 771 | } |
| 840 | 772 | test_eq rebuild-deconstruct-damage-source-gone-files \ |
| 841 | 773 | [rebuild_names d-damaged] $rebuildWant |
| 842 | -file delete damaged.fossil | |
| 843 | 774 | |
| 844 | 775 | ############################################################################### |
| 845 | 776 | # Clusters. test-create-clusters makes one when a hundred or more |
| 846 | 777 | # artifacts are in no cluster yet; test-clusters says whether every |
| 847 | 778 | # artifact can be reached through them. |
| @@ -881,11 +812,11 @@ | ||
| 881 | 812 | fossil test-create-clusters .rep.fossil |
| 882 | 813 | test_eq rebuild-create-clusters-two [rebuild_clusters] 2 |
| 883 | 814 | fossil test-clusters -R .rep.fossil |
| 884 | 815 | test rebuild-clusters-two {$CODE == 0 && |
| 885 | 816 | [string match "*all artifacts reachable through clusters*" $RESULT]} |
| 886 | -rebuild_sound rebuild-clusters | |
| 817 | +repository_sound rebuild-clusters | |
| 887 | 818 | |
| 888 | 819 | # When the newest cluster is purged, what it listed is in no cluster and |
| 889 | 820 | # test-clusters lists each such artifact. |
| 890 | 821 | set rebuildNewest [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT |
| 891 | 822 | max(rid) FROM tagxref WHERE tagid=(SELECT tagid FROM tag |
| @@ -900,15 +831,15 @@ | ||
| 900 | 831 | [regexp -all -line {^ +\d+ [0-9a-f]{64}$} $RESULT] $rebuildCount |
| 901 | 832 | |
| 902 | 833 | # A cluster whose content has been replaced with SQL by that of a file. |
| 903 | 834 | file copy -force .rep.fossil cluster.fossil |
| 904 | 835 | 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 \ | |
| 906 | 837 | $rebuildSide b.txt]') |
| 907 | 838 | WHERE uuid='$rebuildNewest'" |
| 908 | 839 | fossil test-clusters -R cluster.fossil -expectError |
| 909 | 840 | test rebuild-clusters-bad-cluster {$CODE != 0 && |
| 910 | 841 | [string match "*bad cluster: rid=*" $RESULT]} |
| 911 | 842 | |
| 912 | 843 | ############################################################################### |
| 913 | 844 | |
| 914 | 845 | test_cleanup |
| 915 | 846 |
| --- 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 |
-11
| --- test/regress.test | ||
| +++ test/regress.test | ||
| @@ -1,14 +1,9 @@ | ||
| 1 | 1 | # |
| 2 | 2 | # Tests for faults that have been fixed, which have no better home. |
| 3 | 3 | # |
| 4 | 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 | 5 | require_no_open_checkout |
| 11 | 6 | |
| 12 | 7 | test_setup |
| 13 | 8 | |
| 14 | 9 | write_file a.txt "a\n" |
| @@ -93,11 +88,10 @@ | ||
| 93 | 88 | $regressSvnHead[regress_svn_rev 0 $regressProps] |
| 94 | 89 | fossil_raw -seconds 60 import --svn svn-$regressName.fossil \ |
| 95 | 90 | svn-$regressName.dump |
| 96 | 91 | test regress-svn-import-$regressName \ |
| 97 | 92 | {$CODE == 1 && [string match "*svn-dump data*" $RESULT]} |
| 98 | - file delete svn-$regressName.fossil | |
| 99 | 93 | } |
| 100 | 94 | |
| 101 | 95 | set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z} |
| 102 | 96 | set regressSvnSound $regressSvnHead |
| 103 | 97 | append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]] |
| @@ -104,11 +98,10 @@ | ||
| 104 | 98 | append regressSvnSound [regress_svn_rev 1 [regress_svn_props \ |
| 105 | 99 | [concat {svn:log first svn:author dan} $regressSvnDate]]] |
| 106 | 100 | write_file svn-sound.dump $regressSvnSound |
| 107 | 101 | fossil import --svn svn-sound.fossil svn-sound.dump |
| 108 | 102 | test regress-svn-import-sound {$CODE == 0} |
| 109 | -file delete svn-sound.fossil | |
| 110 | 103 | |
| 111 | 104 | ############################################################################### |
| 112 | 105 | # Two more malformed property blocks for "fossil import --svn": one with a |
| 113 | 106 | # NUL byte in it, and one whose length is negative. Each is refused. |
| 114 | 107 | |
| @@ -120,11 +113,10 @@ | ||
| 120 | 113 | foreach regressName {nul-in-block negative-block} { |
| 121 | 114 | fossil_raw -seconds 60 import --svn svn-$regressName.fossil \ |
| 122 | 115 | svn-$regressName.dump |
| 123 | 116 | test regress-svn-import-$regressName \ |
| 124 | 117 | {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]} |
| 125 | - file delete svn-$regressName.fossil | |
| 126 | 118 | } |
| 127 | 119 | |
| 128 | 120 | ############################################################################### |
| 129 | 121 | # A Markdown header that holds an HTML comment is read within its bounds |
| 130 | 122 | # when its id is made. A fault here shows only in a build with run-time |
| @@ -252,11 +244,10 @@ | ||
| 252 | 244 | test regress-push-held-attachment {$CODE == 0 |
| 253 | 245 | && ![string match "*UNIQUE constraint*" $RESULT]} |
| 254 | 246 | fossil sql -R regress-attach-clone.fossil \ |
| 255 | 247 | "SELECT count(*) FROM attachment WHERE target='AttachPage'" |
| 256 | 248 | test_eq regress-push-held-attachment-rows [string trim $RESULT] 1 |
| 257 | -file delete regress-attach-clone.fossil | |
| 258 | 249 | |
| 259 | 250 | ############################################################################### |
| 260 | 251 | # The TH1 command styleHeader run from the command line writes the page |
| 261 | 252 | # header, whatever the robot-restrict setting. |
| 262 | 253 | |
| @@ -278,8 +269,6 @@ | ||
| 278 | 269 | fossil_raw http .rep.fossil --in baseurl-req.txt --baseurl $regressUrl |
| 279 | 270 | test regress-baseurl-no-path-$regressName \ |
| 280 | 271 | {$CODE == 0 && [string match "HTTP/1.0 200*" $RESULT]} |
| 281 | 272 | } |
| 282 | 273 | |
| 283 | -############################################################################### | |
| 284 | - | |
| 285 | 274 | test_cleanup |
| 286 | 275 |
| --- 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 @@ | ||
| 26 | 26 | # |
| 27 | 27 | # Every operation is a separate run of fossil, so this file takes about |
| 28 | 28 | # a minute. |
| 29 | 29 | # |
| 30 | 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 | - | |
| 31 | +# One input runs at every level, and the rest need -assurance stress. | |
| 36 | 32 | require_no_open_checkout |
| 37 | 33 | |
| 38 | 34 | test_setup "" |
| 39 | 35 | |
| 40 | 36 | set scenarioTop [pwd] |
| @@ -195,11 +191,12 @@ | ||
| 195 | 191 | set msg [dict get $opts -errorinfo] |
| 196 | 192 | } |
| 197 | 193 | # The last three commands and the end of what each printed go into the |
| 198 | 194 | # report; the directory does not last. |
| 199 | 195 | 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] | |
| 201 | 198 | } |
| 202 | 199 | return $msg |
| 203 | 200 | } |
| 204 | 201 | |
| 205 | 202 | proc scenario_steps {data} { |
| @@ -393,13 +390,19 @@ | ||
| 393 | 390 | } |
| 394 | 391 | } |
| 395 | 392 | } |
| 396 | 393 | |
| 397 | 394 | 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 { | |
| 401 | 404 | set scenarioFd [open $scenarioF rb] |
| 402 | 405 | set scenarioData [read $scenarioFd] |
| 403 | 406 | close $scenarioFd |
| 404 | 407 | test_eq scenario-[file tail $scenarioF] \ |
| 405 | 408 | [scenario_run [file tail $scenarioF] $scenarioData] "" |
| @@ -432,8 +435,6 @@ | ||
| 432 | 435 | } else { |
| 433 | 436 | unset ::env($scenarioVar) |
| 434 | 437 | } |
| 435 | 438 | } |
| 436 | 439 | |
| 437 | -############################################################################### | |
| 438 | - | |
| 439 | 440 | test_cleanup |
| 440 | 441 |
| --- 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 @@ | ||
| 10 | 10 | # quoting for the local shell does not protect it. These tests require |
| 11 | 11 | # that a value with a character special to a shell never reaches ssh, |
| 12 | 12 | # and that ordinary values reach it unchanged. |
| 13 | 13 | # |
| 14 | 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 | 15 | require_no_open_checkout |
| 21 | 16 | |
| 22 | 17 | if {$::tcl_platform(platform) eq "windows"} { |
| 23 | 18 | test_skip "the stand-in for ssh is a shell script" |
| 24 | 19 | } |
| @@ -35,11 +30,10 @@ | ||
| 35 | 30 | |
| 36 | 31 | # The stand-in must be what "ssh" means from here on. If it is not, run |
| 37 | 32 | # nothing that could start the real one. |
| 38 | 33 | if {[lindex [auto_execok ssh] 0] ne $sshStub} { |
| 39 | 34 | set ::env(PATH) $sshSavedPath |
| 40 | - test_cleanup | |
| 41 | 35 | test_skip "cannot put a stand-in for ssh first on the PATH" |
| 42 | 36 | } |
| 43 | 37 | |
| 44 | 38 | # Run fossil with the arguments given. Sets RESULT to everything it |
| 45 | 39 | # printed and sshArgs to the arguments the stand-in was given, one per |
| @@ -112,12 +106,12 @@ | ||
| 112 | 106 | ############################################################################### |
| 113 | 107 | # "fossil ui HOST:REPO" refuses such a repository name, and puts "--" |
| 114 | 108 | # before the host. |
| 115 | 109 | |
| 116 | 110 | 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>"]]} | |
| 119 | 113 | ssh_run ui --nobrowser "hh:dir/a;b.fossil" |
| 120 | 114 | test ssh-ui-refused-semicolon \ |
| 121 | 115 | {$sshArgs eq "" && [string first "special to the shell" $RESULT] >= 0} |
| 122 | 116 | ssh_run ui --nobrowser "hh:dir/a b.fossil" |
| 123 | 117 | test ssh-ui-refused-space \ |
| @@ -140,13 +134,11 @@ | ||
| 140 | 134 | ############################################################################### |
| 141 | 135 | # An argument that begins with "~" is quoted, so that the shell does not |
| 142 | 136 | # replace it with a home directory. |
| 143 | 137 | |
| 144 | 138 | 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]}}]} | |
| 149 | 141 | |
| 150 | 142 | set ::env(PATH) $sshSavedPath |
| 151 | 143 | unset ::env(ARGS_LOG) |
| 152 | 144 | test_cleanup |
| 153 | 145 |
| --- 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 @@ | ||
| 3 | 3 | # "fossil server". After each operation, the repositories must hold the |
| 4 | 4 | # same artifacts, except for private ones, and pass "fossil |
| 5 | 5 | # test-integrity". |
| 6 | 6 | # |
| 7 | 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 | - | |
| 8 | +# The first sections run at every level, and the rest need | |
| 9 | +# -assurance stress. | |
| 13 | 10 | require_no_open_checkout |
| 14 | 11 | |
| 15 | 12 | test_setup "" |
| 16 | 13 | set dir [pwd] |
| 17 | 14 | set ::env(FOSSIL_USER) tester |
| @@ -143,12 +140,11 @@ | ||
| 143 | 140 | |
| 144 | 141 | set syncXferDir [pwd] |
| 145 | 142 | set syncXferSrv [file join $syncXferDir srv.fossil] |
| 146 | 143 | |
| 147 | 144 | proc sync_sql {repo sql} { |
| 148 | - fossil sql -R $repo $sql | |
| 149 | - return [string trim $::RESULT] | |
| 145 | + return [fossil_sql $sql $repo] | |
| 150 | 146 | } |
| 151 | 147 | |
| 152 | 148 | # How many timeline entries of REPO have the comment COMMENT. |
| 153 | 149 | proc sync_has {repo comment} { |
| 154 | 150 | return [sync_sql $repo "SELECT count(*) FROM event |
| @@ -227,10 +223,14 @@ | ||
| 227 | 223 | [sync_public .rep.fossil] |
| 228 | 224 | test_eq xfer-sync-clone-no-private [sync_has c4.fossil xfersync-g2] 0 |
| 229 | 225 | fossil cat big.txt -R c4.fossil -r $syncXferG1 |
| 230 | 226 | test_eq xfer-sync-clone-content $RESULT "${syncXferText}first" |
| 231 | 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 | 232 | |
| 233 | 233 | ############################################################################### |
| 234 | 234 | # Private check-ins go only when asked for, and stay private where they |
| 235 | 235 | # arrive. |
| 236 | 236 | |
| @@ -295,12 +295,13 @@ | ||
| 295 | 295 | |
| 296 | 296 | write_file two.txt "a file added on the other side\n" |
| 297 | 297 | fossil uv add two.txt -R srv.fossil --mtime 2026-01-02T00:00:00 |
| 298 | 298 | fossil uv sync -v $syncXferSrv |
| 299 | 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} | |
| 300 | +test xfer-sync-uv-pull-said \ | |
| 301 | + {[holds_strings $RESULT {"UV-PULL: two.txt" | |
| 302 | + "Unversioned-file received: two.txt"}]} | |
| 302 | 303 | fossil uv cat two.txt |
| 303 | 304 | test_eq xfer-sync-uv-pull-content $RESULT "a file added on the other side" |
| 304 | 305 | |
| 305 | 306 | # A trial run says what would go and sends nothing. |
| 306 | 307 | write_file one.txt "the second version of one\n" |
| @@ -320,12 +321,12 @@ | ||
| 320 | 321 | write_file one.txt "the second version of one\n" |
| 321 | 322 | fossil uv add one.txt --mtime 2026-01-03T00:00:00 |
| 322 | 323 | fossil uv sync -v $syncXferSrv |
| 323 | 324 | test xfer-sync-uv-push-newer {$CODE == 0} |
| 324 | 325 | 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"}]} | |
| 327 | 328 | fossil uv cat one.txt -R srv.fossil |
| 328 | 329 | test_eq xfer-sync-uv-push-newer-content $RESULT "the second version of one" |
| 329 | 330 | |
| 330 | 331 | # A removal on the other side. |
| 331 | 332 | fossil uv rm two.txt -R srv.fossil --mtime 2026-01-04T00:00:00 |
| @@ -602,11 +603,11 @@ | ||
| 602 | 603 | fossil sql -R d.fossil "UPDATE blob SET uuid='[string repeat 0 40]'\ |
| 603 | 604 | WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\ |
| 604 | 605 | WHERE name='f2.txt' LIMIT 1)" |
| 605 | 606 | fossil test-integrity -R d.fossil -expectError |
| 606 | 607 | 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} | |
| 608 | 609 | test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
| 609 | 610 | set server [test_start_server d.fossil stopArg] |
| 610 | 611 | set url http://127.0.0.1:[lindex $server 1] |
| 611 | 612 | fossil clone --proxy off $url e.fossil -expectError |
| 612 | 613 | test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug |
| @@ -629,11 +630,10 @@ | ||
| 629 | 630 | fossil sync http://sync-test.invalid/x --once \ |
| 630 | 631 | --transport-command $syncWrapper --chdir nr -expectError |
| 631 | 632 | test sync-no-reply-fails {$CODE != 0} |
| 632 | 633 | test_match sync-no-reply-message [normalize_result] {empty reply} |
| 633 | 634 | unset ::env(TRANSPORT_DIR) |
| 634 | - fossil close --chdir nr | |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | ############################################################################### |
| 638 | 638 | # An unversioned file pushed together with a commit that spans more than |
| 639 | 639 | # one message must arrive. |
| @@ -653,9 +653,8 @@ | ||
| 653 | 653 | fossil uv add note.txt --chdir uvco |
| 654 | 654 | fossil sync -u [file join $dir uva.fossil] --chdir uvco |
| 655 | 655 | test sync-unversioned-with-large-commit {$CODE == 0} |
| 656 | 656 | fossil uv list -R uva.fossil |
| 657 | 657 | test_match sync-unversioned-arrived [normalize_result] {note\.txt} |
| 658 | -fossil close --chdir uvco | |
| 659 | 658 | |
| 660 | 659 | test_cleanup |
| 661 | 660 | unset ::env(FOSSIL_USER) |
| 662 | 661 |
| --- 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 |
+157
| --- test/tester.tcl | ||
| +++ test/tester.tcl | ||
| @@ -345,10 +345,71 @@ | ||
| 345 | 345 | return 0 |
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | return 1 |
| 349 | 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 | +} | |
| 350 | 411 | |
| 351 | 412 | # Listens on a port on 127.0.0.1 that the system chooses, and returns |
| 352 | 413 | # the port. Calls HANDLER with each connection and the request on it, |
| 353 | 414 | # once the whole request has arrived or the client has closed its side, |
| 354 | 415 | # and then closes the connection. The request is whole when it has its |
| @@ -526,10 +587,89 @@ | ||
| 526 | 587 | fossil timeline -t ci -n 0 -F {%H %c} |
| 527 | 588 | regexp -line "^(\[0-9a-f\]+) [string map {. \\.} $comment]\$" \ |
| 528 | 589 | $::RESULT -> hash |
| 529 | 590 | return $hash |
| 530 | 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 | +} | |
| 531 | 671 | |
| 532 | 672 | # Returns the path of the repository of the open checkout, from |
| 533 | 673 | # "fossil info", or an empty string when there is none. |
| 534 | 674 | # |
| 535 | 675 | proc repository_path {} { |
| @@ -559,10 +699,27 @@ | ||
| 559 | 699 | write_file $filename $txt |
| 560 | 700 | set hash [sha1_file $filename] |
| 561 | 701 | file delete $filename |
| 562 | 702 | return $hash |
| 563 | 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 | +} | |
| 564 | 721 | |
| 565 | 722 | # Return true if two files are the same |
| 566 | 723 | # |
| 567 | 724 | proc same_file {a b} { |
| 568 | 725 | set x [read_file $a] |
| 569 | 726 |
| --- 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 @@ | ||
| 3 | 3 | # Scripts are run with "fossil test-th-eval", templates with |
| 4 | 4 | # "fossil test-th-render" and "fossil test-th-source", and a ticket page |
| 5 | 5 | # that holds TH1 is asked for through "fossil http --in". |
| 6 | 6 | # |
| 7 | 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 | - | |
| 8 | +# The first sections run at every level, and the rest need | |
| 9 | +# -assurance stress. | |
| 13 | 10 | test_setup |
| 14 | 11 | |
| 15 | 12 | write_file a.txt "hello\n" |
| 16 | 13 | write_file f83.txt "line 83\n" |
| 17 | 14 | write_file f100.txt "line 100\n" |
| @@ -97,12 +94,14 @@ | ||
| 97 | 94 | tclready-many {tclReady a} {tclReady} |
| 98 | 95 | anycap-few {anycap} {anycap STRING} |
| 99 | 96 | anycap-many {anycap a b} {anycap STRING} |
| 100 | 97 | combobox-few {combobox a b} {combobox NAME TEXT-LIST NUMLINES} |
| 101 | 98 | 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?} | |
| 104 | 103 | linecount-few {linecount a 1} {linecount STRING MAX MIN} |
| 105 | 104 | linecount-many {linecount a 1 2 3} {linecount STRING MAX MIN} |
| 106 | 105 | repository-many {repository 1 2} {repository ?BOOLEAN?} |
| 107 | 106 | checkout-many {checkout 1 2} {checkout ?BOOLEAN?} |
| 108 | 107 | trace-few {trace} {trace STRING} |
| @@ -144,27 +143,38 @@ | ||
| 144 | 143 | query-option-many {query -nocomplain a b c} {query SQL CODE} |
| 145 | 144 | setting-few {setting} {setting ?-strict? ?--? name} |
| 146 | 145 | setting-many {setting a b c d} {setting ?-strict? ?--? name} |
| 147 | 146 | setting-two {setting -- a b} {setting ?-strict? ?--? name} |
| 148 | 147 | 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} | |
| 152 | 154 | regexp-few {regexp a} {regexp ?-nocase? ?--? exp string} |
| 153 | 155 | regexp-many {regexp -nocase -- a b c} {regexp ?-nocase? ?--? exp string} |
| 154 | 156 | regexp-three {regexp -- a b c} {regexp ?-nocase? ?--? exp string} |
| 155 | 157 | 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?} | |
| 160 | 166 | capture-few {captureTh1} {captureTh1 STRING} |
| 161 | 167 | capture-many {captureTh1 a b} {captureTh1 STRING} |
| 162 | 168 | } { |
| 163 | 169 | test_eq th1main-args-$th1mainName [th1main_eval $th1mainCall] \ |
| 164 | 170 | "TH_ERROR: wrong # args: should be \"$th1mainUsage\"" |
| 165 | 171 | } |
| 172 | + | |
| 173 | +if {[test_assurance] ne "stress"} { | |
| 174 | + test_skip "the tests after the first sections need -assurance stress" | |
| 175 | +} | |
| 166 | 176 | |
| 167 | 177 | ############################################################################### |
| 168 | 178 | # What the commands return and write. A script that writes ends with |
| 169 | 179 | # "set x {}" so that only what it wrote is printed. |
| 170 | 180 | |
| @@ -486,12 +496,14 @@ | ||
| 486 | 496 | |
| 487 | 497 | # With timeline-utc off, "date -local" gives the time of the zone in TZ. |
| 488 | 498 | fossil settings timeline-utc 0 |
| 489 | 499 | set th1mainSavedTz [expr {[info exists env(TZ)] ? $env(TZ) : ""}] |
| 490 | 500 | 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 } | |
| 493 | 505 | fossil settings timeline-utc 1 |
| 494 | 506 | set th1mainDiff [expr {[clock scan [lindex $th1mainDates 1] -gmt 1] |
| 495 | 507 | - [clock scan [lindex $th1mainDates 0] -gmt 1]}] |
| 496 | 508 | test th1main-date-local {$th1mainDiff >= 17999 && $th1mainDiff <= 18001} |
| 497 | 509 | |
| @@ -551,11 +563,12 @@ | ||
| 551 | 563 | |
| 552 | 564 | # "setting -strict" and "http -asynchronous" with nothing after the |
| 553 | 565 | # option, and "http" with an empty first argument, give a script error. |
| 554 | 566 | foreach {th1mainName th1mainCall th1mainUsage} { |
| 555 | 567 | 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?} | |
| 557 | 570 | http-empty {http {}} {http ?-asynchronous? ?--? url ?payload?} |
| 558 | 571 | } { |
| 559 | 572 | set th1mainGot [th1main_eval $th1mainCall] |
| 560 | 573 | test th1main-args-$th1mainName {$CODE == 0 && [string match \ |
| 561 | 574 | "TH_ERROR: *" $th1mainGot]} |
| @@ -570,13 +583,16 @@ | ||
| 570 | 583 | foreach {th1mainName th1mainSql} { |
| 571 | 584 | two {SELECT 1 AS a; SELECT 2 AS a} |
| 572 | 585 | space {SELECT 1 AS a; } |
| 573 | 586 | } { |
| 574 | 587 | 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"] ""] | |
| 576 | 591 | 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]} | |
| 578 | 594 | } |
| 579 | 595 | |
| 580 | 596 | # builtin_request_js with a name that is not a built-in file gives a |
| 581 | 597 | # script error. |
| 582 | 598 | set th1mainGot [th1main_eval {builtin_request_js nosuch.js}] |
| @@ -591,11 +607,12 @@ | ||
| 591 | 607 | set th1mainGot [th1main_eval {http not-a-url}] |
| 592 | 608 | test th1main-http-not-url \ |
| 593 | 609 | {$CODE == 0 && [string match "TH_ERROR: *" $th1mainGot]} |
| 594 | 610 | |
| 595 | 611 | # A phantom: an artifact whose content the repository does not hold. |
| 596 | -set th1mainPhantom abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 | |
| 612 | +set th1mainPhantom \ | |
| 613 | + abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 | |
| 597 | 614 | fossil sql "INSERT INTO blob(rcvid,size,uuid) VALUES(0,-1,'$th1mainPhantom'); |
| 598 | 615 | INSERT INTO phantom SELECT rid FROM blob WHERE size=-1;" |
| 599 | 616 | test_match th1main-artifact-phantom \ |
| 600 | 617 | [th1main_eval "artifact $th1mainPhantom"] {^TH_ERROR: } |
| 601 | 618 | |
| @@ -659,11 +676,13 @@ | ||
| 659 | 676 | test th1main-http-get-request {[holds_strings $th1mainHeard [list \ |
| 660 | 677 | "GET /dir/page?a=b HTTP/1.0\r\n" "Host: $th1mainUrl\r\n" \ |
| 661 | 678 | "User-Agent: " "!Content-Length" "!Authorization"]]} |
| 662 | 679 | |
| 663 | 680 | 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"] ""]] | |
| 665 | 684 | test_eq th1main-http-post $th1mainGot sent |
| 666 | 685 | test th1main-http-post-request {[holds_strings $th1mainHeard [list \ |
| 667 | 686 | "POST /post HTTP/1.0\r\n" "Content-Length: 12\r\n\r\nsome payload" \ |
| 668 | 687 | "Content-Type: application/x-www-form-urlencoded\r\n"]]} |
| 669 | 688 | |
| @@ -687,11 +706,10 @@ | ||
| 687 | 706 | close $th1mainServer |
| 688 | 707 | # Nothing listens on the port any more. |
| 689 | 708 | set th1mainGot [th1main_eval "http -asynchronous http://$th1mainUrl/x"] |
| 690 | 709 | test_match th1main-http-refused $th1mainGot {^TH_ERROR: .} |
| 691 | 710 | } |
| 692 | -fossil unset th1-uri-regexp | |
| 693 | 711 | |
| 694 | 712 | ############################################################################### |
| 695 | 713 | # Tracing: --th-trace prints a log of what the commands did. |
| 696 | 714 | |
| 697 | 715 | foreach {th1mainName th1mainOpts th1mainScript th1mainWanted} { |
| @@ -742,33 +760,40 @@ | ||
| 742 | 760 | empty {} {} \ |
| 743 | 761 | script {a<th1>puts b</th1>c} abc \ |
| 744 | 762 | script-upper {<TH1>puts 1</TH1><Th1>puts 2</tH1><tH1>puts 3</Th1>} 123 \ |
| 745 | 763 | script-unclosed {a<th1>puts b} ab \ |
| 746 | 764 | script-empty-unclosed {a<th1>} a \ |
| 747 | - script-half-closed {a<th1></th1} "a${th1mainErr}no such command: </th1</p>" \ | |
| 765 | + script-half-closed {a<th1></th1} \ | |
| 766 | + "a${th1mainErr}no such command: </th1</p>" \ | |
| 748 | 767 | not-tags {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \ |
| 749 | 768 | {<t><th><th1 ><th2>x</t></th></th1 ></th2></th1x<xh1><tx1>} \ |
| 750 | 769 | end-tag-alone {a</th1>b} {a</th1>b} \ |
| 751 | 770 | end-tag-look-alikes {<th1>set y {<x </x </tx </thx </th1x}; puts $y</th1>} \ |
| 752 | 771 | {<x </x </tx </thx </th1x} \ |
| 753 | 772 | dollar-end {a$} {a$} \ |
| 754 | 773 | dollar-bracket-end {a$<} {a$<} \ |
| 755 | 774 | dollar-bracket-unclosed {a$<v b} {a$<v b} \ |
| 756 | 775 | 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]} \ | |
| 758 | 778 | {[<b>&][<b>&][G][G][two]} \ |
| 759 | 779 | 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} {[][<i>]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 | + {[][<i>]end} \ | |
| 788 | + error-plain {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \ | |
| 765 | 789 | error-escaped {<th1>error <b></th1>} "${th1mainErr}<b></p>" \ |
| 766 | 790 | nested {<th1>set v 2; render {b$<v>|}; render {c$v}</th1>d} {b2|c2d} \ |
| 767 | 791 | nested-error {<th1>render {b$<v>|}; puts never</th1>d} \ |
| 768 | 792 | "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 \ | |
| 770 | 795 | ] { |
| 771 | 796 | test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \ |
| 772 | 797 | $th1mainExpected |
| 773 | 798 | test th1main-render-$th1mainName-exit {$CODE == 0} |
| 774 | 799 | } |
| @@ -800,11 +825,12 @@ | ||
| 800 | 825 | test_eq th1main-render-anon-caps \ |
| 801 | 826 | [th1main_render {<th1>puts [anoncap s]</th1>} --set-anon-caps] 1 |
| 802 | 827 | set env(TH1_TEST_USER_CAPS) o |
| 803 | 828 | set env(TH1_TEST_ANON_CAPS) h |
| 804 | 829 | 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>} \ | |
| 806 | 832 | --set-user-caps --set-anon-caps] 1010 |
| 807 | 833 | test_eq th1main-eval-caps-from-environment \ |
| 808 | 834 | [th1main_eval {puts [hascap o][hascap s][anoncap h][anoncap s]; set x {}} \ |
| 809 | 835 | --set-user-caps --set-anon-caps] 1010 |
| 810 | 836 | unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS) |
| @@ -831,11 +857,12 @@ | ||
| 831 | 857 | [th1main_source {puts a; set x b} --no-print-result] a |
| 832 | 858 | test_eq th1main-source-no-database \ |
| 833 | 859 | [th1main_source {query {SELECT 1 AS a} {puts $a}}] \ |
| 834 | 860 | {TH_ERROR: database is not open } |
| 835 | 861 | 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}] \ | |
| 837 | 864 | quiet |
| 838 | 865 | test_eq th1main-source-no-repository [th1main_source {repository}] {} |
| 839 | 866 | test_match th1main-source-repository [th1main_source {repository 1}] \ |
| 840 | 867 | {/\.rep\.fossil$} |
| 841 | 868 | test_match th1main-source-checkout [th1main_source {checkout 1}] \ |
| @@ -848,11 +875,12 @@ | ||
| 848 | 875 | test_eq th1main-source-anon-caps \ |
| 849 | 876 | [th1main_source {anoncap s} --set-anon-caps] 1 |
| 850 | 877 | set env(TH1_TEST_USER_CAPS) o |
| 851 | 878 | set env(TH1_TEST_ANON_CAPS) h |
| 852 | 879 | 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 {}} \ | |
| 854 | 882 | --set-user-caps --set-anon-caps] 1010 |
| 855 | 883 | unset env(TH1_TEST_USER_CAPS) env(TH1_TEST_ANON_CAPS) |
| 856 | 884 | set th1mainGot [th1main_source {puts hello; set x {}} --cgi] |
| 857 | 885 | test th1main-source-cgi {[holds_strings $th1mainGot [list \ |
| 858 | 886 | "Status: 200 OK\r\n" "\r\n\r\nhello"]]} |
| @@ -907,12 +935,11 @@ | ||
| 907 | 935 | return "" |
| 908 | 936 | } |
| 909 | 937 | |
| 910 | 938 | # The same for a GET of /tktnew with the query string QUERY. |
| 911 | 939 | 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] | |
| 914 | 941 | } |
| 915 | 942 | |
| 916 | 943 | fossil fts-config enable cdtw |
| 917 | 944 | set th1mainGot [th1main_page {<th1> |
| 918 | 945 | puts "top=[globalState top none] user=[globalState user none]|" |
| @@ -1087,11 +1114,13 @@ | ||
| 1087 | 1114 | # page goes on; a tainted query and a tainted redirect are refused. |
| 1088 | 1115 | fossil unset vuln-report |
| 1089 | 1116 | set th1mainGot [th1main_page {B=$title|C=$<title>|END} $th1mainTaintQuery] |
| 1090 | 1117 | test th1main-taint-block-inline {[holds_strings $th1mainGot \ |
| 1091 | 1118 | {{B=|C=<u>|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] | |
| 1093 | 1122 | test th1main-taint-block-query {[holds_strings $th1mainGot \ |
| 1094 | 1123 | {{ERROR: tainted query SQL: "SELECT 1 AS n /* <i> */"} !n=1}]} |
| 1095 | 1124 | set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \ |
| 1096 | 1125 | "?u=/elsewhere"] |
| 1097 | 1126 | test th1main-taint-block-redirect {[holds_strings $th1mainGot \ |
| @@ -1100,11 +1129,10 @@ | ||
| 1100 | 1129 | fossil settings vuln-report off |
| 1101 | 1130 | set th1mainGot [th1main_page {<th1>redirect [getParameter u]</th1>END} \ |
| 1102 | 1131 | "?u=/elsewhere"] |
| 1103 | 1132 | test th1main-taint-off-redirect {[holds_strings $th1mainGot [list \ |
| 1104 | 1133 | "HTTP/1.0 302 " "\r\nLocation: http://x/elsewhere\r\n"]]} |
| 1105 | -fossil unset vuln-report | |
| 1106 | 1134 | |
| 1107 | 1135 | ############################################################################### |
| 1108 | 1136 | # With no check-out and no repository. |
| 1109 | 1137 | |
| 1110 | 1138 | fossil close --force |
| 1111 | 1139 |
| --- 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: </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 | {<x </x </tx </thx </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>&][<b>&][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} {[][<i>]end} \ |
| 764 | error {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \ |
| 765 | error-escaped {<th1>error <b></th1>} "${th1mainErr}<b></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=<u>|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: "SELECT 1 AS n /* <i> */"} !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: </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 | {<x </x </tx </thx </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>&][<b>&][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 | {[][<i>]end} \ |
| 788 | error-plain {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \ |
| 789 | error-escaped {<th1>error <b></th1>} "${th1mainErr}<b></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=<u>|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: "SELECT 1 AS n /* <i> */"} !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 @@ | ||
| 17 | 17 | # |
| 18 | 18 | # http.test tests whole clones over HTTP and HTTPS. ssh.test tests what |
| 19 | 19 | # goes on an ssh command line. |
| 20 | 20 | # |
| 21 | 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 | - | |
| 22 | +# The first sections run at every level, and the rest need | |
| 23 | +# -assurance stress. | |
| 27 | 24 | require_no_open_checkout |
| 28 | 25 | |
| 29 | 26 | if {![loopback_available]} { |
| 30 | 27 | test_skip "the tests need a TCP connection over the loopback interface" |
| 31 | 28 | } |
| @@ -437,10 +434,14 @@ | ||
| 437 | 434 | # The other network options of a sync command are accepted. |
| 438 | 435 | # |
| 439 | 436 | foreach urlOption {--nosync --ipv4 --ipv6 --accept-any-cert} { |
| 440 | 437 | url_parse_test url-proxy-option$urlOption http://h/x $urlOption {name h} |
| 441 | 438 | } |
| 439 | + | |
| 440 | +if {[test_assurance] ne "stress"} { | |
| 441 | + test_skip "the tests after the first sections need -assurance stress" | |
| 442 | +} | |
| 442 | 443 | |
| 443 | 444 | ############################################################################### |
| 444 | 445 | # The name for a clone of a URL. |
| 445 | 446 | |
| 446 | 447 | foreach {urlName urlText urlExpected} { |
| @@ -475,56 +476,28 @@ | ||
| 475 | 476 | test_eq url-basename-none $RESULT "" |
| 476 | 477 | |
| 477 | 478 | ############################################################################### |
| 478 | 479 | # The HTTP exchange. |
| 479 | 480 | |
| 480 | -set urlServers [list] | |
| 481 | -set urlRequests [list] | |
| 482 | - | |
| 483 | 481 | # Listens on a port on 127.0.0.1 that the system chooses, and returns |
| 484 | 482 | # the port. Connection N is answered with item N of REPLIES, and the |
| 485 | 483 | # last item answers every later connection. "PORT" in a reply stands for |
| 486 | 484 | # the port. Each request is appended to the list urlRequests. |
| 487 | 485 | # |
| 488 | 486 | proc url_listen {replies} { |
| 489 | 487 | 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} { | |
| 512 | 491 | set number [llength $::urlRequests] |
| 513 | 492 | lappend ::urlRequests $request |
| 514 | 493 | if {$number >= [llength $replies]} {set number end} |
| 515 | 494 | set port [lindex [fconfigure $chan -sockname] 2] |
| 516 | 495 | catch { |
| 517 | 496 | puts -nonewline $chan [string map [list PORT $port] \ |
| 518 | 497 | [lindex $replies $number]] |
| 519 | 498 | } |
| 520 | - catch {close $chan} | |
| 521 | -} | |
| 522 | -proc url_listen_stop {} { | |
| 523 | - update | |
| 524 | - foreach urlServer $::urlServers {close $urlServer} | |
| 525 | - set ::urlServers [list] | |
| 526 | 499 | } |
| 527 | 500 | |
| 528 | 501 | # Returns TEXT with each line end changed to CR LF. |
| 529 | 502 | proc url_crlf {text} { |
| 530 | 503 | return [string map [list \n \r\n] $text] |
| @@ -556,11 +529,11 @@ | ||
| 556 | 529 | # with REPLIES, with the options and further arguments in ARGS. |
| 557 | 530 | # |
| 558 | 531 | proc url_httpmsg {replies args} { |
| 559 | 532 | set port [url_listen $replies] |
| 560 | 533 | fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x {*}$args |
| 561 | - url_listen_stop | |
| 534 | + test_listen_stop | |
| 562 | 535 | } |
| 563 | 536 | |
| 564 | 537 | # Replies that are accepted. Each row is a name, the reply header, the |
| 565 | 538 | # reply body and the body that test-httpmsg must print. |
| 566 | 539 | # |
| @@ -595,26 +568,38 @@ | ||
| 595 | 568 | hello hello \ |
| 596 | 569 | content-type-other \ |
| 597 | 570 | "HTTP/1.1 200 OK\nContent-Type: text/html\nContent-Length: 5\n\n" \ |
| 598 | 571 | hello hello \ |
| 599 | 572 | 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"] ""] \ | |
| 601 | 577 | hello hello \ |
| 602 | 578 | 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"] ""] \ | |
| 604 | 583 | hello hello \ |
| 605 | 584 | interim-100 \ |
| 606 | 585 | "HTTP/1.1 100 Continue\n\nHTTP/1.1 200 OK\nContent-Length: 5\n\n" \ |
| 607 | 586 | hello hello \ |
| 608 | 587 | 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"] ""] \ | |
| 610 | 591 | hello hello \ |
| 611 | 592 | 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"] ""] \ | |
| 613 | 596 | hello hello \ |
| 614 | 597 | 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"] ""] \ | |
| 616 | 601 | hello hello \ |
| 617 | 602 | chunked "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 618 | 603 | "3\r\nhel\r\n2\r\nlo\r\n0\r\n\r\n" hello \ |
| 619 | 604 | chunked-upper-case "HTTP/1.1 200 OK\nTransfer-Encoding:CHUNKED\n\n" \ |
| 620 | 605 | "A\r\n0123456789\r\n0\r\n\r\n" 0123456789 \ |
| @@ -698,17 +683,23 @@ | ||
| 698 | 683 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked, gzip\n\n" \ |
| 699 | 684 | {unsupported transfer-encoding: chunked, gzip} \ |
| 700 | 685 | transfer-encoding-empty "HTTP/1.1 200 OK\nTransfer-Encoding:\n\n" \ |
| 701 | 686 | {unsupported transfer-encoding: } \ |
| 702 | 687 | 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"] ""] \ | |
| 704 | 691 | {server sent two transfer-encoding headers} \ |
| 705 | 692 | 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"] ""] \ | |
| 707 | 696 | {reply has both content-length and transfer-encoding} \ |
| 708 | 697 | 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"] ""] \ | |
| 710 | 701 | {reply has both content-length and transfer-encoding} \ |
| 711 | 702 | chunk-no-body "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 712 | 703 | {chunked reply ended without terminator} \ |
| 713 | 704 | chunk-blank-line "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n\n" \ |
| 714 | 705 | {chunked reply ended without terminator} \ |
| @@ -725,11 +716,13 @@ | ||
| 725 | 716 | {chunked reply: missing or malformed chunk size} \ |
| 726 | 717 | chunk-size-80000000 \ |
| 727 | 718 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n80000000\nhello\n0\n\n" \ |
| 728 | 719 | {chunked reply: invalid chunk size} \ |
| 729 | 720 | 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"] ""] \ | |
| 731 | 724 | {chunked reply: invalid chunk size} \ |
| 732 | 725 | chunk-size-then-text \ |
| 733 | 726 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5 x\nhello\n0\n\n" \ |
| 734 | 727 | {chunked reply: malformed chunk size line} \ |
| 735 | 728 | chunk-extension-no-name \ |
| @@ -777,11 +770,12 @@ | ||
| 777 | 770 | {unknown repository: \n} \ |
| 778 | 771 | status-401 "HTTP/1.1 401 Unauthorized\n\n" \ |
| 779 | 772 | {server says: 401 Unauthorized} \ |
| 780 | 773 | ] { |
| 781 | 774 | 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" | |
| 783 | 777 | url_httpmsg [list [url_crlf $urlReply]] |
| 784 | 778 | test url-http-refused-quiet-$urlName {$CODE == 1} |
| 785 | 779 | } |
| 786 | 780 | |
| 787 | 781 | # A redirect to an ssh: URL with no path is refused. |
| @@ -804,11 +798,12 @@ | ||
| 804 | 798 | redirect-to-file "HTTP/1.1 302 Found\nLocation: file:///nosuchdir/r\n\n" \ |
| 805 | 799 | {cannot redirect to file:///nosuchdir/r} \ |
| 806 | 800 | ] { |
| 807 | 801 | file delete out.txt |
| 808 | 802 | 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} | |
| 810 | 805 | url_httpmsg [list [url_crlf $urlReply]] |
| 811 | 806 | test url-http-message-quiet-$urlName {$CODE == 1 && $RESULT eq ""} |
| 812 | 807 | } |
| 813 | 808 | |
| 814 | 809 | # A reply that is shorter than its Content-Length is an error, and only |
| @@ -818,49 +813,52 @@ | ||
| 818 | 813 | file delete out.txt |
| 819 | 814 | url_httpmsg [list $urlShort] --out out.txt |
| 820 | 815 | test url-http-message-truncated {$CODE == 1 && |
| 821 | 816 | [string first "response truncated: got 5 bytes of 6" $RESULT] >= 0} |
| 822 | 817 | url_httpmsg [list $urlShort] |
| 823 | -test url-http-message-quiet-truncated {$CODE == 1} | |
| 824 | 818 | test url-http-truncated-bytes {$RESULT eq "hello"} |
| 825 | 819 | |
| 826 | 820 | # A redirect is followed three times, with the same method and payload, |
| 827 | 821 | # and the fourth is refused. 301, 302, 307 and 308 are followed. A |
| 828 | 822 | # Location that ends in /xfer is used without that ending. |
| 829 | 823 | # |
| 830 | 824 | foreach urlStatus {301 302 307 308} { |
| 831 | 825 | 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"] \ | |
| 833 | 828 | [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] |
| 834 | 829 | test url-http-redirect-$urlStatus {$CODE == 0 && $RESULT eq "hello" && |
| 835 | 830 | [url_request_line 0] eq "GET /x HTTP/1.1" && |
| 836 | 831 | [url_request_line 1] eq "GET /b HTTP/1.1"} |
| 837 | 832 | } |
| 838 | 833 | write_file payload.txt "payload text\n" |
| 839 | 834 | url_httpmsg [list \ |
| 840 | 835 | [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"] \ |
| 841 | 836 | [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"] \ | |
| 843 | 839 | [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] payload.txt |
| 844 | 840 | test url-http-redirect-three {$CODE == 0 && $RESULT eq "hello" && |
| 845 | 841 | [llength $urlRequests] == 4 && |
| 846 | 842 | [url_request_line 3] eq "POST /d HTTP/1.1" && |
| 847 | 843 | [url_request_body 3] eq "payload text\n"} |
| 848 | 844 | url_httpmsg [list \ |
| 849 | 845 | [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/b\n\n"]] |
| 850 | 846 | test url-http-redirect-four {$CODE == 1 && [llength $urlRequests] == 4} |
| 851 | 847 | 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"] \ | |
| 853 | 850 | [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] -v |
| 854 | 851 | test url-http-redirect-after-other-header {$CODE == 0 && |
| 855 | 852 | [string first "redirect with status 302 to http://127.0.0.1:" $RESULT] >= 0} |
| 856 | 853 | |
| 857 | 854 | # A Location that ends in /xfer loses only the last one, so that a |
| 858 | 855 | # repository whose own path ends in /xfer is still found. |
| 859 | 856 | # |
| 860 | 857 | 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"] \ | |
| 862 | 860 | [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] |
| 863 | 861 | test_eq url-http-redirect-xfer-twice [url_request_line 1] "GET /d/xfer HTTP/1.1" |
| 864 | 862 | |
| 865 | 863 | # A 401 reply is asked for again twice, and then is an error. Standard |
| 866 | 864 | # input is not a terminal, so fossil cannot ask for credentials. |
| @@ -891,11 +889,11 @@ | ||
| 891 | 889 | [url_request_header 0 Cookie] eq "(none)"} |
| 892 | 890 | |
| 893 | 891 | set urlPort [url_listen [list $urlOk]] |
| 894 | 892 | fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort |
| 895 | 893 | test_eq url-request-no-path [url_request_line 0] "GET / HTTP/1.1" |
| 896 | -url_listen_stop | |
| 894 | +test_listen_stop | |
| 897 | 895 | |
| 898 | 896 | url_httpmsg [list $urlOk] payload.txt |
| 899 | 897 | test url-request-post {[url_request_line 0] eq "POST /x HTTP/1.1" && |
| 900 | 898 | [url_request_header 0 Content-Type] eq "text/plain" && |
| 901 | 899 | [url_request_header 0 Content-Length] eq "13" && |
| @@ -913,11 +911,11 @@ | ||
| 913 | 911 | fossil_raw -seconds 60 -input "from standard input" \ |
| 914 | 912 | test-httpmsg http://127.0.0.1:$urlPort/x - |
| 915 | 913 | test url-request-standard-input { |
| 916 | 914 | [url_request_header 0 Content-Type] eq "application/x-unknown" && |
| 917 | 915 | [url_request_body 0] eq "from standard input"} |
| 918 | -url_listen_stop | |
| 916 | +test_listen_stop | |
| 919 | 917 | |
| 920 | 918 | # --compress sends the payload compressed and expects a compressed |
| 921 | 919 | # reply: four bytes of size and then a zlib stream. |
| 922 | 920 | # |
| 923 | 921 | proc url_compress {text} { |
| @@ -929,16 +927,18 @@ | ||
| 929 | 927 | } |
| 930 | 928 | binary scan $bytes I size |
| 931 | 929 | if {$size != [string length $text]} {return "(wrong size)"} |
| 932 | 930 | return $text |
| 933 | 931 | } |
| 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"]]] | |
| 935 | 935 | fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$urlPort/x payload.txt \ |
| 936 | 936 | --compress |
| 937 | 937 | test url-request-compress {$CODE == 0 && $RESULT eq "compressed reply" && |
| 938 | 938 | [url_uncompress [url_request_body 0]] eq "payload text\n"} |
| 939 | -url_listen_stop | |
| 939 | +test_listen_stop | |
| 940 | 940 | |
| 941 | 941 | # The reply goes to the file named by --out or by the third argument, |
| 942 | 942 | # but not by both. |
| 943 | 943 | # |
| 944 | 944 | file delete out.txt |
| @@ -952,13 +952,12 @@ | ||
| 952 | 952 | url_httpmsg [list $urlOk] payload.txt out.txt --out other.txt |
| 953 | 953 | test url-request-out-twice {$CODE == 1 && ![file exists out.txt] && |
| 954 | 954 | [string first "output file specified twice" $RESULT] >= 0} |
| 955 | 955 | url_httpmsg [list $urlOk] -v |
| 956 | 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} | |
| 957 | + [holds_strings $RESULT [list "Sending " "Read: \[HTTP/1.1 200 OK\]" \ | |
| 958 | + "Reply received: 2 of 2 bytes"]]} | |
| 960 | 959 | url_httpmsg [list [url_crlf "HTTP/1.1 200 OK\n\n"]hello] -v |
| 961 | 960 | test url-request-verbose-no-length {$CODE == 0 && [string first \ |
| 962 | 961 | "Reply received: 5 bytes (w/o content-length)" $RESULT] >= 0} |
| 963 | 962 | |
| 964 | 963 | foreach urlOption {--ipv4 --no-cert-verify} { |
| @@ -969,13 +968,15 @@ | ||
| 969 | 968 | # 127.0.0.1: macOS reaches it through a mapped address, Linux refuses it. |
| 970 | 969 | url_httpmsg [list $urlOk] --ipv6 |
| 971 | 970 | test url-request-option--ipv6 {($CODE == 0 && $RESULT eq "ok") || |
| 972 | 971 | [string first "getaddrinfo() fails" $RESULT] >= 0} |
| 973 | 972 | 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]} | |
| 975 | 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]} | |
| 976 | +test url-request-usage-many \ | |
| 977 | + {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]} | |
| 977 | 978 | fossil_raw test-httpmsg file://$urlRepo |
| 978 | 979 | test url-request-file-needs-subpath {$CODE == 1 && [string first \ |
| 979 | 980 | "the --subpath option is required for file://" $RESULT] >= 0} |
| 980 | 981 | |
| 981 | 982 | # --httptrace writes each request and reply to a numbered file, and |
| @@ -1024,20 +1025,24 @@ | ||
| 1024 | 1025 | # message BODY. |
| 1025 | 1026 | proc url_login_card {user secret body} { |
| 1026 | 1027 | set nonce [sha1_text $body] |
| 1027 | 1028 | return "login $user $nonce [sha1_text $nonce$secret]" |
| 1028 | 1029 | } |
| 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 | |
| 1030 | 1035 | set urlCard "[url_login_card bob secret "payload text\n"]\npayload text\n" |
| 1031 | 1036 | |
| 1032 | 1037 | # Runs test-httpmsg --xfer for the user and password in USERINFO, which |
| 1033 | 1038 | # is empty or ends with "@", and further options in ARGS. |
| 1034 | 1039 | proc url_xfer {userinfo args} { |
| 1035 | 1040 | set port [url_listen [list $::urlSyncOk]] |
| 1036 | 1041 | fossil_raw -seconds 60 test-httpmsg http://${userinfo}127.0.0.1:$port/x \ |
| 1037 | 1042 | payload.txt --xfer {*}$args |
| 1038 | - url_listen_stop | |
| 1043 | + test_listen_stop | |
| 1039 | 1044 | } |
| 1040 | 1045 | |
| 1041 | 1046 | url_xfer bob:secret@ |
| 1042 | 1047 | test url-login-password {$CODE == 0 && $RESULT eq "ok" && |
| 1043 | 1048 | [url_request_header 0 Content-Type] eq "application/x-fossil" && |
| @@ -1072,11 +1077,15 @@ | ||
| 1072 | 1077 | # already. |
| 1073 | 1078 | # |
| 1074 | 1079 | fossil sql "SELECT value FROM config WHERE name='project-code'" |
| 1075 | 1080 | set urlProject [string trim $RESULT] |
| 1076 | 1081 | 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"] ""]] | |
| 1078 | 1087 | append urlPullOk "# timestamp 2026-01-01T00:00:00 errors 0\n" |
| 1079 | 1088 | |
| 1080 | 1089 | # Returns 1 if request NUMBER of the last exchange begins with the login |
| 1081 | 1090 | # card for USER and the shared secret SECRET, and 0 otherwise. |
| 1082 | 1091 | proc url_login_ok {number user secret} { |
| @@ -1091,11 +1100,11 @@ | ||
| 1091 | 1100 | # text, and the options in ARGS, from the URL with USERINFO. |
| 1092 | 1101 | proc url_pull {userinfo args} { |
| 1093 | 1102 | set port [url_listen [list $::urlPullOk]] |
| 1094 | 1103 | fossil_raw -seconds 60 pull http://${userinfo}127.0.0.1:$port/repo \ |
| 1095 | 1104 | --httptrace {*}$args |
| 1096 | - url_listen_stop | |
| 1105 | + test_listen_stop | |
| 1097 | 1106 | file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt] |
| 1098 | 1107 | return $port |
| 1099 | 1108 | } |
| 1100 | 1109 | url_pull bob:secret@ --once |
| 1101 | 1110 | test url-login-project-code {$CODE == 0 && [url_login_ok 0 bob $urlSecret]} |
| @@ -1134,20 +1143,24 @@ | ||
| 1134 | 1143 | fossil_raw -seconds 60 test-httpmsg http://bob:[email protected]:$urlPort/x \ |
| 1135 | 1144 | --xfer --login-card-header |
| 1136 | 1145 | test url-login-cookie-no-payload { |
| 1137 | 1146 | [url_request_line 0] eq "GET /x HTTP/1.1" && |
| 1138 | 1147 | [url_request_header 0 Cookie] eq "(none)"} |
| 1139 | -url_listen_stop | |
| 1148 | +test_listen_stop | |
| 1140 | 1149 | |
| 1141 | 1150 | # A sync reply of another content type is an error message from the |
| 1142 | 1151 | # server. It is printed without its HTML tags. |
| 1143 | 1152 | # |
| 1144 | 1153 | 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]] | |
| 1146 | 1159 | fossil_raw -seconds 60 test-httpmsg http://127.0.0.1:$port/x \ |
| 1147 | 1160 | payload.txt --xfer {*}$args |
| 1148 | - url_listen_stop | |
| 1161 | + test_listen_stop | |
| 1149 | 1162 | } |
| 1150 | 1163 | url_xfer_reply text/html "<p>no <b>such</b> page</p>" -v |
| 1151 | 1164 | test url-xfer-error-verbose {$CODE == 1 && |
| 1152 | 1165 | [string first "server sends error: no such page" $RESULT] >= 0} |
| 1153 | 1166 | url_xfer_reply text/html "plain text, no tags" -v |
| @@ -1157,12 +1170,11 @@ | ||
| 1157 | 1170 | test url-xfer-error-open-tag {$CODE == 1 && |
| 1158 | 1171 | [string first "server sends error: cut short " $RESULT] >= 0} |
| 1159 | 1172 | file delete out.txt |
| 1160 | 1173 | url_xfer_reply text/html "<p>no such page</p>" --out out.txt |
| 1161 | 1174 | 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"}]} | |
| 1164 | 1176 | url_xfer_reply text/html "<p>no such page</p>" |
| 1165 | 1177 | test url-xfer-error-quiet {$CODE == 1 && |
| 1166 | 1178 | [string first "server sends error" $RESULT] < 0} |
| 1167 | 1179 | url_xfer_reply application/x-fossil-debug "debug reply" |
| 1168 | 1180 | test url-xfer-reply-debug {$CODE == 0 && $RESULT eq "debug reply"} |
| @@ -1175,12 +1187,11 @@ | ||
| 1175 | 1187 | # The file: transport. test-httpmsg sends the request for the path |
| 1176 | 1188 | # given by --subpath to "fossil http" on the repository file. |
| 1177 | 1189 | |
| 1178 | 1190 | fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /test-env |
| 1179 | 1191 | 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"}]} | |
| 1182 | 1193 | fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath /nosuchpage -v |
| 1183 | 1194 | test url-file-not-found {$CODE == 1 && |
| 1184 | 1195 | [string first "server says: 404 Not Found" $RESULT] >= 0} |
| 1185 | 1196 | fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath / -v |
| 1186 | 1197 | test url-file-redirect {$CODE == 1 && |
| @@ -1191,21 +1202,25 @@ | ||
| 1191 | 1202 | ############################################################################### |
| 1192 | 1203 | # Clone, pull and sync against the server of this file. |
| 1193 | 1204 | |
| 1194 | 1205 | # Returns the reply header for a sync reply with the body BODY. |
| 1195 | 1206 | 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 | |
| 1197 | 1212 | } |
| 1198 | 1213 | set urlNotFound [url_crlf "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n"] |
| 1199 | 1214 | |
| 1200 | 1215 | # Runs "fossil VERB URL" with the options in ARGS, where "PORT" in URL |
| 1201 | 1216 | # and in ARGS stands for the port of a server that answers with REPLIES. |
| 1202 | 1217 | proc url_sync {verb url replies args} { |
| 1203 | 1218 | set port [url_listen $replies] |
| 1204 | 1219 | set map [list PORT $port] |
| 1205 | 1220 | fossil_raw -seconds 60 $verb [string map $map $url] {*}[string map $map $args] |
| 1206 | - url_listen_stop | |
| 1221 | + test_listen_stop | |
| 1207 | 1222 | return $port |
| 1208 | 1223 | } |
| 1209 | 1224 | |
| 1210 | 1225 | # A proxy gets the whole URL in the request line and its own user and |
| 1211 | 1226 | # password in a Proxy-Authorization header. |
| @@ -1240,11 +1255,10 @@ | ||
| 1240 | 1255 | |
| 1241 | 1256 | # A proxy is an http: or https: URL. With any other value fossil must |
| 1242 | 1257 | # not talk to the repository that the value names in place of the |
| 1243 | 1258 | # remote. |
| 1244 | 1259 | # |
| 1245 | -file delete proxyclone.fossil | |
| 1246 | 1260 | fossil_raw -seconds 60 clone http://example.invalid/repo proxyclone.fossil \ |
| 1247 | 1261 | --proxy file://$urlRepo |
| 1248 | 1262 | test url-sync-proxy-file {$CODE == 1 && ![file exists proxyclone.fossil]} |
| 1249 | 1263 | file delete proxyclone.fossil |
| 1250 | 1264 | |
| @@ -1290,11 +1304,12 @@ | ||
| 1290 | 1304 | # that is redirected with 302 or 307 does not. |
| 1291 | 1305 | # |
| 1292 | 1306 | foreach {urlStatus urlRemembered} {301 1 308 1 302 0 307 0} { |
| 1293 | 1307 | fossil remote off |
| 1294 | 1308 | 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"] \ | |
| 1296 | 1311 | $urlNotFound]] |
| 1297 | 1312 | fossil remote |
| 1298 | 1313 | test_eq url-sync-redirect-$urlStatus-remembered [string trim $RESULT] \ |
| 1299 | 1314 | [expr {$urlRemembered ? "http://127.0.0.1:$urlPort/new" : "off"}] |
| 1300 | 1315 | } |
| @@ -1324,11 +1339,11 @@ | ||
| 1324 | 1339 | url_parse_test url-sync-saved-password saved {--use-config --show-pw} \ |
| 1325 | 1340 | {user bob passwd secret pwConfig sync-pw:saved} |
| 1326 | 1341 | set urlPort [url_listen [list $urlPullOk]] |
| 1327 | 1342 | url_config sync-url:saved 'http://[email protected]:$urlPort/repo' |
| 1328 | 1343 | fossil_raw -seconds 60 pull saved --once --httptrace |
| 1329 | -url_listen_stop | |
| 1344 | +test_listen_stop | |
| 1330 | 1345 | file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt] |
| 1331 | 1346 | test url-sync-saved-remote {$CODE == 0 && [url_login_ok 0 bob $urlSecret]} |
| 1332 | 1347 | url_parse_test url-sync-saved-password-hashed saved {--use-config --show-pw} \ |
| 1333 | 1348 | [list user bob passwd $urlSecret] |
| 1334 | 1349 | fossil remote delete saved |
| @@ -1348,11 +1363,11 @@ | ||
| 1348 | 1363 | fossil remote add saved http://bob:[email protected]:1/repo |
| 1349 | 1364 | set urlPort [url_listen [list $urlPullOk]] |
| 1350 | 1365 | url_config sync-url:saved 'http://[email protected]:$urlPort/repo' |
| 1351 | 1366 | url_config parent-project-code 'parentcode' |
| 1352 | 1367 | fossil_raw -seconds 60 pull saved --from-parent-project |
| 1353 | -url_listen_stop | |
| 1368 | +test_listen_stop | |
| 1354 | 1369 | url_parse_test url-sync-parent-remembered default {--use-parent --show-pw} \ |
| 1355 | 1370 | [list name 127.0.0.1 port $urlPort user bob \ |
| 1356 | 1371 | passwd [sha1_text parentcode/bob/secret] pwConfig parent-project-pw] |
| 1357 | 1372 | fossil remote |
| 1358 | 1373 | test_eq url-sync-parent-not-default [string trim $RESULT] off |
| @@ -1360,21 +1375,20 @@ | ||
| 1360 | 1375 | fossil sql "DELETE FROM config WHERE name GLOB 'parent-project-*'" |
| 1361 | 1376 | |
| 1362 | 1377 | # A clone that fails with --httptrace prints the last reply. When there |
| 1363 | 1378 | # is no reply it prints none. |
| 1364 | 1379 | # |
| 1365 | -file delete traceclone.fossil | |
| 1366 | 1380 | url_sync clone http://127.0.0.1:PORT/repo [list \ |
| 1367 | 1381 | [url_sync_reply "error not\\sallowed\\shere\n"]] traceclone.fossil \ |
| 1368 | 1382 | --httptrace |
| 1369 | 1383 | test url-sync-clone-httptrace {$CODE == 1 && |
| 1370 | 1384 | ![file exists traceclone.fossil] && |
| 1371 | 1385 | [string first "server returned an error - clone aborted" $RESULT] >= 0 && |
| 1372 | 1386 | [regexp {clone aborted\s+HTTP/1.1 200 OK} $RESULT]} |
| 1373 | 1387 | file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt] |
| 1374 | 1388 | set urlPort [url_listen {}] |
| 1375 | -url_listen_stop | |
| 1389 | +test_listen_stop | |
| 1376 | 1390 | fossil_raw -seconds 60 clone http://127.0.0.1:$urlPort/repo traceclone.fossil \ |
| 1377 | 1391 | --httptrace |
| 1378 | 1392 | test url-sync-clone-httptrace-no-reply {$CODE == 1 && |
| 1379 | 1393 | ![file exists traceclone.fossil] && |
| 1380 | 1394 | [string first "cannot connect to host 127.0.0.1:$urlPort" $RESULT] >= 0} |
| @@ -1394,11 +1408,12 @@ | ||
| 1394 | 1408 | [string first "Transport command failed: " $RESULT] >= 0 && |
| 1395 | 1409 | [regexp -line {^RUN .*transport-fail.sh '?http://u:p@h:81/x'? } $RESULT]} |
| 1396 | 1410 | fossil_raw pull {http://u:p@[::1]/x} --once \ |
| 1397 | 1411 | --transport-command [file join $urlDir transport-fail.sh] --httptrace |
| 1398 | 1412 | 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]} | |
| 1400 | 1415 | fossil_raw pull file://$urlRepo --once \ |
| 1401 | 1416 | --transport-command [file join $urlDir transport-fail.sh] --httptrace |
| 1402 | 1417 | test url-transport-url-file {[regexp -line \ |
| 1403 | 1418 | "^RUN .*transport-fail.sh '?file://$urlRepo'? " $RESULT]} |
| 1404 | 1419 | } |
| @@ -1406,26 +1421,31 @@ | ||
| 1406 | 1421 | ############################################################################### |
| 1407 | 1422 | # The sync button of the /xfersetup page syncs with the saved remote. A |
| 1408 | 1423 | # remote with a user and no saved password gets a message, not a login |
| 1409 | 1424 | # card. |
| 1410 | 1425 | |
| 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"] ""]] | |
| 1412 | 1432 | set urlPort [url_listen [list $urlPullOk]] |
| 1413 | 1433 | url_config last-sync-url 'http://[email protected]:$urlPort/repo' |
| 1414 | 1434 | url_config last-sync-pw obscure('secret') |
| 1415 | 1435 | fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \ |
| 1416 | 1436 | --localauth |
| 1417 | -url_listen_stop | |
| 1437 | +test_listen_stop | |
| 1418 | 1438 | test url-web-sync {[string first "HTTP/1.0 200 OK" $RESULT] == 0 && |
| 1419 | 1439 | [llength $urlRequests] == 1 && |
| 1420 | 1440 | [string first "Sync done" $RESULT] >= 0} |
| 1421 | 1441 | set urlPort [url_listen [list $urlPullOk]] |
| 1422 | 1442 | fossil sql "DELETE FROM config WHERE name='last-sync-pw'" |
| 1423 | 1443 | url_config last-sync-url 'http://[email protected]:$urlPort/repo' |
| 1424 | 1444 | fossil_raw -seconds 60 http --in xfersetup.txt --ipaddr 127.0.0.1 $urlRepo \ |
| 1425 | 1445 | --localauth |
| 1426 | -url_listen_stop | |
| 1446 | +test_listen_stop | |
| 1427 | 1447 | test url-web-sync-no-password {[string first "HTTP/1.0 200 OK" $RESULT] == 0 && |
| 1428 | 1448 | [string first "incorrect or missing password for user bob" $RESULT] >= 0} |
| 1429 | 1449 | fossil sql "DELETE FROM config WHERE name GLOB 'last-sync-*'" |
| 1430 | 1450 | |
| 1431 | 1451 | ############################################################################### |
| @@ -1561,11 +1581,12 @@ | ||
| 1561 | 1581 | proc url_ssh_runs {} { |
| 1562 | 1582 | set file [file join $::urlSshDir count] |
| 1563 | 1583 | return [expr {[file exists $file] ? [string trim [read_file $file]] : 0}] |
| 1564 | 1584 | } |
| 1565 | 1585 | |
| 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 | |
| 1567 | 1588 | |
| 1568 | 1589 | # The reply of "fossil test-http" on the server begins with a Status |
| 1569 | 1590 | # line. The request says that it comes over ssh. |
| 1570 | 1591 | # |
| 1571 | 1592 | url_ssh [list $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x |
| @@ -1577,11 +1598,12 @@ | ||
| 1577 | 1598 | test-httpmsg ssh://hh/dir/r.fossil --subpath /x |
| 1578 | 1599 | test url-ssh-reply-http-status {$CODE == 0 && $RESULT eq "hello"} |
| 1579 | 1600 | url_ssh [list [url_crlf "STATUS: 200\ncontent-length: 5\n\n"]hello] \ |
| 1580 | 1601 | test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x |
| 1581 | 1602 | 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] \ | |
| 1583 | 1605 | test-httpmsg ssh://hh/dir/r.fossil --subpath /x |
| 1584 | 1606 | test url-ssh-reply-both-status-lines {$CODE == 0 && $RESULT eq "hello"} |
| 1585 | 1607 | |
| 1586 | 1608 | foreach {urlName urlReply urlMessage} [list \ |
| 1587 | 1609 | status-500 "Status: 500 Server Error\n\n" {server says: 500 Server Error} \ |
| @@ -1600,17 +1622,22 @@ | ||
| 1600 | 1622 | url_ssh [list [url_crlf $urlReply]] \ |
| 1601 | 1623 | test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x -v |
| 1602 | 1624 | test_match url-ssh-refused-$urlName "$CODE $RESULT" \ |
| 1603 | 1625 | "^1 (?:.*\n)*.*$urlMessage" |
| 1604 | 1626 | } |
| 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"]] \ | |
| 1606 | 1629 | test-httpmsg ssh://hh/dir/r.fossil --subpath /x |
| 1607 | 1630 | test url-ssh-redirect-quiet {$CODE == 1 && $RESULT eq ""} |
| 1608 | 1631 | |
| 1609 | 1632 | # A sync request over ssh has no login card. |
| 1610 | 1633 | # |
| 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] \ | |
| 1612 | 1639 | test-httpmsg ssh://bob:secret@hh/dir/r.fossil --subpath /x \ |
| 1613 | 1640 | payload.txt --xfer -v |
| 1614 | 1641 | test url-ssh-no-login-card {$CODE == 0 && |
| 1615 | 1642 | [string first "13 byte payload" $RESULT] >= 0 && |
| 1616 | 1643 | [string first "<bob@hh>" $urlSshArgs] >= 0} |
| @@ -1621,14 +1648,15 @@ | ||
| 1621 | 1648 | # |
| 1622 | 1649 | url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \ |
| 1623 | 1650 | --out out.txt |
| 1624 | 1651 | test url-ssh-retry-with-path {$CODE == 0 && [url_ssh_runs] == 2 && |
| 1625 | 1652 | [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>} \ | |
| 1630 | 1658 | $urlSshArgs]} |
| 1631 | 1659 | url_ssh [list "" $urlSshOk] test-httpmsg ssh://hh/dir/r.fossil --subpath /x |
| 1632 | 1660 | test url-ssh-retry-quiet {$CODE == 0 && [url_ssh_runs] == 2 && |
| 1633 | 1661 | $RESULT eq "hello"} |
| 1634 | 1662 | url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \ |
| @@ -1702,8 +1730,7 @@ | ||
| 1702 | 1730 | unset env(URL_SSH_DIR) |
| 1703 | 1731 | } |
| 1704 | 1732 | |
| 1705 | 1733 | ############################################################################### |
| 1706 | 1734 | |
| 1707 | -url_listen_stop | |
| 1708 | 1735 | array set env [array get urlSavedEnv] |
| 1709 | 1736 | test_cleanup |
| 1710 | 1737 |
| --- 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 |
+18
-60
| --- test/xfer-client.test | ||
| +++ test/xfer-client.test | ||
| @@ -7,15 +7,12 @@ | ||
| 7 | 7 | # timestamp, which ends the sync. |
| 8 | 8 | # |
| 9 | 9 | # xfer-server.test tests the server side. |
| 10 | 10 | # |
| 11 | 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 | - | |
| 12 | +# The first sections run at every level, and the rest need | |
| 13 | +# -assurance stress. | |
| 17 | 14 | require_no_open_checkout |
| 18 | 15 | |
| 19 | 16 | if {$::tcl_platform(platform) eq "windows"} { |
| 20 | 17 | test_skip "the stand-in for a server is a shell script" |
| 21 | 18 | } |
| @@ -38,21 +35,11 @@ | ||
| 38 | 35 | # Run "fossil VERB" against the stand-in, which answers request N with |
| 39 | 36 | # item N of the list REPLIES. Further arguments are options for the |
| 40 | 37 | # command. Sets xferclientCode to the exit status, or to "crash", and |
| 41 | 38 | # xferclientOut to what fossil printed. |
| 42 | 39 | 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 | |
| 54 | 41 | } |
| 55 | 42 | |
| 56 | 43 | # Like xferclient_sync, for the server at URL. |
| 57 | 44 | proc xferclient_sync_url {verb url replies args} { |
| 58 | 45 | global xferclientDir xferclientWire xferclientCode xferclientOut |
| @@ -201,10 +188,14 @@ | ||
| 201 | 188 | && [regexp -line "^pull \\S+ $xferclientParentCode\$" \ |
| 202 | 189 | [xferclient_request 1]]} |
| 203 | 190 | fossil sql "REPLACE INTO config(name,value,mtime) |
| 204 | 191 | VALUES('project-code','$xferclientOwnCode',now())" |
| 205 | 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 | +} | |
| 206 | 197 | |
| 207 | 198 | ############################################################################### |
| 208 | 199 | # igot and gimme. What the client asks for, or sends, shows in its |
| 209 | 200 | # second request. |
| 210 | 201 | |
| @@ -335,21 +326,12 @@ | ||
| 335 | 326 | 3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532 |
| 336 | 327 | xferclient_expect uvfile-refused-in-pull pull \ |
| 337 | 328 | "uvfile note.txt 2000000001 $xferclientAbcHash 3 0\nabc\n" 1 {} \ |
| 338 | 329 | "unknown command" |
| 339 | 330 | 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" | |
| 351 | 333 | |
| 352 | 334 | ############################################################################### |
| 353 | 335 | # Each card that has a fixed number of words, and each word that selects a |
| 354 | 336 | # card, decides alone whether the card is acted on. A card of the wrong |
| 355 | 337 | # number of words, or with a first word that has the length of a card name |
| @@ -426,11 +408,10 @@ | ||
| 426 | 408 | xferclient_run pull $xferclientCard --share-links |
| 427 | 409 | fossil sql "SELECT count(*) FROM config WHERE name LIKE 'link:%'" |
| 428 | 410 | test_eq xfer-client-mcdc-link-$xferclientName \ |
| 429 | 411 | "$xferclientCode [string trim $RESULT]" "0 $xferclientKept" |
| 430 | 412 | } |
| 431 | -fossil sql "DELETE FROM config WHERE name LIKE 'link:%'" | |
| 432 | 413 | |
| 433 | 414 | ############################################################################### |
| 434 | 415 | # A "private" card makes the next file private. A client that does not sync |
| 435 | 416 | # private content ignores that file, whatever its content; one that does |
| 436 | 417 | # keeps it and marks it private. |
| @@ -724,57 +705,38 @@ | ||
| 724 | 705 | test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc |
| 725 | 706 | xferclient_clone [list "clone_seqno 2\n$xferclientPush" \ |
| 726 | 707 | "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"] |
| 727 | 708 | test xfer-client-mcdc-clone-stops-when-nothing-arrives \ |
| 728 | 709 | {$xferclientCode == 0 && [xferclient_requests] == 2} |
| 729 | -file delete clone.fossil | |
| 730 | 710 | |
| 731 | 711 | ############################################################################### |
| 732 | 712 | # What a sync with -v says at its end about the server. A server that |
| 733 | 713 | # could not be reached is named as the URL names it, with no address. The |
| 734 | 714 | # URLs here have no host; the one for ssh is given standin/log-args.sh as |
| 735 | 715 | # its ssh command, which exits at once. |
| 736 | 716 | |
| 737 | 717 | 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"]]} | |
| 741 | 720 | set xferclientSsh \ |
| 742 | 721 | [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]] |
| 743 | 722 | set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt] |
| 744 | 723 | 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"]]} | |
| 749 | 727 | unset ::env(ARGS_LOG) |
| 750 | 728 | |
| 751 | 729 | ############################################################################### |
| 752 | 730 | # What shows only when the client speaks HTTP. The server is made here: it |
| 753 | 731 | # answers request N with item N of the list xferclientHttpReplies, or with |
| 754 | 732 | # a bare timestamp where that is empty, and keeps the header and the cards |
| 755 | 733 | # of each request in the list xferclientHttpRequests. |
| 756 | 734 | |
| 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 | |
| 766 | 737 | 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 | 738 | # The cards follow four bytes of size when they are compressed. |
| 777 | 739 | set header [string range $request 0 $end+1] |
| 778 | 740 | set cards [string range $request $end+4 end] |
| 779 | 741 | catch {set cards [zlib decompress [string range $cards 4 end]]} |
| 780 | 742 | set reply [lindex $xferclientHttpReplies [llength $xferclientHttpRequests]] |
| @@ -802,13 +764,11 @@ | ||
| 802 | 764 | set xferclientCode $::CODE |
| 803 | 765 | set xferclientOut $::RESULT |
| 804 | 766 | } |
| 805 | 767 | |
| 806 | 768 | 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] | |
| 810 | 770 | |
| 811 | 771 | # The login card goes in front of the cards of a request. Once the |
| 812 | 772 | # server has said that it is of version 2.27 or later and was built at or |
| 813 | 773 | # after 11:05:00 on 2025-07-27, the card goes in a cookie instead. The |
| 814 | 774 | # second request shows where the client puts it. |
| @@ -867,14 +827,12 @@ | ||
| 867 | 827 | test xfer-client-mcdc-autopush-$xferclientName {$xferclientCode == 0 |
| 868 | 828 | && [string trim $RESULT] == 1 |
| 869 | 829 | && [llength $xferclientHttpRequests] == 2 |
| 870 | 830 | && [holds_strings $xferclientOut $xferclientSaid]} |
| 871 | 831 | } |
| 872 | - fossil remote off | |
| 873 | - fossil settings autosync off | |
| 874 | - close $xferclientHttpServer | |
| 832 | + test_listen_stop | |
| 875 | 833 | } |
| 876 | 834 | |
| 877 | 835 | ############################################################################### |
| 878 | 836 | |
| 879 | 837 | unset ::env(TRANSPORT_DIR) |
| 880 | 838 | test_cleanup |
| 881 | 839 |
| --- 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 |
+69
-93
| --- test/xfer-server.test | ||
| +++ test/xfer-server.test | ||
| @@ -7,15 +7,12 @@ | ||
| 7 | 7 | # "fossil test-xfer" treats a login card as a grant of the Read, Write, |
| 8 | 8 | # Private and Admin permissions. A message without a login card runs |
| 9 | 9 | # with the permissions of the user "nobody", which these tests set. |
| 10 | 10 | # |
| 11 | 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 | - | |
| 12 | +# The first sections run at every level, and the rest need | |
| 13 | +# -assurance stress. | |
| 17 | 14 | require_no_open_checkout |
| 18 | 15 | |
| 19 | 16 | test_setup |
| 20 | 17 | |
| 21 | 18 | write_file a.txt "hello world\n" |
| @@ -307,10 +304,14 @@ | ||
| 307 | 304 | "$xferserverLogin$xferserverPush$xferserverCard" \ |
| 308 | 305 | "!Database error" $xferserverWant |
| 309 | 306 | } |
| 310 | 307 | test_eq xfer-server-hash-zero-byte-nothing-stored \ |
| 311 | 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 | +} | |
| 312 | 313 | |
| 313 | 314 | # Clone, in each version of the protocol. A login card to test-xfer does |
| 314 | 315 | # not grant the Clone permission, so "nobody" is given it and these |
| 315 | 316 | # messages have no login card. |
| 316 | 317 | xferserver_caps "g" |
| @@ -427,11 +428,12 @@ | ||
| 427 | 428 | xferserver_set gitpush:[email protected]:someone/other.git "{}" |
| 428 | 429 | xferserver_send "${xferserverPull}pragma req-links\n" |
| 429 | 430 | test xfer-server-read-req-links-git-address \ |
| 430 | 431 | {$CODE == 0 && [string first "errors 0" $RESULT] >= 0} |
| 431 | 432 | 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]} | |
| 433 | 435 | test xfer-server-read-req-links-git-other-left-out \ |
| 434 | 436 | {![string match "*other.git*" $RESULT]} |
| 435 | 437 | xferserver_unset gitpush:* |
| 436 | 438 | |
| 437 | 439 | # The address configuration is given only to a client that may read |
| @@ -528,12 +530,10 @@ | ||
| 528 | 530 | xferserver_enter cards |
| 529 | 531 | |
| 530 | 532 | set xferserverCardsContent "hello world\n" |
| 531 | 533 | set xferserverCardsSize [string length $xferserverCardsContent] |
| 532 | 534 | write_file a.txt $xferserverCardsContent |
| 533 | -fossil add a.txt | |
| 534 | -fossil commit -m one --no-warnings | |
| 535 | 535 | fossil sha3sum a.txt |
| 536 | 536 | set xferserverCardsHash [lindex $RESULT 0] |
| 537 | 537 | |
| 538 | 538 | fossil init tgt.fossil -A tester |
| 539 | 539 | fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'" |
| @@ -578,18 +578,20 @@ | ||
| 578 | 578 | "file $xferserverCardsHash zz\ |
| 579 | 579 | $xferserverCardsSize\n$xferserverCardsContent" \ |
| 580 | 580 | size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \ |
| 581 | 581 | size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \ |
| 582 | 582 | 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" \ | |
| 584 | 585 | content-wrong-hash \ |
| 585 | 586 | "file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \ |
| 586 | 587 | cfile-too-few "cfile $xferserverCardsHash\n" \ |
| 587 | 588 | cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \ |
| 588 | 589 | uvfile-too-few "uvfile note.txt\n" \ |
| 589 | 590 | 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" \ | |
| 591 | 593 | uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \ |
| 592 | 594 | uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \ |
| 593 | 595 | uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \ |
| 594 | 596 | uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \ |
| 595 | 597 | uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \ |
| @@ -598,27 +600,10 @@ | ||
| 598 | 600 | test xfer-cards-reject-$xferserverCardsName \ |
| 599 | 601 | {$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 && |
| 600 | 602 | $xferserverCardsStored == 0} |
| 601 | 603 | } |
| 602 | 604 | |
| 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 | 605 | fossil sql -R tgt.fossil \ |
| 621 | 606 | "INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)" |
| 622 | 607 | xferserver_cards_push "file $xferserverCardsHash\ |
| 623 | 608 | $xferserverCardsSize\n$xferserverCardsContent" |
| 624 | 609 | test xfer-cards-reject-shunned \ |
| @@ -630,23 +615,17 @@ | ||
| 630 | 615 | # More cards sent to the server side of the sync protocol through |
| 631 | 616 | # "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme" |
| 632 | 617 | # and "uvgimme" that xfer-cards.test and xfer-server.test do not send. |
| 633 | 618 | # Each has a stated effect on the server's repository or on the reply, |
| 634 | 619 | # 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 | 620 | |
| 641 | 621 | xferserver_enter edge |
| 642 | 622 | |
| 643 | 623 | # The answer of one SQL statement on the server, trimmed. |
| 644 | 624 | # |
| 645 | 625 | proc xferserver_sql {sql} { |
| 646 | - fossil sql -R srv.fossil $sql | |
| 647 | - return [string trim $::RESULT] | |
| 626 | + return [fossil_sql $sql srv.fossil] | |
| 648 | 627 | } |
| 649 | 628 | |
| 650 | 629 | # Send the cards BODY to the server after a client-version card and a |
| 651 | 630 | # card of KIND, which is "push" or "pull". RESULT is the reply, as |
| 652 | 631 | # bytes. xferserverEdgeErrors is the number of errors that the reply reports, |
| @@ -658,18 +637,10 @@ | ||
| 658 | 637 | fossil_raw test-xfer -R srv.fossil msg.txt |
| 659 | 638 | set xferserverEdgeErrors -1 |
| 660 | 639 | regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors |
| 661 | 640 | } |
| 662 | 641 | |
| 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 | 642 | # Content as a "cfile" card carries it: the size, then the zlib stream. |
| 672 | 643 | # |
| 673 | 644 | proc xferserver_compress {text} { |
| 674 | 645 | return [binary format I [string length $text]][zlib compress $text] |
| 675 | 646 | } |
| @@ -716,11 +687,11 @@ | ||
| 716 | 687 | |
| 717 | 688 | ############################################################################### |
| 718 | 689 | # "file" cards. |
| 719 | 690 | |
| 720 | 691 | set xferserverEdgeNew "content that the server does not have yet\n" |
| 721 | -set xferserverEdgeNewHash [xferserver_hash $xferserverEdgeNew] | |
| 692 | +set xferserverEdgeNewHash [sha3_text $xferserverEdgeNew] | |
| 722 | 693 | set xferserverEdgeLen [string length $xferserverEdgeNew] |
| 723 | 694 | |
| 724 | 695 | foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
| 725 | 696 | too-many-tokens \ |
| 726 | 697 | "file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\ |
| @@ -799,11 +770,11 @@ | ||
| 799 | 770 | [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 800 | 771 | test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0} |
| 801 | 772 | test xfer-edge-cfile-wrong-hash-not-stored \ |
| 802 | 773 | {![xferserver_holds $xferserverEdgeAbsent]} |
| 803 | 774 | set xferserverEdgeSized "content with the wrong size on its card\n" |
| 804 | -set xferserverEdgeSizedHash [xferserver_hash $xferserverEdgeSized] | |
| 775 | +set xferserverEdgeSizedHash [sha3_text $xferserverEdgeSized] | |
| 805 | 776 | set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized] |
| 806 | 777 | xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\ |
| 807 | 778 | [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 808 | 779 | test xfer-edge-cfile-wrong-size \ |
| 809 | 780 | {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| @@ -814,11 +785,11 @@ | ||
| 814 | 785 | {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| 815 | 786 | ![xferserver_holds $xferserverEdgeAbsent]} |
| 816 | 787 | |
| 817 | 788 | # A shunned artifact is not stored. |
| 818 | 789 | set xferserverEdgeShun "content that the server has shunned\n" |
| 819 | -set xferserverEdgeShunHash [xferserver_hash $xferserverEdgeShun] | |
| 790 | +set xferserverEdgeShunHash [sha3_text $xferserverEdgeShun] | |
| 820 | 791 | xferserver_sql "INSERT INTO shun(uuid,mtime)\ |
| 821 | 792 | VALUES('$xferserverEdgeShunHash',0)" |
| 822 | 793 | set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun] |
| 823 | 794 | xferserver_edge_send push "cfile $xferserverEdgeShunHash\ |
| 824 | 795 | [string length $xferserverEdgeShun]\ |
| @@ -831,11 +802,11 @@ | ||
| 831 | 802 | # does not make content of the size on the card is refused. |
| 832 | 803 | set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4] |
| 833 | 804 | write_file delta-src.txt $xferserverEdgeVersion(1) |
| 834 | 805 | write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n" |
| 835 | 806 | 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]] | |
| 837 | 808 | set xferserverEdgeZ [xferserver_compress [read_file delta.out]] |
| 838 | 809 | xferserver_edge_send push "cfile $xferserverEdgeTgtHash\ |
| 839 | 810 | $xferserverEdgeAbsent2 7777\ |
| 840 | 811 | [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 841 | 812 | test xfer-edge-cfile-dangling-delta-wrong-size \ |
| @@ -867,16 +838,16 @@ | ||
| 867 | 838 | |
| 868 | 839 | # A compressed delta whose source the server has is applied and checked. |
| 869 | 840 | # One that does not apply, and one that makes content with another hash |
| 870 | 841 | # than the card gives, are refused; one that makes the content that the |
| 871 | 842 | # card names is stored. |
| 872 | -set xferserverEdgeSrcHash [xferserver_hash $xferserverEdgeVersion(1)] | |
| 843 | +set xferserverEdgeSrcHash [sha3_text $xferserverEdgeVersion(1)] | |
| 873 | 844 | test xfer-edge-cfile-delta-setup-source-held \ |
| 874 | 845 | {[xferserver_holds $xferserverEdgeSrcHash] == 1} |
| 875 | 846 | write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n" |
| 876 | 847 | 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]] | |
| 878 | 849 | set xferserverEdgeDelta [read_file delta2.out] |
| 879 | 850 | # The same delta without the checksum that ends it. |
| 880 | 851 | regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta |
| 881 | 852 | test xfer-edge-cfile-delta-setup-cut \ |
| 882 | 853 | {[string length $xferserverEdgeBadDelta] > 0 && |
| @@ -902,11 +873,11 @@ | ||
| 902 | 873 | |
| 903 | 874 | ############################################################################### |
| 904 | 875 | # "uvfile" cards. |
| 905 | 876 | |
| 906 | 877 | set xferserverEdgeUv "an unversioned note\n" |
| 907 | -set xferserverEdgeUvHash [xferserver_hash $xferserverEdgeUv] | |
| 878 | +set xferserverEdgeUvHash [sha3_text $xferserverEdgeUv] | |
| 908 | 879 | set xferserverEdgeUvLen [string length $xferserverEdgeUv] |
| 909 | 880 | proc xferserver_uv {name} { |
| 910 | 881 | return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL |
| 911 | 882 | FROM unversioned WHERE name='$name'"] |
| 912 | 883 | } |
| @@ -933,11 +904,11 @@ | ||
| 933 | 904 | test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \ |
| 934 | 905 | "1700000000|$xferserverEdgeUvLen|0|1" |
| 935 | 906 | |
| 936 | 907 | # Content that compresses well is stored compressed. |
| 937 | 908 | set xferserverEdgeBig [string repeat "the same line again and again\n" 200] |
| 938 | -set xferserverEdgeBigHash [xferserver_hash $xferserverEdgeBig] | |
| 909 | +set xferserverEdgeBigHash [sha3_text $xferserverEdgeBig] | |
| 939 | 910 | xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\ |
| 940 | 911 | [string length $xferserverEdgeBig] 0\n$xferserverEdgeBig" |
| 941 | 912 | test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \ |
| 942 | 913 | "1700000000|[string length $xferserverEdgeBig]|1|1" |
| 943 | 914 | |
| @@ -949,11 +920,11 @@ | ||
| 949 | 920 | "1700000500|$xferserverEdgeUvLen|0|1" |
| 950 | 921 | |
| 951 | 922 | # Older content does not replace newer. |
| 952 | 923 | set xferserverEdgeOld "an older note\n" |
| 953 | 924 | xferserver_edge_send push "uvfile note.txt 1600000000\ |
| 954 | -[xferserver_hash $xferserverEdgeOld]\ | |
| 925 | +[sha3_text $xferserverEdgeOld]\ | |
| 955 | 926 | [string length $xferserverEdgeOld] 0\n$xferserverEdgeOld" |
| 956 | 927 | test xfer-edge-uvfile-older {$CODE == 0} |
| 957 | 928 | test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash |
| 958 | 929 | FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash |
| 959 | 930 | |
| @@ -1307,12 +1278,11 @@ | ||
| 1307 | 1278 | --ipaddr $address srv.fossil {*}$args |
| 1308 | 1279 | set reply "" |
| 1309 | 1280 | if {[file exists http-reply.txt]} { |
| 1310 | 1281 | set reply [read_file http-reply.txt] |
| 1311 | 1282 | } |
| 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] | |
| 1314 | 1284 | } |
| 1315 | 1285 | |
| 1316 | 1286 | # The login card of USER with PASSWORD for a message of the cards BODY, |
| 1317 | 1287 | # with the nonce made from the cards NONCEBODY. |
| 1318 | 1288 | # |
| @@ -1380,11 +1350,10 @@ | ||
| 1380 | 1350 | VALUES('localauth',1,now())" |
| 1381 | 1351 | xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth |
| 1382 | 1352 | test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \ |
| 1383 | 1353 | {{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting} |
| 1384 | 1354 | "!igot "}]} |
| 1385 | -xferserver_sql "DELETE FROM config WHERE name='localauth'" | |
| 1386 | 1355 | |
| 1387 | 1356 | unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH) |
| 1388 | 1357 | unset ::env(SCN_PROJECT) |
| 1389 | 1358 | |
| 1390 | 1359 | xferserver_leave |
| @@ -1402,31 +1371,22 @@ | ||
| 1402 | 1371 | # artifact stored as a delta of another private one, and a public artifact |
| 1403 | 1372 | # stored as a delta of a public one. |
| 1404 | 1373 | |
| 1405 | 1374 | xferserver_enter mcdc |
| 1406 | 1375 | |
| 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 | 1376 | |
| 1418 | 1377 | # Test NAME passes when the reply to MESSAGE holds each of the strings |
| 1419 | 1378 | # given, and none that begins with "!". |
| 1420 | 1379 | proc xferserver_mcdc_expect {name message args} { |
| 1421 | - xferserver_mcdc_send $message | |
| 1380 | + xferserver_send $message | |
| 1422 | 1381 | test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]} |
| 1423 | 1382 | } |
| 1424 | 1383 | |
| 1425 | 1384 | set xferserverMcdcText "" |
| 1426 | 1385 | 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" | |
| 1428 | 1388 | } |
| 1429 | 1389 | write_file a.txt $xferserverMcdcText |
| 1430 | 1390 | fossil add a.txt |
| 1431 | 1391 | fossil commit -m public-1 --no-warnings |
| 1432 | 1392 | foreach xferserverMcdcI {2 3 4} { |
| @@ -1446,40 +1406,40 @@ | ||
| 1446 | 1406 | WHERE comment='private-2')" |
| 1447 | 1407 | fossil publish [string trim $RESULT] |
| 1448 | 1408 | fossil test-content-deltify [xferserverMcdc_fid public-1] \ |
| 1449 | 1409 | [xferserverMcdc_fid private-2] |
| 1450 | 1410 | file copy .rep.fossil srv.fossil |
| 1451 | -set xferserverMcdcPcode [xferserver_mcdc_sql \ | |
| 1411 | +set xferserverMcdcPcode [xferserver_sql \ | |
| 1452 | 1412 | "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= | |
| 1454 | 1414 | (SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"] |
| 1455 | 1415 | set xferserverMcdcLogin "login tester 0 0\n" |
| 1456 | 1416 | set xferserverMcdcPull "pull x $xferserverMcdcPcode\n" |
| 1457 | 1417 | 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'" | |
| 1459 | 1419 | # 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 | |
| 1461 | 1421 | rid IN (SELECT objid FROM event WHERE type='ci') |
| 1462 | 1422 | AND rid NOT IN (SELECT rid FROM private) LIMIT 1"] |
| 1463 | 1423 | |
| 1464 | 1424 | # 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, | |
| 1466 | 1426 | private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN |
| 1467 | 1427 | (SELECT rid FROM private) LIMIT 1"] |
| 1468 | 1428 | test xfer-server-mcdc-setup-private-delta \ |
| 1469 | 1429 | {[string length $xferserverMcdcDelta] >= 40} |
| 1470 | 1430 | foreach xferserverMcdcI {1 2} { |
| 1471 | - set xferserverMcdcFile($xferserverMcdcI) [xferserver_mcdc_sql \ | |
| 1431 | + set xferserverMcdcFile($xferserverMcdcI) [xferserver_sql \ | |
| 1472 | 1432 | "SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \ |
| 1473 | 1433 | [lindex {x public-1 private-2} $xferserverMcdcI]]"] |
| 1474 | 1434 | } |
| 1475 | 1435 | lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1 |
| 1476 | 1436 | 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 | |
| 1478 | 1438 | count(*) FROM delta d, private p WHERE d.rid= |
| 1479 | 1439 | [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 | |
| 1481 | 1441 | count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1] |
| 1482 | 1442 | AND d.srcid=[xferserverMcdc_fid private-2]"] == 1} |
| 1483 | 1443 | |
| 1484 | 1444 | ############################################################################### |
| 1485 | 1445 | # A lock on a check-in is reported to a second client with the name of the |
| @@ -1492,19 +1452,19 @@ | ||
| 1492 | 1452 | empty {json_object('login','','clientid',$A)} nobody |
| 1493 | 1453 | absent {json_object('clientid',$A)} nobody |
| 1494 | 1454 | } { |
| 1495 | 1455 | set xferserverMcdcValue [string map \ |
| 1496 | 1456 | [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-*'; | |
| 1498 | 1458 | REPLACE INTO config(name,value,mtime) |
| 1499 | 1459 | VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())" |
| 1500 | 1460 | xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \ |
| 1501 | 1461 | "$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\ |
| 1502 | 1462 | $xferserverMcdcTip $xferserverMcdcB\n" \ |
| 1503 | 1463 | "pragma ci-lock-fail $xferserverMcdcWho " |
| 1504 | 1464 | } |
| 1505 | -xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'" | |
| 1465 | +xferserver_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'" | |
| 1506 | 1466 | |
| 1507 | 1467 | ############################################################################### |
| 1508 | 1468 | # A clone of a server that has private artifacts. A client that does not |
| 1509 | 1469 | # ask for private content is sent none, and one that does is sent each of |
| 1510 | 1470 | # them behind a "private" card, a delta of a private artifact as a delta. |
| @@ -1511,11 +1471,13 @@ | ||
| 1511 | 1471 | |
| 1512 | 1472 | xferserver_mcdc_expect clone-no-private \ |
| 1513 | 1473 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| 1514 | 1474 | "cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta" |
| 1515 | 1475 | 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"] ""] \ | |
| 1517 | 1479 | "private\ncfile $xferserverMcdcDelta " |
| 1518 | 1480 | # A public artifact whose source is private is sent whole: the card names no |
| 1519 | 1481 | # source. |
| 1520 | 1482 | xferserver_mcdc_expect clone-public-from-private \ |
| 1521 | 1483 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| @@ -1528,11 +1490,13 @@ | ||
| 1528 | 1490 | "file $xferserverMcdcHash2 $xferserverMcdcSize2\n" |
| 1529 | 1491 | xferserver_mcdc_expect clone-v2-public-from-public \ |
| 1530 | 1492 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \ |
| 1531 | 1493 | "file $xferserverMcdcHash1 $xferserverMcdcHash2 " |
| 1532 | 1494 | 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"] ""] \ | |
| 1534 | 1498 | "private\nfile $xferserverMcdcDelta " |
| 1535 | 1499 | |
| 1536 | 1500 | ############################################################################### |
| 1537 | 1501 | # Artifacts named by a SHA1 hash. A client that does not state its version |
| 1538 | 1502 | # is taken to be older than 2.0: it is sent them, and gets an error in place |
| @@ -1543,37 +1507,39 @@ | ||
| 1543 | 1507 | set xferserverMcdcSha1 [lindex $RESULT 0] |
| 1544 | 1508 | xferserver_mcdc_expect push-sha1 \ |
| 1545 | 1509 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\ |
| 1546 | 1510 | $xferserverMcdcSha1 13\nsha1 content\n" "errors 0" |
| 1547 | 1511 | test xfer-server-mcdc-push-sha1-stored \ |
| 1548 | - {[xferserver_mcdc_sql "SELECT count(*) FROM blob WHERE | |
| 1512 | + {[xferserver_sql "SELECT count(*) FROM blob WHERE | |
| 1549 | 1513 | uuid='$xferserverMcdcSha1' AND size=13"] == 1} |
| 1550 | 1514 | xferserver_mcdc_expect old-client-gimme-sha1 \ |
| 1551 | 1515 | "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \ |
| 1552 | 1516 | "file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil" |
| 1553 | 1517 | xferserver_mcdc_expect old-client-gimme-sha3 \ |
| 1554 | 1518 | "${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" | |
| 1556 | 1521 | xferserver_mcdc_expect old-client-clone-sha1 \ |
| 1557 | 1522 | "${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} | |
| 1559 | 1525 | |
| 1560 | 1526 | ############################################################################### |
| 1561 | 1527 | # A server whose send limit is reached stops sending files and tells the |
| 1562 | 1528 | # client in "igot" cards, and in "uvigot" cards for unversioned files. |
| 1563 | 1529 | |
| 1564 | 1530 | write_file note.txt "hi\n" |
| 1565 | 1531 | 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) | |
| 1567 | 1533 | VALUES('max-download','1',now())" |
| 1568 | 1534 | xferserver_mcdc_expect uvgimme-limit \ |
| 1569 | 1535 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\ |
| 1570 | 1536 | note.txt\n" "uvigot note.txt " "!uvfile note.txt" |
| 1571 | 1537 | xferserver_mcdc_expect catalog-limit \ |
| 1572 | 1538 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\ |
| 1573 | 1539 | 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'" | |
| 1575 | 1541 | xferserver_mcdc_expect uvgimme-no-limit \ |
| 1576 | 1542 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\ |
| 1577 | 1543 | note.txt\n" "uvfile note.txt " "!uvigot" |
| 1578 | 1544 | |
| 1579 | 1545 | # A client that does not state its version is sent an unversioned file |
| @@ -1581,11 +1547,11 @@ | ||
| 1581 | 1547 | # a SHA3 hash. |
| 1582 | 1548 | fossil hash-policy sha1 -R srv.fossil |
| 1583 | 1549 | write_file old.txt "old\n" |
| 1584 | 1550 | fossil unversioned add old.txt -R srv.fossil |
| 1585 | 1551 | 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 | |
| 1587 | 1553 | group_concat(length(hash)) FROM (SELECT hash FROM unversioned |
| 1588 | 1554 | WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40" |
| 1589 | 1555 | xferserver_mcdc_expect old-client-uvgimme-sha1 \ |
| 1590 | 1556 | "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \ |
| 1591 | 1557 | "uvfile old.txt " "!error Fossil" |
| @@ -1595,30 +1561,40 @@ | ||
| 1595 | 1561 | |
| 1596 | 1562 | ############################################################################### |
| 1597 | 1563 | # A server has the number of seconds in max-download-time to make a reply. |
| 1598 | 1564 | # Once they have passed it sends no more artifacts: a client that asks for |
| 1599 | 1565 | # 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. | |
| 1602 | 1572 | |
| 1603 | 1573 | xferserver_mcdc_expect gimme-in-time \ |
| 1604 | 1574 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\ |
| 1605 | 1575 | $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 | |
| 1610 | 1586 | ('max-download-time','1',now()), |
| 1611 | 1587 | ('xfer-common-script','$xferserverMcdcBusy',now())" |
| 1612 | 1588 | xferserver_mcdc_expect gimme-out-of-time \ |
| 1613 | 1589 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\ |
| 1614 | 1590 | $xferserverMcdcPublic\n" \ |
| 1615 | 1591 | "igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0" |
| 1616 | 1592 | xferserver_mcdc_expect clone-out-of-time \ |
| 1617 | 1593 | "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| 1618 | 1594 | "clone_seqno 1\n" "!cfile " "errors 0" |
| 1619 | -xferserver_mcdc_sql "DELETE FROM config | |
| 1595 | +xferserver_sql "DELETE FROM config | |
| 1620 | 1596 | WHERE name IN ('max-download-time','xfer-common-script')" |
| 1621 | 1597 | |
| 1622 | 1598 | ############################################################################### |
| 1623 | 1599 | # A client that says where it can be reached is recorded when the address |
| 1624 | 1600 | # is an http or https one and does not name the local host. |
| @@ -1627,16 +1603,16 @@ | ||
| 1627 | 1603 | http http://example.org/a 1 |
| 1628 | 1604 | https https://example.org/b 1 |
| 1629 | 1605 | localhost http://localhost/c 0 |
| 1630 | 1606 | ssh ssh://example.org/d 0 |
| 1631 | 1607 | } { |
| 1632 | - xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'" | |
| 1608 | + xferserver_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'" | |
| 1633 | 1609 | xferserver_mcdc_expect client-url-$xferserverMcdcName \ |
| 1634 | 1610 | "${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\ |
| 1635 | 1611 | $xferserverMcdcUrl\n" "errors 0" |
| 1636 | 1612 | test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \ |
| 1637 | - {[xferserver_mcdc_sql "SELECT count(*) FROM config | |
| 1613 | + {[xferserver_sql "SELECT count(*) FROM config | |
| 1638 | 1614 | WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept} |
| 1639 | 1615 | } |
| 1640 | 1616 | |
| 1641 | 1617 | ############################################################################### |
| 1642 | 1618 | # "fossil test-xfer" reads the message from the file it is given, or from |
| 1643 | 1619 |
| --- 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 |