- Timestamp:
- 01/23/12 06:00:05 (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm
r13730 r13791 5 5 #Sven wishes he could use ISA AccessControlTest, but the unit test system doesn't do inherited test subs 6 6 7 use FoswikiFnTestCase ;7 use FoswikiFnTestCase(); 8 8 our @ISA = qw( FoswikiFnTestCase ); 9 9 … … 12 12 use Foswiki::Meta (); 13 13 use Foswiki::Plugins (); 14 use Foswiki::Configure::Dependency(); 14 15 15 16 # For Anchor test 16 17 use Foswiki::UI (); 18 19 my $post11 = 0; 17 20 18 21 sub new { … … 20 23 my $self = $class->SUPER::new( 'AccessControl', @args ); 21 24 25 my $dep = new Foswiki::Configure::Dependency( 26 type => "perl", 27 module => "Foswiki", 28 version => ">=1.2" 29 ); 30 my ( $ok, $message ) = $dep->check(); 31 $post11 = $ok; 32 22 33 return $self; 23 34 } 24 35 36 =todo 25 37 sub loadExtraConfig { 26 38 my ( $this, $context, @args ) = @_; … … 35 47 return; 36 48 } 49 =cut 37 50 38 51 my $MrWhite; … … 46 59 $this->SUPER::set_up(); 47 60 48 my $topicObject = Foswiki::Meta->new( 49 $this->{session}, 50 $Foswiki::cfg{UsersWebName}, 51 $Foswiki::cfg{DefaultUserWikiName}, '' 52 ); 53 $topicObject->save(); 61 my ($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, 62 $Foswiki::cfg{DefaultUserWikiName} ); 63 $topicObject->text(''); 64 $topicObject->save(); 65 $topicObject->finish(); 54 66 $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); 55 67 $MrWhite = $this->{session}->{users}->getCanonicalUserID('white'); … … 63 75 $MrYellow = $this->{session}->{users}->getCanonicalUserID('yellow'); 64 76 65 $topicObject = 66 Foswiki::Meta->new( $this->{session}, $this->{users_web}, 67 "ReservoirDogsGroup", <<"THIS"); 77 $this->createNewFoswikiSession(); 78 ($topicObject) = 79 Foswiki::Func::readTopic( $this->{users_web}, "ReservoirDogsGroup" ); 80 $topicObject->text(<<"THIS"); 68 81 * Set GROUP = MrWhite, $this->{users_web}.MrBlue 69 82 THIS 70 83 $topicObject->save(); 71 72 return; 73 } 74 75 sub tear_down { 76 my $this = shift; 77 $this->SUPER::tear_down(); 84 $topicObject->finish(); 78 85 79 86 return; … … 84 91 $web ||= $this->{test_web}; 85 92 $topic ||= $this->{test_topic}; 86 my $topicObject = Foswiki::Meta->load( $this->{session},$web, $topic );93 my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 87 94 $this->assert( !$topicObject->haveAccess( $mode, $user ), 88 95 "$user $mode $web.$topic" ); 96 97 if ($post11) { 98 require Foswiki::Address; 99 $this->assert( 100 !$this->{session}->access->haveAccess( $mode, $user, $topicObject ), 101 "$user $mode $web.$topic" 102 ); 103 $this->assert( 104 !$this->{session}->access->haveAccess( 105 $mode, $user, $topicObject->web, $topicObject->topic 106 ), 107 "$user $mode $web.$topic" 108 ); 109 $this->assert( 110 !$this->{session}->access->haveAccess( 111 $mode, $user, 112 Foswiki::Address->new( 113 web => $topicObject->web, 114 topic => $topicObject->topic 115 ) 116 ), 117 "$user $mode $web.$topic" 118 ); 119 } 120 $topicObject->finish(); 89 121 90 122 return; … … 95 127 $web ||= $this->{test_web}; 96 128 $topic ||= $this->{test_topic}; 97 my $topicObject = Foswiki::Meta->load( $this->{session},$web, $topic );129 my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 98 130 $this->assert( $topicObject->haveAccess( $mode, $user ), 99 131 "$user $mode $web.$topic" ); 132 133 if ($post11) { 134 require Foswiki::Address; 135 $this->assert( 136 $this->{session}->access->haveAccess( $mode, $user, $topicObject ), 137 "$user $mode $web.$topic" 138 ); 139 $this->assert( 140 $this->{session}->access->haveAccess( 141 $mode, $user, $topicObject->web, $topicObject->topic 142 ), 143 "$user $mode $web.$topic" 144 ); 145 $this->assert( 146 $this->{session}->access->haveAccess( 147 $mode, $user, 148 Foswiki::Address->new( 149 web => $topicObject->web, 150 topic => $topicObject->topic 151 ) 152 ), 153 "$user $mode $web.$topic" 154 ); 155 } 156 $topicObject->finish(); 100 157 101 158 return; … … 109 166 sub test_denytopic { 110 167 my $this = shift; 111 my $topicObject=112 Foswiki:: Meta->new( $this->{session}, $this->{test_web},113 $this->{test_topic},<<"THIS");168 my ($topicObject) = 169 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 170 $topicObject->text(<<"THIS"); 114 171 If DENYTOPIC is set to a list of wikinames 115 172 * people in the list will be DENIED. … … 118 175 THIS 119 176 $topicObject->save(); 120 121 $this->{session}->finish(); 122 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 123 $this-> {session} = Foswiki->new();177 $topicObject->finish(); 178 179 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 180 $this->createNewFoswikiSession(); 124 181 125 182 $this->DENIED( "VIEW", $MrGreen ); … … 136 193 sub test_empty_denytopic { 137 194 my $this = shift; 138 my $topicObject=139 Foswiki:: Meta->new( $this->{session}, $this->{test_web},140 $this->{test_topic},<<'THIS');195 my ($topicObject) = 196 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 197 $topicObject->text(<<'THIS'); 141 198 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 142 199 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 144 201 THIS 145 202 $topicObject->save(); 146 147 $this->{session}->finish(); 148 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 149 $this-> {session} = Foswiki->new();203 $topicObject->finish(); 204 205 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 206 $this->createNewFoswikiSession(); 150 207 $this->DENIED( "VIEW", $MrGreen ); 151 208 $this->DENIED( "VIEW", $MrYellow ); … … 161 218 sub test_whitespace_denytopic { 162 219 my $this = shift; 163 my $topicObject=164 Foswiki:: Meta->new( $this->{session}, $this->{test_web},165 $this->{test_topic},<<'THIS');220 my ($topicObject) = 221 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 222 $topicObject->text(<<'THIS'); 166 223 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 167 224 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 169 226 THIS 170 227 $topicObject->save(); 171 172 $this->{session}->finish(); 173 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 174 $this-> {session} = Foswiki->new();228 $topicObject->finish(); 229 230 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 231 $this->createNewFoswikiSession(); 175 232 $this->DENIED( "VIEW", $MrGreen ); 176 233 $this->DENIED( "VIEW", $MrYellow ); … … 186 243 sub test_denytopic_whitespace { 187 244 my $this = shift; 188 my $topicObject=189 Foswiki:: Meta->new( $this->{session}, $this->{test_web},190 $this->{test_topic},<<'THIS');245 my ($topicObject) = 246 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 247 $topicObject->text(<<'THIS'); 191 248 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 192 249 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 194 251 THIS 195 252 $topicObject->save(); 196 197 $this->{session}->finish(); 198 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 199 $this-> {session} = Foswiki->new();253 $topicObject->finish(); 254 255 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 256 $this->createNewFoswikiSession(); 200 257 $this->DENIED( "VIEW", $MrGreen ); 201 258 $this->DENIED( "VIEW", $MrYellow ); … … 211 268 sub test_allowtopic { 212 269 my $this = shift; 213 my $topicObject=214 Foswiki:: Meta->new( $this->{session}, $this->{test_web},215 $this->{test_topic},<<'THIS');270 my ($topicObject) = 271 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 272 $topicObject->text(<<'THIS'); 216 273 If ALLOWTOPIC is set 217 274 1. people in the list are PERMITTED … … 220 277 THIS 221 278 $topicObject->save(); 222 223 $this->{session}->finish(); 224 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 225 $this-> {session} = Foswiki->new();279 $topicObject->finish(); 280 281 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 282 $this->createNewFoswikiSession(); 226 283 $this->DENIED( "VIEW", $MrOrange ); 227 284 $this->DENIED( "VIEW", $MrGreen ); … … 238 295 sub test_allowtopic_a { 239 296 my $this = shift; 240 my $topicObject=241 Foswiki:: Meta->new( $this->{session}, $this->{test_web},242 $this->{test_topic},<<'THIS');297 my ($topicObject) = 298 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 299 $topicObject->text(<<'THIS'); 243 300 If ALLOWTOPIC is set 244 301 1. people in the list are PERMITTED … … 247 304 THIS 248 305 $topicObject->save(); 306 $topicObject->finish(); 249 307 250 308 my $topicquery = Unit::Request->new(""); 251 309 $topicquery->path_info("/$this->{test_web}/$this->{test_topic}"); 252 310 253 # reFoswiki->new, so WebPreferences gets re-read 254 $this->{session}->finish(); 255 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 256 $this->{session} = Foswiki->new( undef, $topicquery ); 257 $this->DENIED( "VIEW", $MrOrange ); 258 $this->{session}->finish(); 259 $this->{session} = Foswiki->new( undef, $topicquery ); 260 $this->DENIED( "VIEW", $MrGreen ); 261 $this->{session}->finish(); 262 $this->{session} = Foswiki->new( undef, $topicquery ); 263 $this->DENIED( "VIEW", $MrYellow ); 264 $this->{session}->finish(); 265 $this->{session} = Foswiki->new( undef, $topicquery ); 266 $this->DENIED( "VIEW", $MrWhite ); 267 $this->{session}->finish(); 268 $this->{session} = Foswiki->new( undef, $topicquery ); 269 $this->DENIED( "view", $MrBlue ); 270 $this->{session}->finish(); 271 $this->{session} = Foswiki->new(); 311 # renew Foswiki, so WebPreferences gets re-read 312 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 313 $this->createNewFoswikiSession( undef, $topicquery ); 314 $this->DENIED( "VIEW", $MrOrange ); 315 $this->createNewFoswikiSession( undef, $topicquery ); 316 $this->DENIED( "VIEW", $MrGreen ); 317 $this->createNewFoswikiSession( undef, $topicquery ); 318 $this->DENIED( "VIEW", $MrYellow ); 319 $this->createNewFoswikiSession( undef, $topicquery ); 320 $this->DENIED( "VIEW", $MrWhite ); 321 $this->createNewFoswikiSession( undef, $topicquery ); 322 $this->DENIED( "view", $MrBlue ); 323 $this->createNewFoswikiSession( undef, $topicquery ); 272 324 $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 273 325 … … 280 332 sub test_allowtopic_b { 281 333 my $this = shift; 282 my $topicObject=283 Foswiki:: Meta->new( $this->{session}, $this->{test_web},284 $this->{test_topic},<<'THIS');334 my ($topicObject) = 335 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 336 $topicObject->text(<<'THIS'); 285 337 If ALLOWTOPIC is set 286 338 1. people in the list are PERMITTED … … 289 341 THIS 290 342 $topicObject->save(); 291 292 # reFoswiki->new, so WebPreferences gets re-read 293 $this->{session}->finish(); 294 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 295 $this->{session} = Foswiki->new(); 296 $this->DENIED( "VIEW", $MrOrange ); 297 $this->{session}->finish(); 298 $this->{session} = Foswiki->new(); 299 $this->DENIED( "VIEW", $MrGreen ); 300 $this->{session}->finish(); 301 $this->{session} = Foswiki->new(); 302 $this->DENIED( "VIEW", $MrYellow ); 303 $this->{session}->finish(); 304 $this->{session} = Foswiki->new(); 305 $this->DENIED( "VIEW", $MrWhite ); 306 $this->{session}->finish(); 307 $this->{session} = Foswiki->new(); 308 $this->DENIED( "view", $MrBlue ); 309 $this->{session}->finish(); 310 $this->{session} = Foswiki->new(); 343 $topicObject->finish(); 344 345 # renew Foswiki, so WebPreferences gets re-read 346 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 347 $this->createNewFoswikiSession(); 348 $this->DENIED( "VIEW", $MrOrange ); 349 $this->createNewFoswikiSession(); 350 $this->DENIED( "VIEW", $MrGreen ); 351 $this->createNewFoswikiSession(); 352 $this->DENIED( "VIEW", $MrYellow ); 353 $this->createNewFoswikiSession(); 354 $this->DENIED( "VIEW", $MrWhite ); 355 $this->createNewFoswikiSession(); 356 $this->DENIED( "view", $MrBlue ); 357 $this->createNewFoswikiSession(); 311 358 $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 312 359 … … 318 365 sub test_allowtopic_c { 319 366 my $this = shift; 320 my $topicObject=321 Foswiki:: Meta->new( $this->{session}, $this->{test_web},322 $this->{test_topic},<<'THIS');367 my ($topicObject) = 368 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 369 $topicObject->text(<<'THIS'); 323 370 If ALLOWTOPIC is set 324 371 1. people in the list are PERMITTED … … 335 382 ); 336 383 $topicObject->save(); 337 338 # reFoswiki->new, so WebPreferences gets re-read 339 $this->{session}->finish(); 340 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 341 $this->{session} = Foswiki->new(); 342 $this->DENIED( "VIEW", $MrOrange ); 343 $this->{session}->finish(); 344 $this->{session} = Foswiki->new(); 345 $this->DENIED( "VIEW", $MrGreen ); 346 $this->{session}->finish(); 347 $this->{session} = Foswiki->new(); 348 $this->DENIED( "VIEW", $MrYellow ); 349 $this->{session}->finish(); 350 $this->{session} = Foswiki->new(); 351 $this->DENIED( "VIEW", $MrWhite ); 352 $this->{session}->finish(); 353 $this->{session} = Foswiki->new(); 354 $this->DENIED( "view", $MrBlue ); 355 $this->{session}->finish(); 356 $this->{session} = Foswiki->new(); 384 $topicObject->finish(); 385 386 # renew Foswiki, so WebPreferences gets re-read 387 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 388 $this->createNewFoswikiSession(); 389 $this->DENIED( "VIEW", $MrOrange ); 390 $this->createNewFoswikiSession(); 391 $this->DENIED( "VIEW", $MrGreen ); 392 $this->createNewFoswikiSession(); 393 $this->DENIED( "VIEW", $MrYellow ); 394 $this->createNewFoswikiSession(); 395 $this->DENIED( "VIEW", $MrWhite ); 396 $this->createNewFoswikiSession(); 397 $this->DENIED( "view", $MrBlue ); 398 $this->createNewFoswikiSession(); 357 399 $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 358 400 … … 363 405 sub test_denyweb { 364 406 my $this = shift; 365 my $topicObject = 366 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 367 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 407 my ($topicObject) = 408 Foswiki::Func::readTopic( $this->{test_web}, 409 $Foswiki::cfg{WebPrefsTopicName} ); 410 $topicObject->text(<<"THIS"); 368 411 If DENYWEB is set to a list of wikiname 369 412 * people in the list are DENIED access … … 371 414 THIS 372 415 $topicObject->save(); 373 374 # reFoswiki->new, so WebPreferences gets re-read 375 $topicObject = Foswiki::Meta->new( 376 $this->{session}, $this->{test_web}, 377 $this->{test_topic}, "Null points" 378 ); 379 $topicObject->save(); 380 381 $this->{session}->finish(); 382 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 383 $this->{session} = Foswiki->new(); 416 $topicObject->finish(); 417 418 # renew Foswiki, so WebPreferences gets re-read 419 $this->createNewFoswikiSession(); 420 ($topicObject) = 421 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 422 $topicObject->text("Null points"); 423 $topicObject->save(); 424 $topicObject->finish(); 425 426 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 427 $this->createNewFoswikiSession(); 384 428 385 429 $this->DENIED( "VIEW", $MrOrange ); … … 395 439 # Test that ALLOWWEB works in a top-level web with no finalisation 396 440 sub test_allow_web { 397 my $this = shift; 398 my $topicObject = Foswiki::Meta->new( 399 $this->{session}, 400 $this->{test_web}, $Foswiki::cfg{WebPrefsTopicName}, 441 my $this = shift; 442 my ($topicObject) = 443 Foswiki::Func::readTopic( $this->{test_web}, 444 $Foswiki::cfg{WebPrefsTopicName} ); 445 $topicObject->text( 401 446 <<'THIS' 402 447 If ALLOWWEB is set to a list of wikinames … … 405 450 * Set ALLOWWEBVIEW = MrGreen MrYellow MrWhite 406 451 THIS 407 , undef 408 ); 409 $topicObject->save(); 410 411 $topicObject = Foswiki::Meta->new( 412 $this->{session}, $this->{test_web}, 413 $this->{test_topic}, "Null points" 414 ); 415 $topicObject->save(); 416 417 # reFoswiki->new, so WebPreferences gets re-read 418 $this->{session}->finish(); 419 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 420 $this->{session} = Foswiki->new(); 452 ); 453 $topicObject->save(); 454 $topicObject->finish(); 455 456 ($topicObject) = 457 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 458 $topicObject->text("Null points"); 459 $topicObject->save(); 460 $topicObject->finish(); 461 462 # renew Foswiki, so WebPreferences gets re-read 463 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 464 $this->createNewFoswikiSession(); 421 465 422 466 $this->DENIED( "VIEW", $MrOrange ); … … 432 476 # Test that Web.UserName is equivalent to UserName in ACLs 433 477 sub test_webDotUserName { 434 my $this = shift; 435 my $topicObject = Foswiki::Meta->new( 436 $this->{session}, $this->{test_web}, $this->{test_topic}, 478 my $this = shift; 479 my ($topicObject) = 480 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 481 $topicObject->text( 437 482 <<'THIS' 438 483 If ALLOWTOPIC is set … … 441 486 * Set ALLOWTOPICVIEW = MrYellow,%USERSWEB%.MrOrange,Nosuchweb.MrGreen,%MAINWEB%.MrBlue,%SYSTEMWEB%.MrWhite 442 487 THIS 443 , undef 444 ); 445 $topicObject->save(); 446 447 # reFoswiki->new, so WebPreferences gets re-read 448 $this->{session}->finish(); 449 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 450 $this->{session} = Foswiki->new(); 488 ); 489 $topicObject->save(); 490 $topicObject->finish(); 491 492 # renew Foswiki, so WebPreferences gets re-read 493 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 494 $this->createNewFoswikiSession(); 451 495 452 496 $this->DENIED( "VIEW", $MrOrange ); … … 498 542 * Set ALLOWTOPICVIEW = %USERSWEB%.MrGreen 499 543 THIS 500 my $topicObject = 501 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 502 $this->{test_topic}, $text ); 503 $topicObject->save(); 504 505 # reFoswiki->new, so WebPreferences gets re-read 506 $this->{session}->finish(); 507 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 508 $this->{session} = Foswiki->new(); 509 510 $topicObject = 511 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 512 $this->{test_topic} ); 544 my ($topicObject) = 545 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 546 $topicObject->text($text); 547 $topicObject->save(); 548 $topicObject->finish(); 549 550 # renew Foswiki, so WebPreferences gets re-read 551 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 552 $this->createNewFoswikiSession(); 553 554 ($topicObject) = 555 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 513 556 $this->_checkSettings($topicObject); 557 $topicObject->finish(); 514 558 515 559 return; … … 520 564 my $this = shift; 521 565 522 my $topicObject=523 Foswiki:: Meta->new( $this->{session}, $this->{test_web},524 $this->{test_topic}, 'Empty');566 my ($topicObject) = 567 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 568 $topicObject->text('Empty'); 525 569 my $args = { 526 570 name => 'ALLOWTOPICVIEW', … … 531 575 $topicObject->putKeyed( 'PREFERENCE', $args ); 532 576 $topicObject->save(); 533 534 # reFoswiki->new, so WebPreferences gets re-read 535 $this->{session}->finish(); 536 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 537 $this->{session} = Foswiki->new(); 538 539 $topicObject = 540 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 541 $this->{test_topic} ); 577 $topicObject->finish(); 578 579 # renew Foswiki, so WebPreferences gets re-read 580 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 581 $this->createNewFoswikiSession(); 582 583 ($topicObject) = 584 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 542 585 543 586 $this->_checkSettings($topicObject); 587 $topicObject->finish(); 544 588 545 589 return; … … 553 597 * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange 554 598 THIS 555 my $topicObject=556 Foswiki:: Meta->new( $this->{session}, $this->{test_web},557 $this->{test_topic}, $text);599 my ($topicObject) = 600 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 601 $topicObject->text($text); 558 602 my $args = { 559 603 name => 'ALLOWTOPICVIEW', … … 564 608 $topicObject->putKeyed( 'PREFERENCE', $args ); 565 609 $topicObject->save(); 566 567 # reFoswiki->new, so WebPreferences gets re-read 568 $this->{session}->finish(); 569 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 570 $this->{session} = Foswiki->new(); 571 572 $topicObject = 573 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 574 $this->{test_topic} ); 610 $topicObject->finish(); 611 612 # renew Foswiki, so WebPreferences gets re-read 613 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 614 $this->createNewFoswikiSession(); 615 616 ($topicObject) = 617 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 575 618 $this->_checkSettings($topicObject); 619 $topicObject->finish(); 576 620 577 621 return; … … 586 630 587 631 # First build a parent web with view restricted to MrGreen 588 my $topicObject = 589 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 590 $this->{test_topic}, "Nowt" ); 591 $topicObject->save(); 592 593 $topicObject = 594 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 595 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 632 my ($topicObject) = 633 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 634 $topicObject->text("Nowt"); 635 $topicObject->save(); 636 $topicObject->finish(); 637 638 ($topicObject) = 639 Foswiki::Func::readTopic( $this->{test_web}, 640 $Foswiki::cfg{WebPrefsTopicName} ); 641 $topicObject->text(<<'THIS'); 596 642 * Set ALLOWWEBVIEW = MrGreen 597 643 THIS 598 644 $topicObject->save(); 645 $topicObject->finish(); 599 646 600 647 # Now build a subweb with view restricted to MrOrange 601 648 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 602 649 $webObject->populateNewWeb(); 603 $topicObject = 604 Foswiki::Meta->new( $this->{session}, $subweb, 605 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 650 $webObject->finish(); 651 ($topicObject) = 652 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 653 $topicObject->text(<<'THIS'); 606 654 * Set ALLOWWEBVIEW = MrOrange 607 655 THIS 608 656 $topicObject->save(); 609 $t his->{session}->finish();610 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 611 $this-> {session} = Foswiki->new();657 $topicObject->finish(); 658 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 659 $this->createNewFoswikiSession(); 612 660 $this->DENIED( "VIEW", $MrOrange, $subweb ); 613 661 $this->DENIED( "VIEW", $MrGreen, $subweb ); … … 628 676 # First build a parent web with view restricted to MrGreen, and 629 677 # finalise the setting 630 my $topicObject = 631 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 632 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 678 my ($topicObject) = 679 Foswiki::Func::readTopic( $this->{test_web}, 680 $Foswiki::cfg{WebPrefsTopicName} ); 681 $topicObject->text(<<'THIS'); 633 682 * Set ALLOWWEBVIEW = MrGreen 634 683 * Set FINALPREFERENCES = ALLOWWEBVIEW 635 684 THIS 636 685 $topicObject->save(); 686 $topicObject->finish(); 637 687 638 688 # Now build a subweb with no restrictions 639 689 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 640 690 $webObject->populateNewWeb(); 641 $topicObject = 642 Foswiki::Meta->new( $this->{session}, $subweb, 643 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 644 THIS 645 $topicObject->save(); 646 $this->{session}->finish(); 647 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 648 $this->{session} = Foswiki->new(); 691 $webObject->finish(); 692 ($topicObject) = 693 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 694 $topicObject->text(<<'THIS'); 695 THIS 696 $topicObject->save(); 697 $topicObject->finish(); 698 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 699 $this->createNewFoswikiSession(); 649 700 $this->DENIED( "VIEW", $MrGreen, $subweb ); 650 701 $this->DENIED( "VIEW", $MrOrange, $subweb ); … … 665 716 # First build a parent web with view restricted to MrGreen, and 666 717 # finalise the setting 667 my $topicObject = 668 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 669 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 718 my ($topicObject) = 719 Foswiki::Func::readTopic( $this->{test_web}, 720 $Foswiki::cfg{WebPrefsTopicName} ); 721 $topicObject->text(<<'THIS'); 670 722 * Set ALLOWWEBVIEW = MrGreen 671 723 * Set FINALPREFERENCES = ALLOWWEBVIEW 672 724 THIS 673 725 $topicObject->save(); 726 $topicObject->finish(); 674 727 675 728 # Now build a subweb with view restricted to MrOrange 676 729 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 677 730 $webObject->populateNewWeb(); 678 $topicObject = 679 Foswiki::Meta->new( $this->{session}, $subweb, 680 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 731 $webObject->finish(); 732 ($topicObject) = 733 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 734 $topicObject->text(<<'THIS'); 681 735 * Set ALLOWWEBVIEW = MrOrange 682 736 THIS 683 737 $topicObject->save(); 684 $t his->{session}->finish();685 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 686 $this-> {session} = Foswiki->new();738 $topicObject->finish(); 739 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 740 $this->createNewFoswikiSession(); 687 741 $this->DENIED( "VIEW", $MrOrange, $subweb ); 688 742 $this->DENIED( "VIEW", $MrGreen, $subweb ); … … 703 757 704 758 # Create a topic with an anchor, viewable only by MrYellow 705 my $topicObject = Foswiki::Meta->new(706 $this->{session}, $this->{test_web}, $test_topic,707 <<'THIS'759 my ($topicObject) = 760 Foswiki::Func::readTopic( $this->{test_web}, $test_topic ); 761 $topicObject->text( <<'THIS' ); 708 762 If there is an anchor, and some access restrictions, 709 763 anchor is preserved after login. … … 711 765 * Set ALLOWTOPICVIEW = MrYellow 712 766 THIS 713 , undef 714 ); 715 $topicObject->save(); 767 $topicObject->save(); 768 $topicObject->finish(); 716 769 717 770 # Request the page with the full UI … … 727 780 my $viewUrl = 728 781 $this->{session} 729 ->getScriptUrl( '0', 'view', $this->{test_web}, $test_topic );782 ->getScriptUrl( 0, 'view', $this->{test_web}, $test_topic ); 730 783 $query->uri("$viewUrl"); 784 $this->finishFoswikiSession(); 731 785 my ($text) = $this->capture( 732 786 sub { 733 $Foswiki::Plugins::SESSION->{response} = 734 Foswiki::UI::handleRequest($query); 787 my $response = Foswiki::UI::handleRequest($query); 788 $this->createNewFoswikiSession( undef, $query ); 789 $this->{session}{response} = $response; 735 790 } 736 791 ); … … 739 794 my $loginUrl = 740 795 $this->{session} 741 ->getScriptUrl( '0', 'login', $this->{test_web}, $test_topic );796 ->getScriptUrl( 0, 'login', $this->{test_web}, $test_topic ); 742 797 743 798 # Item11121: the test doesn't tolerate ShortURLs, for example. … … 755 810 756 811 # Check the redirect contains the login url + view to this topic 757 $this->assert_matches( 758 qr#^$loginUrl.*/view/$this->{test_web}/$test_topic$#, 759 $redirect_to, 760 "Login did not redirect to a page with the proper anchor:\n" 812 my $regex = qr#^\Q$loginUrl\E.*/view/$this->{test_web}/$test_topic$#; 813 $this->assert_matches( $regex, $redirect_to, 814 "Login did not redirect to a page with the proper anchor:\n" 761 815 . "Location: $redirect_to\n" 762 . "Expected: ^$loginUrl.*\%23anchor\$" 763 ); 816 . "Expected: $regex" ); 764 817 765 818 # Get the redirected page after login
Note: See TracChangeset
for help on using the changeset viewer.
