/
AdminOnlyAccessControlTests.pm
815 lines (702 loc) · 25.2 KB
/
AdminOnlyAccessControlTests.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
package AdminOnlyAccessControlTests;
use strict;
use warnings;
#Sven wishes he could use ISA AccessControlTest, but the unit test system doesn't do inherited test subs
use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );
use Foswiki ();
use Foswiki::Plugins ();
use Foswiki::Configure::Dependency();
# For Anchor test
use Foswiki::UI ();
my $post11 = 0;
sub new {
my ( $class, @args ) = @_;
my $self = $class->SUPER::new( 'AccessControl', @args );
my $dep = new Foswiki::Configure::Dependency(
type => "perl",
module => "Foswiki",
version => ">=1.2"
);
my ( $ok, $message ) = $dep->checkDependency();
$post11 = $ok;
return $self;
}
=todo
sub loadExtraConfig {
my ( $this, $context, @args ) = @_;
# $this - the Test::Unit::TestCase object
$this->SUPER::loadExtraConfig( $context, @args );
#can't change to AdminOnlyAccessControl here, as we need to be able to create topics.
#$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'
return;
}
=cut
my $MrWhite;
my $MrBlue;
my $MrOrange;
my $MrGreen;
my $MrYellow;
sub skip {
my ( $this, $test ) = @_;
return $this->check_dependency('Foswiki,<,1.2')
? 'Foswiki 1.1 has no Foswiki::Access'
: undef;
}
sub set_up {
my $this = shift;
$this->SUPER::set_up();
my ($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName},
$Foswiki::cfg{DefaultUserWikiName} );
$topicObject->text('');
$topicObject->save();
$topicObject->finish();
$this->registerUser( 'white', 'Mr', "White", 'white@example.com' );
$MrWhite = $this->{session}->{users}->getCanonicalUserID('white');
$this->registerUser( 'blue', 'Mr', "Blue", 'blue@example.com' );
$MrBlue = $this->{session}->{users}->getCanonicalUserID('blue');
$this->registerUser( 'orange', 'Mr', "Orange", 'orange@example.com' );
$MrOrange = $this->{session}->{users}->getCanonicalUserID('orange');
$this->registerUser( 'green', 'Mr', "Green", 'green@example.com' );
$MrGreen = $this->{session}->{users}->getCanonicalUserID('green');
$this->registerUser( 'yellow', 'Mr', "Yellow", 'yellow@example.com' );
$MrYellow = $this->{session}->{users}->getCanonicalUserID('yellow');
$this->createNewFoswikiSession();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "ReservoirDogsGroup" );
$topicObject->text(<<"THIS");
* Set GROUP = MrWhite, $this->{users_web}.MrBlue
THIS
$topicObject->save();
$topicObject->finish();
return;
}
sub DENIED {
my ( $this, $mode, $user, $web, $topic ) = @_;
$web ||= $this->{test_web};
$topic ||= $this->{test_topic};
my ($topicObject) = Foswiki::Func::readTopic( $web, $topic );
$this->assert( !$topicObject->haveAccess( $mode, $user ),
"$user $mode $web.$topic" );
if ($post11) {
$this->assert(
!$this->{session}->access->haveAccess( $mode, $user, $topicObject ),
"$user $mode $web.$topic"
);
$this->assert(
!$this->{session}->access->haveAccess(
$mode, $user, $topicObject->web, $topicObject->topic
),
"$user $mode $web.$topic"
);
}
$topicObject->finish();
return;
}
sub PERMITTED {
my ( $this, $mode, $user, $web, $topic ) = @_;
$web ||= $this->{test_web};
$topic ||= $this->{test_topic};
my ($topicObject) = Foswiki::Func::readTopic( $web, $topic );
$this->assert( $topicObject->haveAccess( $mode, $user ),
"$user $mode $web.$topic" );
if ($post11) {
$this->assert(
$this->{session}->access->haveAccess( $mode, $user, $topicObject ),
"$user $mode $web.$topic"
);
$this->assert(
$this->{session}->access->haveAccess(
$mode, $user, $topicObject->web, $topicObject->topic
),
"$user $mode $web.$topic"
);
}
$topicObject->finish();
return;
}
# Note: As we do not initialize with a query, the topic that topic prefs
# are initialized from is WebHome. Thus these tests also test reading a topic
# other than the current topic.
# Test that explicitly defined users are denied topic view
sub test_denytopic {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<"THIS");
If DENYTOPIC is set to a list of wikinames
* people in the list will be DENIED.
* Set DENYTOPICVIEW = MrGreen
* Set DENYTOPICVIEW = ,,MrYellow,,$this->{users_web}.MrOrange,%USERSWEB%.ReservoirDogsGroup,,,
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that an empty DENYTOPIC doesn't deny anyone
sub test_empty_denytopic {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = )
* access is PERMITTED _i.e _ no-one is denied access to this topic
* Set DENYTOPICVIEW=
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that an empty DENYTOPIC doesn't deny anyone
sub test_whitespace_denytopic {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = )
* access is PERMITTED _i.e _ no-one is denied access to this topic
* Set DENYTOPICVIEW =
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that an whitespace at the end of DENYTOPIC is ok
sub test_denytopic_whitespace {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = )
* access is PERMITTED _i.e _ no-one is denied access to this topic
* Set DENYTOPICVIEW = MrBlue
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that explicitly defined ALLOWTOPIC excludes everyone else
sub test_allowtopic {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If ALLOWTOPIC is set
1. people in the list are PERMITTED
2. everyone else is DENIED
* Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that explicitly defined ALLOWTOPIC excludes everyone else
# Renew the session after each check to force refresh of any caches
sub test_allowtopic_a {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If ALLOWTOPIC is set
1. people in the list are PERMITTED
2. everyone else is DENIED
* Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange
THIS
$topicObject->save();
$topicObject->finish();
my $topicquery = Unit::Request->new("");
$topicquery->path_info("/$this->{test_web}/$this->{test_topic}");
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession( undef, $topicquery );
$this->DENIED( "VIEW", $MrOrange );
$this->createNewFoswikiSession( undef, $topicquery );
$this->DENIED( "VIEW", $MrGreen );
$this->createNewFoswikiSession( undef, $topicquery );
$this->DENIED( "VIEW", $MrYellow );
$this->createNewFoswikiSession( undef, $topicquery );
$this->DENIED( "VIEW", $MrWhite );
$this->createNewFoswikiSession( undef, $topicquery );
$this->DENIED( "VIEW", $MrBlue );
$this->createNewFoswikiSession( undef, $topicquery );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that explicitly defined ALLOWTOPIC excludes everyone else
# Renew the session after each check to force refresh of any caches,
# but don't provide a context,
sub test_allowtopic_b {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If ALLOWTOPIC is set
1. people in the list are PERMITTED
2. everyone else is DENIED
* Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange
THIS
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrYellow );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrWhite );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrBlue );
$this->createNewFoswikiSession();
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that explicitly defined ALLOWTOPIC excludes everyone else
# Access control in META:PREFERENCE
sub test_allowtopic_c {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'THIS');
If ALLOWTOPIC is set
1. people in the list are PERMITTED
2. everyone else is DENIED
THIS
$topicObject->putKeyed(
'PREFERENCE',
{
name => "ALLOWTOPICVIEW",
title => "ALLOWTOPICVIEW",
type => "Set",
value => "%USERSWEB%.MrOrange MrYellow"
}
);
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrYellow );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrWhite );
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrBlue );
$this->createNewFoswikiSession();
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that DENYWEB works in a top-level web with no finalisation
sub test_denyweb {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web},
$Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<"THIS");
If DENYWEB is set to a list of wikiname
* people in the list are DENIED access
* Set DENYWEBVIEW = $this->{users_web}.MrOrange %USERSWEB%.MrBlue
THIS
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$this->createNewFoswikiSession();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text("Null points");
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that ALLOWWEB works in a top-level web with no finalisation
sub test_allow_web {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web},
$Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(
<<'THIS'
If ALLOWWEB is set to a list of wikinames
* people in the list will be PERMITTED
* everyone else will be DENIED
* Set ALLOWWEBVIEW = MrGreen MrYellow MrWhite
THIS
);
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text("Null points");
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that Web.UserName is equivalent to UserName in ACLs
sub test_webDotUserName {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(
<<'THIS'
If ALLOWTOPIC is set
1. people in the list are PERMITTED
2. everyone else is DENIED
* Set ALLOWTOPICVIEW = MrYellow,%USERSWEB%.MrOrange,Nosuchweb.MrGreen,%MAINWEB%.MrBlue,%SYSTEMWEB%.MrWhite
THIS
);
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrYellow );
$this->DENIED( "VIEW", $MrWhite );
$this->DENIED( "VIEW", $MrBlue );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
sub _checkSettings {
my ( $this, $meta ) = @_;
$this->assert(
!$meta->haveAccess( 'VIEW', $MrOrange ),
" 'VIEW' $this->{test_web}.$this->{test_topic}"
);
$this->assert(
!$meta->haveAccess( 'VIEW', $MrGreen ),
" 'VIEW' $this->{test_web}.$this->{test_topic}"
);
$this->assert(
!$meta->haveAccess( 'VIEW', $MrYellow ),
" 'VIEW' $this->{test_web}.$this->{test_topic}"
);
$this->assert(
!$meta->haveAccess( 'VIEW', $MrWhite ),
" 'VIEW' $this->{test_web}.$this->{test_topic}"
);
$this->assert(
!$meta->haveAccess( 'VIEW', $MrBlue ),
" 'VIEW' $this->{test_web}.$this->{test_topic}"
);
$this->assert(
$meta->haveAccess( 'VIEW', 'BaseUserMapping_333' ),
" 'VIEW' $this->{test_web}.$this->{test_topic}"
);
return;
}
# Test a * Set embedded in text
sub test_SetInText {
my $this = shift;
my $text = <<'THIS';
* Set ALLOWTOPICVIEW = %USERSWEB%.MrGreen
THIS
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text($text);
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->_checkSettings($topicObject);
$topicObject->finish();
return;
}
# Test a set in meta-data
sub test_setInMETA {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text('Empty');
my $args = {
name => 'ALLOWTOPICVIEW',
title => 'ALLOWTOPICVIEW',
value => "%USERSWEB%.MrGreen",
type => "Set"
};
$topicObject->putKeyed( 'PREFERENCE', $args );
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->_checkSettings($topicObject);
$topicObject->finish();
return;
}
# Check that a PREFERENCE takes precedence over a setting in text
sub test_setInSetAndMETA {
my $this = shift;
my $text = <<'THIS';
* Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange
THIS
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text($text);
my $args = {
name => 'ALLOWTOPICVIEW',
title => 'ALLOWTOPICVIEW',
value => "%USERSWEB%.MrGreen",
type => "Set"
};
$topicObject->putKeyed( 'PREFERENCE', $args );
$topicObject->save();
$topicObject->finish();
# renew Foswiki, so WebPreferences gets re-read
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->_checkSettings($topicObject);
$topicObject->finish();
return;
}
# Test that hierarchical subweb controls override the parent web
sub test_subweb_controls_override_parent {
my $this = shift;
my $subweb = "$this->{test_web}.SubWeb";
$Foswiki::cfg{EnableHierarchicalWebs} = 1;
# First build a parent web with view restricted to MrGreen
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text("Nowt");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web},
$Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<'THIS');
* Set ALLOWWEBVIEW = MrGreen
THIS
$topicObject->save();
$topicObject->finish();
# Now build a subweb with view restricted to MrOrange
my $webObject = $this->populateNewWeb($subweb);
$webObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<'THIS');
* Set ALLOWWEBVIEW = MrOrange
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange, $subweb );
$this->DENIED( "VIEW", $MrGreen, $subweb );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrOrange );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that controls are inherited from parent webs
sub test_subweb_inherits_from_parent {
my $this = shift;
my $subweb = "$this->{test_web}.SubWeb";
$Foswiki::cfg{EnableHierarchicalWebs} = 1;
# First build a parent web with view restricted to MrGreen, and
# finalise the setting
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web},
$Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<'THIS');
* Set ALLOWWEBVIEW = MrGreen
* Set FINALPREFERENCES = ALLOWWEBVIEW
THIS
$topicObject->save();
$topicObject->finish();
# Now build a subweb with no restrictions
my $webObject = $this->populateNewWeb($subweb);
$webObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<'THIS');
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrGreen, $subweb );
$this->DENIED( "VIEW", $MrOrange, $subweb );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrOrange );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# Test that finalised controls in parent web override the subweb controls
sub test_finalised_parent_overrides_subweb {
my $this = shift;
my $subweb = "$this->{test_web}.SubWeb";
$Foswiki::cfg{EnableHierarchicalWebs} = 1;
# First build a parent web with view restricted to MrGreen, and
# finalise the setting
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web},
$Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<'THIS');
* Set ALLOWWEBVIEW = MrGreen
* Set FINALPREFERENCES = ALLOWWEBVIEW
THIS
$topicObject->save();
$topicObject->finish();
# Now build a subweb with view restricted to MrOrange
my $webObject = $this->populateNewWeb($subweb);
$webObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text(<<'THIS');
* Set ALLOWWEBVIEW = MrOrange
THIS
$topicObject->save();
$topicObject->finish();
$Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess';
$this->createNewFoswikiSession();
$this->DENIED( "VIEW", $MrOrange, $subweb );
$this->DENIED( "VIEW", $MrGreen, $subweb );
$this->DENIED( "VIEW", $MrGreen );
$this->DENIED( "VIEW", $MrOrange );
$this->PERMITTED( "VIEW", 'BaseUserMapping_333' );
return;
}
# As anchors are never sent by the browser, this is done through JS
# and only testable by Selenium
# Kept this test here as it is the only one I (Babar) know of doing the full
# Foswiki::UI chain, therefore catching the AccessControlExceptions
sub test_login_redirect_preserves_anchor {
my $this = shift;
my $test_topic = 'TestAnchor';
# Create a topic with an anchor, viewable only by MrYellow
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $test_topic );
$topicObject->text( <<'THIS' );
If there is an anchor, and some access restrictions,
anchor is preserved after login.
#anchor
* Set ALLOWTOPICVIEW = MrYellow
THIS
$topicObject->save();
$topicObject->finish();
# Request the page with the full UI
my $query = Unit::Request->new(
{
webName => [ $this->{test_web} ],
topicName => ["$test_topic"],
}
);
$query->path_info("/$this->{test_web}/$test_topic");
$query->method('GET');
$query->action('view');
my $viewUrl =
$this->{session}
->getScriptUrl( 0, 'view', $this->{test_web}, $test_topic );
$query->uri("$viewUrl");
$this->finishFoswikiSession();
my ($text) = $this->capture(
sub {
my $response = Foswiki::UI::handleRequest($query);
$this->createNewFoswikiSession( undef, $query );
$this->{session}{response} = $response;
}
);
# Get the login and view URLs to compare
my $loginUrl =
$this->{session}
->getScriptUrl( 0, 'login', $this->{test_web}, $test_topic );
my $fullViewUrl =
$this->{session}
->getScriptUrl( 1, 'view', $this->{test_web}, $test_topic );
# Item11121: the test doesn't tolerate ShortURLs, for example.
# ShortURLs may involve a {ScriptUrlPaths}{view} of '' or something
# like '/foswiki' (where {ScriptUrlPath} looks like '/foswiki/bin').
# In any case, the test is hard-wired to ignore {ScriptSuffix}
$this->expect_failure( 'Test does\'t cater to ShortURL configurations',
using => 'ShortURLs' );
# Check we got a 401
my ($status) = $text =~ m/^Status: (\d+)\r?$/m;
$this->assert_not_null( $status, "Request did not return a Status header" );
$this->assert_equals( 401, $status,
"Request should have returned a 401, not a $status" );
# Extract what we've been redirected to
my ($formAction) =
$text =~ m/<form action='(.*?)' name='loginform' method='post'/m;
$this->assert_not_null( $formAction,
"Request should have returned a 401 to $loginUrl\n"
. "But it returned:\n$text" );
$this->assert_equals( $loginUrl, $formAction );
# Check the foswiki_origin contains the view URL to this topic
my ($origin) = $text =~
m/^<input type="hidden" name="foswiki_origin" value="([^"]+)" \/>\r?$/m;
$this->assert_not_null( $origin,
"No viewUrl (GET,view,$viewUrl) in foswiki_origin, got:\n$text" );
$this->assert_equals( "GET,view,$viewUrl", $origin );
# Get the redirected page after login
return;
}
1;