Fossil SCM
Add coverage tests for the CGI server, HTTP replies, login, configuration, content, crosslinking, the importers, names, purge, rebuild, sync, URLs, the xfer protocol and TH1, with tools/testbuild.sh, a fuzz corpus and a scenario stand-in.
Commit
94cb804bbdb3c242af0d8b87187ba6210c886bb4077be7d9f45be8053a7fe6ab
Parent
5c86b2ed386f5ff…
28 files changed
+5
-1
+1004
+2052
+1570
+26
+128
+30
+1631
+36
+81
+8
+109
-26
+47
+270
+20
+757
+914
+304
+439
+148
+80
+50
+704
+1709
+313
+99
+1
~
test/README.md
+
test/blob.test
+
test/cgi.test
+
test/config.test
+
test/content.test
+
test/corpus.tcl
+
test/corpus/corpus.pack
+
test/coverage-marks.txt
+
test/crosslink.test
+
test/derived.sql
+
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/standin/scenario-wire.tcl
~
test/sync.test
+
test/th1main.test
+
test/url.test
+
test/xfer-client.test
+
test/xfer-server.test
+
tools/testbuild.sh
+5
-1
| --- test/README.md | ||
| +++ test/README.md | ||
| @@ -94,10 +94,11 @@ | ||
| 94 | 94 | | a TCP connection over the loopback interface | `http`, `unversioned`, the HTTP tests in `sync`, and the HTTP clone in `powerloss` | |
| 95 | 95 | | `-assurance ci` or `stress` | `powerloss` | |
| 96 | 96 | | `openssl` and a Fossil built with TLS support | the HTTPS tests in `http` | |
| 97 | 97 | | `python3` | the tests in `http` that run `http-relay.py` | |
| 98 | 98 | | a C compiler (`cc`, or `CC`), `LD_PRELOAD`, `tools/powerloss/powerloss.c` from the source tree, and a Fossil that isn't statically linked | `powerloss` | |
| 99 | +| a Unix shell | `ssh`, `xfer-client`, and the no-reply and merge-tool tests in `sync` and `regress` | | |
| 99 | 100 | | `configure --json` | `json` | |
| 100 | 101 | | `configure --with-th1-docs` | `th1-docs` | |
| 101 | 102 | | `configure --with-th1-hooks` | `th1-hooks` | |
| 102 | 103 | | `configure --with-tcl` | `th1-tcl` | |
| 103 | 104 | |
| @@ -122,10 +123,13 @@ | ||
| 122 | 123 | | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` | |
| 123 | 124 | | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` | |
| 124 | 125 | | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` | |
| 125 | 126 | | JSON API | `json` | `smoke` | |
| 126 | 127 | | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` | |
| 128 | + | |
| 129 | +## Fuzz inputs and run-time checking | |
| 130 | + | |
| 127 | 131 | | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` | |
| 128 | 132 | |
| 129 | 133 | ## Writing new tests |
| 130 | 134 | |
| 131 | 135 | Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the |
| @@ -196,6 +200,6 @@ | ||
| 196 | 200 | * `release-checklist.wiki` lists the checks to make before a release, with the `.wiki` and `.md` pages they use. |
| 197 | 201 | * `many-www.tcl` requests about 10,000 web pages from an open checkout with `fossil test-http` and times each, to find crashes and slow pages. `valgrind-www.tcl` requests hundreds of pages under valgrind to find memory errors. |
| 198 | 202 | * `update-test-1.sh` and `update-test-2.sh` run `fossil update` scenarios in an empty directory. |
| 199 | 203 | * `link-tester.html` steps through a list of links in `fossil ui`, for checking each page by eye. |
| 200 | 204 | |
| 201 | -The remaining files are helper scripts and test data. | |
| 205 | +`http.test` runs `http-relay.py`, and `tools/testbuild.sh` reads `coverage-marks.txt`. The remaining files are helper scripts and test data. | |
| 202 | 206 | |
| 203 | 207 | ADDED test/blob.test |
| 204 | 208 | ADDED test/cgi.test |
| 205 | 209 | ADDED test/config.test |
| 206 | 210 | ADDED test/content.test |
| 207 | 211 | ADDED test/corpus.tcl |
| 208 | 212 | ADDED test/corpus/corpus.pack |
| 209 | 213 | ADDED test/coverage-marks.txt |
| 210 | 214 | ADDED test/crosslink.test |
| 211 | 215 | ADDED test/derived.sql |
| 212 | 216 | ADDED test/fuzz.test |
| 213 | 217 | ADDED test/import.test |
| --- test/README.md | |
| +++ test/README.md | |
| @@ -94,10 +94,11 @@ | |
| 94 | | a TCP connection over the loopback interface | `http`, `unversioned`, the HTTP tests in `sync`, and the HTTP clone in `powerloss` | |
| 95 | | `-assurance ci` or `stress` | `powerloss` | |
| 96 | | `openssl` and a Fossil built with TLS support | the HTTPS tests in `http` | |
| 97 | | `python3` | the tests in `http` that run `http-relay.py` | |
| 98 | | a C compiler (`cc`, or `CC`), `LD_PRELOAD`, `tools/powerloss/powerloss.c` from the source tree, and a Fossil that isn't statically linked | `powerloss` | |
| 99 | | `configure --json` | `json` | |
| 100 | | `configure --with-th1-docs` | `th1-docs` | |
| 101 | | `configure --with-th1-hooks` | `th1-hooks` | |
| 102 | | `configure --with-tcl` | `th1-tcl` | |
| 103 | |
| @@ -122,10 +123,13 @@ | |
| 122 | | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` | |
| 123 | | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` | |
| 124 | | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` | |
| 125 | | JSON API | `json` | `smoke` | |
| 126 | | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` | |
| 127 | | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` | |
| 128 | |
| 129 | ## Writing new tests |
| 130 | |
| 131 | Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the |
| @@ -196,6 +200,6 @@ | |
| 196 | * `release-checklist.wiki` lists the checks to make before a release, with the `.wiki` and `.md` pages they use. |
| 197 | * `many-www.tcl` requests about 10,000 web pages from an open checkout with `fossil test-http` and times each, to find crashes and slow pages. `valgrind-www.tcl` requests hundreds of pages under valgrind to find memory errors. |
| 198 | * `update-test-1.sh` and `update-test-2.sh` run `fossil update` scenarios in an empty directory. |
| 199 | * `link-tester.html` steps through a list of links in `fossil ui`, for checking each page by eye. |
| 200 | |
| 201 | The remaining files are helper scripts and test data. |
| 202 | |
| 203 | DDED test/blob.test |
| 204 | DDED test/cgi.test |
| 205 | DDED test/config.test |
| 206 | DDED test/content.test |
| 207 | DDED test/corpus.tcl |
| 208 | DDED test/corpus/corpus.pack |
| 209 | DDED test/coverage-marks.txt |
| 210 | DDED test/crosslink.test |
| 211 | DDED test/derived.sql |
| 212 | DDED test/fuzz.test |
| 213 | DDED test/import.test |
| --- test/README.md | |
| +++ test/README.md | |
| @@ -94,10 +94,11 @@ | |
| 94 | | a TCP connection over the loopback interface | `http`, `unversioned`, the HTTP tests in `sync`, and the HTTP clone in `powerloss` | |
| 95 | | `-assurance ci` or `stress` | `powerloss` | |
| 96 | | `openssl` and a Fossil built with TLS support | the HTTPS tests in `http` | |
| 97 | | `python3` | the tests in `http` that run `http-relay.py` | |
| 98 | | a C compiler (`cc`, or `CC`), `LD_PRELOAD`, `tools/powerloss/powerloss.c` from the source tree, and a Fossil that isn't statically linked | `powerloss` | |
| 99 | | a Unix shell | `ssh`, `xfer-client`, and the no-reply and merge-tool tests in `sync` and `regress` | |
| 100 | | `configure --json` | `json` | |
| 101 | | `configure --with-th1-docs` | `th1-docs` | |
| 102 | | `configure --with-th1-hooks` | `th1-hooks` | |
| 103 | | `configure --with-tcl` | `th1-tcl` | |
| 104 | |
| @@ -122,10 +123,13 @@ | |
| 123 | | Settings | `settings`, `settings-repo`, `set-manifest` | `smoke` | |
| 124 | | Wiki, attachments and unversioned files | `wiki`, `unversioned` | `smoke` | |
| 125 | | TH1 scripting | `th1`, `th1-docs`, `th1-hooks`, `th1-repo`, `th1-taint`, `th1-tcl` | `smoke` | |
| 126 | | JSON API | `json` | `smoke` | |
| 127 | | Parsing and file utilities | `cmdline`, `contains-selector`, `file1`, `glob`, `reserved-names`, `utf` | `smoke` | |
| 128 | |
| 129 | ## Fuzz inputs and run-time checking |
| 130 | |
| 131 | | Git export and import, bundles, patches, ZIP and tarball archives | `roundtrip` | |
| 132 | |
| 133 | ## Writing new tests |
| 134 | |
| 135 | Each `NAME.test` file is a Tcl script sourced by `tester.tcl`. `test_setup` creates and opens a repository in a temporary directory. `fossil ARGS` runs the |
| @@ -196,6 +200,6 @@ | |
| 200 | * `release-checklist.wiki` lists the checks to make before a release, with the `.wiki` and `.md` pages they use. |
| 201 | * `many-www.tcl` requests about 10,000 web pages from an open checkout with `fossil test-http` and times each, to find crashes and slow pages. `valgrind-www.tcl` requests hundreds of pages under valgrind to find memory errors. |
| 202 | * `update-test-1.sh` and `update-test-2.sh` run `fossil update` scenarios in an empty directory. |
| 203 | * `link-tester.html` steps through a list of links in `fossil ui`, for checking each page by eye. |
| 204 | |
| 205 | `http.test` runs `http-relay.py`, and `tools/testbuild.sh` reads `coverage-marks.txt`. The remaining files are helper scripts and test data. |
| 206 | |
| 207 | DDED test/blob.test |
| 208 | DDED test/cgi.test |
| 209 | DDED test/config.test |
| 210 | DDED test/content.test |
| 211 | DDED test/corpus.tcl |
| 212 | DDED test/corpus/corpus.pack |
| 213 | DDED test/coverage-marks.txt |
| 214 | DDED test/crosslink.test |
| 215 | DDED test/derived.sql |
| 216 | DDED test/fuzz.test |
| 217 | DDED test/import.test |
+1004
| --- a/test/blob.test | ||
| +++ b/test/blob.test | ||
| @@ -0,0 +1,1004 @@ | ||
| 1 | +# | |
| 2 | +# The buffer type that all of Fossil's text handling is built on: | |
| 3 | +# src/blob.c. The test commands that run its routines directly | |
| 4 | +# (test-isspace, test-atoi, test-strip-comment-lines, test-compress, | |
| 5 | +# test-compress-2, test-uncompress, test-cycle-compress, test-escaped-arg), | |
| 6 | +# reading and writing files, and the routines that are reached only | |
| 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. | |
| 22 | +# | |
| 23 | +proc blob_bytes {hex} { | |
| 24 | + return [binary format H* $hex] | |
| 25 | +} | |
| 26 | + | |
| 27 | +# The hexadecimal digits for the bytes in $bytes. | |
| 28 | +# | |
| 29 | +proc blob_hex {bytes} { | |
| 30 | + binary scan $bytes H* hex | |
| 31 | + return $hex | |
| 32 | +} | |
| 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. | |
| 44 | + | |
| 45 | +foreach {blobName blobArg blobOk32 blobVal32 blobOk64 blobVal64} { | |
| 46 | + zero 0 1 0 1 0 | |
| 47 | + one 1 1 1 1 1 | |
| 48 | + leading-0 0000000000000000000042 1 42 1 42 | |
| 49 | + max32 2147483647 1 2147483647 1 2147483647 | |
| 50 | + over32 2147483648 0 0 1 2147483648 | |
| 51 | + ten-digits 9999999999 0 0 1 9999999999 | |
| 52 | + max64 9223372036854775807 0 0 1 9223372036854775807 | |
| 53 | + over64 9223372036854775808 0 0 0 0 | |
| 54 | + over64-tens 9223372036854775810 0 0 0 0 | |
| 55 | + under64-tens 9223372036854775799 0 0 1 9223372036854775799 | |
| 56 | + twenty 10000000000000000000 0 0 0 0 | |
| 57 | + very-long 123456789012345678901234567890 0 0 0 0 | |
| 58 | + negative -1 0 0 0 0 | |
| 59 | + plus +1 0 0 0 0 | |
| 60 | + space-first { 1} 0 0 0 0 | |
| 61 | + space-last {1 } 0 0 0 0 | |
| 62 | + letter-last 12x 0 0 0 0 | |
| 63 | + letter-first x12 0 0 0 0 | |
| 64 | + hex 0x10 0 0 0 0 | |
| 65 | + colon 1: 0 0 0 0 | |
| 66 | + slash 1/ 0 0 0 0 | |
| 67 | + point 1.5 0 0 0 0 | |
| 68 | +} { | |
| 69 | + fossil test-atoi $blobArg | |
| 70 | + set blobGot [regexp {: 32-bit (\d) (\d+) +64-bit (\d) (\d+)$} \ | |
| 71 | + [string trim $RESULT] -> blobA blobB blobC blobD] | |
| 72 | + test blob-atoi-$blobName {$blobGot && $blobA == $blobOk32 && | |
| 73 | + $blobB eq $blobVal32 && $blobC == $blobOk64 && $blobD eq $blobVal64} | |
| 74 | +} | |
| 75 | + | |
| 76 | +# With no argument test-atoi prints nothing, and with three it prints | |
| 77 | +# three lines. | |
| 78 | +fossil test-atoi | |
| 79 | +test blob-atoi-none {$RESULT eq ""} | |
| 80 | +fossil test-atoi 1 2 3 | |
| 81 | +test blob-atoi-three {[llength [split [string trim $RESULT] \n]] == 3} | |
| 82 | + | |
| 83 | +############################################################################### | |
| 84 | +# test-strip-comment-lines removes the lines that begin with "#" and | |
| 85 | +# takes the backslash from the lines that begin with "\#". Each row: the | |
| 86 | +# content of the file and what must be printed. | |
| 87 | + | |
| 88 | +foreach {blobName blobIn blobOut} { | |
| 89 | + empty {} {} | |
| 90 | + plain "a\nb\n" "a\nb\n" | |
| 91 | + no-newline "a\nb" "a\nb" | |
| 92 | + comment "a\n#b\nc\n" "a\nc\n" | |
| 93 | + comment-first "#a\nb\n" "b\n" | |
| 94 | + comment-last "a\n#b" "a\n" | |
| 95 | + comment-only "#a" {} | |
| 96 | + comments-only "#a\n#b\n" {} | |
| 97 | + hash-inside "a#b\n #c\n" "a#b\n #c\n" | |
| 98 | + escaped "\\#a\nb\n" "#a\nb\n" | |
| 99 | + escaped-last "a\n\\#b" "a\n#b" | |
| 100 | + escaped-only "\\#" "#" | |
| 101 | + backslash "\\a\n\\\n" "\\a\n\\\n" | |
| 102 | + backslash-end "a\n\\" "a\n\\" | |
| 103 | + two-backslash "\\\\#a\n" "\\\\#a\n" | |
| 104 | + blank-lines "\n\n#\n\n" "\n\n\n" | |
| 105 | + crlf "a\r\n#b\r\nc\r\n" "a\r\nc\r\n" | |
| 106 | + nul-bytes "a\x00#b\n#c\x00\nd" "a\x00#b\nd" | |
| 107 | + only-newlines "\n\n" "\n\n" | |
| 108 | +} { | |
| 109 | + write_file strip-$blobName.txt $blobIn | |
| 110 | + fossil_raw test-strip-comment-lines strip-$blobName.txt | |
| 111 | + test blob-strip-$blobName {$CODE == 0 && $RESULT eq $blobOut} | |
| 112 | +} | |
| 113 | + | |
| 114 | +# A line of 100,000 bytes is kept whole, and a comment of that length is | |
| 115 | +# removed whole. | |
| 116 | +set blobLong [string repeat x 100000] | |
| 117 | +write_file strip-long.txt "$blobLong\n#$blobLong\n\\#$blobLong" | |
| 118 | +fossil_raw test-strip-comment-lines strip-long.txt | |
| 119 | +test blob-strip-long {$CODE == 0 && $RESULT eq "$blobLong\n#$blobLong"} | |
| 120 | + | |
| 121 | +# The file is read from standard input when its name is "-" or empty. | |
| 122 | +fossil_raw -input "a\n#b\nc\n" test-strip-comment-lines - | |
| 123 | +test blob-strip-stdin-dash {$CODE == 0 && $RESULT eq "a\nc\n"} | |
| 124 | +fossil_raw -input "#b\nc" test-strip-comment-lines {} | |
| 125 | +test blob-strip-stdin-empty-name {$CODE == 0 && $RESULT eq "c"} | |
| 126 | +fossil_raw -input "" test-strip-comment-lines - | |
| 127 | +test blob-strip-stdin-nothing {$CODE == 0 && $RESULT eq ""} | |
| 128 | +set blobBig [string repeat "line of text\n" 2000] | |
| 129 | +fossil_raw -input "#x\n$blobBig" test-strip-comment-lines - | |
| 130 | +test blob-strip-stdin-big {$CODE == 0 && $RESULT eq $blobBig} | |
| 131 | + | |
| 132 | +# --side-by-side shows the file beside what is left of it, and --width | |
| 133 | +# sets the width of each side. A width that is not positive is ignored. | |
| 134 | +write_file strip-sbs.txt "keep\n#drop\n\\#bare\n" | |
| 135 | +fossil_raw test-strip-comment-lines --side-by-side strip-sbs.txt | |
| 136 | +test blob-strip-sbs {$CODE == 0 && | |
| 137 | + [regexp {1 keep +1 keep} $RESULT] && [regexp {2 #drop +<} $RESULT] && | |
| 138 | + [regexp {3 \\#bare +\| +2 #bare} $RESULT]} | |
| 139 | +set blobWide [string length [lindex [split $RESULT \n] 0]] | |
| 140 | +fossil_raw test-strip-comment-lines -y -W 20 strip-sbs.txt | |
| 141 | +set blobNarrow [string length [lindex [split $RESULT \n] 0]] | |
| 142 | +test blob-strip-sbs-width {$CODE == 0 && $blobNarrow < $blobWide && | |
| 143 | + [regexp {1 keep +1 keep} $RESULT]} | |
| 144 | +foreach blobWidth {0 -5 x} { | |
| 145 | + fossil_raw test-strip-comment-lines -y -W $blobWidth strip-sbs.txt | |
| 146 | + test blob-strip-sbs-width-$blobWidth {$CODE == 0 && | |
| 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 | + | |
| 160 | +fossil_raw test-strip-comment-lines no-such-file.txt | |
| 161 | +test blob-read-missing {$CODE == 1 && | |
| 162 | + [string match "*no such file: no-such-file.txt*" $RESULT]} | |
| 163 | + | |
| 164 | +if {$::tcl_platform(platform) eq "unix" && $::tcl_platform(user) ne "root"} { | |
| 165 | + write_file read-closed.txt "text\n" | |
| 166 | + file attributes read-closed.txt -permissions 0000 | |
| 167 | + fossil_raw test-strip-comment-lines read-closed.txt | |
| 168 | + test blob-read-unreadable {$CODE == 1 && | |
| 169 | + [string match "*cannot open read-closed.txt for reading*" $RESULT]} | |
| 170 | + file attributes read-closed.txt -permissions 0644 | |
| 171 | +} | |
| 172 | + | |
| 173 | +# Outside a repository a symbolic link is followed to its file. | |
| 174 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 175 | + write_file read-target.txt "target\n#gone\n" | |
| 176 | + file link -symbolic read-link.txt read-target.txt | |
| 177 | + fossil_raw test-strip-comment-lines read-link.txt | |
| 178 | + test blob-read-link-followed {$CODE == 0 && $RESULT eq "target\n"} | |
| 179 | + write_file read-gone.txt "soon gone\n" | |
| 180 | + file link -symbolic read-dangling.txt read-gone.txt | |
| 181 | + file delete read-gone.txt | |
| 182 | + fossil_raw test-strip-comment-lines read-dangling.txt | |
| 183 | + test blob-read-link-dangling {$CODE == 1 && | |
| 184 | + [string match "*no such file: read-dangling.txt*" $RESULT]} | |
| 185 | +} | |
| 186 | + | |
| 187 | +# A name that begins with "-" and is longer is the name of a file. | |
| 188 | +write_file -dash.txt "dash\n#gone\n" | |
| 189 | +fossil_raw test-cycle-compress -dash.txt | |
| 190 | +test blob-read-dash-name {$CODE == 0 && $RESULT eq "ok\n"} | |
| 191 | +fossil_raw test-compress -dash.txt -dash.z | |
| 192 | +test blob-write-dash-name {$CODE == 0 && $RESULT eq "" && | |
| 193 | + [zlib decompress [string range [read_file -dash.z] 4 end]] eq | |
| 194 | + "dash\n#gone\n"} | |
| 195 | + | |
| 196 | +# A directory read as a file has no content. | |
| 197 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 198 | + file mkdir read-directory | |
| 199 | + fossil_raw test-strip-comment-lines read-directory | |
| 200 | + test blob-read-directory {$CODE == 0 && $RESULT eq ""} | |
| 201 | +} | |
| 202 | + | |
| 203 | +# test-safe-html prints an empty file as an empty line. | |
| 204 | +write_file read-empty.html "" | |
| 205 | +fossil_raw test-safe-html read-empty.html | |
| 206 | +test blob-read-empty-terminated {$CODE == 0 && $RESULT eq "\n"} | |
| 207 | + | |
| 208 | +############################################################################### | |
| 209 | +# test-compress writes the size of the content as four bytes, high byte | |
| 210 | +# first, and then the content as zlib compresses it. test-uncompress | |
| 211 | +# turns that back into the content. Each row: a name and the content. | |
| 212 | + | |
| 213 | +foreach {blobName blobContent} [list \ | |
| 214 | + empty {} \ | |
| 215 | + one-byte x \ | |
| 216 | + text "some text\nwith two lines\n" \ | |
| 217 | + nul-bytes "a\x00b\x00\x00c" \ | |
| 218 | + repeats [string repeat "0123456789" 30000] \ | |
| 219 | + bytes [blob_bytes [string repeat 00ff7f80c3a9 500]] \ | |
| 220 | +] { | |
| 221 | + set blobSize [string length $blobContent] | |
| 222 | + write_file z-$blobName.in $blobContent | |
| 223 | + fossil_raw test-compress z-$blobName.in z-$blobName.z | |
| 224 | + set blobZ [read_file z-$blobName.z] | |
| 225 | + test blob-compress-$blobName {$CODE == 0 && $RESULT eq "" && | |
| 226 | + [string range $blobZ 0 3] eq [binary format I $blobSize] && | |
| 227 | + [zlib decompress [string range $blobZ 4 end]] eq $blobContent} | |
| 228 | + fossil_raw test-uncompress z-$blobName.z z-$blobName.out | |
| 229 | + test blob-uncompress-$blobName {$CODE == 0 && $RESULT eq "" && | |
| 230 | + [read_file z-$blobName.out] eq $blobContent} | |
| 231 | +} | |
| 232 | + | |
| 233 | +# The 300,000 bytes of repeated digits compress to less than a hundredth. | |
| 234 | +test blob-compress-shrinks {[file size z-repeats.z] < 3000} | |
| 235 | + | |
| 236 | +# test-compress-2 compresses two files as one. Each row: the two | |
| 237 | +# contents. | |
| 238 | +foreach {blobName blobOne blobTwo} [list \ | |
| 239 | + both-empty {} {} \ | |
| 240 | + first-empty {} "second\n" \ | |
| 241 | + second-empty "first\n" {} \ | |
| 242 | + text "first\n" "second\n" \ | |
| 243 | + large [string repeat "abc\n" 50000] [string repeat "xyz\n" 50000] \ | |
| 244 | +] { | |
| 245 | + write_file z2-$blobName.1 $blobOne | |
| 246 | + write_file z2-$blobName.2 $blobTwo | |
| 247 | + set blobSize [string length $blobOne$blobTwo] | |
| 248 | + fossil_raw test-compress-2 z2-$blobName.1 z2-$blobName.2 z2-$blobName.z | |
| 249 | + set blobZ [read_file z2-$blobName.z] | |
| 250 | + test blob-compress2-$blobName {$CODE == 0 && $RESULT eq "" && | |
| 251 | + [string range $blobZ 0 3] eq [binary format I $blobSize] && | |
| 252 | + [zlib decompress [string range $blobZ 4 end]] eq "$blobOne$blobTwo"} | |
| 253 | + fossil_raw test-uncompress z2-$blobName.z z2-$blobName.out | |
| 254 | + test blob-uncompress2-$blobName {$CODE == 0 && | |
| 255 | + [read_file z2-$blobName.out] eq "$blobOne$blobTwo"} | |
| 256 | +} | |
| 257 | + | |
| 258 | +# test-cycle-compress compresses each file, uncompresses the result and | |
| 259 | +# compares it with the file. | |
| 260 | +fossil_raw test-cycle-compress z-text.in z-nul-bytes.in z-repeats.in z-bytes.in | |
| 261 | +test blob-cycle-compress {$CODE == 0 && $RESULT eq "ok\n"} | |
| 262 | +fossil_raw test-cycle-compress | |
| 263 | +test blob-cycle-compress-none {$CODE == 0 && $RESULT eq "ok\n"} | |
| 264 | +fossil_raw test-cycle-compress z-text.in no-such-file.txt | |
| 265 | +test blob-cycle-compress-missing {$CODE == 1 && | |
| 266 | + [string match "*no such file: no-such-file.txt*" $RESULT]} | |
| 267 | + | |
| 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 | |
| 281 | + test blob-usage-$blobName {$CODE == 1 && | |
| 282 | + [string match "Usage:*$blobUsage*" $RESULT] && | |
| 283 | + ![file exists a] && ![file exists b] && ![file exists c]} | |
| 284 | +} | |
| 285 | + | |
| 286 | +############################################################################### | |
| 287 | +# Writing a file. The output goes to standard output when the name is | |
| 288 | +# "-" or empty, directories on the way to the file are made, and a file | |
| 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} | |
| 300 | + | |
| 301 | +fossil_raw test-compress z-text.in write-dir/sub/dir/out.z | |
| 302 | +test blob-write-makes-directories {$CODE == 0 && | |
| 303 | + [read_file write-dir/sub/dir/out.z] eq [read_file z-text.z]} | |
| 304 | + | |
| 305 | +file mkdir write-is-dir | |
| 306 | +fossil_raw test-compress z-text.in write-is-dir | |
| 307 | +test blob-write-onto-directory {$CODE == 1 && | |
| 308 | + [string match "*unable to open file \"write-is-dir\" for writing*" $RESULT]} | |
| 309 | + | |
| 310 | +if {$::tcl_platform(platform) eq "unix" && $::tcl_platform(user) ne "root"} { | |
| 311 | + file mkdir write-closed | |
| 312 | + file attributes write-closed -permissions 0555 | |
| 313 | + fossil_raw test-compress z-text.in write-closed/out.z | |
| 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 | |
| 324 | +# digits. Each row: the argument in hexadecimal, the quoted form that | |
| 325 | +# must end the command line when the argument is a file name and when it | |
| 326 | +# is not. The argument must arrive as it was given, after "./" if it | |
| 327 | +# is a file name that begins with "-". Bytes outside ASCII are written | |
| 328 | +# in the quoted forms as hexadecimal digits between "<" and ">". The | |
| 329 | +# quoted forms are those of a Unix shell. | |
| 330 | + | |
| 331 | +proc blob_escaped {isFilename hex} { | |
| 332 | + fossil_raw test-escaped-arg --filename-args $isFilename --hex $hex | |
| 333 | +} | |
| 334 | + | |
| 335 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 336 | + foreach {blobName blobArgHex blobFile blobOther} { | |
| 337 | + word 616263 {abc} {abc} | |
| 338 | + safe-marks 2b2c2e2f3a3d5f {+,./:=_} {+,./:=_} | |
| 339 | + at-sign 614062 {'a@b'} {'a@b'} | |
| 340 | + dash 2d78 {./-x} {-x} | |
| 341 | + dash-only 2d {./-} {-} | |
| 342 | + two-dashes 2d2d782079 {'./--x y'} {'--x y'} | |
| 343 | + space 612062 {'a b'} {'a b'} | |
| 344 | + dash-space 2d612062 {'./-a b'} {'-a b'} | |
| 345 | + quote 69742773 {it\'s} {it\'s} | |
| 346 | + dash-quote 2d69742773 {./-it\'s} {-it\'s} | |
| 347 | + quote-space 61202762 {a\ \'b} {a\ \'b} | |
| 348 | + quote-marks 2724603b7c {\'\$\`\;\|} {\'\$\`\;\|} | |
| 349 | + dollar 612462 {'a$b'} {'a$b'} | |
| 350 | + backquote 606960 {'`i`'} {'`i`'} | |
| 351 | + backslash 615c62 {'a\b'} {'a\b'} | |
| 352 | + double-quote 612262 {'a"b'} {'a"b'} | |
| 353 | + tilde 7e {'~'} {'~'} | |
| 354 | + bang 2161 {'!a'} {'!a'} | |
| 355 | + star 2a3f5b5d {'*?[]'} {'*?[]'} | |
| 356 | + semicolon 613b62 {'a;b'} {'a;b'} | |
| 357 | + redirect 3c3e7c26 {'<>|&'} {'<>|&'} | |
| 358 | + braces 7b7d2829 {'{}()'} {'{}()'} | |
| 359 | + hash-percent 23255e {'#%^'} {'#%^'} | |
| 360 | + delete 617f {'a<7f>'} {'a<7f>'} | |
| 361 | + two-byte c3a9 {'<c3a9>'} {'<c3a9>'} | |
| 362 | + three-byte e282ac {'<e282ac>'} {'<e282ac>'} | |
| 363 | + four-byte f09f9880 {'<f09f9880>'} {'<f09f9880>'} | |
| 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 | |
| 386 | +# continue a UTF-8 character, or a UTF-8 character that is cut short is | |
| 387 | +# refused, and no command is run. Each row: the argument in hexadecimal | |
| 388 | +# and what the message must say. | |
| 389 | +foreach {blobName blobArgHex blobWhy} { | |
| 390 | + control-01 01 "ascii 0x01" | |
| 391 | + tab 6109 "ascii 0x09" | |
| 392 | + newline 610a62 "ascii 0x0a" | |
| 393 | + return 0d "ascii 0x0d" | |
| 394 | + escape 1b5b "ascii 0x1b" | |
| 395 | + unit-sep 1f "ascii 0x1f" | |
| 396 | + continuation 80 "ascii 0x80" | |
| 397 | + continuation-bf 61bf "ascii 0xbf" | |
| 398 | + two-cut c3 "illegal UTF-8" | |
| 399 | + two-then-ascii c341 "illegal UTF-8" | |
| 400 | + two-then-lead c3c3a9 "illegal UTF-8" | |
| 401 | + three-cut-1 e2 "illegal UTF-8" | |
| 402 | + three-cut-2 e282 "illegal UTF-8" | |
| 403 | + three-bad-2 e241ac "illegal UTF-8" | |
| 404 | + three-bad-3 e28241 "illegal UTF-8" | |
| 405 | + four-cut-1 f0 "illegal UTF-8" | |
| 406 | + four-cut-2 f09f "illegal UTF-8" | |
| 407 | + four-cut-3 f09f98 "illegal UTF-8" | |
| 408 | + four-bad-2 f0419880 "illegal UTF-8" | |
| 409 | + four-bad-3 f09f4180 "illegal UTF-8" | |
| 410 | + four-bad-4 f09f9841 "illegal UTF-8" | |
| 411 | + ff-alone ff "illegal UTF-8" | |
| 412 | + quote-then-cut 27c3 "illegal UTF-8" | |
| 413 | + quote-control 2701 "ascii 0x01" | |
| 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 | |
| 426 | + # on the command line, and --filename-args switches between the two | |
| 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 | + | |
| 440 | + # --hex, --compare and --fuzz without the arguments they need are taken | |
| 441 | + # as file names. | |
| 442 | + foreach blobOption {--hex --fuzz} { | |
| 443 | + fossil_raw test-escaped-arg $blobOption | |
| 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 | |
| 456 | +test blob-escaped-hex-longest {$CODE == 0 && | |
| 457 | + [string first "argv\[2\] = \[[string repeat A 98]\]" $RESULT] >= 0} | |
| 458 | +fossil_raw test-escaped-arg --hex ${blobDigits}41 | |
| 459 | +test blob-escaped-hex-too-long {$CODE == 1 && | |
| 460 | + [string match "*Argument to --hex is too big*" $RESULT]} | |
| 461 | + | |
| 462 | +# --compare HEX TEXT succeeds without output when TEXT is the bytes that | |
| 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" | |
| 474 | + dash-no-slash 2d61 .x-a 1 "argument disagree" | |
| 475 | + dash-no-dot 2d61 x-a 1 "argument disagree" | |
| 476 | + bad-hex zz a 1 "HEX decode of zz failed" | |
| 477 | + odd-hex 616 a 1 "HEX decode of 616 failed" | |
| 478 | +} { | |
| 479 | + set blobText [string map [list ./ $blobDot] $blobText] | |
| 480 | + fossil_raw test-escaped-arg --compare $blobHex $blobText | |
| 481 | + test blob-escaped-compare-$blobName {$CODE == $blobCode && | |
| 482 | + ($blobSays eq "" ? $RESULT eq "" : [string first $blobSays $RESULT] >= 0)} | |
| 483 | +} | |
| 484 | +fossil_raw test-escaped-arg --compare ${blobDigits}41 a | |
| 485 | +test blob-escaped-compare-too-long {$CODE == 1 && | |
| 486 | + [string match "*HEX argument to --compare is too big*" $RESULT]} | |
| 487 | +fossil_raw test-escaped-arg --compare 61 a --compare 62 b --compare 63 x | |
| 488 | +test blob-escaped-compare-third {$CODE == 1 && | |
| 489 | + [string first "\"c\" (63) versus \"x\"" $RESULT] >= 0} | |
| 490 | + | |
| 491 | +# --fuzz N quotes N arguments made of random printable and multi-byte | |
| 492 | +# characters, passes each through the shell to "test-escaped-arg | |
| 493 | +# --compare", and stops at the first one that does not arrive unchanged. | |
| 494 | +fossil_raw -seconds 300 test-escaped-arg --fuzz 150 | |
| 495 | +test blob-escaped-fuzz {$CODE == 0 && $RESULT eq ""} | |
| 496 | +fossil_raw test-escaped-arg --fuzz 0 | |
| 497 | +test blob-escaped-fuzz-none {$CODE == 0 && $RESULT eq ""} | |
| 498 | + | |
| 499 | +############################################################################### | |
| 500 | +# "diff --json" and "diff --tcl" write each piece of a line as a string | |
| 501 | +# literal. The JSON literal escapes the double quote, the backslash and | |
| 502 | +# every control character; the Tcl literal escapes the double quote, the | |
| 503 | +# backslash, the carriage return, the brackets and the dollar sign. | |
| 504 | +# Each row: the bytes of a line, in hexadecimal, and the JSON and Tcl | |
| 505 | +# literals for it. | |
| 506 | + | |
| 507 | +foreach {blobName blobLineHex blobJson blobTcl} { | |
| 508 | + plain 616263 {"abc"} {"abc"} | |
| 509 | + quote 612262 {"a\"b"} {"a\"b"} | |
| 510 | + backslash 615c62 {"a\\b"} {"a\\b"} | |
| 511 | + brackets 5b615d {"[a]"} {"\[a\]"} | |
| 512 | + dollar 2461 {"$a"} {"\$a"} | |
| 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} { | |
| 528 | + while {[regexp {<([0-9a-f]+)>} [set $blobVar] -> blobPart]} { | |
| 529 | + regsub {<[0-9a-f]+>} [set $blobVar] [blob_bytes $blobPart] $blobVar | |
| 530 | + } | |
| 531 | + } | |
| 532 | + write_file lit-$blobName.1 "same\n" | |
| 533 | + write_file lit-$blobName.2 "same\n[blob_bytes $blobLineHex]\n" | |
| 534 | + fossil_raw test-diff --json lit-$blobName.1 lit-$blobName.2 | |
| 535 | + test blob-json-literal-$blobName {$CODE == 0 && | |
| 536 | + [string first "\n\[2,\"same\",\n3,$blobJson,\n0\]" $RESULT] >= 0} | |
| 537 | + fossil_raw test-diff --tcl lit-$blobName.1 lit-$blobName.2 | |
| 538 | + test blob-tcl-literal-$blobName {$CODE == 0 && | |
| 539 | + [string first "\nCOM \"same\"\nINS $blobTcl\n" $RESULT] >= 0} | |
| 540 | +} | |
| 541 | + | |
| 542 | +# The names of the two files are written as literals of the same kind. | |
| 543 | +write_file {lit [n]$.1} "one\n" | |
| 544 | +write_file {lit [n]$.2} "two\n" | |
| 545 | +fossil_raw test-diff --tcl {lit [n]$.1} {lit [n]$.2} | |
| 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" | |
| 565 | +write_file web.2 "one\n2\nthree\nfour\n" | |
| 566 | +fossil_raw test-diff --webpage web.1 web.2 | |
| 567 | +test blob-webpage-diff-columns {$CODE == 0 && [regexp \ | |
| 568 | + {<td class="diffln difflnl"><pre>\n1\n<del>2\n</del>\n3\n\n</pre></td><td class="diffln difflnr"><pre>\n1\n\n<ins>2\n</ins>3\n<ins>4\n</ins></pre></td><td class="diffsep"><pre>\n\n-\n\+\n\n\+\n</pre></td><td class="difftxt difftxtu"><pre>\none\n<del><del>two</del>\n</del><ins><ins>2</ins>\n</ins>three\n<ins><ins>four</ins>\n</ins></pre></td>} \ | |
| 569 | + $RESULT]} | |
| 570 | + | |
| 571 | +############################################################################### | |
| 572 | +# Line ends. "test-ci-mini" checks a file in, and with --convert-eol-unix | |
| 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 | |
| 586 | + foreach {content opt} [list $before {} $given $option] { | |
| 587 | + write_file eol.txt $content | |
| 588 | + fossil test-ci-mini -m eol -r tip --wet-run --allow-older {*}$opt eol.txt | |
| 589 | + } | |
| 590 | + fossil_raw cat eol.txt -r tip | |
| 591 | + return $RESULT | |
| 592 | +} | |
| 593 | + | |
| 594 | +foreach {blobName blobOption blobBefore blobGiven blobStored} { | |
| 595 | + to-windows --convert-eol-windows "s\n" "one\ntwo\n\nlast" | |
| 596 | + "one\r\ntwo\r\n\r\nlast" | |
| 597 | + to-windows-only-nl --convert-eol-windows "s\n" "\n\n\n" "\r\n\r\n\r\n" | |
| 598 | + to-windows-no-nl --convert-eol-windows "s\n" "word" "word" | |
| 599 | + to-windows-already --convert-eol-windows "s\n" "a\r\nb\r\n" "a\r\nb\r\n" | |
| 600 | + to-unix --convert-eol-unix "s\n" "a\r\nb\rc\r\n\r" | |
| 601 | + "a\nb\nc\n\n" | |
| 602 | + to-unix-already --convert-eol-unix "s\n" "a\nb\n" "a\nb\n" | |
| 603 | + to-unix-end-cr --convert-eol-unix "s\n" "a\r\nb\r" "a\nb\n" | |
| 604 | + inherit-unix --convert-eol-inherit "p\nq\n" "x\r\ny\r\nz\r\n" | |
| 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 | + | |
| 623 | +############################################################################### | |
| 624 | +# A commit warns about a file that is not UTF-8 and offers to convert it. | |
| 625 | +# With the answer "c" the file is rewritten as UTF-8 with Unix line ends, | |
| 626 | +# the bytes it had are kept in a file named FILE-original, and the commit | |
| 627 | +# stops. Each row: the bytes of the file and the bytes after conversion, | |
| 628 | +# both in hexadecimal. | |
| 629 | +# | |
| 630 | +# utf16-le, utf16-be: "h", e-acute, CR LF, the euro sign, LF, after a | |
| 631 | +# byte-order mark. The result begins with the UTF-8 byte-order mark. | |
| 632 | +# utf16-le-short, utf16-be-short: a mark and one character. | |
| 633 | +# cp1252: bytes 0x80 to 0x9f stand for the characters of code page | |
| 634 | +# 1252, three bytes long in UTF-8 (0x80, 0x99) or two (0x81, 0x9f), | |
| 635 | +# and bytes from 0xa0 for the characters of ISO 8859-1. | |
| 636 | + | |
| 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__"} { | |
| 648 | + set blobBefore [string repeat 80e941 3000]0a | |
| 649 | + set blobAfter [string repeat e282acc3a941 3000]0a | |
| 650 | + } | |
| 651 | + write_file conv-$blobName.txt [blob_bytes $blobBefore] | |
| 652 | + fossil add conv-$blobName.txt | |
| 653 | + fossil_raw -input "c\n" commit -m "convert $blobName" conv-$blobName.txt | |
| 654 | + test blob-convert-$blobName {$CODE == 1 && | |
| 655 | + [string match "*Commit anyhow (a=all/c=convert/y/N)?*files were\ | |
| 656 | + converted on your request*" $RESULT] && | |
| 657 | + [blob_hex [read_file conv-$blobName.txt]] eq $blobAfter && | |
| 658 | + [blob_hex [read_file conv-$blobName.txt-original]] eq $blobBefore} | |
| 659 | + fossil forget conv-$blobName.txt | |
| 660 | +} | |
| 661 | + | |
| 662 | +############################################################################### | |
| 663 | +# A check-in comment read from a file with -M is stored as UTF-8: a | |
| 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 | |
| 677 | + utf16-be feff0063006120ac 6361e282ac | |
| 678 | + cp1252 636166e92080 636166c3a920e282ac | |
| 679 | + cp1252-two 81a0ff c281c2a0c3bf | |
| 680 | + cp1252-three 808599 e282ace280a6e284a2 | |
| 681 | +} { | |
| 682 | + write_file comment-$blobName.txt [blob_bytes $blobFile] | |
| 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 | |
| 701 | +} { | |
| 702 | + write_file comment-subject.txt "editor $blobName\n" | |
| 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 | |
| 726 | +} { | |
| 727 | + write_file bom-plain.txt [blob_bytes $blobSecond] | |
| 728 | + fossil_raw diff bom-plain.txt | |
| 729 | + test blob-bom-diff-$blobName {$CODE == 0 && | |
| 730 | + [string first "\n one\n-two\n+2\n" $RESULT] >= 0} | |
| 731 | +} | |
| 732 | +# A file that is only a byte-order mark is a file without lines. | |
| 733 | +foreach {blobName blobSecond} { | |
| 734 | + utf8-only efbbbf | |
| 735 | + utf16-le-only fffe | |
| 736 | + utf16-be-only feff | |
| 737 | +} { | |
| 738 | + write_file bom-plain.txt [blob_bytes $blobSecond] | |
| 739 | + fossil_raw diff bom-plain.txt | |
| 740 | + test blob-bom-diff-$blobName {$CODE == 0 && | |
| 741 | + [string first "\n-one\n-two\n" $RESULT] >= 0 && | |
| 742 | + ![regexp -line {^\+[^+]} $RESULT]} | |
| 743 | +} | |
| 744 | +fossil revert bom-plain.txt | |
| 745 | + | |
| 746 | +# Two files with a byte-order mark and a zero byte differ after the zero | |
| 747 | +# byte. They are binary files, which a diff does not compare. | |
| 748 | +write_file bom-nul.1 [blob_bytes efbbbf]a\x00b\n | |
| 749 | +write_file bom-nul.2 [blob_bytes efbbbf]a\x00c\n | |
| 750 | +fossil_raw test-diff bom-nul.1 bom-nul.2 | |
| 751 | +test blob-bom-diff-nul {$CODE == 0 && | |
| 752 | + [string first "cannot compute difference between binary files" $RESULT] >= 0 | |
| 753 | +} knownBug | |
| 754 | + | |
| 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. | |
| 773 | +foreach {blobName blobColor blobOk} { | |
| 774 | + three-digits abc 1 | |
| 775 | + six-digits 09afbc 1 | |
| 776 | + seven-digits 09afbca 1 | |
| 777 | + two-digits 12 0 | |
| 778 | + four-digits 1234 0 | |
| 779 | + five-digits 12345 0 | |
| 780 | + upper-case ABC 0 | |
| 781 | + letter-g ggg 0 | |
| 782 | + sixth-g abcdeg 0 | |
| 783 | + slash ab/ 0 | |
| 784 | + colon 9:1 0 | |
| 785 | + backquote `ab 0 | |
| 786 | + brace ab\{ 0 | |
| 787 | + nothing {} 0 | |
| 788 | +} { | |
| 789 | + set blobReply [blob_page /test-bgcolor?ba=%23[string map \ | |
| 790 | + {/ %2F : %3A ` %60 \{ %7B} $blobColor]] | |
| 791 | + test blob-xdigit-color-$blobName {$CODE == 0 && ($blobOk | |
| 792 | + ? [string first "Requested color \"#$blobColor\"" $blobReply] >= 0 | |
| 793 | + : [string first "is not a recognized color name" $blobReply] >= 0)} | |
| 794 | +} | |
| 795 | + | |
| 796 | +# /cookies calls a cookie the login cookie of another repository when | |
| 797 | +# its name is "fossil-" and 16 hexadecimal digits and its value begins | |
| 798 | +# with more than 24 of them, in either case. Each row: the value and | |
| 799 | +# whether it is such a cookie. | |
| 800 | +foreach {blobName blobValue blobOk} { | |
| 801 | + digits 0123456789012345678901234 1 | |
| 802 | + lower abcdefabcdefabcdefabcdefa 1 | |
| 803 | + upper ABCDEFABCDEFABCDEFABCDEFA 1 | |
| 804 | + mixed 09afAF09afAF09afAF09afAFx 0 | |
| 805 | + mixed-25 09afAF09afAF09afAF09afAF0x 1 | |
| 806 | + short 0123456789abcdefABCDEF01 0 | |
| 807 | + upper-g 0123456789abcdefABCDEF01G 0 | |
| 808 | + lower-g 0123456789abcdefABCDEF01g 0 | |
| 809 | + slash 0123456789abcdefABCDEF01/ 0 | |
| 810 | + colon 0123456789abcdefABCDEF01: 0 | |
| 811 | + at-sign 0123456789abcdefABCDEF01@ 0 | |
| 812 | + backquote 0123456789abcdefABCDEF01` 0 | |
| 813 | +} { | |
| 814 | + set blobReply [blob_page /cookies \ | |
| 815 | + [list "Cookie: fossil-0123456789abcDEF=$blobValue"]] | |
| 816 | + test blob-xdigit-cookie-$blobName {$CODE == 0 && ($blobOk | |
| 817 | + ? [string first "login cookie for another Fossil repository" \ | |
| 818 | + $blobReply] >= 0 | |
| 819 | + : [string first "This cookie was not generated by Fossil" \ | |
| 820 | + $blobReply] >= 0)} | |
| 821 | +} | |
| 822 | +set blobReply [blob_page /cookies \ | |
| 823 | + [list "Cookie: fossil-0123456789abcdeg=0123456789012345678901234"]] | |
| 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" && | |
| 835 | + (![file exists page-reply.txt] || [file size page-reply.txt] == 0)} | |
| 836 | + | |
| 837 | +# The timeline cuts a comment that is longer than the timeline-max-comment | |
| 838 | +# setting and puts "..." after it. It does not cut inside a UTF-8 | |
| 839 | +# character. The comment is "utf caf", then characters of two, three and | |
| 840 | +# four bytes, then " tail". Each row: the setting and the bytes of the | |
| 841 | +# characters that must be left after "utf caf", in hexadecimal. | |
| 842 | +write_file tl.txt "timeline\n" | |
| 843 | +fossil add tl.txt | |
| 844 | +write_file tl-comment.txt "utf caf[blob_bytes c3a9e282acf09f9880] tail" | |
| 845 | +fossil commit -M tl-comment.txt --no-warnings --no-verify-comment tl.txt | |
| 846 | +foreach {blobLimit blobLeft} { | |
| 847 | + 7 {} | |
| 848 | + 8 {} | |
| 849 | + 9 c3a9 | |
| 850 | + 10 c3a9 | |
| 851 | + 11 c3a9 | |
| 852 | + 12 c3a9e282ac | |
| 853 | + 13 c3a9e282ac | |
| 854 | + 15 c3a9e282ac | |
| 855 | + 16 c3a9e282acf09f9880 | |
| 856 | + 17 c3a9e282acf09f988020 | |
| 857 | +} { | |
| 858 | + fossil sql "REPLACE INTO config(name,value,mtime) | |
| 859 | + VALUES('timeline-max-comment',$blobLimit,now())" | |
| 860 | + set blobReply [blob_page /timeline?n=1] | |
| 861 | + test blob-truncate-utf8-$blobLimit {$CODE == 0 && | |
| 862 | + [regexp {utf caf([^<.]*)\.\.\.\n} $blobReply -> blobGot] && | |
| 863 | + [blob_hex $blobGot] eq $blobLeft} | |
| 864 | +} | |
| 865 | +# A setting of 0, a negative one, and one longer than the comment leave | |
| 866 | +# the comment whole. | |
| 867 | +foreach blobLimit {0 -1 21 22 500} { | |
| 868 | + fossil sql "REPLACE INTO config(name,value,mtime) | |
| 869 | + VALUES('timeline-max-comment',$blobLimit,now())" | |
| 870 | + set blobReply [blob_page /timeline?n=1] | |
| 871 | + test blob-truncate-utf8-whole-$blobLimit {$CODE == 0 && | |
| 872 | + [regexp {utf caf([^<]*) tail\n} $blobReply -> blobGot] && | |
| 873 | + [blob_hex $blobGot] eq "c3a9e282acf09f9880"} | |
| 874 | +} | |
| 875 | +fossil sql "DELETE FROM config WHERE name='timeline-max-comment'" | |
| 876 | + | |
| 877 | +############################################################################### | |
| 878 | +# "fossil clean --prompt" asks about each unmanaged file and takes the | |
| 879 | +# first letter of the answer in either case: "n" keeps the file, "a" | |
| 880 | +# removes it and all the others without asking again, "y" removes it. | |
| 881 | +# Each row: the answer given to every question, and the files that must | |
| 882 | +# be left. | |
| 883 | + | |
| 884 | +proc blob_clean {answer} { | |
| 885 | + foreach name {clean-1.tmp clean-2.tmp} { write_file $name "tmp\n" } | |
| 886 | + fossil_raw -input "$answer\n$answer\n$answer\n" clean --prompt \ | |
| 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 {} | |
| 898 | + upper-y Y {} | |
| 899 | + lower-a a {} | |
| 900 | + upper-a A {} | |
| 901 | +} { | |
| 902 | + set blobGot [blob_clean $blobAnswer] | |
| 903 | + test blob-clean-prompt-$blobName {$CODE == 0 && $blobGot eq $blobLeft && | |
| 904 | + [string first "Remove unmanaged file \"clean-1.tmp\" (a=all/y/N)?" \ | |
| 905 | + $RESULT] >= 0} | |
| 906 | +} | |
| 907 | +# After "a" the second file is removed without a question. | |
| 908 | +blob_clean a | |
| 909 | +test blob-clean-prompt-all-asks-once {$CODE == 0 && | |
| 910 | + [string first "\"clean-2.tmp\"" $RESULT] < 0} | |
| 911 | +# An empty answer, and an answer that is none of the letters offered, | |
| 912 | +# keep the file. | |
| 913 | +foreach {blobName blobAnswer} { | |
| 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 | |
| 926 | +# "aaaa bbbbX-ccccc" and whether a line 13 wide, 9 of which are margin, | |
| 927 | +# may end after the hyphen. | |
| 928 | + | |
| 929 | +foreach {blobName blobChar blobBreaks} { | |
| 930 | + lower-a a 1 | |
| 931 | + lower-z z 1 | |
| 932 | + upper-a A 1 | |
| 933 | + upper-z Z 1 | |
| 934 | + digit 1 0 | |
| 935 | + at-sign @ 0 | |
| 936 | + bracket \[ 0 | |
| 937 | + underscore _ 0 | |
| 938 | + backquote ` 0 | |
| 939 | + brace \{ 0 | |
| 940 | + tilde ~ 0 | |
| 941 | +} { | |
| 942 | + fossil_raw test-comment-format -W 13 "aaaa bbbb${blobChar}-ccccc" | |
| 943 | + test blob-isalpha-$blobName {$CODE == 0 && ($blobBreaks | |
| 944 | + ? [string first "\n ${blobChar}-\n" $RESULT] >= 0 | |
| 945 | + : [string first "\n ${blobChar}-cc\n" $RESULT] >= 0)} | |
| 946 | +} | |
| 947 | + | |
| 948 | +############################################################################### | |
| 949 | +# A three-way merge of files whose last line has no line end. | |
| 950 | + | |
| 951 | +# Merge the contents $one and $two, which both come from $base. Returns | |
| 952 | +# the merged content; CODE is the exit status of the merge. | |
| 953 | +proc blob_merge {base one two} { | |
| 954 | + write_file merge.0 $base | |
| 955 | + write_file merge.1 $one | |
| 956 | + write_file merge.2 $two | |
| 957 | + file delete merge.out | |
| 958 | + fossil_raw 3-way-merge merge.0 merge.1 merge.2 merge.out | |
| 959 | + return [read_file merge.out] | |
| 960 | +} | |
| 961 | + | |
| 962 | +test blob-merge-no-final-newline-edit \ | |
| 963 | + {[blob_merge "a\nb\nc" "A\nb\nc" "a\nb\nC"] eq "A\nb\nC" && $CODE == 0} | |
| 964 | +test blob-merge-no-final-newline-same \ | |
| 965 | + {[blob_merge "a\nb\nc" "a\nB\nc" "a\nB\nc"] eq "a\nB\nc" && $CODE == 0} | |
| 966 | +test blob-merge-empty {[blob_merge "" "" ""] eq "" && $CODE == 0} | |
| 967 | + | |
| 968 | +# Both sides change the last line, which has no line end: a conflict, | |
| 969 | +# with each side's line whole between the marks. | |
| 970 | +set blobMerged [blob_merge "a\nb" "a\nONE" "a\nTWO"] | |
| 971 | +test blob-merge-no-final-newline-conflict {$CODE == 0 && | |
| 972 | + [string first "1 merge conflicts" $RESULT] >= 0 && | |
| 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 | + | |
| 986 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 987 | + write_file link-target.txt "content of the target\n" | |
| 988 | + file link -symbolic link-on.lnk link-target.txt | |
| 989 | + fossil settings allow-symlinks on | |
| 990 | + fossil add link-on.lnk | |
| 991 | + fossil commit -m "link, symlinks on" --no-warnings link-on.lnk | |
| 992 | + fossil_raw cat link-on.lnk -r tip | |
| 993 | + test blob-read-link-as-name {$CODE == 0 && $RESULT eq "link-target.txt"} | |
| 994 | + fossil settings allow-symlinks off | |
| 995 | + file link -symbolic link-off.lnk link-target.txt | |
| 996 | + fossil add link-off.lnk | |
| 997 | + fossil commit -m "link, symlinks off" --no-warnings link-off.lnk | |
| 998 | + fossil_raw cat link-off.lnk -r tip | |
| 999 | + test blob-read-link-as-file {$CODE == 0 && | |
| 1000 | + $RESULT eq "content of the target\n"} | |
| 1001 | +} | |
| 1002 | + | |
| 1003 | +############################################################################### | |
| 1004 | +test_cleanup |
| --- a/test/blob.test | |
| +++ b/test/blob.test | |
| @@ -0,0 +1,1004 @@ | |
| --- a/test/blob.test | |
| +++ b/test/blob.test | |
| @@ -0,0 +1,1004 @@ | |
| 1 | # |
| 2 | # The buffer type that all of Fossil's text handling is built on: |
| 3 | # src/blob.c. The test commands that run its routines directly |
| 4 | # (test-isspace, test-atoi, test-strip-comment-lines, test-compress, |
| 5 | # test-compress-2, test-uncompress, test-cycle-compress, test-escaped-arg), |
| 6 | # reading and writing files, and the routines that are reached only |
| 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. |
| 22 | # |
| 23 | proc blob_bytes {hex} { |
| 24 | return [binary format H* $hex] |
| 25 | } |
| 26 | |
| 27 | # The hexadecimal digits for the bytes in $bytes. |
| 28 | # |
| 29 | proc blob_hex {bytes} { |
| 30 | binary scan $bytes H* hex |
| 31 | return $hex |
| 32 | } |
| 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. |
| 44 | |
| 45 | foreach {blobName blobArg blobOk32 blobVal32 blobOk64 blobVal64} { |
| 46 | zero 0 1 0 1 0 |
| 47 | one 1 1 1 1 1 |
| 48 | leading-0 0000000000000000000042 1 42 1 42 |
| 49 | max32 2147483647 1 2147483647 1 2147483647 |
| 50 | over32 2147483648 0 0 1 2147483648 |
| 51 | ten-digits 9999999999 0 0 1 9999999999 |
| 52 | max64 9223372036854775807 0 0 1 9223372036854775807 |
| 53 | over64 9223372036854775808 0 0 0 0 |
| 54 | over64-tens 9223372036854775810 0 0 0 0 |
| 55 | under64-tens 9223372036854775799 0 0 1 9223372036854775799 |
| 56 | twenty 10000000000000000000 0 0 0 0 |
| 57 | very-long 123456789012345678901234567890 0 0 0 0 |
| 58 | negative -1 0 0 0 0 |
| 59 | plus +1 0 0 0 0 |
| 60 | space-first { 1} 0 0 0 0 |
| 61 | space-last {1 } 0 0 0 0 |
| 62 | letter-last 12x 0 0 0 0 |
| 63 | letter-first x12 0 0 0 0 |
| 64 | hex 0x10 0 0 0 0 |
| 65 | colon 1: 0 0 0 0 |
| 66 | slash 1/ 0 0 0 0 |
| 67 | point 1.5 0 0 0 0 |
| 68 | } { |
| 69 | fossil test-atoi $blobArg |
| 70 | set blobGot [regexp {: 32-bit (\d) (\d+) +64-bit (\d) (\d+)$} \ |
| 71 | [string trim $RESULT] -> blobA blobB blobC blobD] |
| 72 | test blob-atoi-$blobName {$blobGot && $blobA == $blobOk32 && |
| 73 | $blobB eq $blobVal32 && $blobC == $blobOk64 && $blobD eq $blobVal64} |
| 74 | } |
| 75 | |
| 76 | # With no argument test-atoi prints nothing, and with three it prints |
| 77 | # three lines. |
| 78 | fossil test-atoi |
| 79 | test blob-atoi-none {$RESULT eq ""} |
| 80 | fossil test-atoi 1 2 3 |
| 81 | test blob-atoi-three {[llength [split [string trim $RESULT] \n]] == 3} |
| 82 | |
| 83 | ############################################################################### |
| 84 | # test-strip-comment-lines removes the lines that begin with "#" and |
| 85 | # takes the backslash from the lines that begin with "\#". Each row: the |
| 86 | # content of the file and what must be printed. |
| 87 | |
| 88 | foreach {blobName blobIn blobOut} { |
| 89 | empty {} {} |
| 90 | plain "a\nb\n" "a\nb\n" |
| 91 | no-newline "a\nb" "a\nb" |
| 92 | comment "a\n#b\nc\n" "a\nc\n" |
| 93 | comment-first "#a\nb\n" "b\n" |
| 94 | comment-last "a\n#b" "a\n" |
| 95 | comment-only "#a" {} |
| 96 | comments-only "#a\n#b\n" {} |
| 97 | hash-inside "a#b\n #c\n" "a#b\n #c\n" |
| 98 | escaped "\\#a\nb\n" "#a\nb\n" |
| 99 | escaped-last "a\n\\#b" "a\n#b" |
| 100 | escaped-only "\\#" "#" |
| 101 | backslash "\\a\n\\\n" "\\a\n\\\n" |
| 102 | backslash-end "a\n\\" "a\n\\" |
| 103 | two-backslash "\\\\#a\n" "\\\\#a\n" |
| 104 | blank-lines "\n\n#\n\n" "\n\n\n" |
| 105 | crlf "a\r\n#b\r\nc\r\n" "a\r\nc\r\n" |
| 106 | nul-bytes "a\x00#b\n#c\x00\nd" "a\x00#b\nd" |
| 107 | only-newlines "\n\n" "\n\n" |
| 108 | } { |
| 109 | write_file strip-$blobName.txt $blobIn |
| 110 | fossil_raw test-strip-comment-lines strip-$blobName.txt |
| 111 | test blob-strip-$blobName {$CODE == 0 && $RESULT eq $blobOut} |
| 112 | } |
| 113 | |
| 114 | # A line of 100,000 bytes is kept whole, and a comment of that length is |
| 115 | # removed whole. |
| 116 | set blobLong [string repeat x 100000] |
| 117 | write_file strip-long.txt "$blobLong\n#$blobLong\n\\#$blobLong" |
| 118 | fossil_raw test-strip-comment-lines strip-long.txt |
| 119 | test blob-strip-long {$CODE == 0 && $RESULT eq "$blobLong\n#$blobLong"} |
| 120 | |
| 121 | # The file is read from standard input when its name is "-" or empty. |
| 122 | fossil_raw -input "a\n#b\nc\n" test-strip-comment-lines - |
| 123 | test blob-strip-stdin-dash {$CODE == 0 && $RESULT eq "a\nc\n"} |
| 124 | fossil_raw -input "#b\nc" test-strip-comment-lines {} |
| 125 | test blob-strip-stdin-empty-name {$CODE == 0 && $RESULT eq "c"} |
| 126 | fossil_raw -input "" test-strip-comment-lines - |
| 127 | test blob-strip-stdin-nothing {$CODE == 0 && $RESULT eq ""} |
| 128 | set blobBig [string repeat "line of text\n" 2000] |
| 129 | fossil_raw -input "#x\n$blobBig" test-strip-comment-lines - |
| 130 | test blob-strip-stdin-big {$CODE == 0 && $RESULT eq $blobBig} |
| 131 | |
| 132 | # --side-by-side shows the file beside what is left of it, and --width |
| 133 | # sets the width of each side. A width that is not positive is ignored. |
| 134 | write_file strip-sbs.txt "keep\n#drop\n\\#bare\n" |
| 135 | fossil_raw test-strip-comment-lines --side-by-side strip-sbs.txt |
| 136 | test blob-strip-sbs {$CODE == 0 && |
| 137 | [regexp {1 keep +1 keep} $RESULT] && [regexp {2 #drop +<} $RESULT] && |
| 138 | [regexp {3 \\#bare +\| +2 #bare} $RESULT]} |
| 139 | set blobWide [string length [lindex [split $RESULT \n] 0]] |
| 140 | fossil_raw test-strip-comment-lines -y -W 20 strip-sbs.txt |
| 141 | set blobNarrow [string length [lindex [split $RESULT \n] 0]] |
| 142 | test blob-strip-sbs-width {$CODE == 0 && $blobNarrow < $blobWide && |
| 143 | [regexp {1 keep +1 keep} $RESULT]} |
| 144 | foreach blobWidth {0 -5 x} { |
| 145 | fossil_raw test-strip-comment-lines -y -W $blobWidth strip-sbs.txt |
| 146 | test blob-strip-sbs-width-$blobWidth {$CODE == 0 && |
| 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 | |
| 160 | fossil_raw test-strip-comment-lines no-such-file.txt |
| 161 | test blob-read-missing {$CODE == 1 && |
| 162 | [string match "*no such file: no-such-file.txt*" $RESULT]} |
| 163 | |
| 164 | if {$::tcl_platform(platform) eq "unix" && $::tcl_platform(user) ne "root"} { |
| 165 | write_file read-closed.txt "text\n" |
| 166 | file attributes read-closed.txt -permissions 0000 |
| 167 | fossil_raw test-strip-comment-lines read-closed.txt |
| 168 | test blob-read-unreadable {$CODE == 1 && |
| 169 | [string match "*cannot open read-closed.txt for reading*" $RESULT]} |
| 170 | file attributes read-closed.txt -permissions 0644 |
| 171 | } |
| 172 | |
| 173 | # Outside a repository a symbolic link is followed to its file. |
| 174 | if {$::tcl_platform(platform) eq "unix"} { |
| 175 | write_file read-target.txt "target\n#gone\n" |
| 176 | file link -symbolic read-link.txt read-target.txt |
| 177 | fossil_raw test-strip-comment-lines read-link.txt |
| 178 | test blob-read-link-followed {$CODE == 0 && $RESULT eq "target\n"} |
| 179 | write_file read-gone.txt "soon gone\n" |
| 180 | file link -symbolic read-dangling.txt read-gone.txt |
| 181 | file delete read-gone.txt |
| 182 | fossil_raw test-strip-comment-lines read-dangling.txt |
| 183 | test blob-read-link-dangling {$CODE == 1 && |
| 184 | [string match "*no such file: read-dangling.txt*" $RESULT]} |
| 185 | } |
| 186 | |
| 187 | # A name that begins with "-" and is longer is the name of a file. |
| 188 | write_file -dash.txt "dash\n#gone\n" |
| 189 | fossil_raw test-cycle-compress -dash.txt |
| 190 | test blob-read-dash-name {$CODE == 0 && $RESULT eq "ok\n"} |
| 191 | fossil_raw test-compress -dash.txt -dash.z |
| 192 | test blob-write-dash-name {$CODE == 0 && $RESULT eq "" && |
| 193 | [zlib decompress [string range [read_file -dash.z] 4 end]] eq |
| 194 | "dash\n#gone\n"} |
| 195 | |
| 196 | # A directory read as a file has no content. |
| 197 | if {$::tcl_platform(platform) eq "unix"} { |
| 198 | file mkdir read-directory |
| 199 | fossil_raw test-strip-comment-lines read-directory |
| 200 | test blob-read-directory {$CODE == 0 && $RESULT eq ""} |
| 201 | } |
| 202 | |
| 203 | # test-safe-html prints an empty file as an empty line. |
| 204 | write_file read-empty.html "" |
| 205 | fossil_raw test-safe-html read-empty.html |
| 206 | test blob-read-empty-terminated {$CODE == 0 && $RESULT eq "\n"} |
| 207 | |
| 208 | ############################################################################### |
| 209 | # test-compress writes the size of the content as four bytes, high byte |
| 210 | # first, and then the content as zlib compresses it. test-uncompress |
| 211 | # turns that back into the content. Each row: a name and the content. |
| 212 | |
| 213 | foreach {blobName blobContent} [list \ |
| 214 | empty {} \ |
| 215 | one-byte x \ |
| 216 | text "some text\nwith two lines\n" \ |
| 217 | nul-bytes "a\x00b\x00\x00c" \ |
| 218 | repeats [string repeat "0123456789" 30000] \ |
| 219 | bytes [blob_bytes [string repeat 00ff7f80c3a9 500]] \ |
| 220 | ] { |
| 221 | set blobSize [string length $blobContent] |
| 222 | write_file z-$blobName.in $blobContent |
| 223 | fossil_raw test-compress z-$blobName.in z-$blobName.z |
| 224 | set blobZ [read_file z-$blobName.z] |
| 225 | test blob-compress-$blobName {$CODE == 0 && $RESULT eq "" && |
| 226 | [string range $blobZ 0 3] eq [binary format I $blobSize] && |
| 227 | [zlib decompress [string range $blobZ 4 end]] eq $blobContent} |
| 228 | fossil_raw test-uncompress z-$blobName.z z-$blobName.out |
| 229 | test blob-uncompress-$blobName {$CODE == 0 && $RESULT eq "" && |
| 230 | [read_file z-$blobName.out] eq $blobContent} |
| 231 | } |
| 232 | |
| 233 | # The 300,000 bytes of repeated digits compress to less than a hundredth. |
| 234 | test blob-compress-shrinks {[file size z-repeats.z] < 3000} |
| 235 | |
| 236 | # test-compress-2 compresses two files as one. Each row: the two |
| 237 | # contents. |
| 238 | foreach {blobName blobOne blobTwo} [list \ |
| 239 | both-empty {} {} \ |
| 240 | first-empty {} "second\n" \ |
| 241 | second-empty "first\n" {} \ |
| 242 | text "first\n" "second\n" \ |
| 243 | large [string repeat "abc\n" 50000] [string repeat "xyz\n" 50000] \ |
| 244 | ] { |
| 245 | write_file z2-$blobName.1 $blobOne |
| 246 | write_file z2-$blobName.2 $blobTwo |
| 247 | set blobSize [string length $blobOne$blobTwo] |
| 248 | fossil_raw test-compress-2 z2-$blobName.1 z2-$blobName.2 z2-$blobName.z |
| 249 | set blobZ [read_file z2-$blobName.z] |
| 250 | test blob-compress2-$blobName {$CODE == 0 && $RESULT eq "" && |
| 251 | [string range $blobZ 0 3] eq [binary format I $blobSize] && |
| 252 | [zlib decompress [string range $blobZ 4 end]] eq "$blobOne$blobTwo"} |
| 253 | fossil_raw test-uncompress z2-$blobName.z z2-$blobName.out |
| 254 | test blob-uncompress2-$blobName {$CODE == 0 && |
| 255 | [read_file z2-$blobName.out] eq "$blobOne$blobTwo"} |
| 256 | } |
| 257 | |
| 258 | # test-cycle-compress compresses each file, uncompresses the result and |
| 259 | # compares it with the file. |
| 260 | fossil_raw test-cycle-compress z-text.in z-nul-bytes.in z-repeats.in z-bytes.in |
| 261 | test blob-cycle-compress {$CODE == 0 && $RESULT eq "ok\n"} |
| 262 | fossil_raw test-cycle-compress |
| 263 | test blob-cycle-compress-none {$CODE == 0 && $RESULT eq "ok\n"} |
| 264 | fossil_raw test-cycle-compress z-text.in no-such-file.txt |
| 265 | test blob-cycle-compress-missing {$CODE == 1 && |
| 266 | [string match "*no such file: no-such-file.txt*" $RESULT]} |
| 267 | |
| 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 |
| 281 | test blob-usage-$blobName {$CODE == 1 && |
| 282 | [string match "Usage:*$blobUsage*" $RESULT] && |
| 283 | ![file exists a] && ![file exists b] && ![file exists c]} |
| 284 | } |
| 285 | |
| 286 | ############################################################################### |
| 287 | # Writing a file. The output goes to standard output when the name is |
| 288 | # "-" or empty, directories on the way to the file are made, and a file |
| 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} |
| 300 | |
| 301 | fossil_raw test-compress z-text.in write-dir/sub/dir/out.z |
| 302 | test blob-write-makes-directories {$CODE == 0 && |
| 303 | [read_file write-dir/sub/dir/out.z] eq [read_file z-text.z]} |
| 304 | |
| 305 | file mkdir write-is-dir |
| 306 | fossil_raw test-compress z-text.in write-is-dir |
| 307 | test blob-write-onto-directory {$CODE == 1 && |
| 308 | [string match "*unable to open file \"write-is-dir\" for writing*" $RESULT]} |
| 309 | |
| 310 | if {$::tcl_platform(platform) eq "unix" && $::tcl_platform(user) ne "root"} { |
| 311 | file mkdir write-closed |
| 312 | file attributes write-closed -permissions 0555 |
| 313 | fossil_raw test-compress z-text.in write-closed/out.z |
| 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 |
| 324 | # digits. Each row: the argument in hexadecimal, the quoted form that |
| 325 | # must end the command line when the argument is a file name and when it |
| 326 | # is not. The argument must arrive as it was given, after "./" if it |
| 327 | # is a file name that begins with "-". Bytes outside ASCII are written |
| 328 | # in the quoted forms as hexadecimal digits between "<" and ">". The |
| 329 | # quoted forms are those of a Unix shell. |
| 330 | |
| 331 | proc blob_escaped {isFilename hex} { |
| 332 | fossil_raw test-escaped-arg --filename-args $isFilename --hex $hex |
| 333 | } |
| 334 | |
| 335 | if {$::tcl_platform(platform) eq "unix"} { |
| 336 | foreach {blobName blobArgHex blobFile blobOther} { |
| 337 | word 616263 {abc} {abc} |
| 338 | safe-marks 2b2c2e2f3a3d5f {+,./:=_} {+,./:=_} |
| 339 | at-sign 614062 {'a@b'} {'a@b'} |
| 340 | dash 2d78 {./-x} {-x} |
| 341 | dash-only 2d {./-} {-} |
| 342 | two-dashes 2d2d782079 {'./--x y'} {'--x y'} |
| 343 | space 612062 {'a b'} {'a b'} |
| 344 | dash-space 2d612062 {'./-a b'} {'-a b'} |
| 345 | quote 69742773 {it\'s} {it\'s} |
| 346 | dash-quote 2d69742773 {./-it\'s} {-it\'s} |
| 347 | quote-space 61202762 {a\ \'b} {a\ \'b} |
| 348 | quote-marks 2724603b7c {\'\$\`\;\|} {\'\$\`\;\|} |
| 349 | dollar 612462 {'a$b'} {'a$b'} |
| 350 | backquote 606960 {'`i`'} {'`i`'} |
| 351 | backslash 615c62 {'a\b'} {'a\b'} |
| 352 | double-quote 612262 {'a"b'} {'a"b'} |
| 353 | tilde 7e {'~'} {'~'} |
| 354 | bang 2161 {'!a'} {'!a'} |
| 355 | star 2a3f5b5d {'*?[]'} {'*?[]'} |
| 356 | semicolon 613b62 {'a;b'} {'a;b'} |
| 357 | redirect 3c3e7c26 {'<>|&'} {'<>|&'} |
| 358 | braces 7b7d2829 {'{}()'} {'{}()'} |
| 359 | hash-percent 23255e {'#%^'} {'#%^'} |
| 360 | delete 617f {'a<7f>'} {'a<7f>'} |
| 361 | two-byte c3a9 {'<c3a9>'} {'<c3a9>'} |
| 362 | three-byte e282ac {'<e282ac>'} {'<e282ac>'} |
| 363 | four-byte f09f9880 {'<f09f9880>'} {'<f09f9880>'} |
| 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 |
| 386 | # continue a UTF-8 character, or a UTF-8 character that is cut short is |
| 387 | # refused, and no command is run. Each row: the argument in hexadecimal |
| 388 | # and what the message must say. |
| 389 | foreach {blobName blobArgHex blobWhy} { |
| 390 | control-01 01 "ascii 0x01" |
| 391 | tab 6109 "ascii 0x09" |
| 392 | newline 610a62 "ascii 0x0a" |
| 393 | return 0d "ascii 0x0d" |
| 394 | escape 1b5b "ascii 0x1b" |
| 395 | unit-sep 1f "ascii 0x1f" |
| 396 | continuation 80 "ascii 0x80" |
| 397 | continuation-bf 61bf "ascii 0xbf" |
| 398 | two-cut c3 "illegal UTF-8" |
| 399 | two-then-ascii c341 "illegal UTF-8" |
| 400 | two-then-lead c3c3a9 "illegal UTF-8" |
| 401 | three-cut-1 e2 "illegal UTF-8" |
| 402 | three-cut-2 e282 "illegal UTF-8" |
| 403 | three-bad-2 e241ac "illegal UTF-8" |
| 404 | three-bad-3 e28241 "illegal UTF-8" |
| 405 | four-cut-1 f0 "illegal UTF-8" |
| 406 | four-cut-2 f09f "illegal UTF-8" |
| 407 | four-cut-3 f09f98 "illegal UTF-8" |
| 408 | four-bad-2 f0419880 "illegal UTF-8" |
| 409 | four-bad-3 f09f4180 "illegal UTF-8" |
| 410 | four-bad-4 f09f9841 "illegal UTF-8" |
| 411 | ff-alone ff "illegal UTF-8" |
| 412 | quote-then-cut 27c3 "illegal UTF-8" |
| 413 | quote-control 2701 "ascii 0x01" |
| 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 |
| 426 | # on the command line, and --filename-args switches between the two |
| 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 | |
| 440 | # --hex, --compare and --fuzz without the arguments they need are taken |
| 441 | # as file names. |
| 442 | foreach blobOption {--hex --fuzz} { |
| 443 | fossil_raw test-escaped-arg $blobOption |
| 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 |
| 456 | test blob-escaped-hex-longest {$CODE == 0 && |
| 457 | [string first "argv\[2\] = \[[string repeat A 98]\]" $RESULT] >= 0} |
| 458 | fossil_raw test-escaped-arg --hex ${blobDigits}41 |
| 459 | test blob-escaped-hex-too-long {$CODE == 1 && |
| 460 | [string match "*Argument to --hex is too big*" $RESULT]} |
| 461 | |
| 462 | # --compare HEX TEXT succeeds without output when TEXT is the bytes that |
| 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" |
| 474 | dash-no-slash 2d61 .x-a 1 "argument disagree" |
| 475 | dash-no-dot 2d61 x-a 1 "argument disagree" |
| 476 | bad-hex zz a 1 "HEX decode of zz failed" |
| 477 | odd-hex 616 a 1 "HEX decode of 616 failed" |
| 478 | } { |
| 479 | set blobText [string map [list ./ $blobDot] $blobText] |
| 480 | fossil_raw test-escaped-arg --compare $blobHex $blobText |
| 481 | test blob-escaped-compare-$blobName {$CODE == $blobCode && |
| 482 | ($blobSays eq "" ? $RESULT eq "" : [string first $blobSays $RESULT] >= 0)} |
| 483 | } |
| 484 | fossil_raw test-escaped-arg --compare ${blobDigits}41 a |
| 485 | test blob-escaped-compare-too-long {$CODE == 1 && |
| 486 | [string match "*HEX argument to --compare is too big*" $RESULT]} |
| 487 | fossil_raw test-escaped-arg --compare 61 a --compare 62 b --compare 63 x |
| 488 | test blob-escaped-compare-third {$CODE == 1 && |
| 489 | [string first "\"c\" (63) versus \"x\"" $RESULT] >= 0} |
| 490 | |
| 491 | # --fuzz N quotes N arguments made of random printable and multi-byte |
| 492 | # characters, passes each through the shell to "test-escaped-arg |
| 493 | # --compare", and stops at the first one that does not arrive unchanged. |
| 494 | fossil_raw -seconds 300 test-escaped-arg --fuzz 150 |
| 495 | test blob-escaped-fuzz {$CODE == 0 && $RESULT eq ""} |
| 496 | fossil_raw test-escaped-arg --fuzz 0 |
| 497 | test blob-escaped-fuzz-none {$CODE == 0 && $RESULT eq ""} |
| 498 | |
| 499 | ############################################################################### |
| 500 | # "diff --json" and "diff --tcl" write each piece of a line as a string |
| 501 | # literal. The JSON literal escapes the double quote, the backslash and |
| 502 | # every control character; the Tcl literal escapes the double quote, the |
| 503 | # backslash, the carriage return, the brackets and the dollar sign. |
| 504 | # Each row: the bytes of a line, in hexadecimal, and the JSON and Tcl |
| 505 | # literals for it. |
| 506 | |
| 507 | foreach {blobName blobLineHex blobJson blobTcl} { |
| 508 | plain 616263 {"abc"} {"abc"} |
| 509 | quote 612262 {"a\"b"} {"a\"b"} |
| 510 | backslash 615c62 {"a\\b"} {"a\\b"} |
| 511 | brackets 5b615d {"[a]"} {"\[a\]"} |
| 512 | dollar 2461 {"$a"} {"\$a"} |
| 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} { |
| 528 | while {[regexp {<([0-9a-f]+)>} [set $blobVar] -> blobPart]} { |
| 529 | regsub {<[0-9a-f]+>} [set $blobVar] [blob_bytes $blobPart] $blobVar |
| 530 | } |
| 531 | } |
| 532 | write_file lit-$blobName.1 "same\n" |
| 533 | write_file lit-$blobName.2 "same\n[blob_bytes $blobLineHex]\n" |
| 534 | fossil_raw test-diff --json lit-$blobName.1 lit-$blobName.2 |
| 535 | test blob-json-literal-$blobName {$CODE == 0 && |
| 536 | [string first "\n\[2,\"same\",\n3,$blobJson,\n0\]" $RESULT] >= 0} |
| 537 | fossil_raw test-diff --tcl lit-$blobName.1 lit-$blobName.2 |
| 538 | test blob-tcl-literal-$blobName {$CODE == 0 && |
| 539 | [string first "\nCOM \"same\"\nINS $blobTcl\n" $RESULT] >= 0} |
| 540 | } |
| 541 | |
| 542 | # The names of the two files are written as literals of the same kind. |
| 543 | write_file {lit [n]$.1} "one\n" |
| 544 | write_file {lit [n]$.2} "two\n" |
| 545 | fossil_raw test-diff --tcl {lit [n]$.1} {lit [n]$.2} |
| 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" |
| 565 | write_file web.2 "one\n2\nthree\nfour\n" |
| 566 | fossil_raw test-diff --webpage web.1 web.2 |
| 567 | test blob-webpage-diff-columns {$CODE == 0 && [regexp \ |
| 568 | {<td class="diffln difflnl"><pre>\n1\n<del>2\n</del>\n3\n\n</pre></td><td class="diffln difflnr"><pre>\n1\n\n<ins>2\n</ins>3\n<ins>4\n</ins></pre></td><td class="diffsep"><pre>\n\n-\n\+\n\n\+\n</pre></td><td class="difftxt difftxtu"><pre>\none\n<del><del>two</del>\n</del><ins><ins>2</ins>\n</ins>three\n<ins><ins>four</ins>\n</ins></pre></td>} \ |
| 569 | $RESULT]} |
| 570 | |
| 571 | ############################################################################### |
| 572 | # Line ends. "test-ci-mini" checks a file in, and with --convert-eol-unix |
| 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 |
| 586 | foreach {content opt} [list $before {} $given $option] { |
| 587 | write_file eol.txt $content |
| 588 | fossil test-ci-mini -m eol -r tip --wet-run --allow-older {*}$opt eol.txt |
| 589 | } |
| 590 | fossil_raw cat eol.txt -r tip |
| 591 | return $RESULT |
| 592 | } |
| 593 | |
| 594 | foreach {blobName blobOption blobBefore blobGiven blobStored} { |
| 595 | to-windows --convert-eol-windows "s\n" "one\ntwo\n\nlast" |
| 596 | "one\r\ntwo\r\n\r\nlast" |
| 597 | to-windows-only-nl --convert-eol-windows "s\n" "\n\n\n" "\r\n\r\n\r\n" |
| 598 | to-windows-no-nl --convert-eol-windows "s\n" "word" "word" |
| 599 | to-windows-already --convert-eol-windows "s\n" "a\r\nb\r\n" "a\r\nb\r\n" |
| 600 | to-unix --convert-eol-unix "s\n" "a\r\nb\rc\r\n\r" |
| 601 | "a\nb\nc\n\n" |
| 602 | to-unix-already --convert-eol-unix "s\n" "a\nb\n" "a\nb\n" |
| 603 | to-unix-end-cr --convert-eol-unix "s\n" "a\r\nb\r" "a\nb\n" |
| 604 | inherit-unix --convert-eol-inherit "p\nq\n" "x\r\ny\r\nz\r\n" |
| 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 | |
| 623 | ############################################################################### |
| 624 | # A commit warns about a file that is not UTF-8 and offers to convert it. |
| 625 | # With the answer "c" the file is rewritten as UTF-8 with Unix line ends, |
| 626 | # the bytes it had are kept in a file named FILE-original, and the commit |
| 627 | # stops. Each row: the bytes of the file and the bytes after conversion, |
| 628 | # both in hexadecimal. |
| 629 | # |
| 630 | # utf16-le, utf16-be: "h", e-acute, CR LF, the euro sign, LF, after a |
| 631 | # byte-order mark. The result begins with the UTF-8 byte-order mark. |
| 632 | # utf16-le-short, utf16-be-short: a mark and one character. |
| 633 | # cp1252: bytes 0x80 to 0x9f stand for the characters of code page |
| 634 | # 1252, three bytes long in UTF-8 (0x80, 0x99) or two (0x81, 0x9f), |
| 635 | # and bytes from 0xa0 for the characters of ISO 8859-1. |
| 636 | |
| 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__"} { |
| 648 | set blobBefore [string repeat 80e941 3000]0a |
| 649 | set blobAfter [string repeat e282acc3a941 3000]0a |
| 650 | } |
| 651 | write_file conv-$blobName.txt [blob_bytes $blobBefore] |
| 652 | fossil add conv-$blobName.txt |
| 653 | fossil_raw -input "c\n" commit -m "convert $blobName" conv-$blobName.txt |
| 654 | test blob-convert-$blobName {$CODE == 1 && |
| 655 | [string match "*Commit anyhow (a=all/c=convert/y/N)?*files were\ |
| 656 | converted on your request*" $RESULT] && |
| 657 | [blob_hex [read_file conv-$blobName.txt]] eq $blobAfter && |
| 658 | [blob_hex [read_file conv-$blobName.txt-original]] eq $blobBefore} |
| 659 | fossil forget conv-$blobName.txt |
| 660 | } |
| 661 | |
| 662 | ############################################################################### |
| 663 | # A check-in comment read from a file with -M is stored as UTF-8: a |
| 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 |
| 677 | utf16-be feff0063006120ac 6361e282ac |
| 678 | cp1252 636166e92080 636166c3a920e282ac |
| 679 | cp1252-two 81a0ff c281c2a0c3bf |
| 680 | cp1252-three 808599 e282ace280a6e284a2 |
| 681 | } { |
| 682 | write_file comment-$blobName.txt [blob_bytes $blobFile] |
| 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 |
| 701 | } { |
| 702 | write_file comment-subject.txt "editor $blobName\n" |
| 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 |
| 726 | } { |
| 727 | write_file bom-plain.txt [blob_bytes $blobSecond] |
| 728 | fossil_raw diff bom-plain.txt |
| 729 | test blob-bom-diff-$blobName {$CODE == 0 && |
| 730 | [string first "\n one\n-two\n+2\n" $RESULT] >= 0} |
| 731 | } |
| 732 | # A file that is only a byte-order mark is a file without lines. |
| 733 | foreach {blobName blobSecond} { |
| 734 | utf8-only efbbbf |
| 735 | utf16-le-only fffe |
| 736 | utf16-be-only feff |
| 737 | } { |
| 738 | write_file bom-plain.txt [blob_bytes $blobSecond] |
| 739 | fossil_raw diff bom-plain.txt |
| 740 | test blob-bom-diff-$blobName {$CODE == 0 && |
| 741 | [string first "\n-one\n-two\n" $RESULT] >= 0 && |
| 742 | ![regexp -line {^\+[^+]} $RESULT]} |
| 743 | } |
| 744 | fossil revert bom-plain.txt |
| 745 | |
| 746 | # Two files with a byte-order mark and a zero byte differ after the zero |
| 747 | # byte. They are binary files, which a diff does not compare. |
| 748 | write_file bom-nul.1 [blob_bytes efbbbf]a\x00b\n |
| 749 | write_file bom-nul.2 [blob_bytes efbbbf]a\x00c\n |
| 750 | fossil_raw test-diff bom-nul.1 bom-nul.2 |
| 751 | test blob-bom-diff-nul {$CODE == 0 && |
| 752 | [string first "cannot compute difference between binary files" $RESULT] >= 0 |
| 753 | } knownBug |
| 754 | |
| 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. |
| 773 | foreach {blobName blobColor blobOk} { |
| 774 | three-digits abc 1 |
| 775 | six-digits 09afbc 1 |
| 776 | seven-digits 09afbca 1 |
| 777 | two-digits 12 0 |
| 778 | four-digits 1234 0 |
| 779 | five-digits 12345 0 |
| 780 | upper-case ABC 0 |
| 781 | letter-g ggg 0 |
| 782 | sixth-g abcdeg 0 |
| 783 | slash ab/ 0 |
| 784 | colon 9:1 0 |
| 785 | backquote `ab 0 |
| 786 | brace ab\{ 0 |
| 787 | nothing {} 0 |
| 788 | } { |
| 789 | set blobReply [blob_page /test-bgcolor?ba=%23[string map \ |
| 790 | {/ %2F : %3A ` %60 \{ %7B} $blobColor]] |
| 791 | test blob-xdigit-color-$blobName {$CODE == 0 && ($blobOk |
| 792 | ? [string first "Requested color \"#$blobColor\"" $blobReply] >= 0 |
| 793 | : [string first "is not a recognized color name" $blobReply] >= 0)} |
| 794 | } |
| 795 | |
| 796 | # /cookies calls a cookie the login cookie of another repository when |
| 797 | # its name is "fossil-" and 16 hexadecimal digits and its value begins |
| 798 | # with more than 24 of them, in either case. Each row: the value and |
| 799 | # whether it is such a cookie. |
| 800 | foreach {blobName blobValue blobOk} { |
| 801 | digits 0123456789012345678901234 1 |
| 802 | lower abcdefabcdefabcdefabcdefa 1 |
| 803 | upper ABCDEFABCDEFABCDEFABCDEFA 1 |
| 804 | mixed 09afAF09afAF09afAF09afAFx 0 |
| 805 | mixed-25 09afAF09afAF09afAF09afAF0x 1 |
| 806 | short 0123456789abcdefABCDEF01 0 |
| 807 | upper-g 0123456789abcdefABCDEF01G 0 |
| 808 | lower-g 0123456789abcdefABCDEF01g 0 |
| 809 | slash 0123456789abcdefABCDEF01/ 0 |
| 810 | colon 0123456789abcdefABCDEF01: 0 |
| 811 | at-sign 0123456789abcdefABCDEF01@ 0 |
| 812 | backquote 0123456789abcdefABCDEF01` 0 |
| 813 | } { |
| 814 | set blobReply [blob_page /cookies \ |
| 815 | [list "Cookie: fossil-0123456789abcDEF=$blobValue"]] |
| 816 | test blob-xdigit-cookie-$blobName {$CODE == 0 && ($blobOk |
| 817 | ? [string first "login cookie for another Fossil repository" \ |
| 818 | $blobReply] >= 0 |
| 819 | : [string first "This cookie was not generated by Fossil" \ |
| 820 | $blobReply] >= 0)} |
| 821 | } |
| 822 | set blobReply [blob_page /cookies \ |
| 823 | [list "Cookie: fossil-0123456789abcdeg=0123456789012345678901234"]] |
| 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" && |
| 835 | (![file exists page-reply.txt] || [file size page-reply.txt] == 0)} |
| 836 | |
| 837 | # The timeline cuts a comment that is longer than the timeline-max-comment |
| 838 | # setting and puts "..." after it. It does not cut inside a UTF-8 |
| 839 | # character. The comment is "utf caf", then characters of two, three and |
| 840 | # four bytes, then " tail". Each row: the setting and the bytes of the |
| 841 | # characters that must be left after "utf caf", in hexadecimal. |
| 842 | write_file tl.txt "timeline\n" |
| 843 | fossil add tl.txt |
| 844 | write_file tl-comment.txt "utf caf[blob_bytes c3a9e282acf09f9880] tail" |
| 845 | fossil commit -M tl-comment.txt --no-warnings --no-verify-comment tl.txt |
| 846 | foreach {blobLimit blobLeft} { |
| 847 | 7 {} |
| 848 | 8 {} |
| 849 | 9 c3a9 |
| 850 | 10 c3a9 |
| 851 | 11 c3a9 |
| 852 | 12 c3a9e282ac |
| 853 | 13 c3a9e282ac |
| 854 | 15 c3a9e282ac |
| 855 | 16 c3a9e282acf09f9880 |
| 856 | 17 c3a9e282acf09f988020 |
| 857 | } { |
| 858 | fossil sql "REPLACE INTO config(name,value,mtime) |
| 859 | VALUES('timeline-max-comment',$blobLimit,now())" |
| 860 | set blobReply [blob_page /timeline?n=1] |
| 861 | test blob-truncate-utf8-$blobLimit {$CODE == 0 && |
| 862 | [regexp {utf caf([^<.]*)\.\.\.\n} $blobReply -> blobGot] && |
| 863 | [blob_hex $blobGot] eq $blobLeft} |
| 864 | } |
| 865 | # A setting of 0, a negative one, and one longer than the comment leave |
| 866 | # the comment whole. |
| 867 | foreach blobLimit {0 -1 21 22 500} { |
| 868 | fossil sql "REPLACE INTO config(name,value,mtime) |
| 869 | VALUES('timeline-max-comment',$blobLimit,now())" |
| 870 | set blobReply [blob_page /timeline?n=1] |
| 871 | test blob-truncate-utf8-whole-$blobLimit {$CODE == 0 && |
| 872 | [regexp {utf caf([^<]*) tail\n} $blobReply -> blobGot] && |
| 873 | [blob_hex $blobGot] eq "c3a9e282acf09f9880"} |
| 874 | } |
| 875 | fossil sql "DELETE FROM config WHERE name='timeline-max-comment'" |
| 876 | |
| 877 | ############################################################################### |
| 878 | # "fossil clean --prompt" asks about each unmanaged file and takes the |
| 879 | # first letter of the answer in either case: "n" keeps the file, "a" |
| 880 | # removes it and all the others without asking again, "y" removes it. |
| 881 | # Each row: the answer given to every question, and the files that must |
| 882 | # be left. |
| 883 | |
| 884 | proc blob_clean {answer} { |
| 885 | foreach name {clean-1.tmp clean-2.tmp} { write_file $name "tmp\n" } |
| 886 | fossil_raw -input "$answer\n$answer\n$answer\n" clean --prompt \ |
| 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 {} |
| 898 | upper-y Y {} |
| 899 | lower-a a {} |
| 900 | upper-a A {} |
| 901 | } { |
| 902 | set blobGot [blob_clean $blobAnswer] |
| 903 | test blob-clean-prompt-$blobName {$CODE == 0 && $blobGot eq $blobLeft && |
| 904 | [string first "Remove unmanaged file \"clean-1.tmp\" (a=all/y/N)?" \ |
| 905 | $RESULT] >= 0} |
| 906 | } |
| 907 | # After "a" the second file is removed without a question. |
| 908 | blob_clean a |
| 909 | test blob-clean-prompt-all-asks-once {$CODE == 0 && |
| 910 | [string first "\"clean-2.tmp\"" $RESULT] < 0} |
| 911 | # An empty answer, and an answer that is none of the letters offered, |
| 912 | # keep the file. |
| 913 | foreach {blobName blobAnswer} { |
| 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 |
| 926 | # "aaaa bbbbX-ccccc" and whether a line 13 wide, 9 of which are margin, |
| 927 | # may end after the hyphen. |
| 928 | |
| 929 | foreach {blobName blobChar blobBreaks} { |
| 930 | lower-a a 1 |
| 931 | lower-z z 1 |
| 932 | upper-a A 1 |
| 933 | upper-z Z 1 |
| 934 | digit 1 0 |
| 935 | at-sign @ 0 |
| 936 | bracket \[ 0 |
| 937 | underscore _ 0 |
| 938 | backquote ` 0 |
| 939 | brace \{ 0 |
| 940 | tilde ~ 0 |
| 941 | } { |
| 942 | fossil_raw test-comment-format -W 13 "aaaa bbbb${blobChar}-ccccc" |
| 943 | test blob-isalpha-$blobName {$CODE == 0 && ($blobBreaks |
| 944 | ? [string first "\n ${blobChar}-\n" $RESULT] >= 0 |
| 945 | : [string first "\n ${blobChar}-cc\n" $RESULT] >= 0)} |
| 946 | } |
| 947 | |
| 948 | ############################################################################### |
| 949 | # A three-way merge of files whose last line has no line end. |
| 950 | |
| 951 | # Merge the contents $one and $two, which both come from $base. Returns |
| 952 | # the merged content; CODE is the exit status of the merge. |
| 953 | proc blob_merge {base one two} { |
| 954 | write_file merge.0 $base |
| 955 | write_file merge.1 $one |
| 956 | write_file merge.2 $two |
| 957 | file delete merge.out |
| 958 | fossil_raw 3-way-merge merge.0 merge.1 merge.2 merge.out |
| 959 | return [read_file merge.out] |
| 960 | } |
| 961 | |
| 962 | test blob-merge-no-final-newline-edit \ |
| 963 | {[blob_merge "a\nb\nc" "A\nb\nc" "a\nb\nC"] eq "A\nb\nC" && $CODE == 0} |
| 964 | test blob-merge-no-final-newline-same \ |
| 965 | {[blob_merge "a\nb\nc" "a\nB\nc" "a\nB\nc"] eq "a\nB\nc" && $CODE == 0} |
| 966 | test blob-merge-empty {[blob_merge "" "" ""] eq "" && $CODE == 0} |
| 967 | |
| 968 | # Both sides change the last line, which has no line end: a conflict, |
| 969 | # with each side's line whole between the marks. |
| 970 | set blobMerged [blob_merge "a\nb" "a\nONE" "a\nTWO"] |
| 971 | test blob-merge-no-final-newline-conflict {$CODE == 0 && |
| 972 | [string first "1 merge conflicts" $RESULT] >= 0 && |
| 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 | |
| 986 | if {$::tcl_platform(platform) eq "unix"} { |
| 987 | write_file link-target.txt "content of the target\n" |
| 988 | file link -symbolic link-on.lnk link-target.txt |
| 989 | fossil settings allow-symlinks on |
| 990 | fossil add link-on.lnk |
| 991 | fossil commit -m "link, symlinks on" --no-warnings link-on.lnk |
| 992 | fossil_raw cat link-on.lnk -r tip |
| 993 | test blob-read-link-as-name {$CODE == 0 && $RESULT eq "link-target.txt"} |
| 994 | fossil settings allow-symlinks off |
| 995 | file link -symbolic link-off.lnk link-target.txt |
| 996 | fossil add link-off.lnk |
| 997 | fossil commit -m "link, symlinks off" --no-warnings link-off.lnk |
| 998 | fossil_raw cat link-off.lnk -r tip |
| 999 | test blob-read-link-as-file {$CODE == 0 && |
| 1000 | $RESULT eq "content of the target\n"} |
| 1001 | } |
| 1002 | |
| 1003 | ############################################################################### |
| 1004 | test_cleanup |
+2052
| --- a/test/cgi.test | ||
| +++ b/test/cgi.test | ||
| @@ -0,0 +1,2052 @@ | ||
| 1 | +# | |
| 2 | +# How a server reads a request: src/cgi.c. Requests are written to a | |
| 3 | +# file and given to "fossil http --in", which handles one request as a | |
| 4 | +# server does and writes the reply to a file. The page /test-env shows | |
| 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 | + | |
| 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 | + request.txt $textULT] >= 0 | |
| 26 | + && [reply_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"} | |
| 27 | +} | |
| 28 | + | |
| 29 | +####{*}$args | |
| 30 | + if a server reads a request a ################### | |
| 31 | +# A reque } | |
| 32 | + return "" | |
| 33 | +} | |
| 34 | + | |
| 35 | +# The same, as a local administrator. | |
| 36 | +proc cgi_admin {text args} { | |
| 37 | + return [cgi_send $text --ipaddr 127.0.0.1 --localauth {*}$args] | |
| 38 | +} | |
| 39 | + | |
| 40 | +# The ] | |
| 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 - } | |
| 48 | + incr start [expr {[string length $name] + 4}] | |
| 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_headernot show it. | |
| 57 | +proc cgi_end [string first "\r\n\r\n" $r [string range $reply $start [expr {$end - 1}]] | |
| 58 | +} | |
| 59 | + | |
| 60 | +# A POST request with BODY as its content, of the type TYPE, and the | |
| 61 | +# header lines in HEADERS, a list. | |
| 62 | +proc cgi_post {type body {path /test-env} {headers {}}} { | |
| 63 | + return [request_post $path $body $headers $type] | |
| 64 | +} | |
| 65 | + | |
| 66 | +# A POST of the form data BODY to PATH, sent from the page REFERER. | |
| 67 | +proc cgi_post_from {referer path body} { | |
| 68 | + return [cgi_post application/x-www-form-urlencoded $body $path \ | |
| 69 | + [list "Referer: $referer"]] | |
| 70 | +} | |
| 71 | + | |
| 72 | +############################################################################### | |
| 73 | +# Plain HTTP. | |
| 74 | + | |
| 75 | +set cgiReply [cgi_admin \ | |
| 76 | + "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"] | |
| 77 | +test cgi-get {$CODE == 0} | |
| 78 | +test_eq cgi-get-status [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 79 | +test_eq cgi-get-plain [cgi_param $cgiReply a] 1 | |
| 80 | +test_eq cgi-get-plus [cgi_param $cgiReply b] "two words" | |
| 81 | +test_eq cgi-get-escape [cgi_param $cgiReply c] AB | |
| 82 | +test_eq cgi-get-empty [cgi_param $cgiReply d] "" | |
| 83 | +test_eq cgi-get-no-value [cgi_param $cgiReply e] "" | |
| 84 | + | |
| 85 | +set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded \ | |
| 86 | + "x=1&y=a%20b&Z=upper"]] | |
| 87 | +test_eq cgi-post-form [cgi_param $cgiReply x] 1 | |
| 88 | +test_eq cgi-post-form-escape [cgi_param $cgiReply y] "a b" | |
| 89 | +test_eq cgi-post-form-upper [cgi_param $cgiReply z] upper | |
| 90 | + | |
| 91 | +foreach {cgiName cgiRequest} [list \ | |
| 92 | + no-method "\r\n\r\n" \ | |
| 93 | + bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 94 | +] { | |
| 95 | + set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1] | |
| 96 | + test cgi-malformed-$cgiName \ | |
| 97 | + {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]} | |
| 98 | +} | |
| 99 | + | |
| 100 | +# A request line with no path is a request for the home page. | |
| 101 | +set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1] | |
| 102 | +test_eq cgi-no-path [reply_status $cgiReply] "HTTP/1.0 302 Moved Temporarily" | |
| 103 | + | |
| 104 | +############################################################################### | |
| 105 | +# Form data in several parts, as a browser sends an upload. | |
| 106 | + | |
| 107 | +proc cgi_part {name body {extra ""}} { | |
| 108 | + return \ | |
| 109 | + [join [list \ | |
| 110 | + "--XB\r\n" \ | |
| 111 | + "Content-Disposition: form-data; " \ | |
| 112 | + "name=\"$name\"$extra\r\n\r\n$body\r\n"] ""] | |
| 113 | +} | |
| 114 | +set cgiType "multipart/form-data; boundary=XB" | |
| 115 | + | |
| 116 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 117 | + "[cgi_part alpha {first value}][cgi_part upload {file body} \ | |
| 118 | + {; filename="a.txt"}]--XB--\r\n"]] | |
| 119 | +test_eq cgi-multipart [cgi_param $cgiReply alpha] "first value" | |
| 120 | +test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body" | |
| 121 | +test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt | |
| 122 | +test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9 | |
| 123 | + | |
| 124 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 125 | + [join [list \ | |
| 126 | + "--XB\r\n" \ | |
| 127 | + "Content-Disposition: form-data; name=\"t\"; " \ | |
| 128 | + "filename=\"t.bin\"\r\n" \ | |
| 129 | + "Content-Type: application/octet-stream\r\n\r\nxyz\r\n" \ | |
| 130 | + "--XB--\r\n"] ""]]] | |
| 131 | +test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \ | |
| 132 | + application/octet-stream | |
| 133 | + | |
| 134 | +# A name that begins with a capital is taken in lower case. | |
| 135 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 136 | + "[cgi_part Upper v {; filename="F.TXT"}]--XB--\r\n"]] | |
| 137 | +test_eq cgi-multipart-upper [cgi_param $cgiReply upper] v | |
| 138 | +test_eq cgi-multipart-upper-filename [cgi_param $cgiReply upper:filename] F.TXT | |
| 139 | + | |
| 140 | +# Lines may end with a bare newline. | |
| 141 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 142 | + "--XB\nContent-Disposition: form-data; name=\"lf\"\n\nvalue\n--XB--\n"]] | |
| 143 | +test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value | |
| 144 | + | |
| 145 | +# A part with no closing boundary after a long one ends at the end of the | |
| 146 | +# request, and every part is read within the request. | |
| 147 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 148 | + [join [list \ | |
| 149 | + "[cgi_part alpha [string repeat x 3000]]--XB\r\n" \ | |
| 150 | + "Content-Disposition: form-data; name=\"beta\"\r\n\r\n" \ | |
| 151 | + "no 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" | |
| 157 | + | |
| 158 | +# Malformed and unusual bodies are read without a crash. | |
| 159 | +set cgiI 0 | |
| 160 | +foreach cgiBody [list \ | |
| 161 | + "" \ | |
| 162 | + "\r\n\r\nvalue\r\n\r\n" \ | |
| 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 | + [join [list \ | |
| 169 | + "--XB\r\n" \ | |
| 170 | + "Content-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n" \ | |
| 171 | + "--XB--\r\n"] ""] \ | |
| 172 | + [join [list \ | |
| 173 | + "--[string repeat B 3000]\r\n" \ | |
| 174 | + "Content-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n"] ""] \ | |
| 175 | + [join [list \ | |
| 176 | + "[cgi_part a [string repeat x 2000]]--XB\r\n" \ | |
| 177 | + "Content-Disposition: form-data; name=\"b\""] ""] \ | |
| 178 | + "[cgi_part {} v]--XB--\r\n" \ | |
| 179 | + [join [list \ | |
| 180 | + "--XB\r\n" \ | |
| 181 | + "Content-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n" \ | |
| 182 | + "--XB--\r\n"] ""] \ | |
| 183 | + [join [list \ | |
| 184 | + "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\n" \ | |
| 185 | + "v\r\n--XB--\r\n"] ""] \ | |
| 186 | + "--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \ | |
| 187 | + [join [list \ | |
| 188 | + "--XB\r\n" \ | |
| 189 | + "Content-Disposition: form-data; name=\"a\"; " \ | |
| 190 | + "filename=\r\n\r\nv\r\n--XB--\r\n"] ""] \ | |
| 191 | + [join [list \ | |
| 192 | + "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\n" \ | |
| 193 | + "content-type:\r\n\r\nv\r\n--XB--\r\n"] ""] \ | |
| 194 | + "[cgi_part a "\n--X"]--XB--\r\n" \ | |
| 195 | +] { | |
| 196 | + incr cgiI | |
| 197 | + cgi_admin [cgi_post $cgiType $cgiBody] | |
| 198 | + test cgi-multipart-odd-$cgiI {$CODE == 0} | |
| 199 | +} | |
| 200 | +set cgiMany "" | |
| 201 | +for {set cgiI 0} {$cgiI < 400} {incr cgiI} { | |
| 202 | + append cgiMany [cgi_part p$cgiI [string repeat v [expr {$cgiI % 50}]]] | |
| 203 | +} | |
| 204 | +set cgiReply [cgi_admin [cgi_post $cgiType "$cgiMany--XB--\r\n"]] | |
| 205 | +test_eq cgi-multipart-many [cgi_param $cgiReply p399] [string repeat v 49] | |
| 206 | + | |
| 207 | +############################################################################### | |
| 208 | +# The date in an If-Modified-Since header. A file that has not changed | |
| 209 | +# since that date is not sent again. | |
| 210 | + | |
| 211 | +proc cgi_since {date} { | |
| 212 | + set reply [cgi_send \ | |
| 213 | + "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" \ | |
| 214 | + --ipaddr 127.0.0.1] | |
| 215 | + return [reply_status $reply] | |
| 216 | +} | |
| 217 | +test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \ | |
| 218 | + "HTTP/1.0 304 Not Modified" | |
| 219 | +test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \ | |
| 220 | + "HTTP/1.0 200 OK" | |
| 221 | +test_eq cgi-since-garbage [cgi_since "yesterday"] "HTTP/1.0 200 OK" | |
| 222 | +# Numbers out of range are not a date. | |
| 223 | +foreach {cgiName cgiDate} { | |
| 224 | + year "Mon, 01 Jan 2147483647 00:00:00 GMT" | |
| 225 | + day "Mon, 2147483647 Jan 2026 00:00:00 GMT" | |
| 226 | + hour "Mon, 01 Jan 2026 2147483647:00:00 GMT" | |
| 227 | + minute "Mon, 01 Jan 2026 00:2147483647:00 GMT" | |
| 228 | +} { | |
| 229 | + test_eq cgi-since-huge-$cgiName [cgi_since $cgiDate] "HTTP/1.0 200 OK" | |
| 230 | +} | |
| 231 | + | |
| 232 | +############################################################################### | |
| 233 | +# A reply is compressed with gzip when the client accepts it and the type | |
| 234 | +# of the content is text, JavaScript, JSON, WebAssembly, Tcl, tar, XML, | |
| 235 | +# SVG or an icon. Other types, and a client that does not accept gzip, | |
| 236 | +# get the content as it is. | |
| 237 | + | |
| 238 | +foreach {cgiName cgiGzip} { | |
| 239 | + g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1 | |
| 240 | + g.ico 1 g.png 0 g.zip 0 g.pdf 0 | |
| 241 | +} { | |
| 242 | + write_file $cgiName [string repeat "content to compress\n" 50] | |
| 243 | + fossil uv add $cgiName | |
| 244 | + set cgiReply [cgi_send \ | |
| 245 | + [join [list \ | |
| 246 | + "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\n" \ | |
| 247 | + "Accept-Encoding: gzip, deflate\r\n\r\n"] ""] --ipaddr 127.0.0.1] | |
| 248 | + test_eq cgi-gzip-$cgiName \ | |
| 249 | + [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip | |
| 250 | +} | |
| 251 | +set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 252 | + --ipaddr 127.0.0.1] | |
| 253 | +test cgi-gzip-not-accepted {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 254 | + && ![string match "*Content-Encoding*" $cgiReply]} | |
| 255 | + | |
| 256 | +############################################################################### | |
| 257 | +# A POST whose Referer is another site is not taken as safe from forgery, | |
| 258 | +# and is written to the error log. | |
| 259 | + | |
| 260 | +proc cgi_logout {referer} { | |
| 261 | + return [cgi_send [cgi_post_from $referer /login "out=1"] --ipaddr 10.0.0.1 \ | |
| 262 | + --errorlog [file join [pwd] err.log]] | |
| 263 | +} | |
| 264 | +file delete err.log | |
| 265 | +cgi_logout http://x/login | |
| 266 | +test cgi-same-origin-not-logged {![file exists err.log] | |
| 267 | + || ![string match "*different origin*" [read_file err.log]]} | |
| 268 | +cgi_logout http://elsewhere.example/page | |
| 269 | +test cgi-other-origin-logged {[file exists err.log] | |
| 270 | + && [string match "*POST from different origin*" [read_file err.log]]} | |
| 271 | + | |
| 272 | +############################################################################### | |
| 273 | +# SCGI: a header of name and value pairs, each ended by a zero byte, | |
| 274 | +# preceded by its length and followed by a comma. | |
| 275 | + | |
| 276 | +proc cgi_scgi {pairs {body ""}} { | |
| 277 | + set h "" | |
| 278 | + foreach {k v} $pairs { append h $k \000 $v \000 } | |
| 279 | + return "[string length $h]:$h,$body" | |
| 280 | +} | |
| 281 | +set cgiReply [cgi_send [cgi_scgi { | |
| 282 | + CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1 | |
| 283 | + PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80 | |
| 284 | + REMOTE_ADDR 127.0.0.1 | |
| 285 | +}] --scgi --localauth] | |
| 286 | +test_eq cgi-scgi [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 287 | +test_eq cgi-scgi-param [cgi_param $cgiReply s] 1 | |
| 288 | + | |
| 289 | +foreach {cgiName cgiRequest} [list \ | |
| 290 | + too-short "15:CONTENT_LENGTH\0000\000," \ | |
| 291 | + cut-short "40:CONTENT_LENGTH\0000\000," \ | |
| 292 | + no-zero "20:CONTENT_LENGTH0000000000," \ | |
| 293 | + huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \ | |
| 294 | +] { | |
| 295 | + set cgiReply [cgi_send $cgiRequest --scgi] | |
| 296 | + test cgi-scgi-$cgiName {$CODE == 0 && | |
| 297 | + [string match "HTTP/1.0 400*" [reply_status $cgiReply]]} | |
| 298 | +} | |
| 299 | + | |
| 300 | +############################################################################### | |
| 301 | +# The same reader for a request that arrives over ssh, which the server | |
| 302 | +# knows from SSH_CONNECTION. It reads the client's probes first. | |
| 303 | + | |
| 304 | +set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" | |
| 305 | +set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 306 | + --localauth] | |
| 307 | +test_eq cgi-ssh [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 308 | +test_eq cgi-ssh-param [cgi_param $cgiReply q] 1 | |
| 309 | +test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1 | |
| 310 | + | |
| 311 | +set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \ | |
| 312 | + "p=posted"] --localauth] | |
| 313 | +test_eq cgi-ssh-post [cgi_param $cgiReply p] posted | |
| 314 | + | |
| 315 | +# An older client opens the connection with "echo" probes, each of which | |
| 316 | +# the server answers with the word it was given, and then names the | |
| 317 | +# command it ran. Any other word in a probe is refused. | |
| 318 | +set cgiReply [cgi_send \ | |
| 319 | + [join [list \ | |
| 320 | + "echo test1\necho probe-2\nfossil\n" \ | |
| 321 | + "GET /test-env?q=3 HTTP/1.1\r\nHost: x\r\n\r\n"] ""] --localauth] | |
| 322 | +test cgi-ssh-probes {[string match "test1\nprobe-2\n*" $cgiReply] | |
| 323 | + && [string match "*\nHTTP/1.0 200 OK*" $cgiReply]} | |
| 324 | +test_eq cgi-ssh-probes-param [cgi_param $cgiReply q] 3 | |
| 325 | +foreach {cgiName cgiRequest} [list \ | |
| 326 | + probe-word "echo hello\n" \ | |
| 327 | + probe-alone "echo\n" \ | |
| 328 | + probe-no-command "echo test1\n" \ | |
| 329 | +] { | |
| 330 | + set cgiReply [cgi_send $cgiRequest --localauth] | |
| 331 | + test cgi-ssh-$cgiName {$CODE == 0 | |
| 332 | + && [string match "*400 Bad Request*" $cgiReply]} | |
| 333 | +} | |
| 334 | + | |
| 335 | +foreach {cgiName cgiRequest} [list \ | |
| 336 | + empty "" \ | |
| 337 | + bad-method "PUT /x HTTP/1.1\r\n\r\n" \ | |
| 338 | + no-url "GET\r\n\r\n" \ | |
| 339 | + long-line "GET /[string repeat a 5000] HTTP/1.1\r\n\r\n" \ | |
| 340 | +] { | |
| 341 | + cgi_send $cgiRequest | |
| 342 | + test cgi-ssh-$cgiName {$CODE == 0 || $CODE == 1} | |
| 343 | +} | |
| 344 | +unset ::env(SSH_CONNECTION) | |
| 345 | + | |
| 346 | +############################################################################### | |
| 347 | +# The tests above try each kind of request once. The tests below aim | |
| 348 | +# at every branch of cgi.c. | |
| 349 | + | |
| 350 | +if {[test_assurance] eq "smoke"} { | |
| 351 | + test_skip "the tests of each branch need -assurance ci or stress" | |
| 352 | +} | |
| 353 | + | |
| 354 | +############################################################################### | |
| 355 | +# Names and values in a query string and in a Cookie header. A name is | |
| 356 | +# taken when it begins with a letter and holds only letters, digits, | |
| 357 | +# "_" and "-"; of two values with one name the first is kept; a value | |
| 358 | +# from the query string that holds a control character is dropped. | |
| 359 | + | |
| 360 | +set cgiReply [cgi_admin [request_get \ | |
| 361 | + "/test-env?e&a=1&=5&&a\$b=6&c=%01x&1a=2&_u=3&a=second&Up=4&zz" \ | |
| 362 | + [list "Cookie: ck=1; sp=2; fossil-x=9; Big=3"]]] | |
| 363 | +foreach {cgiName cgiParam cgiValue} { | |
| 364 | + no-value-first e "" | |
| 365 | + plain a 1 | |
| 366 | + empty-name "" - | |
| 367 | + strange-name a$b - | |
| 368 | + control-char c - | |
| 369 | + digit-first 1a - | |
| 370 | + underscore _u - | |
| 371 | + upper up 4 | |
| 372 | + no-value-last zz "" | |
| 373 | + cookie ck 1 | |
| 374 | + cookie-space sp 2 | |
| 375 | + cookie-upper big 3 | |
| 376 | + cookie-fossil fossil-x - | |
| 377 | + cookie-header HTTP_COOKIE - | |
| 378 | +} { | |
| 379 | + test_eq cgi-names-$cgiName [cgi_param $cgiReply $cgiParam] $cgiValue | |
| 380 | +} | |
| 381 | + | |
| 382 | +# With "showall" the page shows the cookies as well. | |
| 383 | +set cgiReply [cgi_admin [request_get /test-env?showall \ | |
| 384 | + [list "Cookie: ck=1; fossil-x=9"]]] | |
| 385 | +test_eq cgi-showall-cookie [cgi_param $cgiReply fossil-x] 9 | |
| 386 | +test_eq cgi-showall-header [cgi_param $cgiReply HTTP_COOKIE] "ck=1; fossil-x=9" | |
| 387 | + | |
| 388 | +# A value in a form may hold a control character. | |
| 389 | +set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded \ | |
| 390 | + "k=%01x&plain=1"]] | |
| 391 | +test_eq cgi-post-control-char [cgi_param $cgiReply k] "\001x" | |
| 392 | + | |
| 393 | +# More than 630 parameters are refused. | |
| 394 | +set cgiMany "" | |
| 395 | +for {set cgiI 0} {$cgiI < 700} {incr cgiI} { append cgiMany "q$cgiI=1&" } | |
| 396 | +set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded $cgiMany]] | |
| 397 | +test cgi-too-many {$CODE == 1 | |
| 398 | + && [string match "*Too many query parameters*" $cgiReply$RESULT]} | |
| 399 | + | |
| 400 | +############################################################################### | |
| 401 | +# The request line and the header lines. | |
| 402 | + | |
| 403 | +set cgiReply [cgi_admin \ | |
| 404 | + [join [list \ | |
| 405 | + "GET /test-env?showall HTTP/1.1\r\n" \ | |
| 406 | + "HOST: named.example:8080\r\nIf-None-Match: tag\r\n" \ | |
| 407 | + "Authorization: Basic eDp5\r\nAccept-Language: de \r\n" \ | |
| 408 | + "User-Agent: Agent/1\r\nUnknown-Header: ignored\r\n\r\n"] ""]] | |
| 409 | +foreach {cgiParam cgiValue} { | |
| 410 | + HTTP_HOST named.example:8080 | |
| 411 | + SERVER_NAME named.example | |
| 412 | + HTTP_IF_NONE_MATCH tag | |
| 413 | + HTTP_AUTHORIZATION {Basic eDp5} | |
| 414 | + HTTP_ACCEPT_LANGUAGE de | |
| 415 | + HTTP_USER_AGENT Agent/1 | |
| 416 | + REQUEST_SCHEME http | |
| 417 | + REQUEST_METHOD GET | |
| 418 | +} { | |
| 419 | + test_eq cgi-header-$cgiParam [cgi_param $cgiReply $cgiParam] $cgiValue | |
| 420 | +} | |
| 421 | + | |
| 422 | +# An "Https:" header says that the request came by https, so the reply | |
| 423 | +# sends a local user to the https login page. | |
| 424 | +set cgiReply [cgi_admin [request_get /test-env [list "Https: on"]]] | |
| 425 | +test_eq cgi-header-https [reply_header $cgiReply Location] \ | |
| 426 | + https://x/login?g=test-env | |
| 427 | + | |
| 428 | +# X-Forwarded-For names the client when the request comes from this | |
| 429 | +# machine: the last address in it is taken. From any other machine the | |
| 430 | +# header is ignored. Only a local client sees /test-env here. | |
| 431 | +foreach {cgiName cgiFrom cgiForwarded cgiAddr} { | |
| 432 | + one ::1 127.0.0.1 127.0.0.1 | |
| 433 | + comma 127.0.0.1 9.9.9.9,::1 ::1 | |
| 434 | + space 127.0.0.1 {9.9.9.9, 127.0.0.1} 127.0.0.1 | |
| 435 | + mapped 127.0.0.1 ::ffff:127.0.0.1 ::ffff:127.0.0.1 | |
| 436 | + remote 127.0.0.1 {127.0.0.1, 9.9.9.9} - | |
| 437 | + empty 127.0.0.1 {} - | |
| 438 | + not-local 10.0.0.1 127.0.0.1 - | |
| 439 | +} { | |
| 440 | + set cgiReply [cgi_send [request_get /test-env \ | |
| 441 | + [list "X-Forwarded-For: $cgiForwarded"]] --ipaddr $cgiFrom --localauth] | |
| 442 | + test_eq cgi-forwarded-$cgiName [cgi_param $cgiReply REMOTE_ADDR] $cgiAddr | |
| 443 | +} | |
| 444 | + | |
| 445 | +# HEAD gets the headers of the reply to GET and no content. | |
| 446 | +set cgiReply [cgi_send [request_get /uv/g.png {} HEAD] --ipaddr 127.0.0.1] | |
| 447 | +test_eq cgi-head-status [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 448 | +test_eq cgi-head-length [reply_header $cgiReply Content-Length] 1000 | |
| 449 | +test_eq cgi-head-body [reply_body $cgiReply] "" | |
| 450 | + | |
| 451 | +# A POST must say how long its content is, and send that much. | |
| 452 | +set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\n\r\n"] | |
| 453 | +test cgi-post-no-length {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request" | |
| 454 | + && [string match "*missing CONTENT_LENGTH on a POST method*" $cgiReply]} | |
| 455 | +set cgiReply [cgi_admin \ | |
| 456 | + [join [list \ | |
| 457 | + "POST /test-env HTTP/1.1\r\nHost: x\r\n" \ | |
| 458 | + "Content-Type: application/x-www-form-urlencoded\r\n" \ | |
| 459 | + "Content-Length: 50\r\n\r\na=1"] ""]] | |
| 460 | +test cgi-post-short {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request" | |
| 461 | + && [string match "*Wanted 50 bytes but got only 3*" $cgiReply]} | |
| 462 | +# Content with no type is not read. | |
| 463 | +set cgiReply [cgi_admin \ | |
| 464 | + "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\n\r\na=1"] | |
| 465 | +test cgi-post-no-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 466 | + && [cgi_param $cgiReply a] eq "-"} | |
| 467 | +foreach {cgiName cgiLength} \ | |
| 468 | + {negative -5 zero 0 word abc huge 99999999999999999999} { | |
| 469 | + set cgiReply [cgi_admin \ | |
| 470 | + [join [list \ | |
| 471 | + "POST /test-env HTTP/1.1\r\nHost: x\r\n" \ | |
| 472 | + "Content-Type: application/x-www-form-urlencoded\r\ [list \ | |
| 473 | + "POST /teng match "*missing C5 && [regexp {^HTTP/1.0 (200|400) } $cgiReply]} | |
| 474 | +} | |
| 475 | + | |
| 476 | +############################################################################### | |
| 477 | +# Part of a file: a Range header on a GET that succeeds gets the bytes | |
| 478 | +# asked for, not compressed, with status 206. | |
| 479 | + | |
| 480 | +write_file r.css 0123456789abcdefghij | |
| 481 | +fossil uv add r.css | |
| 482 | +proc cgi_range {range {method GET} {file r.css}} { | |
| 483 | + return [cgi_send [request_get /uv/$file \ | |
| 484 | + [file \ | |
| 485 | + [list "Range: $range" "Accept-Encoding: gzip"] $method] \ | |
| 486 | + --ipaddr 127.0.0.1] | |
| 487 | +} | |
| 488 | +set cgiReply [cgi_range bytes=2-5] | |
| 489 | +test_eq cgi-range-s 200 OK" \ | |
| 490 | + $::trunkMark | |
| 491 | +# A reply other than 206 is sent whole, whatever range was asked for. | |
| 492 | +set cgiReply [cgi_send [request_get /uv/nosuch.css [list "Range: bytes=3-9"]] \ | |
| 493 | + --ipaddr 127.0.0.1] | |
| 494 | +test cgi-range-not-found { | |
| 495 | + [string match "HTTP/1.0 404 *" [reply_status $cgiReply]] | |
| 496 | + && [string match "<!DOCTYPE | |
| 497 | + | |
| 498 | +############################################################################### | |
| 499 | +# More shapes of form data in several parts. | |
| 500 | + | |
| 501 | +proc cgi_form {body} { | |
| 502 | + global cgiType | |
| 503 | + return [cgi_admin [cgi_post $cgiType $body]] | |
| 504 | +} | |
| 505 | +# A part with no content, where lines end with a bare newline. | |
| 506 | +set cgiReply [cgi_form \ | |
| 507 | + "--XB\nContent-Disposition: form-data; name=\"none\"\n\n\n--XB--\n"] | |
| 508 | +test_eq cgi-multipart-empty-value [cgi_param $cgiReply none] "" | |
| 509 | + | |
| 510 | +# A name in capitals with no file name is taken in lower case and has no | |
| 511 | +# count of bytes. | |
| 512 | +set cgiReply [cgi_form "[cgi_part Shout loud]--XB--\r\n"] | |
| 513 | +test_eq cgi-multipart-upper-plain [cgi_param $cgiReply shout] loud | |
| 514 | +test_eq cgi-multipart-upper-no-bytes [cgi_param $cgiReply shout:bytes] - | |
| 515 | + | |
| 516 | +# A name in capitals with a type of content. | |
| 517 | +set cgiReply [cgi_form \ | |
| 518 | + [join [list \ | |
| 519 | + "--XB\r\n" \ | |
| 520 | + "Content-Disposition: form-data; name=\"Typed\"; " \ | |
| 521 | + "filename=\"t\"\r\nContent-Type: text/x-test\r\n\r\nv\r\n" \ | |
| 522 | + "--XB--\r\n"] ""]] | |
| 523 | +test_eq cgi-multipart-upper-mimetype [cgi_param $cgiReply typed:mimetype] \ | |
| 524 | + text/x-test | |
| 525 | +test_eq cgi-multipart-upper-bytes [cgi_param $cgiReply typed:bytes] 1 | |
| 526 | + | |
| 527 | +# A name that does not begin with a letter is not taken, with or without | |
| 528 | +# a file name or a type. | |
| 529 | +set cgiReply [cgi_form \ | |
| 530 | + [join [list \ | |
| 531 | + "--XB\r\n" \ | |
| 532 | + "Content-Disposition: form-data; name=\"1st\"; " \ | |
| 533 | + "fir\nContent-Type: text/plain\r\n\r\nv\r\n" \ | |
| 534 | + "[cgi_part after ok]--XB--\r\n"] ""]] | |
| 535 | +test_eq cgi-multipart-digit-name [cgi_param $cgiReply 1st] - | |
| 536 | +test_eq cgi-multipart-digit-filename [cgi_param $cgiReply 1st:filename] - | |
| 537 | +test_eq cgi-multipart-digit-mimetype [cgi_param $cgiReply 1st:mimetype] - | |
| 538 | +test_eq cgi-multipart-digit-next [cgi_param $cgiReply after] ok | |
| 539 | + | |
| 540 | +# A type or a file name given before the name belongs to no parameter. | |
| 541 | +set cgiReply [cgi_form \ | |
| 542 | + [join [list \ | |
| 543 | + "--XB\r\nContent-Type: text/early\r\n" \ | |
| 544 | + "Content-Disposition: form-data; filename=\"early\"; " \ | |
| 545 | + "name=\"late\"\r\n\r\nv\r\n--XB--\r\n"] ""]] | |
| 546 | +test_eq cgi-multipart-type-first-value [cgi_param $cgiReply late] v | |
| 547 | +test_eq cgi-multipart-type-first-mimetype [cgi_param $cgiReply late:mimetype] - | |
| 548 | +test_eq cgi-multipart-type-first-filename [cgi_parfter] eq "ok"} $::trunkMark | |
| 549 | + | |
| 550 | +# Content that begins with a zero byte has no parts. | |
| 551 | +set cgiReply [cgi_form "\000--XB\r\n[cgi_part a v]--XB--\r\n"] | |
| 552 | +test cgi-multipart-zero-first {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 553 | + && [cgi_param $cgiReply a] eq "-"} | |
| 554 | + | |
| 555 | +############################################################################### | |
| 556 | +# More dates in If-Modified-Since. The file is given the time that the | |
| 557 | +# date stands for and is then not sent again; one second newer and it is. | |
| 558 | + | |
| 559 | +write_file d.bin "dated" | |
| 560 | +fossil uv add d.bin | |
| 561 | +proc cgi_since_exact {date seconds} { | |
| 562 | + set result "" | |
| 563 | + foreach mtime [list $seconds [expr {$seconds + 1}]] { | |
| 564 | + fossil sql "UPDATE unversioned SET mtime=$mtime WHERE name='d.bin'" | |
| 565 | + set reply [cgi_send [request_get /uv/d.bin \ | |
| 566 | + [list "If-Modified-Since: $date"]] \ | |
| 567 | + --ipaddr 127.0.0.1] | |
| 568 | + lappend result [lindex [reply_status $reply] 1] | |
| 569 | + } | |
| 570 | + return $result | |
| 571 | +} | |
| 572 | +foreach {cgiName cgiDate cgiSeconds} { | |
| 573 | + epoch-year "Thu, 01 Jan 1970 00:00:10 GMT" 10 | |
| 574 | + two-digit-year "Fri, 31 Dec 99 23:59:59 GMT" 946684799 | |
| 575 | + leap-2000-feb "Tue, 29 Feb 2000 12:00:00 GMT" 951825600 | |
| 576 | + leap-2000-mar "Wed, 01 Mar 2000 00:00:00 GMT" 951868800 | |
| 577 | + leap-2024-jan "Wed, 31 Jan 2024 00:00:00 GMT" 1706659200 | |
| 578 | + leap-2024-dec "Tue, 31 Dec 2024 23:59:60 GMT" 1735689600 | |
| 579 | + plain-2023-mar "Wed, 01 Mar 2023 01:02:03 GMT" 1677632523 | |
| 580 | + not-leap-2100 "Mon, 01 Mar 2100 00:00:00 GMT" 4107456000 | |
| 581 | + year-8099 "Thu, 31 Dec 9999 23:59:59 GMT" 253402300799 | |
| 582 | +} { | |
| 583 | + test_eq cgi-since-exact-$cgiName [cgi_since_exact $cgiDate $cgiSeconds] \ | |
| 584 | + {304 200} | |
| 585 | +} | |
| 586 | +# Each of these is not a date, so the file is sent. | |
| 587 | +fossil sql "UPDATE unversioned SET mtime=1 WHERE name='d.bin'" | |
| 588 | +foreach {cgiName cgiDate} { | |
| 589 | + year-before-1970 "Wed, 01 Jan 69 00:00:00 GMT" | |
| 590 | + year-10000 "Sat, 01 Jan 10000 00:00:00 GMT" | |
| 591 | + day-zero "Mon, 00 Jan 2026 00:00:00 GMT" | |
| 592 | + day-32 "Mon, 32 Jan 2026 00:00:00 GMT" | |
| 593 | + hour-negative "Mon, 01 Jan 2026 -1:00:00 GMT" | |
| 594 | + hour-24 "Mon, 01 Jan 2026 24:00:00 GMT" | |
| 595 | + minute-negative "Mon, 01 Jan 2026 00:-1:00 GMT" | |
| 596 | + minute-60 "Mon, 01 Jan 2026 00:60:00 GMT" | |
| 597 | + second-negative "Mon, 01 Jan 2026 00:00:-1 GMT" | |
| 598 | + second-61 "Mon, 01 Jan 2026 00:00:61 GMT" | |
| 599 | + month "Mon, 01 Foo 2026 00:00:00 GMT" | |
| 600 | + short "Mon, 01 Jan 2026" | |
| 601 | + empty "" | |
| 602 | +} { | |
| 603 | + set cgiReply [cgi_send [request_get /uv/d.bin \ | |
| 604 | + [list "If-Modified-Since: $cgiDate"]] --ipaddr 127.0.0.1] | |
| 605 | + test_eq cgi-since-not-a-date-$cgiName [reply_status $cgiReply] \ | |
| 606 | + "HTTP/1.0 200 OK" | |
| 607 | +} | |
| 608 | + | |
| 609 | +############################################################################### | |
| 610 | +# Redirects. A redirect to an absolute URL is sent as it is; a redirect | |
| 611 | +# to a path that begins with "/" is made relative to the base URL; any | |
| 612 | +# other target is appended to the base URL. The "referer" query | |
| 613 | +# parameter, the Referer header, or a default supplies the target for | |
| 614 | +# the user-edit cancel button. | |
| 615 | + | |
| 616 | +proc cgi_redirect_to {query {referer none}} { | |
| 617 | + set headers {} | |
| 618 | + if {$referer ne "none"} { lappend headers "Referer: $referer" } | |
| 619 | + set reply [cgi_admin [request_get "/setup_uedit?$query" $headers]] | |
| 620 | + return [reply_header $reply Location] | |
| 621 | +} | |
| 622 | +# The cancel button redirects to the referer. | |
| 623 | +test_eq cgi-redirect-absolute-http [cgi_redirect_to can=1 http://other/p] \ | |
| 624 | + http://other/p | |
| 625 | +test_eq cgi-redirect-absolute-https [cgi_redirect_to can=1 https://other/p] \ | |
| 626 | + https://other/p | |
| 627 | +test_eq cgi-redirect-rooted [cgi_redirect_to {can=1&referer=/at-root}] \ | |
| 628 | + http://x/at-root | |
| 629 | +test_eq cgi-redirect-relative [cgi_redirect_to {can=1&referer=some/where}] \ | |
| 630 | + http://x/some/where | |
| 631 | +# With no referer parameter and no Referer header, the default is used. | |
| 632 | +test_eq cgi-redirect-default [cgi_redirect_to can=1] http://x/setup_ulist | |
| 633 | +# The "referer" query parameter is preferred over the Referer header. | |
| 634 | +test_eq cgi-redirect-param-wins \ | |
| 635 | + [cgi_redirect_to {can=1&referer=/from-param} http://x/from-header] \ | |
| 636 | + http://x/from-param | |
| 637 | + | |
| 638 | +############################################################################### | |
| 639 | +# The anti-forgery check. A GET from the same origin is "same origin" | |
| 640 | +# only; a POST adds "POST"; a POST that also carries the right "csrf" | |
| 641 | +# token adds "CSRF token". The page reports the level it reached. | |
| 642 | + | |
| 643 | +proc cgi_csrf_level {reply} { | |
| 644 | + if {[regexp {CSRF safety = ([^<]*)} $reply all level]} { return $level } | |
| 645 | + return - | |
| 646 | +} | |
| 647 | +set cgiToken "" | |
| 648 | +set cgiReply [cgi_admin [request_get /setup_uedit?id=0]] | |
| 649 | +regexp {name="csrf" value="([^"]*)"} $cgiReply all cgiToken | |
| 650 | + | |
| 651 | +set cgiReply [cgi_admin [request_get /test-env [list "Referer: http://x/prev"]]] | |
| 652 | +test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin" | |
| 653 | +proc cgi_env_post {body {referer http://x/prev}} { | |
| 654 | + return [cgi_admin [cgi_post_from $referer /test-env $body]] | |
| 655 | +} | |
| 656 | +set cgiReply [cgi_env_post "csrf=$cgiToken"] | |
| 657 | +test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] \ | |
| 658 | + "Same origin, POST, CSRF token" | |
| 659 | +set cgiReply [cgi_env_post "csrf=wrong"] | |
| 660 | +test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST" | |
| 661 | +set cgiReply [cgi_env_post "x=1" http://elsewhere/p] | |
| 662 | +test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe" | |
| 663 | + | |
| 664 | +# A page that consults the check more than once. A cross-origin POST to | |
| 665 | +# the user-edit page, which asks twice, is ignored without error. | |
| 666 | +set cgiReply [cgi_admin [cgi_post_from http://elsewhere/p /setup_uedit \ | |
| 667 | + "id=0&delete=1&"]] | |
| 668 | +test_eq cgi-csrf-twice-cross [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 669 | +# A valid same-origin POST with the token creates the user. | |
| 670 | +set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken" | |
| 671 | +set cgiReply [cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit \ | |
| 672 | + $cgiBody]] | |
| 673 | +test cgi-csrf-verify-accepts \ | |
| 674 | + {[string match "HTTP/1.0 302*" [reply_status $cgiReply]]} | |
| 675 | +test cgi-csrf-user-created \ | |
| 676 | + {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1} | |
| 677 | + | |
| 678 | +# The user-edit page needs "login", "info", "pw" and "apply" to make a | |
| 679 | +# change. A request with "login" alone changes nothing. | |
| 680 | +set cgiBody "id=0&login=cgighost&csrf=$cgiToken" | |
| 681 | +cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit $cgiBody] | |
| 682 | +test cgi-all-needs-every-field \ | |
| 683 | + {[fossil sql "SELECT count(*) FROM user WHE | |
| 684 | + | |
| 685 | +############################################################################### | |
| 686 | +# rev"]]] | |
| 687 | +test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin" | |
| 688 | +proc cgi_env_post {body {referer http://x/prev}} { | |
| 689 | + return [cgi_admin [cgi_post_from $referer /test-env $body]] | |
| 690 | +} | |
| 691 | +set cgiReply [cgi_env_post "csrf=$cgiToken"] | |
| 692 | +test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] \ | |
| 693 | + "Same origin, POST, CSRF token" | |
| 694 | +set cgiReply [cgi_env_post "csrf=wrong"] | |
| 695 | +test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST" | |
| 696 | +set cgiReply [cgi_env_post "x=1" http://elsewhere/p] | |
| 697 | +test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe" | |
| 698 | + | |
| 699 | +# A page that consults the check more than once. A cross-origin POST to | |
| 700 | +# the user-edit page, which asks twice, is ignored without error. | |
| 701 | +set cgiReply [cgi_admin [cgi_post_from http://elsewhere/p /setup_uedit \ | |
| 702 | + "id=0&delete=1&"]] | |
| 703 | +test_eq cgi-csrf-twice-cross [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 704 | +# A valid same-origin POST with the token creates the user. | |
| 705 | +set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken" | |
| 706 | +set cgiReply [cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit \ | |
| 707 | + $cgiBody]] | |
| 708 | +test cgi-csrf-verify-accepts \ | |
| 709 | + {[string match "HTTP/1.0 302*" [reply_status $cgiReply]]} | |
| 710 | +test cgi-csrf-user-created \ | |
| 711 | + {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1} | |
| 712 | + | |
| 713 | +# The user-edit page needs "login", "info", "pw" and "apply" to make a | |
| 714 | +# change. A request with "login" alone changes nothing. | |
| 715 | +set cgiBody "id=0&login=cgighost&csrf=$cgiToken" | |
| 716 | +cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit $cgiBody] | |
| 717 | +test cgi-all-needs-every-field \ | |
| 718 | + {[fossil sql "SELECT count(*) FROM user WHERE login='cgighost'"] == 0} \ | |
| 719 | + $::trunkMark | |
| 720 | + | |
| 721 | +############################################################################### | |
| 722 | +# Request methods and the same reader over ssh. | |
| 723 | + | |
| 724 | +set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" | |
| 725 | +# A HEAD over ssh. | |
| 726 | +set cgiReply [cgi_send [request_get /test-env?q=9 {} HEAD] --localauth] | |
| 727 | +test_eq cgi-ssh-head [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 728 | +unset ::env(SSH_CONNECTION) | |
| 729 | + | |
| 730 | +############################################################################### | |
| 731 | +# cgi_from_mobile, used by /forum to pick a default display order. An | |
| 732 | +# iPad is not treated as mobile; another phone is; no agent is not. | |
| 733 | +proc cgi_forum_order {agent} { | |
| 734 | + set headers {} | |
| 735 | + if {$agent ne ""} { lappend headers "User-Agent: $agent" } | |
| 736 | + set reply [cgi_admin [request_get /forum?t=a $headers]] | |
| 737 | + return [reply_status $reply] | |
| 738 | +} | |
| 739 | +foreach {cgiName cgiAgent} { | |
| 740 | + phone "Mozilla/5.0 (iPhone; Mobile) Safari" | |
| 741 | + ipad "Mozilla/5.0 (iPad) Safari" | |
| 742 | + none "" | |
| 743 | +} { | |
| 744 | + test_eq cgi-mobile-$cgiName [cgi_forum_order $cgiAgent] "HTTP/1.0 200 OK" | |
| 745 | +} | |
| 746 | + | |
| 747 | +############################################################################### | |
| 748 | +# A spider check. For a request that is not logged in, an unused query | |
| 749 | +# parameter whose value looks like an injection attack gets a 418 reply | |
| 750 | +# and a note in the error log. The whole request environment is written | |
| 751 | +# to the log. | |
| 752 | + | |
| 753 | +proc cgi_attack {value} { | |
| 754 | + global cgiRepo | |
| 755 | + write_file request.txt \ | |
| 756 | + [join [list \ | |
| 757 | + "GET /timeline?inj=$value HTTP/1.1\r\nHost: x\r\n" \ | |
| 758 | + "Cookie: fossil-x=secret\r\n\r\n"] ""] | |
| 759 | + file delete reply.txt attack.log | |
| 760 | + fossil_raw http $cgiRepo --in request.txt --out reply.txt \ | |
| 761 | + --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log] | |
| 762 | + return [expr {[file exists reply.txt] ? [read_file reply.txt] : ""}] | |
| 763 | +} | |
| 764 | +set cgiReply [cgi_attack "1;select"] | |
| 765 | +test_eq cgi-attack-status [reply_status $cgiReply] "HTTP/1.0 418 I'm a teapot" | |
| 766 | +test cgi-attack-logged {[file exists attack.log] | |
| 767 | + && [string match "*possible hack attempt*" [read_file attack.log]] | |
| 768 | + && [string match "*QUERY_STRING = inj=1;select*" [read_file attack.log]]} | |
| 769 | +# A value longer than 100 characters is shortened in the log. | |
| 770 | +set cgiReply [cgi_attack "[string repeat a 200];x"] | |
| 771 | +test cgi-attack-long {[reply_status $cgiReply] eq "HTTP/1.0 418 I'm a teapot" | |
| 772 | + && [string match "*aaa...*" [read_file attack.log]]} | |
| 773 | +# A logged-in request with the same value is not stopped. | |
| 774 | +set cgiReply [cgi_admin [request_get "/timeline?inj=1;select"]] | |
| 775 | +test_eq cgi-attack-admin-ok [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 776 | + | |
| 777 | +############################################################################### | |
| 778 | +# The same-origin test with crafted Referer headers. The base URL here | |
| 779 | +# is "http://x". A Referer that shares the base but has more path after | |
| 780 | +# it with no "/" boundary is a different origin. A Referer with a "%" | |
| 781 | +# escape is decoded before the comparison. The /test-env page reports | |
| 782 | +# the result. | |
| 783 | + | |
| 784 | +proc cgi_origin {referer} { | |
| 785 | + set req "GET /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\n\r\n" | |
| 786 | + set reply [cgi_admin $req] | |
| 787 | + return [cgi_csrf_level $reply] | |
| 788 | +} | |
| 789 | +test_eq cgi-origin-boundary [cgi_origin http://xtra/page] unsafe | |
| 790 | +test_eq cgi-origin-escaped [cgi_origin http://x/a%2Fb] "Same origin" | |
| 791 | +# A different-origin GET reaches the method test in the same-origin check | |
| 792 | +# without writing a warning (the warning is for POST only). | |
| 793 | +test_eq cgi-origin-get-other [cgi_origin http://elsewhere/p] unsafe | |
| 794 | + | |
| 795 | +############################################################################### | |
| 796 | +# cgi_parameter_name walks every parameter: the ticket-entry page copies | |
| 797 | +# each into its interpreter. | |
| 798 | + | |
| 799 | +set cgiReply [cgi_admin [request_get "/tktnew?username=someone&extra=1"]] | |
| 800 | +test_eq cgi-param-name-page [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 801 | + | |
| 802 | +############################################################################### | |
| 803 | +# cgi_param_info walks the parameters for the /cookies page. | |
| 804 | + | |
| 805 | +set cgiReply [cgi_admin [request_get /cookies \ | |
| 806 | + [list "Cookie: fossil_display_settings=x; extra=y"]]] | |
| 807 | +test cgi-param-info-page {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 808 | + && [string match "*fossil_display_settings*" $cgiReply]} | |
| 809 | + | |
| 810 | +############################################################################### | |
| 811 | +# Two more destinations for cgi_print_all. With --cgitrace the whole | |
| 812 | +# parameter set is traced before the page runs. | |
| 813 | + | |
| 814 | +write_file request.txt [request_get "/test-env?traced=1"] | |
| 815 | +file delete reply.txt | |
| 816 | +fossil_raw http $cgiRepo --in request.txt --out reply.txt \ | |
| 817 | + --ipaddr 127.0.0.1 --localauth --cgitrace | |
| 818 | +test cgi-cgitrace {$CODE == 0 | |
| 819 | + && [string match "*Calling*" $RESULT] | |
| 820 | + && [string match "*traced = 1*" $RESULT]} | |
| 821 | + | |
| 822 | +# A CGI control file with "cgi-debug:" writes the environment to a debug | |
| 823 | +# file as the control file is read. | |
| 824 | +write_file cgi.ctl \ | |
| 825 | + "repository: [file nativename $cgiRepo]\ncgi-debug: debug.txt\n" | |
| 826 | +file delete debug.txt | |
| 827 | +set ::env(REQUEST_METHOD) GET | |
| 828 | +set ::env(SCRIPT_NAME) "" | |
| 829 | +set ::env(PATH_INFO) /test-env | |
| 830 | +set ::env(QUERY_STRING) "dbg=1" | |
| 831 | +set ::env(REMOTE_ADDR) 127.0.0.1 | |
| 832 | +fossil_raw cgi cgi.ctl | |
| 833 | +foreach cgiVar {REQUEST_METHOD SCRIPT_NAME PATH_INFO QUERY_STRING REMOTE_ADDR} { | |
| 834 | + unset ::env($cgiVar) | |
| 835 | +} | |
| 836 | +test cgi-debug-file {[file exists debug.txt] | |
| 837 | + && [string match "*QUERY_STRING = dbg=1*" [read_file debug.txt]]} | |
| 838 | + | |
| 839 | +############################################################################### | |
| 840 | +# Trimmed, boolean and "checked" parameter readers, reached through the | |
| 841 | +# email-alert subscription page. The page exists once email is enabled | |
| 842 | +# and its tables are built. | |
| 843 | + | |
| 844 | +fossil settings email-send-method db | |
| 845 | +set cgiNotifyBody "submit=Refresh&esm=db&csrf=$cgiToken" | |
| 846 | +cgi_admin [cgi_post_from http://x/setup_notification /setup_notification \ | |
| 847 | + $cgiNotifyBody] | |
| 848 | +test cgi-alert-tables-built \ | |
| 849 | + {[fossil sql "SELECT count(*) FROM sqlite_schema WHERE name='subscriber'"] | |
| 850 | + == 1} | |
| 851 | + | |
| 852 | +# The form renders the "checked" state of the checkboxes. | |
| 853 | +set cgiReply [cgi_admin [request_get /subscribe]] | |
| 854 | +test cgi-subscribe-form {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 855 | + && [string match "*checkbox*" $cgiReply]} | |
| 856 | + | |
| 857 | +# A submitted subscription: the name is trimmed and the boxes are read as | |
| 858 | +# booleans. A leading and trailing space on the name is removed. | |
| 859 | +set cgiSubBody \ | |
| 860 | + [join [list \ | |
| 861 | + "submit=1&[email protected]&suname= trimmed " \ | |
| 862 | + "&sa=1&sc=on&csrf=$cgiToken"] ""] | |
| 863 | +cgi_admin [cgi_post_from http://x/subscribe /subscribe $cgiSubBody] | |
| 864 | +test_eq cgi-subscribe-trimmed-name \ | |
| 865 | + [fossil sql \ | |
| 866 | + "SELECT suname FROM subscriber WHERE semail='[email protected]'"] \ | |
| 867 | + "trimmed" | |
| 868 | +test cgi-subscribe-boolean-alert \ | |
| 869 | + {[string match "*a*" [fossil sql \ | |
| 870 | + "SELECT ssub FROM subscriber WHERE semail='[email protected]'"]]} | |
| 871 | + | |
| 872 | +############################################################################### | |
| 873 | +# The HTTP reader is called in a loop for a request arriving over ssh. | |
| 874 | +# When the first request announces the Fossil ssh transport, the reader | |
| 875 | +# is called again for a second request in the same connection, and the | |
| 876 | +# later request updates the parameters that the first one set. | |
| 877 | + | |
| 878 | +set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" | |
| 879 | +write_file request.txt \ | |
| 880 | + [join [list \ | |
| 881 | + "GET /test-env?first=1 HTTP/1.1\r\nHost: x\r\n" \ | |
| 882 | + "X-Fossil-Transport: ssh\r\nContent-Length: 0\r\n\r\n" \ | |
| 883 | + "G | |
| 884 | +set cgiReply [cgi_cookie_delete https://x/d] | |
| 885 | +test cgi-cookie-delete-secure {[string match "*max-age=-1;*secure;*" $cgiReply] | |
| 886 | + || [string match "*max-age=-1;* secure*" $cgiReply]} | |
| 887 | + | |
| 888 | +############################################################################### | |
| 889 | +# Compression of several reply content types that are named by the "m" | |
| 890 | +# parameter on a raw artifact. A committed file gives a blob to serve. | |
| 891 | + | |
| 892 | +write_file art.txt "the quick brown fox jumps over the lazy dog\n" | |
| 893 | +fossil add art.txt | |
| 894 | +fossil commit -m "add art" --no-warnings | |
| 895 | +set cgiArt [fossil sql \ | |
| 896 | + "SELECT uuid FROM blob WHERE rid=(SELECT max(rid) FROM blob)"] | |
| 897 | +proc cgi_raw_type {mime} { | |
| 898 | + global cgiArt | |
| 899 | + set reply [cgi_send [request_get /raw/$cgiArt?m=$mime \ | |
| 900 | + [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth] | |
| 901 | + return [reply_header $reply Content-Encoding] | |
| 902 | +} | |
| 903 | +foreach {cgiName cgiMime} { | |
| 904 | + javascript application/javascript | |
| 905 | + json application/json | |
| 906 | + wasm application/wasm | |
| 907 | + xtcl application/x-tcl | |
| 908 | + xtar application/x-tar | |
| 909 | + appxml application/customxml | |
| 910 | +} { | |
| 911 | + test_eq cgi-raw-gzip-$cgiName [cgi_raw_type $cgiMime] gzip | |
| 912 | +} | |
| 913 | +# A type outside the compressible set is sent as-is. | |
| 914 | +test_eq cgi-raw-no-gzip [cgi_raw_type application/octet-stream] - | |
| 915 | +############################################################################### | |
| 916 | +# More content types. A type that begins with "a" but is no[string math "*max-age=Range: bytes=4-8"]] --ipaddr 9.9.9.9] | |
| 917 | +test_eq cgi-range-artifact [reply_body $cgiReply] quick | |
| 918 | +test_eq cgi-range-artifact-cache [reply_header $cgiReply Cache-Control] \ | |
| 919 | + "max-age=315360000, immutable" | |
| 920 | + | |
| 921 | +############################################################################### | |
| 922 | +# The "at" parameter of /raw names the file for the client to save the | |
| 923 | +# content in. Only its last path element is used, and every character | |
| 924 | +# in it other than a letter, a digit, "." and "-" becomes "_". | |
| 925 | + | |
| 926 | +set cgiReply [cgi_send [request_get \ | |
| 927 | + "/raw/$cgiArt?at=some/dir/my%20file-1%3B.txt"] \ | |
| 928 | + --ipaddr 127.0.0.1 --localauth] | |
| 929 | +test_eq cgi-attachment-name [reply_header $cgiReply Content-Disposition] \ | |
| 930 | + {attachment; filename="my_file-1_.txt";} | |
| 931 | + | |
| 932 | +############################################################################### | |
| 933 | +# A request that is refused before any repository is open: the server is | |
| 934 | +# given a directory, and the request has a method it does not know. | |
| 935 | + | |
| 936 | +file mkdir norepo | |
| 937 | +write_file request.txt "DELETE /x HTTP/1.1\r\nHost: x\r\n\r\n" | |
| 938 | +file delete reply.txt | |
| 939 | +fossil_raw http [file join [pwd] norepo] --in request.txt --out reply.txt \ | |
| 940 | + --ipaddr 127.0.0.1 | |
| 941 | +test cgi-no-repository-bad-method {$CODE == 0 | |
| 942 | + && [reply_status [read_file reply.txt]] eq "HTTP/1.0 400 Bad Request"} | |
| 943 | + | |
| 944 | +################## | |
| 945 | +write_fil/test-env?traced=2] | |
| 946 | +eferer that is the base URL and | |
| 947 | +# nothing more is the same origin. | |
| 948 | + | |
| 949 | +test_eq cgi-origin-exact [cgi_origin http://x] "Same origin" | |
| 950 | + | |
| 951 | +############################################################################### | |
| 952 | +# With --httptrace the server reports each parameter as it is set and | |
| 953 | +# copies the request into a file named httplog-NNNNN.txt in the current | |
| 954 | +# directory. If it cannot make that file it says so and goes on. | |
| 955 | + | |
| 956 | +foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog } | |
| 957 | +write_file request.txt [request_get /test-env?traced=2] | |
| 958 | +file delete reply.txt | |
| 959 | +fossil_raw http $cgiRepo --in request.txt --out reply.txt \ | |
| 960 | + --ipaddr 127.0.0.1 --localauth --httptrace | |
| 961 | +set cgiLogs [glob -nocomplain httplog-*.txt] | |
| 962 | +test cgi-httptrace {$CODE == 0 && | |
| 963 | + [holds_strings $RESULT [list "# cgi: traced = \[2\]" \ | |
| 964 | + "# open log on httplog-"]] && [llength $cgiLogs] == 1} | |
| 965 | +if {[llength $cgiLogs] == 1} { | |
| 966 | + set cgiLogText [read_file [lindex $cgiLogs 0]] | |
| 967 | + test cgi-httptrace-log { | |
| 968 | + [string match "GET /test-env?traced=2 HTTP/1.1*Host: x*" $cgiLogText]} | |
| 969 | + file delete [lindex $cgiLogs 0] | |
| 970 | +} | |
| 971 | +# The file holds the header and the content of a POST. | |
| 972 | +write_file request.txt [cgi_post application/x-www-form-urlencoded "body=sent"] | |
| 973 | +fossil_raw http $cgiRepo --in request.txt --out reply.txt \ | |
| 974 | + --ipaddr 127.0.0.1 --localauth --httptrace | |
| 975 | +set cgiLogs [glob -nocomplain httplog-*.txt] | |
| 976 | +set cgiLogText "" | |
| 977 | +foreach cgiLog $cgiLogs { | |
| 978 | + append cgiLogText [read_file $cgiLog] | |
| 979 | + file delete $cgiLog | |
| 980 | +} | |
| 981 | +test cgi-httptrace-post-content {[string match "*body=sent" $cgiLogText]} | |
| 982 | +test cgi-httptrace-post-header \ | |
| 983 | + {[string match "POST /test-env HTTP/1.1*" $cgiLogText]} $::trunkMark | |
| 984 | +write_file request.txt [request_get /test-env?traced=2] | |
| 985 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 986 | + set cgiHere [pwd] | |
| 987 | + file mkdir readonly | |
| 988 | + file attributes readonly -permissions 0555 | |
| 989 | + cd readonly | |
| 990 | + fossil_raw http $cgiRepo --in [file join $cgiHere request.txt] \ | |
| 991 | + --out [file join $cgiHere reply.txt] \ | |
| 992 | + --ipaddr 127.0.0.1 --localauth --httptrace | |
| 993 | + cd $cgiHere | |
| 994 | + file attributes readonly -permissions 0755 | |
| 995 | + test cgi-httptrace-no-log {$CODE == 0 | |
| 996 | + && [string first "# failed to open httplog-" $RESULT] >= 0 | |
| 997 | + && [reply_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"} | |
| 998 | +} | |
| 999 | + | |
| 1000 | +############################################################################### | |
| 1001 | +# A request for the top of the site is sent on to the index page. A | |
| 1002 | +# login-card cookie in such a request is taken once. | |
| 1003 | + | |
| 1004 | +set cgiReply [cgi_admin [request_get / [list "Cookie: x-f-l-c=card-value"]]] | |
| 1005 | +test_eq cgi-login-card-home [reply_header $cgiReply Location] http://x/index | |
| 1006 | + | |
| 1007 | +############################################################################### | |
| 1008 | +# The honeypot page offers a visitor who is not logged in a captcha, and | |
| 1009 | +# keeps the URL that was asked for, with its query parameters, in a | |
| 1010 | +# cookie. | |
| 1011 | + | |
| 1012 | +set cgiReply [cgi_send [request_get "/honeypot?a=1&b&c=two"] --ipaddr 9.9.9.9] | |
| 1013 | +test cgi-original-url {[string first \ | |
| 1014 | + "Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fa%3D1%26b%26c%3Dtwo;" \ | |
| 1015 | + $cgiReply] >= 0} | |
| 1016 | + | |
| 1017 | +############################################################################### | |
| 1018 | +# The "ss" parameter of /timeline is checked for an attack as soon as it | |
| 1019 | +# is read, for a visitor who is not logged in. | |
| 1020 | + | |
| 1021 | +write_file request.txt [request_get "/timeline?ss=1;select"] | |
| 1022 | +file delete reply.txt attack.log | |
| 1023 | +fossil_raw http $cgiRepo --in request.txt --out reply.txt \ | |
| 1024 | + --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log] | |
| 1025 | +test cgi-attack-read-parameter { | |
| 1026 | + [reply_status [read_file reply.txt]] eq "HTTP/1.0 418 I'm a teapot" | |
| 1027 | + && [string match "*418 response on \"ss\"*" [read_file attack.log]]} | |
| 1028 | +set cgiReply [cgi_admin [request_get "/timeline?ss=m"]] | |
| 1029 | +test_eq cgi-attack-read-parameter-admin [reply_status $cgiReply] \ | |
| 1030 | + "HTTP/1.0 200 OK" | |
| 1031 | + | |
| 1032 | +############################################################################### | |
| 1033 | +# SSH_CONNECTION names the client only when it holds an address followed | |
| 1034 | +# by a space. Otherwise the request is read as plain HTTP from an | |
| 1035 | +# unknown address, which --localauth does not log in. | |
| 1036 | + | |
| 1037 | +foreach {cgiName cgiValue} {empty "" one-word nospace} { | |
| 1038 | + set ::env(SSH_CONNECTION) $cgiValue | |
| 1039 | + set cgiReply [cgi_send [request_get /test-env] --localauth] | |
| 1040 | + unset ::env(SSH_CONNECTION) | |
| 1041 | + test_eq cgi-ssh-connection-$cgiName [reply_header $cgiReply Location] \ | |
| 1042 | + http://x/login?g=test-env | |
| 1043 | +} | |
| 1044 | + | |
| 1045 | +############################################################################### | |
| 1046 | +# SCGI: SCRIPT_NAME, PATH_INFO and REQUEST_URI. The server needs | |
| 1047 | +# SCRIPT_NAME, or both of the others to work it out from; and one of | |
| 1048 | +# PATH_INFO and REQUEST_URI, from which it works out the other. If | |
| 1049 | +# SCRIPT_NAME is not the start of REQUEST_URI, it is cut down to the | |
| 1050 | +# part that is. | |
| 1051 | + | |
| 1052 | +# The reply to an SCGI request with the name and value PAIRS added to | |
| 1053 | +# the usual ones: the status and the error for a request that is | |
| 1054 | +# refused, or else the status and what /test-env shows for SCRIPT_NAME, | |
| 1055 | +# PATH_INFO and REQUEST_URI. | |
| 1056 | +proc cgi_scgi_names {pairs} { | |
| 1057 | + set reply [cgi_send [cgi_scgi [concat { | |
| 1058 | + CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SERVER_NAME x SERVER_PORT 80 | |
| 1059 | + REMOTE_ADDR 127.0.0.1 | |
| 1060 | + } $pairs]] --scgi --localauth] | |
| 1061 | + set status [lindex [reply_status $reply] 1] | |
| 1062 | + if {$status eq "400"} { | |
| 1063 | + return [list 400 [string trim [reply_body $reply]]] | |
| 1064 | + } | |
| 1065 | + if {$status ne "200"} { return $status } | |
| 1066 | + return [list 200 [cgi_param $reply SCRIPT_NAME] [cgi_param $reply PATH_INFO] \ | |
| 1067 | + [cgi_param $reply REQUEST_URI]] | |
| 1068 | +} | |
| 1069 | +foreach {cgiName cgiPairs cgiWant} { | |
| 1070 | + nothing | |
| 1071 | + {} | |
| 1072 | + {400 {Bad SCGI Request: missing SCRIPT_NAME}} | |
| 1073 | + uri-only | |
| 1074 | + {REQUEST_URI /test-env} | |
| 1075 | + {400 {Bad SCGI Request: missing SCRIPT_NAME}} | |
| 1076 | + path-only | |
| 1077 | + {PATH_INFO /test-env} | |
| 1078 | + {400 {Bad SCGI Request: missing SCRIPT_NAME}} | |
| 1079 | + path-not-in-uri | |
| 1080 | + {REQUEST_URI /abc PATH_INFO /test-env} | |
| 1081 | + {400 {Bad SCGI Request: PATH_INFO not found in REQUEST_URI}} | |
| 1082 | + script-from-uri-and-path | |
| 1083 | + {REQUEST_URI /pre/test-env PATH_INFO /test-env} | |
| 1084 | + {200 /pre /test-env /pre/test-env} | |
| 1085 | + script-only | |
| 1086 | + {SCRIPT_NAME {}} | |
| 1087 | + {400 {Bad SCGI Request: missing PATH_INFO and/or REQUEST_URI}} | |
| 1088 | + uri-from-path | |
| 1089 | + {SCRIPT_NAME {} PATH_INFO /test-env} | |
| 1090 | + {200 {} /test-env /test-env} | |
| 1091 | + uri-from-path-empty-query | |
| 1092 | + {SCRIPT_NAME {} PATH_INFO /test-env QUERY_STRING {}} | |
| 1093 | + {200 {} /test-env /test-env} | |
| 1094 | + uri-from-path-and-query | |
| 1095 | + {SCRIPT_NAME {} PATH_INFO /test-env QUERY_STRING s=1} | |
| 1096 | + {200 {} /test-env /test-env?s=1} | |
| 1097 | + uri-from-path-no-slash | |
| 1098 | + {SCRIPT_NAME /pre PATH_INFO test-env/x} | |
| 1099 | + 404 | |
| 1100 | + path-from-uri | |
| 1101 | + {SCRIPT_NAME {} REQUEST_URI /test-env} | |
| 1102 | + {200 {} /test-env /test-env} | |
| 1103 | + path-from-uri-with-query | |
| 1104 | + {SCRIPT_NAME {} REQUEST_URI /test-env?s=1 QUERY_STRING s=1} | |
| 1105 | + {200 {} /test-env /test-env?s=1} | |
| 1106 | + script-cut-down | |
| 1107 | + {SCRIPT_NAME /abcd REQUEST_URI /abc/test-env} | |
| 1108 | + {200 /abc /test-env /abc/test-env} | |
| 1109 | + uri-is-script | |
| 1110 | + {SCRIPT_NAME /abc REQUEST_URI /abc} | |
| 1111 | + 302 | |
| 1112 | +} { | |
| 1113 | + test_eq cgi-scgi-names-$cgiName [cgi_scgi_names $cgiPairs] $cgiWant | |
| 1114 | +} | |
| 1115 | +foreach {cgiName cgiRequest cgiError} [list \ | |
| 1116 | + empty "" "SCGI header too short" \ | |
| 1117 | + length-only "20" "cannot read entire SCGI header" \ | |
| 1118 | +] { | |
| 1119 | + set cgiReply [cgi_send $cgiRequest --scgi] | |
| 1120 | + test cgi-scgi-$cgiName {$CODE == 0 | |
| 1121 | + && [reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request" | |
| 1122 | + && [string match "*$cgiError*" $cgiReply]} | |
| 1123 | +} | |
| 1124 | + | |
| 1125 | +############################################################################### | |
| 1126 | +# Page aliases. An alias in the configuration names a page and query | |
| 1127 | +# parameters for it: "NAME=VALUE" sets a parameter, replacing one of the | |
| 1128 | +# same name in the request; a name in capitals is taken in lower case; | |
| 1129 | +# "NAME!" removes a parameter of the request. | |
| 1130 | + | |
| 1131 | +fossil sql \ | |
| 1132 | + "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias','/test-env?a=new&Bb=2&gone!&absent!&fresh',0)" | |
| 1133 | +fossil sql \ | |
| 1134 | + [join [list \ | |
| 1135 | + "REPLACE INTO config(name,value,mtime) " \ | |
| 1136 | + "VALUES('walias:/cgialias2','/test-env?zz!',0)"] ""] | |
| 1137 | +set cgiReply [cgi_admin [request_get "/cgialias?a=old&gone=1&keep=3"]] | |
| 1138 | +test_eq cgi-alias-replace [cgi_param $cgiReply a] new | |
| 1139 | +test_eq cgi-alias-upper [cgi_param $cgiReply bb] 2 | |
| 1140 | +test_eq cgi-alias-delete [cgi_param $cgiReply gone] - | |
| 1141 | +test_eq cgi-alias-add [cgi_param $cgiReply fresh] "" | |
| 1142 | +test_eq cgi-alias-keep [cgi_param $cgiReply keep] 3 | |
| 1143 | +set cgiReply [cgi_admin [request_get "/cgialias2?m=1&zz=9"]] | |
| 1144 | +test {cgi-alias-delete-last} {[cgi_param $cgiReply zz] eq "-" | |
| 1145 | + && [cgi_param $cgiReply m] eq "1"} | |
| 1146 | + | |
| 1147 | +############################################################################### | |
| 1148 | +# The configuration page saves the text given for the main menu, unless | |
| 1149 | +# the request also asks for the menu to be reset: then the saved menu is | |
| 1150 | +# removed and the text is not looked at. | |
| 1151 | + | |
| 1152 | +proc cgi_menu_post {fields} { | |
| 1153 | + global cgiToken | |
| 1154 | + set body "$fields&csrf=$cgiToken" | |
| 1155 | + set reply [cgi_admin [cgi_post_from http://x/setup_config /setup_config \ | |
| 1156 | + $body]] | |
| 1157 | + return [list [lindex [reply_status $reply] 1] \ | |
| 1158 | + [fossil sql "SELECT value FROM config WHERE name='mainmenu'"]] | |
| 1159 | +} | |
| 1160 | +test_eq cgi-menu-saved [cgi_menu_post "mmenu=cgi-menu-text&zlast=1"] \ | |
| 1161 | + {200 cgi-menu-text} | |
| 1162 | +test_eq cgi-menu-reset [cgi_menu_post "mmenu=other-text&resetMenu=1&zlast=1"] \ | |
| 1163 | + {200 {}} | |
| 1164 | +test_eq cgi-menu-reset-alone [cgi_menu_post "resetMenu=1"] {200 {}} | |
| 1165 | + | |
| 1166 | +############################################################################### | |
| 1167 | +# More of the trimmed, boolean and "checked" readers on the subscription | |
| 1168 | +# page. A name that is missing or all spaces is no name; a line end of | |
| 1169 | +# CR LF inside a name becomes LF, and a CR alone is kept. A box with an | |
| 1170 | +# empty value is on, and one with the value "off" is off. | |
| 1171 | + | |
| 1172 | +proc cgi_subscribe {email fields} { | |
| 1173 | + global cgiToken | |
| 1174 | + set body "submit=1&e=$email&$fields&csrf=$cgiToken" | |
| 1175 | + cgi_admin [cgi_post_from http://x/subscribe /subscribe $body] | |
| 1176 | + return [fossil sql \ | |
| 1177 | + "SELECT hex(suname), ssub FROM subscriber WHERE semail='$email'"] | |
| 1178 | +} | |
| 1179 | +test_eq cgi-subscribe-no-name [cgi_ | |
| 1180 | + } \ | |
| 1181 | + too-short "15:aracter. | |
| 1182 | +set cgiGI Request from \"TestServer/1\": missing CONTENT_LENGTH*" \ | |
| 1183 | + $cgiReply]} | |
| 1184 | +set cgiReply [cgi_cgi {SCRIPT_NAME /s PATH_INFO /test-env REMOTE_ADDR 127.0.0.1 | |
| 1185 | + HTTP_HOST x HTTP_REFERER http://x/s/prev}] | |
| 1186 | +test_eq cgi-cgi-no-method [cgi_csrf_level $cgiReply] "Same origin" | |
| 1187 | + | |
| 1188 | +# A control file that names a debug file which cannot be opened is used | |
| 1189 | +# all the same. | |
| 1190 | +write_file cgi3.ctl \ | |
| 1191 | + [join [list \ | |
| 1192 | + "repository: [file nativename $cgiRepo]\nlocalauth\n" \ | |
| 1193 | + "cgi-debug: [file join [pwd] nosuchdir debug.txt]\n"] ""] | |
| 1194 | +set ::env(REQUEST_METHOD) GET | |
| 1195 | +set ::env(SCRIPT_NAME) /s | |
| 1196 | +set ::env(PATH_INFO) /test-env | |
| 1197 | +set ::env(QUERY_STRING) "nodebug=1" | |
| 1198 | +set ::env(REMOTE_ADDR) 127.0.0.1 | |
| 1199 | +fossil_raw cgi cgi3.ctl | |
| 1200 | +foreach cgiVar {REQUEST_METHOD SCRIPT_NAME PATH_INFO QUERY_STRING REMOTE_ADDR} { | |
| 1201 | + unset ::env($cgiVar) | |
| 1202 | +} | |
| 1203 | +test cgi-debug-file-unopened {$CODE == 0 | |
| 1204 | + && [string match "Status: 200 OK*" $RESULT] | |
| 1205 | + && [cgi_param $RESULT nodebug] eq "1"} | |
| 1206 | + | |
| 1207 | +############################################################################### | |
| 1208 | +# The JSON interface, where Fossil has it. Content that is not a JSON | |
| 1209 | +# object is refused with error FOSSIL-1101. Content of a type that is | |
| 1210 | +# not JSON is not read as JSON. A request that the web server marks | |
| 1211 | +# "no_json" is not prepared as a JSON request when it is read. | |
| 1212 | + | |
| 1213 | +fothat is reused" | |
| 1214 | +} else { | |
| 1215 | + test | |
| 1216 | +# The value of par# | |
| 1217 | +# How a server reads a reque$cgiReply]} | |
| 1218 | +foreach {cgiName cgiMoreequest_get /timeline?r=More cgiError} [list \ | |
| 1219 | + cut-short "\n" "incorrect transport_flip" \ | |
| 1220 | + not-blank "\nxyz\n" "transport_flip failed" \ | |
| 1221 | + other-command "\n\nother\n" "transport_open failed" \ | |
| 1222 | + no-request "\n\nfossil\n" "missing HTTP header" \ | |
| 1223 | +] { | |
| 1224 | + set cgiReply [cgi_send $cgiFirst$cgiMore --localauth] | |
| 1225 | + test cgi-ssh-flip-$cgiName {$CODE == 0 | |
| 1226 | + && [string match "*first = 1*400 Bad Request*$cgiError*" $cgiReply]} | |
| 1227 | +} | |
| 1228 | +# With nothing after the two blank lines the connection is over. | |
| 1229 | +set cgiReply [cgi_send "$cgiFirst\n\n" --localauth] | |
| 1230 | +test cgi-ssh-flip-end {$CODE == 0 && [string match "*first = 1*" $cgiReply] | |
| 1231 | + && ![string match "*400 Bad Request*" $cgiReply]} | |
| 1232 | +foreach {cgiName cgiRequest cgiError} [list \ | |
| 1233 | + probes-only "echo test1\nfossil\n" "missing HTTP header" \ | |
| 1234 | + blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 1235 | + "unsupported HTTP method" \ | |
| 1236 | + empty-command \ | |
| 1237 | + [join [list \ | |
| 1238 | + "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\n" \ | |
| 1239 | + "Host: x\r\n\r\n\n\nfossil\n"] ""] \ | |
| 1240 | + "transport_open failed" \ | |
| 1241 | + repository-only "GET $cgiRepo HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 1242 | + "malformed URL in HTTP header" \ | |
| 1243 | +] { | |
| 1244 | + set cgiReply [cgi_send $cgiRequest --localauth] | |
| 1245 | + test cgi-ssh-$cgiName {$CODE == 0 | |
| 1246 | + && [string match "*400 Bad Request*$cgiError*" $cgiReply]} | |
| 1247 | +} | |
| 1248 | +set cgiReply [cgi_send [request_get $cgiRepo/test-env?named=1] --localauth] | |
| 1249 | +test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1" | |
| 1250 | + && [cgi_param $cgiReply PATH_INFO] eq "/test-env"} | |
| 1251 | +# The name is taken off only when a "/" or the end follows it, and only | |
| 1252 | +# for GET. | |
| 1253 | +set cgiReply [cgi_send [request_get ${cgiRepo}x/test-env] --localauth] | |
| 1254 | +test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] - | |
| 1255 | +set cgiReply [cgi_send [request_get $cgiRepo/test-env \ | |
| 1256 | + [list "Content-Length: 0"] \ | |
| 1257 | + POST] --localauth] | |
| 1258 | +test_eq cgi-ssLater; the third | |
| 1259 | +# is a GET with no Content-Length and must be served with a length of 0nnection is over. | |
| 1260 | +set cgiReply [cgi_send "$cgiFirst\n\n" --localauth] | |
| 1261 | +test cgi-ssh-flip-end {$CODE == 0 && [string match "*first = 1*" $cgiReply] | |
| 1262 | + && ![string match "*400 Bad Request*" $cgiReply]} | |
| 1263 | +foreach {cgiName cgiRequest cgiError} [list \ | |
| 1264 | + probes-only "echo test1\nfossil\n" "missing HTTP header" \ | |
| 1265 | + blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 1266 | + "unsuppoThird "GET /test-env?c=3 HTTP/1.1\r\nHost: x\r\n\r\n"[string match "*first = $cgiFirst$cgiSecond$cgiThirTP method" \ | |
| 1267 | + empty-command \ | |
| 1268 | + [join [list \ | |
| 1269 | + "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\n" \ | |
| 1270 | + "Host: x\r\n\r\n\n\nfossCONTENT_LENGTH = 0*c = 3 "transport_open fai | |
| 1271 | +unset ::env(SSH_CONNECTION) | |
| 1272 | + | |
| 1273 | +#######################################################Asoon as it | |
| 1274 | +# is read, for a v test cgi-ssh-$cgiName {$CODE == 0 | |
| 1275 | + && [string match "*400 Bad Request*$cgiError*" $cgiReply]} | |
| 1276 | +} | |
| 1277 | +set cgiReply [cgi_send [request_get $cgiRepo/test-env?named=1] --localauth] | |
| 1278 | +test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1" | |
| 1279 | + && [cgi_param $cgiReply PATH_INFO] eq "/test-env"} | |
| 1280 | +# The name is taken off only when a "/" or the end follows it, and only | |
| 1281 | +# for GET. | |
| 1282 | +set cgiReply [cgi_send [request_get ${cgiRepo}x/test-env] --localauth] | |
| 1283 | +test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] - | |
| 1284 | +set cgiReply [cgi_send [request_get $cgiRepo/test-env \ | |
| 1285 | + [list "Content-Length: 0"] \ | |
| 1286 | + POST] --localauth] | |
| 1287 | +test_eq cgi-ssh-repository-post [cgi_param $cgiReply PATH_INFO] - | |
| 1288 | +# Two requests on one ssh connection: the second sends Content-Length | |
| 1289 | +# before a longer header line and must get its length and body. | |
| 1290 | +# knownBug: the second request's Content-Length is read from memory that | |
| 1291 | +# a later header line overwrites. | |
| 1292 | +set cgiFirst \ | |
| 1293 | + [join [list \ | |
| 1294 | + "POST /test-env HTTP/1.1\r\nX-Fossil-Transport: SSH\r\n" \ | |
| 1295 | + "Content-Type: application/x-www-form-urlencoded\r\n" \ | |
| 1296 | + "Content-Length: 3\r\n\r\na=1"] ""] | |
| 1297 | +set cgiSecond \ | |
| 1298 | + [join [list \ | |
| 1299 | + "POST /test-env HTTP/1.1\r\nContent-Length: 3\r\n" \ | |
| 1300 | + "Content-Type: " \ | |
| 1301 | + "application/x-www-form-urlencoded-and-more\r\n\r\nb=2"] ""] | |
| 1302 | +set cgiReply [cgi_send $cgiFirst$cgiSecond --localauth] | |
| 1303 | +test cgi-ssh-later-content-length {$CODE == 0 && [string match \ | |
| 1304 | + [join [list \ | |
| 1305 | + "*CONTENT_LENGTH = 3*a = 1*CONTENT_LENGTH = 3*b = " \ | |
| 1306 | + "2*"] ""] \ | |
| 1307 | + [regsub -all {<[^>]*>} $cgiReply {}]]} knownBug | |
| 1308 | +unset ::env(SSH_CONNECTION) | |
| 1309 | + | |
| 1310 | +############################################################################### | |
| 1311 | +# A visitor who is not logged in reaches a page that is closed to robots | |
| 1312 | +# with a token, and gets a cookie that opens the page afterwards. The | |
| 1313 | +# same value given as a query parameter does not. | |
| 1314 | + | |
| 1315 | +fossil sql \ | |
| 1316 | + [join [list \ | |
| 1317 | + "REPLACE INTO config(name,value,mtime) " \ | |
| 1318 | + "VALUES('robot-restrict','timeline',0)"] ""] | |
| 1319 | +fossil sql \ | |
| 1320 | + [join [list \ | |
| 1321 | + "REPLACE INTO config(name,value,mtime) " \ | |
| 1322 | + "VALUES('token-cgitoken','{\"user\":\"someone\"}',0)"] ""] | |
| 1323 | +proc cgi_robot {path {cookie ""}} { | |
| 1324 | + set headers [list "User-Agent: Agent/1"] | |
| 1325 | + if {$cookie ne ""} { lappend headers "Cookie: $cookie" } | |
| 1326 | + return [cgi_send [request_get $path $headers] --ipaddr 9.9.9.9] | |
| 1327 | +} | |
| 1328 | +set cgiRobot "*Checking to see if you are a robot*" | |
| 1329 | +test cgi-robot-stopped {[string match $cgiRobot [cgi_robot /timeline]]} | |
| 1330 | +set cgiReply [cgi_robot /timeline?token=cgitoken] | |
| 1331 | +set cgiProof "" | |
| 1332 | +regexp {Set-Cookie: fossil-client-ok=(\d+);} $cgiReply all cgiProof | |
| 1333 | +test cgi-robot-token {$cgiProof ne "" && ![string match $cgiRobot $cgiReply]} | |
| 1334 | +test cgi-robot-cookie {![string match $cgiRobot \ | |
| 1335 | + [cgi_robot /timeline fossil-client-ok=$cgiProof]]} | |
| 1336 | +test cgi-robot-query-parameter {[string match $cgiRobot \ | |
| 1337 | + [cgi_robot /timeline?fossil-client-ok=$cgiProof]]} | |
| 1338 | +# A parameter that failed as proof is left out of the links of the page | |
| 1339 | +# that a good token opens. | |
| 1340 | +set cgiReply [cgi_robot "/timeline?proof=1&token=cgitoken&n=1"] | |
| 1341 | +test cgi-robot-failed-proof-dropped { | |
| 1342 | + [string match "*timeline?*token=cgitoken*" $cgiReply] | |
| 1343 | + && ![string match "*proof=1*" $cgiReply]} | |
| 1344 | +fossil sql "DELETE FROM config WHERE name='robot-restrict'" | |
| 1345 | + | |
| 1346 | +############################################################################### | |
| 1347 | +# A forum thread is shown in order of time to a phone and as a hierarchy | |
| 1348 | +# to anything else, an iPad included. The page offers the other order. | |
| 1349 | + | |
| 1350 | +set cgiFd [open post.txt wb] | |
| 1351 | +puts -nonewline $cgiFd \ | |
| 1352 | + "D 2026-01-04T10:00:01.000\nH Cgi\\sthread\nU alice\nW 5\nhello\n" | |
| 1353 | +close $cgiFd | |
| 1354 | +fossil md5sum post.txt | |
| 1355 | +set cgiSum [lindex $RESULT 0] | |
| 1356 | +set cgiFd [open post.txt ab] | |
| 1357 | +puts -nonewline $cgiFd "Z $cgiSum\n" | |
| 1358 | +close $cgiFd | |
| 1359 | +fossil test-content-put --crosslink post.txt | |
| 1360 | +set cgiPost [fossil sql \ | |
| 1361 | + "SELECT uuid FROM blob WHERE rid=(SELECT fpid FROM forumpost LIMIT 1)"] | |
| 1362 | +foreach {cgiName cgiAgent cgiOther} { | |
| 1363 | + phone "Mozilla/5.0 (iPhone; Mobile) Safari" Hierarchical | |
| 1364 | + ipad "Mozilla/5.0 (iPad; Mobile) Safari" Chronological | |
| 1365 | + desk "Mozilla/5.0 (X11; Linux)" Chronological | |
| 1366 | + none "" Chronological | |
| 1367 | +} { | |
| 1368 | + set cgiHeaders {} | |
| 1369 | + if {$cgiAgent ne ""} { lappend cgiHeaders "User-Agent: $cgiAgent" } | |
| 1370 | + set cgiReply [cgi_admin [request_get /forumthread/$cgiPost?t=a $cgiHeaders]] | |
| 1371 | + test cgi-forum-order-$cgiName {[string match "*>Cgi thread<*" $cgiReply] | |
| 1372 | + && [string match "*?t=?\">$cgiOther</a>*" $cgiReply]} | |
| 1373 | +} | |
| 1374 | + | |
| 1375 | +############################################################################### | |
| 1376 | +# Logging in without "remember me" gives a cookie that lasts for the | |
| 1377 | +# session: it has no age. | |
| 1378 | + | |
| 1379 | +fossil user new cgiuser contact userpw | |
| 1380 | +fossil user capabilities cgiuser o | |
| 1381 | +proc cgi_login {fields} { | |
| 1382 | + set body "u=cgiuser&p=userpw&in=Login&$fields" | |
| 1383 | + return [cgi_send [cgi_post_from http://x/login /login $body] --ipaddr 9.9.9.9] | |
| 1384 | +} | |
| 1385 | +set cgiCookie [reply_header [cgi_login x=1] Set-Cookie] | |
| 1386 | +test cgi-login-session-cookie \ | |
| 1387 | + {[string match "fossil-*=*cgiuser; Path=*; HttpOnly;*" $cgiCookie] | |
| 1388 | + && ![string match "*max-age*" $cgiCookie]} | |
| 1389 | +set cgiCookie [reply_header [cgi_login remember=1] Set-Cookie] | |
| 1390 | +test cgi-login-lasting-cookie \ | |
| 1391 | + {[string match "fossil-*=*cgiuser; Path=*; max-age=*" $cgiCookie]} | |
| 1392 | + | |
| 1393 | +############################################################################### | |
| 1394 | +# A program under /ext that gives a status of 0 gets the usual "200 OK". | |
| 1395 | + | |
| 1396 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 1397 | + file mkdir extroot | |
| 1398 | + write_file extroot/status0.sh \ | |
| 1399 | + [join [list \ | |
| 1400 | + "#!/bin/sh\n" \ | |
| 1401 | + "printf 'Status: 0 Nothing\\r\\nContent-Type: " \ | |
| 1402 | + "text/plain\\r\\n\\r\\nfrom the program\\n'\n"] ""] | |
| 1403 | + file attributes extroot/status0.sh -permissions 0755 | |
| 1404 | + set cgiReply [cgi_admin [request_get /ext/status0.sh] \ | |
| 1405 | + --extroot [file join [pwd] extroot]] | |
| 1406 | + test cgi-ext-status-zero {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1407 | + && [string match "*from the program*" $cgiReply] | |
| 1408 | + && ![string match "*printf*" $cgiReply]} | |
| 1409 | +} | |
| 1410 | + | |
| 1411 | +############################################################################### | |
| 1412 | +# A CGI control file that names no repository gets "500", and so does a | |
| 1413 | +# CGI request with no control file at all. A control file with a | |
| 1414 | +# "redirect: * URL" line sends every request on for good: to URL with | |
| 1415 | +# the name asked for in place of "%s", to URL as it is if it holds a | |
| 1416 | +# "?", and otherwise to URL followed by the path and the query. | |
| 1417 | + | |
| 1418 | +# Run fossil with the words in ARGS and the environment variables in | |
| 1419 | +# VARS, a list of names and values, and return what it printed. | |
| 1420 | +proc cgi_run_with {vars args} { | |
| 1421 | + global RESULT | |
| 1422 | + foreach {name value} $vars { set ::env($name) $value } | |
| 1423 | + fossil_raw {*}$args | |
| 1424 | + foreach {name value} $vars { unset ::env($name) } | |
| 1425 | + return $RESULT | |
| 1426 | +} | |
| 1427 | +# Run from a directory outside the checkout, as a CGI script would be. | |
| 1428 | +set cgiDir [file join [file dirname [pwd]] cgi-no-checkout] | |
| 1429 | +file mkdir $cgiDir | |
| 1430 | +write_file [file join $cgiDir cgi5.ctl] "#!/usr/bin/fossil\n" | |
| 1431 | +set cgiHere [pwd] | |
| 1432 | +cd $cgiDir | |
| 1433 | +set cgiReply [cgi_run_with {REQUEST_METHOD GET SCRIPT_NAME /s PATH_INFO /home} \ | |
| 1434 | + cgi cgi5.ctl] | |
| 1435 | +cd $cgiHere | |
| 1436 | +file delete -force $cgiDir | |
| 1437 | +test cgi-cgi-no-repository {$CODE == 1 | |
| 1438 | + && [string match "Status: 500 Internal Server Error*" $cgiReply] | |
| 1439 | + && [string match "*Unable to find or open the project repository" \ | |
| 1440 | + $cgiReply]} | |
| 1441 | +set cgiReply [cgi_run_with {GATEWAY_INTERFACE CGI/1.1 REQUEST_METHOD GET | |
| 1442 | + SCRIPT_NAME /s PATH_INFO /home}] | |
| 1443 | +test cgi-cgi-no-control-file {$CODE == 1 | |
| 1444 | + && [string match "Status: 500 Internal Server Error*" $cgiReply] | |
| 1445 | + && [string match "*No CGI control file specified" $cgiReply]} | |
| 1446 | +foreach {cgiName cgiTarget cgiLocation} { | |
| 1447 | + name http://other.example/find/%s http://other.example/find/abc | |
| 1448 | + query http://other.example/find?x=1 http://other.example/find?x=1 | |
| 1449 | + path http://other.example/base http://other.example/base/abc?q=1 | |
| 1450 | +} { | |
| 1451 | + write_file cgi6.ctl "#!/usr/bin/fossil\nredirect: * $cgiTarget\n" | |
| 1452 | + set cgiReply [cgi_run_with {REQUEST_METHOD GET HTTP_HOST x SCRIPT_NAME /s | |
| 1453 | + PATH_INFO /abc QUERY_STRING q=1} cgi cgi6.ctl] | |
| 1454 | + test cgi-cgi-redirect-$cgiName {$CODE == 0 | |
| 1455 | + && [string match "Status: 301 Moved Permanently*" $cgiReply] | |
| 1456 | + && [reply_header "$cgiReply\r\n\r\n" Location] eq $cgiLocation} | |
| 1457 | +} | |
| 1458 | + | |
| 1459 | +######################################################ge warns of a page header that has no "base" element, and | |
| 1460 | +# does not when the header has one, as the built-in header does. | |
| 1461 | + | |
| 1462 | +set cgiReply [cgi_admin [request_get /setup]] | |
| 1463 | +test cgi-setup-base-present {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1464 | + && ![string match "*Configuration Error*" $cgiReply]} | |
| 1465 | +fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header', | |
| 1466 | + '<html><head><title>plain</title></head><body>',now())" | |
| 1467 | +set cgiReply [cgi_admin [request_get /setup]] | |
| 1468 | +test cgi-setup-base-missing {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1469 | + && [string match "*Configuration Error*base href=*" $cgiReply]} | |
| 1470 | + | |
| 1471 | +# The TH1 command "redirect" in a page header sends the client to | |
| 1472 | +# another page: with "302", or with "307" when its second argument is | |
| 1473 | +# true, which tells the client to repeat the request as it made it. | |
| 1474 | +foreach {cgiName cgiScript cgiStatus} { | |
| 1475 | + plain {redirect /stat} {HTTP/1.0 302 Moved Temporarily} | |
| 1476 | + method {redirect /stat 1} {HTTP/1.0 307 Temporary Redirect} | |
| 1477 | +} { | |
| 1478 | + fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header', | |
| 1479 | + '<html><head></head><body><th1>$cgiScript</th1>',now())" | |
| 1480 | + set cgiReply [cgi_admin [request_get /timeline]] | |
| 1481 | + test cgi-th1-redirect-$cgiName {[reply_status $cgiReply] eq $cgiStatus | |
| 1482 | + && [reply_header $cgiReply Location] eq "http://x/stat"} | |
| 1483 | +} | |
| 1484 | +fossil sql "DELETE FROM config WHERE name='header'" | |
| 1485 | + | |
| 1486 | +# The same command run from the command line, where there is no request | |
| 1487 | +# to answer, is an error. | |
| 1488 | +foreach {cgiName cgiUrl} {path /stat url http://other.example/x} { | |
| 1489 | + fossil_raw test-th-eval "redirect $cgiUrl" | |
| 1490 | + test cgi-th1-redirect-no-request-$cgiName {$CODE == 0 && [string match \ | |
| 1491 | + "*redirect is only allowed in a web request*" $RESULT]} $::trunkMark | |
| 1492 | +} | |
| 1493 | +# With --http the command line makes a reply, and a redirect to a full | |
| 1494 | +# URL is sent as "302". | |
| 1495 | +fossil_raw test-th-eval --http "redirect http://other.example/x" | |
| 1496 | +test cgi-th1-redirect-http-option {$CODE == 0 | |
| 1497 | + && [string match "HTTP/1.0 302 *" $RESULT] | |
| 1498 | + && [string match "*\r\nLocation: http://other.example/x\r\n*" $RESULT]} | |
| 1499 | + | |
| 1500 | +# The TH1 command "verifyCsrf" from the command line: with no request | |
| 1501 | +# there is no origin to compare, so it refuses. | |
| 1502 | +fossil_raw test-th-eval verifyCsrf | |
| 1503 | +test cgi-th1-verifycsrf-no-request {$CODE == 1 | |
| 1504 | + && [string match "*possible CSRF attack*" $RESULT]} | |
| 1505 | + | |
| 1506 | +############################################################################### | |
| 1507 | +# An ad unit for the right-hand side is used on a page that allows one | |
| 1508 | +# and has no table in its content; a page with a table gets the ad unit | |
| 1509 | +# for the top of the page. | |
| 1510 | + | |
| 1511 | +fossil sql "REPLACE INTO config(name,value,mtime) VALUES | |
| 1512 | + ('adunit-right','<b>ADRIGHT</b>',now()),('adunit','<b>ADTOP</b>',now())" | |
| 1513 | +set cgiReply [cgi_admin [request_get /sitemap]] | |
| 1514 | +test cgi-adunit-right {[string match "*ADRIGHT*" $cgiReply] | |
| 1515 | + && ![string match "*ADTOP*" $cgiReply]} | |
| 1516 | +set cgiReply [cgi_admin [request_get /brlist]] | |
| 1517 | +test cgi-adunit-top-with-table {[string match "*ADTOP*" $cgiReply] | |
| 1518 | + && ![string match "*ADRIGHT*" $cgiReply]} | |
| 1519 | +fossil sql "DELETE FROM config WHERE name IN ('adunit-right','adunit')" | |
| 1520 | + | |
| 1521 | +############################################################################### | |
| 1522 | +# Pages that add a query parameter to the request they were given. | |
| 1523 | +# /file with no file name lists the files of the check-in "tip", and | |
| 1524 | +# its links carry "ci=tip". /timeline with "r=BRANCH" shows the branch | |
| 1525 | +# and what is related to it, and its form keeps that as "t=BRANCH" and | |
| 1526 | +# "rel". | |
| 1527 | + | |
| 1528 | +set cgiReply [cgi_admin [request_get /file]] | |
| 1529 | +test cgi-file-no-name {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1530 | + && [string match "*Top-level Files of tip*" $cgiReply] | |
| 1531 | + && [string match "*ci=tip*" $cgiReply]} | |
| 1532 | +set cgiReply [cgi_admin [request_get /timeline?r=trunk]] | |
| 1533 | +test cgi-timeline-r {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1534 | + && [string match "*name=\"rel\" value=\"1\"*" $cgiReply] | |
| 1535 | + && [string match "*name=\"t\" value=\"trunk\"*" $cgiReply]} | |
| 1536 | + | |
| 1537 | +############################################################################### | |
| 1538 | +# An unversioned file whose time of change is too far in the future to | |
| 1539 | +# be written as a date is sent all the same, with an empty Last-Modified | |
| 1540 | +# header. | |
| 1541 | + | |
| 1542 | +write_file late.css "p{}\n" | |
| 1543 | +fossil uv add late.css | |
| 1544 | +fossil sql "UPDATE unversioned SET mtime=1000000000000000000 | |
| 1545 | + WHERE name='late.css'" | |
| 1546 | +set cgiReply [cgi_send [request_get /uv/late.css] --ipaddr 127.0.0.1] | |
| 1547 | +test cgi-last-modified-out-of-range { | |
| 1548 | + [reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1549 | + && [string match "*\r\nLast-Modified: \r\n*" $cgiReply] | |
| 1550 | + && [reply_body $cgiReply] eq "p{}\n"} | |
| 1551 | +fossil uv rm late.css | |
| 1552 | + | |
| 1553 | +############################################################################### | |
| 1554 | +# "fossil server" itself, where it listens with its own code (not on | |
| 1555 | +# Windows). A server that cannot listen where it was told says why and | |
| 1556 | +# stops. | |
| 1557 | + | |
| 1558 | +if {$::tcl_platform(platform) eq "unix" && [loopback_available]} { | |
| 1559 | + # A port on ADDRESS with a listener on it. Returns the listener and | |
| 1560 | + # the port. | |
| 1561 | + proc cgi_busy_port {address} { | |
| 1562 | + set listener [socket -server {apply {{c a p} {close $c}}} \ | |
| 1563 | + -myaddr $address 0] | |
| 1564 | + return [list $listener [lindex [fconfigure $listener -sockname] 2]] | |
| 1565 | + } | |
| 1566 | + # A port on 127.0.0.1 that was free a moment ago. | |
| 1567 | + proc cgi_free_port {} { | |
| 1568 | + lassign [cgi_busy_port 127.0.0.1] listener port | |
| 1569 | + close $listener | |
| 1570 | + return $port | |
| 1571 | + } | |
| 1572 | + write_file notsocket "a file\n" | |
| 1573 | + lassign [cgi_busy_port 127.0.0.1] cgiListener cgiPort | |
| 1574 | + foreach {cgiName cgiOptions cgiError} [list \ | |
| 1575 | + bad-ipv4 {--port 999.9.9.9:8111} \ | |
| 1576 | + "not a valid IPv4 address: 999.9.9.9" \ | |
| 1577 | + bad-ipv6 {--port {[zz::1]:8111}} \ | |
| 1578 | + "not a valid IPv6 address: zz::1" \ | |
| 1579 | + other-ipv4 {--port 192.0.2.1:8111} \ | |
| 1580 | + "cannot open a listening socket on 192.0.2.1:8111" \ | |
| 1581 | + other-ipv6 {--port {[2001:db8::1]:8111}} \ | |
| 1582 | + [join [list \ | |
| 1583 | + "cannot open a listening socket on " \ | |
| 1584 | + "\\\[2001:db8::1\\\]:8111"] ""] \ | |
| 1585 | + port-in-use [list --localhost --port $cgiPort] \ | |
| 1586 | + "no available TCP ports in the range $cgiPort..$cgiPort" \ | |
| 1587 | + socket-name-long [list --socket-name [string repeat s 200]] \ | |
| 1588 | + "name of unix socket too big" \ | |
| 1589 | + socket-name-taken {--socket-name notsocket} \ | |
| 1590 | + "cannot name socket \"notsocket\" because another object" \ | |
| 1591 | + ] { | |
| 1592 | + fossil_raw -seconds 30 server {*}$cgiOptions $cgiRepo | |
| 1593 | + test cgi-server-refused-$cgiName {$CODE == 1 | |
| 1594 | + && [string match "*$cgiError*" $RESULT]} | |
| 1595 | + } | |
| 1596 | + close $cgiListener | |
| 1597 | + | |
| 1598 | + # Run SCRIPT every ten milliseconds until it returns true, for at most | |
| 1599 | + # five seconds, and return what it last returned. | |
| 1600 | + proc cgi_wait {script} { | |
| 1601 | + for {set i 0} {$i < 500} {incr i} { | |
| 1602 | + if {[uplevel 1 $script]} {return 1} | |
| 1603 | + after 10 | |
| 1604 | + } | |
| 1605 | + return 0 | |
| 1606 | + } | |
| 1607 | + # True if the process PID has not ended. | |
| 1608 | + proc cgi_running {pid} { | |
| 1609 | + return [expr {![catch {exec kill -0 $pid}]}] | |
| 1610 | + } | |
| 1611 | + # Wait for the server PID to print that it listens, and return true | |
| 1612 | + # once it has. A server that ends without listening ends the wait. | |
| 1613 | + proc cgi_listening {pid} { | |
| 1614 | + cgi_wait {expr {[string match "*Listening for*" [read_file server.out]] | |
| 1615 | + || ![cgi_running $pid]}} | |
| 1616 | + return [string match "*Listening for*" [read_file server.out]] | |
| 1617 | + } | |
| 1618 | + # Connect to HOST and PORT and return the socket. A server prints | |
| 1619 | + # that it listens before it accepts connections, so a connection that | |
| 1620 | + # fails is tried again. | |
| 1621 | + proc cgi_connect {host port} { | |
| 1622 | + cgi_wait {expr {![catch {socket $host $port} sock]}} | |
| 1623 | + fconfigure $sock -translation binary | |
| 1624 | + return $sock | |
| 1625 | + } | |
| 1626 | + # Send REQUEST to HOST and PORT and return the reply, waiting at most | |
| 1627 | + # ten seconds for the end of it. With "unix" for HOST, PORT is the | |
| 1628 | + # name of a unix socket, and the program "nc" carries the request. | |
| 1629 | + proc cgi_client {host port request} { | |
| 1630 | + if {$host eq "unix"} { | |
| 1631 | + cgi_wait {expr {![catch {exec nc -w 10 -U $port << $request} reply] | |
| 1632 | + || ![string match "*refused*" $reply]}} | |
| 1633 | + return $reply | |
| 1634 | + } | |
| 1635 | + set sock [cgi_connect $host $port] | |
| 1636 | + fconfigure $sock -blocking 0 | |
| 1637 | + puts -nonewline $sock $request | |
| 1638 | + flush $sock | |
| 1639 | + set reply "" | |
| 1640 | + for {set i 0} {$i < 2000 && ![eof $sock]} {incr i} { | |
| 1641 | + set part [read $sock] | |
| 1642 | + append reply $part | |
| 1643 | + if {$part eq ""} {after 5} | |
| 1644 | + } | |
| 1645 | + close $sock | |
| 1646 | + return $reply | |
| 1647 | + } | |
| 1648 | + # Start a server with OPTIONS that answers one request and stops, send | |
| 1649 | + # it REQUEST at HOST and PORT, and return what the server printed and | |
| 1650 | + # the reply. The server is killed if it has not stopped by itself. | |
| 1651 | + # The request is sent IDLE milliseconds after the server starts to | |
| 1652 | + # listen. | |
| 1653 | + proc cgi_serve_once {options host port request {command server} {idle 0}} { | |
| 1654 | + global fossilexe cgiRepo | |
| 1655 | + file delete server.out | |
| 1656 | + set pid [exec $fossilexe $command --debug-nofork --localauth {*}$options \ | |
| 1657 | + $cgiRepo >& server.out &] | |
| 1658 | + set reply "" | |
| 1659 | + if {[cgi_listening $pid]} { | |
| 1660 | + after $idle | |
| 1661 | + catch {set reply [cgi_client $host $port $request]} | |
| 1662 | + } | |
| 1663 | + cgi_wait {expr {![cgi_running $pid]}} | |
| 1664 | + catch {exec kill -9 $pid} | |
| 1665 | + return [list [string trim [read_file server.out]] $reply] | |
| 1666 | + } | |
| 1667 | + | |
| 1668 | + # An IPv4 address, by number and as "localhost". | |
| 1669 | + foreach {cgiName cgiHost} {ipv4 127.0.0.1 localhost localhost} { | |
| 1670 | + set cgiPort [cgi_free_port] | |
| 1671 | + lassign [cgi_serve_once [list --port $cgiHost:$cgiPort] 127.0.0.1 \ | |
| 1672 | + $cgiPort [request_get /test-env]] cgiPrinted cgiReply | |
| 1673 | + test_eq cgi-server-$cgiName-printed $cgiPrinted \ | |
| 1674 | + "Listening for HTTP requests on TCP port 127.0.0.1:$cgiPort" | |
| 1675 | + test cgi-server-$cgiName-reply { | |
| 1676 | + [reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1677 | + && [cgi_param $cgiReply REMOTE_ADDR] eq "127.0.0.1"} | |
| 1678 | + } | |
| 1679 | + # "fossil ui" starts the browser on the address it listens on. The | |
| 1680 | + # browser here is "echo". | |
| 1681 | + fossil settings web-browser echo | |
| 1682 | + fossil settings web-browser | |
| 1683 | + if {[string match "*echo*" $RESULT]} { | |
| 1684 | + set cgiPort [cgi_free_port] | |
| 1685 | + lassign [cgi_serve_once [list --port 127.0.0.1:$cgiPort] 127.0.0.1 \ | |
| 1686 | + $cgiPort [request_get /test-env] ui] cgiPrinted cgiReply | |
| 1687 | + test cgi-server-ui-browser { | |
| 1688 | + [string match "*\nhttp://127.0.0.1:$cgiPort/*" \n$cgiPrinted] | |
| 1689 | + && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"} | |
| 1690 | + } | |
| 1691 | + # SCGI in place of HTTP. | |
| 1692 | + set cgiPort [cgi_free_port] | |
| 1693 | + lassign [cgi_serve_once [list --scgi --port 127.0.0.1:$cgiPort] 127.0.0.1 \ | |
| 1694 | + $cgiPort [cgi_scgi { | |
| 1695 | + CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SCRIPT_NAME {} | |
| 1696 | + REQUEST_URI /test-env?viascgi=1 QUERY_STRING viascgi=1 SERVER_NAME x | |
| 1697 | + SERVER_PORT 80 REMOTE_ADDR 127.0.0.1 | |
| 1698 | + }]] cgiPrinted cgiReply | |
| 1699 | + test_eq cgi-server-scgi-printed $cgiPrinted \ | |
| 1700 | + "Listening for SCGI requests on TCP port 127.0.0.1:$cgiPort" | |
| 1701 | + test_eq cgi-server-scgi-reply [cgi_param $cgiReply viascgi] 1 | |
| 1702 | + | |
| 1703 | + if {![catch {cgi_busy_port ::1} cgiBusy]} { | |
| 1704 | + close [lindex $cgiBusy 0] | |
| 1705 | + # An IPv6 address. | |
| 1706 | + set cgiPort [cgi_free_port] | |
| 1707 | + lassign [cgi_serve_once [list --port \[::1\]:$cgiPort] ::1 $cgiPort \ | |
| 1708 | + [request_get /test-env]] cgiPrinted cgiReply | |
| 1709 | + test_eq cgi-server-ipv6-printed $cgiPrinted \ | |
| 1710 | + "Listening for HTTP requests on \[::1\]:$cgiPort" | |
| 1711 | + test cgi-server-ipv6-reply {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1712 | + && [cgi_param $cgiReply REMOTE_ADDR] eq "::1"} | |
| 1713 | + # With no address the server listens on both kinds of loopback | |
| 1714 | + # address, or on IPv4 alone if the port is taken for IPv6. The | |
| 1715 | + # server waits a tenth of a second at a time for a connection, and | |
| 1716 | + # this request leaves it waiting for two of them with none. | |
| 1717 | + set cgiPort [cgi_free_port] | |
| 1718 | + lassign [cgi_serve_once [list --localhost --port \[\]:$cgiPort] ::1 \ | |
| 1719 | + $cgiPort [request_get /test-env] server 200] cgiPrinted cgiReply | |
| 1720 | + test_eq cgi-server-both-printed $cgiPrinted \ | |
| 1721 | + [join [list \ | |
| 1722 | + "Listening for HTTP requests on TCP port " \ | |
| 1723 | + "localhost:$cgiPort, IPv4 and IPv6"] ""] | |
| 1724 | + test_eq cgi-server-both-reply [cgi_param $cgiReply REMOTE_ADDR] ::1 | |
| 1725 | + lassign [cgi_busy_port ::1] cgiListener cgiPort | |
| 1726 | + lassign [cgi_serve_once [list --localhost --port $cgiPort] 127.0.0.1 \ | |
| 1727 | + $cgiPort [request_get /test-env]] cgiPrinted cgiReply | |
| 1728 | + close $cgiListener | |
| 1729 | + test_eq cgi-server-ipv4-only-printed $cgiPrinted \ | |
| 1730 | + "Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 only" | |
| 1731 | + test_eq cgi-server-ipv4-only-reply [reply_status $cgiReply] \ | |
| 1732 | + "HTTP/1.0 200 OK" | |
| 1733 | + # With a port and neither an address nor --localhost the server | |
| 1734 | + # listens on every address of the machine. | |
| 1735 | + set cgiPort [cgi_free_port] | |
| 1736 | + lassign [cgi_serve_once [list --port $cgiPort] 127.0.0.1 \ | |
| 1737 | + $cgiPort [request_get /login]] cgiPrinted cgiReply | |
| 1738 | + test_eq cgi-server-any-address-printed $cgiPrinted \ | |
| 1739 | + "Listening eq $cgiMode} $::trunkMark | |
| 1740 | + } | |
| 1741 | + fossil_raw -seconds 30 server --socket-mode rw --socket-name sock3 $cgiRepo | |
| 1742 | + test cgi-server-unix-mode-not-a-number {$CODE == 1 && [string match \ | |
| 1743 | + "*cannot change permissions on sock3 to \"rw\"*" $RESULT]} | |
| 1744 | + } else { | |
| 1745 | + test_skip_part "no nc program for unix sockets: the unix socket tests" | |
| 1746 | + } | |
| 1747 | + | |
| 1748 | + # A server that gives each request to a process of its own. Start | |
| 1749 | + # one with OPTIONS, as COMMAND, and return its process id once it | |
| 1750 | + # listens. What it prints goes to server.out and server.err. WRAP, | |
| 1751 | + # if given, is a list of words to put before the command. | |
| 1752 | + proc cgi_serve_start {options {command server} {wrap {}}} { | |
| 1753 | + global fossilexe cgiRepo | |
| 1754 | + file delete server.out server.err | |
| 1755 | + set pid [exec {*}$wrap $fossilexe $command --localauth {*}$options \ | |
| 1756 | + $cgiRepo > server.out 2> server.err &] | |
| 1757 | + cgi_listening $pid | |
| 1758 | + return $pid | |
| 1759 | + } | |
| 1760 | + # Stop the server with process id PID: ask it to end, and kill it if | |
| 1761 | + # it has not ended after five seconds. | |
| 1762 | + proc cgi_serve_stop {pid} { | |
| 1763 | + catch {exec kill $pid} | |
| 1764 | + cgi_wait {expr {![cgi_running $pid]}} | |
| 1765 | + catch {exec kill -9 $pid} | |
| 1766 | + } | |
| 1767 | + # The process ids of the processes that the server PID has started | |
| 1768 | + # for requests and has not yet found to have ended. | |
| 1769 | + proc cgi_children {pid} { | |
| 1770 | + if {[catch {exec pgrep -P $pid} children]} {return {}} | |
| 1771 | + return $children | |
| 1772 | + } | |
| 1773 | + | |
| 1774 | + # A process that handles a request is killed before the request is | |
| 1775 | + # complete. The server goes on to answer the next request, and one | |
| 1776 | + # that traces its work reports the signal that ended the process. | |
| 1777 | + if {[auto_execok pgrep] ne ""} { | |
| 1778 | + foreach {cgiName cgiOptions cgiReport} { | |
| 1779 | + traced --httptrace {*Child * exited on signal 9 *} | |
| 1780 | + quiet {} {} | |
| 1781 | + } { | |
| 1782 | + set cgiPort [cgi_free_port] | |
| 1783 | + set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort \ | |
| 1784 | + {*}$cgiOptions]] | |
| 1785 | + set cgiReply "" | |
| 1786 | + catch { | |
| 1787 | + set cgiSock [cgi_connect 127.0.0.1 $cgiPort] | |
| 1788 | + puts -nonewline 0 $end] \n] { | |
| 1789 | + if {[string match -nocase "$name: *" $line]} { | |
| 1790 | + return [strinrn - } | |
| 1791 | + incr start [+1 end]] | |
| 1792 | + } | |
| 1793 | + } | |
| 1794 | + return - | |
| 1795 | +} | |
| 1796 | + | |
| 1797 | +# The content of a reply: what follows its heade | |
| 1798 | + set end [string first "\r\n\r\n" $replyirst " <br>" $reply $start"" } | |
| 1799 | + return [string range $reply $end+4 end] | |
| 1800 | +} | |
| 1801 | + | |
| 1802 | +# A GE header lines in HEADERS, a list. | |
| 1803 | +proc cgi_post {type body {path /test-env} {headers {}}} { | |
| 1804 | + return [request_post $path $body $headers $type] | |
| 1805 | +} | |
| 1806 | + | |
| 1807 | +# A POST of the form data BODY to PATH, sent from the page REFERER. | |
| 1808 | +proc cgi_post_from {referer path body} { | |
| 1809 | + return [cgi_post application/x-www-form-urlencoded $body $path \ | |
| 1810 | + [list "Referer: $referer"]] | |
| 1811 | +} | |
| 1812 | + | |
| 1813 | +############################################################################### | |
| 1814 | +# Plain HTTP. | |
| 1815 | + | |
| 1816 | +set cgiReply [cgi_admin \ | |
| 1817 | + "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"] | |
| 1818 | +test cgi-get {$CODE == 0} | |
| 1819 | +test_eq cgi-get-status [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 1820 | +test_eq cgi-get-plain [cgi_param $cgiReply a] 1 | |
| 1821 | +test_eq cgi-get-plus [cgi_param $cgiReply b] "two words" | |
| 1822 | +test_eq cgi-get-escape [cgi_param $cgiReply c] AB | |
| 1823 | +test_eq cgi-get-empty [cgi_param $cgiReply d] "" | |
| 1824 | +test_eq cgi-get-no-value [cgi_param $cgiReply e] "" | |
| 1825 | + | |
| 1826 | +set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded \ | |
| 1827 | + "x=1&y=a%20b&Z=upper"]] | |
| 1828 | +test_eq cgi-post-form [cgi_param $cgiReply x] 1 | |
| 1829 | +test_eq cgi-post-form-escape [cgi_param $cgiReply y] "a b" | |
| 1830 | +test_eq cgi-post-form-upper [cgi_param $cgiReply z] upper | |
| 1831 | + | |
| 1832 | +foreach {cgiName cgiRequest} [list \ | |
| 1833 | + no-method "\r\n\r\n" \ | |
| 1834 | + bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 1835 | +] { | |
| 1836 | + set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1] | |
| 1837 | + test cgi-malformed-$cgiName \ | |
| 1838 | + {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]} | |
| 1839 | +} | |
| 1840 | + | |
| 1841 | +# A request line with no path is a request for the home page. | |
| 1842 | +set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1] | |
| 1843 | +test_eq cgi-no-path [reply_status $cgiReply] "HTTP/1.0 302 Moved Temporarily" | |
| 1844 | + | |
| 1845 | +############################################################################### | |
| 1846 | +# Form data in several parts, as a browser sends an upload. | |
| 1847 | + | |
| 1848 | +proc cgi_part {name body {extra ""}} { | |
| 1849 | + return \ | |
| 1850 | + [join [list \ | |
| 1851 | + "--XB\r\n" \ | |
| 1852 | + "Content-Disposition: form-data; " \ | |
| 1853 | + "name=\"$name\"$extra\r\n\r\n$body\r\n"] ""] | |
| 1854 | +} | |
| 1855 | +set cgiType "multipart/form-data; boundary=XB" | |
| 1856 | + | |
| 1857 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 1858 | + "[cgi_part alpha {first value}][cgi_part upload {file body} \ | |
| 1859 | + {; filename="a.txt"}]--XB--\r\n"]] | |
| 1860 | +test_eq cgi-multipart [cgi_param $cgiReply alpha] "first value" | |
| 1861 | +test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body" | |
| 1862 | +test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt | |
| 1863 | +test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9 | |
| 1864 | + | |
| 1865 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 1866 | + [join [list \ | |
| 1867 | + "--XB\r\n" \ | |
| 1868 | + "Content-Disposition: form-data; name=\"t\"; " \ | |
| 1869 | + "filename=\"t.bin\"\r\n" \ | |
| 1870 | + "Content-Type: application/octet-stream\r\n\r\nxyz\r\n" \ | |
| 1871 | + "--XB--\r\n"] ""]]] | |
| 1872 | +test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \ | |
| 1873 | + application/octet-stream | |
| 1874 | + | |
| 1875 | +# A name that begins with a capital is taken in lower case. | |
| 1876 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 1877 | + "[cgi_part Upper v {; filename="F.TXT"}]--XB--\r\n"]] | |
| 1878 | +test_eq cgi-multipart-upper [cgi_param $cgiReply upper] v | |
| 1879 | +test_eq cgi-multipart-upper-filename [cgi_param $cgiReply upper:filename] F.TXT | |
| 1880 | + | |
| 1881 | +# Lines may end with a bare newline. | |
| 1882 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 1883 | + "--XB\nContent-Disposition: form-data; name=\"lf\"\n\nvalue\n--XB--\n"]] | |
| 1884 | +test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value | |
| 1885 | + | |
| 1886 | +# A part with no closing boundary after a long one ends at the end of the | |
| 1887 | +# request, and every part is read within the request. | |
| 1888 | +set cgiReply [cgi_admin [cgi_post $cgiType \ | |
| 1889 | + [join [list \ | |
| 1890 | + "[cgi_part alpha [string repeat x 3000]]--XB\r\n" \ | |
| 1891 | + "Content-Disposition: form-data; name=\"beta\"\r\n\r\n" \ | |
| 1892 | + "no closing boundary"] ""]]] | |
| 1893 | +test cgi-multipart-unclosed {$CODE == 0} | |
| 1894 | +test_eq cgi-multipart-unclosed-first \ | |
| 1895 | + [string length [cgi_param $cgiReply alpha]] 3000 | |
| 1896 | +test_eq cgi-multipart-unclosed-second [cgi_param $cgiReply beta] \ | |
| 1897 | + "no closing boundary" | |
| 1898 | + | |
| 1899 | +# Malformed and unusual bodies are read without a crash. | |
| 1900 | +set cgiI 0 | |
| 1901 | +foreach cgiBody [list \ | |
| 1902 | + "" \ | |
| 1903 | + "\r\n\r\nvalue\r\n\r\n" \ | |
| 1904 | + "--XB" \ | |
| 1905 | + "--XB\r\n" \ | |
| 1906 | + "--XB\r\n\r\nno name here\r\n--XB--\r\n" \ | |
| 1907 | + "--XB\r\nContent-Disposition: form-data; name=\"a\"" \ | |
| 1908 | + "[cgi_part a "one\000two"]--XB--\r\n" \ | |
| 1909 | + [join [list \ | |
| 1910 | + "--XB\r\n" \ | |
| 1911 | + "Content-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n" \ | |
| 1912 | + "--XB--\r\n"] ""] \ | |
| 1913 | + [join [list \ | |
| 1914 | + "--[string repeat B 3000]\r\n" \ | |
| 1915 | + "Content-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n"] ""] \ | |
| 1916 | + [join [list \ | |
| 1917 | + "[cgi_part a [string repeat x 2000]]--XB\r\n" \ | |
| 1918 | + "Content-Disposition: form-data; name=\"b\""] ""] \ | |
| 1919 | + "[cgi_part {} v]--XB--\r\n" \ | |
| 1920 | + [join [list \ | |
| 1921 | + "--XB\r\n" \ | |
| 1922 | + "Content-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n" \ | |
| 1923 | + "--XB--\r\n"] ""] \ | |
| 1924 | + [join [list \ | |
| 1925 | + "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\n" \ | |
| 1926 | + "v\r\n--XB--\r\n"] ""] \ | |
| 1927 | + "--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \ | |
| 1928 | + [join [list \ | |
| 1929 | + "--XB\r\n" \ | |
| 1930 | + "Content-Disposition: form-data; name=\"a\"; " \ | |
| 1931 | + "filename=\r\n\r\nv\r\n--XB--\r\n"] ""] \ | |
| 1932 | + [join [list \ | |
| 1933 | + "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\n" \ | |
| 1934 | + "content-type:\r\n\r\nv\r\n--XB--\r\n"] ""] \ | |
| 1935 | + "[cgi_part a "\n--X"]--XB--\r\n" \ | |
| 1936 | +] { | |
| 1937 | + incr cgiI | |
| 1938 | + cgi_admin [cgi_post $cgiType $cgiBody] | |
| 1939 | + test cgi-multipart-odd-$cgiI {$CODE == 0} | |
| 1940 | +} | |
| 1941 | +set cgiMany "" | |
| 1942 | +for {set cgiI 0} {$cgiI < 400} {incr cgiI} { | |
| 1943 | + append cgiMany [cgi_part p$cgiI [string repeat v [expr {$cgiI % 50}]]] | |
| 1944 | +} | |
| 1945 | +set cgiReply [cgi_admin [cgi_post $cgiType "$cgiMany--XB--\r\n"]] | |
| 1946 | +test_eq cgi-multipart-many [cgi_param $cgiReply p399] [string repeat v 49] | |
| 1947 | + | |
| 1948 | +############################################################################### | |
| 1949 | +# The date in an If-Modified-Since header. A file that has not changed | |
| 1950 | +# since that date is not sent again. | |
| 1951 | + | |
| 1952 | +proc cgi_since {date} { | |
| 1953 | + set reply [cgi_send \ | |
| 1954 | + "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" \ | |
| 1955 | + --ipaddr 127.0.0.1] | |
| 1956 | + return [reply_status $reply] | |
| 1957 | +} | |
| 1958 | +test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \ | |
| 1959 | + "HTTP/1.0 304 Not Modified" | |
| 1960 | +test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \ | |
| 1961 | + "HTTP/1.0 200 OK" | |
| 1962 | +test_eq cgi-since-garbage [cgi_since "yesterday"] "HTTP/1.0 200 OK" | |
| 1963 | +# Numbers out of range are not a date. | |
| 1964 | +foreach {cgiName cgiDate} { | |
| 1965 | + year "Mon, 01 Jan 2147483647 00:00:00 GMT" | |
| 1966 | + day "Mon, 2147483647 Jan 2026 00:00:00 GMT" | |
| 1967 | + hour "Mon, 01 Jan 2026 2147483647:00:00 GMT" | |
| 1968 | + minute "Mon, 01 Jan 2026 00:2147483647:00 GMT" | |
| 1969 | +} { | |
| 1970 | + test_eq cgi-since-huge-$cgiName [cgi_since $cgiDate] "HTTP/1.0 200 OK" | |
| 1971 | +} | |
| 1972 | + | |
| 1973 | +############################################################################### | |
| 1974 | +# A reply is compressed with gzip when the client accepts it and the type | |
| 1975 | +# of the content is text, JavaScript, JSON, WebAssembly, Tcl, tar, XML, | |
| 1976 | +# SVG or an icon. Other types, and a client that does not accept gzip, | |
| 1977 | +# get the content as it is. | |
| 1978 | + | |
| 1979 | +foreach {cgiName cgiGzip} { | |
| 1980 | + g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1 | |
| 1981 | + g.ico 1 g.png 0 g.zip 0 g.pdf 0 | |
| 1982 | +} { | |
| 1983 | + write_file $cgiName [string repeat "content to compress\n" 50] | |
| 1984 | + fossil uv add $cgiName | |
| 1985 | + set cgiReply [cgi_send \ | |
| 1986 | + [join [list \ | |
| 1987 | + "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\n" \ | |
| 1988 | + "Accept-Encoding: gzip, deflate\r\n\r\n"] ""] --ipaddr 127.0.0.1] | |
| 1989 | + test_eq cgi-gzip-$cgiName \ | |
| 1990 | + [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip | |
| 1991 | +} | |
| 1992 | +set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 1993 | + --ipaddr 127.0.0.1] | |
| 1994 | +test cgi-gzip-not-accepted {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" | |
| 1995 | + && ![string match "*Content-Encoding*" $cgiReply]} | |
| 1996 | + | |
| 1997 | +############################################################################### | |
| 1998 | +# A POST whose Referer is another site is not taken as safe from forgery, | |
| 1999 | +# and is written to the error log. | |
| 2000 | + | |
| 2001 | +proc cgi_logout {referer} { | |
| 2002 | + return [cgi_send [cgi_post_from $referer /login "out=1"] --ipaddr 10.0.0.1 \ | |
| 2003 | + --errorlog [file join [pwd] err.log]] | |
| 2004 | +} | |
| 2005 | +file delete err.log | |
| 2006 | +cgi_logout http://x/login | |
| 2007 | +test cgi-same-origin-not-logged {![file exists err.log] | |
| 2008 | + || ![string match "*different origin*" [read_file err.log]]} | |
| 2009 | +cgi_logout http://elsewhere.example/page | |
| 2010 | +test cgi-other-origin-logged {[file exists err.log] | |
| 2011 | + && [string match "*POST from different origin*" [read_file err.log]]} | |
| 2012 | + | |
| 2013 | +############################################################################### | |
| 2014 | +# SCGI: a header of name and value pairs, each ended by a zero byte, | |
| 2015 | +# preceded by its length and followed by a comma. | |
| 2016 | + | |
| 2017 | +proc cgi_scgi {pairs {body ""}} { | |
| 2018 | + set h "" | |
| 2019 | + foreach {k v} $pairs { append h $k \000 $v \000 } | |
| 2020 | + return "[string length $h]:$h,$body" | |
| 2021 | +} | |
| 2022 | +set cgiReply [cgi_send [cgi_scgi { | |
| 2023 | + CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1 | |
| 2024 | + PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80 | |
| 2025 | + REMOTE_ADDR 127.0.0.1 | |
| 2026 | +}] --scgi --localauth] | |
| 2027 | +test_eq cgi-scgi [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 2028 | +test_eq cgi-scgi-param [cgi_param $cgiReply s] 1 | |
| 2029 | + | |
| 2030 | +foreach {cgiName cgiRequest} [list \ | |
| 2031 | + too-short "15:CONTENT_LENGTH\0000\000," \ | |
| 2032 | + cut-short "40:CONTENT_LENGTH\0000\000," \ | |
| 2033 | + no-zero "20:CONTENT_LENGTH0000000000," \ | |
| 2034 | + huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \ | |
| 2035 | +] { | |
| 2036 | + set cgiReply [cgi_send $cgiRequest --scgi] | |
| 2037 | + test cgi-scgi-$cgiName {$CODE == 0 && | |
| 2038 | + [string match "HTTP/1.0 400*" [reply_status $cgiReply]]} | |
| 2039 | +} | |
| 2040 | + | |
| 2041 | +############################################################################### | |
| 2042 | +# The same reader for a request that arrives over ssh, which the server | |
| 2043 | +# knows from SSH_CONNECTION. It reads the client's probes first. | |
| 2044 | + | |
| 2045 | +set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" | |
| 2046 | +set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" \ | |
| 2047 | + --localauth] | |
| 2048 | +test_eq cgi-ssh [reply_status $cgiReply] "HTTP/1.0 200 OK" | |
| 2049 | +test_eq cgi-ssh-param [cgi_param $cgiReply q] 1 | |
| 2050 | +test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1 | |
| 2051 | + | |
| 2052 | +set cgiReply [cgi_send [cgi_ |
| --- a/test/cgi.test | |
| +++ b/test/cgi.test | |
| @@ -0,0 +1,2052 @@ | |
| --- a/test/cgi.test | |
| +++ b/test/cgi.test | |
| @@ -0,0 +1,2052 @@ | |
| 1 | # |
| 2 | # How a server reads a request: src/cgi.c. Requests are written to a |
| 3 | # file and given to "fossil http --in", which handles one request as a |
| 4 | # server does and writes the reply to a file. The page /test-env shows |
| 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 | |
| 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 | request.txt $textULT] >= 0 |
| 26 | && [reply_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"} |
| 27 | } |
| 28 | |
| 29 | ####{*}$args |
| 30 | if a server reads a request a ################### |
| 31 | # A reque } |
| 32 | return "" |
| 33 | } |
| 34 | |
| 35 | # The same, as a local administrator. |
| 36 | proc cgi_admin {text args} { |
| 37 | return [cgi_send $text --ipaddr 127.0.0.1 --localauth {*}$args] |
| 38 | } |
| 39 | |
| 40 | # The ] |
| 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 - } |
| 48 | incr start [expr {[string length $name] + 4}] |
| 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_headernot show it. |
| 57 | proc cgi_end [string first "\r\n\r\n" $r [string range $reply $start [expr {$end - 1}]] |
| 58 | } |
| 59 | |
| 60 | # A POST request with BODY as its content, of the type TYPE, and the |
| 61 | # header lines in HEADERS, a list. |
| 62 | proc cgi_post {type body {path /test-env} {headers {}}} { |
| 63 | return [request_post $path $body $headers $type] |
| 64 | } |
| 65 | |
| 66 | # A POST of the form data BODY to PATH, sent from the page REFERER. |
| 67 | proc cgi_post_from {referer path body} { |
| 68 | return [cgi_post application/x-www-form-urlencoded $body $path \ |
| 69 | [list "Referer: $referer"]] |
| 70 | } |
| 71 | |
| 72 | ############################################################################### |
| 73 | # Plain HTTP. |
| 74 | |
| 75 | set cgiReply [cgi_admin \ |
| 76 | "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"] |
| 77 | test cgi-get {$CODE == 0} |
| 78 | test_eq cgi-get-status [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 79 | test_eq cgi-get-plain [cgi_param $cgiReply a] 1 |
| 80 | test_eq cgi-get-plus [cgi_param $cgiReply b] "two words" |
| 81 | test_eq cgi-get-escape [cgi_param $cgiReply c] AB |
| 82 | test_eq cgi-get-empty [cgi_param $cgiReply d] "" |
| 83 | test_eq cgi-get-no-value [cgi_param $cgiReply e] "" |
| 84 | |
| 85 | set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded \ |
| 86 | "x=1&y=a%20b&Z=upper"]] |
| 87 | test_eq cgi-post-form [cgi_param $cgiReply x] 1 |
| 88 | test_eq cgi-post-form-escape [cgi_param $cgiReply y] "a b" |
| 89 | test_eq cgi-post-form-upper [cgi_param $cgiReply z] upper |
| 90 | |
| 91 | foreach {cgiName cgiRequest} [list \ |
| 92 | no-method "\r\n\r\n" \ |
| 93 | bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 94 | ] { |
| 95 | set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1] |
| 96 | test cgi-malformed-$cgiName \ |
| 97 | {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]} |
| 98 | } |
| 99 | |
| 100 | # A request line with no path is a request for the home page. |
| 101 | set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1] |
| 102 | test_eq cgi-no-path [reply_status $cgiReply] "HTTP/1.0 302 Moved Temporarily" |
| 103 | |
| 104 | ############################################################################### |
| 105 | # Form data in several parts, as a browser sends an upload. |
| 106 | |
| 107 | proc cgi_part {name body {extra ""}} { |
| 108 | return \ |
| 109 | [join [list \ |
| 110 | "--XB\r\n" \ |
| 111 | "Content-Disposition: form-data; " \ |
| 112 | "name=\"$name\"$extra\r\n\r\n$body\r\n"] ""] |
| 113 | } |
| 114 | set cgiType "multipart/form-data; boundary=XB" |
| 115 | |
| 116 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 117 | "[cgi_part alpha {first value}][cgi_part upload {file body} \ |
| 118 | {; filename="a.txt"}]--XB--\r\n"]] |
| 119 | test_eq cgi-multipart [cgi_param $cgiReply alpha] "first value" |
| 120 | test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body" |
| 121 | test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt |
| 122 | test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9 |
| 123 | |
| 124 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 125 | [join [list \ |
| 126 | "--XB\r\n" \ |
| 127 | "Content-Disposition: form-data; name=\"t\"; " \ |
| 128 | "filename=\"t.bin\"\r\n" \ |
| 129 | "Content-Type: application/octet-stream\r\n\r\nxyz\r\n" \ |
| 130 | "--XB--\r\n"] ""]]] |
| 131 | test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \ |
| 132 | application/octet-stream |
| 133 | |
| 134 | # A name that begins with a capital is taken in lower case. |
| 135 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 136 | "[cgi_part Upper v {; filename="F.TXT"}]--XB--\r\n"]] |
| 137 | test_eq cgi-multipart-upper [cgi_param $cgiReply upper] v |
| 138 | test_eq cgi-multipart-upper-filename [cgi_param $cgiReply upper:filename] F.TXT |
| 139 | |
| 140 | # Lines may end with a bare newline. |
| 141 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 142 | "--XB\nContent-Disposition: form-data; name=\"lf\"\n\nvalue\n--XB--\n"]] |
| 143 | test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value |
| 144 | |
| 145 | # A part with no closing boundary after a long one ends at the end of the |
| 146 | # request, and every part is read within the request. |
| 147 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 148 | [join [list \ |
| 149 | "[cgi_part alpha [string repeat x 3000]]--XB\r\n" \ |
| 150 | "Content-Disposition: form-data; name=\"beta\"\r\n\r\n" \ |
| 151 | "no 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" |
| 157 | |
| 158 | # Malformed and unusual bodies are read without a crash. |
| 159 | set cgiI 0 |
| 160 | foreach cgiBody [list \ |
| 161 | "" \ |
| 162 | "\r\n\r\nvalue\r\n\r\n" \ |
| 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 | [join [list \ |
| 169 | "--XB\r\n" \ |
| 170 | "Content-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n" \ |
| 171 | "--XB--\r\n"] ""] \ |
| 172 | [join [list \ |
| 173 | "--[string repeat B 3000]\r\n" \ |
| 174 | "Content-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n"] ""] \ |
| 175 | [join [list \ |
| 176 | "[cgi_part a [string repeat x 2000]]--XB\r\n" \ |
| 177 | "Content-Disposition: form-data; name=\"b\""] ""] \ |
| 178 | "[cgi_part {} v]--XB--\r\n" \ |
| 179 | [join [list \ |
| 180 | "--XB\r\n" \ |
| 181 | "Content-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n" \ |
| 182 | "--XB--\r\n"] ""] \ |
| 183 | [join [list \ |
| 184 | "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\n" \ |
| 185 | "v\r\n--XB--\r\n"] ""] \ |
| 186 | "--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \ |
| 187 | [join [list \ |
| 188 | "--XB\r\n" \ |
| 189 | "Content-Disposition: form-data; name=\"a\"; " \ |
| 190 | "filename=\r\n\r\nv\r\n--XB--\r\n"] ""] \ |
| 191 | [join [list \ |
| 192 | "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\n" \ |
| 193 | "content-type:\r\n\r\nv\r\n--XB--\r\n"] ""] \ |
| 194 | "[cgi_part a "\n--X"]--XB--\r\n" \ |
| 195 | ] { |
| 196 | incr cgiI |
| 197 | cgi_admin [cgi_post $cgiType $cgiBody] |
| 198 | test cgi-multipart-odd-$cgiI {$CODE == 0} |
| 199 | } |
| 200 | set cgiMany "" |
| 201 | for {set cgiI 0} {$cgiI < 400} {incr cgiI} { |
| 202 | append cgiMany [cgi_part p$cgiI [string repeat v [expr {$cgiI % 50}]]] |
| 203 | } |
| 204 | set cgiReply [cgi_admin [cgi_post $cgiType "$cgiMany--XB--\r\n"]] |
| 205 | test_eq cgi-multipart-many [cgi_param $cgiReply p399] [string repeat v 49] |
| 206 | |
| 207 | ############################################################################### |
| 208 | # The date in an If-Modified-Since header. A file that has not changed |
| 209 | # since that date is not sent again. |
| 210 | |
| 211 | proc cgi_since {date} { |
| 212 | set reply [cgi_send \ |
| 213 | "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" \ |
| 214 | --ipaddr 127.0.0.1] |
| 215 | return [reply_status $reply] |
| 216 | } |
| 217 | test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \ |
| 218 | "HTTP/1.0 304 Not Modified" |
| 219 | test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \ |
| 220 | "HTTP/1.0 200 OK" |
| 221 | test_eq cgi-since-garbage [cgi_since "yesterday"] "HTTP/1.0 200 OK" |
| 222 | # Numbers out of range are not a date. |
| 223 | foreach {cgiName cgiDate} { |
| 224 | year "Mon, 01 Jan 2147483647 00:00:00 GMT" |
| 225 | day "Mon, 2147483647 Jan 2026 00:00:00 GMT" |
| 226 | hour "Mon, 01 Jan 2026 2147483647:00:00 GMT" |
| 227 | minute "Mon, 01 Jan 2026 00:2147483647:00 GMT" |
| 228 | } { |
| 229 | test_eq cgi-since-huge-$cgiName [cgi_since $cgiDate] "HTTP/1.0 200 OK" |
| 230 | } |
| 231 | |
| 232 | ############################################################################### |
| 233 | # A reply is compressed with gzip when the client accepts it and the type |
| 234 | # of the content is text, JavaScript, JSON, WebAssembly, Tcl, tar, XML, |
| 235 | # SVG or an icon. Other types, and a client that does not accept gzip, |
| 236 | # get the content as it is. |
| 237 | |
| 238 | foreach {cgiName cgiGzip} { |
| 239 | g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1 |
| 240 | g.ico 1 g.png 0 g.zip 0 g.pdf 0 |
| 241 | } { |
| 242 | write_file $cgiName [string repeat "content to compress\n" 50] |
| 243 | fossil uv add $cgiName |
| 244 | set cgiReply [cgi_send \ |
| 245 | [join [list \ |
| 246 | "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\n" \ |
| 247 | "Accept-Encoding: gzip, deflate\r\n\r\n"] ""] --ipaddr 127.0.0.1] |
| 248 | test_eq cgi-gzip-$cgiName \ |
| 249 | [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip |
| 250 | } |
| 251 | set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 252 | --ipaddr 127.0.0.1] |
| 253 | test cgi-gzip-not-accepted {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 254 | && ![string match "*Content-Encoding*" $cgiReply]} |
| 255 | |
| 256 | ############################################################################### |
| 257 | # A POST whose Referer is another site is not taken as safe from forgery, |
| 258 | # and is written to the error log. |
| 259 | |
| 260 | proc cgi_logout {referer} { |
| 261 | return [cgi_send [cgi_post_from $referer /login "out=1"] --ipaddr 10.0.0.1 \ |
| 262 | --errorlog [file join [pwd] err.log]] |
| 263 | } |
| 264 | file delete err.log |
| 265 | cgi_logout http://x/login |
| 266 | test cgi-same-origin-not-logged {![file exists err.log] |
| 267 | || ![string match "*different origin*" [read_file err.log]]} |
| 268 | cgi_logout http://elsewhere.example/page |
| 269 | test cgi-other-origin-logged {[file exists err.log] |
| 270 | && [string match "*POST from different origin*" [read_file err.log]]} |
| 271 | |
| 272 | ############################################################################### |
| 273 | # SCGI: a header of name and value pairs, each ended by a zero byte, |
| 274 | # preceded by its length and followed by a comma. |
| 275 | |
| 276 | proc cgi_scgi {pairs {body ""}} { |
| 277 | set h "" |
| 278 | foreach {k v} $pairs { append h $k \000 $v \000 } |
| 279 | return "[string length $h]:$h,$body" |
| 280 | } |
| 281 | set cgiReply [cgi_send [cgi_scgi { |
| 282 | CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1 |
| 283 | PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80 |
| 284 | REMOTE_ADDR 127.0.0.1 |
| 285 | }] --scgi --localauth] |
| 286 | test_eq cgi-scgi [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 287 | test_eq cgi-scgi-param [cgi_param $cgiReply s] 1 |
| 288 | |
| 289 | foreach {cgiName cgiRequest} [list \ |
| 290 | too-short "15:CONTENT_LENGTH\0000\000," \ |
| 291 | cut-short "40:CONTENT_LENGTH\0000\000," \ |
| 292 | no-zero "20:CONTENT_LENGTH0000000000," \ |
| 293 | huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \ |
| 294 | ] { |
| 295 | set cgiReply [cgi_send $cgiRequest --scgi] |
| 296 | test cgi-scgi-$cgiName {$CODE == 0 && |
| 297 | [string match "HTTP/1.0 400*" [reply_status $cgiReply]]} |
| 298 | } |
| 299 | |
| 300 | ############################################################################### |
| 301 | # The same reader for a request that arrives over ssh, which the server |
| 302 | # knows from SSH_CONNECTION. It reads the client's probes first. |
| 303 | |
| 304 | set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" |
| 305 | set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 306 | --localauth] |
| 307 | test_eq cgi-ssh [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 308 | test_eq cgi-ssh-param [cgi_param $cgiReply q] 1 |
| 309 | test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1 |
| 310 | |
| 311 | set cgiReply [cgi_send [cgi_post application/x-www-form-urlencoded \ |
| 312 | "p=posted"] --localauth] |
| 313 | test_eq cgi-ssh-post [cgi_param $cgiReply p] posted |
| 314 | |
| 315 | # An older client opens the connection with "echo" probes, each of which |
| 316 | # the server answers with the word it was given, and then names the |
| 317 | # command it ran. Any other word in a probe is refused. |
| 318 | set cgiReply [cgi_send \ |
| 319 | [join [list \ |
| 320 | "echo test1\necho probe-2\nfossil\n" \ |
| 321 | "GET /test-env?q=3 HTTP/1.1\r\nHost: x\r\n\r\n"] ""] --localauth] |
| 322 | test cgi-ssh-probes {[string match "test1\nprobe-2\n*" $cgiReply] |
| 323 | && [string match "*\nHTTP/1.0 200 OK*" $cgiReply]} |
| 324 | test_eq cgi-ssh-probes-param [cgi_param $cgiReply q] 3 |
| 325 | foreach {cgiName cgiRequest} [list \ |
| 326 | probe-word "echo hello\n" \ |
| 327 | probe-alone "echo\n" \ |
| 328 | probe-no-command "echo test1\n" \ |
| 329 | ] { |
| 330 | set cgiReply [cgi_send $cgiRequest --localauth] |
| 331 | test cgi-ssh-$cgiName {$CODE == 0 |
| 332 | && [string match "*400 Bad Request*" $cgiReply]} |
| 333 | } |
| 334 | |
| 335 | foreach {cgiName cgiRequest} [list \ |
| 336 | empty "" \ |
| 337 | bad-method "PUT /x HTTP/1.1\r\n\r\n" \ |
| 338 | no-url "GET\r\n\r\n" \ |
| 339 | long-line "GET /[string repeat a 5000] HTTP/1.1\r\n\r\n" \ |
| 340 | ] { |
| 341 | cgi_send $cgiRequest |
| 342 | test cgi-ssh-$cgiName {$CODE == 0 || $CODE == 1} |
| 343 | } |
| 344 | unset ::env(SSH_CONNECTION) |
| 345 | |
| 346 | ############################################################################### |
| 347 | # The tests above try each kind of request once. The tests below aim |
| 348 | # at every branch of cgi.c. |
| 349 | |
| 350 | if {[test_assurance] eq "smoke"} { |
| 351 | test_skip "the tests of each branch need -assurance ci or stress" |
| 352 | } |
| 353 | |
| 354 | ############################################################################### |
| 355 | # Names and values in a query string and in a Cookie header. A name is |
| 356 | # taken when it begins with a letter and holds only letters, digits, |
| 357 | # "_" and "-"; of two values with one name the first is kept; a value |
| 358 | # from the query string that holds a control character is dropped. |
| 359 | |
| 360 | set cgiReply [cgi_admin [request_get \ |
| 361 | "/test-env?e&a=1&=5&&a\$b=6&c=%01x&1a=2&_u=3&a=second&Up=4&zz" \ |
| 362 | [list "Cookie: ck=1; sp=2; fossil-x=9; Big=3"]]] |
| 363 | foreach {cgiName cgiParam cgiValue} { |
| 364 | no-value-first e "" |
| 365 | plain a 1 |
| 366 | empty-name "" - |
| 367 | strange-name a$b - |
| 368 | control-char c - |
| 369 | digit-first 1a - |
| 370 | underscore _u - |
| 371 | upper up 4 |
| 372 | no-value-last zz "" |
| 373 | cookie ck 1 |
| 374 | cookie-space sp 2 |
| 375 | cookie-upper big 3 |
| 376 | cookie-fossil fossil-x - |
| 377 | cookie-header HTTP_COOKIE - |
| 378 | } { |
| 379 | test_eq cgi-names-$cgiName [cgi_param $cgiReply $cgiParam] $cgiValue |
| 380 | } |
| 381 | |
| 382 | # With "showall" the page shows the cookies as well. |
| 383 | set cgiReply [cgi_admin [request_get /test-env?showall \ |
| 384 | [list "Cookie: ck=1; fossil-x=9"]]] |
| 385 | test_eq cgi-showall-cookie [cgi_param $cgiReply fossil-x] 9 |
| 386 | test_eq cgi-showall-header [cgi_param $cgiReply HTTP_COOKIE] "ck=1; fossil-x=9" |
| 387 | |
| 388 | # A value in a form may hold a control character. |
| 389 | set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded \ |
| 390 | "k=%01x&plain=1"]] |
| 391 | test_eq cgi-post-control-char [cgi_param $cgiReply k] "\001x" |
| 392 | |
| 393 | # More than 630 parameters are refused. |
| 394 | set cgiMany "" |
| 395 | for {set cgiI 0} {$cgiI < 700} {incr cgiI} { append cgiMany "q$cgiI=1&" } |
| 396 | set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded $cgiMany]] |
| 397 | test cgi-too-many {$CODE == 1 |
| 398 | && [string match "*Too many query parameters*" $cgiReply$RESULT]} |
| 399 | |
| 400 | ############################################################################### |
| 401 | # The request line and the header lines. |
| 402 | |
| 403 | set cgiReply [cgi_admin \ |
| 404 | [join [list \ |
| 405 | "GET /test-env?showall HTTP/1.1\r\n" \ |
| 406 | "HOST: named.example:8080\r\nIf-None-Match: tag\r\n" \ |
| 407 | "Authorization: Basic eDp5\r\nAccept-Language: de \r\n" \ |
| 408 | "User-Agent: Agent/1\r\nUnknown-Header: ignored\r\n\r\n"] ""]] |
| 409 | foreach {cgiParam cgiValue} { |
| 410 | HTTP_HOST named.example:8080 |
| 411 | SERVER_NAME named.example |
| 412 | HTTP_IF_NONE_MATCH tag |
| 413 | HTTP_AUTHORIZATION {Basic eDp5} |
| 414 | HTTP_ACCEPT_LANGUAGE de |
| 415 | HTTP_USER_AGENT Agent/1 |
| 416 | REQUEST_SCHEME http |
| 417 | REQUEST_METHOD GET |
| 418 | } { |
| 419 | test_eq cgi-header-$cgiParam [cgi_param $cgiReply $cgiParam] $cgiValue |
| 420 | } |
| 421 | |
| 422 | # An "Https:" header says that the request came by https, so the reply |
| 423 | # sends a local user to the https login page. |
| 424 | set cgiReply [cgi_admin [request_get /test-env [list "Https: on"]]] |
| 425 | test_eq cgi-header-https [reply_header $cgiReply Location] \ |
| 426 | https://x/login?g=test-env |
| 427 | |
| 428 | # X-Forwarded-For names the client when the request comes from this |
| 429 | # machine: the last address in it is taken. From any other machine the |
| 430 | # header is ignored. Only a local client sees /test-env here. |
| 431 | foreach {cgiName cgiFrom cgiForwarded cgiAddr} { |
| 432 | one ::1 127.0.0.1 127.0.0.1 |
| 433 | comma 127.0.0.1 9.9.9.9,::1 ::1 |
| 434 | space 127.0.0.1 {9.9.9.9, 127.0.0.1} 127.0.0.1 |
| 435 | mapped 127.0.0.1 ::ffff:127.0.0.1 ::ffff:127.0.0.1 |
| 436 | remote 127.0.0.1 {127.0.0.1, 9.9.9.9} - |
| 437 | empty 127.0.0.1 {} - |
| 438 | not-local 10.0.0.1 127.0.0.1 - |
| 439 | } { |
| 440 | set cgiReply [cgi_send [request_get /test-env \ |
| 441 | [list "X-Forwarded-For: $cgiForwarded"]] --ipaddr $cgiFrom --localauth] |
| 442 | test_eq cgi-forwarded-$cgiName [cgi_param $cgiReply REMOTE_ADDR] $cgiAddr |
| 443 | } |
| 444 | |
| 445 | # HEAD gets the headers of the reply to GET and no content. |
| 446 | set cgiReply [cgi_send [request_get /uv/g.png {} HEAD] --ipaddr 127.0.0.1] |
| 447 | test_eq cgi-head-status [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 448 | test_eq cgi-head-length [reply_header $cgiReply Content-Length] 1000 |
| 449 | test_eq cgi-head-body [reply_body $cgiReply] "" |
| 450 | |
| 451 | # A POST must say how long its content is, and send that much. |
| 452 | set cgiReply [cgi_admin "POST /test-env HTTP/1.1\r\nHost: x\r\n\r\n"] |
| 453 | test cgi-post-no-length {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request" |
| 454 | && [string match "*missing CONTENT_LENGTH on a POST method*" $cgiReply]} |
| 455 | set cgiReply [cgi_admin \ |
| 456 | [join [list \ |
| 457 | "POST /test-env HTTP/1.1\r\nHost: x\r\n" \ |
| 458 | "Content-Type: application/x-www-form-urlencoded\r\n" \ |
| 459 | "Content-Length: 50\r\n\r\na=1"] ""]] |
| 460 | test cgi-post-short {[reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request" |
| 461 | && [string match "*Wanted 50 bytes but got only 3*" $cgiReply]} |
| 462 | # Content with no type is not read. |
| 463 | set cgiReply [cgi_admin \ |
| 464 | "POST /test-env HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\n\r\na=1"] |
| 465 | test cgi-post-no-type {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 466 | && [cgi_param $cgiReply a] eq "-"} |
| 467 | foreach {cgiName cgiLength} \ |
| 468 | {negative -5 zero 0 word abc huge 99999999999999999999} { |
| 469 | set cgiReply [cgi_admin \ |
| 470 | [join [list \ |
| 471 | "POST /test-env HTTP/1.1\r\nHost: x\r\n" \ |
| 472 | "Content-Type: application/x-www-form-urlencoded\r\ [list \ |
| 473 | "POST /teng match "*missing C5 && [regexp {^HTTP/1.0 (200|400) } $cgiReply]} |
| 474 | } |
| 475 | |
| 476 | ############################################################################### |
| 477 | # Part of a file: a Range header on a GET that succeeds gets the bytes |
| 478 | # asked for, not compressed, with status 206. |
| 479 | |
| 480 | write_file r.css 0123456789abcdefghij |
| 481 | fossil uv add r.css |
| 482 | proc cgi_range {range {method GET} {file r.css}} { |
| 483 | return [cgi_send [request_get /uv/$file \ |
| 484 | [file \ |
| 485 | [list "Range: $range" "Accept-Encoding: gzip"] $method] \ |
| 486 | --ipaddr 127.0.0.1] |
| 487 | } |
| 488 | set cgiReply [cgi_range bytes=2-5] |
| 489 | test_eq cgi-range-s 200 OK" \ |
| 490 | $::trunkMark |
| 491 | # A reply other than 206 is sent whole, whatever range was asked for. |
| 492 | set cgiReply [cgi_send [request_get /uv/nosuch.css [list "Range: bytes=3-9"]] \ |
| 493 | --ipaddr 127.0.0.1] |
| 494 | test cgi-range-not-found { |
| 495 | [string match "HTTP/1.0 404 *" [reply_status $cgiReply]] |
| 496 | && [string match "<!DOCTYPE |
| 497 | |
| 498 | ############################################################################### |
| 499 | # More shapes of form data in several parts. |
| 500 | |
| 501 | proc cgi_form {body} { |
| 502 | global cgiType |
| 503 | return [cgi_admin [cgi_post $cgiType $body]] |
| 504 | } |
| 505 | # A part with no content, where lines end with a bare newline. |
| 506 | set cgiReply [cgi_form \ |
| 507 | "--XB\nContent-Disposition: form-data; name=\"none\"\n\n\n--XB--\n"] |
| 508 | test_eq cgi-multipart-empty-value [cgi_param $cgiReply none] "" |
| 509 | |
| 510 | # A name in capitals with no file name is taken in lower case and has no |
| 511 | # count of bytes. |
| 512 | set cgiReply [cgi_form "[cgi_part Shout loud]--XB--\r\n"] |
| 513 | test_eq cgi-multipart-upper-plain [cgi_param $cgiReply shout] loud |
| 514 | test_eq cgi-multipart-upper-no-bytes [cgi_param $cgiReply shout:bytes] - |
| 515 | |
| 516 | # A name in capitals with a type of content. |
| 517 | set cgiReply [cgi_form \ |
| 518 | [join [list \ |
| 519 | "--XB\r\n" \ |
| 520 | "Content-Disposition: form-data; name=\"Typed\"; " \ |
| 521 | "filename=\"t\"\r\nContent-Type: text/x-test\r\n\r\nv\r\n" \ |
| 522 | "--XB--\r\n"] ""]] |
| 523 | test_eq cgi-multipart-upper-mimetype [cgi_param $cgiReply typed:mimetype] \ |
| 524 | text/x-test |
| 525 | test_eq cgi-multipart-upper-bytes [cgi_param $cgiReply typed:bytes] 1 |
| 526 | |
| 527 | # A name that does not begin with a letter is not taken, with or without |
| 528 | # a file name or a type. |
| 529 | set cgiReply [cgi_form \ |
| 530 | [join [list \ |
| 531 | "--XB\r\n" \ |
| 532 | "Content-Disposition: form-data; name=\"1st\"; " \ |
| 533 | "fir\nContent-Type: text/plain\r\n\r\nv\r\n" \ |
| 534 | "[cgi_part after ok]--XB--\r\n"] ""]] |
| 535 | test_eq cgi-multipart-digit-name [cgi_param $cgiReply 1st] - |
| 536 | test_eq cgi-multipart-digit-filename [cgi_param $cgiReply 1st:filename] - |
| 537 | test_eq cgi-multipart-digit-mimetype [cgi_param $cgiReply 1st:mimetype] - |
| 538 | test_eq cgi-multipart-digit-next [cgi_param $cgiReply after] ok |
| 539 | |
| 540 | # A type or a file name given before the name belongs to no parameter. |
| 541 | set cgiReply [cgi_form \ |
| 542 | [join [list \ |
| 543 | "--XB\r\nContent-Type: text/early\r\n" \ |
| 544 | "Content-Disposition: form-data; filename=\"early\"; " \ |
| 545 | "name=\"late\"\r\n\r\nv\r\n--XB--\r\n"] ""]] |
| 546 | test_eq cgi-multipart-type-first-value [cgi_param $cgiReply late] v |
| 547 | test_eq cgi-multipart-type-first-mimetype [cgi_param $cgiReply late:mimetype] - |
| 548 | test_eq cgi-multipart-type-first-filename [cgi_parfter] eq "ok"} $::trunkMark |
| 549 | |
| 550 | # Content that begins with a zero byte has no parts. |
| 551 | set cgiReply [cgi_form "\000--XB\r\n[cgi_part a v]--XB--\r\n"] |
| 552 | test cgi-multipart-zero-first {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 553 | && [cgi_param $cgiReply a] eq "-"} |
| 554 | |
| 555 | ############################################################################### |
| 556 | # More dates in If-Modified-Since. The file is given the time that the |
| 557 | # date stands for and is then not sent again; one second newer and it is. |
| 558 | |
| 559 | write_file d.bin "dated" |
| 560 | fossil uv add d.bin |
| 561 | proc cgi_since_exact {date seconds} { |
| 562 | set result "" |
| 563 | foreach mtime [list $seconds [expr {$seconds + 1}]] { |
| 564 | fossil sql "UPDATE unversioned SET mtime=$mtime WHERE name='d.bin'" |
| 565 | set reply [cgi_send [request_get /uv/d.bin \ |
| 566 | [list "If-Modified-Since: $date"]] \ |
| 567 | --ipaddr 127.0.0.1] |
| 568 | lappend result [lindex [reply_status $reply] 1] |
| 569 | } |
| 570 | return $result |
| 571 | } |
| 572 | foreach {cgiName cgiDate cgiSeconds} { |
| 573 | epoch-year "Thu, 01 Jan 1970 00:00:10 GMT" 10 |
| 574 | two-digit-year "Fri, 31 Dec 99 23:59:59 GMT" 946684799 |
| 575 | leap-2000-feb "Tue, 29 Feb 2000 12:00:00 GMT" 951825600 |
| 576 | leap-2000-mar "Wed, 01 Mar 2000 00:00:00 GMT" 951868800 |
| 577 | leap-2024-jan "Wed, 31 Jan 2024 00:00:00 GMT" 1706659200 |
| 578 | leap-2024-dec "Tue, 31 Dec 2024 23:59:60 GMT" 1735689600 |
| 579 | plain-2023-mar "Wed, 01 Mar 2023 01:02:03 GMT" 1677632523 |
| 580 | not-leap-2100 "Mon, 01 Mar 2100 00:00:00 GMT" 4107456000 |
| 581 | year-8099 "Thu, 31 Dec 9999 23:59:59 GMT" 253402300799 |
| 582 | } { |
| 583 | test_eq cgi-since-exact-$cgiName [cgi_since_exact $cgiDate $cgiSeconds] \ |
| 584 | {304 200} |
| 585 | } |
| 586 | # Each of these is not a date, so the file is sent. |
| 587 | fossil sql "UPDATE unversioned SET mtime=1 WHERE name='d.bin'" |
| 588 | foreach {cgiName cgiDate} { |
| 589 | year-before-1970 "Wed, 01 Jan 69 00:00:00 GMT" |
| 590 | year-10000 "Sat, 01 Jan 10000 00:00:00 GMT" |
| 591 | day-zero "Mon, 00 Jan 2026 00:00:00 GMT" |
| 592 | day-32 "Mon, 32 Jan 2026 00:00:00 GMT" |
| 593 | hour-negative "Mon, 01 Jan 2026 -1:00:00 GMT" |
| 594 | hour-24 "Mon, 01 Jan 2026 24:00:00 GMT" |
| 595 | minute-negative "Mon, 01 Jan 2026 00:-1:00 GMT" |
| 596 | minute-60 "Mon, 01 Jan 2026 00:60:00 GMT" |
| 597 | second-negative "Mon, 01 Jan 2026 00:00:-1 GMT" |
| 598 | second-61 "Mon, 01 Jan 2026 00:00:61 GMT" |
| 599 | month "Mon, 01 Foo 2026 00:00:00 GMT" |
| 600 | short "Mon, 01 Jan 2026" |
| 601 | empty "" |
| 602 | } { |
| 603 | set cgiReply [cgi_send [request_get /uv/d.bin \ |
| 604 | [list "If-Modified-Since: $cgiDate"]] --ipaddr 127.0.0.1] |
| 605 | test_eq cgi-since-not-a-date-$cgiName [reply_status $cgiReply] \ |
| 606 | "HTTP/1.0 200 OK" |
| 607 | } |
| 608 | |
| 609 | ############################################################################### |
| 610 | # Redirects. A redirect to an absolute URL is sent as it is; a redirect |
| 611 | # to a path that begins with "/" is made relative to the base URL; any |
| 612 | # other target is appended to the base URL. The "referer" query |
| 613 | # parameter, the Referer header, or a default supplies the target for |
| 614 | # the user-edit cancel button. |
| 615 | |
| 616 | proc cgi_redirect_to {query {referer none}} { |
| 617 | set headers {} |
| 618 | if {$referer ne "none"} { lappend headers "Referer: $referer" } |
| 619 | set reply [cgi_admin [request_get "/setup_uedit?$query" $headers]] |
| 620 | return [reply_header $reply Location] |
| 621 | } |
| 622 | # The cancel button redirects to the referer. |
| 623 | test_eq cgi-redirect-absolute-http [cgi_redirect_to can=1 http://other/p] \ |
| 624 | http://other/p |
| 625 | test_eq cgi-redirect-absolute-https [cgi_redirect_to can=1 https://other/p] \ |
| 626 | https://other/p |
| 627 | test_eq cgi-redirect-rooted [cgi_redirect_to {can=1&referer=/at-root}] \ |
| 628 | http://x/at-root |
| 629 | test_eq cgi-redirect-relative [cgi_redirect_to {can=1&referer=some/where}] \ |
| 630 | http://x/some/where |
| 631 | # With no referer parameter and no Referer header, the default is used. |
| 632 | test_eq cgi-redirect-default [cgi_redirect_to can=1] http://x/setup_ulist |
| 633 | # The "referer" query parameter is preferred over the Referer header. |
| 634 | test_eq cgi-redirect-param-wins \ |
| 635 | [cgi_redirect_to {can=1&referer=/from-param} http://x/from-header] \ |
| 636 | http://x/from-param |
| 637 | |
| 638 | ############################################################################### |
| 639 | # The anti-forgery check. A GET from the same origin is "same origin" |
| 640 | # only; a POST adds "POST"; a POST that also carries the right "csrf" |
| 641 | # token adds "CSRF token". The page reports the level it reached. |
| 642 | |
| 643 | proc cgi_csrf_level {reply} { |
| 644 | if {[regexp {CSRF safety = ([^<]*)} $reply all level]} { return $level } |
| 645 | return - |
| 646 | } |
| 647 | set cgiToken "" |
| 648 | set cgiReply [cgi_admin [request_get /setup_uedit?id=0]] |
| 649 | regexp {name="csrf" value="([^"]*)"} $cgiReply all cgiToken |
| 650 | |
| 651 | set cgiReply [cgi_admin [request_get /test-env [list "Referer: http://x/prev"]]] |
| 652 | test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin" |
| 653 | proc cgi_env_post {body {referer http://x/prev}} { |
| 654 | return [cgi_admin [cgi_post_from $referer /test-env $body]] |
| 655 | } |
| 656 | set cgiReply [cgi_env_post "csrf=$cgiToken"] |
| 657 | test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] \ |
| 658 | "Same origin, POST, CSRF token" |
| 659 | set cgiReply [cgi_env_post "csrf=wrong"] |
| 660 | test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST" |
| 661 | set cgiReply [cgi_env_post "x=1" http://elsewhere/p] |
| 662 | test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe" |
| 663 | |
| 664 | # A page that consults the check more than once. A cross-origin POST to |
| 665 | # the user-edit page, which asks twice, is ignored without error. |
| 666 | set cgiReply [cgi_admin [cgi_post_from http://elsewhere/p /setup_uedit \ |
| 667 | "id=0&delete=1&"]] |
| 668 | test_eq cgi-csrf-twice-cross [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 669 | # A valid same-origin POST with the token creates the user. |
| 670 | set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken" |
| 671 | set cgiReply [cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit \ |
| 672 | $cgiBody]] |
| 673 | test cgi-csrf-verify-accepts \ |
| 674 | {[string match "HTTP/1.0 302*" [reply_status $cgiReply]]} |
| 675 | test cgi-csrf-user-created \ |
| 676 | {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1} |
| 677 | |
| 678 | # The user-edit page needs "login", "info", "pw" and "apply" to make a |
| 679 | # change. A request with "login" alone changes nothing. |
| 680 | set cgiBody "id=0&login=cgighost&csrf=$cgiToken" |
| 681 | cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit $cgiBody] |
| 682 | test cgi-all-needs-every-field \ |
| 683 | {[fossil sql "SELECT count(*) FROM user WHE |
| 684 | |
| 685 | ############################################################################### |
| 686 | # rev"]]] |
| 687 | test_eq cgi-csrf-get [cgi_csrf_level $cgiReply] "Same origin" |
| 688 | proc cgi_env_post {body {referer http://x/prev}} { |
| 689 | return [cgi_admin [cgi_post_from $referer /test-env $body]] |
| 690 | } |
| 691 | set cgiReply [cgi_env_post "csrf=$cgiToken"] |
| 692 | test_eq cgi-csrf-post-token [cgi_csrf_level $cgiReply] \ |
| 693 | "Same origin, POST, CSRF token" |
| 694 | set cgiReply [cgi_env_post "csrf=wrong"] |
| 695 | test_eq cgi-csrf-post-bad-token [cgi_csrf_level $cgiReply] "Same origin, POST" |
| 696 | set cgiReply [cgi_env_post "x=1" http://elsewhere/p] |
| 697 | test_eq cgi-csrf-post-other-origin [cgi_csrf_level $cgiReply] "unsafe" |
| 698 | |
| 699 | # A page that consults the check more than once. A cross-origin POST to |
| 700 | # the user-edit page, which asks twice, is ignored without error. |
| 701 | set cgiReply [cgi_admin [cgi_post_from http://elsewhere/p /setup_uedit \ |
| 702 | "id=0&delete=1&"]] |
| 703 | test_eq cgi-csrf-twice-cross [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 704 | # A valid same-origin POST with the token creates the user. |
| 705 | set cgiBody "id=0&login=newcomer&info=x&pw=secretpw&apply=1&csrf=$cgiToken" |
| 706 | set cgiReply [cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit \ |
| 707 | $cgiBody]] |
| 708 | test cgi-csrf-verify-accepts \ |
| 709 | {[string match "HTTP/1.0 302*" [reply_status $cgiReply]]} |
| 710 | test cgi-csrf-user-created \ |
| 711 | {[fossil sql "SELECT count(*) FROM user WHERE login='newcomer'"] == 1} |
| 712 | |
| 713 | # The user-edit page needs "login", "info", "pw" and "apply" to make a |
| 714 | # change. A request with "login" alone changes nothing. |
| 715 | set cgiBody "id=0&login=cgighost&csrf=$cgiToken" |
| 716 | cgi_admin [cgi_post_from http://x/setup_uedit /setup_uedit $cgiBody] |
| 717 | test cgi-all-needs-every-field \ |
| 718 | {[fossil sql "SELECT count(*) FROM user WHERE login='cgighost'"] == 0} \ |
| 719 | $::trunkMark |
| 720 | |
| 721 | ############################################################################### |
| 722 | # Request methods and the same reader over ssh. |
| 723 | |
| 724 | set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" |
| 725 | # A HEAD over ssh. |
| 726 | set cgiReply [cgi_send [request_get /test-env?q=9 {} HEAD] --localauth] |
| 727 | test_eq cgi-ssh-head [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 728 | unset ::env(SSH_CONNECTION) |
| 729 | |
| 730 | ############################################################################### |
| 731 | # cgi_from_mobile, used by /forum to pick a default display order. An |
| 732 | # iPad is not treated as mobile; another phone is; no agent is not. |
| 733 | proc cgi_forum_order {agent} { |
| 734 | set headers {} |
| 735 | if {$agent ne ""} { lappend headers "User-Agent: $agent" } |
| 736 | set reply [cgi_admin [request_get /forum?t=a $headers]] |
| 737 | return [reply_status $reply] |
| 738 | } |
| 739 | foreach {cgiName cgiAgent} { |
| 740 | phone "Mozilla/5.0 (iPhone; Mobile) Safari" |
| 741 | ipad "Mozilla/5.0 (iPad) Safari" |
| 742 | none "" |
| 743 | } { |
| 744 | test_eq cgi-mobile-$cgiName [cgi_forum_order $cgiAgent] "HTTP/1.0 200 OK" |
| 745 | } |
| 746 | |
| 747 | ############################################################################### |
| 748 | # A spider check. For a request that is not logged in, an unused query |
| 749 | # parameter whose value looks like an injection attack gets a 418 reply |
| 750 | # and a note in the error log. The whole request environment is written |
| 751 | # to the log. |
| 752 | |
| 753 | proc cgi_attack {value} { |
| 754 | global cgiRepo |
| 755 | write_file request.txt \ |
| 756 | [join [list \ |
| 757 | "GET /timeline?inj=$value HTTP/1.1\r\nHost: x\r\n" \ |
| 758 | "Cookie: fossil-x=secret\r\n\r\n"] ""] |
| 759 | file delete reply.txt attack.log |
| 760 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 761 | --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log] |
| 762 | return [expr {[file exists reply.txt] ? [read_file reply.txt] : ""}] |
| 763 | } |
| 764 | set cgiReply [cgi_attack "1;select"] |
| 765 | test_eq cgi-attack-status [reply_status $cgiReply] "HTTP/1.0 418 I'm a teapot" |
| 766 | test cgi-attack-logged {[file exists attack.log] |
| 767 | && [string match "*possible hack attempt*" [read_file attack.log]] |
| 768 | && [string match "*QUERY_STRING = inj=1;select*" [read_file attack.log]]} |
| 769 | # A value longer than 100 characters is shortened in the log. |
| 770 | set cgiReply [cgi_attack "[string repeat a 200];x"] |
| 771 | test cgi-attack-long {[reply_status $cgiReply] eq "HTTP/1.0 418 I'm a teapot" |
| 772 | && [string match "*aaa...*" [read_file attack.log]]} |
| 773 | # A logged-in request with the same value is not stopped. |
| 774 | set cgiReply [cgi_admin [request_get "/timeline?inj=1;select"]] |
| 775 | test_eq cgi-attack-admin-ok [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 776 | |
| 777 | ############################################################################### |
| 778 | # The same-origin test with crafted Referer headers. The base URL here |
| 779 | # is "http://x". A Referer that shares the base but has more path after |
| 780 | # it with no "/" boundary is a different origin. A Referer with a "%" |
| 781 | # escape is decoded before the comparison. The /test-env page reports |
| 782 | # the result. |
| 783 | |
| 784 | proc cgi_origin {referer} { |
| 785 | set req "GET /test-env HTTP/1.1\r\nHost: x\r\nReferer: $referer\r\n\r\n" |
| 786 | set reply [cgi_admin $req] |
| 787 | return [cgi_csrf_level $reply] |
| 788 | } |
| 789 | test_eq cgi-origin-boundary [cgi_origin http://xtra/page] unsafe |
| 790 | test_eq cgi-origin-escaped [cgi_origin http://x/a%2Fb] "Same origin" |
| 791 | # A different-origin GET reaches the method test in the same-origin check |
| 792 | # without writing a warning (the warning is for POST only). |
| 793 | test_eq cgi-origin-get-other [cgi_origin http://elsewhere/p] unsafe |
| 794 | |
| 795 | ############################################################################### |
| 796 | # cgi_parameter_name walks every parameter: the ticket-entry page copies |
| 797 | # each into its interpreter. |
| 798 | |
| 799 | set cgiReply [cgi_admin [request_get "/tktnew?username=someone&extra=1"]] |
| 800 | test_eq cgi-param-name-page [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 801 | |
| 802 | ############################################################################### |
| 803 | # cgi_param_info walks the parameters for the /cookies page. |
| 804 | |
| 805 | set cgiReply [cgi_admin [request_get /cookies \ |
| 806 | [list "Cookie: fossil_display_settings=x; extra=y"]]] |
| 807 | test cgi-param-info-page {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 808 | && [string match "*fossil_display_settings*" $cgiReply]} |
| 809 | |
| 810 | ############################################################################### |
| 811 | # Two more destinations for cgi_print_all. With --cgitrace the whole |
| 812 | # parameter set is traced before the page runs. |
| 813 | |
| 814 | write_file request.txt [request_get "/test-env?traced=1"] |
| 815 | file delete reply.txt |
| 816 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 817 | --ipaddr 127.0.0.1 --localauth --cgitrace |
| 818 | test cgi-cgitrace {$CODE == 0 |
| 819 | && [string match "*Calling*" $RESULT] |
| 820 | && [string match "*traced = 1*" $RESULT]} |
| 821 | |
| 822 | # A CGI control file with "cgi-debug:" writes the environment to a debug |
| 823 | # file as the control file is read. |
| 824 | write_file cgi.ctl \ |
| 825 | "repository: [file nativename $cgiRepo]\ncgi-debug: debug.txt\n" |
| 826 | file delete debug.txt |
| 827 | set ::env(REQUEST_METHOD) GET |
| 828 | set ::env(SCRIPT_NAME) "" |
| 829 | set ::env(PATH_INFO) /test-env |
| 830 | set ::env(QUERY_STRING) "dbg=1" |
| 831 | set ::env(REMOTE_ADDR) 127.0.0.1 |
| 832 | fossil_raw cgi cgi.ctl |
| 833 | foreach cgiVar {REQUEST_METHOD SCRIPT_NAME PATH_INFO QUERY_STRING REMOTE_ADDR} { |
| 834 | unset ::env($cgiVar) |
| 835 | } |
| 836 | test cgi-debug-file {[file exists debug.txt] |
| 837 | && [string match "*QUERY_STRING = dbg=1*" [read_file debug.txt]]} |
| 838 | |
| 839 | ############################################################################### |
| 840 | # Trimmed, boolean and "checked" parameter readers, reached through the |
| 841 | # email-alert subscription page. The page exists once email is enabled |
| 842 | # and its tables are built. |
| 843 | |
| 844 | fossil settings email-send-method db |
| 845 | set cgiNotifyBody "submit=Refresh&esm=db&csrf=$cgiToken" |
| 846 | cgi_admin [cgi_post_from http://x/setup_notification /setup_notification \ |
| 847 | $cgiNotifyBody] |
| 848 | test cgi-alert-tables-built \ |
| 849 | {[fossil sql "SELECT count(*) FROM sqlite_schema WHERE name='subscriber'"] |
| 850 | == 1} |
| 851 | |
| 852 | # The form renders the "checked" state of the checkboxes. |
| 853 | set cgiReply [cgi_admin [request_get /subscribe]] |
| 854 | test cgi-subscribe-form {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 855 | && [string match "*checkbox*" $cgiReply]} |
| 856 | |
| 857 | # A submitted subscription: the name is trimmed and the boxes are read as |
| 858 | # booleans. A leading and trailing space on the name is removed. |
| 859 | set cgiSubBody \ |
| 860 | [join [list \ |
| 861 | "submit=1&[email protected]&suname= trimmed " \ |
| 862 | "&sa=1&sc=on&csrf=$cgiToken"] ""] |
| 863 | cgi_admin [cgi_post_from http://x/subscribe /subscribe $cgiSubBody] |
| 864 | test_eq cgi-subscribe-trimmed-name \ |
| 865 | [fossil sql \ |
| 866 | "SELECT suname FROM subscriber WHERE semail='[email protected]'"] \ |
| 867 | "trimmed" |
| 868 | test cgi-subscribe-boolean-alert \ |
| 869 | {[string match "*a*" [fossil sql \ |
| 870 | "SELECT ssub FROM subscriber WHERE semail='[email protected]'"]]} |
| 871 | |
| 872 | ############################################################################### |
| 873 | # The HTTP reader is called in a loop for a request arriving over ssh. |
| 874 | # When the first request announces the Fossil ssh transport, the reader |
| 875 | # is called again for a second request in the same connection, and the |
| 876 | # later request updates the parameters that the first one set. |
| 877 | |
| 878 | set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" |
| 879 | write_file request.txt \ |
| 880 | [join [list \ |
| 881 | "GET /test-env?first=1 HTTP/1.1\r\nHost: x\r\n" \ |
| 882 | "X-Fossil-Transport: ssh\r\nContent-Length: 0\r\n\r\n" \ |
| 883 | "G |
| 884 | set cgiReply [cgi_cookie_delete https://x/d] |
| 885 | test cgi-cookie-delete-secure {[string match "*max-age=-1;*secure;*" $cgiReply] |
| 886 | || [string match "*max-age=-1;* secure*" $cgiReply]} |
| 887 | |
| 888 | ############################################################################### |
| 889 | # Compression of several reply content types that are named by the "m" |
| 890 | # parameter on a raw artifact. A committed file gives a blob to serve. |
| 891 | |
| 892 | write_file art.txt "the quick brown fox jumps over the lazy dog\n" |
| 893 | fossil add art.txt |
| 894 | fossil commit -m "add art" --no-warnings |
| 895 | set cgiArt [fossil sql \ |
| 896 | "SELECT uuid FROM blob WHERE rid=(SELECT max(rid) FROM blob)"] |
| 897 | proc cgi_raw_type {mime} { |
| 898 | global cgiArt |
| 899 | set reply [cgi_send [request_get /raw/$cgiArt?m=$mime \ |
| 900 | [list "Accept-Encoding: gzip"]] --ipaddr 127.0.0.1 --localauth] |
| 901 | return [reply_header $reply Content-Encoding] |
| 902 | } |
| 903 | foreach {cgiName cgiMime} { |
| 904 | javascript application/javascript |
| 905 | json application/json |
| 906 | wasm application/wasm |
| 907 | xtcl application/x-tcl |
| 908 | xtar application/x-tar |
| 909 | appxml application/customxml |
| 910 | } { |
| 911 | test_eq cgi-raw-gzip-$cgiName [cgi_raw_type $cgiMime] gzip |
| 912 | } |
| 913 | # A type outside the compressible set is sent as-is. |
| 914 | test_eq cgi-raw-no-gzip [cgi_raw_type application/octet-stream] - |
| 915 | ############################################################################### |
| 916 | # More content types. A type that begins with "a" but is no[string math "*max-age=Range: bytes=4-8"]] --ipaddr 9.9.9.9] |
| 917 | test_eq cgi-range-artifact [reply_body $cgiReply] quick |
| 918 | test_eq cgi-range-artifact-cache [reply_header $cgiReply Cache-Control] \ |
| 919 | "max-age=315360000, immutable" |
| 920 | |
| 921 | ############################################################################### |
| 922 | # The "at" parameter of /raw names the file for the client to save the |
| 923 | # content in. Only its last path element is used, and every character |
| 924 | # in it other than a letter, a digit, "." and "-" becomes "_". |
| 925 | |
| 926 | set cgiReply [cgi_send [request_get \ |
| 927 | "/raw/$cgiArt?at=some/dir/my%20file-1%3B.txt"] \ |
| 928 | --ipaddr 127.0.0.1 --localauth] |
| 929 | test_eq cgi-attachment-name [reply_header $cgiReply Content-Disposition] \ |
| 930 | {attachment; filename="my_file-1_.txt";} |
| 931 | |
| 932 | ############################################################################### |
| 933 | # A request that is refused before any repository is open: the server is |
| 934 | # given a directory, and the request has a method it does not know. |
| 935 | |
| 936 | file mkdir norepo |
| 937 | write_file request.txt "DELETE /x HTTP/1.1\r\nHost: x\r\n\r\n" |
| 938 | file delete reply.txt |
| 939 | fossil_raw http [file join [pwd] norepo] --in request.txt --out reply.txt \ |
| 940 | --ipaddr 127.0.0.1 |
| 941 | test cgi-no-repository-bad-method {$CODE == 0 |
| 942 | && [reply_status [read_file reply.txt]] eq "HTTP/1.0 400 Bad Request"} |
| 943 | |
| 944 | ################## |
| 945 | write_fil/test-env?traced=2] |
| 946 | eferer that is the base URL and |
| 947 | # nothing more is the same origin. |
| 948 | |
| 949 | test_eq cgi-origin-exact [cgi_origin http://x] "Same origin" |
| 950 | |
| 951 | ############################################################################### |
| 952 | # With --httptrace the server reports each parameter as it is set and |
| 953 | # copies the request into a file named httplog-NNNNN.txt in the current |
| 954 | # directory. If it cannot make that file it says so and goes on. |
| 955 | |
| 956 | foreach cgiLog [glob -nocomplain httplog-*.txt] { file delete $cgiLog } |
| 957 | write_file request.txt [request_get /test-env?traced=2] |
| 958 | file delete reply.txt |
| 959 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 960 | --ipaddr 127.0.0.1 --localauth --httptrace |
| 961 | set cgiLogs [glob -nocomplain httplog-*.txt] |
| 962 | test cgi-httptrace {$CODE == 0 && |
| 963 | [holds_strings $RESULT [list "# cgi: traced = \[2\]" \ |
| 964 | "# open log on httplog-"]] && [llength $cgiLogs] == 1} |
| 965 | if {[llength $cgiLogs] == 1} { |
| 966 | set cgiLogText [read_file [lindex $cgiLogs 0]] |
| 967 | test cgi-httptrace-log { |
| 968 | [string match "GET /test-env?traced=2 HTTP/1.1*Host: x*" $cgiLogText]} |
| 969 | file delete [lindex $cgiLogs 0] |
| 970 | } |
| 971 | # The file holds the header and the content of a POST. |
| 972 | write_file request.txt [cgi_post application/x-www-form-urlencoded "body=sent"] |
| 973 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 974 | --ipaddr 127.0.0.1 --localauth --httptrace |
| 975 | set cgiLogs [glob -nocomplain httplog-*.txt] |
| 976 | set cgiLogText "" |
| 977 | foreach cgiLog $cgiLogs { |
| 978 | append cgiLogText [read_file $cgiLog] |
| 979 | file delete $cgiLog |
| 980 | } |
| 981 | test cgi-httptrace-post-content {[string match "*body=sent" $cgiLogText]} |
| 982 | test cgi-httptrace-post-header \ |
| 983 | {[string match "POST /test-env HTTP/1.1*" $cgiLogText]} $::trunkMark |
| 984 | write_file request.txt [request_get /test-env?traced=2] |
| 985 | if {$::tcl_platform(platform) eq "unix"} { |
| 986 | set cgiHere [pwd] |
| 987 | file mkdir readonly |
| 988 | file attributes readonly -permissions 0555 |
| 989 | cd readonly |
| 990 | fossil_raw http $cgiRepo --in [file join $cgiHere request.txt] \ |
| 991 | --out [file join $cgiHere reply.txt] \ |
| 992 | --ipaddr 127.0.0.1 --localauth --httptrace |
| 993 | cd $cgiHere |
| 994 | file attributes readonly -permissions 0755 |
| 995 | test cgi-httptrace-no-log {$CODE == 0 |
| 996 | && [string first "# failed to open httplog-" $RESULT] >= 0 |
| 997 | && [reply_status [read_file reply.txt]] eq "HTTP/1.0 200 OK"} |
| 998 | } |
| 999 | |
| 1000 | ############################################################################### |
| 1001 | # A request for the top of the site is sent on to the index page. A |
| 1002 | # login-card cookie in such a request is taken once. |
| 1003 | |
| 1004 | set cgiReply [cgi_admin [request_get / [list "Cookie: x-f-l-c=card-value"]]] |
| 1005 | test_eq cgi-login-card-home [reply_header $cgiReply Location] http://x/index |
| 1006 | |
| 1007 | ############################################################################### |
| 1008 | # The honeypot page offers a visitor who is not logged in a captcha, and |
| 1009 | # keeps the URL that was asked for, with its query parameters, in a |
| 1010 | # cookie. |
| 1011 | |
| 1012 | set cgiReply [cgi_send [request_get "/honeypot?a=1&b&c=two"] --ipaddr 9.9.9.9] |
| 1013 | test cgi-original-url {[string first \ |
| 1014 | "Set-Cookie: fossil-goto=http%3A%2F%2Fx%2Fhoneypot%3Fa%3D1%26b%26c%3Dtwo;" \ |
| 1015 | $cgiReply] >= 0} |
| 1016 | |
| 1017 | ############################################################################### |
| 1018 | # The "ss" parameter of /timeline is checked for an attack as soon as it |
| 1019 | # is read, for a visitor who is not logged in. |
| 1020 | |
| 1021 | write_file request.txt [request_get "/timeline?ss=1;select"] |
| 1022 | file delete reply.txt attack.log |
| 1023 | fossil_raw http $cgiRepo --in request.txt --out reply.txt \ |
| 1024 | --ipaddr 9.9.9.9 --errorlog [file join [pwd] attack.log] |
| 1025 | test cgi-attack-read-parameter { |
| 1026 | [reply_status [read_file reply.txt]] eq "HTTP/1.0 418 I'm a teapot" |
| 1027 | && [string match "*418 response on \"ss\"*" [read_file attack.log]]} |
| 1028 | set cgiReply [cgi_admin [request_get "/timeline?ss=m"]] |
| 1029 | test_eq cgi-attack-read-parameter-admin [reply_status $cgiReply] \ |
| 1030 | "HTTP/1.0 200 OK" |
| 1031 | |
| 1032 | ############################################################################### |
| 1033 | # SSH_CONNECTION names the client only when it holds an address followed |
| 1034 | # by a space. Otherwise the request is read as plain HTTP from an |
| 1035 | # unknown address, which --localauth does not log in. |
| 1036 | |
| 1037 | foreach {cgiName cgiValue} {empty "" one-word nospace} { |
| 1038 | set ::env(SSH_CONNECTION) $cgiValue |
| 1039 | set cgiReply [cgi_send [request_get /test-env] --localauth] |
| 1040 | unset ::env(SSH_CONNECTION) |
| 1041 | test_eq cgi-ssh-connection-$cgiName [reply_header $cgiReply Location] \ |
| 1042 | http://x/login?g=test-env |
| 1043 | } |
| 1044 | |
| 1045 | ############################################################################### |
| 1046 | # SCGI: SCRIPT_NAME, PATH_INFO and REQUEST_URI. The server needs |
| 1047 | # SCRIPT_NAME, or both of the others to work it out from; and one of |
| 1048 | # PATH_INFO and REQUEST_URI, from which it works out the other. If |
| 1049 | # SCRIPT_NAME is not the start of REQUEST_URI, it is cut down to the |
| 1050 | # part that is. |
| 1051 | |
| 1052 | # The reply to an SCGI request with the name and value PAIRS added to |
| 1053 | # the usual ones: the status and the error for a request that is |
| 1054 | # refused, or else the status and what /test-env shows for SCRIPT_NAME, |
| 1055 | # PATH_INFO and REQUEST_URI. |
| 1056 | proc cgi_scgi_names {pairs} { |
| 1057 | set reply [cgi_send [cgi_scgi [concat { |
| 1058 | CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SERVER_NAME x SERVER_PORT 80 |
| 1059 | REMOTE_ADDR 127.0.0.1 |
| 1060 | } $pairs]] --scgi --localauth] |
| 1061 | set status [lindex [reply_status $reply] 1] |
| 1062 | if {$status eq "400"} { |
| 1063 | return [list 400 [string trim [reply_body $reply]]] |
| 1064 | } |
| 1065 | if {$status ne "200"} { return $status } |
| 1066 | return [list 200 [cgi_param $reply SCRIPT_NAME] [cgi_param $reply PATH_INFO] \ |
| 1067 | [cgi_param $reply REQUEST_URI]] |
| 1068 | } |
| 1069 | foreach {cgiName cgiPairs cgiWant} { |
| 1070 | nothing |
| 1071 | {} |
| 1072 | {400 {Bad SCGI Request: missing SCRIPT_NAME}} |
| 1073 | uri-only |
| 1074 | {REQUEST_URI /test-env} |
| 1075 | {400 {Bad SCGI Request: missing SCRIPT_NAME}} |
| 1076 | path-only |
| 1077 | {PATH_INFO /test-env} |
| 1078 | {400 {Bad SCGI Request: missing SCRIPT_NAME}} |
| 1079 | path-not-in-uri |
| 1080 | {REQUEST_URI /abc PATH_INFO /test-env} |
| 1081 | {400 {Bad SCGI Request: PATH_INFO not found in REQUEST_URI}} |
| 1082 | script-from-uri-and-path |
| 1083 | {REQUEST_URI /pre/test-env PATH_INFO /test-env} |
| 1084 | {200 /pre /test-env /pre/test-env} |
| 1085 | script-only |
| 1086 | {SCRIPT_NAME {}} |
| 1087 | {400 {Bad SCGI Request: missing PATH_INFO and/or REQUEST_URI}} |
| 1088 | uri-from-path |
| 1089 | {SCRIPT_NAME {} PATH_INFO /test-env} |
| 1090 | {200 {} /test-env /test-env} |
| 1091 | uri-from-path-empty-query |
| 1092 | {SCRIPT_NAME {} PATH_INFO /test-env QUERY_STRING {}} |
| 1093 | {200 {} /test-env /test-env} |
| 1094 | uri-from-path-and-query |
| 1095 | {SCRIPT_NAME {} PATH_INFO /test-env QUERY_STRING s=1} |
| 1096 | {200 {} /test-env /test-env?s=1} |
| 1097 | uri-from-path-no-slash |
| 1098 | {SCRIPT_NAME /pre PATH_INFO test-env/x} |
| 1099 | 404 |
| 1100 | path-from-uri |
| 1101 | {SCRIPT_NAME {} REQUEST_URI /test-env} |
| 1102 | {200 {} /test-env /test-env} |
| 1103 | path-from-uri-with-query |
| 1104 | {SCRIPT_NAME {} REQUEST_URI /test-env?s=1 QUERY_STRING s=1} |
| 1105 | {200 {} /test-env /test-env?s=1} |
| 1106 | script-cut-down |
| 1107 | {SCRIPT_NAME /abcd REQUEST_URI /abc/test-env} |
| 1108 | {200 /abc /test-env /abc/test-env} |
| 1109 | uri-is-script |
| 1110 | {SCRIPT_NAME /abc REQUEST_URI /abc} |
| 1111 | 302 |
| 1112 | } { |
| 1113 | test_eq cgi-scgi-names-$cgiName [cgi_scgi_names $cgiPairs] $cgiWant |
| 1114 | } |
| 1115 | foreach {cgiName cgiRequest cgiError} [list \ |
| 1116 | empty "" "SCGI header too short" \ |
| 1117 | length-only "20" "cannot read entire SCGI header" \ |
| 1118 | ] { |
| 1119 | set cgiReply [cgi_send $cgiRequest --scgi] |
| 1120 | test cgi-scgi-$cgiName {$CODE == 0 |
| 1121 | && [reply_status $cgiReply] eq "HTTP/1.0 400 Bad Request" |
| 1122 | && [string match "*$cgiError*" $cgiReply]} |
| 1123 | } |
| 1124 | |
| 1125 | ############################################################################### |
| 1126 | # Page aliases. An alias in the configuration names a page and query |
| 1127 | # parameters for it: "NAME=VALUE" sets a parameter, replacing one of the |
| 1128 | # same name in the request; a name in capitals is taken in lower case; |
| 1129 | # "NAME!" removes a parameter of the request. |
| 1130 | |
| 1131 | fossil sql \ |
| 1132 | "REPLACE INTO config(name,value,mtime) VALUES('walias:/cgialias','/test-env?a=new&Bb=2&gone!&absent!&fresh',0)" |
| 1133 | fossil sql \ |
| 1134 | [join [list \ |
| 1135 | "REPLACE INTO config(name,value,mtime) " \ |
| 1136 | "VALUES('walias:/cgialias2','/test-env?zz!',0)"] ""] |
| 1137 | set cgiReply [cgi_admin [request_get "/cgialias?a=old&gone=1&keep=3"]] |
| 1138 | test_eq cgi-alias-replace [cgi_param $cgiReply a] new |
| 1139 | test_eq cgi-alias-upper [cgi_param $cgiReply bb] 2 |
| 1140 | test_eq cgi-alias-delete [cgi_param $cgiReply gone] - |
| 1141 | test_eq cgi-alias-add [cgi_param $cgiReply fresh] "" |
| 1142 | test_eq cgi-alias-keep [cgi_param $cgiReply keep] 3 |
| 1143 | set cgiReply [cgi_admin [request_get "/cgialias2?m=1&zz=9"]] |
| 1144 | test {cgi-alias-delete-last} {[cgi_param $cgiReply zz] eq "-" |
| 1145 | && [cgi_param $cgiReply m] eq "1"} |
| 1146 | |
| 1147 | ############################################################################### |
| 1148 | # The configuration page saves the text given for the main menu, unless |
| 1149 | # the request also asks for the menu to be reset: then the saved menu is |
| 1150 | # removed and the text is not looked at. |
| 1151 | |
| 1152 | proc cgi_menu_post {fields} { |
| 1153 | global cgiToken |
| 1154 | set body "$fields&csrf=$cgiToken" |
| 1155 | set reply [cgi_admin [cgi_post_from http://x/setup_config /setup_config \ |
| 1156 | $body]] |
| 1157 | return [list [lindex [reply_status $reply] 1] \ |
| 1158 | [fossil sql "SELECT value FROM config WHERE name='mainmenu'"]] |
| 1159 | } |
| 1160 | test_eq cgi-menu-saved [cgi_menu_post "mmenu=cgi-menu-text&zlast=1"] \ |
| 1161 | {200 cgi-menu-text} |
| 1162 | test_eq cgi-menu-reset [cgi_menu_post "mmenu=other-text&resetMenu=1&zlast=1"] \ |
| 1163 | {200 {}} |
| 1164 | test_eq cgi-menu-reset-alone [cgi_menu_post "resetMenu=1"] {200 {}} |
| 1165 | |
| 1166 | ############################################################################### |
| 1167 | # More of the trimmed, boolean and "checked" readers on the subscription |
| 1168 | # page. A name that is missing or all spaces is no name; a line end of |
| 1169 | # CR LF inside a name becomes LF, and a CR alone is kept. A box with an |
| 1170 | # empty value is on, and one with the value "off" is off. |
| 1171 | |
| 1172 | proc cgi_subscribe {email fields} { |
| 1173 | global cgiToken |
| 1174 | set body "submit=1&e=$email&$fields&csrf=$cgiToken" |
| 1175 | cgi_admin [cgi_post_from http://x/subscribe /subscribe $body] |
| 1176 | return [fossil sql \ |
| 1177 | "SELECT hex(suname), ssub FROM subscriber WHERE semail='$email'"] |
| 1178 | } |
| 1179 | test_eq cgi-subscribe-no-name [cgi_ |
| 1180 | } \ |
| 1181 | too-short "15:aracter. |
| 1182 | set cgiGI Request from \"TestServer/1\": missing CONTENT_LENGTH*" \ |
| 1183 | $cgiReply]} |
| 1184 | set cgiReply [cgi_cgi {SCRIPT_NAME /s PATH_INFO /test-env REMOTE_ADDR 127.0.0.1 |
| 1185 | HTTP_HOST x HTTP_REFERER http://x/s/prev}] |
| 1186 | test_eq cgi-cgi-no-method [cgi_csrf_level $cgiReply] "Same origin" |
| 1187 | |
| 1188 | # A control file that names a debug file which cannot be opened is used |
| 1189 | # all the same. |
| 1190 | write_file cgi3.ctl \ |
| 1191 | [join [list \ |
| 1192 | "repository: [file nativename $cgiRepo]\nlocalauth\n" \ |
| 1193 | "cgi-debug: [file join [pwd] nosuchdir debug.txt]\n"] ""] |
| 1194 | set ::env(REQUEST_METHOD) GET |
| 1195 | set ::env(SCRIPT_NAME) /s |
| 1196 | set ::env(PATH_INFO) /test-env |
| 1197 | set ::env(QUERY_STRING) "nodebug=1" |
| 1198 | set ::env(REMOTE_ADDR) 127.0.0.1 |
| 1199 | fossil_raw cgi cgi3.ctl |
| 1200 | foreach cgiVar {REQUEST_METHOD SCRIPT_NAME PATH_INFO QUERY_STRING REMOTE_ADDR} { |
| 1201 | unset ::env($cgiVar) |
| 1202 | } |
| 1203 | test cgi-debug-file-unopened {$CODE == 0 |
| 1204 | && [string match "Status: 200 OK*" $RESULT] |
| 1205 | && [cgi_param $RESULT nodebug] eq "1"} |
| 1206 | |
| 1207 | ############################################################################### |
| 1208 | # The JSON interface, where Fossil has it. Content that is not a JSON |
| 1209 | # object is refused with error FOSSIL-1101. Content of a type that is |
| 1210 | # not JSON is not read as JSON. A request that the web server marks |
| 1211 | # "no_json" is not prepared as a JSON request when it is read. |
| 1212 | |
| 1213 | fothat is reused" |
| 1214 | } else { |
| 1215 | test |
| 1216 | # The value of par# |
| 1217 | # How a server reads a reque$cgiReply]} |
| 1218 | foreach {cgiName cgiMoreequest_get /timeline?r=More cgiError} [list \ |
| 1219 | cut-short "\n" "incorrect transport_flip" \ |
| 1220 | not-blank "\nxyz\n" "transport_flip failed" \ |
| 1221 | other-command "\n\nother\n" "transport_open failed" \ |
| 1222 | no-request "\n\nfossil\n" "missing HTTP header" \ |
| 1223 | ] { |
| 1224 | set cgiReply [cgi_send $cgiFirst$cgiMore --localauth] |
| 1225 | test cgi-ssh-flip-$cgiName {$CODE == 0 |
| 1226 | && [string match "*first = 1*400 Bad Request*$cgiError*" $cgiReply]} |
| 1227 | } |
| 1228 | # With nothing after the two blank lines the connection is over. |
| 1229 | set cgiReply [cgi_send "$cgiFirst\n\n" --localauth] |
| 1230 | test cgi-ssh-flip-end {$CODE == 0 && [string match "*first = 1*" $cgiReply] |
| 1231 | && ![string match "*400 Bad Request*" $cgiReply]} |
| 1232 | foreach {cgiName cgiRequest cgiError} [list \ |
| 1233 | probes-only "echo test1\nfossil\n" "missing HTTP header" \ |
| 1234 | blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1235 | "unsupported HTTP method" \ |
| 1236 | empty-command \ |
| 1237 | [join [list \ |
| 1238 | "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\n" \ |
| 1239 | "Host: x\r\n\r\n\n\nfossil\n"] ""] \ |
| 1240 | "transport_open failed" \ |
| 1241 | repository-only "GET $cgiRepo HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1242 | "malformed URL in HTTP header" \ |
| 1243 | ] { |
| 1244 | set cgiReply [cgi_send $cgiRequest --localauth] |
| 1245 | test cgi-ssh-$cgiName {$CODE == 0 |
| 1246 | && [string match "*400 Bad Request*$cgiError*" $cgiReply]} |
| 1247 | } |
| 1248 | set cgiReply [cgi_send [request_get $cgiRepo/test-env?named=1] --localauth] |
| 1249 | test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1" |
| 1250 | && [cgi_param $cgiReply PATH_INFO] eq "/test-env"} |
| 1251 | # The name is taken off only when a "/" or the end follows it, and only |
| 1252 | # for GET. |
| 1253 | set cgiReply [cgi_send [request_get ${cgiRepo}x/test-env] --localauth] |
| 1254 | test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] - |
| 1255 | set cgiReply [cgi_send [request_get $cgiRepo/test-env \ |
| 1256 | [list "Content-Length: 0"] \ |
| 1257 | POST] --localauth] |
| 1258 | test_eq cgi-ssLater; the third |
| 1259 | # is a GET with no Content-Length and must be served with a length of 0nnection is over. |
| 1260 | set cgiReply [cgi_send "$cgiFirst\n\n" --localauth] |
| 1261 | test cgi-ssh-flip-end {$CODE == 0 && [string match "*first = 1*" $cgiReply] |
| 1262 | && ![string match "*400 Bad Request*" $cgiReply]} |
| 1263 | foreach {cgiName cgiRequest cgiError} [list \ |
| 1264 | probes-only "echo test1\nfossil\n" "missing HTTP header" \ |
| 1265 | blank-first "\nGET /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1266 | "unsuppoThird "GET /test-env?c=3 HTTP/1.1\r\nHost: x\r\n\r\n"[string match "*first = $cgiFirst$cgiSecond$cgiThirTP method" \ |
| 1267 | empty-command \ |
| 1268 | [join [list \ |
| 1269 | "echo test1\n\nGET /test-env?first=1 HTTP/1.1\r\n" \ |
| 1270 | "Host: x\r\n\r\n\n\nfossCONTENT_LENGTH = 0*c = 3 "transport_open fai |
| 1271 | unset ::env(SSH_CONNECTION) |
| 1272 | |
| 1273 | #######################################################Asoon as it |
| 1274 | # is read, for a v test cgi-ssh-$cgiName {$CODE == 0 |
| 1275 | && [string match "*400 Bad Request*$cgiError*" $cgiReply]} |
| 1276 | } |
| 1277 | set cgiReply [cgi_send [request_get $cgiRepo/test-env?named=1] --localauth] |
| 1278 | test cgi-ssh-repository-in-url {[cgi_param $cgiReply named] eq "1" |
| 1279 | && [cgi_param $cgiReply PATH_INFO] eq "/test-env"} |
| 1280 | # The name is taken off only when a "/" or the end follows it, and only |
| 1281 | # for GET. |
| 1282 | set cgiReply [cgi_send [request_get ${cgiRepo}x/test-env] --localauth] |
| 1283 | test_eq cgi-ssh-repository-longer [cgi_param $cgiReply PATH_INFO] - |
| 1284 | set cgiReply [cgi_send [request_get $cgiRepo/test-env \ |
| 1285 | [list "Content-Length: 0"] \ |
| 1286 | POST] --localauth] |
| 1287 | test_eq cgi-ssh-repository-post [cgi_param $cgiReply PATH_INFO] - |
| 1288 | # Two requests on one ssh connection: the second sends Content-Length |
| 1289 | # before a longer header line and must get its length and body. |
| 1290 | # knownBug: the second request's Content-Length is read from memory that |
| 1291 | # a later header line overwrites. |
| 1292 | set cgiFirst \ |
| 1293 | [join [list \ |
| 1294 | "POST /test-env HTTP/1.1\r\nX-Fossil-Transport: SSH\r\n" \ |
| 1295 | "Content-Type: application/x-www-form-urlencoded\r\n" \ |
| 1296 | "Content-Length: 3\r\n\r\na=1"] ""] |
| 1297 | set cgiSecond \ |
| 1298 | [join [list \ |
| 1299 | "POST /test-env HTTP/1.1\r\nContent-Length: 3\r\n" \ |
| 1300 | "Content-Type: " \ |
| 1301 | "application/x-www-form-urlencoded-and-more\r\n\r\nb=2"] ""] |
| 1302 | set cgiReply [cgi_send $cgiFirst$cgiSecond --localauth] |
| 1303 | test cgi-ssh-later-content-length {$CODE == 0 && [string match \ |
| 1304 | [join [list \ |
| 1305 | "*CONTENT_LENGTH = 3*a = 1*CONTENT_LENGTH = 3*b = " \ |
| 1306 | "2*"] ""] \ |
| 1307 | [regsub -all {<[^>]*>} $cgiReply {}]]} knownBug |
| 1308 | unset ::env(SSH_CONNECTION) |
| 1309 | |
| 1310 | ############################################################################### |
| 1311 | # A visitor who is not logged in reaches a page that is closed to robots |
| 1312 | # with a token, and gets a cookie that opens the page afterwards. The |
| 1313 | # same value given as a query parameter does not. |
| 1314 | |
| 1315 | fossil sql \ |
| 1316 | [join [list \ |
| 1317 | "REPLACE INTO config(name,value,mtime) " \ |
| 1318 | "VALUES('robot-restrict','timeline',0)"] ""] |
| 1319 | fossil sql \ |
| 1320 | [join [list \ |
| 1321 | "REPLACE INTO config(name,value,mtime) " \ |
| 1322 | "VALUES('token-cgitoken','{\"user\":\"someone\"}',0)"] ""] |
| 1323 | proc cgi_robot {path {cookie ""}} { |
| 1324 | set headers [list "User-Agent: Agent/1"] |
| 1325 | if {$cookie ne ""} { lappend headers "Cookie: $cookie" } |
| 1326 | return [cgi_send [request_get $path $headers] --ipaddr 9.9.9.9] |
| 1327 | } |
| 1328 | set cgiRobot "*Checking to see if you are a robot*" |
| 1329 | test cgi-robot-stopped {[string match $cgiRobot [cgi_robot /timeline]]} |
| 1330 | set cgiReply [cgi_robot /timeline?token=cgitoken] |
| 1331 | set cgiProof "" |
| 1332 | regexp {Set-Cookie: fossil-client-ok=(\d+);} $cgiReply all cgiProof |
| 1333 | test cgi-robot-token {$cgiProof ne "" && ![string match $cgiRobot $cgiReply]} |
| 1334 | test cgi-robot-cookie {![string match $cgiRobot \ |
| 1335 | [cgi_robot /timeline fossil-client-ok=$cgiProof]]} |
| 1336 | test cgi-robot-query-parameter {[string match $cgiRobot \ |
| 1337 | [cgi_robot /timeline?fossil-client-ok=$cgiProof]]} |
| 1338 | # A parameter that failed as proof is left out of the links of the page |
| 1339 | # that a good token opens. |
| 1340 | set cgiReply [cgi_robot "/timeline?proof=1&token=cgitoken&n=1"] |
| 1341 | test cgi-robot-failed-proof-dropped { |
| 1342 | [string match "*timeline?*token=cgitoken*" $cgiReply] |
| 1343 | && ![string match "*proof=1*" $cgiReply]} |
| 1344 | fossil sql "DELETE FROM config WHERE name='robot-restrict'" |
| 1345 | |
| 1346 | ############################################################################### |
| 1347 | # A forum thread is shown in order of time to a phone and as a hierarchy |
| 1348 | # to anything else, an iPad included. The page offers the other order. |
| 1349 | |
| 1350 | set cgiFd [open post.txt wb] |
| 1351 | puts -nonewline $cgiFd \ |
| 1352 | "D 2026-01-04T10:00:01.000\nH Cgi\\sthread\nU alice\nW 5\nhello\n" |
| 1353 | close $cgiFd |
| 1354 | fossil md5sum post.txt |
| 1355 | set cgiSum [lindex $RESULT 0] |
| 1356 | set cgiFd [open post.txt ab] |
| 1357 | puts -nonewline $cgiFd "Z $cgiSum\n" |
| 1358 | close $cgiFd |
| 1359 | fossil test-content-put --crosslink post.txt |
| 1360 | set cgiPost [fossil sql \ |
| 1361 | "SELECT uuid FROM blob WHERE rid=(SELECT fpid FROM forumpost LIMIT 1)"] |
| 1362 | foreach {cgiName cgiAgent cgiOther} { |
| 1363 | phone "Mozilla/5.0 (iPhone; Mobile) Safari" Hierarchical |
| 1364 | ipad "Mozilla/5.0 (iPad; Mobile) Safari" Chronological |
| 1365 | desk "Mozilla/5.0 (X11; Linux)" Chronological |
| 1366 | none "" Chronological |
| 1367 | } { |
| 1368 | set cgiHeaders {} |
| 1369 | if {$cgiAgent ne ""} { lappend cgiHeaders "User-Agent: $cgiAgent" } |
| 1370 | set cgiReply [cgi_admin [request_get /forumthread/$cgiPost?t=a $cgiHeaders]] |
| 1371 | test cgi-forum-order-$cgiName {[string match "*>Cgi thread<*" $cgiReply] |
| 1372 | && [string match "*?t=?\">$cgiOther</a>*" $cgiReply]} |
| 1373 | } |
| 1374 | |
| 1375 | ############################################################################### |
| 1376 | # Logging in without "remember me" gives a cookie that lasts for the |
| 1377 | # session: it has no age. |
| 1378 | |
| 1379 | fossil user new cgiuser contact userpw |
| 1380 | fossil user capabilities cgiuser o |
| 1381 | proc cgi_login {fields} { |
| 1382 | set body "u=cgiuser&p=userpw&in=Login&$fields" |
| 1383 | return [cgi_send [cgi_post_from http://x/login /login $body] --ipaddr 9.9.9.9] |
| 1384 | } |
| 1385 | set cgiCookie [reply_header [cgi_login x=1] Set-Cookie] |
| 1386 | test cgi-login-session-cookie \ |
| 1387 | {[string match "fossil-*=*cgiuser; Path=*; HttpOnly;*" $cgiCookie] |
| 1388 | && ![string match "*max-age*" $cgiCookie]} |
| 1389 | set cgiCookie [reply_header [cgi_login remember=1] Set-Cookie] |
| 1390 | test cgi-login-lasting-cookie \ |
| 1391 | {[string match "fossil-*=*cgiuser; Path=*; max-age=*" $cgiCookie]} |
| 1392 | |
| 1393 | ############################################################################### |
| 1394 | # A program under /ext that gives a status of 0 gets the usual "200 OK". |
| 1395 | |
| 1396 | if {$::tcl_platform(platform) eq "unix"} { |
| 1397 | file mkdir extroot |
| 1398 | write_file extroot/status0.sh \ |
| 1399 | [join [list \ |
| 1400 | "#!/bin/sh\n" \ |
| 1401 | "printf 'Status: 0 Nothing\\r\\nContent-Type: " \ |
| 1402 | "text/plain\\r\\n\\r\\nfrom the program\\n'\n"] ""] |
| 1403 | file attributes extroot/status0.sh -permissions 0755 |
| 1404 | set cgiReply [cgi_admin [request_get /ext/status0.sh] \ |
| 1405 | --extroot [file join [pwd] extroot]] |
| 1406 | test cgi-ext-status-zero {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1407 | && [string match "*from the program*" $cgiReply] |
| 1408 | && ![string match "*printf*" $cgiReply]} |
| 1409 | } |
| 1410 | |
| 1411 | ############################################################################### |
| 1412 | # A CGI control file that names no repository gets "500", and so does a |
| 1413 | # CGI request with no control file at all. A control file with a |
| 1414 | # "redirect: * URL" line sends every request on for good: to URL with |
| 1415 | # the name asked for in place of "%s", to URL as it is if it holds a |
| 1416 | # "?", and otherwise to URL followed by the path and the query. |
| 1417 | |
| 1418 | # Run fossil with the words in ARGS and the environment variables in |
| 1419 | # VARS, a list of names and values, and return what it printed. |
| 1420 | proc cgi_run_with {vars args} { |
| 1421 | global RESULT |
| 1422 | foreach {name value} $vars { set ::env($name) $value } |
| 1423 | fossil_raw {*}$args |
| 1424 | foreach {name value} $vars { unset ::env($name) } |
| 1425 | return $RESULT |
| 1426 | } |
| 1427 | # Run from a directory outside the checkout, as a CGI script would be. |
| 1428 | set cgiDir [file join [file dirname [pwd]] cgi-no-checkout] |
| 1429 | file mkdir $cgiDir |
| 1430 | write_file [file join $cgiDir cgi5.ctl] "#!/usr/bin/fossil\n" |
| 1431 | set cgiHere [pwd] |
| 1432 | cd $cgiDir |
| 1433 | set cgiReply [cgi_run_with {REQUEST_METHOD GET SCRIPT_NAME /s PATH_INFO /home} \ |
| 1434 | cgi cgi5.ctl] |
| 1435 | cd $cgiHere |
| 1436 | file delete -force $cgiDir |
| 1437 | test cgi-cgi-no-repository {$CODE == 1 |
| 1438 | && [string match "Status: 500 Internal Server Error*" $cgiReply] |
| 1439 | && [string match "*Unable to find or open the project repository" \ |
| 1440 | $cgiReply]} |
| 1441 | set cgiReply [cgi_run_with {GATEWAY_INTERFACE CGI/1.1 REQUEST_METHOD GET |
| 1442 | SCRIPT_NAME /s PATH_INFO /home}] |
| 1443 | test cgi-cgi-no-control-file {$CODE == 1 |
| 1444 | && [string match "Status: 500 Internal Server Error*" $cgiReply] |
| 1445 | && [string match "*No CGI control file specified" $cgiReply]} |
| 1446 | foreach {cgiName cgiTarget cgiLocation} { |
| 1447 | name http://other.example/find/%s http://other.example/find/abc |
| 1448 | query http://other.example/find?x=1 http://other.example/find?x=1 |
| 1449 | path http://other.example/base http://other.example/base/abc?q=1 |
| 1450 | } { |
| 1451 | write_file cgi6.ctl "#!/usr/bin/fossil\nredirect: * $cgiTarget\n" |
| 1452 | set cgiReply [cgi_run_with {REQUEST_METHOD GET HTTP_HOST x SCRIPT_NAME /s |
| 1453 | PATH_INFO /abc QUERY_STRING q=1} cgi cgi6.ctl] |
| 1454 | test cgi-cgi-redirect-$cgiName {$CODE == 0 |
| 1455 | && [string match "Status: 301 Moved Permanently*" $cgiReply] |
| 1456 | && [reply_header "$cgiReply\r\n\r\n" Location] eq $cgiLocation} |
| 1457 | } |
| 1458 | |
| 1459 | ######################################################ge warns of a page header that has no "base" element, and |
| 1460 | # does not when the header has one, as the built-in header does. |
| 1461 | |
| 1462 | set cgiReply [cgi_admin [request_get /setup]] |
| 1463 | test cgi-setup-base-present {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1464 | && ![string match "*Configuration Error*" $cgiReply]} |
| 1465 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header', |
| 1466 | '<html><head><title>plain</title></head><body>',now())" |
| 1467 | set cgiReply [cgi_admin [request_get /setup]] |
| 1468 | test cgi-setup-base-missing {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1469 | && [string match "*Configuration Error*base href=*" $cgiReply]} |
| 1470 | |
| 1471 | # The TH1 command "redirect" in a page header sends the client to |
| 1472 | # another page: with "302", or with "307" when its second argument is |
| 1473 | # true, which tells the client to repeat the request as it made it. |
| 1474 | foreach {cgiName cgiScript cgiStatus} { |
| 1475 | plain {redirect /stat} {HTTP/1.0 302 Moved Temporarily} |
| 1476 | method {redirect /stat 1} {HTTP/1.0 307 Temporary Redirect} |
| 1477 | } { |
| 1478 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES('header', |
| 1479 | '<html><head></head><body><th1>$cgiScript</th1>',now())" |
| 1480 | set cgiReply [cgi_admin [request_get /timeline]] |
| 1481 | test cgi-th1-redirect-$cgiName {[reply_status $cgiReply] eq $cgiStatus |
| 1482 | && [reply_header $cgiReply Location] eq "http://x/stat"} |
| 1483 | } |
| 1484 | fossil sql "DELETE FROM config WHERE name='header'" |
| 1485 | |
| 1486 | # The same command run from the command line, where there is no request |
| 1487 | # to answer, is an error. |
| 1488 | foreach {cgiName cgiUrl} {path /stat url http://other.example/x} { |
| 1489 | fossil_raw test-th-eval "redirect $cgiUrl" |
| 1490 | test cgi-th1-redirect-no-request-$cgiName {$CODE == 0 && [string match \ |
| 1491 | "*redirect is only allowed in a web request*" $RESULT]} $::trunkMark |
| 1492 | } |
| 1493 | # With --http the command line makes a reply, and a redirect to a full |
| 1494 | # URL is sent as "302". |
| 1495 | fossil_raw test-th-eval --http "redirect http://other.example/x" |
| 1496 | test cgi-th1-redirect-http-option {$CODE == 0 |
| 1497 | && [string match "HTTP/1.0 302 *" $RESULT] |
| 1498 | && [string match "*\r\nLocation: http://other.example/x\r\n*" $RESULT]} |
| 1499 | |
| 1500 | # The TH1 command "verifyCsrf" from the command line: with no request |
| 1501 | # there is no origin to compare, so it refuses. |
| 1502 | fossil_raw test-th-eval verifyCsrf |
| 1503 | test cgi-th1-verifycsrf-no-request {$CODE == 1 |
| 1504 | && [string match "*possible CSRF attack*" $RESULT]} |
| 1505 | |
| 1506 | ############################################################################### |
| 1507 | # An ad unit for the right-hand side is used on a page that allows one |
| 1508 | # and has no table in its content; a page with a table gets the ad unit |
| 1509 | # for the top of the page. |
| 1510 | |
| 1511 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES |
| 1512 | ('adunit-right','<b>ADRIGHT</b>',now()),('adunit','<b>ADTOP</b>',now())" |
| 1513 | set cgiReply [cgi_admin [request_get /sitemap]] |
| 1514 | test cgi-adunit-right {[string match "*ADRIGHT*" $cgiReply] |
| 1515 | && ![string match "*ADTOP*" $cgiReply]} |
| 1516 | set cgiReply [cgi_admin [request_get /brlist]] |
| 1517 | test cgi-adunit-top-with-table {[string match "*ADTOP*" $cgiReply] |
| 1518 | && ![string match "*ADRIGHT*" $cgiReply]} |
| 1519 | fossil sql "DELETE FROM config WHERE name IN ('adunit-right','adunit')" |
| 1520 | |
| 1521 | ############################################################################### |
| 1522 | # Pages that add a query parameter to the request they were given. |
| 1523 | # /file with no file name lists the files of the check-in "tip", and |
| 1524 | # its links carry "ci=tip". /timeline with "r=BRANCH" shows the branch |
| 1525 | # and what is related to it, and its form keeps that as "t=BRANCH" and |
| 1526 | # "rel". |
| 1527 | |
| 1528 | set cgiReply [cgi_admin [request_get /file]] |
| 1529 | test cgi-file-no-name {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1530 | && [string match "*Top-level Files of tip*" $cgiReply] |
| 1531 | && [string match "*ci=tip*" $cgiReply]} |
| 1532 | set cgiReply [cgi_admin [request_get /timeline?r=trunk]] |
| 1533 | test cgi-timeline-r {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1534 | && [string match "*name=\"rel\" value=\"1\"*" $cgiReply] |
| 1535 | && [string match "*name=\"t\" value=\"trunk\"*" $cgiReply]} |
| 1536 | |
| 1537 | ############################################################################### |
| 1538 | # An unversioned file whose time of change is too far in the future to |
| 1539 | # be written as a date is sent all the same, with an empty Last-Modified |
| 1540 | # header. |
| 1541 | |
| 1542 | write_file late.css "p{}\n" |
| 1543 | fossil uv add late.css |
| 1544 | fossil sql "UPDATE unversioned SET mtime=1000000000000000000 |
| 1545 | WHERE name='late.css'" |
| 1546 | set cgiReply [cgi_send [request_get /uv/late.css] --ipaddr 127.0.0.1] |
| 1547 | test cgi-last-modified-out-of-range { |
| 1548 | [reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1549 | && [string match "*\r\nLast-Modified: \r\n*" $cgiReply] |
| 1550 | && [reply_body $cgiReply] eq "p{}\n"} |
| 1551 | fossil uv rm late.css |
| 1552 | |
| 1553 | ############################################################################### |
| 1554 | # "fossil server" itself, where it listens with its own code (not on |
| 1555 | # Windows). A server that cannot listen where it was told says why and |
| 1556 | # stops. |
| 1557 | |
| 1558 | if {$::tcl_platform(platform) eq "unix" && [loopback_available]} { |
| 1559 | # A port on ADDRESS with a listener on it. Returns the listener and |
| 1560 | # the port. |
| 1561 | proc cgi_busy_port {address} { |
| 1562 | set listener [socket -server {apply {{c a p} {close $c}}} \ |
| 1563 | -myaddr $address 0] |
| 1564 | return [list $listener [lindex [fconfigure $listener -sockname] 2]] |
| 1565 | } |
| 1566 | # A port on 127.0.0.1 that was free a moment ago. |
| 1567 | proc cgi_free_port {} { |
| 1568 | lassign [cgi_busy_port 127.0.0.1] listener port |
| 1569 | close $listener |
| 1570 | return $port |
| 1571 | } |
| 1572 | write_file notsocket "a file\n" |
| 1573 | lassign [cgi_busy_port 127.0.0.1] cgiListener cgiPort |
| 1574 | foreach {cgiName cgiOptions cgiError} [list \ |
| 1575 | bad-ipv4 {--port 999.9.9.9:8111} \ |
| 1576 | "not a valid IPv4 address: 999.9.9.9" \ |
| 1577 | bad-ipv6 {--port {[zz::1]:8111}} \ |
| 1578 | "not a valid IPv6 address: zz::1" \ |
| 1579 | other-ipv4 {--port 192.0.2.1:8111} \ |
| 1580 | "cannot open a listening socket on 192.0.2.1:8111" \ |
| 1581 | other-ipv6 {--port {[2001:db8::1]:8111}} \ |
| 1582 | [join [list \ |
| 1583 | "cannot open a listening socket on " \ |
| 1584 | "\\\[2001:db8::1\\\]:8111"] ""] \ |
| 1585 | port-in-use [list --localhost --port $cgiPort] \ |
| 1586 | "no available TCP ports in the range $cgiPort..$cgiPort" \ |
| 1587 | socket-name-long [list --socket-name [string repeat s 200]] \ |
| 1588 | "name of unix socket too big" \ |
| 1589 | socket-name-taken {--socket-name notsocket} \ |
| 1590 | "cannot name socket \"notsocket\" because another object" \ |
| 1591 | ] { |
| 1592 | fossil_raw -seconds 30 server {*}$cgiOptions $cgiRepo |
| 1593 | test cgi-server-refused-$cgiName {$CODE == 1 |
| 1594 | && [string match "*$cgiError*" $RESULT]} |
| 1595 | } |
| 1596 | close $cgiListener |
| 1597 | |
| 1598 | # Run SCRIPT every ten milliseconds until it returns true, for at most |
| 1599 | # five seconds, and return what it last returned. |
| 1600 | proc cgi_wait {script} { |
| 1601 | for {set i 0} {$i < 500} {incr i} { |
| 1602 | if {[uplevel 1 $script]} {return 1} |
| 1603 | after 10 |
| 1604 | } |
| 1605 | return 0 |
| 1606 | } |
| 1607 | # True if the process PID has not ended. |
| 1608 | proc cgi_running {pid} { |
| 1609 | return [expr {![catch {exec kill -0 $pid}]}] |
| 1610 | } |
| 1611 | # Wait for the server PID to print that it listens, and return true |
| 1612 | # once it has. A server that ends without listening ends the wait. |
| 1613 | proc cgi_listening {pid} { |
| 1614 | cgi_wait {expr {[string match "*Listening for*" [read_file server.out]] |
| 1615 | || ![cgi_running $pid]}} |
| 1616 | return [string match "*Listening for*" [read_file server.out]] |
| 1617 | } |
| 1618 | # Connect to HOST and PORT and return the socket. A server prints |
| 1619 | # that it listens before it accepts connections, so a connection that |
| 1620 | # fails is tried again. |
| 1621 | proc cgi_connect {host port} { |
| 1622 | cgi_wait {expr {![catch {socket $host $port} sock]}} |
| 1623 | fconfigure $sock -translation binary |
| 1624 | return $sock |
| 1625 | } |
| 1626 | # Send REQUEST to HOST and PORT and return the reply, waiting at most |
| 1627 | # ten seconds for the end of it. With "unix" for HOST, PORT is the |
| 1628 | # name of a unix socket, and the program "nc" carries the request. |
| 1629 | proc cgi_client {host port request} { |
| 1630 | if {$host eq "unix"} { |
| 1631 | cgi_wait {expr {![catch {exec nc -w 10 -U $port << $request} reply] |
| 1632 | || ![string match "*refused*" $reply]}} |
| 1633 | return $reply |
| 1634 | } |
| 1635 | set sock [cgi_connect $host $port] |
| 1636 | fconfigure $sock -blocking 0 |
| 1637 | puts -nonewline $sock $request |
| 1638 | flush $sock |
| 1639 | set reply "" |
| 1640 | for {set i 0} {$i < 2000 && ![eof $sock]} {incr i} { |
| 1641 | set part [read $sock] |
| 1642 | append reply $part |
| 1643 | if {$part eq ""} {after 5} |
| 1644 | } |
| 1645 | close $sock |
| 1646 | return $reply |
| 1647 | } |
| 1648 | # Start a server with OPTIONS that answers one request and stops, send |
| 1649 | # it REQUEST at HOST and PORT, and return what the server printed and |
| 1650 | # the reply. The server is killed if it has not stopped by itself. |
| 1651 | # The request is sent IDLE milliseconds after the server starts to |
| 1652 | # listen. |
| 1653 | proc cgi_serve_once {options host port request {command server} {idle 0}} { |
| 1654 | global fossilexe cgiRepo |
| 1655 | file delete server.out |
| 1656 | set pid [exec $fossilexe $command --debug-nofork --localauth {*}$options \ |
| 1657 | $cgiRepo >& server.out &] |
| 1658 | set reply "" |
| 1659 | if {[cgi_listening $pid]} { |
| 1660 | after $idle |
| 1661 | catch {set reply [cgi_client $host $port $request]} |
| 1662 | } |
| 1663 | cgi_wait {expr {![cgi_running $pid]}} |
| 1664 | catch {exec kill -9 $pid} |
| 1665 | return [list [string trim [read_file server.out]] $reply] |
| 1666 | } |
| 1667 | |
| 1668 | # An IPv4 address, by number and as "localhost". |
| 1669 | foreach {cgiName cgiHost} {ipv4 127.0.0.1 localhost localhost} { |
| 1670 | set cgiPort [cgi_free_port] |
| 1671 | lassign [cgi_serve_once [list --port $cgiHost:$cgiPort] 127.0.0.1 \ |
| 1672 | $cgiPort [request_get /test-env]] cgiPrinted cgiReply |
| 1673 | test_eq cgi-server-$cgiName-printed $cgiPrinted \ |
| 1674 | "Listening for HTTP requests on TCP port 127.0.0.1:$cgiPort" |
| 1675 | test cgi-server-$cgiName-reply { |
| 1676 | [reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1677 | && [cgi_param $cgiReply REMOTE_ADDR] eq "127.0.0.1"} |
| 1678 | } |
| 1679 | # "fossil ui" starts the browser on the address it listens on. The |
| 1680 | # browser here is "echo". |
| 1681 | fossil settings web-browser echo |
| 1682 | fossil settings web-browser |
| 1683 | if {[string match "*echo*" $RESULT]} { |
| 1684 | set cgiPort [cgi_free_port] |
| 1685 | lassign [cgi_serve_once [list --port 127.0.0.1:$cgiPort] 127.0.0.1 \ |
| 1686 | $cgiPort [request_get /test-env] ui] cgiPrinted cgiReply |
| 1687 | test cgi-server-ui-browser { |
| 1688 | [string match "*\nhttp://127.0.0.1:$cgiPort/*" \n$cgiPrinted] |
| 1689 | && [reply_status $cgiReply] eq "HTTP/1.0 200 OK"} |
| 1690 | } |
| 1691 | # SCGI in place of HTTP. |
| 1692 | set cgiPort [cgi_free_port] |
| 1693 | lassign [cgi_serve_once [list --scgi --port 127.0.0.1:$cgiPort] 127.0.0.1 \ |
| 1694 | $cgiPort [cgi_scgi { |
| 1695 | CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET SCRIPT_NAME {} |
| 1696 | REQUEST_URI /test-env?viascgi=1 QUERY_STRING viascgi=1 SERVER_NAME x |
| 1697 | SERVER_PORT 80 REMOTE_ADDR 127.0.0.1 |
| 1698 | }]] cgiPrinted cgiReply |
| 1699 | test_eq cgi-server-scgi-printed $cgiPrinted \ |
| 1700 | "Listening for SCGI requests on TCP port 127.0.0.1:$cgiPort" |
| 1701 | test_eq cgi-server-scgi-reply [cgi_param $cgiReply viascgi] 1 |
| 1702 | |
| 1703 | if {![catch {cgi_busy_port ::1} cgiBusy]} { |
| 1704 | close [lindex $cgiBusy 0] |
| 1705 | # An IPv6 address. |
| 1706 | set cgiPort [cgi_free_port] |
| 1707 | lassign [cgi_serve_once [list --port \[::1\]:$cgiPort] ::1 $cgiPort \ |
| 1708 | [request_get /test-env]] cgiPrinted cgiReply |
| 1709 | test_eq cgi-server-ipv6-printed $cgiPrinted \ |
| 1710 | "Listening for HTTP requests on \[::1\]:$cgiPort" |
| 1711 | test cgi-server-ipv6-reply {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1712 | && [cgi_param $cgiReply REMOTE_ADDR] eq "::1"} |
| 1713 | # With no address the server listens on both kinds of loopback |
| 1714 | # address, or on IPv4 alone if the port is taken for IPv6. The |
| 1715 | # server waits a tenth of a second at a time for a connection, and |
| 1716 | # this request leaves it waiting for two of them with none. |
| 1717 | set cgiPort [cgi_free_port] |
| 1718 | lassign [cgi_serve_once [list --localhost --port \[\]:$cgiPort] ::1 \ |
| 1719 | $cgiPort [request_get /test-env] server 200] cgiPrinted cgiReply |
| 1720 | test_eq cgi-server-both-printed $cgiPrinted \ |
| 1721 | [join [list \ |
| 1722 | "Listening for HTTP requests on TCP port " \ |
| 1723 | "localhost:$cgiPort, IPv4 and IPv6"] ""] |
| 1724 | test_eq cgi-server-both-reply [cgi_param $cgiReply REMOTE_ADDR] ::1 |
| 1725 | lassign [cgi_busy_port ::1] cgiListener cgiPort |
| 1726 | lassign [cgi_serve_once [list --localhost --port $cgiPort] 127.0.0.1 \ |
| 1727 | $cgiPort [request_get /test-env]] cgiPrinted cgiReply |
| 1728 | close $cgiListener |
| 1729 | test_eq cgi-server-ipv4-only-printed $cgiPrinted \ |
| 1730 | "Listening for HTTP requests on TCP port localhost:$cgiPort, IPv4 only" |
| 1731 | test_eq cgi-server-ipv4-only-reply [reply_status $cgiReply] \ |
| 1732 | "HTTP/1.0 200 OK" |
| 1733 | # With a port and neither an address nor --localhost the server |
| 1734 | # listens on every address of the machine. |
| 1735 | set cgiPort [cgi_free_port] |
| 1736 | lassign [cgi_serve_once [list --port $cgiPort] 127.0.0.1 \ |
| 1737 | $cgiPort [request_get /login]] cgiPrinted cgiReply |
| 1738 | test_eq cgi-server-any-address-printed $cgiPrinted \ |
| 1739 | "Listening eq $cgiMode} $::trunkMark |
| 1740 | } |
| 1741 | fossil_raw -seconds 30 server --socket-mode rw --socket-name sock3 $cgiRepo |
| 1742 | test cgi-server-unix-mode-not-a-number {$CODE == 1 && [string match \ |
| 1743 | "*cannot change permissions on sock3 to \"rw\"*" $RESULT]} |
| 1744 | } else { |
| 1745 | test_skip_part "no nc program for unix sockets: the unix socket tests" |
| 1746 | } |
| 1747 | |
| 1748 | # A server that gives each request to a process of its own. Start |
| 1749 | # one with OPTIONS, as COMMAND, and return its process id once it |
| 1750 | # listens. What it prints goes to server.out and server.err. WRAP, |
| 1751 | # if given, is a list of words to put before the command. |
| 1752 | proc cgi_serve_start {options {command server} {wrap {}}} { |
| 1753 | global fossilexe cgiRepo |
| 1754 | file delete server.out server.err |
| 1755 | set pid [exec {*}$wrap $fossilexe $command --localauth {*}$options \ |
| 1756 | $cgiRepo > server.out 2> server.err &] |
| 1757 | cgi_listening $pid |
| 1758 | return $pid |
| 1759 | } |
| 1760 | # Stop the server with process id PID: ask it to end, and kill it if |
| 1761 | # it has not ended after five seconds. |
| 1762 | proc cgi_serve_stop {pid} { |
| 1763 | catch {exec kill $pid} |
| 1764 | cgi_wait {expr {![cgi_running $pid]}} |
| 1765 | catch {exec kill -9 $pid} |
| 1766 | } |
| 1767 | # The process ids of the processes that the server PID has started |
| 1768 | # for requests and has not yet found to have ended. |
| 1769 | proc cgi_children {pid} { |
| 1770 | if {[catch {exec pgrep -P $pid} children]} {return {}} |
| 1771 | return $children |
| 1772 | } |
| 1773 | |
| 1774 | # A process that handles a request is killed before the request is |
| 1775 | # complete. The server goes on to answer the next request, and one |
| 1776 | # that traces its work reports the signal that ended the process. |
| 1777 | if {[auto_execok pgrep] ne ""} { |
| 1778 | foreach {cgiName cgiOptions cgiReport} { |
| 1779 | traced --httptrace {*Child * exited on signal 9 *} |
| 1780 | quiet {} {} |
| 1781 | } { |
| 1782 | set cgiPort [cgi_free_port] |
| 1783 | set cgiPid [cgi_serve_start [list --port 127.0.0.1:$cgiPort \ |
| 1784 | {*}$cgiOptions]] |
| 1785 | set cgiReply "" |
| 1786 | catch { |
| 1787 | set cgiSock [cgi_connect 127.0.0.1 $cgiPort] |
| 1788 | puts -nonewline 0 $end] \n] { |
| 1789 | if {[string match -nocase "$name: *" $line]} { |
| 1790 | return [strinrn - } |
| 1791 | incr start [+1 end]] |
| 1792 | } |
| 1793 | } |
| 1794 | return - |
| 1795 | } |
| 1796 | |
| 1797 | # The content of a reply: what follows its heade |
| 1798 | set end [string first "\r\n\r\n" $replyirst " <br>" $reply $start"" } |
| 1799 | return [string range $reply $end+4 end] |
| 1800 | } |
| 1801 | |
| 1802 | # A GE header lines in HEADERS, a list. |
| 1803 | proc cgi_post {type body {path /test-env} {headers {}}} { |
| 1804 | return [request_post $path $body $headers $type] |
| 1805 | } |
| 1806 | |
| 1807 | # A POST of the form data BODY to PATH, sent from the page REFERER. |
| 1808 | proc cgi_post_from {referer path body} { |
| 1809 | return [cgi_post application/x-www-form-urlencoded $body $path \ |
| 1810 | [list "Referer: $referer"]] |
| 1811 | } |
| 1812 | |
| 1813 | ############################################################################### |
| 1814 | # Plain HTTP. |
| 1815 | |
| 1816 | set cgiReply [cgi_admin \ |
| 1817 | "GET /test-env?a=1&b=two+words&c=%41%42&d=&e HTTP/1.1\r\nHost: x\r\n\r\n"] |
| 1818 | test cgi-get {$CODE == 0} |
| 1819 | test_eq cgi-get-status [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 1820 | test_eq cgi-get-plain [cgi_param $cgiReply a] 1 |
| 1821 | test_eq cgi-get-plus [cgi_param $cgiReply b] "two words" |
| 1822 | test_eq cgi-get-escape [cgi_param $cgiReply c] AB |
| 1823 | test_eq cgi-get-empty [cgi_param $cgiReply d] "" |
| 1824 | test_eq cgi-get-no-value [cgi_param $cgiReply e] "" |
| 1825 | |
| 1826 | set cgiReply [cgi_admin [cgi_post application/x-www-form-urlencoded \ |
| 1827 | "x=1&y=a%20b&Z=upper"]] |
| 1828 | test_eq cgi-post-form [cgi_param $cgiReply x] 1 |
| 1829 | test_eq cgi-post-form-escape [cgi_param $cgiReply y] "a b" |
| 1830 | test_eq cgi-post-form-upper [cgi_param $cgiReply z] upper |
| 1831 | |
| 1832 | foreach {cgiName cgiRequest} [list \ |
| 1833 | no-method "\r\n\r\n" \ |
| 1834 | bad-method "DELETE /test-env HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1835 | ] { |
| 1836 | set cgiReply [cgi_send $cgiRequest --ipaddr 127.0.0.1] |
| 1837 | test cgi-malformed-$cgiName \ |
| 1838 | {[string match "HTTP/1.0 40*" [reply_status $cgiReply]]} |
| 1839 | } |
| 1840 | |
| 1841 | # A request line with no path is a request for the home page. |
| 1842 | set cgiReply [cgi_send "GET\r\n\r\n" --ipaddr 127.0.0.1] |
| 1843 | test_eq cgi-no-path [reply_status $cgiReply] "HTTP/1.0 302 Moved Temporarily" |
| 1844 | |
| 1845 | ############################################################################### |
| 1846 | # Form data in several parts, as a browser sends an upload. |
| 1847 | |
| 1848 | proc cgi_part {name body {extra ""}} { |
| 1849 | return \ |
| 1850 | [join [list \ |
| 1851 | "--XB\r\n" \ |
| 1852 | "Content-Disposition: form-data; " \ |
| 1853 | "name=\"$name\"$extra\r\n\r\n$body\r\n"] ""] |
| 1854 | } |
| 1855 | set cgiType "multipart/form-data; boundary=XB" |
| 1856 | |
| 1857 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 1858 | "[cgi_part alpha {first value}][cgi_part upload {file body} \ |
| 1859 | {; filename="a.txt"}]--XB--\r\n"]] |
| 1860 | test_eq cgi-multipart [cgi_param $cgiReply alpha] "first value" |
| 1861 | test_eq cgi-multipart-file [cgi_param $cgiReply upload] "file body" |
| 1862 | test_eq cgi-multipart-filename [cgi_param $cgiReply upload:filename] a.txt |
| 1863 | test_eq cgi-multipart-bytes [cgi_param $cgiReply upload:bytes] 9 |
| 1864 | |
| 1865 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 1866 | [join [list \ |
| 1867 | "--XB\r\n" \ |
| 1868 | "Content-Disposition: form-data; name=\"t\"; " \ |
| 1869 | "filename=\"t.bin\"\r\n" \ |
| 1870 | "Content-Type: application/octet-stream\r\n\r\nxyz\r\n" \ |
| 1871 | "--XB--\r\n"] ""]]] |
| 1872 | test_eq cgi-multipart-mimetype [cgi_param $cgiReply t:mimetype] \ |
| 1873 | application/octet-stream |
| 1874 | |
| 1875 | # A name that begins with a capital is taken in lower case. |
| 1876 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 1877 | "[cgi_part Upper v {; filename="F.TXT"}]--XB--\r\n"]] |
| 1878 | test_eq cgi-multipart-upper [cgi_param $cgiReply upper] v |
| 1879 | test_eq cgi-multipart-upper-filename [cgi_param $cgiReply upper:filename] F.TXT |
| 1880 | |
| 1881 | # Lines may end with a bare newline. |
| 1882 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 1883 | "--XB\nContent-Disposition: form-data; name=\"lf\"\n\nvalue\n--XB--\n"]] |
| 1884 | test_eq cgi-multipart-lf [cgi_param $cgiReply lf] value |
| 1885 | |
| 1886 | # A part with no closing boundary after a long one ends at the end of the |
| 1887 | # request, and every part is read within the request. |
| 1888 | set cgiReply [cgi_admin [cgi_post $cgiType \ |
| 1889 | [join [list \ |
| 1890 | "[cgi_part alpha [string repeat x 3000]]--XB\r\n" \ |
| 1891 | "Content-Disposition: form-data; name=\"beta\"\r\n\r\n" \ |
| 1892 | "no closing boundary"] ""]]] |
| 1893 | test cgi-multipart-unclosed {$CODE == 0} |
| 1894 | test_eq cgi-multipart-unclosed-first \ |
| 1895 | [string length [cgi_param $cgiReply alpha]] 3000 |
| 1896 | test_eq cgi-multipart-unclosed-second [cgi_param $cgiReply beta] \ |
| 1897 | "no closing boundary" |
| 1898 | |
| 1899 | # Malformed and unusual bodies are read without a crash. |
| 1900 | set cgiI 0 |
| 1901 | foreach cgiBody [list \ |
| 1902 | "" \ |
| 1903 | "\r\n\r\nvalue\r\n\r\n" \ |
| 1904 | "--XB" \ |
| 1905 | "--XB\r\n" \ |
| 1906 | "--XB\r\n\r\nno name here\r\n--XB--\r\n" \ |
| 1907 | "--XB\r\nContent-Disposition: form-data; name=\"a\"" \ |
| 1908 | "[cgi_part a "one\000two"]--XB--\r\n" \ |
| 1909 | [join [list \ |
| 1910 | "--XB\r\n" \ |
| 1911 | "Content-Disp\000osition: form-data; name=\"a\"\r\n\r\nv\r\n" \ |
| 1912 | "--XB--\r\n"] ""] \ |
| 1913 | [join [list \ |
| 1914 | "--[string repeat B 3000]\r\n" \ |
| 1915 | "Content-Disposition: form-data; name=\"a\"\r\n\r\nshort\r\n"] ""] \ |
| 1916 | [join [list \ |
| 1917 | "[cgi_part a [string repeat x 2000]]--XB\r\n" \ |
| 1918 | "Content-Disposition: form-data; name=\"b\""] ""] \ |
| 1919 | "[cgi_part {} v]--XB--\r\n" \ |
| 1920 | [join [list \ |
| 1921 | "--XB\r\n" \ |
| 1922 | "Content-Disposition: form-data; filename=\"f\"\r\n\r\nv\r\n" \ |
| 1923 | "--XB--\r\n"] ""] \ |
| 1924 | [join [list \ |
| 1925 | "--XB\r\nContent-Disposition: form-data; name=\"abc\r\n\r\n" \ |
| 1926 | "v\r\n--XB--\r\n"] ""] \ |
| 1927 | "--XB\r\nContent-Disposition: form-data; name=\r\n\r\nv\r\n--XB--\r\n" \ |
| 1928 | [join [list \ |
| 1929 | "--XB\r\n" \ |
| 1930 | "Content-Disposition: form-data; name=\"a\"; " \ |
| 1931 | "filename=\r\n\r\nv\r\n--XB--\r\n"] ""] \ |
| 1932 | [join [list \ |
| 1933 | "--XB\r\nContent-Disposition: form-data; name=\"a\"\r\n" \ |
| 1934 | "content-type:\r\n\r\nv\r\n--XB--\r\n"] ""] \ |
| 1935 | "[cgi_part a "\n--X"]--XB--\r\n" \ |
| 1936 | ] { |
| 1937 | incr cgiI |
| 1938 | cgi_admin [cgi_post $cgiType $cgiBody] |
| 1939 | test cgi-multipart-odd-$cgiI {$CODE == 0} |
| 1940 | } |
| 1941 | set cgiMany "" |
| 1942 | for {set cgiI 0} {$cgiI < 400} {incr cgiI} { |
| 1943 | append cgiMany [cgi_part p$cgiI [string repeat v [expr {$cgiI % 50}]]] |
| 1944 | } |
| 1945 | set cgiReply [cgi_admin [cgi_post $cgiType "$cgiMany--XB--\r\n"]] |
| 1946 | test_eq cgi-multipart-many [cgi_param $cgiReply p399] [string repeat v 49] |
| 1947 | |
| 1948 | ############################################################################### |
| 1949 | # The date in an If-Modified-Since header. A file that has not changed |
| 1950 | # since that date is not sent again. |
| 1951 | |
| 1952 | proc cgi_since {date} { |
| 1953 | set reply [cgi_send \ |
| 1954 | "GET /uv/a.txt HTTP/1.1\r\nHost: x\r\nIf-Modified-Since: $date\r\n\r\n" \ |
| 1955 | --ipaddr 127.0.0.1] |
| 1956 | return [reply_status $reply] |
| 1957 | } |
| 1958 | test_eq cgi-since-later [cgi_since "Mon, 01 Jan 2099 00:00:00 GMT"] \ |
| 1959 | "HTTP/1.0 304 Not Modified" |
| 1960 | test_eq cgi-since-earlier [cgi_since "Sat, 01 Jan 2000 00:00:00 GMT"] \ |
| 1961 | "HTTP/1.0 200 OK" |
| 1962 | test_eq cgi-since-garbage [cgi_since "yesterday"] "HTTP/1.0 200 OK" |
| 1963 | # Numbers out of range are not a date. |
| 1964 | foreach {cgiName cgiDate} { |
| 1965 | year "Mon, 01 Jan 2147483647 00:00:00 GMT" |
| 1966 | day "Mon, 2147483647 Jan 2026 00:00:00 GMT" |
| 1967 | hour "Mon, 01 Jan 2026 2147483647:00:00 GMT" |
| 1968 | minute "Mon, 01 Jan 2026 00:2147483647:00 GMT" |
| 1969 | } { |
| 1970 | test_eq cgi-since-huge-$cgiName [cgi_since $cgiDate] "HTTP/1.0 200 OK" |
| 1971 | } |
| 1972 | |
| 1973 | ############################################################################### |
| 1974 | # A reply is compressed with gzip when the client accepts it and the type |
| 1975 | # of the content is text, JavaScript, JSON, WebAssembly, Tcl, tar, XML, |
| 1976 | # SVG or an icon. Other types, and a client that does not accept gzip, |
| 1977 | # get the content as it is. |
| 1978 | |
| 1979 | foreach {cgiName cgiGzip} { |
| 1980 | g.txt 1 g.js 1 g.json 1 g.wasm 1 g.tcl 1 g.tar 1 g.xml 1 g.svg 1 |
| 1981 | g.ico 1 g.png 0 g.zip 0 g.pdf 0 |
| 1982 | } { |
| 1983 | write_file $cgiName [string repeat "content to compress\n" 50] |
| 1984 | fossil uv add $cgiName |
| 1985 | set cgiReply [cgi_send \ |
| 1986 | [join [list \ |
| 1987 | "GET /uv/$cgiName HTTP/1.1\r\nHost: x\r\n" \ |
| 1988 | "Accept-Encoding: gzip, deflate\r\n\r\n"] ""] --ipaddr 127.0.0.1] |
| 1989 | test_eq cgi-gzip-$cgiName \ |
| 1990 | [string match "*\nContent-Encoding: gzip\r\n*" $cgiReply] $cgiGzip |
| 1991 | } |
| 1992 | set cgiReply [cgi_send "GET /uv/g.txt HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 1993 | --ipaddr 127.0.0.1] |
| 1994 | test cgi-gzip-not-accepted {[reply_status $cgiReply] eq "HTTP/1.0 200 OK" |
| 1995 | && ![string match "*Content-Encoding*" $cgiReply]} |
| 1996 | |
| 1997 | ############################################################################### |
| 1998 | # A POST whose Referer is another site is not taken as safe from forgery, |
| 1999 | # and is written to the error log. |
| 2000 | |
| 2001 | proc cgi_logout {referer} { |
| 2002 | return [cgi_send [cgi_post_from $referer /login "out=1"] --ipaddr 10.0.0.1 \ |
| 2003 | --errorlog [file join [pwd] err.log]] |
| 2004 | } |
| 2005 | file delete err.log |
| 2006 | cgi_logout http://x/login |
| 2007 | test cgi-same-origin-not-logged {![file exists err.log] |
| 2008 | || ![string match "*different origin*" [read_file err.log]]} |
| 2009 | cgi_logout http://elsewhere.example/page |
| 2010 | test cgi-other-origin-logged {[file exists err.log] |
| 2011 | && [string match "*POST from different origin*" [read_file err.log]]} |
| 2012 | |
| 2013 | ############################################################################### |
| 2014 | # SCGI: a header of name and value pairs, each ended by a zero byte, |
| 2015 | # preceded by its length and followed by a comma. |
| 2016 | |
| 2017 | proc cgi_scgi {pairs {body ""}} { |
| 2018 | set h "" |
| 2019 | foreach {k v} $pairs { append h $k \000 $v \000 } |
| 2020 | return "[string length $h]:$h,$body" |
| 2021 | } |
| 2022 | set cgiReply [cgi_send [cgi_scgi { |
| 2023 | CONTENT_LENGTH 0 SCGI 1 REQUEST_METHOD GET REQUEST_URI /test-env?s=1 |
| 2024 | PATH_INFO /test-env QUERY_STRING s=1 SERVER_NAME x SERVER_PORT 80 |
| 2025 | REMOTE_ADDR 127.0.0.1 |
| 2026 | }] --scgi --localauth] |
| 2027 | test_eq cgi-scgi [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 2028 | test_eq cgi-scgi-param [cgi_param $cgiReply s] 1 |
| 2029 | |
| 2030 | foreach {cgiName cgiRequest} [list \ |
| 2031 | too-short "15:CONTENT_LENGTH\0000\000," \ |
| 2032 | cut-short "40:CONTENT_LENGTH\0000\000," \ |
| 2033 | no-zero "20:CONTENT_LENGTH0000000000," \ |
| 2034 | huge-length "99999999999999999999:CONTENT_LENGTH\0000\000," \ |
| 2035 | ] { |
| 2036 | set cgiReply [cgi_send $cgiRequest --scgi] |
| 2037 | test cgi-scgi-$cgiName {$CODE == 0 && |
| 2038 | [string match "HTTP/1.0 400*" [reply_status $cgiReply]]} |
| 2039 | } |
| 2040 | |
| 2041 | ############################################################################### |
| 2042 | # The same reader for a request that arrives over ssh, which the server |
| 2043 | # knows from SSH_CONNECTION. It reads the client's probes first. |
| 2044 | |
| 2045 | set ::env(SSH_CONNECTION) "127.0.0.1 5000 127.0.0.1 22" |
| 2046 | set cgiReply [cgi_send "GET /test-env?q=1 HTTP/1.1\r\nHost: x\r\n\r\n" \ |
| 2047 | --localauth] |
| 2048 | test_eq cgi-ssh [reply_status $cgiReply] "HTTP/1.0 200 OK" |
| 2049 | test_eq cgi-ssh-param [cgi_param $cgiReply q] 1 |
| 2050 | test_eq cgi-ssh-address [cgi_param $cgiReply REMOTE_ADDR] 127.0.0.1 |
| 2051 | |
| 2052 | set cgiReply [cgi_send [cgi_ |
+1570
| --- a/test/config.test | ||
| +++ b/test/config.test | ||
| @@ -0,0 +1,1570 @@ | ||
| 1 | +# | |
| 2 | +# Tests of "fossil configuration": the methods export, import, merge and | |
| 3 | +# reset on every configuration area, the files they write and read, the | |
| 4 | +# files they refuse, and the configuration that push, pull and sync carry | |
| 5 | +# between repositories, with and without the capabilities the other side | |
| 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 | |
| 21 | + | |
| 22 | +############################################################################### | |
| 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} { | |
| 35 | + fossil new $file | |
| 36 | + fossil sql -R $file "UPDATE config SET mtime=1" | |
| 37 | + return $file | |
| 38 | +} | |
| 39 | + | |
| 40 | +# Run "fossil" with ARGS and keep standard error in RESULT; CODE is the exit | |
| 41 | +# status. | |
| 42 | +proc configRun {args} { | |
| 43 | + fossil_raw -seconds 120 {*}$args | |
| 44 | +} | |
| 45 | + | |
| 46 | +# The names, in each area, of the settings that sit in the CONFIG table. | |
| 47 | +# The settings that "th1-uri-regexp" names belong to the skin, ticket and | |
| 48 | +# transfer areas together. | |
| 49 | +set configNames(skin) { | |
| 50 | + css header mainmenu footer details js default-skin logo-mimetype | |
| 51 | + logo-image background-mimetype background-image icon-mimetype icon-image | |
| 52 | + timeline-date-format timeline-default-style timeline-dwelltime | |
| 53 | + timeline-closetime timeline-hard-newlines timeline-max-comment | |
| 54 | + timeline-plaintext timeline-truncate-at-blank timeline-tslink-info | |
| 55 | + timeline-utc adunit adunit-omit-if-admin adunit-omit-if-user default-csp | |
| 56 | + sitemap-extra safe-html th1-uri-regexp | |
| 57 | +} | |
| 58 | +set configNames(css) {css} | |
| 59 | +set configNames(project) { | |
| 60 | + project-name short-project-name project-description index-page manifest | |
| 61 | + binary-glob clean-glob ignore-glob keep-glob crlf-glob crnl-glob | |
| 62 | + encoding-glob empty-dirs dotfiles parent-project-code parent-project-name | |
| 63 | + hash-policy comment-format mimetypes forbid-delta-manifests mv-rm-files | |
| 64 | + forum-statuses path-to-tag | |
| 65 | +} | |
| 66 | +set configNames(ticket) { | |
| 67 | + ticket-table ticket-common ticket-change ticket-newpage ticket-viewpage | |
| 68 | + ticket-editpage ticket-reportlist ticket-report-template | |
| 69 | + ticket-key-template ticket-title-expr ticket-closed-expr th1-uri-regexp | |
| 70 | +} | |
| 71 | +set configNames(user) {user-color-map} | |
| 72 | +set configNames(xfer) { | |
| 73 | + xfer-common-script xfer-push-script xfer-commit-script xfer-ticket-script | |
| 74 | + th1-uri-regexp | |
| 75 | +} | |
| 76 | + | |
| 77 | +# The tables each area holds besides settings: rpt is the ticket | |
| 78 | +# reports, usr the users, cnc the concealed email addresses, shn the shunned | |
| 79 | +# artifacts, sub the subscribers. alias and interwiki are settings whose | |
| 80 | +# names have a fixed beginning. | |
| 81 | +set configTables(skin) {} | |
| 82 | +set configTables(css) {} | |
| 83 | +set configTables(project) {} | |
| 84 | +set configTables(ticket) rpt | |
| 85 | +set configTables(user) usr | |
| 86 | +set configTables(email) cnc | |
| 87 | +set configTables(shun) shn | |
| 88 | +set configTables(xfer) {} | |
| 89 | +set configTables(alias) {} | |
| 90 | +set configTables(interwiki) {} | |
| 91 | +set configTables(subscriber) sub | |
| 92 | +set configTables(all) {rpt usr cnc shn sub} | |
| 93 | +set configAreas {skin css project ticket user email shun xfer alias interwiki | |
| 94 | + subscriber all} | |
| 95 | + | |
| 96 | +# The SQL condition that selects the settings of AREA by name. | |
| 97 | +proc configCond {area} { | |
| 98 | + global configNames | |
| 99 | + set parts {} | |
| 100 | + switch -- $area { | |
| 101 | + all { | |
| 102 | + foreach a {skin project ticket user xfer} { | |
| 103 | + lappend parts [configCond $a] | |
| 104 | + } | |
| 105 | + lappend parts [configCond alias] [configCond interwiki] | |
| 106 | + } | |
| 107 | + alias {lappend parts "name GLOB 'walias:/*'"} | |
| 108 | + interwiki {lappend parts "name GLOB 'interwiki:*'"} | |
| 109 | + email - shun - subscriber {lappend parts 0} | |
| 110 | + default { | |
| 111 | + lappend parts "name IN ('[join $configNames($area) {','}]')" | |
| 112 | + } | |
| 113 | + } | |
| 114 | + return "([join $parts { OR }])" | |
| 115 | +} | |
| 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), | |
| 130 | + quote(info), quote(photo), quote(ifnull(jx,'{}')), mtime FROM user $m | |
| 131 | + ORDER BY login;"} | |
| 132 | + cnc {append sql "SELECT 'cnc', hash, quote(content), mtime | |
| 133 | + FROM concealed $m ORDER BY hash;"} | |
| 134 | + shn {append sql "SELECT 'shn', uuid, quote(scom), mtime | |
| 135 | + FROM shun $m ORDER BY uuid;"} | |
| 136 | + sub { | |
| 137 | + append sql "SELECT 'sub', semail, quote(suname), quote(sdigest), | |
| 138 | + quote(sdonotcall), quote(ssub), quote(sctime), quote(smip), mtime | |
| 139 | + FROM subscriber WHERE sverified [expr {$exported ? {AND mtime | |
| 140 | + IS NOT NULL} : {}}] ORDER BY semail;" | |
| 141 | + } | |
| 142 | + } | |
| 143 | + } | |
| 144 | + return $sql | |
| 145 | +} | |
| 146 | + | |
| 147 | +# What REPO holds for AREA: the settings and the tables. | |
| 148 | +proc configState {repo area {exported 0} {mask 0}} { | |
| 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} { | |
| 168 | + global configTables | |
| 169 | + set sql "SELECT 'cfg', name, quote(value), mtime FROM config | |
| 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] { | |
| 192 | + if {[regexp {^config (/[a-z]+) [0-9]+$} $line -> kind]} { | |
| 193 | + lappend kinds $kind | |
| 194 | + } | |
| 195 | + } | |
| 196 | + return [lsort -unique $kinds] | |
| 197 | +} | |
| 198 | + | |
| 199 | +# Insert settings into REPO. ROWS is a list of names and SQL expressions; | |
| 200 | +# the times of last change count up from MTIME. | |
| 201 | +proc configPut {repo rows mtime} { | |
| 202 | + set sql "" | |
| 203 | + foreach {name expr} $rows { | |
| 204 | + append sql "INSERT OR REPLACE INTO config(name,value,mtime) | |
| 205 | + VALUES('$name',$expr,$mtime);" | |
| 206 | + incr mtime | |
| 207 | + } | |
| 208 | + fossil sql -R $repo $sql | |
| 209 | +} | |
| 210 | + | |
| 211 | +############################################################################### | |
| 212 | +# The repository whose configuration the tests export: every area has | |
| 213 | +# something in it, with the awkward values that a configuration holds: | |
| 214 | +# quotes, line ends, characters beyond ASCII and binary content. | |
| 215 | + | |
| 216 | +set configSkin { | |
| 217 | + css {'body { color: #123; }'} | |
| 218 | + header {'<html> | |
| 219 | +<head><title>It''s "quoted"</title></head> | |
| 220 | +'} | |
| 221 | + mainmenu {'[["Home","/home"]]'} | |
| 222 | + footer {'caf' || char(233) || ' ' || char(8364)} | |
| 223 | + details {''} | |
| 224 | + js {'var a = ''b'';'} | |
| 225 | + default-skin {'plain'} | |
| 226 | + logo-mimetype {'image/png'} | |
| 227 | + logo-image {x'89504e470d0a1a0a0000'} | |
| 228 | + background-mimetype {'image/jpeg'} | |
| 229 | + background-image {x'ffd8ffe000104a46'} | |
| 230 | + icon-mimetype {'image/x-icon'} | |
| 231 | + icon-image {x'00000100'} | |
| 232 | + timeline-date-format {'2'} | |
| 233 | + timeline-default-style {'compact'} | |
| 234 | + timeline-dwelltime {'8'} | |
| 235 | + timeline-closetime {'9'} | |
| 236 | + timeline-hard-newlines {'1'} | |
| 237 | + timeline-max-comment {'77'} | |
| 238 | + timeline-plaintext {'1'} | |
| 239 | + timeline-truncate-at-blank {'1'} | |
| 240 | + timeline-tslink-info {'1'} | |
| 241 | + timeline-utc {'0'} | |
| 242 | + adunit {'<b>an ad</b>'} | |
| 243 | + adunit-omit-if-admin {'1'} | |
| 244 | + adunit-omit-if-user {'1'} | |
| 245 | + default-csp {'default-src ''self'''} | |
| 246 | + sitemap-extra {'3'} | |
| 247 | + safe-html {'1'} | |
| 248 | + th1-uri-regexp {'/ok/*'} | |
| 249 | +} | |
| 250 | +set configProject { | |
| 251 | + project-name {'Alpha'} | |
| 252 | + short-project-name {'AP'} | |
| 253 | + project-description {'The first line. | |
| 254 | +The second line.'} | |
| 255 | + index-page {'/home'} | |
| 256 | + manifest {'on'} | |
| 257 | + binary-glob {'*.bin,*.dat'} | |
| 258 | + clean-glob {'*.o'} | |
| 259 | + ignore-glob {'*.tmp'} | |
| 260 | + keep-glob {'keep/*'} | |
| 261 | + crlf-glob {'*.bat'} | |
| 262 | + crnl-glob {'*.cmd'} | |
| 263 | + encoding-glob {'*.txt'} | |
| 264 | + empty-dirs {'docs'} | |
| 265 | + dotfiles {'1'} | |
| 266 | + parent-project-code {'0123456789abcdef0123456789abcdef01234567'} | |
| 267 | + parent-project-name {'Parent'} | |
| 268 | + comment-format {'1'} | |
| 269 | + mimetypes {'*.x=text/x-x'} | |
| 270 | + forbid-delta-manifests {'1'} | |
| 271 | + mv-rm-files {'1'} | |
| 272 | + forum-statuses {'open,closed'} | |
| 273 | + path-to-tag {'1'} | |
| 274 | +} | |
| 275 | +set configXfer { | |
| 276 | + xfer-common-script {'proc common {} {return 1}'} | |
| 277 | + xfer-push-script {'proc push {} {return 2}'} | |
| 278 | + xfer-commit-script {'proc commit {} {return 3}'} | |
| 279 | + xfer-ticket-script {'proc ticket {} {return 4}'} | |
| 280 | +} | |
| 281 | +set configAlias { | |
| 282 | + walias:/docs {'/doc/trunk/www/index.wiki'} | |
| 283 | + walias:/news {'/forum'} | |
| 284 | +} | |
| 285 | +set configInterwiki { | |
| 286 | + interwiki:wp {'https://en.wikipedia.org/wiki/%s'} | |
| 287 | + interwiki:gh {'https://github.com/%s'} | |
| 288 | +} | |
| 289 | + | |
| 290 | +# The ticket configuration needs a ticket table that works: the default | |
| 291 | +# one with a column added. | |
| 292 | +proc configTicketTable {repo} { | |
| 293 | + set sql [configSql $repo "SELECT group_concat(sql,';') FROM sqlite_schema | |
| 294 | + WHERE tbl_name IN ('ticket','ticketchng') AND sql IS NOT NULL"] | |
| 295 | + return [string map {"comment TEXT\n)" "comment TEXT,\n zzz TEXT\n)"} $sql] | |
| 296 | +} | |
| 297 | + | |
| 298 | +proc configFill {repo} { | |
| 299 | + global configSkin configProject configXfer configAlias configInterwiki | |
| 300 | + configPut $repo $configSkin 1700000000 | |
| 301 | + configPut $repo $configProject 1700001000 | |
| 302 | + configPut $repo $configXfer 1700002000 | |
| 303 | + configPut $repo $configAlias 1700003000 | |
| 304 | + configPut $repo $configInterwiki 1700004000 | |
| 305 | + set table [string map {' ''} [configTicketTable $repo]] | |
| 306 | + configPut $repo [list \ | |
| 307 | + ticket-table "'$table'" \ | |
| 308 | + ticket-common {'set a 1'} \ | |
| 309 | + ticket-change {'set b "x"'} \ | |
| 310 | + ticket-newpage {'<h1>New</h1>'} \ | |
| 311 | + ticket-viewpage {'<h1>View</h1>'} \ | |
| 312 | + ticket-editpage {'<h1>Edit</h1>'} \ | |
| 313 | + ticket-reportlist {'1'} \ | |
| 314 | + ticket-report-template {'$a'} \ | |
| 315 | + ticket-key-template {'k-%s'} \ | |
| 316 | + ticket-title-expr {'title'} \ | |
| 317 | + ticket-closed-expr {'status=''Closed'''} \ | |
| 318 | + user-color-map {'alice=#ff0000'} \ | |
| 319 | + ] 1700005000 | |
| 320 | + fossil sql -R $repo " | |
| 321 | + UPDATE user SET mtime=1700006000 WHERE login='tester'; | |
| 322 | + INSERT INTO user(login,pw,cap,info,photo,jx,mtime) | |
| 323 | + VALUES('alice','pw-alice','oj','Alice <[email protected]>', | |
| 324 | + x'ffd8ffe0','{\"k\":1}',1700006001); | |
| 325 | + INSERT INTO user(login,pw,cap,info,photo,jx,mtime) | |
| 326 | + VALUES('bob',NULL,NULL,NULL,NULL,NULL,1700006002); | |
| 327 | + INSERT INTO shun(uuid,mtime,scom) VALUES | |
| 328 | + ('0123456789abcdef0123456789abcdef01234567',1700007000,'it''s spam'), | |
| 329 | + ('fedcba9876543210fedcba9876543210fedcba98',1700007001,NULL); | |
| 330 | + INSERT INTO concealed(hash,mtime,content) VALUES | |
| 331 | + ('aaaa1111',1700008000,'[email protected]'), | |
| 332 | + ('bbbb2222',1700008001,'[email protected]'); | |
| 333 | + UPDATE reportfmt SET mtime=2440588 WHERE title='All Tickets'; | |
| 334 | + INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode,jx) VALUES | |
| 335 | + ('alice','Mine',2460000,'#ffffff Key:','SELECT 1 AS ''x''', | |
| 336 | + '{\"a\":2}'), | |
| 337 | + (NULL,'Theirs',2460001,NULL,'SELECT 2',NULL), | |
| 338 | + (NULL,'Bare',2460002,NULL,NULL,NULL); | |
| 339 | + " | |
| 340 | + # The subscribers arrive as cards, which create the table. | |
| 341 | + set card "1700009000 '[email protected]' suname 'alice' sdigest 0\ | |
| 342 | + sdonotcall 0 ssub 'a' sctime 1700000000 smip '10.0.0.1'" | |
| 343 | + set card2 "1700009001 '[email protected]' suname NULL sdigest 1\ | |
| 344 | + sdonotcall 1 ssub 'ctw' sctime 1700000001 smip NULL" | |
| 345 | + write_file subscribers.cfg "config /subscriber [string length $card]\n$card\n\ | |
| 346 | + config /subscriber [string length $card2]\n$card2\n" | |
| 347 | + fossil config merge subscribers.cfg -R $repo | |
| 348 | + fossil sql -R $repo "INSERT INTO subscriber(semail,mtime,sverified) | |
| 349 | + VALUES('[email protected]',1700009002,0)" | |
| 350 | +} | |
| 351 | + | |
| 352 | +configNew a.fossil | |
| 353 | +configFill a.fossil | |
| 354 | +fossil sql -R a.fossil "UPDATE config SET mtime=1700010000 | |
| 355 | + WHERE name IN ('project-code')" | |
| 356 | +test config-fill-complete {[configSql a.fossil "SELECT count(*) FROM config | |
| 357 | + WHERE name IN ('header','project-name','ticket-table','xfer-push-script', | |
| 358 | + 'walias:/docs','interwiki:wp','user-color-map')"] == 7} | |
| 359 | +test config-fill-subscribers {[configSql a.fossil "SELECT count(*) FROM | |
| 360 | + subscriber"] == 3} | |
| 361 | + | |
| 362 | +############################################################################### | |
| 363 | +# Export: each area writes a file that starts with a comment naming the area | |
| 364 | +# and the repository, holds cards for that area only, and changes nothing. | |
| 365 | + | |
| 366 | +set configKindsOf(skin) /config | |
| 367 | +set configKindsOf(css) /config | |
| 368 | +set configKindsOf(project) /config | |
| 369 | +set configKindsOf(ticket) {/config /reportfmt} | |
| 370 | +set configKindsOf(user) {/config /user} | |
| 371 | +set configKindsOf(email) /concealed | |
| 372 | +set configKindsOf(shun) /shun | |
| 373 | +set configKindsOf(xfer) /config | |
| 374 | +set configKindsOf(alias) /config | |
| 375 | +set configKindsOf(interwiki) /config | |
| 376 | +set configKindsOf(subscriber) /subscriber | |
| 377 | +set configKindsOf(all) {/concealed /config /reportfmt /shun /subscriber /user} | |
| 378 | + | |
| 379 | +set configBefore [configSql a.fossil "SELECT 'c',name,mtime FROM config | |
| 380 | + ORDER BY name"] | |
| 381 | +foreach configArea $configAreas { | |
| 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 | |
| 398 | +# only the importing side held is gone. Nothing outside the area changes. | |
| 399 | +# Reset: the area is back at its defaults, the command names a file that | |
| 400 | +# restores what was there, and importing that file does so. | |
| 401 | + | |
| 402 | +# What an area has once it is reset. | |
| 403 | +proc configDefaults {area} { | |
| 404 | + global configDefault | |
| 405 | + if {![info exists configDefault]} { | |
| 406 | + configNew defaults.fossil | |
| 407 | + foreach a {skin css project ticket user email shun xfer alias interwiki | |
| 408 | + subscriber all} { | |
| 409 | + set configDefault($a) [configState defaults.fossil $a 0 1] | |
| 410 | + } | |
| 411 | + } | |
| 412 | + return $configDefault($area) | |
| 413 | +} | |
| 414 | + | |
| 415 | +# A row in the tables of AREA that the exporting repository lacks, for the | |
| 416 | +# importing one. | |
| 417 | +proc configDecoy {repo area} { | |
| 418 | + switch -- $area { | |
| 419 | + ticket {fossil sql -R $repo "INSERT INTO reportfmt(owner,title,mtime) | |
| 420 | + VALUES('x','Decoy',2450000)"} | |
| 421 | + user {fossil sql -R $repo "INSERT INTO user(login,cap,mtime) | |
| 422 | + VALUES('decoy','o',5)"} | |
| 423 | + email {fossil sql -R $repo "INSERT INTO concealed(hash,mtime,content) | |
| 424 | + VALUES('decoy',5,'[email protected]')"} | |
| 425 | + shun {fossil sql -R $repo "INSERT INTO shun(uuid,mtime,scom) | |
| 426 | + VALUES('decoy',5,'x')"} | |
| 427 | + subscriber {fossil sql -R $repo "INSERT INTO subscriber(semail,mtime) | |
| 428 | + VALUES('[email protected]',5)"} | |
| 429 | + all { | |
| 430 | + foreach a {ticket user email shun subscriber} {configDecoy $repo $a} | |
| 431 | + } | |
| 432 | + } | |
| 433 | +} | |
| 434 | + | |
| 435 | +foreach configArea $configAreas { | |
| 436 | + set configB b-$configArea.fossil | |
| 437 | + configNew $configB | |
| 438 | + if {$configArea eq "subscriber" || $configArea eq "all"} { | |
| 439 | + # A table that is there already, with a row only this side holds. | |
| 440 | + fossil config merge subscribers.cfg -R $configB | |
| 441 | + fossil sql -R $configB "DELETE FROM subscriber" | |
| 442 | + } | |
| 443 | + configDecoy $configB $configArea | |
| 444 | + set configOut [configOutside $configB $configArea] | |
| 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 | + } | |
| 457 | + fossil test-integrity -R $configB | |
| 458 | + test config-import-$configArea-integrity {$CODE == 0} | |
| 459 | + | |
| 460 | + # Reset. | |
| 461 | + set configPre [configState $configB $configArea] | |
| 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 | +############################################################################### | |
| 499 | +# Reset removes the URL aliases and the inter-wiki prefixes with their areas. | |
| 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(*) | |
| 512 | + FROM config WHERE name GLOB 'walias:/*' OR name GLOB 'interwiki:*'"] == 0} | |
| 513 | +test_eq config-reset-all-settings [configSql r-all.fossil "SELECT group_concat( | |
| 514 | + name) FROM (SELECT name FROM config WHERE NOT name GLOB 'walias:/*' AND | |
| 515 | + NOT name GLOB 'interwiki:*' ORDER BY name)"] \ | |
| 516 | + "aux-schema,content-schema,hash-policy,project-code,rebuilt,server-code" | |
| 517 | + | |
| 518 | +# Reset on a repository that has no subscriber table is no error. | |
| 519 | +configNew r-empty.fossil | |
| 520 | +configRun configuration reset subscriber -R r-empty.fossil | |
| 521 | +test config-reset-no-subscriber-table {$CODE == 0} | |
| 522 | +configRun configuration reset all -R r-empty.fossil | |
| 523 | +test config-reset-all-empty {$CODE == 0} | |
| 524 | +foreach configPart {skin project ticket xfer alias interwiki email shun | |
| 525 | + subscriber} { | |
| 526 | + test_eq config-reset-all-empty-$configPart \ | |
| 527 | + [configState r-empty.fossil $configPart 0 1] [configDefaults $configPart] | |
| 528 | +} | |
| 529 | +test_eq config-reset-all-empty-users [configSql r-empty.fossil "SELECT | |
| 530 | + group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] \ | |
| 531 | + "anonymous,developer,nobody,reader,tester" | |
| 532 | +test_eq config-reset-all-empty-reports [configSql r-empty.fossil "SELECT | |
| 533 | + group_concat(title) FROM reportfmt"] "All Tickets" | |
| 534 | +configRun configuration export all r-empty.cfg -R r-empty.fossil | |
| 535 | +test config-export-all-empty {$CODE == 0 && | |
| 536 | + [configKinds r-empty.cfg] eq "/config /reportfmt"} | |
| 537 | +configRun configuration export subscriber r-empty-sub.cfg -R r-empty.fossil | |
| 538 | +test config-export-subscriber-no-table {$CODE == 0 && | |
| 539 | + [configKinds r-empty-sub.cfg] eq ""} | |
| 540 | + | |
| 541 | +############################################################################### | |
| 542 | +# A ticket report whose time of change has a fraction, as the time of the | |
| 543 | +# default report has, comes back from an export. | |
| 544 | +# knownBug: the card of such a report is refused, because its first token | |
| 545 | +# must be a whole number. | |
| 546 | + | |
| 547 | +configNew f-a.fossil | |
| 548 | +configNew f-b.fossil | |
| 549 | +fossil sql -R f-a.fossil "INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode) | |
| 550 | + VALUES('o','Fractional',julianday('now'),'','SELECT 1')" | |
| 551 | +configRun configuration export ticket f-a.cfg -R f-a.fossil | |
| 552 | +configRun configuration merge f-a.cfg -R f-b.fossil | |
| 553 | +test config-merge-report-fraction {[configSql f-b.fossil "SELECT count(*) | |
| 554 | + FROM reportfmt WHERE title='Fractional'"] == 1} knownBug | |
| 555 | +configRun configuration import f-a.cfg -R f-b.fossil | |
| 556 | +test config-import-report-fraction {[configSql f-b.fossil "SELECT count(*) | |
| 557 | + FROM reportfmt WHERE title='Fractional'"] == 1} knownBug | |
| 558 | + | |
| 559 | +############################################################################### | |
| 560 | +# Export of changes since a time: only what changed since then is written. | |
| 561 | + | |
| 562 | +configRun configuration export project since.cfg --since 2099-01-01 \ | |
| 563 | + -R a.fossil | |
| 564 | +test config-export-since-future {$CODE == 0 && [configKinds since.cfg] eq ""} | |
| 565 | +configRun configuration export project since2.cfg --since 2000-01-01 \ | |
| 566 | + -R a.fossil | |
| 567 | +test config-export-since-past {$CODE == 0 && | |
| 568 | + [configKinds since2.cfg] eq "/config"} | |
| 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]} | |
| 580 | + # Everything after the header, which names the area and the time. | |
| 581 | + test_eq config-area-abbrev-$configAbbrev-same \ | |
| 582 | + [lrange [split [read_file abbrev.cfg] \n] 3 end] \ | |
| 583 | + [lrange [split [read_file export-$configArea.cfg] \n] 3 end] | |
| 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 && | |
| 598 | + [string first "no such configuration area: \"nosuch\"" $RESULT] >= 0} | |
| 599 | +} | |
| 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'" | |
| 614 | +} | |
| 615 | +configRun configuration res skin -R m-abbrev.fossil | |
| 616 | +test config-method-abbrev-res {$CODE == 0 && | |
| 617 | + [string first "Configuration reset" $RESULT] >= 0} | |
| 618 | +configRun configuration r skin -R m-abbrev.fossil | |
| 619 | +test config-method-abbrev-r {$CODE == 0 && | |
| 620 | + [string first "Configuration reset" $RESULT] >= 0} | |
| 621 | + | |
| 622 | +# Wrong numbers of arguments and unknown methods. | |
| 623 | +foreach {configNm configArgs} { | |
| 624 | + none {} | |
| 625 | + export-no-file {export skin} | |
| 626 | + export-too-many {export skin x.cfg y} | |
| 627 | + export-none {export} | |
| 628 | + import-none {import} | |
| 629 | + import-too-many {import a b} | |
| 630 | + merge-none {merge} | |
| 631 | + merge-too-many {merge a b} | |
| 632 | + reset-none {reset} | |
| 633 | + reset-too-many {reset skin skin} | |
| 634 | + pull-none {pull} | |
| 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 | +############################################################################### | |
| 653 | +# Merge: a value that the file has is taken where the repository has none | |
| 654 | +# or an older one; a value that the repository changed at the same time or | |
| 655 | +# later is kept. Nothing is removed. | |
| 656 | + | |
| 657 | +# A card for TABLE with TEXT as its content. | |
| 658 | +proc configCard {table text} { | |
| 659 | + return "config /$table [string length $text]\n$text\n" | |
| 660 | +} | |
| 661 | + | |
| 662 | +configNew m.fossil | |
| 663 | +fossil config merge subscribers.cfg -R m.fossil | |
| 664 | +fossil sql -R m.fossil " | |
| 665 | + INSERT INTO config(name,value,mtime) VALUES | |
| 666 | + ('css','local-css',1800000000), | |
| 667 | + ('header','local-header',5), | |
| 668 | + ('mainmenu','local-menu',1700000002), | |
| 669 | + ('walias:/docs','local-alias',1800000000), | |
| 670 | + ('walias:/only','only-here',5); | |
| 671 | + INSERT INTO user(login,pw,cap,info,mtime) VALUES | |
| 672 | + ('alice','local-pw','x','local',1800000000), | |
| 673 | + ('only','p','o','',5); | |
| 674 | + UPDATE user SET cap='o' WHERE login='tester'; | |
| 675 | + INSERT INTO shun(uuid,mtime,scom) VALUES | |
| 676 | + ('0123456789abcdef0123456789abcdef01234567',5,'old'), | |
| 677 | + ('only',5,'only here'); | |
| 678 | + INSERT INTO concealed(hash,mtime,content) VALUES | |
| 679 | + ('aaaa1111',1800000000,'[email protected]'), | |
| 680 | + ('only',5,'[email protected]'); | |
| 681 | + INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode) VALUES | |
| 682 | + ('local','Mine',2400000,'','SELECT 0'), | |
| 683 | + ('local','Only',2400000,'','SELECT 0'); | |
| 684 | + UPDATE subscriber SET suname='local', mtime=1800000000 | |
| 685 | + WHERE semail='[email protected]'; | |
| 686 | + INSERT INTO subscriber(semail,mtime) VALUES('[email protected]',5); | |
| 687 | +" | |
| 688 | +configRun configuration merge export-all.cfg -R m.fossil | |
| 689 | +test config-merge {$CODE == 0 && $RESULT eq ""} | |
| 690 | +proc configMergeCheck {name sql expected} { | |
| 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 | |
| 702 | + WHERE name='walias:/docs'" local-alias | |
| 703 | +configMergeCheck alias-absent-added "SELECT value FROM config | |
| 704 | + WHERE name='walias:/news'" /forum | |
| 705 | +configMergeCheck interwiki-added "SELECT value FROM config | |
| 706 | + WHERE name='interwiki:wp'" "https://en.wikipedia.org/wiki/%s" | |
| 707 | +configMergeCheck local-only-alias-kept "SELECT value FROM config | |
| 708 | + WHERE name='walias:/only'" only-here | |
| 709 | +configMergeCheck user-newer-local-kept "SELECT pw||cap||info FROM user | |
| 710 | + WHERE login='alice'" "local-pwxlocal" | |
| 711 | +configMergeCheck user-absent-added "SELECT count(*) FROM user | |
| 712 | + WHERE login='bob' AND mtime=1700006002" 1 | |
| 713 | +configMergeCheck user-local-only-kept "SELECT count(*) FROM user | |
| 714 | + WHERE login='only'" 1 | |
| 715 | +configMergeCheck shun-older-local-replaced "SELECT scom||'|'||mtime FROM shun | |
| 716 | + WHERE uuid='0123456789abcdef0123456789abcdef01234567'" \ | |
| 717 | + "it's spam|1700007000" | |
| 718 | +configMergeCheck shun-absent-added "SELECT count(*) FROM shun | |
| 719 | + WHERE uuid='fedcba9876543210fedcba9876543210fedcba98' AND scom IS NULL" 1 | |
| 720 | +configMergeCheck shun-local-only-kept "SELECT count(*) FROM shun | |
| 721 | + WHERE uuid='only'" 1 | |
| 722 | +configMergeCheck concealed-newer-local-kept "SELECT content FROM concealed | |
| 723 | + WHERE hash='aaaa1111'" [email protected] | |
| 724 | +configMergeCheck concealed-absent-added "SELECT content FROM concealed | |
| 725 | + WHERE hash='bbbb2222'" [email protected] | |
| 726 | +configMergeCheck concealed-local-only-kept "SELECT count(*) FROM concealed | |
| 727 | + WHERE hash='only'" 1 | |
| 728 | +configMergeCheck report-older-local-replaced "SELECT owner||'|'||sqlcode FROM | |
| 729 | + reportfmt WHERE title='Mine'" "alice|SELECT 1 AS 'x'" | |
| 730 | +configMergeCheck report-absent-added "SELECT count(*) FROM reportfmt | |
| 731 | + WHERE title='Theirs'" 1 | |
| 732 | +configMergeCheck report-local-only-kept "SELECT count(*) FROM reportfmt | |
| 733 | + WHERE title='Only'" 1 | |
| 734 | +configMergeCheck subscriber-newer-local-kept "SELECT suname FROM subscriber | |
| 735 | + WHERE semail='[email protected]'" local | |
| 736 | +configMergeCheck subscriber-absent-added "SELECT ssub FROM subscriber | |
| 737 | + WHERE semail='[email protected]'" ctw | |
| 738 | +configMergeCheck subscriber-local-only-kept "SELECT count(*) FROM subscriber | |
| 739 | + WHERE semail='[email protected]'" 1 | |
| 740 | +fossil test-integrity -R m.fossil | |
| 741 | +test config-merge-integrity {$CODE == 0} | |
| 742 | + | |
| 743 | +# The same file merged again changes nothing. | |
| 744 | +set configMerged [configState m.fossil all] | |
| 745 | +configRun configuration merge export-all.cfg -R m.fossil | |
| 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 | +############################################################################### | |
| 775 | +# The literals of a card. A value is a string, a blob in hexadecimal, an | |
| 776 | +# integer or NULL; anything else is refused and the card does nothing. | |
| 777 | + | |
| 778 | +configNew l.fossil | |
| 779 | +proc configLiteral {name value expected} { | |
| 780 | + fossil sql -R l.fossil "DELETE FROM config WHERE name='header'" | |
| 781 | + write_file lit.cfg [configCard config "1700000000 'header' value $value"] | |
| 782 | + configRun configuration merge lit.cfg -R l.fossil | |
| 783 | + set got [configSql l.fossil "SELECT quote(value) FROM config | |
| 784 | + WHERE name='header'"] | |
| 785 | + test_eq config-literal-$name $got $expected | |
| 786 | + test config-literal-$name-exit {$::CODE == 0} | |
| 787 | +} | |
| 788 | +configLiteral string {'plain'} {'plain'} | |
| 789 | +configLiteral string-empty {''} {''} | |
| 790 | +configLiteral string-quote {'it''s'} {'it''s'} | |
| 791 | +configLiteral string-newline "'a\nb'" "'a\nb'" | |
| 792 | +configLiteral blob {x'41424344'} {X'41424344'} | |
| 793 | +configLiteral blob-upper {X'4a4B'} {X'4A4B'} | |
| 794 | +configLiteral blob-empty {x''} {X''} | |
| 795 | +configLiteral integer {12} {'12'} | |
| 796 | +# Text after the closing quote of a string is a token of its own, which is | |
| 797 | +# no field name, so it is skipped and the string stays the value. | |
| 798 | +configLiteral string-trailing {'a'b'} {'a'} | |
| 799 | +configLiteral string-concat {'a'||'b'} {'a'} | |
| 800 | +configLiteral null {NULL} {NULL} | |
| 801 | +configLiteral null-lower {null} {NULL} | |
| 802 | +configLiteral null-mixed {NuLl} {NULL} | |
| 803 | +foreach {configNm configValue} { | |
| 804 | + bare-word hello | |
| 805 | + float 1.5 | |
| 806 | + negative -5 | |
| 807 | + digits-letters 12ab | |
| 808 | + expression {1+1} | |
| 809 | + blob-odd {x'abc'} | |
| 810 | + blob-not-hex {x'zz'} | |
| 811 | + blob-open {x'ab} | |
| 812 | + blob-no-quote {xab} | |
| 813 | + blob-upper-no-quote {Xab} | |
| 814 | + blob-short {x'} | |
| 815 | + string-open {'abc} | |
| 816 | + string-open-doubled {'abc''} | |
| 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 | +} | |
| 828 | + | |
| 829 | + | |
| 830 | +############################################################################### | |
| 831 | +# Files that are not well formed. A line that is no card is skipped; a card | |
| 832 | +# that is not well formed does nothing, and the cards after it are read as | |
| 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 | + | |
| 878 | +configMalformed empty-file "" 0 | |
| 879 | +configMalformed only-comments "# one\n# two\n\n\n" 0 | |
| 880 | +configMalformed junk-first-line "this is not a configuration file\n" 1 | |
| 881 | +configMalformed binary-junk "\x01\x02\x03\n\xff\xfe\n" 1 | |
| 882 | +configMalformed no-final-newline "config /config" 0 | |
| 883 | +configMalformed old-format "config css 5\nhello\n" 1 | |
| 884 | +configMalformed unknown-kind "config /nosuch $configLen\n$configBody\n" 1 | |
| 885 | +configMalformed upper-case "CONFIG /config $configLen\n$configBody\n" 1 | |
| 886 | +configMalformed first-char-of-kind "config Xconfig $configLen\n$configBody\n" 1 | |
| 887 | +configMalformed no-size "config /config\n$configBody\n" 1 | |
| 888 | +configMalformed no-kind "config\n$configBody\n" 1 | |
| 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" | |
| 905 | + unknown-name "1700000600 'nosuch' value 'x'\n" | |
| 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 | |
| 920 | + write_file big.cfg "config /config 100000\n$configBody" | |
| 921 | + configRun configuration $configMethod big.cfg -R c-$configMethod.fossil | |
| 922 | + test config-size-large-$configMethod {$CODE == 0 && | |
| 923 | + [configSql c-$configMethod.fossil "SELECT value FROM config | |
| 924 | + WHERE name='css'"] eq "new"} | |
| 925 | +} | |
| 926 | + | |
| 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'" | |
| 952 | +configRun configuration merge many.cfg -R k.fossil | |
| 953 | +test_eq config-fields-many-kept [configSql k.fossil "SELECT info FROM user | |
| 954 | + WHERE login='carol'"] v10 | |
| 955 | + | |
| 956 | +# A card whose key or value is no literal does not reach the database. | |
| 957 | +foreach {configNm configText} { | |
| 958 | + semicolon {'x'; DROP TABLE shun; --} | |
| 959 | + quote-break {'x'');DELETE FROM user;--'} | |
| 960 | + subquery {(SELECT 1)} | |
| 961 | + function {char(65)} | |
| 962 | +} { | |
| 963 | + set configCardBody "1700000600 $configText\n" | |
| 964 | + write_file inj.cfg "[configCard shun $configCardBody]" | |
| 965 | + configRun configuration merge inj.cfg -R k.fossil | |
| 966 | + test config-literal-no-sql-$configNm {$CODE == 0 && | |
| 967 | + [configSql k.fossil "SELECT count(*) FROM sqlite_schema | |
| 968 | + WHERE name IN ('shun','user')"] == 2} | |
| 969 | +} | |
| 970 | + | |
| 971 | +############################################################################### | |
| 972 | +# Settings that the file may not set: the ones that no area holds (the | |
| 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" | |
| 985 | + write_file ne.cfg [configCard config $configCardBody] | |
| 986 | + configRun configuration import ne.cfg -R n.fossil | |
| 987 | + test config-not-exportable-$configNm {$CODE == 0 && | |
| 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" | |
| 1000 | + no-value "1700000600 'nosuch'\n" | |
| 1001 | +} { | |
| 1002 | + write_file ne.cfg [configCard config $configCardBody] | |
| 1003 | + configRun configuration merge ne.cfg -R n.fossil | |
| 1004 | + test config-not-exportable-$configNm {$CODE == 0 && | |
| 1005 | + [string first "Skipping non-exportable setting: " $RESULT] >= 0} | |
| 1006 | + if {$configNm eq "no-value"} { | |
| 1007 | + test config-not-exportable-no-value-said {[string first "= ?" $RESULT] >= 0} | |
| 1008 | + } | |
| 1009 | + test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \ | |
| 1010 | + $configNBefore | |
| 1011 | +} | |
| 1012 | + | |
| 1013 | +# Names quoted as a literal are read without the quotes; a name that holds | |
| 1014 | +# a quote can still be a setting of an area. | |
| 1015 | +set configCardBody "1700000600 'walias:/it''s' value '/x'\n" | |
| 1016 | +write_file ne.cfg [configCard config $configCardBody] | |
| 1017 | +configRun configuration merge ne.cfg -R n.fossil | |
| 1018 | +test_eq config-name-quoted [configSql n.fossil "SELECT value FROM config | |
| 1019 | + WHERE name='walias:/it''s'"] /x | |
| 1020 | + | |
| 1021 | + | |
| 1022 | +############################################################################### | |
| 1023 | +# Push, pull and sync with a repository named by its file: the client starts | |
| 1024 | +# "fossil http" on the file, so both sides speak the whole protocol and the | |
| 1025 | +# other side grants everything. Each area that is pulled arrives as the | |
| 1026 | +# other side holds it, each that is pushed is there afterwards, and nothing | |
| 1027 | +# outside the area changes. The users are left out of the comparison: | |
| 1028 | +# those that a repository made for itself have no time of change, and a | |
| 1029 | +# merge does not replace them. | |
| 1030 | + | |
| 1031 | +set configSrv [file join $configDir a.fossil] | |
| 1032 | + | |
| 1033 | +# The parts of AREA that a comparison looks at. | |
| 1034 | +proc configParts {area} { | |
| 1035 | + if {$area eq "all"} { | |
| 1036 | + return {skin project ticket xfer alias interwiki email shun subscriber | |
| 1037 | + user} | |
| 1038 | + } | |
| 1039 | + return $area | |
| 1040 | +} | |
| 1041 | + | |
| 1042 | +# Test that REPO holds what EXPECTED holds, as an export of it, for AREA. | |
| 1043 | +proc configSameAs {name repo area expected} { | |
| 1044 | + foreach part [configParts $area] { | |
| 1045 | + if {$part eq "user"} { | |
| 1046 | + set sql "SELECT name, value, mtime FROM config | |
| 1047 | + WHERE name='user-color-map'; | |
| 1048 | + SELECT login,quote(pw),cap,info,quote(photo),mtime FROM user | |
| 1049 | + WHERE login IN ('alice','bob') ORDER BY login" | |
| 1050 | + test_eq $name-$part [configSql $repo $sql] [configSql $expected $sql] | |
| 1051 | + } else { | |
| 1052 | + test_eq $name-$part [configState $repo $part] \ | |
| 1053 | + [configState $expected $part 1] | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | +} | |
| 1057 | + | |
| 1058 | +foreach configArea $configAreas { | |
| 1059 | + # Pull. | |
| 1060 | + set configC cl-pull-$configArea.fossil | |
| 1061 | + configNew $configC | |
| 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 | + | |
| 1086 | + | |
| 1087 | +# Sync sends and receives. Each side gets what only the other has, and for | |
| 1088 | +# a value that both have, the one changed last wins on both. | |
| 1089 | +configNew s1.fossil | |
| 1090 | +configNew s2.fossil | |
| 1091 | +configPut s1.fossil {walias:/only1 {'one'} walias:/both {'old-1'} | |
| 1092 | + walias:/tie {'tie-1'}} 1700000000 | |
| 1093 | +fossil sql -R s1.fossil "UPDATE config SET mtime=1700000100 | |
| 1094 | + WHERE name='walias:/both'" | |
| 1095 | +fossil sql -R s1.fossil "UPDATE config SET mtime=1700000300 | |
| 1096 | + WHERE name='walias:/tie'" | |
| 1097 | +configPut s2.fossil {walias:/only2 {'two'} walias:/both {'new-2'} | |
| 1098 | + walias:/tie {'tie-2'}} 1700000000 | |
| 1099 | +fossil sql -R s2.fossil "UPDATE config SET mtime=1700000200 | |
| 1100 | + WHERE name='walias:/both'" | |
| 1101 | +fossil sql -R s2.fossil "UPDATE config SET mtime=1700000300 | |
| 1102 | + WHERE name='walias:/tie'" | |
| 1103 | +configRun configuration sync alias [file join $configDir s2.fossil] -R s1.fossil | |
| 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 ""} | |
| 1133 | +test_eq config-pull-overwrite-user-local-gone [configSql o1.fossil "SELECT | |
| 1134 | + count(*) FROM user WHERE login='local'"] 0 | |
| 1135 | +test_eq config-pull-overwrite-user-remote [configSql o1.fossil "SELECT | |
| 1136 | + count(*) FROM user WHERE login='remote'"] 1 | |
| 1137 | + | |
| 1138 | +# --overwrite is an option of pull only. | |
| 1139 | +configRun configuration push shun --overwrite [file join $configDir o2.fossil] \ | |
| 1140 | + -R o1.fossil | |
| 1141 | +test config-push-overwrite {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} | |
| 1142 | +configRun configuration sync shun --overwrite [file join $configDir o2.fossil] \ | |
| 1143 | + -R o1.fossil | |
| 1144 | +test config-sync-overwrite {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} | |
| 1145 | + | |
| 1146 | +# Without a URL the command uses the default server; with none it stops. | |
| 1147 | +configNew u1.fossil | |
| 1148 | +configRun configuration pull skin -R u1.fossil | |
| 1149 | +test config-pull-no-server {$CODE == 1 && | |
| 1150 | + [string first "no server URL specified" $RESULT] >= 0} | |
| 1151 | +configRun configuration push skin -R u1.fossil | |
| 1152 | +test config-push-no-server {$CODE == 1} | |
| 1153 | +configRun configuration sync skin -R u1.fossil | |
| 1154 | +test config-sync-no-server {$CODE == 1} | |
| 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 | |
| 1171 | +# is answered with nothing, and an area it knows with its cards. | |
| 1172 | + | |
| 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. | |
| 1186 | + | |
| 1187 | +configNew old.fossil | |
| 1188 | +fossil sql -R old.fossil "ALTER TABLE user DROP COLUMN jx; | |
| 1189 | + ALTER TABLE reportfmt DROP COLUMN jx; | |
| 1190 | + UPDATE user SET mtime=5" | |
| 1191 | +configRun configuration export all old.cfg -R old.fossil | |
| 1192 | +test config-export-old-schema {$CODE == 0 && | |
| 1193 | + [string first " jx " [read_file old.cfg]] < 0 && | |
| 1194 | + [configKinds old.cfg] eq "/config /reportfmt /user"} | |
| 1195 | +configNew old2.fossil | |
| 1196 | +configRun configuration import old.cfg -R old2.fossil | |
| 1197 | +test config-import-old-schema {$CODE == 0 && | |
| 1198 | + [configSql old2.fossil "SELECT login FROM user WHERE login='tester'"] eq | |
| 1199 | + "tester"} | |
| 1200 | + | |
| 1201 | +############################################################################### | |
| 1202 | +# The settings table by hand: test-var-set, test-var-get and test-var-list. | |
| 1203 | + | |
| 1204 | +configNew v.fossil | |
| 1205 | +fossil test-var-set alpha hello -R v.fossil | |
| 1206 | +test config-var-set {$CODE == 0} | |
| 1207 | +fossil test-var-get alpha -R v.fossil | |
| 1208 | +test_eq config-var-get $RESULT hello | |
| 1209 | +fossil test-var-get alpha out.txt -R v.fossil | |
| 1210 | +test_eq config-var-get-file [read_file out.txt] hello | |
| 1211 | +fossil test-var-get alpha - -R v.fossil | |
| 1212 | +test_eq config-var-get-stdout $RESULT hello | |
| 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 | |
| 1224 | +test_eq config-var-set-blob-type [configSql v.fossil "SELECT typeof(value) FROM | |
| 1225 | + config WHERE name='gamma'"] blob | |
| 1226 | +fossil_raw -input "piped in\n" test-var-set delta --file - -R v.fossil | |
| 1227 | +test config-var-set-stdin {$CODE == 0} | |
| 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 | + | |
| 1252 | +# The list: names and values in two columns, control characters written as | |
| 1253 | +# escapes, long values cut with the count of what is left, long names on a | |
| 1254 | +# line of their own. | |
| 1255 | +set configLongValue [string repeat abcdefghij 6] | |
| 1256 | +set configLongName1 a-name-that-is-long-but-with-a-short-value | |
| 1257 | +set configLongName2 a-name-that-is-long-with-a-value-that-is-long-too-and-so-on | |
| 1258 | +set configMidName a-name-that-is-between-the-two-lengths | |
| 1259 | +configNew w.fossil | |
| 1260 | +fossil sql -R w.fossil "DELETE FROM config WHERE NOT name GLOB 'a*'; | |
| 1261 | + INSERT INTO config(name,value,mtime) VALUES | |
| 1262 | + ('a-short','plain',1700000000), | |
| 1263 | + ('a-ctl','x'||char(10)||char(13)||char(9)||char(1)||'y',1700000001), | |
| 1264 | + ('a-long','$configLongValue',1700000002), | |
| 1265 | + ('$configLongName1','v',1700000003), | |
| 1266 | + ('$configLongName2','a value that has more than ten characters', | |
| 1267 | + 1700000004), | |
| 1268 | + ('$configMidName','x',1700000005), | |
| 1269 | + ('$configMidName-long','a value that has more than ten characters', | |
| 1270 | + 1700000006), | |
| 1271 | + ('a-high','caf'||char(233)||char(127),1700000007)" | |
| 1272 | +# A line for NAME that has its value in the column that NAME's length gives. | |
| 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" \ | |
| 1284 | + $configList] >= 0} | |
| 1285 | +test config-var-list-long-name-short-value {[string first \ | |
| 1286 | + "[configListLine $configLongName1 v 59]\n" $configList] >= 0} | |
| 1287 | +test config-var-list-long-name-long-value {[string first \ | |
| 1288 | + "$configLongName2:\n[string repeat { } 28]a value that has more than ten\ | |
| 1289 | + character...+1\n" $configList] >= 0} | |
| 1290 | +test config-var-list-mid-name {[string first \ | |
| 1291 | + "[configListLine $configMidName x 59]\n" $configList] >= 0} | |
| 1292 | +test config-var-list-mid-name-long-value {[string first \ | |
| 1293 | + "$configMidName-long:\n[string repeat { } 28]a value that has more than ten\ | |
| 1294 | + character...+1\n" $configList] >= 0} | |
| 1295 | +test config-var-list-high-bytes {[string first \ | |
| 1296 | + "[configListLine a-high {caf\303\251\177} 27]\n" $configList] >= 0} | |
| 1297 | +configRun test-var-list "a-s*" -R w.fossil | |
| 1298 | +test_eq config-var-list-pattern [string trimright $RESULT] \ | |
| 1299 | + [configListLine a-short plain 27] | |
| 1300 | +configRun test-var-list "a-s*" --mtime -R w.fossil | |
| 1301 | +test_eq config-var-list-mtime [string trimright $RESULT] \ | |
| 1302 | + [configListLine a-short "2023-11-14 22:13:20" 58] | |
| 1303 | +configRun test-var-list nosuch -R w.fossil | |
| 1304 | +test_eq config-var-list-none $RESULT "" | |
| 1305 | +# Delete only on an answer of y, and only with a pattern. | |
| 1306 | +set configCount [configSql w.fossil "SELECT count(*) FROM config"] | |
| 1307 | +fossil_raw -input "n\n" test-var-list "a-s*" --unset -R w.fossil | |
| 1308 | +test config-var-unset-no {$CODE == 0 && [configSql w.fossil "SELECT count(*) | |
| 1309 | + FROM config WHERE name='a-short'"] == 1} | |
| 1310 | +fossil_raw -input "y\n" test-var-list --unset -R w.fossil | |
| 1311 | +test config-var-unset-no-pattern {[configSql w.fossil "SELECT count(*) FROM | |
| 1312 | + config"] == $configCount} | |
| 1313 | +fossil_raw -input "Y\n" test-var-list "a-s*" --unset -R w.fossil | |
| 1314 | +test config-var-unset-capital {[configSql w.fossil "SELECT count(*) FROM config | |
| 1315 | + WHERE name='a-short'"] == 0} | |
| 1316 | +fossil_raw -input "y\n" test-var-list "a-s*" --unset -R w.fossil | |
| 1317 | +test config-var-unset-yes {$CODE == 0 && [configSql w.fossil "SELECT count(*) | |
| 1318 | + FROM config WHERE name='a-short'"] == 0} | |
| 1319 | + | |
| 1320 | +############################################################################### | |
| 1321 | +# The rest of the file needs a TCP connection over the loopback interface. | |
| 1322 | + | |
| 1323 | +if {![loopback_available]} { | |
| 1324 | + unset ::env(FOSSIL_USER) | |
| 1325 | + test_skip "no TCP connection over the loopback interface" | |
| 1326 | +} | |
| 1327 | + | |
| 1328 | +############################################################################### | |
| 1329 | +# Pull and push to a server that checks the login card. What a pull brings | |
| 1330 | +# depends on the capabilities of the user on the server: every area comes | |
| 1331 | +# to anyone who may read, except the concealed email addresses (capability | |
| 1332 | +# e), the users and the subscribers (a). A push needs capability a; for a | |
| 1333 | +# user without it, the server refuses and holds what it held. | |
| 1334 | + | |
| 1335 | +# Make a server repository FILE that has the configuration of a.fossil and | |
| 1336 | +# the users that these tests log in as, and return it. | |
| 1337 | +proc configServer {file} { | |
| 1338 | + file copy -force a.fossil $file | |
| 1339 | + fossil sql -R $file " | |
| 1340 | + INSERT INTO user(login,pw,cap) VALUES | |
| 1341 | + ('rdr','pw','o'), ('eml','pw','oe'), ('adm','pw','a'), ('blind','pw','j'); | |
| 1342 | + " | |
| 1343 | + return $file | |
| 1344 | +} | |
| 1345 | + | |
| 1346 | +# Give REPO the project code of a.fossil: a client makes its login card from | |
| 1347 | +# its own project code, so it must be the server's. | |
| 1348 | +proc configShareProject {repo} { | |
| 1349 | + global configProjectCode | |
| 1350 | + if {![info exists configProjectCode]} { | |
| 1351 | + set configProjectCode [configSql a.fossil "SELECT value FROM config | |
| 1352 | + WHERE name='project-code'"] | |
| 1353 | + } | |
| 1354 | + fossil sql -R $repo "UPDATE config SET value='$configProjectCode' | |
| 1355 | + WHERE name='project-code'" | |
| 1356 | +} | |
| 1357 | + | |
| 1358 | +# Run VERB on repository CLIENT against the server on PORT, logged in as | |
| 1359 | +# USER, who has the password "pw", or as nobody for an empty USER. | |
| 1360 | +proc configNetRun {verb area client port user} { | |
| 1361 | + set at [expr {$user eq "" ? "" : "$user:pw@"}] | |
| 1362 | + configRun configuration $verb $area http://${at}127.0.0.1:$port/ -R $client | |
| 1363 | +} | |
| 1364 | + | |
| 1365 | +# Whether USER may pull PART of the configuration. | |
| 1366 | +proc configMayPull {user part} { | |
| 1367 | + switch -- $part { | |
| 1368 | + email {return [expr {$user in {eml adm}}]} | |
| 1369 | + user - subscriber {return [expr {$user eq "adm"}]} | |
| 1370 | + } | |
| 1371 | + return [expr {$user ne "blind"}] | |
| 1372 | +} | |
| 1373 | + | |
| 1374 | +# Test that REPO holds PART as the server's repository does if WANT is true, | |
| 1375 | +# and as a new repository does if it is false. | |
| 1376 | +proc configHasPart {name repo part want} { | |
| 1377 | + if {$part eq "user"} { | |
| 1378 | + set sql "SELECT count(*) FROM user WHERE login IN ('alice','bob') | |
| 1379 | + AND mtime IS NOT NULL; | |
| 1380 | + SELECT count(*) FROM config WHERE name='user-color-map'" | |
| 1381 | + test_eq $name-$part [configSql $repo $sql] \ | |
| 1382 | + [expr {$want ? "2\n1" : "0\n0"}] | |
| 1383 | + } elseif {$want} { | |
| 1384 | + test_eq $name-$part [configState $repo $part] \ | |
| 1385 | + [configState a.fossil $part 1] | |
| 1386 | + } else { | |
| 1387 | + test_eq $name-$part [configState $repo $part 0 1] [configDefaults $part] | |
| 1388 | + } | |
| 1389 | +} | |
| 1390 | + | |
| 1391 | +configServer ps.fossil | |
| 1392 | +set configServerProc [test_start_server ps.fossil configStop] | |
| 1393 | +set configPort [lindex $configServerProc 1] | |
| 1394 | +# Each pair is a user and an area to pull as that user. | |
| 1395 | +foreach {configUser configArea} {{} skin {} all eml email eml user adm all | |
| 1396 | + blind skin} { | |
| 1397 | + set configLabel [expr {$configUser eq "" ? "nobody" : $configUser}] | |
| 1398 | + if {$configUser eq "blind"} { | |
| 1399 | + # A user whose capabilities, with those of nobody, include no reading. | |
| 1400 | + fossil sql -R ps.fossil "UPDATE user SET cap='' WHERE login IN | |
| 1401 | + ('nobody','anonymous')" | |
| 1402 | + } | |
| 1403 | + set configC cp-$configLabel-$configArea.fossil | |
| 1404 | + configNew $configC | |
| 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} | |
| 1416 | + } | |
| 1417 | +} | |
| 1418 | +test_stop_server $configStop [lindex $configServerProc 0] \ | |
| 1419 | + [lindex $configServerProc 2] | |
| 1420 | + | |
| 1421 | +configNew cs-base.fossil | |
| 1422 | +configShareProject cs-base.fossil | |
| 1423 | +fossil sql -R cs-base.fossil "INSERT INTO user(login,pw,cap) VALUES | |
| 1424 | + ('rdr','pw','o'), ('eml','pw','oe'), ('adm','pw','a')" | |
| 1425 | +file copy -force cs-base.fossil cs.fossil | |
| 1426 | +set configServerProc [test_start_server cs.fossil configStop] | |
| 1427 | +set configPort [lindex $configServerProc 1] | |
| 1428 | +# Each pair is a user and an area to push as that user; only adm may push. | |
| 1429 | +foreach {configUser configArea} {{} skin adm email adm user adm all} { | |
| 1430 | + set configLabel [expr {$configUser eq "" ? "nobody" : $configUser}] | |
| 1431 | + file copy -force cs-base.fossil cs.fossil | |
| 1432 | + set configPre [configDump cs.fossil] | |
| 1433 | + configNetRun push $configArea a.fossil $configPort $configUser | |
| 1434 | + if {$configUser eq "adm"} { | |
| 1435 | + test config-push-$configLabel-$configArea {$CODE == 0} | |
| 1436 | + foreach configPart [configParts $configArea] { | |
| 1437 | + configHasPart config-push-$configLabel-$configArea-has cs.fossil \ | |
| 1438 | + $configPart 1 | |
| 1439 | + } | |
| 1440 | + } else { | |
| 1441 | + test config-push-$configLabel-$configArea-refused { | |
| 1442 | + [string first "not authorized to push configuration" $RESULT] >= 0} | |
| 1443 | + test config-push-refused-status {$CODE == 1} | |
| 1444 | + test_eq config-push-$configLabel-$configArea-unchanged \ | |
| 1445 | + [configDump cs.fossil] $configPre | |
| 1446 | + } | |
| 1447 | +} | |
| 1448 | +test_stop_server $configStop [lindex $configServerProc 0] \ | |
| 1449 | + [lindex $configServerProc 2] | |
| 1450 | + | |
| 1451 | +############################################################################### | |
| 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]] | |
| 1483 | + } | |
| 1484 | + lappend ::configFakeRequests $body | |
| 1485 | + if {[incr ::configFakeCount] == 1} { | |
| 1486 | + set reply $::configFakeReply | |
| 1487 | + } else { | |
| 1488 | + set reply "# timestamp 2026-01-01T00:00:00 errors 0\n" | |
| 1489 | + } | |
| 1490 | + catch { | |
| 1491 | + puts -nonewline $chan "HTTP/1.0 200 OK\r\nContent-Type:\ | |
| 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 | |
| 1504 | + set configFakeRequests {} | |
| 1505 | + configRun configuration $verb $area http://127.0.0.1:$configFakePort/ \ | |
| 1506 | + -R rp.fossil | |
| 1507 | +} | |
| 1508 | + | |
| 1509 | +configNew rp.fossil | |
| 1510 | +set configRpReply [configCard config "1700000000 'header' value 'asked'"] | |
| 1511 | +append configRpReply [configCard config "1700000000 'project-name' value 'not'"] | |
| 1512 | +append configRpReply [configCard user "1700000000 'zed' cap 's'"] | |
| 1513 | +append configRpReply [configCard nosuch "1700000000 'zed' cap 's'"] | |
| 1514 | +append configRpReply [configCard config "1700000000 'adunit' value 'asked'"] | |
| 1515 | +configReply pull skin $configRpReply | |
| 1516 | +test config-reply-unasked {$CODE == 0} | |
| 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. | |
| 1528 | +proc configAsked {} { | |
| 1529 | + return [regexp -all {reqconfig [^\n]*} [lindex $::configFakeRequests 0]] | |
| 1530 | +} | |
| 1531 | +# The style sheet is part of the skin, so both are asked for; only the style | |
| 1532 | +# sheet is taken. | |
| 1533 | +test config-reply-request-css {[configAsked] == 2 && | |
| 1534 | + [string first "reqconfig /skin\nreqconfig /css\n" \ | |
| 1535 | + [lindex $configFakeRequests 0]] >= 0} | |
| 1536 | +configReply pull all "" | |
| 1537 | +test config-reply-request-all {[configAsked] == 1 && | |
| 1538 | + [string first "reqconfig /all\n" [lindex $configFakeRequests 0]] >= 0} | |
| 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 | + | |
| 1551 | +configNew tpl.fossil | |
| 1552 | +fossil sql -R tpl.fossil " | |
| 1553 | + INSERT OR REPLACE INTO config(name,value,mtime) VALUES | |
| 1554 | + ('css','from-template',1700000000), | |
| 1555 | + ('ticket-title-expr','from-template',1700000000), | |
| 1556 | + ('walias:/tpl','/timeline',1700000000), | |
| 1557 | + ('project-name','Template Project',1700000000), | |
| 1558 | + ('short-project-name','tpl',1700000000), | |
| 1559 | + ('config-test-other','from-template',1700000000)" | |
| 1560 | +configRun init --template tpl.fossil fromtpl.fossil | |
| 1561 | +test config-init-template {$CODE == 0} | |
| 1562 | +test_eq config-init-template-copied [configSql fromtpl.fossil " | |
| 1563 | + SELECT group_concat(name||'='||value, ' ') FROM (SELECT name, value | |
| 1564 | + FROM config WHERE name IN ('css','ticket-title-expr','walias:/tpl', | |
| 1565 | + 'project-name','short-project-name','config-test-other') | |
| 1566 | + ORDER BY name)"] \ | |
| 1567 | + "css=from-template ticket-title-expr=from-template walias:/tpl=/timeline" | |
| 1568 | + | |
| 1569 | +test_cleanup | |
| 1570 | +unset ::env(FOSSIL_USER) |
| --- a/test/config.test | |
| +++ b/test/config.test | |
| @@ -0,0 +1,1570 @@ | |
| --- a/test/config.test | |
| +++ b/test/config.test | |
| @@ -0,0 +1,1570 @@ | |
| 1 | # |
| 2 | # Tests of "fossil configuration": the methods export, import, merge and |
| 3 | # reset on every configuration area, the files they write and read, the |
| 4 | # files they refuse, and the configuration that push, pull and sync carry |
| 5 | # between repositories, with and without the capabilities the other side |
| 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 |
| 21 | |
| 22 | ############################################################################### |
| 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} { |
| 35 | fossil new $file |
| 36 | fossil sql -R $file "UPDATE config SET mtime=1" |
| 37 | return $file |
| 38 | } |
| 39 | |
| 40 | # Run "fossil" with ARGS and keep standard error in RESULT; CODE is the exit |
| 41 | # status. |
| 42 | proc configRun {args} { |
| 43 | fossil_raw -seconds 120 {*}$args |
| 44 | } |
| 45 | |
| 46 | # The names, in each area, of the settings that sit in the CONFIG table. |
| 47 | # The settings that "th1-uri-regexp" names belong to the skin, ticket and |
| 48 | # transfer areas together. |
| 49 | set configNames(skin) { |
| 50 | css header mainmenu footer details js default-skin logo-mimetype |
| 51 | logo-image background-mimetype background-image icon-mimetype icon-image |
| 52 | timeline-date-format timeline-default-style timeline-dwelltime |
| 53 | timeline-closetime timeline-hard-newlines timeline-max-comment |
| 54 | timeline-plaintext timeline-truncate-at-blank timeline-tslink-info |
| 55 | timeline-utc adunit adunit-omit-if-admin adunit-omit-if-user default-csp |
| 56 | sitemap-extra safe-html th1-uri-regexp |
| 57 | } |
| 58 | set configNames(css) {css} |
| 59 | set configNames(project) { |
| 60 | project-name short-project-name project-description index-page manifest |
| 61 | binary-glob clean-glob ignore-glob keep-glob crlf-glob crnl-glob |
| 62 | encoding-glob empty-dirs dotfiles parent-project-code parent-project-name |
| 63 | hash-policy comment-format mimetypes forbid-delta-manifests mv-rm-files |
| 64 | forum-statuses path-to-tag |
| 65 | } |
| 66 | set configNames(ticket) { |
| 67 | ticket-table ticket-common ticket-change ticket-newpage ticket-viewpage |
| 68 | ticket-editpage ticket-reportlist ticket-report-template |
| 69 | ticket-key-template ticket-title-expr ticket-closed-expr th1-uri-regexp |
| 70 | } |
| 71 | set configNames(user) {user-color-map} |
| 72 | set configNames(xfer) { |
| 73 | xfer-common-script xfer-push-script xfer-commit-script xfer-ticket-script |
| 74 | th1-uri-regexp |
| 75 | } |
| 76 | |
| 77 | # The tables each area holds besides settings: rpt is the ticket |
| 78 | # reports, usr the users, cnc the concealed email addresses, shn the shunned |
| 79 | # artifacts, sub the subscribers. alias and interwiki are settings whose |
| 80 | # names have a fixed beginning. |
| 81 | set configTables(skin) {} |
| 82 | set configTables(css) {} |
| 83 | set configTables(project) {} |
| 84 | set configTables(ticket) rpt |
| 85 | set configTables(user) usr |
| 86 | set configTables(email) cnc |
| 87 | set configTables(shun) shn |
| 88 | set configTables(xfer) {} |
| 89 | set configTables(alias) {} |
| 90 | set configTables(interwiki) {} |
| 91 | set configTables(subscriber) sub |
| 92 | set configTables(all) {rpt usr cnc shn sub} |
| 93 | set configAreas {skin css project ticket user email shun xfer alias interwiki |
| 94 | subscriber all} |
| 95 | |
| 96 | # The SQL condition that selects the settings of AREA by name. |
| 97 | proc configCond {area} { |
| 98 | global configNames |
| 99 | set parts {} |
| 100 | switch -- $area { |
| 101 | all { |
| 102 | foreach a {skin project ticket user xfer} { |
| 103 | lappend parts [configCond $a] |
| 104 | } |
| 105 | lappend parts [configCond alias] [configCond interwiki] |
| 106 | } |
| 107 | alias {lappend parts "name GLOB 'walias:/*'"} |
| 108 | interwiki {lappend parts "name GLOB 'interwiki:*'"} |
| 109 | email - shun - subscriber {lappend parts 0} |
| 110 | default { |
| 111 | lappend parts "name IN ('[join $configNames($area) {','}]')" |
| 112 | } |
| 113 | } |
| 114 | return "([join $parts { OR }])" |
| 115 | } |
| 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), |
| 130 | quote(info), quote(photo), quote(ifnull(jx,'{}')), mtime FROM user $m |
| 131 | ORDER BY login;"} |
| 132 | cnc {append sql "SELECT 'cnc', hash, quote(content), mtime |
| 133 | FROM concealed $m ORDER BY hash;"} |
| 134 | shn {append sql "SELECT 'shn', uuid, quote(scom), mtime |
| 135 | FROM shun $m ORDER BY uuid;"} |
| 136 | sub { |
| 137 | append sql "SELECT 'sub', semail, quote(suname), quote(sdigest), |
| 138 | quote(sdonotcall), quote(ssub), quote(sctime), quote(smip), mtime |
| 139 | FROM subscriber WHERE sverified [expr {$exported ? {AND mtime |
| 140 | IS NOT NULL} : {}}] ORDER BY semail;" |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | return $sql |
| 145 | } |
| 146 | |
| 147 | # What REPO holds for AREA: the settings and the tables. |
| 148 | proc configState {repo area {exported 0} {mask 0}} { |
| 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} { |
| 168 | global configTables |
| 169 | set sql "SELECT 'cfg', name, quote(value), mtime FROM config |
| 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] { |
| 192 | if {[regexp {^config (/[a-z]+) [0-9]+$} $line -> kind]} { |
| 193 | lappend kinds $kind |
| 194 | } |
| 195 | } |
| 196 | return [lsort -unique $kinds] |
| 197 | } |
| 198 | |
| 199 | # Insert settings into REPO. ROWS is a list of names and SQL expressions; |
| 200 | # the times of last change count up from MTIME. |
| 201 | proc configPut {repo rows mtime} { |
| 202 | set sql "" |
| 203 | foreach {name expr} $rows { |
| 204 | append sql "INSERT OR REPLACE INTO config(name,value,mtime) |
| 205 | VALUES('$name',$expr,$mtime);" |
| 206 | incr mtime |
| 207 | } |
| 208 | fossil sql -R $repo $sql |
| 209 | } |
| 210 | |
| 211 | ############################################################################### |
| 212 | # The repository whose configuration the tests export: every area has |
| 213 | # something in it, with the awkward values that a configuration holds: |
| 214 | # quotes, line ends, characters beyond ASCII and binary content. |
| 215 | |
| 216 | set configSkin { |
| 217 | css {'body { color: #123; }'} |
| 218 | header {'<html> |
| 219 | <head><title>It''s "quoted"</title></head> |
| 220 | '} |
| 221 | mainmenu {'[["Home","/home"]]'} |
| 222 | footer {'caf' || char(233) || ' ' || char(8364)} |
| 223 | details {''} |
| 224 | js {'var a = ''b'';'} |
| 225 | default-skin {'plain'} |
| 226 | logo-mimetype {'image/png'} |
| 227 | logo-image {x'89504e470d0a1a0a0000'} |
| 228 | background-mimetype {'image/jpeg'} |
| 229 | background-image {x'ffd8ffe000104a46'} |
| 230 | icon-mimetype {'image/x-icon'} |
| 231 | icon-image {x'00000100'} |
| 232 | timeline-date-format {'2'} |
| 233 | timeline-default-style {'compact'} |
| 234 | timeline-dwelltime {'8'} |
| 235 | timeline-closetime {'9'} |
| 236 | timeline-hard-newlines {'1'} |
| 237 | timeline-max-comment {'77'} |
| 238 | timeline-plaintext {'1'} |
| 239 | timeline-truncate-at-blank {'1'} |
| 240 | timeline-tslink-info {'1'} |
| 241 | timeline-utc {'0'} |
| 242 | adunit {'<b>an ad</b>'} |
| 243 | adunit-omit-if-admin {'1'} |
| 244 | adunit-omit-if-user {'1'} |
| 245 | default-csp {'default-src ''self'''} |
| 246 | sitemap-extra {'3'} |
| 247 | safe-html {'1'} |
| 248 | th1-uri-regexp {'/ok/*'} |
| 249 | } |
| 250 | set configProject { |
| 251 | project-name {'Alpha'} |
| 252 | short-project-name {'AP'} |
| 253 | project-description {'The first line. |
| 254 | The second line.'} |
| 255 | index-page {'/home'} |
| 256 | manifest {'on'} |
| 257 | binary-glob {'*.bin,*.dat'} |
| 258 | clean-glob {'*.o'} |
| 259 | ignore-glob {'*.tmp'} |
| 260 | keep-glob {'keep/*'} |
| 261 | crlf-glob {'*.bat'} |
| 262 | crnl-glob {'*.cmd'} |
| 263 | encoding-glob {'*.txt'} |
| 264 | empty-dirs {'docs'} |
| 265 | dotfiles {'1'} |
| 266 | parent-project-code {'0123456789abcdef0123456789abcdef01234567'} |
| 267 | parent-project-name {'Parent'} |
| 268 | comment-format {'1'} |
| 269 | mimetypes {'*.x=text/x-x'} |
| 270 | forbid-delta-manifests {'1'} |
| 271 | mv-rm-files {'1'} |
| 272 | forum-statuses {'open,closed'} |
| 273 | path-to-tag {'1'} |
| 274 | } |
| 275 | set configXfer { |
| 276 | xfer-common-script {'proc common {} {return 1}'} |
| 277 | xfer-push-script {'proc push {} {return 2}'} |
| 278 | xfer-commit-script {'proc commit {} {return 3}'} |
| 279 | xfer-ticket-script {'proc ticket {} {return 4}'} |
| 280 | } |
| 281 | set configAlias { |
| 282 | walias:/docs {'/doc/trunk/www/index.wiki'} |
| 283 | walias:/news {'/forum'} |
| 284 | } |
| 285 | set configInterwiki { |
| 286 | interwiki:wp {'https://en.wikipedia.org/wiki/%s'} |
| 287 | interwiki:gh {'https://github.com/%s'} |
| 288 | } |
| 289 | |
| 290 | # The ticket configuration needs a ticket table that works: the default |
| 291 | # one with a column added. |
| 292 | proc configTicketTable {repo} { |
| 293 | set sql [configSql $repo "SELECT group_concat(sql,';') FROM sqlite_schema |
| 294 | WHERE tbl_name IN ('ticket','ticketchng') AND sql IS NOT NULL"] |
| 295 | return [string map {"comment TEXT\n)" "comment TEXT,\n zzz TEXT\n)"} $sql] |
| 296 | } |
| 297 | |
| 298 | proc configFill {repo} { |
| 299 | global configSkin configProject configXfer configAlias configInterwiki |
| 300 | configPut $repo $configSkin 1700000000 |
| 301 | configPut $repo $configProject 1700001000 |
| 302 | configPut $repo $configXfer 1700002000 |
| 303 | configPut $repo $configAlias 1700003000 |
| 304 | configPut $repo $configInterwiki 1700004000 |
| 305 | set table [string map {' ''} [configTicketTable $repo]] |
| 306 | configPut $repo [list \ |
| 307 | ticket-table "'$table'" \ |
| 308 | ticket-common {'set a 1'} \ |
| 309 | ticket-change {'set b "x"'} \ |
| 310 | ticket-newpage {'<h1>New</h1>'} \ |
| 311 | ticket-viewpage {'<h1>View</h1>'} \ |
| 312 | ticket-editpage {'<h1>Edit</h1>'} \ |
| 313 | ticket-reportlist {'1'} \ |
| 314 | ticket-report-template {'$a'} \ |
| 315 | ticket-key-template {'k-%s'} \ |
| 316 | ticket-title-expr {'title'} \ |
| 317 | ticket-closed-expr {'status=''Closed'''} \ |
| 318 | user-color-map {'alice=#ff0000'} \ |
| 319 | ] 1700005000 |
| 320 | fossil sql -R $repo " |
| 321 | UPDATE user SET mtime=1700006000 WHERE login='tester'; |
| 322 | INSERT INTO user(login,pw,cap,info,photo,jx,mtime) |
| 323 | VALUES('alice','pw-alice','oj','Alice <[email protected]>', |
| 324 | x'ffd8ffe0','{\"k\":1}',1700006001); |
| 325 | INSERT INTO user(login,pw,cap,info,photo,jx,mtime) |
| 326 | VALUES('bob',NULL,NULL,NULL,NULL,NULL,1700006002); |
| 327 | INSERT INTO shun(uuid,mtime,scom) VALUES |
| 328 | ('0123456789abcdef0123456789abcdef01234567',1700007000,'it''s spam'), |
| 329 | ('fedcba9876543210fedcba9876543210fedcba98',1700007001,NULL); |
| 330 | INSERT INTO concealed(hash,mtime,content) VALUES |
| 331 | ('aaaa1111',1700008000,'[email protected]'), |
| 332 | ('bbbb2222',1700008001,'[email protected]'); |
| 333 | UPDATE reportfmt SET mtime=2440588 WHERE title='All Tickets'; |
| 334 | INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode,jx) VALUES |
| 335 | ('alice','Mine',2460000,'#ffffff Key:','SELECT 1 AS ''x''', |
| 336 | '{\"a\":2}'), |
| 337 | (NULL,'Theirs',2460001,NULL,'SELECT 2',NULL), |
| 338 | (NULL,'Bare',2460002,NULL,NULL,NULL); |
| 339 | " |
| 340 | # The subscribers arrive as cards, which create the table. |
| 341 | set card "1700009000 '[email protected]' suname 'alice' sdigest 0\ |
| 342 | sdonotcall 0 ssub 'a' sctime 1700000000 smip '10.0.0.1'" |
| 343 | set card2 "1700009001 '[email protected]' suname NULL sdigest 1\ |
| 344 | sdonotcall 1 ssub 'ctw' sctime 1700000001 smip NULL" |
| 345 | write_file subscribers.cfg "config /subscriber [string length $card]\n$card\n\ |
| 346 | config /subscriber [string length $card2]\n$card2\n" |
| 347 | fossil config merge subscribers.cfg -R $repo |
| 348 | fossil sql -R $repo "INSERT INTO subscriber(semail,mtime,sverified) |
| 349 | VALUES('[email protected]',1700009002,0)" |
| 350 | } |
| 351 | |
| 352 | configNew a.fossil |
| 353 | configFill a.fossil |
| 354 | fossil sql -R a.fossil "UPDATE config SET mtime=1700010000 |
| 355 | WHERE name IN ('project-code')" |
| 356 | test config-fill-complete {[configSql a.fossil "SELECT count(*) FROM config |
| 357 | WHERE name IN ('header','project-name','ticket-table','xfer-push-script', |
| 358 | 'walias:/docs','interwiki:wp','user-color-map')"] == 7} |
| 359 | test config-fill-subscribers {[configSql a.fossil "SELECT count(*) FROM |
| 360 | subscriber"] == 3} |
| 361 | |
| 362 | ############################################################################### |
| 363 | # Export: each area writes a file that starts with a comment naming the area |
| 364 | # and the repository, holds cards for that area only, and changes nothing. |
| 365 | |
| 366 | set configKindsOf(skin) /config |
| 367 | set configKindsOf(css) /config |
| 368 | set configKindsOf(project) /config |
| 369 | set configKindsOf(ticket) {/config /reportfmt} |
| 370 | set configKindsOf(user) {/config /user} |
| 371 | set configKindsOf(email) /concealed |
| 372 | set configKindsOf(shun) /shun |
| 373 | set configKindsOf(xfer) /config |
| 374 | set configKindsOf(alias) /config |
| 375 | set configKindsOf(interwiki) /config |
| 376 | set configKindsOf(subscriber) /subscriber |
| 377 | set configKindsOf(all) {/concealed /config /reportfmt /shun /subscriber /user} |
| 378 | |
| 379 | set configBefore [configSql a.fossil "SELECT 'c',name,mtime FROM config |
| 380 | ORDER BY name"] |
| 381 | foreach configArea $configAreas { |
| 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 |
| 398 | # only the importing side held is gone. Nothing outside the area changes. |
| 399 | # Reset: the area is back at its defaults, the command names a file that |
| 400 | # restores what was there, and importing that file does so. |
| 401 | |
| 402 | # What an area has once it is reset. |
| 403 | proc configDefaults {area} { |
| 404 | global configDefault |
| 405 | if {![info exists configDefault]} { |
| 406 | configNew defaults.fossil |
| 407 | foreach a {skin css project ticket user email shun xfer alias interwiki |
| 408 | subscriber all} { |
| 409 | set configDefault($a) [configState defaults.fossil $a 0 1] |
| 410 | } |
| 411 | } |
| 412 | return $configDefault($area) |
| 413 | } |
| 414 | |
| 415 | # A row in the tables of AREA that the exporting repository lacks, for the |
| 416 | # importing one. |
| 417 | proc configDecoy {repo area} { |
| 418 | switch -- $area { |
| 419 | ticket {fossil sql -R $repo "INSERT INTO reportfmt(owner,title,mtime) |
| 420 | VALUES('x','Decoy',2450000)"} |
| 421 | user {fossil sql -R $repo "INSERT INTO user(login,cap,mtime) |
| 422 | VALUES('decoy','o',5)"} |
| 423 | email {fossil sql -R $repo "INSERT INTO concealed(hash,mtime,content) |
| 424 | VALUES('decoy',5,'[email protected]')"} |
| 425 | shun {fossil sql -R $repo "INSERT INTO shun(uuid,mtime,scom) |
| 426 | VALUES('decoy',5,'x')"} |
| 427 | subscriber {fossil sql -R $repo "INSERT INTO subscriber(semail,mtime) |
| 428 | VALUES('[email protected]',5)"} |
| 429 | all { |
| 430 | foreach a {ticket user email shun subscriber} {configDecoy $repo $a} |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | foreach configArea $configAreas { |
| 436 | set configB b-$configArea.fossil |
| 437 | configNew $configB |
| 438 | if {$configArea eq "subscriber" || $configArea eq "all"} { |
| 439 | # A table that is there already, with a row only this side holds. |
| 440 | fossil config merge subscribers.cfg -R $configB |
| 441 | fossil sql -R $configB "DELETE FROM subscriber" |
| 442 | } |
| 443 | configDecoy $configB $configArea |
| 444 | set configOut [configOutside $configB $configArea] |
| 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 | } |
| 457 | fossil test-integrity -R $configB |
| 458 | test config-import-$configArea-integrity {$CODE == 0} |
| 459 | |
| 460 | # Reset. |
| 461 | set configPre [configState $configB $configArea] |
| 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 | ############################################################################### |
| 499 | # Reset removes the URL aliases and the inter-wiki prefixes with their areas. |
| 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(*) |
| 512 | FROM config WHERE name GLOB 'walias:/*' OR name GLOB 'interwiki:*'"] == 0} |
| 513 | test_eq config-reset-all-settings [configSql r-all.fossil "SELECT group_concat( |
| 514 | name) FROM (SELECT name FROM config WHERE NOT name GLOB 'walias:/*' AND |
| 515 | NOT name GLOB 'interwiki:*' ORDER BY name)"] \ |
| 516 | "aux-schema,content-schema,hash-policy,project-code,rebuilt,server-code" |
| 517 | |
| 518 | # Reset on a repository that has no subscriber table is no error. |
| 519 | configNew r-empty.fossil |
| 520 | configRun configuration reset subscriber -R r-empty.fossil |
| 521 | test config-reset-no-subscriber-table {$CODE == 0} |
| 522 | configRun configuration reset all -R r-empty.fossil |
| 523 | test config-reset-all-empty {$CODE == 0} |
| 524 | foreach configPart {skin project ticket xfer alias interwiki email shun |
| 525 | subscriber} { |
| 526 | test_eq config-reset-all-empty-$configPart \ |
| 527 | [configState r-empty.fossil $configPart 0 1] [configDefaults $configPart] |
| 528 | } |
| 529 | test_eq config-reset-all-empty-users [configSql r-empty.fossil "SELECT |
| 530 | group_concat(login) FROM (SELECT login FROM user ORDER BY login)"] \ |
| 531 | "anonymous,developer,nobody,reader,tester" |
| 532 | test_eq config-reset-all-empty-reports [configSql r-empty.fossil "SELECT |
| 533 | group_concat(title) FROM reportfmt"] "All Tickets" |
| 534 | configRun configuration export all r-empty.cfg -R r-empty.fossil |
| 535 | test config-export-all-empty {$CODE == 0 && |
| 536 | [configKinds r-empty.cfg] eq "/config /reportfmt"} |
| 537 | configRun configuration export subscriber r-empty-sub.cfg -R r-empty.fossil |
| 538 | test config-export-subscriber-no-table {$CODE == 0 && |
| 539 | [configKinds r-empty-sub.cfg] eq ""} |
| 540 | |
| 541 | ############################################################################### |
| 542 | # A ticket report whose time of change has a fraction, as the time of the |
| 543 | # default report has, comes back from an export. |
| 544 | # knownBug: the card of such a report is refused, because its first token |
| 545 | # must be a whole number. |
| 546 | |
| 547 | configNew f-a.fossil |
| 548 | configNew f-b.fossil |
| 549 | fossil sql -R f-a.fossil "INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode) |
| 550 | VALUES('o','Fractional',julianday('now'),'','SELECT 1')" |
| 551 | configRun configuration export ticket f-a.cfg -R f-a.fossil |
| 552 | configRun configuration merge f-a.cfg -R f-b.fossil |
| 553 | test config-merge-report-fraction {[configSql f-b.fossil "SELECT count(*) |
| 554 | FROM reportfmt WHERE title='Fractional'"] == 1} knownBug |
| 555 | configRun configuration import f-a.cfg -R f-b.fossil |
| 556 | test config-import-report-fraction {[configSql f-b.fossil "SELECT count(*) |
| 557 | FROM reportfmt WHERE title='Fractional'"] == 1} knownBug |
| 558 | |
| 559 | ############################################################################### |
| 560 | # Export of changes since a time: only what changed since then is written. |
| 561 | |
| 562 | configRun configuration export project since.cfg --since 2099-01-01 \ |
| 563 | -R a.fossil |
| 564 | test config-export-since-future {$CODE == 0 && [configKinds since.cfg] eq ""} |
| 565 | configRun configuration export project since2.cfg --since 2000-01-01 \ |
| 566 | -R a.fossil |
| 567 | test config-export-since-past {$CODE == 0 && |
| 568 | [configKinds since2.cfg] eq "/config"} |
| 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]} |
| 580 | # Everything after the header, which names the area and the time. |
| 581 | test_eq config-area-abbrev-$configAbbrev-same \ |
| 582 | [lrange [split [read_file abbrev.cfg] \n] 3 end] \ |
| 583 | [lrange [split [read_file export-$configArea.cfg] \n] 3 end] |
| 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 && |
| 598 | [string first "no such configuration area: \"nosuch\"" $RESULT] >= 0} |
| 599 | } |
| 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'" |
| 614 | } |
| 615 | configRun configuration res skin -R m-abbrev.fossil |
| 616 | test config-method-abbrev-res {$CODE == 0 && |
| 617 | [string first "Configuration reset" $RESULT] >= 0} |
| 618 | configRun configuration r skin -R m-abbrev.fossil |
| 619 | test config-method-abbrev-r {$CODE == 0 && |
| 620 | [string first "Configuration reset" $RESULT] >= 0} |
| 621 | |
| 622 | # Wrong numbers of arguments and unknown methods. |
| 623 | foreach {configNm configArgs} { |
| 624 | none {} |
| 625 | export-no-file {export skin} |
| 626 | export-too-many {export skin x.cfg y} |
| 627 | export-none {export} |
| 628 | import-none {import} |
| 629 | import-too-many {import a b} |
| 630 | merge-none {merge} |
| 631 | merge-too-many {merge a b} |
| 632 | reset-none {reset} |
| 633 | reset-too-many {reset skin skin} |
| 634 | pull-none {pull} |
| 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 | ############################################################################### |
| 653 | # Merge: a value that the file has is taken where the repository has none |
| 654 | # or an older one; a value that the repository changed at the same time or |
| 655 | # later is kept. Nothing is removed. |
| 656 | |
| 657 | # A card for TABLE with TEXT as its content. |
| 658 | proc configCard {table text} { |
| 659 | return "config /$table [string length $text]\n$text\n" |
| 660 | } |
| 661 | |
| 662 | configNew m.fossil |
| 663 | fossil config merge subscribers.cfg -R m.fossil |
| 664 | fossil sql -R m.fossil " |
| 665 | INSERT INTO config(name,value,mtime) VALUES |
| 666 | ('css','local-css',1800000000), |
| 667 | ('header','local-header',5), |
| 668 | ('mainmenu','local-menu',1700000002), |
| 669 | ('walias:/docs','local-alias',1800000000), |
| 670 | ('walias:/only','only-here',5); |
| 671 | INSERT INTO user(login,pw,cap,info,mtime) VALUES |
| 672 | ('alice','local-pw','x','local',1800000000), |
| 673 | ('only','p','o','',5); |
| 674 | UPDATE user SET cap='o' WHERE login='tester'; |
| 675 | INSERT INTO shun(uuid,mtime,scom) VALUES |
| 676 | ('0123456789abcdef0123456789abcdef01234567',5,'old'), |
| 677 | ('only',5,'only here'); |
| 678 | INSERT INTO concealed(hash,mtime,content) VALUES |
| 679 | ('aaaa1111',1800000000,'[email protected]'), |
| 680 | ('only',5,'[email protected]'); |
| 681 | INSERT INTO reportfmt(owner,title,mtime,cols,sqlcode) VALUES |
| 682 | ('local','Mine',2400000,'','SELECT 0'), |
| 683 | ('local','Only',2400000,'','SELECT 0'); |
| 684 | UPDATE subscriber SET suname='local', mtime=1800000000 |
| 685 | WHERE semail='[email protected]'; |
| 686 | INSERT INTO subscriber(semail,mtime) VALUES('[email protected]',5); |
| 687 | " |
| 688 | configRun configuration merge export-all.cfg -R m.fossil |
| 689 | test config-merge {$CODE == 0 && $RESULT eq ""} |
| 690 | proc configMergeCheck {name sql expected} { |
| 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 |
| 702 | WHERE name='walias:/docs'" local-alias |
| 703 | configMergeCheck alias-absent-added "SELECT value FROM config |
| 704 | WHERE name='walias:/news'" /forum |
| 705 | configMergeCheck interwiki-added "SELECT value FROM config |
| 706 | WHERE name='interwiki:wp'" "https://en.wikipedia.org/wiki/%s" |
| 707 | configMergeCheck local-only-alias-kept "SELECT value FROM config |
| 708 | WHERE name='walias:/only'" only-here |
| 709 | configMergeCheck user-newer-local-kept "SELECT pw||cap||info FROM user |
| 710 | WHERE login='alice'" "local-pwxlocal" |
| 711 | configMergeCheck user-absent-added "SELECT count(*) FROM user |
| 712 | WHERE login='bob' AND mtime=1700006002" 1 |
| 713 | configMergeCheck user-local-only-kept "SELECT count(*) FROM user |
| 714 | WHERE login='only'" 1 |
| 715 | configMergeCheck shun-older-local-replaced "SELECT scom||'|'||mtime FROM shun |
| 716 | WHERE uuid='0123456789abcdef0123456789abcdef01234567'" \ |
| 717 | "it's spam|1700007000" |
| 718 | configMergeCheck shun-absent-added "SELECT count(*) FROM shun |
| 719 | WHERE uuid='fedcba9876543210fedcba9876543210fedcba98' AND scom IS NULL" 1 |
| 720 | configMergeCheck shun-local-only-kept "SELECT count(*) FROM shun |
| 721 | WHERE uuid='only'" 1 |
| 722 | configMergeCheck concealed-newer-local-kept "SELECT content FROM concealed |
| 723 | WHERE hash='aaaa1111'" [email protected] |
| 724 | configMergeCheck concealed-absent-added "SELECT content FROM concealed |
| 725 | WHERE hash='bbbb2222'" [email protected] |
| 726 | configMergeCheck concealed-local-only-kept "SELECT count(*) FROM concealed |
| 727 | WHERE hash='only'" 1 |
| 728 | configMergeCheck report-older-local-replaced "SELECT owner||'|'||sqlcode FROM |
| 729 | reportfmt WHERE title='Mine'" "alice|SELECT 1 AS 'x'" |
| 730 | configMergeCheck report-absent-added "SELECT count(*) FROM reportfmt |
| 731 | WHERE title='Theirs'" 1 |
| 732 | configMergeCheck report-local-only-kept "SELECT count(*) FROM reportfmt |
| 733 | WHERE title='Only'" 1 |
| 734 | configMergeCheck subscriber-newer-local-kept "SELECT suname FROM subscriber |
| 735 | WHERE semail='[email protected]'" local |
| 736 | configMergeCheck subscriber-absent-added "SELECT ssub FROM subscriber |
| 737 | WHERE semail='[email protected]'" ctw |
| 738 | configMergeCheck subscriber-local-only-kept "SELECT count(*) FROM subscriber |
| 739 | WHERE semail='[email protected]'" 1 |
| 740 | fossil test-integrity -R m.fossil |
| 741 | test config-merge-integrity {$CODE == 0} |
| 742 | |
| 743 | # The same file merged again changes nothing. |
| 744 | set configMerged [configState m.fossil all] |
| 745 | configRun configuration merge export-all.cfg -R m.fossil |
| 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 | ############################################################################### |
| 775 | # The literals of a card. A value is a string, a blob in hexadecimal, an |
| 776 | # integer or NULL; anything else is refused and the card does nothing. |
| 777 | |
| 778 | configNew l.fossil |
| 779 | proc configLiteral {name value expected} { |
| 780 | fossil sql -R l.fossil "DELETE FROM config WHERE name='header'" |
| 781 | write_file lit.cfg [configCard config "1700000000 'header' value $value"] |
| 782 | configRun configuration merge lit.cfg -R l.fossil |
| 783 | set got [configSql l.fossil "SELECT quote(value) FROM config |
| 784 | WHERE name='header'"] |
| 785 | test_eq config-literal-$name $got $expected |
| 786 | test config-literal-$name-exit {$::CODE == 0} |
| 787 | } |
| 788 | configLiteral string {'plain'} {'plain'} |
| 789 | configLiteral string-empty {''} {''} |
| 790 | configLiteral string-quote {'it''s'} {'it''s'} |
| 791 | configLiteral string-newline "'a\nb'" "'a\nb'" |
| 792 | configLiteral blob {x'41424344'} {X'41424344'} |
| 793 | configLiteral blob-upper {X'4a4B'} {X'4A4B'} |
| 794 | configLiteral blob-empty {x''} {X''} |
| 795 | configLiteral integer {12} {'12'} |
| 796 | # Text after the closing quote of a string is a token of its own, which is |
| 797 | # no field name, so it is skipped and the string stays the value. |
| 798 | configLiteral string-trailing {'a'b'} {'a'} |
| 799 | configLiteral string-concat {'a'||'b'} {'a'} |
| 800 | configLiteral null {NULL} {NULL} |
| 801 | configLiteral null-lower {null} {NULL} |
| 802 | configLiteral null-mixed {NuLl} {NULL} |
| 803 | foreach {configNm configValue} { |
| 804 | bare-word hello |
| 805 | float 1.5 |
| 806 | negative -5 |
| 807 | digits-letters 12ab |
| 808 | expression {1+1} |
| 809 | blob-odd {x'abc'} |
| 810 | blob-not-hex {x'zz'} |
| 811 | blob-open {x'ab} |
| 812 | blob-no-quote {xab} |
| 813 | blob-upper-no-quote {Xab} |
| 814 | blob-short {x'} |
| 815 | string-open {'abc} |
| 816 | string-open-doubled {'abc''} |
| 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 | } |
| 828 | |
| 829 | |
| 830 | ############################################################################### |
| 831 | # Files that are not well formed. A line that is no card is skipped; a card |
| 832 | # that is not well formed does nothing, and the cards after it are read as |
| 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 | |
| 878 | configMalformed empty-file "" 0 |
| 879 | configMalformed only-comments "# one\n# two\n\n\n" 0 |
| 880 | configMalformed junk-first-line "this is not a configuration file\n" 1 |
| 881 | configMalformed binary-junk "\x01\x02\x03\n\xff\xfe\n" 1 |
| 882 | configMalformed no-final-newline "config /config" 0 |
| 883 | configMalformed old-format "config css 5\nhello\n" 1 |
| 884 | configMalformed unknown-kind "config /nosuch $configLen\n$configBody\n" 1 |
| 885 | configMalformed upper-case "CONFIG /config $configLen\n$configBody\n" 1 |
| 886 | configMalformed first-char-of-kind "config Xconfig $configLen\n$configBody\n" 1 |
| 887 | configMalformed no-size "config /config\n$configBody\n" 1 |
| 888 | configMalformed no-kind "config\n$configBody\n" 1 |
| 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" |
| 905 | unknown-name "1700000600 'nosuch' value 'x'\n" |
| 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 |
| 920 | write_file big.cfg "config /config 100000\n$configBody" |
| 921 | configRun configuration $configMethod big.cfg -R c-$configMethod.fossil |
| 922 | test config-size-large-$configMethod {$CODE == 0 && |
| 923 | [configSql c-$configMethod.fossil "SELECT value FROM config |
| 924 | WHERE name='css'"] eq "new"} |
| 925 | } |
| 926 | |
| 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'" |
| 952 | configRun configuration merge many.cfg -R k.fossil |
| 953 | test_eq config-fields-many-kept [configSql k.fossil "SELECT info FROM user |
| 954 | WHERE login='carol'"] v10 |
| 955 | |
| 956 | # A card whose key or value is no literal does not reach the database. |
| 957 | foreach {configNm configText} { |
| 958 | semicolon {'x'; DROP TABLE shun; --} |
| 959 | quote-break {'x'');DELETE FROM user;--'} |
| 960 | subquery {(SELECT 1)} |
| 961 | function {char(65)} |
| 962 | } { |
| 963 | set configCardBody "1700000600 $configText\n" |
| 964 | write_file inj.cfg "[configCard shun $configCardBody]" |
| 965 | configRun configuration merge inj.cfg -R k.fossil |
| 966 | test config-literal-no-sql-$configNm {$CODE == 0 && |
| 967 | [configSql k.fossil "SELECT count(*) FROM sqlite_schema |
| 968 | WHERE name IN ('shun','user')"] == 2} |
| 969 | } |
| 970 | |
| 971 | ############################################################################### |
| 972 | # Settings that the file may not set: the ones that no area holds (the |
| 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" |
| 985 | write_file ne.cfg [configCard config $configCardBody] |
| 986 | configRun configuration import ne.cfg -R n.fossil |
| 987 | test config-not-exportable-$configNm {$CODE == 0 && |
| 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" |
| 1000 | no-value "1700000600 'nosuch'\n" |
| 1001 | } { |
| 1002 | write_file ne.cfg [configCard config $configCardBody] |
| 1003 | configRun configuration merge ne.cfg -R n.fossil |
| 1004 | test config-not-exportable-$configNm {$CODE == 0 && |
| 1005 | [string first "Skipping non-exportable setting: " $RESULT] >= 0} |
| 1006 | if {$configNm eq "no-value"} { |
| 1007 | test config-not-exportable-no-value-said {[string first "= ?" $RESULT] >= 0} |
| 1008 | } |
| 1009 | test_eq config-not-exportable-$configNm-unchanged [configDump n.fossil] \ |
| 1010 | $configNBefore |
| 1011 | } |
| 1012 | |
| 1013 | # Names quoted as a literal are read without the quotes; a name that holds |
| 1014 | # a quote can still be a setting of an area. |
| 1015 | set configCardBody "1700000600 'walias:/it''s' value '/x'\n" |
| 1016 | write_file ne.cfg [configCard config $configCardBody] |
| 1017 | configRun configuration merge ne.cfg -R n.fossil |
| 1018 | test_eq config-name-quoted [configSql n.fossil "SELECT value FROM config |
| 1019 | WHERE name='walias:/it''s'"] /x |
| 1020 | |
| 1021 | |
| 1022 | ############################################################################### |
| 1023 | # Push, pull and sync with a repository named by its file: the client starts |
| 1024 | # "fossil http" on the file, so both sides speak the whole protocol and the |
| 1025 | # other side grants everything. Each area that is pulled arrives as the |
| 1026 | # other side holds it, each that is pushed is there afterwards, and nothing |
| 1027 | # outside the area changes. The users are left out of the comparison: |
| 1028 | # those that a repository made for itself have no time of change, and a |
| 1029 | # merge does not replace them. |
| 1030 | |
| 1031 | set configSrv [file join $configDir a.fossil] |
| 1032 | |
| 1033 | # The parts of AREA that a comparison looks at. |
| 1034 | proc configParts {area} { |
| 1035 | if {$area eq "all"} { |
| 1036 | return {skin project ticket xfer alias interwiki email shun subscriber |
| 1037 | user} |
| 1038 | } |
| 1039 | return $area |
| 1040 | } |
| 1041 | |
| 1042 | # Test that REPO holds what EXPECTED holds, as an export of it, for AREA. |
| 1043 | proc configSameAs {name repo area expected} { |
| 1044 | foreach part [configParts $area] { |
| 1045 | if {$part eq "user"} { |
| 1046 | set sql "SELECT name, value, mtime FROM config |
| 1047 | WHERE name='user-color-map'; |
| 1048 | SELECT login,quote(pw),cap,info,quote(photo),mtime FROM user |
| 1049 | WHERE login IN ('alice','bob') ORDER BY login" |
| 1050 | test_eq $name-$part [configSql $repo $sql] [configSql $expected $sql] |
| 1051 | } else { |
| 1052 | test_eq $name-$part [configState $repo $part] \ |
| 1053 | [configState $expected $part 1] |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | foreach configArea $configAreas { |
| 1059 | # Pull. |
| 1060 | set configC cl-pull-$configArea.fossil |
| 1061 | configNew $configC |
| 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 | |
| 1086 | |
| 1087 | # Sync sends and receives. Each side gets what only the other has, and for |
| 1088 | # a value that both have, the one changed last wins on both. |
| 1089 | configNew s1.fossil |
| 1090 | configNew s2.fossil |
| 1091 | configPut s1.fossil {walias:/only1 {'one'} walias:/both {'old-1'} |
| 1092 | walias:/tie {'tie-1'}} 1700000000 |
| 1093 | fossil sql -R s1.fossil "UPDATE config SET mtime=1700000100 |
| 1094 | WHERE name='walias:/both'" |
| 1095 | fossil sql -R s1.fossil "UPDATE config SET mtime=1700000300 |
| 1096 | WHERE name='walias:/tie'" |
| 1097 | configPut s2.fossil {walias:/only2 {'two'} walias:/both {'new-2'} |
| 1098 | walias:/tie {'tie-2'}} 1700000000 |
| 1099 | fossil sql -R s2.fossil "UPDATE config SET mtime=1700000200 |
| 1100 | WHERE name='walias:/both'" |
| 1101 | fossil sql -R s2.fossil "UPDATE config SET mtime=1700000300 |
| 1102 | WHERE name='walias:/tie'" |
| 1103 | configRun configuration sync alias [file join $configDir s2.fossil] -R s1.fossil |
| 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 ""} |
| 1133 | test_eq config-pull-overwrite-user-local-gone [configSql o1.fossil "SELECT |
| 1134 | count(*) FROM user WHERE login='local'"] 0 |
| 1135 | test_eq config-pull-overwrite-user-remote [configSql o1.fossil "SELECT |
| 1136 | count(*) FROM user WHERE login='remote'"] 1 |
| 1137 | |
| 1138 | # --overwrite is an option of pull only. |
| 1139 | configRun configuration push shun --overwrite [file join $configDir o2.fossil] \ |
| 1140 | -R o1.fossil |
| 1141 | test config-push-overwrite {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} |
| 1142 | configRun configuration sync shun --overwrite [file join $configDir o2.fossil] \ |
| 1143 | -R o1.fossil |
| 1144 | test config-sync-overwrite {$CODE == 1 && [string first "Usage:" $RESULT] >= 0} |
| 1145 | |
| 1146 | # Without a URL the command uses the default server; with none it stops. |
| 1147 | configNew u1.fossil |
| 1148 | configRun configuration pull skin -R u1.fossil |
| 1149 | test config-pull-no-server {$CODE == 1 && |
| 1150 | [string first "no server URL specified" $RESULT] >= 0} |
| 1151 | configRun configuration push skin -R u1.fossil |
| 1152 | test config-push-no-server {$CODE == 1} |
| 1153 | configRun configuration sync skin -R u1.fossil |
| 1154 | test config-sync-no-server {$CODE == 1} |
| 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 |
| 1171 | # is answered with nothing, and an area it knows with its cards. |
| 1172 | |
| 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. |
| 1186 | |
| 1187 | configNew old.fossil |
| 1188 | fossil sql -R old.fossil "ALTER TABLE user DROP COLUMN jx; |
| 1189 | ALTER TABLE reportfmt DROP COLUMN jx; |
| 1190 | UPDATE user SET mtime=5" |
| 1191 | configRun configuration export all old.cfg -R old.fossil |
| 1192 | test config-export-old-schema {$CODE == 0 && |
| 1193 | [string first " jx " [read_file old.cfg]] < 0 && |
| 1194 | [configKinds old.cfg] eq "/config /reportfmt /user"} |
| 1195 | configNew old2.fossil |
| 1196 | configRun configuration import old.cfg -R old2.fossil |
| 1197 | test config-import-old-schema {$CODE == 0 && |
| 1198 | [configSql old2.fossil "SELECT login FROM user WHERE login='tester'"] eq |
| 1199 | "tester"} |
| 1200 | |
| 1201 | ############################################################################### |
| 1202 | # The settings table by hand: test-var-set, test-var-get and test-var-list. |
| 1203 | |
| 1204 | configNew v.fossil |
| 1205 | fossil test-var-set alpha hello -R v.fossil |
| 1206 | test config-var-set {$CODE == 0} |
| 1207 | fossil test-var-get alpha -R v.fossil |
| 1208 | test_eq config-var-get $RESULT hello |
| 1209 | fossil test-var-get alpha out.txt -R v.fossil |
| 1210 | test_eq config-var-get-file [read_file out.txt] hello |
| 1211 | fossil test-var-get alpha - -R v.fossil |
| 1212 | test_eq config-var-get-stdout $RESULT hello |
| 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 |
| 1224 | test_eq config-var-set-blob-type [configSql v.fossil "SELECT typeof(value) FROM |
| 1225 | config WHERE name='gamma'"] blob |
| 1226 | fossil_raw -input "piped in\n" test-var-set delta --file - -R v.fossil |
| 1227 | test config-var-set-stdin {$CODE == 0} |
| 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 | |
| 1252 | # The list: names and values in two columns, control characters written as |
| 1253 | # escapes, long values cut with the count of what is left, long names on a |
| 1254 | # line of their own. |
| 1255 | set configLongValue [string repeat abcdefghij 6] |
| 1256 | set configLongName1 a-name-that-is-long-but-with-a-short-value |
| 1257 | set configLongName2 a-name-that-is-long-with-a-value-that-is-long-too-and-so-on |
| 1258 | set configMidName a-name-that-is-between-the-two-lengths |
| 1259 | configNew w.fossil |
| 1260 | fossil sql -R w.fossil "DELETE FROM config WHERE NOT name GLOB 'a*'; |
| 1261 | INSERT INTO config(name,value,mtime) VALUES |
| 1262 | ('a-short','plain',1700000000), |
| 1263 | ('a-ctl','x'||char(10)||char(13)||char(9)||char(1)||'y',1700000001), |
| 1264 | ('a-long','$configLongValue',1700000002), |
| 1265 | ('$configLongName1','v',1700000003), |
| 1266 | ('$configLongName2','a value that has more than ten characters', |
| 1267 | 1700000004), |
| 1268 | ('$configMidName','x',1700000005), |
| 1269 | ('$configMidName-long','a value that has more than ten characters', |
| 1270 | 1700000006), |
| 1271 | ('a-high','caf'||char(233)||char(127),1700000007)" |
| 1272 | # A line for NAME that has its value in the column that NAME's length gives. |
| 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" \ |
| 1284 | $configList] >= 0} |
| 1285 | test config-var-list-long-name-short-value {[string first \ |
| 1286 | "[configListLine $configLongName1 v 59]\n" $configList] >= 0} |
| 1287 | test config-var-list-long-name-long-value {[string first \ |
| 1288 | "$configLongName2:\n[string repeat { } 28]a value that has more than ten\ |
| 1289 | character...+1\n" $configList] >= 0} |
| 1290 | test config-var-list-mid-name {[string first \ |
| 1291 | "[configListLine $configMidName x 59]\n" $configList] >= 0} |
| 1292 | test config-var-list-mid-name-long-value {[string first \ |
| 1293 | "$configMidName-long:\n[string repeat { } 28]a value that has more than ten\ |
| 1294 | character...+1\n" $configList] >= 0} |
| 1295 | test config-var-list-high-bytes {[string first \ |
| 1296 | "[configListLine a-high {caf\303\251\177} 27]\n" $configList] >= 0} |
| 1297 | configRun test-var-list "a-s*" -R w.fossil |
| 1298 | test_eq config-var-list-pattern [string trimright $RESULT] \ |
| 1299 | [configListLine a-short plain 27] |
| 1300 | configRun test-var-list "a-s*" --mtime -R w.fossil |
| 1301 | test_eq config-var-list-mtime [string trimright $RESULT] \ |
| 1302 | [configListLine a-short "2023-11-14 22:13:20" 58] |
| 1303 | configRun test-var-list nosuch -R w.fossil |
| 1304 | test_eq config-var-list-none $RESULT "" |
| 1305 | # Delete only on an answer of y, and only with a pattern. |
| 1306 | set configCount [configSql w.fossil "SELECT count(*) FROM config"] |
| 1307 | fossil_raw -input "n\n" test-var-list "a-s*" --unset -R w.fossil |
| 1308 | test config-var-unset-no {$CODE == 0 && [configSql w.fossil "SELECT count(*) |
| 1309 | FROM config WHERE name='a-short'"] == 1} |
| 1310 | fossil_raw -input "y\n" test-var-list --unset -R w.fossil |
| 1311 | test config-var-unset-no-pattern {[configSql w.fossil "SELECT count(*) FROM |
| 1312 | config"] == $configCount} |
| 1313 | fossil_raw -input "Y\n" test-var-list "a-s*" --unset -R w.fossil |
| 1314 | test config-var-unset-capital {[configSql w.fossil "SELECT count(*) FROM config |
| 1315 | WHERE name='a-short'"] == 0} |
| 1316 | fossil_raw -input "y\n" test-var-list "a-s*" --unset -R w.fossil |
| 1317 | test config-var-unset-yes {$CODE == 0 && [configSql w.fossil "SELECT count(*) |
| 1318 | FROM config WHERE name='a-short'"] == 0} |
| 1319 | |
| 1320 | ############################################################################### |
| 1321 | # The rest of the file needs a TCP connection over the loopback interface. |
| 1322 | |
| 1323 | if {![loopback_available]} { |
| 1324 | unset ::env(FOSSIL_USER) |
| 1325 | test_skip "no TCP connection over the loopback interface" |
| 1326 | } |
| 1327 | |
| 1328 | ############################################################################### |
| 1329 | # Pull and push to a server that checks the login card. What a pull brings |
| 1330 | # depends on the capabilities of the user on the server: every area comes |
| 1331 | # to anyone who may read, except the concealed email addresses (capability |
| 1332 | # e), the users and the subscribers (a). A push needs capability a; for a |
| 1333 | # user without it, the server refuses and holds what it held. |
| 1334 | |
| 1335 | # Make a server repository FILE that has the configuration of a.fossil and |
| 1336 | # the users that these tests log in as, and return it. |
| 1337 | proc configServer {file} { |
| 1338 | file copy -force a.fossil $file |
| 1339 | fossil sql -R $file " |
| 1340 | INSERT INTO user(login,pw,cap) VALUES |
| 1341 | ('rdr','pw','o'), ('eml','pw','oe'), ('adm','pw','a'), ('blind','pw','j'); |
| 1342 | " |
| 1343 | return $file |
| 1344 | } |
| 1345 | |
| 1346 | # Give REPO the project code of a.fossil: a client makes its login card from |
| 1347 | # its own project code, so it must be the server's. |
| 1348 | proc configShareProject {repo} { |
| 1349 | global configProjectCode |
| 1350 | if {![info exists configProjectCode]} { |
| 1351 | set configProjectCode [configSql a.fossil "SELECT value FROM config |
| 1352 | WHERE name='project-code'"] |
| 1353 | } |
| 1354 | fossil sql -R $repo "UPDATE config SET value='$configProjectCode' |
| 1355 | WHERE name='project-code'" |
| 1356 | } |
| 1357 | |
| 1358 | # Run VERB on repository CLIENT against the server on PORT, logged in as |
| 1359 | # USER, who has the password "pw", or as nobody for an empty USER. |
| 1360 | proc configNetRun {verb area client port user} { |
| 1361 | set at [expr {$user eq "" ? "" : "$user:pw@"}] |
| 1362 | configRun configuration $verb $area http://${at}127.0.0.1:$port/ -R $client |
| 1363 | } |
| 1364 | |
| 1365 | # Whether USER may pull PART of the configuration. |
| 1366 | proc configMayPull {user part} { |
| 1367 | switch -- $part { |
| 1368 | email {return [expr {$user in {eml adm}}]} |
| 1369 | user - subscriber {return [expr {$user eq "adm"}]} |
| 1370 | } |
| 1371 | return [expr {$user ne "blind"}] |
| 1372 | } |
| 1373 | |
| 1374 | # Test that REPO holds PART as the server's repository does if WANT is true, |
| 1375 | # and as a new repository does if it is false. |
| 1376 | proc configHasPart {name repo part want} { |
| 1377 | if {$part eq "user"} { |
| 1378 | set sql "SELECT count(*) FROM user WHERE login IN ('alice','bob') |
| 1379 | AND mtime IS NOT NULL; |
| 1380 | SELECT count(*) FROM config WHERE name='user-color-map'" |
| 1381 | test_eq $name-$part [configSql $repo $sql] \ |
| 1382 | [expr {$want ? "2\n1" : "0\n0"}] |
| 1383 | } elseif {$want} { |
| 1384 | test_eq $name-$part [configState $repo $part] \ |
| 1385 | [configState a.fossil $part 1] |
| 1386 | } else { |
| 1387 | test_eq $name-$part [configState $repo $part 0 1] [configDefaults $part] |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | configServer ps.fossil |
| 1392 | set configServerProc [test_start_server ps.fossil configStop] |
| 1393 | set configPort [lindex $configServerProc 1] |
| 1394 | # Each pair is a user and an area to pull as that user. |
| 1395 | foreach {configUser configArea} {{} skin {} all eml email eml user adm all |
| 1396 | blind skin} { |
| 1397 | set configLabel [expr {$configUser eq "" ? "nobody" : $configUser}] |
| 1398 | if {$configUser eq "blind"} { |
| 1399 | # A user whose capabilities, with those of nobody, include no reading. |
| 1400 | fossil sql -R ps.fossil "UPDATE user SET cap='' WHERE login IN |
| 1401 | ('nobody','anonymous')" |
| 1402 | } |
| 1403 | set configC cp-$configLabel-$configArea.fossil |
| 1404 | configNew $configC |
| 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} |
| 1416 | } |
| 1417 | } |
| 1418 | test_stop_server $configStop [lindex $configServerProc 0] \ |
| 1419 | [lindex $configServerProc 2] |
| 1420 | |
| 1421 | configNew cs-base.fossil |
| 1422 | configShareProject cs-base.fossil |
| 1423 | fossil sql -R cs-base.fossil "INSERT INTO user(login,pw,cap) VALUES |
| 1424 | ('rdr','pw','o'), ('eml','pw','oe'), ('adm','pw','a')" |
| 1425 | file copy -force cs-base.fossil cs.fossil |
| 1426 | set configServerProc [test_start_server cs.fossil configStop] |
| 1427 | set configPort [lindex $configServerProc 1] |
| 1428 | # Each pair is a user and an area to push as that user; only adm may push. |
| 1429 | foreach {configUser configArea} {{} skin adm email adm user adm all} { |
| 1430 | set configLabel [expr {$configUser eq "" ? "nobody" : $configUser}] |
| 1431 | file copy -force cs-base.fossil cs.fossil |
| 1432 | set configPre [configDump cs.fossil] |
| 1433 | configNetRun push $configArea a.fossil $configPort $configUser |
| 1434 | if {$configUser eq "adm"} { |
| 1435 | test config-push-$configLabel-$configArea {$CODE == 0} |
| 1436 | foreach configPart [configParts $configArea] { |
| 1437 | configHasPart config-push-$configLabel-$configArea-has cs.fossil \ |
| 1438 | $configPart 1 |
| 1439 | } |
| 1440 | } else { |
| 1441 | test config-push-$configLabel-$configArea-refused { |
| 1442 | [string first "not authorized to push configuration" $RESULT] >= 0} |
| 1443 | test config-push-refused-status {$CODE == 1} |
| 1444 | test_eq config-push-$configLabel-$configArea-unchanged \ |
| 1445 | [configDump cs.fossil] $configPre |
| 1446 | } |
| 1447 | } |
| 1448 | test_stop_server $configStop [lindex $configServerProc 0] \ |
| 1449 | [lindex $configServerProc 2] |
| 1450 | |
| 1451 | ############################################################################### |
| 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]] |
| 1483 | } |
| 1484 | lappend ::configFakeRequests $body |
| 1485 | if {[incr ::configFakeCount] == 1} { |
| 1486 | set reply $::configFakeReply |
| 1487 | } else { |
| 1488 | set reply "# timestamp 2026-01-01T00:00:00 errors 0\n" |
| 1489 | } |
| 1490 | catch { |
| 1491 | puts -nonewline $chan "HTTP/1.0 200 OK\r\nContent-Type:\ |
| 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 |
| 1504 | set configFakeRequests {} |
| 1505 | configRun configuration $verb $area http://127.0.0.1:$configFakePort/ \ |
| 1506 | -R rp.fossil |
| 1507 | } |
| 1508 | |
| 1509 | configNew rp.fossil |
| 1510 | set configRpReply [configCard config "1700000000 'header' value 'asked'"] |
| 1511 | append configRpReply [configCard config "1700000000 'project-name' value 'not'"] |
| 1512 | append configRpReply [configCard user "1700000000 'zed' cap 's'"] |
| 1513 | append configRpReply [configCard nosuch "1700000000 'zed' cap 's'"] |
| 1514 | append configRpReply [configCard config "1700000000 'adunit' value 'asked'"] |
| 1515 | configReply pull skin $configRpReply |
| 1516 | test config-reply-unasked {$CODE == 0} |
| 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. |
| 1528 | proc configAsked {} { |
| 1529 | return [regexp -all {reqconfig [^\n]*} [lindex $::configFakeRequests 0]] |
| 1530 | } |
| 1531 | # The style sheet is part of the skin, so both are asked for; only the style |
| 1532 | # sheet is taken. |
| 1533 | test config-reply-request-css {[configAsked] == 2 && |
| 1534 | [string first "reqconfig /skin\nreqconfig /css\n" \ |
| 1535 | [lindex $configFakeRequests 0]] >= 0} |
| 1536 | configReply pull all "" |
| 1537 | test config-reply-request-all {[configAsked] == 1 && |
| 1538 | [string first "reqconfig /all\n" [lindex $configFakeRequests 0]] >= 0} |
| 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 | |
| 1551 | configNew tpl.fossil |
| 1552 | fossil sql -R tpl.fossil " |
| 1553 | INSERT OR REPLACE INTO config(name,value,mtime) VALUES |
| 1554 | ('css','from-template',1700000000), |
| 1555 | ('ticket-title-expr','from-template',1700000000), |
| 1556 | ('walias:/tpl','/timeline',1700000000), |
| 1557 | ('project-name','Template Project',1700000000), |
| 1558 | ('short-project-name','tpl',1700000000), |
| 1559 | ('config-test-other','from-template',1700000000)" |
| 1560 | configRun init --template tpl.fossil fromtpl.fossil |
| 1561 | test config-init-template {$CODE == 0} |
| 1562 | test_eq config-init-template-copied [configSql fromtpl.fossil " |
| 1563 | SELECT group_concat(name||'='||value, ' ') FROM (SELECT name, value |
| 1564 | FROM config WHERE name IN ('css','ticket-title-expr','walias:/tpl', |
| 1565 | 'project-name','short-project-name','config-test-other') |
| 1566 | ORDER BY name)"] \ |
| 1567 | "css=from-template ticket-title-expr=from-template walias:/tpl=/timeline" |
| 1568 | |
| 1569 | test_cleanup |
| 1570 | unset ::env(FOSSIL_USER) |
+26
| --- a/test/content.test | ||
| +++ b/test/content.test | ||
| @@ -0,0 +1,26 @@ | ||
| 1 | +##### These tests run only in a long pass: -assurance stress. | |
| 2 | +if {[test_assurance] ne "stress"} { | |
| 3 | + test_skip "runs only with -assurance stress" | |
| 4 | +}sql {sql} { | |
| 5 | +RESULT] | |
| 6 | +}contentThe hash that Fossil hash {filename} { | |
| 7 | + global RESULTcontentcontent_sql \ | |
| 8 | + content########contentcontentSrc--forceforced [contentcontent_hashcontent_hash small2contentcontentcontent_hash other.txt]]contentcontent_hashcontentRid"] 0contentcontent_hash###content_hashcontentcontent####Farcontentcontentcontent_hashcontent_hash latlcontentcontentcontent_hashcontentcontent1contentcontentcontent_hashcontent_hash 6}content_hashcontent_hashcontent_hash \ | |
| 9 | + technote "30:00.000\nU alice\nW 1\nx#}"SHUNNED: $cont< 0}####contentsrccontentcontentcontentSmall"] 0content_hashcontentcontentcontentcontent_sha1 and drops the. | |
| 10 | + the | |
| 11 | +# cache fills an | |
| 12 | +# | |
| 13 | +.fossil { | |
| 14 | + END) | |
| 15 | + FROM v; | |
| 16 | +} | |
| 17 | +# The cache alsoies while it holds more than 256 MB, | |
| 18 | +# as many as it takes. Each version here is a longer prefix of one random | |
| 19 | +# text, up to 18 MB, so the oldest entries are the smallest and dropping | |
| 20 | +# one is not always enough. | |
| 21 | + | |
| 22 | +-sizeCREATE TEMP TABLE r(x BLOB); | |
| 23 | + INSERT INTO r VALUES(hex(randomblob(9000000))); | |
| 24 | +); | |
| 25 | +299) | |
| 26 | + INSE |
| --- a/test/content.test | |
| +++ b/test/content.test | |
| @@ -0,0 +1,26 @@ | |
| --- a/test/content.test | |
| +++ b/test/content.test | |
| @@ -0,0 +1,26 @@ | |
| 1 | ##### These tests run only in a long pass: -assurance stress. |
| 2 | if {[test_assurance] ne "stress"} { |
| 3 | test_skip "runs only with -assurance stress" |
| 4 | }sql {sql} { |
| 5 | RESULT] |
| 6 | }contentThe hash that Fossil hash {filename} { |
| 7 | global RESULTcontentcontent_sql \ |
| 8 | content########contentcontentSrc--forceforced [contentcontent_hashcontent_hash small2contentcontentcontent_hash other.txt]]contentcontent_hashcontentRid"] 0contentcontent_hash###content_hashcontentcontent####Farcontentcontentcontent_hashcontent_hash latlcontentcontentcontent_hashcontentcontent1contentcontentcontent_hashcontent_hash 6}content_hashcontent_hashcontent_hash \ |
| 9 | technote "30:00.000\nU alice\nW 1\nx#}"SHUNNED: $cont< 0}####contentsrccontentcontentcontentSmall"] 0content_hashcontentcontentcontentcontent_sha1 and drops the. |
| 10 | the |
| 11 | # cache fills an |
| 12 | # |
| 13 | .fossil { |
| 14 | END) |
| 15 | FROM v; |
| 16 | } |
| 17 | # The cache alsoies while it holds more than 256 MB, |
| 18 | # as many as it takes. Each version here is a longer prefix of one random |
| 19 | # text, up to 18 MB, so the oldest entries are the smallest and dropping |
| 20 | # one is not always enough. |
| 21 | |
| 22 | -sizeCREATE TEMP TABLE r(x BLOB); |
| 23 | INSERT INTO r VALUES(hex(randomblob(9000000))); |
| 24 | ); |
| 25 | 299) |
| 26 | INSE |
+128
| --- a/test/corpus.tcl | ||
| +++ b/test/corpus.tcl | ||
| @@ -0,0 +1,128 @@ | ||
| 1 | +# The test corpus: inputs for "fossil test-fuzz" and for scenario.test, | |
| 2 | +# all kept in the one file corpus/corpus.pack. Many small files would | |
| 3 | +# each add a line to every check-in manifest of the project, so they are | |
| 4 | +# packed and unpacked into the test's own directory when a test runs. The | |
| 5 | +# pack is in a directory of its own because merge2.test runs every file | |
| 6 | +# directly in this directory through a three-way merge. | |
| 7 | +# | |
| 8 | +# tclsh corpus.tcl unpack corpus/corpus.pack DIR write DIR/TYPE/NAME | |
| 9 | +# tclsh corpus.tcl pack DIR corpus/corpus.pack pack DIR/TYPE/NAME | |
| 10 | +# | |
| 11 | +# To add an input: unpack, add the file, pack, and check that the pack | |
| 12 | +# changed only by the new record. A fuzzing engine such as AFL++ or | |
| 13 | +# libFuzzer can use an unpacked directory as its starting corpus, and | |
| 14 | +# "fossil test-fuzz DIR/TYPE" runs one directory through its target. | |
| 15 | +# | |
| 16 | +# The pack is a few lines that begin with "#", then one record per file: | |
| 17 | +# | |
| 18 | +# == TYPE/NAME LENGTH | |
| 19 | +# LENGTH bytes of content, then a newline | |
| 20 | +# | |
| 21 | +# Records are sorted by TYPE/NAME, so packing the same files gives the | |
| 22 | +# same pack. | |
| 23 | +# | |
| 24 | +# TYPE is the fuzz target the file is an input to, or "scenario". | |
| 25 | +# | |
| 26 | +# Each input is a case that its target must handle without a crash, a | |
| 27 | +# report from a run-time checker, or a failed property. When a fuzzer | |
| 28 | +# finds athat once showed ainput is added | |
| 29 | +# once the defect is fixed, named for what it showed. | |
| 30 | +# | |
| 31 | +# The delta targets take a pair of files as one input: two bytes giving | |
| 32 | +# the size of the first file, most significant byte first, then the | |
| 33 | +# first file, then the second. | |
| 34 | +# | |
| 35 | +# delta-roundtrip: the pair is a source and a target. A delta is made | |
| 36 | +# from one to the other and must reproduce the target. | |
| 37 | +# | |
| 38 | +# delta-apply, delta-accept, delta-reject: the pair is a source and a | |
| 39 | +# delta. All three apply the delta and check the same properties. | |
| 40 | +# delta-accept also requires that the delta be accepted, and | |
| 41 | +# delta-reject that it be refused, so those inputs are examples with a | |
| 42 | +# known answer. The delta-accept inputs whose names begin with "ok-" | |
| 43 | +# hold deltas made by Fossil. Each delta-reject input is named for what | |
| 44 | +# is wrong with it. A fuzzing engine should be pointed at delta-apply, | |
| 45 | +# with all three as its starting corpus. | |
| 46 | +# | |
| 47 | +# manifest: each input is one structural artifact: a check-in, tag, wiki | |
| 48 | +# page, ticket, technote, attachment or forum post. The inputs whose | |
| 49 | +# names begin with "ok-" were made by Fossil. The rest are one of those | |
| 50 | +# with a single card changed, and a Z card that is still correct so that | |
| 51 | +# the parser reads as far as the change. Names give the cards of the | |
| 52 | +# artifact, the card that was changed, and how. | |
| 53 | +# | |
| 54 | +# manifest-body: each input is an artifact without its Z card. The | |
| 55 | +# target adds the right one, so every input reaches the parser proper. | |
| 56 | +# This is the corpus to give a fuzzing engine, which cannot produce a | |
| 57 | +# matching checksum by changing bytes. The inputs named with card | |
| 58 | +# letters only are the "ok-" inputs of manifest with the Z card removed. | |
| 59 | +# A name with a suffix after the letters is an input for one particular | |
| 60 | +# defect. The "fuzz-" inputs were found by libFuzzer and are kept for | |
| 61 | +# the branches of manifest.c they reach: a run from the other inputs was | |
| 62 | +# reduced with -set_cover_merge=1, and from the result a small set was | |
| 63 | +# chosen that still takes every branch outcome in manifest.c the whole | |
| 64 | +# set takes. Their names give the card letters that begin a line, then | |
| 65 | +# part of the SHA1 of the content. | |
| 66 | +# | |
| 67 | +# Every manifest and manifest-body input begins with two lines that | |
| 68 | +# start with "#". They are not part of the input: the target removes | |
| 69 | +# them. They are there because Fossil treats any file whose content is | |
| 70 | +# a well-formed artifact as a real one. Without them, a repository that | |
| 71 | +# received an unpacked input by sync, or was rebuilt while holding it, | |
| 72 | +# would show it as a check-in, wiki page or ticket of its own. A new | |
| 73 | +# input of either type must begin with the same two lines; fuzz.test | |
| 74 | +# checks that each one does, and that Fossil accepts neither the pack | |
| 75 | +# nor any unpacked input as an artifact as stored. | |
| 76 | +# | |
| 77 | +# xfer: each input is the body of one sync request as a client sends it | |
| 78 | +# to a server, not compressed. The target serves it from a small | |
| 79 | +# repository that is the same for every input; fuzz_xfer_setup() in | |
| 80 | +# src/fuzz.c says what it holds. The pull and push cards give that | |
| 81 | +# repository's project code, and the gimme cards and delta sources are | |
| 82 | +# its artifacts. An input is named for the cards it holds. | |
| 83 | +# | |
| 84 | +# scenario: these are not inputs to a fuzz target. Each is a random | |
| 85 | +# integration test of sync, run by scenario.test: a list of four-byte | |
| 86 | +# records, each one operation on one of three clones of a new | |
| 87 | +# repository: operation, clone, argument, option. See scenario.test for | |
| 88 | +# the operations. A sync can be told to lose its request, lose its | |
| 89 | +# reply or deliver half a reply. A sync, pull, push or clone that is | |
| 90 | +# not told to go wrong must deliver everything at once. The clones are | |
| 91 | +# synced at the end and must then be sound and identical. Each input | |
| 92 | +# takes a second or two, because every operation is a separate run of | |
| 93 | +# fossil. An input is named for what it tests. | |
| 94 | +# | |
| 95 | + | |
| 96 | +# Write every record of the pack PACK as a file DIR/TYPE/NAME and return | |
| 97 | +# the list of TYPE directories made, sorted. A malformed pack is an | |
| 98 | +# error. | |
| 99 | +# | |
| 100 | +proc corpus_unpack {pack dir} { | |
| 101 | + set fd [open $pack rb] | |
| 102 | + set data [read $fd] | |
| 103 | + close $fd | |
| 104 | + set at 0 | |
| 105 | + set end [string length $data] | |
| 106 | + # The comment lines at the top. | |
| 107 | + while {$at < $end && [string index $data $at] eq "#"} { | |
| 108 | + set nl [string first \n $data $at] | |
| 109 | + if {$nl < 0} { error "$pack: no newline after a comment line" } | |
| 110 | + set at [expr {$nl + 1}] | |
| 111 | + } | |
| 112 | + set types {} | |
| 113 | + while {$at < $end} { | |
| 114 | + set nl [string first \n $data $at] | |
| 115 | + if {$nl < 0} { error "$pack: no newline after a record header" } | |
| 116 | + set header [string range $data $at [expr {$nl - 1}]] | |
| 117 | + if {![regexp {^== ([a-z0-9-]+)/([A-Za-z0-9._+-]+) ([0-9]+)$} $header \ | |
| 118 | + all type name len] | |
| 119 | + || [string index $name 0] eq "."} { | |
| 120 | + error "$pack: malformed record header \"$header\"" | |
| 121 | + } | |
| 122 | + set len [scan $len %d] | |
| 123 | + set from [expr {$nl + 1}] | |
| 124 | + set to [expr {$from + $len}] | |
| 125 | + if {$to >= $end || [string index $data $to] ne "\n"} { | |
| 126 | + error "$pack: record $type/$name is cut short" | |
| 127 | + } | |
| 128 | + set path [file join $dir $type $name] |
| --- a/test/corpus.tcl | |
| +++ b/test/corpus.tcl | |
| @@ -0,0 +1,128 @@ | |
| --- a/test/corpus.tcl | |
| +++ b/test/corpus.tcl | |
| @@ -0,0 +1,128 @@ | |
| 1 | # The test corpus: inputs for "fossil test-fuzz" and for scenario.test, |
| 2 | # all kept in the one file corpus/corpus.pack. Many small files would |
| 3 | # each add a line to every check-in manifest of the project, so they are |
| 4 | # packed and unpacked into the test's own directory when a test runs. The |
| 5 | # pack is in a directory of its own because merge2.test runs every file |
| 6 | # directly in this directory through a three-way merge. |
| 7 | # |
| 8 | # tclsh corpus.tcl unpack corpus/corpus.pack DIR write DIR/TYPE/NAME |
| 9 | # tclsh corpus.tcl pack DIR corpus/corpus.pack pack DIR/TYPE/NAME |
| 10 | # |
| 11 | # To add an input: unpack, add the file, pack, and check that the pack |
| 12 | # changed only by the new record. A fuzzing engine such as AFL++ or |
| 13 | # libFuzzer can use an unpacked directory as its starting corpus, and |
| 14 | # "fossil test-fuzz DIR/TYPE" runs one directory through its target. |
| 15 | # |
| 16 | # The pack is a few lines that begin with "#", then one record per file: |
| 17 | # |
| 18 | # == TYPE/NAME LENGTH |
| 19 | # LENGTH bytes of content, then a newline |
| 20 | # |
| 21 | # Records are sorted by TYPE/NAME, so packing the same files gives the |
| 22 | # same pack. |
| 23 | # |
| 24 | # TYPE is the fuzz target the file is an input to, or "scenario". |
| 25 | # |
| 26 | # Each input is a case that its target must handle without a crash, a |
| 27 | # report from a run-time checker, or a failed property. When a fuzzer |
| 28 | # finds athat once showed ainput is added |
| 29 | # once the defect is fixed, named for what it showed. |
| 30 | # |
| 31 | # The delta targets take a pair of files as one input: two bytes giving |
| 32 | # the size of the first file, most significant byte first, then the |
| 33 | # first file, then the second. |
| 34 | # |
| 35 | # delta-roundtrip: the pair is a source and a target. A delta is made |
| 36 | # from one to the other and must reproduce the target. |
| 37 | # |
| 38 | # delta-apply, delta-accept, delta-reject: the pair is a source and a |
| 39 | # delta. All three apply the delta and check the same properties. |
| 40 | # delta-accept also requires that the delta be accepted, and |
| 41 | # delta-reject that it be refused, so those inputs are examples with a |
| 42 | # known answer. The delta-accept inputs whose names begin with "ok-" |
| 43 | # hold deltas made by Fossil. Each delta-reject input is named for what |
| 44 | # is wrong with it. A fuzzing engine should be pointed at delta-apply, |
| 45 | # with all three as its starting corpus. |
| 46 | # |
| 47 | # manifest: each input is one structural artifact: a check-in, tag, wiki |
| 48 | # page, ticket, technote, attachment or forum post. The inputs whose |
| 49 | # names begin with "ok-" were made by Fossil. The rest are one of those |
| 50 | # with a single card changed, and a Z card that is still correct so that |
| 51 | # the parser reads as far as the change. Names give the cards of the |
| 52 | # artifact, the card that was changed, and how. |
| 53 | # |
| 54 | # manifest-body: each input is an artifact without its Z card. The |
| 55 | # target adds the right one, so every input reaches the parser proper. |
| 56 | # This is the corpus to give a fuzzing engine, which cannot produce a |
| 57 | # matching checksum by changing bytes. The inputs named with card |
| 58 | # letters only are the "ok-" inputs of manifest with the Z card removed. |
| 59 | # A name with a suffix after the letters is an input for one particular |
| 60 | # defect. The "fuzz-" inputs were found by libFuzzer and are kept for |
| 61 | # the branches of manifest.c they reach: a run from the other inputs was |
| 62 | # reduced with -set_cover_merge=1, and from the result a small set was |
| 63 | # chosen that still takes every branch outcome in manifest.c the whole |
| 64 | # set takes. Their names give the card letters that begin a line, then |
| 65 | # part of the SHA1 of the content. |
| 66 | # |
| 67 | # Every manifest and manifest-body input begins with two lines that |
| 68 | # start with "#". They are not part of the input: the target removes |
| 69 | # them. They are there because Fossil treats any file whose content is |
| 70 | # a well-formed artifact as a real one. Without them, a repository that |
| 71 | # received an unpacked input by sync, or was rebuilt while holding it, |
| 72 | # would show it as a check-in, wiki page or ticket of its own. A new |
| 73 | # input of either type must begin with the same two lines; fuzz.test |
| 74 | # checks that each one does, and that Fossil accepts neither the pack |
| 75 | # nor any unpacked input as an artifact as stored. |
| 76 | # |
| 77 | # xfer: each input is the body of one sync request as a client sends it |
| 78 | # to a server, not compressed. The target serves it from a small |
| 79 | # repository that is the same for every input; fuzz_xfer_setup() in |
| 80 | # src/fuzz.c says what it holds. The pull and push cards give that |
| 81 | # repository's project code, and the gimme cards and delta sources are |
| 82 | # its artifacts. An input is named for the cards it holds. |
| 83 | # |
| 84 | # scenario: these are not inputs to a fuzz target. Each is a random |
| 85 | # integration test of sync, run by scenario.test: a list of four-byte |
| 86 | # records, each one operation on one of three clones of a new |
| 87 | # repository: operation, clone, argument, option. See scenario.test for |
| 88 | # the operations. A sync can be told to lose its request, lose its |
| 89 | # reply or deliver half a reply. A sync, pull, push or clone that is |
| 90 | # not told to go wrong must deliver everything at once. The clones are |
| 91 | # synced at the end and must then be sound and identical. Each input |
| 92 | # takes a second or two, because every operation is a separate run of |
| 93 | # fossil. An input is named for what it tests. |
| 94 | # |
| 95 | |
| 96 | # Write every record of the pack PACK as a file DIR/TYPE/NAME and return |
| 97 | # the list of TYPE directories made, sorted. A malformed pack is an |
| 98 | # error. |
| 99 | # |
| 100 | proc corpus_unpack {pack dir} { |
| 101 | set fd [open $pack rb] |
| 102 | set data [read $fd] |
| 103 | close $fd |
| 104 | set at 0 |
| 105 | set end [string length $data] |
| 106 | # The comment lines at the top. |
| 107 | while {$at < $end && [string index $data $at] eq "#"} { |
| 108 | set nl [string first \n $data $at] |
| 109 | if {$nl < 0} { error "$pack: no newline after a comment line" } |
| 110 | set at [expr {$nl + 1}] |
| 111 | } |
| 112 | set types {} |
| 113 | while {$at < $end} { |
| 114 | set nl [string first \n $data $at] |
| 115 | if {$nl < 0} { error "$pack: no newline after a record header" } |
| 116 | set header [string range $data $at [expr {$nl - 1}]] |
| 117 | if {![regexp {^== ([a-z0-9-]+)/([A-Za-z0-9._+-]+) ([0-9]+)$} $header \ |
| 118 | all type name len] |
| 119 | || [string index $name 0] eq "."} { |
| 120 | error "$pack: malformed record header \"$header\"" |
| 121 | } |
| 122 | set len [scan $len %d] |
| 123 | set from [expr {$nl + 1}] |
| 124 | set to [expr {$from + $len}] |
| 125 | if {$to >= $end || [string index $data $to] ne "\n"} { |
| 126 | error "$pack: record $type/$name is cut short" |
| 127 | } |
| 128 | set path [file join $dir $type $name] |
Binary file
+30
| --- a/test/coverage-marks.txt | ||
| +++ b/test/coverage-marks.txt | ||
| @@ -0,0 +1,30 @@ | ||
| 1 | +# Branches that the tests cannot reach, and why. Used by | |
| 2 | +# "tools/testbuild.sh missed". One branch per line: | |
| 3 | +# | |
| 4 | +# FILE | the source line, without leading or trailing spaces | reason | |
| 5 | +# | |
| 6 | +# The three parts are separated by " | ", a bar with a space on each side. | |
| 7 | +# | |
| 8 | +# The source line must match exactly, so an entry stops applying, and | |
| 9 | +# the branch is reported again, as soon as that line of code is changed. | |
| 10 | +# | |
| 11 | +delta.c | assert( (z - (const unsigned char*)0)%4==0 ); /* Four-byte alignment */ | an assert() is never false | |
| 12 | +delta.c | if( 0==*(char*)&byteOrderTest ){ | true only on a big-endian machine | |
| 13 | +delta.c | while( z<zEnd ){ | runs only on a big-endian machine | |
| 14 | +xfer.c | if( blob_size(&xfer.line)==0 ) continue; | blob_line() keeps the newline, so a line it returns is never empty | |
| 15 | +xfer.c | }else if( g.perm.Read ){ | never false: the enclosing test already requires g.perm.Read | |
| 16 | +manifest.c | assert( pParent==0 || pChild==0 ); | an assert() is never false | |
| 17 | +manifest.c | assert( manifest_crosslink_busy==0 ); | an assert() is never false | |
| 18 | +manifest.c | assert( manifest_crosslink_busy==1 ); | an assert() is never false | |
| 19 | +manifest.c | assert(p->type==CFTYPE_WIKI || | an assert() is never false | |
| 20 | +manifest.c | assert( blob_is_reset(pContent) || pContent==0 ); | an assert() is never false | |
| 21 | +manifest.c | assert( blob_is_reset(pContent) ); | an assert() is never false | |
| 22 | +manifest.c | assert( manifest_event_triggers_are_enabled ); | an assert() is never false | |
| 23 | +manifest.c | assert( 0==zUuid ); | an assert() is never false | |
| 24 | +manifest.c | assert( VAL ); CARD_LETTER(LETTER); blob_appendf(b, "%!j", VAL) | an assert() is never false | |
| 25 | +content.c | assert( g.repositoryOpen ); | an assert() is never false | |
| 26 | +content.c | assert( blob_is_reset(&content) ); | an assert() is never false | |
| 27 | +content.c | assert( pBlob!=0 ); | an assert() is never false | |
| 28 | +content.c | assert( srcId==0 || zUuid!=0 ); | an assert() is never false | |
| 29 | +content.c | assert( nBlob==0 ); | an assert() is never false | |
| 30 | +content.c | assert(!"cannot happen: pBlob is always non-NULL"); | an assert() is never false |
| --- a/test/coverage-marks.txt | |
| +++ b/test/coverage-marks.txt | |
| @@ -0,0 +1,30 @@ | |
| --- a/test/coverage-marks.txt | |
| +++ b/test/coverage-marks.txt | |
| @@ -0,0 +1,30 @@ | |
| 1 | # Branches that the tests cannot reach, and why. Used by |
| 2 | # "tools/testbuild.sh missed". One branch per line: |
| 3 | # |
| 4 | # FILE | the source line, without leading or trailing spaces | reason |
| 5 | # |
| 6 | # The three parts are separated by " | ", a bar with a space on each side. |
| 7 | # |
| 8 | # The source line must match exactly, so an entry stops applying, and |
| 9 | # the branch is reported again, as soon as that line of code is changed. |
| 10 | # |
| 11 | delta.c | assert( (z - (const unsigned char*)0)%4==0 ); /* Four-byte alignment */ | an assert() is never false |
| 12 | delta.c | if( 0==*(char*)&byteOrderTest ){ | true only on a big-endian machine |
| 13 | delta.c | while( z<zEnd ){ | runs only on a big-endian machine |
| 14 | xfer.c | if( blob_size(&xfer.line)==0 ) continue; | blob_line() keeps the newline, so a line it returns is never empty |
| 15 | xfer.c | }else if( g.perm.Read ){ | never false: the enclosing test already requires g.perm.Read |
| 16 | manifest.c | assert( pParent==0 || pChild==0 ); | an assert() is never false |
| 17 | manifest.c | assert( manifest_crosslink_busy==0 ); | an assert() is never false |
| 18 | manifest.c | assert( manifest_crosslink_busy==1 ); | an assert() is never false |
| 19 | manifest.c | assert(p->type==CFTYPE_WIKI || | an assert() is never false |
| 20 | manifest.c | assert( blob_is_reset(pContent) || pContent==0 ); | an assert() is never false |
| 21 | manifest.c | assert( blob_is_reset(pContent) ); | an assert() is never false |
| 22 | manifest.c | assert( manifest_event_triggers_are_enabled ); | an assert() is never false |
| 23 | manifest.c | assert( 0==zUuid ); | an assert() is never false |
| 24 | manifest.c | assert( VAL ); CARD_LETTER(LETTER); blob_appendf(b, "%!j", VAL) | an assert() is never false |
| 25 | content.c | assert( g.repositoryOpen ); | an assert() is never false |
| 26 | content.c | assert( blob_is_reset(&content) ); | an assert() is never false |
| 27 | content.c | assert( pBlob!=0 ); | an assert() is never false |
| 28 | content.c | assert( srcId==0 || zUuid!=0 ); | an assert() is never false |
| 29 | content.c | assert( nBlob==0 ); | an assert() is never false |
| 30 | content.c | assert(!"cannot happen: pBlob is always non-NULL"); | an assert() is never false |
+1631
| --- a/test/crosslink.test | ||
| +++ b/test/crosslink.test | ||
| @@ -0,0 +1,1631 @@ | ||
| 1 | +# | |
| 2 | +# What the repository database shows after an artifact of each kind has | |
| 3 | +# been stored and crosslinked: manifest_crosslink() and the routines | |
| 4 | +# around it in src/manifest.c. | |
| 5 | +# | |
| 6 | +# Each artifact is written out here card by card, given its Z card, and | |
| 7 | +# stored with "fossil test-content-put --crosslink". That reaches cases | |
| 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 | |
| 23 | + | |
| 24 | +# Write a file that holds the cards $body and the Z card for them, and | |
| 25 | +# return its name. | |
| 26 | +# | |
| 27 | +proc crosslink_file {body} { | |
| 28 | + global crosslinkSeq RESULT | |
| 29 | + set fn artifact-[incr crosslinkSeq].txt | |
| 30 | + set fd [open $fn wb] | |
| 31 | + puts -nonewline $fd $body | |
| 32 | + close $fd | |
| 33 | + fossil md5sum $fn | |
| 34 | + set sum [lindex $RESULT 0] | |
| 35 | + set fd [open $fn ab] | |
| 36 | + puts -nonewline $fd "Z $sum\n" | |
| 37 | + close $fd | |
| 38 | + return $fn | |
| 39 | +} | |
| 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" | |
| 58 | + set hash [string trim $RESULT '] | |
| 59 | + } | |
| 60 | + set CODE $code | |
| 61 | + set RESULT $result | |
| 62 | + return $hash | |
| 63 | +} | |
| 64 | + | |
| 65 | +# A W card for the given text. | |
| 66 | +# | |
| 67 | +proc crosslink_w {text} { | |
| 68 | + return "W [string length $text]\n$text\n" | |
| 69 | +} | |
| 70 | + | |
| 71 | +# Test NAME passes if ACTUAL matches the glob PATTERN. | |
| 72 | +# | |
| 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] | |
| 95 | + | |
| 96 | +############################################################################### | |
| 97 | +# Wiki pages: a new page, an edit, and an edit that empties the page. | |
| 98 | + | |
| 99 | +set crosslinkW1 [crosslink_put "D 2026-01-01T10:00:00.000 | |
| 100 | +L Crosslink\\sPage | |
| 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 | +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 | |
| 123 | +P $crosslinkW2 | |
| 124 | +U alice | |
| 125 | +[crosslink_w {}]"] | |
| 126 | +test_eq crosslink-wiki-empty-event [crosslink_event $crosslinkW3] \ | |
| 127 | + {w -Crosslink Page} | |
| 128 | + | |
| 129 | +# A parent that is not in the repository: the page still counts as an | |
| 130 | +# edit. | |
| 131 | +set crosslinkW4 [crosslink_put "D 2026-01-01T12:30:00.000 | |
| 132 | +L Orphan | |
| 133 | +P $crosslinkNone | |
| 134 | +U alice | |
| 135 | +[crosslink_w {text}]"] | |
| 136 | +test_eq crosslink-wiki-missing-parent [crosslink_event $crosslinkW4] \ | |
| 137 | + {w :Orphan} | |
| 138 | + | |
| 139 | +############################################################################### | |
| 140 | +# Tech notes: a note, a later version of it, and an earlier version that | |
| 141 | +# arrives last. | |
| 142 | + | |
| 143 | +set crosslinkEid [string repeat ab 20] | |
| 144 | +set crosslinkE1 [crosslink_put "C First\\snote | |
| 145 | +D 2026-01-02T10:00:00.000 | |
| 146 | +E 2026-01-02T09:00:00 $crosslinkEid | |
| 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. | |
| 176 | + | |
| 177 | +set crosslinkTkt [string repeat cd 20] | |
| 178 | +set crosslinkT1 [crosslink_put "D 2026-01-03T10:00:00.000 | |
| 179 | +J status Open | |
| 180 | +J title Crosslink\\sticket | |
| 181 | +K $crosslinkTkt | |
| 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 | |
| 212 | +K $crosslinkTkt | |
| 213 | +U alice | |
| 214 | +"] | |
| 215 | +crosslink_match crosslink-ticket-no-status-two [crosslink_event $crosslinkT4] \ | |
| 216 | + {t Ticket * status still Closed with 2 other changes} | |
| 217 | + | |
| 218 | +set crosslinkT5 [crosslink_put "D 2026-01-03T14:00:00.000 | |
| 219 | +J +comment more\\stext | |
| 220 | +K $crosslinkTkt | |
| 221 | +U alice | |
| 222 | +"] | |
| 223 | +crosslink_match crosslink-ticket-no-status-one [crosslink_event $crosslinkT5] \ | |
| 224 | + {t Ticket * status still Closed with 1 other change} | |
| 225 | + | |
| 226 | +set crosslinkT6 [crosslink_put "D 2026-01-03T15:00:00.000 | |
| 227 | +J status Verified | |
| 228 | +K $crosslinkTkt | |
| 229 | +U alice | |
| 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 | |
| 241 | +# arrives last. | |
| 242 | + | |
| 243 | +set crosslinkFtext "See \[[string range $crosslinkW1 0 15]\]." | |
| 244 | +set crosslinkF1 [crosslink_put "D 2026-01-04T10:00:01.000 | |
| 245 | +H Crosslink\\sthread | |
| 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 | |
| 257 | +I $crosslinkF1 | |
| 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 | + | |
| 269 | +set crosslinkF3 [crosslink_put "D 2026-01-04T12:00:00.000 | |
| 270 | +G $crosslinkF1 | |
| 271 | +I $crosslinkF1 | |
| 272 | +P $crosslinkF2 | |
| 273 | +U bob | |
| 274 | +[crosslink_w {reply2}]"] | |
| 275 | +test_eq crosslink-forum-reply-edit-event [crosslink_event $crosslinkF3] \ | |
| 276 | + {f Edit reply: Crosslink thread} | |
| 277 | + | |
| 278 | +set crosslinkF4 [crosslink_put "D 2026-01-04T13:00:00.000 | |
| 279 | +G $crosslinkF1 | |
| 280 | +I $crosslinkF1 | |
| 281 | +P $crosslinkF3 | |
| 282 | +U bob | |
| 283 | +[crosslink_w {}]"] | |
| 284 | +test_eq crosslink-forum-reply-delete-event [crosslink_event $crosslinkF4] \ | |
| 285 | + {f Delete reply: Crosslink thread} | |
| 286 | + | |
| 287 | +set crosslinkF5 [crosslink_put "D 2026-01-04T14:00:00.000 | |
| 288 | +G $crosslinkF1 | |
| 289 | +H New\\stitle | |
| 290 | +P $crosslinkF1 | |
| 291 | +U alice | |
| 292 | +[crosslink_w {text}]"] | |
| 293 | +test_eq crosslink-forum-edit-event [crosslink_event $crosslinkF5] \ | |
| 294 | + {f Edit: New title} | |
| 295 | +test_eq crosslink-forum-edit-retitles-thread [crosslink_event $crosslinkF2] \ | |
| 296 | + {f Reply: New title} | |
| 297 | + | |
| 298 | +# An edit of the first post dated before the one above does not change | |
| 299 | +# the title of the thread. | |
| 300 | +set crosslinkF6 [crosslink_put "D 2026-01-04T13:30:00.000 | |
| 301 | +G $crosslinkF1 | |
| 302 | +H Older\\stitle | |
| 303 | +P $crosslinkF1 | |
| 304 | +U alice | |
| 305 | +[crosslink_w {text}]"] | |
| 306 | +test_eq crosslink-forum-older-edit-event [crosslink_event $crosslinkF6] \ | |
| 307 | + {f Edit: Older title} | |
| 308 | +test_eq crosslink-forum-older-edit-keeps-title [crosslink_event $crosslinkF2] \ | |
| 309 | + {f Reply: New title} | |
| 310 | + | |
| 311 | +# A first post with its title removed. | |
| 312 | +set crosslinkF7 [crosslink_put "D 2026-01-04T15:00:00.000 | |
| 313 | +G $crosslinkF1 | |
| 314 | +P $crosslinkF5 | |
| 315 | +U alice | |
| 316 | +[crosslink_w {}]"] | |
| 317 | +test_eq crosslink-forum-deleted-thread [crosslink_event $crosslinkF7] \ | |
| 318 | + {f Edit: (Deleted)} | |
| 319 | + | |
| 320 | +# A reply to a thread whose first post is not in the repository. | |
| 321 | +set crosslinkF8 [crosslink_put "D 2026-01-04T16:00:00.000 | |
| 322 | +G $crosslinkNone | |
| 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] | |
| 333 | +foreach {crosslinkKind crosslinkTarget crosslinkType crosslinkAdd | |
| 334 | + crosslinkDel} [list \ | |
| 335 | + wiki Crosslink\\sPage w {*to wiki page \[Crosslink Page\]*} \ | |
| 336 | + {*from wiki page \[Crosslink Page\]*} \ | |
| 337 | + technote $crosslinkEid e {*to tech note *} \ | |
| 338 | + {"file.txt" from tech note \[/technote/*\]} \ | |
| 339 | + ticket $crosslinkTkt t {*to ticket *} {*from ticket *} \ | |
| 340 | + forum $crosslinkF1 f {*to forum post *} {*from forum post *} \ | |
| 341 | + unknown $crosslinkNone2 a {*to \[/artifact/*} \ | |
| 342 | + {"file.txt" from \[/artifact/*\]} \ | |
| 343 | +] { | |
| 344 | + set crosslinkA [crosslink_put "A file.txt $crosslinkTarget $crosslinkSrc | |
| 345 | +C A\\scomment | |
| 346 | +D 2026-01-05T10:00:00.000 | |
| 347 | +U alice | |
| 348 | +"] | |
| 349 | + test crosslink-attach-$crosslinkKind-add {$CODE == 0 && $crosslinkA ne ""} | |
| 350 | + set crosslinkEv [crosslink_event $crosslinkA] | |
| 351 | + crosslink_match crosslink-attach-$crosslinkKind-add-event $crosslinkEv \ | |
| 352 | + "$crosslinkType Add attachment $crosslinkAdd" | |
| 353 | + set crosslinkA [crosslink_put "A file.txt $crosslinkTarget | |
| 354 | +D 2026-01-05T11:00:00.000 | |
| 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 | +############################################################################### | |
| 390 | +# Check-ins made by hand, and the tags put on them. | |
| 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".*} \ | |
| 424 | + other-value "+thing2 * val" {*Add "thing2" with value "val".*} \ | |
| 425 | + other-prop "*thing3 *" {*Add propagating "thing3".*} \ | |
| 426 | + other-cancel "-thing *" {*Cancel "thing".*} \ | |
| 427 | +] { | |
| 428 | + set crosslinkCard [string map [list " * " " $crosslinkC1 "] $crosslinkCard] | |
| 429 | + if {[string match "* \\*" $crosslinkCard]} { | |
| 430 | + set crosslinkCard "[string range $crosslinkCard 0 end-1]$crosslinkC1" | |
| 431 | + } | |
| 432 | + set crosslinkG [crosslink_put "D 2026-01-06T10:00:[format %02d \ | |
| 433 | + [incr crosslinkSeq 0]].000 | |
| 434 | +T $crosslinkCard | |
| 435 | +U alice | |
| 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 | |
| 452 | +"] | |
| 453 | +crosslink_match crosslink-tag-branch-move-quiet [crosslink_event $crosslinkG] \ | |
| 454 | + {g Edit *: Move to branch *moved*} | |
| 455 | +test crosslink-tag-branch-move-no-sym \ | |
| 456 | + {![string match *tag* [crosslink_event $crosslinkG]]} | |
| 457 | + | |
| 458 | +# Tags for two check-ins in one artifact are listed under each. | |
| 459 | +set crosslinkTwo [lsort [list $crosslinkC1 $crosslinkW1]] | |
| 460 | +set crosslinkG [crosslink_put "D 2026-01-06T11:15:00.000 | |
| 461 | +T +sym-both [lindex $crosslinkTwo 0] | |
| 462 | +T +sym-both [lindex $crosslinkTwo 1] | |
| 463 | +U alice | |
| 464 | +"] | |
| 465 | +crosslink_match crosslink-tag-two-targets [crosslink_event $crosslinkG] \ | |
| 466 | + {g Edit *: Add tag "both". Edit *: Add tag "both".} | |
| 467 | + | |
| 468 | +# A tag on an artifact that is not in the repository is recorded against | |
| 469 | +# a phantom. | |
| 470 | +set crosslinkG [crosslink_put "D 2026-01-06T11:30:00.000 | |
| 471 | +T +sym-far $crosslinkNone | |
| 472 | +U alice | |
| 473 | +"] | |
| 474 | +crosslink_match crosslink-tag-on-missing [crosslink_event $crosslinkG] \ | |
| 475 | + {g Edit *: Add tag "far".} | |
| 476 | + | |
| 477 | +############################################################################### | |
| 478 | +# A check-in with a second parent, a cherrypick, a symbolic link, an | |
| 479 | +# executable and a renamed file. | |
| 480 | + | |
| 481 | +set crosslinkM1 [crosslink_put "C crosslink-c2 | |
| 482 | +D 2026-01-07T10:00:00.000 | |
| 483 | +F a.txt $crosslinkFa x | |
| 484 | +F c.txt $crosslinkFb w b.txt | |
| 485 | +F l.txt $crosslinkFa l | |
| 486 | +P $crosslinkC1 | |
| 487 | +Q +$crosslinkC1 | |
| 488 | +Q -$crosslinkC1 $crosslinkC1 | |
| 489 | +T +sym-made-by-hand * | |
| 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, | |
| 506 | +# so the file is back. | |
| 507 | +set crosslinkM2 [crosslink_put "B $crosslinkM1 | |
| 508 | +C crosslink-c3 | |
| 509 | +D 2026-01-07T11:00:00.000 | |
| 510 | +F a.txt | |
| 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 | |
| 527 | +F c.txt | |
| 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 | + | |
| 539 | +set crosslinkM4 [crosslink_put "C crosslink-c5 | |
| 540 | +D 2026-01-07T13:00:00.000 | |
| 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 | + | |
| 552 | +# The files of each of them can be listed and checked out. | |
| 553 | +foreach crosslinkCi [list $crosslinkM1 $crosslinkM2 $crosslinkM3 $crosslinkM4] { | |
| 554 | + fossil ls -r $crosslinkCi | |
| 555 | + test crosslink-ls-[string range $crosslinkCi 0 7] {$CODE == 0} | |
| 556 | +} | |
| 557 | +fossil ls -r $crosslinkM3 | |
| 558 | +test_eq crosslink-ls-delta [normalize_result] "a.txt\nd.txt\ne.txt\nl.txt" | |
| 559 | + | |
| 560 | +# A file that a delta manifest removes cannot be read from that check-in, | |
| 561 | +# and one that it leaves alone comes from the baseline. | |
| 562 | +fossil cat a.txt -r $crosslinkM2 -expectError | |
| 563 | +test crosslink-cat-removed-by-delta {$CODE != 0} | |
| 564 | +fossil cat l.txt -r $crosslinkM2 | |
| 565 | +test_eq crosslink-cat-from-baseline [normalize_result] a | |
| 566 | + | |
| 567 | +# A check-in that picks a change from a check-in that is not in the | |
| 568 | +# repository. | |
| 569 | +set crosslinkM5 [crosslink_put "C crosslink-c6 | |
| 570 | +D 2026-01-07T13:30:00.000 | |
| 571 | +F a.txt $crosslinkFa | |
| 572 | +P $crosslinkM4 | |
| 573 | +Q +$crosslinkNone | |
| 574 | +U alice | |
| 575 | +"] | |
| 576 | +test_eq crosslink-cherrypick-of-missing [crosslink_event $crosslinkM5] \ | |
| 577 | + {ci crosslink-c6} | |
| 578 | + | |
| 579 | +# A check-in whose baseline is not in the repository is stored but not | |
| 580 | +# shown, and so is anything that is not an artifact. | |
| 581 | +set crosslinkBad [crosslink_put "B $crosslinkNone | |
| 582 | +C crosslink-no-baseline | |
| 583 | +D 2026-01-07T14:00:00.000 | |
| 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 | |
| 595 | +D 2026-01-07T14:30:00.000 | |
| 596 | +F a.txt $crosslinkFa | |
| 597 | +P $crosslinkBad | |
| 598 | +U alice | |
| 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. | |
| 632 | +set crosslinkI 0 | |
| 633 | +foreach {crosslinkName crosslinkValue} [list \ | |
| 634 | + two-sha3-short "$crosslinkM1\\s$crosslinkM2\\sx" \ | |
| 635 | + one-sha3-short "$crosslinkM1\\sx" \ | |
| 636 | + one-sha1-short "[string repeat a 40]\\sxxxxx" \ | |
| 637 | +] { | |
| 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 | |
| 692 | +} | |
| 693 | +# Every artifact that the repository shows in its timeline has a JSON | |
| 694 | +# form. | |
| 695 | +fossil sql "SELECT uuid FROM blob WHERE rid IN (SELECT objid FROM event)" | |
| 696 | +set crosslinkAll [string map {' {}} $RESULT] | |
| 697 | +fossil test-artifact-to-json {*}$crosslinkAll | |
| 698 | +test crosslink-json-every-artifact {$CODE == 0 && [llength $crosslinkAll] > 30} | |
| 699 | + | |
| 700 | +fossil test-artifact-to-json --pretty $crosslinkW1 $crosslinkT1 | |
| 701 | +test crosslink-json-pretty {$CODE == 0} | |
| 702 | +crosslink_match crosslink-json-pretty-text $RESULT "*\"type\": \"wiki\"*" | |
| 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 | +############################################################################### | |
| 726 | +# What the parser refuses, and the reason it gives. | |
| 727 | + | |
| 728 | +set crosslinkH40 [string repeat ab 20] | |
| 729 | +foreach {crosslinkName crosslinkBody crosslinkWant} [list \ | |
| 730 | + cards-out-of-order "U alice\nD 2026-02-01T10:00:00.000\n" \ | |
| 731 | + {*cards not in lexicographical order*} \ | |
| 732 | + bad-card-type "D 2026-02-01T10:00:00.000\na b\n" \ | |
| 733 | + {*bad card type*} \ | |
| 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 \ | |
| 754 | + "*ERROR:$crosslinkWant" | |
| 755 | +} | |
| 756 | + | |
| 757 | +# A file that does not end in a newline, an empty one, and one whose Z | |
| 758 | +# card does not match. | |
| 759 | +write_file refuse-no-newline.txt "D 2026-02-01T10:00:00.000\nU alice" | |
| 760 | +fossil test-parse-manifest refuse-no-newline.txt | |
| 761 | +crosslink_match crosslink-refuse-no-newline $RESULT {*ERROR:*not terminated*} | |
| 762 | +write_file refuse-empty.txt "" | |
| 763 | +fossil test-parse-manifest refuse-empty.txt | |
| 764 | +crosslink_match crosslink-refuse-empty $RESULT {*ERROR:*zero-length*} | |
| 765 | +write_file refuse-checksum.txt \ | |
| 766 | + "D 2026-02-01T10:00:00.000\nU alice\nZ [string repeat 0 32]\n" | |
| 767 | +fossil test-parse-manifest refuse-checksum.txt | |
| 768 | +crosslink_match crosslink-refuse-checksum $RESULT \ | |
| 769 | + {*ERROR:*incorrect Z-card cksum*} | |
| 770 | + | |
| 771 | +# Files without a comment are still a check-in. | |
| 772 | +fossil test-parse-manifest [crosslink_file \ | |
| 773 | + "D 2026-02-01T10:00:00.000\nF a.txt $crosslinkH40\nU alice\n"] | |
| 774 | +crosslink_match crosslink-files-without-comment $RESULT \ | |
| 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. | |
| 789 | +foreach {crosslinkName crosslinkText} [list \ | |
| 790 | + digit-first "1 x and some more text\nD x\n" \ | |
| 791 | + no-space "AB and some more text\nD x\n" \ | |
| 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} | |
| 803 | +} | |
| 804 | +fossil test-parse-all-blobs --wellformed | |
| 805 | +crosslink_match crosslink-wellformed-agrees $RESULT {*tests with 0 errors*} | |
| 806 | + | |
| 807 | +# A name that is not a check-in, where one is needed. | |
| 808 | +fossil ls -r $crosslinkW1 -expectError | |
| 809 | +test crosslink-wiki-is-not-a-checkin {$CODE != 0} | |
| 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(*} | |
| 833 | + | |
| 834 | +############################################################################### | |
| 835 | +# The commands that parse artifacts again. | |
| 836 | + | |
| 837 | +fossil artifact $crosslinkM1 checkin.txt | |
| 838 | +fossil test-parse-manifest checkin.txt | |
| 839 | +test crosslink-parse-manifest {$CODE == 0} | |
| 840 | +crosslink_match crosslink-parse-manifest-text $RESULT {*is ok*} | |
| 841 | +fossil test-parse-manifest checkin.txt 5 | |
| 842 | +test crosslink-parse-manifest-repeat {$CODE == 0} | |
| 843 | +fossil test-parse-manifest checkin.txt 2 | |
| 844 | +crosslink_match crosslink-parse-manifest-twice $RESULT \ | |
| 845 | + {*manifest_parse() worked*manifest_parse() worked*} | |
| 846 | +fossil test-parse-manifest not-an-artifact.txt 3 | |
| 847 | +crosslink_match crosslink-parse-manifest-bad $RESULT {*contains errors*} | |
| 848 | +fossil test-parse-manifest -expectError | |
| 849 | +test crosslink-parse-manifest-usage {$CODE != 0} | |
| 850 | + | |
| 851 | +fossil test-parse-all-blobs | |
| 852 | +test crosslink-parse-all {$CODE == 0} | |
| 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 | +############################################################################### | |
| 872 | +# A rebuild reaches the same state from the artifacts alone. | |
| 873 | + | |
| 874 | +set crosslinkState {SELECT (SELECT count(*) FROM event) || ' ' || | |
| 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 | + | |
| 893 | +############################################################################### | |
| 894 | +# The kind of an artifact that has no card naming its kind: a comment, a | |
| 895 | +# file or a parent card alone makes a check-in; none of them makes a | |
| 896 | +# control artifact, which has no entry in the timeline. Each row of the | |
| 897 | +# table has one of the three and no other. | |
| 898 | + | |
| 899 | +foreach {crosslinkName crosslinkBody crosslinkKind} [list \ | |
| 900 | + comment-only "C only\\sa\\scomment\nD 2026-03-01T10:00:00.000\nU alice\n" ci \ | |
| 901 | + file-only "D 2026-03-01T10:01:00.000\nF a.txt $crosslinkFa\nU alice\n" ci \ | |
| 902 | + parent-only "D 2026-03-01T10:02:00.000\nP $crosslinkC1\nU alice\n" ci \ | |
| 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*} | |
| 914 | +} | |
| 915 | + | |
| 916 | +############################################################################### | |
| 917 | +# The links between a check-in and its parents when the parents arrive | |
| 918 | +# after it, in either order. A merge parent that arrives while the first | |
| 919 | +# parent is still missing adds no file links; they are added when the | |
| 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 | |
| 945 | +"] | |
| 946 | +test crosslink-mcdc-merge-child {$CODE == 0 && $crosslinkKid ne ""} | |
| 947 | +test_eq crosslink-mcdc-merge-child-event [crosslink_event $crosslinkKid] \ | |
| 948 | + {ci merge kid} | |
| 949 | + | |
| 950 | +# The second parent first: no links yet. | |
| 951 | +set crosslinkGot [crosslink_put "C second\\sparent | |
| 952 | +D 2026-03-02T10:01:00.000 | |
| 953 | +F a.txt $crosslinkFb | |
| 954 | +U alice | |
| 955 | +"] | |
| 956 | +test_eq crosslink-mcdc-merge-parent-first-hash $crosslinkGot $crosslinkPB | |
| 957 | +test_eq crosslink-mcdc-merge-parent-first-links \ | |
| 958 | + [crosslink_links $crosslinkKid $crosslinkPB] 0 | |
| 959 | + | |
| 960 | +# Then the first parent: links to both. | |
| 961 | +set crosslinkGot [crosslink_put "C first\\sparent | |
| 962 | +D 2026-03-02T10:00:00.000 | |
| 963 | +F a.txt $crosslinkFa | |
| 964 | +U alice | |
| 965 | +"] | |
| 966 | +test_eq crosslink-mcdc-merge-parent-second-hash $crosslinkGot $crosslinkPA | |
| 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 | +" | |
| 979 | +set crosslinkKid2 [crosslink_put "C other\\skid | |
| 980 | +D 2026-03-02T13:00:00.000 | |
| 981 | +F a.txt $crosslinkNone | |
| 982 | +P $crosslinkQA $crosslinkQB | |
| 983 | +U alice | |
| 984 | +"] | |
| 985 | +test_eq crosslink-mcdc-merge-second-missing-links \ | |
| 986 | + [list [crosslink_links $crosslinkKid2 $crosslinkQA] \ | |
| 987 | + [crosslink_links $crosslinkKid2 $crosslinkQB]] {1 0} | |
| 988 | +crosslink_put "C other\\ssecond | |
| 989 | +D 2026-03-02T12:01:00.000 | |
| 990 | +F a.txt $crosslinkFb | |
| 991 | +U alice | |
| 992 | +" | |
| 993 | +test_eq crosslink-mcdc-merge-second-arrives-links \ | |
| 994 | + [list [crosslink_links $crosslinkKid2 $crosslinkQA] \ | |
| 995 | + [crosslink_links $crosslinkKid2 $crosslinkQB]] {1 1} | |
| 996 | + | |
| 997 | +############################################################################### | |
| 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 \ | |
| 1013 | + [crosslink_event $crosslinkHash] $crosslinkWant | |
| 1014 | + fossil test-artifact-to-json $crosslinkHash | |
| 1015 | + crosslink_match crosslink-mcdc-forum-$crosslinkName-json $RESULT \ | |
| 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 | |
| 1027 | +foreach {crosslinkName crosslinkCard crosslinkWant} [list \ | |
| 1028 | + sym-empty "+sym-empty" {*Add tag "empty".} \ | |
| 1029 | + other-empty "+other-empty" {*Add "other-empty".} \ | |
| 1030 | + other-value "+other-value" {*Add "other-value" with value "v".} \ | |
| 1031 | +] { | |
| 1032 | + set crosslinkValue [expr {$crosslinkName eq "other-value" ? "v" : ""}] | |
| 1033 | + set crosslinkHash [crosslink_put "D 2026-03-04T10:[incr crosslinkMin]:00.000 | |
| 1034 | +T $crosslinkCard $crosslinkC1 $crosslinkValue | |
| 1035 | +U alice | |
| 1036 | +"] | |
| 1037 | + test crosslink-mcdc-tag-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""} | |
| 1038 | + crosslink_match crosslink-mcdc-tag-$crosslinkName-event \ | |
| 1039 | + [crosslink_event $crosslinkHash] "g Edit *:$crosslinkWant" | |
| 1040 | +} | |
| 1041 | + | |
| 1042 | +############################################################################### | |
| 1043 | +# A check-in that picks a change from a check-in the repository has never | |
| 1044 | +# seen, and from one it has: only the second gets file links to it. | |
| 1045 | + | |
| 1046 | +set crosslinkUnseen [string repeat 5a 20] | |
| 1047 | +foreach {crosslinkName crosslinkTarget} [list unseen $crosslinkUnseen \ | |
| 1048 | + known $crosslinkM1] { | |
| 1049 | + set crosslinkHash [crosslink_put "C cherry-$crosslinkName | |
| 1050 | +D 2026-03-05T10:[incr crosslinkMin]:00.000 | |
| 1051 | +F a.txt $crosslinkFa | |
| 1052 | +P $crosslinkC1 | |
| 1053 | +Q +$crosslinkTarget | |
| 1054 | +U alice | |
| 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 \ | |
| 1080 | + ticket $crosslinkT1 0 \ | |
| 1081 | + forum $crosslinkF1 0 \ | |
| 1082 | + file $crosslinkFa 0 \ | |
| 1083 | + nothing $crosslinkNone2 0 \ | |
| 1084 | +] { | |
| 1085 | + set crosslinkReply [crosslink_get /winfo?name=$crosslinkHash] | |
| 1086 | + test crosslink-mcdc-winfo-$crosslinkName \ | |
| 1087 | + {[string match "HTTP/1.0 200*" $crosslinkReply]} | |
| 1088 | + test crosslink-mcdc-winfo-$crosslinkName-answer \ | |
| 1089 | + {[string match "*No such object*" $crosslinkReply] == !$crosslinkIs} | |
| 1090 | +} | |
| 1091 | + | |
| 1092 | +############################################################################### | |
| 1093 | +# A check-in on a delta manifest that removed a file, where the check-in | |
| 1094 | +# has the file again: the file is new in it. A file the delta manifest | |
| 1095 | +# does not mention is compared with the baseline's, so that l.txt, the | |
| 1096 | +# same as in the baseline, has no link, and the files the delta manifest | |
| 1097 | +# added or changed are removed. | |
| 1098 | + | |
| 1099 | +set crosslinkBack [crosslink_put "C file-back-after-delta | |
| 1100 | +D 2026-03-06T10:00:00.000 | |
| 1101 | +F a.txt $crosslinkFa | |
| 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 | + | |
| 1113 | +############################################################################### | |
| 1114 | +# A delta manifest that removes a file its baseline does not have, and a | |
| 1115 | +# check-in on it: the check-in has no link for that name. The files of | |
| 1116 | +# the baseline that the check-in lacks are removed in it. | |
| 1117 | + | |
| 1118 | +set crosslinkGhost [crosslink_put "B $crosslinkM1 | |
| 1119 | +C delta-removes-unknown | |
| 1120 | +D 2026-03-07T10:00:00.000 | |
| 1121 | +F zz-never.txt | |
| 1122 | +P $crosslinkM1 | |
| 1123 | +U alice | |
| 1124 | +"] | |
| 1125 | +test crosslink-mcdc-delta-removes-unknown {$CODE == 0 && $crosslinkGhost ne ""} | |
| 1126 | +test_eq crosslink-mcdc-delta-removes-unknown-event \ | |
| 1127 | + [crosslink_event $crosslinkGhost] {ci delta-removes-unknown} | |
| 1128 | +set crosslinkHash [crosslink_put "C child-of-delta-removes-unknown | |
| 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 | + | |
| 1140 | +############################################################################### | |
| 1141 | +# A delta manifest whose baseline is not in the repository is not a | |
| 1142 | +# check-in. A "parent" tag on it is recorded as its parent, and no file | |
| 1143 | +# links are made while the baseline is missing. | |
| 1144 | + | |
| 1145 | +set crosslinkKid3 [crosslink_put "B [string repeat 6b 20] | |
| 1146 | +C delta-without-baseline | |
| 1147 | +D 2026-03-07T11:00:00.000 | |
| 1148 | +F b.txt | |
| 1149 | +P $crosslinkC1 | |
| 1150 | +U alice | |
| 1151 | +"] | |
| 1152 | +test crosslink-mcdc-reparent-no-baseline {$CODE == 0 && $crosslinkKid3 ne ""} | |
| 1153 | +test_eq crosslink-mcdc-reparent-no-baseline-no-event \ | |
| 1154 | + [crosslink_event $crosslinkKid3] {} | |
| 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 | + | |
| 1166 | +############################################################################### | |
| 1167 | +# A check-in whose parent is a wiki page, and a delta manifest whose | |
| 1168 | +# baseline is the same wiki page, stored by one command: the first is a | |
| 1169 | +# check-in, the second is not and is recorded as waiting for a baseline. | |
| 1170 | + | |
| 1171 | +set crosslinkOnWiki [crosslink_file "C child-of-wiki-page | |
| 1172 | +D 2026-03-07T12:00:00.000 | |
| 1173 | +F a.txt $crosslinkFa | |
| 1174 | +P $crosslinkW1 | |
| 1175 | +U alice | |
| 1176 | +"] | |
| 1177 | +set crosslinkBasedOnWiki [crosslink_file "B $crosslinkW1 | |
| 1178 | +C based-on-wiki-page | |
| 1179 | +D 2026-03-07T12:01:00.000 | |
| 1180 | +F a.txt $crosslinkFa | |
| 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 ""} { | |
| 1206 | + fossil sql "DELETE FROM config WHERE name='$name'" | |
| 1207 | + } else { | |
| 1208 | + fossil sql "REPLACE INTO config(name,value,mtime) | |
| 1209 | + VALUES('$name','$script',now())" | |
| 1210 | + } | |
| 1211 | +} | |
| 1212 | + | |
| 1213 | +crosslink_script xfer-commit-script {query {SELECT artifact_to_json(pid) AS j | |
| 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 | |
| 1246 | +# them. A check-in with a Q card is still a check-in there, and a | |
| 1247 | +# rebuild makes the table and records the cherrypick. | |
| 1248 | + | |
| 1249 | +fossil sql "DROP TABLE cherrypick" | |
| 1250 | +set crosslinkHash [crosslink_put "C cherry-no-table | |
| 1251 | +D 2026-03-07T13:00:00.000 | |
| 1252 | +F a.txt $crosslinkFa | |
| 1253 | +P $crosslinkC1 | |
| 1254 | +Q +$crosslinkM1 | |
| 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. | |
| 1270 | +# | |
| 1271 | +# A signed artifact is an artifact. A check-in whose second card is a P | |
| 1272 | +# card that names no parent is an artifact. A signed artifact whose | |
| 1273 | +# signature does not end in a newline is not an artifact. | |
| 1274 | + | |
| 1275 | +set crosslinkSigned "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n" | |
| 1276 | +append crosslinkSigned [read_file [crosslink_file \ | |
| 1277 | + "D 2026-03-08T10:00:00.000\nL Signed\nU alice\n[crosslink_w {x}]"]] | |
| 1278 | +append crosslinkSigned "-----BEGIN PGP SIGNATURE-----\nabc\n" | |
| 1279 | +append crosslinkSigned "-----END PGP SIGNATURE-----" | |
| 1280 | +write_file wf-signed.txt "$crosslinkSigned\n" | |
| 1281 | +write_file wf-signed-no-newline.txt $crosslinkSigned | |
| 1282 | +set crosslinkEmptyP [crosslink_file \ | |
| 1283 | + "D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"] | |
| 1284 | + | |
| 1285 | +fossil test-parse-manifest wf-signed.txt | |
| 1286 | +crosslink_match crosslink-mcdc-agree-signed $RESULT \ | |
| 1287 | + {*reports the input is ok*manifest_parse() worked} | |
| 1288 | + | |
| 1289 | +fossil test-parse-manifest $crosslinkEmptyP | |
| 1290 | +crosslink_match crosslink-mcdc-agree-empty-p-parses $RESULT \ | |
| 1291 | + {*manifest_parse() worked*} | |
| 1292 | +test crosslink-mcdc-agree-empty-p {![string match *disagree* $RESULT]} | |
| 1293 | + | |
| 1294 | +fossil test-parse-manifest wf-signed-no-newline.txt | |
| 1295 | +crosslink_match crosslink-mcdc-agree-signed-no-newline-refused $RESULT \ | |
| 1296 | + {*ERROR: not terminated*} | |
| 1297 | +test crosslink-mcdc-agree-signed-no-newline \ | |
| 1298 | + {![string match *disagree* $RESULT]} | |
| 1299 | + | |
| 1300 | +# The same for content held by a repository. | |
| 1301 | +fossil init wf.fossil | |
| 1302 | +fossil test-content-put -R wf.fossil wf-signed.txt $crosslinkEmptyP \ | |
| 1303 | + wf-signed-no-newline.txt | |
| 1304 | +test crosslink-mcdc-agree-stored {$CODE == 0} | |
| 1305 | +fossil test-parse-all-blobs --wellformed -R wf.fossil | |
| 1306 | +test crosslink-mcdc-agree-stored-checked \ | |
| 1307 | + {$CODE == 0 && [regexp {(\d+) tests with} $RESULT all n] && $n >= 3} | |
| 1308 | +crosslink_match crosslink-mcdc-agree-stored-no-errors $RESULT \ | |
| 1309 | + {*tests with 0 errors*} | |
| 1310 | + | |
| 1311 | +############################################################################### | |
| 1312 | +# More values of the "parent" tag. A value that ends in a space names the | |
| 1313 | +# parent before the space. A value long enough to be a hash that is not | |
| 1314 | +# one is ignored. A "parent" tag on a wiki page makes no links. | |
| 1315 | + | |
| 1316 | +set crosslinkR1 [crosslink_put "C reparent-one | |
| 1317 | +D 2026-04-01T10:00:00.000 | |
| 1318 | +U alice | |
| 1319 | +"] | |
| 1320 | +set crosslinkR2 [crosslink_put "C reparent-two | |
| 1321 | +D 2026-04-01T10:01:00.000 | |
| 1322 | +P $crosslinkR1 | |
| 1323 | +U alice | |
| 1324 | +"] | |
| 1325 | +set crosslinkR3 [crosslink_put "C reparent-three | |
| 1326 | +D 2026-04-01T10:02:00.000 | |
| 1327 | +P $crosslinkR2 | |
| 1328 | +U alice | |
| 1329 | +"] | |
| 1330 | +test crosslink-reparent-more-setup \ | |
| 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 | |
| 1342 | +U alice | |
| 1343 | +" | |
| 1344 | +test crosslink-reparent-trailing-space {$CODE == 0} | |
| 1345 | +test_eq crosslink-reparent-trailing-space-parent \ | |
| 1346 | + [crosslink_primary $crosslinkR3] $crosslinkR1 | |
| 1347 | + | |
| 1348 | +crosslink_put "D 2026-04-01T11:01:00.000 | |
| 1349 | +T +parent $crosslinkR2 [string repeat z 50] | |
| 1350 | +U alice | |
| 1351 | +" | |
| 1352 | +test crosslink-reparent-not-hex {$CODE == 0} | |
| 1353 | +test_eq crosslink-reparent-not-hex-ignored \ | |
| 1354 | + [crosslink_primary $crosslinkR2] $crosslinkR1 | |
| 1355 | + | |
| 1356 | +set crosslinkHash [crosslink_put "D 2026-04-01T11:02:00.000 | |
| 1357 | +L Reparented | |
| 1358 | +U alice | |
| 1359 | +[crosslink_w {text}]"] | |
| 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 | +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 | |
| 1382 | +# primary one. | |
| 1383 | + | |
| 1384 | +set crosslinkWa [crosslink_put "D 2026-04-02T10:00:00.000 | |
| 1385 | +L Two\\sParents | |
| 1386 | +U alice | |
| 1387 | +[crosslink_w {one}]"] | |
| 1388 | +set crosslinkWb [crosslink_put "D 2026-04-02T10:01:00.000 | |
| 1389 | +L Two\\sParents | |
| 1390 | +U alice | |
| 1391 | +[crosslink_w {other}]"] | |
| 1392 | +set crosslinkHash [crosslink_put "D 2026-04-02T10:02:00.000 | |
| 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 | + | |
| 1404 | +############################################################################### | |
| 1405 | +# An artifact whose Z card does not match its text is stored, and is | |
| 1406 | +# nothing in the timeline. | |
| 1407 | + | |
| 1408 | +write_file bad-z.txt "D 2026-04-02T11:00:00.000 | |
| 1409 | +L Bad\\sSum | |
| 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 | |
| 1423 | +# later one in the timeline. | |
| 1424 | + | |
| 1425 | +set crosslinkEid2 [string repeat e7 20] | |
| 1426 | +set crosslinkHash [crosslink_put "C note-first | |
| 1427 | +D 2026-04-03T10:00:00.000 | |
| 1428 | +E 2026-04-03T09:00:00 $crosslinkEid2 | |
| 1429 | +U alice | |
| 1430 | +[crosslink_w {first}]"] | |
| 1431 | +crosslink_put "C note-last | |
| 1432 | +D 2026-04-03T12:00:00.000 | |
| 1433 | +E 2026-04-03T09:00:00 $crosslinkEid2 | |
| 1434 | +P $crosslinkHash | |
| 1435 | +U alice | |
| 1436 | +[crosslink_w {last}]" | |
| 1437 | +crosslink_put "C note-middle | |
| 1438 | +D 2026-04-03T11:00:00.000 | |
| 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 | |
| 1450 | +# names only b.txt, as removed: a.txt is the baseline's again and is | |
| 1451 | +# linked as changed; b.txt and x.txt get no link. | |
| 1452 | + | |
| 1453 | +set crosslinkBase [crosslink_put "C two-deltas-base | |
| 1454 | +D 2026-04-04T10:00:00.000 | |
| 1455 | +F a.txt $crosslinkFa | |
| 1456 | +F b.txt $crosslinkFb | |
| 1457 | +U alice | |
| 1458 | +"] | |
| 1459 | +set crosslinkDp [crosslink_put "B $crosslinkBase | |
| 1460 | +C two-deltas-parent | |
| 1461 | +D 2026-04-04T10:01:00.000 | |
| 1462 | +F a.txt $crosslinkFb | |
| 1463 | +F b.txt | |
| 1464 | +F x.txt $crosslinkFa | |
| 1465 | +P $crosslinkBase | |
| 1466 | +U alice | |
| 1467 | +"] | |
| 1468 | +set crosslinkHash [crosslink_put "B $crosslinkBase | |
| 1469 | +C two-deltas-child | |
| 1470 | +D 2026-04-04T10:02:00.000 | |
| 1471 | +F b.txt | |
| 1472 | +P $crosslinkDp | |
| 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 | + | |
| 1484 | +############################################################################### | |
| 1485 | +# Check-ins made within the same second, each the parent of the next, and | |
| 1486 | +# stored by one command: the timeline puts every parent before its child | |
| 1487 | +# for the first thirty, and leaves the rest at the time they carry. | |
| 1488 | + | |
| 1489 | +set crosslinkFiles {} | |
| 1490 | +set crosslinkPrev "" | |
| 1491 | +for {set crosslinkI 0} {$crosslinkI < 33} {incr crosslinkI} { | |
| 1492 | + set crosslinkBody "C same-second-$crosslinkI\nD 2026-04-05T10:00:00.000\n" | |
| 1493 | + if {$crosslinkPrev ne ""} { append crosslinkBody "P $crosslinkPrev\n" } | |
| 1494 | + append crosslinkBody "U alice\n" | |
| 1495 | + set crosslinkFn [crosslink_file $crosslinkBody] | |
| 1496 | + fossil sha3sum $crosslinkFn | |
| 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 | |
| 1513 | +# stored and set aside until the baseline comes, and nothing is said. | |
| 1514 | + | |
| 1515 | +fossil init xl-from.fossil | |
| 1516 | +fossil clone xl-from.fossil xl-pull.fossil | |
| 1517 | +test crosslink-pull-orphan-clone {$CODE == 0} | |
| 1518 | +set crosslinkFn [crosslink_file "B [string repeat 5c 20] | |
| 1519 | +C pulled-without-baseline | |
| 1520 | +D 2026-04-06T10:00:00.000 | |
| 1521 | +F b.txt | |
| 1522 | +U alice | |
| 1523 | +"] | |
| 1524 | +fossil sha3sum $crosslinkFn | |
| 1525 | +set crosslinkHash [lindex $RESULT 0] | |
| 1526 | +fossil test-content-put -R xl-from.fossil --crosslink $crosslinkFn | |
| 1527 | +fossil pull xl-from.fossil -R xl-pull.fossil | |
| 1528 | +test crosslink-pull-orphan {$CODE == 0} | |
| 1529 | +fossil sql -R xl-pull.fossil "SELECT count(*) FROM orphan, blob | |
| 1530 | + WHERE orphan.rid=blob.rid AND uuid='$crosslinkHash'" | |
| 1531 | +test_eq crosslink-pull-orphan-set-aside [string trim $RESULT] 1 | |
| 1532 | +fossil sql -R xl-pull.fossil "SELECT count(*) FROM event, blob | |
| 1533 | + WHERE objid=rid AND uuid='$crosslinkHash'" | |
| 1534 | +test_eq crosslink-pull-orphan-no-event [string trim $RESULT] 0 | |
| 1535 | + | |
| 1536 | +############################################################################### | |
| 1537 | +# Artifacts that name a shunned artifact. No placeholder is made for it. | |
| 1538 | +# A cluster that lists it still clears its other members. A tag on it is | |
| 1539 | +# in the timeline and tags nothing. A check-in with it as second parent | |
| 1540 | +# gets file links to its first parent only. | |
| 1541 | + | |
| 1542 | +set crosslinkShun [string repeat 5e 20] | |
| 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 | +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 | |
| 1570 | +F a.txt $crosslinkFb | |
| 1571 | +P $crosslinkR1 $crosslinkShun | |
| 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 | + | |
| 1584 | +crosslink_script xfer-common-script {error common-script-refuses} | |
| 1585 | +fossil branch new refused $crosslinkR1 -expectError | |
| 1586 | +test crosslink-script-branch-fails {$CODE != 0} | |
| 1587 | +crosslink_match crosslink-script-branch-message $RESULT \ | |
| 1588 | + {*common-script-refuses*} | |
| 1589 | +crosslink_script xfer-common-script "" | |
| 1590 | + | |
| 1591 | +############################################################################### | |
| 1592 | +# A repository whose record of an attachment has an empty source in place | |
| 1593 | +# of none: a tech note or ticket stored for the same target words the | |
| 1594 | +# attachment as deleted. | |
| 1595 | + | |
| 1596 | +set crosslinkEid3 [string repeat e9 20] | |
| 1597 | +set crosslinkTkt3 [string repeat c9 20] | |
| 1598 | +set crosslinkAe [crosslink_put "A note.txt $crosslinkEid3 $crosslinkSrc | |
| 1599 | +D 2026-04-08T10:00:00.000 | |
| 1600 | +U alice | |
| 1601 | +"] | |
| 1602 | +set crosslinkAt [crosslink_put "A tkt.txt $crosslinkTkt3 $crosslinkSrc | |
| 1603 | +D 2026-04-08T10:01:00.000 | |
| 1604 | +U alice | |
| 1605 | +"] | |
| 1606 | +test crosslink-attach-empty-source-setup \ | |
| 1607 | + {$crosslinkAe ne "" && $crosslinkAt ne ""} | |
| 1608 | +fossil sql "UPDATE attachment SET src='' | |
| 1609 | + WHERE target IN ('$crosslinkEid3','$crosslinkTkt3')" | |
| 1610 | +crosslink_put "C attached-note | |
| 1611 | +D 2026-04-08T11:00:00.000 | |
| 1612 | +E 2026-04-08T09:00:00 $crosslinkEid3 | |
| 1613 | +U alice | |
| 1614 | +[crosslink_w {note}]" | |
| 1615 | +test crosslink-attach-empty-source-technote {$CODE == 0} | |
| 1616 | +crosslink_match crosslink-attach-empty-source-technote-event \ | |
| 1617 | + [crosslink_event $crosslinkAe] \ | |
| 1618 | + {e Delete attachment "note.txt" from tech note \[/technote/*\]} | |
| 1619 | +crosslink_put "D 2026-04-08T11:01:00.000 | |
| 1620 | +J title Attached | |
| 1621 | +K $crosslinkTkt3 | |
| 1622 | +U alice | |
| 1623 | +" | |
| 1624 | +test crosslink-attach-empty-source-ticket {$CODE == 0} | |
| 1625 | +crosslink_match crosslink-attach-empty-source-ticket-event \ | |
| 1626 | + [crosslink_event $crosslinkAt] \ | |
| 1627 | + {t Delete attachment "tkt.txt" from ticket \[*\]} | |
| 1628 | + | |
| 1629 | +############################################################################### | |
| 1630 | + | |
| 1631 | +test_cleanup |
| --- a/test/crosslink.test | |
| +++ b/test/crosslink.test | |
| @@ -0,0 +1,1631 @@ | |
| --- a/test/crosslink.test | |
| +++ b/test/crosslink.test | |
| @@ -0,0 +1,1631 @@ | |
| 1 | # |
| 2 | # What the repository database shows after an artifact of each kind has |
| 3 | # been stored and crosslinked: manifest_crosslink() and the routines |
| 4 | # around it in src/manifest.c. |
| 5 | # |
| 6 | # Each artifact is written out here card by card, given its Z card, and |
| 7 | # stored with "fossil test-content-put --crosslink". That reaches cases |
| 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 |
| 23 | |
| 24 | # Write a file that holds the cards $body and the Z card for them, and |
| 25 | # return its name. |
| 26 | # |
| 27 | proc crosslink_file {body} { |
| 28 | global crosslinkSeq RESULT |
| 29 | set fn artifact-[incr crosslinkSeq].txt |
| 30 | set fd [open $fn wb] |
| 31 | puts -nonewline $fd $body |
| 32 | close $fd |
| 33 | fossil md5sum $fn |
| 34 | set sum [lindex $RESULT 0] |
| 35 | set fd [open $fn ab] |
| 36 | puts -nonewline $fd "Z $sum\n" |
| 37 | close $fd |
| 38 | return $fn |
| 39 | } |
| 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" |
| 58 | set hash [string trim $RESULT '] |
| 59 | } |
| 60 | set CODE $code |
| 61 | set RESULT $result |
| 62 | return $hash |
| 63 | } |
| 64 | |
| 65 | # A W card for the given text. |
| 66 | # |
| 67 | proc crosslink_w {text} { |
| 68 | return "W [string length $text]\n$text\n" |
| 69 | } |
| 70 | |
| 71 | # Test NAME passes if ACTUAL matches the glob PATTERN. |
| 72 | # |
| 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] |
| 95 | |
| 96 | ############################################################################### |
| 97 | # Wiki pages: a new page, an edit, and an edit that empties the page. |
| 98 | |
| 99 | set crosslinkW1 [crosslink_put "D 2026-01-01T10:00:00.000 |
| 100 | L Crosslink\\sPage |
| 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 | 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 |
| 123 | P $crosslinkW2 |
| 124 | U alice |
| 125 | [crosslink_w {}]"] |
| 126 | test_eq crosslink-wiki-empty-event [crosslink_event $crosslinkW3] \ |
| 127 | {w -Crosslink Page} |
| 128 | |
| 129 | # A parent that is not in the repository: the page still counts as an |
| 130 | # edit. |
| 131 | set crosslinkW4 [crosslink_put "D 2026-01-01T12:30:00.000 |
| 132 | L Orphan |
| 133 | P $crosslinkNone |
| 134 | U alice |
| 135 | [crosslink_w {text}]"] |
| 136 | test_eq crosslink-wiki-missing-parent [crosslink_event $crosslinkW4] \ |
| 137 | {w :Orphan} |
| 138 | |
| 139 | ############################################################################### |
| 140 | # Tech notes: a note, a later version of it, and an earlier version that |
| 141 | # arrives last. |
| 142 | |
| 143 | set crosslinkEid [string repeat ab 20] |
| 144 | set crosslinkE1 [crosslink_put "C First\\snote |
| 145 | D 2026-01-02T10:00:00.000 |
| 146 | E 2026-01-02T09:00:00 $crosslinkEid |
| 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. |
| 176 | |
| 177 | set crosslinkTkt [string repeat cd 20] |
| 178 | set crosslinkT1 [crosslink_put "D 2026-01-03T10:00:00.000 |
| 179 | J status Open |
| 180 | J title Crosslink\\sticket |
| 181 | K $crosslinkTkt |
| 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 |
| 212 | K $crosslinkTkt |
| 213 | U alice |
| 214 | "] |
| 215 | crosslink_match crosslink-ticket-no-status-two [crosslink_event $crosslinkT4] \ |
| 216 | {t Ticket * status still Closed with 2 other changes} |
| 217 | |
| 218 | set crosslinkT5 [crosslink_put "D 2026-01-03T14:00:00.000 |
| 219 | J +comment more\\stext |
| 220 | K $crosslinkTkt |
| 221 | U alice |
| 222 | "] |
| 223 | crosslink_match crosslink-ticket-no-status-one [crosslink_event $crosslinkT5] \ |
| 224 | {t Ticket * status still Closed with 1 other change} |
| 225 | |
| 226 | set crosslinkT6 [crosslink_put "D 2026-01-03T15:00:00.000 |
| 227 | J status Verified |
| 228 | K $crosslinkTkt |
| 229 | U alice |
| 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 |
| 241 | # arrives last. |
| 242 | |
| 243 | set crosslinkFtext "See \[[string range $crosslinkW1 0 15]\]." |
| 244 | set crosslinkF1 [crosslink_put "D 2026-01-04T10:00:01.000 |
| 245 | H Crosslink\\sthread |
| 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 |
| 257 | I $crosslinkF1 |
| 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 | |
| 269 | set crosslinkF3 [crosslink_put "D 2026-01-04T12:00:00.000 |
| 270 | G $crosslinkF1 |
| 271 | I $crosslinkF1 |
| 272 | P $crosslinkF2 |
| 273 | U bob |
| 274 | [crosslink_w {reply2}]"] |
| 275 | test_eq crosslink-forum-reply-edit-event [crosslink_event $crosslinkF3] \ |
| 276 | {f Edit reply: Crosslink thread} |
| 277 | |
| 278 | set crosslinkF4 [crosslink_put "D 2026-01-04T13:00:00.000 |
| 279 | G $crosslinkF1 |
| 280 | I $crosslinkF1 |
| 281 | P $crosslinkF3 |
| 282 | U bob |
| 283 | [crosslink_w {}]"] |
| 284 | test_eq crosslink-forum-reply-delete-event [crosslink_event $crosslinkF4] \ |
| 285 | {f Delete reply: Crosslink thread} |
| 286 | |
| 287 | set crosslinkF5 [crosslink_put "D 2026-01-04T14:00:00.000 |
| 288 | G $crosslinkF1 |
| 289 | H New\\stitle |
| 290 | P $crosslinkF1 |
| 291 | U alice |
| 292 | [crosslink_w {text}]"] |
| 293 | test_eq crosslink-forum-edit-event [crosslink_event $crosslinkF5] \ |
| 294 | {f Edit: New title} |
| 295 | test_eq crosslink-forum-edit-retitles-thread [crosslink_event $crosslinkF2] \ |
| 296 | {f Reply: New title} |
| 297 | |
| 298 | # An edit of the first post dated before the one above does not change |
| 299 | # the title of the thread. |
| 300 | set crosslinkF6 [crosslink_put "D 2026-01-04T13:30:00.000 |
| 301 | G $crosslinkF1 |
| 302 | H Older\\stitle |
| 303 | P $crosslinkF1 |
| 304 | U alice |
| 305 | [crosslink_w {text}]"] |
| 306 | test_eq crosslink-forum-older-edit-event [crosslink_event $crosslinkF6] \ |
| 307 | {f Edit: Older title} |
| 308 | test_eq crosslink-forum-older-edit-keeps-title [crosslink_event $crosslinkF2] \ |
| 309 | {f Reply: New title} |
| 310 | |
| 311 | # A first post with its title removed. |
| 312 | set crosslinkF7 [crosslink_put "D 2026-01-04T15:00:00.000 |
| 313 | G $crosslinkF1 |
| 314 | P $crosslinkF5 |
| 315 | U alice |
| 316 | [crosslink_w {}]"] |
| 317 | test_eq crosslink-forum-deleted-thread [crosslink_event $crosslinkF7] \ |
| 318 | {f Edit: (Deleted)} |
| 319 | |
| 320 | # A reply to a thread whose first post is not in the repository. |
| 321 | set crosslinkF8 [crosslink_put "D 2026-01-04T16:00:00.000 |
| 322 | G $crosslinkNone |
| 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] |
| 333 | foreach {crosslinkKind crosslinkTarget crosslinkType crosslinkAdd |
| 334 | crosslinkDel} [list \ |
| 335 | wiki Crosslink\\sPage w {*to wiki page \[Crosslink Page\]*} \ |
| 336 | {*from wiki page \[Crosslink Page\]*} \ |
| 337 | technote $crosslinkEid e {*to tech note *} \ |
| 338 | {"file.txt" from tech note \[/technote/*\]} \ |
| 339 | ticket $crosslinkTkt t {*to ticket *} {*from ticket *} \ |
| 340 | forum $crosslinkF1 f {*to forum post *} {*from forum post *} \ |
| 341 | unknown $crosslinkNone2 a {*to \[/artifact/*} \ |
| 342 | {"file.txt" from \[/artifact/*\]} \ |
| 343 | ] { |
| 344 | set crosslinkA [crosslink_put "A file.txt $crosslinkTarget $crosslinkSrc |
| 345 | C A\\scomment |
| 346 | D 2026-01-05T10:00:00.000 |
| 347 | U alice |
| 348 | "] |
| 349 | test crosslink-attach-$crosslinkKind-add {$CODE == 0 && $crosslinkA ne ""} |
| 350 | set crosslinkEv [crosslink_event $crosslinkA] |
| 351 | crosslink_match crosslink-attach-$crosslinkKind-add-event $crosslinkEv \ |
| 352 | "$crosslinkType Add attachment $crosslinkAdd" |
| 353 | set crosslinkA [crosslink_put "A file.txt $crosslinkTarget |
| 354 | D 2026-01-05T11:00:00.000 |
| 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 | ############################################################################### |
| 390 | # Check-ins made by hand, and the tags put on them. |
| 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".*} \ |
| 424 | other-value "+thing2 * val" {*Add "thing2" with value "val".*} \ |
| 425 | other-prop "*thing3 *" {*Add propagating "thing3".*} \ |
| 426 | other-cancel "-thing *" {*Cancel "thing".*} \ |
| 427 | ] { |
| 428 | set crosslinkCard [string map [list " * " " $crosslinkC1 "] $crosslinkCard] |
| 429 | if {[string match "* \\*" $crosslinkCard]} { |
| 430 | set crosslinkCard "[string range $crosslinkCard 0 end-1]$crosslinkC1" |
| 431 | } |
| 432 | set crosslinkG [crosslink_put "D 2026-01-06T10:00:[format %02d \ |
| 433 | [incr crosslinkSeq 0]].000 |
| 434 | T $crosslinkCard |
| 435 | U alice |
| 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 |
| 452 | "] |
| 453 | crosslink_match crosslink-tag-branch-move-quiet [crosslink_event $crosslinkG] \ |
| 454 | {g Edit *: Move to branch *moved*} |
| 455 | test crosslink-tag-branch-move-no-sym \ |
| 456 | {![string match *tag* [crosslink_event $crosslinkG]]} |
| 457 | |
| 458 | # Tags for two check-ins in one artifact are listed under each. |
| 459 | set crosslinkTwo [lsort [list $crosslinkC1 $crosslinkW1]] |
| 460 | set crosslinkG [crosslink_put "D 2026-01-06T11:15:00.000 |
| 461 | T +sym-both [lindex $crosslinkTwo 0] |
| 462 | T +sym-both [lindex $crosslinkTwo 1] |
| 463 | U alice |
| 464 | "] |
| 465 | crosslink_match crosslink-tag-two-targets [crosslink_event $crosslinkG] \ |
| 466 | {g Edit *: Add tag "both". Edit *: Add tag "both".} |
| 467 | |
| 468 | # A tag on an artifact that is not in the repository is recorded against |
| 469 | # a phantom. |
| 470 | set crosslinkG [crosslink_put "D 2026-01-06T11:30:00.000 |
| 471 | T +sym-far $crosslinkNone |
| 472 | U alice |
| 473 | "] |
| 474 | crosslink_match crosslink-tag-on-missing [crosslink_event $crosslinkG] \ |
| 475 | {g Edit *: Add tag "far".} |
| 476 | |
| 477 | ############################################################################### |
| 478 | # A check-in with a second parent, a cherrypick, a symbolic link, an |
| 479 | # executable and a renamed file. |
| 480 | |
| 481 | set crosslinkM1 [crosslink_put "C crosslink-c2 |
| 482 | D 2026-01-07T10:00:00.000 |
| 483 | F a.txt $crosslinkFa x |
| 484 | F c.txt $crosslinkFb w b.txt |
| 485 | F l.txt $crosslinkFa l |
| 486 | P $crosslinkC1 |
| 487 | Q +$crosslinkC1 |
| 488 | Q -$crosslinkC1 $crosslinkC1 |
| 489 | T +sym-made-by-hand * |
| 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, |
| 506 | # so the file is back. |
| 507 | set crosslinkM2 [crosslink_put "B $crosslinkM1 |
| 508 | C crosslink-c3 |
| 509 | D 2026-01-07T11:00:00.000 |
| 510 | F a.txt |
| 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 |
| 527 | F c.txt |
| 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 | |
| 539 | set crosslinkM4 [crosslink_put "C crosslink-c5 |
| 540 | D 2026-01-07T13:00:00.000 |
| 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 | |
| 552 | # The files of each of them can be listed and checked out. |
| 553 | foreach crosslinkCi [list $crosslinkM1 $crosslinkM2 $crosslinkM3 $crosslinkM4] { |
| 554 | fossil ls -r $crosslinkCi |
| 555 | test crosslink-ls-[string range $crosslinkCi 0 7] {$CODE == 0} |
| 556 | } |
| 557 | fossil ls -r $crosslinkM3 |
| 558 | test_eq crosslink-ls-delta [normalize_result] "a.txt\nd.txt\ne.txt\nl.txt" |
| 559 | |
| 560 | # A file that a delta manifest removes cannot be read from that check-in, |
| 561 | # and one that it leaves alone comes from the baseline. |
| 562 | fossil cat a.txt -r $crosslinkM2 -expectError |
| 563 | test crosslink-cat-removed-by-delta {$CODE != 0} |
| 564 | fossil cat l.txt -r $crosslinkM2 |
| 565 | test_eq crosslink-cat-from-baseline [normalize_result] a |
| 566 | |
| 567 | # A check-in that picks a change from a check-in that is not in the |
| 568 | # repository. |
| 569 | set crosslinkM5 [crosslink_put "C crosslink-c6 |
| 570 | D 2026-01-07T13:30:00.000 |
| 571 | F a.txt $crosslinkFa |
| 572 | P $crosslinkM4 |
| 573 | Q +$crosslinkNone |
| 574 | U alice |
| 575 | "] |
| 576 | test_eq crosslink-cherrypick-of-missing [crosslink_event $crosslinkM5] \ |
| 577 | {ci crosslink-c6} |
| 578 | |
| 579 | # A check-in whose baseline is not in the repository is stored but not |
| 580 | # shown, and so is anything that is not an artifact. |
| 581 | set crosslinkBad [crosslink_put "B $crosslinkNone |
| 582 | C crosslink-no-baseline |
| 583 | D 2026-01-07T14:00:00.000 |
| 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 |
| 595 | D 2026-01-07T14:30:00.000 |
| 596 | F a.txt $crosslinkFa |
| 597 | P $crosslinkBad |
| 598 | U alice |
| 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. |
| 632 | set crosslinkI 0 |
| 633 | foreach {crosslinkName crosslinkValue} [list \ |
| 634 | two-sha3-short "$crosslinkM1\\s$crosslinkM2\\sx" \ |
| 635 | one-sha3-short "$crosslinkM1\\sx" \ |
| 636 | one-sha1-short "[string repeat a 40]\\sxxxxx" \ |
| 637 | ] { |
| 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 |
| 692 | } |
| 693 | # Every artifact that the repository shows in its timeline has a JSON |
| 694 | # form. |
| 695 | fossil sql "SELECT uuid FROM blob WHERE rid IN (SELECT objid FROM event)" |
| 696 | set crosslinkAll [string map {' {}} $RESULT] |
| 697 | fossil test-artifact-to-json {*}$crosslinkAll |
| 698 | test crosslink-json-every-artifact {$CODE == 0 && [llength $crosslinkAll] > 30} |
| 699 | |
| 700 | fossil test-artifact-to-json --pretty $crosslinkW1 $crosslinkT1 |
| 701 | test crosslink-json-pretty {$CODE == 0} |
| 702 | crosslink_match crosslink-json-pretty-text $RESULT "*\"type\": \"wiki\"*" |
| 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 | ############################################################################### |
| 726 | # What the parser refuses, and the reason it gives. |
| 727 | |
| 728 | set crosslinkH40 [string repeat ab 20] |
| 729 | foreach {crosslinkName crosslinkBody crosslinkWant} [list \ |
| 730 | cards-out-of-order "U alice\nD 2026-02-01T10:00:00.000\n" \ |
| 731 | {*cards not in lexicographical order*} \ |
| 732 | bad-card-type "D 2026-02-01T10:00:00.000\na b\n" \ |
| 733 | {*bad card type*} \ |
| 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 \ |
| 754 | "*ERROR:$crosslinkWant" |
| 755 | } |
| 756 | |
| 757 | # A file that does not end in a newline, an empty one, and one whose Z |
| 758 | # card does not match. |
| 759 | write_file refuse-no-newline.txt "D 2026-02-01T10:00:00.000\nU alice" |
| 760 | fossil test-parse-manifest refuse-no-newline.txt |
| 761 | crosslink_match crosslink-refuse-no-newline $RESULT {*ERROR:*not terminated*} |
| 762 | write_file refuse-empty.txt "" |
| 763 | fossil test-parse-manifest refuse-empty.txt |
| 764 | crosslink_match crosslink-refuse-empty $RESULT {*ERROR:*zero-length*} |
| 765 | write_file refuse-checksum.txt \ |
| 766 | "D 2026-02-01T10:00:00.000\nU alice\nZ [string repeat 0 32]\n" |
| 767 | fossil test-parse-manifest refuse-checksum.txt |
| 768 | crosslink_match crosslink-refuse-checksum $RESULT \ |
| 769 | {*ERROR:*incorrect Z-card cksum*} |
| 770 | |
| 771 | # Files without a comment are still a check-in. |
| 772 | fossil test-parse-manifest [crosslink_file \ |
| 773 | "D 2026-02-01T10:00:00.000\nF a.txt $crosslinkH40\nU alice\n"] |
| 774 | crosslink_match crosslink-files-without-comment $RESULT \ |
| 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. |
| 789 | foreach {crosslinkName crosslinkText} [list \ |
| 790 | digit-first "1 x and some more text\nD x\n" \ |
| 791 | no-space "AB and some more text\nD x\n" \ |
| 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} |
| 803 | } |
| 804 | fossil test-parse-all-blobs --wellformed |
| 805 | crosslink_match crosslink-wellformed-agrees $RESULT {*tests with 0 errors*} |
| 806 | |
| 807 | # A name that is not a check-in, where one is needed. |
| 808 | fossil ls -r $crosslinkW1 -expectError |
| 809 | test crosslink-wiki-is-not-a-checkin {$CODE != 0} |
| 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(*} |
| 833 | |
| 834 | ############################################################################### |
| 835 | # The commands that parse artifacts again. |
| 836 | |
| 837 | fossil artifact $crosslinkM1 checkin.txt |
| 838 | fossil test-parse-manifest checkin.txt |
| 839 | test crosslink-parse-manifest {$CODE == 0} |
| 840 | crosslink_match crosslink-parse-manifest-text $RESULT {*is ok*} |
| 841 | fossil test-parse-manifest checkin.txt 5 |
| 842 | test crosslink-parse-manifest-repeat {$CODE == 0} |
| 843 | fossil test-parse-manifest checkin.txt 2 |
| 844 | crosslink_match crosslink-parse-manifest-twice $RESULT \ |
| 845 | {*manifest_parse() worked*manifest_parse() worked*} |
| 846 | fossil test-parse-manifest not-an-artifact.txt 3 |
| 847 | crosslink_match crosslink-parse-manifest-bad $RESULT {*contains errors*} |
| 848 | fossil test-parse-manifest -expectError |
| 849 | test crosslink-parse-manifest-usage {$CODE != 0} |
| 850 | |
| 851 | fossil test-parse-all-blobs |
| 852 | test crosslink-parse-all {$CODE == 0} |
| 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 | ############################################################################### |
| 872 | # A rebuild reaches the same state from the artifacts alone. |
| 873 | |
| 874 | set crosslinkState {SELECT (SELECT count(*) FROM event) || ' ' || |
| 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 | |
| 893 | ############################################################################### |
| 894 | # The kind of an artifact that has no card naming its kind: a comment, a |
| 895 | # file or a parent card alone makes a check-in; none of them makes a |
| 896 | # control artifact, which has no entry in the timeline. Each row of the |
| 897 | # table has one of the three and no other. |
| 898 | |
| 899 | foreach {crosslinkName crosslinkBody crosslinkKind} [list \ |
| 900 | comment-only "C only\\sa\\scomment\nD 2026-03-01T10:00:00.000\nU alice\n" ci \ |
| 901 | file-only "D 2026-03-01T10:01:00.000\nF a.txt $crosslinkFa\nU alice\n" ci \ |
| 902 | parent-only "D 2026-03-01T10:02:00.000\nP $crosslinkC1\nU alice\n" ci \ |
| 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*} |
| 914 | } |
| 915 | |
| 916 | ############################################################################### |
| 917 | # The links between a check-in and its parents when the parents arrive |
| 918 | # after it, in either order. A merge parent that arrives while the first |
| 919 | # parent is still missing adds no file links; they are added when the |
| 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 |
| 945 | "] |
| 946 | test crosslink-mcdc-merge-child {$CODE == 0 && $crosslinkKid ne ""} |
| 947 | test_eq crosslink-mcdc-merge-child-event [crosslink_event $crosslinkKid] \ |
| 948 | {ci merge kid} |
| 949 | |
| 950 | # The second parent first: no links yet. |
| 951 | set crosslinkGot [crosslink_put "C second\\sparent |
| 952 | D 2026-03-02T10:01:00.000 |
| 953 | F a.txt $crosslinkFb |
| 954 | U alice |
| 955 | "] |
| 956 | test_eq crosslink-mcdc-merge-parent-first-hash $crosslinkGot $crosslinkPB |
| 957 | test_eq crosslink-mcdc-merge-parent-first-links \ |
| 958 | [crosslink_links $crosslinkKid $crosslinkPB] 0 |
| 959 | |
| 960 | # Then the first parent: links to both. |
| 961 | set crosslinkGot [crosslink_put "C first\\sparent |
| 962 | D 2026-03-02T10:00:00.000 |
| 963 | F a.txt $crosslinkFa |
| 964 | U alice |
| 965 | "] |
| 966 | test_eq crosslink-mcdc-merge-parent-second-hash $crosslinkGot $crosslinkPA |
| 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 | " |
| 979 | set crosslinkKid2 [crosslink_put "C other\\skid |
| 980 | D 2026-03-02T13:00:00.000 |
| 981 | F a.txt $crosslinkNone |
| 982 | P $crosslinkQA $crosslinkQB |
| 983 | U alice |
| 984 | "] |
| 985 | test_eq crosslink-mcdc-merge-second-missing-links \ |
| 986 | [list [crosslink_links $crosslinkKid2 $crosslinkQA] \ |
| 987 | [crosslink_links $crosslinkKid2 $crosslinkQB]] {1 0} |
| 988 | crosslink_put "C other\\ssecond |
| 989 | D 2026-03-02T12:01:00.000 |
| 990 | F a.txt $crosslinkFb |
| 991 | U alice |
| 992 | " |
| 993 | test_eq crosslink-mcdc-merge-second-arrives-links \ |
| 994 | [list [crosslink_links $crosslinkKid2 $crosslinkQA] \ |
| 995 | [crosslink_links $crosslinkKid2 $crosslinkQB]] {1 1} |
| 996 | |
| 997 | ############################################################################### |
| 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 \ |
| 1013 | [crosslink_event $crosslinkHash] $crosslinkWant |
| 1014 | fossil test-artifact-to-json $crosslinkHash |
| 1015 | crosslink_match crosslink-mcdc-forum-$crosslinkName-json $RESULT \ |
| 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 |
| 1027 | foreach {crosslinkName crosslinkCard crosslinkWant} [list \ |
| 1028 | sym-empty "+sym-empty" {*Add tag "empty".} \ |
| 1029 | other-empty "+other-empty" {*Add "other-empty".} \ |
| 1030 | other-value "+other-value" {*Add "other-value" with value "v".} \ |
| 1031 | ] { |
| 1032 | set crosslinkValue [expr {$crosslinkName eq "other-value" ? "v" : ""}] |
| 1033 | set crosslinkHash [crosslink_put "D 2026-03-04T10:[incr crosslinkMin]:00.000 |
| 1034 | T $crosslinkCard $crosslinkC1 $crosslinkValue |
| 1035 | U alice |
| 1036 | "] |
| 1037 | test crosslink-mcdc-tag-$crosslinkName {$CODE == 0 && $crosslinkHash ne ""} |
| 1038 | crosslink_match crosslink-mcdc-tag-$crosslinkName-event \ |
| 1039 | [crosslink_event $crosslinkHash] "g Edit *:$crosslinkWant" |
| 1040 | } |
| 1041 | |
| 1042 | ############################################################################### |
| 1043 | # A check-in that picks a change from a check-in the repository has never |
| 1044 | # seen, and from one it has: only the second gets file links to it. |
| 1045 | |
| 1046 | set crosslinkUnseen [string repeat 5a 20] |
| 1047 | foreach {crosslinkName crosslinkTarget} [list unseen $crosslinkUnseen \ |
| 1048 | known $crosslinkM1] { |
| 1049 | set crosslinkHash [crosslink_put "C cherry-$crosslinkName |
| 1050 | D 2026-03-05T10:[incr crosslinkMin]:00.000 |
| 1051 | F a.txt $crosslinkFa |
| 1052 | P $crosslinkC1 |
| 1053 | Q +$crosslinkTarget |
| 1054 | U alice |
| 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 \ |
| 1080 | ticket $crosslinkT1 0 \ |
| 1081 | forum $crosslinkF1 0 \ |
| 1082 | file $crosslinkFa 0 \ |
| 1083 | nothing $crosslinkNone2 0 \ |
| 1084 | ] { |
| 1085 | set crosslinkReply [crosslink_get /winfo?name=$crosslinkHash] |
| 1086 | test crosslink-mcdc-winfo-$crosslinkName \ |
| 1087 | {[string match "HTTP/1.0 200*" $crosslinkReply]} |
| 1088 | test crosslink-mcdc-winfo-$crosslinkName-answer \ |
| 1089 | {[string match "*No such object*" $crosslinkReply] == !$crosslinkIs} |
| 1090 | } |
| 1091 | |
| 1092 | ############################################################################### |
| 1093 | # A check-in on a delta manifest that removed a file, where the check-in |
| 1094 | # has the file again: the file is new in it. A file the delta manifest |
| 1095 | # does not mention is compared with the baseline's, so that l.txt, the |
| 1096 | # same as in the baseline, has no link, and the files the delta manifest |
| 1097 | # added or changed are removed. |
| 1098 | |
| 1099 | set crosslinkBack [crosslink_put "C file-back-after-delta |
| 1100 | D 2026-03-06T10:00:00.000 |
| 1101 | F a.txt $crosslinkFa |
| 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 | |
| 1113 | ############################################################################### |
| 1114 | # A delta manifest that removes a file its baseline does not have, and a |
| 1115 | # check-in on it: the check-in has no link for that name. The files of |
| 1116 | # the baseline that the check-in lacks are removed in it. |
| 1117 | |
| 1118 | set crosslinkGhost [crosslink_put "B $crosslinkM1 |
| 1119 | C delta-removes-unknown |
| 1120 | D 2026-03-07T10:00:00.000 |
| 1121 | F zz-never.txt |
| 1122 | P $crosslinkM1 |
| 1123 | U alice |
| 1124 | "] |
| 1125 | test crosslink-mcdc-delta-removes-unknown {$CODE == 0 && $crosslinkGhost ne ""} |
| 1126 | test_eq crosslink-mcdc-delta-removes-unknown-event \ |
| 1127 | [crosslink_event $crosslinkGhost] {ci delta-removes-unknown} |
| 1128 | set crosslinkHash [crosslink_put "C child-of-delta-removes-unknown |
| 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 | |
| 1140 | ############################################################################### |
| 1141 | # A delta manifest whose baseline is not in the repository is not a |
| 1142 | # check-in. A "parent" tag on it is recorded as its parent, and no file |
| 1143 | # links are made while the baseline is missing. |
| 1144 | |
| 1145 | set crosslinkKid3 [crosslink_put "B [string repeat 6b 20] |
| 1146 | C delta-without-baseline |
| 1147 | D 2026-03-07T11:00:00.000 |
| 1148 | F b.txt |
| 1149 | P $crosslinkC1 |
| 1150 | U alice |
| 1151 | "] |
| 1152 | test crosslink-mcdc-reparent-no-baseline {$CODE == 0 && $crosslinkKid3 ne ""} |
| 1153 | test_eq crosslink-mcdc-reparent-no-baseline-no-event \ |
| 1154 | [crosslink_event $crosslinkKid3] {} |
| 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 | |
| 1166 | ############################################################################### |
| 1167 | # A check-in whose parent is a wiki page, and a delta manifest whose |
| 1168 | # baseline is the same wiki page, stored by one command: the first is a |
| 1169 | # check-in, the second is not and is recorded as waiting for a baseline. |
| 1170 | |
| 1171 | set crosslinkOnWiki [crosslink_file "C child-of-wiki-page |
| 1172 | D 2026-03-07T12:00:00.000 |
| 1173 | F a.txt $crosslinkFa |
| 1174 | P $crosslinkW1 |
| 1175 | U alice |
| 1176 | "] |
| 1177 | set crosslinkBasedOnWiki [crosslink_file "B $crosslinkW1 |
| 1178 | C based-on-wiki-page |
| 1179 | D 2026-03-07T12:01:00.000 |
| 1180 | F a.txt $crosslinkFa |
| 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 ""} { |
| 1206 | fossil sql "DELETE FROM config WHERE name='$name'" |
| 1207 | } else { |
| 1208 | fossil sql "REPLACE INTO config(name,value,mtime) |
| 1209 | VALUES('$name','$script',now())" |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | crosslink_script xfer-commit-script {query {SELECT artifact_to_json(pid) AS j |
| 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 |
| 1246 | # them. A check-in with a Q card is still a check-in there, and a |
| 1247 | # rebuild makes the table and records the cherrypick. |
| 1248 | |
| 1249 | fossil sql "DROP TABLE cherrypick" |
| 1250 | set crosslinkHash [crosslink_put "C cherry-no-table |
| 1251 | D 2026-03-07T13:00:00.000 |
| 1252 | F a.txt $crosslinkFa |
| 1253 | P $crosslinkC1 |
| 1254 | Q +$crosslinkM1 |
| 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. |
| 1270 | # |
| 1271 | # A signed artifact is an artifact. A check-in whose second card is a P |
| 1272 | # card that names no parent is an artifact. A signed artifact whose |
| 1273 | # signature does not end in a newline is not an artifact. |
| 1274 | |
| 1275 | set crosslinkSigned "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n" |
| 1276 | append crosslinkSigned [read_file [crosslink_file \ |
| 1277 | "D 2026-03-08T10:00:00.000\nL Signed\nU alice\n[crosslink_w {x}]"]] |
| 1278 | append crosslinkSigned "-----BEGIN PGP SIGNATURE-----\nabc\n" |
| 1279 | append crosslinkSigned "-----END PGP SIGNATURE-----" |
| 1280 | write_file wf-signed.txt "$crosslinkSigned\n" |
| 1281 | write_file wf-signed-no-newline.txt $crosslinkSigned |
| 1282 | set crosslinkEmptyP [crosslink_file \ |
| 1283 | "D 2026-03-08T10:01:00.000\nP\nR d41d8cd98f00b204e9800998ecf8427e\n"] |
| 1284 | |
| 1285 | fossil test-parse-manifest wf-signed.txt |
| 1286 | crosslink_match crosslink-mcdc-agree-signed $RESULT \ |
| 1287 | {*reports the input is ok*manifest_parse() worked} |
| 1288 | |
| 1289 | fossil test-parse-manifest $crosslinkEmptyP |
| 1290 | crosslink_match crosslink-mcdc-agree-empty-p-parses $RESULT \ |
| 1291 | {*manifest_parse() worked*} |
| 1292 | test crosslink-mcdc-agree-empty-p {![string match *disagree* $RESULT]} |
| 1293 | |
| 1294 | fossil test-parse-manifest wf-signed-no-newline.txt |
| 1295 | crosslink_match crosslink-mcdc-agree-signed-no-newline-refused $RESULT \ |
| 1296 | {*ERROR: not terminated*} |
| 1297 | test crosslink-mcdc-agree-signed-no-newline \ |
| 1298 | {![string match *disagree* $RESULT]} |
| 1299 | |
| 1300 | # The same for content held by a repository. |
| 1301 | fossil init wf.fossil |
| 1302 | fossil test-content-put -R wf.fossil wf-signed.txt $crosslinkEmptyP \ |
| 1303 | wf-signed-no-newline.txt |
| 1304 | test crosslink-mcdc-agree-stored {$CODE == 0} |
| 1305 | fossil test-parse-all-blobs --wellformed -R wf.fossil |
| 1306 | test crosslink-mcdc-agree-stored-checked \ |
| 1307 | {$CODE == 0 && [regexp {(\d+) tests with} $RESULT all n] && $n >= 3} |
| 1308 | crosslink_match crosslink-mcdc-agree-stored-no-errors $RESULT \ |
| 1309 | {*tests with 0 errors*} |
| 1310 | |
| 1311 | ############################################################################### |
| 1312 | # More values of the "parent" tag. A value that ends in a space names the |
| 1313 | # parent before the space. A value long enough to be a hash that is not |
| 1314 | # one is ignored. A "parent" tag on a wiki page makes no links. |
| 1315 | |
| 1316 | set crosslinkR1 [crosslink_put "C reparent-one |
| 1317 | D 2026-04-01T10:00:00.000 |
| 1318 | U alice |
| 1319 | "] |
| 1320 | set crosslinkR2 [crosslink_put "C reparent-two |
| 1321 | D 2026-04-01T10:01:00.000 |
| 1322 | P $crosslinkR1 |
| 1323 | U alice |
| 1324 | "] |
| 1325 | set crosslinkR3 [crosslink_put "C reparent-three |
| 1326 | D 2026-04-01T10:02:00.000 |
| 1327 | P $crosslinkR2 |
| 1328 | U alice |
| 1329 | "] |
| 1330 | test crosslink-reparent-more-setup \ |
| 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 |
| 1342 | U alice |
| 1343 | " |
| 1344 | test crosslink-reparent-trailing-space {$CODE == 0} |
| 1345 | test_eq crosslink-reparent-trailing-space-parent \ |
| 1346 | [crosslink_primary $crosslinkR3] $crosslinkR1 |
| 1347 | |
| 1348 | crosslink_put "D 2026-04-01T11:01:00.000 |
| 1349 | T +parent $crosslinkR2 [string repeat z 50] |
| 1350 | U alice |
| 1351 | " |
| 1352 | test crosslink-reparent-not-hex {$CODE == 0} |
| 1353 | test_eq crosslink-reparent-not-hex-ignored \ |
| 1354 | [crosslink_primary $crosslinkR2] $crosslinkR1 |
| 1355 | |
| 1356 | set crosslinkHash [crosslink_put "D 2026-04-01T11:02:00.000 |
| 1357 | L Reparented |
| 1358 | U alice |
| 1359 | [crosslink_w {text}]"] |
| 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 | 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 |
| 1382 | # primary one. |
| 1383 | |
| 1384 | set crosslinkWa [crosslink_put "D 2026-04-02T10:00:00.000 |
| 1385 | L Two\\sParents |
| 1386 | U alice |
| 1387 | [crosslink_w {one}]"] |
| 1388 | set crosslinkWb [crosslink_put "D 2026-04-02T10:01:00.000 |
| 1389 | L Two\\sParents |
| 1390 | U alice |
| 1391 | [crosslink_w {other}]"] |
| 1392 | set crosslinkHash [crosslink_put "D 2026-04-02T10:02:00.000 |
| 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 | |
| 1404 | ############################################################################### |
| 1405 | # An artifact whose Z card does not match its text is stored, and is |
| 1406 | # nothing in the timeline. |
| 1407 | |
| 1408 | write_file bad-z.txt "D 2026-04-02T11:00:00.000 |
| 1409 | L Bad\\sSum |
| 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 |
| 1423 | # later one in the timeline. |
| 1424 | |
| 1425 | set crosslinkEid2 [string repeat e7 20] |
| 1426 | set crosslinkHash [crosslink_put "C note-first |
| 1427 | D 2026-04-03T10:00:00.000 |
| 1428 | E 2026-04-03T09:00:00 $crosslinkEid2 |
| 1429 | U alice |
| 1430 | [crosslink_w {first}]"] |
| 1431 | crosslink_put "C note-last |
| 1432 | D 2026-04-03T12:00:00.000 |
| 1433 | E 2026-04-03T09:00:00 $crosslinkEid2 |
| 1434 | P $crosslinkHash |
| 1435 | U alice |
| 1436 | [crosslink_w {last}]" |
| 1437 | crosslink_put "C note-middle |
| 1438 | D 2026-04-03T11:00:00.000 |
| 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 |
| 1450 | # names only b.txt, as removed: a.txt is the baseline's again and is |
| 1451 | # linked as changed; b.txt and x.txt get no link. |
| 1452 | |
| 1453 | set crosslinkBase [crosslink_put "C two-deltas-base |
| 1454 | D 2026-04-04T10:00:00.000 |
| 1455 | F a.txt $crosslinkFa |
| 1456 | F b.txt $crosslinkFb |
| 1457 | U alice |
| 1458 | "] |
| 1459 | set crosslinkDp [crosslink_put "B $crosslinkBase |
| 1460 | C two-deltas-parent |
| 1461 | D 2026-04-04T10:01:00.000 |
| 1462 | F a.txt $crosslinkFb |
| 1463 | F b.txt |
| 1464 | F x.txt $crosslinkFa |
| 1465 | P $crosslinkBase |
| 1466 | U alice |
| 1467 | "] |
| 1468 | set crosslinkHash [crosslink_put "B $crosslinkBase |
| 1469 | C two-deltas-child |
| 1470 | D 2026-04-04T10:02:00.000 |
| 1471 | F b.txt |
| 1472 | P $crosslinkDp |
| 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 | |
| 1484 | ############################################################################### |
| 1485 | # Check-ins made within the same second, each the parent of the next, and |
| 1486 | # stored by one command: the timeline puts every parent before its child |
| 1487 | # for the first thirty, and leaves the rest at the time they carry. |
| 1488 | |
| 1489 | set crosslinkFiles {} |
| 1490 | set crosslinkPrev "" |
| 1491 | for {set crosslinkI 0} {$crosslinkI < 33} {incr crosslinkI} { |
| 1492 | set crosslinkBody "C same-second-$crosslinkI\nD 2026-04-05T10:00:00.000\n" |
| 1493 | if {$crosslinkPrev ne ""} { append crosslinkBody "P $crosslinkPrev\n" } |
| 1494 | append crosslinkBody "U alice\n" |
| 1495 | set crosslinkFn [crosslink_file $crosslinkBody] |
| 1496 | fossil sha3sum $crosslinkFn |
| 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 |
| 1513 | # stored and set aside until the baseline comes, and nothing is said. |
| 1514 | |
| 1515 | fossil init xl-from.fossil |
| 1516 | fossil clone xl-from.fossil xl-pull.fossil |
| 1517 | test crosslink-pull-orphan-clone {$CODE == 0} |
| 1518 | set crosslinkFn [crosslink_file "B [string repeat 5c 20] |
| 1519 | C pulled-without-baseline |
| 1520 | D 2026-04-06T10:00:00.000 |
| 1521 | F b.txt |
| 1522 | U alice |
| 1523 | "] |
| 1524 | fossil sha3sum $crosslinkFn |
| 1525 | set crosslinkHash [lindex $RESULT 0] |
| 1526 | fossil test-content-put -R xl-from.fossil --crosslink $crosslinkFn |
| 1527 | fossil pull xl-from.fossil -R xl-pull.fossil |
| 1528 | test crosslink-pull-orphan {$CODE == 0} |
| 1529 | fossil sql -R xl-pull.fossil "SELECT count(*) FROM orphan, blob |
| 1530 | WHERE orphan.rid=blob.rid AND uuid='$crosslinkHash'" |
| 1531 | test_eq crosslink-pull-orphan-set-aside [string trim $RESULT] 1 |
| 1532 | fossil sql -R xl-pull.fossil "SELECT count(*) FROM event, blob |
| 1533 | WHERE objid=rid AND uuid='$crosslinkHash'" |
| 1534 | test_eq crosslink-pull-orphan-no-event [string trim $RESULT] 0 |
| 1535 | |
| 1536 | ############################################################################### |
| 1537 | # Artifacts that name a shunned artifact. No placeholder is made for it. |
| 1538 | # A cluster that lists it still clears its other members. A tag on it is |
| 1539 | # in the timeline and tags nothing. A check-in with it as second parent |
| 1540 | # gets file links to its first parent only. |
| 1541 | |
| 1542 | set crosslinkShun [string repeat 5e 20] |
| 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 | 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 |
| 1570 | F a.txt $crosslinkFb |
| 1571 | P $crosslinkR1 $crosslinkShun |
| 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 | |
| 1584 | crosslink_script xfer-common-script {error common-script-refuses} |
| 1585 | fossil branch new refused $crosslinkR1 -expectError |
| 1586 | test crosslink-script-branch-fails {$CODE != 0} |
| 1587 | crosslink_match crosslink-script-branch-message $RESULT \ |
| 1588 | {*common-script-refuses*} |
| 1589 | crosslink_script xfer-common-script "" |
| 1590 | |
| 1591 | ############################################################################### |
| 1592 | # A repository whose record of an attachment has an empty source in place |
| 1593 | # of none: a tech note or ticket stored for the same target words the |
| 1594 | # attachment as deleted. |
| 1595 | |
| 1596 | set crosslinkEid3 [string repeat e9 20] |
| 1597 | set crosslinkTkt3 [string repeat c9 20] |
| 1598 | set crosslinkAe [crosslink_put "A note.txt $crosslinkEid3 $crosslinkSrc |
| 1599 | D 2026-04-08T10:00:00.000 |
| 1600 | U alice |
| 1601 | "] |
| 1602 | set crosslinkAt [crosslink_put "A tkt.txt $crosslinkTkt3 $crosslinkSrc |
| 1603 | D 2026-04-08T10:01:00.000 |
| 1604 | U alice |
| 1605 | "] |
| 1606 | test crosslink-attach-empty-source-setup \ |
| 1607 | {$crosslinkAe ne "" && $crosslinkAt ne ""} |
| 1608 | fossil sql "UPDATE attachment SET src='' |
| 1609 | WHERE target IN ('$crosslinkEid3','$crosslinkTkt3')" |
| 1610 | crosslink_put "C attached-note |
| 1611 | D 2026-04-08T11:00:00.000 |
| 1612 | E 2026-04-08T09:00:00 $crosslinkEid3 |
| 1613 | U alice |
| 1614 | [crosslink_w {note}]" |
| 1615 | test crosslink-attach-empty-source-technote {$CODE == 0} |
| 1616 | crosslink_match crosslink-attach-empty-source-technote-event \ |
| 1617 | [crosslink_event $crosslinkAe] \ |
| 1618 | {e Delete attachment "note.txt" from tech note \[/technote/*\]} |
| 1619 | crosslink_put "D 2026-04-08T11:01:00.000 |
| 1620 | J title Attached |
| 1621 | K $crosslinkTkt3 |
| 1622 | U alice |
| 1623 | " |
| 1624 | test crosslink-attach-empty-source-ticket {$CODE == 0} |
| 1625 | crosslink_match crosslink-attach-empty-source-ticket-event \ |
| 1626 | [crosslink_event $crosslinkAt] \ |
| 1627 | {t Delete attachment "tkt.txt" from ticket \[*\]} |
| 1628 | |
| 1629 | ############################################################################### |
| 1630 | |
| 1631 | test_cleanup |
+36
| --- a/test/derived.sql | ||
| +++ b/test/derived.sql | ||
| @@ -0,0 +1,36 @@ | ||
| 1 | +-- Print the tables of a Fossil repository that are derived from its | |
| 2 | +-- artifacts, with each record number replaced by the hash or name it | |
| 3 | +-- stands for and the rows in a fixed order. Two repositories that hold | |
| 4 | +-- the same artifacts should print the same text, and so should one | |
| 5 | +-- repository before and after "fossil rebuild". Used by integrity.test | |
| 6 | +-- and sync.test: | |
| 7 | +-- | |
| 8 | +-- fossil sql -R REPOSITORY <test/derived.sql | |
| 9 | +-- | |
| 10 | +SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime, | |
| 11 | + user, euser, comment, ecomment, bgcolor, brief | |
| 12 | + FROM event ORDER BY 2; | |
| 13 | +SELECT 'plink', (SELECT uuid FROM blob WHERE rid=pid), | |
| 14 | + (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime | |
| 15 | + FROM plink ORDER BY 2, 3; | |
| 16 | +SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid), | |
| 17 | + (SELECT uuid FROM blob WHERE rid=fid), | |
| 18 | + (SELECT uuid FROM blob WHERE rid=pid), | |
| 19 | + (SELECT name FROM filename WHERE fnid=mlink.fnid), | |
| 20 | + (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux | |
| 21 | + FROM mlink ORDER BY 2, 5, 3, 4; | |
| 22 | +SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid), | |
| 23 | + tagtype, (SELECT uuid FROM blob WHERE rid=srcid), | |
| 24 | + (SELECT uuid FROM blob WHERE rid=origid), value, mtime, | |
| 25 | + (SELECT uuid FROM blob WHERE rid=tagxref.rid) | |
| 26 | + FROM tagxref ORDER BY 2, 8, 3; | |
| 27 | +SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid) | |
| 28 | + FROM leaf ORDER BY 2; | |
| 29 | +SELECT 'filename', name FROM filename ORDER BY 2; | |
| 30 | +SELECT 'tag', tagname FROM tag | |
| 31 | + WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2; | |
| 32 | +SELECT 'backlink', target, srctype, | |
| 33 | + (SELECT uuid FROM blob WHERE rid=srcid), mtime | |
| 34 | + FROM backlink ORDER BY 2, 4; | |
| 35 | +SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user | |
| 36 | + FROM attachment ORDER BY 3, 4; |
| --- a/test/derived.sql | |
| +++ b/test/derived.sql | |
| @@ -0,0 +1,36 @@ | |
| --- a/test/derived.sql | |
| +++ b/test/derived.sql | |
| @@ -0,0 +1,36 @@ | |
| 1 | -- Print the tables of a Fossil repository that are derived from its |
| 2 | -- artifacts, with each record number replaced by the hash or name it |
| 3 | -- stands for and the rows in a fixed order. Two repositories that hold |
| 4 | -- the same artifacts should print the same text, and so should one |
| 5 | -- repository before and after "fossil rebuild". Used by integrity.test |
| 6 | -- and sync.test: |
| 7 | -- |
| 8 | -- fossil sql -R REPOSITORY <test/derived.sql |
| 9 | -- |
| 10 | SELECT 'event', (SELECT uuid FROM blob WHERE rid=objid), type, mtime, |
| 11 | user, euser, comment, ecomment, bgcolor, brief |
| 12 | FROM event ORDER BY 2; |
| 13 | SELECT 'plink', (SELECT uuid FROM blob WHERE rid=pid), |
| 14 | (SELECT uuid FROM blob WHERE rid=cid), isprim, mtime |
| 15 | FROM plink ORDER BY 2, 3; |
| 16 | SELECT 'mlink', (SELECT uuid FROM blob WHERE rid=mid), |
| 17 | (SELECT uuid FROM blob WHERE rid=fid), |
| 18 | (SELECT uuid FROM blob WHERE rid=pid), |
| 19 | (SELECT name FROM filename WHERE fnid=mlink.fnid), |
| 20 | (SELECT name FROM filename WHERE fnid=mlink.pfnid), mperm, isaux |
| 21 | FROM mlink ORDER BY 2, 5, 3, 4; |
| 22 | SELECT 'tagxref', (SELECT tagname FROM tag WHERE tagid=tagxref.tagid), |
| 23 | tagtype, (SELECT uuid FROM blob WHERE rid=srcid), |
| 24 | (SELECT uuid FROM blob WHERE rid=origid), value, mtime, |
| 25 | (SELECT uuid FROM blob WHERE rid=tagxref.rid) |
| 26 | FROM tagxref ORDER BY 2, 8, 3; |
| 27 | SELECT 'leaf', (SELECT uuid FROM blob WHERE rid=leaf.rid) |
| 28 | FROM leaf ORDER BY 2; |
| 29 | SELECT 'filename', name FROM filename ORDER BY 2; |
| 30 | SELECT 'tag', tagname FROM tag |
| 31 | WHERE tagid IN (SELECT tagid FROM tagxref) ORDER BY 2; |
| 32 | SELECT 'backlink', target, srctype, |
| 33 | (SELECT uuid FROM blob WHERE rid=srcid), mtime |
| 34 | FROM backlink ORDER BY 2, 4; |
| 35 | SELECT 'attachment', isLatest, mtime, src, target, filename, comment, user |
| 36 | FROM attachment ORDER BY 3, 4; |
+81
| --- a/test/fuzz.test | ||
| +++ b/test/fuzz.test | ||
| @@ -0,0 +1,81 @@ | ||
| 1 | +# | |
| 2 | +# Run every input in corpus/corpus.pack, and the sample wiki and markdown pages | |
| 3 | +# in this directory, through "fossil test-fuzz". The pack is unpacked | |
| 4 | +# into a directory for each fuzz type. See corpus.tcl. | |
| 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] | |
| 20 | +set fuzzTypes [corpus_unpack [file join $::testfiledir corpus corpus.pack] \ | |
| 21 | + [file join [pwd] corpus]] | |
| 22 | +test_eq fuzz-corpus-types $fuzzTypes [list delta-accept delta-apply \ | |
| 23 | + delta-reject delta-roundtrip manifest manifest-body scenario xfer] | |
| 24 | + | |
| 25 | +foreach fuzzDir [lsort [glob -nocomplain -types d [file join corpus *]]] { | |
| 26 | + set fuzzType [file tail $fuzzDir] | |
| 27 | + if {$fuzzType eq "scenario"} continue | |
| 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 | + | |
| 39 | +# Every input of the two manifest types must begin with the guard lines, | |
| 40 | +# and neither the pack nor any input may be accepted by Fossil as an | |
| 41 | +# artifact. Otherwise a repository holding the file would act on it. | |
| 42 | +# See corpus.tcl. | |
| 43 | +set fuzzGuard "# test-corpus: inert on disk. " | |
| 44 | +set fuzzNotInert {} | |
| 45 | +foreach fuzzType {manifest manifest-body} { | |
| 46 | + foreach fuzzF [lsort [glob -nocomplain [file join corpus $fuzzType *]]] { | |
| 47 | + set fuzzFd [open $fuzzF rb] | |
| 48 | + set fuzzHead [read $fuzzFd [string length $fuzzGuard]] | |
| 49 | + close $fuzzFd | |
| 50 | + if {$fuzzHead ne $fuzzGuard} { | |
| 51 | + lappend fuzzNotInert $fuzzType/[file tail $fuzzF] | |
| 52 | + } | |
| 53 | + } | |
| 54 | +} | |
| 55 | +test fuzz-corpus-manifest-guarded {[llength $fuzzNotInert] == 0} | |
| 56 | +file mkdir pack | |
| 57 | +file copy [file join $::testfiledir corpus corpus.pack] pack | |
| 58 | +fossil test-fuzz-inert pack | |
| 59 | +test fuzz-corpus-pack-inert {$CODE == 0} | |
| 60 | +foreach fuzzDir [lsort [glob -nocomplain -types d [file join corpus *]]] { | |
| 61 | + fossil test-fuzz-inert $fuzzDir | |
| 62 | + test fuzz-corpus-[file tail $fuzzDir]-inert {$CODE == 0} | |
| 63 | +} | |
| 64 | + | |
| 65 | +# A fuzzing engine begins with an input of no bytes. | |
| 66 | +write_file empty-input "" | |
| 67 | +foreach fuzzType {manifest manifest-body xfer} { | |
| 68 | + fossil test-fuzz --fuzztype $fuzzType empty-input | |
| 69 | + test fuzz-$fuzzType-empty-input {$CODE == 0} | |
| 70 | +} | |
| 71 | + | |
| 72 | +# A directory that is not named for a fuzz type must be refused, so that | |
| 73 | +# its files are not quietly run through the wrong target. | |
| 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 |
| --- a/test/fuzz.test | |
| +++ b/test/fuzz.test | |
| @@ -0,0 +1,81 @@ | |
| --- a/test/fuzz.test | |
| +++ b/test/fuzz.test | |
| @@ -0,0 +1,81 @@ | |
| 1 | # |
| 2 | # Run every input in corpus/corpus.pack, and the sample wiki and markdown pages |
| 3 | # in this directory, through "fossil test-fuzz". The pack is unpacked |
| 4 | # into a directory for each fuzz type. See corpus.tcl. |
| 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] |
| 20 | set fuzzTypes [corpus_unpack [file join $::testfiledir corpus corpus.pack] \ |
| 21 | [file join [pwd] corpus]] |
| 22 | test_eq fuzz-corpus-types $fuzzTypes [list delta-accept delta-apply \ |
| 23 | delta-reject delta-roundtrip manifest manifest-body scenario xfer] |
| 24 | |
| 25 | foreach fuzzDir [lsort [glob -nocomplain -types d [file join corpus *]]] { |
| 26 | set fuzzType [file tail $fuzzDir] |
| 27 | if {$fuzzType eq "scenario"} continue |
| 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 | |
| 39 | # Every input of the two manifest types must begin with the guard lines, |
| 40 | # and neither the pack nor any input may be accepted by Fossil as an |
| 41 | # artifact. Otherwise a repository holding the file would act on it. |
| 42 | # See corpus.tcl. |
| 43 | set fuzzGuard "# test-corpus: inert on disk. " |
| 44 | set fuzzNotInert {} |
| 45 | foreach fuzzType {manifest manifest-body} { |
| 46 | foreach fuzzF [lsort [glob -nocomplain [file join corpus $fuzzType *]]] { |
| 47 | set fuzzFd [open $fuzzF rb] |
| 48 | set fuzzHead [read $fuzzFd [string length $fuzzGuard]] |
| 49 | close $fuzzFd |
| 50 | if {$fuzzHead ne $fuzzGuard} { |
| 51 | lappend fuzzNotInert $fuzzType/[file tail $fuzzF] |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | test fuzz-corpus-manifest-guarded {[llength $fuzzNotInert] == 0} |
| 56 | file mkdir pack |
| 57 | file copy [file join $::testfiledir corpus corpus.pack] pack |
| 58 | fossil test-fuzz-inert pack |
| 59 | test fuzz-corpus-pack-inert {$CODE == 0} |
| 60 | foreach fuzzDir [lsort [glob -nocomplain -types d [file join corpus *]]] { |
| 61 | fossil test-fuzz-inert $fuzzDir |
| 62 | test fuzz-corpus-[file tail $fuzzDir]-inert {$CODE == 0} |
| 63 | } |
| 64 | |
| 65 | # A fuzzing engine begins with an input of no bytes. |
| 66 | write_file empty-input "" |
| 67 | foreach fuzzType {manifest manifest-body xfer} { |
| 68 | fossil test-fuzz --fuzztype $fuzzType empty-input |
| 69 | test fuzz-$fuzzType-empty-input {$CODE == 0} |
| 70 | } |
| 71 | |
| 72 | # A directory that is not named for a fuzz type must be refused, so that |
| 73 | # its files are not quietly run through the wrong target. |
| 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 |
+8
| --- a/test/import.test | ||
| +++ b/test/import.test | ||
| @@ -0,0 +1,8 @@ | ||
| 1 | +########################################no longer on its check-in.se tests run only in a lo -assurance stress.n@1PK,E:runs only withN@1Qi,9M@6y,G@1EW,7Y@Gg,I@2pU,V@O~,G@990,C:$len\n\n$p\nH@Ik,53@QV,U@TB,P@WW,H@990,T@XP,2s@Xw,T@Cyz,5:3\n\nl@9Q8,N@fB,cB@cF,1w@1EW,15@1EW,G@HW,7V@1Hr,1D@2LW,3U@1SH,8:{exec svL@1VF,1h@F5E,3H@1Xz,2x@1aP,1G@1dT,16@1es,NO@1g7,Gx@22a,t@2Js,R@2Kx,1K@1wk,4H@2Ml,12:; a commit | |
| 2 | +# names a ref of 992 bytes with no slash and no newline1f@2R1,1: M@2V0,2v@2T4,a@2YW,g@2X5,J: \ | |
| 3 | + time-13-digitsb@2YV,h@2ZG,I: \ | |
| 4 | + time-no-spacec@2YU,f@2aR,1t@2bA,K@2z0,GX@2dU,X@9PG,l@2uZ,s@2vd,L@WW,U@2w~,c@2bA,1H@2y9,J@2z0,4:dumpM@2dV,3P@2~F,Q@2vg,Q@33U,L@WW,U@2w~,O@CeW,43@35L,Q@2vg,P@3AE,c@DI9,U@2w~,1Z@3CB,Q@2z0,FH@3EG,R:"commit $ref\nmark :$mark\nS@4A0,H:$when +0000\ndataH@Nl,S@3Vt,G@Il,3B@3We,11:fossil sql -R $name.fossil $query | |
| 5 | + return [string trim $::RESULT3A@3_Q,L@3u0,dG@3d1,IE@4GN,1:{O@52V,1K@4Z4,3e@4_U,s@4dT,b@4eX,3e@4fC,t@4jB,O@4kG,K@7tW,7:all-twoT@4nE,6:wo] onL@7tV,3p@4m0,M@4jB,X@4qW,r@4rE,K@7tW,_b@4sT,Le@5S9,S@3u0,10m@5nK,S@7m0,Q@6pg,1Wc@6oz,5:writeP@8Kg,b: | |
| 6 | +fossil add plain.txt | |
| 7 | +fossil commit -ma1@8L4,s@8vR,U@8wV,HX@8x2,io@9Dk,f6@9wd,9:"trunk v2S@B6l,4:threG@G60,1z@Abi,D:"(no comment)S@B6l,O@4oB,54@Aen,1:"N@AlW,6:b-copyH@AZW,6Q@Akg,4V@ArB,1N3@Avl,L@DL0,Ji@CIE,L@DL0,7: 2 two]H@BdW,1s@Cbj,d@52G,E2@CeJ,1:"W@990,I4@Csx,s@DCW,1D@DAw,y@DCW,6:K 1\naG@Dtl,J@DLz,U@D9S,8:negative1q@DF0,m@DHD,l@DI9,Ba@DIz,m@Db9,11@DVO,TT@DWT,s@DCW,D:$importLengthI@2x0,W@E0E,3: | |
| 8 | + G@Ch0,4:propS@8FU,L@6hW,12l@E1w,8:{exec svL@1VF,Gz@F5E,P@FKt,G@Ch0,W7@FM~,Wq@FsE,3VXn27; |
| --- a/test/import.test | |
| +++ b/test/import.test | |
| @@ -0,0 +1,8 @@ | |
| --- a/test/import.test | |
| +++ b/test/import.test | |
| @@ -0,0 +1,8 @@ | |
| 1 | ########################################no longer on its check-in.se tests run only in a lo -assurance stress.n@1PK,E:runs only withN@1Qi,9M@6y,G@1EW,7Y@Gg,I@2pU,V@O~,G@990,C:$len\n\n$p\nH@Ik,53@QV,U@TB,P@WW,H@990,T@XP,2s@Xw,T@Cyz,5:3\n\nl@9Q8,N@fB,cB@cF,1w@1EW,15@1EW,G@HW,7V@1Hr,1D@2LW,3U@1SH,8:{exec svL@1VF,1h@F5E,3H@1Xz,2x@1aP,1G@1dT,16@1es,NO@1g7,Gx@22a,t@2Js,R@2Kx,1K@1wk,4H@2Ml,12:; a commit |
| 2 | # names a ref of 992 bytes with no slash and no newline1f@2R1,1: M@2V0,2v@2T4,a@2YW,g@2X5,J: \ |
| 3 | time-13-digitsb@2YV,h@2ZG,I: \ |
| 4 | time-no-spacec@2YU,f@2aR,1t@2bA,K@2z0,GX@2dU,X@9PG,l@2uZ,s@2vd,L@WW,U@2w~,c@2bA,1H@2y9,J@2z0,4:dumpM@2dV,3P@2~F,Q@2vg,Q@33U,L@WW,U@2w~,O@CeW,43@35L,Q@2vg,P@3AE,c@DI9,U@2w~,1Z@3CB,Q@2z0,FH@3EG,R:"commit $ref\nmark :$mark\nS@4A0,H:$when +0000\ndataH@Nl,S@3Vt,G@Il,3B@3We,11:fossil sql -R $name.fossil $query |
| 5 | return [string trim $::RESULT3A@3_Q,L@3u0,dG@3d1,IE@4GN,1:{O@52V,1K@4Z4,3e@4_U,s@4dT,b@4eX,3e@4fC,t@4jB,O@4kG,K@7tW,7:all-twoT@4nE,6:wo] onL@7tV,3p@4m0,M@4jB,X@4qW,r@4rE,K@7tW,_b@4sT,Le@5S9,S@3u0,10m@5nK,S@7m0,Q@6pg,1Wc@6oz,5:writeP@8Kg,b: |
| 6 | fossil add plain.txt |
| 7 | fossil commit -ma1@8L4,s@8vR,U@8wV,HX@8x2,io@9Dk,f6@9wd,9:"trunk v2S@B6l,4:threG@G60,1z@Abi,D:"(no comment)S@B6l,O@4oB,54@Aen,1:"N@AlW,6:b-copyH@AZW,6Q@Akg,4V@ArB,1N3@Avl,L@DL0,Ji@CIE,L@DL0,7: 2 two]H@BdW,1s@Cbj,d@52G,E2@CeJ,1:"W@990,I4@Csx,s@DCW,1D@DAw,y@DCW,6:K 1\naG@Dtl,J@DLz,U@D9S,8:negative1q@DF0,m@DHD,l@DI9,Ba@DIz,m@Db9,11@DVO,TT@DWT,s@DCW,D:$importLengthI@2x0,W@E0E,3: |
| 8 | G@Ch0,4:propS@8FU,L@6hW,12l@E1w,8:{exec svL@1VF,Gz@F5E,P@FKt,G@Ch0,W7@FM~,Wq@FsE,3VXn27; |
+109
-26
| --- test/integrity.test | ||
| +++ test/integrity.test | ||
| @@ -1,60 +1,74 @@ | ||
| 1 | 1 | # |
| 2 | -# Tests that "fossil rebuild" and a "fossil deconstruct" and "fossil | |
| 3 | -# reconstruct" round trip keep every artifact, and that "fossil | |
| 4 | -# test-integrity" finds an artifact whose content is damaged. | |
| 2 | +# Integrity of a repository. Two kinds of test: | |
| 3 | +# | |
| 4 | +# * A "fossil rebuild", and a "fossil deconstruct" and "fossil | |
| 5 | +# reconstruct" round trip, keep every artifact; "fossil | |
| 6 | +# test-integrity" reports an artifact whose content is damaged. | |
| 7 | +# | |
| 8 | +# * "fossil test-integrity" and "fossil test-missing" pass on a sound | |
| 9 | +# repository and fail, with a non-zero exit status, on each of nine | |
| 10 | +# kinds of damage made with SQL; and "fossil rebuild" leaves the | |
| 11 | +# tables derived from the artifacts as they were, or repairs them. | |
| 5 | 12 | # |
| 6 | 13 | |
| 7 | 14 | require_no_open_checkout |
| 8 | 15 | |
| 9 | 16 | test_setup "" |
| 10 | 17 | set ::env(FOSSIL_USER) tester |
| 11 | 18 | |
| 12 | -# Returns the hashes of the artifacts in repository REPO that are not | |
| 13 | -# phantoms, in order. | |
| 14 | -# | |
| 19 | +# The hashes of the artifacts in REPO that are not phantoms, in order. | |
| 15 | 20 | proc integrity_artifacts {repo} { |
| 16 | 21 | fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0 ORDER BY uuid" |
| 17 | 22 | return [normalize_result] |
| 18 | 23 | } |
| 19 | 24 | |
| 20 | -# Returns the check-ins in repository REPO with their parents and | |
| 21 | -# comments, in order of hash. | |
| 22 | -# | |
| 25 | +# The check-ins in REPO with their parents and comments, in order of hash. | |
| 23 | 26 | proc integrity_checkins {repo} { |
| 24 | 27 | fossil sql -R $repo "SELECT b.uuid, coalesce(p.uuid,''), e.comment\ |
| 25 | 28 | FROM event e JOIN blob b ON b.rid=e.objid\ |
| 26 | 29 | LEFT JOIN plink ON cid=e.objid LEFT JOIN blob p ON p.rid=pid\ |
| 27 | 30 | WHERE e.type='ci' ORDER BY b.uuid" |
| 28 | 31 | return [normalize_result] |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | -# Test NAME passes when "fossil test-integrity --parse" finds no | |
| 32 | -# problems in repository REPO. | |
| 33 | -# | |
| 34 | +# Test NAME passes when "fossil test-integrity --parse" finds no problems. | |
| 34 | 35 | proc integrity_ok {name repo} { |
| 35 | 36 | fossil test-integrity --parse -R $repo |
| 36 | 37 | test_match $name [normalize_result] {checked: 0 errors} |
| 37 | 38 | } |
| 38 | 39 | |
| 40 | +# The derived tables of REPO as text that does not depend on record | |
| 41 | +# numbers. See derived.sql. | |
| 42 | +proc integrity_derived {repo} { | |
| 43 | + fossil sql -R $repo ".read [file join $::testfiledir derived.sql]" | |
| 44 | + return $::RESULT | |
| 45 | +} | |
| 46 | + | |
| 47 | +# An origin repository with three check-ins of one file (so the store | |
| 48 | +# holds deltas), a tag and a wiki page. | |
| 39 | 49 | fossil new r.fossil |
| 40 | 50 | file mkdir ck |
| 41 | 51 | cd ck |
| 42 | 52 | fossil open ../r.fossil |
| 43 | -foreach {file comment} {a.txt one b.txt two a.txt three c.txt four} { | |
| 44 | - write_file $file "$comment\n[string repeat $comment 200]\n" | |
| 45 | - fossil add $file | |
| 46 | - fossil commit -m $comment | |
| 53 | +foreach {integrityFile integrityComment} \ | |
| 54 | + {a.txt one b.txt two a.txt three c.txt four} { | |
| 55 | + write_file $integrityFile "$integrityComment\n[string repeat $integrityComment 200]\n" | |
| 56 | + fossil add $integrityFile | |
| 57 | + fossil commit -m $integrityComment | |
| 47 | 58 | } |
| 48 | 59 | fossil tag add release current |
| 49 | 60 | write_file ../wiki.txt "A page" |
| 50 | 61 | fossil wiki create Page ../wiki.txt |
| 51 | 62 | fossil close |
| 52 | 63 | cd .. |
| 53 | 64 | set artifacts [integrity_artifacts r.fossil] |
| 54 | 65 | set checkins [integrity_checkins r.fossil] |
| 55 | 66 | integrity_ok integrity-new r.fossil |
| 67 | + | |
| 68 | +############################################################################### | |
| 69 | +# Round trips keep every artifact. | |
| 56 | 70 | |
| 57 | 71 | fossil rebuild r.fossil |
| 58 | 72 | test integrity-rebuild {$CODE == 0} |
| 59 | 73 | test_eq integrity-rebuild-artifacts [integrity_artifacts r.fossil] $artifacts |
| 60 | 74 | test_eq integrity-rebuild-checkins [integrity_checkins r.fossil] $checkins |
| @@ -63,28 +77,97 @@ | ||
| 63 | 77 | file mkdir artifacts |
| 64 | 78 | fossil deconstruct -R r.fossil artifacts |
| 65 | 79 | test integrity-deconstruct {$CODE == 0} |
| 66 | 80 | fossil reconstruct r2.fossil artifacts |
| 67 | 81 | test integrity-reconstruct {$CODE == 0} |
| 68 | -test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] \ | |
| 69 | - $artifacts | |
| 70 | -test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] \ | |
| 71 | - $checkins | |
| 82 | +test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] $artifacts | |
| 83 | +test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] $checkins | |
| 72 | 84 | integrity_ok integrity-reconstruct-check r2.fossil |
| 73 | 85 | |
| 74 | -# Replace the stored content of one file artifact with bytes that do not | |
| 75 | -# decompress. | |
| 86 | +# A file artifact whose stored content does not decompress. | |
| 76 | 87 | fossil sql -R r2.fossil "UPDATE blob SET content=x'00000010deadbeef'\ |
| 77 | 88 | WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\ |
| 78 | 89 | WHERE name='b.txt' LIMIT 1)" |
| 79 | 90 | fossil test-integrity -R r2.fossil -expectError |
| 80 | -test_match integrity-damaged-content [normalize_result] \ | |
| 81 | - {wrong hash on artifact \d+} | |
| 91 | +test_match integrity-damaged-content [normalize_result] {wrong hash on artifact \d+} | |
| 82 | 92 | # An undamaged artifact is still readable. |
| 83 | 93 | fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\ |
| 84 | 94 | JOIN filename USING(fnid) WHERE name='c.txt'" |
| 85 | 95 | fossil artifact [normalize_result] -R r2.fossil |
| 86 | -test_eq integrity-artifact-readable [normalize_result] \ | |
| 87 | - "four\n[string repeat four 200]" | |
| 96 | +test_eq integrity-artifact-readable [normalize_result] "four\n[string repeat four 200]" | |
| 97 | +file delete r2.fossil | |
| 98 | + | |
| 99 | +############################################################################### | |
| 100 | +# test-integrity and test-missing: exit 0 on a sound repository, non-zero | |
| 101 | +# on each kind of damage. Each kind is made to a copy. | |
| 102 | + | |
| 103 | +fossil sql -R r.fossil "SELECT count(*) FROM delta" | |
| 104 | +test integrity-has-deltas {$RESULT > 0} | |
| 105 | +fossil test-integrity --parse -R r.fossil | |
| 106 | +test integrity-sound {$CODE == 0} | |
| 107 | +fossil test-missing -R r.fossil | |
| 108 | +test integrity-nothing-missing {$CODE == 0} | |
| 109 | + | |
| 110 | +# A file of a check-in that is neither a delta nor the source of one. | |
| 111 | +set integrityOneFile "(SELECT fid FROM mlink WHERE fid>0\ | |
| 112 | + AND fid NOT IN (SELECT srcid FROM delta)\ | |
| 113 | + AND fid NOT IN (SELECT rid FROM delta) LIMIT 1)" | |
| 114 | + | |
| 115 | +foreach {integrityName integritySql integrityCmd} [list \ | |
| 116 | + wrong-size \ | |
| 117 | + "UPDATE blob SET size=size+1 WHERE rid=$integrityOneFile" \ | |
| 118 | + test-integrity \ | |
| 119 | + content-does-not-match-hash \ | |
| 120 | + "UPDATE blob SET content=x'0102030405060708' WHERE rid=$integrityOneFile" \ | |
| 121 | + test-integrity \ | |
| 122 | + hash-does-not-match-content \ | |
| 123 | + "UPDATE blob SET uuid=substr(uuid,1,length(uuid)-1) ||\ | |
| 124 | + CASE substr(uuid,-1) WHEN '0' THEN '1' ELSE '0' END WHERE rid=$integrityOneFile" \ | |
| 125 | + test-integrity \ | |
| 126 | + delta-is-its-own-source \ | |
| 127 | + "UPDATE delta SET srcid=rid WHERE rid=(SELECT rid FROM delta LIMIT 1)" \ | |
| 128 | + test-integrity \ | |
| 129 | + delta-source-gone \ | |
| 130 | + "DELETE FROM blob WHERE rid=(SELECT srcid FROM delta LIMIT 1)" \ | |
| 131 | + test-integrity \ | |
| 132 | + public-delta-from-private \ | |
| 133 | + "INSERT INTO private SELECT srcid FROM delta LIMIT 1" \ | |
| 134 | + test-integrity \ | |
| 135 | + checkin-is-not-a-manifest \ | |
| 136 | + "UPDATE blob SET content=(SELECT content FROM blob WHERE rid=$integrityOneFile)\ | |
| 137 | + WHERE rid=(SELECT max(objid) FROM event WHERE type='ci')" \ | |
| 138 | + {test-integrity --parse} \ | |
| 139 | + file-gone \ | |
| 140 | + "DELETE FROM blob WHERE rid=$integrityOneFile" \ | |
| 141 | + test-missing \ | |
| 142 | + file-is-a-phantom \ | |
| 143 | + "UPDATE blob SET size=-1, content=NULL WHERE rid=$integrityOneFile" \ | |
| 144 | + test-missing \ | |
| 145 | +] { | |
| 146 | + set integrityDamaged [file join [pwd] damaged.fossil] | |
| 147 | + file copy -force r.fossil $integrityDamaged | |
| 148 | + fossil sql -R $integrityDamaged $integritySql | |
| 149 | + fossil {*}$integrityCmd -R $integrityDamaged -expectError | |
| 150 | + test integrity-damage-$integrityName {$CODE != 0} | |
| 151 | + file delete $integrityDamaged | |
| 152 | +} | |
| 153 | + | |
| 154 | +############################################################################### | |
| 155 | +# Rebuild leaves the derived tables alone, or repairs a wrong one. | |
| 156 | + | |
| 157 | +set integrityBefore [integrity_derived r.fossil] | |
| 158 | +test integrity-derived-not-empty {[string length $integrityBefore] > 0} | |
| 159 | +fossil rebuild r.fossil | |
| 160 | +test_eq integrity-rebuild-same [integrity_derived r.fossil] $integrityBefore | |
| 161 | + | |
| 162 | +set integrityDamaged [file join [pwd] damaged.fossil] | |
| 163 | +file copy -force r.fossil $integrityDamaged | |
| 164 | +fossil sql -R $integrityDamaged \ | |
| 165 | + "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)" | |
| 166 | +test integrity-missing-parent-link-shows \ | |
| 167 | + {[integrity_derived $integrityDamaged] ne $integrityBefore} | |
| 168 | +fossil rebuild $integrityDamaged | |
| 169 | +test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] $integrityBefore | |
| 170 | +file delete $integrityDamaged | |
| 88 | 171 | |
| 89 | 172 | test_cleanup |
| 90 | 173 | unset ::env(FOSSIL_USER) |
| 91 | 174 | |
| 92 | 175 | ADDED test/login.test |
| 93 | 176 | ADDED test/manifest.test |
| 94 | 177 | ADDED test/name.test |
| 95 | 178 | ADDED test/purge.test |
| 96 | 179 | ADDED test/rebuild.test |
| 97 | 180 | ADDED test/regress.test |
| 98 | 181 | ADDED test/scenario.test |
| 99 | 182 | ADDED test/ssh.test |
| 100 | 183 | ADDED test/standin/scenario-wire.tcl |
| --- test/integrity.test | |
| +++ test/integrity.test | |
| @@ -1,60 +1,74 @@ | |
| 1 | # |
| 2 | # Tests that "fossil rebuild" and a "fossil deconstruct" and "fossil |
| 3 | # reconstruct" round trip keep every artifact, and that "fossil |
| 4 | # test-integrity" finds an artifact whose content is damaged. |
| 5 | # |
| 6 | |
| 7 | require_no_open_checkout |
| 8 | |
| 9 | test_setup "" |
| 10 | set ::env(FOSSIL_USER) tester |
| 11 | |
| 12 | # Returns the hashes of the artifacts in repository REPO that are not |
| 13 | # phantoms, in order. |
| 14 | # |
| 15 | proc integrity_artifacts {repo} { |
| 16 | fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0 ORDER BY uuid" |
| 17 | return [normalize_result] |
| 18 | } |
| 19 | |
| 20 | # Returns the check-ins in repository REPO with their parents and |
| 21 | # comments, in order of hash. |
| 22 | # |
| 23 | proc integrity_checkins {repo} { |
| 24 | fossil sql -R $repo "SELECT b.uuid, coalesce(p.uuid,''), e.comment\ |
| 25 | FROM event e JOIN blob b ON b.rid=e.objid\ |
| 26 | LEFT JOIN plink ON cid=e.objid LEFT JOIN blob p ON p.rid=pid\ |
| 27 | WHERE e.type='ci' ORDER BY b.uuid" |
| 28 | return [normalize_result] |
| 29 | } |
| 30 | |
| 31 | # Test NAME passes when "fossil test-integrity --parse" finds no |
| 32 | # problems in repository REPO. |
| 33 | # |
| 34 | proc integrity_ok {name repo} { |
| 35 | fossil test-integrity --parse -R $repo |
| 36 | test_match $name [normalize_result] {checked: 0 errors} |
| 37 | } |
| 38 | |
| 39 | fossil new r.fossil |
| 40 | file mkdir ck |
| 41 | cd ck |
| 42 | fossil open ../r.fossil |
| 43 | foreach {file comment} {a.txt one b.txt two a.txt three c.txt four} { |
| 44 | write_file $file "$comment\n[string repeat $comment 200]\n" |
| 45 | fossil add $file |
| 46 | fossil commit -m $comment |
| 47 | } |
| 48 | fossil tag add release current |
| 49 | write_file ../wiki.txt "A page" |
| 50 | fossil wiki create Page ../wiki.txt |
| 51 | fossil close |
| 52 | cd .. |
| 53 | set artifacts [integrity_artifacts r.fossil] |
| 54 | set checkins [integrity_checkins r.fossil] |
| 55 | integrity_ok integrity-new r.fossil |
| 56 | |
| 57 | fossil rebuild r.fossil |
| 58 | test integrity-rebuild {$CODE == 0} |
| 59 | test_eq integrity-rebuild-artifacts [integrity_artifacts r.fossil] $artifacts |
| 60 | test_eq integrity-rebuild-checkins [integrity_checkins r.fossil] $checkins |
| @@ -63,28 +77,97 @@ | |
| 63 | file mkdir artifacts |
| 64 | fossil deconstruct -R r.fossil artifacts |
| 65 | test integrity-deconstruct {$CODE == 0} |
| 66 | fossil reconstruct r2.fossil artifacts |
| 67 | test integrity-reconstruct {$CODE == 0} |
| 68 | test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] \ |
| 69 | $artifacts |
| 70 | test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] \ |
| 71 | $checkins |
| 72 | integrity_ok integrity-reconstruct-check r2.fossil |
| 73 | |
| 74 | # Replace the stored content of one file artifact with bytes that do not |
| 75 | # decompress. |
| 76 | fossil sql -R r2.fossil "UPDATE blob SET content=x'00000010deadbeef'\ |
| 77 | WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\ |
| 78 | WHERE name='b.txt' LIMIT 1)" |
| 79 | fossil test-integrity -R r2.fossil -expectError |
| 80 | test_match integrity-damaged-content [normalize_result] \ |
| 81 | {wrong hash on artifact \d+} |
| 82 | # An undamaged artifact is still readable. |
| 83 | fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\ |
| 84 | JOIN filename USING(fnid) WHERE name='c.txt'" |
| 85 | fossil artifact [normalize_result] -R r2.fossil |
| 86 | test_eq integrity-artifact-readable [normalize_result] \ |
| 87 | "four\n[string repeat four 200]" |
| 88 | |
| 89 | test_cleanup |
| 90 | unset ::env(FOSSIL_USER) |
| 91 | |
| 92 | DDED test/login.test |
| 93 | DDED test/manifest.test |
| 94 | DDED test/name.test |
| 95 | DDED test/purge.test |
| 96 | DDED test/rebuild.test |
| 97 | DDED test/regress.test |
| 98 | DDED test/scenario.test |
| 99 | DDED test/ssh.test |
| 100 | DDED test/standin/scenario-wire.tcl |
| --- test/integrity.test | |
| +++ test/integrity.test | |
| @@ -1,60 +1,74 @@ | |
| 1 | # |
| 2 | # Integrity of a repository. Two kinds of test: |
| 3 | # |
| 4 | # * A "fossil rebuild", and a "fossil deconstruct" and "fossil |
| 5 | # reconstruct" round trip, keep every artifact; "fossil |
| 6 | # test-integrity" reports an artifact whose content is damaged. |
| 7 | # |
| 8 | # * "fossil test-integrity" and "fossil test-missing" pass on a sound |
| 9 | # repository and fail, with a non-zero exit status, on each of nine |
| 10 | # kinds of damage made with SQL; and "fossil rebuild" leaves the |
| 11 | # tables derived from the artifacts as they were, or repairs them. |
| 12 | # |
| 13 | |
| 14 | require_no_open_checkout |
| 15 | |
| 16 | test_setup "" |
| 17 | set ::env(FOSSIL_USER) tester |
| 18 | |
| 19 | # The hashes of the artifacts in REPO that are not phantoms, in order. |
| 20 | proc integrity_artifacts {repo} { |
| 21 | fossil sql -R $repo "SELECT uuid FROM blob WHERE size>=0 ORDER BY uuid" |
| 22 | return [normalize_result] |
| 23 | } |
| 24 | |
| 25 | # The check-ins in REPO with their parents and comments, in order of hash. |
| 26 | proc integrity_checkins {repo} { |
| 27 | fossil sql -R $repo "SELECT b.uuid, coalesce(p.uuid,''), e.comment\ |
| 28 | FROM event e JOIN blob b ON b.rid=e.objid\ |
| 29 | LEFT JOIN plink ON cid=e.objid LEFT JOIN blob p ON p.rid=pid\ |
| 30 | WHERE e.type='ci' ORDER BY b.uuid" |
| 31 | return [normalize_result] |
| 32 | } |
| 33 | |
| 34 | # Test NAME passes when "fossil test-integrity --parse" finds no problems. |
| 35 | proc integrity_ok {name repo} { |
| 36 | fossil test-integrity --parse -R $repo |
| 37 | test_match $name [normalize_result] {checked: 0 errors} |
| 38 | } |
| 39 | |
| 40 | # The derived tables of REPO as text that does not depend on record |
| 41 | # numbers. See derived.sql. |
| 42 | proc integrity_derived {repo} { |
| 43 | fossil sql -R $repo ".read [file join $::testfiledir derived.sql]" |
| 44 | return $::RESULT |
| 45 | } |
| 46 | |
| 47 | # An origin repository with three check-ins of one file (so the store |
| 48 | # holds deltas), a tag and a wiki page. |
| 49 | fossil new r.fossil |
| 50 | file mkdir ck |
| 51 | cd ck |
| 52 | fossil open ../r.fossil |
| 53 | foreach {integrityFile integrityComment} \ |
| 54 | {a.txt one b.txt two a.txt three c.txt four} { |
| 55 | write_file $integrityFile "$integrityComment\n[string repeat $integrityComment 200]\n" |
| 56 | fossil add $integrityFile |
| 57 | fossil commit -m $integrityComment |
| 58 | } |
| 59 | fossil tag add release current |
| 60 | write_file ../wiki.txt "A page" |
| 61 | fossil wiki create Page ../wiki.txt |
| 62 | fossil close |
| 63 | cd .. |
| 64 | set artifacts [integrity_artifacts r.fossil] |
| 65 | set checkins [integrity_checkins r.fossil] |
| 66 | integrity_ok integrity-new r.fossil |
| 67 | |
| 68 | ############################################################################### |
| 69 | # Round trips keep every artifact. |
| 70 | |
| 71 | fossil rebuild r.fossil |
| 72 | test integrity-rebuild {$CODE == 0} |
| 73 | test_eq integrity-rebuild-artifacts [integrity_artifacts r.fossil] $artifacts |
| 74 | test_eq integrity-rebuild-checkins [integrity_checkins r.fossil] $checkins |
| @@ -63,28 +77,97 @@ | |
| 77 | file mkdir artifacts |
| 78 | fossil deconstruct -R r.fossil artifacts |
| 79 | test integrity-deconstruct {$CODE == 0} |
| 80 | fossil reconstruct r2.fossil artifacts |
| 81 | test integrity-reconstruct {$CODE == 0} |
| 82 | test_eq integrity-reconstruct-artifacts [integrity_artifacts r2.fossil] $artifacts |
| 83 | test_eq integrity-reconstruct-checkins [integrity_checkins r2.fossil] $checkins |
| 84 | integrity_ok integrity-reconstruct-check r2.fossil |
| 85 | |
| 86 | # A file artifact whose stored content does not decompress. |
| 87 | fossil sql -R r2.fossil "UPDATE blob SET content=x'00000010deadbeef'\ |
| 88 | WHERE rid=(SELECT fid FROM mlink JOIN filename USING(fnid)\ |
| 89 | WHERE name='b.txt' LIMIT 1)" |
| 90 | fossil test-integrity -R r2.fossil -expectError |
| 91 | test_match integrity-damaged-content [normalize_result] {wrong hash on artifact \d+} |
| 92 | # An undamaged artifact is still readable. |
| 93 | fossil sql -R r2.fossil "SELECT uuid FROM blob JOIN mlink ON fid=rid\ |
| 94 | JOIN filename USING(fnid) WHERE name='c.txt'" |
| 95 | fossil artifact [normalize_result] -R r2.fossil |
| 96 | test_eq integrity-artifact-readable [normalize_result] "four\n[string repeat four 200]" |
| 97 | file delete r2.fossil |
| 98 | |
| 99 | ############################################################################### |
| 100 | # test-integrity and test-missing: exit 0 on a sound repository, non-zero |
| 101 | # on each kind of damage. Each kind is made to a copy. |
| 102 | |
| 103 | fossil sql -R r.fossil "SELECT count(*) FROM delta" |
| 104 | test integrity-has-deltas {$RESULT > 0} |
| 105 | fossil test-integrity --parse -R r.fossil |
| 106 | test integrity-sound {$CODE == 0} |
| 107 | fossil test-missing -R r.fossil |
| 108 | test integrity-nothing-missing {$CODE == 0} |
| 109 | |
| 110 | # A file of a check-in that is neither a delta nor the source of one. |
| 111 | set integrityOneFile "(SELECT fid FROM mlink WHERE fid>0\ |
| 112 | AND fid NOT IN (SELECT srcid FROM delta)\ |
| 113 | AND fid NOT IN (SELECT rid FROM delta) LIMIT 1)" |
| 114 | |
| 115 | foreach {integrityName integritySql integrityCmd} [list \ |
| 116 | wrong-size \ |
| 117 | "UPDATE blob SET size=size+1 WHERE rid=$integrityOneFile" \ |
| 118 | test-integrity \ |
| 119 | content-does-not-match-hash \ |
| 120 | "UPDATE blob SET content=x'0102030405060708' WHERE rid=$integrityOneFile" \ |
| 121 | test-integrity \ |
| 122 | hash-does-not-match-content \ |
| 123 | "UPDATE blob SET uuid=substr(uuid,1,length(uuid)-1) ||\ |
| 124 | CASE substr(uuid,-1) WHEN '0' THEN '1' ELSE '0' END WHERE rid=$integrityOneFile" \ |
| 125 | test-integrity \ |
| 126 | delta-is-its-own-source \ |
| 127 | "UPDATE delta SET srcid=rid WHERE rid=(SELECT rid FROM delta LIMIT 1)" \ |
| 128 | test-integrity \ |
| 129 | delta-source-gone \ |
| 130 | "DELETE FROM blob WHERE rid=(SELECT srcid FROM delta LIMIT 1)" \ |
| 131 | test-integrity \ |
| 132 | public-delta-from-private \ |
| 133 | "INSERT INTO private SELECT srcid FROM delta LIMIT 1" \ |
| 134 | test-integrity \ |
| 135 | checkin-is-not-a-manifest \ |
| 136 | "UPDATE blob SET content=(SELECT content FROM blob WHERE rid=$integrityOneFile)\ |
| 137 | WHERE rid=(SELECT max(objid) FROM event WHERE type='ci')" \ |
| 138 | {test-integrity --parse} \ |
| 139 | file-gone \ |
| 140 | "DELETE FROM blob WHERE rid=$integrityOneFile" \ |
| 141 | test-missing \ |
| 142 | file-is-a-phantom \ |
| 143 | "UPDATE blob SET size=-1, content=NULL WHERE rid=$integrityOneFile" \ |
| 144 | test-missing \ |
| 145 | ] { |
| 146 | set integrityDamaged [file join [pwd] damaged.fossil] |
| 147 | file copy -force r.fossil $integrityDamaged |
| 148 | fossil sql -R $integrityDamaged $integritySql |
| 149 | fossil {*}$integrityCmd -R $integrityDamaged -expectError |
| 150 | test integrity-damage-$integrityName {$CODE != 0} |
| 151 | file delete $integrityDamaged |
| 152 | } |
| 153 | |
| 154 | ############################################################################### |
| 155 | # Rebuild leaves the derived tables alone, or repairs a wrong one. |
| 156 | |
| 157 | set integrityBefore [integrity_derived r.fossil] |
| 158 | test integrity-derived-not-empty {[string length $integrityBefore] > 0} |
| 159 | fossil rebuild r.fossil |
| 160 | test_eq integrity-rebuild-same [integrity_derived r.fossil] $integrityBefore |
| 161 | |
| 162 | set integrityDamaged [file join [pwd] damaged.fossil] |
| 163 | file copy -force r.fossil $integrityDamaged |
| 164 | fossil sql -R $integrityDamaged \ |
| 165 | "DELETE FROM plink WHERE rowid=(SELECT max(rowid) FROM plink)" |
| 166 | test integrity-missing-parent-link-shows \ |
| 167 | {[integrity_derived $integrityDamaged] ne $integrityBefore} |
| 168 | fossil rebuild $integrityDamaged |
| 169 | test_eq integrity-rebuild-repairs [integrity_derived $integrityDamaged] $integrityBefore |
| 170 | file delete $integrityDamaged |
| 171 | |
| 172 | test_cleanup |
| 173 | unset ::env(FOSSIL_USER) |
| 174 | |
| 175 | DDED test/login.test |
| 176 | DDED test/manifest.test |
| 177 | DDED test/name.test |
| 178 | DDED test/purge.test |
| 179 | DDED test/rebuild.test |
| 180 | DDED test/regress.test |
| 181 | DDED test/scenario.test |
| 182 | DDED test/ssh.test |
| 183 | DDED test/standin/scenario-wire.tcl |
+47
| --- a/test/login.test | ||
| +++ b/test/login.test | ||
| @@ -0,0 +1,47 @@ | ||
| 1 | +########################## | |
| 2 | +# | |
| 3 | +# Authentication: how the server in src/login.c reads a request and decides | |
| 4 | +# who the user is. Requests are written to a file and handed to "fossil http | |
| 5 | +# REPO --in", which serves one request and writes the reply to a file, the way | |
| 6 | +# test/cgi.test does. The /test-env page reports g.zLogin, g.isRobot and the | |
| 7 | +# capabilities the server granted. Several command-line test eThese tests run only in a long -assurance stress. | |
| 8 | +ifO@Au,l:tress"} { | |
| 9 | + test_skip "runs only with -assuranceAt@Cn,G:global loginRepoN@EE~,5:$texth@6uE,11@7CF,A: {*}$args1H@6w8,1k@Ze,1_@EDU,J@gk,B:"$text\r\n"e@fN,P@bx,I: the base URL so | |
| 10 | +#t@cc,2: {S@5mu,D:set text "POSV@EDf,N@ENu,J:\r\n" | |
| 11 | + append textU@Dd5,b:www-form-urlencoded\r\n" | |
| 12 | + append textg@De7,u@EE9,M:append text "\r\n$bodyN@DbU,10:$text] | |
| 13 | +} | |
| 14 | + | |
| 15 | +# The status line of a reply. | |
| 16 | +proc login_status {replyR@9QS,3p:lindex [split $reply \n] 0]] | |
| 17 | +} | |
| 18 | + | |
| 19 | +# The value of the first header NAME in a reply, or "-" if there is none. | |
| 20 | +proc login_header {reply name} { | |
| 21 | + set end [string first "\r\n\r\n" $reply] | |
| 22 | + foreach line [split [string range $reply 0 $end] \n] { | |
| 23 | + iH@EzW,X:-nocase "$name: *" $line]} { | |
| 24 | + N@9QW,15:string range $line [string length $name]+1 end]] | |
| 25 | + } | |
| 26 | + } | |
| 27 | + return -F3@he,n@CtE,1p@xb,2b@zW,6:[loginN@1iW,Ws@11e,6:[loginN@1iW,M:set loginCookie [loginV@7Ql,18@1Zt,31@1a6,_@1vl,6:nope] | |
| 28 | +M@1hT,G@9JG,L:HTTP/1.0 401*" [loginN@1iW,L@1hT,H:-nocookie {[loginV@7Ql,1u: eq "-"} | |
| 29 | + | |
| 30 | +# "remember me" controls whether the cookie is persistent (has max-age) or | |
| 31 | +# lasts only for the browser sessionO@5Y0,K@1ph,L:remember=1] | |
| 32 | +test logig@7Xz,H:max-age=*" [logint@7Ql,W@1XL,o@7Pt,5:loginY@7Ql,1N@7~G,3f@1n5,5:loginK@7Ql,9:Location]5c@1rN,5:loginV@7Ql,54@1xY,5:loginY@7Ql,1J@FP0,8z@23W,Q@EJW,MQ@2Cz,H@9JG,6G@2Zk,T@HL,z@CFB,29@2fr,3:$::S@Cxj,I@H7G,1j@2iv,IE@2kj,F:login_header $rH@7zG,5X@32S,T@EmG,r@38W,6:[loginN@1iW,2_@39u,B:login_statuu@z~,2g@3DX,Y@1~0,2:\ | |
| 33 | +t@3H7,T@EmG,K@3F0,5:badolJ@2jl,c@3JQ,1J@FP0,IM@3LM,b@43T,3j@3dO,1l@3hC,6:[loginN@1iW,K@GU0,5:creatI@B0U,H@H8W,n@3kT,E:eq "realuser"}Tz@3lV,b@HjW,U7@4F9,9F@4iQ,1: 1T@4rf,15@4rg,2a@4uE,5:loginK@9h0,9S@4xC,5:loginBh@55i,V@5HS,F:\ | |
| 34 | + {[loginK@7Ql,o@5SY,w@5JC,U@5KA,F:\ | |
| 35 | + {[loginK@7Ql,o@5SY,1d@5Lu,W@5N_,F:\ | |
| 36 | + {[loginK@7Ql,u@5SY,G@HSl,_@5Ti,19@5QF,5:loginW@7Ql,H: | |
| 37 | + && [loginK@7Ql,1k@5SY,W@5UK,F:\ | |
| 38 | + {[loginK@7Ql,Q:Location] eq $loginGoWant}5G@5Vh,f@8Gi,1p@5al,5:loginK@7Ql,3X@5cy,1X@Gfv,E1@5i5,1O:# The SHA1 hash of TEXT, in lower-case hex. | |
| 39 | +proc login_sha1 {text} { | |
| 40 | + set fd [open sha1X@3Y0,5:$textU@3Yx,J:sha1in.txt | |
| 41 | + returnL@3Z~,2: | |
| 42 | +}3L@5w5,b@HjW,W2@5~A,5:loginK@9h0,Q@4xC,eO@6V~,b@79o,g@ww,I@6D~,9:\r\n\r\n"Ei@7Bz,5:login8I@7Ql,6:[loginY@7Ql,4k@7Zp,A:login_sha12o@7dh,l@7ge,A:login_sha12q@7hY,y@7kX,A:login_sha12t@7lc,5:loginx@7Ql,M@7mg,P@7qB,G@7Xl,M@5fh,L:HTTP/1.0 401*" [login_@9h0,c@8U0,g@5yD,2j@7tY,Y@89W,A:$loginAnonJ@7Xi,5:loginK@F00,M:"HTTP/1.0 401*" [login_@9h0,c@8U0,Y@HRi,1:"1L@6YW,BL@80Z,N@8Jy,T@Bwx,3m@8Cr,85@8Gi,5:loginL@D2k,44@8PC,6:[login_@9h0,4X@8U0,Q@6tF,Y@F5y,S@8YW,S:[read_file lreq.txt] --nosslI@9wG,3f@8Zz,H@9JG,Jz@8c~,N@91i,41@8xU,P@3~0,2r@90z,M@F20,B:g=timeline"V@96W,PF@94z,D2@9UJ,G@9JG,L:HTTP/1.0 302*" [login4s@9h0,1H@9ly,G@9JG,L:HTTP/1.0 302*" [loginU@9h0,U@2SW,Lr@9oq,W@9jg,5:unamet@9k9,Qa@ABE,J@85l,1Y@AbG,_@F20,81@AdW,i@Ai~,LV@AmK,L@8J0,82@B7E,6V@BGV,77@BN4,6:BobUidd@CJ0,R@BJS,C:loginbob'"]]1G@BU1,46@BWY,3:Bobp@B_d,3:BobW@BaS,6:] { | |
| 43 | + J@BlG,H@Bfk,H@9JG,E:URL is invalidV@BjE,G:$loginRbSuffix]]Kq@Bgx,5:loginN@1iW,V8@C1D,L@HDl,h@CWl,G@9JG,L:HTTP/1.0 302*" [loginT@9h0,H@EOl,CZ@CYq,U@4W0,10@CkS,M@4ZG,Hp@ClW,X@Gal,1:he@Hd0,D:needed [login2g@D2k,5:loginAL@D5V,L: login-robot-restrictU@CPW,3:-"}41@DGd,5:loginl@D5V,65@DLU,9O@DRe,c:login_sha1 $tail] | |
| 44 | + set sig [login_sha11F@Dab,Z@DcL,o@Dd7,p@De9,1: | |
| 45 | +Y@GtW,4:NULLJ@9u0,1n@Dfx,2: 0Z@GtW,L@6AV,Gz@Dih,H@9JG,46@D~3,1:"J@DzG,Yq@E3a,5:login32@EbV,S@FNF,8r@Ef3,5:loginQ@9h0,5: &&J@FSz,4e@Eol,5:loginK@9h0,b@4xC,c@8U0,QV@Eu~,J@85l,S@7N9,S@7mF,1Q@FLk,5f@FNF,Ma@FS~,10@6tF,13@7B~,3p@Fpc,b@79o,H9@Fu7,I@HtW,E2@GAd,6k@GOl,N@91i,Ct@GW0,C:suffix whoseW@BFU,2: | |
| 46 | +#S@BFz,2R@Ghs,T@BVQ,U:foreach {loginRb2Name loginRb2I@BWz,B:uid-end "1I@Bbj,A: time-endT@Bbe,J@BlG,F:bad-$loginRb2NaJ@56l,F:*URL is invalidV@BjE,I:$loginRb2Suffix]]}13@BLc,Hw@Gl9,G2@H2A,V@AOC,2e@HIm,m@1d9,2:. | |
| 47 | +Y@1k7,G@9JG,~:HTTP/1.0 401*" [login_status [login_form [email protected] wrongpw]]]}62@HLM,a@HRi,Y@89W,A:$loginAnonJ@7Xi,H:negative-lifespanN@B3G,L:HTTP/1.0 401*" [loginQ@9h0,A: && [loginV@7Ql,7: eq "-"G@8ul,P@7zu,3R@HWD,L@1cV,K@DPz,Mu@H_T,17R3TF; |
| --- a/test/login.test | |
| +++ b/test/login.test | |
| @@ -0,0 +1,47 @@ | |
| --- a/test/login.test | |
| +++ b/test/login.test | |
| @@ -0,0 +1,47 @@ | |
| 1 | ########################## |
| 2 | # |
| 3 | # Authentication: how the server in src/login.c reads a request and decides |
| 4 | # who the user is. Requests are written to a file and handed to "fossil http |
| 5 | # REPO --in", which serves one request and writes the reply to a file, the way |
| 6 | # test/cgi.test does. The /test-env page reports g.zLogin, g.isRobot and the |
| 7 | # capabilities the server granted. Several command-line test eThese tests run only in a long -assurance stress. |
| 8 | ifO@Au,l:tress"} { |
| 9 | test_skip "runs only with -assuranceAt@Cn,G:global loginRepoN@EE~,5:$texth@6uE,11@7CF,A: {*}$args1H@6w8,1k@Ze,1_@EDU,J@gk,B:"$text\r\n"e@fN,P@bx,I: the base URL so |
| 10 | #t@cc,2: {S@5mu,D:set text "POSV@EDf,N@ENu,J:\r\n" |
| 11 | append textU@Dd5,b:www-form-urlencoded\r\n" |
| 12 | append textg@De7,u@EE9,M:append text "\r\n$bodyN@DbU,10:$text] |
| 13 | } |
| 14 | |
| 15 | # The status line of a reply. |
| 16 | proc login_status {replyR@9QS,3p:lindex [split $reply \n] 0]] |
| 17 | } |
| 18 | |
| 19 | # The value of the first header NAME in a reply, or "-" if there is none. |
| 20 | proc login_header {reply name} { |
| 21 | set end [string first "\r\n\r\n" $reply] |
| 22 | foreach line [split [string range $reply 0 $end] \n] { |
| 23 | iH@EzW,X:-nocase "$name: *" $line]} { |
| 24 | N@9QW,15:string range $line [string length $name]+1 end]] |
| 25 | } |
| 26 | } |
| 27 | return -F3@he,n@CtE,1p@xb,2b@zW,6:[loginN@1iW,Ws@11e,6:[loginN@1iW,M:set loginCookie [loginV@7Ql,18@1Zt,31@1a6,_@1vl,6:nope] |
| 28 | M@1hT,G@9JG,L:HTTP/1.0 401*" [loginN@1iW,L@1hT,H:-nocookie {[loginV@7Ql,1u: eq "-"} |
| 29 | |
| 30 | # "remember me" controls whether the cookie is persistent (has max-age) or |
| 31 | # lasts only for the browser sessionO@5Y0,K@1ph,L:remember=1] |
| 32 | test logig@7Xz,H:max-age=*" [logint@7Ql,W@1XL,o@7Pt,5:loginY@7Ql,1N@7~G,3f@1n5,5:loginK@7Ql,9:Location]5c@1rN,5:loginV@7Ql,54@1xY,5:loginY@7Ql,1J@FP0,8z@23W,Q@EJW,MQ@2Cz,H@9JG,6G@2Zk,T@HL,z@CFB,29@2fr,3:$::S@Cxj,I@H7G,1j@2iv,IE@2kj,F:login_header $rH@7zG,5X@32S,T@EmG,r@38W,6:[loginN@1iW,2_@39u,B:login_statuu@z~,2g@3DX,Y@1~0,2:\ |
| 33 | t@3H7,T@EmG,K@3F0,5:badolJ@2jl,c@3JQ,1J@FP0,IM@3LM,b@43T,3j@3dO,1l@3hC,6:[loginN@1iW,K@GU0,5:creatI@B0U,H@H8W,n@3kT,E:eq "realuser"}Tz@3lV,b@HjW,U7@4F9,9F@4iQ,1: 1T@4rf,15@4rg,2a@4uE,5:loginK@9h0,9S@4xC,5:loginBh@55i,V@5HS,F:\ |
| 34 | {[loginK@7Ql,o@5SY,w@5JC,U@5KA,F:\ |
| 35 | {[loginK@7Ql,o@5SY,1d@5Lu,W@5N_,F:\ |
| 36 | {[loginK@7Ql,u@5SY,G@HSl,_@5Ti,19@5QF,5:loginW@7Ql,H: |
| 37 | && [loginK@7Ql,1k@5SY,W@5UK,F:\ |
| 38 | {[loginK@7Ql,Q:Location] eq $loginGoWant}5G@5Vh,f@8Gi,1p@5al,5:loginK@7Ql,3X@5cy,1X@Gfv,E1@5i5,1O:# The SHA1 hash of TEXT, in lower-case hex. |
| 39 | proc login_sha1 {text} { |
| 40 | set fd [open sha1X@3Y0,5:$textU@3Yx,J:sha1in.txt |
| 41 | returnL@3Z~,2: |
| 42 | }3L@5w5,b@HjW,W2@5~A,5:loginK@9h0,Q@4xC,eO@6V~,b@79o,g@ww,I@6D~,9:\r\n\r\n"Ei@7Bz,5:login8I@7Ql,6:[loginY@7Ql,4k@7Zp,A:login_sha12o@7dh,l@7ge,A:login_sha12q@7hY,y@7kX,A:login_sha12t@7lc,5:loginx@7Ql,M@7mg,P@7qB,G@7Xl,M@5fh,L:HTTP/1.0 401*" [login_@9h0,c@8U0,g@5yD,2j@7tY,Y@89W,A:$loginAnonJ@7Xi,5:loginK@F00,M:"HTTP/1.0 401*" [login_@9h0,c@8U0,Y@HRi,1:"1L@6YW,BL@80Z,N@8Jy,T@Bwx,3m@8Cr,85@8Gi,5:loginL@D2k,44@8PC,6:[login_@9h0,4X@8U0,Q@6tF,Y@F5y,S@8YW,S:[read_file lreq.txt] --nosslI@9wG,3f@8Zz,H@9JG,Jz@8c~,N@91i,41@8xU,P@3~0,2r@90z,M@F20,B:g=timeline"V@96W,PF@94z,D2@9UJ,G@9JG,L:HTTP/1.0 302*" [login4s@9h0,1H@9ly,G@9JG,L:HTTP/1.0 302*" [loginU@9h0,U@2SW,Lr@9oq,W@9jg,5:unamet@9k9,Qa@ABE,J@85l,1Y@AbG,_@F20,81@AdW,i@Ai~,LV@AmK,L@8J0,82@B7E,6V@BGV,77@BN4,6:BobUidd@CJ0,R@BJS,C:loginbob'"]]1G@BU1,46@BWY,3:Bobp@B_d,3:BobW@BaS,6:] { |
| 43 | J@BlG,H@Bfk,H@9JG,E:URL is invalidV@BjE,G:$loginRbSuffix]]Kq@Bgx,5:loginN@1iW,V8@C1D,L@HDl,h@CWl,G@9JG,L:HTTP/1.0 302*" [loginT@9h0,H@EOl,CZ@CYq,U@4W0,10@CkS,M@4ZG,Hp@ClW,X@Gal,1:he@Hd0,D:needed [login2g@D2k,5:loginAL@D5V,L: login-robot-restrictU@CPW,3:-"}41@DGd,5:loginl@D5V,65@DLU,9O@DRe,c:login_sha1 $tail] |
| 44 | set sig [login_sha11F@Dab,Z@DcL,o@Dd7,p@De9,1: |
| 45 | Y@GtW,4:NULLJ@9u0,1n@Dfx,2: 0Z@GtW,L@6AV,Gz@Dih,H@9JG,46@D~3,1:"J@DzG,Yq@E3a,5:login32@EbV,S@FNF,8r@Ef3,5:loginQ@9h0,5: &&J@FSz,4e@Eol,5:loginK@9h0,b@4xC,c@8U0,QV@Eu~,J@85l,S@7N9,S@7mF,1Q@FLk,5f@FNF,Ma@FS~,10@6tF,13@7B~,3p@Fpc,b@79o,H9@Fu7,I@HtW,E2@GAd,6k@GOl,N@91i,Ct@GW0,C:suffix whoseW@BFU,2: |
| 46 | #S@BFz,2R@Ghs,T@BVQ,U:foreach {loginRb2Name loginRb2I@BWz,B:uid-end "1I@Bbj,A: time-endT@Bbe,J@BlG,F:bad-$loginRb2NaJ@56l,F:*URL is invalidV@BjE,I:$loginRb2Suffix]]}13@BLc,Hw@Gl9,G2@H2A,V@AOC,2e@HIm,m@1d9,2:. |
| 47 | Y@1k7,G@9JG,~:HTTP/1.0 401*" [login_status [login_form [email protected] wrongpw]]]}62@HLM,a@HRi,Y@89W,A:$loginAnonJ@7Xi,H:negative-lifespanN@B3G,L:HTTP/1.0 401*" [loginQ@9h0,A: && [loginV@7Ql,7: eq "-"G@8ul,P@7zu,3R@HWD,L@1cV,K@DPz,Mu@H_T,17R3TF; |
+270
| --- a/test/manifest.test | ||
| +++ b/test/manifest.test | ||
| @@ -0,0 +1,270 @@ | ||
| 1 | +# | |
| 2 | +# Reading check-ins and their files in src/manifest.c: two check-ins | |
| 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" | |
| 44 | +fossil add a.txt b.txt keep.txt | |
| 45 | +fossil commit -m first | |
| 46 | +set manifestV1 [manifest_ci first] | |
| 47 | +write_file a.txt "one\ntwo\n" | |
| 48 | +fossil mv --hard b.txt c.txt | |
| 49 | +fossil commit -m second | |
| 50 | +set manifestV2 [manifest_ci second] | |
| 51 | + | |
| 52 | +############################################################################### | |
| 53 | +# Two check-ins compared by name. | |
| 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]} | |
| 65 | + | |
| 66 | +############################################################################### | |
| 67 | +# The /dir and /tree pages of a check-in. | |
| 68 | + | |
| 69 | +set manifestReply [manifest_get "/dir?ci=$manifestV2"] | |
| 70 | +test manifest-dir {[string match "*c.txt*" $manifestReply] | |
| 71 | + && ![string match "*b.txt*" $manifestReply]} | |
| 72 | +set manifestReply [manifest_get "/tree?ci=$manifestV2"] | |
| 73 | +test manifest-tree {[string match "*keep.txt*" $manifestReply]} | |
| 74 | +set manifestReply [manifest_get "/dir?ci=$manifestFile"] | |
| 75 | +test manifest-dir-not-checkin {[string match "HTTP/1.0 400 *" $manifestReply]} | |
| 76 | + | |
| 77 | +############################################################################### | |
| 78 | +# A delta manifest names only what changed since its baseline. A file it | |
| 79 | +# does not name is read from the baseline, and one it deletes is gone. | |
| 80 | + | |
| 81 | +fossil settings forbid-delta-manifests 0 | |
| 82 | +write_file a.txt "one\ntwo\nthree\n" | |
| 83 | +fossil commit --delta -m third | |
| 84 | +set manifestV3 [manifest_ci third] | |
| 85 | +fossil artifact $manifestV3 | |
| 86 | +test manifest-delta-made {[string match "B *" $RESULT]} | |
| 87 | +fossil cat keep.txt -r $manifestV3 | |
| 88 | +test_eq manifest-delta-from-baseline [string trim $RESULT] kept | |
| 89 | +fossil rm --hard keep.txt | |
| 90 | +fossil commit --delta -m fourth | |
| 91 | +set manifestV4 [manifest_ci fourth] | |
| 92 | +fossil artifact $manifestV4 | |
| 93 | +test manifest-delta-deletes {[string match "B *" $RESULT] | |
| 94 | + && [regexp {\nF keep.txt\n} $RESULT]} | |
| 95 | +fossil cat keep.txt -r $manifestV4 -expectError | |
| 96 | +test manifest-delta-deleted-gone {$CODE != 0} | |
| 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 | +############################################################################### | |
| 108 | +# With case-sensitive off, a file named in another letter case is the file | |
| 109 | +# the check-in holds. test-ci-mini does not commit without --wet-run. | |
| 110 | + | |
| 111 | +write_file a.txt "one\ntwo\nthree\nfour\n" | |
| 112 | +fossil settings case-sensitive off | |
| 113 | +fossil test-ci-mini -m case -r trunk --as A.TXT a.txt | |
| 114 | +test manifest-case-insensitive-found {$CODE == 0} | |
| 115 | +fossil cat NONE.TXT -r $manifestV3 -expectError | |
| 116 | +test manifest-case-insensitive-missing-in-delta {$CODE != 0 | |
| 117 | + && [string match "*NONE.TXT*" $RESULT]} | |
| 118 | +fossil settings case-sensitive on | |
| 119 | +fossil test-ci-mini -m case -r trunk --as A.TXT a.txt -expectError | |
| 120 | +test manifest-case-sensitive-new {$CODE != 0} | |
| 121 | +test_eq manifest-case-no-commit [manifest_ci case] "" | |
| 122 | + | |
| 123 | +############################################################################### | |
| 124 | +# artifact_to_json() describes every kind of artifact as JSON. | |
| 125 | + | |
| 126 | +write_file run.sh "#!/bin/sh\n" | |
| 127 | +fossil add run.sh | |
| 128 | +fossil commit -m exec | |
| 129 | +file attributes run.sh -permissions 0755 | |
| 130 | +fossil commit -m exec-set | |
| 131 | +fossil branch new side $manifestV2 | |
| 132 | +fossil update side | |
| 133 | +test manifest-json-update-side {$CODE == 0} | |
| 134 | +write_file side.txt "side\n" | |
| 135 | +fossil add side.txt | |
| 136 | +fossil commit -m side | |
| 137 | +fossil update trunk | |
| 138 | +fossil merge --cherrypick side | |
| 139 | +fossil commit -m cherrypick | |
| 140 | +fossil tag add release $manifestV1 | |
| 141 | +fossil tag add level $manifestV2 2 | |
| 142 | +write_file page.wiki "A page.\n" | |
| 143 | +fossil wiki create Page page.wiki | |
| 144 | +fossil wiki create Note page.wiki --technote 2026-01-01T00:00:00 | |
| 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 \ | |
| 160 | + cherrypick "\$.Q\[0\].type" + \ | |
| 161 | + tag "\$.T\[0\].name" sym-release \ | |
| 162 | +] { | |
| 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]} | |
| 204 | + | |
| 205 | +############################################################################### | |
| 206 | +# A repository that has lost the content of the baseline of a delta | |
| 207 | +# manifest: a file the delta manifest leaves to its baseline cannot be | |
| 208 | +# read. | |
| 209 | + | |
| 210 | +fossil artifact $manifestV3 | |
| 211 | +regexp {^B ([0-9a-f]+)} $RESULT manifestAll manifestBase | |
| 212 | +file copy [file join [pwd] .rep.fossil] lost-base.fossil | |
| 213 | +fossil sql -R lost-base.fossil "DELETE FROM delta WHERE rid=(SELECT rid | |
| 214 | + FROM blob WHERE uuid='$manifestBase'); | |
| 215 | + UPDATE blob SET size=-1, content=NULL WHERE uuid='$manifestBase'" | |
| 216 | +fossil cat keep.txt -r $manifestV3 -R lost-base.fossil -expectError | |
| 217 | +test manifest-lost-baseline {$CODE != 0 | |
| 218 | + && [string match "*cannot access baseline manifest*" $RESULT]} | |
| 219 | + | |
| 220 | +# A repository that has lost the content of a check-in: the check of all | |
| 221 | +# artifacts reports it, and the check-in cannot be compared. | |
| 222 | +file copy [file join [pwd] .rep.fossil] lost-ci.fossil | |
| 223 | +fossil sql -R lost-ci.fossil "DELETE FROM delta WHERE rid=(SELECT rid | |
| 224 | + FROM blob WHERE uuid='$manifestV1'); | |
| 225 | + UPDATE blob SET size=-1, content=NULL WHERE uuid='$manifestV1'" | |
| 226 | +fossil test-parse-all-blobs -R lost-ci.fossil | |
| 227 | +test manifest-lost-checkin-reported {$CODE == 0 | |
| 228 | + && [regexp {\d+ ERROR: } $RESULT] | |
| 229 | + && [string match "*tests with 1 errors*" $RESULT]} | |
| 230 | +fossil diff --from $manifestV1 --to $manifestV2 -R lost-ci.fossil -expectError | |
| 231 | +test manifest-lost-checkin-diff {$CODE != 0 | |
| 232 | + && [string match "*cannot parse manifest for check-in*" $RESULT]} | |
| 233 | + | |
| 234 | +############################################################################### | |
| 235 | +# A signed check-in whose parent is not in the repository. With the | |
| 236 | +# manifest setting on, the manifest file of a checkout of it carries a | |
| 237 | +# line that keeps the file from being an artifact, placed before the | |
| 238 | +# signature. "prev" names nothing that can be compared. | |
| 239 | + | |
| 240 | +write_file signed-body.txt "C signed | |
| 241 | +D 2026-05-01T10:00:00.000 | |
| 242 | +F a.txt $manifestFile | |
| 243 | +P [string repeat 3a 20] | |
| 244 | +U alice | |
| 245 | +" | |
| 246 | +fossil md5sum signed-body.txt | |
| 247 | +set manifestSigned "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n" | |
| 248 | +append manifestSigned [read_file signed-body.txt] "Z [lindex $RESULT 0]\n" | |
| 249 | +append manifestSigned "-----BEGIN PGP SIGNATURE-----\nabc\n" | |
| 250 | +append manifestSigned "-----END PGP SIGNATURE-----\n" | |
| 251 | +write_file signed.txt $manifestSigned | |
| 252 | +fossil test-content-put --crosslink signed.txt | |
| 253 | +set manifestSignedHash [manifest_ci signed] | |
| 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 | +fossil update trunk | |
| 266 | +test manifest-signed-update-back {$CODE == 0} | |
| 267 | + | |
| 268 | +############################################################################### | |
| 269 | + | |
| 270 | +test_cleanup |
| --- a/test/manifest.test | |
| +++ b/test/manifest.test | |
| @@ -0,0 +1,270 @@ | |
| --- a/test/manifest.test | |
| +++ b/test/manifest.test | |
| @@ -0,0 +1,270 @@ | |
| 1 | # |
| 2 | # Reading check-ins and their files in src/manifest.c: two check-ins |
| 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" |
| 44 | fossil add a.txt b.txt keep.txt |
| 45 | fossil commit -m first |
| 46 | set manifestV1 [manifest_ci first] |
| 47 | write_file a.txt "one\ntwo\n" |
| 48 | fossil mv --hard b.txt c.txt |
| 49 | fossil commit -m second |
| 50 | set manifestV2 [manifest_ci second] |
| 51 | |
| 52 | ############################################################################### |
| 53 | # Two check-ins compared by name. |
| 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]} |
| 65 | |
| 66 | ############################################################################### |
| 67 | # The /dir and /tree pages of a check-in. |
| 68 | |
| 69 | set manifestReply [manifest_get "/dir?ci=$manifestV2"] |
| 70 | test manifest-dir {[string match "*c.txt*" $manifestReply] |
| 71 | && ![string match "*b.txt*" $manifestReply]} |
| 72 | set manifestReply [manifest_get "/tree?ci=$manifestV2"] |
| 73 | test manifest-tree {[string match "*keep.txt*" $manifestReply]} |
| 74 | set manifestReply [manifest_get "/dir?ci=$manifestFile"] |
| 75 | test manifest-dir-not-checkin {[string match "HTTP/1.0 400 *" $manifestReply]} |
| 76 | |
| 77 | ############################################################################### |
| 78 | # A delta manifest names only what changed since its baseline. A file it |
| 79 | # does not name is read from the baseline, and one it deletes is gone. |
| 80 | |
| 81 | fossil settings forbid-delta-manifests 0 |
| 82 | write_file a.txt "one\ntwo\nthree\n" |
| 83 | fossil commit --delta -m third |
| 84 | set manifestV3 [manifest_ci third] |
| 85 | fossil artifact $manifestV3 |
| 86 | test manifest-delta-made {[string match "B *" $RESULT]} |
| 87 | fossil cat keep.txt -r $manifestV3 |
| 88 | test_eq manifest-delta-from-baseline [string trim $RESULT] kept |
| 89 | fossil rm --hard keep.txt |
| 90 | fossil commit --delta -m fourth |
| 91 | set manifestV4 [manifest_ci fourth] |
| 92 | fossil artifact $manifestV4 |
| 93 | test manifest-delta-deletes {[string match "B *" $RESULT] |
| 94 | && [regexp {\nF keep.txt\n} $RESULT]} |
| 95 | fossil cat keep.txt -r $manifestV4 -expectError |
| 96 | test manifest-delta-deleted-gone {$CODE != 0} |
| 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 | ############################################################################### |
| 108 | # With case-sensitive off, a file named in another letter case is the file |
| 109 | # the check-in holds. test-ci-mini does not commit without --wet-run. |
| 110 | |
| 111 | write_file a.txt "one\ntwo\nthree\nfour\n" |
| 112 | fossil settings case-sensitive off |
| 113 | fossil test-ci-mini -m case -r trunk --as A.TXT a.txt |
| 114 | test manifest-case-insensitive-found {$CODE == 0} |
| 115 | fossil cat NONE.TXT -r $manifestV3 -expectError |
| 116 | test manifest-case-insensitive-missing-in-delta {$CODE != 0 |
| 117 | && [string match "*NONE.TXT*" $RESULT]} |
| 118 | fossil settings case-sensitive on |
| 119 | fossil test-ci-mini -m case -r trunk --as A.TXT a.txt -expectError |
| 120 | test manifest-case-sensitive-new {$CODE != 0} |
| 121 | test_eq manifest-case-no-commit [manifest_ci case] "" |
| 122 | |
| 123 | ############################################################################### |
| 124 | # artifact_to_json() describes every kind of artifact as JSON. |
| 125 | |
| 126 | write_file run.sh "#!/bin/sh\n" |
| 127 | fossil add run.sh |
| 128 | fossil commit -m exec |
| 129 | file attributes run.sh -permissions 0755 |
| 130 | fossil commit -m exec-set |
| 131 | fossil branch new side $manifestV2 |
| 132 | fossil update side |
| 133 | test manifest-json-update-side {$CODE == 0} |
| 134 | write_file side.txt "side\n" |
| 135 | fossil add side.txt |
| 136 | fossil commit -m side |
| 137 | fossil update trunk |
| 138 | fossil merge --cherrypick side |
| 139 | fossil commit -m cherrypick |
| 140 | fossil tag add release $manifestV1 |
| 141 | fossil tag add level $manifestV2 2 |
| 142 | write_file page.wiki "A page.\n" |
| 143 | fossil wiki create Page page.wiki |
| 144 | fossil wiki create Note page.wiki --technote 2026-01-01T00:00:00 |
| 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 \ |
| 160 | cherrypick "\$.Q\[0\].type" + \ |
| 161 | tag "\$.T\[0\].name" sym-release \ |
| 162 | ] { |
| 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]} |
| 204 | |
| 205 | ############################################################################### |
| 206 | # A repository that has lost the content of the baseline of a delta |
| 207 | # manifest: a file the delta manifest leaves to its baseline cannot be |
| 208 | # read. |
| 209 | |
| 210 | fossil artifact $manifestV3 |
| 211 | regexp {^B ([0-9a-f]+)} $RESULT manifestAll manifestBase |
| 212 | file copy [file join [pwd] .rep.fossil] lost-base.fossil |
| 213 | fossil sql -R lost-base.fossil "DELETE FROM delta WHERE rid=(SELECT rid |
| 214 | FROM blob WHERE uuid='$manifestBase'); |
| 215 | UPDATE blob SET size=-1, content=NULL WHERE uuid='$manifestBase'" |
| 216 | fossil cat keep.txt -r $manifestV3 -R lost-base.fossil -expectError |
| 217 | test manifest-lost-baseline {$CODE != 0 |
| 218 | && [string match "*cannot access baseline manifest*" $RESULT]} |
| 219 | |
| 220 | # A repository that has lost the content of a check-in: the check of all |
| 221 | # artifacts reports it, and the check-in cannot be compared. |
| 222 | file copy [file join [pwd] .rep.fossil] lost-ci.fossil |
| 223 | fossil sql -R lost-ci.fossil "DELETE FROM delta WHERE rid=(SELECT rid |
| 224 | FROM blob WHERE uuid='$manifestV1'); |
| 225 | UPDATE blob SET size=-1, content=NULL WHERE uuid='$manifestV1'" |
| 226 | fossil test-parse-all-blobs -R lost-ci.fossil |
| 227 | test manifest-lost-checkin-reported {$CODE == 0 |
| 228 | && [regexp {\d+ ERROR: } $RESULT] |
| 229 | && [string match "*tests with 1 errors*" $RESULT]} |
| 230 | fossil diff --from $manifestV1 --to $manifestV2 -R lost-ci.fossil -expectError |
| 231 | test manifest-lost-checkin-diff {$CODE != 0 |
| 232 | && [string match "*cannot parse manifest for check-in*" $RESULT]} |
| 233 | |
| 234 | ############################################################################### |
| 235 | # A signed check-in whose parent is not in the repository. With the |
| 236 | # manifest setting on, the manifest file of a checkout of it carries a |
| 237 | # line that keeps the file from being an artifact, placed before the |
| 238 | # signature. "prev" names nothing that can be compared. |
| 239 | |
| 240 | write_file signed-body.txt "C signed |
| 241 | D 2026-05-01T10:00:00.000 |
| 242 | F a.txt $manifestFile |
| 243 | P [string repeat 3a 20] |
| 244 | U alice |
| 245 | " |
| 246 | fossil md5sum signed-body.txt |
| 247 | set manifestSigned "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n" |
| 248 | append manifestSigned [read_file signed-body.txt] "Z [lindex $RESULT 0]\n" |
| 249 | append manifestSigned "-----BEGIN PGP SIGNATURE-----\nabc\n" |
| 250 | append manifestSigned "-----END PGP SIGNATURE-----\n" |
| 251 | write_file signed.txt $manifestSigned |
| 252 | fossil test-content-put --crosslink signed.txt |
| 253 | set manifestSignedHash [manifest_ci signed] |
| 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 | fossil update trunk |
| 266 | test manifest-signed-update-back {$CODE == 0} |
| 267 | |
| 268 | ############################################################################### |
| 269 | |
| 270 | test_cleanup |
+20
| --- a/test/name.test | ||
| +++ b/test/name.test | ||
| @@ -0,0 +1,20 @@ | ||
| 1 | +########################## | |
| 2 | +# | |
| 3 | +# How a name typed by a user or taken from a URL becomes an artifact: | |
| 4 | +# src/name.c. One small repository holds check-ins on two branches with | |
| 5 | +# a merge between them, tags, a wiki page, a ticket, a technote, a forum | |
| 6 | +# post, an attachment, a cluster, phantoms and pairs of artifacts whose | |
| 7 | +# hashes begin alike. Every kind of name is then given to | |
| 8 | +# "fossil test-name-to-id", "fossil whatis" and other commands, and to | |
| 9 | +# web pages through "se tests run only in a lo -assurance stress.n@32t,_:runs only with -assurance stress" | |
| 10 | +} | |
| 11 | +3s@8U,v:answer of one SQL statement, trimmed. | |
| 12 | +# | |
| 13 | +proc name_sql {sqlM@Zx,l:fossil sql $sql | |
| 14 | + return [string trim $RESULT] | |
| 15 | +}1X@CD,4:namec@1AC,Dr@ER,4:nameN@1AC,HO@Sj,4:nameRv@jC,4:name164@1AC,4:nameR@8ZE,R:phantom"] == 5 | |
| 16 | + && [namek@2HE,4:nameV@8ZE,N@D00,CH@2Iu,W@310,DU@2Vg,Z@2jW,F6@2ij,V@2jW,s@2yL,V@2jW,t@2zi,V@2jW,2o@306,1I@5L0,1OF@35v,4:NoneU@2m0,1:}Qs@4U0,A:empty-typea@4Wf,B:"" $nameC1Pt@4tn,1:n9l@5Ii,4:name4j@5SZ,A:name_sql "b@D0V,Gz@5Y3,4:nameN@1AC,5z@5oU,A:name_sql "b@D0V,ez@5vE,d3@6_I,4:nameK@7Gz,1V@7Ck,4:nameK@7Gz,1A@7Ed,x@7Fx,4:name1d@7Gz,4:nametB@7Ih,1:"M@6VW,1:0J@8FW,Y@Azj,V@8OV,2:B3J@8FW,2:brT@5T~,V@8OV,Y@8FS,I@5aU,J@8GT,T@8QW,Ch@8HI,1:"L@6VW,b@8Uf,T@8VT,Y@8QW,Y@8kF,J: $nameCluster"]] {}M@86G,p@8YK,4:nameMJ@8ZE,4:nameV@8ZE,EU@8v6,3f:write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n" | |
| 17 | + file delete reply.txt | |
| 18 | + fossil_raw http $nameWeb --in request.txt --out reply.txt {*}$options | |
| 19 | + if {[file exists reply.txt]} { return [read_file reply.txt] } | |
| 20 | + return ""1X0@99X,Ff@Afc,4:namep@AvN,4:nameSL@AwH,88@BNl,K@BXj,I@8RF,5:</td>L@BIV,O@9MF,nL@BXQ,P@CN0,b@DVU,6:$nameCJ@CPG,T@CIw,R@CME,T@CN0,X@DOx,D:$nameTwin</a>L@BIV,5Z@COo,S@CUi,s@CVN,1Ho@CWJ,3R_4kw; |
| --- a/test/name.test | |
| +++ b/test/name.test | |
| @@ -0,0 +1,20 @@ | |
| --- a/test/name.test | |
| +++ b/test/name.test | |
| @@ -0,0 +1,20 @@ | |
| 1 | ########################## |
| 2 | # |
| 3 | # How a name typed by a user or taken from a URL becomes an artifact: |
| 4 | # src/name.c. One small repository holds check-ins on two branches with |
| 5 | # a merge between them, tags, a wiki page, a ticket, a technote, a forum |
| 6 | # post, an attachment, a cluster, phantoms and pairs of artifacts whose |
| 7 | # hashes begin alike. Every kind of name is then given to |
| 8 | # "fossil test-name-to-id", "fossil whatis" and other commands, and to |
| 9 | # web pages through "se tests run only in a lo -assurance stress.n@32t,_:runs only with -assurance stress" |
| 10 | } |
| 11 | 3s@8U,v:answer of one SQL statement, trimmed. |
| 12 | # |
| 13 | proc name_sql {sqlM@Zx,l:fossil sql $sql |
| 14 | return [string trim $RESULT] |
| 15 | }1X@CD,4:namec@1AC,Dr@ER,4:nameN@1AC,HO@Sj,4:nameRv@jC,4:name164@1AC,4:nameR@8ZE,R:phantom"] == 5 |
| 16 | && [namek@2HE,4:nameV@8ZE,N@D00,CH@2Iu,W@310,DU@2Vg,Z@2jW,F6@2ij,V@2jW,s@2yL,V@2jW,t@2zi,V@2jW,2o@306,1I@5L0,1OF@35v,4:NoneU@2m0,1:}Qs@4U0,A:empty-typea@4Wf,B:"" $nameC1Pt@4tn,1:n9l@5Ii,4:name4j@5SZ,A:name_sql "b@D0V,Gz@5Y3,4:nameN@1AC,5z@5oU,A:name_sql "b@D0V,ez@5vE,d3@6_I,4:nameK@7Gz,1V@7Ck,4:nameK@7Gz,1A@7Ed,x@7Fx,4:name1d@7Gz,4:nametB@7Ih,1:"M@6VW,1:0J@8FW,Y@Azj,V@8OV,2:B3J@8FW,2:brT@5T~,V@8OV,Y@8FS,I@5aU,J@8GT,T@8QW,Ch@8HI,1:"L@6VW,b@8Uf,T@8VT,Y@8QW,Y@8kF,J: $nameCluster"]] {}M@86G,p@8YK,4:nameMJ@8ZE,4:nameV@8ZE,EU@8v6,3f:write_file request.txt "GET $path HTTP/1.1\r\nHost: x\r\n\r\n" |
| 17 | file delete reply.txt |
| 18 | fossil_raw http $nameWeb --in request.txt --out reply.txt {*}$options |
| 19 | if {[file exists reply.txt]} { return [read_file reply.txt] } |
| 20 | return ""1X0@99X,Ff@Afc,4:namep@AvN,4:nameSL@AwH,88@BNl,K@BXj,I@8RF,5:</td>L@BIV,O@9MF,nL@BXQ,P@CN0,b@DVU,6:$nameCJ@CPG,T@CIw,R@CME,T@CN0,X@DOx,D:$nameTwin</a>L@BIV,5Z@COo,S@CUi,s@CVN,1Ho@CWJ,3R_4kw; |
+757
| --- a/test/purge.test | ||
| +++ b/test/purge.test | ||
| @@ -0,0 +1,757 @@ | ||
| 1 | +# | |
| 2 | +# Commands that remove content from a repository: "fossil purge", with | |
| 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] | |
| 93 | +} | |
| 94 | + | |
| 95 | +proc purge_has {repo hash} { | |
| 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 | |
| 107 | + WHERE pid NOT IN (SELECT rid FROM blob) | |
| 108 | + OR cid NOT IN (SELECT rid FROM blob))" $repo] | |
| 109 | +} | |
| 110 | + | |
| 111 | +############################################################################### | |
| 112 | +# A trunk of five check-ins, each a new version of one file, so that the | |
| 113 | +# file is stored as deltas; a branch of two check-ins off the third; and a | |
| 114 | +# second file that only the branch has. | |
| 115 | + | |
| 116 | +fossil settings autosync off | |
| 117 | +set purgeText "" | |
| 118 | +for {set purgeI 0} {$purgeI < 60} {incr purgeI} { | |
| 119 | + append purgeText "line $purgeI of a file that is stored as deltas\n" | |
| 120 | +} | |
| 121 | +set purgeTrunk {} | |
| 122 | +for {set purgeI 1} {$purgeI <= 5} {incr purgeI} { | |
| 123 | + append purgeText "version $purgeI\n" | |
| 124 | + lappend purgeTrunk [purge_commit a.txt $purgeText purge-trunk-$purgeI] | |
| 125 | + set purgeTrunkText($purgeI) $purgeText | |
| 126 | +} | |
| 127 | +fossil update [lindex $purgeTrunk 2] | |
| 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 | + 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 | +############################################################################### | |
| 164 | +# Purge a branch. Its check-ins, and the files that only it uses, go; | |
| 165 | +# everything on trunk can still be read. | |
| 166 | + | |
| 167 | +fossil purge checkins side | |
| 168 | +test purge-checkins {$CODE == 0 && | |
| 169 | + [string match "*artifacts purged*" $RESULT]} | |
| 170 | +test_eq purge-checkins-gone [purge_sql "SELECT count(*) FROM blob | |
| 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] | |
| 182 | +fossil purge list | |
| 183 | +test purge-list {[string match "*$purgeEvent on *" $RESULT]} | |
| 184 | +fossil purge list -l | |
| 185 | +test purge-list-detail {[string first [string range $purgeSide2 0 9] \ | |
| 186 | + $RESULT] >= 0} | |
| 187 | +# "ls" is another name for "list". | |
| 188 | +fossil purge ls | |
| 189 | +test purge-ls {[string match "*$purgeEvent on *" $RESULT]} | |
| 190 | + | |
| 191 | +# The graveyard gives back the content, a delta among it included. | |
| 192 | +fossil purge cat $purgeSideB | |
| 193 | +test_eq purge-cat [string trim $RESULT] "a file only the branch has" | |
| 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 | + | |
| 217 | +############################################################################### | |
| 218 | +# A record number that a purge frees can be given to the next artifact | |
| 219 | +# stored. A kept check-in must never take that artifact for its parent, | |
| 220 | +# before the undo or after it. The parent is made the newest record by | |
| 221 | +# storing it last, and the repository is then rebuilt to link them. | |
| 222 | +set purgeP [lindex $purgeTrunk 3] | |
| 223 | +set purgeC [lindex $purgeTrunk 4] | |
| 224 | +fossil init p5.fossil | |
| 225 | +set purgeAll [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid | |
| 226 | + FROM blob WHERE size>=0 AND uuid<>'$purgeP' ORDER BY rid)" full.fossil] | |
| 227 | +foreach purgeH [concat $purgeAll [list $purgeP]] { | |
| 228 | + fossil artifact $purgeH -R full.fossil art.txt | |
| 229 | + fossil test-content-put art.txt -R p5.fossil | |
| 230 | +} | |
| 231 | +fossil rebuild p5.fossil | |
| 232 | +test purge-reuse-setup {[purge_sql "SELECT count(*) FROM plink | |
| 233 | + WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeC') | |
| 234 | + AND pid=(SELECT rid FROM blob WHERE uuid='$purgeP') | |
| 235 | + AND pid=(SELECT max(rid) FROM blob)" p5.fossil] == 1} | |
| 236 | +fossil purge artifacts $purgeP -R p5.fossil | |
| 237 | +write_file other.txt "an artifact stored after the purge\n" | |
| 238 | +fossil test-content-put other.txt -R p5.fossil | |
| 239 | +proc purge_parent_of {repo child} { | |
| 240 | + return [purge_sql "SELECT group_concat(p.uuid) FROM plink | |
| 241 | + JOIN blob p ON p.rid=plink.pid | |
| 242 | + WHERE plink.cid=(SELECT rid FROM blob WHERE uuid='$child')" $repo] | |
| 243 | +} | |
| 244 | +test purge-reuse-no-false-parent \ | |
| 245 | + {[purge_parent_of p5.fossil $purgeC] in [list "" $purgeP]} | |
| 246 | +fossil purge undo [purge_last_event p5.fossil] -R p5.fossil | |
| 247 | +test purge-reuse-undo {$CODE == 0} | |
| 248 | +test purge-reuse-undo-no-false-parent \ | |
| 249 | + {[purge_parent_of p5.fossil $purgeC] in [list "" $purgeP]} | |
| 250 | + | |
| 251 | +# What is refused. | |
| 252 | + | |
| 253 | +fossil update side | |
| 254 | +fossil purge checkins side -expectError | |
| 255 | +test purge-current-checkout {$CODE != 0 && | |
| 256 | + [string match "*cannot purge the current check-out*" $RESULT]} | |
| 257 | +# The same when the repository is named with -R from inside the check-out. | |
| 258 | +fossil purge checkins side -R [file join [pwd] .rep.fossil] -expectError | |
| 259 | +test purge-current-checkout-repository {$CODE != 0 && | |
| 260 | + [string match "*cannot purge the current check-out*" $RESULT]} | |
| 261 | +# And when it is named by a symbolic link to it. | |
| 262 | +if {$::tcl_platform(platform) eq "unix"} { | |
| 263 | + file link -symbolic link.fossil [file join [pwd] .rep.fossil] | |
| 264 | + fossil purge checkins side -R link.fossil -expectError | |
| 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} | |
| 276 | +fossil purge wiki x -expectError | |
| 277 | +test purge-wiki-not-implemented {$CODE != 0} | |
| 278 | +fossil purge frobnicate -expectError | |
| 279 | +test purge-unknown-subcommand {$CODE != 0} | |
| 280 | + | |
| 281 | +# Each of these lacks an argument and gets the usage message. | |
| 282 | +foreach {purgeName purgeArgs} { | |
| 283 | + nothing {} | |
| 284 | + cat {cat} | |
| 285 | + checkins {checkins} | |
| 286 | + obliterate {obliterate --force} | |
| 287 | + undo {undo} | |
| 288 | + undo-two {undo 1 2} | |
| 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 | |
| 308 | +fossil artifact $purgeV2 -R p1.fossil | |
| 309 | +test_eq purge-artifact-neighbour-readable "$RESULT\n" $purgeTrunkText(2) | |
| 310 | +fossil test-integrity -R p1.fossil | |
| 311 | +test purge-artifact-integrity {$CODE == 0} | |
| 312 | +# While it is purged, the check-in that holds it lacks a file, and | |
| 313 | +# test-missing says so. | |
| 314 | +fossil test-missing -R p1.fossil -expectError | |
| 315 | +test purge-artifact-missing-reported {$CODE != 0} | |
| 316 | + | |
| 317 | +# After the undo the check-ins that hold the file point to it again, and | |
| 318 | +# the history of the file has every version. | |
| 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} | |
| 334 | +test_eq purge-files-gone [purge_sql "SELECT count(*) FROM blob | |
| 335 | + WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 0 | |
| 336 | +fossil purge undo [purge_last_event p2.fossil] -R p2.fossil | |
| 337 | +test purge-files-undo {$CODE == 0} | |
| 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 | |
| 349 | +test purge-checkins-repository-explain {$CODE == 0} | |
| 350 | +# The same from a directory that is not in any check-out. | |
| 351 | +set purgeHere [pwd] | |
| 352 | +cd [file dirname $purgeHere] | |
| 353 | +fossil_raw purge checkins side --explain -R [file join $purgeHere p3.fossil] | |
| 354 | +cd $purgeHere | |
| 355 | +test purge-checkins-no-checkout-explain {$CODE == 0 && | |
| 356 | + [string first [string range $purgeSide2 0 15] $RESULT] >= 0} | |
| 357 | +fossil_raw purge checkins side -R p3.fossil | |
| 358 | +test purge-checkins-repository {$CODE == 0} | |
| 359 | + | |
| 360 | +# One check-in in the middle of trunk, alone, on a copy. Its child keeps | |
| 361 | +# its link to it, and after the undo the history is as it was. While it is | |
| 362 | +# purged the child names a parent that is not there, and test-missing says | |
| 363 | +# so. | |
| 364 | +file copy full.fossil p4.fossil | |
| 365 | +set purgeMiddle [lindex $purgeTrunk 3] | |
| 366 | +fossil purge artifacts $purgeMiddle -R p4.fossil | |
| 367 | +test purge-middle {$CODE == 0} | |
| 368 | +test_eq purge-middle-gone [purge_has p4.fossil $purgeMiddle] 0 | |
| 369 | +fossil test-integrity -R p4.fossil | |
| 370 | +test purge-middle-integrity {$CODE == 0} | |
| 371 | +fossil test-missing -R p4.fossil -expectError | |
| 372 | +test purge-middle-missing-reported {$CODE != 0} | |
| 373 | +fossil timeline -n 20 -R p4.fossil | |
| 374 | +test purge-middle-timeline {$CODE == 0 && | |
| 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. | |
| 406 | +file copy full.fossil p6.fossil | |
| 407 | +fossil sql -R p6.fossil "ALTER TABLE plink DROP COLUMN baseid" | |
| 408 | +fossil purge artifacts $purgeMiddle -R p6.fossil | |
| 409 | +test purge-old-plink {$CODE == 0} | |
| 410 | +test_eq purge-old-plink-gone [purge_has p6.fossil $purgeMiddle] 0 | |
| 411 | +fossil rebuild p6.fossil | |
| 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 | |
| 424 | +fossil bundle export side.bundle --branch side -R p7.fossil | |
| 425 | +test purge-bundle-export {$CODE == 0} | |
| 426 | +fossil bundle purge side.bundle -R p7.fossil | |
| 427 | +test purge-bundle {$CODE == 0 && ![string match "*undoable*" $RESULT] && | |
| 428 | + ![string match "*artifacts purged*" $RESULT]} | |
| 429 | +test_eq purge-bundle-gone [purge_sql "SELECT count(*) FROM blob | |
| 430 | + WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')" p7.fossil] 0 | |
| 431 | +test_eq purge-bundle-no-graveyard [purge_sql "SELECT count(*) | |
| 432 | + FROM sqlite_schema WHERE name IN ('purgeevent','purgeitem')" p7.fossil] 0 | |
| 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 | |
| 444 | +# the repository under record number 0; that undo stops with no message. | |
| 445 | + | |
| 446 | +file copy full.fossil p8.fossil | |
| 447 | +fossil purge files a.txt -R p8.fossil | |
| 448 | +set purgeEvent8 [purge_last_event p8.fossil] | |
| 449 | +set purgeDeltaItem [purge_sql "SELECT uuid FROM purgeitem | |
| 450 | + WHERE srcid IS NOT NULL LIMIT 1" p8.fossil] | |
| 451 | +set purgeWholeItem [purge_sql "SELECT uuid FROM purgeitem | |
| 452 | + WHERE srcid IS NULL LIMIT 1" p8.fossil] | |
| 453 | +test purge-damage-setup {$purgeDeltaItem ne "" && $purgeWholeItem ne ""} | |
| 454 | +set purgeOtherHash [string repeat a 64] | |
| 455 | +foreach {purgeName purgeDamage purgeArgs purgeMessage} [list \ | |
| 456 | + source-gone \ | |
| 457 | + "DELETE FROM purgeitem WHERE piid=(SELECT srcid FROM purgeitem | |
| 458 | + WHERE uuid='$purgeDeltaItem')" \ | |
| 459 | + [list cat $purgeDeltaItem] \ | |
| 460 | + "*missing purge-item*" \ | |
| 461 | + cat-wrong-hash \ | |
| 462 | + "UPDATE purgeitem SET uuid='$purgeOtherHash' | |
| 463 | + WHERE uuid='$purgeWholeItem'" \ | |
| 464 | + [list cat $purgeOtherHash] \ | |
| 465 | + "*incorrect artifact hash on $purgeOtherHash*" \ | |
| 466 | + undo-wrong-hash \ | |
| 467 | + "UPDATE purgeitem SET uuid='$purgeOtherHash' | |
| 468 | + WHERE uuid='$purgeWholeItem'" \ | |
| 469 | + [list undo $purgeEvent8] \ | |
| 470 | + "*incorrect hash on $purgeOtherHash*" \ | |
| 471 | + cat-source-loop \ | |
| 472 | + "UPDATE purgeitem SET srcid=(SELECT piid FROM purgeitem | |
| 473 | + WHERE uuid='$purgeDeltaItem') | |
| 474 | + WHERE piid=(SELECT srcid FROM purgeitem | |
| 475 | + WHERE uuid='$purgeDeltaItem')" \ | |
| 476 | + [list cat $purgeDeltaItem] \ | |
| 477 | + "*is part of a delta cycle*" \ | |
| 478 | + undo-record-zero \ | |
| 479 | + "PRAGMA ignore_check_constraints=1; | |
| 480 | + INSERT INTO blob(rid,rcvid,size,uuid) | |
| 481 | + VALUES(0,0,1,'$purgeWholeItem')" \ | |
| 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 | + | |
| 497 | +# An item with no record number is restored under a new one. | |
| 498 | +file copy -force p8.fossil damaged.fossil | |
| 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 | |
| 511 | +fossil purge artifacts $purgeP -R damaged.fossil | |
| 512 | +fossil sql -R damaged.fossil "UPDATE blob SET size=-1, content=NULL | |
| 513 | + WHERE uuid='$purgeC'" | |
| 514 | +fossil purge undo [purge_last_event damaged.fossil] -R damaged.fossil | |
| 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 | + | |
| 526 | +fossil purge checkins side | |
| 527 | +set purgeEvent [purge_last_event] | |
| 528 | + | |
| 529 | +# The error for a missing item names the item that is missing. | |
| 530 | +fossil_raw purge cat $purgeSideB [string repeat 0 40] | |
| 531 | +test purge-cat-second-missing {$CODE != 0 && | |
| 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. | |
| 543 | +fossil purge artifacts $purgeMiddle -R p4.fossil | |
| 544 | +set purgeEvent4 [purge_last_event p4.fossil] | |
| 545 | +fossil_raw -input "Y\n" purge obliterate $purgeEvent4 -R p4.fossil | |
| 546 | +test purge-obliterate-capital {$CODE == 0} | |
| 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 | |
| 565 | +foreach {purgeName purgeArgs} { | |
| 566 | + undo {undo 1} | |
| 567 | + obliterate {obliterate 1 --force} | |
| 568 | +} { | |
| 569 | + fossil_raw purge {*}$purgeArgs -R nograve.fossil | |
| 570 | + test purge-no-graveyard-$purgeName {$CODE == 1 && | |
| 571 | + [string match "*no such purge event: 1*" $RESULT]} | |
| 572 | +} | |
| 573 | +fossil purge list -R nograve.fossil | |
| 574 | +test_eq purge-no-graveyard-list [string trim $RESULT] "" | |
| 575 | +fossil scrub --private --force nograve.fossil | |
| 576 | +test purge-no-graveyard-scrub {$CODE == 0} | |
| 577 | +test_eq purge-no-graveyard-none-made [purge_sql "SELECT count(*) | |
| 578 | + FROM sqlite_schema WHERE name IN ('purgeevent','purgeitem')" \ | |
| 579 | + nograve.fossil] 0 | |
| 580 | + | |
| 581 | +############################################################################### | |
| 582 | +# A purge is local. A clone made afterwards lacks what was purged; a | |
| 583 | +# pull from a repository that still holds it brings it back. | |
| 584 | + | |
| 585 | +fossil clone .rep.fossil c1.fossil | |
| 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 | + | |
| 598 | +set purgeSecretText "" | |
| 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 | |
| 640 | +test_eq purge-scrub-private-file-gone [purge_has s2.fossil $purgeSecretFile] 0 | |
| 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} | |
| 653 | +# The detailed list marks each private item with a P. | |
| 654 | +fossil purge list -l -R s3.fossil | |
| 655 | +test purge-list-private-mark {[regexp -line \ | |
| 656 | + "^ +\\d+ [string range $purgeSecret 0 15] +P +\\d+ " $RESULT]} | |
| 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 | |
| 689 | + WHERE rid=(SELECT rid FROM blob WHERE uuid='$purgeSecretFile') | |
| 690 | + AND srcid=(SELECT rid FROM blob WHERE uuid='$purgeSecretFile2') | |
| 691 | + AND rid NOT IN private AND srcid IN private" s6.fossil] == 1} | |
| 692 | +fossil purge artifacts $purgeSecretFile $purgeSecretFile2 -R s6.fossil | |
| 693 | +test purge-scrub-delta-in-graveyard {[purge_sql "SELECT count(*) | |
| 694 | + FROM purgeitem a JOIN purgeitem b ON a.srcid=b.piid | |
| 695 | + WHERE NOT a.isPrivate AND b.isPrivate" s6.fossil] == 1} | |
| 696 | +fossil scrub --private --force s6.fossil | |
| 697 | +test purge-scrub-delta {$CODE == 0} | |
| 698 | +test_eq purge-scrub-delta-private-gone [purge_sql "SELECT count(*) | |
| 699 | + FROM purgeitem WHERE isPrivate" s6.fossil] 0 | |
| 700 | +fossil purge cat $purgeSecretFile -R s6.fossil | |
| 701 | +test_eq purge-scrub-delta-public-kept $RESULT [string trim $purgeSecretText] | |
| 702 | + | |
| 703 | +# --verily removes the graveyard too, and the private branch. | |
| 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 | |
| 717 | + | |
| 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. | |
| 732 | + | |
| 733 | +fossil settings forbid-delta-manifests off | |
| 734 | +set purgeBase [lindex $purgeTrunk 4] | |
| 735 | +set purgeDeltaM [purge_commit a.txt "${purgeTrunkText(5)}one more line\n" \ | |
| 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 |
| --- a/test/purge.test | |
| +++ b/test/purge.test | |
| @@ -0,0 +1,757 @@ | |
| --- a/test/purge.test | |
| +++ b/test/purge.test | |
| @@ -0,0 +1,757 @@ | |
| 1 | # |
| 2 | # Commands that remove content from a repository: "fossil purge", with |
| 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] |
| 93 | } |
| 94 | |
| 95 | proc purge_has {repo hash} { |
| 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 |
| 107 | WHERE pid NOT IN (SELECT rid FROM blob) |
| 108 | OR cid NOT IN (SELECT rid FROM blob))" $repo] |
| 109 | } |
| 110 | |
| 111 | ############################################################################### |
| 112 | # A trunk of five check-ins, each a new version of one file, so that the |
| 113 | # file is stored as deltas; a branch of two check-ins off the third; and a |
| 114 | # second file that only the branch has. |
| 115 | |
| 116 | fossil settings autosync off |
| 117 | set purgeText "" |
| 118 | for {set purgeI 0} {$purgeI < 60} {incr purgeI} { |
| 119 | append purgeText "line $purgeI of a file that is stored as deltas\n" |
| 120 | } |
| 121 | set purgeTrunk {} |
| 122 | for {set purgeI 1} {$purgeI <= 5} {incr purgeI} { |
| 123 | append purgeText "version $purgeI\n" |
| 124 | lappend purgeTrunk [purge_commit a.txt $purgeText purge-trunk-$purgeI] |
| 125 | set purgeTrunkText($purgeI) $purgeText |
| 126 | } |
| 127 | fossil update [lindex $purgeTrunk 2] |
| 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 | 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 | ############################################################################### |
| 164 | # Purge a branch. Its check-ins, and the files that only it uses, go; |
| 165 | # everything on trunk can still be read. |
| 166 | |
| 167 | fossil purge checkins side |
| 168 | test purge-checkins {$CODE == 0 && |
| 169 | [string match "*artifacts purged*" $RESULT]} |
| 170 | test_eq purge-checkins-gone [purge_sql "SELECT count(*) FROM blob |
| 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] |
| 182 | fossil purge list |
| 183 | test purge-list {[string match "*$purgeEvent on *" $RESULT]} |
| 184 | fossil purge list -l |
| 185 | test purge-list-detail {[string first [string range $purgeSide2 0 9] \ |
| 186 | $RESULT] >= 0} |
| 187 | # "ls" is another name for "list". |
| 188 | fossil purge ls |
| 189 | test purge-ls {[string match "*$purgeEvent on *" $RESULT]} |
| 190 | |
| 191 | # The graveyard gives back the content, a delta among it included. |
| 192 | fossil purge cat $purgeSideB |
| 193 | test_eq purge-cat [string trim $RESULT] "a file only the branch has" |
| 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 | |
| 217 | ############################################################################### |
| 218 | # A record number that a purge frees can be given to the next artifact |
| 219 | # stored. A kept check-in must never take that artifact for its parent, |
| 220 | # before the undo or after it. The parent is made the newest record by |
| 221 | # storing it last, and the repository is then rebuilt to link them. |
| 222 | set purgeP [lindex $purgeTrunk 3] |
| 223 | set purgeC [lindex $purgeTrunk 4] |
| 224 | fossil init p5.fossil |
| 225 | set purgeAll [purge_sql "SELECT group_concat(uuid,' ') FROM (SELECT uuid |
| 226 | FROM blob WHERE size>=0 AND uuid<>'$purgeP' ORDER BY rid)" full.fossil] |
| 227 | foreach purgeH [concat $purgeAll [list $purgeP]] { |
| 228 | fossil artifact $purgeH -R full.fossil art.txt |
| 229 | fossil test-content-put art.txt -R p5.fossil |
| 230 | } |
| 231 | fossil rebuild p5.fossil |
| 232 | test purge-reuse-setup {[purge_sql "SELECT count(*) FROM plink |
| 233 | WHERE cid=(SELECT rid FROM blob WHERE uuid='$purgeC') |
| 234 | AND pid=(SELECT rid FROM blob WHERE uuid='$purgeP') |
| 235 | AND pid=(SELECT max(rid) FROM blob)" p5.fossil] == 1} |
| 236 | fossil purge artifacts $purgeP -R p5.fossil |
| 237 | write_file other.txt "an artifact stored after the purge\n" |
| 238 | fossil test-content-put other.txt -R p5.fossil |
| 239 | proc purge_parent_of {repo child} { |
| 240 | return [purge_sql "SELECT group_concat(p.uuid) FROM plink |
| 241 | JOIN blob p ON p.rid=plink.pid |
| 242 | WHERE plink.cid=(SELECT rid FROM blob WHERE uuid='$child')" $repo] |
| 243 | } |
| 244 | test purge-reuse-no-false-parent \ |
| 245 | {[purge_parent_of p5.fossil $purgeC] in [list "" $purgeP]} |
| 246 | fossil purge undo [purge_last_event p5.fossil] -R p5.fossil |
| 247 | test purge-reuse-undo {$CODE == 0} |
| 248 | test purge-reuse-undo-no-false-parent \ |
| 249 | {[purge_parent_of p5.fossil $purgeC] in [list "" $purgeP]} |
| 250 | |
| 251 | # What is refused. |
| 252 | |
| 253 | fossil update side |
| 254 | fossil purge checkins side -expectError |
| 255 | test purge-current-checkout {$CODE != 0 && |
| 256 | [string match "*cannot purge the current check-out*" $RESULT]} |
| 257 | # The same when the repository is named with -R from inside the check-out. |
| 258 | fossil purge checkins side -R [file join [pwd] .rep.fossil] -expectError |
| 259 | test purge-current-checkout-repository {$CODE != 0 && |
| 260 | [string match "*cannot purge the current check-out*" $RESULT]} |
| 261 | # And when it is named by a symbolic link to it. |
| 262 | if {$::tcl_platform(platform) eq "unix"} { |
| 263 | file link -symbolic link.fossil [file join [pwd] .rep.fossil] |
| 264 | fossil purge checkins side -R link.fossil -expectError |
| 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} |
| 276 | fossil purge wiki x -expectError |
| 277 | test purge-wiki-not-implemented {$CODE != 0} |
| 278 | fossil purge frobnicate -expectError |
| 279 | test purge-unknown-subcommand {$CODE != 0} |
| 280 | |
| 281 | # Each of these lacks an argument and gets the usage message. |
| 282 | foreach {purgeName purgeArgs} { |
| 283 | nothing {} |
| 284 | cat {cat} |
| 285 | checkins {checkins} |
| 286 | obliterate {obliterate --force} |
| 287 | undo {undo} |
| 288 | undo-two {undo 1 2} |
| 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 |
| 308 | fossil artifact $purgeV2 -R p1.fossil |
| 309 | test_eq purge-artifact-neighbour-readable "$RESULT\n" $purgeTrunkText(2) |
| 310 | fossil test-integrity -R p1.fossil |
| 311 | test purge-artifact-integrity {$CODE == 0} |
| 312 | # While it is purged, the check-in that holds it lacks a file, and |
| 313 | # test-missing says so. |
| 314 | fossil test-missing -R p1.fossil -expectError |
| 315 | test purge-artifact-missing-reported {$CODE != 0} |
| 316 | |
| 317 | # After the undo the check-ins that hold the file point to it again, and |
| 318 | # the history of the file has every version. |
| 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} |
| 334 | test_eq purge-files-gone [purge_sql "SELECT count(*) FROM blob |
| 335 | WHERE uuid IN ('$purgeV2','$purgeV3')" p2.fossil] 0 |
| 336 | fossil purge undo [purge_last_event p2.fossil] -R p2.fossil |
| 337 | test purge-files-undo {$CODE == 0} |
| 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 |
| 349 | test purge-checkins-repository-explain {$CODE == 0} |
| 350 | # The same from a directory that is not in any check-out. |
| 351 | set purgeHere [pwd] |
| 352 | cd [file dirname $purgeHere] |
| 353 | fossil_raw purge checkins side --explain -R [file join $purgeHere p3.fossil] |
| 354 | cd $purgeHere |
| 355 | test purge-checkins-no-checkout-explain {$CODE == 0 && |
| 356 | [string first [string range $purgeSide2 0 15] $RESULT] >= 0} |
| 357 | fossil_raw purge checkins side -R p3.fossil |
| 358 | test purge-checkins-repository {$CODE == 0} |
| 359 | |
| 360 | # One check-in in the middle of trunk, alone, on a copy. Its child keeps |
| 361 | # its link to it, and after the undo the history is as it was. While it is |
| 362 | # purged the child names a parent that is not there, and test-missing says |
| 363 | # so. |
| 364 | file copy full.fossil p4.fossil |
| 365 | set purgeMiddle [lindex $purgeTrunk 3] |
| 366 | fossil purge artifacts $purgeMiddle -R p4.fossil |
| 367 | test purge-middle {$CODE == 0} |
| 368 | test_eq purge-middle-gone [purge_has p4.fossil $purgeMiddle] 0 |
| 369 | fossil test-integrity -R p4.fossil |
| 370 | test purge-middle-integrity {$CODE == 0} |
| 371 | fossil test-missing -R p4.fossil -expectError |
| 372 | test purge-middle-missing-reported {$CODE != 0} |
| 373 | fossil timeline -n 20 -R p4.fossil |
| 374 | test purge-middle-timeline {$CODE == 0 && |
| 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. |
| 406 | file copy full.fossil p6.fossil |
| 407 | fossil sql -R p6.fossil "ALTER TABLE plink DROP COLUMN baseid" |
| 408 | fossil purge artifacts $purgeMiddle -R p6.fossil |
| 409 | test purge-old-plink {$CODE == 0} |
| 410 | test_eq purge-old-plink-gone [purge_has p6.fossil $purgeMiddle] 0 |
| 411 | fossil rebuild p6.fossil |
| 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 |
| 424 | fossil bundle export side.bundle --branch side -R p7.fossil |
| 425 | test purge-bundle-export {$CODE == 0} |
| 426 | fossil bundle purge side.bundle -R p7.fossil |
| 427 | test purge-bundle {$CODE == 0 && ![string match "*undoable*" $RESULT] && |
| 428 | ![string match "*artifacts purged*" $RESULT]} |
| 429 | test_eq purge-bundle-gone [purge_sql "SELECT count(*) FROM blob |
| 430 | WHERE uuid IN ('$purgeSide1','$purgeSide2','$purgeSideB')" p7.fossil] 0 |
| 431 | test_eq purge-bundle-no-graveyard [purge_sql "SELECT count(*) |
| 432 | FROM sqlite_schema WHERE name IN ('purgeevent','purgeitem')" p7.fossil] 0 |
| 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 |
| 444 | # the repository under record number 0; that undo stops with no message. |
| 445 | |
| 446 | file copy full.fossil p8.fossil |
| 447 | fossil purge files a.txt -R p8.fossil |
| 448 | set purgeEvent8 [purge_last_event p8.fossil] |
| 449 | set purgeDeltaItem [purge_sql "SELECT uuid FROM purgeitem |
| 450 | WHERE srcid IS NOT NULL LIMIT 1" p8.fossil] |
| 451 | set purgeWholeItem [purge_sql "SELECT uuid FROM purgeitem |
| 452 | WHERE srcid IS NULL LIMIT 1" p8.fossil] |
| 453 | test purge-damage-setup {$purgeDeltaItem ne "" && $purgeWholeItem ne ""} |
| 454 | set purgeOtherHash [string repeat a 64] |
| 455 | foreach {purgeName purgeDamage purgeArgs purgeMessage} [list \ |
| 456 | source-gone \ |
| 457 | "DELETE FROM purgeitem WHERE piid=(SELECT srcid FROM purgeitem |
| 458 | WHERE uuid='$purgeDeltaItem')" \ |
| 459 | [list cat $purgeDeltaItem] \ |
| 460 | "*missing purge-item*" \ |
| 461 | cat-wrong-hash \ |
| 462 | "UPDATE purgeitem SET uuid='$purgeOtherHash' |
| 463 | WHERE uuid='$purgeWholeItem'" \ |
| 464 | [list cat $purgeOtherHash] \ |
| 465 | "*incorrect artifact hash on $purgeOtherHash*" \ |
| 466 | undo-wrong-hash \ |
| 467 | "UPDATE purgeitem SET uuid='$purgeOtherHash' |
| 468 | WHERE uuid='$purgeWholeItem'" \ |
| 469 | [list undo $purgeEvent8] \ |
| 470 | "*incorrect hash on $purgeOtherHash*" \ |
| 471 | cat-source-loop \ |
| 472 | "UPDATE purgeitem SET srcid=(SELECT piid FROM purgeitem |
| 473 | WHERE uuid='$purgeDeltaItem') |
| 474 | WHERE piid=(SELECT srcid FROM purgeitem |
| 475 | WHERE uuid='$purgeDeltaItem')" \ |
| 476 | [list cat $purgeDeltaItem] \ |
| 477 | "*is part of a delta cycle*" \ |
| 478 | undo-record-zero \ |
| 479 | "PRAGMA ignore_check_constraints=1; |
| 480 | INSERT INTO blob(rid,rcvid,size,uuid) |
| 481 | VALUES(0,0,1,'$purgeWholeItem')" \ |
| 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 | |
| 497 | # An item with no record number is restored under a new one. |
| 498 | file copy -force p8.fossil damaged.fossil |
| 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 |
| 511 | fossil purge artifacts $purgeP -R damaged.fossil |
| 512 | fossil sql -R damaged.fossil "UPDATE blob SET size=-1, content=NULL |
| 513 | WHERE uuid='$purgeC'" |
| 514 | fossil purge undo [purge_last_event damaged.fossil] -R damaged.fossil |
| 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 | |
| 526 | fossil purge checkins side |
| 527 | set purgeEvent [purge_last_event] |
| 528 | |
| 529 | # The error for a missing item names the item that is missing. |
| 530 | fossil_raw purge cat $purgeSideB [string repeat 0 40] |
| 531 | test purge-cat-second-missing {$CODE != 0 && |
| 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. |
| 543 | fossil purge artifacts $purgeMiddle -R p4.fossil |
| 544 | set purgeEvent4 [purge_last_event p4.fossil] |
| 545 | fossil_raw -input "Y\n" purge obliterate $purgeEvent4 -R p4.fossil |
| 546 | test purge-obliterate-capital {$CODE == 0} |
| 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 |
| 565 | foreach {purgeName purgeArgs} { |
| 566 | undo {undo 1} |
| 567 | obliterate {obliterate 1 --force} |
| 568 | } { |
| 569 | fossil_raw purge {*}$purgeArgs -R nograve.fossil |
| 570 | test purge-no-graveyard-$purgeName {$CODE == 1 && |
| 571 | [string match "*no such purge event: 1*" $RESULT]} |
| 572 | } |
| 573 | fossil purge list -R nograve.fossil |
| 574 | test_eq purge-no-graveyard-list [string trim $RESULT] "" |
| 575 | fossil scrub --private --force nograve.fossil |
| 576 | test purge-no-graveyard-scrub {$CODE == 0} |
| 577 | test_eq purge-no-graveyard-none-made [purge_sql "SELECT count(*) |
| 578 | FROM sqlite_schema WHERE name IN ('purgeevent','purgeitem')" \ |
| 579 | nograve.fossil] 0 |
| 580 | |
| 581 | ############################################################################### |
| 582 | # A purge is local. A clone made afterwards lacks what was purged; a |
| 583 | # pull from a repository that still holds it brings it back. |
| 584 | |
| 585 | fossil clone .rep.fossil c1.fossil |
| 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 | |
| 598 | set purgeSecretText "" |
| 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 |
| 640 | test_eq purge-scrub-private-file-gone [purge_has s2.fossil $purgeSecretFile] 0 |
| 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} |
| 653 | # The detailed list marks each private item with a P. |
| 654 | fossil purge list -l -R s3.fossil |
| 655 | test purge-list-private-mark {[regexp -line \ |
| 656 | "^ +\\d+ [string range $purgeSecret 0 15] +P +\\d+ " $RESULT]} |
| 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 |
| 689 | WHERE rid=(SELECT rid FROM blob WHERE uuid='$purgeSecretFile') |
| 690 | AND srcid=(SELECT rid FROM blob WHERE uuid='$purgeSecretFile2') |
| 691 | AND rid NOT IN private AND srcid IN private" s6.fossil] == 1} |
| 692 | fossil purge artifacts $purgeSecretFile $purgeSecretFile2 -R s6.fossil |
| 693 | test purge-scrub-delta-in-graveyard {[purge_sql "SELECT count(*) |
| 694 | FROM purgeitem a JOIN purgeitem b ON a.srcid=b.piid |
| 695 | WHERE NOT a.isPrivate AND b.isPrivate" s6.fossil] == 1} |
| 696 | fossil scrub --private --force s6.fossil |
| 697 | test purge-scrub-delta {$CODE == 0} |
| 698 | test_eq purge-scrub-delta-private-gone [purge_sql "SELECT count(*) |
| 699 | FROM purgeitem WHERE isPrivate" s6.fossil] 0 |
| 700 | fossil purge cat $purgeSecretFile -R s6.fossil |
| 701 | test_eq purge-scrub-delta-public-kept $RESULT [string trim $purgeSecretText] |
| 702 | |
| 703 | # --verily removes the graveyard too, and the private branch. |
| 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 |
| 717 | |
| 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. |
| 732 | |
| 733 | fossil settings forbid-delta-manifests off |
| 734 | set purgeBase [lindex $purgeTrunk 4] |
| 735 | set purgeDeltaM [purge_commit a.txt "${purgeTrunkText(5)}one more line\n" \ |
| 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 |
+914
| --- a/test/rebuild.test | ||
| +++ b/test/rebuild.test | ||
| @@ -0,0 +1,914 @@ | ||
| 1 | +# | |
| 2 | +# "fossil rebuild" with each of its options, "fossil repack", "fossil | |
| 3 | +# deconstruct" and "fossil reconstruct", "fossil detach", the prompt of | |
| 4 | +# "fossil scrub", and the cluster test commands. None of them may change | |
| 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}} { | |
| 85 | + return [split [rebuild_sql "SELECT uuid FROM blob | |
| 86 | + WHERE size>=0 AND $where ORDER BY uuid" $repo] \n] | |
| 87 | +} | |
| 88 | + | |
| 89 | +# Text of LENGTH characters that has nothing in common with the text for | |
| 90 | +# another SEED, so that neither is stored as a delta of the other. | |
| 91 | +proc rebuild_noise {seed length} { | |
| 92 | + set x [expr {$seed*7919 + 17}] | |
| 93 | + set out "" | |
| 94 | + for {set i 0} {$i < $length} {incr i} { | |
| 95 | + set x [expr {($x*1103515245 + 12345) % 2147483648}] | |
| 96 | + append out [format %c [expr {33 + ($x >> 16) % 90}]] | |
| 97 | + if {$i % 60 == 59} {append out \n} | |
| 98 | + } | |
| 99 | + return "$out\n" | |
| 100 | +} | |
| 101 | + | |
| 102 | +# The files below DIR whose names do not begin with a dot, each as its | |
| 103 | +# path below DIR. | |
| 104 | +proc rebuild_files {dir {below ""}} { | |
| 105 | + set out {} | |
| 106 | + foreach f [lsort [glob -nocomplain -tails -directory \ | |
| 107 | + [file join $dir $below] *]] { | |
| 108 | + if {$below eq ""} {set rel $f} else {set rel $below/$f} | |
| 109 | + if {[file isdirectory [file join $dir $rel]]} { | |
| 110 | + lappend out {*}[rebuild_files $dir $rel] | |
| 111 | + } else { | |
| 112 | + lappend out $rel | |
| 113 | + } | |
| 114 | + } | |
| 115 | + return $out | |
| 116 | +} | |
| 117 | + | |
| 118 | +# The names a deconstruct into DIR gave the artifacts, with the directory | |
| 119 | +# part folded back into the hash, in order. | |
| 120 | +proc rebuild_names {dir} { | |
| 121 | + set out {} | |
| 122 | + foreach f [rebuild_files $dir] { lappend out [string map {/ ""} $f] } | |
| 123 | + return [lsort $out] | |
| 124 | +} | |
| 125 | + | |
| 126 | +############################################################################### | |
| 127 | +# Seven check-ins on trunk. Each has a new version of a.txt, which is | |
| 128 | +# stored as deltas, and a new n.txt that has nothing in common with the | |
| 129 | +# one before. A branch off the third with a file of its own; a tag, a | |
| 130 | +# wiki page and a ticket; and a private branch of two check-ins. | |
| 131 | + | |
| 132 | +fossil settings autosync off | |
| 133 | +set rebuildText "" | |
| 134 | +for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} { | |
| 135 | + append rebuildText "line $rebuildI of a file that is stored as deltas\n" | |
| 136 | +} | |
| 137 | +set rebuildTrunk {} | |
| 138 | +for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} { | |
| 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 | |
| 181 | + | |
| 182 | +############################################################################### | |
| 183 | +# Rebuild with each option, one after another on one copy. Each row is a | |
| 184 | +# name, the options, a pattern the output must match, a query, and the | |
| 185 | +# answer the query must give afterwards. After every one the repository | |
| 186 | +# holds what it held and is sound. | |
| 187 | + | |
| 188 | +file copy full.fossil r.fossil | |
| 189 | +set rebuildCheckins [rebuild_sql "SELECT count(*) FROM event WHERE type='ci'"] | |
| 190 | +foreach {rebuildName rebuildOpts rebuildOut rebuildQuery rebuildWant} [list \ | |
| 191 | + plain {} \ | |
| 192 | + "*100.0% complete*" \ | |
| 193 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 194 | + quiet {--quiet} \ | |
| 195 | + "" \ | |
| 196 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 197 | + cluster {--cluster} \ | |
| 198 | + "*100.0% complete*" \ | |
| 199 | + "SELECT count(*) FROM tagxref WHERE tagid=(SELECT tagid FROM tag | |
| 200 | + WHERE tagname='cluster')" 0 \ | |
| 201 | + noverify {--noverify} \ | |
| 202 | + "*100.0% complete*" \ | |
| 203 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 204 | + force {--force} \ | |
| 205 | + "*100.0% complete*" \ | |
| 206 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 207 | + analyze {--analyze} \ | |
| 208 | + "*Analyzing the database... done*" \ | |
| 209 | + "SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'" 1 \ | |
| 210 | + vacuum {--vacuum} \ | |
| 211 | + "*Vacuuming the database... done*" \ | |
| 212 | + "PRAGMA repository.freelist_count" 0 \ | |
| 213 | + pagesize {--pagesize 8192} \ | |
| 214 | + "*Vacuuming the database... done*" \ | |
| 215 | + "PRAGMA repository.page_size" 8192 \ | |
| 216 | + wal {--wal} \ | |
| 217 | + "*100.0% complete*" \ | |
| 218 | + "PRAGMA repository.journal_mode" wal \ | |
| 219 | + pagesize-in-wal {--pagesize 2048} \ | |
| 220 | + "*Vacuuming the database... done*" \ | |
| 221 | + "PRAGMA repository.page_size; PRAGMA repository.journal_mode" \ | |
| 222 | + "2048\nwal" \ | |
| 223 | + stats {--stats} \ | |
| 224 | + "*Artifacts:*Manifests:*Clusters:*Tags:*Wikis:*Tickets:*Other:*" \ | |
| 225 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 226 | + compress {--compress} \ | |
| 227 | + "*100.0% complete*Extra delta compression... *" \ | |
| 228 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 229 | + compress-only {--compress-only} \ | |
| 230 | + "Extra delta compression... *" \ | |
| 231 | + "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ | |
| 232 | +] { | |
| 233 | + fossil rebuild r.fossil {*}$rebuildOpts | |
| 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. | |
| 246 | +test_eq rebuild-deanalyze-setup [rebuild_sql "SELECT count(*) | |
| 247 | + FROM sqlite_schema WHERE name='sqlite_stat1'" r.fossil] 1 | |
| 248 | +fossil rebuild r.fossil --deanalyze | |
| 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} { | |
| 260 | + manifests Manifests ci | |
| 261 | + tags Tags g | |
| 262 | + wikis Wikis w | |
| 263 | + tickets Tickets t | |
| 264 | +} { | |
| 265 | + set rebuildCount "" | |
| 266 | + regexp -line "^$rebuildLabel: +(\\d+)" $rebuildStats -> rebuildCount | |
| 267 | + test_eq rebuild-stats-$rebuildName $rebuildCount [rebuild_sql "SELECT | |
| 268 | + count(*) FROM event WHERE type='$rebuildType'" full.fossil] | |
| 269 | +} | |
| 270 | + | |
| 271 | +# A page size that is too small, too large, or not a power of two is | |
| 272 | +# refused and nothing is rebuilt. | |
| 273 | +fossil sql -R r.fossil "UPDATE config SET mtime=1 WHERE name='rebuilt'" | |
| 274 | +foreach rebuildSize {256 131072 1000 abc} { | |
| 275 | + fossil rebuild r.fossil --pagesize $rebuildSize -expectError | |
| 276 | + test rebuild-pagesize-$rebuildSize-refused {$CODE != 0 && | |
| 277 | + [string match "*page size must be a power of two*" $RESULT]} | |
| 278 | +} | |
| 279 | +test_eq rebuild-pagesize-refused-unchanged [rebuild_sql "PRAGMA | |
| 280 | + repository.page_size; SELECT mtime FROM config WHERE name='rebuilt'" \ | |
| 281 | + r.fossil] "2048\n1" | |
| 282 | + | |
| 283 | +# --ifneeded does nothing when the schema is the current one, and | |
| 284 | +# rebuilds when the repository says it has an older one. | |
| 285 | +set rebuildSchema [rebuild_sql "SELECT value FROM config | |
| 286 | + WHERE name='aux-schema'" r.fossil] | |
| 287 | +fossil rebuild r.fossil --ifneeded | |
| 288 | +test rebuild-ifneeded-not-needed {$CODE == 0 && $RESULT eq ""} | |
| 289 | +test_eq rebuild-ifneeded-not-needed-untouched [rebuild_sql "SELECT mtime | |
| 290 | + FROM config WHERE name='rebuilt'" r.fossil] 1 | |
| 291 | +fossil sql -R r.fossil "UPDATE config SET value='2011-04-25 19:50' | |
| 292 | + WHERE name='aux-schema'" | |
| 293 | +fossil rebuild r.fossil --ifneeded | |
| 294 | +test rebuild-ifneeded-needed {$CODE == 0 && | |
| 295 | + [string match "*100.0% complete*" $RESULT]} | |
| 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 | |
| 315 | +# (before 2011-04-27), no jx in user and reportfmt, and a blob table that | |
| 316 | +# takes only hashes of 40 characters (before 2.0). It is made from a new | |
| 317 | +# one by dropping the columns and editing the stored definition with SQL. | |
| 318 | +# Rebuild brings every table up to date and loses none of their rows. | |
| 319 | + | |
| 320 | +file copy full.fossil old.fossil | |
| 321 | +fossil sql -R old.fossil " | |
| 322 | + INSERT INTO concealed(hash,content,mtime) | |
| 323 | + VALUES('abc','[email protected]',1); | |
| 324 | + INSERT INTO shun(uuid,mtime,scom) | |
| 325 | + VALUES('[string repeat b 64]',1,'a reason'); | |
| 326 | + ALTER TABLE plink DROP COLUMN baseid; | |
| 327 | + DROP INDEX mlink_i4; | |
| 328 | + ALTER TABLE mlink DROP COLUMN isaux; | |
| 329 | + ALTER TABLE mlink DROP COLUMN pmid; | |
| 330 | + ALTER TABLE user DROP COLUMN jx; | |
| 331 | + ALTER TABLE user DROP COLUMN mtime; | |
| 332 | + ALTER TABLE shun DROP COLUMN mtime; | |
| 333 | + ALTER TABLE shun DROP COLUMN scom; | |
| 334 | + ALTER TABLE reportfmt DROP COLUMN jx; | |
| 335 | + ALTER TABLE reportfmt DROP COLUMN mtime; | |
| 336 | + ALTER TABLE concealed DROP COLUMN mtime; | |
| 337 | + ALTER TABLE config DROP COLUMN mtime; | |
| 338 | +" | |
| 339 | +fossil sql -R old.fossil ".dbconfig defensive off" \ | |
| 340 | + "PRAGMA writable_schema=ON" \ | |
| 341 | + "UPDATE repository.sqlite_schema | |
| 342 | + SET sql=replace(sql,'length(uuid)>=40','length(uuid)==40') | |
| 343 | + WHERE name='blob'" \ | |
| 344 | + "PRAGMA writable_schema=OFF" | |
| 345 | +proc rebuild_columns {repo} { | |
| 346 | + return [rebuild_sql " | |
| 347 | + SELECT group_concat(m.name || '.' || p.name, ' ') FROM ( | |
| 348 | + SELECT 'plink' AS name UNION ALL SELECT 'mlink' UNION ALL | |
| 349 | + SELECT 'user' UNION ALL SELECT 'config' UNION ALL SELECT 'shun' | |
| 350 | + UNION ALL SELECT 'reportfmt' UNION ALL SELECT 'concealed') AS m, | |
| 351 | + pragma_table_info(m.name, 'repository') AS p | |
| 352 | + WHERE m.name || '.' || p.name IN ('plink.baseid', 'mlink.pmid', | |
| 353 | + 'mlink.isaux', 'user.mtime', 'user.jx', 'config.mtime', | |
| 354 | + 'shun.mtime', 'shun.scom', 'reportfmt.mtime', 'reportfmt.jx', | |
| 355 | + 'concealed.mtime')" $repo] | |
| 356 | +} | |
| 357 | +proc rebuild_blob_check {repo} { | |
| 358 | + return [rebuild_sql "SELECT sql LIKE '%length(uuid)>=40%' | |
| 359 | + FROM repository.sqlite_schema WHERE name='blob'" $repo] | |
| 360 | +} | |
| 361 | +test_eq rebuild-old-schema-setup-columns [rebuild_columns old.fossil] "" | |
| 362 | +test_eq rebuild-old-schema-setup-blob [rebuild_blob_check old.fossil] 0 | |
| 363 | +set rebuildUsers [rebuild_sql "SELECT group_concat(login || '/' || cap, ' ') | |
| 364 | + FROM (SELECT login, cap FROM user ORDER BY login)" full.fossil] | |
| 365 | +set rebuildCode [rebuild_sql "SELECT value FROM config | |
| 366 | + WHERE name='project-code'" full.fossil] | |
| 367 | +set rebuildReports [rebuild_sql "SELECT group_concat(title, '|') | |
| 368 | + FROM (SELECT title FROM reportfmt ORDER BY rn)" full.fossil] | |
| 369 | +fossil rebuild old.fossil | |
| 370 | +test rebuild-old-schema {$CODE == 0} | |
| 371 | +test_eq rebuild-old-schema-columns [lsort [rebuild_columns old.fossil]] \ | |
| 372 | + [lsort [rebuild_columns full.fossil]] | |
| 373 | +test_eq rebuild-old-schema-blob [rebuild_blob_check old.fossil] 1 | |
| 374 | +test_eq rebuild-old-schema-users [rebuild_sql "SELECT group_concat(login | |
| 375 | + || '/' || cap, ' ') FROM (SELECT login, cap FROM user ORDER BY login)" \ | |
| 376 | + old.fossil] $rebuildUsers | |
| 377 | +test_eq rebuild-old-schema-users-dated [rebuild_sql "SELECT count(*) FROM user | |
| 378 | + WHERE mtime IS NULL" old.fossil] 0 | |
| 379 | +test_eq rebuild-old-schema-config [rebuild_sql "SELECT value, mtime>1 | |
| 380 | + FROM config WHERE name='project-code'" old.fossil] "$rebuildCode|1" | |
| 381 | +test_eq rebuild-old-schema-shun [rebuild_sql "SELECT uuid, mtime>1 FROM shun" \ | |
| 382 | + old.fossil] "[string repeat b 64]|1" | |
| 383 | +test_eq rebuild-old-schema-reports [rebuild_sql "SELECT group_concat(title, '|') | |
| 384 | + FROM (SELECT title FROM reportfmt ORDER BY rn)" old.fossil] $rebuildReports | |
| 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 | + | |
| 397 | +file copy full.fossil main.fossil | |
| 398 | +fossil sql -R main.fossil "REPLACE INTO config(name,value,mtime) | |
| 399 | + VALUES('main-branch','primary',now())" | |
| 400 | +set rebuildRoot [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid | |
| 401 | + FROM plink AS x WHERE NOT EXISTS(SELECT 1 FROM plink | |
| 402 | + WHERE cid=x.pid))" main.fossil] | |
| 403 | +fossil rebuild main.fossil | |
| 404 | +test rebuild-main-branch {$CODE == 0} | |
| 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 | |
| 420 | + | |
| 421 | +############################################################################### | |
| 422 | +# Rebuild of a repository damaged with SQL: an artifact stored as a delta | |
| 423 | +# whose own row is gone, or has become a phantom. The rebuild finishes, | |
| 424 | +# every check-in is still in the timeline, and the artifact is listed as | |
| 425 | +# a phantom. | |
| 426 | + | |
| 427 | +set rebuildDeltaFile "(SELECT delta.rid FROM delta JOIN mlink | |
| 428 | + ON mlink.fid=delta.rid JOIN filename USING(fnid) | |
| 429 | + WHERE name='a.txt' ORDER BY delta.rid LIMIT 1)" | |
| 430 | +foreach {rebuildName rebuildDamage} [list \ | |
| 431 | + delta-row-gone \ | |
| 432 | + "DELETE FROM blob WHERE rid=$rebuildDeltaFile" \ | |
| 433 | + delta-is-a-phantom \ | |
| 434 | + "UPDATE blob SET size=-1, content=NULL WHERE rid=$rebuildDeltaFile" \ | |
| 435 | +] { | |
| 436 | + file copy -force full.fossil damaged.fossil | |
| 437 | + fossil sql -R damaged.fossil $rebuildDamage | |
| 438 | + fossil rebuild damaged.fossil | |
| 439 | + test rebuild-damage-$rebuildName {$CODE == 0} | |
| 440 | + test_eq rebuild-damage-$rebuildName-checkins [rebuild_sql "SELECT count(*) | |
| 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; | |
| 452 | +# --noindex leaves it out; --index adds one; --compress-only leaves it | |
| 453 | +# alone. | |
| 454 | + | |
| 455 | +file copy full.fossil fts.fossil | |
| 456 | +proc rebuild_indexed {repo} { | |
| 457 | + if {[rebuild_sql "SELECT count(*) FROM sqlite_schema | |
| 458 | + WHERE name='ftsdocs'" $repo] == 0} {return none} | |
| 459 | + return [rebuild_sql "SELECT count(*) FROM ftsdocs" $repo] | |
| 460 | +} | |
| 461 | +test_eq rebuild-index-setup-none [rebuild_indexed fts.fossil] none | |
| 462 | +fossil rebuild fts.fossil --index | |
| 463 | +test rebuild-index {$CODE == 0} | |
| 464 | +set rebuildDocs [rebuild_indexed fts.fossil] | |
| 465 | +test rebuild-index-made {$rebuildDocs ne "none"} | |
| 466 | +fossil fts-config enable cdtwe -R fts.fossil | |
| 467 | +fossil rebuild fts.fossil | |
| 468 | +test rebuild-index-kept {$CODE == 0} | |
| 469 | +set rebuildDocs [rebuild_indexed fts.fossil] | |
| 470 | +test rebuild-index-kept-filled {$rebuildDocs ne "none" && $rebuildDocs > 0} | |
| 471 | +fossil sql -R fts.fossil "DELETE FROM ftsdocs" | |
| 472 | +fossil rebuild fts.fossil --compress-only | |
| 473 | +test rebuild-index-compress-only {$CODE == 0} | |
| 474 | +test_eq rebuild-index-compress-only-untouched [rebuild_indexed fts.fossil] 0 | |
| 475 | +fossil rebuild fts.fossil | |
| 476 | +test_eq rebuild-index-refilled [rebuild_indexed fts.fossil] $rebuildDocs | |
| 477 | +fossil search rebuild-side-1 -R fts.fossil | |
| 478 | +test rebuild-index-search {[string match "*rebuild-side-1*" $RESULT]} | |
| 479 | +# --compress-only with --index, when there is an index already, builds it | |
| 480 | +# again. | |
| 481 | +fossil sql -R fts.fossil "DELETE FROM ftsdocs" | |
| 482 | +fossil rebuild fts.fossil --compress-only --index | |
| 483 | +test rebuild-index-compress-only-index {$CODE == 0} | |
| 484 | +test_eq rebuild-index-compress-only-index-filled \ | |
| 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 | + | |
| 496 | +############################################################################### | |
| 497 | +# Extra compression. "fossil repack" and "rebuild --compress-only" store | |
| 498 | +# more artifacts as deltas and say how many; what the artifacts are does | |
| 499 | +# not change. One or two file versions are stored whole again before | |
| 500 | +# each run, so that there is that much to find. | |
| 501 | + | |
| 502 | +fossil repack r.fossil full.fossil -expectError | |
| 503 | +test rebuild-repack-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]} | |
| 504 | +fossil repack | |
| 505 | +test rebuild-repack-checkout {$CODE == 0} | |
| 506 | +fossil repack | |
| 507 | +test rebuild-repack-nothing {$CODE == 0 && | |
| 508 | + [string match "*no new compression opportunities found*" $RESULT] && | |
| 509 | + ![string match "*Vacuuming*" $RESULT]} | |
| 510 | +fossil rebuild --compress | |
| 511 | +test rebuild-compress-nothing {$CODE == 0 && | |
| 512 | + [string match "*Extra delta compression... none found*" $RESULT]} | |
| 513 | +proc rebuild_store_whole {count} { | |
| 514 | + foreach rid [split [rebuild_sql "SELECT delta.rid FROM delta JOIN mlink | |
| 515 | + ON mlink.fid=delta.rid JOIN filename USING(fnid) | |
| 516 | + WHERE name='a.txt' GROUP BY delta.rid ORDER BY delta.rid | |
| 517 | + LIMIT $count"] \n] { | |
| 518 | + fossil test-content-undelta $rid | |
| 519 | + } | |
| 520 | +} | |
| 521 | +foreach {rebuildName rebuildCmd rebuildCount rebuildOut} { | |
| 522 | + repack-one {repack} 1 "*1 new delta saves *Vacuuming*" | |
| 523 | + repack-two {repack} 2 "*2 new deltas save *Vacuuming*" | |
| 524 | + compress-one {rebuild --compress-only} 1 "*1 new delta saves *Vacuuming*" | |
| 525 | + compress-two {rebuild --compress-only} 2 "*2 new deltas save *Vacuuming*" | |
| 526 | +} { | |
| 527 | + set rebuildDeltas [rebuild_sql "SELECT count(*) FROM delta"] | |
| 528 | + rebuild_store_whole $rebuildCount | |
| 529 | + test_eq rebuild-$rebuildName-setup [rebuild_sql "SELECT count(*) | |
| 530 | + FROM delta"] [expr {$rebuildDeltas - $rebuildCount}] | |
| 531 | + fossil {*}$rebuildCmd | |
| 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] | |
| 544 | +} | |
| 545 | + | |
| 546 | +############################################################################### | |
| 547 | +# Detach asks first. "n" changes nothing; a capital Y is a yes. | |
| 548 | + | |
| 549 | +file copy full.fossil detach.fossil | |
| 550 | +fossil_raw -input "n\n" detach detach.fossil | |
| 551 | +test rebuild-detach-declined {$CODE == 0} | |
| 552 | +test_eq rebuild-detach-declined-same-code [rebuild_sql "SELECT value | |
| 553 | + FROM config WHERE name='project-code'" detach.fossil] $rebuildCode | |
| 554 | +fossil_raw -input "Y\n" detach detach.fossil | |
| 555 | +test rebuild-detach-capital {$CODE == 0 && | |
| 556 | + [string match "*New project code: *" $RESULT]} | |
| 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. | |
| 585 | + | |
| 586 | +file mkdir d-public | |
| 587 | +fossil deconstruct -R full.fossil d-public | |
| 588 | +test rebuild-deconstruct {$CODE == 0} | |
| 589 | +test_eq rebuild-deconstruct-public-only [rebuild_names d-public] $rebuildPublic | |
| 590 | +test rebuild-deconstruct-two-letter-directories {[lsearch -not -regexp \ | |
| 591 | + [rebuild_files d-public] {^[0-9a-f]{2}/[0-9a-f]+$}] < 0} | |
| 592 | +test_eq rebuild-deconstruct-no-lists \ | |
| 593 | + [glob -nocomplain -directory d-public .rid1 .private] "" | |
| 594 | +fossil artifact [lindex $rebuildTrunk 0] -R full.fossil one.txt | |
| 595 | +test rebuild-deconstruct-content {[same_file one.txt [file join d-public \ | |
| 596 | + [string range [lindex $rebuildTrunk 0] 0 1] \ | |
| 597 | + [string range [lindex $rebuildTrunk 0] 2 end]]]} | |
| 598 | +fossil reconstruct r-public.fossil d-public | |
| 599 | +test rebuild-reconstruct {$CODE == 0 && | |
| 600 | + [string match "*project-id: *server-id: *admin-user: *" $RESULT]} | |
| 601 | +test_eq rebuild-reconstruct-artifacts [rebuild_hashes r-public.fossil] \ | |
| 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 ""} | |
| 613 | +test_eq rebuild-deconstruct-quiet-files [rebuild_names d-quiet] $rebuildPublic | |
| 614 | + | |
| 615 | +# --private writes the private artifacts too. A repository made from the | |
| 616 | +# files has them all, and none is private. | |
| 617 | +file mkdir d-private | |
| 618 | +fossil deconstruct -R full.fossil d-private --private | |
| 619 | +test rebuild-deconstruct-private {$CODE == 0} | |
| 620 | +test_eq rebuild-deconstruct-private-all [rebuild_names d-private] $rebuildAll | |
| 621 | +test_eq rebuild-deconstruct-private-no-lists \ | |
| 622 | + [glob -nocomplain -directory d-private .rid1 .private] "" | |
| 623 | + | |
| 624 | +# -P writes them and lists them in .private; -K names the file of the | |
| 625 | +# first artifact in .rid1. Reconstruct with -P and -K reads both lists: | |
| 626 | +# the same artifacts are private, the first artifact is the first again, | |
| 627 | +# and everything else is as it was. An empty line, a comment and a line | |
| 628 | +# that is not a hash are added to the lists first, and are passed over. | |
| 629 | +file mkdir d-keep | |
| 630 | +fossil deconstruct -R full.fossil d-keep -P -K | |
| 631 | +test rebuild-deconstruct-keep {$CODE == 0} | |
| 632 | +test_eq rebuild-deconstruct-keep-all [rebuild_names d-keep] $rebuildAll | |
| 633 | +set rebuildFirst [rebuild_sql "SELECT uuid FROM blob WHERE rid=1" full.fossil] | |
| 634 | +test_eq rebuild-deconstruct-keep-rid1 \ | |
| 635 | + [lindex [split [string trim [read_file d-keep/.rid1]] \n] end] \ | |
| 636 | + "[string range $rebuildFirst 0 1]/[string range $rebuildFirst 2 end]" | |
| 637 | +set rebuildPrivate [rebuild_hashes full.fossil "rid IN private"] | |
| 638 | +test_eq rebuild-deconstruct-keep-private [lsort [lrange [split \ | |
| 639 | + [string trim [read_file d-keep/.private]] \n] 1 end]] $rebuildPrivate | |
| 640 | +write_file d-keep/.private \ | |
| 641 | + "\n# one more comment\nnot-a-hash\n[read_file d-keep/.private]" | |
| 642 | +write_file d-keep/.rid1 "\n[read_file d-keep/.rid1]" | |
| 643 | +fossil reconstruct r-keep.fossil d-keep -K -P | |
| 644 | +test rebuild-reconstruct-keep {$CODE == 0} | |
| 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 | |
| 669 | +test rebuild-deconstruct-flat {$CODE == 0} | |
| 670 | +test_eq rebuild-deconstruct-flat-files [rebuild_files d-flat] $rebuildPublic | |
| 671 | +test_eq rebuild-deconstruct-flat-rid1 \ | |
| 672 | + [lindex [split [string trim [read_file d-flat/.rid1]] \n] end] \ | |
| 673 | + $rebuildFirst | |
| 674 | +fossil reconstruct r-flat.fossil d-flat -K | |
| 675 | +test rebuild-reconstruct-flat {$CODE == 0} | |
| 676 | +test_eq rebuild-reconstruct-flat-artifacts [rebuild_hashes r-flat.fossil] \ | |
| 677 | + $rebuildPublic | |
| 678 | +test_eq rebuild-reconstruct-flat-rid1 [rebuild_sql "SELECT uuid FROM blob | |
| 679 | + WHERE rid=1" r-flat.fossil] $rebuildFirst | |
| 680 | +fossil deconstruct -R full.fossil d-five --prefixlength 5 | |
| 681 | +test rebuild-deconstruct-five {$CODE == 0} | |
| 682 | +test_eq rebuild-deconstruct-five-names [rebuild_names d-five] $rebuildPublic | |
| 683 | +test rebuild-deconstruct-five-directories {[lsearch -not -regexp \ | |
| 684 | + [rebuild_files d-five] {^[0-9a-f]{5}/[0-9a-f]+$}] < 0} | |
| 685 | + | |
| 686 | +# What deconstruct refuses: a prefix length that is not one digit, no | |
| 687 | +# destination or two, and a destination that is empty or missing. | |
| 688 | +file mkdir d-none | |
| 689 | +foreach {rebuildName rebuildArgs rebuildOut} { | |
| 690 | + prefix-below-digits {d-none -L /} "*not a valid prefix length*" | |
| 691 | + prefix-letter {d-none -L x} "*not a valid prefix length*" | |
| 692 | + prefix-two-digits {d-none -L 10} "*not a valid prefix length*" | |
| 693 | + no-destination {} "*Usage:*" | |
| 694 | + two-destinations {d-none d-flat} "*Usage:*" | |
| 695 | + empty-destination {{}} "*is not a directory*" | |
| 696 | + missing-destination {d-missing} "*is not a directory*" | |
| 697 | +} { | |
| 698 | + fossil deconstruct -R full.fossil {*}$rebuildArgs -expectError | |
| 699 | + test rebuild-deconstruct-$rebuildName {$CODE != 0 && | |
| 700 | + [string match $rebuildOut $RESULT]} | |
| 701 | +} | |
| 702 | +test_eq rebuild-deconstruct-refused-wrote-nothing [rebuild_files d-none] "" | |
| 703 | + | |
| 704 | +# A destination that is a file is refused, and the file is kept. | |
| 705 | +write_file d-file.txt "a file, not a directory\n" | |
| 706 | +fossil deconstruct -R full.fossil d-file.txt -expectError | |
| 707 | +test rebuild-deconstruct-file-destination {$CODE != 0 && | |
| 708 | + [string match "*is not a directory*" $RESULT]} | |
| 709 | +test rebuild-deconstruct-file-destination-kept \ | |
| 710 | + {[file isfile d-file.txt]} | |
| 711 | + | |
| 712 | +# A destination that cannot be written to, where the system can make one. | |
| 713 | +catch {file attributes d-none -permissions 0555} | |
| 714 | +if {![file writable d-none]} { | |
| 715 | + fossil deconstruct -R full.fossil d-none -expectError | |
| 716 | + test rebuild-deconstruct-not-writable {$CODE != 0 && | |
| 717 | + [string match "*is not writeable*" $RESULT]} | |
| 718 | +} | |
| 719 | +catch {file attributes d-none -permissions 0755} | |
| 720 | + | |
| 721 | +# What reconstruct refuses: too few names, and a directory that is not one. | |
| 722 | +fossil reconstruct r-none.fossil -expectError | |
| 723 | +test rebuild-reconstruct-usage {$CODE != 0 && | |
| 724 | + [string match "*Usage:*" $RESULT]} | |
| 725 | +fossil reconstruct r-none.fossil one.txt -expectError | |
| 726 | +test rebuild-reconstruct-not-a-directory {$CODE != 0 && | |
| 727 | + [string match "*is not a directory*Usage:*" $RESULT]} | |
| 728 | +test rebuild-reconstruct-refused-made-nothing {![file exists r-none.fossil]} | |
| 729 | + | |
| 730 | +# -K when .rid1 names no file, and when there is no .rid1. | |
| 731 | +write_file d-flat/.rid1 "# nothing but a comment\n\n" | |
| 732 | +fossil reconstruct r-rid1-empty.fossil d-flat -K -expectError | |
| 733 | +test rebuild-reconstruct-rid1-empty {$CODE != 0 && | |
| 734 | + [string match "*error occurred while reading or parsing*" $RESULT]} | |
| 735 | +file delete d-flat/.rid1 | |
| 736 | +fossil reconstruct r-rid1-missing.fossil d-flat -K -expectError | |
| 737 | +test rebuild-reconstruct-rid1-missing {$CODE != 0 && | |
| 738 | + [string match "*no such file*" $RESULT]} | |
| 739 | + | |
| 740 | +# A directory below that cannot be read, where the system can make one. | |
| 741 | +file mkdir d-five/locked | |
| 742 | +write_file d-five/locked/file.txt "out of reach\n" | |
| 743 | +catch {file attributes d-five/locked -permissions 0000} | |
| 744 | +if {![file readable d-five/locked]} { | |
| 745 | + fossil reconstruct r-locked.fossil d-five -expectError | |
| 746 | + test rebuild-reconstruct-unreadable-directory {$CODE != 0 && | |
| 747 | + [string match "*encountered error*while trying to open*" $RESULT]} | |
| 748 | +} | |
| 749 | +catch {file attributes d-five/locked -permissions 0755} | |
| 750 | + | |
| 751 | +############################################################################### | |
| 752 | +# Artifacts named by SHA1. Reconstruct stores each file under the kind | |
| 753 | +# of hash its name has; a file whose name is no hash is stored as well. | |
| 754 | + | |
| 755 | +fossil init --sha1 sha1.fossil | |
| 756 | +write_file sha1-content.txt "content stored under a SHA1 hash\n" | |
| 757 | +fossil test-content-put sha1-content.txt -R sha1.fossil | |
| 758 | +set rebuildSha1 [rebuild_hashes sha1.fossil] | |
| 759 | +test rebuild-sha1-setup {[llength $rebuildSha1] >= 2 && | |
| 760 | + [lsearch -not -regexp $rebuildSha1 {^[0-9a-f]{40}$}] < 0} | |
| 761 | +file mkdir d-sha1 | |
| 762 | +fossil deconstruct -R sha1.fossil d-sha1 | |
| 763 | +test_eq rebuild-sha1-deconstruct [rebuild_names d-sha1] $rebuildSha1 | |
| 764 | +write_file d-sha1/notes "a file whose name is not a hash\n" | |
| 765 | +fossil sha1sum d-sha1/notes | |
| 766 | +set rebuildNote1 [lindex $RESULT 0] | |
| 767 | +fossil sha3sum d-sha1/notes | |
| 768 | +set rebuildNote3 [lindex $RESULT 0] | |
| 769 | +fossil reconstruct r-sha1.fossil d-sha1 | |
| 770 | +test rebuild-sha1-reconstruct {$CODE == 0} | |
| 771 | +test_eq rebuild-sha1-reconstruct-same-hashes [rebuild_hashes r-sha1.fossil \ | |
| 772 | + "length(uuid)=40 AND uuid<>'$rebuildNote1'"] $rebuildSha1 | |
| 773 | +test_eq rebuild-sha1-reconstruct-other-file [rebuild_sql "SELECT count(*) | |
| 774 | + FROM blob WHERE uuid IN ('$rebuildNote1','$rebuildNote3')" r-sha1.fossil] 1 | |
| 775 | +test_eq rebuild-sha1-reconstruct-count [llength [rebuild_hashes \ | |
| 776 | + r-sha1.fossil]] [expr {[llength $rebuildSha1] + 1}] | |
| 777 | + | |
| 778 | +############################################################################### | |
| 779 | +# Deconstruct of repositories that lack content. | |
| 780 | + | |
| 781 | +# A check-in whose parent and files are not there: they are phantoms, and | |
| 782 | +# only what has content is written. | |
| 783 | +fossil init phantom.fossil | |
| 784 | +fossil artifact $rebuildSide -R full.fossil side.txt | |
| 785 | +fossil test-content-put --crosslink side.txt -R phantom.fossil | |
| 786 | +test rebuild-phantom-setup {[rebuild_sql "SELECT count(*) FROM phantom" \ | |
| 787 | + phantom.fossil] > 0} | |
| 788 | +file mkdir d-phantom | |
| 789 | +fossil deconstruct -R phantom.fossil d-phantom | |
| 790 | +test rebuild-deconstruct-phantom {$CODE == 0} | |
| 791 | +test_eq rebuild-deconstruct-phantom-files [rebuild_names d-phantom] \ | |
| 792 | + [rebuild_hashes phantom.fossil] | |
| 793 | +test rebuild-deconstruct-phantom-has-checkin \ | |
| 794 | + {[lsearch -exact [rebuild_names d-phantom] $rebuildSide] >= 0} | |
| 795 | + | |
| 796 | +# A public artifact stored as a delta from a private one, which "fossil | |
| 797 | +# publish" of the older of two private check-ins leaves. Without | |
| 798 | +# --private the public one is written and the private one is not. | |
| 799 | +file copy full.fossil publish.fossil | |
| 800 | +fossil publish $rebuildSecret1 -R publish.fossil | |
| 801 | +test rebuild-public-from-private-setup {[rebuild_sql "SELECT count(*) | |
| 802 | + FROM delta | |
| 803 | + WHERE rid=(SELECT rid FROM blob WHERE uuid='$rebuildSecretFile1') | |
| 804 | + AND srcid=(SELECT rid FROM blob WHERE uuid='$rebuildSecretFile2') | |
| 805 | + AND rid NOT IN private AND srcid IN private" publish.fossil] == 1} | |
| 806 | +file mkdir d-publish | |
| 807 | +fossil deconstruct -R publish.fossil d-publish | |
| 808 | +test rebuild-deconstruct-public-from-private {$CODE == 0} | |
| 809 | +test_eq rebuild-deconstruct-public-from-private-files \ | |
| 810 | + [rebuild_names d-publish] \ | |
| 811 | + [rebuild_hashes publish.fossil "rid NOT IN private"] | |
| 812 | +test rebuild-deconstruct-public-from-private-written \ | |
| 813 | + {[lsearch -exact [rebuild_names d-publish] $rebuildSecretFile1] >= 0 && | |
| 814 | + [lsearch -exact [rebuild_names d-publish] $rebuildSecretFile2] < 0} | |
| 815 | + | |
| 816 | +# A repository damaged with SQL: the artifact that others are deltas of | |
| 817 | +# is gone. Deconstruct finishes; it writes what can still be read and | |
| 818 | +# nothing for what cannot. | |
| 819 | +file copy full.fossil damaged.fossil | |
| 820 | +set rebuildSource [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT srcid | |
| 821 | + FROM delta JOIN mlink ON mlink.fid=delta.rid JOIN filename USING(fnid) | |
| 822 | + WHERE name='a.txt' AND srcid NOT IN (SELECT rid FROM delta))" \ | |
| 823 | + damaged.fossil] | |
| 824 | +set rebuildLost [rebuild_sql "WITH RECURSIVE lost(rid) AS ( | |
| 825 | + SELECT rid FROM blob WHERE uuid='$rebuildSource' | |
| 826 | + UNION SELECT delta.rid FROM delta, lost WHERE delta.srcid=lost.rid) | |
| 827 | + SELECT group_concat(uuid, ' ') FROM blob WHERE rid IN lost" \ | |
| 828 | + damaged.fossil] | |
| 829 | +test rebuild-damage-source-setup {[llength $rebuildLost] > 1} | |
| 830 | +fossil sql -R damaged.fossil "DELETE FROM blob WHERE uuid='$rebuildSource'" | |
| 831 | +file mkdir d-damaged | |
| 832 | +fossil deconstruct -R damaged.fossil d-damaged | |
| 833 | +test rebuild-deconstruct-damage-source-gone {$CODE == 0} | |
| 834 | +set rebuildWant {} | |
| 835 | +foreach rebuildH $rebuildPublic { | |
| 836 | + if {[lsearch -exact $rebuildLost $rebuildH] < 0} { | |
| 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. | |
| 848 | + | |
| 849 | +proc rebuild_clusters {{repo .rep.fossil}} { | |
| 850 | + return [rebuild_sql "SELECT count(*) FROM tagxref WHERE tagid=(SELECT tagid | |
| 851 | + FROM tag WHERE tagname='cluster')" $repo] | |
| 852 | +} | |
| 853 | +proc rebuild_many_files {dir} { | |
| 854 | + file mkdir $dir | |
| 855 | + for {set i 0} {$i < 110} {incr i} { | |
| 856 | + write_file $dir/f$i.txt "file $i in $dir\n" | |
| 857 | + } | |
| 858 | + fossil add $dir | |
| 859 | + fossil commit -m rebuild-$dir --no-warnings | |
| 860 | +} | |
| 861 | +fossil test-create-clusters r.fossil full.fossil -expectError | |
| 862 | +test rebuild-create-clusters-usage {$CODE != 0 && | |
| 863 | + [string match "*Usage:*" $RESULT]} | |
| 864 | +fossil test-create-clusters | |
| 865 | +test rebuild-create-clusters-too-few {$CODE == 0} | |
| 866 | +test_eq rebuild-create-clusters-too-few-none [rebuild_clusters] 0 | |
| 867 | +fossil test-clusters | |
| 868 | +test rebuild-clusters-none {$CODE == 0 && | |
| 869 | + [string match "*all artifacts reachable through clusters*" $RESULT]} | |
| 870 | +rebuild_many_files many1 | |
| 871 | +fossil test-create-clusters .rep.fossil | |
| 872 | +test rebuild-create-clusters {$CODE == 0} | |
| 873 | +test_eq rebuild-create-clusters-one [rebuild_clusters] 1 | |
| 874 | +test_eq rebuild-create-clusters-one-left [rebuild_sql "SELECT count(*) | |
| 875 | + FROM unclustered"] 1 | |
| 876 | +fossil test-clusters | |
| 877 | +test rebuild-clusters-one {$CODE == 0 && | |
| 878 | + [string match "*all artifacts reachable through clusters*" $RESULT]} | |
| 879 | +# A second cluster lists the first. | |
| 880 | +rebuild_many_files many2 | |
| 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 | |
| 892 | + WHERE tagname='cluster'))"] | |
| 893 | +file copy .rep.fossil cluster.fossil | |
| 894 | +fossil purge artifacts $rebuildNewest -R cluster.fossil | |
| 895 | +fossil test-clusters -R cluster.fossil | |
| 896 | +set rebuildCount 0 | |
| 897 | +regexp {(\d+) unreachable artifacts:} $RESULT -> rebuildCount | |
| 898 | +test rebuild-clusters-unreachable {$CODE == 0 && $rebuildCount > 100} | |
| 899 | +test_eq rebuild-clusters-unreachable-listed \ | |
| 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 |
| --- a/test/rebuild.test | |
| +++ b/test/rebuild.test | |
| @@ -0,0 +1,914 @@ | |
| --- a/test/rebuild.test | |
| +++ b/test/rebuild.test | |
| @@ -0,0 +1,914 @@ | |
| 1 | # |
| 2 | # "fossil rebuild" with each of its options, "fossil repack", "fossil |
| 3 | # deconstruct" and "fossil reconstruct", "fossil detach", the prompt of |
| 4 | # "fossil scrub", and the cluster test commands. None of them may change |
| 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}} { |
| 85 | return [split [rebuild_sql "SELECT uuid FROM blob |
| 86 | WHERE size>=0 AND $where ORDER BY uuid" $repo] \n] |
| 87 | } |
| 88 | |
| 89 | # Text of LENGTH characters that has nothing in common with the text for |
| 90 | # another SEED, so that neither is stored as a delta of the other. |
| 91 | proc rebuild_noise {seed length} { |
| 92 | set x [expr {$seed*7919 + 17}] |
| 93 | set out "" |
| 94 | for {set i 0} {$i < $length} {incr i} { |
| 95 | set x [expr {($x*1103515245 + 12345) % 2147483648}] |
| 96 | append out [format %c [expr {33 + ($x >> 16) % 90}]] |
| 97 | if {$i % 60 == 59} {append out \n} |
| 98 | } |
| 99 | return "$out\n" |
| 100 | } |
| 101 | |
| 102 | # The files below DIR whose names do not begin with a dot, each as its |
| 103 | # path below DIR. |
| 104 | proc rebuild_files {dir {below ""}} { |
| 105 | set out {} |
| 106 | foreach f [lsort [glob -nocomplain -tails -directory \ |
| 107 | [file join $dir $below] *]] { |
| 108 | if {$below eq ""} {set rel $f} else {set rel $below/$f} |
| 109 | if {[file isdirectory [file join $dir $rel]]} { |
| 110 | lappend out {*}[rebuild_files $dir $rel] |
| 111 | } else { |
| 112 | lappend out $rel |
| 113 | } |
| 114 | } |
| 115 | return $out |
| 116 | } |
| 117 | |
| 118 | # The names a deconstruct into DIR gave the artifacts, with the directory |
| 119 | # part folded back into the hash, in order. |
| 120 | proc rebuild_names {dir} { |
| 121 | set out {} |
| 122 | foreach f [rebuild_files $dir] { lappend out [string map {/ ""} $f] } |
| 123 | return [lsort $out] |
| 124 | } |
| 125 | |
| 126 | ############################################################################### |
| 127 | # Seven check-ins on trunk. Each has a new version of a.txt, which is |
| 128 | # stored as deltas, and a new n.txt that has nothing in common with the |
| 129 | # one before. A branch off the third with a file of its own; a tag, a |
| 130 | # wiki page and a ticket; and a private branch of two check-ins. |
| 131 | |
| 132 | fossil settings autosync off |
| 133 | set rebuildText "" |
| 134 | for {set rebuildI 0} {$rebuildI < 60} {incr rebuildI} { |
| 135 | append rebuildText "line $rebuildI of a file that is stored as deltas\n" |
| 136 | } |
| 137 | set rebuildTrunk {} |
| 138 | for {set rebuildI 1} {$rebuildI <= 7} {incr rebuildI} { |
| 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 |
| 181 | |
| 182 | ############################################################################### |
| 183 | # Rebuild with each option, one after another on one copy. Each row is a |
| 184 | # name, the options, a pattern the output must match, a query, and the |
| 185 | # answer the query must give afterwards. After every one the repository |
| 186 | # holds what it held and is sound. |
| 187 | |
| 188 | file copy full.fossil r.fossil |
| 189 | set rebuildCheckins [rebuild_sql "SELECT count(*) FROM event WHERE type='ci'"] |
| 190 | foreach {rebuildName rebuildOpts rebuildOut rebuildQuery rebuildWant} [list \ |
| 191 | plain {} \ |
| 192 | "*100.0% complete*" \ |
| 193 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 194 | quiet {--quiet} \ |
| 195 | "" \ |
| 196 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 197 | cluster {--cluster} \ |
| 198 | "*100.0% complete*" \ |
| 199 | "SELECT count(*) FROM tagxref WHERE tagid=(SELECT tagid FROM tag |
| 200 | WHERE tagname='cluster')" 0 \ |
| 201 | noverify {--noverify} \ |
| 202 | "*100.0% complete*" \ |
| 203 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 204 | force {--force} \ |
| 205 | "*100.0% complete*" \ |
| 206 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 207 | analyze {--analyze} \ |
| 208 | "*Analyzing the database... done*" \ |
| 209 | "SELECT count(*) FROM sqlite_schema WHERE name='sqlite_stat1'" 1 \ |
| 210 | vacuum {--vacuum} \ |
| 211 | "*Vacuuming the database... done*" \ |
| 212 | "PRAGMA repository.freelist_count" 0 \ |
| 213 | pagesize {--pagesize 8192} \ |
| 214 | "*Vacuuming the database... done*" \ |
| 215 | "PRAGMA repository.page_size" 8192 \ |
| 216 | wal {--wal} \ |
| 217 | "*100.0% complete*" \ |
| 218 | "PRAGMA repository.journal_mode" wal \ |
| 219 | pagesize-in-wal {--pagesize 2048} \ |
| 220 | "*Vacuuming the database... done*" \ |
| 221 | "PRAGMA repository.page_size; PRAGMA repository.journal_mode" \ |
| 222 | "2048\nwal" \ |
| 223 | stats {--stats} \ |
| 224 | "*Artifacts:*Manifests:*Clusters:*Tags:*Wikis:*Tickets:*Other:*" \ |
| 225 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 226 | compress {--compress} \ |
| 227 | "*100.0% complete*Extra delta compression... *" \ |
| 228 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 229 | compress-only {--compress-only} \ |
| 230 | "Extra delta compression... *" \ |
| 231 | "SELECT count(*) FROM event WHERE type='ci'" $rebuildCheckins \ |
| 232 | ] { |
| 233 | fossil rebuild r.fossil {*}$rebuildOpts |
| 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. |
| 246 | test_eq rebuild-deanalyze-setup [rebuild_sql "SELECT count(*) |
| 247 | FROM sqlite_schema WHERE name='sqlite_stat1'" r.fossil] 1 |
| 248 | fossil rebuild r.fossil --deanalyze |
| 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} { |
| 260 | manifests Manifests ci |
| 261 | tags Tags g |
| 262 | wikis Wikis w |
| 263 | tickets Tickets t |
| 264 | } { |
| 265 | set rebuildCount "" |
| 266 | regexp -line "^$rebuildLabel: +(\\d+)" $rebuildStats -> rebuildCount |
| 267 | test_eq rebuild-stats-$rebuildName $rebuildCount [rebuild_sql "SELECT |
| 268 | count(*) FROM event WHERE type='$rebuildType'" full.fossil] |
| 269 | } |
| 270 | |
| 271 | # A page size that is too small, too large, or not a power of two is |
| 272 | # refused and nothing is rebuilt. |
| 273 | fossil sql -R r.fossil "UPDATE config SET mtime=1 WHERE name='rebuilt'" |
| 274 | foreach rebuildSize {256 131072 1000 abc} { |
| 275 | fossil rebuild r.fossil --pagesize $rebuildSize -expectError |
| 276 | test rebuild-pagesize-$rebuildSize-refused {$CODE != 0 && |
| 277 | [string match "*page size must be a power of two*" $RESULT]} |
| 278 | } |
| 279 | test_eq rebuild-pagesize-refused-unchanged [rebuild_sql "PRAGMA |
| 280 | repository.page_size; SELECT mtime FROM config WHERE name='rebuilt'" \ |
| 281 | r.fossil] "2048\n1" |
| 282 | |
| 283 | # --ifneeded does nothing when the schema is the current one, and |
| 284 | # rebuilds when the repository says it has an older one. |
| 285 | set rebuildSchema [rebuild_sql "SELECT value FROM config |
| 286 | WHERE name='aux-schema'" r.fossil] |
| 287 | fossil rebuild r.fossil --ifneeded |
| 288 | test rebuild-ifneeded-not-needed {$CODE == 0 && $RESULT eq ""} |
| 289 | test_eq rebuild-ifneeded-not-needed-untouched [rebuild_sql "SELECT mtime |
| 290 | FROM config WHERE name='rebuilt'" r.fossil] 1 |
| 291 | fossil sql -R r.fossil "UPDATE config SET value='2011-04-25 19:50' |
| 292 | WHERE name='aux-schema'" |
| 293 | fossil rebuild r.fossil --ifneeded |
| 294 | test rebuild-ifneeded-needed {$CODE == 0 && |
| 295 | [string match "*100.0% complete*" $RESULT]} |
| 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 |
| 315 | # (before 2011-04-27), no jx in user and reportfmt, and a blob table that |
| 316 | # takes only hashes of 40 characters (before 2.0). It is made from a new |
| 317 | # one by dropping the columns and editing the stored definition with SQL. |
| 318 | # Rebuild brings every table up to date and loses none of their rows. |
| 319 | |
| 320 | file copy full.fossil old.fossil |
| 321 | fossil sql -R old.fossil " |
| 322 | INSERT INTO concealed(hash,content,mtime) |
| 323 | VALUES('abc','[email protected]',1); |
| 324 | INSERT INTO shun(uuid,mtime,scom) |
| 325 | VALUES('[string repeat b 64]',1,'a reason'); |
| 326 | ALTER TABLE plink DROP COLUMN baseid; |
| 327 | DROP INDEX mlink_i4; |
| 328 | ALTER TABLE mlink DROP COLUMN isaux; |
| 329 | ALTER TABLE mlink DROP COLUMN pmid; |
| 330 | ALTER TABLE user DROP COLUMN jx; |
| 331 | ALTER TABLE user DROP COLUMN mtime; |
| 332 | ALTER TABLE shun DROP COLUMN mtime; |
| 333 | ALTER TABLE shun DROP COLUMN scom; |
| 334 | ALTER TABLE reportfmt DROP COLUMN jx; |
| 335 | ALTER TABLE reportfmt DROP COLUMN mtime; |
| 336 | ALTER TABLE concealed DROP COLUMN mtime; |
| 337 | ALTER TABLE config DROP COLUMN mtime; |
| 338 | " |
| 339 | fossil sql -R old.fossil ".dbconfig defensive off" \ |
| 340 | "PRAGMA writable_schema=ON" \ |
| 341 | "UPDATE repository.sqlite_schema |
| 342 | SET sql=replace(sql,'length(uuid)>=40','length(uuid)==40') |
| 343 | WHERE name='blob'" \ |
| 344 | "PRAGMA writable_schema=OFF" |
| 345 | proc rebuild_columns {repo} { |
| 346 | return [rebuild_sql " |
| 347 | SELECT group_concat(m.name || '.' || p.name, ' ') FROM ( |
| 348 | SELECT 'plink' AS name UNION ALL SELECT 'mlink' UNION ALL |
| 349 | SELECT 'user' UNION ALL SELECT 'config' UNION ALL SELECT 'shun' |
| 350 | UNION ALL SELECT 'reportfmt' UNION ALL SELECT 'concealed') AS m, |
| 351 | pragma_table_info(m.name, 'repository') AS p |
| 352 | WHERE m.name || '.' || p.name IN ('plink.baseid', 'mlink.pmid', |
| 353 | 'mlink.isaux', 'user.mtime', 'user.jx', 'config.mtime', |
| 354 | 'shun.mtime', 'shun.scom', 'reportfmt.mtime', 'reportfmt.jx', |
| 355 | 'concealed.mtime')" $repo] |
| 356 | } |
| 357 | proc rebuild_blob_check {repo} { |
| 358 | return [rebuild_sql "SELECT sql LIKE '%length(uuid)>=40%' |
| 359 | FROM repository.sqlite_schema WHERE name='blob'" $repo] |
| 360 | } |
| 361 | test_eq rebuild-old-schema-setup-columns [rebuild_columns old.fossil] "" |
| 362 | test_eq rebuild-old-schema-setup-blob [rebuild_blob_check old.fossil] 0 |
| 363 | set rebuildUsers [rebuild_sql "SELECT group_concat(login || '/' || cap, ' ') |
| 364 | FROM (SELECT login, cap FROM user ORDER BY login)" full.fossil] |
| 365 | set rebuildCode [rebuild_sql "SELECT value FROM config |
| 366 | WHERE name='project-code'" full.fossil] |
| 367 | set rebuildReports [rebuild_sql "SELECT group_concat(title, '|') |
| 368 | FROM (SELECT title FROM reportfmt ORDER BY rn)" full.fossil] |
| 369 | fossil rebuild old.fossil |
| 370 | test rebuild-old-schema {$CODE == 0} |
| 371 | test_eq rebuild-old-schema-columns [lsort [rebuild_columns old.fossil]] \ |
| 372 | [lsort [rebuild_columns full.fossil]] |
| 373 | test_eq rebuild-old-schema-blob [rebuild_blob_check old.fossil] 1 |
| 374 | test_eq rebuild-old-schema-users [rebuild_sql "SELECT group_concat(login |
| 375 | || '/' || cap, ' ') FROM (SELECT login, cap FROM user ORDER BY login)" \ |
| 376 | old.fossil] $rebuildUsers |
| 377 | test_eq rebuild-old-schema-users-dated [rebuild_sql "SELECT count(*) FROM user |
| 378 | WHERE mtime IS NULL" old.fossil] 0 |
| 379 | test_eq rebuild-old-schema-config [rebuild_sql "SELECT value, mtime>1 |
| 380 | FROM config WHERE name='project-code'" old.fossil] "$rebuildCode|1" |
| 381 | test_eq rebuild-old-schema-shun [rebuild_sql "SELECT uuid, mtime>1 FROM shun" \ |
| 382 | old.fossil] "[string repeat b 64]|1" |
| 383 | test_eq rebuild-old-schema-reports [rebuild_sql "SELECT group_concat(title, '|') |
| 384 | FROM (SELECT title FROM reportfmt ORDER BY rn)" old.fossil] $rebuildReports |
| 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 | |
| 397 | file copy full.fossil main.fossil |
| 398 | fossil sql -R main.fossil "REPLACE INTO config(name,value,mtime) |
| 399 | VALUES('main-branch','primary',now())" |
| 400 | set rebuildRoot [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT pid |
| 401 | FROM plink AS x WHERE NOT EXISTS(SELECT 1 FROM plink |
| 402 | WHERE cid=x.pid))" main.fossil] |
| 403 | fossil rebuild main.fossil |
| 404 | test rebuild-main-branch {$CODE == 0} |
| 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 |
| 420 | |
| 421 | ############################################################################### |
| 422 | # Rebuild of a repository damaged with SQL: an artifact stored as a delta |
| 423 | # whose own row is gone, or has become a phantom. The rebuild finishes, |
| 424 | # every check-in is still in the timeline, and the artifact is listed as |
| 425 | # a phantom. |
| 426 | |
| 427 | set rebuildDeltaFile "(SELECT delta.rid FROM delta JOIN mlink |
| 428 | ON mlink.fid=delta.rid JOIN filename USING(fnid) |
| 429 | WHERE name='a.txt' ORDER BY delta.rid LIMIT 1)" |
| 430 | foreach {rebuildName rebuildDamage} [list \ |
| 431 | delta-row-gone \ |
| 432 | "DELETE FROM blob WHERE rid=$rebuildDeltaFile" \ |
| 433 | delta-is-a-phantom \ |
| 434 | "UPDATE blob SET size=-1, content=NULL WHERE rid=$rebuildDeltaFile" \ |
| 435 | ] { |
| 436 | file copy -force full.fossil damaged.fossil |
| 437 | fossil sql -R damaged.fossil $rebuildDamage |
| 438 | fossil rebuild damaged.fossil |
| 439 | test rebuild-damage-$rebuildName {$CODE == 0} |
| 440 | test_eq rebuild-damage-$rebuildName-checkins [rebuild_sql "SELECT count(*) |
| 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; |
| 452 | # --noindex leaves it out; --index adds one; --compress-only leaves it |
| 453 | # alone. |
| 454 | |
| 455 | file copy full.fossil fts.fossil |
| 456 | proc rebuild_indexed {repo} { |
| 457 | if {[rebuild_sql "SELECT count(*) FROM sqlite_schema |
| 458 | WHERE name='ftsdocs'" $repo] == 0} {return none} |
| 459 | return [rebuild_sql "SELECT count(*) FROM ftsdocs" $repo] |
| 460 | } |
| 461 | test_eq rebuild-index-setup-none [rebuild_indexed fts.fossil] none |
| 462 | fossil rebuild fts.fossil --index |
| 463 | test rebuild-index {$CODE == 0} |
| 464 | set rebuildDocs [rebuild_indexed fts.fossil] |
| 465 | test rebuild-index-made {$rebuildDocs ne "none"} |
| 466 | fossil fts-config enable cdtwe -R fts.fossil |
| 467 | fossil rebuild fts.fossil |
| 468 | test rebuild-index-kept {$CODE == 0} |
| 469 | set rebuildDocs [rebuild_indexed fts.fossil] |
| 470 | test rebuild-index-kept-filled {$rebuildDocs ne "none" && $rebuildDocs > 0} |
| 471 | fossil sql -R fts.fossil "DELETE FROM ftsdocs" |
| 472 | fossil rebuild fts.fossil --compress-only |
| 473 | test rebuild-index-compress-only {$CODE == 0} |
| 474 | test_eq rebuild-index-compress-only-untouched [rebuild_indexed fts.fossil] 0 |
| 475 | fossil rebuild fts.fossil |
| 476 | test_eq rebuild-index-refilled [rebuild_indexed fts.fossil] $rebuildDocs |
| 477 | fossil search rebuild-side-1 -R fts.fossil |
| 478 | test rebuild-index-search {[string match "*rebuild-side-1*" $RESULT]} |
| 479 | # --compress-only with --index, when there is an index already, builds it |
| 480 | # again. |
| 481 | fossil sql -R fts.fossil "DELETE FROM ftsdocs" |
| 482 | fossil rebuild fts.fossil --compress-only --index |
| 483 | test rebuild-index-compress-only-index {$CODE == 0} |
| 484 | test_eq rebuild-index-compress-only-index-filled \ |
| 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 | |
| 496 | ############################################################################### |
| 497 | # Extra compression. "fossil repack" and "rebuild --compress-only" store |
| 498 | # more artifacts as deltas and say how many; what the artifacts are does |
| 499 | # not change. One or two file versions are stored whole again before |
| 500 | # each run, so that there is that much to find. |
| 501 | |
| 502 | fossil repack r.fossil full.fossil -expectError |
| 503 | test rebuild-repack-usage {$CODE != 0 && [string match "*Usage:*" $RESULT]} |
| 504 | fossil repack |
| 505 | test rebuild-repack-checkout {$CODE == 0} |
| 506 | fossil repack |
| 507 | test rebuild-repack-nothing {$CODE == 0 && |
| 508 | [string match "*no new compression opportunities found*" $RESULT] && |
| 509 | ![string match "*Vacuuming*" $RESULT]} |
| 510 | fossil rebuild --compress |
| 511 | test rebuild-compress-nothing {$CODE == 0 && |
| 512 | [string match "*Extra delta compression... none found*" $RESULT]} |
| 513 | proc rebuild_store_whole {count} { |
| 514 | foreach rid [split [rebuild_sql "SELECT delta.rid FROM delta JOIN mlink |
| 515 | ON mlink.fid=delta.rid JOIN filename USING(fnid) |
| 516 | WHERE name='a.txt' GROUP BY delta.rid ORDER BY delta.rid |
| 517 | LIMIT $count"] \n] { |
| 518 | fossil test-content-undelta $rid |
| 519 | } |
| 520 | } |
| 521 | foreach {rebuildName rebuildCmd rebuildCount rebuildOut} { |
| 522 | repack-one {repack} 1 "*1 new delta saves *Vacuuming*" |
| 523 | repack-two {repack} 2 "*2 new deltas save *Vacuuming*" |
| 524 | compress-one {rebuild --compress-only} 1 "*1 new delta saves *Vacuuming*" |
| 525 | compress-two {rebuild --compress-only} 2 "*2 new deltas save *Vacuuming*" |
| 526 | } { |
| 527 | set rebuildDeltas [rebuild_sql "SELECT count(*) FROM delta"] |
| 528 | rebuild_store_whole $rebuildCount |
| 529 | test_eq rebuild-$rebuildName-setup [rebuild_sql "SELECT count(*) |
| 530 | FROM delta"] [expr {$rebuildDeltas - $rebuildCount}] |
| 531 | fossil {*}$rebuildCmd |
| 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] |
| 544 | } |
| 545 | |
| 546 | ############################################################################### |
| 547 | # Detach asks first. "n" changes nothing; a capital Y is a yes. |
| 548 | |
| 549 | file copy full.fossil detach.fossil |
| 550 | fossil_raw -input "n\n" detach detach.fossil |
| 551 | test rebuild-detach-declined {$CODE == 0} |
| 552 | test_eq rebuild-detach-declined-same-code [rebuild_sql "SELECT value |
| 553 | FROM config WHERE name='project-code'" detach.fossil] $rebuildCode |
| 554 | fossil_raw -input "Y\n" detach detach.fossil |
| 555 | test rebuild-detach-capital {$CODE == 0 && |
| 556 | [string match "*New project code: *" $RESULT]} |
| 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. |
| 585 | |
| 586 | file mkdir d-public |
| 587 | fossil deconstruct -R full.fossil d-public |
| 588 | test rebuild-deconstruct {$CODE == 0} |
| 589 | test_eq rebuild-deconstruct-public-only [rebuild_names d-public] $rebuildPublic |
| 590 | test rebuild-deconstruct-two-letter-directories {[lsearch -not -regexp \ |
| 591 | [rebuild_files d-public] {^[0-9a-f]{2}/[0-9a-f]+$}] < 0} |
| 592 | test_eq rebuild-deconstruct-no-lists \ |
| 593 | [glob -nocomplain -directory d-public .rid1 .private] "" |
| 594 | fossil artifact [lindex $rebuildTrunk 0] -R full.fossil one.txt |
| 595 | test rebuild-deconstruct-content {[same_file one.txt [file join d-public \ |
| 596 | [string range [lindex $rebuildTrunk 0] 0 1] \ |
| 597 | [string range [lindex $rebuildTrunk 0] 2 end]]]} |
| 598 | fossil reconstruct r-public.fossil d-public |
| 599 | test rebuild-reconstruct {$CODE == 0 && |
| 600 | [string match "*project-id: *server-id: *admin-user: *" $RESULT]} |
| 601 | test_eq rebuild-reconstruct-artifacts [rebuild_hashes r-public.fossil] \ |
| 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 ""} |
| 613 | test_eq rebuild-deconstruct-quiet-files [rebuild_names d-quiet] $rebuildPublic |
| 614 | |
| 615 | # --private writes the private artifacts too. A repository made from the |
| 616 | # files has them all, and none is private. |
| 617 | file mkdir d-private |
| 618 | fossil deconstruct -R full.fossil d-private --private |
| 619 | test rebuild-deconstruct-private {$CODE == 0} |
| 620 | test_eq rebuild-deconstruct-private-all [rebuild_names d-private] $rebuildAll |
| 621 | test_eq rebuild-deconstruct-private-no-lists \ |
| 622 | [glob -nocomplain -directory d-private .rid1 .private] "" |
| 623 | |
| 624 | # -P writes them and lists them in .private; -K names the file of the |
| 625 | # first artifact in .rid1. Reconstruct with -P and -K reads both lists: |
| 626 | # the same artifacts are private, the first artifact is the first again, |
| 627 | # and everything else is as it was. An empty line, a comment and a line |
| 628 | # that is not a hash are added to the lists first, and are passed over. |
| 629 | file mkdir d-keep |
| 630 | fossil deconstruct -R full.fossil d-keep -P -K |
| 631 | test rebuild-deconstruct-keep {$CODE == 0} |
| 632 | test_eq rebuild-deconstruct-keep-all [rebuild_names d-keep] $rebuildAll |
| 633 | set rebuildFirst [rebuild_sql "SELECT uuid FROM blob WHERE rid=1" full.fossil] |
| 634 | test_eq rebuild-deconstruct-keep-rid1 \ |
| 635 | [lindex [split [string trim [read_file d-keep/.rid1]] \n] end] \ |
| 636 | "[string range $rebuildFirst 0 1]/[string range $rebuildFirst 2 end]" |
| 637 | set rebuildPrivate [rebuild_hashes full.fossil "rid IN private"] |
| 638 | test_eq rebuild-deconstruct-keep-private [lsort [lrange [split \ |
| 639 | [string trim [read_file d-keep/.private]] \n] 1 end]] $rebuildPrivate |
| 640 | write_file d-keep/.private \ |
| 641 | "\n# one more comment\nnot-a-hash\n[read_file d-keep/.private]" |
| 642 | write_file d-keep/.rid1 "\n[read_file d-keep/.rid1]" |
| 643 | fossil reconstruct r-keep.fossil d-keep -K -P |
| 644 | test rebuild-reconstruct-keep {$CODE == 0} |
| 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 |
| 669 | test rebuild-deconstruct-flat {$CODE == 0} |
| 670 | test_eq rebuild-deconstruct-flat-files [rebuild_files d-flat] $rebuildPublic |
| 671 | test_eq rebuild-deconstruct-flat-rid1 \ |
| 672 | [lindex [split [string trim [read_file d-flat/.rid1]] \n] end] \ |
| 673 | $rebuildFirst |
| 674 | fossil reconstruct r-flat.fossil d-flat -K |
| 675 | test rebuild-reconstruct-flat {$CODE == 0} |
| 676 | test_eq rebuild-reconstruct-flat-artifacts [rebuild_hashes r-flat.fossil] \ |
| 677 | $rebuildPublic |
| 678 | test_eq rebuild-reconstruct-flat-rid1 [rebuild_sql "SELECT uuid FROM blob |
| 679 | WHERE rid=1" r-flat.fossil] $rebuildFirst |
| 680 | fossil deconstruct -R full.fossil d-five --prefixlength 5 |
| 681 | test rebuild-deconstruct-five {$CODE == 0} |
| 682 | test_eq rebuild-deconstruct-five-names [rebuild_names d-five] $rebuildPublic |
| 683 | test rebuild-deconstruct-five-directories {[lsearch -not -regexp \ |
| 684 | [rebuild_files d-five] {^[0-9a-f]{5}/[0-9a-f]+$}] < 0} |
| 685 | |
| 686 | # What deconstruct refuses: a prefix length that is not one digit, no |
| 687 | # destination or two, and a destination that is empty or missing. |
| 688 | file mkdir d-none |
| 689 | foreach {rebuildName rebuildArgs rebuildOut} { |
| 690 | prefix-below-digits {d-none -L /} "*not a valid prefix length*" |
| 691 | prefix-letter {d-none -L x} "*not a valid prefix length*" |
| 692 | prefix-two-digits {d-none -L 10} "*not a valid prefix length*" |
| 693 | no-destination {} "*Usage:*" |
| 694 | two-destinations {d-none d-flat} "*Usage:*" |
| 695 | empty-destination {{}} "*is not a directory*" |
| 696 | missing-destination {d-missing} "*is not a directory*" |
| 697 | } { |
| 698 | fossil deconstruct -R full.fossil {*}$rebuildArgs -expectError |
| 699 | test rebuild-deconstruct-$rebuildName {$CODE != 0 && |
| 700 | [string match $rebuildOut $RESULT]} |
| 701 | } |
| 702 | test_eq rebuild-deconstruct-refused-wrote-nothing [rebuild_files d-none] "" |
| 703 | |
| 704 | # A destination that is a file is refused, and the file is kept. |
| 705 | write_file d-file.txt "a file, not a directory\n" |
| 706 | fossil deconstruct -R full.fossil d-file.txt -expectError |
| 707 | test rebuild-deconstruct-file-destination {$CODE != 0 && |
| 708 | [string match "*is not a directory*" $RESULT]} |
| 709 | test rebuild-deconstruct-file-destination-kept \ |
| 710 | {[file isfile d-file.txt]} |
| 711 | |
| 712 | # A destination that cannot be written to, where the system can make one. |
| 713 | catch {file attributes d-none -permissions 0555} |
| 714 | if {![file writable d-none]} { |
| 715 | fossil deconstruct -R full.fossil d-none -expectError |
| 716 | test rebuild-deconstruct-not-writable {$CODE != 0 && |
| 717 | [string match "*is not writeable*" $RESULT]} |
| 718 | } |
| 719 | catch {file attributes d-none -permissions 0755} |
| 720 | |
| 721 | # What reconstruct refuses: too few names, and a directory that is not one. |
| 722 | fossil reconstruct r-none.fossil -expectError |
| 723 | test rebuild-reconstruct-usage {$CODE != 0 && |
| 724 | [string match "*Usage:*" $RESULT]} |
| 725 | fossil reconstruct r-none.fossil one.txt -expectError |
| 726 | test rebuild-reconstruct-not-a-directory {$CODE != 0 && |
| 727 | [string match "*is not a directory*Usage:*" $RESULT]} |
| 728 | test rebuild-reconstruct-refused-made-nothing {![file exists r-none.fossil]} |
| 729 | |
| 730 | # -K when .rid1 names no file, and when there is no .rid1. |
| 731 | write_file d-flat/.rid1 "# nothing but a comment\n\n" |
| 732 | fossil reconstruct r-rid1-empty.fossil d-flat -K -expectError |
| 733 | test rebuild-reconstruct-rid1-empty {$CODE != 0 && |
| 734 | [string match "*error occurred while reading or parsing*" $RESULT]} |
| 735 | file delete d-flat/.rid1 |
| 736 | fossil reconstruct r-rid1-missing.fossil d-flat -K -expectError |
| 737 | test rebuild-reconstruct-rid1-missing {$CODE != 0 && |
| 738 | [string match "*no such file*" $RESULT]} |
| 739 | |
| 740 | # A directory below that cannot be read, where the system can make one. |
| 741 | file mkdir d-five/locked |
| 742 | write_file d-five/locked/file.txt "out of reach\n" |
| 743 | catch {file attributes d-five/locked -permissions 0000} |
| 744 | if {![file readable d-five/locked]} { |
| 745 | fossil reconstruct r-locked.fossil d-five -expectError |
| 746 | test rebuild-reconstruct-unreadable-directory {$CODE != 0 && |
| 747 | [string match "*encountered error*while trying to open*" $RESULT]} |
| 748 | } |
| 749 | catch {file attributes d-five/locked -permissions 0755} |
| 750 | |
| 751 | ############################################################################### |
| 752 | # Artifacts named by SHA1. Reconstruct stores each file under the kind |
| 753 | # of hash its name has; a file whose name is no hash is stored as well. |
| 754 | |
| 755 | fossil init --sha1 sha1.fossil |
| 756 | write_file sha1-content.txt "content stored under a SHA1 hash\n" |
| 757 | fossil test-content-put sha1-content.txt -R sha1.fossil |
| 758 | set rebuildSha1 [rebuild_hashes sha1.fossil] |
| 759 | test rebuild-sha1-setup {[llength $rebuildSha1] >= 2 && |
| 760 | [lsearch -not -regexp $rebuildSha1 {^[0-9a-f]{40}$}] < 0} |
| 761 | file mkdir d-sha1 |
| 762 | fossil deconstruct -R sha1.fossil d-sha1 |
| 763 | test_eq rebuild-sha1-deconstruct [rebuild_names d-sha1] $rebuildSha1 |
| 764 | write_file d-sha1/notes "a file whose name is not a hash\n" |
| 765 | fossil sha1sum d-sha1/notes |
| 766 | set rebuildNote1 [lindex $RESULT 0] |
| 767 | fossil sha3sum d-sha1/notes |
| 768 | set rebuildNote3 [lindex $RESULT 0] |
| 769 | fossil reconstruct r-sha1.fossil d-sha1 |
| 770 | test rebuild-sha1-reconstruct {$CODE == 0} |
| 771 | test_eq rebuild-sha1-reconstruct-same-hashes [rebuild_hashes r-sha1.fossil \ |
| 772 | "length(uuid)=40 AND uuid<>'$rebuildNote1'"] $rebuildSha1 |
| 773 | test_eq rebuild-sha1-reconstruct-other-file [rebuild_sql "SELECT count(*) |
| 774 | FROM blob WHERE uuid IN ('$rebuildNote1','$rebuildNote3')" r-sha1.fossil] 1 |
| 775 | test_eq rebuild-sha1-reconstruct-count [llength [rebuild_hashes \ |
| 776 | r-sha1.fossil]] [expr {[llength $rebuildSha1] + 1}] |
| 777 | |
| 778 | ############################################################################### |
| 779 | # Deconstruct of repositories that lack content. |
| 780 | |
| 781 | # A check-in whose parent and files are not there: they are phantoms, and |
| 782 | # only what has content is written. |
| 783 | fossil init phantom.fossil |
| 784 | fossil artifact $rebuildSide -R full.fossil side.txt |
| 785 | fossil test-content-put --crosslink side.txt -R phantom.fossil |
| 786 | test rebuild-phantom-setup {[rebuild_sql "SELECT count(*) FROM phantom" \ |
| 787 | phantom.fossil] > 0} |
| 788 | file mkdir d-phantom |
| 789 | fossil deconstruct -R phantom.fossil d-phantom |
| 790 | test rebuild-deconstruct-phantom {$CODE == 0} |
| 791 | test_eq rebuild-deconstruct-phantom-files [rebuild_names d-phantom] \ |
| 792 | [rebuild_hashes phantom.fossil] |
| 793 | test rebuild-deconstruct-phantom-has-checkin \ |
| 794 | {[lsearch -exact [rebuild_names d-phantom] $rebuildSide] >= 0} |
| 795 | |
| 796 | # A public artifact stored as a delta from a private one, which "fossil |
| 797 | # publish" of the older of two private check-ins leaves. Without |
| 798 | # --private the public one is written and the private one is not. |
| 799 | file copy full.fossil publish.fossil |
| 800 | fossil publish $rebuildSecret1 -R publish.fossil |
| 801 | test rebuild-public-from-private-setup {[rebuild_sql "SELECT count(*) |
| 802 | FROM delta |
| 803 | WHERE rid=(SELECT rid FROM blob WHERE uuid='$rebuildSecretFile1') |
| 804 | AND srcid=(SELECT rid FROM blob WHERE uuid='$rebuildSecretFile2') |
| 805 | AND rid NOT IN private AND srcid IN private" publish.fossil] == 1} |
| 806 | file mkdir d-publish |
| 807 | fossil deconstruct -R publish.fossil d-publish |
| 808 | test rebuild-deconstruct-public-from-private {$CODE == 0} |
| 809 | test_eq rebuild-deconstruct-public-from-private-files \ |
| 810 | [rebuild_names d-publish] \ |
| 811 | [rebuild_hashes publish.fossil "rid NOT IN private"] |
| 812 | test rebuild-deconstruct-public-from-private-written \ |
| 813 | {[lsearch -exact [rebuild_names d-publish] $rebuildSecretFile1] >= 0 && |
| 814 | [lsearch -exact [rebuild_names d-publish] $rebuildSecretFile2] < 0} |
| 815 | |
| 816 | # A repository damaged with SQL: the artifact that others are deltas of |
| 817 | # is gone. Deconstruct finishes; it writes what can still be read and |
| 818 | # nothing for what cannot. |
| 819 | file copy full.fossil damaged.fossil |
| 820 | set rebuildSource [rebuild_sql "SELECT uuid FROM blob WHERE rid=(SELECT srcid |
| 821 | FROM delta JOIN mlink ON mlink.fid=delta.rid JOIN filename USING(fnid) |
| 822 | WHERE name='a.txt' AND srcid NOT IN (SELECT rid FROM delta))" \ |
| 823 | damaged.fossil] |
| 824 | set rebuildLost [rebuild_sql "WITH RECURSIVE lost(rid) AS ( |
| 825 | SELECT rid FROM blob WHERE uuid='$rebuildSource' |
| 826 | UNION SELECT delta.rid FROM delta, lost WHERE delta.srcid=lost.rid) |
| 827 | SELECT group_concat(uuid, ' ') FROM blob WHERE rid IN lost" \ |
| 828 | damaged.fossil] |
| 829 | test rebuild-damage-source-setup {[llength $rebuildLost] > 1} |
| 830 | fossil sql -R damaged.fossil "DELETE FROM blob WHERE uuid='$rebuildSource'" |
| 831 | file mkdir d-damaged |
| 832 | fossil deconstruct -R damaged.fossil d-damaged |
| 833 | test rebuild-deconstruct-damage-source-gone {$CODE == 0} |
| 834 | set rebuildWant {} |
| 835 | foreach rebuildH $rebuildPublic { |
| 836 | if {[lsearch -exact $rebuildLost $rebuildH] < 0} { |
| 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. |
| 848 | |
| 849 | proc rebuild_clusters {{repo .rep.fossil}} { |
| 850 | return [rebuild_sql "SELECT count(*) FROM tagxref WHERE tagid=(SELECT tagid |
| 851 | FROM tag WHERE tagname='cluster')" $repo] |
| 852 | } |
| 853 | proc rebuild_many_files {dir} { |
| 854 | file mkdir $dir |
| 855 | for {set i 0} {$i < 110} {incr i} { |
| 856 | write_file $dir/f$i.txt "file $i in $dir\n" |
| 857 | } |
| 858 | fossil add $dir |
| 859 | fossil commit -m rebuild-$dir --no-warnings |
| 860 | } |
| 861 | fossil test-create-clusters r.fossil full.fossil -expectError |
| 862 | test rebuild-create-clusters-usage {$CODE != 0 && |
| 863 | [string match "*Usage:*" $RESULT]} |
| 864 | fossil test-create-clusters |
| 865 | test rebuild-create-clusters-too-few {$CODE == 0} |
| 866 | test_eq rebuild-create-clusters-too-few-none [rebuild_clusters] 0 |
| 867 | fossil test-clusters |
| 868 | test rebuild-clusters-none {$CODE == 0 && |
| 869 | [string match "*all artifacts reachable through clusters*" $RESULT]} |
| 870 | rebuild_many_files many1 |
| 871 | fossil test-create-clusters .rep.fossil |
| 872 | test rebuild-create-clusters {$CODE == 0} |
| 873 | test_eq rebuild-create-clusters-one [rebuild_clusters] 1 |
| 874 | test_eq rebuild-create-clusters-one-left [rebuild_sql "SELECT count(*) |
| 875 | FROM unclustered"] 1 |
| 876 | fossil test-clusters |
| 877 | test rebuild-clusters-one {$CODE == 0 && |
| 878 | [string match "*all artifacts reachable through clusters*" $RESULT]} |
| 879 | # A second cluster lists the first. |
| 880 | rebuild_many_files many2 |
| 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 |
| 892 | WHERE tagname='cluster'))"] |
| 893 | file copy .rep.fossil cluster.fossil |
| 894 | fossil purge artifacts $rebuildNewest -R cluster.fossil |
| 895 | fossil test-clusters -R cluster.fossil |
| 896 | set rebuildCount 0 |
| 897 | regexp {(\d+) unreachable artifacts:} $RESULT -> rebuildCount |
| 898 | test rebuild-clusters-unreachable {$CODE == 0 && $rebuildCount > 100} |
| 899 | test_eq rebuild-clusters-unreachable-listed \ |
| 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 |
+304
| --- a/test/regress.test | ||
| +++ b/test/regress.test | ||
| @@ -0,0 +1,304 @@ | ||
| 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" | |
| 10 | +fossil add a.txt | |
| 11 | +fossil commit -m "regress-c1" | |
| 12 | + | |
| 13 | +############################################################################### | |
| 14 | +# "fossil test-dir-list" on an empty directory, and on one that does not | |
| 15 | +# exist, used to crash. | |
| 16 | + | |
| 17 | +file mkdir empty-directory | |
| 18 | +fossil test-dir-list empty-directory | |
| 19 | +test regress-dir-list-empty {$CODE == 0} | |
| 20 | +fossil test-dir-list no-such-directory | |
| 21 | +test regress-dir-list-missing {$CODE == 0} | |
| 22 | + | |
| 23 | +############################################################################### | |
| 24 | +# "fossil test-xfer" used to print a robot captcha and then crash. | |
| 25 | + | |
| 26 | +write_file request.txt "pragma client-versi | |
| 27 | +fossil test-xfer request.txt | |
| 28 | +test regress-test-xfer {$CODE == 0} | |
| 29 | +test_match regress-test-xfer-reply $RESULT {# timestamp} | |
| 30 | + | |
| 31 | +############################################################################### | |
| 32 | +# A branch name shorter than "date:" was read past its end when it was | |
| 33 | +# looked up. This shows only in a build with run-time checking. | |
| 34 | + | |
| 35 | +fossil branch new br trunk | |
| 36 | +fossil update br | |
| 37 | +test regress-short-branch-name {$CODE == 0} | |
| 38 | +fossil update trunk | |
| 39 | + | |
| 40 | +############################################################################### | |
| 41 | +# A delta for a target of 2^24 bytes or more that has nothing in common | |
| 42 | +# with its source overflowed length of the wrong string. This shows | |
| 43 | +# only in a build with run-time checking. | |
| 44 | + | |
| 45 | +file mkdir rel/b rel/c-with-a-longer-name/sub | |
| 46 | +fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt | |
| 47 | +test regress-relative-name-sibling \ | |
| 48 | + {$CODE == 0 | |
| 49 | + && [string trim $RESULT] eq "../c-with-a-longer-name/sub/file.txt"} | |
| 50 | +fossil test-relative-name --slash --chdir rel/b ../c-with-a-longer-name/sub/ | |
| 51 | +test regress-relative-name-sibling-slash \ | |
| 52 | + {$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"} | |
| 53 | + | |
| 54 | +############################################################################### | |
| 55 | +# The names of the files in a merge conflict are put into the | |
| 56 | +# gmerge-command as they are, inside the double quotes that the setting | |
| 57 | +# has around them. A name with a double quote reached the merge tool as | |
| 58 | +# several arguments, and one with a dollar sign or a backquote stopped the | |
| 59 | +# merge. For such a name the tool is now left out, with a warning, and | |
| 60 | +# the conflict stays marked in the file. The merge tool here is | |
| 61 | +# standin/log-args.sh, which records its arguments and resolves nothing. | |
| 62 | + | |
| 63 | +if {$::tcl_platform(platform) ne "windows"} { | |
| 64 | + set regressTop [pwd] | |
| 65 | + set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]] | |
| 66 | + set regressToolLog [file join $regressTop gmerge-args.txt] | |
| 67 | + set ::env(ARGS_LOG) $regressToolLog | |
| 68 | + foreach {regressName regressFile regressRuns} { | |
| 69 | + plain plain.txt 1 | |
| 70 | + space {sp ace.txt} 1 | |
| 71 | + quote {a" "b.txt} 0 | |
| 72 | + dollar {a$b.txt} 0 | |
| 73 | + backquote {a`x`b.txt} 0 | |
| 74 | + } { | |
| 75 | + file mkdir gmerge-$regressName | |
| 76 | + cd gmerge-$regressName | |
| 77 | + fossil init r.fossil | |
| 78 | + fossil open r.fossil --nested | |
| 79 | + write_file $regressFile "one\ntwo\nthree\n" | |
| 80 | + fossil add $regressFile | |
| 81 | + fossil commit -m base --no-warnings | |
| 82 | + write_file $regressFile "one\nTWO-branch\nthree\n" | |
| 83 | + fossil commit -m branch --branch br --no-warnings | |
| 84 | + fossil update trunk | |
| 85 | + write_file $regressFile "one\nTWO-trunk\nthree\n" | |
| 86 | + fossil commit -m trunk --no-warnings | |
| 87 | + fossil settings gmerge-command \ | |
| 88 | + "$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\"" | |
| 89 | + file delete $regressToolLog | |
| 90 | + fossil_raw merge br | |
| 91 | + set regressArgs 0 | |
| 92 | + if {[file exists $regressToolLog]} { | |
| 93 | + set regressArgs \ | |
| 94 | + [llength [split [string trim [read_file $regressToolLog]] \n]] | |
| 95 | + } | |
| 96 | + set regressMarked \ | |
| 97 | + [expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}] | |
| 98 | + set regressWarned \ | |
| 99 | + [expr {[string first "not running the gmerge-command" $RESULT] >= 0}] | |
| 100 | + test regress-gmerge-$regressName \ | |
| 101 | + {$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns | |
| 102 | + && $regressWarned != $regressRuns} | |
| 103 | + fossil close --force | |
| 104 | + cd $regressTop | |
| 105 | + } | |
| 106 | + unset ::env(ARGS_LOG) | |
| 107 | +} | |
| 108 | + | |
| 109 | +############################################################################### | |
| 110 | + | |
| 111 | +test_cleanup | |
| 112 | +write_file tiny.txt "x\n" | |
| 113 | +write_file big.txt [string repeat "0123456789abcde\n" 1048576] | |
| 114 | +fossil test-delta-create tiny.txt big.txt big.delta | |
| 115 | +test regress-large-delta-create {$CODE == 0} | |
| 116 | +fossil test-delta-apply tiny.txt big.delta big.out | |
| 117 | +test regress-large-delta-apply {$CODE == 0} | |
| 118 | +test regress-large-delta-same {[same_file big.txt big.out]} | |
| 119 | +file delete ########################################################################################################## | |
| 120 | +# An HTML comment or an HR tag followed by spaces and no newline made the | |
| 121 | +# Markdown translator copy one byte from past the end of its input into | |
| 122 | +# the output. That byte was a NUL. | |
| 123 | + | |
| 124 | +foreach {regressName regressText} { | |
| 125 | + hr "<hr> " | |
| 126 | + comment "<!-- x --> " | |
| 127 | + quoted "> <hr> " | |
| 128 | +} { | |
| 129 | + write_file md-$reg# The output goes to a file and is read back as bytes, so that a NUL | |
| 130 | + # in it is seen as one. | |
| 131 | + set regressRc [catch {exec $::fossilexe test-markdown-render \ | |
| 132 | + md-$regressName.md > md-$regressName.out}] | |
| 133 | + set regressFd [open md-$regressName.out rb] | |
| 134 | + set regressOut [read $regressFd] | |
| 135 | + close $regressFwn-render md-$regressName.md | |
| 136 | + tesregressRcregressName \ | |
| 137 | + {$CODE =regressOut] < 0} | |
| 138 | +} | |
| 139 | + | |
| 140 | +############################################################################### | |
| 141 | +# "fossil import --svn" took the lengths in a property block from the dump | |
| 142 | +# file without checking them. A block too short for its end marker was | |
| 143 | +# read before its start, a negative length made the import run for ever, | |
| 144 | +# and an oversized one read and wrote outside the block. | |
| 145 | + | |
| 146 | +proc regress_svn_rev {regressN:" was read past itset regressLen [string len "Revision-number: $number\nProp-content-length: $length\n" | |
| 147 | + return "${head}Content-length: $length\n\n$props\n" | |
| 148 | +} | |
| 149 | + | |
| 150 | +proc regress_svn_props {props} { | |
| 151 | + set block "" | |
| 152 | + foreach {name value} $props { | |
| 153 | + append block "K [string length $name]\n$name\n" | |
| 154 | + append block "V [string length $value]\n$value\n" | |
| 155 | + } | |
| 156 | + return "${block}PROPS-END\n" | |
| 157 | +} | |
| 158 | + | |
| 159 | +# Each import has a time limit of 60 seconds, because one of these faults | |
| 160 | +# was an endless loop. | |
| 161 | +set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n" | |
| 162 | +foreach {regressName regressProps} { | |
| 163 | + short-block "abcd\n" | |
| 164 | + negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n" | |
| 165 | + oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n" | |
| 166 | + oversized-value "K 2\nab\nV 99999\nx\nPROPS-END\n" | |
| 167 | + negative-value "K 2\nab\nV -40\nx\nPROPS-END\n" | |
| 168 | +} { | |
| 169 | + write_file svn-$regressName.dump \ | |
| 170 | + $regressSvnHead[regress_svn_rev 0 $regressProps] | |
| 171 | + fossil_raw -seconds 60 import --svn svn-$regressName.fossil \ | |
| 172 | + svn-$regressName.dump | |
| 173 | + test regress-svn-import-$regressName \ | |
| 174 | + {$CODE == 1 && [string match "*svn-dump data*" $RESULT]} | |
| 175 | + file delete svn-$regressName.fossil | |
| 176 | +} | |
| 177 | + | |
| 178 | +set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z} | |
| 179 | +set regressSvnSound $regressSvnHead | |
| 180 | +append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]] | |
| 181 | +append regressSvnSound [regress_svn_rev 1 [regress_svn_props \ | |
| 182 | + [concat {svn:log first svn:author dan} $regressSvnDate]]] | |
| 183 | +write_file svn-sound.dump $regressSvnSound | |
| 184 | +fossil import --svn svn-sound.fossil svn-sound.dump | |
| 185 | +test regress-svn-import-sound {$CODE == 0} | |
| 186 | +file delete svn-sound.fossil | |
| 187 | + | |
| 188 | +############################################################################### | |
| 189 | +# Two more faults in the property block of "fossil import --svn". A NUL | |
| 190 | +# byte in the block made the search for the end of a line fail, which | |
| 191 | +# crashed the import. A negative length for the block itself was passed | |
| 192 | +# on as the size of an allocation. | |
| 193 | + | |
| 194 | +write_file svn-nul-in-block.dump \ | |
| 195 | + $regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"] | |
| 196 | +set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n" | |
| 197 | +append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n" | |
| 198 | +write_file svn-negative-block.dump $regressSvnHead$regressSvnNegative | |
| 199 | +foreach regressName {nul-in-block negative-block} { | |
| 200 | + fossil_raw -seconds 60 import --svn svn-$regressName.fossil \ | |
| 201 | + svn-$regressName.dump | |
| 202 | + test regress-svn-import-$regressName \ | |
| 203 | + {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]} | |
| 204 | + file delete svn-$regressName.fossil | |
| 205 | +} | |
| 206 | + | |
| 207 | +############################################################################### | |
| 208 | +# A Markdown header that holds an HTML comment was read past its end when | |
| 209 | +# its id was made. This shows only in a build with run-time checking. | |
| 210 | + | |
| 211 | +write_file md-header.md "intro\n\n# a <!-- -->\n" | |
| 212 | +fossil test-markdown-render md-header.md | |
| 213 | +test regress-markdown-header-comment \ | |
| 214 | + {$CODE == 0 && [string first {<h1 id="a">} $RESULT] >= 0} | |
| 215 | + | |
| 216 | +############################################################################### | |
| 217 | +# The name of a file in a sibling directory, relative to the current | |
| 218 | +# directory, was copied with the length of the wrong string. This shows | |
| 219 | +# only in a build with run-time checking. | |
| 220 | + | |
| 221 | +file mkdir rel/b rel/c-with-a-longer-name/sub | |
| 222 | +fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt | |
| 223 | +test regress-relative-name-sibling \ | |
| 224 | + {$CODE == 0 | |
| 225 | + && [string trim $RESULT] eq "../c-with-a-longer-name/sub/file.txt"} | |
| 226 | +fossil test-relative-name --slash --chdir rel/b ../c-with-a-longer-name/sub/ | |
| 227 | +test regress-relative-name-sibling-slash \ | |
| 228 | + {$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"} | |
| 229 | + | |
| 230 | +############################################################################### | |
| 231 | +# The names of the files in a merge conflict are put into the | |
| 232 | +# gmerge-command as they are, inside the double quotes that the setting | |
| 233 | +# has around them. A name with a double quote reached the merge tool as | |
| 234 | +# several arguments, and one with a dollar sign or a backquote stopped the | |
| 235 | +# merge. For such a name the tool is now left out, with a warning, and | |
| 236 | +# the conflict stays marked in the file. The merge tool here is | |
| 237 | +# standin/log-args.sh, which records its arguments and resolves nothing. | |
| 238 | + | |
| 239 | +if {$::tcl_platform(platform) ne "windows"} { | |
| 240 | + set regressTop [pwd] | |
| 241 | + set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]] | |
| 242 | + set regressToolLog [file join $regressTop gmerge-args.txt] | |
| 243 | + set ::env(ARGS_LOG) $regressToolLog | |
| 244 | + foreach {regressName regressFile regressRuns} { | |
| 245 | + plain plain.txt 1 | |
| 246 | + space {sp ace.txt} 1 | |
| 247 | + quote {a" "b.txt} 0 | |
| 248 | + dollar {a$b.txt} 0 | |
| 249 | + backquote {a`x`b.txt} 0 | |
| 250 | + } { | |
| 251 | + file mkdir gmerge-$regressName | |
| 252 | + cd gmerge-$regressName | |
| 253 | + fossil init r.fossil | |
| 254 | + fossil open r.fossil --nested | |
| 255 | + write_file $regressFile "one\ntwo\nthree\n" | |
| 256 | + fossil add $regressFile | |
| 257 | + fossil commit -m base --no-warnings | |
| 258 | + write_file $regressFile "one\nTWO-branch\nthree\n" | |
| 259 | + fossil commit -m branch --branch br --no-warnings | |
| 260 | + fossil update trunk | |
| 261 | + write_file $regressFile "one\nTWO-trunk\nthree\n" | |
| 262 | + fossil commit -m trunk --no-warnings | |
| 263 | + fossil settings gmerge-command \ | |
| 264 | + "$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\"" | |
| 265 | + file delete $regressToolLog | |
| 266 | + fossil_raw merge br | |
| 267 | + set regressArgs 0 | |
| 268 | + if {[file exists $regressToolLog]} { | |
| 269 | + set regressArgs \ | |
| 270 | + [llength [split [string trim [read_file $regressToolLog]] \n]] | |
| 271 | + } | |
| 272 | + set regressMarked \ | |
| 273 | + [expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}] | |
| 274 | + set regressWarned \ | |
| 275 | + [expr {[string first "not running the gmerge-command" $RESULT] >= 0}] | |
| 276 | + test regress-gmerge-$regressName \ | |
| 277 | + {$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns | |
| 278 | + && $regressWarned != $regressRuns} | |
| 279 | + fossil close --force | |
| 280 | + cd $regressTop | |
| 281 | + } | |
| 282 | + unset ::env(ARGS_LOG) | |
| 283 | +} | |
| 284 | + | |
| 285 | +############################################################################### | |
| 286 | + | |
| 287 | +test_cleanup | |
| 288 | +regressNd "Revision-number: $numregressLen\nContent-length: $regressLen\n\n$regressProps\n" | |
| 289 | +} | |
| 290 | +# Run fossil with the arguments given and a time limit in seconds, because | |
| 291 | +# one of these faults##################### The result is the exit status, | |
| 292 | +# or -1 if the limit ran out, followed by the output. | |
| 293 | +proc regress_read {regressFd} { | |
| 294 | + append ::regressOutput [read $regressFd] | |
| 295 | + if {[eof $regressFd]} {set ::regressState done} | |
| 296 | +} | |
| 297 | +proc regress_limited {regressSeconds args} { | |
| 298 | + set ::regressOutput "" | |
| 299 | + set ::regressState running | |
| 300 | + set regressFd [open "|[linsert $args 0 $::fossilexe] 2>@1" r] | |
| 301 | + fconfigure $regressFd -blocking 0 | |
| 302 | + fileevent $regressFd readable [list regress_read $regressFd] | |
| 303 | + set rwn-rendeeconds*1000}] \ | |
| 304 | + |
| --- a/test/regress.test | |
| +++ b/test/regress.test | |
| @@ -0,0 +1,304 @@ | |
| --- a/test/regress.test | |
| +++ b/test/regress.test | |
| @@ -0,0 +1,304 @@ | |
| 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" |
| 10 | fossil add a.txt |
| 11 | fossil commit -m "regress-c1" |
| 12 | |
| 13 | ############################################################################### |
| 14 | # "fossil test-dir-list" on an empty directory, and on one that does not |
| 15 | # exist, used to crash. |
| 16 | |
| 17 | file mkdir empty-directory |
| 18 | fossil test-dir-list empty-directory |
| 19 | test regress-dir-list-empty {$CODE == 0} |
| 20 | fossil test-dir-list no-such-directory |
| 21 | test regress-dir-list-missing {$CODE == 0} |
| 22 | |
| 23 | ############################################################################### |
| 24 | # "fossil test-xfer" used to print a robot captcha and then crash. |
| 25 | |
| 26 | write_file request.txt "pragma client-versi |
| 27 | fossil test-xfer request.txt |
| 28 | test regress-test-xfer {$CODE == 0} |
| 29 | test_match regress-test-xfer-reply $RESULT {# timestamp} |
| 30 | |
| 31 | ############################################################################### |
| 32 | # A branch name shorter than "date:" was read past its end when it was |
| 33 | # looked up. This shows only in a build with run-time checking. |
| 34 | |
| 35 | fossil branch new br trunk |
| 36 | fossil update br |
| 37 | test regress-short-branch-name {$CODE == 0} |
| 38 | fossil update trunk |
| 39 | |
| 40 | ############################################################################### |
| 41 | # A delta for a target of 2^24 bytes or more that has nothing in common |
| 42 | # with its source overflowed length of the wrong string. This shows |
| 43 | # only in a build with run-time checking. |
| 44 | |
| 45 | file mkdir rel/b rel/c-with-a-longer-name/sub |
| 46 | fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt |
| 47 | test regress-relative-name-sibling \ |
| 48 | {$CODE == 0 |
| 49 | && [string trim $RESULT] eq "../c-with-a-longer-name/sub/file.txt"} |
| 50 | fossil test-relative-name --slash --chdir rel/b ../c-with-a-longer-name/sub/ |
| 51 | test regress-relative-name-sibling-slash \ |
| 52 | {$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"} |
| 53 | |
| 54 | ############################################################################### |
| 55 | # The names of the files in a merge conflict are put into the |
| 56 | # gmerge-command as they are, inside the double quotes that the setting |
| 57 | # has around them. A name with a double quote reached the merge tool as |
| 58 | # several arguments, and one with a dollar sign or a backquote stopped the |
| 59 | # merge. For such a name the tool is now left out, with a warning, and |
| 60 | # the conflict stays marked in the file. The merge tool here is |
| 61 | # standin/log-args.sh, which records its arguments and resolves nothing. |
| 62 | |
| 63 | if {$::tcl_platform(platform) ne "windows"} { |
| 64 | set regressTop [pwd] |
| 65 | set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]] |
| 66 | set regressToolLog [file join $regressTop gmerge-args.txt] |
| 67 | set ::env(ARGS_LOG) $regressToolLog |
| 68 | foreach {regressName regressFile regressRuns} { |
| 69 | plain plain.txt 1 |
| 70 | space {sp ace.txt} 1 |
| 71 | quote {a" "b.txt} 0 |
| 72 | dollar {a$b.txt} 0 |
| 73 | backquote {a`x`b.txt} 0 |
| 74 | } { |
| 75 | file mkdir gmerge-$regressName |
| 76 | cd gmerge-$regressName |
| 77 | fossil init r.fossil |
| 78 | fossil open r.fossil --nested |
| 79 | write_file $regressFile "one\ntwo\nthree\n" |
| 80 | fossil add $regressFile |
| 81 | fossil commit -m base --no-warnings |
| 82 | write_file $regressFile "one\nTWO-branch\nthree\n" |
| 83 | fossil commit -m branch --branch br --no-warnings |
| 84 | fossil update trunk |
| 85 | write_file $regressFile "one\nTWO-trunk\nthree\n" |
| 86 | fossil commit -m trunk --no-warnings |
| 87 | fossil settings gmerge-command \ |
| 88 | "$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\"" |
| 89 | file delete $regressToolLog |
| 90 | fossil_raw merge br |
| 91 | set regressArgs 0 |
| 92 | if {[file exists $regressToolLog]} { |
| 93 | set regressArgs \ |
| 94 | [llength [split [string trim [read_file $regressToolLog]] \n]] |
| 95 | } |
| 96 | set regressMarked \ |
| 97 | [expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}] |
| 98 | set regressWarned \ |
| 99 | [expr {[string first "not running the gmerge-command" $RESULT] >= 0}] |
| 100 | test regress-gmerge-$regressName \ |
| 101 | {$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns |
| 102 | && $regressWarned != $regressRuns} |
| 103 | fossil close --force |
| 104 | cd $regressTop |
| 105 | } |
| 106 | unset ::env(ARGS_LOG) |
| 107 | } |
| 108 | |
| 109 | ############################################################################### |
| 110 | |
| 111 | test_cleanup |
| 112 | write_file tiny.txt "x\n" |
| 113 | write_file big.txt [string repeat "0123456789abcde\n" 1048576] |
| 114 | fossil test-delta-create tiny.txt big.txt big.delta |
| 115 | test regress-large-delta-create {$CODE == 0} |
| 116 | fossil test-delta-apply tiny.txt big.delta big.out |
| 117 | test regress-large-delta-apply {$CODE == 0} |
| 118 | test regress-large-delta-same {[same_file big.txt big.out]} |
| 119 | file delete ########################################################################################################## |
| 120 | # An HTML comment or an HR tag followed by spaces and no newline made the |
| 121 | # Markdown translator copy one byte from past the end of its input into |
| 122 | # the output. That byte was a NUL. |
| 123 | |
| 124 | foreach {regressName regressText} { |
| 125 | hr "<hr> " |
| 126 | comment "<!-- x --> " |
| 127 | quoted "> <hr> " |
| 128 | } { |
| 129 | write_file md-$reg# The output goes to a file and is read back as bytes, so that a NUL |
| 130 | # in it is seen as one. |
| 131 | set regressRc [catch {exec $::fossilexe test-markdown-render \ |
| 132 | md-$regressName.md > md-$regressName.out}] |
| 133 | set regressFd [open md-$regressName.out rb] |
| 134 | set regressOut [read $regressFd] |
| 135 | close $regressFwn-render md-$regressName.md |
| 136 | tesregressRcregressName \ |
| 137 | {$CODE =regressOut] < 0} |
| 138 | } |
| 139 | |
| 140 | ############################################################################### |
| 141 | # "fossil import --svn" took the lengths in a property block from the dump |
| 142 | # file without checking them. A block too short for its end marker was |
| 143 | # read before its start, a negative length made the import run for ever, |
| 144 | # and an oversized one read and wrote outside the block. |
| 145 | |
| 146 | proc regress_svn_rev {regressN:" was read past itset regressLen [string len "Revision-number: $number\nProp-content-length: $length\n" |
| 147 | return "${head}Content-length: $length\n\n$props\n" |
| 148 | } |
| 149 | |
| 150 | proc regress_svn_props {props} { |
| 151 | set block "" |
| 152 | foreach {name value} $props { |
| 153 | append block "K [string length $name]\n$name\n" |
| 154 | append block "V [string length $value]\n$value\n" |
| 155 | } |
| 156 | return "${block}PROPS-END\n" |
| 157 | } |
| 158 | |
| 159 | # Each import has a time limit of 60 seconds, because one of these faults |
| 160 | # was an endless loop. |
| 161 | set regressSvnHead "SVN-fs-dump-format-version: 2\n\nUUID: 0\n\n" |
| 162 | foreach {regressName regressProps} { |
| 163 | short-block "abcd\n" |
| 164 | negative-delete "D -6\nxxxxxxxxxxxxxxxx\nPROPS-END\n" |
| 165 | oversized-key "K 5000\nab\nV 1\nx\nPROPS-END\n" |
| 166 | oversized-value "K 2\nab\nV 99999\nx\nPROPS-END\n" |
| 167 | negative-value "K 2\nab\nV -40\nx\nPROPS-END\n" |
| 168 | } { |
| 169 | write_file svn-$regressName.dump \ |
| 170 | $regressSvnHead[regress_svn_rev 0 $regressProps] |
| 171 | fossil_raw -seconds 60 import --svn svn-$regressName.fossil \ |
| 172 | svn-$regressName.dump |
| 173 | test regress-svn-import-$regressName \ |
| 174 | {$CODE == 1 && [string match "*svn-dump data*" $RESULT]} |
| 175 | file delete svn-$regressName.fossil |
| 176 | } |
| 177 | |
| 178 | set regressSvnDate {svn:date 2026-01-01T00:00:00.000000Z} |
| 179 | set regressSvnSound $regressSvnHead |
| 180 | append regressSvnSound [regress_svn_rev 0 [regress_svn_props $regressSvnDate]] |
| 181 | append regressSvnSound [regress_svn_rev 1 [regress_svn_props \ |
| 182 | [concat {svn:log first svn:author dan} $regressSvnDate]]] |
| 183 | write_file svn-sound.dump $regressSvnSound |
| 184 | fossil import --svn svn-sound.fossil svn-sound.dump |
| 185 | test regress-svn-import-sound {$CODE == 0} |
| 186 | file delete svn-sound.fossil |
| 187 | |
| 188 | ############################################################################### |
| 189 | # Two more faults in the property block of "fossil import --svn". A NUL |
| 190 | # byte in the block made the search for the end of a line fail, which |
| 191 | # crashed the import. A negative length for the block itself was passed |
| 192 | # on as the size of an allocation. |
| 193 | |
| 194 | write_file svn-nul-in-block.dump \ |
| 195 | $regressSvnHead[regress_svn_rev 0 "K\x00\x00\x00PROPS-END\n"] |
| 196 | set regressSvnNegative "Revision-number: 0\nProp-content-length: -5\n" |
| 197 | append regressSvnNegative "Content-length: 10\n\nPROPS-END\n\n" |
| 198 | write_file svn-negative-block.dump $regressSvnHead$regressSvnNegative |
| 199 | foreach regressName {nul-in-block negative-block} { |
| 200 | fossil_raw -seconds 60 import --svn svn-$regressName.fossil \ |
| 201 | svn-$regressName.dump |
| 202 | test regress-svn-import-$regressName \ |
| 203 | {$CODE == 1 && [string match "*svn-dump data format broken*" $RESULT]} |
| 204 | file delete svn-$regressName.fossil |
| 205 | } |
| 206 | |
| 207 | ############################################################################### |
| 208 | # A Markdown header that holds an HTML comment was read past its end when |
| 209 | # its id was made. This shows only in a build with run-time checking. |
| 210 | |
| 211 | write_file md-header.md "intro\n\n# a <!-- -->\n" |
| 212 | fossil test-markdown-render md-header.md |
| 213 | test regress-markdown-header-comment \ |
| 214 | {$CODE == 0 && [string first {<h1 id="a">} $RESULT] >= 0} |
| 215 | |
| 216 | ############################################################################### |
| 217 | # The name of a file in a sibling directory, relative to the current |
| 218 | # directory, was copied with the length of the wrong string. This shows |
| 219 | # only in a build with run-time checking. |
| 220 | |
| 221 | file mkdir rel/b rel/c-with-a-longer-name/sub |
| 222 | fossil test-relative-name --chdir rel/b ../c-with-a-longer-name/sub/file.txt |
| 223 | test regress-relative-name-sibling \ |
| 224 | {$CODE == 0 |
| 225 | && [string trim $RESULT] eq "../c-with-a-longer-name/sub/file.txt"} |
| 226 | fossil test-relative-name --slash --chdir rel/b ../c-with-a-longer-name/sub/ |
| 227 | test regress-relative-name-sibling-slash \ |
| 228 | {$CODE == 0 && [string trim $RESULT] eq "../c-with-a-longer-name/sub/"} |
| 229 | |
| 230 | ############################################################################### |
| 231 | # The names of the files in a merge conflict are put into the |
| 232 | # gmerge-command as they are, inside the double quotes that the setting |
| 233 | # has around them. A name with a double quote reached the merge tool as |
| 234 | # several arguments, and one with a dollar sign or a backquote stopped the |
| 235 | # merge. For such a name the tool is now left out, with a warning, and |
| 236 | # the conflict stays marked in the file. The merge tool here is |
| 237 | # standin/log-args.sh, which records its arguments and resolves nothing. |
| 238 | |
| 239 | if {$::tcl_platform(platform) ne "windows"} { |
| 240 | set regressTop [pwd] |
| 241 | set regressTool [test_standin log-args.sh [file join $regressTop gmerge.sh]] |
| 242 | set regressToolLog [file join $regressTop gmerge-args.txt] |
| 243 | set ::env(ARGS_LOG) $regressToolLog |
| 244 | foreach {regressName regressFile regressRuns} { |
| 245 | plain plain.txt 1 |
| 246 | space {sp ace.txt} 1 |
| 247 | quote {a" "b.txt} 0 |
| 248 | dollar {a$b.txt} 0 |
| 249 | backquote {a`x`b.txt} 0 |
| 250 | } { |
| 251 | file mkdir gmerge-$regressName |
| 252 | cd gmerge-$regressName |
| 253 | fossil init r.fossil |
| 254 | fossil open r.fossil --nested |
| 255 | write_file $regressFile "one\ntwo\nthree\n" |
| 256 | fossil add $regressFile |
| 257 | fossil commit -m base --no-warnings |
| 258 | write_file $regressFile "one\nTWO-branch\nthree\n" |
| 259 | fossil commit -m branch --branch br --no-warnings |
| 260 | fossil update trunk |
| 261 | write_file $regressFile "one\nTWO-trunk\nthree\n" |
| 262 | fossil commit -m trunk --no-warnings |
| 263 | fossil settings gmerge-command \ |
| 264 | "$regressTool \"%baseline\" \"%original\" \"%merge\" \"%output\"" |
| 265 | file delete $regressToolLog |
| 266 | fossil_raw merge br |
| 267 | set regressArgs 0 |
| 268 | if {[file exists $regressToolLog]} { |
| 269 | set regressArgs \ |
| 270 | [llength [split [string trim [read_file $regressToolLog]] \n]] |
| 271 | } |
| 272 | set regressMarked \ |
| 273 | [expr {[string first "<<<<<<<" [read_file $regressFile]] >= 0}] |
| 274 | set regressWarned \ |
| 275 | [expr {[string first "not running the gmerge-command" $RESULT] >= 0}] |
| 276 | test regress-gmerge-$regressName \ |
| 277 | {$CODE == 0 && $regressMarked && $regressArgs == 4*$regressRuns |
| 278 | && $regressWarned != $regressRuns} |
| 279 | fossil close --force |
| 280 | cd $regressTop |
| 281 | } |
| 282 | unset ::env(ARGS_LOG) |
| 283 | } |
| 284 | |
| 285 | ############################################################################### |
| 286 | |
| 287 | test_cleanup |
| 288 | regressNd "Revision-number: $numregressLen\nContent-length: $regressLen\n\n$regressProps\n" |
| 289 | } |
| 290 | # Run fossil with the arguments given and a time limit in seconds, because |
| 291 | # one of these faults##################### The result is the exit status, |
| 292 | # or -1 if the limit ran out, followed by the output. |
| 293 | proc regress_read {regressFd} { |
| 294 | append ::regressOutput [read $regressFd] |
| 295 | if {[eof $regressFd]} {set ::regressState done} |
| 296 | } |
| 297 | proc regress_limited {regressSeconds args} { |
| 298 | set ::regressOutput "" |
| 299 | set ::regressState running |
| 300 | set regressFd [open "|[linsert $args 0 $::fossilexe] 2>@1" r] |
| 301 | fconfigure $regressFd -blocking 0 |
| 302 | fileevent $regressFd readable [list regress_read $regressFd] |
| 303 | set rwn-rendeeconds*1000}] \ |
| 304 |
+439
| --- a/test/scenario.test | ||
| +++ b/test/scenario.test | ||
| @@ -0,0 +1,439 @@ | ||
| 1 | +# | |
| 2 | +# Random integration tests of sync. Each scenario input in corpus/corpus.pack | |
| 3 | +# is a list of operations to perform on three clones of a new repository: | |
| 4 | +# commits, branches, merges, syncs and so on. A sync can be made to lose | |
| 5 | +# its request, lose its reply, or deliver half a reply. | |
| 6 | +# | |
| 7 | +# A sync, pull, push or clone that is not made to go wrong must succeed | |
| 8 | +# and must deliver: straight afterwards the receiving clone must hold | |
| 9 | +# everything the sending clone holds. Any other operation may fail in | |
| 10 | +# the ordinary way, because many random operations are not valid: a | |
| 11 | +# commit with nothing changed, a branch that already exists. No command | |
| 12 | +# may crash or run for more than two minutes. | |
| 13 | +# | |
| 14 | +# At the end the clones are synced along the chain 0-1-2, so that | |
| 15 | +# whatever clones 0 and 2 learn of each other has to pass through clone | |
| 16 | +# 1. Each must then pass test-integrity and test-missing, and all three | |
| 17 | +# must hold the same artifacts and the same unversioned files. | |
| 18 | +# | |
| 19 | +# An input is a list of four-byte records: operation, clone, argument, | |
| 20 | +# option. See scenario_run below for what each means. | |
| 21 | +# | |
| 22 | +# To run random inputs as well as the files, set the environment variable | |
| 23 | +# FOSSIL_SCENARIO_RANDOM to how many. Each is made from a seed, which is | |
| 24 | +# printed with its result. FOSSIL_SCENARIO_SEED sets the first seed, so | |
| 25 | +# that a failing run can be repeated. | |
| 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] | |
| 41 | +set scenarioSeconds 120 ;# time allowed for any one command | |
| 42 | +set scenarioMaxOps 64 ;# use at most this many records of an input | |
| 43 | + | |
| 44 | +# Make a sanitizer end the program with abort(), so that its report is | |
| 45 | +# told from an ordinary failure, and give the commits a user name. The | |
| 46 | +# environment is put back at the end. | |
| 47 | +# | |
| 48 | +foreach {scenarioVar scenarioOpt} { | |
| 49 | + ASAN_OPTIONS abort_on_error=1 | |
| 50 | + UBSAN_OPTIONS halt_on_error=1:abort_on_error=1 | |
| 51 | + USER scenario | |
| 52 | +} { | |
| 53 | + if {![info exists ::env($scenarioVar)]} { | |
| 54 | + set ::env($scenarioVar) $scenarioOpt | |
| 55 | + continue | |
| 56 | + } | |
| 57 | + set scenarioSaved($scenarioVar) $::env($scenarioVar) | |
| 58 | + if {$scenarioVar eq "USER"} { | |
| 59 | + set ::env(USER) $scenarioOpt | |
| 60 | + } elseif {![string match *abort_on_error* $::env($scenarioVar)]} { | |
| 61 | + append ::env($scenarioVar) :$scenarioOpt | |
| 62 | + } | |
| 63 | +} | |
| 64 | + | |
| 65 | +# Stop the scenario because it has found a problem. | |
| 66 | +# | |
| 67 | +proc scenario_fail {msg} { | |
| 68 | + return -code error -errorcode SCENARIO $msg | |
| 69 | +} | |
| 70 | + | |
| 71 | +# Run fossil with the arguments given in subdirectory $sub of the | |
| 72 | +# scenario. Return 0 if it succeeds and 1 if it fails in the ordinary | |
| 73 | +# way. A crash or a command that does not finish is a problem found. | |
| 74 | +# The output is left in scenarioOut and added to the log. | |
| 75 | +# | |
| 76 | +proc scenario_fossil {sub args} { | |
| 77 | + global scenarioDir scenarioSeconds scenarioOut scenarioLog CODE RESULT | |
| 78 | + cd [file join $scenarioDir $sub] | |
| 79 | + fossil_raw -seconds $scenarioSeconds {*}$args | |
| 80 | + cd $scenarioDir | |
| 81 | + set scenarioOut $RESULT | |
| 82 | + lappend scenarioLog "+ $sub: fossil $args" $scenarioOut | |
| 83 | + if {$CODE eq "timeout"} { | |
| 84 | + scenario_fail "a command did not finish in $scenarioSeconds seconds:\ | |
| 85 | + fossil $args" | |
| 86 | + } | |
| 87 | + if {$CODE eq "crash"} { | |
| 88 | + scenario_fail "a command crashed: fossil $args" | |
| 89 | + } | |
| 90 | + return [expr {$CODE != 0}] | |
| 91 | +} | |
| 92 | + | |
| 93 | +# Run a fossil command that must succeed. | |
| 94 | +# | |
| 95 | +proc scenario_must {sub args} { | |
| 96 | + if {[scenario_fossil $sub {*}$args]} { | |
| 97 | + scenario_fail "a command that must succeed has failed: fossil $args" | |
| 98 | + } | |
| 99 | +} | |
| 100 | + | |
| 101 | +# The number that one SQL query on clone $i gives. | |
| 102 | +# | |
| 103 | +proc scenario_count {i sql} { | |
| 104 | + global scenarioOut | |
| 105 | + scenario_must . sql -R r$i.fossil $sql | |
| 106 | + set n [string trim $scenarioOut] | |
| 107 | + if {![string is integer -strict $n]} { | |
| 108 | + scenario_fail "a count is not a number: $n" | |
| 109 | + } | |
| 110 | + return $n | |
| 111 | +} | |
| 112 | + | |
| 113 | +# Add a line to a file in checkout $i, or replace the file by the line. | |
| 114 | +# | |
| 115 | +proc scenario_write {i name line {mode a}} { | |
| 116 | + global scenarioDir | |
| 117 | + set fd [open [file join $scenarioDir c$i $name] $mode] | |
| 118 | + puts $fd $line | |
| 119 | + close $fd | |
| 120 | +} | |
| 121 | + | |
| 122 | +# Commit whatever has changed in checkout $i. Every commit has a later | |
| 123 | +# date than the one before, so that the result does not depend on the | |
| 124 | +# clock. | |
| 125 | +# | |
| 126 | +proc scenario_commit {i} { | |
| 127 | + global scenarioCommits | |
| 128 | + set n [incr scenarioCommits] | |
| 129 | + set date [format "2026-01-%02d %02d:%02d:00" \ | |
| 130 | + [expr {2+$n/1440}] [expr {($n/60)%24}] [expr {$n%60}]] | |
| 131 | + return [scenario_fossil c$i commit -m "commit $n" --no-warnings \ | |
| 132 | + --allow-fork --allow-conflict --allow-older --date-override $date] | |
| 133 | +} | |
| 134 | + | |
| 135 | +# Open a checkout of clone $i in a new directory. | |
| 136 | +# | |
| 137 | +proc scenario_open {i} { | |
| 138 | + global scenarioDir | |
| 139 | + file mkdir [file join $scenarioDir c$i] | |
| 140 | + scenario_must c$i open ../r$i.fossil | |
| 141 | + scenario_must c$i settings autosync off | |
| 142 | + scenario_must c$i uv list | |
| 143 | +} | |
| 144 | + | |
| 145 | +# Require that clone $have holds every public artifact that clone $of | |
| 146 | +# holds, and every unversioned file too if $uv is true. $when says what | |
| 147 | +# has just been done. | |
| 148 | +# | |
| 149 | +# An artifact that clone $of holds only as a delta from something it is | |
| 150 | +# still waiting for does not count: it cannot be sent until its source | |
| 151 | +# arrives. A sync that lost its reply can leave one behind. | |
| 152 | +# | |
| 153 | +proc scenario_holds {have of uv when} { | |
| 154 | + set n [scenario_count $have "ATTACH 'r$of.fossil' AS o; | |
| 155 | + WITH RECURSIVE waiting(rid) AS ( | |
| 156 | + SELECT rid FROM o.delta | |
| 157 | + WHERE srcid IN (SELECT rid FROM o.blob WHERE size<0) | |
| 158 | + UNION SELECT d.rid FROM o.delta d, waiting w WHERE d.srcid=w.rid) | |
| 159 | + SELECT count(*) FROM o.blob WHERE size>=0 | |
| 160 | + AND rid NOT IN (SELECT rid FROM o.private) | |
| 161 | + AND rid NOT IN waiting | |
| 162 | + AND uuid NOT IN (SELECT uuid FROM blob WHERE size>=0)"] | |
| 163 | + if {$n > 0} { | |
| 164 | + scenario_fail "$when, clone $have lacks $n artifacts that clone $of holds" | |
| 165 | + } | |
| 166 | + if {$uv} { | |
| 167 | + set n [scenario_count $have "ATTACH 'r$of.fossil' AS o; | |
| 168 | + SELECT count(*) FROM o.unversioned WHERE hash IS NOT NULL | |
| 169 | + AND name||'/'||hash NOT IN (SELECT name||'/'||hash FROM unversioned | |
| 170 | + WHERE hash IS NOT NULL)"] | |
| 171 | + if {$n > 0} { | |
| 172 | + scenario_fail "$when, clone $have lacks $n unversioned files that\ | |
| 173 | + clone $of holds" | |
| 174 | + } | |
| 175 | + } | |
| 176 | +} | |
| 177 | + | |
| 178 | +# Run the scenario whose records are the bytes of $data. The result is | |
| 179 | +# an empty string, or what went wrong. | |
| 180 | +# | |
| 181 | +proc scenario_run {name data} { | |
| 182 | + global scenarioTop scenarioDir scenarioLog scenarioCommits scenarioMaxOps | |
| 183 | + set scenarioDir [file join $scenarioTop $name] | |
| 184 | + set scenarioLog {} | |
| 185 | + set scenarioCommits 0 | |
| 186 | + file mkdir $scenarioDir | |
| 187 | + cd $scenarioDir | |
| 188 | + set rc [catch {scenario_steps $data} msg opts] | |
| 189 | + cd $scenarioTop | |
| 190 | + if {!$rc} { | |
| 191 | + file delete -force $scenarioDir | |
| 192 | + return "" | |
| 193 | + } | |
| 194 | + if {[dict get $opts -errorcode] ne "SCENARIO"} { | |
| 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} { | |
| 206 | + global scenarioDir scenarioMaxOps scenarioOut | |
| 207 | + | |
| 208 | + # The script that carries a sync that is to go wrong | |
| 209 | + # It is run with tclsh, so it needs no permission to be executed. | |
| 210 | + set wire [file join $scenarioDir wire.tcl] | |
| 211 | + file copy [file join $::testfiledir standin scenario-wire.tcl] $wire | |
| 212 | + set wire "\"[info nameofexecutable]\" \"$wire\"" | |
| 213 | + | |
| 214 | + # One repository with one check-in, cloned twice | |
| 215 | + scenario_must . init r0.fossil -A scenario \ | |
| 216 | + --date-override "2026-01-01 00:00:00" | |
| 217 | + foreach i {0 1 2} { | |
| 218 | + if {$i > 0} {scenario_must . clone r0.fossil r$i.fossil} | |
| 219 | + scenario_open $i | |
| 220 | + if {$i == 0} { | |
| 221 | + foreach x {0 1 2} { | |
| 222 | + foreach y {1 2 3 4 5 6 7 8 9} { | |
| 223 | + scenario_write 0 f$x.txt "file $x line $y" | |
| 224 | + } | |
| 225 | + } | |
| 226 | + scenario_must c0 add f0.txt f1.txt f2.txt | |
| 227 | + if {[scenario_commit 0]} {scenario_fail "the first commit failed"} | |
| 228 | + } | |
| 229 | + } | |
| 230 | + | |
| 231 | + # Do the operations | |
| 232 | + set nOp [expr {min([string length $data]/4, $scenarioMaxOps)}] | |
| 233 | + for {set i 0} {$i < $nOp} {incr i} { | |
| 234 | + binary scan $data "@[expr {$i*4}]cu4" rec | |
| 235 | + lassign $rec op me a opt | |
| 236 | + set me [expr {$me % 3}] | |
| 237 | + set ck c$me | |
| 238 | + set peer [expr {($me + 1 + $a%2) % 3}] | |
| 239 | + switch [expr {$op % 14}] { | |
| 240 | + 0 - 1 { ;# Change a file and commit | |
| 241 | + scenario_write $me f[expr {$a%3}].txt "change $i" | |
| 242 | + scenario_commit $me | |
| 243 | + } | |
| 244 | + 2 { ;# Add a file and commit | |
| 245 | + scenario_write $me n[expr {$a%8}].txt "new $i" | |
| 246 | + scenario_fossil $ck add n[expr {$a%8}].txt | |
| 247 | + scenario_commit $me | |
| 248 | + } | |
| 249 | + 3 { ;# Remove a file and commit | |
| 250 | + if {![scenario_fossil $ck rm --hard f[expr {$a%3}].txt]} { | |
| 251 | + scenario_commit $me | |
| 252 | + } | |
| 253 | + } | |
| 254 | + 4 { ;# Start a branch, or move to one that exists | |
| 255 | + scenario_fossil $ck branch new b[expr {$a%4}] current | |
| 256 | + scenario_fossil $ck update b[expr {$a%4}] | |
| 257 | + } | |
| 258 | + 5 { ;# Merge a branch or trunk and commit | |
| 259 | + if {$a & 0x80} { | |
| 260 | + scenario_fossil $ck merge trunk | |
| 261 | + } else { | |
| 262 | + scenario_fossil $ck merge b[expr {$a%4}] | |
| 263 | + } | |
| 264 | + scenario_commit $me | |
| 265 | + } | |
| 266 | + 6 { ;# Sync, pull or push with another clone | |
| 267 | + set verb [lindex {sync pull push} [expr {$opt%3}]] | |
| 268 | + set fault [expr {($opt/3) % 5}] | |
| 269 | + # Only "sync" takes -u. The option bit is ignored otherwise. | |
| 270 | + set uv [expr {($opt & 0x80) && $verb eq "sync"}] | |
| 271 | + set args [list $verb] | |
| 272 | + if {$fault == 0} { | |
| 273 | + lappend args ../r$peer.fossil | |
| 274 | + } else { | |
| 275 | + lappend args http://scenario.invalid/x --once \ | |
| 276 | + --transport-command $wire | |
| 277 | + } | |
| 278 | + if {$uv} {lappend args -u} | |
| 279 | + if {$fault == 0} { | |
| 280 | + scenario_must $ck {*}$args | |
| 281 | + } else { | |
| 282 | + # Fault 4 is the script with no fault, to show that it works | |
| 283 | + set ::env(SCN_EXE) $::fossilexe | |
| 284 | + set ::env(SCN_REPO) [file join $scenarioDir r$peer.fossil] | |
| 285 | + set ::env(SCN_FAULT) $fault | |
| 286 | + set rc [catch {scenario_fossil $ck {*}$args} failed opts] | |
| 287 | + unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) | |
| 288 | + if {$rc} {return -options $opts $failed} | |
| 289 | + if {$fault == 4 && $failed} { | |
| 290 | + scenario_fail "a sync through the wire script, with no fault,\ | |
| 291 | + failed" | |
| 292 | + } | |
| 293 | + if {($fault == 1 || $fault == 2) && !$failed} { | |
| 294 | + scenario_fail "a sync that got no reply reported success" | |
| 295 | + } | |
| 296 | + } | |
| 297 | + if {$fault == 0 || $fault == 4} { | |
| 298 | + if {$verb ne "push"} {scenario_holds $me $peer $uv $verb} | |
| 299 | + if {$verb ne "pull"} {scenario_holds $peer $me $uv $verb} | |
| 300 | + } | |
| 301 | + } | |
| 302 | + 7 { ;# Update the checkout | |
| 303 | + if {$a & 1} { | |
| 304 | + scenario_fossil $ck update trunk | |
| 305 | + } else { | |
| 306 | + scenario_fossil $ck update | |
| 307 | + } | |
| 308 | + } | |
| 309 | + 8 { ;# Add a tag | |
| 310 | + scenario_fossil $ck tag add t[expr {$a%4}] current | |
| 311 | + } | |
| 312 | + 9 { ;# Rebuild | |
| 313 | + scenario_fossil . rebuild r$me.fossil | |
| 314 | + } | |
| 315 | + 10 { ;# Change how much this clone will send in one message | |
| 316 | + set limits {250000 20000 2000 300} | |
| 317 | + scenario_fossil . sql -R r$me.fossil "REPLACE INTO | |
| 318 | + config(name,value,mtime) | |
| 319 | + VALUES('max-upload',[lindex $limits [expr {$a%4}]],0), | |
| 320 | + ('max-download',[lindex $limits [expr {($a/4)%4}]],0)" | |
| 321 | + } | |
| 322 | + 11 { ;# Commit many files at once | |
| 323 | + file mkdir [file join $scenarioDir $ck d$i] | |
| 324 | + set n [expr {40 + 40*($a%4)}] | |
| 325 | + for {set k 0} {$k < $n} {incr k} { | |
| 326 | + scenario_write $me d$i/b$k.txt "bulk $i file $k" | |
| 327 | + } | |
| 328 | + scenario_fossil $ck add d$i | |
| 329 | + scenario_commit $me | |
| 330 | + } | |
| 331 | + 12 { ;# Add or change an unversioned file | |
| 332 | + scenario_write $me u[expr {$a%16}].txt "unversioned $i" w | |
| 333 | + scenario_fossil $ck uv add u[expr {$a%16}].txt --mtime \ | |
| 334 | + [format "2026-01-01 %02d:%02d:%02d" [expr {$i/60}] \ | |
| 335 | + [expr {$i%60}] $me] | |
| 336 | + } | |
| 337 | + 13 { ;# Replace this clone by a new clone of another | |
| 338 | + # Skip the operation if the source is waiting for anything. | |
| 339 | + # "fossil clone" refuses a source that holds a delta from | |
| 340 | + # something missing, and a check-in with a missing file cannot | |
| 341 | + # be checked out of the new clone. | |
| 342 | + if {[scenario_count $peer "SELECT count(*) FROM phantom"]} continue | |
| 343 | + # Also skip it if this clone holds something that neither of the | |
| 344 | + # others holds. Throwing away the only copy of an artifact would | |
| 345 | + # leave the others waiting for it for ever, and that would be the | |
| 346 | + # fault of this test, not of Fossil. | |
| 347 | + set o1 [expr {($me+1)%3}] | |
| 348 | + set o2 [expr {($me+2)%3}] | |
| 349 | + if {[scenario_count $me "ATTACH 'r$o1.fossil' AS o1; | |
| 350 | + ATTACH 'r$o2.fossil' AS o2; | |
| 351 | + SELECT count(*) FROM blob WHERE size>=0 | |
| 352 | + AND uuid NOT IN (SELECT uuid FROM o1.blob WHERE size>=0) | |
| 353 | + AND uuid NOT IN (SELECT uuid FROM o2.blob WHERE size>=0)"]} { | |
| 354 | + continue | |
| 355 | + } | |
| 356 | + set uv [expr {($a & 0x80) != 0}] | |
| 357 | + scenario_fossil $ck close --force | |
| 358 | + file delete -force [file join $scenarioDir $ck] \ | |
| 359 | + [file join $scenarioDir r$me.fossil] | |
| 360 | + if {$uv} { | |
| 361 | + scenario_must . clone r$peer.fossil r$me.fossil -u | |
| 362 | + } else { | |
| 363 | + scenario_must . clone r$peer.fossil r$me.fossil | |
| 364 | + } | |
| 365 | + scenario_open $me | |
| 366 | + scenario_holds $me $peer $uv clone | |
| 367 | + } | |
| 368 | + } | |
| 369 | + } | |
| 370 | + | |
| 371 | + # Sync along the chain 0-1-2 until nothing more can move. One pass | |
| 372 | + # each way is enough; two more guard the count. | |
| 373 | + foreach pass {1 2 3} { | |
| 374 | + scenario_must c0 sync -u ../r1.fossil | |
| 375 | + scenario_must c1 sync -u ../r2.fossil | |
| 376 | + scenario_must c2 sync -u ../r1.fossil | |
| 377 | + scenario_must c1 sync -u ../r0.fossil | |
| 378 | + } | |
| 379 | + | |
| 380 | + # Every clone must be sound, and all must hold the same artifacts | |
| 381 | + foreach i {0 1 2} { | |
| 382 | + scenario_must . test-integrity --parse -R r$i.fossil | |
| 383 | + scenario_must . test-missing -R r$i.fossil | |
| 384 | + scenario_must . sql -R r$i.fossil "SELECT uuid FROM blob WHERE size>=0 | |
| 385 | + AND rid NOT IN private ORDER BY 1; | |
| 386 | + SELECT 'uv', name, hash FROM unversioned | |
| 387 | + WHERE hash IS NOT NULL ORDER BY 2" | |
| 388 | + set held($i) [string trim $scenarioOut] | |
| 389 | + if {$held($i) eq ""} {scenario_fail "clone $i lists no artifacts"} | |
| 390 | + if {$i > 0 && $held($i) ne $held(0)} { | |
| 391 | + scenario_fail "clones 0 and $i hold different artifacts or\ | |
| 392 | + unversioned files after syncing" | |
| 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] "" | |
| 406 | +} | |
| 407 | + | |
| 408 | +# Random inputs, on request. The generator is written out here so that a | |
| 409 | +# seed gives the same input with every version of Tcl. | |
| 410 | +# | |
| 411 | +if {[info exists ::env(FOSSIL_SCENARIO_RANDOM)]} { | |
| 412 | + set scenarioSeed [clock seconds] | |
| 413 | + if {[info exists ::env(FOSSIL_SCENARIO_SEED)]} { | |
| 414 | + set scenarioSeed $::env(FOSSIL_SCENARIO_SEED) | |
| 415 | + } | |
| 416 | + for {set scenarioN 0} {$scenarioN < $::env(FOSSIL_SCENARIO_RANDOM)} \ | |
| 417 | + {incr scenarioN; incr scenarioSeed} { | |
| 418 | + set scenarioX $scenarioSeed | |
| 419 | + set scenarioData "" | |
| 420 | + for {set scenarioK 0} {$scenarioK < 4*$scenarioMaxOps} {incr scenarioK} { | |
| 421 | + set scenarioX [expr {($scenarioX*1103515245 + 12345) & 0x7fffffff}] | |
| 422 | + append scenarioData [binary format c [expr {($scenarioX>>16) & 255}]] | |
| 423 | + } | |
| 424 | + test_eq scenario-seed-$scenarioSeed \ | |
| 425 | + [scenario_run seed-$scenarioSeed $scenarioData] "" | |
| 426 | + } | |
| 427 | +} | |
| 428 | + | |
| 429 | +foreach scenarioVar {ASAN_OPTIONS UBSAN_OPTIONS USER} { | |
| 430 | + if {[info exists scenarioSaved($scenarioVar)]} { | |
| 431 | + set ::env($scenarioVar) $scenarioSaved($scenarioVar) | |
| 432 | + } else { | |
| 433 | + unset ::env($scenarioVar) | |
| 434 | + } | |
| 435 | +} | |
| 436 | + | |
| 437 | +############################################################################### | |
| 438 | + | |
| 439 | +test_cleanup |
| --- a/test/scenario.test | |
| +++ b/test/scenario.test | |
| @@ -0,0 +1,439 @@ | |
| --- a/test/scenario.test | |
| +++ b/test/scenario.test | |
| @@ -0,0 +1,439 @@ | |
| 1 | # |
| 2 | # Random integration tests of sync. Each scenario input in corpus/corpus.pack |
| 3 | # is a list of operations to perform on three clones of a new repository: |
| 4 | # commits, branches, merges, syncs and so on. A sync can be made to lose |
| 5 | # its request, lose its reply, or deliver half a reply. |
| 6 | # |
| 7 | # A sync, pull, push or clone that is not made to go wrong must succeed |
| 8 | # and must deliver: straight afterwards the receiving clone must hold |
| 9 | # everything the sending clone holds. Any other operation may fail in |
| 10 | # the ordinary way, because many random operations are not valid: a |
| 11 | # commit with nothing changed, a branch that already exists. No command |
| 12 | # may crash or run for more than two minutes. |
| 13 | # |
| 14 | # At the end the clones are synced along the chain 0-1-2, so that |
| 15 | # whatever clones 0 and 2 learn of each other has to pass through clone |
| 16 | # 1. Each must then pass test-integrity and test-missing, and all three |
| 17 | # must hold the same artifacts and the same unversioned files. |
| 18 | # |
| 19 | # An input is a list of four-byte records: operation, clone, argument, |
| 20 | # option. See scenario_run below for what each means. |
| 21 | # |
| 22 | # To run random inputs as well as the files, set the environment variable |
| 23 | # FOSSIL_SCENARIO_RANDOM to how many. Each is made from a seed, which is |
| 24 | # printed with its result. FOSSIL_SCENARIO_SEED sets the first seed, so |
| 25 | # that a failing run can be repeated. |
| 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] |
| 41 | set scenarioSeconds 120 ;# time allowed for any one command |
| 42 | set scenarioMaxOps 64 ;# use at most this many records of an input |
| 43 | |
| 44 | # Make a sanitizer end the program with abort(), so that its report is |
| 45 | # told from an ordinary failure, and give the commits a user name. The |
| 46 | # environment is put back at the end. |
| 47 | # |
| 48 | foreach {scenarioVar scenarioOpt} { |
| 49 | ASAN_OPTIONS abort_on_error=1 |
| 50 | UBSAN_OPTIONS halt_on_error=1:abort_on_error=1 |
| 51 | USER scenario |
| 52 | } { |
| 53 | if {![info exists ::env($scenarioVar)]} { |
| 54 | set ::env($scenarioVar) $scenarioOpt |
| 55 | continue |
| 56 | } |
| 57 | set scenarioSaved($scenarioVar) $::env($scenarioVar) |
| 58 | if {$scenarioVar eq "USER"} { |
| 59 | set ::env(USER) $scenarioOpt |
| 60 | } elseif {![string match *abort_on_error* $::env($scenarioVar)]} { |
| 61 | append ::env($scenarioVar) :$scenarioOpt |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | # Stop the scenario because it has found a problem. |
| 66 | # |
| 67 | proc scenario_fail {msg} { |
| 68 | return -code error -errorcode SCENARIO $msg |
| 69 | } |
| 70 | |
| 71 | # Run fossil with the arguments given in subdirectory $sub of the |
| 72 | # scenario. Return 0 if it succeeds and 1 if it fails in the ordinary |
| 73 | # way. A crash or a command that does not finish is a problem found. |
| 74 | # The output is left in scenarioOut and added to the log. |
| 75 | # |
| 76 | proc scenario_fossil {sub args} { |
| 77 | global scenarioDir scenarioSeconds scenarioOut scenarioLog CODE RESULT |
| 78 | cd [file join $scenarioDir $sub] |
| 79 | fossil_raw -seconds $scenarioSeconds {*}$args |
| 80 | cd $scenarioDir |
| 81 | set scenarioOut $RESULT |
| 82 | lappend scenarioLog "+ $sub: fossil $args" $scenarioOut |
| 83 | if {$CODE eq "timeout"} { |
| 84 | scenario_fail "a command did not finish in $scenarioSeconds seconds:\ |
| 85 | fossil $args" |
| 86 | } |
| 87 | if {$CODE eq "crash"} { |
| 88 | scenario_fail "a command crashed: fossil $args" |
| 89 | } |
| 90 | return [expr {$CODE != 0}] |
| 91 | } |
| 92 | |
| 93 | # Run a fossil command that must succeed. |
| 94 | # |
| 95 | proc scenario_must {sub args} { |
| 96 | if {[scenario_fossil $sub {*}$args]} { |
| 97 | scenario_fail "a command that must succeed has failed: fossil $args" |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | # The number that one SQL query on clone $i gives. |
| 102 | # |
| 103 | proc scenario_count {i sql} { |
| 104 | global scenarioOut |
| 105 | scenario_must . sql -R r$i.fossil $sql |
| 106 | set n [string trim $scenarioOut] |
| 107 | if {![string is integer -strict $n]} { |
| 108 | scenario_fail "a count is not a number: $n" |
| 109 | } |
| 110 | return $n |
| 111 | } |
| 112 | |
| 113 | # Add a line to a file in checkout $i, or replace the file by the line. |
| 114 | # |
| 115 | proc scenario_write {i name line {mode a}} { |
| 116 | global scenarioDir |
| 117 | set fd [open [file join $scenarioDir c$i $name] $mode] |
| 118 | puts $fd $line |
| 119 | close $fd |
| 120 | } |
| 121 | |
| 122 | # Commit whatever has changed in checkout $i. Every commit has a later |
| 123 | # date than the one before, so that the result does not depend on the |
| 124 | # clock. |
| 125 | # |
| 126 | proc scenario_commit {i} { |
| 127 | global scenarioCommits |
| 128 | set n [incr scenarioCommits] |
| 129 | set date [format "2026-01-%02d %02d:%02d:00" \ |
| 130 | [expr {2+$n/1440}] [expr {($n/60)%24}] [expr {$n%60}]] |
| 131 | return [scenario_fossil c$i commit -m "commit $n" --no-warnings \ |
| 132 | --allow-fork --allow-conflict --allow-older --date-override $date] |
| 133 | } |
| 134 | |
| 135 | # Open a checkout of clone $i in a new directory. |
| 136 | # |
| 137 | proc scenario_open {i} { |
| 138 | global scenarioDir |
| 139 | file mkdir [file join $scenarioDir c$i] |
| 140 | scenario_must c$i open ../r$i.fossil |
| 141 | scenario_must c$i settings autosync off |
| 142 | scenario_must c$i uv list |
| 143 | } |
| 144 | |
| 145 | # Require that clone $have holds every public artifact that clone $of |
| 146 | # holds, and every unversioned file too if $uv is true. $when says what |
| 147 | # has just been done. |
| 148 | # |
| 149 | # An artifact that clone $of holds only as a delta from something it is |
| 150 | # still waiting for does not count: it cannot be sent until its source |
| 151 | # arrives. A sync that lost its reply can leave one behind. |
| 152 | # |
| 153 | proc scenario_holds {have of uv when} { |
| 154 | set n [scenario_count $have "ATTACH 'r$of.fossil' AS o; |
| 155 | WITH RECURSIVE waiting(rid) AS ( |
| 156 | SELECT rid FROM o.delta |
| 157 | WHERE srcid IN (SELECT rid FROM o.blob WHERE size<0) |
| 158 | UNION SELECT d.rid FROM o.delta d, waiting w WHERE d.srcid=w.rid) |
| 159 | SELECT count(*) FROM o.blob WHERE size>=0 |
| 160 | AND rid NOT IN (SELECT rid FROM o.private) |
| 161 | AND rid NOT IN waiting |
| 162 | AND uuid NOT IN (SELECT uuid FROM blob WHERE size>=0)"] |
| 163 | if {$n > 0} { |
| 164 | scenario_fail "$when, clone $have lacks $n artifacts that clone $of holds" |
| 165 | } |
| 166 | if {$uv} { |
| 167 | set n [scenario_count $have "ATTACH 'r$of.fossil' AS o; |
| 168 | SELECT count(*) FROM o.unversioned WHERE hash IS NOT NULL |
| 169 | AND name||'/'||hash NOT IN (SELECT name||'/'||hash FROM unversioned |
| 170 | WHERE hash IS NOT NULL)"] |
| 171 | if {$n > 0} { |
| 172 | scenario_fail "$when, clone $have lacks $n unversioned files that\ |
| 173 | clone $of holds" |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | # Run the scenario whose records are the bytes of $data. The result is |
| 179 | # an empty string, or what went wrong. |
| 180 | # |
| 181 | proc scenario_run {name data} { |
| 182 | global scenarioTop scenarioDir scenarioLog scenarioCommits scenarioMaxOps |
| 183 | set scenarioDir [file join $scenarioTop $name] |
| 184 | set scenarioLog {} |
| 185 | set scenarioCommits 0 |
| 186 | file mkdir $scenarioDir |
| 187 | cd $scenarioDir |
| 188 | set rc [catch {scenario_steps $data} msg opts] |
| 189 | cd $scenarioTop |
| 190 | if {!$rc} { |
| 191 | file delete -force $scenarioDir |
| 192 | return "" |
| 193 | } |
| 194 | if {[dict get $opts -errorcode] ne "SCENARIO"} { |
| 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} { |
| 206 | global scenarioDir scenarioMaxOps scenarioOut |
| 207 | |
| 208 | # The script that carries a sync that is to go wrong |
| 209 | # It is run with tclsh, so it needs no permission to be executed. |
| 210 | set wire [file join $scenarioDir wire.tcl] |
| 211 | file copy [file join $::testfiledir standin scenario-wire.tcl] $wire |
| 212 | set wire "\"[info nameofexecutable]\" \"$wire\"" |
| 213 | |
| 214 | # One repository with one check-in, cloned twice |
| 215 | scenario_must . init r0.fossil -A scenario \ |
| 216 | --date-override "2026-01-01 00:00:00" |
| 217 | foreach i {0 1 2} { |
| 218 | if {$i > 0} {scenario_must . clone r0.fossil r$i.fossil} |
| 219 | scenario_open $i |
| 220 | if {$i == 0} { |
| 221 | foreach x {0 1 2} { |
| 222 | foreach y {1 2 3 4 5 6 7 8 9} { |
| 223 | scenario_write 0 f$x.txt "file $x line $y" |
| 224 | } |
| 225 | } |
| 226 | scenario_must c0 add f0.txt f1.txt f2.txt |
| 227 | if {[scenario_commit 0]} {scenario_fail "the first commit failed"} |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | # Do the operations |
| 232 | set nOp [expr {min([string length $data]/4, $scenarioMaxOps)}] |
| 233 | for {set i 0} {$i < $nOp} {incr i} { |
| 234 | binary scan $data "@[expr {$i*4}]cu4" rec |
| 235 | lassign $rec op me a opt |
| 236 | set me [expr {$me % 3}] |
| 237 | set ck c$me |
| 238 | set peer [expr {($me + 1 + $a%2) % 3}] |
| 239 | switch [expr {$op % 14}] { |
| 240 | 0 - 1 { ;# Change a file and commit |
| 241 | scenario_write $me f[expr {$a%3}].txt "change $i" |
| 242 | scenario_commit $me |
| 243 | } |
| 244 | 2 { ;# Add a file and commit |
| 245 | scenario_write $me n[expr {$a%8}].txt "new $i" |
| 246 | scenario_fossil $ck add n[expr {$a%8}].txt |
| 247 | scenario_commit $me |
| 248 | } |
| 249 | 3 { ;# Remove a file and commit |
| 250 | if {![scenario_fossil $ck rm --hard f[expr {$a%3}].txt]} { |
| 251 | scenario_commit $me |
| 252 | } |
| 253 | } |
| 254 | 4 { ;# Start a branch, or move to one that exists |
| 255 | scenario_fossil $ck branch new b[expr {$a%4}] current |
| 256 | scenario_fossil $ck update b[expr {$a%4}] |
| 257 | } |
| 258 | 5 { ;# Merge a branch or trunk and commit |
| 259 | if {$a & 0x80} { |
| 260 | scenario_fossil $ck merge trunk |
| 261 | } else { |
| 262 | scenario_fossil $ck merge b[expr {$a%4}] |
| 263 | } |
| 264 | scenario_commit $me |
| 265 | } |
| 266 | 6 { ;# Sync, pull or push with another clone |
| 267 | set verb [lindex {sync pull push} [expr {$opt%3}]] |
| 268 | set fault [expr {($opt/3) % 5}] |
| 269 | # Only "sync" takes -u. The option bit is ignored otherwise. |
| 270 | set uv [expr {($opt & 0x80) && $verb eq "sync"}] |
| 271 | set args [list $verb] |
| 272 | if {$fault == 0} { |
| 273 | lappend args ../r$peer.fossil |
| 274 | } else { |
| 275 | lappend args http://scenario.invalid/x --once \ |
| 276 | --transport-command $wire |
| 277 | } |
| 278 | if {$uv} {lappend args -u} |
| 279 | if {$fault == 0} { |
| 280 | scenario_must $ck {*}$args |
| 281 | } else { |
| 282 | # Fault 4 is the script with no fault, to show that it works |
| 283 | set ::env(SCN_EXE) $::fossilexe |
| 284 | set ::env(SCN_REPO) [file join $scenarioDir r$peer.fossil] |
| 285 | set ::env(SCN_FAULT) $fault |
| 286 | set rc [catch {scenario_fossil $ck {*}$args} failed opts] |
| 287 | unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) |
| 288 | if {$rc} {return -options $opts $failed} |
| 289 | if {$fault == 4 && $failed} { |
| 290 | scenario_fail "a sync through the wire script, with no fault,\ |
| 291 | failed" |
| 292 | } |
| 293 | if {($fault == 1 || $fault == 2) && !$failed} { |
| 294 | scenario_fail "a sync that got no reply reported success" |
| 295 | } |
| 296 | } |
| 297 | if {$fault == 0 || $fault == 4} { |
| 298 | if {$verb ne "push"} {scenario_holds $me $peer $uv $verb} |
| 299 | if {$verb ne "pull"} {scenario_holds $peer $me $uv $verb} |
| 300 | } |
| 301 | } |
| 302 | 7 { ;# Update the checkout |
| 303 | if {$a & 1} { |
| 304 | scenario_fossil $ck update trunk |
| 305 | } else { |
| 306 | scenario_fossil $ck update |
| 307 | } |
| 308 | } |
| 309 | 8 { ;# Add a tag |
| 310 | scenario_fossil $ck tag add t[expr {$a%4}] current |
| 311 | } |
| 312 | 9 { ;# Rebuild |
| 313 | scenario_fossil . rebuild r$me.fossil |
| 314 | } |
| 315 | 10 { ;# Change how much this clone will send in one message |
| 316 | set limits {250000 20000 2000 300} |
| 317 | scenario_fossil . sql -R r$me.fossil "REPLACE INTO |
| 318 | config(name,value,mtime) |
| 319 | VALUES('max-upload',[lindex $limits [expr {$a%4}]],0), |
| 320 | ('max-download',[lindex $limits [expr {($a/4)%4}]],0)" |
| 321 | } |
| 322 | 11 { ;# Commit many files at once |
| 323 | file mkdir [file join $scenarioDir $ck d$i] |
| 324 | set n [expr {40 + 40*($a%4)}] |
| 325 | for {set k 0} {$k < $n} {incr k} { |
| 326 | scenario_write $me d$i/b$k.txt "bulk $i file $k" |
| 327 | } |
| 328 | scenario_fossil $ck add d$i |
| 329 | scenario_commit $me |
| 330 | } |
| 331 | 12 { ;# Add or change an unversioned file |
| 332 | scenario_write $me u[expr {$a%16}].txt "unversioned $i" w |
| 333 | scenario_fossil $ck uv add u[expr {$a%16}].txt --mtime \ |
| 334 | [format "2026-01-01 %02d:%02d:%02d" [expr {$i/60}] \ |
| 335 | [expr {$i%60}] $me] |
| 336 | } |
| 337 | 13 { ;# Replace this clone by a new clone of another |
| 338 | # Skip the operation if the source is waiting for anything. |
| 339 | # "fossil clone" refuses a source that holds a delta from |
| 340 | # something missing, and a check-in with a missing file cannot |
| 341 | # be checked out of the new clone. |
| 342 | if {[scenario_count $peer "SELECT count(*) FROM phantom"]} continue |
| 343 | # Also skip it if this clone holds something that neither of the |
| 344 | # others holds. Throwing away the only copy of an artifact would |
| 345 | # leave the others waiting for it for ever, and that would be the |
| 346 | # fault of this test, not of Fossil. |
| 347 | set o1 [expr {($me+1)%3}] |
| 348 | set o2 [expr {($me+2)%3}] |
| 349 | if {[scenario_count $me "ATTACH 'r$o1.fossil' AS o1; |
| 350 | ATTACH 'r$o2.fossil' AS o2; |
| 351 | SELECT count(*) FROM blob WHERE size>=0 |
| 352 | AND uuid NOT IN (SELECT uuid FROM o1.blob WHERE size>=0) |
| 353 | AND uuid NOT IN (SELECT uuid FROM o2.blob WHERE size>=0)"]} { |
| 354 | continue |
| 355 | } |
| 356 | set uv [expr {($a & 0x80) != 0}] |
| 357 | scenario_fossil $ck close --force |
| 358 | file delete -force [file join $scenarioDir $ck] \ |
| 359 | [file join $scenarioDir r$me.fossil] |
| 360 | if {$uv} { |
| 361 | scenario_must . clone r$peer.fossil r$me.fossil -u |
| 362 | } else { |
| 363 | scenario_must . clone r$peer.fossil r$me.fossil |
| 364 | } |
| 365 | scenario_open $me |
| 366 | scenario_holds $me $peer $uv clone |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | # Sync along the chain 0-1-2 until nothing more can move. One pass |
| 372 | # each way is enough; two more guard the count. |
| 373 | foreach pass {1 2 3} { |
| 374 | scenario_must c0 sync -u ../r1.fossil |
| 375 | scenario_must c1 sync -u ../r2.fossil |
| 376 | scenario_must c2 sync -u ../r1.fossil |
| 377 | scenario_must c1 sync -u ../r0.fossil |
| 378 | } |
| 379 | |
| 380 | # Every clone must be sound, and all must hold the same artifacts |
| 381 | foreach i {0 1 2} { |
| 382 | scenario_must . test-integrity --parse -R r$i.fossil |
| 383 | scenario_must . test-missing -R r$i.fossil |
| 384 | scenario_must . sql -R r$i.fossil "SELECT uuid FROM blob WHERE size>=0 |
| 385 | AND rid NOT IN private ORDER BY 1; |
| 386 | SELECT 'uv', name, hash FROM unversioned |
| 387 | WHERE hash IS NOT NULL ORDER BY 2" |
| 388 | set held($i) [string trim $scenarioOut] |
| 389 | if {$held($i) eq ""} {scenario_fail "clone $i lists no artifacts"} |
| 390 | if {$i > 0 && $held($i) ne $held(0)} { |
| 391 | scenario_fail "clones 0 and $i hold different artifacts or\ |
| 392 | unversioned files after syncing" |
| 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] "" |
| 406 | } |
| 407 | |
| 408 | # Random inputs, on request. The generator is written out here so that a |
| 409 | # seed gives the same input with every version of Tcl. |
| 410 | # |
| 411 | if {[info exists ::env(FOSSIL_SCENARIO_RANDOM)]} { |
| 412 | set scenarioSeed [clock seconds] |
| 413 | if {[info exists ::env(FOSSIL_SCENARIO_SEED)]} { |
| 414 | set scenarioSeed $::env(FOSSIL_SCENARIO_SEED) |
| 415 | } |
| 416 | for {set scenarioN 0} {$scenarioN < $::env(FOSSIL_SCENARIO_RANDOM)} \ |
| 417 | {incr scenarioN; incr scenarioSeed} { |
| 418 | set scenarioX $scenarioSeed |
| 419 | set scenarioData "" |
| 420 | for {set scenarioK 0} {$scenarioK < 4*$scenarioMaxOps} {incr scenarioK} { |
| 421 | set scenarioX [expr {($scenarioX*1103515245 + 12345) & 0x7fffffff}] |
| 422 | append scenarioData [binary format c [expr {($scenarioX>>16) & 255}]] |
| 423 | } |
| 424 | test_eq scenario-seed-$scenarioSeed \ |
| 425 | [scenario_run seed-$scenarioSeed $scenarioData] "" |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | foreach scenarioVar {ASAN_OPTIONS UBSAN_OPTIONS USER} { |
| 430 | if {[info exists scenarioSaved($scenarioVar)]} { |
| 431 | set ::env($scenarioVar) $scenarioSaved($scenarioVar) |
| 432 | } else { |
| 433 | unset ::env($scenarioVar) |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | ############################################################################### |
| 438 | |
| 439 | test_cleanup |
+148
| --- a/test/ssh.test | ||
| +++ b/test/ssh.test | ||
| @@ -0,0 +1,148 @@ | ||
| 1 | +# | |
| 2 | +# What fossil puts on an ssh command line. Nothing here connects to | |
| 3 | +# another machine: "ssh" is a script that writes down the arguments it | |
| 4 | +# is given and exits. The script is named by --ssh-command where a | |
| 5 | +# command takes that option, and is first on the PATH for the commands | |
| 6 | +# that do not. | |
| 7 | +# | |
| 8 | +# Whatever follows the host on an ssh command line is joined into one | |
| 9 | +# string by ssh and parsed again by the login shell on the server, so | |
| 10 | +# quoting for the local shell does not protect it. These tests require | |
| 11 | +# that a value with a character special to a shell never reaches ssh, | |
| 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 | +} | |
| 20 | + | |
| 21 | +test_setup | |
| 22 | + | |
| 23 | +set sshDir [file join [pwd] ssh-standin] | |
| 24 | +file mkdir $sshDir | |
| 25 | +set sshStub [file join $sshDir ssh] | |
| 26 | +set sshLog [file join [pwd] ssh-args.txt] | |
| 27 | +write_file $sshStub "#!/bin/sh\nfor a in \"\$@\"; do printf '<%s>\\n' \"\$a\"; done >> \"\$SSHTESTLOG\"\nexit 1\n" | |
| 28 | +file attributes $sshStub -permissions 0755 | |
| 29 | +set ::env(SSHTESTLOG) $sshLog | |
| 30 | +set sshSavedPath $::env(PATH) | |
| 31 | +set ::env(PATH) "$sshDir:$::env(PATH)" | |
| 32 | + | |
| 33 | +# The stand-in must be what "ssh" means from here on. If it is not, run | |
| 34 | +# nothing that could start the real one. | |
| 35 | +if {[lindex [auto_execok ssh] 0] ne $sshStub} { | |
| 36 | + set ::env(PATH) $sshSavedPath | |
| 37 | + test_cleanup | |
| 38 | + test_skip "cannot put a stand-in for ssh first on the PATH" | |
| 39 | +} | |
| 40 | + | |
| 41 | +# Run fossil with the arguments given. Sets sshOut to everything it | |
| 42 | +# printed and sshArgs to the arguments the stand-in was given, one per | |
| 43 | +# line inside <>, or to an empty string if it was not run. | |
| 44 | +proc ssh_run {args} { | |
| 45 | + global sshOut sshArgs sshLog | |
| 46 | + file delete $sshLog | |
| 47 | + catch {exec $::fossilexe {*}$args < /dev/null 2>@1} sshOut | |
| 48 | + set sshArgs "" | |
| 49 | + if {[file exists $sshLog]} { | |
| 50 | + set sshFd [open $sshLog r] | |
| 51 | + set sshArgs [read $sshFd] | |
| 52 | + close $sshFd | |
| 53 | + } | |
| 54 | +} | |
| 55 | +proc ssh_clone {url} { | |
| 56 | + file delete ssh-clone.fossil | |
| 57 | + ssh_run clone --ssh-command $::sshStub $url ssh-clone.fossil | |
| 58 | +} | |
| 59 | + | |
| 60 | +############################################################################### | |
| 61 | +# Ordinary URLs reach ssh, with "--" before the host and the path as one | |
| 62 | +# argument. | |
| 63 | + | |
| 64 | +ssh_clone ssh://hh/dir/repo.fossil | |
| 65 | +test ssh-clone-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0 | |
| 66 | + && [string first "<test-http>\n<dir/repo.fossil>" $sshArgs] >= 0} | |
| 67 | +ssh_clone ssh://uu@hh:2222/dir/repo.fossil | |
| 68 | +test ssh-clone-user-port {[string first "<-p>\n<2222>\n" $sshArgs] >= 0 | |
| 69 | + && [string first "<-->\n<uu@hh>\n" $sshArgs] >= 0} | |
| 70 | +ssh_clone "ssh://hh/dir/a-b_c.d,e=f@g/repo.fossil" | |
| 71 | +test ssh-clone-punctuation \ | |
| 72 | + {[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0} | |
| 73 | +ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil" | |
| 74 | +test ssh-clone-fossil-parameter \ | |
| 75 | + {[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0} | |
| 76 | + | |
| 77 | +# A path that begins with "~" is for the server to expand. It used to be | |
| 78 | +# expanded on the local machine. | |
| 79 | +ssh_clone ssh://hh/~/repo.fossil | |
| 80 | +test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0} | |
| 81 | + | |
| 82 | +############################################################################### | |
| 83 | +# A path or a fossil= value with a character special to a shell is | |
| 84 | +# refused, and ssh is not run. | |
| 85 | + | |
| 86 | +foreach {sshName sshUrl} { | |
| 87 | + semicolon ssh://hh/a;b.fossil | |
| 88 | + space ssh://hh/a%20b.fossil | |
| 89 | + dollar ssh://hh/$HOME/b.fossil | |
| 90 | + ampersand ssh://hh/a%26b.fossil | |
| 91 | + backquote ssh://hh/a%60b.fossil | |
| 92 | + pipe ssh://hh/a|b.fossil | |
| 93 | + parenthesis ssh://hh/a(b).fossil | |
| 94 | + redirect ssh://hh/a>b.fossil | |
| 95 | +} { | |
| 96 | + ssh_clone $sshUrl | |
| 97 | + test ssh-clone-refused-$sshName \ | |
| 98 | + {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0} | |
| 99 | +} | |
| 100 | +foreach {sshName sshUrl} { | |
| 101 | + semicolon ssh://hh/repo.fossil?fossil=a;b/fossil | |
| 102 | + dollar ssh://hh/repo.fossil?fossil=$HOME/bin/fossil | |
| 103 | + other ssh://hh/repo.fossil?fossil=/bin/other | |
| 104 | +} { | |
| 105 | + ssh_clone $sshUrl | |
| 106 | + test ssh-clone-fossil-refused-$sshName \ | |
| 107 | + {$sshArgs eq "" && [string first "unsafe command" $sshOut] >= 0} | |
| 108 | +} | |
| 109 | + | |
| 110 | +############################################################################### | |
| 111 | +# "fossil ui HOST:REPO" refuses such a repository name, and puts "--" | |
| 112 | +# before the host. | |
| 113 | + | |
| 114 | +ssh_run ui --nobrowser hh:dir/repo.fossil | |
| 115 | +test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0 | |
| 116 | + && [string first "<dir/repo.fossil>" $sshArgs] >= 0} | |
| 117 | +ssh_run ui --nobrowser "hh:dir/a;b.fossil" | |
| 118 | +test ssh-ui-refused-semicolon \ | |
| 119 | + {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0} | |
| 120 | +ssh_run ui --nobrowser "hh:dir/a b.fossil" | |
| 121 | +test ssh-ui-refused-space \ | |
| 122 | + {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0} | |
| 123 | +ssh_run ui --nobrowser -- "-x@hh:dir/repo.fossil" | |
| 124 | +test ssh-ui-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} | |
| 125 | + | |
| 126 | +############################################################################### | |
| 127 | +# "fossil patch push" and "fossil patch pull" put "--" before the host. | |
| 128 | + | |
| 129 | +write_file ssh-file.txt "one\n" | |
| 130 | +fossil add ssh-file.txt | |
| 131 | +ssh_run patch push -- "-x@hh:dir" | |
| 132 | +test ssh-patch-push-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} | |
| 133 | +ssh_run patch pull -- "-x@hh:dir" | |
| 134 | +test ssh-patch-pull-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} | |
| 135 | + | |
| 136 | +############################################################################### | |
| 137 | +# An argument that begins with "~" is quoted, so that the shell does not | |
| 138 | +# replace it with a home directory. | |
| 139 | + | |
| 140 | +ssh_run test-escaped-arg ~ ~root/x | |
| 141 | +test ssh-escaped-tilde {[string first {argv[2] = [~]} $sshOut] >= 0 | |
| 142 | + && [string first {argv[2] = [~root/x]} $sshOut] >= 0} | |
| 143 | + | |
| 144 | +############################################################################### | |
| 145 | + | |
| 146 | +set ::env(PATH) $sshSavedPath | |
| 147 | +unset ::env(SSHTESTLOG) | |
| 148 | +test_cleanup |
| --- a/test/ssh.test | |
| +++ b/test/ssh.test | |
| @@ -0,0 +1,148 @@ | |
| --- a/test/ssh.test | |
| +++ b/test/ssh.test | |
| @@ -0,0 +1,148 @@ | |
| 1 | # |
| 2 | # What fossil puts on an ssh command line. Nothing here connects to |
| 3 | # another machine: "ssh" is a script that writes down the arguments it |
| 4 | # is given and exits. The script is named by --ssh-command where a |
| 5 | # command takes that option, and is first on the PATH for the commands |
| 6 | # that do not. |
| 7 | # |
| 8 | # Whatever follows the host on an ssh command line is joined into one |
| 9 | # string by ssh and parsed again by the login shell on the server, so |
| 10 | # quoting for the local shell does not protect it. These tests require |
| 11 | # that a value with a character special to a shell never reaches ssh, |
| 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 | } |
| 20 | |
| 21 | test_setup |
| 22 | |
| 23 | set sshDir [file join [pwd] ssh-standin] |
| 24 | file mkdir $sshDir |
| 25 | set sshStub [file join $sshDir ssh] |
| 26 | set sshLog [file join [pwd] ssh-args.txt] |
| 27 | write_file $sshStub "#!/bin/sh\nfor a in \"\$@\"; do printf '<%s>\\n' \"\$a\"; done >> \"\$SSHTESTLOG\"\nexit 1\n" |
| 28 | file attributes $sshStub -permissions 0755 |
| 29 | set ::env(SSHTESTLOG) $sshLog |
| 30 | set sshSavedPath $::env(PATH) |
| 31 | set ::env(PATH) "$sshDir:$::env(PATH)" |
| 32 | |
| 33 | # The stand-in must be what "ssh" means from here on. If it is not, run |
| 34 | # nothing that could start the real one. |
| 35 | if {[lindex [auto_execok ssh] 0] ne $sshStub} { |
| 36 | set ::env(PATH) $sshSavedPath |
| 37 | test_cleanup |
| 38 | test_skip "cannot put a stand-in for ssh first on the PATH" |
| 39 | } |
| 40 | |
| 41 | # Run fossil with the arguments given. Sets sshOut to everything it |
| 42 | # printed and sshArgs to the arguments the stand-in was given, one per |
| 43 | # line inside <>, or to an empty string if it was not run. |
| 44 | proc ssh_run {args} { |
| 45 | global sshOut sshArgs sshLog |
| 46 | file delete $sshLog |
| 47 | catch {exec $::fossilexe {*}$args < /dev/null 2>@1} sshOut |
| 48 | set sshArgs "" |
| 49 | if {[file exists $sshLog]} { |
| 50 | set sshFd [open $sshLog r] |
| 51 | set sshArgs [read $sshFd] |
| 52 | close $sshFd |
| 53 | } |
| 54 | } |
| 55 | proc ssh_clone {url} { |
| 56 | file delete ssh-clone.fossil |
| 57 | ssh_run clone --ssh-command $::sshStub $url ssh-clone.fossil |
| 58 | } |
| 59 | |
| 60 | ############################################################################### |
| 61 | # Ordinary URLs reach ssh, with "--" before the host and the path as one |
| 62 | # argument. |
| 63 | |
| 64 | ssh_clone ssh://hh/dir/repo.fossil |
| 65 | test ssh-clone-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0 |
| 66 | && [string first "<test-http>\n<dir/repo.fossil>" $sshArgs] >= 0} |
| 67 | ssh_clone ssh://uu@hh:2222/dir/repo.fossil |
| 68 | test ssh-clone-user-port {[string first "<-p>\n<2222>\n" $sshArgs] >= 0 |
| 69 | && [string first "<-->\n<uu@hh>\n" $sshArgs] >= 0} |
| 70 | ssh_clone "ssh://hh/dir/a-b_c.d,e=f@g/repo.fossil" |
| 71 | test ssh-clone-punctuation \ |
| 72 | {[string first "<dir/a-b_c.d,e=f@g/repo.fossil>" $sshArgs] >= 0} |
| 73 | ssh_clone "ssh://hh/repo.fossil?fossil=/opt/bin/fossil" |
| 74 | test ssh-clone-fossil-parameter \ |
| 75 | {[string first "<hh>\n</opt/bin/fossil>\n<test-http>" $sshArgs] >= 0} |
| 76 | |
| 77 | # A path that begins with "~" is for the server to expand. It used to be |
| 78 | # expanded on the local machine. |
| 79 | ssh_clone ssh://hh/~/repo.fossil |
| 80 | test ssh-clone-tilde {[string first "<~/repo.fossil>" $sshArgs] >= 0} |
| 81 | |
| 82 | ############################################################################### |
| 83 | # A path or a fossil= value with a character special to a shell is |
| 84 | # refused, and ssh is not run. |
| 85 | |
| 86 | foreach {sshName sshUrl} { |
| 87 | semicolon ssh://hh/a;b.fossil |
| 88 | space ssh://hh/a%20b.fossil |
| 89 | dollar ssh://hh/$HOME/b.fossil |
| 90 | ampersand ssh://hh/a%26b.fossil |
| 91 | backquote ssh://hh/a%60b.fossil |
| 92 | pipe ssh://hh/a|b.fossil |
| 93 | parenthesis ssh://hh/a(b).fossil |
| 94 | redirect ssh://hh/a>b.fossil |
| 95 | } { |
| 96 | ssh_clone $sshUrl |
| 97 | test ssh-clone-refused-$sshName \ |
| 98 | {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0} |
| 99 | } |
| 100 | foreach {sshName sshUrl} { |
| 101 | semicolon ssh://hh/repo.fossil?fossil=a;b/fossil |
| 102 | dollar ssh://hh/repo.fossil?fossil=$HOME/bin/fossil |
| 103 | other ssh://hh/repo.fossil?fossil=/bin/other |
| 104 | } { |
| 105 | ssh_clone $sshUrl |
| 106 | test ssh-clone-fossil-refused-$sshName \ |
| 107 | {$sshArgs eq "" && [string first "unsafe command" $sshOut] >= 0} |
| 108 | } |
| 109 | |
| 110 | ############################################################################### |
| 111 | # "fossil ui HOST:REPO" refuses such a repository name, and puts "--" |
| 112 | # before the host. |
| 113 | |
| 114 | ssh_run ui --nobrowser hh:dir/repo.fossil |
| 115 | test ssh-ui-plain {[string first "<-->\n<hh>\n" $sshArgs] >= 0 |
| 116 | && [string first "<dir/repo.fossil>" $sshArgs] >= 0} |
| 117 | ssh_run ui --nobrowser "hh:dir/a;b.fossil" |
| 118 | test ssh-ui-refused-semicolon \ |
| 119 | {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0} |
| 120 | ssh_run ui --nobrowser "hh:dir/a b.fossil" |
| 121 | test ssh-ui-refused-space \ |
| 122 | {$sshArgs eq "" && [string first "special to the shell" $sshOut] >= 0} |
| 123 | ssh_run ui --nobrowser -- "-x@hh:dir/repo.fossil" |
| 124 | test ssh-ui-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} |
| 125 | |
| 126 | ############################################################################### |
| 127 | # "fossil patch push" and "fossil patch pull" put "--" before the host. |
| 128 | |
| 129 | write_file ssh-file.txt "one\n" |
| 130 | fossil add ssh-file.txt |
| 131 | ssh_run patch push -- "-x@hh:dir" |
| 132 | test ssh-patch-push-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} |
| 133 | ssh_run patch pull -- "-x@hh:dir" |
| 134 | test ssh-patch-pull-user-with-dash {[string first "<-->\n<-x@hh>\n" $sshArgs] >= 0} |
| 135 | |
| 136 | ############################################################################### |
| 137 | # An argument that begins with "~" is quoted, so that the shell does not |
| 138 | # replace it with a home directory. |
| 139 | |
| 140 | ssh_run test-escaped-arg ~ ~root/x |
| 141 | test ssh-escaped-tilde {[string first {argv[2] = [~]} $sshOut] >= 0 |
| 142 | && [string first {argv[2] = [~root/x]} $sshOut] >= 0} |
| 143 | |
| 144 | ############################################################################### |
| 145 | |
| 146 | set ::env(PATH) $sshSavedPath |
| 147 | unset ::env(SSHTESTLOG) |
| 148 | test_cleanup |
| --- a/test/standin/scenario-wire.tcl | ||
| +++ b/test/standin/scenario-wire.tcl | ||
| @@ -0,0 +1,80 @@ | ||
| 1 | +# | |
| 2 | +# Carry one round trip of a sync for scenario.test, and lose or damage | |
| 3 | +# it if told to. Fossil runs this script as its --transport-command: | |
| 4 | +# | |
| 5 | +# tclsh scenario-wire.tcl URL REQUESTFILE REPLYFILE | |
| 6 | +# | |
| 7 | +# SCN_EXE is the fossil executable and SCN_REPO the repository to talk | |
| 8 | +# to. SCN_FAULT is 1 to lose the request, 2 to lose the reply after the | |
| 9 | +# other side has acted on the request, and 3 to deliver only the first | |
| 10 | +# half of the reply. Any other value means no fault. | |
| 11 | +# | |
| 12 | +# The other side trusts the request as a local one, unless SCN_AUTH is | |
| 13 | +# set: then it checks the login card as a server on a network does. | |
| 14 | +# Fossil puts no login card on a request that it gives to a transport | |
| 15 | +# command. If SCN_LOGIN is set, to USER:PASSWORD, this script adds the | |
| 16 | +# card that Fossil would add on a network; SCN_PROJECT is then the | |
| 17 | +# project code of the repository. | |
| 18 | +# | |
| 19 | +proc slurp {name} { | |
| 20 | + set fd [open $name rb] | |
| 21 | + set data [read $fd] | |
| 22 | + close $fd | |
| 23 | + return $data | |
| 24 | +} | |
| 25 | +proc spit {name data} { | |
| 26 | + set fd [open $name wb] | |
| 27 | + puts -nonewline $fd $data | |
| 28 | + close $fd | |
| 29 | +} | |
| 30 | + | |
| 31 | +lassign $argv url requestFile replyFile | |
| 32 | +set fault $env(SCN_FAULT) | |
| 33 | +if {$fault == 1} { | |
| 34 | + spit $replyFile "" | |
| 35 | + exit 0 | |
| 36 | +} | |
| 37 | + | |
| 38 | +# The SHA1 hash of a string, by way of "fossil sha1sum". | |
| 39 | +proc sha1 {text} { | |
| 40 | + global env requestFile | |
| 41 | + spit $requestFile.sha $text | |
| 42 | + set sum [lindex [exec $env(SCN_EXE) sha1sum $requestFile.sha] 0] | |
| 43 | + file delete $requestFile.sha | |
| 44 | + return $sum | |
| 45 | +} | |
| 46 | + | |
| 47 | +# Hand the request to "fossil http" on the other repository. | |
| 48 | +set request [slurp $requestFile] | |
| 49 | +if {[info exists env(SCN_LOGIN)]} { | |
| 50 | + set colon [string first : $env(SCN_LOGIN)] | |
| 51 | + set user [string range $env(SCN_LOGIN) 0 [expr {$colon-1}]] | |
| 52 | + set password [string range $env(SCN_LOGIN) [expr {$colon+1}] end] | |
| 53 | + set secret [sha1 $env(SCN_PROJECT)/$user/$password] | |
| 54 | + set nonce [sha1 $request] | |
| 55 | + set request "login $user $nonce [sha1 $nonce$secret]\n$request" | |
| 56 | +} | |
| 57 | +set head "POST /xfer HTTP/1.0\r\n" | |
| 58 | +append head "Content-Type: application/x-fossil-debug\r\n" | |
| 59 | +append head "Content-Length: [string length $request]\r\n\r\n" | |
| 60 | +spit $requestFile.req $head$request | |
| 61 | +set trust [expr {[info exists env(SCN_AUTH)] ? {} : {--localauth}}] | |
| 62 | +set failed [catch { | |
| 63 | + exec $env(SCN_EXE) http --in $requestFile.req --out $requestFile.raw \ | |
| 64 | + --ipaddr 127.0.0.1 $env(SCN_REPO) {*}$trust 2>@1 | |
| 65 | +}] | |
| 66 | +if {$failed} { | |
| 67 | + file delete $requestFile.req $requestFile.raw | |
| 68 | + exit 1 | |
| 69 | +} | |
| 70 | + | |
| 71 | +# The reply is what follows the first empty line. | |
| 72 | +set raw [slurp $requestFile.raw] | |
| 73 | +file delete $requestFile.req $requestFile.raw | |
| 74 | +set end [string first "\r\n\r\n" $raw] | |
| 75 | +set reply [expr {$end < 0 ? "" : [string range $raw [expr {$end+4}] end]}] | |
| 76 | +switch -- $fault { | |
| 77 | + 2 {set reply ""} | |
| 78 | + 3 {set reply [string range $reply 0 [expr {[string length $reply]/2 - 1}]]} | |
| 79 | +} | |
| 80 | +spit $replyFile $reply |
| --- a/test/standin/scenario-wire.tcl | |
| +++ b/test/standin/scenario-wire.tcl | |
| @@ -0,0 +1,80 @@ | |
| --- a/test/standin/scenario-wire.tcl | |
| +++ b/test/standin/scenario-wire.tcl | |
| @@ -0,0 +1,80 @@ | |
| 1 | # |
| 2 | # Carry one round trip of a sync for scenario.test, and lose or damage |
| 3 | # it if told to. Fossil runs this script as its --transport-command: |
| 4 | # |
| 5 | # tclsh scenario-wire.tcl URL REQUESTFILE REPLYFILE |
| 6 | # |
| 7 | # SCN_EXE is the fossil executable and SCN_REPO the repository to talk |
| 8 | # to. SCN_FAULT is 1 to lose the request, 2 to lose the reply after the |
| 9 | # other side has acted on the request, and 3 to deliver only the first |
| 10 | # half of the reply. Any other value means no fault. |
| 11 | # |
| 12 | # The other side trusts the request as a local one, unless SCN_AUTH is |
| 13 | # set: then it checks the login card as a server on a network does. |
| 14 | # Fossil puts no login card on a request that it gives to a transport |
| 15 | # command. If SCN_LOGIN is set, to USER:PASSWORD, this script adds the |
| 16 | # card that Fossil would add on a network; SCN_PROJECT is then the |
| 17 | # project code of the repository. |
| 18 | # |
| 19 | proc slurp {name} { |
| 20 | set fd [open $name rb] |
| 21 | set data [read $fd] |
| 22 | close $fd |
| 23 | return $data |
| 24 | } |
| 25 | proc spit {name data} { |
| 26 | set fd [open $name wb] |
| 27 | puts -nonewline $fd $data |
| 28 | close $fd |
| 29 | } |
| 30 | |
| 31 | lassign $argv url requestFile replyFile |
| 32 | set fault $env(SCN_FAULT) |
| 33 | if {$fault == 1} { |
| 34 | spit $replyFile "" |
| 35 | exit 0 |
| 36 | } |
| 37 | |
| 38 | # The SHA1 hash of a string, by way of "fossil sha1sum". |
| 39 | proc sha1 {text} { |
| 40 | global env requestFile |
| 41 | spit $requestFile.sha $text |
| 42 | set sum [lindex [exec $env(SCN_EXE) sha1sum $requestFile.sha] 0] |
| 43 | file delete $requestFile.sha |
| 44 | return $sum |
| 45 | } |
| 46 | |
| 47 | # Hand the request to "fossil http" on the other repository. |
| 48 | set request [slurp $requestFile] |
| 49 | if {[info exists env(SCN_LOGIN)]} { |
| 50 | set colon [string first : $env(SCN_LOGIN)] |
| 51 | set user [string range $env(SCN_LOGIN) 0 [expr {$colon-1}]] |
| 52 | set password [string range $env(SCN_LOGIN) [expr {$colon+1}] end] |
| 53 | set secret [sha1 $env(SCN_PROJECT)/$user/$password] |
| 54 | set nonce [sha1 $request] |
| 55 | set request "login $user $nonce [sha1 $nonce$secret]\n$request" |
| 56 | } |
| 57 | set head "POST /xfer HTTP/1.0\r\n" |
| 58 | append head "Content-Type: application/x-fossil-debug\r\n" |
| 59 | append head "Content-Length: [string length $request]\r\n\r\n" |
| 60 | spit $requestFile.req $head$request |
| 61 | set trust [expr {[info exists env(SCN_AUTH)] ? {} : {--localauth}}] |
| 62 | set failed [catch { |
| 63 | exec $env(SCN_EXE) http --in $requestFile.req --out $requestFile.raw \ |
| 64 | --ipaddr 127.0.0.1 $env(SCN_REPO) {*}$trust 2>@1 |
| 65 | }] |
| 66 | if {$failed} { |
| 67 | file delete $requestFile.req $requestFile.raw |
| 68 | exit 1 |
| 69 | } |
| 70 | |
| 71 | # The reply is what follows the first empty line. |
| 72 | set raw [slurp $requestFile.raw] |
| 73 | file delete $requestFile.req $requestFile.raw |
| 74 | set end [string first "\r\n\r\n" $raw] |
| 75 | set reply [expr {$end < 0 ? "" : [string range $raw [expr {$end+4}] end]}] |
| 76 | switch -- $fault { |
| 77 | 2 {set reply ""} |
| 78 | 3 {set reply [string range $reply 0 [expr {[string length $reply]/2 - 1}]]} |
| 79 | } |
| 80 | spit $replyFile $reply |
+50
| --- test/sync.test | ||
| +++ test/sync.test | ||
| @@ -51,10 +51,19 @@ | ||
| 51 | 51 | proc sync_commit {dir file comment args} { |
| 52 | 52 | write_file [file join $dir $file] "$comment\n" |
| 53 | 53 | fossil add $file --chdir $dir |
| 54 | 54 | fossil commit -m $comment --chdir $dir {*}$args |
| 55 | 55 | } |
| 56 | + | |
| 57 | +# N bytes of deterministic pseudo-random binary data. | |
| 58 | +proc sync_random_bytes {n} { | |
| 59 | + set s "" | |
| 60 | + for {set syncI 0} {$syncI < $n} {incr syncI 4} { | |
| 61 | + append s [binary format i [expr {int(rand()*4294967296)}]] | |
| 62 | + } | |
| 63 | + return [string range $s 0 [expr {$n-1}]] | |
| 64 | +} | |
| 56 | 65 | |
| 57 | 66 | # The origin repository, with three check-ins, a tag and a wiki page. |
| 58 | 67 | fossil new a.fossil |
| 59 | 68 | fossil user capabilities nobody gio -R a.fossil |
| 60 | 69 | file mkdir a |
| @@ -148,8 +157,49 @@ | ||
| 148 | 157 | set server [test_start_server d.fossil stopArg] |
| 149 | 158 | set url http://127.0.0.1:[lindex $server 1] |
| 150 | 159 | fossil clone --proxy off $url e.fossil -expectError |
| 151 | 160 | test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug |
| 152 | 161 | test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
| 162 | + | |
| 163 | +############################################################################### | |
| 164 | +# A sync that gets no reply must not report success. | |
| 165 | + | |
| 166 | +if {$::tcl_platform(platform) ne "windows"} { | |
| 167 | + fossil new nr.fossil | |
| 168 | + file mkdir nr | |
| 169 | + fossil open ../nr.fossil --chdir nr | |
| 170 | + sync_commit nr nf.txt one | |
| 171 | + set syncWrapper [file join $dir no-reply.sh] | |
| 172 | + write_file $syncWrapper "#!/bin/sh\n: >\"\$3\"\n" | |
| 173 | + file attributes $syncWrapper -permissions 0755 | |
| 174 | + fossil sync http://sync-test.invalid/x --once \ | |
| 175 | + --transport-command $syncWrapper --chdir nr -expectError | |
| 176 | + test sync-no-reply-fails {$CODE != 0} | |
| 177 | + test_match sync-no-reply-message [normalize_result] {empty reply} | |
| 178 | + fossil close --chdir nr | |
| 179 | +} | |
| 180 | + | |
| 181 | +############################################################################### | |
| 182 | +# An unversioned file pushed together with a commit that spans more than | |
| 183 | +# one message must arrive. | |
| 184 | + | |
| 185 | +fossil new uva.fossil | |
| 186 | +fossil clone [file join $dir uva.fossil] uvb.fossil | |
| 187 | +file mkdir uvco | |
| 188 | +fossil open ../uvb.fossil --chdir uvco | |
| 189 | +fossil settings autosync off --chdir uvco | |
| 190 | +expr {srand(1)} | |
| 191 | +foreach syncI {1 2 3 4 5 6} { | |
| 192 | + write_file [file join uvco big$syncI.bin] [sync_random_bytes 200000] | |
| 193 | + fossil add big$syncI.bin --chdir uvco | |
| 194 | +} | |
| 195 | +fossil commit -m big --chdir uvco --no-warnings | |
| 196 | +write_file [file join uvco note.txt] "an unversioned file\n" | |
| 197 | +fossil uv add note.txt --chdir uvco | |
| 198 | +fossil sync -u [file join $dir uva.fossil] --chdir uvco | |
| 199 | +test sync-unversioned-with-large-commit {$CODE == 0} | |
| 200 | +fossil uv list -R uva.fossil | |
| 201 | +test_match sync-unversioned-arrived [normalize_result] {note\.txt} | |
| 202 | +fossil close --chdir uvco | |
| 153 | 203 | |
| 154 | 204 | test_cleanup |
| 155 | 205 | unset ::env(FOSSIL_USER) |
| 156 | 206 | |
| 157 | 207 | ADDED test/th1main.test |
| 158 | 208 | ADDED test/url.test |
| 159 | 209 | ADDED test/xfer-client.test |
| 160 | 210 | ADDED test/xfer-server.test |
| 161 | 211 | ADDED tools/testbuild.sh |
| --- test/sync.test | |
| +++ test/sync.test | |
| @@ -51,10 +51,19 @@ | |
| 51 | proc sync_commit {dir file comment args} { |
| 52 | write_file [file join $dir $file] "$comment\n" |
| 53 | fossil add $file --chdir $dir |
| 54 | fossil commit -m $comment --chdir $dir {*}$args |
| 55 | } |
| 56 | |
| 57 | # The origin repository, with three check-ins, a tag and a wiki page. |
| 58 | fossil new a.fossil |
| 59 | fossil user capabilities nobody gio -R a.fossil |
| 60 | file mkdir a |
| @@ -148,8 +157,49 @@ | |
| 148 | set server [test_start_server d.fossil stopArg] |
| 149 | set url http://127.0.0.1:[lindex $server 1] |
| 150 | fossil clone --proxy off $url e.fossil -expectError |
| 151 | test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug |
| 152 | test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
| 153 | |
| 154 | test_cleanup |
| 155 | unset ::env(FOSSIL_USER) |
| 156 | |
| 157 | DDED test/th1main.test |
| 158 | DDED test/url.test |
| 159 | DDED test/xfer-client.test |
| 160 | DDED test/xfer-server.test |
| 161 | DDED tools/testbuild.sh |
| --- test/sync.test | |
| +++ test/sync.test | |
| @@ -51,10 +51,19 @@ | |
| 51 | proc sync_commit {dir file comment args} { |
| 52 | write_file [file join $dir $file] "$comment\n" |
| 53 | fossil add $file --chdir $dir |
| 54 | fossil commit -m $comment --chdir $dir {*}$args |
| 55 | } |
| 56 | |
| 57 | # N bytes of deterministic pseudo-random binary data. |
| 58 | proc sync_random_bytes {n} { |
| 59 | set s "" |
| 60 | for {set syncI 0} {$syncI < $n} {incr syncI 4} { |
| 61 | append s [binary format i [expr {int(rand()*4294967296)}]] |
| 62 | } |
| 63 | return [string range $s 0 [expr {$n-1}]] |
| 64 | } |
| 65 | |
| 66 | # The origin repository, with three check-ins, a tag and a wiki page. |
| 67 | fossil new a.fossil |
| 68 | fossil user capabilities nobody gio -R a.fossil |
| 69 | file mkdir a |
| @@ -148,8 +157,49 @@ | |
| 157 | set server [test_start_server d.fossil stopArg] |
| 158 | set url http://127.0.0.1:[lindex $server 1] |
| 159 | fossil clone --proxy off $url e.fossil -expectError |
| 160 | test sync-bad-hash-clone {$CODE != 0 && ![file exists e.fossil]} knownBug |
| 161 | test_stop_server $stopArg [lindex $server 0] [lindex $server 2] |
| 162 | |
| 163 | ############################################################################### |
| 164 | # A sync that gets no reply must not report success. |
| 165 | |
| 166 | if {$::tcl_platform(platform) ne "windows"} { |
| 167 | fossil new nr.fossil |
| 168 | file mkdir nr |
| 169 | fossil open ../nr.fossil --chdir nr |
| 170 | sync_commit nr nf.txt one |
| 171 | set syncWrapper [file join $dir no-reply.sh] |
| 172 | write_file $syncWrapper "#!/bin/sh\n: >\"\$3\"\n" |
| 173 | file attributes $syncWrapper -permissions 0755 |
| 174 | fossil sync http://sync-test.invalid/x --once \ |
| 175 | --transport-command $syncWrapper --chdir nr -expectError |
| 176 | test sync-no-reply-fails {$CODE != 0} |
| 177 | test_match sync-no-reply-message [normalize_result] {empty reply} |
| 178 | fossil close --chdir nr |
| 179 | } |
| 180 | |
| 181 | ############################################################################### |
| 182 | # An unversioned file pushed together with a commit that spans more than |
| 183 | # one message must arrive. |
| 184 | |
| 185 | fossil new uva.fossil |
| 186 | fossil clone [file join $dir uva.fossil] uvb.fossil |
| 187 | file mkdir uvco |
| 188 | fossil open ../uvb.fossil --chdir uvco |
| 189 | fossil settings autosync off --chdir uvco |
| 190 | expr {srand(1)} |
| 191 | foreach syncI {1 2 3 4 5 6} { |
| 192 | write_file [file join uvco big$syncI.bin] [sync_random_bytes 200000] |
| 193 | fossil add big$syncI.bin --chdir uvco |
| 194 | } |
| 195 | fossil commit -m big --chdir uvco --no-warnings |
| 196 | write_file [file join uvco note.txt] "an unversioned file\n" |
| 197 | fossil uv add note.txt --chdir uvco |
| 198 | fossil sync -u [file join $dir uva.fossil] --chdir uvco |
| 199 | test sync-unversioned-with-large-commit {$CODE == 0} |
| 200 | fossil uv list -R uva.fossil |
| 201 | test_match sync-unversioned-arrived [normalize_result] {note\.txt} |
| 202 | fossil close --chdir uvco |
| 203 | |
| 204 | test_cleanup |
| 205 | unset ::env(FOSSIL_USER) |
| 206 | |
| 207 | DDED test/th1main.test |
| 208 | DDED test/url.test |
| 209 | DDED test/xfer-client.test |
| 210 | DDED test/xfer-server.test |
| 211 | DDED tools/testbuild.sh |
+704
| --- a/test/th1main.test | ||
| +++ b/test/th1main.test | ||
| @@ -0,0 +1,704 @@ | ||
| 1 | +########################## | |
| 2 | +# | |
| 3 | +# Fossil's own TH1 commands and the template renderer: src/th_main.c. | |
| 4 | +# Scripts are run with "fossil test-th-eval", templates with | |
| 5 | +# "fossil test-th-render" and "fossil test-th-source", and a ticket page | |
| 6 | +# that holds TH1 is asked for through "se tests run only in a long pass:ter the first sect.H_ERROR: wrong # args: runs only withter the first sections need | |
| 7 | +# -assurance stress. | |
| 8 | +test_setup | |
| 9 | + | |
| 10 | +write_file a.txt "hello\n" | |
| 11 | +write_file f83.txt "line 83\n" | |
| 12 | +write_file f100.txt "line 100\n" | |
| 13 | +fossil add a.txt f83.txt f100.txt | |
| 14 | +fossil commit -m "three files" | |
| 15 | +fossil user new u1 "" pw1 | |
| 16 | +set th1mainRepo [file join [pwd] .rep.fossil] | |
| 17 | + | |
| 18 | +# Run SCRIPT with "fossil test-th-eval" and the options in ARGS. Returns | |
| 19 | +# what fossil printed, without the final newline. | |
| 20 | +# | |
| 21 | +# A build with TH1 hooks runs th1-setup and opens the checkout before the | |
| 22 | +# command itself; these tests are of the commands, so they turn hooks off. | |
| 23 | +fossil test-th-eval "hasfeature th1Hooks" | |
| 24 | +set th1mainNoHook [expr {[string trim $RESULT] eq "1" ? "--no-th-hook" : ""}] | |
| 25 | + | |
| 26 | +proc th1main_eval {script args} { | |
| 27 | + fossil_raw -seconds 60 test-th-eval {*}$::th1mainNoHook {*}$args $script | |
| 28 | + return [string trimright $::RESULT \n] | |
| 29 | +} | |
| 30 | + | |
| 31 | +# Test NAME passes if ACTUAL is as EXPECTED says. MODE is "eq" for an | |
| 32 | +# exact value, "re" for a regular expression, or "has" for a list of | |
| 33 | +# strings that must all be there (one that begins with "!" must not). | |
| 34 | +# | |
| 35 | +proc th1main_check {name actual mode expected {constraints ""}} { | |
| 36 | + switch -- $mode { | |
| 37 | + eq { test_eq $name $actual $expected $constraints } | |
| 38 | + re { test_match $name $actual $expected $constraints } | |
| 39 | + has { test $name {[holds_strings $actual $expected]} $constraints } | |
| 40 | + } | |
| 41 | +} | |
| 42 | + | |
| 43 | +# Run each row of TABLE: a test name, options for test-th-eval, a | |
| 44 | +# script, a mode and an expected value as th1main_check takes them. | |
| 45 | +# | |
| 46 | +proc th1main_table {table} { | |
| 47 | + foreach {name opts script mode expected} $table { | |
| 48 | + set got [th1main_eval $script {*}$opts] | |
| 49 | + th1main_check th1main-$name $got $mode $expected | |
| 50 | + } | |
| 51 | +} | |
| 52 | + | |
| 53 | +############################################################################### | |
| 54 | +# Every command refuses a call with too few or too many arguments. Each | |
| 55 | +# row is a call and the usage text of the error. | |
| 56 | + | |
| 57 | +foreach {th1mainName th1mainCall th1mainUsage} { | |
| 58 | + dir-few {dir} {dir CHECKIN ?GLOB? ?DETAILS?} | |
| 59 | + dir-many {dir a b 1 d} {dir CHECKIN ?GLOB? ?DETAILS?} | |
| 60 | + httpize-few {httpize} {httpize STRING} | |
| 61 | + httpize-many {httpize a b} {httpize STRING} | |
| 62 | + output-few {enable_output} {enable_output [LABEL] BOOLEAN} | |
| 63 | + output-many {enable_output a 1 c} {enable_output [LABEL] BOOLEAN} | |
| 64 | + nonce-many {nonce a} {nonce} | |
| 65 | + puts-few {puts} {puts STRING} | |
| 66 | + puts-many {puts a b} {puts STRING} | |
| 67 | + html-few {html} {puts STRING} | |
| 68 | + redirect-few {redirect} {redirect URL ?withMethod?} | |
| 69 | + redirect-many {redirect a 1 c} {redirect URL ?withMethod?} | |
| 70 | + insertcsrf-many {insertCsrf a} {insertCsrf} | |
| 71 | + verifycsrf-many {verifyCsrf a} {verifyCsrf} | |
| 72 | + login-few {verifyLogin a} {verifyLogin userName password} | |
| 73 | + login-many {verifyLogin a b c} {verifyLogin userName password} | |
| 74 | + markdown-few {markdown} {markdown STRING} | |
| 75 | + markdown-many {markdown a b} {markdown STRING} | |
| 76 | + wiki-few {wiki} {wiki STRING} | |
| 77 | + wiki-many {wiki a b} {wiki STRING} | |
| 78 | + decorate-few {decorate} {wiki STRING} | |
| 79 | + assoc-few {wiki_assoc a} {wiki_assoc STRING STRING} | |
| 80 | + assoc-many {wiki_assoc a b c} {wiki_assoc STRING STRING} | |
| 81 | + htmlize-few {htmlize} {htmlize STRING} | |
| 82 | + htmlize-many {htmlize a b} {htmlize STRING} | |
| 83 | + encode64-few {encode64} {encode64 STRING} | |
| 84 | + encode64-many {encode64 a b} {encode64 STRING} | |
| 85 | + hascap-few {hascap} {hascap STRING ...} | |
| 86 | + anoncap-few {anoncap} {hascap STRING ...} | |
| 87 | + capexpr-few {capexpr} {capexpr EXPR} | |
| 88 | + capexpr-many {capexpr a b} {capexpr EXPR} | |
| 89 | + searchable-few {searchable} {hascap STRING ...} | |
| 90 | + hasfeature-few {hasfeature} {hasfeature STRING} | |
| 91 | + hasfeature-many {hasfeature a b} {hasfeature STRING} | |
| 92 | + tclready-many {tclReady a} {tclReady} | |
| 93 | + anycap-few {anycap} {anycap STRING} | |
| 94 | + anycap-many {anycap a b} {anycap STRING} | |
| 95 | + combobox-few {combobox a b} {combobox NAME TEXT-LIST NUMLINES} | |
| 96 | + combobox-many {combobox a b 1 d} {combobox NAM ted {conCOPYLENGTH?} | |
| 97 | + copyb ?COPYLENGTH?} | |
| 98 | + copybtn-many {copybtn a 0 c 1 e} | |
| 99 | + {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?} | |
| 100 | + linecount-few {linecount a 1} {linecount STRING MAX MIN} | |
| 101 | + linecount-many {linecount a 1 2 3} {linecount STRING MAX MIN} | |
| 102 | + repository-many {repository 1 2} {repository ?BOOLEAN?} | |
| 103 | + checkout-many {checkout 1 2} {checkout ?BOOLEAN?} | |
| 104 | + trace-few {trace} {trace STRING} | |
| 105 | + trace-many {trace a b} {trace STRING} | |
| 106 | + state-few {globalState} {globalState NAME ?DEFAULT?} | |
| 107 | + state-many {globalState a b c} {globalState NAME ?DEFAULT?} | |
| 108 | + getparam-few {getParameter} {getParameter NAME ?DEFAULT?} | |
| 109 | + getparam-many {getParameter a b c} {getParameter NAME ?DEFAULT?} | |
| 110 | + setparam-few {setParameter a} {setParameter NAME VALUE} | |
| 111 | + setparam-many {setParameter a b c} {setParameter NAME VALUE} | |
| 112 | + reinit-many {reinitialize 1 2} {reinitialize ?FLAGS?} | |
| 113 | + render-few {render} {render STRING} | |
| 114 | + render-many {render a b} {render STRING} | |
| 115 | + defheader-many {defHeader a} {defHeader} | |
| 116 | + header-few {styleHeader} {styleHeader TITLE} | |
| 117 | + header-many {styleHeader a b} {styleHeader TITLE} | |
| 118 | + foote-few {gl. | |
| 119 | +# Scripts are run###########} eq 0 | |
| 120 | + glob-one-dasa b c}ript-many {styleScrimenu link LABEL URL} | |
| 121 | + submenu c} {submenu link LABEL URL} | |
| 122 | + submenu-word {submenu lin a b} {submenu link LABEL URL} | |
| 123 | + submenu-longer {submenu links a b} {submenu link LABEL URL} | |
| 124 | + requestjs-few {builtin_request_js} {builtin_request_js NAME} | |
| 125 | + requestjs-many {builtin_request_js a b} {builtin_request_js NAME} | |
| 126 | + artifact-few {artifact} {artifact ID ?FILENAME?} | |
| 127 | + artifac {reinitialize ad?} | |
| 128 | + http-many many e \ | |
| 129 | + {$CODE == 0 -- a b c}d?} | |
| 130 | + http-many {http -asynchronous -- a b c} | |
| 131 | + {http ?-asynchro {reinitialize ? ?--? url ?payload?} | |
| 132 | + http-none {http --} | |
| 133 | + {http ?-asynchronous? ad?} | |
| 134 | + http-many a b c} | |
| 135 | + {http ?-asynchronous? ?--? url ?payload?} | |
| 136 | + capture-few {captureTh1} {captureTh1 STRING} | |
| 137 | + capture-many {captureTh1 a b} {captureTh1 STRING} | |
| 138 | +} { | |
| 139 | + test_eq th1main-args-$th1mainName [th1main_eval $th1mainCall] \ | |
| 140 | + "THgot $mode $expected | |
| 141 | + } | |
| 142 | +} | |
| 143 | + | |
| 144 | +########################################################################################################## | |
| 145 | +# What the commands return and write. A script that writes ends with | |
| 146 | +# "set x {}" so that only what it wrote is printed. | |
| 147 | + | |
| 148 | +th1main_table { | |
| 149 | + httpize {} {httpize {a b/c?d&e=f%"<>}} eq {a+b%2Fc%3Fd%26e%3Df%25%22%3C%3E} | |
| 150 | + htmlize {} {htmlize {<a href="x">&'</a>}} | |
| 151 | + eq {<a href="x">&'</a>} | |
| 152 | + encode64 {} {encode64 {hello, world}} eq aGVsbG8sIHdvcmxk | |
| 153 | + encode64-empty {} {encode64 {}} eq {} | |
| 154 | + markdown {} {markdown "# Title\n\nbody *text*"} | |
| 155 | + has {{<div class="markdown">} {<p>body <em>text</em></p>}} | |
| 156 | + markdown-title {} {lindex [markdown "# Title\n\nbody *text*"] 0} eq Title | |
| 157 | + markdown-empty {} {lindex [markdown {}] 0} eq {} | |
| 158 | + | |
| 159 | + puts-escapes {} {puts "<b>&"; html "<i>"; set x {}} eq {<b>&<i>} | |
| 160 | + html-tainted {} {html [taint <i>]} | |
| 161 | + eq {TH_ERROR: tainted output string: "<i>"} | |
| 162 | + puts-tainted {} {puts [taint <i>]; set x {}} eq {<i>} | |
| 163 | + html-empty {} {html {}; set x done} eq done | |
| 164 | + untaint {} {string is tainted [untaint [taint abc]]} eq 0 | |
| 165 | + taint-length {} {string length [taint abc]} eq 3 | |
| 166 | + | |
| 167 | + hasfeature-markdown {} {hasfeature markdown} eq 1 | |
| 168 | + hasfeature-case {} {hasfeature MARKDOWN} eq 1 | |
| 169 | + hasfeature-unknown {} {hasfeature nosuch} eq 0 | |
| 170 | + hasfeature-empty {} {hasfeature {}} eq 0 | |
| 171 | + hasfeature-longer {} {hasfeature markdownx} eq 0 | |
| 172 | + tclready {} {tclReady} eq 0 | |
| 173 | + | |
| 174 | + anycap-empty {} {anycap {}} eq 0 | |
| 175 | + anycap-first {--set-user-caps} {anycap sz} eq 1 | |
| 176 | + anycap-second {--set-user-caps} {anycap zs} eq 1 | |
| 177 | + anycap-none {} {anycap sz} eq 0 | |
| 178 | + hascap-empty {} {hascap {}} eq 1 | |
| 179 | + hascap-all {--set-user-caps} {hascap s x} eq 1 | |
| 180 | + hascap-none {} {hascap s} eq 0 | |
| 181 | + anoncap-all {--set-anon-caps} {anoncap s x} eq 1 | |
| 182 | + anoncap-user-only {--set-user-caps} {anoncap s} eq 0 | |
| 183 | + capexpr-empty {} {capexpr {}} eq 0 | |
| 184 | + capexpr-star {} {capexpr {*}} eq 1 | |
| 185 | + capexpr-not {} {capexpr {!s}} eq 1 | |
| 186 | + capexpr-not-held {--set-user-caps} {capexpr {!s}} eq 0 | |
| 187 | + capexpr-anon {} {capexpr {@s}} eq 0 | |
| 188 | + capexpr-anon-held {--set-anon-caps} {capexpr {@s}} eq 1 | |
| 189 | + capexpr-second {} {capexpr {zz !zz}} eq 1 | |
| 190 | + capexpr-held {--set-user-caps} {capexpr {z sx}} eq 1 | |
| 191 | + | |
| 192 | + linecount-max {} {linecount "a\nb\nc\nd" 3 1} eq 3 | |
| 193 | + linecount-min {} {linecount "a\nb" 10 5} eq 5 | |
| 194 | + linecount-between {} {linecount "a\nb\nc" 10 1} eq 3 | |
| 195 | + linecount-empty {} {linecount {} 0 0} eq 0 | |
| 196 | + linecount-negative {} {linecount "a\nb\nc" -5 -9} eq -5 | |
| 197 | + linecount-widest {} {linecount "a\nb\nc" 2147483647 -2147483648} eq 3 | |
| 198 | + linecount-bad-max {} {linecount x a 1} | |
| 199 | + eq {TH_ERROR: expected integer, got: "a"} | |
| 200 | + linecount-bad-min {} {linecount x 1 b} | |
| 201 | + eq {TH_ERROR: expected integer, got: "b"} | |
| 202 | + linecount-too-big {} {linecount x 99999999999 1} eq 1 | |
| 203 | + | |
| 204 | + combobox {} {set nm b; combobox nm {a b <c>} 3; set x {}} | |
| 205 | + eq {<select id="nm" name="nm" size="3"><option value="a">a</option><option value="b" selected="selected">b</option><option value="<c>"><c></option></select>} | |
| 206 | + combobox-same-length {} {set nm x; combobox nm {a b} 1; set x {}} | |
| 207 | + eq {<select id="nm" name="nm" size="1"><option value="a">a</option><option value="b">b</option></select>} | |
| 208 | + combobox-other-length {} {set nm bb; combobox nm {a b} 1; set x {}} | |
| 209 | + eq {<select id="nm" name="nm" size="1"><option value="a">a</option><option value="b">b</option></select>} | |
| 210 | + combobox-no-variable {} {combobox {n"m} {a} 1; set x {}} | |
| 211 | + eq {<select id="n"m" name="n"m" size="1"><option value="a">a</option></select>} | |
| 212 | + combobox-no-values {} {set nm x; combobox nm {} 1; set x {}} | |
| 213 | + eq {<select id="nm" name="nm" size="1"></select>} | |
| 214 | + combobox-bad-lines {} {combobox nm {a b} x} | |
| 215 | + eq {TH_ERROR: expected integer, got: "x"} | |
| 216 | + | |
| 217 | + output-off {} {enable_output 0; puts hidden; html hidden; | |
| 218 | + combobox nm {a b} 1; copybtn id 0 text; wiki {[x]}; decorate {[x]} | |
| 219 | + enable_output 1; puts shown; set x {}} eq shown | |
| 220 | + output-label {} {enable_output lbl 0; puts hidden; enable_output lbl 1 | |
| 221 | + puts shown; set x {}} eq shown | |
| 222 | + output-bad {} {enable_output lbl xyz} | |
| 223 | + eq {TH_ERROR: expected integer, got: "xyz"} | |
| 224 | + output-off-error {} {enable_output 0; render {<th1>error shown</th1>} | |
| 225 | + set x {}} has {{ERROR: shown}} | |
| 226 | + | |
| 227 | + copybtn {} {copybtn cid 0 text; set x {}} | |
| 228 | + has {{data-copytarget="cid"} {data-copylength="0"} | |
| 229 | + {<span id="cid">text</span>} !copy-button-flipped} | |
| 230 | + copybtn-flipped {} {copybtn cid 1 {<t>} 3; set x {}} | |
| 231 | + has {{data-copylength="3"} copy-button-flipped | |
| 232 | + {<span id="cid"><t></span>}} | |
| 233 | + copybtn-bad-flipped {} {copybtn cid x text} | |
| 234 | + eq {TH_ERROR: expected integer, got: "x"} | |
| 235 | + copybtn-bad-length {} {copybtn cid 0 text x} | |
| 236 | + eq {TH_ERROR: expected integer, got: "x"} | |
| 237 | + | |
| 238 | + repository {} {repository} re {/\.rep\.fossil$} | |
| 239 | + repository-0 {} {repository 0} re {/\.rep\.fossil$} | |
| 240 | + repository-1 {} {repository 1} re {/\.rep\.fossil$} | |
| 241 | + repository-bad {} {repository x} eq {TH_ERROR: expected integer, got: "x"} | |
| 242 | + checkout {} {checkout} re {/th1main\.test/$} | |
| 243 | + checkout-0 {} {checkout 0} re {/th1main\.test/$} | |
| 244 | + checkout-1 {} {checkout 1} re {/th1main\.test/$} | |
| 245 | + checkout-bad {} {checkout x} eq {TH_ERROR: expected integer, got: "x"} | |
| 246 | + | |
| 247 | + state-unknown {} {globalState nosuch} | |
| 248 | + eq {TH_ERROR: unsupported global state: nosuch} | |
| 249 | + state-checkout {} {globalState checkout dflt} re {/th1main\.test/$} | |
| 250 | + state-case {} {globalState CHECKOUT} re {/th1main\.test/$} | |
| 251 | + state-longer {} {globalState checkouts} | |
| 252 | + eq {TH_ERROR: unsupported global state: checkouts} | |
| 253 | + state-configuration {--open-config} {globalState configuration dflt} | |
| 254 | + re {fossil} | |
| 255 | + state-executable {} {globalState executable dflt} re {fossil[^/]*$} | |
| 256 | + state-flags {} {globalState flags} eq 0 | |
| 257 | + state-flags-config {--open-config} {expr {[globalState flags] & 0x600}} | |
| 258 | + eq 1024 | |
| 259 | + state-log {} {globalState log dflt} eq dflt | |
| 260 | + state-log-set {--errorlog th1main-errors.log} {globalState log dflt} | |
| 261 | + re {th1main-errors\.log$} | |
| 262 | + state-repository {} {globalState repository dflt} re {/\.rep\.fossil$} | |
| 263 | + state-top {} {globalState top dflt} eq dflt | |
| 264 | + state-user {} {globalState user dflt} eq dflt | |
| 265 | + state-vfs {} {globalState vfs dflt} eq dflt | |
| 266 | + state-vfs-set {--vfs unix-none} {globalState vfs dflt} eq unix-none | |
| 267 | + | |
| 268 | + reinit {} {reinitialize; globalState flags} eq 0 | |
| 269 | + reinit-reset {} {reinitialize 4; globalState flags} eq 4 | |
| 270 | + reinit-setup {} {reinitialize 8; globalState flags} eq 8 | |
| 271 | + reinit-no-tcl {} {reinitialize 31; globalState flags} eq 29 | |
| 272 | + reinit-bad {} {reinitialize x} eq {TH_ERROR: expected integer, got: "x"} | |
| 273 | + reinit-keeps-procs {} {proc p {} {return kept}; reinitialize 4; p} eq kept | |
| 274 | + | |
| 275 | + render {} {set v 5; render {a $v <th1>puts [expr {$v+1}]</th1> b} | |
| 276 | + set x {}} eq {a 5 6 b} | |
| 277 | + render-error {} {render {<th1>error inner</th1>}; puts after} | |
| 278 | + eq {<hr><p class="thmainError">ERROR: inner</p>TH_ERROR: } | |
| 279 | + submenu-no-label {} {submenu link {} /url} | |
| 280 | + eq {TH_ERROR: link's LABEL is empty} | |
| 281 | + submenu-no-url {} {submenu link label {}} eq {TH_ERROR: link's URL is empty} | |
| 282 | + defheader {} {defHeader} has {<html> {$<title>}} | |
| 283 | + | |
| 284 | + dir {} {dir tip} eq {a.txt f100.txt f83.txt} | |
| 285 | + dir-glob {} {dir tip {f*}} eq {f100.txt f83.txt} | |
| 286 | + dir-glob-none {} {dir tip nomatch} eq {} | |
| 287 | + dir-details {} {dir tip {a*} 1} | |
| 288 | + re {^\{a\.txt 6 \{\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\}\}$} | |
| 289 | + dir-details-0 {} {dir tip {a*} 0} eq a.txt | |
| 290 | + dir-details-bad {} {dir tip * x} eq {TH_ERROR: expected integer, got: "x"} | |
| 291 | + dir-unknown {} {dir nosuch} eq {} | |
| 292 | + dir-empty-name {} {dir {}} eq {} | |
| 293 | + | |
| 294 | + artifact-file {} {artifact tip a.txt} eq hello | |
| 295 | + artifact-checkin {} {artifact tip} has {{C three\sfiles} {F a.txt }} | |
| 296 | + artifact-unknown {} {artifact nosuch} eq {TH_ERROR: name not found} | |
| 297 | + artifact-empty-name {} {artifact {}} eq {TH_ERROR: } | |
| 298 | + artifact-unknown-checkin {} {artifact nosuch a.txt} | |
| 299 | + eq {TH_ERROR: manifest not found} | |
| 300 | + artifact-not-a-checkin {} {artifact [lindex [artifact tip] 6] a.txt} | |
| 301 | + re {^TH_ERROR: } | |
| 302 | + artifact-unknown-file {} {artifact tip nosuch} | |
| 303 | + eq {TH_ERROR: file name not found in manifest} | |
| 304 | + | |
| 305 | + glob-list {} {glob_match {*.txt,*.c} a.c} eq 2 | |
| 306 | + glob-list-none {} {glob_match {*.txt,*.c} a.h} eq 0 | |
| 307 | + glob-empty {} {glob_match {} x} | |
| 308 | + eq {TH_ERROR: unable to create glob from pattern list} | |
| 309 | + glob-one {} {glob_match -one {*.c} a.c} eq 1 | |
| 310 | + glob-one-none {} {glob_match -one {*.c} a.h} eq 0 | |
| 311 | + glob-one-dashes {} {glob_match -one -- -one -one} eq 1 | |
| 312 | + glob-dashes {} {glob_match -- {*.c} a.h} eq 0 | |
| 313 | + | |
| 314 | + regexp {} {regexp {^a+b$} aaab} eq 1 | |
| 315 | + regexp-case {} {regexp {^a+b$} AAAB} eq 0 | |
| 316 | + regexp-nocase {} {regexp -nocase {^a+b$} AAAB} eq 1 | |
| 317 | + regexp-dashes {} {regexp -nocase -- -nocase -NOCASE} eq 1 | |
| 318 | + regexp-empty {} {regexp {} {}} eq 1 | |
| 319 | + regexp-unclosed {} {regexp {((a} x} eq {TH_ERROR: unmatched '('} | |
| 320 | + regexp-bracket {} {regexp {[} x} eq {TH_ERROR: unclosed '['} | |
| 321 | + regexp-too-big {} {regexp [string repeat {(a|b)*} 2000] x} | |
| 322 | + eq {TH_ERROR: REGEXP pattern too big} | |
| 323 | + | |
| 324 | + setting {} {setting autosync} re {^(on|off|0|1)?$} | |
| 325 | + setting-unknown {} {setting th1main-no-such-setting} eq {} | |
| 326 | + setting-strict-unknown {} {setting -strict th1main-no-such-setting} | |
| 327 | + eq {TH_ERROR: no value for setting "th1main-no-such-setting"} | |
| 328 | + | |
| 329 | + capture {} {captureTh1 {puts <b>; html <i>}} eq {<b><i>} | |
| 330 | + capture-error {} {captureTh1 {puts lost; error boom}} eq {TH_ERROR: boom} | |
| 331 | + capture-return {} {captureTh1 {return 9}} eq {TH_RETURN: 9} | |
| 332 | + capture-nested {} {puts a; set r [captureTh1 {puts b | |
| 333 | + puts [captureTh1 {puts c}]}]; puts d; set r} eq adbc | |
| 334 | + capture-render {} {set v <b>; captureTh1 {render {x<th1>puts y</th1>$<v>z}}} | |
| 335 | + eq {xy<b>z} | |
| 336 | + capture-render-error {} {captureTh1 {render {x$<nosuch>z}}} eq {TH_ERROR: } | |
| 337 | + capture-widgets {} {set nm a; captureTh1 {combobox nm {a} 1 | |
| 338 | + copybtn cid 0 t}} has {{<select id="nm"} {<span id="cid">t</span>}} | |
| 339 | + | |
| 340 | + login-good {} {verifyLogin u1 pw1} eq 1 | |
| 341 | + login-wrong-password {} {verifyLogin u1 wrong} eq 0 | |
| 342 | + login-unknown-user {} {verifyLogin nosuch pw1} eq 0 | |
| 343 | + login-empty {} {verifyLogin {} {}} eq 0 | |
| 344 | + | |
| 345 | + date {} {date} re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} | |
| 346 | + date-other-option {} {date -utc} re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} | |
| 347 | + date-longer-option {} {date -localx} re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} | |
| 348 | + date-same-length-option {} {date -locax} | |
| 349 | + re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} | |
| 350 | + utime {} {utime} re {^\d+$} | |
| 351 | + stime {} {stime} re {^\d+$} | |
| 352 | + | |
| 353 | + randhex {} {randhex} re {^[0-9a-f]{20}$} | |
| 354 | + randhex-3 {} {randhex 3} re {^[0-9a-f]{6}$} | |
| 355 | + randhex-0 {} {randhex 0} re {^[0-9a-f]{2}$} | |
| 356 | + randhex-negative {} {randhex -5} re {^[0-9a-f]{2}$} | |
| 357 | + randhex-49 {} {randhex 49} re {^[0-9a-f]{98}$} | |
| 358 | + randhex-bad {} {randhex x} eq {TH_ERROR: expected integer, got: "x"} | |
| 359 | + | |
| 360 | + query {} {query {SELECT 1 AS a, 'x' AS b UNION ALL SELECT 2, 'y'} { | |
| 361 | + puts "$a$b "}; set x {}} eq {1x 2y } | |
| 362 | + query-variables {} {set v 7; set w {it's} | |
| 363 | + query {SELECT $v+1 AS a, $w='it''s' AS b, $nosuch IS NULL AS c, | |
| 364 | + :v IS NULL AS d, ?5 IS NULL AS e, ? IS NULL AS f} { | |
| 365 | + puts "$a/$b/$c/$d/$e/$f"}; set x {}} eq {8/1/1/1/1/1} | |
| 366 | + query-null-and-blob {} {query {SELECT NULL AS a, x'410042' AS b} { | |
| 367 | + puts "[string length $a]/[string length $b]"}; set x {}} eq 0/3 | |
| 368 | + query-values-tainted {} {query {SELECT 'v' AS a} { | |
| 369 | + puts [string is tainted $a]}; set x {}} eq 1 | |
| 370 | + query-column-names {} {query {SELECT 1 AS "", 2 AS "a(b", 3 AS "a b"} { | |
| 371 | + puts ran}; set x {}} eq ran | |
| 372 | + query-no-rows {} {query {SELECT 1 WHERE 0} {puts never}; set x none} | |
| 373 | + eq none | |
| 374 | + query-empty {} {query {} {puts never}; set x none} eq none | |
| 375 | + query-spaces {} {query { } {puts never}; set x none} eq none | |
| 376 | + query-semicolon {} {query {;} {puts never}; set x none} eq none | |
| 377 | + query-break {} {query {SELECT 1 AS a UNION ALL SELECT 2} { | |
| 378 | + puts $a; break}; set x {}} eq 12 | |
| 379 | + query-continue {} {query {SELECT 1 AS a UNION ALL SELECT 2} { | |
| 380 | + puts $a; continue; puts never}; set x {}} eq 12 | |
| 381 | + query-return {} {query {SELECT 1 AS a UNION ALL SELECT 2} { | |
| 382 | + puts $a; return 7}} eq {1TH_RETURN: 7} | |
| 383 | + query-error {} {query {SELECT 1 AS a UNION ALL SELECT 2} { | |
| 384 | + puts $a; error boom}} eq {1TH_ERROR: boom} | |
| 385 | + query-nested {} {query {SELECT 1 AS a} {query {SELECT 2 AS b} { | |
| 386 | + puts $a$b}}; set x {}} eq 12 | |
| 387 | + query-bad-sql {} {query {SELECT nosuch} {puts never}} | |
| 388 | + eq {TH_ERROR: SQL error: no such column: nosuch} | |
| 389 | + query-bad-sql-quiet {} {query -nocomplain {SELECT nosuch} {puts never} | |
| 390 | + set x quiet} eq quiet | |
| 391 | + query-quiet {} {query -nocomplain {SELECT 4 AS a} {puts $a}; set x {}} eq 4 | |
| 392 | + query-delete {} {query {DELETE FROM user} {puts never}} | |
| 393 | + eq {TH_ERROR: SQL error: not authorized} | |
| 394 | + query-delete-quiet {} {query -nocomplain {DELETE FROM user} {puts never} | |
| 395 | + set x quiet} eq quiet | |
| 396 | + query-update {} {query {UPDATE config SET value=1} {puts never}} | |
| 397 | + eq {TH_ERROR: SQL error: not authorized} | |
| 398 | + query-password {} {query {SELECT pw FROM user} {puts never}} | |
| 399 | + re {^TH_ERROR: SQL error: } | |
| 400 | + query-step-error {} {query {SELECT abs(-9223372036854775807-1) AS a} { | |
| 401 | + puts never}} eq {TH_ERROR: SQL error: integer overflow} | |
| 402 | + query-step-error-quiet {} { | |
| 403 | + query -nocomplain {SELECT abs(-9223372036854775807-1) AS a} {puts never} | |
| 404 | + set x quiet} eq quiet | |
| 405 | + query-option-as-sql {} {query -nocomplain {puts never}} | |
| 406 | + eq {TH_ERROR: SQL error: near "-": syntax error} | |
| 407 | + query-option-misspelt {} {query -nocomplaix {SELECT 1} {puts never}} | |
| 408 | + eq {TH_ERROR: wrong # args: should be "query SQL CODE"} | |
| 409 | + query-tainted {} {query [taint {SELECT 1}] {puts never}} | |
| 410 | + eq {TH_ERROR: tainted query SQL: "SELECT 1"} | |
| 411 | + query-undefined {} {query $nosuch {}} eq {TH_ERROR: no such variable: nosuch} | |
| 412 | + | |
| 413 | + code-break {} {break} re {^TH_BREAK: } | |
| 414 | + code-continue {} {continue} re {^TH_CONTINUE: } | |
| 415 | + code-return {} {return x} eq {TH_RETURN: x} | |
| 416 | + code-return2 {} {return -code 5 x} eq {TH_RETURN2: x} | |
| 417 | + code-other {} {return -code 99 x} eq {TH1 return code 99: x} | |
| 418 | +} | |
| 419 | + | |
| 420 | +test_eq th1main-capexpr-not-list [th1main_eval "capexpr \"\{\""] \ | |
| 421 | + "TH_ERROR: Expected list, got: \"\{\"" | |
| 422 | + | |
| 423 | +# With capability "o" alone for the user and "h" alone for anonymous. | |
| 424 | +set env(TH1_TEST_USER_CAPS) o | |
| 425 | +set env(TH1_TEST_ANON_CAPS) h | |
| 426 | +th1main_table { | |
| 427 | + caps-hascap {--set-user-caps} {hascap o} eq 1 | |
| 428 | + caps-hascap-first-missing {--set-user-caps} {hascap z o} eq -local]"; set x {}}] \ | |
| 429 | + {$th1mainSavedTz eq ""} { unset env(TZ) } else \ | |
| 430 | + { set env(TZ) $th1mainSavedTz } | |
| 431 | +fossil settings timeline-utc 1 | |
| 432 | +set th1mainDiff [expr {[clock scan [lindex $th1mainDates 1] -gmt 1] | |
| 433 | + - [clock scan [lindex $th1mainDates 0] -gmt 1]}] | |
| 434 | +test th1main-date-local {$th1mainDiff >= 17999 && $th1mainDiff <= 18001} | |
| 435 | + | |
| 436 | +# A script given as the name of a file is read from the file. | |
| 437 | +write_file script.th1 "puts from-file; set x {}\n" | |
| 438 | +test_eq th1main-eval-file [th1main_eval script.th1] from-file | |
| 439 | + | |
| 440 | +fossil_raw test-th-eval | |
| 441 | +test th1main-eval-usage {$CODE == 1 && [string match "Usage: *" $RESULT]} | |
| 442 | +fossil_raw test-th-eval a b | |
| 443 | +test th1main-eval-usage-many {$CODE == 1 && [string match "Usage: *" $RESULT]} | |
| 444 | + | |
| 445 | +############################################################################### | |
| 446 | +# Unversioned files. | |
| 447 | + | |
| 448 | +# In a repository that has never held an unversioned file, "unversioned | |
| 449 | +# list" gives an empty list and "unversioned content" a script error. | |
| 450 | +set th1mainGot [th1main_eval {unversioned list}] | |
| 451 | +test th1main-uv-list-none {$CODE == 0 && $th1mainGot eq ""} | |
| 452 | +set th1mainGot [th1main_eval {unversioned content nosd?} | |
| 453 | + http-many le u.txt "data\n" | |
| 454 | +write_file v.txt "more\n" | |
| 455 | +fossil uv add u.txt v.txt | |
| 456 | +fossil uv rm v.txt | |
| 457 | +th1main_table { | |
| 458 | + uv-list {} {unversioned list} eq u.txt | |
| 459 | + uv-content {} {unversioned content u.txt} eq data | |
| 460 | + uv-content-unknown {} {unversioned content nosuch} re {^TH_ERROR: } | |
| 461 | + uv-unknown {} {unversioned nosuch} | |
| 462 | + eq {TH_ERROR: Expected sub-command, got: nosuch} | |
| 463 | +} | |
| 464 | + | |
| 465 | +# knownBug: the content of a removed file is given as an empty string; | |
| 466 | +# "unversioned list" does not list the file. | |
| 467 | +test_match th1main-uv-content-removed \ | |
| 468 | + [th1main_eval {unversioned content v.txt}] {^TH_ERROR: } knownBug | |
| 469 | + | |
| 470 | +######### [join [list \ | |
| 471 | + "seth1mainSql} {set n \[expr {\$n+1}\\ | |
| 472 | + {{GET /xset n"] ""] | |
| 473 | + test th1main-query-statements-$th1mainName \ | |
| 474 | + {$CODE == 0 two 2 space 1} \ | |
| 475 | + $th1mainName]} | |
| 476 | +} | |
| 477 | + | |
| 478 | +# builtin_request_js with a name that is not a built-in file gives a | |
| 479 | +# script error. | |
| 480 | +set th1mainGot [th1main_eval {builtin_request_js nosuch.js}] | |
| 481 | +test th1main-requestjs-unknown {$CODE == 0} | |
| 482 | + | |
| 483 | +# randhex gives at most 50 bytes, 100 digits. | |
| 484 | +test_match th1main-randhex-50 [th1main_eval {randhex 50}] {^[0-9a-f]{100}$} | |
| 485 | +test th1main-randhex-50-exit {$CODE == 0} | |
| 486 | +test_match th1main-randhex-over [th1main_eval {randhex 1000}] {^[0-9a-f]{100}$} | |
| 487 | + | |
| 488 | +# http with text that is not a URL gives a script error. | |
| 489 | +set th1mainGot [th1main_eval {http not-a-url}] | |
| 490 | +test th1main-http-not-url \ | |
| 491 | + {$CODE == 0 && [string match "TH_ERROR: *" $th1mainGot]} | |
| 492 | + | |
| 493 | +# A phantom: an artifact whose content the repository does nohe repository does not hold. | |
| 494 | +set th1mainPhantom \ | |
| 495 | + abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 | |
| 496 | +fossil sql "INSERT INTO blob(rcvid,size,uuid) VALUES(0,-1,'$th1mainPhantom'); | |
| 497 | + INSERT INTO phantom SELECT rid FROM blob WHERE size=-1;" | |
| 498 | +test_match th1main-artifact-phantom \ | |
| 499 | + [th1main_eval "artifact $th1mainPhantom"] {^TH_ERROR: } | |
| 500 | + | |
| 501 | +############################################################################### | |
| 502 | +# The http command. Only a URL that matches the th1-uri-regexp setting | |
| 503 | +# is allowed, and only an asynchronous request is implemented. | |
| 504 | + | |
| 505 | +th1main_table { | |
| 506 | + http-ssh {} {http ssh://host/path} | |
| 507 | + eq {TH_ERROR: url must be http:// or https:// } | |
| 508 | + http-file {} {http file:///tmp/x} | |
| 509 | + eq {TH_ERROR: url must be http:// or https:// } | |
| 510 | + http-no-setting {} {http http://localhost/x} eq {TH_ERROR: url not allowed} | |
| 511 | + http-no-setting-async {} {http -asynchronous -- http://localhost/x} | |
| 512 | + eq {TH_ERROR: url not allowed} | |
| 513 | +} | |
| 514 | +fossil test-var-set th1-uri-regexp "" | |
| 515 | +test_eq th1main-http-empty-setting [th1main_eval {http http://localhost/x}] \ | |
| 516 | + {TH_ERROR: url not alloet]\r\n"]]} | |
| 517 | + th1mai://localhost/x}] \ | |
| 518 | + {TH_ERROR:payload}ting-async pos {http -asyn################### | |
| 519 | +# | |
| 520 | +# Fossil's own TH1 commands and the template renderer: src/th_main.c. | |
| 521 | +# Scripts are run with "fossil test-th-eval", templates with | |
| 522 | +# "fossil test-th-render" and "fossil test-th-source", and a ticket page | |
| 523 | +# that holds TH1 is asked for through "fossil http --in". | |
| 524 | +# | |
| 525 | + | |
| 526 | +# The first sections run at every level, and the rest need | |
| 527 | +# -assurance stress. | |
| 528 | +test_setup | |
| 529 | + | |
| 530 | +write_file a.txt "hello\n" | |
| 531 | +write_file f83.txt "line 83\n" | |
| 532 | +write_file f100.txt "line 100\n" | |
| 533 | +fossil add a.txt f83.txt f100.txt | |
| 534 | +fossil commit -m "three files" | |
| 535 | +fossil user new u1 "" pw1 | |
| 536 | +set th1mainRepo [file join [pwd] .rep.fossil] | |
| 537 | + | |
| 538 | +# Run SCRIPT with "fossil test-th-eval" and the options in ARGS. Returns | |
| 539 | +# what fossil printed, without the final newline. | |
| 540 | +# | |
| 541 | +# A build with TH1 hooks runs th1-setup and opens the checkout before the | |
| 542 | +# command itself; these tests are of the commands, so they turn hooks off. | |
| 543 | +fossil test-th-eval "hasfeature th1Hooks" | |
| 544 | +set th1mainNoHook [expr {[string trim $RESULT] eq "1" ? "--no-th-hook" : ""}] | |
| 545 | + | |
| 546 | +proc th1main_eval {script args} { | |
| 547 | + fossil_raw -seconds 60 test-th-eval {*}$::th1mainNoHook {*}$args $script | |
| 548 | + return [string trimright $::RESULT \n] | |
| 549 | +} | |
| 550 | + | |
| 551 | +# Test NAME passes if ACTUAL is as EXPECTED says. MODE is "eq" for an | |
| 552 | +# exact value, "re" for a regular expression, or "has" for a list ########################## | |
| 553 | + http://x/elsewhere\r\n"]]} | |
| 554 | + | |
| 555 | +############################################################################### | |
| 556 | +# With######################## | |
| 557 | +# Tracing: --th-trace prints a log of what the commands did. | |
| 558 | + | |
| 559 | +foreach {th1mainName th1mainOpts th1mainScript th1mainWanted} { | |
| 560 | + output {} {enable_output lbl 1} {{enable_output {lbl} -> 1<br>}} | |
| 561 | + hascap {--set-user-caps} {hascap s x} {{[hascap s x] => 1<br>}} | |
| 562 | + hascap-missing {} {hascap s x} {{[hascap s] => 0<br>}} | |
| 563 | + anycap {--set-user-caps} {anycap zs} {{[anycap zs] => 1<br>}} | |
| 564 | + searchable {} {searchable cdtw} {{[searchable cdtw] => 0<br>}} | |
| 565 | + hasfeature {} {hasfeature markdown} {{[hasfeature markdown] => 1<br>}} | |
| 566 | + tclready {} {tclReady} {{[tclReady] => 0<br>}} | |
| 567 | + trace {} {trace {a message}} {{a message}} | |
| 568 | + setting {} {setting th1main-no-such-setting} | |
| 569 | + {{[setting th1main-no-such-setting] => 0<br>}} | |
| 570 | +"a\ | |
| 571 | + "a${th1mainNoVar}etting} | |
| 572 | + {{[setting strict th1main-no-such-setting] => 1<br>}} | |
| 573 | + query {} {query {SELECT 1 AS a} {set y <$a>}} | |
| 574 | + {{query_eval {<pre>set y <$a></pre>}<br>} | |
| 575 | + {[query_eval] => TH_OK {<1>}<br>}} | |
| 576 | + render {} {render {<th1>set y <b></th1>}} | |
| 577 | + {{render_eval {<pre>set y <b></pre>}<br>} | |
| 578 | + {[render_eval] => TH_OK {<b>}<br>}} | |
| 579 | + init {} {reinitialize 12} {{th1-init 0x0 => 0x0<br>} {th1-init 0x0 => 0xc<br>} | |
| 580 | + {th1-setup {} => TH_OK<br>}} | |
| 581 | + header {--cgi} {styleHeader {A Title}} {{set titl{v}} {a$1 $_ $: $:: $::1 $<1> ${v}} \ | |
| 582 | + variables \ | |
| 583 | + {<th1>set v {<b>&}; set ::g G; set v_2 two</th1>[$v][$<v>][$::g][$<::g>][$v_2]} \ | |
| 584 | + {[<b>&][<b>&][G][G][two]} \ | |
| 585 | + variable-then-text {<th1>set v 1</th1>$v-escaped {a$<nosuch>b} \ | |
| 586 | + "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuchrr}no such variable: n-escaped {a$<nosuch>b} \ | |
| 587 | + "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \ | |
| 588 | + variable-unknown-then-known {<th1>se1</th1>a$nosuch b$v c} \ | |
| 589 | + "a${th1mainNoVar}nosuch b1 c" \ | |
| 590 | + variable-tainted {<th1>set t [taininted {<th1>set t [taint <i> {ah1mainGot [th1main_re<i>]end} \ | |
| 591 | + error-plain {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \ | |
| 592 | + error-escaped {<th1>error <b></th1>} "${th1mainErr}<b></p>" \ | |
| 593 | + nested {<th1>set v 2; render {b$<v>|}; render {c$v}</th1>d} {b2|c2d} \ | |
| 594 | + nested-error {<th1>render {b$<v>|}; puts never</th1>d} \ | |
| 595 | + "b${th1mainNoVar}v${th1mainErr}no variable: v</p>${th1mainErr}</p>" \ | |
| 596 | + output-off \ | |
| 597 | + {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \ | |
| 598 | +] { | |
| 599 | + test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \ | |
| 600 | + $th1mainExpected | |
| 601 | + test th1main-render-$th1mainName-exit {$CODE == 0} | |
| 602 | +} | |
| 603 | + | |
| 604 | +# A script that ends with break, continue or return ends the template; | |
| 605 | +# nothing of the block is written to the output. | |
| 606 | +foreach {th1mainName th1mainText} { | |
| 607 | + break {a<th1>break</th1>after} | |
| 608 | + continue {a<th1>continue</th1>after} | |
| 609 | + return {a<th1>return 5</th1>after} | |
| 610 | +} { | |
| 611 | + test_eq th1main-render-$th1mainName [th1main_render $th1mainText] a | |
| 612 | +} | |
| 613 | + | |
| 614 | +# Text after a zero byte in the file is not rendered. | |
| 615 | +test_eq th1main-render-zero-byte [th1main_render "a\0b<th1>puts c</th1>"] a | |
| 616 | + | |
| 617 | +set th1mainGot [th1main_render {<th1>puts hello</th1>} --cgi] | |
| 618 | +test th1main-render-cgi {[holds_strings $th1mainGot [list \ | |
| 619 | + "Status: 200 OK\r\n" "Content-Length: 5\r\n" "\r\n\r\nhello"]]} | |
| 620 | +set th1mainGot [th1main_render {<th1>error boom</th1>} --http] | |
| 621 | +test th1main-render-http {[holds_strings $th1mainGot [list \ | |
| 622 | + "HTTP/1.0 200 OK\r\n" "${th1mainErr}boom</p>"]]} | |
| 623 | +test_match th1main-render-open-config \ | |
| 624 | + [th1main_render {<th1>puts [globalState configuration none]</th1>} \ | |
| 625 | + --open-config] {fossil} | |
| 626 | +test_eq th1main-render-user-caps \ | |
| 627 | + [th1main_render {<th1>puts [hascap s][anoncap s]</th1>} --set-user-caps] 10 | |
| 628 | +test_eq th1main-render-anon-caps \ | |
| 629 | + [th1main_render {<th1>puts [anoncap s]</th1>} --set-anon-caps] 1 | |
| 630 | +set env(TH1_TEST_USER_CAPS) o | |
| 631 | +set env(TH1_TEST_ANON_CAPS) h | |
| 632 | +test_eq th1ma{<th1>ff \ | |
| 633 | + {<th1>enable_alikes {<th1>seto][hascap s][ah1mainErr}no such variable: v</p>${th1mainErr}</p>" \ | |
| 634 | + output-off \ | |
| 635 | + {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \ | |
| 636 | +] { | |
| 637 | + test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \ | |
| 638 | + $th1mainExpected | |
| 639 | + test th1main-render-$th1mainName-exit {$CODE == 0} | |
| 640 | +} | |
| 641 | + | |
| 642 | +# A script that ends with break, continue or return ends the template; | |
| 643 | +# nothing of the block is written to the output. | |
| 644 | +foreach {th1mainName th1mainText} { | |
| 645 | + break {a<th1>break</th1>after} | |
| 646 | + continue {a<th1>continue</th1>after} | |
| 647 | + return {a<th1>return 5</th1>after} | |
| 648 | +} { | |
| 649 | + test_eq th1main-render-$th1mainName [th1main_render $th1mainText] a | |
| 650 | +} | |
| 651 | + | |
| 652 | +# Text after a zero byte in the file is not rendered. | |
| 653 | +test_eq th1main-render-zero-byte [th1main_render "a\0b<th1>puts c</th1>"] a | |
| 654 | + | |
| 655 | +set th1mainGot [th1main_render {<th1>puts hello</th1>} --cgi] | |
| 656 | +test th1main-render-cgi {[holds_strings $th1mainGot [list \ | |
| 657 | + "Status: 200 OK\r\n" "Content-Length: 5\r\n" "\r\n\r\nhello"]]} | |
| 658 | +set th1mainGot [th1main_render {<th1>error boom</th1>} --http] | |
| 659 | +test th1main-render-http {[holds_strings $th1mainGot [list \ | |
| 660 | + "HTTP/1.0 200 OK\r\n" "${th1mainErr}boom</p>"]]} | |
| 661 | +test_match th1main-render-open-config \ | |
| 662 | + [th1main_render {<th1>puts [globalState configuration none]</th1>} \ | |
| 663 | + --open-config] {fossil} | |
| 664 | +test_eq th1main-render-user-caps \ | |
| 665 | + [th1main_render {<th} | |
| 666 | + query-bad-sql-quiet {} [th1main_source \ | |
| 667 | + {query -nocomplain {SELECT 1 AS a} {puts $a}; set x quiet}] \ | |
| 668 | + quiet | |
| 669 | +test_eq th1main-source-no-repository [th1main_source {repository}] {} | |
| 670 | +test_match th1main-source-repository [th1main_source {repository 1}] \ | |
| 671 | + {/\.rep\.fossil$} | |
| 672 | +test_match th1main-source-checkout [th1main_source {checkout 1}] \ | |
| 673 | + {/th1main\.test/$} | |
| 674 | +test_eq th1main-source-checkout-not-opened [th1main_source {checkout 0}] {} | |
| 675 | +test_match th1main-source-open-config \ | |
| 676 | + [th1main_source {globalState configuration none} --open-config] {fossil} | |
| 677 | +test_eq th1main-source-user-caps \ | |
| 678 | + [th1main_source {puts [hascap s][anoncap s]; set x {}} --set-user-caps] 10 | |
| 679 | +test_eq th1main-source-anon-caps \ | |
| 680 | + [th1main_source {anoncap s} --set-anon-caps] 1 | |
| 681 | +set env(TH1_TEST_USER_CAPS) o | |
| 682 | +set env(TH1_TESToff \ | |
| 683 | + {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \ | |
| 684 | +] { | |
| 685 | + test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \CAPS) env(TH1_TEST_ANON_CAPS) | |
| 686 | +set th1mainGot [th1main_source {puts hello; set x {}} --cgi] | |
| 687 | +test th1main-source-cgi {[holds_strings $th1mainGot [list \ | |
| 688 | + "Status: 200 OK\r\n" "\r\n\r\nhello"]]} | |
| 689 | +set th1mainGot [th1main_source {puts hello; set x {}} --http] | |
| 690 | +test th1main-source-http {[holds_strings $th1mainGot [list \ | |
| 691 | + "HTTP/1.0 200 OK\r\n" "\r\n\r\nhello"]]} | |
| 692 | +fossil_raw test-th-source | |
| 693 | +test th1main-source-usage {$CODE == 1 && [string match "Usage: *" $RESULT]} | |
| 694 | + | |
| 695 | +############################################################################### | |
| 696 | +# The th1-setup setting holds a script that runs before any other. | |
| 697 | + | |
| 698 | +fossil settings th1-setup {proc from_setup {} {return made-by-setup} | |
| 699 | + if {[info exists ::runs]} {set ::runs 2} else {set ::runs 1}} | |
| 700 | +test_eq th1main-setup [th1main_eval {from_setup}] made-by-setup | |
| 701 | +test_eq th1main-setup-once [th1main_eval {set ::runs}] 1 | |
| 702 | +# reinitialize with flag 8 runs the script again. | |
| 703 | +t\ | |
| 704 | + "GET /tktnew$query H x\r\n\r\n"228@AyY,19@C~l,AY@D0~,P@CxE,1J@UV,Rv@DCp,10Kz3s; |
| --- a/test/th1main.test | |
| +++ b/test/th1main.test | |
| @@ -0,0 +1,704 @@ | |
| --- a/test/th1main.test | |
| +++ b/test/th1main.test | |
| @@ -0,0 +1,704 @@ | |
| 1 | ########################## |
| 2 | # |
| 3 | # Fossil's own TH1 commands and the template renderer: src/th_main.c. |
| 4 | # Scripts are run with "fossil test-th-eval", templates with |
| 5 | # "fossil test-th-render" and "fossil test-th-source", and a ticket page |
| 6 | # that holds TH1 is asked for through "se tests run only in a long pass:ter the first sect.H_ERROR: wrong # args: runs only withter the first sections need |
| 7 | # -assurance stress. |
| 8 | test_setup |
| 9 | |
| 10 | write_file a.txt "hello\n" |
| 11 | write_file f83.txt "line 83\n" |
| 12 | write_file f100.txt "line 100\n" |
| 13 | fossil add a.txt f83.txt f100.txt |
| 14 | fossil commit -m "three files" |
| 15 | fossil user new u1 "" pw1 |
| 16 | set th1mainRepo [file join [pwd] .rep.fossil] |
| 17 | |
| 18 | # Run SCRIPT with "fossil test-th-eval" and the options in ARGS. Returns |
| 19 | # what fossil printed, without the final newline. |
| 20 | # |
| 21 | # A build with TH1 hooks runs th1-setup and opens the checkout before the |
| 22 | # command itself; these tests are of the commands, so they turn hooks off. |
| 23 | fossil test-th-eval "hasfeature th1Hooks" |
| 24 | set th1mainNoHook [expr {[string trim $RESULT] eq "1" ? "--no-th-hook" : ""}] |
| 25 | |
| 26 | proc th1main_eval {script args} { |
| 27 | fossil_raw -seconds 60 test-th-eval {*}$::th1mainNoHook {*}$args $script |
| 28 | return [string trimright $::RESULT \n] |
| 29 | } |
| 30 | |
| 31 | # Test NAME passes if ACTUAL is as EXPECTED says. MODE is "eq" for an |
| 32 | # exact value, "re" for a regular expression, or "has" for a list of |
| 33 | # strings that must all be there (one that begins with "!" must not). |
| 34 | # |
| 35 | proc th1main_check {name actual mode expected {constraints ""}} { |
| 36 | switch -- $mode { |
| 37 | eq { test_eq $name $actual $expected $constraints } |
| 38 | re { test_match $name $actual $expected $constraints } |
| 39 | has { test $name {[holds_strings $actual $expected]} $constraints } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | # Run each row of TABLE: a test name, options for test-th-eval, a |
| 44 | # script, a mode and an expected value as th1main_check takes them. |
| 45 | # |
| 46 | proc th1main_table {table} { |
| 47 | foreach {name opts script mode expected} $table { |
| 48 | set got [th1main_eval $script {*}$opts] |
| 49 | th1main_check th1main-$name $got $mode $expected |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | ############################################################################### |
| 54 | # Every command refuses a call with too few or too many arguments. Each |
| 55 | # row is a call and the usage text of the error. |
| 56 | |
| 57 | foreach {th1mainName th1mainCall th1mainUsage} { |
| 58 | dir-few {dir} {dir CHECKIN ?GLOB? ?DETAILS?} |
| 59 | dir-many {dir a b 1 d} {dir CHECKIN ?GLOB? ?DETAILS?} |
| 60 | httpize-few {httpize} {httpize STRING} |
| 61 | httpize-many {httpize a b} {httpize STRING} |
| 62 | output-few {enable_output} {enable_output [LABEL] BOOLEAN} |
| 63 | output-many {enable_output a 1 c} {enable_output [LABEL] BOOLEAN} |
| 64 | nonce-many {nonce a} {nonce} |
| 65 | puts-few {puts} {puts STRING} |
| 66 | puts-many {puts a b} {puts STRING} |
| 67 | html-few {html} {puts STRING} |
| 68 | redirect-few {redirect} {redirect URL ?withMethod?} |
| 69 | redirect-many {redirect a 1 c} {redirect URL ?withMethod?} |
| 70 | insertcsrf-many {insertCsrf a} {insertCsrf} |
| 71 | verifycsrf-many {verifyCsrf a} {verifyCsrf} |
| 72 | login-few {verifyLogin a} {verifyLogin userName password} |
| 73 | login-many {verifyLogin a b c} {verifyLogin userName password} |
| 74 | markdown-few {markdown} {markdown STRING} |
| 75 | markdown-many {markdown a b} {markdown STRING} |
| 76 | wiki-few {wiki} {wiki STRING} |
| 77 | wiki-many {wiki a b} {wiki STRING} |
| 78 | decorate-few {decorate} {wiki STRING} |
| 79 | assoc-few {wiki_assoc a} {wiki_assoc STRING STRING} |
| 80 | assoc-many {wiki_assoc a b c} {wiki_assoc STRING STRING} |
| 81 | htmlize-few {htmlize} {htmlize STRING} |
| 82 | htmlize-many {htmlize a b} {htmlize STRING} |
| 83 | encode64-few {encode64} {encode64 STRING} |
| 84 | encode64-many {encode64 a b} {encode64 STRING} |
| 85 | hascap-few {hascap} {hascap STRING ...} |
| 86 | anoncap-few {anoncap} {hascap STRING ...} |
| 87 | capexpr-few {capexpr} {capexpr EXPR} |
| 88 | capexpr-many {capexpr a b} {capexpr EXPR} |
| 89 | searchable-few {searchable} {hascap STRING ...} |
| 90 | hasfeature-few {hasfeature} {hasfeature STRING} |
| 91 | hasfeature-many {hasfeature a b} {hasfeature STRING} |
| 92 | tclready-many {tclReady a} {tclReady} |
| 93 | anycap-few {anycap} {anycap STRING} |
| 94 | anycap-many {anycap a b} {anycap STRING} |
| 95 | combobox-few {combobox a b} {combobox NAME TEXT-LIST NUMLINES} |
| 96 | combobox-many {combobox a b 1 d} {combobox NAM ted {conCOPYLENGTH?} |
| 97 | copyb ?COPYLENGTH?} |
| 98 | copybtn-many {copybtn a 0 c 1 e} |
| 99 | {copybtn TARGETID FLIPPED TEXT ?COPYLENGTH?} |
| 100 | linecount-few {linecount a 1} {linecount STRING MAX MIN} |
| 101 | linecount-many {linecount a 1 2 3} {linecount STRING MAX MIN} |
| 102 | repository-many {repository 1 2} {repository ?BOOLEAN?} |
| 103 | checkout-many {checkout 1 2} {checkout ?BOOLEAN?} |
| 104 | trace-few {trace} {trace STRING} |
| 105 | trace-many {trace a b} {trace STRING} |
| 106 | state-few {globalState} {globalState NAME ?DEFAULT?} |
| 107 | state-many {globalState a b c} {globalState NAME ?DEFAULT?} |
| 108 | getparam-few {getParameter} {getParameter NAME ?DEFAULT?} |
| 109 | getparam-many {getParameter a b c} {getParameter NAME ?DEFAULT?} |
| 110 | setparam-few {setParameter a} {setParameter NAME VALUE} |
| 111 | setparam-many {setParameter a b c} {setParameter NAME VALUE} |
| 112 | reinit-many {reinitialize 1 2} {reinitialize ?FLAGS?} |
| 113 | render-few {render} {render STRING} |
| 114 | render-many {render a b} {render STRING} |
| 115 | defheader-many {defHeader a} {defHeader} |
| 116 | header-few {styleHeader} {styleHeader TITLE} |
| 117 | header-many {styleHeader a b} {styleHeader TITLE} |
| 118 | foote-few {gl. |
| 119 | # Scripts are run###########} eq 0 |
| 120 | glob-one-dasa b c}ript-many {styleScrimenu link LABEL URL} |
| 121 | submenu c} {submenu link LABEL URL} |
| 122 | submenu-word {submenu lin a b} {submenu link LABEL URL} |
| 123 | submenu-longer {submenu links a b} {submenu link LABEL URL} |
| 124 | requestjs-few {builtin_request_js} {builtin_request_js NAME} |
| 125 | requestjs-many {builtin_request_js a b} {builtin_request_js NAME} |
| 126 | artifact-few {artifact} {artifact ID ?FILENAME?} |
| 127 | artifac {reinitialize ad?} |
| 128 | http-many many e \ |
| 129 | {$CODE == 0 -- a b c}d?} |
| 130 | http-many {http -asynchronous -- a b c} |
| 131 | {http ?-asynchro {reinitialize ? ?--? url ?payload?} |
| 132 | http-none {http --} |
| 133 | {http ?-asynchronous? ad?} |
| 134 | http-many a b c} |
| 135 | {http ?-asynchronous? ?--? url ?payload?} |
| 136 | capture-few {captureTh1} {captureTh1 STRING} |
| 137 | capture-many {captureTh1 a b} {captureTh1 STRING} |
| 138 | } { |
| 139 | test_eq th1main-args-$th1mainName [th1main_eval $th1mainCall] \ |
| 140 | "THgot $mode $expected |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | ########################################################################################################## |
| 145 | # What the commands return and write. A script that writes ends with |
| 146 | # "set x {}" so that only what it wrote is printed. |
| 147 | |
| 148 | th1main_table { |
| 149 | httpize {} {httpize {a b/c?d&e=f%"<>}} eq {a+b%2Fc%3Fd%26e%3Df%25%22%3C%3E} |
| 150 | htmlize {} {htmlize {<a href="x">&'</a>}} |
| 151 | eq {<a href="x">&'</a>} |
| 152 | encode64 {} {encode64 {hello, world}} eq aGVsbG8sIHdvcmxk |
| 153 | encode64-empty {} {encode64 {}} eq {} |
| 154 | markdown {} {markdown "# Title\n\nbody *text*"} |
| 155 | has {{<div class="markdown">} {<p>body <em>text</em></p>}} |
| 156 | markdown-title {} {lindex [markdown "# Title\n\nbody *text*"] 0} eq Title |
| 157 | markdown-empty {} {lindex [markdown {}] 0} eq {} |
| 158 | |
| 159 | puts-escapes {} {puts "<b>&"; html "<i>"; set x {}} eq {<b>&<i>} |
| 160 | html-tainted {} {html [taint <i>]} |
| 161 | eq {TH_ERROR: tainted output string: "<i>"} |
| 162 | puts-tainted {} {puts [taint <i>]; set x {}} eq {<i>} |
| 163 | html-empty {} {html {}; set x done} eq done |
| 164 | untaint {} {string is tainted [untaint [taint abc]]} eq 0 |
| 165 | taint-length {} {string length [taint abc]} eq 3 |
| 166 | |
| 167 | hasfeature-markdown {} {hasfeature markdown} eq 1 |
| 168 | hasfeature-case {} {hasfeature MARKDOWN} eq 1 |
| 169 | hasfeature-unknown {} {hasfeature nosuch} eq 0 |
| 170 | hasfeature-empty {} {hasfeature {}} eq 0 |
| 171 | hasfeature-longer {} {hasfeature markdownx} eq 0 |
| 172 | tclready {} {tclReady} eq 0 |
| 173 | |
| 174 | anycap-empty {} {anycap {}} eq 0 |
| 175 | anycap-first {--set-user-caps} {anycap sz} eq 1 |
| 176 | anycap-second {--set-user-caps} {anycap zs} eq 1 |
| 177 | anycap-none {} {anycap sz} eq 0 |
| 178 | hascap-empty {} {hascap {}} eq 1 |
| 179 | hascap-all {--set-user-caps} {hascap s x} eq 1 |
| 180 | hascap-none {} {hascap s} eq 0 |
| 181 | anoncap-all {--set-anon-caps} {anoncap s x} eq 1 |
| 182 | anoncap-user-only {--set-user-caps} {anoncap s} eq 0 |
| 183 | capexpr-empty {} {capexpr {}} eq 0 |
| 184 | capexpr-star {} {capexpr {*}} eq 1 |
| 185 | capexpr-not {} {capexpr {!s}} eq 1 |
| 186 | capexpr-not-held {--set-user-caps} {capexpr {!s}} eq 0 |
| 187 | capexpr-anon {} {capexpr {@s}} eq 0 |
| 188 | capexpr-anon-held {--set-anon-caps} {capexpr {@s}} eq 1 |
| 189 | capexpr-second {} {capexpr {zz !zz}} eq 1 |
| 190 | capexpr-held {--set-user-caps} {capexpr {z sx}} eq 1 |
| 191 | |
| 192 | linecount-max {} {linecount "a\nb\nc\nd" 3 1} eq 3 |
| 193 | linecount-min {} {linecount "a\nb" 10 5} eq 5 |
| 194 | linecount-between {} {linecount "a\nb\nc" 10 1} eq 3 |
| 195 | linecount-empty {} {linecount {} 0 0} eq 0 |
| 196 | linecount-negative {} {linecount "a\nb\nc" -5 -9} eq -5 |
| 197 | linecount-widest {} {linecount "a\nb\nc" 2147483647 -2147483648} eq 3 |
| 198 | linecount-bad-max {} {linecount x a 1} |
| 199 | eq {TH_ERROR: expected integer, got: "a"} |
| 200 | linecount-bad-min {} {linecount x 1 b} |
| 201 | eq {TH_ERROR: expected integer, got: "b"} |
| 202 | linecount-too-big {} {linecount x 99999999999 1} eq 1 |
| 203 | |
| 204 | combobox {} {set nm b; combobox nm {a b <c>} 3; set x {}} |
| 205 | eq {<select id="nm" name="nm" size="3"><option value="a">a</option><option value="b" selected="selected">b</option><option value="<c>"><c></option></select>} |
| 206 | combobox-same-length {} {set nm x; combobox nm {a b} 1; set x {}} |
| 207 | eq {<select id="nm" name="nm" size="1"><option value="a">a</option><option value="b">b</option></select>} |
| 208 | combobox-other-length {} {set nm bb; combobox nm {a b} 1; set x {}} |
| 209 | eq {<select id="nm" name="nm" size="1"><option value="a">a</option><option value="b">b</option></select>} |
| 210 | combobox-no-variable {} {combobox {n"m} {a} 1; set x {}} |
| 211 | eq {<select id="n"m" name="n"m" size="1"><option value="a">a</option></select>} |
| 212 | combobox-no-values {} {set nm x; combobox nm {} 1; set x {}} |
| 213 | eq {<select id="nm" name="nm" size="1"></select>} |
| 214 | combobox-bad-lines {} {combobox nm {a b} x} |
| 215 | eq {TH_ERROR: expected integer, got: "x"} |
| 216 | |
| 217 | output-off {} {enable_output 0; puts hidden; html hidden; |
| 218 | combobox nm {a b} 1; copybtn id 0 text; wiki {[x]}; decorate {[x]} |
| 219 | enable_output 1; puts shown; set x {}} eq shown |
| 220 | output-label {} {enable_output lbl 0; puts hidden; enable_output lbl 1 |
| 221 | puts shown; set x {}} eq shown |
| 222 | output-bad {} {enable_output lbl xyz} |
| 223 | eq {TH_ERROR: expected integer, got: "xyz"} |
| 224 | output-off-error {} {enable_output 0; render {<th1>error shown</th1>} |
| 225 | set x {}} has {{ERROR: shown}} |
| 226 | |
| 227 | copybtn {} {copybtn cid 0 text; set x {}} |
| 228 | has {{data-copytarget="cid"} {data-copylength="0"} |
| 229 | {<span id="cid">text</span>} !copy-button-flipped} |
| 230 | copybtn-flipped {} {copybtn cid 1 {<t>} 3; set x {}} |
| 231 | has {{data-copylength="3"} copy-button-flipped |
| 232 | {<span id="cid"><t></span>}} |
| 233 | copybtn-bad-flipped {} {copybtn cid x text} |
| 234 | eq {TH_ERROR: expected integer, got: "x"} |
| 235 | copybtn-bad-length {} {copybtn cid 0 text x} |
| 236 | eq {TH_ERROR: expected integer, got: "x"} |
| 237 | |
| 238 | repository {} {repository} re {/\.rep\.fossil$} |
| 239 | repository-0 {} {repository 0} re {/\.rep\.fossil$} |
| 240 | repository-1 {} {repository 1} re {/\.rep\.fossil$} |
| 241 | repository-bad {} {repository x} eq {TH_ERROR: expected integer, got: "x"} |
| 242 | checkout {} {checkout} re {/th1main\.test/$} |
| 243 | checkout-0 {} {checkout 0} re {/th1main\.test/$} |
| 244 | checkout-1 {} {checkout 1} re {/th1main\.test/$} |
| 245 | checkout-bad {} {checkout x} eq {TH_ERROR: expected integer, got: "x"} |
| 246 | |
| 247 | state-unknown {} {globalState nosuch} |
| 248 | eq {TH_ERROR: unsupported global state: nosuch} |
| 249 | state-checkout {} {globalState checkout dflt} re {/th1main\.test/$} |
| 250 | state-case {} {globalState CHECKOUT} re {/th1main\.test/$} |
| 251 | state-longer {} {globalState checkouts} |
| 252 | eq {TH_ERROR: unsupported global state: checkouts} |
| 253 | state-configuration {--open-config} {globalState configuration dflt} |
| 254 | re {fossil} |
| 255 | state-executable {} {globalState executable dflt} re {fossil[^/]*$} |
| 256 | state-flags {} {globalState flags} eq 0 |
| 257 | state-flags-config {--open-config} {expr {[globalState flags] & 0x600}} |
| 258 | eq 1024 |
| 259 | state-log {} {globalState log dflt} eq dflt |
| 260 | state-log-set {--errorlog th1main-errors.log} {globalState log dflt} |
| 261 | re {th1main-errors\.log$} |
| 262 | state-repository {} {globalState repository dflt} re {/\.rep\.fossil$} |
| 263 | state-top {} {globalState top dflt} eq dflt |
| 264 | state-user {} {globalState user dflt} eq dflt |
| 265 | state-vfs {} {globalState vfs dflt} eq dflt |
| 266 | state-vfs-set {--vfs unix-none} {globalState vfs dflt} eq unix-none |
| 267 | |
| 268 | reinit {} {reinitialize; globalState flags} eq 0 |
| 269 | reinit-reset {} {reinitialize 4; globalState flags} eq 4 |
| 270 | reinit-setup {} {reinitialize 8; globalState flags} eq 8 |
| 271 | reinit-no-tcl {} {reinitialize 31; globalState flags} eq 29 |
| 272 | reinit-bad {} {reinitialize x} eq {TH_ERROR: expected integer, got: "x"} |
| 273 | reinit-keeps-procs {} {proc p {} {return kept}; reinitialize 4; p} eq kept |
| 274 | |
| 275 | render {} {set v 5; render {a $v <th1>puts [expr {$v+1}]</th1> b} |
| 276 | set x {}} eq {a 5 6 b} |
| 277 | render-error {} {render {<th1>error inner</th1>}; puts after} |
| 278 | eq {<hr><p class="thmainError">ERROR: inner</p>TH_ERROR: } |
| 279 | submenu-no-label {} {submenu link {} /url} |
| 280 | eq {TH_ERROR: link's LABEL is empty} |
| 281 | submenu-no-url {} {submenu link label {}} eq {TH_ERROR: link's URL is empty} |
| 282 | defheader {} {defHeader} has {<html> {$<title>}} |
| 283 | |
| 284 | dir {} {dir tip} eq {a.txt f100.txt f83.txt} |
| 285 | dir-glob {} {dir tip {f*}} eq {f100.txt f83.txt} |
| 286 | dir-glob-none {} {dir tip nomatch} eq {} |
| 287 | dir-details {} {dir tip {a*} 1} |
| 288 | re {^\{a\.txt 6 \{\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\}\}$} |
| 289 | dir-details-0 {} {dir tip {a*} 0} eq a.txt |
| 290 | dir-details-bad {} {dir tip * x} eq {TH_ERROR: expected integer, got: "x"} |
| 291 | dir-unknown {} {dir nosuch} eq {} |
| 292 | dir-empty-name {} {dir {}} eq {} |
| 293 | |
| 294 | artifact-file {} {artifact tip a.txt} eq hello |
| 295 | artifact-checkin {} {artifact tip} has {{C three\sfiles} {F a.txt }} |
| 296 | artifact-unknown {} {artifact nosuch} eq {TH_ERROR: name not found} |
| 297 | artifact-empty-name {} {artifact {}} eq {TH_ERROR: } |
| 298 | artifact-unknown-checkin {} {artifact nosuch a.txt} |
| 299 | eq {TH_ERROR: manifest not found} |
| 300 | artifact-not-a-checkin {} {artifact [lindex [artifact tip] 6] a.txt} |
| 301 | re {^TH_ERROR: } |
| 302 | artifact-unknown-file {} {artifact tip nosuch} |
| 303 | eq {TH_ERROR: file name not found in manifest} |
| 304 | |
| 305 | glob-list {} {glob_match {*.txt,*.c} a.c} eq 2 |
| 306 | glob-list-none {} {glob_match {*.txt,*.c} a.h} eq 0 |
| 307 | glob-empty {} {glob_match {} x} |
| 308 | eq {TH_ERROR: unable to create glob from pattern list} |
| 309 | glob-one {} {glob_match -one {*.c} a.c} eq 1 |
| 310 | glob-one-none {} {glob_match -one {*.c} a.h} eq 0 |
| 311 | glob-one-dashes {} {glob_match -one -- -one -one} eq 1 |
| 312 | glob-dashes {} {glob_match -- {*.c} a.h} eq 0 |
| 313 | |
| 314 | regexp {} {regexp {^a+b$} aaab} eq 1 |
| 315 | regexp-case {} {regexp {^a+b$} AAAB} eq 0 |
| 316 | regexp-nocase {} {regexp -nocase {^a+b$} AAAB} eq 1 |
| 317 | regexp-dashes {} {regexp -nocase -- -nocase -NOCASE} eq 1 |
| 318 | regexp-empty {} {regexp {} {}} eq 1 |
| 319 | regexp-unclosed {} {regexp {((a} x} eq {TH_ERROR: unmatched '('} |
| 320 | regexp-bracket {} {regexp {[} x} eq {TH_ERROR: unclosed '['} |
| 321 | regexp-too-big {} {regexp [string repeat {(a|b)*} 2000] x} |
| 322 | eq {TH_ERROR: REGEXP pattern too big} |
| 323 | |
| 324 | setting {} {setting autosync} re {^(on|off|0|1)?$} |
| 325 | setting-unknown {} {setting th1main-no-such-setting} eq {} |
| 326 | setting-strict-unknown {} {setting -strict th1main-no-such-setting} |
| 327 | eq {TH_ERROR: no value for setting "th1main-no-such-setting"} |
| 328 | |
| 329 | capture {} {captureTh1 {puts <b>; html <i>}} eq {<b><i>} |
| 330 | capture-error {} {captureTh1 {puts lost; error boom}} eq {TH_ERROR: boom} |
| 331 | capture-return {} {captureTh1 {return 9}} eq {TH_RETURN: 9} |
| 332 | capture-nested {} {puts a; set r [captureTh1 {puts b |
| 333 | puts [captureTh1 {puts c}]}]; puts d; set r} eq adbc |
| 334 | capture-render {} {set v <b>; captureTh1 {render {x<th1>puts y</th1>$<v>z}}} |
| 335 | eq {xy<b>z} |
| 336 | capture-render-error {} {captureTh1 {render {x$<nosuch>z}}} eq {TH_ERROR: } |
| 337 | capture-widgets {} {set nm a; captureTh1 {combobox nm {a} 1 |
| 338 | copybtn cid 0 t}} has {{<select id="nm"} {<span id="cid">t</span>}} |
| 339 | |
| 340 | login-good {} {verifyLogin u1 pw1} eq 1 |
| 341 | login-wrong-password {} {verifyLogin u1 wrong} eq 0 |
| 342 | login-unknown-user {} {verifyLogin nosuch pw1} eq 0 |
| 343 | login-empty {} {verifyLogin {} {}} eq 0 |
| 344 | |
| 345 | date {} {date} re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} |
| 346 | date-other-option {} {date -utc} re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} |
| 347 | date-longer-option {} {date -localx} re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} |
| 348 | date-same-length-option {} {date -locax} |
| 349 | re {^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$} |
| 350 | utime {} {utime} re {^\d+$} |
| 351 | stime {} {stime} re {^\d+$} |
| 352 | |
| 353 | randhex {} {randhex} re {^[0-9a-f]{20}$} |
| 354 | randhex-3 {} {randhex 3} re {^[0-9a-f]{6}$} |
| 355 | randhex-0 {} {randhex 0} re {^[0-9a-f]{2}$} |
| 356 | randhex-negative {} {randhex -5} re {^[0-9a-f]{2}$} |
| 357 | randhex-49 {} {randhex 49} re {^[0-9a-f]{98}$} |
| 358 | randhex-bad {} {randhex x} eq {TH_ERROR: expected integer, got: "x"} |
| 359 | |
| 360 | query {} {query {SELECT 1 AS a, 'x' AS b UNION ALL SELECT 2, 'y'} { |
| 361 | puts "$a$b "}; set x {}} eq {1x 2y } |
| 362 | query-variables {} {set v 7; set w {it's} |
| 363 | query {SELECT $v+1 AS a, $w='it''s' AS b, $nosuch IS NULL AS c, |
| 364 | :v IS NULL AS d, ?5 IS NULL AS e, ? IS NULL AS f} { |
| 365 | puts "$a/$b/$c/$d/$e/$f"}; set x {}} eq {8/1/1/1/1/1} |
| 366 | query-null-and-blob {} {query {SELECT NULL AS a, x'410042' AS b} { |
| 367 | puts "[string length $a]/[string length $b]"}; set x {}} eq 0/3 |
| 368 | query-values-tainted {} {query {SELECT 'v' AS a} { |
| 369 | puts [string is tainted $a]}; set x {}} eq 1 |
| 370 | query-column-names {} {query {SELECT 1 AS "", 2 AS "a(b", 3 AS "a b"} { |
| 371 | puts ran}; set x {}} eq ran |
| 372 | query-no-rows {} {query {SELECT 1 WHERE 0} {puts never}; set x none} |
| 373 | eq none |
| 374 | query-empty {} {query {} {puts never}; set x none} eq none |
| 375 | query-spaces {} {query { } {puts never}; set x none} eq none |
| 376 | query-semicolon {} {query {;} {puts never}; set x none} eq none |
| 377 | query-break {} {query {SELECT 1 AS a UNION ALL SELECT 2} { |
| 378 | puts $a; break}; set x {}} eq 12 |
| 379 | query-continue {} {query {SELECT 1 AS a UNION ALL SELECT 2} { |
| 380 | puts $a; continue; puts never}; set x {}} eq 12 |
| 381 | query-return {} {query {SELECT 1 AS a UNION ALL SELECT 2} { |
| 382 | puts $a; return 7}} eq {1TH_RETURN: 7} |
| 383 | query-error {} {query {SELECT 1 AS a UNION ALL SELECT 2} { |
| 384 | puts $a; error boom}} eq {1TH_ERROR: boom} |
| 385 | query-nested {} {query {SELECT 1 AS a} {query {SELECT 2 AS b} { |
| 386 | puts $a$b}}; set x {}} eq 12 |
| 387 | query-bad-sql {} {query {SELECT nosuch} {puts never}} |
| 388 | eq {TH_ERROR: SQL error: no such column: nosuch} |
| 389 | query-bad-sql-quiet {} {query -nocomplain {SELECT nosuch} {puts never} |
| 390 | set x quiet} eq quiet |
| 391 | query-quiet {} {query -nocomplain {SELECT 4 AS a} {puts $a}; set x {}} eq 4 |
| 392 | query-delete {} {query {DELETE FROM user} {puts never}} |
| 393 | eq {TH_ERROR: SQL error: not authorized} |
| 394 | query-delete-quiet {} {query -nocomplain {DELETE FROM user} {puts never} |
| 395 | set x quiet} eq quiet |
| 396 | query-update {} {query {UPDATE config SET value=1} {puts never}} |
| 397 | eq {TH_ERROR: SQL error: not authorized} |
| 398 | query-password {} {query {SELECT pw FROM user} {puts never}} |
| 399 | re {^TH_ERROR: SQL error: } |
| 400 | query-step-error {} {query {SELECT abs(-9223372036854775807-1) AS a} { |
| 401 | puts never}} eq {TH_ERROR: SQL error: integer overflow} |
| 402 | query-step-error-quiet {} { |
| 403 | query -nocomplain {SELECT abs(-9223372036854775807-1) AS a} {puts never} |
| 404 | set x quiet} eq quiet |
| 405 | query-option-as-sql {} {query -nocomplain {puts never}} |
| 406 | eq {TH_ERROR: SQL error: near "-": syntax error} |
| 407 | query-option-misspelt {} {query -nocomplaix {SELECT 1} {puts never}} |
| 408 | eq {TH_ERROR: wrong # args: should be "query SQL CODE"} |
| 409 | query-tainted {} {query [taint {SELECT 1}] {puts never}} |
| 410 | eq {TH_ERROR: tainted query SQL: "SELECT 1"} |
| 411 | query-undefined {} {query $nosuch {}} eq {TH_ERROR: no such variable: nosuch} |
| 412 | |
| 413 | code-break {} {break} re {^TH_BREAK: } |
| 414 | code-continue {} {continue} re {^TH_CONTINUE: } |
| 415 | code-return {} {return x} eq {TH_RETURN: x} |
| 416 | code-return2 {} {return -code 5 x} eq {TH_RETURN2: x} |
| 417 | code-other {} {return -code 99 x} eq {TH1 return code 99: x} |
| 418 | } |
| 419 | |
| 420 | test_eq th1main-capexpr-not-list [th1main_eval "capexpr \"\{\""] \ |
| 421 | "TH_ERROR: Expected list, got: \"\{\"" |
| 422 | |
| 423 | # With capability "o" alone for the user and "h" alone for anonymous. |
| 424 | set env(TH1_TEST_USER_CAPS) o |
| 425 | set env(TH1_TEST_ANON_CAPS) h |
| 426 | th1main_table { |
| 427 | caps-hascap {--set-user-caps} {hascap o} eq 1 |
| 428 | caps-hascap-first-missing {--set-user-caps} {hascap z o} eq -local]"; set x {}}] \ |
| 429 | {$th1mainSavedTz eq ""} { unset env(TZ) } else \ |
| 430 | { set env(TZ) $th1mainSavedTz } |
| 431 | fossil settings timeline-utc 1 |
| 432 | set th1mainDiff [expr {[clock scan [lindex $th1mainDates 1] -gmt 1] |
| 433 | - [clock scan [lindex $th1mainDates 0] -gmt 1]}] |
| 434 | test th1main-date-local {$th1mainDiff >= 17999 && $th1mainDiff <= 18001} |
| 435 | |
| 436 | # A script given as the name of a file is read from the file. |
| 437 | write_file script.th1 "puts from-file; set x {}\n" |
| 438 | test_eq th1main-eval-file [th1main_eval script.th1] from-file |
| 439 | |
| 440 | fossil_raw test-th-eval |
| 441 | test th1main-eval-usage {$CODE == 1 && [string match "Usage: *" $RESULT]} |
| 442 | fossil_raw test-th-eval a b |
| 443 | test th1main-eval-usage-many {$CODE == 1 && [string match "Usage: *" $RESULT]} |
| 444 | |
| 445 | ############################################################################### |
| 446 | # Unversioned files. |
| 447 | |
| 448 | # In a repository that has never held an unversioned file, "unversioned |
| 449 | # list" gives an empty list and "unversioned content" a script error. |
| 450 | set th1mainGot [th1main_eval {unversioned list}] |
| 451 | test th1main-uv-list-none {$CODE == 0 && $th1mainGot eq ""} |
| 452 | set th1mainGot [th1main_eval {unversioned content nosd?} |
| 453 | http-many le u.txt "data\n" |
| 454 | write_file v.txt "more\n" |
| 455 | fossil uv add u.txt v.txt |
| 456 | fossil uv rm v.txt |
| 457 | th1main_table { |
| 458 | uv-list {} {unversioned list} eq u.txt |
| 459 | uv-content {} {unversioned content u.txt} eq data |
| 460 | uv-content-unknown {} {unversioned content nosuch} re {^TH_ERROR: } |
| 461 | uv-unknown {} {unversioned nosuch} |
| 462 | eq {TH_ERROR: Expected sub-command, got: nosuch} |
| 463 | } |
| 464 | |
| 465 | # knownBug: the content of a removed file is given as an empty string; |
| 466 | # "unversioned list" does not list the file. |
| 467 | test_match th1main-uv-content-removed \ |
| 468 | [th1main_eval {unversioned content v.txt}] {^TH_ERROR: } knownBug |
| 469 | |
| 470 | ######### [join [list \ |
| 471 | "seth1mainSql} {set n \[expr {\$n+1}\\ |
| 472 | {{GET /xset n"] ""] |
| 473 | test th1main-query-statements-$th1mainName \ |
| 474 | {$CODE == 0 two 2 space 1} \ |
| 475 | $th1mainName]} |
| 476 | } |
| 477 | |
| 478 | # builtin_request_js with a name that is not a built-in file gives a |
| 479 | # script error. |
| 480 | set th1mainGot [th1main_eval {builtin_request_js nosuch.js}] |
| 481 | test th1main-requestjs-unknown {$CODE == 0} |
| 482 | |
| 483 | # randhex gives at most 50 bytes, 100 digits. |
| 484 | test_match th1main-randhex-50 [th1main_eval {randhex 50}] {^[0-9a-f]{100}$} |
| 485 | test th1main-randhex-50-exit {$CODE == 0} |
| 486 | test_match th1main-randhex-over [th1main_eval {randhex 1000}] {^[0-9a-f]{100}$} |
| 487 | |
| 488 | # http with text that is not a URL gives a script error. |
| 489 | set th1mainGot [th1main_eval {http not-a-url}] |
| 490 | test th1main-http-not-url \ |
| 491 | {$CODE == 0 && [string match "TH_ERROR: *" $th1mainGot]} |
| 492 | |
| 493 | # A phantom: an artifact whose content the repository does nohe repository does not hold. |
| 494 | set th1mainPhantom \ |
| 495 | abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 |
| 496 | fossil sql "INSERT INTO blob(rcvid,size,uuid) VALUES(0,-1,'$th1mainPhantom'); |
| 497 | INSERT INTO phantom SELECT rid FROM blob WHERE size=-1;" |
| 498 | test_match th1main-artifact-phantom \ |
| 499 | [th1main_eval "artifact $th1mainPhantom"] {^TH_ERROR: } |
| 500 | |
| 501 | ############################################################################### |
| 502 | # The http command. Only a URL that matches the th1-uri-regexp setting |
| 503 | # is allowed, and only an asynchronous request is implemented. |
| 504 | |
| 505 | th1main_table { |
| 506 | http-ssh {} {http ssh://host/path} |
| 507 | eq {TH_ERROR: url must be http:// or https:// } |
| 508 | http-file {} {http file:///tmp/x} |
| 509 | eq {TH_ERROR: url must be http:// or https:// } |
| 510 | http-no-setting {} {http http://localhost/x} eq {TH_ERROR: url not allowed} |
| 511 | http-no-setting-async {} {http -asynchronous -- http://localhost/x} |
| 512 | eq {TH_ERROR: url not allowed} |
| 513 | } |
| 514 | fossil test-var-set th1-uri-regexp "" |
| 515 | test_eq th1main-http-empty-setting [th1main_eval {http http://localhost/x}] \ |
| 516 | {TH_ERROR: url not alloet]\r\n"]]} |
| 517 | th1mai://localhost/x}] \ |
| 518 | {TH_ERROR:payload}ting-async pos {http -asyn################### |
| 519 | # |
| 520 | # Fossil's own TH1 commands and the template renderer: src/th_main.c. |
| 521 | # Scripts are run with "fossil test-th-eval", templates with |
| 522 | # "fossil test-th-render" and "fossil test-th-source", and a ticket page |
| 523 | # that holds TH1 is asked for through "fossil http --in". |
| 524 | # |
| 525 | |
| 526 | # The first sections run at every level, and the rest need |
| 527 | # -assurance stress. |
| 528 | test_setup |
| 529 | |
| 530 | write_file a.txt "hello\n" |
| 531 | write_file f83.txt "line 83\n" |
| 532 | write_file f100.txt "line 100\n" |
| 533 | fossil add a.txt f83.txt f100.txt |
| 534 | fossil commit -m "three files" |
| 535 | fossil user new u1 "" pw1 |
| 536 | set th1mainRepo [file join [pwd] .rep.fossil] |
| 537 | |
| 538 | # Run SCRIPT with "fossil test-th-eval" and the options in ARGS. Returns |
| 539 | # what fossil printed, without the final newline. |
| 540 | # |
| 541 | # A build with TH1 hooks runs th1-setup and opens the checkout before the |
| 542 | # command itself; these tests are of the commands, so they turn hooks off. |
| 543 | fossil test-th-eval "hasfeature th1Hooks" |
| 544 | set th1mainNoHook [expr {[string trim $RESULT] eq "1" ? "--no-th-hook" : ""}] |
| 545 | |
| 546 | proc th1main_eval {script args} { |
| 547 | fossil_raw -seconds 60 test-th-eval {*}$::th1mainNoHook {*}$args $script |
| 548 | return [string trimright $::RESULT \n] |
| 549 | } |
| 550 | |
| 551 | # Test NAME passes if ACTUAL is as EXPECTED says. MODE is "eq" for an |
| 552 | # exact value, "re" for a regular expression, or "has" for a list ########################## |
| 553 | http://x/elsewhere\r\n"]]} |
| 554 | |
| 555 | ############################################################################### |
| 556 | # With######################## |
| 557 | # Tracing: --th-trace prints a log of what the commands did. |
| 558 | |
| 559 | foreach {th1mainName th1mainOpts th1mainScript th1mainWanted} { |
| 560 | output {} {enable_output lbl 1} {{enable_output {lbl} -> 1<br>}} |
| 561 | hascap {--set-user-caps} {hascap s x} {{[hascap s x] => 1<br>}} |
| 562 | hascap-missing {} {hascap s x} {{[hascap s] => 0<br>}} |
| 563 | anycap {--set-user-caps} {anycap zs} {{[anycap zs] => 1<br>}} |
| 564 | searchable {} {searchable cdtw} {{[searchable cdtw] => 0<br>}} |
| 565 | hasfeature {} {hasfeature markdown} {{[hasfeature markdown] => 1<br>}} |
| 566 | tclready {} {tclReady} {{[tclReady] => 0<br>}} |
| 567 | trace {} {trace {a message}} {{a message}} |
| 568 | setting {} {setting th1main-no-such-setting} |
| 569 | {{[setting th1main-no-such-setting] => 0<br>}} |
| 570 | "a\ |
| 571 | "a${th1mainNoVar}etting} |
| 572 | {{[setting strict th1main-no-such-setting] => 1<br>}} |
| 573 | query {} {query {SELECT 1 AS a} {set y <$a>}} |
| 574 | {{query_eval {<pre>set y <$a></pre>}<br>} |
| 575 | {[query_eval] => TH_OK {<1>}<br>}} |
| 576 | render {} {render {<th1>set y <b></th1>}} |
| 577 | {{render_eval {<pre>set y <b></pre>}<br>} |
| 578 | {[render_eval] => TH_OK {<b>}<br>}} |
| 579 | init {} {reinitialize 12} {{th1-init 0x0 => 0x0<br>} {th1-init 0x0 => 0xc<br>} |
| 580 | {th1-setup {} => TH_OK<br>}} |
| 581 | header {--cgi} {styleHeader {A Title}} {{set titl{v}} {a$1 $_ $: $:: $::1 $<1> ${v}} \ |
| 582 | variables \ |
| 583 | {<th1>set v {<b>&}; set ::g G; set v_2 two</th1>[$v][$<v>][$::g][$<::g>][$v_2]} \ |
| 584 | {[<b>&][<b>&][G][G][two]} \ |
| 585 | variable-then-text {<th1>set v 1</th1>$v-escaped {a$<nosuch>b} \ |
| 586 | "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuchrr}no such variable: n-escaped {a$<nosuch>b} \ |
| 587 | "a${th1mainNoVar}nosuch${th1mainErr}no such variable: nosuch</p>" \ |
| 588 | variable-unknown-then-known {<th1>se1</th1>a$nosuch b$v c} \ |
| 589 | "a${th1mainNoVar}nosuch b1 c" \ |
| 590 | variable-tainted {<th1>set t [taininted {<th1>set t [taint <i> {ah1mainGot [th1main_re<i>]end} \ |
| 591 | error-plain {a<th1>error boom</th1>after} "a${th1mainErr}boom</p>" \ |
| 592 | error-escaped {<th1>error <b></th1>} "${th1mainErr}<b></p>" \ |
| 593 | nested {<th1>set v 2; render {b$<v>|}; render {c$v}</th1>d} {b2|c2d} \ |
| 594 | nested-error {<th1>render {b$<v>|}; puts never</th1>d} \ |
| 595 | "b${th1mainNoVar}v${th1mainErr}no variable: v</p>${th1mainErr}</p>" \ |
| 596 | output-off \ |
| 597 | {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \ |
| 598 | ] { |
| 599 | test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \ |
| 600 | $th1mainExpected |
| 601 | test th1main-render-$th1mainName-exit {$CODE == 0} |
| 602 | } |
| 603 | |
| 604 | # A script that ends with break, continue or return ends the template; |
| 605 | # nothing of the block is written to the output. |
| 606 | foreach {th1mainName th1mainText} { |
| 607 | break {a<th1>break</th1>after} |
| 608 | continue {a<th1>continue</th1>after} |
| 609 | return {a<th1>return 5</th1>after} |
| 610 | } { |
| 611 | test_eq th1main-render-$th1mainName [th1main_render $th1mainText] a |
| 612 | } |
| 613 | |
| 614 | # Text after a zero byte in the file is not rendered. |
| 615 | test_eq th1main-render-zero-byte [th1main_render "a\0b<th1>puts c</th1>"] a |
| 616 | |
| 617 | set th1mainGot [th1main_render {<th1>puts hello</th1>} --cgi] |
| 618 | test th1main-render-cgi {[holds_strings $th1mainGot [list \ |
| 619 | "Status: 200 OK\r\n" "Content-Length: 5\r\n" "\r\n\r\nhello"]]} |
| 620 | set th1mainGot [th1main_render {<th1>error boom</th1>} --http] |
| 621 | test th1main-render-http {[holds_strings $th1mainGot [list \ |
| 622 | "HTTP/1.0 200 OK\r\n" "${th1mainErr}boom</p>"]]} |
| 623 | test_match th1main-render-open-config \ |
| 624 | [th1main_render {<th1>puts [globalState configuration none]</th1>} \ |
| 625 | --open-config] {fossil} |
| 626 | test_eq th1main-render-user-caps \ |
| 627 | [th1main_render {<th1>puts [hascap s][anoncap s]</th1>} --set-user-caps] 10 |
| 628 | test_eq th1main-render-anon-caps \ |
| 629 | [th1main_render {<th1>puts [anoncap s]</th1>} --set-anon-caps] 1 |
| 630 | set env(TH1_TEST_USER_CAPS) o |
| 631 | set env(TH1_TEST_ANON_CAPS) h |
| 632 | test_eq th1ma{<th1>ff \ |
| 633 | {<th1>enable_alikes {<th1>seto][hascap s][ah1mainErr}no such variable: v</p>${th1mainErr}</p>" \ |
| 634 | output-off \ |
| 635 | {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \ |
| 636 | ] { |
| 637 | test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \ |
| 638 | $th1mainExpected |
| 639 | test th1main-render-$th1mainName-exit {$CODE == 0} |
| 640 | } |
| 641 | |
| 642 | # A script that ends with break, continue or return ends the template; |
| 643 | # nothing of the block is written to the output. |
| 644 | foreach {th1mainName th1mainText} { |
| 645 | break {a<th1>break</th1>after} |
| 646 | continue {a<th1>continue</th1>after} |
| 647 | return {a<th1>return 5</th1>after} |
| 648 | } { |
| 649 | test_eq th1main-render-$th1mainName [th1main_render $th1mainText] a |
| 650 | } |
| 651 | |
| 652 | # Text after a zero byte in the file is not rendered. |
| 653 | test_eq th1main-render-zero-byte [th1main_render "a\0b<th1>puts c</th1>"] a |
| 654 | |
| 655 | set th1mainGot [th1main_render {<th1>puts hello</th1>} --cgi] |
| 656 | test th1main-render-cgi {[holds_strings $th1mainGot [list \ |
| 657 | "Status: 200 OK\r\n" "Content-Length: 5\r\n" "\r\n\r\nhello"]]} |
| 658 | set th1mainGot [th1main_render {<th1>error boom</th1>} --http] |
| 659 | test th1main-render-http {[holds_strings $th1mainGot [list \ |
| 660 | "HTTP/1.0 200 OK\r\n" "${th1mainErr}boom</p>"]]} |
| 661 | test_match th1main-render-open-config \ |
| 662 | [th1main_render {<th1>puts [globalState configuration none]</th1>} \ |
| 663 | --open-config] {fossil} |
| 664 | test_eq th1main-render-user-caps \ |
| 665 | [th1main_render {<th} |
| 666 | query-bad-sql-quiet {} [th1main_source \ |
| 667 | {query -nocomplain {SELECT 1 AS a} {puts $a}; set x quiet}] \ |
| 668 | quiet |
| 669 | test_eq th1main-source-no-repository [th1main_source {repository}] {} |
| 670 | test_match th1main-source-repository [th1main_source {repository 1}] \ |
| 671 | {/\.rep\.fossil$} |
| 672 | test_match th1main-source-checkout [th1main_source {checkout 1}] \ |
| 673 | {/th1main\.test/$} |
| 674 | test_eq th1main-source-checkout-not-opened [th1main_source {checkout 0}] {} |
| 675 | test_match th1main-source-open-config \ |
| 676 | [th1main_source {globalState configuration none} --open-config] {fossil} |
| 677 | test_eq th1main-source-user-caps \ |
| 678 | [th1main_source {puts [hascap s][anoncap s]; set x {}} --set-user-caps] 10 |
| 679 | test_eq th1main-source-anon-caps \ |
| 680 | [th1main_source {anoncap s} --set-anon-caps] 1 |
| 681 | set env(TH1_TEST_USER_CAPS) o |
| 682 | set env(TH1_TESToff \ |
| 683 | {<th1>enable_output 0</th1>hidden $<v><th1>enable_output 1</th1>shown} shown \ |
| 684 | ] { |
| 685 | test_eq th1main-render-$th1mainName [th1main_render $th1mainText] \CAPS) env(TH1_TEST_ANON_CAPS) |
| 686 | set th1mainGot [th1main_source {puts hello; set x {}} --cgi] |
| 687 | test th1main-source-cgi {[holds_strings $th1mainGot [list \ |
| 688 | "Status: 200 OK\r\n" "\r\n\r\nhello"]]} |
| 689 | set th1mainGot [th1main_source {puts hello; set x {}} --http] |
| 690 | test th1main-source-http {[holds_strings $th1mainGot [list \ |
| 691 | "HTTP/1.0 200 OK\r\n" "\r\n\r\nhello"]]} |
| 692 | fossil_raw test-th-source |
| 693 | test th1main-source-usage {$CODE == 1 && [string match "Usage: *" $RESULT]} |
| 694 | |
| 695 | ############################################################################### |
| 696 | # The th1-setup setting holds a script that runs before any other. |
| 697 | |
| 698 | fossil settings th1-setup {proc from_setup {} {return made-by-setup} |
| 699 | if {[info exists ::runs]} {set ::runs 2} else {set ::runs 1}} |
| 700 | test_eq th1main-setup [th1main_eval {from_setup}] made-by-setup |
| 701 | test_eq th1main-setup-once [th1main_eval {set ::runs}] 1 |
| 702 | # reinitialize with flag 8 runs the script again. |
| 703 | t\ |
| 704 | "GET /tktnew$query H x\r\n\r\n"228@AyY,19@C~l,AY@D0~,P@CxE,1J@UV,Rv@DCp,10Kz3s; |
+1709
| --- a/test/url.test | ||
| +++ b/test/url.test | ||
| @@ -0,0 +1,1709 @@ | ||
| 1 | +# | |
| 2 | +# URLs of remote repositories, and the HTTP exchange of the sync client. | |
| 3 | +# | |
| 4 | +# The first part gives URLs to "fossil test-urlparser" and | |
| 5 | +# "fossil test-url-basename" and checks each part of the result, and | |
| 6 | +# checks how a saved remote, the parent project and a proxy are read. | |
| 7 | +# | |
| 8 | +# The second part gives "fossil test-httpmsg", "fossil clone" and | |
| 9 | +# "fossil pull" a server made by this file, which answers each | |
| 10 | +# connection with a reply that the test wrote. A well-formed reply must | |
| 11 | +# be accepted. A malformed one must be refused with a message and exit | |
| 12 | +# status 1. | |
| 13 | +# | |
| 14 | +# The third part does the same over the ssh: transport. Nothing here | |
| 15 | +# connects to another machine: "ssh" is a script written by this file, | |
| 16 | +# which writes down its arguments and prints a reply that the test wrote. | |
| 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 | +} | |
| 32 | + | |
| 33 | +# fossil must not use a proxy from the environment of the test run. | |
| 34 | +foreach urlVar {http_proxy HTTP_PROXY https_proxy HTTPS_PROXY all_proxy | |
| 35 | + ALL_PROXY} { | |
| 36 | + if {[info exists env($urlVar)]} { | |
| 37 | + set urlSavedEnv($urlVar) $env($urlVar) | |
| 38 | + unset env($urlVar) | |
| 39 | + } | |
| 40 | +} | |
| 41 | + | |
| 42 | +test_setup | |
| 43 | +set urlRepo [file join [pwd] .rep.fossil] | |
| 44 | +set urlDir [pwd] | |
| 45 | + | |
| 46 | +############################################################################### | |
| 47 | +# The parts of a URL. | |
| 48 | + | |
| 49 | +# Runs "fossil test-urlparser URL" with the options in ARGS and returns | |
| 50 | +# a dictionary of what it printed for the URL as given: the name after | |
| 51 | +# "g.url." and the value. url_full(g.url) is under the key "full". | |
| 52 | +# | |
| 53 | +proc url_parse {url args} { | |
| 54 | + fossil_raw test-urlparser $url --proxy off {*}$args | |
| 55 | + set fields [dict create] | |
| 56 | + foreach urlLine [split $::RESULT \n] { | |
| 57 | + if {[string match "\\*\\*\\*\\**" $urlLine]} break | |
| 58 | + if {[regexp {^g\.url\.(\w+) *= (.*)$} $urlLine -> key value]} { | |
| 59 | + dict set fields $key $value | |
| 60 | + } elseif {[regexp {^url_full\(g\.url\) = (.*)$} $urlLine -> value]} { | |
| 61 | + dict set fields full $value | |
| 62 | + } | |
| 63 | + } | |
| 64 | + return $fields | |
| 65 | +} | |
| 66 | + | |
| 67 | +# Test NAME passes when "fossil test-urlparser URL" with the options | |
| 68 | +# OPTIONS gives each part in EXPECTED the value that follows it there. | |
| 69 | +# | |
| 70 | +proc url_parse_test {name url options expected {constraints ""}} { | |
| 71 | + set fields [url_parse $url {*}$options] | |
| 72 | + set actual [list] | |
| 73 | + foreach {urlKey urlValue} $expected { | |
| 74 | + if {[dict exists $fields $urlKey]} { | |
| 75 | + lappend actual $urlKey [dict get $fields $urlKey] | |
| 76 | + } else { | |
| 77 | + lappend actual $urlKey (missing) | |
| 78 | + } | |
| 79 | + } | |
| 80 | + test_eq $name $actual [list {*}$expected] $constraints | |
| 81 | +} | |
| 82 | + | |
| 83 | +foreach {urlName urlText urlExpected} { | |
| 84 | + http-plain http://example.com | |
| 85 | + {isFile 0 isHttps 0 isSsh 0 protocol http name example.com port 80 | |
| 86 | + dfltPort 80 hostname example.com path {} user {} passwd {} | |
| 87 | + canonical http://example.com fossil {} flags 0x0000 | |
| 88 | + full http://example.com} | |
| 89 | + https-upper-case HTTPS://Example.COM:8443/a/b | |
| 90 | + {isHttps 1 protocol https name example.com port 8443 dfltPort 443 | |
| 91 | + hostname example.com:8443 path /a/b | |
| 92 | + canonical https://example.com:8443/a/b} | |
| 93 | + https-default-port-given https://h:443/x | |
| 94 | + {port 443 hostname h:443 canonical https://h/x} | |
| 95 | + http-port-zero http://h:0/x | |
| 96 | + {port 0 hostname h:0 canonical http://h:0/x} | |
| 97 | + http-port-largest http://h:65535 | |
| 98 | + {port 65535 hostname h:65535 path {} canonical http://h:65535} | |
| 99 | + http-port-then-query http://h:81?x=1 | |
| 100 | + {port 81 path {} canonical http://h:81} | |
| 101 | + http-port-then-fragment http://h:81#top | |
| 102 | + {port 81 path {} canonical http://h:81} | |
| 103 | + http-port-empty http://h:/x | |
| 104 | + {port 0 hostname h:0 path /x} | |
| 105 | + http-user-password http://u:p@h/x | |
| 106 | + {name h user u passwd p canonical http://u@h/x full http://u:p@h/x} | |
| 107 | + http-user-only http://u@h:81/x | |
| 108 | + {user u passwd {} canonical http://u@h:81/x full http://u@h:81/x} | |
| 109 | + http-user-empty-password http://u:@h/x | |
| 110 | + {user u passwd {} canonical http://u@h/x full http://u@h/x} | |
| 111 | + http-user-escapes http://a%40b:p%3Aq%2Fr@h/ | |
| 112 | + {user a@b passwd p:q/r canonical http://a%40b@h/ | |
| 113 | + full http://a%40b:p%3Aq%2Fr@h/} | |
| 114 | + http-user-bad-escape http://%@h/ | |
| 115 | + {user % canonical http://%25@h/} | |
| 116 | + http-password-colons http://u:p:q@h/ | |
| 117 | + {user u passwd p:q} | |
| 118 | + http-at-in-path http://h/a@b | |
| 119 | + {name h user {} path /a@b canonical http://h/a%40b} | |
| 120 | + http-at-in-query http://h?x=a@b | |
| 121 | + {name h user {} path {} canonical http://h} | |
| 122 | + http-at-in-fragment http://h#a@b | |
| 123 | + {name h user {} path {} canonical http://h} | |
| 124 | + http-fragment-dropped http://h/a/b#frag | |
| 125 | + {path /a/b canonical http://h/a/b} | |
| 126 | + http-query-dropped http://h/a?x=1&y=2 | |
| 127 | + {path /a canonical http://h/a fossil {}} | |
| 128 | + http-query-no-value http://h/a?x&y | |
| 129 | + {path /a canonical http://h/a fossil {}} | |
| 130 | + http-path-escapes {http://h/a%20b/c%2Bd} | |
| 131 | + {path {/a b/c+d} canonical http://h/a+b/c%2Bd} | |
| 132 | + http-path-bad-escape http://h/a%zz | |
| 133 | + {path /a%zz canonical http://h/a%25zz} | |
| 134 | + http-host-escape http://loc%61lhost/x | |
| 135 | + {name localhost} | |
| 136 | + http-host-upper-case http://LOCALHOST/X | |
| 137 | + {name localhost path /X} | |
| 138 | + http-ipv6 {http://[::1]/x} | |
| 139 | + {name ::1 port 80 hostname {[::1]} canonical {http://[::1]/x}} | |
| 140 | + http-ipv6-port {http://[2001:DB8::1]:8080/x} | |
| 141 | + {name 2001:db8::1 port 8080 hostname {[2001:db8::1]:8080} | |
| 142 | + canonical {http://[2001:db8::1]:8080/x}} | |
| 143 | + http-ipv6-user {http://u:p@[::1]:81/x} | |
| 144 | + {name ::1 user u full {http://u:p@[::1]:81/x}} | |
| 145 | + http-brackets-one-letter {http://[a]/x} | |
| 146 | + {name a hostname a} | |
| 147 | + http-bracket-not-closed {http://[ab/x} | |
| 148 | + {name {[ab} path /x} | |
| 149 | + http-user-empty http://@h/x | |
| 150 | + {user {} name h canonical http://@h/x full http://@h/x} | |
| 151 | + http-host-one-letter http://h | |
| 152 | + {name h hostname h} | |
| 153 | + ssh-plain ssh://h/dir/r.fossil | |
| 154 | + {isSsh 1 protocol ssh name h port 22 dfltPort 22 hostname h | |
| 155 | + path dir/r.fossil fossil fossil canonical ssh://h/dir/r.fossil | |
| 156 | + flags 0x0000} | |
| 157 | + ssh-upper-case-user-port SSH://U@H:2222/dir/r.fossil | |
| 158 | + {isSsh 1 name h user U port 2222 hostname h:2222 path dir/r.fossil | |
| 159 | + canonical ssh://U@h:2222/dir/r.fossil} | |
| 160 | + ssh-absolute-path ssh://h//abs/r.fossil | |
| 161 | + {path /abs/r.fossil canonical ssh://h//abs/r.fossil} | |
| 162 | + ssh-root-path ssh://h/ | |
| 163 | + {path / canonical ssh://h/} | |
| 164 | + ssh-fossil-parameter ssh://h/r.fossil?fossil=/opt/bin/fossil | |
| 165 | + {path r.fossil fossil /opt/bin/fossil | |
| 166 | + canonical ssh://h/r.fossil?fossil=/opt/bin/fossil flags 0x0400} | |
| 167 | + ssh-fossil-parameter-escaped ssh://h/r.fossil?fossil=/opt/my%20bin/fossil | |
| 168 | + {fossil {/opt/my bin/fossil} | |
| 169 | + canonical ssh://h/r.fossil?fossil=/opt/my+bin/fossil} | |
| 170 | + ssh-fossil-parameter-among-others ssh://h/r.fossil?a=b&fossil=/x/fossil&c | |
| 171 | + {path r.fossil fossil /x/fossil | |
| 172 | + canonical ssh://h/r.fossil?fossil=/x/fossil} | |
| 173 | + ssh-fossil-parameter-empty ssh://h/r.fossil?fossil= | |
| 174 | + {fossil {} flags 0x0400} | |
| 175 | + ssh-ipv6 {ssh://[::1]/r.fossil} | |
| 176 | + {name ::1 hostname ::1 canonical {ssh://[::1]/r.fossil}} | |
| 177 | + ssh-ipv6-port {ssh://[::1]:2222/r.fossil} | |
| 178 | + {name ::1 port 2222 hostname ::1:2222 | |
| 179 | + canonical {ssh://[::1]:2222/r.fossil}} | |
| 180 | + ssh-user-password ssh://u:p@h/r.fossil | |
| 181 | + {user u passwd p canonical ssh://u@h/r.fossil} | |
| 182 | + file-three-slashes file:///nosuchdir/r.fossil | |
| 183 | + {isFile 1 protocol file name /nosuchdir/r.fossil path {} | |
| 184 | + canonical file:///nosuchdir/r.fossil full file:///nosuchdir/r.fossil} | |
| 185 | + file-one-slash file:/nosuchdir/r.fossil | |
| 186 | + {isFile 1 name /nosuchdir/r.fossil} | |
| 187 | + file-upper-case FILE:///nosuchdir/r.fossil | |
| 188 | + {isFile 1 name /nosuchdir/r.fossil} | |
| 189 | + file-escaped-space file:///nosuchdir/my%20r.fossil | |
| 190 | + {isFile 1 name {/nosuchdir/my r.fossil} | |
| 191 | + canonical file:///nosuchdir/my+r.fossil} | |
| 192 | +} { | |
| 193 | + url_parse_test url-parse-$urlName $urlText {} $urlExpected | |
| 194 | +} | |
| 195 | + | |
| 196 | +# A file: URL with a relative name, the name of a repository file, and | |
| 197 | +# the name of a directory that holds a file named FOSSIL, are all the | |
| 198 | +# absolute name of the file. | |
| 199 | +# | |
| 200 | +file mkdir holder emptydir | |
| 201 | +file copy $urlRepo holder/FOSSIL | |
| 202 | +url_parse_test url-parse-file-relative file:.rep.fossil {} \ | |
| 203 | + [list isFile 1 name $urlRepo canonical file://$urlRepo] | |
| 204 | +url_parse_test url-parse-file-name .rep.fossil {} \ | |
| 205 | + [list isFile 1 protocol file name $urlRepo] | |
| 206 | +url_parse_test url-parse-directory holder {} \ | |
| 207 | + [list isFile 1 name [file join $urlDir holder FOSSIL]] | |
| 208 | + | |
| 209 | +# What is not a URL, a file or a directory with a repository is refused, | |
| 210 | +# and so is a port that is too large or is followed by other text. | |
| 211 | +# | |
| 212 | +foreach {urlName urlText urlMessage} { | |
| 213 | + no-scheme nosuchfile {unknown repository: nosuchfile} | |
| 214 | + empty {} {unknown repository: } | |
| 215 | + other-scheme ftp://h/x {unknown repository: ftp://h/x} | |
| 216 | + scheme-no-slashes http:h/x {unknown repository: http:h/x} | |
| 217 | + directory-empty emptydir {unknown repository: emptydir} | |
| 218 | + port-too-large http://h:65536/x {port number too large in url} | |
| 219 | + port-huge http://h:99999999999999999999/x | |
| 220 | + {port number too large in url} | |
| 221 | + port-negative http://h:-1/x {url missing '/' after port number} | |
| 222 | + port-letters http://h:80x/ {url missing '/' after port number} | |
| 223 | + port-ipv6-junk {http://[::1]:8x} {url missing '/' after port number} | |
| 224 | +} { | |
| 225 | + fossil_raw test-urlparser $urlText --proxy off | |
| 226 | + test url-parse-refused-$urlName \ | |
| 227 | + {$CODE == 1 && [string first $urlMessage $RESULT] >= 0} | |
| 228 | +} | |
| 229 | + | |
| 230 | +# An ssh: URL with a host and no path has an empty path, and fossil | |
| 231 | +# prints nothing but the parts of the URL. | |
| 232 | +# | |
| 233 | +foreach {urlName urlText urlExpected} { | |
| 234 | + host ssh://host | |
| 235 | + {isSsh 1 name host port 22 hostname host user {} path {} | |
| 236 | + canonical ssh://host} | |
| 237 | + user-host ssh://u@h | |
| 238 | + {isSsh 1 name h port 22 user u path {} canonical ssh://u@h} | |
| 239 | + host-port ssh://h:22 | |
| 240 | + {isSsh 1 name h port 22 hostname h:22 path {} canonical ssh://h} | |
| 241 | + user-host-port ssh://u@h:2222 | |
| 242 | + {isSsh 1 name h port 2222 path {} canonical ssh://u@h:2222} | |
| 243 | + scheme-only ssh:// | |
| 244 | + {isSsh 1 name {} path {} canonical ssh://} | |
| 245 | +} { | |
| 246 | + url_parse_test url-parse-ssh-no-path-$urlName $urlText {} $urlExpected | |
| 247 | + test url-parse-ssh-no-path-$urlName-output {$CODE == 0 && | |
| 248 | + [regexp -all -line {^(g\.url\.\w+ +|url_full\(g\.url\) )= } $RESULT] == | |
| 249 | + [llength [split [string trim $RESULT] \n]]} | |
| 250 | +} | |
| 251 | + | |
| 252 | +# The complete URL of an ssh: remote has the "/" between the host and | |
| 253 | +# the path. | |
| 254 | +# | |
| 255 | +url_parse_test url-parse-ssh-full ssh://u@h/dir/r.fossil {} \ | |
| 256 | + {full ssh://u@h/dir/r.fossil} | |
| 257 | + | |
| 258 | +# A second fossil= parameter is refused. | |
| 259 | +# | |
| 260 | +fossil_raw test-urlparser ssh://h/r.fossil?fossil=/a/fossil&fossil=/b/fossil \ | |
| 261 | + --proxy off | |
| 262 | +test url-parse-ssh-fossil-twice {$CODE == 1 && | |
| 263 | + [string match "*more than one fossil= query parameter*" $RESULT]} | |
| 264 | + | |
| 265 | +# A very long user name, password, host and path. The four together stay | |
| 266 | +# under the 128 KB that Linux allows for one argument. | |
| 267 | +# | |
| 268 | +set urlLong [string repeat a 30000] | |
| 269 | +url_parse_test url-parse-long http://$urlLong:$urlLong@$urlLong/$urlLong {} \ | |
| 270 | + [list user $urlLong passwd $urlLong name $urlLong path /$urlLong] | |
| 271 | + | |
| 272 | +# test-urlparser takes one or two arguments. | |
| 273 | +# | |
| 274 | +fossil_raw test-urlparser | |
| 275 | +test url-parse-usage-none {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]} | |
| 276 | +fossil_raw test-urlparser http://h/ extra more | |
| 277 | +test url-parse-usage-many {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]} | |
| 278 | +url_parse_test url-parse-two-arguments http://h/x extra {name h path /x} | |
| 279 | + | |
| 280 | +############################################################################### | |
| 281 | +# Flags of the parser: --remember, --prompt-pw. Standard input is not a | |
| 282 | +# terminal here, so fossil cannot ask for a password. | |
| 283 | + | |
| 284 | +url_parse_test url-flag-remember http://h/x --remember {flags 0x0002} | |
| 285 | +url_parse_test url-flag-remember-password http://u:p@h/x --remember \ | |
| 286 | + {user u passwd p flags 0x0006} | |
| 287 | +url_parse_test url-flag-remember-password-ssh ssh://u:p@h/x --remember \ | |
| 288 | + {user u passwd p flags 0x0002} | |
| 289 | +url_parse_test url-flag-prompt-has-password http://u:p@h/x --prompt-pw \ | |
| 290 | + {user u passwd p flags 0x0001} | |
| 291 | +url_parse_test url-flag-prompt-no-user http://h/x --prompt-pw \ | |
| 292 | + {user {} flags 0x0001} | |
| 293 | +url_parse_test url-flag-prompt-ssh ssh://u@h/x --prompt-pw \ | |
| 294 | + {user u passwd {} flags 0x0001} | |
| 295 | +url_parse_test url-flag-prompt-file file:///nosuchdir/x --prompt-pw \ | |
| 296 | + {isFile 1 flags 0x0001} | |
| 297 | +fossil_raw test-urlparser http://u@h/x --proxy off --prompt-pw | |
| 298 | +test url-flag-prompt-no-terminal {$CODE == 1 && [string first \ | |
| 299 | + {missing or incorrect password for user "u"} $RESULT] >= 0} | |
| 300 | + | |
| 301 | +############################################################################### | |
| 302 | +# Saved remotes. --use-config reads the URL "default" from the | |
| 303 | +# last-sync-url setting and any other name from the remote of that name, | |
| 304 | +# with the saved password. --use-parent reads the parent project. | |
| 305 | + | |
| 306 | +proc url_config {name value} { | |
| 307 | + fossil sql "REPLACE INTO config(name,value,mtime) VALUES('$name',$value,0)" | |
| 308 | +} | |
| 309 | + | |
| 310 | +url_parse_test url-config-default-unset default --use-config \ | |
| 311 | + {protocol {} name {} canonical {} isFile 0} | |
| 312 | +url_parse_test url-config-parent-unset default --use-parent \ | |
| 313 | + {protocol {} name {} canonical {}} | |
| 314 | +url_config last-sync-url 'http://u@h/last' | |
| 315 | +url_config last-sync-pw obscure('lastpw') | |
| 316 | +url_parse_test url-config-default default --use-config \ | |
| 317 | + {name h user u passwd ************ pwConfig last-sync-pw | |
| 318 | + canonical http://u@h/last flags 0x0040} | |
| 319 | +url_parse_test url-config-default-show default {--use-config --show-pw} \ | |
| 320 | + {name h user u passwd lastpw pwConfig last-sync-pw} | |
| 321 | +url_parse_test url-config-parent-falls-back default --use-parent \ | |
| 322 | + {user u passwd ************ pwConfig last-sync-pw | |
| 323 | + canonical http://u@h/last flags 0x00c0} | |
| 324 | +url_config parent-project-url 'http://pu@ph/parent' | |
| 325 | +url_config parent-project-pw obscure('parentpw') | |
| 326 | +url_parse_test url-config-parent default {--use-parent --show-pw} \ | |
| 327 | + {name ph user pu passwd parentpw pwConfig parent-project-pw | |
| 328 | + canonical http://pu@ph/parent} | |
| 329 | +url_parse_test url-config-default-not-parent default {--use-config --show-pw} \ | |
| 330 | + {name h passwd lastpw} | |
| 331 | + | |
| 332 | +fossil remote add east http://eu:eastpw@eh:81/east | |
| 333 | +url_parse_test url-config-named east {--use-config --show-pw} \ | |
| 334 | + {name eh port 81 user eu passwd eastpw pwConfig sync-pw:east | |
| 335 | + canonical http://eu@eh:81/east flags 0x0048} | |
| 336 | +url_parse_test url-config-named-hidden east --use-config \ | |
| 337 | + {user eu passwd ************} | |
| 338 | +url_parse_test url-config-url-not-a-name http://x/y --use-config \ | |
| 339 | + {name x path /y pwConfig {} flags 0x0040} | |
| 340 | +fossil_raw test-urlparser nosuchremote --proxy off --use-config | |
| 341 | +test url-config-unknown-name {$CODE == 1 && | |
| 342 | + [string first "unknown repository: nosuchremote" $RESULT] >= 0} | |
| 343 | +url_parse_test url-config-name-without-flag east {} \ | |
| 344 | + {protocol (missing)} | |
| 345 | +test url-config-name-without-flag-refused {$CODE == 1 && | |
| 346 | + [string first "unknown repository: east" $RESULT] >= 0} | |
| 347 | + | |
| 348 | +# "fossil remote" saves the URL without the password. It does not save | |
| 349 | +# the password when it cannot ask whether to. | |
| 350 | +# | |
| 351 | +fossil remote http://ru:remotepw@rh/remote | |
| 352 | +fossil remote | |
| 353 | +test_eq url-remember-url [string trim $RESULT] http://ru@rh/remote | |
| 354 | +url_parse_test url-remember-no-password default {--use-config --show-pw} \ | |
| 355 | + {name rh user ru passwd {}} | |
| 356 | + | |
| 357 | +# "fossil remote hyperlink" prints the URL of the remote without the user. | |
| 358 | +# | |
| 359 | +fossil_raw remote hyperlink | |
| 360 | +test_match url-nouser-hyperlink $RESULT {^http://rh/remote/info/[0-9a-f]+\s*$} | |
| 361 | +fossil remote http://ru:remotepw@rh:8081/remote | |
| 362 | +fossil_raw remote hyperlink | |
| 363 | +test_match url-nouser-hyperlink-port $RESULT \ | |
| 364 | + {^http://rh:8081/remote/info/[0-9a-f]+\s*$} | |
| 365 | +fossil remote {http://ru:remotepw@[::1]/remote} | |
| 366 | +fossil_raw remote hyperlink | |
| 367 | +test_match url-nouser-hyperlink-ipv6 $RESULT \ | |
| 368 | + {^http://\[::1\]/remote/info/[0-9a-f]+\s*$} | |
| 369 | +fossil remote http://rh/remote | |
| 370 | +fossil_raw remote hyperlink | |
| 371 | +test_match url-nouser-hyperlink-no-user $RESULT \ | |
| 372 | + {^http://rh/remote/info/[0-9a-f]+\s*$} | |
| 373 | +url_config last-sync-url 'http://@rh/remote' | |
| 374 | +fossil_raw remote hyperlink | |
| 375 | +test_match url-nouser-hyperlink-empty-user $RESULT \ | |
| 376 | + {^http://@rh/remote/info/[0-9a-f]+\s*$} | |
| 377 | +fossil remote off | |
| 378 | + | |
| 379 | +# The SQL function url_nouser() gives a URL without its user and | |
| 380 | +# password, and NULL for NULL. | |
| 381 | +# | |
| 382 | +foreach {urlName urlSql urlExpected} { | |
| 383 | + http {url_nouser('http://u:p@h:81/x')} http://h:81/x | |
| 384 | + no-user {url_nouser('https://h/x')} https://h/x | |
| 385 | + ssh {url_nouser('ssh://u@h/dir/r.fossil')} ssh://h/dir/r.fossil | |
| 386 | + file {url_nouser('file:///nosuchdir/r')} file:///nosuchdir/r | |
| 387 | + null {coalesce(url_nouser(NULL),'null')} null | |
| 388 | +} { | |
| 389 | + fossil sql "SELECT $urlSql" | |
| 390 | + test_eq url-nouser-sql-$urlName [string trim $RESULT] $urlExpected | |
| 391 | +} | |
| 392 | + | |
| 393 | +# The /urllist page links each saved remote to its URL without the user. | |
| 394 | +# | |
| 395 | +write_file urllist.txt "GET /urllist HTTP/1.0\r\n\r\n" | |
| 396 | +fossil_raw http --in urllist.txt --ipaddr 127.0.0.1 $urlRepo --localauth | |
| 397 | +test url-nouser-urllist {[string first "HTTP/1.0 200 OK" $RESULT] == 0 && | |
| 398 | + [string first "<a href='http://eh:81/east'>http://eu@eh:81/east</a>" \ | |
| 399 | + $RESULT] >= 0} | |
| 400 | + | |
| 401 | +############################################################################### | |
| 402 | +# A proxy. test-urlparser prints the URL again as it is used through | |
| 403 | +# the proxy from --proxy, the "proxy" setting or the http_proxy | |
| 404 | +# environment variable, after a line of stars. | |
| 405 | + | |
| 406 | +# Returns what test-urlparser printed after "Using proxy:", or "none" if | |
| 407 | +# it named no proxy. | |
| 408 | +proc url_proxy {url args} { | |
| 409 | + fossil_raw test-urlparser $url {*}$args | |
| 410 | + if {[regexp -line {^Using proxy: (.*)$} $::RESULT -> proxy]} { | |
| 411 | + return $proxy | |
| 412 | + } | |
| 413 | + return none | |
| 414 | +} | |
| 415 | +test_eq url-proxy-option [url_proxy http://h/x --proxy http://pu:pp@ph:3128] \ | |
| 416 | + http://pu@ph:3128 | |
| 417 | +test_eq url-proxy-off [url_proxy http://h/x --proxy off] none | |
| 418 | +test_eq url-proxy-empty [url_proxy http://h/x --proxy ""] none | |
| 419 | +test_eq url-proxy-none-set [url_proxy http://h/x] none | |
| 420 | +test_eq url-proxy-ssh-url [url_proxy ssh://h/x --proxy http://ph:3128] none | |
| 421 | +test_eq url-proxy-file-url \ | |
| 422 | + [url_proxy file:///nosuchdir/x --proxy http://ph:3128] none | |
| 423 | +set env(http_proxy) http://envproxy:3128 | |
| 424 | +test_eq url-proxy-environment [url_proxy http://h/x] http://envproxy:3128 | |
| 425 | +test_eq url-proxy-option-over-environment \ | |
| 426 | + [url_proxy http://h/x --proxy http://ph:3128] http://ph:3128 | |
| 427 | +fossil settings proxy http://setproxy:3128 | |
| 428 | +test_eq url-proxy-setting [url_proxy http://h/x] http://setproxy:3128 | |
| 429 | +fossil settings proxy off | |
| 430 | +test_eq url-proxy-setting-off [url_proxy http://h/x] none | |
| 431 | +fossil unset proxy | |
| 432 | +unset env(http_proxy) | |
| 433 | +fossil_raw test-urlparser http://h/x --proxy nosuchproxy | |
| 434 | +test url-proxy-not-a-url {$CODE == 1 && | |
| 435 | + [string first "unknown repository: nosuchproxy" $RESULT] >= 0} | |
| 436 | + | |
| 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} { | |
| 447 | + path-tail http://h/a/b/repo repo | |
| 448 | + suffix-dropped http://h/a/repo.fossil repo | |
| 449 | + trailing-slash http://h/a/repo/ repo | |
| 450 | + query-dropped http://h/a/repo?x=/y repo | |
| 451 | + host-only http://example.com example | |
| 452 | + host-www http://www.example.com example | |
| 453 | + host-www-upper http://WWW.example.com example | |
| 454 | + host-www-suffix http://www.com www | |
| 455 | + host-port http://example.com:8080 example | |
| 456 | + host-www-port http://www.example.org:8080/ example | |
| 457 | + user-at-host ssh://u@host host | |
| 458 | + user-host-path ssh://u@host/dir/r.fossil r | |
| 459 | + no-separator nosuchthing {} | |
| 460 | + slash-only / {} | |
| 461 | + at-only @ {} | |
| 462 | + empty {} {} | |
| 463 | + dot-first http://h/.hidden {} | |
| 464 | + www-dot-only http://www. www | |
| 465 | + colon-in-tail host/a:b a | |
| 466 | +} { | |
| 467 | + fossil test-url-basename $urlText | |
| 468 | + test_eq url-basename-$urlName [string trim $RESULT] \ | |
| 469 | + [string trim "$urlText -> $urlExpected"] | |
| 470 | +} | |
| 471 | +fossil test-url-basename http://h/one http://h/two | |
| 472 | +test_eq url-basename-two [string trim $RESULT] \ | |
| 473 | + "http://h/one -> one\nhttp://h/two -> two" | |
| 474 | +fossil test-url-basename | |
| 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] | |
| 531 | +} | |
| 532 | + | |
| 533 | +# Returns the request line of request NUMBER of the last exchange. | |
| 534 | +proc url_request_line {number} { | |
| 535 | + return [lindex [split [lindex $::urlRequests $number] \r] 0] | |
| 536 | +} | |
| 537 | + | |
| 538 | +# Returns the value of the header NAME in request NUMBER of the last | |
| 539 | +# exchange, or "(none)". | |
| 540 | +proc url_request_header {number name} { | |
| 541 | + if {[regexp -nocase -line "^$name: (\[^\r\]*)" \ | |
| 542 | + [lindex $::urlRequests $number] -> value]} { | |
| 543 | + return $value | |
| 544 | + } | |
| 545 | + return (none) | |
| 546 | +} | |
| 547 | + | |
| 548 | +# Returns the body of request NUMBER of the last exchange. | |
| 549 | +proc url_request_body {number} { | |
| 550 | + set request [lindex $::urlRequests $number] | |
| 551 | + return [string range $request [expr {[string first "\r\n\r\n" $request]+4}] \ | |
| 552 | + end] | |
| 553 | +} | |
| 554 | + | |
| 555 | +# Runs "fossil test-httpmsg" on the path /x of a server that answers | |
| 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 | +# | |
| 567 | +set urlBig [string repeat 0123456789 500] | |
| 568 | +foreach {urlName urlHeader urlBody urlExpected} [list \ | |
| 569 | + content-length "HTTP/1.1 200 OK\nContent-Length: 5\n\n" hello hello \ | |
| 570 | + content-length-zero "HTTP/1.1 200 OK\nContent-Length: 0\n\n" "" "" \ | |
| 571 | + content-length-spaces "HTTP/1.1 200 OK\nContent-Length: 5 \n\n" hello \ | |
| 572 | + hello \ | |
| 573 | + content-length-twice-same \ | |
| 574 | + "HTTP/1.1 200 OK\nContent-Length: 5\nContent-Length: 5\n\n" hello \ | |
| 575 | + hello \ | |
| 576 | + bytes-after-length "HTTP/1.1 200 OK\nContent-Length: 2\n\n" hello he \ | |
| 577 | + no-length "HTTP/1.1 200 OK\n\n" hello hello \ | |
| 578 | + no-length-large "HTTP/1.1 200 OK\n\n" $urlBig $urlBig \ | |
| 579 | + no-length-empty "HTTP/1.1 200 OK\n\n" "" "" \ | |
| 580 | + header-cut-short "HTTP/1.1 200 OK\nContent-Length: 0\n" "" "" \ | |
| 581 | + status-line-only "HTTP/1.1 200" "" "" \ | |
| 582 | + http-1.0 "HTTP/1.0 200 OK\nContent-Length: 5\n\n" hello hello \ | |
| 583 | + header-lower-case "HTTP/1.1 200 ok\ncontent-length: 5\n\n" hello hello \ | |
| 584 | + connection-close \ | |
| 585 | + "HTTP/1.1 200 OK\nConnection: close\nContent-Length: 5\n\n" hello \ | |
| 586 | + hello \ | |
| 587 | + connection-keep-alive \ | |
| 588 | + "HTTP/1.0 200 OK\nConnection: Keep-Alive\nContent-Length: 5\n\n" \ | |
| 589 | + hello hello \ | |
| 590 | + connection-other \ | |
| 591 | + "HTTP/1.1 200 OK\nConnection: upgrade\nContent-Length: 5\n\n" hello \ | |
| 592 | + hello \ | |
| 593 | + location-with-200 \ | |
| 594 | + "HTTP/1.1 200 OK\nLocation: http://127.0.0.1:1/\nContent-Length: 5\n\n" \ | |
| 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 \ | |
| 621 | + chunked-hex-letters "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 622 | + "a\r\n0123456789\r\n00\r\n\r\n" 0123456789 \ | |
| 623 | + chunked-extension "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 624 | + "5;name=value\r\nhello\r\n0\r\n\r\n" hello \ | |
| 625 | + chunked-extension-spaces "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 626 | + "5 \t; \tname\r\nhello\r\n0 \r\n\r\n" hello \ | |
| 627 | + chunked-extension-punctuation \ | |
| 628 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 629 | + "5;!x\r\nhello\r\n0\r\n\r\n" hello \ | |
| 630 | + chunked-trailer "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 631 | + "5\r\nhello\r\n0\r\nTrailer: x\r\nOther: y\r\n\r\n" hello \ | |
| 632 | + chunked-trailer-cut-short "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 633 | + "5\r\nhello\r\n0\r\nTrailer: x" hello \ | |
| 634 | + chunked-empty "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ | |
| 635 | + "0\r\n\r\n" "" \ | |
| 636 | +] { | |
| 637 | + url_httpmsg [list [url_crlf $urlHeader]$urlBody] | |
| 638 | + test url-http-accepted-$urlName {$CODE == 0 && $RESULT eq $urlExpected} | |
| 639 | +} | |
| 640 | + | |
| 641 | +# Replies that are refused. Each row is a name, the reply, and what | |
| 642 | +# "fossil test-httpmsg -v" must say. | |
| 643 | +# | |
| 644 | +foreach {urlName urlReply urlMessage} [list \ | |
| 645 | + nothing "" {server did not reply} \ | |
| 646 | + not-http "hello\r\n\r\n" {server did not reply} \ | |
| 647 | + status-bad-version "HTTP/1.x 200 OK\n\n" {Read: \[HTTP/1.x 200 OK\]\s*$} \ | |
| 648 | + status-no-code "HTTP/1.1\n\n" {Read: \[HTTP/1.1\]\s*$} \ | |
| 649 | + status-lower-case "http/1.1 200 OK\nContent-Length: 0\n\n" \ | |
| 650 | + {Read: \[http/1.1 200 OK\]\s*$} \ | |
| 651 | + status-500 "HTTP/1.1 500 Server Error\n\n" \ | |
| 652 | + {server says: 500 Server Error} \ | |
| 653 | + status-500-no-reason "HTTP/1.1 500\n\n" {server says: 500\n} \ | |
| 654 | + status-tab "HTTP/1.1\t500\n\n" {server says: \n} \ | |
| 655 | + status-404 "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n" \ | |
| 656 | + {server says: 404 Not Found} \ | |
| 657 | + status-negative "HTTP/1.1 -200 OK\n\n" {server says: -200 OK} \ | |
| 658 | + status-huge "HTTP/1.1 99999999999999999999 OK\n\n" {server says: } \ | |
| 659 | + status-204 "HTTP/1.1 204 No Content\n\n" {server says: 204 No Content} \ | |
| 660 | + folded-space "HTTP/1.1 200 OK\nX-A: b\n c\n\n" \ | |
| 661 | + {server sent a folded header line} \ | |
| 662 | + folded-tab "HTTP/1.1 200 OK\nX-A: b\n\tc\n\n" \ | |
| 663 | + {server sent a folded header line} \ | |
| 664 | + interim-only "HTTP/1.1 100 Continue\n\n" {server did not reply} \ | |
| 665 | + interim-cut-short "HTTP/1.1 100 Continue\nX-A: b\n" {server did not reply} \ | |
| 666 | + interim-five-blank-lines \ | |
| 667 | + "HTTP/1.1 100 Continue\n\n\n\n\n\n\nHTTP/1.1 200 OK\n\n" \ | |
| 668 | + {server did not reply} \ | |
| 669 | + content-length-none "HTTP/1.1 200 OK\nContent-Length:\n\n" \ | |
| 670 | + {server sent a bad content-length: Content-Length:} \ | |
| 671 | + content-length-negative "HTTP/1.1 200 OK\nContent-Length: -5\n\nhello" \ | |
| 672 | + {server sent a bad content-length} \ | |
| 673 | + content-length-plus "HTTP/1.1 200 OK\nContent-Length: +5\n\nhello" \ | |
| 674 | + {server sent a bad content-length} \ | |
| 675 | + content-length-hex "HTTP/1.1 200 OK\nContent-Length: 0x5\n\nhello" \ | |
| 676 | + {server sent a bad content-length} \ | |
| 677 | + content-length-two-numbers "HTTP/1.1 200 OK\nContent-Length: 5 5\n\nhello" \ | |
| 678 | + {server sent a bad content-length} \ | |
| 679 | + content-length-list "HTTP/1.1 200 OK\nContent-Length: 5,5\n\nhello" \ | |
| 680 | + {server sent a bad content-length} \ | |
| 681 | + content-length-2147483648 \ | |
| 682 | + "HTTP/1.1 200 OK\nContent-Length: 2147483648\n\nhello" \ | |
| 683 | + {server sent a bad content-length} \ | |
| 684 | + content-length-twice-different \ | |
| 685 | + "HTTP/1.1 200 OK\nContent-Length: 5\nContent-Length: 4\n\nhello" \ | |
| 686 | + {server sent two different content-length values} \ | |
| 687 | + content-length-zero-then-other \ | |
| 688 | + "HTTP/1.1 200 OK\nContent-Length: 0\nContent-Length: 5\n\nhello" \ | |
| 689 | + {server sent two different content-length values} \ | |
| 690 | + content-length-too-long "HTTP/1.1 200 OK\nContent-Length: 6\n\nhello" \ | |
| 691 | + {response truncated: got 5 bytes of 6} \ | |
| 692 | + transfer-encoding-gzip "HTTP/1.1 200 OK\nTransfer-Encoding: gzip\n\n" \ | |
| 693 | + {unsupported transfer-encoding: gzip} \ | |
| 694 | + transfer-encoding-gzip-chunked \ | |
| 695 | + "HTTP/1.1 200 OK\nTransfer-Encoding: gzip, chunked\n\n" \ | |
| 696 | + {unsupported transfer-encoding: gzip, chunked} \ | |
| 697 | + transfer-encoding-chunked-more \ | |
| 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} \ | |
| 715 | + chunk-size-letters "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\nzz\n" \ | |
| 716 | + {chunked reply: missing or malformed chunk size} \ | |
| 717 | + chunk-size-negative \ | |
| 718 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n-5\nhello\n0\n\n" \ | |
| 719 | + {chunked reply: missing or malformed chunk size} \ | |
| 720 | + chunk-size-0x \ | |
| 721 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n0x5\nhello\n0\n\n" \ | |
| 722 | + {chunked reply: malformed chunk size line} \ | |
| 723 | + chunk-size-space-first \ | |
| 724 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n 5\nhello\n0\n\n" \ | |
| 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 \ | |
| 736 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5;\nhello\n0\n\n" \ | |
| 737 | + {chunked reply: malformed chunk size line} \ | |
| 738 | + chunk-extension-equals \ | |
| 739 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5; =v\nhello\n0\n\n" \ | |
| 740 | + {chunked reply: malformed chunk size line} \ | |
| 741 | + chunk-cut-short "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\nhel" \ | |
| 742 | + {chunked reply truncated} \ | |
| 743 | + chunk-no-data "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\n" \ | |
| 744 | + {chunked reply truncated} \ | |
| 745 | + chunk-too-long \ | |
| 746 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n3\nhello\n0\n\n" \ | |
| 747 | + {chunked reply: no line end after chunk data} \ | |
| 748 | + chunk-no-line-end "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\nhello" \ | |
| 749 | + {chunked reply ended without terminator} \ | |
| 750 | + chunk-no-terminator \ | |
| 751 | + "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\nhello\n" \ | |
| 752 | + {chunked reply ended without terminator} \ | |
| 753 | + redirect-no-location "HTTP/1.1 302 Found\nContent-Length: 0\n\n" \ | |
| 754 | + {"location:" missing from 302 redirect reply} \ | |
| 755 | + redirect-301-no-location "HTTP/1.1 301 Moved\n\n" \ | |
| 756 | + {"location:" missing from 301 redirect reply} \ | |
| 757 | + redirect-307-no-location "HTTP/1.1 307 Temporary\n\n" \ | |
| 758 | + {"location:" missing from 307 redirect reply} \ | |
| 759 | + redirect-308-no-location "HTTP/1.1 308 Permanent\n\n" \ | |
| 760 | + {"location:" missing from 308 redirect reply} \ | |
| 761 | + redirect-empty-location "HTTP/1.1 302 Found\nLocation:\n\n" \ | |
| 762 | + {malformed redirect: Location:} \ | |
| 763 | + redirect-blank-location "HTTP/1.1 302 Found\nLocation: \n\n" \ | |
| 764 | + {malformed redirect: Location:} \ | |
| 765 | + redirect-to-file \ | |
| 766 | + "HTTP/1.1 302 Found\nLocation: file:///nosuchdir/r.fossil\n\n" \ | |
| 767 | + {cannot redirect to file:///nosuchdir/r.fossil} \ | |
| 768 | + redirect-to-ssh "HTTP/1.1 302 Found\nLocation: ssh://h/r.fossil\n\n" \ | |
| 769 | + {cannot redirect to ssh://h/r.fossil} \ | |
| 770 | + redirect-to-other-scheme "HTTP/1.1 302 Found\nLocation: ftp://h/x\n\n" \ | |
| 771 | + {unknown repository: ftp://h/x} \ | |
| 772 | + redirect-to-bad-port "HTTP/1.1 302 Found\nLocation: http://h:99999/\n\n" \ | |
| 773 | + {port number too large in url} \ | |
| 774 | + redirect-loop "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/x\n\n" \ | |
| 775 | + {redirect limit exceeded} \ | |
| 776 | + redirect-only-xfer "HTTP/1.1 302 Found\nLocation: /xfer\n\n" \ | |
| 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. | |
| 788 | +# | |
| 789 | +url_httpmsg [list [url_crlf "HTTP/1.1 302 Found\nLocation: ssh://h\n\n"]] -v | |
| 790 | +test_match url-http-refused-redirect-to-ssh-no-path "$CODE $RESULT" \ | |
| 791 | + {^1 (?:.*\n)*.*cannot redirect to ssh://h} | |
| 792 | + | |
| 793 | +# A status line that test-httpmsg prints an error for without -v only | |
| 794 | +# when it is not told to be quiet: it is quiet when it prints the reply | |
| 795 | +# on standard output, and it is not when the reply goes to a file. | |
| 796 | +# | |
| 797 | +foreach {urlName urlReply urlMessage} [list \ | |
| 798 | + status-500 "HTTP/1.1 500 Server Error\n\n" {server says: 500 Server Error} \ | |
| 799 | + no-reply "" {server did not reply} \ | |
| 800 | + redirect-no-location "HTTP/1.1 302 Found\n\n" \ | |
| 801 | + {"location:" missing from 302 redirect reply} \ | |
| 802 | + redirect-loop "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/x\n\n" \ | |
| 803 | + {redirect limit exceeded} \ | |
| 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 | |
| 815 | +# the bytes that came are printed. | |
| 816 | +# | |
| 817 | +set urlShort [url_crlf "HTTP/1.1 200 OK\nContent-Length: 6\n\nhello"] | |
| 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. | |
| 867 | +# | |
| 868 | +url_httpmsg [list [url_crlf "HTTP/1.1 401 Unauthorized\n\n"]] -v | |
| 869 | +test url-http-401-three-requests {$CODE == 1 && [llength $urlRequests] == 3 && | |
| 870 | + [string first "server says: 401 Unauthorized" $RESULT] >= 0} | |
| 871 | +url_httpmsg [list [url_crlf "HTTP/1.1 401 Unauthorized\n\n"] \ | |
| 872 | + [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] | |
| 873 | +test url-http-401-then-200 {$CODE == 0 && $RESULT eq "hello" && | |
| 874 | + [llength $urlRequests] == 2} | |
| 875 | + | |
| 876 | +############################################################################### | |
| 877 | +# The request. | |
| 878 | + | |
| 879 | +set urlOk [url_crlf "HTTP/1.1 200 OK\nContent-Length: 2\n\nok"] | |
| 880 | + | |
| 881 | +url_httpmsg [list $urlOk] | |
| 882 | +test url-request-get {[url_request_line 0] eq "GET /x HTTP/1.1" && | |
| 883 | + [string match 127.0.0.1:* [url_request_header 0 Host]] && | |
| 884 | + [url_request_header 0 Connection] eq "close" && | |
| 885 | + [string match "Fossil/*" [url_request_header 0 User-Agent]] && | |
| 886 | + [url_request_header 0 Content-Type] eq "(none)" && | |
| 887 | + [url_request_header 0 Content-Length] eq "(none)" && | |
| 888 | + [url_request_header 0 X-Fossil-Transport] eq "(none)" && | |
| 889 | + [url_request_header 0 Authorization] eq "(none)" && | |
| 890 | + [url_request_header 0 Proxy-Authorization] eq "(none)" && | |
| 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" && | |
| 902 | + [url_request_body 0] eq "payload text\n"} | |
| 903 | + | |
| 904 | +write_file empty.txt "" | |
| 905 | +url_httpmsg [list $urlOk] empty.txt | |
| 906 | +test_eq url-request-empty-payload [url_request_line 0] "GET /x HTTP/1.1" | |
| 907 | + | |
| 908 | +url_httpmsg [list $urlOk] payload.txt --mimetype application/x-test | |
| 909 | +test_eq url-request-mimetype [url_request_header 0 Content-Type] \ | |
| 910 | + application/x-test | |
| 911 | + | |
| 912 | +set urlPort [url_listen [list $urlOk]] | |
| 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} { | |
| 924 | + return [binary format I [string length $text]][zlib compress $text] | |
| 925 | +} | |
| 926 | +proc url_uncompress {bytes} { | |
| 927 | + if {[catch {zlib decompress [string range $bytes 4 end]} text]} { | |
| 928 | + return "(not compressed)" | |
| 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 | |
| 945 | +url_httpmsg [list $urlOk] --out out.txt | |
| 946 | +test url-request-out-option {$CODE == 0 && $RESULT eq "" && | |
| 947 | + [read_file out.txt] eq "ok"} | |
| 948 | +file delete out.txt | |
| 949 | +url_httpmsg [list $urlOk] payload.txt out.txt | |
| 950 | +test url-request-out-argument {$CODE == 0 && [read_file out.txt] eq "ok"} | |
| 951 | +file delete out.txt | |
| 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} { | |
| 965 | + url_httpmsg [list $urlOk] $urlOption | |
| 966 | + test url-request-option$urlOption {$CODE == 0 && $RESULT eq "ok"} | |
| 967 | +} | |
| 968 | +# --ipv6 asks for an IPv6 address of the test server, which listens on | |
| 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 | |
| 982 | +# sends the payload with the debug content type. | |
| 983 | +# | |
| 984 | +file mkdir trace | |
| 985 | +cd trace | |
| 986 | +url_httpmsg [list $urlOk] ../payload.txt --httptrace | |
| 987 | +test url-request-httptrace {$CODE == 0 && | |
| 988 | + [url_request_header 0 Content-Type] eq "text/plain" && | |
| 989 | + [string match "POST /x HTTP/1.1\r\n*\r\n\r\npayload text\n" \ | |
| 990 | + [read_file http-request-1.txt]] && | |
| 991 | + [string match "HTTP/1.1 200 OK\r\n*" [read_file http-reply-1.txt]]} | |
| 992 | +cd .. | |
| 993 | + | |
| 994 | +# --httptrace in a directory where the files cannot be made does not | |
| 995 | +# stop the exchange. | |
| 996 | +# | |
| 997 | +file mkdir readonly | |
| 998 | +file attributes readonly -permissions 0555 | |
| 999 | +if {$is_windows || [file writable readonly]} { | |
| 1000 | + test_skip_part "cannot make a directory that fossil cannot write in" | |
| 1001 | +} else { | |
| 1002 | + cd readonly | |
| 1003 | + url_httpmsg [list $urlOk] ../payload.txt --httptrace | |
| 1004 | + test url-request-httptrace-read-only { | |
| 1005 | + [string match "*\nok" $RESULT] && | |
| 1006 | + [url_request_body 0] eq "payload text\n" && | |
| 1007 | + [glob -nocomplain http-re*] eq ""} | |
| 1008 | + cd .. | |
| 1009 | +} | |
| 1010 | +file attributes readonly -permissions 0755 | |
| 1011 | + | |
| 1012 | +############################################################################### | |
| 1013 | +# The login card of a sync request. test-httpmsg --xfer sends the | |
| 1014 | +# payload as a sync message: with a login card when the URL names a | |
| 1015 | +# user, and expecting an application/x-fossil reply. The card is | |
| 1016 | +# | |
| 1017 | +# login USER NONCE SIGNATURE | |
| 1018 | +# | |
| 1019 | +# where NONCE is the SHA1 hash of the rest of the message and SIGNATURE | |
| 1020 | +# is the SHA1 hash of NONCE followed by the shared secret. test-httpmsg | |
| 1021 | +# opens no repository, so the shared secret is the password as given. | |
| 1022 | + | |
| 1023 | +# Returns the login card for USER with the shared secret SECRET, for a | |
| 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" && | |
| 1044 | + [url_request_body 0] eq $urlCard} | |
| 1045 | +url_xfer b%20ob:secret@ | |
| 1046 | +test_eq url-login-user-space [url_request_body 0] \ | |
| 1047 | + "[string map {{login b ob} {login b\sob}} \ | |
| 1048 | + [url_login_card "b ob" secret "payload text\n"]]\npayload text\n" | |
| 1049 | +url_xfer bob:@ | |
| 1050 | +test_eq url-login-empty-password [url_request_body 0] \ | |
| 1051 | + "[url_login_card bob "" "payload text\n"]\npayload text\n" | |
| 1052 | +url_xfer "" | |
| 1053 | +test url-login-no-user {$CODE == 0 && | |
| 1054 | + [url_request_body 0] eq "payload text\n"} | |
| 1055 | +url_xfer anonymous:secret@ | |
| 1056 | +test url-login-anonymous {$CODE == 0 && | |
| 1057 | + [url_request_body 0] eq "payload text\n"} | |
| 1058 | +url_xfer bob@ | |
| 1059 | +test url-login-no-password {$CODE == 1 && [url_request_line 0] eq "" && | |
| 1060 | + [string first {missing or incorrect password for user "bob"} $RESULT] >= 0} | |
| 1061 | +url_xfer bob:secret@ --httptrace | |
| 1062 | +test url-login-httptrace {$CODE == 0 && | |
| 1063 | + [url_request_header 0 Content-Type] eq "application/x-fossil-debug" && | |
| 1064 | + [url_request_body 0] eq $urlCard} | |
| 1065 | +file delete http-request-1.txt http-reply-1.txt | |
| 1066 | +url_xfer bob:secret@ --compress | |
| 1067 | +test url-login-compress {$CODE == 0 && | |
| 1068 | + [url_uncompress [url_request_body 0]] eq $urlCard} | |
| 1069 | + | |
| 1070 | +# A pull from an open check-out signs the card with the SHA1 hash of | |
| 1071 | +# PROJECTCODE/USER/PASSWORD. A password of 40 hex digits is that hash | |
| 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} { | |
| 1083 | + set body [url_request_body $number] | |
| 1084 | + set end [string first \n $body] | |
| 1085 | + set rest [string range $body [expr {$end + 1}] end] | |
| 1086 | + return [expr {[string range $body 0 [expr {$end - 1}]] eq | |
| 1087 | + [url_login_card $user $secret $rest]}] | |
| 1088 | +} | |
| 1089 | + | |
| 1090 | +# Runs "fossil pull" with --httptrace, which sends the request as plain | |
| 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]} | |
| 1102 | +url_pull bob:$urlSecret@ --once | |
| 1103 | +test url-login-password-is-hash {$CODE == 0 && | |
| 1104 | + [url_login_ok 0 bob $urlSecret]} | |
| 1105 | +set urlNotHex [string repeat g 40] | |
| 1106 | +url_pull bob:$urlNotHex@ --once | |
| 1107 | +test url-login-password-forty-letters {$CODE == 0 && | |
| 1108 | + [url_login_ok 0 bob [sha1_text $urlProject/bob/$urlNotHex]]} | |
| 1109 | +url_pull bob:[string range $urlSecret 1 end]@ --once | |
| 1110 | +test url-login-password-thirty-nine-digits {$CODE == 0 && [url_login_ok 0 bob \ | |
| 1111 | + [sha1_text $urlProject/bob/[string range $urlSecret 1 end]]]} | |
| 1112 | + | |
| 1113 | +# With --login-card-header the card goes in a cookie, not in the payload. | |
| 1114 | +# | |
| 1115 | +url_xfer bob:secret@ --login-card-header | |
| 1116 | +test url-login-cookie {$CODE == 0 && | |
| 1117 | + [url_request_body 0] eq "payload text\n" && | |
| 1118 | + [url_request_header 0 Cookie] eq "x-f-l-c=[string map {{ } +} \ | |
| 1119 | + [url_login_card bob secret "payload text\n"]]"} | |
| 1120 | +url_xfer "" --login-card-header | |
| 1121 | +test url-login-cookie-no-user {$CODE == 0 && | |
| 1122 | + [url_request_body 0] eq "payload text\n" && | |
| 1123 | + [url_request_header 0 Cookie] eq "(none)"} | |
| 1124 | +url_xfer bob:secret@ --login-card-header --httptrace | |
| 1125 | +test url-login-cookie-httptrace {$CODE == 0 && | |
| 1126 | + [url_request_body 0] eq "payload text\n" && | |
| 1127 | + [string match "x-f-l-c=login+bob+*" [url_request_header 0 Cookie]]} | |
| 1128 | +file delete http-request-1.txt http-reply-1.txt | |
| 1129 | +url_xfer bob:secret@ --login-card-header --compress | |
| 1130 | +test url-login-cookie-compress { | |
| 1131 | + [url_uncompress [url_request_body 0]] eq "payload text\n" && | |
| 1132 | + [string match "x-f-l-c=login+bob+*" [url_request_header 0 Cookie]]} | |
| 1133 | +set urlPort [url_listen [list $urlOk]] | |
| 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 | |
| 1154 | +test url-xfer-error-plain-text {$CODE == 1 && | |
| 1155 | + [string first "server sends error: plain text, no tags" $RESULT] >= 0} | |
| 1156 | +url_xfer_reply text/html "cut short <b" -v | |
| 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"} | |
| 1169 | +url_xfer_reply application/x-fossil [url_compress "compressed reply"] | |
| 1170 | +test url-xfer-reply-compressed {$CODE == 0 && $RESULT eq "compressed reply"} | |
| 1171 | +url_xfer_reply APPLICATION/X-FOSSIL-UNCOMPRESSED "plain reply" | |
| 1172 | +test url-xfer-reply-uncompressed {$CODE == 0 && $RESULT eq "plain reply"} | |
| 1173 | + | |
| 1174 | +############################################################################### | |
| 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 && | |
| 1187 | + [string first "cannot redirect from file://$urlRepo to " $RESULT] >= 0} | |
| 1188 | +fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath / | |
| 1189 | +test url-file-redirect-quiet {$CODE == 1 && $RESULT eq ""} | |
| 1190 | + | |
| 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. | |
| 1212 | +# | |
| 1213 | +url_sync pull http://example.invalid:81/repo [list $urlNotFound] --once \ | |
| 1214 | + --proxy http://pu:p%[email protected]:PORT | |
| 1215 | +test url-sync-proxy {$CODE == 1 && | |
| 1216 | + [string first "via proxy: http://[email protected]:" $RESULT] >= 0 && | |
| 1217 | + [url_request_line 0] eq "POST http://example.invalid:81/repo HTTP/1.1" && | |
| 1218 | + [url_request_header 0 Host] eq "example.invalid:81" && | |
| 1219 | + [url_request_header 0 Proxy-Authorization] eq | |
| 1220 | + "Basic [binary encode base64 pu:p@p]"} | |
| 1221 | +url_sync pull http://example.invalid/repo [list $urlNotFound] --once \ | |
| 1222 | + --proxy http://127.0.0.1:PORT | |
| 1223 | +test url-sync-proxy-no-user {$CODE == 1 && | |
| 1224 | + [url_request_line 0] eq "POST http://example.invalid/repo HTTP/1.1" && | |
| 1225 | + [url_request_header 0 Proxy-Authorization] eq "(none)"} | |
| 1226 | +url_sync pull http://example.invalid/repo [list $urlNotFound] --once \ | |
| 1227 | + --proxy http://[email protected]:PORT | |
| 1228 | +test url-sync-proxy-user-no-password {$CODE == 1 && | |
| 1229 | + [url_request_header 0 Proxy-Authorization] eq | |
| 1230 | + "Basic [binary encode base64 pu:]"} | |
| 1231 | + | |
| 1232 | +# A redirect received through a proxy is followed through the proxy. | |
| 1233 | +# | |
| 1234 | +url_sync pull http://example.invalid/repo [list \ | |
| 1235 | + [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/moved\n\n"] \ | |
| 1236 | + $urlNotFound] --once --proxy http://127.0.0.1:PORT | |
| 1237 | +test url-sync-proxy-redirect {[llength $urlRequests] == 2 && | |
| 1238 | + [string match "POST http://127.0.0.1:*/moved HTTP/1.1" \ | |
| 1239 | + [url_request_line 1]]} | |
| 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 | + | |
| 1251 | +# A pull through a proxy remembers the URL of the remote, not of the | |
| 1252 | +# proxy. A proxy is not used for a file: URL. | |
| 1253 | +# | |
| 1254 | +fossil remote off | |
| 1255 | +url_sync pull http://example.invalid/repo [list $urlPullOk] \ | |
| 1256 | + --proxy http://127.0.0.1:PORT | |
| 1257 | +fossil remote | |
| 1258 | +test_eq url-sync-proxy-remembered [string trim $RESULT] \ | |
| 1259 | + http://example.invalid/repo | |
| 1260 | +fossil remote off | |
| 1261 | +fossil_raw -seconds 60 pull file://[file join $urlDir holder FOSSIL] --once \ | |
| 1262 | + --proxy http://127.0.0.1:1 | |
| 1263 | +test url-sync-proxy-file-url {$CODE == 0 && | |
| 1264 | + [string first "via proxy" $RESULT] < 0} | |
| 1265 | + | |
| 1266 | +# --httpauth gives the user and password for HTTP Basic authorization. | |
| 1267 | +# They are not sent again after a 401 reply to them. | |
| 1268 | +# | |
| 1269 | +url_sync pull http://127.0.0.1:PORT/repo [list $urlNotFound] --once \ | |
| 1270 | + --httpauth hu:hp | |
| 1271 | +test_eq url-sync-httpauth [url_request_header 0 Authorization] \ | |
| 1272 | + "Basic [binary encode base64 hu:hp]" | |
| 1273 | +url_sync pull http://127.0.0.1:PORT/repo \ | |
| 1274 | + [list [url_crlf "HTTP/1.1 401 Unauthorized\n\n"]] --once --httpauth hu:hp | |
| 1275 | +test url-sync-httpauth-401 {$CODE == 1 && [llength $urlRequests] == 3 && | |
| 1276 | + [url_request_header 0 Authorization] eq | |
| 1277 | + "Basic [binary encode base64 hu:hp]" && | |
| 1278 | + [url_request_header 1 Authorization] eq "(none)" && | |
| 1279 | + [string first "server says: 401 Unauthorized" $RESULT] >= 0} | |
| 1280 | +url_sync pull http://127.0.0.1:PORT/repo [list \ | |
| 1281 | + [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/moved\n\n"] \ | |
| 1282 | + $urlNotFound] --once --httpauth hu:hp | |
| 1283 | +test url-sync-httpauth-redirect {[llength $urlRequests] == 2 && | |
| 1284 | + [url_request_line 1] eq "POST /moved HTTP/1.1" && | |
| 1285 | + [url_request_header 0 Authorization] eq | |
| 1286 | + "Basic [binary encode base64 hu:hp]" && | |
| 1287 | + [url_request_header 1 Authorization] eq "(none)"} | |
| 1288 | + | |
| 1289 | +# A pull that is redirected with 301 or 308 remembers the new URL. One | |
| 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 | +} | |
| 1301 | +fossil remote off | |
| 1302 | +set urlPort [url_sync pull http://127.0.0.1:PORT/old [list \ | |
| 1303 | + [url_crlf "HTTP/1.1 301 Moved\nLocation: http://127.0.0.1:PORT/new\n\n"] \ | |
| 1304 | + $urlNotFound] --once] | |
| 1305 | +fossil remote | |
| 1306 | +test_eq url-sync-redirect-301-once [string trim $RESULT] off | |
| 1307 | + | |
| 1308 | +# A pull that succeeds remembers the URL. It does not remember the | |
| 1309 | +# password when it cannot ask whether to. | |
| 1310 | +# | |
| 1311 | +fossil remote off | |
| 1312 | +set urlPort [url_pull bob:secret@] | |
| 1313 | +fossil remote | |
| 1314 | +test_eq url-sync-remembered-url [string trim $RESULT] \ | |
| 1315 | + http://[email protected]:$urlPort/repo | |
| 1316 | +url_parse_test url-sync-password-not-remembered default \ | |
| 1317 | + {--use-config --show-pw} {user bob passwd {} pwConfig last-sync-pw} | |
| 1318 | +fossil remote off | |
| 1319 | + | |
| 1320 | +# A pull from a saved remote sends the saved password, and saves it | |
| 1321 | +# again as its hash for this project. | |
| 1322 | +# | |
| 1323 | +fossil remote add saved http://bob:[email protected]:1/repo | |
| 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 | |
| 1335 | + | |
| 1336 | +# A pull from the parent project signs the login card with the project | |
| 1337 | +# code of the parent. | |
| 1338 | +# | |
| 1339 | +url_config parent-project-code 'parentcode' | |
| 1340 | +url_pull bob:secret@ --from-parent-project --once | |
| 1341 | +test url-sync-parent-login {$CODE == 0 && | |
| 1342 | + [url_login_ok 0 bob [sha1_text parentcode/bob/secret]]} | |
| 1343 | +fossil sql "DELETE FROM config WHERE name GLOB 'parent-project-*'" | |
| 1344 | + | |
| 1345 | +# A pull from the parent project by the name of a saved remote | |
| 1346 | +# remembers the URL and the password as those of the parent project. | |
| 1347 | +# | |
| 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 | |
| 1359 | +fossil remote delete saved | |
| 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} | |
| 1381 | +test url-sync-clone-httptrace-no-reply-message \ | |
| 1382 | + {[string first "server returned an error - clone aborted" $RESULT] >= 0} | |
| 1383 | +file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt] | |
| 1384 | + | |
| 1385 | +# --transport-command with --httptrace prints the command. A command | |
| 1386 | +# that fails, or writes no reply, is an error. | |
| 1387 | +# | |
| 1388 | +if {!$is_windows} { | |
| 1389 | + write_file transport-fail.sh "#!/bin/sh\nexit 3\n" | |
| 1390 | + file attributes transport-fail.sh -permissions 0755 | |
| 1391 | + fossil_raw pull http://u:p@h:81/x --once \ | |
| 1392 | + --transport-command [file join $urlDir transport-fail.sh] --httptrace | |
| 1393 | + test url-transport-fails {$CODE == 1 && | |
| 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 | +} | |
| 1405 | + | |
| 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 | +############################################################################### | |
| 1432 | +# Links that web pages build from their own query parameters. Each row | |
| 1433 | +# is a page and regular expressions for links that the page must have. | |
| 1434 | + | |
| 1435 | +file mkdir sub | |
| 1436 | +write_file sub/a.txt "one\n" | |
| 1437 | +write_file sub/doc.md "# title\n" | |
| 1438 | +fossil add sub | |
| 1439 | +fossil commit -m one --no-warnings | |
| 1440 | +write_file sub/a.txt "one\ntwo\n" | |
| 1441 | +fossil commit -m two --no-warnings | |
| 1442 | +write_file sub/a.txt "one\ntwo\nthree\n" | |
| 1443 | +fossil commit -m three --no-warnings | |
| 1444 | + | |
| 1445 | +foreach {urlName urlPage urlLinks} { | |
| 1446 | + dir /dir?name=sub&ci=tip | |
| 1447 | + {{href="/dir\?ci=tip"} {href="/dir\?ci=tip&name=sub&type=tree"}} | |
| 1448 | + dir-flat /tree?name=sub&ci=tip&type=flat | |
| 1449 | + {{href="/dir\?ci=tip&type=flat"} | |
| 1450 | + {href="/dir\?ci=tip&name=sub&type=tree"}} | |
| 1451 | + tree /tree?name=sub&ci=tip&type=tree | |
| 1452 | + {{ci=tip}} | |
| 1453 | + leaves-all /leaves?all&ng&brbg | |
| 1454 | + {{href="/leaves\?ng&brbg"} {href="/leaves\?ng&brbg&closed"}} | |
| 1455 | + leaves-closed /leaves?closed&nohidden&ubg | |
| 1456 | + {{href="/leaves\?nohidden&ubg"} | |
| 1457 | + {href="/leaves\?nohidden&ubg&all"}} | |
| 1458 | + leaves-open /leaves?onlyhidden | |
| 1459 | + {{href="/leaves\?onlyhidden&all"} | |
| 1460 | + {href="/leaves\?onlyhidden&closed"}} | |
| 1461 | + timeline /timeline?n=1 | |
| 1462 | + {{href="/timeline\?n=1&advm=1&udc=1"} | |
| 1463 | + {href="/timeline\?n=1&b=[0-9-]+\+[0-9:]+"}} | |
| 1464 | + timeline-after /timeline?n=1&a=2020-01-01 | |
| 1465 | + {{href="/timeline\?a=2020-01-01&n=1&advm=1&udc=1"} | |
| 1466 | + {href="/timeline\?a=[0-9-]+\+[0-9:]+&n=1"}} | |
| 1467 | + timeline-before-circa /timeline?n=1&b=2030-01-01&c=2026-01-01 | |
| 1468 | + {{href="/timeline\?b=2030-01-01&n=1&advm=1&udc=1"} | |
| 1469 | + {href="/timeline\?b=[0-9-]+\+[0-9:]+&n=1"}} | |
| 1470 | + timeline-after-before /timeline?n=1&a=2020-01-01&b=2030-01-01&c=2026-01-01 | |
| 1471 | + {{href="/timeline\?a=2020-01-01&b=2030-01-01&n=1&advm=1&udc=1"}} | |
| 1472 | + timeline-advanced /timeline?n=1&advm=1 | |
| 1473 | + {{href="/timeline\?advm=0&n=1&udc=1"}} | |
| 1474 | + timeline-month /timeline?ym=2026-11 | |
| 1475 | + {{href="/timeline\?ym=2026-11&advm=1&udc=1"}} | |
| 1476 | + file-markdown /file?name=sub/doc.md&ci=tip | |
| 1477 | + {{href="/file\?name=sub/doc.md&ci=tip&txt=1"}} | |
| 1478 | + file-markdown-text /file?name=sub/doc.md&ci=tip&txt=1 | |
| 1479 | + {{href="/file\?name=sub/doc.md&ci=tip"}} | |
| 1480 | + finfo /finfo?name=sub/a.txt&brbg&ubg&n=1 | |
| 1481 | + {{sub/a.txt}} | |
| 1482 | + annotate /annotate?filename=sub/a.txt&checkin=tip&limit=1 | |
| 1483 | + {{sub/a.txt}} | |
| 1484 | + annotate-no-limit /annotate?filename=sub/a.txt&checkin=tip | |
| 1485 | + {{sub/a.txt}} | |
| 1486 | +} { | |
| 1487 | + write_file page.txt "GET $urlPage HTTP/1.0\r\n\r\n" | |
| 1488 | + fossil_raw http --in page.txt --ipaddr 127.0.0.1 $urlRepo --localauth | |
| 1489 | + set urlMissing [list] | |
| 1490 | + if {[string first "HTTP/1.0 200 OK" $RESULT] != 0} { | |
| 1491 | + lappend urlMissing "status 200" | |
| 1492 | + } | |
| 1493 | + foreach urlLink $urlLinks { | |
| 1494 | + if {![regexp -- $urlLink $RESULT]} {lappend urlMissing $urlLink} | |
| 1495 | + } | |
| 1496 | + test_eq url-links-$urlName $urlMissing {} | |
| 1497 | +} | |
| 1498 | + | |
| 1499 | +############################################################################### | |
| 1500 | +# The ssh: transport. | |
| 1501 | + | |
| 1502 | +if {$is_windows} { | |
| 1503 | + test_skip_part "the stand-in for ssh is a shell script" | |
| 1504 | +} else { | |
| 1505 | + set urlSshDir [file join $urlDir ssh-standin] | |
| 1506 | + file mkdir $urlSshDir | |
| 1507 | + set urlSshStub [file join $urlSshDir ssh] | |
| 1508 | + write_file $urlSshStub {#!/bin/sh | |
| 1509 | +# Stands in for ssh. Appends each of its arguments to the file | |
| 1510 | +# $URL_SSH_DIR/args, on a line of its own inside <>. Run N prints the | |
| 1511 | +# file $URL_SSH_DIR/reply.N and then reads its input to the end. Where | |
| 1512 | +# there is no such file it exits with status 1 at once. | |
| 1513 | +for argument in "$@"; do | |
| 1514 | + printf '<%s>\n' "$argument" | |
| 1515 | +done >> "$URL_SSH_DIR/args" | |
| 1516 | +count=$(cat "$URL_SSH_DIR/count" 2>/dev/null || echo 0) | |
| 1517 | +count=$((count + 1)) | |
| 1518 | +echo $count > "$URL_SSH_DIR/count" | |
| 1519 | +if test -f "$URL_SSH_DIR/reply.$count"; then | |
| 1520 | + cat "$URL_SSH_DIR/reply.$count" | |
| 1521 | + cat > /dev/null | |
| 1522 | + exit 0 | |
| 1523 | +fi | |
| 1524 | +exit 1 | |
| 1525 | +} | |
| 1526 | + file attributes $urlSshStub -permissions 0755 | |
| 1527 | + set env(URL_SSH_DIR) $urlSshDir | |
| 1528 | + set urlSavedPath $env(PATH) | |
| 1529 | + set env(PATH) "$urlSshDir:$env(PATH)" | |
| 1530 | +} | |
| 1531 | + | |
| 1532 | +# The stand-in must be what "ssh" means from here on. If it is not, run | |
| 1533 | +# nothing that could start the real one. Tcl remembers where it last | |
| 1534 | +# found a program, so forget that first. | |
| 1535 | +unset -nocomplain ::auto_execs(ssh) | |
| 1536 | +if {!$is_windows && [lindex [auto_execok ssh] 0] ne $urlSshStub} { | |
| 1537 | + set env(PATH) $urlSavedPath | |
| 1538 | + test_skip_part "cannot put a stand-in for ssh first on the PATH" | |
| 1539 | +} elseif {!$is_windows} { | |
| 1540 | + | |
| 1541 | + # Runs fossil with the arguments ARGS. Run N of the stand-in prints | |
| 1542 | + # item N of REPLIES, where an empty item makes it exit at once. Sets | |
| 1543 | + # urlSshArgs to the arguments of each run. | |
| 1544 | + proc url_ssh {replies args} { | |
| 1545 | + global urlSshDir urlSshArgs | |
| 1546 | + file delete {*}[glob -nocomplain -directory $urlSshDir reply.* count args] | |
| 1547 | + set number 0 | |
| 1548 | + foreach reply $replies { | |
| 1549 | + incr number | |
| 1550 | + if {$reply ne ""} { | |
| 1551 | + write_file [file join $urlSshDir reply.$number] $reply | |
| 1552 | + } | |
| 1553 | + } | |
| 1554 | + fossil_raw -seconds 60 {*}$args | |
| 1555 | + set urlSshArgs "" | |
| 1556 | + if {[file exists [file join $urlSshDir args]]} { | |
| 1557 | + set urlSshArgs [read_file [file join $urlSshDir args]] | |
| 1558 | + } | |
| 1559 | + } | |
| 1560 | + # Returns how many times the stand-in ran in the last url_ssh. | |
| 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 | |
| 1572 | + test url-ssh-reply {$CODE == 0 && $RESULT eq "hello" && | |
| 1573 | + [url_ssh_runs] == 1 && | |
| 1574 | + [holds_strings $urlSshArgs \ | |
| 1575 | + [list "<-->\n<hh>\n<fossil>\n<test-http>\n<dir/r.fossil>"]]} | |
| 1576 | + url_ssh [list [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\n"]hello] \ | |
| 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} \ | |
| 1588 | + status-404 "Status: 404\n\n" {server says: 404} \ | |
| 1589 | + status-tab "Status:\t500\n\n" {server says: \n} \ | |
| 1590 | + status-no-code "Status: none\n\n" {Read: \[Status: none\]\s*$} \ | |
| 1591 | + status-301-no-location "Status: 301 Moved\nContent-Length: 0\n\n" \ | |
| 1592 | + {"location:" missing from 301 redirect reply} \ | |
| 1593 | + status-302 "Status: 302 Found\nLocation: http://127.0.0.1:1/x\n\n" \ | |
| 1594 | + {cannot redirect from ssh://hh/dir/r.fossil\?fossil=/opt/fossil to http://127.0.0.1:1/x} \ | |
| 1595 | + status-307 "Status: 307 Temporary\nLocation: http://127.0.0.1:1/x\n\n" \ | |
| 1596 | + {cannot redirect from ssh://hh/dir/r.fossil\?fossil=/opt/fossil to http://127.0.0.1:1/x} \ | |
| 1597 | + status-308 "Status: 308 Permanent\nLocation: http://127.0.0.1:1/x\n\n" \ | |
| 1598 | + {cannot redirect from ssh://hh/dir/r.fossil\?fossil=/opt/fossil to http://127.0.0.1:1/x} \ | |
| 1599 | + ] { | |
| 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} | |
| 1617 | + | |
| 1618 | + # When the server does not reply, fossil tries once more with a PATH= | |
| 1619 | + # argument before the name of the fossil program on the server. It | |
| 1620 | + # does not when the URL names that program. | |
| 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 \ | |
| 1635 | + --out out.txt | |
| 1636 | + test url-ssh-retry-fails {$CODE == 1 && [url_ssh_runs] == 2 && | |
| 1637 | + [string first "server did not reply: rerun with --sshtrace" \ | |
| 1638 | + $RESULT] >= 0} | |
| 1639 | + url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x | |
| 1640 | + test url-ssh-retry-fails-quiet {$CODE == 1 && [url_ssh_runs] == 2 && | |
| 1641 | + $RESULT eq ""} | |
| 1642 | + url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \ | |
| 1643 | + --out out.txt --sshtrace | |
| 1644 | + test url-ssh-retry-fails-sshtrace {$CODE == 1 && [url_ssh_runs] == 2 && | |
| 1645 | + [regexp -line {^server did not reply$} $RESULT]} | |
| 1646 | + url_ssh [list "" $urlSshOk] \ | |
| 1647 | + test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x \ | |
| 1648 | + --out out.txt | |
| 1649 | + test url-ssh-no-retry-with-fossil-parameter {$CODE == 1 && | |
| 1650 | + [url_ssh_runs] == 1 && [string first "server did not reply" $RESULT] >= 0} | |
| 1651 | + | |
| 1652 | + # A sync from an open check-out remembers that the host needed the | |
| 1653 | + # PATH= argument and uses it at once the next time. When that fails | |
| 1654 | + # and the attempt without it works, the host is forgotten again. | |
| 1655 | + # | |
| 1656 | + set urlSshPull [string map {"HTTP/1.1 200 OK" "Status: 200 OK"} $urlPullOk] | |
| 1657 | + fossil test-ssh-needs-path hh | |
| 1658 | + test_match url-ssh-path-unknown-host $RESULT {^hh +no$} | |
| 1659 | + url_ssh [list "" $urlSshPull] pull ssh://hh/dir/r.fossil --once | |
| 1660 | + test url-ssh-path-pull-retry {$CODE == 0 && [url_ssh_runs] == 2} | |
| 1661 | + fossil test-ssh-needs-path hh | |
| 1662 | + test_match url-ssh-path-remembered $RESULT {^hh +yes$} | |
| 1663 | + fossil test-ssh-needs-path | |
| 1664 | + test_match url-ssh-path-list $RESULT {^hh +yes$} | |
| 1665 | + url_ssh [list $urlSshPull] pull ssh://hh/dir/r.fossil --once | |
| 1666 | + test url-ssh-path-used {$CODE == 0 && [url_ssh_runs] == 1 && | |
| 1667 | + [regexp {<hh>\n<PATH=[^\n]*>\n<fossil>} $urlSshArgs]} | |
| 1668 | + url_ssh [list "" $urlSshPull] pull ssh://hh/dir/r.fossil --once | |
| 1669 | + test url-ssh-path-pull-retry-without {$CODE == 0 && [url_ssh_runs] == 2 && | |
| 1670 | + [string first "Retrying without the PATH= argument" $RESULT] >= 0} | |
| 1671 | + fossil test-ssh-needs-path hh | |
| 1672 | + test_match url-ssh-path-forgotten $RESULT {^hh +no$} | |
| 1673 | + fossil test-ssh-needs-path | |
| 1674 | + test_eq url-ssh-path-list-empty $RESULT "" | |
| 1675 | + url_ssh [list "" ""] pull ssh://hh/dir/r.fossil --once | |
| 1676 | + test url-ssh-path-pull-fails {$CODE == 1 && [url_ssh_runs] == 2} | |
| 1677 | + fossil test-ssh-needs-path hh | |
| 1678 | + test_match url-ssh-path-not-remembered-on-failure $RESULT {^hh +no$} | |
| 1679 | + | |
| 1680 | + # test-ssh-needs-path HOST BOOLEAN sets the answer for the host. | |
| 1681 | + # | |
| 1682 | + fossil test-ssh-needs-path other.example yes | |
| 1683 | + test_match url-ssh-path-set $RESULT {^other.example +yes$} | |
| 1684 | + fossil test-ssh-needs-path other.example | |
| 1685 | + test_match url-ssh-path-set-read $RESULT {^other.example +yes$} | |
| 1686 | + fossil test-ssh-needs-path other.example no | |
| 1687 | + test_match url-ssh-path-clear $RESULT {^other.example +no$} | |
| 1688 | + fossil test-ssh-needs-path other.example | |
| 1689 | + test_match url-ssh-path-clear-read $RESULT {^other.example +no$} | |
| 1690 | + | |
| 1691 | + # A proxy is not used for an ssh: URL, and a proxy that is an ssh: URL | |
| 1692 | + # does not make fossil run ssh. | |
| 1693 | + # | |
| 1694 | + url_ssh [list $urlSshPull] pull ssh://hh/dir/r.fossil --once \ | |
| 1695 | + --proxy http://127.0.0.1:1 | |
| 1696 | + test url-ssh-proxy-not-used {$CODE == 0 && [url_ssh_runs] == 1 && | |
| 1697 | + [string first "via proxy" $RESULT] < 0} | |
| 1698 | + url_ssh [list] pull http://example.invalid/repo --once --proxy ssh://hh/x | |
| 1699 | + test url-ssh-proxy-is-ssh-url {[url_ssh_runs] == 0} | |
| 1700 | + | |
| 1701 | + set env(PATH) $urlSavedPath | |
| 1702 | + unset env(URL_SSH_DIR) | |
| 1703 | +} | |
| 1704 | + | |
| 1705 | +############################################################################### | |
| 1706 | + | |
| 1707 | +url_listen_stop | |
| 1708 | +array set env [array get urlSavedEnv] | |
| 1709 | +test_cleanup |
| --- a/test/url.test | |
| +++ b/test/url.test | |
| @@ -0,0 +1,1709 @@ | |
| --- a/test/url.test | |
| +++ b/test/url.test | |
| @@ -0,0 +1,1709 @@ | |
| 1 | # |
| 2 | # URLs of remote repositories, and the HTTP exchange of the sync client. |
| 3 | # |
| 4 | # The first part gives URLs to "fossil test-urlparser" and |
| 5 | # "fossil test-url-basename" and checks each part of the result, and |
| 6 | # checks how a saved remote, the parent project and a proxy are read. |
| 7 | # |
| 8 | # The second part gives "fossil test-httpmsg", "fossil clone" and |
| 9 | # "fossil pull" a server made by this file, which answers each |
| 10 | # connection with a reply that the test wrote. A well-formed reply must |
| 11 | # be accepted. A malformed one must be refused with a message and exit |
| 12 | # status 1. |
| 13 | # |
| 14 | # The third part does the same over the ssh: transport. Nothing here |
| 15 | # connects to another machine: "ssh" is a script written by this file, |
| 16 | # which writes down its arguments and prints a reply that the test wrote. |
| 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 | } |
| 32 | |
| 33 | # fossil must not use a proxy from the environment of the test run. |
| 34 | foreach urlVar {http_proxy HTTP_PROXY https_proxy HTTPS_PROXY all_proxy |
| 35 | ALL_PROXY} { |
| 36 | if {[info exists env($urlVar)]} { |
| 37 | set urlSavedEnv($urlVar) $env($urlVar) |
| 38 | unset env($urlVar) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | test_setup |
| 43 | set urlRepo [file join [pwd] .rep.fossil] |
| 44 | set urlDir [pwd] |
| 45 | |
| 46 | ############################################################################### |
| 47 | # The parts of a URL. |
| 48 | |
| 49 | # Runs "fossil test-urlparser URL" with the options in ARGS and returns |
| 50 | # a dictionary of what it printed for the URL as given: the name after |
| 51 | # "g.url." and the value. url_full(g.url) is under the key "full". |
| 52 | # |
| 53 | proc url_parse {url args} { |
| 54 | fossil_raw test-urlparser $url --proxy off {*}$args |
| 55 | set fields [dict create] |
| 56 | foreach urlLine [split $::RESULT \n] { |
| 57 | if {[string match "\\*\\*\\*\\**" $urlLine]} break |
| 58 | if {[regexp {^g\.url\.(\w+) *= (.*)$} $urlLine -> key value]} { |
| 59 | dict set fields $key $value |
| 60 | } elseif {[regexp {^url_full\(g\.url\) = (.*)$} $urlLine -> value]} { |
| 61 | dict set fields full $value |
| 62 | } |
| 63 | } |
| 64 | return $fields |
| 65 | } |
| 66 | |
| 67 | # Test NAME passes when "fossil test-urlparser URL" with the options |
| 68 | # OPTIONS gives each part in EXPECTED the value that follows it there. |
| 69 | # |
| 70 | proc url_parse_test {name url options expected {constraints ""}} { |
| 71 | set fields [url_parse $url {*}$options] |
| 72 | set actual [list] |
| 73 | foreach {urlKey urlValue} $expected { |
| 74 | if {[dict exists $fields $urlKey]} { |
| 75 | lappend actual $urlKey [dict get $fields $urlKey] |
| 76 | } else { |
| 77 | lappend actual $urlKey (missing) |
| 78 | } |
| 79 | } |
| 80 | test_eq $name $actual [list {*}$expected] $constraints |
| 81 | } |
| 82 | |
| 83 | foreach {urlName urlText urlExpected} { |
| 84 | http-plain http://example.com |
| 85 | {isFile 0 isHttps 0 isSsh 0 protocol http name example.com port 80 |
| 86 | dfltPort 80 hostname example.com path {} user {} passwd {} |
| 87 | canonical http://example.com fossil {} flags 0x0000 |
| 88 | full http://example.com} |
| 89 | https-upper-case HTTPS://Example.COM:8443/a/b |
| 90 | {isHttps 1 protocol https name example.com port 8443 dfltPort 443 |
| 91 | hostname example.com:8443 path /a/b |
| 92 | canonical https://example.com:8443/a/b} |
| 93 | https-default-port-given https://h:443/x |
| 94 | {port 443 hostname h:443 canonical https://h/x} |
| 95 | http-port-zero http://h:0/x |
| 96 | {port 0 hostname h:0 canonical http://h:0/x} |
| 97 | http-port-largest http://h:65535 |
| 98 | {port 65535 hostname h:65535 path {} canonical http://h:65535} |
| 99 | http-port-then-query http://h:81?x=1 |
| 100 | {port 81 path {} canonical http://h:81} |
| 101 | http-port-then-fragment http://h:81#top |
| 102 | {port 81 path {} canonical http://h:81} |
| 103 | http-port-empty http://h:/x |
| 104 | {port 0 hostname h:0 path /x} |
| 105 | http-user-password http://u:p@h/x |
| 106 | {name h user u passwd p canonical http://u@h/x full http://u:p@h/x} |
| 107 | http-user-only http://u@h:81/x |
| 108 | {user u passwd {} canonical http://u@h:81/x full http://u@h:81/x} |
| 109 | http-user-empty-password http://u:@h/x |
| 110 | {user u passwd {} canonical http://u@h/x full http://u@h/x} |
| 111 | http-user-escapes http://a%40b:p%3Aq%2Fr@h/ |
| 112 | {user a@b passwd p:q/r canonical http://a%40b@h/ |
| 113 | full http://a%40b:p%3Aq%2Fr@h/} |
| 114 | http-user-bad-escape http://%@h/ |
| 115 | {user % canonical http://%25@h/} |
| 116 | http-password-colons http://u:p:q@h/ |
| 117 | {user u passwd p:q} |
| 118 | http-at-in-path http://h/a@b |
| 119 | {name h user {} path /a@b canonical http://h/a%40b} |
| 120 | http-at-in-query http://h?x=a@b |
| 121 | {name h user {} path {} canonical http://h} |
| 122 | http-at-in-fragment http://h#a@b |
| 123 | {name h user {} path {} canonical http://h} |
| 124 | http-fragment-dropped http://h/a/b#frag |
| 125 | {path /a/b canonical http://h/a/b} |
| 126 | http-query-dropped http://h/a?x=1&y=2 |
| 127 | {path /a canonical http://h/a fossil {}} |
| 128 | http-query-no-value http://h/a?x&y |
| 129 | {path /a canonical http://h/a fossil {}} |
| 130 | http-path-escapes {http://h/a%20b/c%2Bd} |
| 131 | {path {/a b/c+d} canonical http://h/a+b/c%2Bd} |
| 132 | http-path-bad-escape http://h/a%zz |
| 133 | {path /a%zz canonical http://h/a%25zz} |
| 134 | http-host-escape http://loc%61lhost/x |
| 135 | {name localhost} |
| 136 | http-host-upper-case http://LOCALHOST/X |
| 137 | {name localhost path /X} |
| 138 | http-ipv6 {http://[::1]/x} |
| 139 | {name ::1 port 80 hostname {[::1]} canonical {http://[::1]/x}} |
| 140 | http-ipv6-port {http://[2001:DB8::1]:8080/x} |
| 141 | {name 2001:db8::1 port 8080 hostname {[2001:db8::1]:8080} |
| 142 | canonical {http://[2001:db8::1]:8080/x}} |
| 143 | http-ipv6-user {http://u:p@[::1]:81/x} |
| 144 | {name ::1 user u full {http://u:p@[::1]:81/x}} |
| 145 | http-brackets-one-letter {http://[a]/x} |
| 146 | {name a hostname a} |
| 147 | http-bracket-not-closed {http://[ab/x} |
| 148 | {name {[ab} path /x} |
| 149 | http-user-empty http://@h/x |
| 150 | {user {} name h canonical http://@h/x full http://@h/x} |
| 151 | http-host-one-letter http://h |
| 152 | {name h hostname h} |
| 153 | ssh-plain ssh://h/dir/r.fossil |
| 154 | {isSsh 1 protocol ssh name h port 22 dfltPort 22 hostname h |
| 155 | path dir/r.fossil fossil fossil canonical ssh://h/dir/r.fossil |
| 156 | flags 0x0000} |
| 157 | ssh-upper-case-user-port SSH://U@H:2222/dir/r.fossil |
| 158 | {isSsh 1 name h user U port 2222 hostname h:2222 path dir/r.fossil |
| 159 | canonical ssh://U@h:2222/dir/r.fossil} |
| 160 | ssh-absolute-path ssh://h//abs/r.fossil |
| 161 | {path /abs/r.fossil canonical ssh://h//abs/r.fossil} |
| 162 | ssh-root-path ssh://h/ |
| 163 | {path / canonical ssh://h/} |
| 164 | ssh-fossil-parameter ssh://h/r.fossil?fossil=/opt/bin/fossil |
| 165 | {path r.fossil fossil /opt/bin/fossil |
| 166 | canonical ssh://h/r.fossil?fossil=/opt/bin/fossil flags 0x0400} |
| 167 | ssh-fossil-parameter-escaped ssh://h/r.fossil?fossil=/opt/my%20bin/fossil |
| 168 | {fossil {/opt/my bin/fossil} |
| 169 | canonical ssh://h/r.fossil?fossil=/opt/my+bin/fossil} |
| 170 | ssh-fossil-parameter-among-others ssh://h/r.fossil?a=b&fossil=/x/fossil&c |
| 171 | {path r.fossil fossil /x/fossil |
| 172 | canonical ssh://h/r.fossil?fossil=/x/fossil} |
| 173 | ssh-fossil-parameter-empty ssh://h/r.fossil?fossil= |
| 174 | {fossil {} flags 0x0400} |
| 175 | ssh-ipv6 {ssh://[::1]/r.fossil} |
| 176 | {name ::1 hostname ::1 canonical {ssh://[::1]/r.fossil}} |
| 177 | ssh-ipv6-port {ssh://[::1]:2222/r.fossil} |
| 178 | {name ::1 port 2222 hostname ::1:2222 |
| 179 | canonical {ssh://[::1]:2222/r.fossil}} |
| 180 | ssh-user-password ssh://u:p@h/r.fossil |
| 181 | {user u passwd p canonical ssh://u@h/r.fossil} |
| 182 | file-three-slashes file:///nosuchdir/r.fossil |
| 183 | {isFile 1 protocol file name /nosuchdir/r.fossil path {} |
| 184 | canonical file:///nosuchdir/r.fossil full file:///nosuchdir/r.fossil} |
| 185 | file-one-slash file:/nosuchdir/r.fossil |
| 186 | {isFile 1 name /nosuchdir/r.fossil} |
| 187 | file-upper-case FILE:///nosuchdir/r.fossil |
| 188 | {isFile 1 name /nosuchdir/r.fossil} |
| 189 | file-escaped-space file:///nosuchdir/my%20r.fossil |
| 190 | {isFile 1 name {/nosuchdir/my r.fossil} |
| 191 | canonical file:///nosuchdir/my+r.fossil} |
| 192 | } { |
| 193 | url_parse_test url-parse-$urlName $urlText {} $urlExpected |
| 194 | } |
| 195 | |
| 196 | # A file: URL with a relative name, the name of a repository file, and |
| 197 | # the name of a directory that holds a file named FOSSIL, are all the |
| 198 | # absolute name of the file. |
| 199 | # |
| 200 | file mkdir holder emptydir |
| 201 | file copy $urlRepo holder/FOSSIL |
| 202 | url_parse_test url-parse-file-relative file:.rep.fossil {} \ |
| 203 | [list isFile 1 name $urlRepo canonical file://$urlRepo] |
| 204 | url_parse_test url-parse-file-name .rep.fossil {} \ |
| 205 | [list isFile 1 protocol file name $urlRepo] |
| 206 | url_parse_test url-parse-directory holder {} \ |
| 207 | [list isFile 1 name [file join $urlDir holder FOSSIL]] |
| 208 | |
| 209 | # What is not a URL, a file or a directory with a repository is refused, |
| 210 | # and so is a port that is too large or is followed by other text. |
| 211 | # |
| 212 | foreach {urlName urlText urlMessage} { |
| 213 | no-scheme nosuchfile {unknown repository: nosuchfile} |
| 214 | empty {} {unknown repository: } |
| 215 | other-scheme ftp://h/x {unknown repository: ftp://h/x} |
| 216 | scheme-no-slashes http:h/x {unknown repository: http:h/x} |
| 217 | directory-empty emptydir {unknown repository: emptydir} |
| 218 | port-too-large http://h:65536/x {port number too large in url} |
| 219 | port-huge http://h:99999999999999999999/x |
| 220 | {port number too large in url} |
| 221 | port-negative http://h:-1/x {url missing '/' after port number} |
| 222 | port-letters http://h:80x/ {url missing '/' after port number} |
| 223 | port-ipv6-junk {http://[::1]:8x} {url missing '/' after port number} |
| 224 | } { |
| 225 | fossil_raw test-urlparser $urlText --proxy off |
| 226 | test url-parse-refused-$urlName \ |
| 227 | {$CODE == 1 && [string first $urlMessage $RESULT] >= 0} |
| 228 | } |
| 229 | |
| 230 | # An ssh: URL with a host and no path has an empty path, and fossil |
| 231 | # prints nothing but the parts of the URL. |
| 232 | # |
| 233 | foreach {urlName urlText urlExpected} { |
| 234 | host ssh://host |
| 235 | {isSsh 1 name host port 22 hostname host user {} path {} |
| 236 | canonical ssh://host} |
| 237 | user-host ssh://u@h |
| 238 | {isSsh 1 name h port 22 user u path {} canonical ssh://u@h} |
| 239 | host-port ssh://h:22 |
| 240 | {isSsh 1 name h port 22 hostname h:22 path {} canonical ssh://h} |
| 241 | user-host-port ssh://u@h:2222 |
| 242 | {isSsh 1 name h port 2222 path {} canonical ssh://u@h:2222} |
| 243 | scheme-only ssh:// |
| 244 | {isSsh 1 name {} path {} canonical ssh://} |
| 245 | } { |
| 246 | url_parse_test url-parse-ssh-no-path-$urlName $urlText {} $urlExpected |
| 247 | test url-parse-ssh-no-path-$urlName-output {$CODE == 0 && |
| 248 | [regexp -all -line {^(g\.url\.\w+ +|url_full\(g\.url\) )= } $RESULT] == |
| 249 | [llength [split [string trim $RESULT] \n]]} |
| 250 | } |
| 251 | |
| 252 | # The complete URL of an ssh: remote has the "/" between the host and |
| 253 | # the path. |
| 254 | # |
| 255 | url_parse_test url-parse-ssh-full ssh://u@h/dir/r.fossil {} \ |
| 256 | {full ssh://u@h/dir/r.fossil} |
| 257 | |
| 258 | # A second fossil= parameter is refused. |
| 259 | # |
| 260 | fossil_raw test-urlparser ssh://h/r.fossil?fossil=/a/fossil&fossil=/b/fossil \ |
| 261 | --proxy off |
| 262 | test url-parse-ssh-fossil-twice {$CODE == 1 && |
| 263 | [string match "*more than one fossil= query parameter*" $RESULT]} |
| 264 | |
| 265 | # A very long user name, password, host and path. The four together stay |
| 266 | # under the 128 KB that Linux allows for one argument. |
| 267 | # |
| 268 | set urlLong [string repeat a 30000] |
| 269 | url_parse_test url-parse-long http://$urlLong:$urlLong@$urlLong/$urlLong {} \ |
| 270 | [list user $urlLong passwd $urlLong name $urlLong path /$urlLong] |
| 271 | |
| 272 | # test-urlparser takes one or two arguments. |
| 273 | # |
| 274 | fossil_raw test-urlparser |
| 275 | test url-parse-usage-none {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]} |
| 276 | fossil_raw test-urlparser http://h/ extra more |
| 277 | test url-parse-usage-many {$CODE == 1 && [string match "*Usage:*URL*" $RESULT]} |
| 278 | url_parse_test url-parse-two-arguments http://h/x extra {name h path /x} |
| 279 | |
| 280 | ############################################################################### |
| 281 | # Flags of the parser: --remember, --prompt-pw. Standard input is not a |
| 282 | # terminal here, so fossil cannot ask for a password. |
| 283 | |
| 284 | url_parse_test url-flag-remember http://h/x --remember {flags 0x0002} |
| 285 | url_parse_test url-flag-remember-password http://u:p@h/x --remember \ |
| 286 | {user u passwd p flags 0x0006} |
| 287 | url_parse_test url-flag-remember-password-ssh ssh://u:p@h/x --remember \ |
| 288 | {user u passwd p flags 0x0002} |
| 289 | url_parse_test url-flag-prompt-has-password http://u:p@h/x --prompt-pw \ |
| 290 | {user u passwd p flags 0x0001} |
| 291 | url_parse_test url-flag-prompt-no-user http://h/x --prompt-pw \ |
| 292 | {user {} flags 0x0001} |
| 293 | url_parse_test url-flag-prompt-ssh ssh://u@h/x --prompt-pw \ |
| 294 | {user u passwd {} flags 0x0001} |
| 295 | url_parse_test url-flag-prompt-file file:///nosuchdir/x --prompt-pw \ |
| 296 | {isFile 1 flags 0x0001} |
| 297 | fossil_raw test-urlparser http://u@h/x --proxy off --prompt-pw |
| 298 | test url-flag-prompt-no-terminal {$CODE == 1 && [string first \ |
| 299 | {missing or incorrect password for user "u"} $RESULT] >= 0} |
| 300 | |
| 301 | ############################################################################### |
| 302 | # Saved remotes. --use-config reads the URL "default" from the |
| 303 | # last-sync-url setting and any other name from the remote of that name, |
| 304 | # with the saved password. --use-parent reads the parent project. |
| 305 | |
| 306 | proc url_config {name value} { |
| 307 | fossil sql "REPLACE INTO config(name,value,mtime) VALUES('$name',$value,0)" |
| 308 | } |
| 309 | |
| 310 | url_parse_test url-config-default-unset default --use-config \ |
| 311 | {protocol {} name {} canonical {} isFile 0} |
| 312 | url_parse_test url-config-parent-unset default --use-parent \ |
| 313 | {protocol {} name {} canonical {}} |
| 314 | url_config last-sync-url 'http://u@h/last' |
| 315 | url_config last-sync-pw obscure('lastpw') |
| 316 | url_parse_test url-config-default default --use-config \ |
| 317 | {name h user u passwd ************ pwConfig last-sync-pw |
| 318 | canonical http://u@h/last flags 0x0040} |
| 319 | url_parse_test url-config-default-show default {--use-config --show-pw} \ |
| 320 | {name h user u passwd lastpw pwConfig last-sync-pw} |
| 321 | url_parse_test url-config-parent-falls-back default --use-parent \ |
| 322 | {user u passwd ************ pwConfig last-sync-pw |
| 323 | canonical http://u@h/last flags 0x00c0} |
| 324 | url_config parent-project-url 'http://pu@ph/parent' |
| 325 | url_config parent-project-pw obscure('parentpw') |
| 326 | url_parse_test url-config-parent default {--use-parent --show-pw} \ |
| 327 | {name ph user pu passwd parentpw pwConfig parent-project-pw |
| 328 | canonical http://pu@ph/parent} |
| 329 | url_parse_test url-config-default-not-parent default {--use-config --show-pw} \ |
| 330 | {name h passwd lastpw} |
| 331 | |
| 332 | fossil remote add east http://eu:eastpw@eh:81/east |
| 333 | url_parse_test url-config-named east {--use-config --show-pw} \ |
| 334 | {name eh port 81 user eu passwd eastpw pwConfig sync-pw:east |
| 335 | canonical http://eu@eh:81/east flags 0x0048} |
| 336 | url_parse_test url-config-named-hidden east --use-config \ |
| 337 | {user eu passwd ************} |
| 338 | url_parse_test url-config-url-not-a-name http://x/y --use-config \ |
| 339 | {name x path /y pwConfig {} flags 0x0040} |
| 340 | fossil_raw test-urlparser nosuchremote --proxy off --use-config |
| 341 | test url-config-unknown-name {$CODE == 1 && |
| 342 | [string first "unknown repository: nosuchremote" $RESULT] >= 0} |
| 343 | url_parse_test url-config-name-without-flag east {} \ |
| 344 | {protocol (missing)} |
| 345 | test url-config-name-without-flag-refused {$CODE == 1 && |
| 346 | [string first "unknown repository: east" $RESULT] >= 0} |
| 347 | |
| 348 | # "fossil remote" saves the URL without the password. It does not save |
| 349 | # the password when it cannot ask whether to. |
| 350 | # |
| 351 | fossil remote http://ru:remotepw@rh/remote |
| 352 | fossil remote |
| 353 | test_eq url-remember-url [string trim $RESULT] http://ru@rh/remote |
| 354 | url_parse_test url-remember-no-password default {--use-config --show-pw} \ |
| 355 | {name rh user ru passwd {}} |
| 356 | |
| 357 | # "fossil remote hyperlink" prints the URL of the remote without the user. |
| 358 | # |
| 359 | fossil_raw remote hyperlink |
| 360 | test_match url-nouser-hyperlink $RESULT {^http://rh/remote/info/[0-9a-f]+\s*$} |
| 361 | fossil remote http://ru:remotepw@rh:8081/remote |
| 362 | fossil_raw remote hyperlink |
| 363 | test_match url-nouser-hyperlink-port $RESULT \ |
| 364 | {^http://rh:8081/remote/info/[0-9a-f]+\s*$} |
| 365 | fossil remote {http://ru:remotepw@[::1]/remote} |
| 366 | fossil_raw remote hyperlink |
| 367 | test_match url-nouser-hyperlink-ipv6 $RESULT \ |
| 368 | {^http://\[::1\]/remote/info/[0-9a-f]+\s*$} |
| 369 | fossil remote http://rh/remote |
| 370 | fossil_raw remote hyperlink |
| 371 | test_match url-nouser-hyperlink-no-user $RESULT \ |
| 372 | {^http://rh/remote/info/[0-9a-f]+\s*$} |
| 373 | url_config last-sync-url 'http://@rh/remote' |
| 374 | fossil_raw remote hyperlink |
| 375 | test_match url-nouser-hyperlink-empty-user $RESULT \ |
| 376 | {^http://@rh/remote/info/[0-9a-f]+\s*$} |
| 377 | fossil remote off |
| 378 | |
| 379 | # The SQL function url_nouser() gives a URL without its user and |
| 380 | # password, and NULL for NULL. |
| 381 | # |
| 382 | foreach {urlName urlSql urlExpected} { |
| 383 | http {url_nouser('http://u:p@h:81/x')} http://h:81/x |
| 384 | no-user {url_nouser('https://h/x')} https://h/x |
| 385 | ssh {url_nouser('ssh://u@h/dir/r.fossil')} ssh://h/dir/r.fossil |
| 386 | file {url_nouser('file:///nosuchdir/r')} file:///nosuchdir/r |
| 387 | null {coalesce(url_nouser(NULL),'null')} null |
| 388 | } { |
| 389 | fossil sql "SELECT $urlSql" |
| 390 | test_eq url-nouser-sql-$urlName [string trim $RESULT] $urlExpected |
| 391 | } |
| 392 | |
| 393 | # The /urllist page links each saved remote to its URL without the user. |
| 394 | # |
| 395 | write_file urllist.txt "GET /urllist HTTP/1.0\r\n\r\n" |
| 396 | fossil_raw http --in urllist.txt --ipaddr 127.0.0.1 $urlRepo --localauth |
| 397 | test url-nouser-urllist {[string first "HTTP/1.0 200 OK" $RESULT] == 0 && |
| 398 | [string first "<a href='http://eh:81/east'>http://eu@eh:81/east</a>" \ |
| 399 | $RESULT] >= 0} |
| 400 | |
| 401 | ############################################################################### |
| 402 | # A proxy. test-urlparser prints the URL again as it is used through |
| 403 | # the proxy from --proxy, the "proxy" setting or the http_proxy |
| 404 | # environment variable, after a line of stars. |
| 405 | |
| 406 | # Returns what test-urlparser printed after "Using proxy:", or "none" if |
| 407 | # it named no proxy. |
| 408 | proc url_proxy {url args} { |
| 409 | fossil_raw test-urlparser $url {*}$args |
| 410 | if {[regexp -line {^Using proxy: (.*)$} $::RESULT -> proxy]} { |
| 411 | return $proxy |
| 412 | } |
| 413 | return none |
| 414 | } |
| 415 | test_eq url-proxy-option [url_proxy http://h/x --proxy http://pu:pp@ph:3128] \ |
| 416 | http://pu@ph:3128 |
| 417 | test_eq url-proxy-off [url_proxy http://h/x --proxy off] none |
| 418 | test_eq url-proxy-empty [url_proxy http://h/x --proxy ""] none |
| 419 | test_eq url-proxy-none-set [url_proxy http://h/x] none |
| 420 | test_eq url-proxy-ssh-url [url_proxy ssh://h/x --proxy http://ph:3128] none |
| 421 | test_eq url-proxy-file-url \ |
| 422 | [url_proxy file:///nosuchdir/x --proxy http://ph:3128] none |
| 423 | set env(http_proxy) http://envproxy:3128 |
| 424 | test_eq url-proxy-environment [url_proxy http://h/x] http://envproxy:3128 |
| 425 | test_eq url-proxy-option-over-environment \ |
| 426 | [url_proxy http://h/x --proxy http://ph:3128] http://ph:3128 |
| 427 | fossil settings proxy http://setproxy:3128 |
| 428 | test_eq url-proxy-setting [url_proxy http://h/x] http://setproxy:3128 |
| 429 | fossil settings proxy off |
| 430 | test_eq url-proxy-setting-off [url_proxy http://h/x] none |
| 431 | fossil unset proxy |
| 432 | unset env(http_proxy) |
| 433 | fossil_raw test-urlparser http://h/x --proxy nosuchproxy |
| 434 | test url-proxy-not-a-url {$CODE == 1 && |
| 435 | [string first "unknown repository: nosuchproxy" $RESULT] >= 0} |
| 436 | |
| 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} { |
| 447 | path-tail http://h/a/b/repo repo |
| 448 | suffix-dropped http://h/a/repo.fossil repo |
| 449 | trailing-slash http://h/a/repo/ repo |
| 450 | query-dropped http://h/a/repo?x=/y repo |
| 451 | host-only http://example.com example |
| 452 | host-www http://www.example.com example |
| 453 | host-www-upper http://WWW.example.com example |
| 454 | host-www-suffix http://www.com www |
| 455 | host-port http://example.com:8080 example |
| 456 | host-www-port http://www.example.org:8080/ example |
| 457 | user-at-host ssh://u@host host |
| 458 | user-host-path ssh://u@host/dir/r.fossil r |
| 459 | no-separator nosuchthing {} |
| 460 | slash-only / {} |
| 461 | at-only @ {} |
| 462 | empty {} {} |
| 463 | dot-first http://h/.hidden {} |
| 464 | www-dot-only http://www. www |
| 465 | colon-in-tail host/a:b a |
| 466 | } { |
| 467 | fossil test-url-basename $urlText |
| 468 | test_eq url-basename-$urlName [string trim $RESULT] \ |
| 469 | [string trim "$urlText -> $urlExpected"] |
| 470 | } |
| 471 | fossil test-url-basename http://h/one http://h/two |
| 472 | test_eq url-basename-two [string trim $RESULT] \ |
| 473 | "http://h/one -> one\nhttp://h/two -> two" |
| 474 | fossil test-url-basename |
| 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] |
| 531 | } |
| 532 | |
| 533 | # Returns the request line of request NUMBER of the last exchange. |
| 534 | proc url_request_line {number} { |
| 535 | return [lindex [split [lindex $::urlRequests $number] \r] 0] |
| 536 | } |
| 537 | |
| 538 | # Returns the value of the header NAME in request NUMBER of the last |
| 539 | # exchange, or "(none)". |
| 540 | proc url_request_header {number name} { |
| 541 | if {[regexp -nocase -line "^$name: (\[^\r\]*)" \ |
| 542 | [lindex $::urlRequests $number] -> value]} { |
| 543 | return $value |
| 544 | } |
| 545 | return (none) |
| 546 | } |
| 547 | |
| 548 | # Returns the body of request NUMBER of the last exchange. |
| 549 | proc url_request_body {number} { |
| 550 | set request [lindex $::urlRequests $number] |
| 551 | return [string range $request [expr {[string first "\r\n\r\n" $request]+4}] \ |
| 552 | end] |
| 553 | } |
| 554 | |
| 555 | # Runs "fossil test-httpmsg" on the path /x of a server that answers |
| 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 | # |
| 567 | set urlBig [string repeat 0123456789 500] |
| 568 | foreach {urlName urlHeader urlBody urlExpected} [list \ |
| 569 | content-length "HTTP/1.1 200 OK\nContent-Length: 5\n\n" hello hello \ |
| 570 | content-length-zero "HTTP/1.1 200 OK\nContent-Length: 0\n\n" "" "" \ |
| 571 | content-length-spaces "HTTP/1.1 200 OK\nContent-Length: 5 \n\n" hello \ |
| 572 | hello \ |
| 573 | content-length-twice-same \ |
| 574 | "HTTP/1.1 200 OK\nContent-Length: 5\nContent-Length: 5\n\n" hello \ |
| 575 | hello \ |
| 576 | bytes-after-length "HTTP/1.1 200 OK\nContent-Length: 2\n\n" hello he \ |
| 577 | no-length "HTTP/1.1 200 OK\n\n" hello hello \ |
| 578 | no-length-large "HTTP/1.1 200 OK\n\n" $urlBig $urlBig \ |
| 579 | no-length-empty "HTTP/1.1 200 OK\n\n" "" "" \ |
| 580 | header-cut-short "HTTP/1.1 200 OK\nContent-Length: 0\n" "" "" \ |
| 581 | status-line-only "HTTP/1.1 200" "" "" \ |
| 582 | http-1.0 "HTTP/1.0 200 OK\nContent-Length: 5\n\n" hello hello \ |
| 583 | header-lower-case "HTTP/1.1 200 ok\ncontent-length: 5\n\n" hello hello \ |
| 584 | connection-close \ |
| 585 | "HTTP/1.1 200 OK\nConnection: close\nContent-Length: 5\n\n" hello \ |
| 586 | hello \ |
| 587 | connection-keep-alive \ |
| 588 | "HTTP/1.0 200 OK\nConnection: Keep-Alive\nContent-Length: 5\n\n" \ |
| 589 | hello hello \ |
| 590 | connection-other \ |
| 591 | "HTTP/1.1 200 OK\nConnection: upgrade\nContent-Length: 5\n\n" hello \ |
| 592 | hello \ |
| 593 | location-with-200 \ |
| 594 | "HTTP/1.1 200 OK\nLocation: http://127.0.0.1:1/\nContent-Length: 5\n\n" \ |
| 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 \ |
| 621 | chunked-hex-letters "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 622 | "a\r\n0123456789\r\n00\r\n\r\n" 0123456789 \ |
| 623 | chunked-extension "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 624 | "5;name=value\r\nhello\r\n0\r\n\r\n" hello \ |
| 625 | chunked-extension-spaces "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 626 | "5 \t; \tname\r\nhello\r\n0 \r\n\r\n" hello \ |
| 627 | chunked-extension-punctuation \ |
| 628 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 629 | "5;!x\r\nhello\r\n0\r\n\r\n" hello \ |
| 630 | chunked-trailer "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 631 | "5\r\nhello\r\n0\r\nTrailer: x\r\nOther: y\r\n\r\n" hello \ |
| 632 | chunked-trailer-cut-short "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 633 | "5\r\nhello\r\n0\r\nTrailer: x" hello \ |
| 634 | chunked-empty "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n" \ |
| 635 | "0\r\n\r\n" "" \ |
| 636 | ] { |
| 637 | url_httpmsg [list [url_crlf $urlHeader]$urlBody] |
| 638 | test url-http-accepted-$urlName {$CODE == 0 && $RESULT eq $urlExpected} |
| 639 | } |
| 640 | |
| 641 | # Replies that are refused. Each row is a name, the reply, and what |
| 642 | # "fossil test-httpmsg -v" must say. |
| 643 | # |
| 644 | foreach {urlName urlReply urlMessage} [list \ |
| 645 | nothing "" {server did not reply} \ |
| 646 | not-http "hello\r\n\r\n" {server did not reply} \ |
| 647 | status-bad-version "HTTP/1.x 200 OK\n\n" {Read: \[HTTP/1.x 200 OK\]\s*$} \ |
| 648 | status-no-code "HTTP/1.1\n\n" {Read: \[HTTP/1.1\]\s*$} \ |
| 649 | status-lower-case "http/1.1 200 OK\nContent-Length: 0\n\n" \ |
| 650 | {Read: \[http/1.1 200 OK\]\s*$} \ |
| 651 | status-500 "HTTP/1.1 500 Server Error\n\n" \ |
| 652 | {server says: 500 Server Error} \ |
| 653 | status-500-no-reason "HTTP/1.1 500\n\n" {server says: 500\n} \ |
| 654 | status-tab "HTTP/1.1\t500\n\n" {server says: \n} \ |
| 655 | status-404 "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n" \ |
| 656 | {server says: 404 Not Found} \ |
| 657 | status-negative "HTTP/1.1 -200 OK\n\n" {server says: -200 OK} \ |
| 658 | status-huge "HTTP/1.1 99999999999999999999 OK\n\n" {server says: } \ |
| 659 | status-204 "HTTP/1.1 204 No Content\n\n" {server says: 204 No Content} \ |
| 660 | folded-space "HTTP/1.1 200 OK\nX-A: b\n c\n\n" \ |
| 661 | {server sent a folded header line} \ |
| 662 | folded-tab "HTTP/1.1 200 OK\nX-A: b\n\tc\n\n" \ |
| 663 | {server sent a folded header line} \ |
| 664 | interim-only "HTTP/1.1 100 Continue\n\n" {server did not reply} \ |
| 665 | interim-cut-short "HTTP/1.1 100 Continue\nX-A: b\n" {server did not reply} \ |
| 666 | interim-five-blank-lines \ |
| 667 | "HTTP/1.1 100 Continue\n\n\n\n\n\n\nHTTP/1.1 200 OK\n\n" \ |
| 668 | {server did not reply} \ |
| 669 | content-length-none "HTTP/1.1 200 OK\nContent-Length:\n\n" \ |
| 670 | {server sent a bad content-length: Content-Length:} \ |
| 671 | content-length-negative "HTTP/1.1 200 OK\nContent-Length: -5\n\nhello" \ |
| 672 | {server sent a bad content-length} \ |
| 673 | content-length-plus "HTTP/1.1 200 OK\nContent-Length: +5\n\nhello" \ |
| 674 | {server sent a bad content-length} \ |
| 675 | content-length-hex "HTTP/1.1 200 OK\nContent-Length: 0x5\n\nhello" \ |
| 676 | {server sent a bad content-length} \ |
| 677 | content-length-two-numbers "HTTP/1.1 200 OK\nContent-Length: 5 5\n\nhello" \ |
| 678 | {server sent a bad content-length} \ |
| 679 | content-length-list "HTTP/1.1 200 OK\nContent-Length: 5,5\n\nhello" \ |
| 680 | {server sent a bad content-length} \ |
| 681 | content-length-2147483648 \ |
| 682 | "HTTP/1.1 200 OK\nContent-Length: 2147483648\n\nhello" \ |
| 683 | {server sent a bad content-length} \ |
| 684 | content-length-twice-different \ |
| 685 | "HTTP/1.1 200 OK\nContent-Length: 5\nContent-Length: 4\n\nhello" \ |
| 686 | {server sent two different content-length values} \ |
| 687 | content-length-zero-then-other \ |
| 688 | "HTTP/1.1 200 OK\nContent-Length: 0\nContent-Length: 5\n\nhello" \ |
| 689 | {server sent two different content-length values} \ |
| 690 | content-length-too-long "HTTP/1.1 200 OK\nContent-Length: 6\n\nhello" \ |
| 691 | {response truncated: got 5 bytes of 6} \ |
| 692 | transfer-encoding-gzip "HTTP/1.1 200 OK\nTransfer-Encoding: gzip\n\n" \ |
| 693 | {unsupported transfer-encoding: gzip} \ |
| 694 | transfer-encoding-gzip-chunked \ |
| 695 | "HTTP/1.1 200 OK\nTransfer-Encoding: gzip, chunked\n\n" \ |
| 696 | {unsupported transfer-encoding: gzip, chunked} \ |
| 697 | transfer-encoding-chunked-more \ |
| 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} \ |
| 715 | chunk-size-letters "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\nzz\n" \ |
| 716 | {chunked reply: missing or malformed chunk size} \ |
| 717 | chunk-size-negative \ |
| 718 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n-5\nhello\n0\n\n" \ |
| 719 | {chunked reply: missing or malformed chunk size} \ |
| 720 | chunk-size-0x \ |
| 721 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n0x5\nhello\n0\n\n" \ |
| 722 | {chunked reply: malformed chunk size line} \ |
| 723 | chunk-size-space-first \ |
| 724 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n 5\nhello\n0\n\n" \ |
| 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 \ |
| 736 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5;\nhello\n0\n\n" \ |
| 737 | {chunked reply: malformed chunk size line} \ |
| 738 | chunk-extension-equals \ |
| 739 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5; =v\nhello\n0\n\n" \ |
| 740 | {chunked reply: malformed chunk size line} \ |
| 741 | chunk-cut-short "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\nhel" \ |
| 742 | {chunked reply truncated} \ |
| 743 | chunk-no-data "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\n" \ |
| 744 | {chunked reply truncated} \ |
| 745 | chunk-too-long \ |
| 746 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n3\nhello\n0\n\n" \ |
| 747 | {chunked reply: no line end after chunk data} \ |
| 748 | chunk-no-line-end "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\nhello" \ |
| 749 | {chunked reply ended without terminator} \ |
| 750 | chunk-no-terminator \ |
| 751 | "HTTP/1.1 200 OK\nTransfer-Encoding: chunked\n\n5\nhello\n" \ |
| 752 | {chunked reply ended without terminator} \ |
| 753 | redirect-no-location "HTTP/1.1 302 Found\nContent-Length: 0\n\n" \ |
| 754 | {"location:" missing from 302 redirect reply} \ |
| 755 | redirect-301-no-location "HTTP/1.1 301 Moved\n\n" \ |
| 756 | {"location:" missing from 301 redirect reply} \ |
| 757 | redirect-307-no-location "HTTP/1.1 307 Temporary\n\n" \ |
| 758 | {"location:" missing from 307 redirect reply} \ |
| 759 | redirect-308-no-location "HTTP/1.1 308 Permanent\n\n" \ |
| 760 | {"location:" missing from 308 redirect reply} \ |
| 761 | redirect-empty-location "HTTP/1.1 302 Found\nLocation:\n\n" \ |
| 762 | {malformed redirect: Location:} \ |
| 763 | redirect-blank-location "HTTP/1.1 302 Found\nLocation: \n\n" \ |
| 764 | {malformed redirect: Location:} \ |
| 765 | redirect-to-file \ |
| 766 | "HTTP/1.1 302 Found\nLocation: file:///nosuchdir/r.fossil\n\n" \ |
| 767 | {cannot redirect to file:///nosuchdir/r.fossil} \ |
| 768 | redirect-to-ssh "HTTP/1.1 302 Found\nLocation: ssh://h/r.fossil\n\n" \ |
| 769 | {cannot redirect to ssh://h/r.fossil} \ |
| 770 | redirect-to-other-scheme "HTTP/1.1 302 Found\nLocation: ftp://h/x\n\n" \ |
| 771 | {unknown repository: ftp://h/x} \ |
| 772 | redirect-to-bad-port "HTTP/1.1 302 Found\nLocation: http://h:99999/\n\n" \ |
| 773 | {port number too large in url} \ |
| 774 | redirect-loop "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/x\n\n" \ |
| 775 | {redirect limit exceeded} \ |
| 776 | redirect-only-xfer "HTTP/1.1 302 Found\nLocation: /xfer\n\n" \ |
| 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. |
| 788 | # |
| 789 | url_httpmsg [list [url_crlf "HTTP/1.1 302 Found\nLocation: ssh://h\n\n"]] -v |
| 790 | test_match url-http-refused-redirect-to-ssh-no-path "$CODE $RESULT" \ |
| 791 | {^1 (?:.*\n)*.*cannot redirect to ssh://h} |
| 792 | |
| 793 | # A status line that test-httpmsg prints an error for without -v only |
| 794 | # when it is not told to be quiet: it is quiet when it prints the reply |
| 795 | # on standard output, and it is not when the reply goes to a file. |
| 796 | # |
| 797 | foreach {urlName urlReply urlMessage} [list \ |
| 798 | status-500 "HTTP/1.1 500 Server Error\n\n" {server says: 500 Server Error} \ |
| 799 | no-reply "" {server did not reply} \ |
| 800 | redirect-no-location "HTTP/1.1 302 Found\n\n" \ |
| 801 | {"location:" missing from 302 redirect reply} \ |
| 802 | redirect-loop "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/x\n\n" \ |
| 803 | {redirect limit exceeded} \ |
| 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 |
| 815 | # the bytes that came are printed. |
| 816 | # |
| 817 | set urlShort [url_crlf "HTTP/1.1 200 OK\nContent-Length: 6\n\nhello"] |
| 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. |
| 867 | # |
| 868 | url_httpmsg [list [url_crlf "HTTP/1.1 401 Unauthorized\n\n"]] -v |
| 869 | test url-http-401-three-requests {$CODE == 1 && [llength $urlRequests] == 3 && |
| 870 | [string first "server says: 401 Unauthorized" $RESULT] >= 0} |
| 871 | url_httpmsg [list [url_crlf "HTTP/1.1 401 Unauthorized\n\n"] \ |
| 872 | [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\nhello"]] |
| 873 | test url-http-401-then-200 {$CODE == 0 && $RESULT eq "hello" && |
| 874 | [llength $urlRequests] == 2} |
| 875 | |
| 876 | ############################################################################### |
| 877 | # The request. |
| 878 | |
| 879 | set urlOk [url_crlf "HTTP/1.1 200 OK\nContent-Length: 2\n\nok"] |
| 880 | |
| 881 | url_httpmsg [list $urlOk] |
| 882 | test url-request-get {[url_request_line 0] eq "GET /x HTTP/1.1" && |
| 883 | [string match 127.0.0.1:* [url_request_header 0 Host]] && |
| 884 | [url_request_header 0 Connection] eq "close" && |
| 885 | [string match "Fossil/*" [url_request_header 0 User-Agent]] && |
| 886 | [url_request_header 0 Content-Type] eq "(none)" && |
| 887 | [url_request_header 0 Content-Length] eq "(none)" && |
| 888 | [url_request_header 0 X-Fossil-Transport] eq "(none)" && |
| 889 | [url_request_header 0 Authorization] eq "(none)" && |
| 890 | [url_request_header 0 Proxy-Authorization] eq "(none)" && |
| 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" && |
| 902 | [url_request_body 0] eq "payload text\n"} |
| 903 | |
| 904 | write_file empty.txt "" |
| 905 | url_httpmsg [list $urlOk] empty.txt |
| 906 | test_eq url-request-empty-payload [url_request_line 0] "GET /x HTTP/1.1" |
| 907 | |
| 908 | url_httpmsg [list $urlOk] payload.txt --mimetype application/x-test |
| 909 | test_eq url-request-mimetype [url_request_header 0 Content-Type] \ |
| 910 | application/x-test |
| 911 | |
| 912 | set urlPort [url_listen [list $urlOk]] |
| 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} { |
| 924 | return [binary format I [string length $text]][zlib compress $text] |
| 925 | } |
| 926 | proc url_uncompress {bytes} { |
| 927 | if {[catch {zlib decompress [string range $bytes 4 end]} text]} { |
| 928 | return "(not compressed)" |
| 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 |
| 945 | url_httpmsg [list $urlOk] --out out.txt |
| 946 | test url-request-out-option {$CODE == 0 && $RESULT eq "" && |
| 947 | [read_file out.txt] eq "ok"} |
| 948 | file delete out.txt |
| 949 | url_httpmsg [list $urlOk] payload.txt out.txt |
| 950 | test url-request-out-argument {$CODE == 0 && [read_file out.txt] eq "ok"} |
| 951 | file delete out.txt |
| 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} { |
| 965 | url_httpmsg [list $urlOk] $urlOption |
| 966 | test url-request-option$urlOption {$CODE == 0 && $RESULT eq "ok"} |
| 967 | } |
| 968 | # --ipv6 asks for an IPv6 address of the test server, which listens on |
| 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 |
| 982 | # sends the payload with the debug content type. |
| 983 | # |
| 984 | file mkdir trace |
| 985 | cd trace |
| 986 | url_httpmsg [list $urlOk] ../payload.txt --httptrace |
| 987 | test url-request-httptrace {$CODE == 0 && |
| 988 | [url_request_header 0 Content-Type] eq "text/plain" && |
| 989 | [string match "POST /x HTTP/1.1\r\n*\r\n\r\npayload text\n" \ |
| 990 | [read_file http-request-1.txt]] && |
| 991 | [string match "HTTP/1.1 200 OK\r\n*" [read_file http-reply-1.txt]]} |
| 992 | cd .. |
| 993 | |
| 994 | # --httptrace in a directory where the files cannot be made does not |
| 995 | # stop the exchange. |
| 996 | # |
| 997 | file mkdir readonly |
| 998 | file attributes readonly -permissions 0555 |
| 999 | if {$is_windows || [file writable readonly]} { |
| 1000 | test_skip_part "cannot make a directory that fossil cannot write in" |
| 1001 | } else { |
| 1002 | cd readonly |
| 1003 | url_httpmsg [list $urlOk] ../payload.txt --httptrace |
| 1004 | test url-request-httptrace-read-only { |
| 1005 | [string match "*\nok" $RESULT] && |
| 1006 | [url_request_body 0] eq "payload text\n" && |
| 1007 | [glob -nocomplain http-re*] eq ""} |
| 1008 | cd .. |
| 1009 | } |
| 1010 | file attributes readonly -permissions 0755 |
| 1011 | |
| 1012 | ############################################################################### |
| 1013 | # The login card of a sync request. test-httpmsg --xfer sends the |
| 1014 | # payload as a sync message: with a login card when the URL names a |
| 1015 | # user, and expecting an application/x-fossil reply. The card is |
| 1016 | # |
| 1017 | # login USER NONCE SIGNATURE |
| 1018 | # |
| 1019 | # where NONCE is the SHA1 hash of the rest of the message and SIGNATURE |
| 1020 | # is the SHA1 hash of NONCE followed by the shared secret. test-httpmsg |
| 1021 | # opens no repository, so the shared secret is the password as given. |
| 1022 | |
| 1023 | # Returns the login card for USER with the shared secret SECRET, for a |
| 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" && |
| 1044 | [url_request_body 0] eq $urlCard} |
| 1045 | url_xfer b%20ob:secret@ |
| 1046 | test_eq url-login-user-space [url_request_body 0] \ |
| 1047 | "[string map {{login b ob} {login b\sob}} \ |
| 1048 | [url_login_card "b ob" secret "payload text\n"]]\npayload text\n" |
| 1049 | url_xfer bob:@ |
| 1050 | test_eq url-login-empty-password [url_request_body 0] \ |
| 1051 | "[url_login_card bob "" "payload text\n"]\npayload text\n" |
| 1052 | url_xfer "" |
| 1053 | test url-login-no-user {$CODE == 0 && |
| 1054 | [url_request_body 0] eq "payload text\n"} |
| 1055 | url_xfer anonymous:secret@ |
| 1056 | test url-login-anonymous {$CODE == 0 && |
| 1057 | [url_request_body 0] eq "payload text\n"} |
| 1058 | url_xfer bob@ |
| 1059 | test url-login-no-password {$CODE == 1 && [url_request_line 0] eq "" && |
| 1060 | [string first {missing or incorrect password for user "bob"} $RESULT] >= 0} |
| 1061 | url_xfer bob:secret@ --httptrace |
| 1062 | test url-login-httptrace {$CODE == 0 && |
| 1063 | [url_request_header 0 Content-Type] eq "application/x-fossil-debug" && |
| 1064 | [url_request_body 0] eq $urlCard} |
| 1065 | file delete http-request-1.txt http-reply-1.txt |
| 1066 | url_xfer bob:secret@ --compress |
| 1067 | test url-login-compress {$CODE == 0 && |
| 1068 | [url_uncompress [url_request_body 0]] eq $urlCard} |
| 1069 | |
| 1070 | # A pull from an open check-out signs the card with the SHA1 hash of |
| 1071 | # PROJECTCODE/USER/PASSWORD. A password of 40 hex digits is that hash |
| 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} { |
| 1083 | set body [url_request_body $number] |
| 1084 | set end [string first \n $body] |
| 1085 | set rest [string range $body [expr {$end + 1}] end] |
| 1086 | return [expr {[string range $body 0 [expr {$end - 1}]] eq |
| 1087 | [url_login_card $user $secret $rest]}] |
| 1088 | } |
| 1089 | |
| 1090 | # Runs "fossil pull" with --httptrace, which sends the request as plain |
| 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]} |
| 1102 | url_pull bob:$urlSecret@ --once |
| 1103 | test url-login-password-is-hash {$CODE == 0 && |
| 1104 | [url_login_ok 0 bob $urlSecret]} |
| 1105 | set urlNotHex [string repeat g 40] |
| 1106 | url_pull bob:$urlNotHex@ --once |
| 1107 | test url-login-password-forty-letters {$CODE == 0 && |
| 1108 | [url_login_ok 0 bob [sha1_text $urlProject/bob/$urlNotHex]]} |
| 1109 | url_pull bob:[string range $urlSecret 1 end]@ --once |
| 1110 | test url-login-password-thirty-nine-digits {$CODE == 0 && [url_login_ok 0 bob \ |
| 1111 | [sha1_text $urlProject/bob/[string range $urlSecret 1 end]]]} |
| 1112 | |
| 1113 | # With --login-card-header the card goes in a cookie, not in the payload. |
| 1114 | # |
| 1115 | url_xfer bob:secret@ --login-card-header |
| 1116 | test url-login-cookie {$CODE == 0 && |
| 1117 | [url_request_body 0] eq "payload text\n" && |
| 1118 | [url_request_header 0 Cookie] eq "x-f-l-c=[string map {{ } +} \ |
| 1119 | [url_login_card bob secret "payload text\n"]]"} |
| 1120 | url_xfer "" --login-card-header |
| 1121 | test url-login-cookie-no-user {$CODE == 0 && |
| 1122 | [url_request_body 0] eq "payload text\n" && |
| 1123 | [url_request_header 0 Cookie] eq "(none)"} |
| 1124 | url_xfer bob:secret@ --login-card-header --httptrace |
| 1125 | test url-login-cookie-httptrace {$CODE == 0 && |
| 1126 | [url_request_body 0] eq "payload text\n" && |
| 1127 | [string match "x-f-l-c=login+bob+*" [url_request_header 0 Cookie]]} |
| 1128 | file delete http-request-1.txt http-reply-1.txt |
| 1129 | url_xfer bob:secret@ --login-card-header --compress |
| 1130 | test url-login-cookie-compress { |
| 1131 | [url_uncompress [url_request_body 0]] eq "payload text\n" && |
| 1132 | [string match "x-f-l-c=login+bob+*" [url_request_header 0 Cookie]]} |
| 1133 | set urlPort [url_listen [list $urlOk]] |
| 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 |
| 1154 | test url-xfer-error-plain-text {$CODE == 1 && |
| 1155 | [string first "server sends error: plain text, no tags" $RESULT] >= 0} |
| 1156 | url_xfer_reply text/html "cut short <b" -v |
| 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"} |
| 1169 | url_xfer_reply application/x-fossil [url_compress "compressed reply"] |
| 1170 | test url-xfer-reply-compressed {$CODE == 0 && $RESULT eq "compressed reply"} |
| 1171 | url_xfer_reply APPLICATION/X-FOSSIL-UNCOMPRESSED "plain reply" |
| 1172 | test url-xfer-reply-uncompressed {$CODE == 0 && $RESULT eq "plain reply"} |
| 1173 | |
| 1174 | ############################################################################### |
| 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 && |
| 1187 | [string first "cannot redirect from file://$urlRepo to " $RESULT] >= 0} |
| 1188 | fossil_raw -seconds 60 test-httpmsg file://$urlRepo --subpath / |
| 1189 | test url-file-redirect-quiet {$CODE == 1 && $RESULT eq ""} |
| 1190 | |
| 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. |
| 1212 | # |
| 1213 | url_sync pull http://example.invalid:81/repo [list $urlNotFound] --once \ |
| 1214 | --proxy http://pu:p%[email protected]:PORT |
| 1215 | test url-sync-proxy {$CODE == 1 && |
| 1216 | [string first "via proxy: http://[email protected]:" $RESULT] >= 0 && |
| 1217 | [url_request_line 0] eq "POST http://example.invalid:81/repo HTTP/1.1" && |
| 1218 | [url_request_header 0 Host] eq "example.invalid:81" && |
| 1219 | [url_request_header 0 Proxy-Authorization] eq |
| 1220 | "Basic [binary encode base64 pu:p@p]"} |
| 1221 | url_sync pull http://example.invalid/repo [list $urlNotFound] --once \ |
| 1222 | --proxy http://127.0.0.1:PORT |
| 1223 | test url-sync-proxy-no-user {$CODE == 1 && |
| 1224 | [url_request_line 0] eq "POST http://example.invalid/repo HTTP/1.1" && |
| 1225 | [url_request_header 0 Proxy-Authorization] eq "(none)"} |
| 1226 | url_sync pull http://example.invalid/repo [list $urlNotFound] --once \ |
| 1227 | --proxy http://[email protected]:PORT |
| 1228 | test url-sync-proxy-user-no-password {$CODE == 1 && |
| 1229 | [url_request_header 0 Proxy-Authorization] eq |
| 1230 | "Basic [binary encode base64 pu:]"} |
| 1231 | |
| 1232 | # A redirect received through a proxy is followed through the proxy. |
| 1233 | # |
| 1234 | url_sync pull http://example.invalid/repo [list \ |
| 1235 | [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/moved\n\n"] \ |
| 1236 | $urlNotFound] --once --proxy http://127.0.0.1:PORT |
| 1237 | test url-sync-proxy-redirect {[llength $urlRequests] == 2 && |
| 1238 | [string match "POST http://127.0.0.1:*/moved HTTP/1.1" \ |
| 1239 | [url_request_line 1]]} |
| 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 | |
| 1251 | # A pull through a proxy remembers the URL of the remote, not of the |
| 1252 | # proxy. A proxy is not used for a file: URL. |
| 1253 | # |
| 1254 | fossil remote off |
| 1255 | url_sync pull http://example.invalid/repo [list $urlPullOk] \ |
| 1256 | --proxy http://127.0.0.1:PORT |
| 1257 | fossil remote |
| 1258 | test_eq url-sync-proxy-remembered [string trim $RESULT] \ |
| 1259 | http://example.invalid/repo |
| 1260 | fossil remote off |
| 1261 | fossil_raw -seconds 60 pull file://[file join $urlDir holder FOSSIL] --once \ |
| 1262 | --proxy http://127.0.0.1:1 |
| 1263 | test url-sync-proxy-file-url {$CODE == 0 && |
| 1264 | [string first "via proxy" $RESULT] < 0} |
| 1265 | |
| 1266 | # --httpauth gives the user and password for HTTP Basic authorization. |
| 1267 | # They are not sent again after a 401 reply to them. |
| 1268 | # |
| 1269 | url_sync pull http://127.0.0.1:PORT/repo [list $urlNotFound] --once \ |
| 1270 | --httpauth hu:hp |
| 1271 | test_eq url-sync-httpauth [url_request_header 0 Authorization] \ |
| 1272 | "Basic [binary encode base64 hu:hp]" |
| 1273 | url_sync pull http://127.0.0.1:PORT/repo \ |
| 1274 | [list [url_crlf "HTTP/1.1 401 Unauthorized\n\n"]] --once --httpauth hu:hp |
| 1275 | test url-sync-httpauth-401 {$CODE == 1 && [llength $urlRequests] == 3 && |
| 1276 | [url_request_header 0 Authorization] eq |
| 1277 | "Basic [binary encode base64 hu:hp]" && |
| 1278 | [url_request_header 1 Authorization] eq "(none)" && |
| 1279 | [string first "server says: 401 Unauthorized" $RESULT] >= 0} |
| 1280 | url_sync pull http://127.0.0.1:PORT/repo [list \ |
| 1281 | [url_crlf "HTTP/1.1 302 Found\nLocation: http://127.0.0.1:PORT/moved\n\n"] \ |
| 1282 | $urlNotFound] --once --httpauth hu:hp |
| 1283 | test url-sync-httpauth-redirect {[llength $urlRequests] == 2 && |
| 1284 | [url_request_line 1] eq "POST /moved HTTP/1.1" && |
| 1285 | [url_request_header 0 Authorization] eq |
| 1286 | "Basic [binary encode base64 hu:hp]" && |
| 1287 | [url_request_header 1 Authorization] eq "(none)"} |
| 1288 | |
| 1289 | # A pull that is redirected with 301 or 308 remembers the new URL. One |
| 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 | } |
| 1301 | fossil remote off |
| 1302 | set urlPort [url_sync pull http://127.0.0.1:PORT/old [list \ |
| 1303 | [url_crlf "HTTP/1.1 301 Moved\nLocation: http://127.0.0.1:PORT/new\n\n"] \ |
| 1304 | $urlNotFound] --once] |
| 1305 | fossil remote |
| 1306 | test_eq url-sync-redirect-301-once [string trim $RESULT] off |
| 1307 | |
| 1308 | # A pull that succeeds remembers the URL. It does not remember the |
| 1309 | # password when it cannot ask whether to. |
| 1310 | # |
| 1311 | fossil remote off |
| 1312 | set urlPort [url_pull bob:secret@] |
| 1313 | fossil remote |
| 1314 | test_eq url-sync-remembered-url [string trim $RESULT] \ |
| 1315 | http://[email protected]:$urlPort/repo |
| 1316 | url_parse_test url-sync-password-not-remembered default \ |
| 1317 | {--use-config --show-pw} {user bob passwd {} pwConfig last-sync-pw} |
| 1318 | fossil remote off |
| 1319 | |
| 1320 | # A pull from a saved remote sends the saved password, and saves it |
| 1321 | # again as its hash for this project. |
| 1322 | # |
| 1323 | fossil remote add saved http://bob:[email protected]:1/repo |
| 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 |
| 1335 | |
| 1336 | # A pull from the parent project signs the login card with the project |
| 1337 | # code of the parent. |
| 1338 | # |
| 1339 | url_config parent-project-code 'parentcode' |
| 1340 | url_pull bob:secret@ --from-parent-project --once |
| 1341 | test url-sync-parent-login {$CODE == 0 && |
| 1342 | [url_login_ok 0 bob [sha1_text parentcode/bob/secret]]} |
| 1343 | fossil sql "DELETE FROM config WHERE name GLOB 'parent-project-*'" |
| 1344 | |
| 1345 | # A pull from the parent project by the name of a saved remote |
| 1346 | # remembers the URL and the password as those of the parent project. |
| 1347 | # |
| 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 |
| 1359 | fossil remote delete saved |
| 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} |
| 1381 | test url-sync-clone-httptrace-no-reply-message \ |
| 1382 | {[string first "server returned an error - clone aborted" $RESULT] >= 0} |
| 1383 | file delete {*}[glob -nocomplain http-request-*.txt http-reply-*.txt] |
| 1384 | |
| 1385 | # --transport-command with --httptrace prints the command. A command |
| 1386 | # that fails, or writes no reply, is an error. |
| 1387 | # |
| 1388 | if {!$is_windows} { |
| 1389 | write_file transport-fail.sh "#!/bin/sh\nexit 3\n" |
| 1390 | file attributes transport-fail.sh -permissions 0755 |
| 1391 | fossil_raw pull http://u:p@h:81/x --once \ |
| 1392 | --transport-command [file join $urlDir transport-fail.sh] --httptrace |
| 1393 | test url-transport-fails {$CODE == 1 && |
| 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 | } |
| 1405 | |
| 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 | ############################################################################### |
| 1432 | # Links that web pages build from their own query parameters. Each row |
| 1433 | # is a page and regular expressions for links that the page must have. |
| 1434 | |
| 1435 | file mkdir sub |
| 1436 | write_file sub/a.txt "one\n" |
| 1437 | write_file sub/doc.md "# title\n" |
| 1438 | fossil add sub |
| 1439 | fossil commit -m one --no-warnings |
| 1440 | write_file sub/a.txt "one\ntwo\n" |
| 1441 | fossil commit -m two --no-warnings |
| 1442 | write_file sub/a.txt "one\ntwo\nthree\n" |
| 1443 | fossil commit -m three --no-warnings |
| 1444 | |
| 1445 | foreach {urlName urlPage urlLinks} { |
| 1446 | dir /dir?name=sub&ci=tip |
| 1447 | {{href="/dir\?ci=tip"} {href="/dir\?ci=tip&name=sub&type=tree"}} |
| 1448 | dir-flat /tree?name=sub&ci=tip&type=flat |
| 1449 | {{href="/dir\?ci=tip&type=flat"} |
| 1450 | {href="/dir\?ci=tip&name=sub&type=tree"}} |
| 1451 | tree /tree?name=sub&ci=tip&type=tree |
| 1452 | {{ci=tip}} |
| 1453 | leaves-all /leaves?all&ng&brbg |
| 1454 | {{href="/leaves\?ng&brbg"} {href="/leaves\?ng&brbg&closed"}} |
| 1455 | leaves-closed /leaves?closed&nohidden&ubg |
| 1456 | {{href="/leaves\?nohidden&ubg"} |
| 1457 | {href="/leaves\?nohidden&ubg&all"}} |
| 1458 | leaves-open /leaves?onlyhidden |
| 1459 | {{href="/leaves\?onlyhidden&all"} |
| 1460 | {href="/leaves\?onlyhidden&closed"}} |
| 1461 | timeline /timeline?n=1 |
| 1462 | {{href="/timeline\?n=1&advm=1&udc=1"} |
| 1463 | {href="/timeline\?n=1&b=[0-9-]+\+[0-9:]+"}} |
| 1464 | timeline-after /timeline?n=1&a=2020-01-01 |
| 1465 | {{href="/timeline\?a=2020-01-01&n=1&advm=1&udc=1"} |
| 1466 | {href="/timeline\?a=[0-9-]+\+[0-9:]+&n=1"}} |
| 1467 | timeline-before-circa /timeline?n=1&b=2030-01-01&c=2026-01-01 |
| 1468 | {{href="/timeline\?b=2030-01-01&n=1&advm=1&udc=1"} |
| 1469 | {href="/timeline\?b=[0-9-]+\+[0-9:]+&n=1"}} |
| 1470 | timeline-after-before /timeline?n=1&a=2020-01-01&b=2030-01-01&c=2026-01-01 |
| 1471 | {{href="/timeline\?a=2020-01-01&b=2030-01-01&n=1&advm=1&udc=1"}} |
| 1472 | timeline-advanced /timeline?n=1&advm=1 |
| 1473 | {{href="/timeline\?advm=0&n=1&udc=1"}} |
| 1474 | timeline-month /timeline?ym=2026-11 |
| 1475 | {{href="/timeline\?ym=2026-11&advm=1&udc=1"}} |
| 1476 | file-markdown /file?name=sub/doc.md&ci=tip |
| 1477 | {{href="/file\?name=sub/doc.md&ci=tip&txt=1"}} |
| 1478 | file-markdown-text /file?name=sub/doc.md&ci=tip&txt=1 |
| 1479 | {{href="/file\?name=sub/doc.md&ci=tip"}} |
| 1480 | finfo /finfo?name=sub/a.txt&brbg&ubg&n=1 |
| 1481 | {{sub/a.txt}} |
| 1482 | annotate /annotate?filename=sub/a.txt&checkin=tip&limit=1 |
| 1483 | {{sub/a.txt}} |
| 1484 | annotate-no-limit /annotate?filename=sub/a.txt&checkin=tip |
| 1485 | {{sub/a.txt}} |
| 1486 | } { |
| 1487 | write_file page.txt "GET $urlPage HTTP/1.0\r\n\r\n" |
| 1488 | fossil_raw http --in page.txt --ipaddr 127.0.0.1 $urlRepo --localauth |
| 1489 | set urlMissing [list] |
| 1490 | if {[string first "HTTP/1.0 200 OK" $RESULT] != 0} { |
| 1491 | lappend urlMissing "status 200" |
| 1492 | } |
| 1493 | foreach urlLink $urlLinks { |
| 1494 | if {![regexp -- $urlLink $RESULT]} {lappend urlMissing $urlLink} |
| 1495 | } |
| 1496 | test_eq url-links-$urlName $urlMissing {} |
| 1497 | } |
| 1498 | |
| 1499 | ############################################################################### |
| 1500 | # The ssh: transport. |
| 1501 | |
| 1502 | if {$is_windows} { |
| 1503 | test_skip_part "the stand-in for ssh is a shell script" |
| 1504 | } else { |
| 1505 | set urlSshDir [file join $urlDir ssh-standin] |
| 1506 | file mkdir $urlSshDir |
| 1507 | set urlSshStub [file join $urlSshDir ssh] |
| 1508 | write_file $urlSshStub {#!/bin/sh |
| 1509 | # Stands in for ssh. Appends each of its arguments to the file |
| 1510 | # $URL_SSH_DIR/args, on a line of its own inside <>. Run N prints the |
| 1511 | # file $URL_SSH_DIR/reply.N and then reads its input to the end. Where |
| 1512 | # there is no such file it exits with status 1 at once. |
| 1513 | for argument in "$@"; do |
| 1514 | printf '<%s>\n' "$argument" |
| 1515 | done >> "$URL_SSH_DIR/args" |
| 1516 | count=$(cat "$URL_SSH_DIR/count" 2>/dev/null || echo 0) |
| 1517 | count=$((count + 1)) |
| 1518 | echo $count > "$URL_SSH_DIR/count" |
| 1519 | if test -f "$URL_SSH_DIR/reply.$count"; then |
| 1520 | cat "$URL_SSH_DIR/reply.$count" |
| 1521 | cat > /dev/null |
| 1522 | exit 0 |
| 1523 | fi |
| 1524 | exit 1 |
| 1525 | } |
| 1526 | file attributes $urlSshStub -permissions 0755 |
| 1527 | set env(URL_SSH_DIR) $urlSshDir |
| 1528 | set urlSavedPath $env(PATH) |
| 1529 | set env(PATH) "$urlSshDir:$env(PATH)" |
| 1530 | } |
| 1531 | |
| 1532 | # The stand-in must be what "ssh" means from here on. If it is not, run |
| 1533 | # nothing that could start the real one. Tcl remembers where it last |
| 1534 | # found a program, so forget that first. |
| 1535 | unset -nocomplain ::auto_execs(ssh) |
| 1536 | if {!$is_windows && [lindex [auto_execok ssh] 0] ne $urlSshStub} { |
| 1537 | set env(PATH) $urlSavedPath |
| 1538 | test_skip_part "cannot put a stand-in for ssh first on the PATH" |
| 1539 | } elseif {!$is_windows} { |
| 1540 | |
| 1541 | # Runs fossil with the arguments ARGS. Run N of the stand-in prints |
| 1542 | # item N of REPLIES, where an empty item makes it exit at once. Sets |
| 1543 | # urlSshArgs to the arguments of each run. |
| 1544 | proc url_ssh {replies args} { |
| 1545 | global urlSshDir urlSshArgs |
| 1546 | file delete {*}[glob -nocomplain -directory $urlSshDir reply.* count args] |
| 1547 | set number 0 |
| 1548 | foreach reply $replies { |
| 1549 | incr number |
| 1550 | if {$reply ne ""} { |
| 1551 | write_file [file join $urlSshDir reply.$number] $reply |
| 1552 | } |
| 1553 | } |
| 1554 | fossil_raw -seconds 60 {*}$args |
| 1555 | set urlSshArgs "" |
| 1556 | if {[file exists [file join $urlSshDir args]]} { |
| 1557 | set urlSshArgs [read_file [file join $urlSshDir args]] |
| 1558 | } |
| 1559 | } |
| 1560 | # Returns how many times the stand-in ran in the last url_ssh. |
| 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 |
| 1572 | test url-ssh-reply {$CODE == 0 && $RESULT eq "hello" && |
| 1573 | [url_ssh_runs] == 1 && |
| 1574 | [holds_strings $urlSshArgs \ |
| 1575 | [list "<-->\n<hh>\n<fossil>\n<test-http>\n<dir/r.fossil>"]]} |
| 1576 | url_ssh [list [url_crlf "HTTP/1.1 200 OK\nContent-Length: 5\n\n"]hello] \ |
| 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} \ |
| 1588 | status-404 "Status: 404\n\n" {server says: 404} \ |
| 1589 | status-tab "Status:\t500\n\n" {server says: \n} \ |
| 1590 | status-no-code "Status: none\n\n" {Read: \[Status: none\]\s*$} \ |
| 1591 | status-301-no-location "Status: 301 Moved\nContent-Length: 0\n\n" \ |
| 1592 | {"location:" missing from 301 redirect reply} \ |
| 1593 | status-302 "Status: 302 Found\nLocation: http://127.0.0.1:1/x\n\n" \ |
| 1594 | {cannot redirect from ssh://hh/dir/r.fossil\?fossil=/opt/fossil to http://127.0.0.1:1/x} \ |
| 1595 | status-307 "Status: 307 Temporary\nLocation: http://127.0.0.1:1/x\n\n" \ |
| 1596 | {cannot redirect from ssh://hh/dir/r.fossil\?fossil=/opt/fossil to http://127.0.0.1:1/x} \ |
| 1597 | status-308 "Status: 308 Permanent\nLocation: http://127.0.0.1:1/x\n\n" \ |
| 1598 | {cannot redirect from ssh://hh/dir/r.fossil\?fossil=/opt/fossil to http://127.0.0.1:1/x} \ |
| 1599 | ] { |
| 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} |
| 1617 | |
| 1618 | # When the server does not reply, fossil tries once more with a PATH= |
| 1619 | # argument before the name of the fossil program on the server. It |
| 1620 | # does not when the URL names that program. |
| 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 \ |
| 1635 | --out out.txt |
| 1636 | test url-ssh-retry-fails {$CODE == 1 && [url_ssh_runs] == 2 && |
| 1637 | [string first "server did not reply: rerun with --sshtrace" \ |
| 1638 | $RESULT] >= 0} |
| 1639 | url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x |
| 1640 | test url-ssh-retry-fails-quiet {$CODE == 1 && [url_ssh_runs] == 2 && |
| 1641 | $RESULT eq ""} |
| 1642 | url_ssh [list "" ""] test-httpmsg ssh://hh/dir/r.fossil --subpath /x \ |
| 1643 | --out out.txt --sshtrace |
| 1644 | test url-ssh-retry-fails-sshtrace {$CODE == 1 && [url_ssh_runs] == 2 && |
| 1645 | [regexp -line {^server did not reply$} $RESULT]} |
| 1646 | url_ssh [list "" $urlSshOk] \ |
| 1647 | test-httpmsg ssh://hh/dir/r.fossil?fossil=/opt/fossil --subpath /x \ |
| 1648 | --out out.txt |
| 1649 | test url-ssh-no-retry-with-fossil-parameter {$CODE == 1 && |
| 1650 | [url_ssh_runs] == 1 && [string first "server did not reply" $RESULT] >= 0} |
| 1651 | |
| 1652 | # A sync from an open check-out remembers that the host needed the |
| 1653 | # PATH= argument and uses it at once the next time. When that fails |
| 1654 | # and the attempt without it works, the host is forgotten again. |
| 1655 | # |
| 1656 | set urlSshPull [string map {"HTTP/1.1 200 OK" "Status: 200 OK"} $urlPullOk] |
| 1657 | fossil test-ssh-needs-path hh |
| 1658 | test_match url-ssh-path-unknown-host $RESULT {^hh +no$} |
| 1659 | url_ssh [list "" $urlSshPull] pull ssh://hh/dir/r.fossil --once |
| 1660 | test url-ssh-path-pull-retry {$CODE == 0 && [url_ssh_runs] == 2} |
| 1661 | fossil test-ssh-needs-path hh |
| 1662 | test_match url-ssh-path-remembered $RESULT {^hh +yes$} |
| 1663 | fossil test-ssh-needs-path |
| 1664 | test_match url-ssh-path-list $RESULT {^hh +yes$} |
| 1665 | url_ssh [list $urlSshPull] pull ssh://hh/dir/r.fossil --once |
| 1666 | test url-ssh-path-used {$CODE == 0 && [url_ssh_runs] == 1 && |
| 1667 | [regexp {<hh>\n<PATH=[^\n]*>\n<fossil>} $urlSshArgs]} |
| 1668 | url_ssh [list "" $urlSshPull] pull ssh://hh/dir/r.fossil --once |
| 1669 | test url-ssh-path-pull-retry-without {$CODE == 0 && [url_ssh_runs] == 2 && |
| 1670 | [string first "Retrying without the PATH= argument" $RESULT] >= 0} |
| 1671 | fossil test-ssh-needs-path hh |
| 1672 | test_match url-ssh-path-forgotten $RESULT {^hh +no$} |
| 1673 | fossil test-ssh-needs-path |
| 1674 | test_eq url-ssh-path-list-empty $RESULT "" |
| 1675 | url_ssh [list "" ""] pull ssh://hh/dir/r.fossil --once |
| 1676 | test url-ssh-path-pull-fails {$CODE == 1 && [url_ssh_runs] == 2} |
| 1677 | fossil test-ssh-needs-path hh |
| 1678 | test_match url-ssh-path-not-remembered-on-failure $RESULT {^hh +no$} |
| 1679 | |
| 1680 | # test-ssh-needs-path HOST BOOLEAN sets the answer for the host. |
| 1681 | # |
| 1682 | fossil test-ssh-needs-path other.example yes |
| 1683 | test_match url-ssh-path-set $RESULT {^other.example +yes$} |
| 1684 | fossil test-ssh-needs-path other.example |
| 1685 | test_match url-ssh-path-set-read $RESULT {^other.example +yes$} |
| 1686 | fossil test-ssh-needs-path other.example no |
| 1687 | test_match url-ssh-path-clear $RESULT {^other.example +no$} |
| 1688 | fossil test-ssh-needs-path other.example |
| 1689 | test_match url-ssh-path-clear-read $RESULT {^other.example +no$} |
| 1690 | |
| 1691 | # A proxy is not used for an ssh: URL, and a proxy that is an ssh: URL |
| 1692 | # does not make fossil run ssh. |
| 1693 | # |
| 1694 | url_ssh [list $urlSshPull] pull ssh://hh/dir/r.fossil --once \ |
| 1695 | --proxy http://127.0.0.1:1 |
| 1696 | test url-ssh-proxy-not-used {$CODE == 0 && [url_ssh_runs] == 1 && |
| 1697 | [string first "via proxy" $RESULT] < 0} |
| 1698 | url_ssh [list] pull http://example.invalid/repo --once --proxy ssh://hh/x |
| 1699 | test url-ssh-proxy-is-ssh-url {[url_ssh_runs] == 0} |
| 1700 | |
| 1701 | set env(PATH) $urlSavedPath |
| 1702 | unset env(URL_SSH_DIR) |
| 1703 | } |
| 1704 | |
| 1705 | ############################################################################### |
| 1706 | |
| 1707 | url_listen_stop |
| 1708 | array set env [array get urlSavedEnv] |
| 1709 | test_cleanup |
+313
| --- a/test/xfer-client.test | ||
| +++ b/test/xfer-client.test | ||
| @@ -0,0 +1,313 @@ | ||
| 1 | +# | |
| 2 | +# Hand the client side of the sync protocol replies that a server would | |
| 3 | +# not normally give, and require that each is answered | |
| 4 | +# Replies that a ser# | |
| 5 | +# Replies are given aandin/transport.sh a, a script thIt saves each | |
| 6 | +# requesprepared by the test. When the prepared replies | |
| 7 | +# run out it answers with a bareest wrote,This complements xfer-card, which do the | |
| 8 | +# same for the server side through "fossil test-xfer". | |
| 9 | +# | |
| 10 | + | |
| 11 | +require_no_open_checkout | |
| 12 | + | |
| 13 | +if {$::tcl_platform(platform) eq "windows"} { | |
| 14 | + test_skip "the stand-in for a server is a shell script" | |
| 15 | +} | |
| 16 | + | |
| 17 | +test_setup | |
| 18 | + | |
| 19 | +write_file a.txt "hello world\n" | |
| 20 | +fossil add a.txt | |
| 21 | +fossil commit -mql "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\ | |
| 22 | + JOIN filename f USING(fnid) WHERE f.name='a.txt'" | |
| 23 | +set xferclientFileientFirst [string trim $RentFile [lindex $RESULT 0] | |
| 24 | +set xferclientAbsent [string repeat 0123456789abcdef 4] | |
| 25 | + | |
| 26 | +set xferclientDir [file join [pwd] xferclient-wire] | |
| 27 | +file mkdir $xfercl[file join $xferclientDir wire.sh] | |
| 28 | +write_file $xferclientWire {#!/bin/sh | |
| 29 | +# Called as: wire.sh URL REQUESTFILE REPLYFILE | |
| 30 | +n=`cat "$XFERCLIENT_DIR/count" 2>/dev/null || echo 0` | |
| 31 | +n=`expr $n + 1` | |
| 32 | +echo $n > "$XFERCLIENT_DIR/count" | |
| 33 | +cp "$2" "$XFERCLIENT_DIR/request.$n" | |
| 34 | +if test $n -gt 20; then exit 1; fi | |
| 35 | +if test -f "$XFERCLIENT_DIR/reply.$n"; then | |
| 36 | + cp "$XFERCLIENT_DIR/reply.$n" "$3" | |
| 37 | +else | |
| 38 | + printf '# timestamp %s errors 0\n' "`date -u +%Y-%m-%dT%H:%M:%S`" > "$3" | |
| 39 | +fi | |
| 40 | +} | |
| 41 | +file attributes on-while-coWire -permissioT_DIR) $xferclientDir | |
| 42 | + | |
| 43 | +# Run "fossil VERB" against the stand-in, which answers request N with | |
| 44 | +# item N of the list REPLIES. Further arguments are options for the | |
| 45 | +# command. Sets xferclientCode to the exit status, or to "crash", and | |
| 46 | +# xferclientOut to what fossil printed. | |
| 47 | +proc xferclient_sync {verb replies args} { | |
| 48 | + global xferclientDir xferclientWire xferclientCode xferclientOut | |
| 49 | + file delete {*}[glob -nocomplain -directory $xferclientDir \ | |
| 50 | + reply.* request.* count] | |
| 51 | + set number 0 | |
| 52 | + foreach reply $replies { | |
| 53 | + write_file [file join $xferclientDir reply.[incr number]] $reply | |
| 54 | + } | |
| 55 | + fossil_raw $verb http://localhost/x --once \ | |
| 56 | + --transport-command $xferclientWire {*}$args | |
| 57 | + set xferclientCode $::CODE | |
| 58 | + set xferclientOut $::RESULT | |
| 59 | +} | |
| 60 | + | |
| 61 | +proc xferclient_l script" | |
| 62 | +} | |
| 63 | + | |
| 64 | +test_setup | |
| 65 | + | |
| 66 | +write_file a.txt "hello world\n" | |
| 67 | +fossil add a.txt | |
| 68 | +fossil commit -m one --no-warnings | |
| 69 | +fossil sha3sum a.txt | |
| 70 | +set xferclientFile [lindex $RESULT 0] | |
| 71 | +set xferclientAbsent [string repeat 0123456789abcdef 4] | |
| 72 | + | |
| 73 | +set xferclientDir [file join [pwd] xferclient-wire] | |
| 74 | +file mkdir $xferclientDir | |
| 75 | +set xferclientWire \ | |
| 76 | + [test_standin transport.sh [file join $xferclientDir transport.sh]] | |
| 77 | +set ::env(TRANSPORT_DIR) $xferclientDir | |
| 78 | + | |
| 79 | +# Run "fossil VERB" against the stand-in, which answers request N with | |
| 80 | +# item N of the list REPLIES. Further arguments are options for the | |
| 81 | +# command. Sets xferclientCode to the exit status, or to "crash", and | |
| 82 | +# xferclientOut to what fossil printed. | |
| 83 | +proc xferclient_sync {verb replies args} { | |
| 84 | + global xferclientDir xferclientWire xferclientCode xferclientOut | |
| 85 | + file delete {*}[glob -nocomplain -directory $xferclientDir \ | |
| 86 | + reply.* request.* count] | |
| 87 | + set number 0 | |
| 88 | + foreach reply $replies { | |
| 89 | + write_file [file join $xferclientDir reply.[incr number]] $reply | |
| 90 | + } | |
| 91 | + fossil_raw $verb http://localhost/x --once \ | |
| 92 | + --transport-command $xferclientWire {*}$args | |
| 93 | + set xferclientCode $::CODE | |
| 94 | + set xferclientOut $::RESULT | |
| 95 | +} | |
| 96 | + | |
| 97 | +# Like xferclient_sync, for the server at URL. | |
| 98 | +proc xferclient_sync_url {verb url replies args} { | |
| 99 | + global xferclientDir xferclientWire xferclientCode xferclientOut | |
| 100 | + file delete {*}[glob -nocomplain -directory $xferclientDir \ | |
| 101 | + reply.* request.* count] | |
| 102 | + set number 0 | |
| 103 | + foreach reply $replies { | |
| 104 | + write_file [file join $xferclientDir reply.[incr number]] $reply | |
| 105 | + } | |
| 106 | + fossil_raw $verb $url --once --transport-command $xferclientWire {*}$args | |
| 107 | + set xferclientCode $::CODE | |
| 108 | + set xferclientOut $::RESULT | |
| 109 | +} | |
| 110 | + | |
| 111 | +proc xferclient_run {verb reply args} { | |
| 112 | + xferclient_sync $verb [list $reply] {*}$args | |
| 113 | +} | |
| 114 | + | |
| 115 | +# Returns request NUMBER of the last run, or an empty string if fossil | |
| 116 | +# made fewer requests. | |
| 117 | +proc xferclient_request {number} { | |
| 118 | + set file [file join $::xferclientDir request.$number] | |
| 119 | + if {![file exists $file]} { | |
| 120 | + return "" | |
| 121 | + } | |
| 122 | + return [read_file $file] | |
| 123 | +} | |
| 124 | + | |
| 125 | +proc xferclient_requests {} { | |
| 126 | + return [llength [glob -nocomplain -dir######################## | |
| 127 | +# igot and gimme. What the client asks for, or sends, shows in its | |
| 128 | +# second request. | |
| 129 | + | |
| 130 | +xferclient_run pull "igot $xferclientAbsent\n" | |
| 131 | +test xfer-client-igot-asks-for-it \ | |
| 132 | + {$xferclientCode == 0 | |
| 133 | + && [string first "gimme $xferclientAbsent" [xferclient_request 2]] >= 0} | |
| 134 | +# A hash that the client hears of only as private, or only in a push. | |
| 135 | +set xferclientPrivate [string repeat fedcba9876543210 4] | |
| 136 | +xferclient_run pull "igot $xferclientPrivate 1\n" | |
| 137 | +test xfer-client-igot-private-not-asked-for \ | |
| 138 | + {$xferclientCode == 0 | |
| 139 | + && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0} | |
| 140 | +xferclient_run pull "igot $xferclientFile\n" | |
| 141 | +test xfer-client-igot-held-not-asked-for \ | |
| 142 | + {$xferclientCode == 0 | |
| 143 | + && [string first "gimme $xferclientFile" [xferclient_request 2]] < 0} | |
| 144 | +xferclient_run push "igot $xferclientPrivate\n" | |
| 145 | +test xfer-client-igot-on-push-not-asked-for \ | |
| 146 | + {$xferclientCode == 0 | |
| 147 | + && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0} | |
| 148 | +xferclient_expect igot-not-a-hash pull "igot nothash\n" 1 {} "unknown command" | |
| 149 | +xferclient_expect igot-alone pull "igot\n" 1 {} "unknown command" | |
| 150 | + | |
| 151 | +xferclient_run push "gimme $xferclientFile\n" | |
| 152 | +test xfer-client-gimme-sends-it \ | |
| 153 | + {$xferclientCode == 0 | |
| 154 | + && [string first "file $xferclientFile" [xferclient_request 2]] >= 0} | |
| 155 | +xferclient_run pull "gimme $xferclientFile\n" | |
| 156 | +test xfer-client-gimme-on-pull-sends-nothing \ | |
| 157 | + {$xferclientCode == 0 | |
| 158 | + && [string first "file $xferclientFile" [xferclient_request 2]] < 0} | |
| 159 | +xferclient_expect gimme-absent push "gimme $xferclientAbsent\n" 0 {} | |
| 160 | +xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \ | |
| 161 | + "unknown command" | |
| 162 | + | |
| 163 | +############################################################################### | |
| 164 | +# An igot card can say that an artifact is private. The client marks its | |
| 165 | +# own copy private only i. It-igot-asks-for-it \ | |
| 166 | + {$xferould previouslyks-for-it \ | |
| 167 | + {$xferclientCod, after | |
| 168 | +# which tte and then bare timestamps. | |
| 169 | + | |
| 170 | +fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT min(objid) FROM event | |
| 171 | + WHERE type='ci')" | |
| 172 | +set xferclientFirst [string trim $RESULT] | |
| 173 | +fossil artifact $xferclientFirst first-manifest.out | |
| 174 | +set xferclientManifest [read_file first-manifest.out] | |
| 175 | +set xferclientPush "push $xferclientOwnCode $xferclientOwnCode\n" | |
| 176 | + | |
| 177 | +# Clone into clone.fossil from a server that gives the replies REPLIES. | |
| 178 | +# Sets xferclientCode and xferclientOut as xferclient_sync does. | |
| 179 | +proc xferclient_clone {replies} { | |
| 180 | + global xferclientDir xferclientWire xferclientCode xferclientOut | |
| 181 | + file delete clone.fossil | |
| 182 | + file delete {*}[glob -nocomplain -directory $xferclientDir \ | |
| 183 | + reply.* request.* count] | |
| 184 | + set number 0 | |
| 185 | + foreach reply $replies { | |
| 186 | + write_file [file join $xferclientDir reply.[incr number]] $reply | |
| 187 | + } | |
| 188 | + fossil_raw clone http://localhost/x clone.fossil --no-open \ | |
| 189 | + --transport-command $xferclientWire | |
| 190 | + set xferclientCode $::CODE | |
| 191 | + set xferclientOut $::RESULT | |
| 192 | +} | |
| 193 | + | |
| 194 | +# The number of the artifacts HASHES that clone.fossil holds. | |
| 195 | +proc xferclient_clone_holds {hashes} { | |
| 196 | + fossil sql -R clone.fossil "SELECT count(*) FROM blob WHERE size>=0 | |
| 197 | + AND uuid IN ('[join $hashes ',']')" | |
| 198 | + return [string trim $::RESULT] | |
| 199 | +} | |
| 200 | + | |
| 201 | +# A server of the first version of the protocol lists what it has in | |
| 202 | +# "igot" cards and sends each artifact, in a "file" card, when it is asked | |
| 203 | +# for it. The clone asks in every round and never asks for clusters. | |
| 204 | +xferclient_clone [list \ | |
| 205 | + "${xferclientPush}igot $xferclientFirst\nigot $xferclientFile\n" \ | |
| 206 | + "file $xferclientFirst [string length $xferclientManifest]\n\ | |
| 207 | +$xferclientManifest" \ | |
| 208 | + "file $xferclientFile 12\nhello world\n"] | |
| 209 | +test xfer-client-mcdc-clone-by-igot {$xferclientCode == 0 | |
| 210 | + && [xferclient_requests] == 4 | |
| 211 | + && [string first "gimme $xferclientFirst" [xferclient_request 2]] >= 0 | |
| 212 | + && [string first "gimme $xferclientFile" [xferclient_request 3]] >= 0 | |
| 213 | + && [string first "pragma req-clusters" [xferclient_request 3]] < 0} | |
| 214 | +test_eq xfer-client-mcdc-clone-by-igot-holds \ | |
| 215 | + [xferclient_clone_holds [list $xferclientFirst $xferclientFile]] 2 | |
| 216 | +fossil sql -R clone.fossil "SELECT value FROM config WHERE name='project-code'" | |
| 217 | +test_eq xfer-client-mcdc-clone-project-code [string trim $RESULT] \ | |
| 218 | + $xferclientOwnCode | |
| 219 | + | |
| 220 | +# The card that gives a clone its project code has three words, the third | |
| 221 | +# a hash. Any other card that begins with "push" ends the clone with an | |
| 222 | +# error and leaves no repository. | |
| 223 | +foreach {xferclientName xferclientCard} [list \ | |
| 224 | + two-words "push $xferclientOwnCode\n" \ | |
| 225 | + not-a-hash "push $xferclientOwnCode nothash\n" \ | |
| 226 | +] { | |
| 227 | + xferclient_clone [list $xferclientCard] | |
| 228 | + test xfer-client-mcdc-clone-push-$xferclientName {$xferclientCode == 1 | |
| 229 | + && [string first "unknown command" $xferclientOut] >= 0 | |
| 230 | + && ![file exists clone.fossil]} | |
| 231 | +} | |
| 232 | + | |
| 233 | +# An error in the first reply ends the clone, unless it says that the | |
| 234 | +# login failed or that the client is not authorized: the first request of | |
| 235 | +# a clone has no login card, so those are expected and the clone goes on. | |
| 236 | +foreach {xferclientName xferclientError xferclientGoesOn} { | |
| 237 | + other-error {something\sfailed} 0 | |
| 238 | + login-failed {login\sfailed} 1 | |
| 239 | + not-authorized {not\sauthorized\sto\sclone} 1 | |
| 240 | +} { | |
| 241 | + xferclient_clone [list "${xferclientPush}error $xferclientError\n"] | |
| 242 | + test xfer-client-mcdc-clone-first-error-$xferclientName { | |
| 243 | + $xferclientGoesOn | |
| 244 | + ? ($xferclientCode == 0 && [xferclient_requests] == 2 | |
| 245 | + && [file exists clone.fossil]) | |
| 246 | + : ($xferclientCode == 1 | |
| 247 | + && [string first "Error: something failed" $xferclientOut] >= 0 | |
| 248 | + && ![file exists clone.fossil])} | |
| 249 | +} | |
| 250 | + | |
| 251 | +# A clone goes on asking while the server says that it has more to send | |
| 252 | +# and something arrives, here an unversioned file. It stops after a reply | |
| 253 | +# in which nothing arrives. | |
| 254 | +xferclient_clone [list "clone_seqno 2\n$xferclientPush" \ | |
| 255 | + "[xferclient_uvfile cloned.txt]clone_seqno 3\n$xferclientPush" \ | |
| 256 | + "clone_seqno 4\n$xferclientPush"] | |
| 257 | +test xfer-client-mcdc-clone-goes-on-while-content-arrives \ | |
| 258 | + {$xferclientCode == 0 && [xferclient_requests] == 3 | |
| 259 | + && [string first "clone 3 3" [xferclient_request 3]] >= 0} | |
| 260 | +fossil unversioned cat cloned.txt -R clone.fossil | |
| 261 | +test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc | |
| 262 | +xferclient_clone [list "clone_seqno 2\n$xferclientPush" \ | |
| 263 | + "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"] | |
| 264 | +test xfer-client-mcdc-clone-stops-when-nothing-arrives \ | |
| 265 | + {$xferclientCode == 0 && [xferclient_requests] == 2} | |
| 266 | +file delete clone.fossil | |
| 267 | + | |
| 268 | +############################################################################### | |
| 269 | +# What a sync with -v says at its end about the server. A server that | |
| 270 | +# could not be reached is named as the URL names it, with no address. The | |
| 271 | +# URLs here have no host; the one for ssh is given standin/log-args.sh as | |
| 272 | +# its ssh command, which exits at once. | |
| 273 | + | |
| 274 | +fossil_raw pull -v --once --proxy off http:///x | |
| 275 | +test xfer-client-mcdc-remote-no-host {$CODE == 1 | |
| 276 | + && [string first "Pull done," $RESULT] >= 0 | |
| 277 | + && [string first "remote: \n" $RESULT] >= 0} | |
| 278 | +set xferclientSsh \ | |
| 279 | + [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]] | |
| 280 | +set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt] | |
| 281 | +fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x | |
| 282 | +test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1 | |
| 283 | + && [file exists $::env(ARGS_LOG)] | |
| 284 | + && [string first "Pull done," $RESULT] >= 0 | |
| 285 | + && [string first "remote: \n" $RESULT] >= 0} | |
| 286 | +unset ::env(ARGS_LOG) | |
| 287 | + | |
| 288 | +############################################################################### | |
| 289 | +# What shows only when the client speaks HTTP. The server is made here: it | |
| 290 | +# answers request N with item N of the list xferclientHttpReplies, or with | |
| 291 | +# a bare timestamp where that is empty, and keeps the header and the cards | |
| 292 | +# of each request in the list xferclientHttpRequests. | |
| 293 | + | |
| 294 | +proc xferclient_http_accept {chan address port} { | |
| 295 | + fconfigure $chan -translation binary -blocking 0 | |
| 296 | + set ::xferclientHttpBuf($chan) "" | |
| 297 | + fileevent $chan readable [list xferclient_http_read $chan] | |
| 298 | +} | |
| 299 | +proc xferclient_http_read {chan} { | |
| 300 | + global xferclientHttpBuf xferclientHttpRequests xferclientHttpReplies | |
| 301 | + append xferclientHttpBuf($chan) [read $chan] | |
| 302 | + set request $xferclientHttpBuf($chan) | |
| 303 | + set end [string first "\r\n\r\n" $request] | |
| 304 | + set length 0 | |
| 305 | + regexp -nocase -line {^content-length:\s*(\d+)} $request -> length | |
| 306 | + if {![eof $chan] && | |
| 307 | + ($end < 0 || [string length $request] < $end + 4 + $length)} { | |
| 308 | + return | |
| 309 | + } | |
| 310 | + unset xferclientHttpBuf($chan) | |
| 311 | + fileevent $chan readable {} | |
| 312 | + fconfigure $chan -blocking 1 | |
| 313 | + # The cards follow four bytes of size when they are compresse |
| --- a/test/xfer-client.test | |
| +++ b/test/xfer-client.test | |
| @@ -0,0 +1,313 @@ | |
| --- a/test/xfer-client.test | |
| +++ b/test/xfer-client.test | |
| @@ -0,0 +1,313 @@ | |
| 1 | # |
| 2 | # Hand the client side of the sync protocol replies that a server would |
| 3 | # not normally give, and require that each is answered |
| 4 | # Replies that a ser# |
| 5 | # Replies are given aandin/transport.sh a, a script thIt saves each |
| 6 | # requesprepared by the test. When the prepared replies |
| 7 | # run out it answers with a bareest wrote,This complements xfer-card, which do the |
| 8 | # same for the server side through "fossil test-xfer". |
| 9 | # |
| 10 | |
| 11 | require_no_open_checkout |
| 12 | |
| 13 | if {$::tcl_platform(platform) eq "windows"} { |
| 14 | test_skip "the stand-in for a server is a shell script" |
| 15 | } |
| 16 | |
| 17 | test_setup |
| 18 | |
| 19 | write_file a.txt "hello world\n" |
| 20 | fossil add a.txt |
| 21 | fossil commit -mql "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\ |
| 22 | JOIN filename f USING(fnid) WHERE f.name='a.txt'" |
| 23 | set xferclientFileientFirst [string trim $RentFile [lindex $RESULT 0] |
| 24 | set xferclientAbsent [string repeat 0123456789abcdef 4] |
| 25 | |
| 26 | set xferclientDir [file join [pwd] xferclient-wire] |
| 27 | file mkdir $xfercl[file join $xferclientDir wire.sh] |
| 28 | write_file $xferclientWire {#!/bin/sh |
| 29 | # Called as: wire.sh URL REQUESTFILE REPLYFILE |
| 30 | n=`cat "$XFERCLIENT_DIR/count" 2>/dev/null || echo 0` |
| 31 | n=`expr $n + 1` |
| 32 | echo $n > "$XFERCLIENT_DIR/count" |
| 33 | cp "$2" "$XFERCLIENT_DIR/request.$n" |
| 34 | if test $n -gt 20; then exit 1; fi |
| 35 | if test -f "$XFERCLIENT_DIR/reply.$n"; then |
| 36 | cp "$XFERCLIENT_DIR/reply.$n" "$3" |
| 37 | else |
| 38 | printf '# timestamp %s errors 0\n' "`date -u +%Y-%m-%dT%H:%M:%S`" > "$3" |
| 39 | fi |
| 40 | } |
| 41 | file attributes on-while-coWire -permissioT_DIR) $xferclientDir |
| 42 | |
| 43 | # Run "fossil VERB" against the stand-in, which answers request N with |
| 44 | # item N of the list REPLIES. Further arguments are options for the |
| 45 | # command. Sets xferclientCode to the exit status, or to "crash", and |
| 46 | # xferclientOut to what fossil printed. |
| 47 | proc xferclient_sync {verb replies args} { |
| 48 | global xferclientDir xferclientWire xferclientCode xferclientOut |
| 49 | file delete {*}[glob -nocomplain -directory $xferclientDir \ |
| 50 | reply.* request.* count] |
| 51 | set number 0 |
| 52 | foreach reply $replies { |
| 53 | write_file [file join $xferclientDir reply.[incr number]] $reply |
| 54 | } |
| 55 | fossil_raw $verb http://localhost/x --once \ |
| 56 | --transport-command $xferclientWire {*}$args |
| 57 | set xferclientCode $::CODE |
| 58 | set xferclientOut $::RESULT |
| 59 | } |
| 60 | |
| 61 | proc xferclient_l script" |
| 62 | } |
| 63 | |
| 64 | test_setup |
| 65 | |
| 66 | write_file a.txt "hello world\n" |
| 67 | fossil add a.txt |
| 68 | fossil commit -m one --no-warnings |
| 69 | fossil sha3sum a.txt |
| 70 | set xferclientFile [lindex $RESULT 0] |
| 71 | set xferclientAbsent [string repeat 0123456789abcdef 4] |
| 72 | |
| 73 | set xferclientDir [file join [pwd] xferclient-wire] |
| 74 | file mkdir $xferclientDir |
| 75 | set xferclientWire \ |
| 76 | [test_standin transport.sh [file join $xferclientDir transport.sh]] |
| 77 | set ::env(TRANSPORT_DIR) $xferclientDir |
| 78 | |
| 79 | # Run "fossil VERB" against the stand-in, which answers request N with |
| 80 | # item N of the list REPLIES. Further arguments are options for the |
| 81 | # command. Sets xferclientCode to the exit status, or to "crash", and |
| 82 | # xferclientOut to what fossil printed. |
| 83 | proc xferclient_sync {verb replies args} { |
| 84 | global xferclientDir xferclientWire xferclientCode xferclientOut |
| 85 | file delete {*}[glob -nocomplain -directory $xferclientDir \ |
| 86 | reply.* request.* count] |
| 87 | set number 0 |
| 88 | foreach reply $replies { |
| 89 | write_file [file join $xferclientDir reply.[incr number]] $reply |
| 90 | } |
| 91 | fossil_raw $verb http://localhost/x --once \ |
| 92 | --transport-command $xferclientWire {*}$args |
| 93 | set xferclientCode $::CODE |
| 94 | set xferclientOut $::RESULT |
| 95 | } |
| 96 | |
| 97 | # Like xferclient_sync, for the server at URL. |
| 98 | proc xferclient_sync_url {verb url replies args} { |
| 99 | global xferclientDir xferclientWire xferclientCode xferclientOut |
| 100 | file delete {*}[glob -nocomplain -directory $xferclientDir \ |
| 101 | reply.* request.* count] |
| 102 | set number 0 |
| 103 | foreach reply $replies { |
| 104 | write_file [file join $xferclientDir reply.[incr number]] $reply |
| 105 | } |
| 106 | fossil_raw $verb $url --once --transport-command $xferclientWire {*}$args |
| 107 | set xferclientCode $::CODE |
| 108 | set xferclientOut $::RESULT |
| 109 | } |
| 110 | |
| 111 | proc xferclient_run {verb reply args} { |
| 112 | xferclient_sync $verb [list $reply] {*}$args |
| 113 | } |
| 114 | |
| 115 | # Returns request NUMBER of the last run, or an empty string if fossil |
| 116 | # made fewer requests. |
| 117 | proc xferclient_request {number} { |
| 118 | set file [file join $::xferclientDir request.$number] |
| 119 | if {![file exists $file]} { |
| 120 | return "" |
| 121 | } |
| 122 | return [read_file $file] |
| 123 | } |
| 124 | |
| 125 | proc xferclient_requests {} { |
| 126 | return [llength [glob -nocomplain -dir######################## |
| 127 | # igot and gimme. What the client asks for, or sends, shows in its |
| 128 | # second request. |
| 129 | |
| 130 | xferclient_run pull "igot $xferclientAbsent\n" |
| 131 | test xfer-client-igot-asks-for-it \ |
| 132 | {$xferclientCode == 0 |
| 133 | && [string first "gimme $xferclientAbsent" [xferclient_request 2]] >= 0} |
| 134 | # A hash that the client hears of only as private, or only in a push. |
| 135 | set xferclientPrivate [string repeat fedcba9876543210 4] |
| 136 | xferclient_run pull "igot $xferclientPrivate 1\n" |
| 137 | test xfer-client-igot-private-not-asked-for \ |
| 138 | {$xferclientCode == 0 |
| 139 | && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0} |
| 140 | xferclient_run pull "igot $xferclientFile\n" |
| 141 | test xfer-client-igot-held-not-asked-for \ |
| 142 | {$xferclientCode == 0 |
| 143 | && [string first "gimme $xferclientFile" [xferclient_request 2]] < 0} |
| 144 | xferclient_run push "igot $xferclientPrivate\n" |
| 145 | test xfer-client-igot-on-push-not-asked-for \ |
| 146 | {$xferclientCode == 0 |
| 147 | && [string first "gimme $xferclientPrivate" [xferclient_request 2]] < 0} |
| 148 | xferclient_expect igot-not-a-hash pull "igot nothash\n" 1 {} "unknown command" |
| 149 | xferclient_expect igot-alone pull "igot\n" 1 {} "unknown command" |
| 150 | |
| 151 | xferclient_run push "gimme $xferclientFile\n" |
| 152 | test xfer-client-gimme-sends-it \ |
| 153 | {$xferclientCode == 0 |
| 154 | && [string first "file $xferclientFile" [xferclient_request 2]] >= 0} |
| 155 | xferclient_run pull "gimme $xferclientFile\n" |
| 156 | test xfer-client-gimme-on-pull-sends-nothing \ |
| 157 | {$xferclientCode == 0 |
| 158 | && [string first "file $xferclientFile" [xferclient_request 2]] < 0} |
| 159 | xferclient_expect gimme-absent push "gimme $xferclientAbsent\n" 0 {} |
| 160 | xferclient_expect gimme-not-a-hash push "gimme nothash\n" 1 {} \ |
| 161 | "unknown command" |
| 162 | |
| 163 | ############################################################################### |
| 164 | # An igot card can say that an artifact is private. The client marks its |
| 165 | # own copy private only i. It-igot-asks-for-it \ |
| 166 | {$xferould previouslyks-for-it \ |
| 167 | {$xferclientCod, after |
| 168 | # which tte and then bare timestamps. |
| 169 | |
| 170 | fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT min(objid) FROM event |
| 171 | WHERE type='ci')" |
| 172 | set xferclientFirst [string trim $RESULT] |
| 173 | fossil artifact $xferclientFirst first-manifest.out |
| 174 | set xferclientManifest [read_file first-manifest.out] |
| 175 | set xferclientPush "push $xferclientOwnCode $xferclientOwnCode\n" |
| 176 | |
| 177 | # Clone into clone.fossil from a server that gives the replies REPLIES. |
| 178 | # Sets xferclientCode and xferclientOut as xferclient_sync does. |
| 179 | proc xferclient_clone {replies} { |
| 180 | global xferclientDir xferclientWire xferclientCode xferclientOut |
| 181 | file delete clone.fossil |
| 182 | file delete {*}[glob -nocomplain -directory $xferclientDir \ |
| 183 | reply.* request.* count] |
| 184 | set number 0 |
| 185 | foreach reply $replies { |
| 186 | write_file [file join $xferclientDir reply.[incr number]] $reply |
| 187 | } |
| 188 | fossil_raw clone http://localhost/x clone.fossil --no-open \ |
| 189 | --transport-command $xferclientWire |
| 190 | set xferclientCode $::CODE |
| 191 | set xferclientOut $::RESULT |
| 192 | } |
| 193 | |
| 194 | # The number of the artifacts HASHES that clone.fossil holds. |
| 195 | proc xferclient_clone_holds {hashes} { |
| 196 | fossil sql -R clone.fossil "SELECT count(*) FROM blob WHERE size>=0 |
| 197 | AND uuid IN ('[join $hashes ',']')" |
| 198 | return [string trim $::RESULT] |
| 199 | } |
| 200 | |
| 201 | # A server of the first version of the protocol lists what it has in |
| 202 | # "igot" cards and sends each artifact, in a "file" card, when it is asked |
| 203 | # for it. The clone asks in every round and never asks for clusters. |
| 204 | xferclient_clone [list \ |
| 205 | "${xferclientPush}igot $xferclientFirst\nigot $xferclientFile\n" \ |
| 206 | "file $xferclientFirst [string length $xferclientManifest]\n\ |
| 207 | $xferclientManifest" \ |
| 208 | "file $xferclientFile 12\nhello world\n"] |
| 209 | test xfer-client-mcdc-clone-by-igot {$xferclientCode == 0 |
| 210 | && [xferclient_requests] == 4 |
| 211 | && [string first "gimme $xferclientFirst" [xferclient_request 2]] >= 0 |
| 212 | && [string first "gimme $xferclientFile" [xferclient_request 3]] >= 0 |
| 213 | && [string first "pragma req-clusters" [xferclient_request 3]] < 0} |
| 214 | test_eq xfer-client-mcdc-clone-by-igot-holds \ |
| 215 | [xferclient_clone_holds [list $xferclientFirst $xferclientFile]] 2 |
| 216 | fossil sql -R clone.fossil "SELECT value FROM config WHERE name='project-code'" |
| 217 | test_eq xfer-client-mcdc-clone-project-code [string trim $RESULT] \ |
| 218 | $xferclientOwnCode |
| 219 | |
| 220 | # The card that gives a clone its project code has three words, the third |
| 221 | # a hash. Any other card that begins with "push" ends the clone with an |
| 222 | # error and leaves no repository. |
| 223 | foreach {xferclientName xferclientCard} [list \ |
| 224 | two-words "push $xferclientOwnCode\n" \ |
| 225 | not-a-hash "push $xferclientOwnCode nothash\n" \ |
| 226 | ] { |
| 227 | xferclient_clone [list $xferclientCard] |
| 228 | test xfer-client-mcdc-clone-push-$xferclientName {$xferclientCode == 1 |
| 229 | && [string first "unknown command" $xferclientOut] >= 0 |
| 230 | && ![file exists clone.fossil]} |
| 231 | } |
| 232 | |
| 233 | # An error in the first reply ends the clone, unless it says that the |
| 234 | # login failed or that the client is not authorized: the first request of |
| 235 | # a clone has no login card, so those are expected and the clone goes on. |
| 236 | foreach {xferclientName xferclientError xferclientGoesOn} { |
| 237 | other-error {something\sfailed} 0 |
| 238 | login-failed {login\sfailed} 1 |
| 239 | not-authorized {not\sauthorized\sto\sclone} 1 |
| 240 | } { |
| 241 | xferclient_clone [list "${xferclientPush}error $xferclientError\n"] |
| 242 | test xfer-client-mcdc-clone-first-error-$xferclientName { |
| 243 | $xferclientGoesOn |
| 244 | ? ($xferclientCode == 0 && [xferclient_requests] == 2 |
| 245 | && [file exists clone.fossil]) |
| 246 | : ($xferclientCode == 1 |
| 247 | && [string first "Error: something failed" $xferclientOut] >= 0 |
| 248 | && ![file exists clone.fossil])} |
| 249 | } |
| 250 | |
| 251 | # A clone goes on asking while the server says that it has more to send |
| 252 | # and something arrives, here an unversioned file. It stops after a reply |
| 253 | # in which nothing arrives. |
| 254 | xferclient_clone [list "clone_seqno 2\n$xferclientPush" \ |
| 255 | "[xferclient_uvfile cloned.txt]clone_seqno 3\n$xferclientPush" \ |
| 256 | "clone_seqno 4\n$xferclientPush"] |
| 257 | test xfer-client-mcdc-clone-goes-on-while-content-arrives \ |
| 258 | {$xferclientCode == 0 && [xferclient_requests] == 3 |
| 259 | && [string first "clone 3 3" [xferclient_request 3]] >= 0} |
| 260 | fossil unversioned cat cloned.txt -R clone.fossil |
| 261 | test_eq xfer-client-mcdc-clone-unversioned-arrived $RESULT abc |
| 262 | xferclient_clone [list "clone_seqno 2\n$xferclientPush" \ |
| 263 | "clone_seqno 3\n$xferclientPush" "clone_seqno 4\n$xferclientPush"] |
| 264 | test xfer-client-mcdc-clone-stops-when-nothing-arrives \ |
| 265 | {$xferclientCode == 0 && [xferclient_requests] == 2} |
| 266 | file delete clone.fossil |
| 267 | |
| 268 | ############################################################################### |
| 269 | # What a sync with -v says at its end about the server. A server that |
| 270 | # could not be reached is named as the URL names it, with no address. The |
| 271 | # URLs here have no host; the one for ssh is given standin/log-args.sh as |
| 272 | # its ssh command, which exits at once. |
| 273 | |
| 274 | fossil_raw pull -v --once --proxy off http:///x |
| 275 | test xfer-client-mcdc-remote-no-host {$CODE == 1 |
| 276 | && [string first "Pull done," $RESULT] >= 0 |
| 277 | && [string first "remote: \n" $RESULT] >= 0} |
| 278 | set xferclientSsh \ |
| 279 | [test_standin log-args.sh [file join $xferclientDir ssh-standin.sh]] |
| 280 | set ::env(ARGS_LOG) [file join $xferclientDir ssh-args.txt] |
| 281 | fossil_raw pull -v --once --ssh-command $xferclientSsh ssh:///x |
| 282 | test xfer-client-mcdc-remote-ssh-no-host {$CODE == 1 |
| 283 | && [file exists $::env(ARGS_LOG)] |
| 284 | && [string first "Pull done," $RESULT] >= 0 |
| 285 | && [string first "remote: \n" $RESULT] >= 0} |
| 286 | unset ::env(ARGS_LOG) |
| 287 | |
| 288 | ############################################################################### |
| 289 | # What shows only when the client speaks HTTP. The server is made here: it |
| 290 | # answers request N with item N of the list xferclientHttpReplies, or with |
| 291 | # a bare timestamp where that is empty, and keeps the header and the cards |
| 292 | # of each request in the list xferclientHttpRequests. |
| 293 | |
| 294 | proc xferclient_http_accept {chan address port} { |
| 295 | fconfigure $chan -translation binary -blocking 0 |
| 296 | set ::xferclientHttpBuf($chan) "" |
| 297 | fileevent $chan readable [list xferclient_http_read $chan] |
| 298 | } |
| 299 | proc xferclient_http_read {chan} { |
| 300 | global xferclientHttpBuf xferclientHttpRequests xferclientHttpReplies |
| 301 | append xferclientHttpBuf($chan) [read $chan] |
| 302 | set request $xferclientHttpBuf($chan) |
| 303 | set end [string first "\r\n\r\n" $request] |
| 304 | set length 0 |
| 305 | regexp -nocase -line {^content-length:\s*(\d+)} $request -> length |
| 306 | if {![eof $chan] && |
| 307 | ($end < 0 || [string length $request] < $end + 4 + $length)} { |
| 308 | return |
| 309 | } |
| 310 | unset xferclientHttpBuf($chan) |
| 311 | fileevent $chan readable {} |
| 312 | fconfigure $chan -blocking 1 |
| 313 | # The cards follow four bytes of size when they are compresse |
+99
| --- a/test/xfer-server.test | ||
| +++ b/test/xfer-server.test | ||
| @@ -0,0 +1,99 @@ | ||
| 1 | +# | |
| 2 | +# Send each kind of card and of the sync protocol, through "fossil tethe permissions. The server must give the documented answer and must not | |
| 3 | +# crash. xfer-cards.test has the cards with content. | |
| 4 | +# | |
| 5 | +# "fossil test-xfer" treats a login card as a grant of the Read, Write, | |
| 6 | +# Private and Admin permissions. A message without a login card runs | |
| 7 | +# with the permissions of the user "nobody", whicse tests run only in a | |
| 8 | +test_cleanup | |
| 9 | +no crash. This complements | |
| 10 | +# xfer-cards.test, which covers the cards that carryql -R .rep.fossil \ | |
| 11 | + "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\ | |
| 12 | + JOIN filename f USING(fnid) WHERE f.name='a.txtFileset Version 20261110 12482 runs | |
| 13 | +# with the permissions of the user "nobody", whicse tests run only in a | |
| 14 | +test_cleanup | |
| 15 | + on the server# Send one message. Sets xferserverOk to 1 when fossil did not crash and | |
| 16 | +# Reply to what it printed. The reply goes through a file and | |
| 17 | +# is read back as bytes,send {body} { | |
| 18 | + global xset xferserverOk [expr# | |
| 19 | +# Each kind of card and pragma of the sync protocol, sent to the server | |
| 20 | +# side through "fossil test-xfer", with and without valid card | |
| 21 | +# permissions. The server must give the documented answer and must not | |
| 22 | +# crash. xfer-cards.test has the cards with content. | |
| 23 | +# | |
| 24 | +# "fossil test-xfer" treats a login card as a grant of the Read, Write, | |
| 25 | +# Private and Admin permissions. A message without a login card runs | |
| 26 | +# with the permissions of the user "nobody", whicse tests run only in a | |
| 27 | +test_cleanup | |
| 28 | +f card and pragma of the sync protocol, sent to the server | |
| 29 | +# side through "fossil test-xfer", with and without valid card | |
| 30 | +# permissions. The server must give the documented answer and must not | |
| 31 | +# crash. xfer-cards.test has the cards with content. | |
| 32 | +# | |
| 33 | +# "fossil test-xfer" treats a login | |
| 34 | +# string that beginsglobal xferserverOk xferserverReplyset Good $xferserverOk | |
| 35 | + foreach xferserverWant $args { | |
| 36 | + if {[string index $xferserverWant 0] eq "!"} { | |
| 37 | + if {[string first [string range $xferserverWReply]>=0} {set xferserverGood 0} | |
| 38 | + } elseif {[string first $xferserverWant $xferserverReply]<0} { | |
| 39 | + set xferserverGood 0 | |
| 40 | + } | |
| 41 | + } | |
| 42 | + if {!$xferserverGood} { | |
| 43 | + puts " reply to $name: $xferserverReply" | |
| 44 | + } | |
| 45 | + $name {$xferserverGood} | |
| 46 | +} | |
| 47 | + | |
| 48 | +# Each kiagma ofxferserverVersio""igot" Each kind of car# | |
| 49 | +# Each kind of Absent"SELECT count(*) FROM \ | |
| 50 | + '-not-privatSELECT count(*) FROM \ | |
| 51 | + 'marks-phantom2Absent2fossil tes# | |
| 52 | +# Each kind\ | |
| 53 | + "SELECT count(*) FROM Absent2'{[string trim $RESULT]==0\ | |
| 54 | + "SELECT count(*)client-url-recordd card | |
| 55 | +# permissions. The server must give the documented answer and must not | |
| 56 | +# crash. xfer-cards.test has the cards with content. | |
| 57 | +# | |
| 58 | +# "fossil te# | |
| 59 | +# Each kind of car3lacks phantom. It | |
| 60 | +# content.igotsh}igot3fossil tes# | |
| 61 | +# Each kindSELECT count(*) FROM \ | |
| 62 | + 3'-phantom {[string trim $RESULT]==1xferserverOkReply]>=xferserverReply# Each kind of card anf card and # Each kind of card and pragma of the sync protocol, sent to the server | |
| 63 | +# side through "fossil test-xfer", with and without valid card | |
| 64 | +# permissions. The server must give the documented answer and must not | |
| 65 | +# crash. xfer-cards.test has the cards with content. | |
| 66 | +# | |
| 67 | +# "fossi# | |
| 68 | +# Each kLogin}clonev1-odd-arguments "${xferserverLoginxferserverLogin}# "fossil test-xfer" prints the reply as a string, so a reply that holds | |
| 69 | +# compressed content is cut at its first zero byte. Only the start of | |
| 70 | +# s "${xferserverLoginxferserverLoginxferserverLoginmax-download',1,now())lone-v3-sma!cfile " "clone_seqno 1"='max-download'"',0,now())lone-v3-no-time "${xferserver=''"uv-sync',1,now())lone-uv-sync "${xferserverLogin='uv-sync'" | |
| 71 | + | |
| 72 | +set Login "login tester 0 0\n"# Each kind of car card and pragma of the sync protocol, sent to the server | |
| 73 | +# side through "fossil test-xfer", with and without valid card | |
| 74 | +# permissions. The server must give the documented answer and must not | |
| 75 | +# crash. xfer-cards.test has the cards with content. | |
| 76 | +# | |
| 77 | +# "fossil test-xfer" treats a login card as a grant of the Read, Write, | |
| 78 | +# Private and Admin permissions. A message without a login card runs | |
| 79 | +# with the permissions # | |
| 80 | +# Each kind # | |
| 81 | +#\n"ions. The ser# | |
| 82 | +#\n"i-lock-second-clientll}B\n" \ | |
| 83 | + "errors 0"SELECT count(*)ci-unlock-removeions. The ser# | |
| 84 | +#B\n" | |
| 85 | +# A lock older than the lock-ions. The ser# | |
| 86 | +#\n"',0,now())ions. The ser# | |
| 87 | +#\n"ci-lock-*'"='Absent4Absent4 04i-lock-not-a-hashll}pragma ci-\n"ient-urlxferserverReply]==1} | |
| 88 | + | |
| 89 | +# Without the Write permission a client URL is not recorde# Each kind of card of card and pragma of the client-urlnet/z\n" "errors 0"\ | |
| 90 | + "SELECT count(*) GLOB 'sync*example.net*'{[string trim $RESULT]==\ | |
| 91 | + VALUES('','{}',now())# Clone combined with other cards# Each kind of card flone-versixferserverVersionxferserverVersionuv-sync',1,now())xferserverVersionxferserverReply]==='uv-sync'"# Each kind of car card and pragma of the sync protoc of card and prais no longer a leaf is>=40ions. The ser# | |
| 92 | +#A\n"ions. The ser# | |
| 93 | +#\n"tipll}\n"SELECT count(*)ci-lock-parent-droppions. The ser# | |
| 94 | +#B\n" \ | |
| 95 | + nobody "ci-lock-*'"\ | |
| 96 | + VALUES('xfer-push-script','',now())\ | |
| 97 | + VALUES('xfer-push-script','error push-script-says-no',now())='xfer-push-script'"\ | |
| 98 | + VALUES('','',now())=''"='project-code'"!$xferserverOkReply]>=0 | |
| 99 | +test_cleanup |
| --- a/test/xfer-server.test | |
| +++ b/test/xfer-server.test | |
| @@ -0,0 +1,99 @@ | |
| --- a/test/xfer-server.test | |
| +++ b/test/xfer-server.test | |
| @@ -0,0 +1,99 @@ | |
| 1 | # |
| 2 | # Send each kind of card and of the sync protocol, through "fossil tethe permissions. The server must give the documented answer and must not |
| 3 | # crash. xfer-cards.test has the cards with content. |
| 4 | # |
| 5 | # "fossil test-xfer" treats a login card as a grant of the Read, Write, |
| 6 | # Private and Admin permissions. A message without a login card runs |
| 7 | # with the permissions of the user "nobody", whicse tests run only in a |
| 8 | test_cleanup |
| 9 | no crash. This complements |
| 10 | # xfer-cards.test, which covers the cards that carryql -R .rep.fossil \ |
| 11 | "SELECT b.uuid FROM blob b JOIN mlink m ON m.fid=b.rid\ |
| 12 | JOIN filename f USING(fnid) WHERE f.name='a.txtFileset Version 20261110 12482 runs |
| 13 | # with the permissions of the user "nobody", whicse tests run only in a |
| 14 | test_cleanup |
| 15 | on the server# Send one message. Sets xferserverOk to 1 when fossil did not crash and |
| 16 | # Reply to what it printed. The reply goes through a file and |
| 17 | # is read back as bytes,send {body} { |
| 18 | global xset xferserverOk [expr# |
| 19 | # Each kind of card and pragma of the sync protocol, sent to the server |
| 20 | # side through "fossil test-xfer", with and without valid card |
| 21 | # permissions. The server must give the documented answer and must not |
| 22 | # crash. xfer-cards.test has the cards with content. |
| 23 | # |
| 24 | # "fossil test-xfer" treats a login card as a grant of the Read, Write, |
| 25 | # Private and Admin permissions. A message without a login card runs |
| 26 | # with the permissions of the user "nobody", whicse tests run only in a |
| 27 | test_cleanup |
| 28 | f card and pragma of the sync protocol, sent to the server |
| 29 | # side through "fossil test-xfer", with and without valid card |
| 30 | # permissions. The server must give the documented answer and must not |
| 31 | # crash. xfer-cards.test has the cards with content. |
| 32 | # |
| 33 | # "fossil test-xfer" treats a login |
| 34 | # string that beginsglobal xferserverOk xferserverReplyset Good $xferserverOk |
| 35 | foreach xferserverWant $args { |
| 36 | if {[string index $xferserverWant 0] eq "!"} { |
| 37 | if {[string first [string range $xferserverWReply]>=0} {set xferserverGood 0} |
| 38 | } elseif {[string first $xferserverWant $xferserverReply]<0} { |
| 39 | set xferserverGood 0 |
| 40 | } |
| 41 | } |
| 42 | if {!$xferserverGood} { |
| 43 | puts " reply to $name: $xferserverReply" |
| 44 | } |
| 45 | $name {$xferserverGood} |
| 46 | } |
| 47 | |
| 48 | # Each kiagma ofxferserverVersio""igot" Each kind of car# |
| 49 | # Each kind of Absent"SELECT count(*) FROM \ |
| 50 | '-not-privatSELECT count(*) FROM \ |
| 51 | 'marks-phantom2Absent2fossil tes# |
| 52 | # Each kind\ |
| 53 | "SELECT count(*) FROM Absent2'{[string trim $RESULT]==0\ |
| 54 | "SELECT count(*)client-url-recordd card |
| 55 | # permissions. The server must give the documented answer and must not |
| 56 | # crash. xfer-cards.test has the cards with content. |
| 57 | # |
| 58 | # "fossil te# |
| 59 | # Each kind of car3lacks phantom. It |
| 60 | # content.igotsh}igot3fossil tes# |
| 61 | # Each kindSELECT count(*) FROM \ |
| 62 | 3'-phantom {[string trim $RESULT]==1xferserverOkReply]>=xferserverReply# Each kind of card anf card and # Each kind of card and pragma of the sync protocol, sent to the server |
| 63 | # side through "fossil test-xfer", with and without valid card |
| 64 | # permissions. The server must give the documented answer and must not |
| 65 | # crash. xfer-cards.test has the cards with content. |
| 66 | # |
| 67 | # "fossi# |
| 68 | # Each kLogin}clonev1-odd-arguments "${xferserverLoginxferserverLogin}# "fossil test-xfer" prints the reply as a string, so a reply that holds |
| 69 | # compressed content is cut at its first zero byte. Only the start of |
| 70 | # s "${xferserverLoginxferserverLoginxferserverLoginmax-download',1,now())lone-v3-sma!cfile " "clone_seqno 1"='max-download'"',0,now())lone-v3-no-time "${xferserver=''"uv-sync',1,now())lone-uv-sync "${xferserverLogin='uv-sync'" |
| 71 | |
| 72 | set Login "login tester 0 0\n"# Each kind of car card and pragma of the sync protocol, sent to the server |
| 73 | # side through "fossil test-xfer", with and without valid card |
| 74 | # permissions. The server must give the documented answer and must not |
| 75 | # crash. xfer-cards.test has the cards with content. |
| 76 | # |
| 77 | # "fossil test-xfer" treats a login card as a grant of the Read, Write, |
| 78 | # Private and Admin permissions. A message without a login card runs |
| 79 | # with the permissions # |
| 80 | # Each kind # |
| 81 | #\n"ions. The ser# |
| 82 | #\n"i-lock-second-clientll}B\n" \ |
| 83 | "errors 0"SELECT count(*)ci-unlock-removeions. The ser# |
| 84 | #B\n" |
| 85 | # A lock older than the lock-ions. The ser# |
| 86 | #\n"',0,now())ions. The ser# |
| 87 | #\n"ci-lock-*'"='Absent4Absent4 04i-lock-not-a-hashll}pragma ci-\n"ient-urlxferserverReply]==1} |
| 88 | |
| 89 | # Without the Write permission a client URL is not recorde# Each kind of card of card and pragma of the client-urlnet/z\n" "errors 0"\ |
| 90 | "SELECT count(*) GLOB 'sync*example.net*'{[string trim $RESULT]==\ |
| 91 | VALUES('','{}',now())# Clone combined with other cards# Each kind of card flone-versixferserverVersionxferserverVersionuv-sync',1,now())xferserverVersionxferserverReply]==='uv-sync'"# Each kind of car card and pragma of the sync protoc of card and prais no longer a leaf is>=40ions. The ser# |
| 92 | #A\n"ions. The ser# |
| 93 | #\n"tipll}\n"SELECT count(*)ci-lock-parent-droppions. The ser# |
| 94 | #B\n" \ |
| 95 | nobody "ci-lock-*'"\ |
| 96 | VALUES('xfer-push-script','',now())\ |
| 97 | VALUES('xfer-push-script','error push-script-says-no',now())='xfer-push-script'"\ |
| 98 | VALUES('','',now())=''"='project-code'"!$xferserverOkReply]>=0 |
| 99 | test_cleanup |
+1
| --- a/tools/testbuild.sh | ||
| +++ b/tools/testbuild.sh | ||
| @@ -0,0 +1 @@ | ||
| 1 | +# |
| --- a/tools/testbuild.sh | |
| +++ b/tools/testbuild.sh | |
| @@ -0,0 +1 @@ | |
| --- a/tools/testbuild.sh | |
| +++ b/tools/testbuild.sh | |
| @@ -0,0 +1 @@ | |
| 1 | # |