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.

mistachkin 2016-08-18 01:47 trunk
Commit 5ea2a4fb075cf024a293b756209c0fa6f39a2ce3
2 files changed +30 +60 -1
--- src/th_main.c
+++ src/th_main.c
@@ -2385,10 +2385,12 @@
23852385
** Options:
23862386
**
23872387
** --cgi Include a CGI response header in the output
23882388
** --http Include an HTTP response header in the output
23892389
** --open-config Open the configuration database
2390
+** --set-anon-caps Set anonymous login capabilities
2391
+** --set-user-caps Set user login capabilities
23902392
** --th-trace Trace TH1 execution (for debugging purposes)
23912393
*/
23922394
void test_th_render(void){
23932395
int forceCgi, fullHttpReply;
23942396
Blob in;
@@ -2397,10 +2399,18 @@
23972399
fullHttpReply = find_option("http", 0, 0)!=0;
23982400
if( fullHttpReply ) forceCgi = 1;
23992401
if( forceCgi ) Th_ForceCgi(fullHttpReply);
24002402
if( find_option("open-config", 0, 0)!=0 ){
24012403
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;
24022412
}
24032413
verify_all_options();
24042414
if( g.argc<3 ){
24052415
usage("FILE");
24062416
}
@@ -2422,10 +2432,12 @@
24222432
** Options:
24232433
**
24242434
** --cgi Include a CGI response header in the output
24252435
** --http Include an HTTP response header in the output
24262436
** --open-config Open the configuration database
2437
+** --set-anon-caps Set anonymous login capabilities
2438
+** --set-user-caps Set user login capabilities
24272439
** --th-trace Trace TH1 execution (for debugging purposes)
24282440
*/
24292441
void test_th_eval(void){
24302442
int rc;
24312443
const char *zRc;
@@ -2435,10 +2447,18 @@
24352447
fullHttpReply = find_option("http", 0, 0)!=0;
24362448
if( fullHttpReply ) forceCgi = 1;
24372449
if( forceCgi ) Th_ForceCgi(fullHttpReply);
24382450
if( find_option("open-config", 0, 0)!=0 ){
24392451
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;
24402460
}
24412461
verify_all_options();
24422462
if( g.argc!=3 ){
24432463
usage("script");
24442464
}
@@ -2462,10 +2482,12 @@
24622482
** Options:
24632483
**
24642484
** --cgi Include a CGI response header in the output
24652485
** --http Include an HTTP response header in the output
24662486
** --open-config Open the configuration database
2487
+** --set-anon-caps Set anonymous login capabilities
2488
+** --set-user-caps Set user login capabilities
24672489
** --th-trace Trace TH1 execution (for debugging purposes)
24682490
*/
24692491
void test_th_source(void){
24702492
int rc;
24712493
const char *zRc;
@@ -2476,10 +2498,18 @@
24762498
fullHttpReply = find_option("http", 0, 0)!=0;
24772499
if( fullHttpReply ) forceCgi = 1;
24782500
if( forceCgi ) Th_ForceCgi(fullHttpReply);
24792501
if( find_option("open-config", 0, 0)!=0 ){
24802502
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;
24812511
}
24822512
verify_all_options();
24832513
if( g.argc!=3 ){
24842514
usage("file");
24852515
}
24862516
--- 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 @@
554554
fossil test-th-eval "lindex list -0x"
555555
test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}}
556556
557557
###############################################################################
558558
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
+
559618
run_in_checkout {
560619
# NOTE: The "1" here forces the checkout to be opened.
561620
fossil test-th-eval "checkout 1"
562621
}
563622
@@ -914,11 +973,11 @@
914973
915974
###############################################################################
916975
917976
#
918977
# 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
920979
# command lists eliminates a dependence on order.
921980
#
922981
fossil test-th-eval "info commands"
923982
set sorted_result [lsort $RESULT]
924983
protOut "Sorted: $sorted_result"
925984
--- 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

Keyboard Shortcuts

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