| | @@ -1,15 +1,20 @@ |
| 1 | 1 | # |
| 2 | 2 | # Each kind of card and pragma of the sync protocol, sent to the server |
| 3 | 3 | # side through "fossil test-xfer", with and without valid card |
| 4 | 4 | # permissions. The server must give the documented answer and must not |
| 5 | | -# crash. xfer-cards.test has the cards with content. |
| 5 | +# crash. The cards with content are in the sections at the end. |
| 6 | 6 | # |
| 7 | 7 | # "fossil test-xfer" treats a login card as a grant of the Read, Write, |
| 8 | 8 | # Private and Admin permissions. A message without a login card runs |
| 9 | 9 | # with the permissions of the user "nobody", which these tests set. |
| 10 | 10 | # |
| 11 | + |
| 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 | +} |
| 11 | 16 | |
| 12 | 17 | require_no_open_checkout |
| 13 | 18 | |
| 14 | 19 | test_setup |
| 15 | 20 | |
| | @@ -196,10 +201,32 @@ |
| 196 | 201 | xferserver_expect write-client-url \ |
| 197 | 202 | "${xferserverPush}pragma client-url http://example.org/x\n" "errors 0" |
| 198 | 203 | test xfer-server-write-client-url-recorded \ |
| 199 | 204 | {[xferserver_count \ |
| 200 | 205 | "config WHERE name GLOB 'syncfrom:*example.org*'"] == 1} |
| 206 | +# A client URL that is not http or https is ignored and the request goes |
| 207 | +# on; it is not read as a path on the server. |
| 208 | +foreach {xferserverName xferserverUrl} {ftp ftp://example.org/y path /} { |
| 209 | + xferserver_expect write-client-url-$xferserverName \ |
| 210 | + "${xferserverPush}pragma client-url $xferserverUrl\n" \ |
| 211 | + "!unknown repository" "errors 0" |
| 212 | +} |
| 213 | + |
| 214 | +# A first word that has the length of a card name and is not it selects no |
| 215 | +# card. A pragma with a name of the length of a known one that is not it |
| 216 | +# does nothing. |
| 217 | +foreach {xferserverName xferserverBody} [list \ |
| 218 | + pull-other-word "pulx x $xferserverPcode\n" \ |
| 219 | + reqconfig-other-word "reqconfih /project\n" \ |
| 220 | +] { |
| 221 | + xferserver_expect bad-$xferserverName $xferserverBody \ |
| 222 | + {error bad\scommand:} "!config " "!igot " |
| 223 | +} |
| 224 | +xferserver_expect write-pragma-other-word \ |
| 225 | + "${xferserverPush}pragma client-urx http://example.net/w\n" "errors 0" |
| 226 | +test xfer-server-write-pragma-other-word-not-recorded \ |
| 227 | + {[xferserver_count "config WHERE name GLOB 'sync*example.net*'"] == 0} |
| 201 | 228 | |
| 202 | 229 | ############################################################################### |
| 203 | 230 | # With a login card: private content, configuration, clone and locks. |
| 204 | 231 | |
| 205 | 232 | xferserver_caps "" |
| | @@ -239,10 +266,51 @@ |
| 239 | 266 | } |
| 240 | 267 | xferserver_expect login-config-roundtrip \ |
| 241 | 268 | "$xferserverLogin$xferserverPush$xferserverCards" "errors 0" |
| 242 | 269 | xferserver_expect login-config-negative-size \ |
| 243 | 270 | "${xferserverLogin}config /project -5\n" {error bad\scommand:} |
| 271 | + |
| 272 | +# A value in a config card for a table must be a string or blob literal, |
| 273 | +# an integer or NULL. A card with any other value is ignored, and the |
| 274 | +# request goes on. |
| 275 | +proc xferserver_config_user {content} { |
| 276 | + global xferserverLogin xferserverPush |
| 277 | + return "$xferserverLogin${xferserverPush}config /user\ |
| 278 | + [string length $content]\n$content\n" |
| 279 | +} |
| 280 | +foreach {xferserverName xferserverValue} { |
| 281 | + word x column pw blob-not-hex X'zz' blob-odd X'abc' |
| 282 | +} { |
| 283 | + xferserver_expect config-value-$xferserverName [xferserver_config_user \ |
| 284 | + "1262304000 'cfgbad$xferserverName' info $xferserverValue"] \ |
| 285 | + "!Database error" "errors 0" |
| 286 | +} |
| 287 | +test_eq xfer-server-config-value-ignored \ |
| 288 | + [xferserver_count "user WHERE login GLOB 'cfgbad*'"] 0 |
| 289 | +foreach {xferserverName xferserverValue} { |
| 290 | + string 'text' integer 7 null NULL blob X'00ff' empty-blob X'' |
| 291 | +} { |
| 292 | + xferserver_expect config-value-$xferserverName [xferserver_config_user \ |
| 293 | + "1262304000 'cfgok$xferserverName' info $xferserverValue"] "errors 0" |
| 294 | +} |
| 295 | +test_eq xfer-server-config-value-stored \ |
| 296 | + [xferserver_count "user WHERE login GLOB 'cfgok*'"] 5 |
| 297 | + |
| 298 | +# A hash with a zero byte inside is not a hash. Each card that names an |
| 299 | +# artifact by hash refuses it, and nothing is stored under a short hash. |
| 300 | +set xferserverZeroHash "ceafb\000[string repeat a 58]" |
| 301 | +foreach {xferserverName xferserverCard xferserverWant} [list \ |
| 302 | + igot "igot $xferserverZeroHash\n" {error bad\scommand:} \ |
| 303 | + gimme "gimme $xferserverZeroHash\n" {error bad\scommand:} \ |
| 304 | + file "file $xferserverZeroHash 3\nabc\n" "error malformed" \ |
| 305 | +] { |
| 306 | + xferserver_expect hash-zero-byte-$xferserverName \ |
| 307 | + "$xferserverLogin$xferserverPush$xferserverCard" \ |
| 308 | + "!Database error" $xferserverWant |
| 309 | +} |
| 310 | +test_eq xfer-server-hash-zero-byte-nothing-stored \ |
| 311 | + [xferserver_count "blob WHERE length(uuid)<40"] 0 |
| 244 | 312 | |
| 245 | 313 | # Clone, in each version of the protocol. A login card to test-xfer does |
| 246 | 314 | # not grant the Clone permission, so "nobody" is given it and these |
| 247 | 315 | # messages have no login card. |
| 248 | 316 | xferserver_caps "g" |
| | @@ -349,10 +417,24 @@ |
| 349 | 417 | # Links to other repositories of the project are given on request, except |
| 350 | 418 | # those on the local host. |
| 351 | 419 | xferserver_set syncwith:http://localhost:8080/y "{}" |
| 352 | 420 | xferserver_expect read-req-links "${xferserverPull}pragma req-links\n" \ |
| 353 | 421 | "pragma link http://example.org/x" "!localhost:8080/y" |
| 422 | +# A repository that is mirrored to Git has the address it pushes to among |
| 423 | +# these links when that address is an http or https URL. An address that |
| 424 | +# Git takes and that is not a URL is left out, and the reply goes on. |
| 425 | +xferserver_set gitpush:https://git.example.org/someone/mirror.git "{}" |
| 426 | +xferserver_set gitpush:[email protected]:someone/other.git "{}" |
| 427 | +xferserver_set gitpush:[email protected]:someone/other.git "{}" |
| 428 | +xferserver_send "${xferserverPull}pragma req-links\n" |
| 429 | +test xfer-server-read-req-links-git-address \ |
| 430 | + {$CODE == 0 && [string first "errors 0" $RESULT] >= 0} |
| 431 | +test xfer-server-read-req-links-git-https \ |
| 432 | + {[string match "*pragma link https://git.example.org/someone/mirror.git*" $RESULT]} |
| 433 | +test xfer-server-read-req-links-git-other-left-out \ |
| 434 | + {![string match "*other.git*" $RESULT]} |
| 435 | +xferserver_unset gitpush:* |
| 354 | 436 | |
| 355 | 437 | # The address configuration is given only to a client that may read |
| 356 | 438 | # addresses. |
| 357 | 439 | xferserver_caps "oe" |
| 358 | 440 | xferserver_expect read-address-reqconfig "reqconfig /all\n" "errors 0" |
| | @@ -415,9 +497,1192 @@ |
| 415 | 497 | # A repository with no project code cannot answer a pull or a push. |
| 416 | 498 | xferserver_unset project-code |
| 417 | 499 | xferserver_send "$xferserverLogin$xferserverPull" |
| 418 | 500 | test xfer-server-no-project-code \ |
| 419 | 501 | {$CODE == 1 && [string first "missing project code" $RESULT] >= 0} |
| 502 | + |
| 503 | +############################################################################### |
| 504 | +# The sections below each run in a directory of their own, with a repository |
| 505 | +# and a checkout of their own inside this one. |
| 506 | + |
| 507 | +set xferserverDir [pwd] |
| 508 | +proc xferserver_enter {name} { |
| 509 | + global xferserverDir |
| 510 | + file mkdir [file join $xferserverDir $name] |
| 511 | + cd [file join $xferserverDir $name] |
| 512 | + fossil new .rep.fossil |
| 513 | + fossil open .rep.fossil --nested |
| 514 | + fossil set mtime-changes off |
| 515 | +} |
| 516 | +proc xferserver_leave {} { |
| 517 | + global xferserverDir |
| 518 | + cd $xferserverDir |
| 519 | +} |
| 520 | + |
| 521 | +############################################################################### |
| 522 | +# Malformed "file", "cfile" and "uvfile" cards, sent to the server side |
| 523 | +# of the sync protocol through "fossil test-xfer". The server must |
| 524 | +# refuse each one and must not crash. These cards reach the checks in |
| 525 | +# xfer_accept_file(), xfer_accept_compressed_file() and |
| 526 | +# xfer_accept_unversioned_file() in src/xfer.c. |
| 527 | + |
| 528 | +xferserver_enter cards |
| 529 | + |
| 530 | +set xferserverCardsContent "hello world\n" |
| 531 | +set xferserverCardsSize [string length $xferserverCardsContent] |
| 532 | +write_file a.txt $xferserverCardsContent |
| 533 | +fossil add a.txt |
| 534 | +fossil commit -m one --no-warnings |
| 535 | +fossil sha3sum a.txt |
| 536 | +set xferserverCardsHash [lindex $RESULT 0] |
| 537 | + |
| 538 | +fossil init tgt.fossil -A tester |
| 539 | +fossil sql -R tgt.fossil "SELECT value FROM config WHERE name='project-code'" |
| 540 | +set xferserverCardsPcode [string trim $::RESULT] |
| 541 | + |
| 542 | +# Push the cards in BODY to the target. test-xfer disables the login |
| 543 | +# check, so the nonce and signature in the login card are ignored. The |
| 544 | +# push card has the target's project code. |
| 545 | +# |
| 546 | +# Sets xferserverCardsCode to the exit status of fossil, |
| 547 | +# xferserverCardsErrors to the number of errors that the reply reports, and |
| 548 | +# xferserverCardsStored to 1 when the target now holds the source file. |
| 549 | +proc xferserver_cards_push {body} { |
| 550 | + global xferserverCardsHash xferserverCardsPcode |
| 551 | + global xferserverCardsCode xferserverCardsErrors xferserverCardsStored |
| 552 | + fossil sql -R tgt.fossil "DELETE FROM blob WHERE uuid='$xferserverCardsHash'" |
| 553 | + write_file push.txt "login tester 0 0\npush x $xferserverCardsPcode\n$body" |
| 554 | + fossil_raw test-xfer -R tgt.fossil push.txt |
| 555 | + set xferserverCardsCode $::CODE |
| 556 | + set xferserverCardsErrors 0 |
| 557 | + regexp {errors ([0-9]+)} $::RESULT -> xferserverCardsErrors |
| 558 | + fossil sql -R tgt.fossil \ |
| 559 | + "SELECT count(*) FROM blob WHERE uuid='$xferserverCardsHash' AND size>=0" |
| 560 | + set xferserverCardsStored [string trim $::RESULT] |
| 561 | +} |
| 562 | + |
| 563 | +xferserver_cards_push "file $xferserverCardsHash\ |
| 564 | + $xferserverCardsSize\n$xferserverCardsContent" |
| 565 | +test xfer-cards-valid-accepted \ |
| 566 | + {$xferserverCardsCode == 0 && $xferserverCardsErrors == 0 && |
| 567 | + $xferserverCardsStored == 1} |
| 568 | + |
| 569 | +set xferserverCardsZeros [string repeat 0 64] |
| 570 | +set xferserverCardsUv "uvfile note.txt 1700000000" |
| 571 | +foreach {xferserverCardsName xferserverCardsBody} [list \ |
| 572 | + too-few-tokens "file $xferserverCardsHash\n" \ |
| 573 | + bad-hash-name \ |
| 574 | + "file nothash $xferserverCardsSize\n$xferserverCardsContent" \ |
| 575 | + bad-size-int \ |
| 576 | + "file $xferserverCardsHash notint\n$xferserverCardsContent" \ |
| 577 | + bad-delta-source \ |
| 578 | + "file $xferserverCardsHash zz\ |
| 579 | + $xferserverCardsSize\n$xferserverCardsContent" \ |
| 580 | + size-exceeds-input "file $xferserverCardsHash 99\n$xferserverCardsContent" \ |
| 581 | + size-too-small "file $xferserverCardsHash 5\n$xferserverCardsContent" \ |
| 582 | + size-at-end "file $xferserverCardsHash 5\n" \ |
| 583 | + size-with-nul "file $xferserverCardsHash 1\x002\n$xferserverCardsContent" \ |
| 584 | + content-wrong-hash \ |
| 585 | + "file $xferserverCardsHash $xferserverCardsSize\nWRONG TEXT!!\n" \ |
| 586 | + cfile-too-few "cfile $xferserverCardsHash\n" \ |
| 587 | + cfile-size-exceeds "cfile $xferserverCardsHash 5 99\nxx\n" \ |
| 588 | + uvfile-too-few "uvfile note.txt\n" \ |
| 589 | + uvfile-bad-mtime "uvfile note.txt notint $xferserverCardsZeros 3 0\nabc" \ |
| 590 | + uvfile-mtime-nul "uvfile note.txt 17\x0000 $xferserverCardsZeros 3 0\nabc" \ |
| 591 | + uvfile-bad-hash "$xferserverCardsUv nothash 3 0\nabc" \ |
| 592 | + uvfile-bad-size "$xferserverCardsUv $xferserverCardsZeros notint 0\nabc" \ |
| 593 | + uvfile-bad-flags "$xferserverCardsUv $xferserverCardsZeros 3 notint\nabc" \ |
| 594 | + uvfile-negative "uvfile note.txt -5 $xferserverCardsZeros 3 0\nabc" \ |
| 595 | + uvfile-wrong-hash "$xferserverCardsUv $xferserverCardsZeros 3 0\nabc" \ |
| 596 | +] { |
| 597 | + xferserver_cards_push $xferserverCardsBody |
| 598 | + test xfer-cards-reject-$xferserverCardsName \ |
| 599 | + {$xferserverCardsCode == 0 && $xferserverCardsErrors > 0 && |
| 600 | + $xferserverCardsStored == 0} |
| 601 | +} |
| 602 | + |
| 603 | +# A client that does not send a version is treated as older than 2.0 and |
| 604 | +# cannot be sent a SHA3 hash. When such a client asks for an unversioned |
| 605 | +# file the server answers with an error; a current client gets the file. |
| 606 | +write_file note.txt "hi\n" |
| 607 | +fossil unversioned add note.txt -R tgt.fossil --user tester |
| 608 | +set xferserverCardsUvgimme \ |
| 609 | + "login tester 0 0\npull x $xferserverCardsPcode\nuvgimme note.txt\n" |
| 610 | +write_file uvgimme.txt $xferserverCardsUvgimme |
| 611 | +fossil_raw test-xfer -R tgt.fossil uvgimme.txt |
| 612 | +test xfer-cards-uvgimme-old-client \ |
| 613 | + {$CODE == 0 |
| 614 | + && [holds_strings $RESULT [list {or\slater\srequired} "!uvfile note.txt"]]} |
| 615 | +write_file uvgimme.txt $CLIENT_VERSION_CARD$xferserverCardsUvgimme |
| 616 | +fossil_raw test-xfer -R tgt.fossil uvgimme.txt |
| 617 | +test xfer-cards-uvgimme-current-client \ |
| 618 | + {$CODE == 0 && [string first "uvfile note.txt" $RESULT] >= 0} |
| 619 | + |
| 620 | +fossil sql -R tgt.fossil \ |
| 621 | + "INSERT OR IGNORE INTO shun(uuid,mtime) VALUES('$xferserverCardsHash',0)" |
| 622 | +xferserver_cards_push "file $xferserverCardsHash\ |
| 623 | + $xferserverCardsSize\n$xferserverCardsContent" |
| 624 | +test xfer-cards-reject-shunned \ |
| 625 | + {$xferserverCardsCode == 0 && $xferserverCardsStored == 0} |
| 626 | + |
| 627 | +xferserver_leave |
| 628 | + |
| 629 | +############################################################################### |
| 630 | +# More cards sent to the server side of the sync protocol through |
| 631 | +# "fossil test-xfer": the cases of "file", "cfile", "uvfile", "gimme" |
| 632 | +# and "uvgimme" that xfer-cards.test and xfer-server.test do not send. |
| 633 | +# Each has a stated effect on the server's repository or on the reply, |
| 634 | +# and none may crash. |
| 635 | +# |
| 636 | +# The messages carry no login card, so they run with the permissions of |
| 637 | +# the user "nobody", which these tests set. |
| 638 | +# |
| 639 | + |
| 640 | + |
| 641 | +xferserver_enter edge |
| 642 | + |
| 643 | +# The answer of one SQL statement on the server, trimmed. |
| 644 | +# |
| 645 | +proc xferserver_sql {sql} { |
| 646 | + fossil sql -R srv.fossil $sql |
| 647 | + return [string trim $::RESULT] |
| 648 | +} |
| 649 | + |
| 650 | +# Send the cards BODY to the server after a client-version card and a |
| 651 | +# card of KIND, which is "push" or "pull". RESULT is the reply, as |
| 652 | +# bytes. xferserverEdgeErrors is the number of errors that the reply reports, |
| 653 | +# or -1 if it reports none at all. |
| 654 | +# |
| 655 | +proc xferserver_edge_send {kind body} { |
| 656 | + global xferserverEdgePcode xferserverEdgeErrors CLIENT_VERSION_CARD |
| 657 | + write_file msg.txt "${CLIENT_VERSION_CARD}$kind x $xferserverEdgePcode\n$body" |
| 658 | + fossil_raw test-xfer -R srv.fossil msg.txt |
| 659 | + set xferserverEdgeErrors -1 |
| 660 | + regexp {errors ([0-9]+)} $::RESULT -> xferserverEdgeErrors |
| 661 | +} |
| 662 | + |
| 663 | +# The hash that Fossil gives TEXT. |
| 664 | +# |
| 665 | +proc xferserver_hash {text} { |
| 666 | + write_file hash-me.txt $text |
| 667 | + fossil sha3sum hash-me.txt |
| 668 | + return [lindex $::RESULT 0] |
| 669 | +} |
| 670 | + |
| 671 | +# Content as a "cfile" card carries it: the size, then the zlib stream. |
| 672 | +# |
| 673 | +proc xferserver_compress {text} { |
| 674 | + return [binary format I [string length $text]][zlib compress $text] |
| 675 | +} |
| 676 | + |
| 677 | +# 1 if the server holds the content of the artifact HASH. |
| 678 | +# |
| 679 | +proc xferserver_holds {hash} { |
| 680 | + return [xferserver_sql "SELECT count(*) FROM blob |
| 681 | + WHERE uuid='$hash' AND size>=0"] |
| 682 | +} |
| 683 | + |
| 684 | +# Remove every trace of the artifacts HASHES from the server. |
| 685 | +# |
| 686 | +proc xferserver_forget {hashes} { |
| 687 | + set list '[join $hashes ',']' |
| 688 | + xferserver_sql "CREATE TEMP TABLE gone AS |
| 689 | + SELECT rid FROM blob WHERE uuid IN ($list); |
| 690 | + DELETE FROM delta WHERE rid IN gone OR srcid IN gone; |
| 691 | + DELETE FROM phantom WHERE rid IN gone; |
| 692 | + DELETE FROM unclustered WHERE rid IN gone; |
| 693 | + DELETE FROM private WHERE rid IN gone; |
| 694 | + DELETE FROM blob WHERE rid IN gone" |
| 695 | +} |
| 696 | + |
| 697 | +# Three versions of one file, so that the server stores deltas. |
| 698 | +set xferserverEdgeText "" |
| 699 | +for {set xferserverEdgeI 0} {$xferserverEdgeI < 40} {incr xferserverEdgeI} { |
| 700 | + append xferserverEdgeText \ |
| 701 | + "line $xferserverEdgeI of a file that is worth a delta\n" |
| 702 | +} |
| 703 | +foreach xferserverEdgeI {1 2 3} { |
| 704 | + append xferserverEdgeText "version $xferserverEdgeI\n" |
| 705 | + write_file a.txt $xferserverEdgeText |
| 706 | + if {$xferserverEdgeI == 1} {fossil add a.txt} |
| 707 | + fossil commit -m "xferedge-v$xferserverEdgeI" --no-warnings |
| 708 | + set xferserverEdgeVersion($xferserverEdgeI) $xferserverEdgeText |
| 709 | +} |
| 710 | +file copy .rep.fossil srv.fossil |
| 711 | +fossil unversioned list -R srv.fossil |
| 712 | +set xferserverEdgePcode [xferserver_sql \ |
| 713 | + "SELECT value FROM config WHERE name='project-code'"] |
| 714 | +xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'" |
| 715 | +set xferserverEdgeAbsent [string repeat 0123456789abcdef 4] |
| 716 | + |
| 717 | +############################################################################### |
| 718 | +# "file" cards. |
| 719 | + |
| 720 | +set xferserverEdgeNew "content that the server does not have yet\n" |
| 721 | +set xferserverEdgeNewHash [xferserver_hash $xferserverEdgeNew] |
| 722 | +set xferserverEdgeLen [string length $xferserverEdgeNew] |
| 723 | + |
| 724 | +foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
| 725 | + too-many-tokens \ |
| 726 | + "file $xferserverEdgeNewHash $xferserverEdgeAbsent 1\ |
| 727 | + $xferserverEdgeLen\n$xferserverEdgeNew" \ |
| 728 | + negative-size "file $xferserverEdgeNewHash -1\n$xferserverEdgeNew" \ |
| 729 | +] { |
| 730 | + xferserver_edge_send push $xferserverEdgeCard |
| 731 | + test xfer-edge-file-$xferserverEdgeName \ |
| 732 | + {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| 733 | + ![xferserver_holds $xferserverEdgeNewHash]} |
| 734 | +} |
| 735 | + |
| 736 | +# A delta whose source the server does not have is kept as it is, with a |
| 737 | +# phantom for the source, and is public. |
| 738 | +xferserver_edge_send push \ |
| 739 | + "file $xferserverEdgeNewHash $xferserverEdgeAbsent 9\nnot-delta" |
| 740 | +test xfer-edge-file-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0} |
| 741 | +test_eq xfer-edge-file-dangling-delta-stored [xferserver_sql "SELECT |
| 742 | + (SELECT size FROM blob WHERE uuid='$xferserverEdgeAbsent'), |
| 743 | + (SELECT count(*) FROM delta, blob a, blob b WHERE delta.rid=a.rid |
| 744 | + AND delta.srcid=b.rid AND a.uuid='$xferserverEdgeNewHash' |
| 745 | + AND b.uuid='$xferserverEdgeAbsent'), |
| 746 | + (SELECT count(*) FROM private, blob WHERE private.rid=blob.rid |
| 747 | + AND uuid='$xferserverEdgeNewHash')"] {-1|1|0} |
| 748 | +xferserver_forget [list $xferserverEdgeNewHash $xferserverEdgeAbsent] |
| 749 | + |
| 750 | +############################################################################### |
| 751 | +# "cfile" cards. |
| 752 | + |
| 753 | +set xferserverEdgeZ [xferserver_compress $xferserverEdgeNew] |
| 754 | +set xferserverEdgeZLen [string length $xferserverEdgeZ] |
| 755 | +foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
| 756 | + too-many-tokens \ |
| 757 | + "cfile $xferserverEdgeNewHash $xferserverEdgeAbsent 1 $xferserverEdgeLen\ |
| 758 | + $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
| 759 | + bad-hash \ |
| 760 | + "cfile nothash $xferserverEdgeLen $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
| 761 | + bad-usize \ |
| 762 | + "cfile $xferserverEdgeNewHash notint\ |
| 763 | + $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
| 764 | + bad-csize \ |
| 765 | + "cfile $xferserverEdgeNewHash $xferserverEdgeLen notint\n$xferserverEdgeZ" \ |
| 766 | + negative-usize \ |
| 767 | + "cfile $xferserverEdgeNewHash -1 $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
| 768 | + negative-csize \ |
| 769 | + "cfile $xferserverEdgeNewHash $xferserverEdgeLen -1\n$xferserverEdgeZ" \ |
| 770 | + bad-source \ |
| 771 | + "cfile $xferserverEdgeNewHash zz $xferserverEdgeLen\ |
| 772 | + $xferserverEdgeZLen\n$xferserverEdgeZ" \ |
| 773 | +] { |
| 774 | + xferserver_edge_send push $xferserverEdgeCard |
| 775 | + test xfer-edge-cfile-$xferserverEdgeName \ |
| 776 | + {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| 777 | + ![xferserver_holds $xferserverEdgeNewHash]} |
| 778 | +} |
| 779 | + |
| 780 | +xferserver_edge_send push "cfile $xferserverEdgeNewHash $xferserverEdgeLen\ |
| 781 | +$xferserverEdgeZLen\n$xferserverEdgeZ" |
| 782 | +test xfer-edge-cfile-accepted \ |
| 783 | + {$CODE == 0 && $xferserverEdgeErrors == 0 && |
| 784 | + [xferserver_holds $xferserverEdgeNewHash]} |
| 785 | +fossil artifact $xferserverEdgeNewHash -R srv.fossil cfile.out |
| 786 | +test_eq xfer-edge-cfile-content [read_file cfile.out] $xferserverEdgeNew |
| 787 | + |
| 788 | +# The size recorded for the artifact is that of its content, not of its |
| 789 | +# compressed form. |
| 790 | +test_eq xfer-edge-cfile-size-recorded [xferserver_sql "SELECT size FROM blob |
| 791 | + WHERE uuid='$xferserverEdgeNewHash'"] $xferserverEdgeLen |
| 792 | + |
| 793 | +# Content that does not have the hash or the size on the card is refused |
| 794 | +# with an error, as it is for a "file" card. |
| 795 | +set xferserverEdgeWrong "content that is not what its card says\n" |
| 796 | +set xferserverEdgeZ [xferserver_compress $xferserverEdgeWrong] |
| 797 | +xferserver_edge_send push "cfile $xferserverEdgeAbsent\ |
| 798 | +[string length $xferserverEdgeWrong]\ |
| 799 | +[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 800 | +test xfer-edge-cfile-wrong-hash {$CODE == 0 && $xferserverEdgeErrors > 0} |
| 801 | +test xfer-edge-cfile-wrong-hash-not-stored \ |
| 802 | + {![xferserver_holds $xferserverEdgeAbsent]} |
| 803 | +set xferserverEdgeSized "content with the wrong size on its card\n" |
| 804 | +set xferserverEdgeSizedHash [xferserver_hash $xferserverEdgeSized] |
| 805 | +set xferserverEdgeZ [xferserver_compress $xferserverEdgeSized] |
| 806 | +xferserver_edge_send push "cfile $xferserverEdgeSizedHash 7777\ |
| 807 | +[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 808 | +test xfer-edge-cfile-wrong-size \ |
| 809 | + {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| 810 | + ![xferserver_holds $xferserverEdgeSizedHash]} |
| 811 | +xferserver_edge_send push \ |
| 812 | + "cfile $xferserverEdgeAbsent 16 20\n\x00\x00\x00\x10not zlib data !!" |
| 813 | +test xfer-edge-cfile-not-compressed \ |
| 814 | + {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| 815 | + ![xferserver_holds $xferserverEdgeAbsent]} |
| 816 | + |
| 817 | +# A shunned artifact is not stored. |
| 818 | +set xferserverEdgeShun "content that the server has shunned\n" |
| 819 | +set xferserverEdgeShunHash [xferserver_hash $xferserverEdgeShun] |
| 820 | +xferserver_sql "INSERT INTO shun(uuid,mtime)\ |
| 821 | + VALUES('$xferserverEdgeShunHash',0)" |
| 822 | +set xferserverEdgeZ [xferserver_compress $xferserverEdgeShun] |
| 823 | +xferserver_edge_send push "cfile $xferserverEdgeShunHash\ |
| 824 | +[string length $xferserverEdgeShun]\ |
| 825 | +[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 826 | +test xfer-edge-cfile-shunned \ |
| 827 | + {$CODE == 0 && ![xferserver_holds $xferserverEdgeShunHash]} |
| 828 | + |
| 829 | +# A compressed delta whose source the server does not have is kept as it |
| 830 | +# is. Its hash cannot be checked yet; its size can, and a delta that |
| 831 | +# does not make content of the size on the card is refused. |
| 832 | +set xferserverEdgeAbsent2 [string repeat fedcba9876543210 4] |
| 833 | +write_file delta-src.txt $xferserverEdgeVersion(1) |
| 834 | +write_file delta-tgt.txt "$xferserverEdgeVersion(1)and a line of its own\n" |
| 835 | +fossil test-delta-create delta-src.txt delta-tgt.txt delta.out |
| 836 | +set xferserverEdgeTgtHash [xferserver_hash [read_file delta-tgt.txt]] |
| 837 | +set xferserverEdgeZ [xferserver_compress [read_file delta.out]] |
| 838 | +xferserver_edge_send push "cfile $xferserverEdgeTgtHash\ |
| 839 | +$xferserverEdgeAbsent2 7777\ |
| 840 | +[string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 841 | +test xfer-edge-cfile-dangling-delta-wrong-size \ |
| 842 | + {$CODE == 0 && $xferserverEdgeErrors > 0} |
| 843 | +xferserver_edge_send push "cfile $xferserverEdgeTgtHash $xferserverEdgeAbsent2\ |
| 844 | +[file size delta-tgt.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 845 | +test xfer-edge-cfile-dangling-delta {$CODE == 0 && $xferserverEdgeErrors == 0} |
| 846 | +test_eq xfer-edge-cfile-dangling-delta-stored [xferserver_sql "SELECT a.size |
| 847 | + FROM delta, blob a WHERE delta.rid=a.rid |
| 848 | + AND a.uuid='$xferserverEdgeTgtHash'"] \ |
| 849 | + [file size delta-tgt.txt] |
| 850 | +xferserver_forget [list $xferserverEdgeTgtHash $xferserverEdgeAbsent2] |
| 851 | + |
| 852 | +# Content that is too short to hold a size, or that is not compressed |
| 853 | +# data, is refused as malformed, whether or not the card gives a size |
| 854 | +# for the content. |
| 855 | +foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
| 856 | + short-content "cfile $xferserverEdgeAbsent 5 3\nabc\n" \ |
| 857 | + no-usize-short "cfile $xferserverEdgeAbsent 0 3\nabc\n" \ |
| 858 | + no-usize-not-compressed \ |
| 859 | + "cfile $xferserverEdgeAbsent 0 20\n\x00\x00\x00\x10not zlib data !!" \ |
| 860 | +] { |
| 861 | + xferserver_edge_send push $xferserverEdgeCard |
| 862 | + test xfer-edge-cfile-$xferserverEdgeName \ |
| 863 | + {$CODE == 0 && $xferserverEdgeErrors > 0 && |
| 864 | + [string first {malformed+cfile+content} $RESULT] >= 0 && |
| 865 | + ![xferserver_holds $xferserverEdgeAbsent]} |
| 866 | +} |
| 867 | + |
| 868 | +# A compressed delta whose source the server has is applied and checked. |
| 869 | +# One that does not apply, and one that makes content with another hash |
| 870 | +# than the card gives, are refused; one that makes the content that the |
| 871 | +# card names is stored. |
| 872 | +set xferserverEdgeSrcHash [xferserver_hash $xferserverEdgeVersion(1)] |
| 873 | +test xfer-edge-cfile-delta-setup-source-held \ |
| 874 | + {[xferserver_holds $xferserverEdgeSrcHash] == 1} |
| 875 | +write_file delta-tgt2.txt "$xferserverEdgeVersion(1)and another line\n" |
| 876 | +fossil test-delta-create delta-src.txt delta-tgt2.txt delta2.out |
| 877 | +set xferserverEdgeTgt2Hash [xferserver_hash [read_file delta-tgt2.txt]] |
| 878 | +set xferserverEdgeDelta [read_file delta2.out] |
| 879 | +# The same delta without the checksum that ends it. |
| 880 | +regsub {[0-9A-Za-z_~]+;$} $xferserverEdgeDelta {} xferserverEdgeBadDelta |
| 881 | +test xfer-edge-cfile-delta-setup-cut \ |
| 882 | + {[string length $xferserverEdgeBadDelta] > 0 && |
| 883 | + [string length $xferserverEdgeBadDelta] |
| 884 | + < [string length $xferserverEdgeDelta]} |
| 885 | +foreach {xferserverEdgeName xferserverEdgeHash xferserverEdgeBody |
| 886 | + xferserverEdgeStored} [list \ |
| 887 | + does-not-apply $xferserverEdgeTgt2Hash $xferserverEdgeBadDelta 0 \ |
| 888 | + other-hash $xferserverEdgeAbsent2 $xferserverEdgeDelta 0 \ |
| 889 | + accepted $xferserverEdgeTgt2Hash $xferserverEdgeDelta 1 \ |
| 890 | +] { |
| 891 | + set xferserverEdgeZ [xferserver_compress $xferserverEdgeBody] |
| 892 | + xferserver_edge_send push "cfile $xferserverEdgeHash $xferserverEdgeSrcHash\ |
| 893 | +[file size delta-tgt2.txt] [string length $xferserverEdgeZ]\n$xferserverEdgeZ" |
| 894 | + test xfer-edge-cfile-delta-$xferserverEdgeName \ |
| 895 | + {$CODE == 0 && ($xferserverEdgeErrors > 0) != $xferserverEdgeStored |
| 896 | + && [xferserver_holds $xferserverEdgeHash] == $xferserverEdgeStored} |
| 897 | +} |
| 898 | +fossil artifact $xferserverEdgeTgt2Hash -R srv.fossil cfile-delta.out |
| 899 | +test_eq xfer-edge-cfile-delta-content [read_file cfile-delta.out] \ |
| 900 | + [read_file delta-tgt2.txt] |
| 901 | +xferserver_forget [list $xferserverEdgeTgt2Hash] |
| 902 | + |
| 903 | +############################################################################### |
| 904 | +# "uvfile" cards. |
| 905 | + |
| 906 | +set xferserverEdgeUv "an unversioned note\n" |
| 907 | +set xferserverEdgeUvHash [xferserver_hash $xferserverEdgeUv] |
| 908 | +set xferserverEdgeUvLen [string length $xferserverEdgeUv] |
| 909 | +proc xferserver_uv {name} { |
| 910 | + return [xferserver_sql "SELECT mtime, sz, encoding, hash IS NOT NULL |
| 911 | + FROM unversioned WHERE name='$name'"] |
| 912 | +} |
| 913 | + |
| 914 | +foreach {xferserverEdgeName xferserverEdgeCard} [list \ |
| 915 | + five-tokens \ |
| 916 | + "uvfile note.txt 1700000000 $xferserverEdgeUvHash\ |
| 917 | + $xferserverEdgeUvLen\n$xferserverEdgeUv" \ |
| 918 | + bad-filename \ |
| 919 | + "uvfile ../note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\ |
| 920 | + 0\n$xferserverEdgeUv" \ |
| 921 | +] { |
| 922 | + xferserver_edge_send push $xferserverEdgeCard |
| 923 | + test xfer-edge-uvfile-$xferserverEdgeName \ |
| 924 | + {$CODE == 0 && $xferserverEdgeErrors > 0} |
| 925 | +} |
| 926 | +test_eq xfer-edge-uvfile-none-stored [xferserver_sql \ |
| 927 | + "SELECT count(*) FROM unversioned"] 0 |
| 928 | + |
| 929 | +xferserver_edge_send push \ |
| 930 | + "uvfile note.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\ |
| 931 | + 0\n$xferserverEdgeUv" |
| 932 | +test xfer-edge-uvfile-accepted {$CODE == 0 && $xferserverEdgeErrors == 0} |
| 933 | +test_eq xfer-edge-uvfile-stored [xferserver_uv note.txt] \ |
| 934 | + "1700000000|$xferserverEdgeUvLen|0|1" |
| 935 | + |
| 936 | +# Content that compresses well is stored compressed. |
| 937 | +set xferserverEdgeBig [string repeat "the same line again and again\n" 200] |
| 938 | +set xferserverEdgeBigHash [xferserver_hash $xferserverEdgeBig] |
| 939 | +xferserver_edge_send push "uvfile big.txt 1700000000 $xferserverEdgeBigHash\ |
| 940 | +[string length $xferserverEdgeBig] 0\n$xferserverEdgeBig" |
| 941 | +test_eq xfer-edge-uvfile-compressed [xferserver_uv big.txt] \ |
| 942 | + "1700000000|[string length $xferserverEdgeBig]|1|1" |
| 943 | + |
| 944 | +# The same content with a newer time and no content: only the time |
| 945 | +# changes. |
| 946 | +xferserver_edge_send push \ |
| 947 | + "uvfile note.txt 1700000500 $xferserverEdgeUvHash $xferserverEdgeUvLen 4\n" |
| 948 | +test_eq xfer-edge-uvfile-time-only [xferserver_uv note.txt] \ |
| 949 | + "1700000500|$xferserverEdgeUvLen|0|1" |
| 950 | + |
| 951 | +# Older content does not replace newer. |
| 952 | +set xferserverEdgeOld "an older note\n" |
| 953 | +xferserver_edge_send push "uvfile note.txt 1600000000\ |
| 954 | +[xferserver_hash $xferserverEdgeOld]\ |
| 955 | +[string length $xferserverEdgeOld] 0\n$xferserverEdgeOld" |
| 956 | +test xfer-edge-uvfile-older {$CODE == 0} |
| 957 | +test_eq xfer-edge-uvfile-older-ignored [xferserver_sql "SELECT hash |
| 958 | + FROM unversioned WHERE name='note.txt'"] $xferserverEdgeUvHash |
| 959 | + |
| 960 | +# A newer deletion empties the file but keeps its name. |
| 961 | +xferserver_edge_send push "uvfile note.txt 1700001000 - 0 1\n" |
| 962 | +test xfer-edge-uvfile-delete {$CODE == 0 && $xferserverEdgeErrors == 0} |
| 963 | +test_eq xfer-edge-uvfile-deleted [xferserver_uv note.txt] {1700001000|0|0|0} |
| 964 | + |
| 965 | +# Without the permission to write unversioned files, nothing is stored. |
| 966 | +xferserver_sql "UPDATE user SET cap='oi' WHERE login='nobody'" |
| 967 | +xferserver_edge_send push \ |
| 968 | + "uvfile other.txt 1700000000 $xferserverEdgeUvHash $xferserverEdgeUvLen\ |
| 969 | + 0\n$xferserverEdgeUv" |
| 970 | +test xfer-edge-uvfile-no-permission {$CODE == 0 && $xferserverEdgeErrors > 0} |
| 971 | +test_eq xfer-edge-uvfile-no-permission-stored [xferserver_sql "SELECT count(*) |
| 972 | + FROM unversioned WHERE name='other.txt'"] 0 |
| 973 | +xferserver_sql "UPDATE user SET cap='oiy' WHERE login='nobody'" |
| 974 | + |
| 975 | +############################################################################### |
| 976 | +# "uvgimme" cards. |
| 977 | + |
| 978 | +xferserver_edge_send pull "uvgimme big.txt\n" |
| 979 | +test xfer-edge-uvgimme-file {$CODE == 0 && [string first \ |
| 980 | + "uvfile big.txt 1700000000 $xferserverEdgeBigHash [string length\ |
| 981 | + $xferserverEdgeBig] 0\n$xferserverEdgeBig" \ |
| 982 | + $RESULT] >= 0} |
| 983 | +xferserver_edge_send pull "uvgimme note.txt\n" |
| 984 | +test xfer-edge-uvgimme-deleted \ |
| 985 | + {$CODE == 0 && |
| 986 | + [string first "uvfile note.txt 1700001000 - 0 1\n" $RESULT] >= 0} |
| 987 | +xferserver_edge_send pull "uvgimme no-such-file.txt\n" |
| 988 | +test xfer-edge-uvgimme-unknown \ |
| 989 | + {$CODE == 0 && [string first "uvfile no-such-file.txt" $RESULT] < 0} |
| 990 | + |
| 991 | +############################################################################### |
| 992 | +# "gimme" cards. |
| 993 | + |
| 994 | +proc xferserver_file_hash {version} { |
| 995 | + return [xferserver_sql "SELECT uuid FROM blob, mlink, event |
| 996 | + WHERE blob.rid=mlink.fid AND mlink.mid=event.objid |
| 997 | + AND event.comment='xferedge-v$version'"] |
| 998 | +} |
| 999 | +set xferserverEdgeV1 [xferserver_file_hash 1] |
| 1000 | +set xferserverEdgeV2 [xferserver_file_hash 2] |
| 1001 | +set xferserverEdgeV3 [xferserver_file_hash 3] |
| 1002 | + |
| 1003 | +# The server sends a version as a delta from the version before it, |
| 1004 | +# which the client is likely to have. The first version has none and |
| 1005 | +# goes whole, although the server stores it as a delta. |
| 1006 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1007 | +test xfer-edge-gimme-delta-from-parent \ |
| 1008 | + {$CODE == 0 && |
| 1009 | + [string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0} |
| 1010 | +xferserver_edge_send pull "gimme $xferserverEdgeV1\n" |
| 1011 | +test xfer-edge-gimme-whole {$CODE == 0 && [string first \ |
| 1012 | + "file $xferserverEdgeV1 [string length $xferserverEdgeVersion(1)]\n"\ |
| 1013 | + $RESULT] >= 0} |
| 1014 | + |
| 1015 | +# An artifact that the server does not have, and one that it has |
| 1016 | +# shunned, are not sent. |
| 1017 | +xferserver_edge_send pull "gimme $xferserverEdgeAbsent\n" |
| 1018 | +test xfer-edge-gimme-absent \ |
| 1019 | + {$CODE == 0 && [string first "file $xferserverEdgeAbsent" $RESULT] < 0} |
| 1020 | +xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV3',0)" |
| 1021 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1022 | +test xfer-edge-gimme-shunned \ |
| 1023 | + {$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0} |
| 1024 | +xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV3'" |
| 1025 | + |
| 1026 | +# A delta is not sent from a shunned source: the content goes whole. |
| 1027 | +xferserver_sql "INSERT INTO shun(uuid,mtime) VALUES('$xferserverEdgeV2',0)" |
| 1028 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1029 | +test xfer-edge-gimme-shunned-source {$CODE == 0 && [string first \ |
| 1030 | + "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\ |
| 1031 | + $RESULT] >= 0} |
| 1032 | +xferserver_sql "DELETE FROM shun WHERE uuid='$xferserverEdgeV2'" |
| 1033 | + |
| 1034 | +# A private artifact is not sent to a client that has not asked for |
| 1035 | +# private content, and a delta is not sent from a private source. |
| 1036 | +xferserver_sql "INSERT INTO private SELECT rid FROM blob |
| 1037 | + WHERE uuid='$xferserverEdgeV3'" |
| 1038 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1039 | +test xfer-edge-gimme-private \ |
| 1040 | + {$CODE == 0 && [string first "file $xferserverEdgeV3" $RESULT] < 0} |
| 1041 | +xferserver_sql "DELETE FROM private" |
| 1042 | +xferserver_sql "INSERT INTO private SELECT rid FROM blob |
| 1043 | + WHERE uuid='$xferserverEdgeV2'" |
| 1044 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1045 | +test xfer-edge-gimme-private-source {$CODE == 0 && [string first \ |
| 1046 | + "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\ |
| 1047 | + $RESULT] >= 0} |
| 1048 | +xferserver_sql "DELETE FROM private" |
| 1049 | + |
| 1050 | +# A delta is not sent from a version that the server holds only as a |
| 1051 | +# delta whose own source has not arrived, because that version cannot be |
| 1052 | +# rebuilt: the content goes whole. |
| 1053 | +set xferserverEdgeMissing [string repeat 0a1b2c3d 8] |
| 1054 | +set xferserverEdgeV2Src [xferserver_sql "SELECT srcid FROM delta, blob |
| 1055 | + WHERE delta.rid=blob.rid AND uuid='$xferserverEdgeV2'"] |
| 1056 | +xferserver_sql "INSERT INTO blob(rcvid,size,uuid) |
| 1057 | + VALUES(0,-1,'$xferserverEdgeMissing'); |
| 1058 | + INSERT INTO phantom SELECT rid FROM blob |
| 1059 | + WHERE uuid='$xferserverEdgeMissing'; |
| 1060 | + REPLACE INTO delta(rid,srcid) SELECT a.rid, b.rid FROM blob a, blob b |
| 1061 | + WHERE a.uuid='$xferserverEdgeV2' AND b.uuid='$xferserverEdgeMissing'" |
| 1062 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1063 | +test xfer-edge-gimme-source-cannot-be-rebuilt {$CODE == 0 && [string first \ |
| 1064 | + "file $xferserverEdgeV3 [string length $xferserverEdgeVersion(3)]\n"\ |
| 1065 | + $RESULT] >= 0} |
| 1066 | +if {$xferserverEdgeV2Src eq ""} { |
| 1067 | + xferserver_sql "DELETE FROM delta WHERE rid=(SELECT rid FROM blob |
| 1068 | + WHERE uuid='$xferserverEdgeV2')" |
| 1069 | +} else { |
| 1070 | + xferserver_sql "UPDATE delta SET srcid=$xferserverEdgeV2Src |
| 1071 | + WHERE rid=(SELECT rid FROM blob WHERE uuid='$xferserverEdgeV2')" |
| 1072 | +} |
| 1073 | +xferserver_forget [list $xferserverEdgeMissing] |
| 1074 | +xferserver_edge_send pull "gimme $xferserverEdgeV3\n" |
| 1075 | +test xfer-edge-gimme-delta-again \ |
| 1076 | + {$CODE == 0 && |
| 1077 | + [string first "file $xferserverEdgeV3 $xferserverEdgeV2 " $RESULT] >= 0} |
| 1078 | + |
| 1079 | +fossil test-integrity -R srv.fossil |
| 1080 | +test xfer-edge-integrity {$CODE == 0} |
| 1081 | + |
| 1082 | +############################################################################### |
| 1083 | +# A repository that has never held an unversioned file has no table for |
| 1084 | +# them. A request for one is answered like any other request for a file |
| 1085 | +# that is not there. |
| 1086 | + |
| 1087 | +fossil init fresh.fossil |
| 1088 | +fossil sql -R fresh.fossil "UPDATE user SET cap='oiy' WHERE login='nobody'" |
| 1089 | +fossil sql -R fresh.fossil "SELECT value FROM config WHERE name='project-code'" |
| 1090 | +write_file msg.txt \ |
| 1091 | + "${CLIENT_VERSION_CARD}pull x [string trim $RESULT]\nuvgimme note.txt\n" |
| 1092 | +fossil_raw test-xfer -R fresh.fossil msg.txt |
| 1093 | +test xfer-edge-uvgimme-no-table \ |
| 1094 | + {$CODE == 0 && [string first "Database error" $RESULT] < 0} |
| 1095 | + |
| 1096 | +xferserver_leave |
| 1097 | + |
| 1098 | +############################################################################### |
| 1099 | +# The login card of the sync protocol, checked by a server as it is on a |
| 1100 | +# network. A real client syncs with a real server through |
| 1101 | +# standin/scenario-wire.tcl, which hands each request to "fossil http" |
| 1102 | +# on the server's repository without --localauth, so the server decides |
| 1103 | +# what the client may do from the login card alone. Fossil puts no login |
| 1104 | +# card on a request that goes through a transport command, so the |
| 1105 | +# stand-in adds the card, made as http_build_login_card() makes it. |
| 1106 | + |
| 1107 | +xferserver_enter login |
| 1108 | + |
| 1109 | +write_file a.txt "first\n" |
| 1110 | +fossil add a.txt |
| 1111 | +fossil commit -m "xferlogin-c1" --no-warnings |
| 1112 | +file copy .rep.fossil srv.fossil |
| 1113 | +file copy .rep.fossil cli.fossil |
| 1114 | + |
| 1115 | +set xferserverLoginWire [file join [pwd] wire.tcl] |
| 1116 | +file copy [file join $::testfiledir standin scenario-wire.tcl] \ |
| 1117 | + $xferserverLoginWire |
| 1118 | +set xferserverLoginWire "\"[info nameofexecutable]\" \"$xferserverLoginWire\"" |
| 1119 | +set ::env(SCN_EXE) $::fossilexe |
| 1120 | +set ::env(SCN_REPO) [file join [pwd] srv.fossil] |
| 1121 | +set ::env(SCN_FAULT) 0 |
| 1122 | +set ::env(SCN_AUTH) 1 |
| 1123 | +fossil sql -R srv.fossil "SELECT value FROM config WHERE name='project-code'" |
| 1124 | +set ::env(SCN_PROJECT) [string trim $RESULT] |
| 1125 | + |
| 1126 | +# Sync the client with the server as USERINFO, which is "user:password" |
| 1127 | +# or empty for no login card. VERB is pull, push or sync. |
| 1128 | +# |
| 1129 | +proc xferserver_login_sync {verb userinfo} { |
| 1130 | + global xferserverLoginWire |
| 1131 | + if {$userinfo ne ""} {set ::env(SCN_LOGIN) $userinfo} |
| 1132 | + fossil_raw -seconds 60 $verb http://xferlogin.invalid/x --once \ |
| 1133 | + --transport-command $xferserverLoginWire -R cli.fossil |
| 1134 | + unset -nocomplain ::env(SCN_LOGIN) |
| 1135 | +} |
| 1136 | + |
| 1137 | +# The number of artifacts with content that the repository holds. |
| 1138 | +# |
| 1139 | +proc xferserver_blobs {repo} { |
| 1140 | + fossil sql -R $repo "SELECT count(*) FROM blob WHERE size>=0" |
| 1141 | + return [string trim $::RESULT] |
| 1142 | +} |
| 1143 | + |
| 1144 | +# Give the server something that the client does not have. |
| 1145 | +# |
| 1146 | +proc xferserver_login_new_on_server {} { |
| 1147 | + global xferserverLoginN |
| 1148 | + write_file srv-[incr xferserverLoginN].txt \ |
| 1149 | + "content number $xferserverLoginN\n" |
| 1150 | + fossil test-content-put srv-$xferserverLoginN.txt -R srv.fossil |
| 1151 | +} |
| 1152 | +set xferserverLoginN 0 |
| 1153 | + |
| 1154 | +# Nobody may do anything; the user "tester" may read and write. |
| 1155 | +xferserver_sql "UPDATE user SET cap='' WHERE login IN ('nobody','anonymous')" |
| 1156 | +fossil user new tester "" secret -R srv.fossil |
| 1157 | +xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'" |
| 1158 | +test_eq xfer-login-password-stored-hashed \ |
| 1159 | + [xferserver_sql "SELECT length(pw) FROM user WHERE login='tester'"] 40 |
| 1160 | + |
| 1161 | +############################################################################### |
| 1162 | +# With no login card the client is "nobody", who may not read. |
| 1163 | + |
| 1164 | +xferserver_login_new_on_server |
| 1165 | +set xferserverLoginBefore [xferserver_blobs cli.fossil] |
| 1166 | +xferserver_login_sync pull "" |
| 1167 | +test xfer-login-nobody-refused \ |
| 1168 | + {$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0} |
| 1169 | +test_eq xfer-login-nobody-got-nothing [xferserver_blobs cli.fossil] \ |
| 1170 | + $xferserverLoginBefore |
| 1171 | + |
| 1172 | +############################################################################### |
| 1173 | +# The right password gives the user's permissions. |
| 1174 | + |
| 1175 | +xferserver_login_sync pull tester:secret |
| 1176 | +test xfer-login-accepted {$CODE == 0} |
| 1177 | +test_eq xfer-login-accepted-pulled [xferserver_blobs cli.fossil] \ |
| 1178 | + [expr {$xferserverLoginBefore + 1}] |
| 1179 | + |
| 1180 | +# The same for a push. |
| 1181 | +write_file cli-1.txt "content from the client\n" |
| 1182 | +fossil test-content-put cli-1.txt -R cli.fossil |
| 1183 | +set xferserverLoginBefore [xferserver_blobs srv.fossil] |
| 1184 | +xferserver_login_sync push tester:secret |
| 1185 | +test xfer-login-push-accepted {$CODE == 0} |
| 1186 | +test_eq xfer-login-push-arrived [xferserver_blobs srv.fossil] \ |
| 1187 | + [expr {$xferserverLoginBefore + 1}] |
| 1188 | + |
| 1189 | +############################################################################### |
| 1190 | +# A wrong password, and a user that the server does not know. |
| 1191 | + |
| 1192 | +xferserver_login_new_on_server |
| 1193 | +set xferserverLoginBefore [xferserver_blobs cli.fossil] |
| 1194 | +foreach {xferserverLoginName xferserverLoginUser} { |
| 1195 | + wrong-password tester:wrong |
| 1196 | + unknown-user stranger:secret |
| 1197 | +} { |
| 1198 | + xferserver_login_sync pull $xferserverLoginUser |
| 1199 | + test xfer-login-$xferserverLoginName \ |
| 1200 | + {$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
| 1201 | + test_eq xfer-login-$xferserverLoginName-got-nothing \ |
| 1202 | + [xferserver_blobs cli.fossil] \ |
| 1203 | + $xferserverLoginBefore |
| 1204 | +} |
| 1205 | + |
| 1206 | +# The special users cannot be logged in as with a password, whatever |
| 1207 | +# password the server has for them. |
| 1208 | +xferserver_sql "UPDATE user SET pw='secret', cap='oi' WHERE login='developer'" |
| 1209 | +xferserver_login_sync pull developer:secret |
| 1210 | +test xfer-login-special-user-refused {$CODE != 0} |
| 1211 | +test_eq xfer-login-special-user-got-nothing [xferserver_blobs cli.fossil] \ |
| 1212 | + $xferserverLoginBefore |
| 1213 | + |
| 1214 | +############################################################################### |
| 1215 | +# A user with read permission only may not push. |
| 1216 | + |
| 1217 | +xferserver_sql "UPDATE user SET cap='o' WHERE login='tester'" |
| 1218 | +write_file cli-2.txt "more content from the client\n" |
| 1219 | +fossil test-content-put cli-2.txt -R cli.fossil |
| 1220 | +set xferserverLoginSrvBefore [xferserver_blobs srv.fossil] |
| 1221 | +xferserver_login_sync push tester:secret |
| 1222 | +test xfer-login-push-without-write \ |
| 1223 | + {$CODE != 0 && [string first "not authorized to write" $RESULT] >= 0} |
| 1224 | +test_eq xfer-login-push-without-write-nothing-arrived \ |
| 1225 | + [xferserver_blobs srv.fossil] $xferserverLoginSrvBefore |
| 1226 | +xferserver_sql "UPDATE user SET cap='oi' WHERE login='tester'" |
| 1227 | + |
| 1228 | +############################################################################### |
| 1229 | +# A server that keeps the password as the user typed it still accepts the |
| 1230 | +# login, and still refuses a wrong password. |
| 1231 | + |
| 1232 | +xferserver_sql "UPDATE user SET pw='secret' WHERE login='tester'" |
| 1233 | +xferserver_login_sync pull tester:wrong |
| 1234 | +test xfer-login-cleartext-wrong \ |
| 1235 | + {$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
| 1236 | +set xferserverLoginBefore [xferserver_blobs cli.fossil] |
| 1237 | +xferserver_login_sync pull tester:secret |
| 1238 | +test xfer-login-cleartext-accepted {$CODE == 0} |
| 1239 | +test_eq xfer-login-cleartext-pulled [xferserver_blobs cli.fossil] \ |
| 1240 | + [expr {$xferserverLoginBefore + 1}] |
| 1241 | + |
| 1242 | +############################################################################### |
| 1243 | +# A login card for "nobody" or "anonymous" is accepted without a |
| 1244 | +# password, and gives the permissions of "nobody". |
| 1245 | + |
| 1246 | +xferserver_login_new_on_server |
| 1247 | +set xferserverLoginBefore [xferserver_blobs cli.fossil] |
| 1248 | +foreach xferserverLoginUser {nobody anonymous} { |
| 1249 | + xferserver_login_sync pull $xferserverLoginUser:anything |
| 1250 | + test xfer-login-as-$xferserverLoginUser \ |
| 1251 | + {$CODE != 0 && [string first "not authorized to read" $RESULT] >= 0} |
| 1252 | +} |
| 1253 | +xferserver_sql "UPDATE user SET cap='o' WHERE login='nobody'" |
| 1254 | +xferserver_login_sync pull nobody:anything |
| 1255 | +test xfer-login-as-nobody-who-may-read {$CODE == 0} |
| 1256 | +test_eq xfer-login-as-nobody-pulled [xferserver_blobs cli.fossil] \ |
| 1257 | + [expr {$xferserverLoginBefore + 1}] |
| 1258 | +xferserver_sql "UPDATE user SET cap='' WHERE login='nobody'" |
| 1259 | + |
| 1260 | +############################################################################### |
| 1261 | +# A web server that has already checked the user's password says so in |
| 1262 | +# REMOTE_USER. The login card of that user is then accepted whatever |
| 1263 | +# its signature, but only if the remote_user_ok setting is on. |
| 1264 | + |
| 1265 | +xferserver_login_new_on_server |
| 1266 | +set xferserverLoginBefore [xferserver_blobs cli.fossil] |
| 1267 | +set ::env(REMOTE_USER) tester |
| 1268 | +xferserver_login_sync pull tester:wrong |
| 1269 | +test xfer-login-remote-user-setting-off \ |
| 1270 | + {$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
| 1271 | +xferserver_sql "REPLACE INTO config(name,value,mtime) |
| 1272 | + VALUES('remote_user_ok',1,now())" |
| 1273 | +xferserver_login_sync pull stranger:wrong |
| 1274 | +test xfer-login-remote-user-other-name \ |
| 1275 | + {$CODE != 0 && [string first "login failed" $RESULT] >= 0} |
| 1276 | +test_eq xfer-login-remote-user-nothing-yet [xferserver_blobs cli.fossil] \ |
| 1277 | + $xferserverLoginBefore |
| 1278 | +xferserver_login_sync pull tester:wrong |
| 1279 | +test xfer-login-remote-user-accepted {$CODE == 0} |
| 1280 | +test_eq xfer-login-remote-user-pulled [xferserver_blobs cli.fossil] \ |
| 1281 | + [expr {$xferserverLoginBefore + 1}] |
| 1282 | +unset ::env(REMOTE_USER) |
| 1283 | +xferserver_sql "DELETE FROM config WHERE name='remote_user_ok'" |
| 1284 | + |
| 1285 | +############################################################################### |
| 1286 | +# Requests written here and given to "fossil http" as a web server gives |
| 1287 | +# them, so that the login card can be wrong in one way at a time and can |
| 1288 | +# come in a cookie. |
| 1289 | + |
| 1290 | +set xferserverLoginProject $::env(SCN_PROJECT) |
| 1291 | +set xferserverLoginPull "pull x $xferserverLoginProject\n" |
| 1292 | + |
| 1293 | +# Give the server the cards BODY in a request with the extra header lines |
| 1294 | +# HEADERS, from the address ADDRESS, with any more options for "fossil |
| 1295 | +# http" in ARGS. RESULT is the reply without its header. |
| 1296 | +# |
| 1297 | +proc xferserver_http {body headers address args} { |
| 1298 | + set request "POST /xfer HTTP/1.0\r\n" |
| 1299 | + append request "Content-Type: application/x-fossil-debug\r\n" |
| 1300 | + foreach header $headers { |
| 1301 | + append request "$header\r\n" |
| 1302 | + } |
| 1303 | + append request "Content-Length: [string length $body]\r\n\r\n$body" |
| 1304 | + write_file http-request.txt $request |
| 1305 | + file delete http-reply.txt |
| 1306 | + fossil_raw http --in http-request.txt --out http-reply.txt \ |
| 1307 | + --ipaddr $address srv.fossil {*}$args |
| 1308 | + set reply "" |
| 1309 | + if {[file exists http-reply.txt]} { |
| 1310 | + set reply [read_file http-reply.txt] |
| 1311 | + } |
| 1312 | + set end [string first "\r\n\r\n" $reply] |
| 1313 | + set ::RESULT [expr {$end < 0 ? "" : [string range $reply $end+4 end]}] |
| 1314 | +} |
| 1315 | + |
| 1316 | +# The login card of USER with PASSWORD for a message of the cards BODY, |
| 1317 | +# with the nonce made from the cards NONCEBODY. |
| 1318 | +# |
| 1319 | +proc xferserver_login_card {user password body {nonceBody ""}} { |
| 1320 | + global xferserverLoginProject |
| 1321 | + if {$nonceBody eq ""} {set nonceBody $body} |
| 1322 | + set secret [sha1_text $xferserverLoginProject/$user/$password] |
| 1323 | + set nonce [sha1_text $nonceBody] |
| 1324 | + return "login $user $nonce [sha1_text $nonce$secret]" |
| 1325 | +} |
| 1326 | + |
| 1327 | +# The card is accepted when its nonce is the hash of the cards after it. |
| 1328 | +# A card with a nonce made from other cards is refused, although its |
| 1329 | +# signature fits that nonce. |
| 1330 | +xferserver_http "[xferserver_login_card tester secret \ |
| 1331 | + $xferserverLoginPull]\n$xferserverLoginPull" {} 127.0.0.1 |
| 1332 | +test xfer-login-http-accepted \ |
| 1333 | + {$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]} |
| 1334 | +xferserver_http "[xferserver_login_card tester secret $xferserverLoginPull \ |
| 1335 | + "other cards\n"]\n$xferserverLoginPull" {} 127.0.0.1 |
| 1336 | +test xfer-login-http-nonce-of-other-cards \ |
| 1337 | + {$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]} |
| 1338 | + |
| 1339 | +# A signature that is not as long as a hash is refused. |
| 1340 | +foreach {xferserverLoginName xferserverLoginSig} [list \ |
| 1341 | + short-signature abc \ |
| 1342 | + long-signature [string repeat a 41] \ |
| 1343 | +] { |
| 1344 | + xferserver_http "login tester [sha1_text $xferserverLoginPull]\ |
| 1345 | + $xferserverLoginSig\n$xferserverLoginPull" {} 127.0.0.1 |
| 1346 | + test xfer-login-http-$xferserverLoginName \ |
| 1347 | + {$CODE == 0 && [holds_strings $RESULT {{error login\sfailed} "!igot "}]} |
| 1348 | +} |
| 1349 | + |
| 1350 | +# The same card in the cookie x-f-l-c logs the user in. A cookie that is |
| 1351 | +# not a login card of four words is ignored, and the request is that of |
| 1352 | +# "nobody". |
| 1353 | +set xferserverLoginCard \ |
| 1354 | + [xferserver_login_card tester secret $xferserverLoginPull] |
| 1355 | +foreach {xferserverLoginName xferserverLoginCookie xferserverLoginOk} [list \ |
| 1356 | + card $xferserverLoginCard 1 \ |
| 1357 | + three-words [lrange $xferserverLoginCard 0 2] 0 \ |
| 1358 | + longer-word [lreplace $xferserverLoginCard 0 0 logins] 0 \ |
| 1359 | + other-word [lreplace $xferserverLoginCard 0 0 logix] 0 \ |
| 1360 | +] { |
| 1361 | + xferserver_http $xferserverLoginPull [list \ |
| 1362 | + "Cookie: x-f-l-c=[string map {{ } %20} $xferserverLoginCookie]"] \ |
| 1363 | + 127.0.0.1 |
| 1364 | + set xferserverLoginWant [expr {$xferserverLoginOk |
| 1365 | + ? {"igot " "errors 0"} : {{error not\sauthorized\sto\sread} "!igot "}}] |
| 1366 | + test xfer-login-cookie-$xferserverLoginName \ |
| 1367 | + {$CODE == 0 && [holds_strings $RESULT $xferserverLoginWant]} |
| 1368 | +} |
| 1369 | + |
| 1370 | +# With --localauth a request from this machine needs no login, unless the |
| 1371 | +# localauth setting is on; the refusal then says so. A request from |
| 1372 | +# another machine is refused without that reason. |
| 1373 | +xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth |
| 1374 | +test xfer-login-localauth-local \ |
| 1375 | + {$CODE == 0 && [holds_strings $RESULT {"igot " "errors 0"}]} |
| 1376 | +xferserver_http $xferserverLoginPull {} 10.1.2.3 --localauth |
| 1377 | +test xfer-login-localauth-other-machine {$CODE == 0 && [holds_strings $RESULT \ |
| 1378 | + {{error not\sauthorized\sto\sread} "!localauth" "!igot "}]} |
| 1379 | +xferserver_sql "REPLACE INTO config(name,value,mtime) |
| 1380 | + VALUES('localauth',1,now())" |
| 1381 | +xferserver_http $xferserverLoginPull {} 127.0.0.1 --localauth |
| 1382 | +test xfer-login-localauth-setting-on {$CODE == 0 && [holds_strings $RESULT \ |
| 1383 | + {{error not\sauthorized\sto\sread\sbecause\sthe\s'localauth'\ssetting} |
| 1384 | + "!igot "}]} |
| 1385 | +xferserver_sql "DELETE FROM config WHERE name='localauth'" |
| 1386 | + |
| 1387 | +unset ::env(SCN_EXE) ::env(SCN_REPO) ::env(SCN_FAULT) ::env(SCN_AUTH) |
| 1388 | +unset ::env(SCN_PROJECT) |
| 1389 | + |
| 1390 | +xferserver_leave |
| 1391 | + |
| 1392 | +############################################################################### |
| 1393 | +# Checks on the server side of the protocol that each decide on several |
| 1394 | +# conditions: check-in locks, clones with private content and with content |
| 1395 | +# that an old client cannot take, the limits on what the server sends, new |
| 1396 | +# clusters, and the way "fossil test-xfer" reads its message. Each case has |
| 1397 | +# one input that changes only one of the conditions. |
| 1398 | +# |
| 1399 | +# The server is a repository of its own with a public check-in, then three |
| 1400 | +# private ones on top of it; the first of the three is then made public. So |
| 1401 | +# it holds a public artifact stored as a delta of a private one, a private |
| 1402 | +# artifact stored as a delta of another private one, and a public artifact |
| 1403 | +# stored as a delta of a public one. |
| 1404 | + |
| 1405 | +xferserver_enter mcdc |
| 1406 | + |
| 1407 | +proc xferserver_mcdc_sql {sql} { |
| 1408 | + fossil sql -R srv.fossil $sql |
| 1409 | + return [string trim $::RESULT] |
| 1410 | +} |
| 1411 | + |
| 1412 | +# Send MESSAGE to the server and set RESULT and CODE. |
| 1413 | +proc xferserver_mcdc_send {message} { |
| 1414 | + write_file msg.txt $message |
| 1415 | + fossil_raw test-xfer -R srv.fossil msg.txt |
| 1416 | +} |
| 1417 | + |
| 1418 | +# Test NAME passes when the reply to MESSAGE holds each of the strings |
| 1419 | +# given, and none that begins with "!". |
| 1420 | +proc xferserver_mcdc_expect {name message args} { |
| 1421 | + xferserver_mcdc_send $message |
| 1422 | + test xfer-server-mcdc-$name {$::CODE == 0 && [holds_strings $::RESULT $args]} |
| 1423 | +} |
| 1424 | + |
| 1425 | +set xferserverMcdcText "" |
| 1426 | +for {set xferserverMcdcI 0} {$xferserverMcdcI < 40} {incr xferserverMcdcI} { |
| 1427 | + append xferserverMcdcText "line $xferserverMcdcI of a file that is worth a delta\n" |
| 1428 | +} |
| 1429 | +write_file a.txt $xferserverMcdcText |
| 1430 | +fossil add a.txt |
| 1431 | +fossil commit -m public-1 --no-warnings |
| 1432 | +foreach xferserverMcdcI {2 3 4} { |
| 1433 | + append xferserverMcdcText "version $xferserverMcdcI\n" |
| 1434 | + write_file a.txt $xferserverMcdcText |
| 1435 | + fossil commit -m private-$xferserverMcdcI --private --no-warnings |
| 1436 | +} |
| 1437 | +# The blob of the file in each version. |
| 1438 | +proc xferserverMcdc_fid {comment} { |
| 1439 | + fossil sql "SELECT mlink.fid FROM mlink, event WHERE mlink.mid=event.objid |
| 1440 | + AND event.comment='$comment'" |
| 1441 | + return [string trim $::RESULT] |
| 1442 | +} |
| 1443 | +# Version 2 becomes public while it is stored as a delta of the private |
| 1444 | +# version 3, and version 1 becomes a delta of version 2. |
| 1445 | +fossil sql "SELECT uuid FROM blob WHERE rid=(SELECT objid FROM event |
| 1446 | + WHERE comment='private-2')" |
| 1447 | +fossil publish [string trim $RESULT] |
| 1448 | +fossil test-content-deltify [xferserverMcdc_fid public-1] \ |
| 1449 | + [xferserverMcdc_fid private-2] |
| 1450 | +file copy .rep.fossil srv.fossil |
| 1451 | +set xferserverMcdcPcode [xferserver_mcdc_sql \ |
| 1452 | + "SELECT value FROM config WHERE name='project-code'"] |
| 1453 | +set xferserverMcdcTip [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE rid= |
| 1454 | + (SELECT objid FROM event WHERE type='ci' ORDER BY mtime DESC LIMIT 1)"] |
| 1455 | +set xferserverMcdcLogin "login tester 0 0\n" |
| 1456 | +set xferserverMcdcPull "pull x $xferserverMcdcPcode\n" |
| 1457 | +set xferserverMcdcPush "push x $xferserverMcdcPcode\n" |
| 1458 | +xferserver_mcdc_sql "UPDATE user SET cap='oiyg' WHERE login='nobody'" |
| 1459 | +# A public check-in, named by a SHA3 hash. |
| 1460 | +set xferserverMcdcPublic [xferserver_mcdc_sql "SELECT uuid FROM blob WHERE |
| 1461 | + rid IN (SELECT objid FROM event WHERE type='ci') |
| 1462 | + AND rid NOT IN (SELECT rid FROM private) LIMIT 1"] |
| 1463 | + |
| 1464 | +# A private artifact that is stored as a delta of another private artifact. |
| 1465 | +set xferserverMcdcDelta [xferserver_mcdc_sql "SELECT b.uuid FROM blob b, delta d, |
| 1466 | + private p WHERE b.rid=d.rid AND p.rid=d.rid AND d.srcid IN |
| 1467 | + (SELECT rid FROM private) LIMIT 1"] |
| 1468 | +test xfer-server-mcdc-setup-private-delta \ |
| 1469 | + {[string length $xferserverMcdcDelta] >= 40} |
| 1470 | +foreach xferserverMcdcI {1 2} { |
| 1471 | + set xferserverMcdcFile($xferserverMcdcI) [xferserver_mcdc_sql \ |
| 1472 | + "SELECT uuid||' '||size FROM blob WHERE rid=[xferserverMcdc_fid \ |
| 1473 | + [lindex {x public-1 private-2} $xferserverMcdcI]]"] |
| 1474 | +} |
| 1475 | +lassign $xferserverMcdcFile(1) xferserverMcdcHash1 xferserverMcdcSize1 |
| 1476 | +lassign $xferserverMcdcFile(2) xferserverMcdcHash2 xferserverMcdcSize2 |
| 1477 | +test xfer-server-mcdc-setup-public-from-private {[xferserver_mcdc_sql "SELECT |
| 1478 | + count(*) FROM delta d, private p WHERE d.rid= |
| 1479 | + [xferserverMcdc_fid private-2] AND p.rid=d.srcid"] == 1} |
| 1480 | +test xfer-server-mcdc-setup-public-from-public {[xferserver_mcdc_sql "SELECT |
| 1481 | + count(*) FROM delta d WHERE d.rid=[xferserverMcdc_fid public-1] |
| 1482 | + AND d.srcid=[xferserverMcdc_fid private-2]"] == 1} |
| 1483 | + |
| 1484 | +############################################################################### |
| 1485 | +# A lock on a check-in is reported to a second client with the name of the |
| 1486 | +# user who holds it, "nobody" when the lock has no name or an empty one. |
| 1487 | + |
| 1488 | +set xferserverMcdcA [string repeat a 40] |
| 1489 | +set xferserverMcdcB [string repeat b 40] |
| 1490 | +foreach {xferserverMcdcName xferserverMcdcValue xferserverMcdcWho} { |
| 1491 | + named {json_object('login','alice','clientid',$A)} alice |
| 1492 | + empty {json_object('login','','clientid',$A)} nobody |
| 1493 | + absent {json_object('clientid',$A)} nobody |
| 1494 | +} { |
| 1495 | + set xferserverMcdcValue [string map \ |
| 1496 | + [list \$A "'$xferserverMcdcA'"] $xferserverMcdcValue] |
| 1497 | + xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'; |
| 1498 | + REPLACE INTO config(name,value,mtime) |
| 1499 | + VALUES('ci-lock-$xferserverMcdcTip',$xferserverMcdcValue,now())" |
| 1500 | + xferserver_mcdc_expect lock-held-by-$xferserverMcdcName \ |
| 1501 | + "$xferserverMcdcLogin${xferserverMcdcPull}pragma ci-lock\ |
| 1502 | + $xferserverMcdcTip $xferserverMcdcB\n" \ |
| 1503 | + "pragma ci-lock-fail $xferserverMcdcWho " |
| 1504 | +} |
| 1505 | +xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'ci-lock-*'" |
| 1506 | + |
| 1507 | +############################################################################### |
| 1508 | +# A clone of a server that has private artifacts. A client that does not |
| 1509 | +# ask for private content is sent none, and one that does is sent each of |
| 1510 | +# them behind a "private" card, a delta of a private artifact as a delta. |
| 1511 | + |
| 1512 | +xferserver_mcdc_expect clone-no-private \ |
| 1513 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| 1514 | + "cfile " "!private\ncfile" "!cfile $xferserverMcdcDelta" |
| 1515 | +xferserver_mcdc_expect clone-private \ |
| 1516 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 3 1\n" \ |
| 1517 | + "private\ncfile $xferserverMcdcDelta " |
| 1518 | +# A public artifact whose source is private is sent whole: the card names no |
| 1519 | +# source. |
| 1520 | +xferserver_mcdc_expect clone-public-from-private \ |
| 1521 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| 1522 | + "cfile $xferserverMcdcHash2 $xferserverMcdcSize2 " |
| 1523 | +xferserver_mcdc_expect clone-public-from-public \ |
| 1524 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| 1525 | + "cfile $xferserverMcdcHash1 $xferserverMcdcHash2 $xferserverMcdcSize1 " |
| 1526 | +xferserver_mcdc_expect clone-v2-public-from-private \ |
| 1527 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \ |
| 1528 | + "file $xferserverMcdcHash2 $xferserverMcdcSize2\n" |
| 1529 | +xferserver_mcdc_expect clone-v2-public-from-public \ |
| 1530 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 2 1\n" \ |
| 1531 | + "file $xferserverMcdcHash1 $xferserverMcdcHash2 " |
| 1532 | +xferserver_mcdc_expect clone-v2-private \ |
| 1533 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}pragma send-private\nclone 2 1\n" \ |
| 1534 | + "private\nfile $xferserverMcdcDelta " |
| 1535 | + |
| 1536 | +############################################################################### |
| 1537 | +# Artifacts named by a SHA1 hash. A client that does not state its version |
| 1538 | +# is taken to be older than 2.0: it is sent them, and gets an error in place |
| 1539 | +# of an artifact named by a SHA3 hash. |
| 1540 | + |
| 1541 | +write_file sha1.txt "sha1 content\n" |
| 1542 | +fossil sha1sum sha1.txt |
| 1543 | +set xferserverMcdcSha1 [lindex $RESULT 0] |
| 1544 | +xferserver_mcdc_expect push-sha1 \ |
| 1545 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPush}file\ |
| 1546 | + $xferserverMcdcSha1 13\nsha1 content\n" "errors 0" |
| 1547 | +test xfer-server-mcdc-push-sha1-stored \ |
| 1548 | + {[xferserver_mcdc_sql "SELECT count(*) FROM blob WHERE |
| 1549 | + uuid='$xferserverMcdcSha1' AND size=13"] == 1} |
| 1550 | +xferserver_mcdc_expect old-client-gimme-sha1 \ |
| 1551 | + "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcSha1\n" \ |
| 1552 | + "file $xferserverMcdcSha1 13\nsha1 content\n" "!error Fossil" |
| 1553 | +xferserver_mcdc_expect old-client-gimme-sha3 \ |
| 1554 | + "${xferserverMcdcLogin}${xferserverMcdcPull}gimme $xferserverMcdcPublic\n" \ |
| 1555 | + {error Fossil\sversion\s2.0\sor\slater\srequired} "!file $xferserverMcdcPublic" |
| 1556 | +xferserver_mcdc_expect old-client-clone-sha1 \ |
| 1557 | + "${xferserverMcdcLogin}clone 3 1\n" \ |
| 1558 | + "cfile $xferserverMcdcSha1 13 " {error Fossil\sversion\s2.0\sor\slater\srequired} |
| 1559 | + |
| 1560 | +############################################################################### |
| 1561 | +# A server whose send limit is reached stops sending files and tells the |
| 1562 | +# client in "igot" cards, and in "uvigot" cards for unversioned files. |
| 1563 | + |
| 1564 | +write_file note.txt "hi\n" |
| 1565 | +fossil unversioned add note.txt -R srv.fossil |
| 1566 | +xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime) |
| 1567 | + VALUES('max-download','1',now())" |
| 1568 | +xferserver_mcdc_expect uvgimme-limit \ |
| 1569 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\ |
| 1570 | + note.txt\n" "uvigot note.txt " "!uvfile note.txt" |
| 1571 | +xferserver_mcdc_expect catalog-limit \ |
| 1572 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}pragma\ |
| 1573 | + send-catalog x\n" "igot " "errors 0" |
| 1574 | +xferserver_mcdc_sql "DELETE FROM config WHERE name='max-download'" |
| 1575 | +xferserver_mcdc_expect uvgimme-no-limit \ |
| 1576 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme\ |
| 1577 | + note.txt\n" "uvfile note.txt " "!uvigot" |
| 1578 | + |
| 1579 | +# A client that does not state its version is sent an unversioned file |
| 1580 | +# that is named by a SHA1 hash, and gets an error in place of one named by |
| 1581 | +# a SHA3 hash. |
| 1582 | +fossil hash-policy sha1 -R srv.fossil |
| 1583 | +write_file old.txt "old\n" |
| 1584 | +fossil unversioned add old.txt -R srv.fossil |
| 1585 | +fossil hash-policy sha3 -R srv.fossil |
| 1586 | +test_eq xfer-server-mcdc-setup-uv-sha1 [xferserver_mcdc_sql "SELECT |
| 1587 | + group_concat(length(hash)) FROM (SELECT hash FROM unversioned |
| 1588 | + WHERE name IN ('note.txt','old.txt') ORDER BY name)"] "64,40" |
| 1589 | +xferserver_mcdc_expect old-client-uvgimme-sha1 \ |
| 1590 | + "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme old.txt\n" \ |
| 1591 | + "uvfile old.txt " "!error Fossil" |
| 1592 | +xferserver_mcdc_expect old-client-uvgimme-sha3 \ |
| 1593 | + "${xferserverMcdcLogin}${xferserverMcdcPull}uvgimme note.txt\n" \ |
| 1594 | + {error Fossil\sversion\s2.0\sor\slater\srequired} "!uvfile note.txt" |
| 1595 | + |
| 1596 | +############################################################################### |
| 1597 | +# A server has the number of seconds in max-download-time to make a reply. |
| 1598 | +# Once they have passed it sends no more artifacts: a client that asks for |
| 1599 | +# one is told in an "igot" card that the server has it, and a clone is told |
| 1600 | +# to ask again from where it was. Here the script that the server runs |
| 1601 | +# before it reads the request keeps it busy for more than one second. |
| 1602 | + |
| 1603 | +xferserver_mcdc_expect gimme-in-time \ |
| 1604 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\ |
| 1605 | + $xferserverMcdcPublic\n" "file $xferserverMcdcPublic " |
| 1606 | +set xferserverMcdcBusy {set s [expr {[utime]+[stime]}]} |
| 1607 | +append xferserverMcdcBusy \ |
| 1608 | + {; for {set t $s} {$t-$s < 1100000} {set t [expr {[utime]+[stime]}]} {}} |
| 1609 | +xferserver_mcdc_sql "REPLACE INTO config(name,value,mtime) VALUES |
| 1610 | + ('max-download-time','1',now()), |
| 1611 | + ('xfer-common-script','$xferserverMcdcBusy',now())" |
| 1612 | +xferserver_mcdc_expect gimme-out-of-time \ |
| 1613 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}${xferserverMcdcPull}gimme\ |
| 1614 | + $xferserverMcdcPublic\n" \ |
| 1615 | + "igot $xferserverMcdcPublic\n" "!file $xferserverMcdcPublic " "errors 0" |
| 1616 | +xferserver_mcdc_expect clone-out-of-time \ |
| 1617 | + "${CLIENT_VERSION_CARD}${xferserverMcdcLogin}clone 3 1\n" \ |
| 1618 | + "clone_seqno 1\n" "!cfile " "errors 0" |
| 1619 | +xferserver_mcdc_sql "DELETE FROM config |
| 1620 | + WHERE name IN ('max-download-time','xfer-common-script')" |
| 1621 | + |
| 1622 | +############################################################################### |
| 1623 | +# A client that says where it can be reached is recorded when the address |
| 1624 | +# is an http or https one and does not name the local host. |
| 1625 | + |
| 1626 | +foreach {xferserverMcdcName xferserverMcdcUrl xferserverMcdcKept} { |
| 1627 | + http http://example.org/a 1 |
| 1628 | + https https://example.org/b 1 |
| 1629 | + localhost http://localhost/c 0 |
| 1630 | + ssh ssh://example.org/d 0 |
| 1631 | +} { |
| 1632 | + xferserver_mcdc_sql "DELETE FROM config WHERE name GLOB 'syncfrom:*'" |
| 1633 | + xferserver_mcdc_expect client-url-$xferserverMcdcName \ |
| 1634 | + "${xferserverMcdcLogin}${xferserverMcdcPush}pragma client-url\ |
| 1635 | + $xferserverMcdcUrl\n" "errors 0" |
| 1636 | + test xfer-server-mcdc-client-url-$xferserverMcdcName-recorded \ |
| 1637 | + {[xferserver_mcdc_sql "SELECT count(*) FROM config |
| 1638 | + WHERE name GLOB 'syncfrom:*'"] == $xferserverMcdcKept} |
| 1639 | +} |
| 1640 | + |
| 1641 | +############################################################################### |
| 1642 | +# "fossil test-xfer" reads the message from the file it is given, or from |
| 1643 | +# its standard input when it is given none, and takes no more arguments. |
| 1644 | + |
| 1645 | +fossil_raw -input "${xferserverMcdcLogin}${xferserverMcdcPull}" \ |
| 1646 | + test-xfer -R srv.fossil |
| 1647 | +test xfer-server-mcdc-test-xfer-stdin \ |
| 1648 | + {$CODE == 0 && [string first "errors 0" $RESULT] >= 0} |
| 1649 | +fossil_raw test-xfer -R srv.fossil msg.txt msg.txt |
| 1650 | +test xfer-server-mcdc-test-xfer-extra-argument \ |
| 1651 | + {$CODE != 0 && [string first "Usage:" $RESULT] >= 0} |
| 1652 | + |
| 1653 | +xferserver_leave |
| 1654 | + |
| 1655 | +############################################################################### |
| 1656 | +# New clusters. A pull on a server with many artifacts that no cluster |
| 1657 | +# lists makes clusters of up to 800 artifacts, but not one that leaves |
| 1658 | +# 100 or fewer for the next. The artifacts here are inserted with their |
| 1659 | +# contents empty: only their names are listed in a cluster. |
| 1660 | + |
| 1661 | +foreach {xferserverMcdcName xferserverMcdcCount xferserverMcdcClusters} { |
| 1662 | + few 700 1 |
| 1663 | + many 850 1 |
| 1664 | + more 1100 2 |
| 1665 | +} { |
| 1666 | + xferserver_enter mcdc-cluster-$xferserverMcdcName |
| 1667 | + fossil sql "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM n |
| 1668 | + WHERE i<$xferserverMcdcCount) |
| 1669 | + INSERT INTO blob(rcvid,size,uuid,content) |
| 1670 | + SELECT 1, 0, printf('%040x', i+1000000), x'' FROM n; |
| 1671 | + INSERT OR IGNORE INTO unclustered |
| 1672 | + SELECT rid FROM blob WHERE uuid GLOB '0000000000*'" |
| 1673 | + fossil sql "SELECT value FROM config WHERE name='project-code'" |
| 1674 | + set xferserverMcdcCode [string trim $RESULT] |
| 1675 | + fossil sql "UPDATE user SET cap='o' WHERE login='nobody'" |
| 1676 | + write_file msg.txt "pull x $xferserverMcdcCode\n" |
| 1677 | + fossil_raw test-xfer -R .rep.fossil msg.txt |
| 1678 | + test xfer-server-mcdc-cluster-$xferserverMcdcName-pull {$CODE == 0} |
| 1679 | + fossil sql "SELECT count(*) FROM tagxref WHERE tagid= |
| 1680 | + (SELECT tagid FROM tag WHERE tagname='cluster')" |
| 1681 | + test_eq xfer-server-mcdc-cluster-$xferserverMcdcName-count \ |
| 1682 | + [string trim $RESULT] $xferserverMcdcClusters |
| 1683 | + xferserver_leave |
| 1684 | +} |
| 420 | 1685 | |
| 421 | 1686 | ############################################################################### |
| 422 | 1687 | |
| 423 | 1688 | test_cleanup |
| 424 | 1689 | |