Fossil SCM
Add tests for the 'anycap', 'anoncap', and 'hascap' TH1 commands. Also, add the --set-user-caps and --set-anon-caps options to the 'test-th-eval', 'test-th-render', and 'test-th-source' test commands.
Commit
5ea2a4fb075cf024a293b756209c0fa6f39a2ce3
Parent
1f8a667f8e14388…
2 files changed
+30
+60
-1
+30
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -2385,10 +2385,12 @@ | ||
| 2385 | 2385 | ** Options: |
| 2386 | 2386 | ** |
| 2387 | 2387 | ** --cgi Include a CGI response header in the output |
| 2388 | 2388 | ** --http Include an HTTP response header in the output |
| 2389 | 2389 | ** --open-config Open the configuration database |
| 2390 | +** --set-anon-caps Set anonymous login capabilities | |
| 2391 | +** --set-user-caps Set user login capabilities | |
| 2390 | 2392 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2391 | 2393 | */ |
| 2392 | 2394 | void test_th_render(void){ |
| 2393 | 2395 | int forceCgi, fullHttpReply; |
| 2394 | 2396 | Blob in; |
| @@ -2397,10 +2399,18 @@ | ||
| 2397 | 2399 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2398 | 2400 | if( fullHttpReply ) forceCgi = 1; |
| 2399 | 2401 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2400 | 2402 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2401 | 2403 | Th_OpenConfig(1); |
| 2404 | + } | |
| 2405 | + if( find_option("set-anon-caps", 0, 0)!=0 ){ | |
| 2406 | + login_set_capabilities("sx", LOGIN_ANON); | |
| 2407 | + g.useLocalauth = 1; | |
| 2408 | + } | |
| 2409 | + if( find_option("set-user-caps", 0, 0)!=0 ){ | |
| 2410 | + login_set_capabilities("sx", 0); | |
| 2411 | + g.useLocalauth = 1; | |
| 2402 | 2412 | } |
| 2403 | 2413 | verify_all_options(); |
| 2404 | 2414 | if( g.argc<3 ){ |
| 2405 | 2415 | usage("FILE"); |
| 2406 | 2416 | } |
| @@ -2422,10 +2432,12 @@ | ||
| 2422 | 2432 | ** Options: |
| 2423 | 2433 | ** |
| 2424 | 2434 | ** --cgi Include a CGI response header in the output |
| 2425 | 2435 | ** --http Include an HTTP response header in the output |
| 2426 | 2436 | ** --open-config Open the configuration database |
| 2437 | +** --set-anon-caps Set anonymous login capabilities | |
| 2438 | +** --set-user-caps Set user login capabilities | |
| 2427 | 2439 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2428 | 2440 | */ |
| 2429 | 2441 | void test_th_eval(void){ |
| 2430 | 2442 | int rc; |
| 2431 | 2443 | const char *zRc; |
| @@ -2435,10 +2447,18 @@ | ||
| 2435 | 2447 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2436 | 2448 | if( fullHttpReply ) forceCgi = 1; |
| 2437 | 2449 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2438 | 2450 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2439 | 2451 | Th_OpenConfig(1); |
| 2452 | + } | |
| 2453 | + if( find_option("set-anon-caps", 0, 0)!=0 ){ | |
| 2454 | + login_set_capabilities("sx", LOGIN_ANON); | |
| 2455 | + g.useLocalauth = 1; | |
| 2456 | + } | |
| 2457 | + if( find_option("set-user-caps", 0, 0)!=0 ){ | |
| 2458 | + login_set_capabilities("sx", 0); | |
| 2459 | + g.useLocalauth = 1; | |
| 2440 | 2460 | } |
| 2441 | 2461 | verify_all_options(); |
| 2442 | 2462 | if( g.argc!=3 ){ |
| 2443 | 2463 | usage("script"); |
| 2444 | 2464 | } |
| @@ -2462,10 +2482,12 @@ | ||
| 2462 | 2482 | ** Options: |
| 2463 | 2483 | ** |
| 2464 | 2484 | ** --cgi Include a CGI response header in the output |
| 2465 | 2485 | ** --http Include an HTTP response header in the output |
| 2466 | 2486 | ** --open-config Open the configuration database |
| 2487 | +** --set-anon-caps Set anonymous login capabilities | |
| 2488 | +** --set-user-caps Set user login capabilities | |
| 2467 | 2489 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2468 | 2490 | */ |
| 2469 | 2491 | void test_th_source(void){ |
| 2470 | 2492 | int rc; |
| 2471 | 2493 | const char *zRc; |
| @@ -2476,10 +2498,18 @@ | ||
| 2476 | 2498 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2477 | 2499 | if( fullHttpReply ) forceCgi = 1; |
| 2478 | 2500 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2479 | 2501 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2480 | 2502 | Th_OpenConfig(1); |
| 2503 | + } | |
| 2504 | + if( find_option("set-anon-caps", 0, 0)!=0 ){ | |
| 2505 | + login_set_capabilities("sx", LOGIN_ANON); | |
| 2506 | + g.useLocalauth = 1; | |
| 2507 | + } | |
| 2508 | + if( find_option("set-user-caps", 0, 0)!=0 ){ | |
| 2509 | + login_set_capabilities("sx", 0); | |
| 2510 | + g.useLocalauth = 1; | |
| 2481 | 2511 | } |
| 2482 | 2512 | verify_all_options(); |
| 2483 | 2513 | if( g.argc!=3 ){ |
| 2484 | 2514 | usage("file"); |
| 2485 | 2515 | } |
| 2486 | 2516 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2385,10 +2385,12 @@ | |
| 2385 | ** Options: |
| 2386 | ** |
| 2387 | ** --cgi Include a CGI response header in the output |
| 2388 | ** --http Include an HTTP response header in the output |
| 2389 | ** --open-config Open the configuration database |
| 2390 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2391 | */ |
| 2392 | void test_th_render(void){ |
| 2393 | int forceCgi, fullHttpReply; |
| 2394 | Blob in; |
| @@ -2397,10 +2399,18 @@ | |
| 2397 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2398 | if( fullHttpReply ) forceCgi = 1; |
| 2399 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2400 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2401 | Th_OpenConfig(1); |
| 2402 | } |
| 2403 | verify_all_options(); |
| 2404 | if( g.argc<3 ){ |
| 2405 | usage("FILE"); |
| 2406 | } |
| @@ -2422,10 +2432,12 @@ | |
| 2422 | ** Options: |
| 2423 | ** |
| 2424 | ** --cgi Include a CGI response header in the output |
| 2425 | ** --http Include an HTTP response header in the output |
| 2426 | ** --open-config Open the configuration database |
| 2427 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2428 | */ |
| 2429 | void test_th_eval(void){ |
| 2430 | int rc; |
| 2431 | const char *zRc; |
| @@ -2435,10 +2447,18 @@ | |
| 2435 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2436 | if( fullHttpReply ) forceCgi = 1; |
| 2437 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2438 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2439 | Th_OpenConfig(1); |
| 2440 | } |
| 2441 | verify_all_options(); |
| 2442 | if( g.argc!=3 ){ |
| 2443 | usage("script"); |
| 2444 | } |
| @@ -2462,10 +2482,12 @@ | |
| 2462 | ** Options: |
| 2463 | ** |
| 2464 | ** --cgi Include a CGI response header in the output |
| 2465 | ** --http Include an HTTP response header in the output |
| 2466 | ** --open-config Open the configuration database |
| 2467 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2468 | */ |
| 2469 | void test_th_source(void){ |
| 2470 | int rc; |
| 2471 | const char *zRc; |
| @@ -2476,10 +2498,18 @@ | |
| 2476 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2477 | if( fullHttpReply ) forceCgi = 1; |
| 2478 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2479 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2480 | Th_OpenConfig(1); |
| 2481 | } |
| 2482 | verify_all_options(); |
| 2483 | if( g.argc!=3 ){ |
| 2484 | usage("file"); |
| 2485 | } |
| 2486 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -2385,10 +2385,12 @@ | |
| 2385 | ** Options: |
| 2386 | ** |
| 2387 | ** --cgi Include a CGI response header in the output |
| 2388 | ** --http Include an HTTP response header in the output |
| 2389 | ** --open-config Open the configuration database |
| 2390 | ** --set-anon-caps Set anonymous login capabilities |
| 2391 | ** --set-user-caps Set user login capabilities |
| 2392 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2393 | */ |
| 2394 | void test_th_render(void){ |
| 2395 | int forceCgi, fullHttpReply; |
| 2396 | Blob in; |
| @@ -2397,10 +2399,18 @@ | |
| 2399 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2400 | if( fullHttpReply ) forceCgi = 1; |
| 2401 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2402 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2403 | Th_OpenConfig(1); |
| 2404 | } |
| 2405 | if( find_option("set-anon-caps", 0, 0)!=0 ){ |
| 2406 | login_set_capabilities("sx", LOGIN_ANON); |
| 2407 | g.useLocalauth = 1; |
| 2408 | } |
| 2409 | if( find_option("set-user-caps", 0, 0)!=0 ){ |
| 2410 | login_set_capabilities("sx", 0); |
| 2411 | g.useLocalauth = 1; |
| 2412 | } |
| 2413 | verify_all_options(); |
| 2414 | if( g.argc<3 ){ |
| 2415 | usage("FILE"); |
| 2416 | } |
| @@ -2422,10 +2432,12 @@ | |
| 2432 | ** Options: |
| 2433 | ** |
| 2434 | ** --cgi Include a CGI response header in the output |
| 2435 | ** --http Include an HTTP response header in the output |
| 2436 | ** --open-config Open the configuration database |
| 2437 | ** --set-anon-caps Set anonymous login capabilities |
| 2438 | ** --set-user-caps Set user login capabilities |
| 2439 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2440 | */ |
| 2441 | void test_th_eval(void){ |
| 2442 | int rc; |
| 2443 | const char *zRc; |
| @@ -2435,10 +2447,18 @@ | |
| 2447 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2448 | if( fullHttpReply ) forceCgi = 1; |
| 2449 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2450 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2451 | Th_OpenConfig(1); |
| 2452 | } |
| 2453 | if( find_option("set-anon-caps", 0, 0)!=0 ){ |
| 2454 | login_set_capabilities("sx", LOGIN_ANON); |
| 2455 | g.useLocalauth = 1; |
| 2456 | } |
| 2457 | if( find_option("set-user-caps", 0, 0)!=0 ){ |
| 2458 | login_set_capabilities("sx", 0); |
| 2459 | g.useLocalauth = 1; |
| 2460 | } |
| 2461 | verify_all_options(); |
| 2462 | if( g.argc!=3 ){ |
| 2463 | usage("script"); |
| 2464 | } |
| @@ -2462,10 +2482,12 @@ | |
| 2482 | ** Options: |
| 2483 | ** |
| 2484 | ** --cgi Include a CGI response header in the output |
| 2485 | ** --http Include an HTTP response header in the output |
| 2486 | ** --open-config Open the configuration database |
| 2487 | ** --set-anon-caps Set anonymous login capabilities |
| 2488 | ** --set-user-caps Set user login capabilities |
| 2489 | ** --th-trace Trace TH1 execution (for debugging purposes) |
| 2490 | */ |
| 2491 | void test_th_source(void){ |
| 2492 | int rc; |
| 2493 | const char *zRc; |
| @@ -2476,10 +2498,18 @@ | |
| 2498 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2499 | if( fullHttpReply ) forceCgi = 1; |
| 2500 | if( forceCgi ) Th_ForceCgi(fullHttpReply); |
| 2501 | if( find_option("open-config", 0, 0)!=0 ){ |
| 2502 | Th_OpenConfig(1); |
| 2503 | } |
| 2504 | if( find_option("set-anon-caps", 0, 0)!=0 ){ |
| 2505 | login_set_capabilities("sx", LOGIN_ANON); |
| 2506 | g.useLocalauth = 1; |
| 2507 | } |
| 2508 | if( find_option("set-user-caps", 0, 0)!=0 ){ |
| 2509 | login_set_capabilities("sx", 0); |
| 2510 | g.useLocalauth = 1; |
| 2511 | } |
| 2512 | verify_all_options(); |
| 2513 | if( g.argc!=3 ){ |
| 2514 | usage("file"); |
| 2515 | } |
| 2516 |
+60
-1
| --- test/th1.test | ||
| +++ test/th1.test | ||
| @@ -554,10 +554,69 @@ | ||
| 554 | 554 | fossil test-th-eval "lindex list -0x" |
| 555 | 555 | test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}} |
| 556 | 556 | |
| 557 | 557 | ############################################################################### |
| 558 | 558 | |
| 559 | +foreach perm [list a b c d e f g h i j k l m n o p q r s t u v w x y z] { | |
| 560 | + if {$perm eq "u"} continue; # NOTE: Skip "reader" meta-permission. | |
| 561 | + if {$perm eq "v"} continue; # NOTE: Skip "developer" meta-permission. | |
| 562 | + | |
| 563 | + fossil test-th-eval "anycap $perm" | |
| 564 | + test th1-anycap-no-$perm {$RESULT eq {0}} | |
| 565 | + | |
| 566 | + fossil test-th-eval "hascap $perm" | |
| 567 | + test th1-hascap-no-$perm {$RESULT eq {0}} | |
| 568 | + | |
| 569 | + fossil test-th-eval "anoncap $perm" | |
| 570 | + test th1-anoncap-no-$perm {$RESULT eq {0}} | |
| 571 | + | |
| 572 | + run_in_checkout { | |
| 573 | + fossil test-th-eval --set-user-caps "anycap $perm" | |
| 574 | + test th1-anycap-yes-$perm {$RESULT eq {1}} | |
| 575 | + | |
| 576 | + fossil test-th-eval --set-user-caps "hascap $perm" | |
| 577 | + test th1-hascap-yes-$perm {$RESULT eq {1}} | |
| 578 | + | |
| 579 | + fossil test-th-eval --set-anon-caps "anoncap $perm" | |
| 580 | + test th1-anoncap-yes-$perm {$RESULT eq {1}} | |
| 581 | + } | |
| 582 | +} | |
| 583 | + | |
| 584 | +fossil test-th-eval "anycap oh" | |
| 585 | +test th1-anycap-no-multiple {$RESULT eq {0}} | |
| 586 | + | |
| 587 | +fossil test-th-eval "hascap oh" | |
| 588 | +test th1-hascap-no-multiple1 {$RESULT eq {0}} | |
| 589 | + | |
| 590 | +fossil test-th-eval "hascap o h" | |
| 591 | +test th1-hascap-no-multiple2 {$RESULT eq {0}} | |
| 592 | + | |
| 593 | +fossil test-th-eval "anoncap oh" | |
| 594 | +test th1-anoncap-no-multiple1 {$RESULT eq {0}} | |
| 595 | + | |
| 596 | +fossil test-th-eval "anoncap o h" | |
| 597 | +test th1-anoncap-no-multiple2 {$RESULT eq {0}} | |
| 598 | + | |
| 599 | +run_in_checkout { | |
| 600 | + fossil test-th-eval --set-user-caps "anycap oh" | |
| 601 | + test th1-anycap-yes-multiple1 {$RESULT eq {1}} | |
| 602 | + | |
| 603 | + fossil test-th-eval --set-user-caps "hascap oh" | |
| 604 | + test th1-hascap-yes-multiple1 {$RESULT eq {1}} | |
| 605 | + | |
| 606 | + fossil test-th-eval --set-user-caps "hascap o h" | |
| 607 | + test th1-hascap-yes-multiple2 {$RESULT eq {1}} | |
| 608 | + | |
| 609 | + fossil test-th-eval --set-anon-caps "anoncap oh" | |
| 610 | + test th1-anoncap-yes-multiple1 {$RESULT eq {1}} | |
| 611 | + | |
| 612 | + fossil test-th-eval --set-anon-caps "anoncap o h" | |
| 613 | + test th1-anoncap-yes-multiple2 {$RESULT eq {1}} | |
| 614 | +} | |
| 615 | + | |
| 616 | +############################################################################### | |
| 617 | + | |
| 559 | 618 | run_in_checkout { |
| 560 | 619 | # NOTE: The "1" here forces the checkout to be opened. |
| 561 | 620 | fossil test-th-eval "checkout 1" |
| 562 | 621 | } |
| 563 | 622 | |
| @@ -914,11 +973,11 @@ | ||
| 914 | 973 | |
| 915 | 974 | ############################################################################### |
| 916 | 975 | |
| 917 | 976 | # |
| 918 | 977 | # NOTE: This test will fail if the command names are added to TH1, or |
| 919 | -# moved from Tcl builds to plain or the reverse. Sorting the | |
| 978 | +# moved from Tcl builds to plain or the reverse. Sorting the | |
| 920 | 979 | # command lists eliminates a dependence on order. |
| 921 | 980 | # |
| 922 | 981 | fossil test-th-eval "info commands" |
| 923 | 982 | set sorted_result [lsort $RESULT] |
| 924 | 983 | protOut "Sorted: $sorted_result" |
| 925 | 984 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -554,10 +554,69 @@ | |
| 554 | fossil test-th-eval "lindex list -0x" |
| 555 | test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}} |
| 556 | |
| 557 | ############################################################################### |
| 558 | |
| 559 | run_in_checkout { |
| 560 | # NOTE: The "1" here forces the checkout to be opened. |
| 561 | fossil test-th-eval "checkout 1" |
| 562 | } |
| 563 | |
| @@ -914,11 +973,11 @@ | |
| 914 | |
| 915 | ############################################################################### |
| 916 | |
| 917 | # |
| 918 | # NOTE: This test will fail if the command names are added to TH1, or |
| 919 | # moved from Tcl builds to plain or the reverse. Sorting the |
| 920 | # command lists eliminates a dependence on order. |
| 921 | # |
| 922 | fossil test-th-eval "info commands" |
| 923 | set sorted_result [lsort $RESULT] |
| 924 | protOut "Sorted: $sorted_result" |
| 925 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -554,10 +554,69 @@ | |
| 554 | fossil test-th-eval "lindex list -0x" |
| 555 | test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}} |
| 556 | |
| 557 | ############################################################################### |
| 558 | |
| 559 | foreach perm [list a b c d e f g h i j k l m n o p q r s t u v w x y z] { |
| 560 | if {$perm eq "u"} continue; # NOTE: Skip "reader" meta-permission. |
| 561 | if {$perm eq "v"} continue; # NOTE: Skip "developer" meta-permission. |
| 562 | |
| 563 | fossil test-th-eval "anycap $perm" |
| 564 | test th1-anycap-no-$perm {$RESULT eq {0}} |
| 565 | |
| 566 | fossil test-th-eval "hascap $perm" |
| 567 | test th1-hascap-no-$perm {$RESULT eq {0}} |
| 568 | |
| 569 | fossil test-th-eval "anoncap $perm" |
| 570 | test th1-anoncap-no-$perm {$RESULT eq {0}} |
| 571 | |
| 572 | run_in_checkout { |
| 573 | fossil test-th-eval --set-user-caps "anycap $perm" |
| 574 | test th1-anycap-yes-$perm {$RESULT eq {1}} |
| 575 | |
| 576 | fossil test-th-eval --set-user-caps "hascap $perm" |
| 577 | test th1-hascap-yes-$perm {$RESULT eq {1}} |
| 578 | |
| 579 | fossil test-th-eval --set-anon-caps "anoncap $perm" |
| 580 | test th1-anoncap-yes-$perm {$RESULT eq {1}} |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | fossil test-th-eval "anycap oh" |
| 585 | test th1-anycap-no-multiple {$RESULT eq {0}} |
| 586 | |
| 587 | fossil test-th-eval "hascap oh" |
| 588 | test th1-hascap-no-multiple1 {$RESULT eq {0}} |
| 589 | |
| 590 | fossil test-th-eval "hascap o h" |
| 591 | test th1-hascap-no-multiple2 {$RESULT eq {0}} |
| 592 | |
| 593 | fossil test-th-eval "anoncap oh" |
| 594 | test th1-anoncap-no-multiple1 {$RESULT eq {0}} |
| 595 | |
| 596 | fossil test-th-eval "anoncap o h" |
| 597 | test th1-anoncap-no-multiple2 {$RESULT eq {0}} |
| 598 | |
| 599 | run_in_checkout { |
| 600 | fossil test-th-eval --set-user-caps "anycap oh" |
| 601 | test th1-anycap-yes-multiple1 {$RESULT eq {1}} |
| 602 | |
| 603 | fossil test-th-eval --set-user-caps "hascap oh" |
| 604 | test th1-hascap-yes-multiple1 {$RESULT eq {1}} |
| 605 | |
| 606 | fossil test-th-eval --set-user-caps "hascap o h" |
| 607 | test th1-hascap-yes-multiple2 {$RESULT eq {1}} |
| 608 | |
| 609 | fossil test-th-eval --set-anon-caps "anoncap oh" |
| 610 | test th1-anoncap-yes-multiple1 {$RESULT eq {1}} |
| 611 | |
| 612 | fossil test-th-eval --set-anon-caps "anoncap o h" |
| 613 | test th1-anoncap-yes-multiple2 {$RESULT eq {1}} |
| 614 | } |
| 615 | |
| 616 | ############################################################################### |
| 617 | |
| 618 | run_in_checkout { |
| 619 | # NOTE: The "1" here forces the checkout to be opened. |
| 620 | fossil test-th-eval "checkout 1" |
| 621 | } |
| 622 | |
| @@ -914,11 +973,11 @@ | |
| 973 | |
| 974 | ############################################################################### |
| 975 | |
| 976 | # |
| 977 | # NOTE: This test will fail if the command names are added to TH1, or |
| 978 | # moved from Tcl builds to plain or the reverse. Sorting the |
| 979 | # command lists eliminates a dependence on order. |
| 980 | # |
| 981 | fossil test-th-eval "info commands" |
| 982 | set sorted_result [lsort $RESULT] |
| 983 | protOut "Sorted: $sorted_result" |
| 984 |