| 1 | |
|---|
| 2 | |
|---|
| 3 | #TODO: permission tests |
|---|
| 4 | #TODO: non-existant user test |
|---|
| 5 | |
|---|
| 6 | use strict; |
|---|
| 7 | use warnings; |
|---|
| 8 | use diagnostics; |
|---|
| 9 | |
|---|
| 10 | package ManageDotPmTests; |
|---|
| 11 | |
|---|
| 12 | use FoswikiFnTestCase; |
|---|
| 13 | our @ISA = qw( FoswikiFnTestCase ); |
|---|
| 14 | use Error qw(:try); |
|---|
| 15 | use Foswiki; |
|---|
| 16 | use Foswiki::UI::Manage; |
|---|
| 17 | use Foswiki::UI::Save; |
|---|
| 18 | use FileHandle; |
|---|
| 19 | |
|---|
| 20 | our $REG_UI_FN; |
|---|
| 21 | our $MAN_UI_FN; |
|---|
| 22 | |
|---|
| 23 | # Set up the test fixture |
|---|
| 24 | sub set_up { |
|---|
| 25 | my $this = shift; |
|---|
| 26 | $this->SUPER::set_up(); |
|---|
| 27 | |
|---|
| 28 | $REG_UI_FN ||= $this->getUIFn('register'); |
|---|
| 29 | $MAN_UI_FN ||= $this->getUIFn('manage'); |
|---|
| 30 | |
|---|
| 31 | @FoswikiFnTestCase::mails = (); |
|---|
| 32 | |
|---|
| 33 | } |
|---|
| 34 | sub tear_down { |
|---|
| 35 | my $this = shift; |
|---|
| 36 | |
|---|
| 37 | $this->SUPER::tear_down(); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | ################################### |
|---|
| 41 | #verify tests |
|---|
| 42 | |
|---|
| 43 | sub AllowLoginName { |
|---|
| 44 | my $this = shift; |
|---|
| 45 | $Foswiki::cfg{Register}{AllowLoginName} = 1; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | sub DontAllowLoginName { |
|---|
| 49 | my $this = shift; |
|---|
| 50 | $Foswiki::cfg{Register}{AllowLoginName} = 0; |
|---|
| 51 | $this->{new_user_login} = $this->{new_user_wikiname}; |
|---|
| 52 | |
|---|
| 53 | #$this->{test_user_login} = $this->{test_user_wikiname}; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | sub TemplateLoginManager { |
|---|
| 57 | $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin'; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | sub ApacheLoginManager { |
|---|
| 61 | $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::ApacheLogin'; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | sub NoLoginManager { |
|---|
| 65 | $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager'; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | sub HtPasswdManager { |
|---|
| 69 | $Foswiki::cfg{PasswordManager} = 'Foswiki::Users::HtPasswdUser'; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | sub NonePasswdManager { |
|---|
| 73 | $Foswiki::cfg{PasswordManager} = 'none'; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | sub BaseUserMapping { |
|---|
| 77 | my $this = shift; |
|---|
| 78 | $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::BaseUserMapping'; |
|---|
| 79 | $this->set_up_for_verify(); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | sub TopicUserMapping { |
|---|
| 83 | my $this = shift; |
|---|
| 84 | $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping'; |
|---|
| 85 | $this->set_up_for_verify(); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | # See the pod doc in Unit::TestCase for details of how to use this |
|---|
| 89 | sub fixture_groups { |
|---|
| 90 | return ( |
|---|
| 91 | # [ 'TemplateLoginManager', 'ApacheLoginManager', 'NoLoginManager', ], |
|---|
| 92 | [ 'AllowLoginName', 'DontAllowLoginName', ], |
|---|
| 93 | [ |
|---|
| 94 | 'HtPasswdManager', |
|---|
| 95 | |
|---|
| 96 | #'NonePasswdManager', |
|---|
| 97 | ], |
|---|
| 98 | [ |
|---|
| 99 | 'TopicUserMapping', |
|---|
| 100 | |
|---|
| 101 | #'BaseUserMapping', |
|---|
| 102 | ] |
|---|
| 103 | ); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | #delay the calling of set_up til after the cfg's are set by above closure |
|---|
| 107 | sub set_up_for_verify { |
|---|
| 108 | my $this = shift; |
|---|
| 109 | |
|---|
| 110 | $this->{session}->finish(); |
|---|
| 111 | $this->{session} = new Foswiki(); |
|---|
| 112 | $Foswiki::Plugins::SESSION = $this->{session}; |
|---|
| 113 | |
|---|
| 114 | @FoswikiFntestCase::mails = (); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | #to simplify registration |
|---|
| 118 | #SMELL: why are we not re-using code like this |
|---|
| 119 | #SMELL: or the verify code... this would benefit from reusing the mixing of mappers and other settings. |
|---|
| 120 | sub registerUserException { |
|---|
| 121 | my ( $this, $loginname, $forename, $surname, $email ) = @_; |
|---|
| 122 | |
|---|
| 123 | my $query = new Unit::Request( |
|---|
| 124 | { |
|---|
| 125 | 'TopicName' => ['UserRegistration'], |
|---|
| 126 | 'Twk1Email' => [$email], |
|---|
| 127 | 'Twk1WikiName' => ["$forename$surname"], |
|---|
| 128 | 'Twk1Name' => ["$forename $surname"], |
|---|
| 129 | 'Twk0Comment' => [''], |
|---|
| 130 | 'Twk1LoginName' => [$loginname], |
|---|
| 131 | 'Twk1FirstName' => [$forename], |
|---|
| 132 | 'Twk1LastName' => [$surname], |
|---|
| 133 | 'action' => ['register'] |
|---|
| 134 | } |
|---|
| 135 | ); |
|---|
| 136 | |
|---|
| 137 | $query->path_info("/$this->{users_web}/UserRegistration"); |
|---|
| 138 | my $fatwilly = new Foswiki( undef, $query ); |
|---|
| 139 | $fatwilly->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 140 | my $exception; |
|---|
| 141 | try { |
|---|
| 142 | $this->captureWithKey( register => $REG_UI_FN, $fatwilly ); |
|---|
| 143 | } |
|---|
| 144 | catch Foswiki::OopsException with { |
|---|
| 145 | $exception = shift; |
|---|
| 146 | if ( ( "attention" eq $exception->{template} ) |
|---|
| 147 | && ( "thanks" eq $exception->{def} ) ) |
|---|
| 148 | { |
|---|
| 149 | |
|---|
| 150 | print STDERR "---------".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 151 | $exception = undef; #the only correct answer |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | catch Foswiki::AccessControlException with { |
|---|
| 155 | $exception = shift; |
|---|
| 156 | } |
|---|
| 157 | catch Error::Simple with { |
|---|
| 158 | $exception = shift; |
|---|
| 159 | } |
|---|
| 160 | otherwise { |
|---|
| 161 | $exception = new Error::Simple(); |
|---|
| 162 | }; |
|---|
| 163 | $fatwilly->finish(); |
|---|
| 164 | |
|---|
| 165 | # Reload caches |
|---|
| 166 | my $q = $this->{request}; |
|---|
| 167 | $this->{session}->finish(); |
|---|
| 168 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 169 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 170 | |
|---|
| 171 | return $exception; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | sub addUserToGroup { |
|---|
| 175 | my $this = shift; |
|---|
| 176 | #my $queryHash = shift; |
|---|
| 177 | |
|---|
| 178 | my $query = new Unit::Request(@_); |
|---|
| 179 | |
|---|
| 180 | $query->path_info("/$this->{users_web}/WikiGroups"); |
|---|
| 181 | my $fatwilly = new Foswiki( undef, $query ); |
|---|
| 182 | |
|---|
| 183 | my $exception; |
|---|
| 184 | try { |
|---|
| 185 | no strict 'refs'; |
|---|
| 186 | $this->captureWithKey( manage => $this->getUIFn('manage'), $fatwilly ); |
|---|
| 187 | no strict 'refs'; |
|---|
| 188 | } |
|---|
| 189 | catch Foswiki::OopsException with { |
|---|
| 190 | $exception = shift; |
|---|
| 191 | print STDERR "---------".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 192 | if ( ( "attention" eq $exception->{template} ) |
|---|
| 193 | && ( "added_users_to_group" eq $exception->{def} ) ) |
|---|
| 194 | { |
|---|
| 195 | #TODO: confirm that that onle the expected group and user is created |
|---|
| 196 | undef $exception; #the only correct answer |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | catch Foswiki::AccessControlException with { |
|---|
| 200 | $exception = shift; |
|---|
| 201 | print STDERR "---------2 ".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 202 | } |
|---|
| 203 | catch Error::Simple with { |
|---|
| 204 | $exception = shift; |
|---|
| 205 | print STDERR "---------3 ".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 206 | } |
|---|
| 207 | otherwise { |
|---|
| 208 | print STDERR "--------- otherwise\n" if ($Error::Debug); |
|---|
| 209 | $exception = new Error::Simple(); |
|---|
| 210 | }; |
|---|
| 211 | return $exception; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | sub removeUserFromGroup { |
|---|
| 215 | my $this = shift; |
|---|
| 216 | #my $queryHash = shift; |
|---|
| 217 | |
|---|
| 218 | my $query = new Unit::Request(@_); |
|---|
| 219 | |
|---|
| 220 | $query->path_info("/$this->{users_web}/WikiGroups"); |
|---|
| 221 | my $fatwilly = new Foswiki( undef, $query ); |
|---|
| 222 | |
|---|
| 223 | my $exception; |
|---|
| 224 | try { |
|---|
| 225 | no strict 'refs'; |
|---|
| 226 | $this->captureWithKey( manage => $this->getUIFn('manage'), $fatwilly ); |
|---|
| 227 | no strict 'refs'; |
|---|
| 228 | } |
|---|
| 229 | catch Foswiki::OopsException with { |
|---|
| 230 | $exception = shift; |
|---|
| 231 | print STDERR "---------".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 232 | if ( ( "attention" eq $exception->{template} ) |
|---|
| 233 | && ( "removed_users_from_group" eq $exception->{def} ) ) |
|---|
| 234 | { |
|---|
| 235 | #TODO: confirm that that onle the expected group and user is created |
|---|
| 236 | undef $exception; #the only correct answer |
|---|
| 237 | } |
|---|
| 238 | } |
|---|
| 239 | catch Foswiki::AccessControlException with { |
|---|
| 240 | $exception = shift; |
|---|
| 241 | print STDERR "---------2 ".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 242 | } |
|---|
| 243 | catch Error::Simple with { |
|---|
| 244 | $exception = shift; |
|---|
| 245 | print STDERR "---------3 ".$exception->stringify()."\n" if ($Error::Debug); |
|---|
| 246 | } |
|---|
| 247 | otherwise { |
|---|
| 248 | print STDERR "--------- otherwise\n" if ($Error::Debug); |
|---|
| 249 | $exception = new Error::Simple(); |
|---|
| 250 | }; |
|---|
| 251 | return $exception; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | sub test_SingleAddToNewGroupCreate { |
|---|
| 255 | my $this = shift; |
|---|
| 256 | my $ret; |
|---|
| 257 | |
|---|
| 258 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 259 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 260 | |
|---|
| 261 | $ret = $this->addUserToGroup( { |
|---|
| 262 | 'username' => ['AsdfPoiu'], |
|---|
| 263 | 'groupname' => ['NewGroup'], |
|---|
| 264 | 'create' => [1], |
|---|
| 265 | 'action' => ['addUserToGroup'] |
|---|
| 266 | }); |
|---|
| 267 | $this->assert_null( $ret, "Simple add to new group" ); |
|---|
| 268 | |
|---|
| 269 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 270 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 271 | |
|---|
| 272 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 273 | my $q = $this->{request}; |
|---|
| 274 | $this->{session}->finish(); |
|---|
| 275 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 276 | |
|---|
| 277 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 278 | #SMELL: (maybe) yes, at the moment, the currently logged in user _is_ also added to the group - this ensures that they are able to complete the operation - as we're saving once per user |
|---|
| 279 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", $this->{session}->{user} )); |
|---|
| 280 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | sub test_DoubleAddToNewGroupCreate { |
|---|
| 286 | my $this = shift; |
|---|
| 287 | my $ret; |
|---|
| 288 | |
|---|
| 289 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 290 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 291 | $ret = $this->registerUserException( 'qwer', 'Qwer', 'Poiu', 'qwer@example.com' ); |
|---|
| 292 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 293 | $ret = $this->registerUserException( 'zxcv', 'Zxcv', 'Poiu', 'zxcv@example.com' ); |
|---|
| 294 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 295 | |
|---|
| 296 | $ret = $this->addUserToGroup( { |
|---|
| 297 | 'username' => ['AsdfPoiu','QwerPoiu'], |
|---|
| 298 | 'groupname' => ['NewGroup'], |
|---|
| 299 | 'create' => [1], |
|---|
| 300 | 'action' => ['addUserToGroup'] |
|---|
| 301 | }); |
|---|
| 302 | $this->assert_null( $ret, "Simple add to new group" ); |
|---|
| 303 | |
|---|
| 304 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 305 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 306 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 307 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 308 | |
|---|
| 309 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 310 | my $q = $this->{request}; |
|---|
| 311 | $this->{session}->finish(); |
|---|
| 312 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 313 | |
|---|
| 314 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 315 | #SMELL: (maybe) yes, at the moment, the currently logged in user _is_ also added to the group - this ensures that they are able to complete the operation - as we're saving once per user |
|---|
| 316 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", $this->{session}->{user} )); |
|---|
| 317 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 318 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 319 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | sub test_TwiceAddToNewGroupCreate { |
|---|
| 323 | my $this = shift; |
|---|
| 324 | my $ret; |
|---|
| 325 | |
|---|
| 326 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 327 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 328 | $ret = $this->registerUserException( 'qwer', 'Qwer', 'Poiu', 'qwer@example.com' ); |
|---|
| 329 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 330 | $ret = $this->registerUserException( 'zxcv', 'Zxcv', 'Poiu', 'zxcv@example.com' ); |
|---|
| 331 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 332 | $ret = $this->registerUserException( 'zxcv2', 'Zxcv', 'Poiu2', 'zxcv@2example.com' ); |
|---|
| 333 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 334 | $ret = $this->registerUserException( 'zxcv3', 'Zxcv', 'Poiu3', 'zxcv3@example.com' ); |
|---|
| 335 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 336 | $ret = $this->registerUserException( 'zxcv4', 'Zxcv', 'Poiu4', 'zxcv4@example.com' ); |
|---|
| 337 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 338 | |
|---|
| 339 | $ret = $this->addUserToGroup( { |
|---|
| 340 | 'username' => [$this->{session}->{user}], |
|---|
| 341 | 'groupname' => ['NewGroup'], |
|---|
| 342 | 'create' => [1], |
|---|
| 343 | 'action' => ['addUserToGroup'] |
|---|
| 344 | }); |
|---|
| 345 | $this->assert_null( $ret, "add myself" ); |
|---|
| 346 | |
|---|
| 347 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 348 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 349 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 350 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 351 | |
|---|
| 352 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 353 | my $q = $this->{request}; |
|---|
| 354 | $this->{session}->finish(); |
|---|
| 355 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 356 | |
|---|
| 357 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 358 | #SMELL: (maybe) yes, at the moment, the currently logged in user _is_ also added to the group - this ensures that they are able to complete the operation - as we're saving once per user |
|---|
| 359 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", $this->{session}->{user} )); |
|---|
| 360 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 361 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 362 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 363 | |
|---|
| 364 | $ret = $this->addUserToGroup( { |
|---|
| 365 | 'username' => ["AsdfPoiu"], |
|---|
| 366 | 'groupname' => ['NewGroup'], |
|---|
| 367 | 'create' => [], |
|---|
| 368 | 'action' => ['addUserToGroup'] |
|---|
| 369 | }); |
|---|
| 370 | $this->assert_null( $ret, "second add user" ); |
|---|
| 371 | |
|---|
| 372 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 373 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 374 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 375 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 376 | |
|---|
| 377 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 378 | $q = $this->{request}; |
|---|
| 379 | $this->{session}->finish(); |
|---|
| 380 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 381 | |
|---|
| 382 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 383 | #SMELL: (maybe) yes, at the moment, the currently logged in user _is_ also added to the group - this ensures that they are able to complete the operation - as we're saving once per user |
|---|
| 384 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", $this->{session}->{user} )); |
|---|
| 385 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 386 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 387 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 388 | |
|---|
| 389 | $ret = $this->addUserToGroup( { |
|---|
| 390 | 'username' => ["QwerPoiu", "ZxcvPoiu", "ZxcvPoiu2", "ZxcvPoiu3", "ZxcvPoiu4"], |
|---|
| 391 | 'groupname' => ['NewGroup'], |
|---|
| 392 | 'create' => [], |
|---|
| 393 | 'action' => ['addUserToGroup'] |
|---|
| 394 | }); |
|---|
| 395 | $this->assert_null( $ret, "third add user" ); |
|---|
| 396 | |
|---|
| 397 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 398 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 399 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 400 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 401 | |
|---|
| 402 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 403 | $q = $this->{request}; |
|---|
| 404 | $this->{session}->finish(); |
|---|
| 405 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 406 | |
|---|
| 407 | $this->assert(Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 408 | #SMELL: (maybe) yes, at the moment, the currently logged in user _is_ also added to the group - this ensures that they are able to complete the operation - as we're saving once per user |
|---|
| 409 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", $this->{session}->{user} )); |
|---|
| 410 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 411 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 412 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 413 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu2" )); |
|---|
| 414 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu3" )); |
|---|
| 415 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu4" )); |
|---|
| 416 | |
|---|
| 417 | $ret = $this->removeUserFromGroup( { |
|---|
| 418 | 'username' => ["ZxcvPoiu4"], |
|---|
| 419 | 'groupname' => ['NewGroup'], |
|---|
| 420 | 'action' => ['removeUserFromGroup'] |
|---|
| 421 | }); |
|---|
| 422 | $this->assert_null( $ret, "remove one user" ); |
|---|
| 423 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu4" )); |
|---|
| 424 | |
|---|
| 425 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 426 | $q = $this->{request}; |
|---|
| 427 | $this->{session}->finish(); |
|---|
| 428 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 429 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu2" )); |
|---|
| 430 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu3" )); |
|---|
| 431 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu4" )); |
|---|
| 432 | |
|---|
| 433 | $ret = $this->removeUserFromGroup( { |
|---|
| 434 | 'username' => ["ZxcvPoiu", "ZxcvPoiu2"], |
|---|
| 435 | 'groupname' => ['NewGroup'], |
|---|
| 436 | 'action' => ['removeUserFromGroup'] |
|---|
| 437 | }); |
|---|
| 438 | $this->assert_null( $ret, "remove two user" ); |
|---|
| 439 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 440 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu2" )); |
|---|
| 441 | |
|---|
| 442 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 443 | $q = $this->{request}; |
|---|
| 444 | $this->{session}->finish(); |
|---|
| 445 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 446 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 447 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu2" )); |
|---|
| 448 | $this->assert(Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu3" )); |
|---|
| 449 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu4" )); |
|---|
| 450 | |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | ########################################################################### |
|---|
| 455 | #totoal failure type tests.. |
|---|
| 456 | sub test_SingleAddToNewGroupNoCreate { |
|---|
| 457 | my $this = shift; |
|---|
| 458 | my $ret; |
|---|
| 459 | |
|---|
| 460 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 461 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 462 | |
|---|
| 463 | $ret = $this->addUserToGroup( { |
|---|
| 464 | 'username' => ['AsdfPoiu'], |
|---|
| 465 | 'groupname' => ['AnotherNewGroup'], |
|---|
| 466 | 'create' => [0], |
|---|
| 467 | 'action' => ['addUserToGroup'] |
|---|
| 468 | }); |
|---|
| 469 | $this->assert_not_null( $ret, "can't add to new group without setting create" ); |
|---|
| 470 | |
|---|
| 471 | #SMELL: TopicUserMapping specific - we don't refresh Groups cache :( |
|---|
| 472 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "AnotherNewGroup" )); |
|---|
| 473 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 474 | |
|---|
| 475 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 476 | my $q = $this->{request}; |
|---|
| 477 | $this->{session}->finish(); |
|---|
| 478 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 479 | |
|---|
| 480 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "AnotherNewGroup" )); |
|---|
| 481 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | sub test_NoUserAddToNewGroupCreate { |
|---|
| 485 | my $this = shift; |
|---|
| 486 | my $ret; |
|---|
| 487 | |
|---|
| 488 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 489 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 490 | $ret = $this->registerUserException( 'qwer', 'Qwer', 'Poiu', 'qwer@example.com' ); |
|---|
| 491 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 492 | $ret = $this->registerUserException( 'zxcv', 'Zxcv', 'Poiu', 'zxcv@example.com' ); |
|---|
| 493 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 494 | |
|---|
| 495 | $ret = $this->addUserToGroup( { |
|---|
| 496 | 'username' => [], |
|---|
| 497 | 'groupname' => ['NewGroup'], |
|---|
| 498 | 'create' => [1], |
|---|
| 499 | 'action' => ['addUserToGroup'] |
|---|
| 500 | }); |
|---|
| 501 | $this->assert_not_null( $ret, "no users in list of users to add to group" ); |
|---|
| 502 | |
|---|
| 503 | #SMELL: TopicUserMapping specific - we don't refresh Groups cache :( |
|---|
| 504 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 505 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 506 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 507 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 508 | |
|---|
| 509 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 510 | my $q = $this->{request}; |
|---|
| 511 | $this->{session}->finish(); |
|---|
| 512 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 513 | |
|---|
| 514 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "NewGroup" )); |
|---|
| 515 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", $this->{session}->{user} )); |
|---|
| 516 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 517 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "QwerPoiu" )); |
|---|
| 518 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "ZxcvPoiu" )); |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | sub test_RemoveFromNonExistantGroup { |
|---|
| 522 | my $this = shift; |
|---|
| 523 | my $ret; |
|---|
| 524 | |
|---|
| 525 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 526 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 527 | |
|---|
| 528 | $ret = $this->removeUserFromGroup( { |
|---|
| 529 | 'username' => ['AsdfPoiu'], |
|---|
| 530 | 'groupname' => ['AnotherNewGroup'], |
|---|
| 531 | 'action' => ['removeUserFromGroup'] |
|---|
| 532 | }); |
|---|
| 533 | $this->assert_not_null( $ret, "there ain't any such group" ); |
|---|
| 534 | $this->assert_equals( $ret->{template}, "attention" ); |
|---|
| 535 | $this->assert_equals( $ret->{def}, "problem_removing_from_group" ); |
|---|
| 536 | |
|---|
| 537 | #SMELL: TopicUserMapping specific - we don't refresh Groups cache :( |
|---|
| 538 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "AnotherNewGroup" )); |
|---|
| 539 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 540 | |
|---|
| 541 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 542 | my $q = $this->{request}; |
|---|
| 543 | $this->{session}->finish(); |
|---|
| 544 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 545 | |
|---|
| 546 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "AnotherNewGroup" )); |
|---|
| 547 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | sub test_RemoveNoUserFromExistantGroup { |
|---|
| 551 | my $this = shift; |
|---|
| 552 | my $ret; |
|---|
| 553 | |
|---|
| 554 | $ret = $this->registerUserException( 'asdf', 'Asdf', 'Poiu', 'asdf@example.com' ); |
|---|
| 555 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 556 | |
|---|
| 557 | $ret = $this->removeUserFromGroup( { |
|---|
| 558 | 'username' => [], |
|---|
| 559 | 'groupname' => ['AnotherNewGroup'], |
|---|
| 560 | 'action' => ['removeUserFromGroup'] |
|---|
| 561 | }); |
|---|
| 562 | $this->assert_not_null( $ret, "no user.." ); |
|---|
| 563 | $this->assert_equals( $ret->{template}, "attention" ); |
|---|
| 564 | $this->assert_equals( $ret->{def}, "no_users_to_remove_from_group" ); |
|---|
| 565 | |
|---|
| 566 | #SMELL: TopicUserMapping specific - we don't refresh Groups cache :( |
|---|
| 567 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "AnotherNewGroup" )); |
|---|
| 568 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 569 | |
|---|
| 570 | #need to reload to force Foswiki to reparse Groups :( |
|---|
| 571 | my $q = $this->{request}; |
|---|
| 572 | $this->{session}->finish(); |
|---|
| 573 | $this->{session} = new Foswiki( undef, $q ); |
|---|
| 574 | |
|---|
| 575 | $this->assert(!Foswiki::Func::topicExists( $this->{users_web}, "AnotherNewGroup" )); |
|---|
| 576 | $this->assert(!Foswiki::Func::isGroupMember( "NewGroup", "AsdfPoiu" )); |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | sub verify_resetEmailOkay { |
|---|
| 580 | my $this = shift; |
|---|
| 581 | |
|---|
| 582 | ## Need to create an account (else oopsnotwikiuser) |
|---|
| 583 | ### with a known email address (else oopsregemail) |
|---|
| 584 | ### need to know the password too |
|---|
| 585 | my $ret = $this->registerUserException( |
|---|
| 586 | 'brian', 'Brian', 'Griffin', 'brian@example.com' ); |
|---|
| 587 | $this->assert_null( $ret, "Simple rego should work" ); |
|---|
| 588 | |
|---|
| 589 | my $cUID = |
|---|
| 590 | $this->{session}->{users}->getCanonicalUserID( 'brian' ); |
|---|
| 591 | $this->assert( $this->{session}->{users}->userExists($cUID), |
|---|
| 592 | "new user created" ); |
|---|
| 593 | my $newPassU = '12345'; |
|---|
| 594 | my $oldPassU = 1; #force set |
|---|
| 595 | $this->assert( |
|---|
| 596 | $this->{session}->{users}->setPassword( $cUID, $newPassU, $oldPassU ) ); |
|---|
| 597 | my $newEmail = 'brian@family.guy'; |
|---|
| 598 | |
|---|
| 599 | my $query = new Unit::Request( |
|---|
| 600 | { |
|---|
| 601 | 'LoginName' => [ 'brian' ], |
|---|
| 602 | 'TopicName' => ['ChangeEmailAddress'], |
|---|
| 603 | 'username' => [ 'brian' ], |
|---|
| 604 | 'oldpassword' => ['12345'], |
|---|
| 605 | 'email' => [$newEmail], |
|---|
| 606 | 'action' => ['changePassword'] |
|---|
| 607 | } |
|---|
| 608 | ); |
|---|
| 609 | |
|---|
| 610 | $query->path_info( '/' . $this->{users_web} . '/WebHome' ); |
|---|
| 611 | $this->{session}->finish(); |
|---|
| 612 | $this->{session} = new Foswiki( 'brian', $query ); |
|---|
| 613 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 614 | try { |
|---|
| 615 | $this->captureWithKey( manage => $MAN_UI_FN, $this->{session} ); |
|---|
| 616 | } |
|---|
| 617 | catch Foswiki::AccessControlException with { |
|---|
| 618 | my $e = shift; |
|---|
| 619 | $this->assert( 0, $e->stringify ); |
|---|
| 620 | } |
|---|
| 621 | catch Foswiki::OopsException with { |
|---|
| 622 | my $e = shift; |
|---|
| 623 | $this->assert_str_equals( "attention", $e->{template}, |
|---|
| 624 | $e->stringify() ); |
|---|
| 625 | $this->assert_str_equals( "email_changed", $e->{def}, $e->stringify() ); |
|---|
| 626 | $this->assert_str_equals( |
|---|
| 627 | $newEmail, |
|---|
| 628 | ${ $e->{params} }[0], |
|---|
| 629 | ${ $e->{params} }[0] |
|---|
| 630 | ); |
|---|
| 631 | } |
|---|
| 632 | catch Error::Simple with { |
|---|
| 633 | $this->assert( 0, shift->stringify() ); |
|---|
| 634 | } |
|---|
| 635 | otherwise { |
|---|
| 636 | $this->assert( 0, "expected an oops redirect" ); |
|---|
| 637 | }; |
|---|
| 638 | |
|---|
| 639 | my @emails = $this->{session}->{users}->getEmails($cUID); |
|---|
| 640 | $this->assert_str_equals( $newEmail, $emails[0] ); |
|---|
| 641 | } |
|---|
| 642 | |
|---|
| 643 | sub verify_bulkRegister { |
|---|
| 644 | my $this = shift; |
|---|
| 645 | |
|---|
| 646 | my $testReg = <<'EOM'; |
|---|
| 647 | | FirstName | LastName | Email | WikiName | LoginName | CustomFieldThis | SomeOtherRandomField | WhateverYouLike | |
|---|
| 648 | | Test | User | Martin.Cleaver@BCS.org.uk | TestBulkUser1 | a | A | B | C | |
|---|
| 649 | | Test | User2 | Martin.Cleaver@BCS.org.uk | TestBulkUser2 | b | A | B | C | |
|---|
| 650 | | Test | User3 | Martin.Cleaver@BCS.org.uk | TestBulkUser3 | c | A | B | C | |
|---|
| 651 | EOM |
|---|
| 652 | |
|---|
| 653 | my $regTopic = 'UnprocessedRegistrations2'; |
|---|
| 654 | |
|---|
| 655 | my $logTopic = 'UnprocessedRegistrations2Log'; |
|---|
| 656 | my $file = |
|---|
| 657 | $Foswiki::cfg{DataDir} . '/' |
|---|
| 658 | . $this->{test_web} . '/' |
|---|
| 659 | . $regTopic . '.txt'; |
|---|
| 660 | my $fh = new FileHandle; |
|---|
| 661 | |
|---|
| 662 | die "Can't write $file" unless ( $fh->open(">$file") ); |
|---|
| 663 | print $fh $testReg; |
|---|
| 664 | $fh->close; |
|---|
| 665 | |
|---|
| 666 | my $query = new Unit::Request( |
|---|
| 667 | { |
|---|
| 668 | 'LogTopic' => [$logTopic], |
|---|
| 669 | 'EmailUsersWithDetails' => ['0'], |
|---|
| 670 | 'OverwriteHomeTopics' => ['1'], |
|---|
| 671 | 'action' => ['bulkRegister'], |
|---|
| 672 | } |
|---|
| 673 | ); |
|---|
| 674 | |
|---|
| 675 | $query->path_info("/$this->{test_web}/$regTopic"); |
|---|
| 676 | $this->{session}->finish(); |
|---|
| 677 | $this->{session} = new Foswiki( $Foswiki::cfg{SuperAdminGroup}, $query ); |
|---|
| 678 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 679 | $this->{session}->{topicName} = $regTopic; |
|---|
| 680 | $this->{session}->{webName} = $this->{test_web}; |
|---|
| 681 | try { |
|---|
| 682 | $this->captureWithKey( manage => $MAN_UI_FN, $this->{session} ); |
|---|
| 683 | } |
|---|
| 684 | catch Foswiki::OopsException with { |
|---|
| 685 | my $e = shift; |
|---|
| 686 | $this->assert( 0, $e->stringify() . " UNEXPECTED" ); |
|---|
| 687 | |
|---|
| 688 | } |
|---|
| 689 | catch Error::Simple with { |
|---|
| 690 | my $e = shift; |
|---|
| 691 | $this->assert( 0, $e->stringify ); |
|---|
| 692 | |
|---|
| 693 | } |
|---|
| 694 | catch Foswiki::AccessControlException with { |
|---|
| 695 | my $e = shift; |
|---|
| 696 | $this->assert( 0, $e->stringify ); |
|---|
| 697 | |
|---|
| 698 | } |
|---|
| 699 | otherwise { |
|---|
| 700 | $this->assert( 0, "expected an oops redirect" ); |
|---|
| 701 | }; |
|---|
| 702 | $this->assert_equals( 0, scalar(@FoswikiFnTestCase::mails) ); |
|---|
| 703 | } |
|---|
| 704 | |
|---|
| 705 | #in which a user correctly points out that the error checking is a bit minimal |
|---|
| 706 | sub verify_bulkRegister_Item2191 { |
|---|
| 707 | my $this = shift; |
|---|
| 708 | |
|---|
| 709 | my $testReg = <<'EOM'; |
|---|
| 710 | | Vorname | Nachname | Mailadresse | WikiName | LoginName | CustomFieldThis | SomeOtherRandomField | WhateverYouLike | |
|---|
| 711 | | Test | User | Martin.Cleaver@BCS.org.uk | TestBulkUser1 | a | A | B | C | |
|---|
| 712 | | Test | User2 | Martin.Cleaver@BCS.org.uk | TestBulkUser2 | b | A | B | C | |
|---|
| 713 | | Test | User3 | Martin.Cleaver@BCS.org.uk | TestBulkUser3 | c | A | B | C | |
|---|
| 714 | EOM |
|---|
| 715 | |
|---|
| 716 | my $regTopic = 'UnprocessedRegistrations2'; |
|---|
| 717 | |
|---|
| 718 | my $logTopic = 'UnprocessedRegistrations2Log'; |
|---|
| 719 | my $file = |
|---|
| 720 | $Foswiki::cfg{DataDir} . '/' |
|---|
| 721 | . $this->{test_web} . '/' |
|---|
| 722 | . $regTopic . '.txt'; |
|---|
| 723 | my $fh = new FileHandle; |
|---|
| 724 | |
|---|
| 725 | die "Can't write $file" unless ( $fh->open(">$file") ); |
|---|
| 726 | print $fh $testReg; |
|---|
| 727 | $fh->close; |
|---|
| 728 | |
|---|
| 729 | my $query = new Unit::Request( |
|---|
| 730 | { |
|---|
| 731 | 'LogTopic' => [$logTopic], |
|---|
| 732 | 'EmailUsersWithDetails' => ['0'], |
|---|
| 733 | 'OverwriteHomeTopics' => ['1'], |
|---|
| 734 | 'action' => ['bulkRegister'], |
|---|
| 735 | } |
|---|
| 736 | ); |
|---|
| 737 | |
|---|
| 738 | $query->path_info("/$this->{test_web}/$regTopic"); |
|---|
| 739 | $this->{session}->finish(); |
|---|
| 740 | $this->{session} = new Foswiki( $Foswiki::cfg{SuperAdminGroup}, $query ); |
|---|
| 741 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 742 | $this->{session}->{topicName} = $regTopic; |
|---|
| 743 | $this->{session}->{webName} = $this->{test_web}; |
|---|
| 744 | try { |
|---|
| 745 | my ($text) = $this->captureWithKey( manage => $MAN_UI_FN, |
|---|
| 746 | $this->{session} ); |
|---|
| 747 | |
|---|
| 748 | #TODO: um, really need to test what the output was, and |
|---|
| 749 | #TODO: test if a user was registered.. |
|---|
| 750 | #$this->assert( '', $text); |
|---|
| 751 | #my $readMeta = Foswiki::Meta->load( $this->{session}, $this->{test_web}, 'TemporaryRegistrationTestWebRegistration/UnprocessedRegistrations2Log' ); |
|---|
| 752 | #$this->assert( '', $readMeta->text()); |
|---|
| 753 | } |
|---|
| 754 | catch Foswiki::OopsException with { |
|---|
| 755 | my $e = shift; |
|---|
| 756 | $this->assert( 0, $e->stringify() . " UNEXPECTED" ); |
|---|
| 757 | |
|---|
| 758 | } |
|---|
| 759 | catch Error::Simple with { |
|---|
| 760 | my $e = shift; |
|---|
| 761 | $this->assert( 0, $e->stringify ); |
|---|
| 762 | |
|---|
| 763 | } |
|---|
| 764 | catch Foswiki::AccessControlException with { |
|---|
| 765 | my $e = shift; |
|---|
| 766 | $this->assert( 0, $e->stringify ); |
|---|
| 767 | |
|---|
| 768 | } |
|---|
| 769 | otherwise { |
|---|
| 770 | $this->assert( 0, "expected an oops redirect" ); |
|---|
| 771 | }; |
|---|
| 772 | $this->assert_equals( 0, scalar(@FoswikiFnTestCase::mails) ); |
|---|
| 773 | } |
|---|
| 774 | |
|---|
| 775 | sub verify_deleteUser { |
|---|
| 776 | my $this = shift; |
|---|
| 777 | my $ret = $this->registerUserException( |
|---|
| 778 | 'eric', 'Eric', 'Cartman', 'eric@example.com' ); |
|---|
| 779 | $this->assert_null( $ret, "Respect mah authoritah" ); |
|---|
| 780 | |
|---|
| 781 | my $cUID = |
|---|
| 782 | $this->{session}->{users}->getCanonicalUserID( 'eric' ); |
|---|
| 783 | my $newPassU = '12345'; |
|---|
| 784 | my $oldPassU = 1; #force set |
|---|
| 785 | $this->assert( |
|---|
| 786 | $this->{session}->{users}->setPassword( |
|---|
| 787 | $cUID, $newPassU, $oldPassU ) ); |
|---|
| 788 | |
|---|
| 789 | my $query = new Unit::Request( |
|---|
| 790 | { |
|---|
| 791 | 'password' => ['12345'], |
|---|
| 792 | 'action' => ['deleteUserAccount'], |
|---|
| 793 | } |
|---|
| 794 | ); |
|---|
| 795 | $query->path_info("/$this->{test_web}/Arbitrary"); |
|---|
| 796 | $this->{session}->finish(); |
|---|
| 797 | $this->{session} = new Foswiki( 'eric', $query ); |
|---|
| 798 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 799 | $this->{session}->{topicName} = 'Arbitrary'; |
|---|
| 800 | $this->{session}->{webName} = $this->{test_web}; |
|---|
| 801 | |
|---|
| 802 | try { |
|---|
| 803 | $this->captureWithKey( manage => $MAN_UI_FN, $this->{session} ); |
|---|
| 804 | } |
|---|
| 805 | catch Foswiki::OopsException with { |
|---|
| 806 | my $e = shift; |
|---|
| 807 | $this->assert_str_equals( "attention", $e->{template}, |
|---|
| 808 | $e->stringify() ); |
|---|
| 809 | $this->assert_str_equals( "remove_user_done", $e->{def}, $e->stringify() ); |
|---|
| 810 | my $johndoe = 'eric'; |
|---|
| 811 | if ($Foswiki::cfg{Register}{AllowLoginName}) { |
|---|
| 812 | $johndoe = 'EricCartman'; |
|---|
| 813 | } |
|---|
| 814 | $this->assert_str_equals( |
|---|
| 815 | $johndoe, |
|---|
| 816 | ${ $e->{params} }[0], |
|---|
| 817 | ${ $e->{params} }[0] |
|---|
| 818 | ); |
|---|
| 819 | } |
|---|
| 820 | catch Error::Simple with { |
|---|
| 821 | my $e = shift; |
|---|
| 822 | $this->assert( 0, $e->stringify ); |
|---|
| 823 | |
|---|
| 824 | } |
|---|
| 825 | catch Foswiki::AccessControlException with { |
|---|
| 826 | my $e = shift; |
|---|
| 827 | $this->assert( 0, $e->stringify ); |
|---|
| 828 | |
|---|
| 829 | } |
|---|
| 830 | otherwise { |
|---|
| 831 | $this->assert( 0, "expected an oops redirect" ); |
|---|
| 832 | }; |
|---|
| 833 | } |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | sub test_createDefaultWeb { |
|---|
| 837 | my $this = shift; |
|---|
| 838 | my $newWeb = $this->{test_web}.'NewExtra'; #no, this is not nested |
|---|
| 839 | my $query = new Unit::Request( |
|---|
| 840 | { |
|---|
| 841 | 'action' => ['createweb'], |
|---|
| 842 | 'baseweb' => ['_default'], |
|---|
| 843 | # 'newtopic' => ['qwer'], #TODO: er, what the? |
|---|
| 844 | 'newweb' => [$newWeb], |
|---|
| 845 | 'nosearchall' => ['on'], |
|---|
| 846 | 'webbgcolor' => ['fuchsia'], |
|---|
| 847 | 'websummary' => ['twinkle twinkle little star'], |
|---|
| 848 | } |
|---|
| 849 | ); |
|---|
| 850 | $query->path_info("/$this->{test_web}/Arbitrary"); |
|---|
| 851 | $this->{session}->finish(); |
|---|
| 852 | $this->{session} = new Foswiki( $Foswiki::cfg{SuperAdminGroup}, $query ); |
|---|
| 853 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 854 | $this->{session}->{topicName} = 'Arbitrary'; |
|---|
| 855 | $this->{session}->{webName} = $this->{test_web}; |
|---|
| 856 | |
|---|
| 857 | try { |
|---|
| 858 | my ($stdout, $stderr, $result) = $this->captureWithKey( manage => $MAN_UI_FN, $this->{session} ); |
|---|
| 859 | } |
|---|
| 860 | catch Foswiki::OopsException with { |
|---|
| 861 | my $e = shift; |
|---|
| 862 | $this->assert_str_equals( "attention", $e->{template}, |
|---|
| 863 | $e->stringify() ); |
|---|
| 864 | $this->assert_str_equals( "created_web", $e->{def}, $e->stringify() ); |
|---|
| 865 | print STDERR "captured STDERR: ".$this->{stderr}."\n" if (defined($this->{stderr})); |
|---|
| 866 | } |
|---|
| 867 | catch Error::Simple with { |
|---|
| 868 | my $e = shift; |
|---|
| 869 | $this->assert( 0, $e->stringify ); |
|---|
| 870 | |
|---|
| 871 | } |
|---|
| 872 | catch Foswiki::AccessControlException with { |
|---|
| 873 | my $e = shift; |
|---|
| 874 | $this->assert( 0, $e->stringify ); |
|---|
| 875 | |
|---|
| 876 | } |
|---|
| 877 | otherwise { |
|---|
| 878 | $this->assert( 0, "expected an oops redirect" ); |
|---|
| 879 | }; |
|---|
| 880 | |
|---|
| 881 | #check that the settings we created with happened. |
|---|
| 882 | $this->assert( $this->{session}->webExists($newWeb) ); |
|---|
| 883 | my $webObject = Foswiki::Meta->new( $this->{session}, $newWeb ); |
|---|
| 884 | $this->assert_equals('fuchsia', |
|---|
| 885 | $webObject->getPreference('WEBBGCOLOR')); |
|---|
| 886 | $this->assert_equals('on', $webObject->getPreference('SITEMAPLIST')); |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | #check that the topics from _default web are actually in the new web, and make sure they are expectently similar |
|---|
| 890 | my @expectedTopicsItr = Foswiki::Func::getTopicList('_default'); |
|---|
| 891 | foreach my $expectedTopic (@expectedTopicsItr) { |
|---|
| 892 | $this->assert(Foswiki::Func::topicExists($newWeb, $expectedTopic)); |
|---|
| 893 | my ($eMeta, $eText) = Foswiki::Func::readTopic('_default', $expectedTopic); |
|---|
| 894 | my ($nMeta, $nText) = Foswiki::Func::readTopic($newWeb, $expectedTopic); |
|---|
| 895 | |
|---|
| 896 | #change the params set above to what they were in the template WebPreferences |
|---|
| 897 | $nText =~ s/($Foswiki::regex{setRegex}WEBBGCOLOR\s*=).fuchsia$/$1 #DDDDDD/m; |
|---|
| 898 | $this->assert(defined($1)); |
|---|
| 899 | $nText =~ s/($Foswiki::regex{setRegex}WEBSUMMARY\s*=).twinkle twinkle little star$/$1 /m; |
|---|
| 900 | $this->assert(defined($1)); |
|---|
| 901 | $nText =~ s/($Foswiki::regex{setRegex}NOSEARCHALL\s*=).on$/$1 /m; |
|---|
| 902 | $this->assert(defined($1)); |
|---|
| 903 | |
|---|
| 904 | $this->assert_html_equals($eText, $nText); #.($Foswiki::RELEASE =~ /1\.1\.0/?"\n":'')); |
|---|
| 905 | } |
|---|
| 906 | |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | sub test_createEmptyWeb { |
|---|
| 911 | my $this = shift; |
|---|
| 912 | my $newWeb = $this->{test_web}.'EmptyNewExtra'; #no, this is not nested |
|---|
| 913 | my $query = new Unit::Request( |
|---|
| 914 | { |
|---|
| 915 | 'action' => ['createweb'], |
|---|
| 916 | 'baseweb' => ['_empty'], |
|---|
| 917 | # 'newtopic' => ['qwer'], #TODO: er, what the? |
|---|
| 918 | 'newweb' => [$newWeb], |
|---|
| 919 | 'nosearchall' => ['on'], |
|---|
| 920 | 'webbgcolor' => ['fuchsia'], |
|---|
| 921 | 'websummary' => ['somthing there.'], |
|---|
| 922 | #TODO: I don't think this is what will get passed through - it should probably deal correctly with ['somenewskin','another'] |
|---|
| 923 | 'SKIN' => ['somenewskin,another'], |
|---|
| 924 | } |
|---|
| 925 | ); |
|---|
| 926 | $query->path_info("/$this->{test_web}/Arbitrary"); |
|---|
| 927 | $this->{session}->finish(); |
|---|
| 928 | $this->{session} = new Foswiki( $Foswiki::cfg{SuperAdminGroup}, $query ); |
|---|
| 929 | $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); |
|---|
| 930 | $this->{session}->{topicName} = 'Arbitrary'; |
|---|
| 931 | $this->{session}->{webName} = $this->{test_web}; |
|---|
| 932 | |
|---|
| 933 | try { |
|---|
| 934 | my ($stdout, $stderr, $result) = $this->captureWithKey( manage => $MAN_UI_FN, $this->{session} ); |
|---|
| 935 | } |
|---|
| 936 | catch Foswiki::OopsException with { |
|---|
| 937 | my $e = shift; |
|---|
| 938 | $this->assert_str_equals( "attention", $e->{template}, |
|---|
| 939 | $e->stringify() ); |
|---|
| 940 | $this->assert_str_equals( "created_web", $e->{def}, $e->stringify() ); |
|---|
| 941 | print STDERR "captured STDERR: ".$this->{stderr}."\n" if (defined($this->{stderr})); |
|---|
| 942 | } |
|---|
| 943 | catch Error::Simple with { |
|---|
| 944 | my $e = shift; |
|---|
| 945 | $this->assert( 0, $e->stringify ); |
|---|
| 946 | |
|---|
| 947 | } |
|---|
| 948 | catch Foswiki::AccessControlException with { |
|---|
| 949 | my $e = shift; |
|---|
| 950 | $this->assert( 0, $e->stringify ); |
|---|
| 951 | |
|---|
| 952 | } |
|---|
| 953 | otherwise { |
|---|
| 954 | $this->assert( 0, "expected an oops redirect" ); |
|---|
| 955 | }; |
|---|
| 956 | |
|---|
| 957 | #check that the settings we created with happened. |
|---|
| 958 | $this->assert( $this->{session}->webExists($newWeb) ); |
|---|
| 959 | my $webObject = Foswiki::Meta->new( $this->{session}, $newWeb ); |
|---|
| 960 | $this->assert_equals('fuchsia', |
|---|
| 961 | $webObject->getPreference('WEBBGCOLOR')); |
|---|
| 962 | $this->assert_equals('somenewskin,another', |
|---|
| 963 | $webObject->getPreference('SKIN')); |
|---|
| 964 | #nope, SITEMAPLIST isn't required |
|---|
| 965 | #$this->assert_equals('on', $webObject->getPreference('SITEMAPLIST')); |
|---|
| 966 | |
|---|
| 967 | |
|---|
| 968 | #check that the topics from _default web are actually in the new web, and make sure they are expectently similar |
|---|
| 969 | my @expectedTopicsItr = Foswiki::Func::getTopicList('_empty'); |
|---|
| 970 | foreach my $expectedTopic (@expectedTopicsItr) { |
|---|
| 971 | $this->assert(Foswiki::Func::topicExists($newWeb, $expectedTopic)); |
|---|
| 972 | |
|---|
| 973 | next if ($expectedTopic eq 'WebPreferences'); # we've modified the topic alot |
|---|
| 974 | |
|---|
| 975 | my ($eMeta, $eText) = Foswiki::Func::readTopic('_empty', $expectedTopic); |
|---|
| 976 | my ($nMeta, $nText) = Foswiki::Func::readTopic($newWeb, $expectedTopic); |
|---|
| 977 | |
|---|
| 978 | #change the params set above to what they were in the template WebPreferences |
|---|
| 979 | $nText =~ s/($Foswiki::regex{setRegex}WEBBGCOLOR\s*=).fuchsia$/$1 #DDDDDD/m; |
|---|
| 980 | $this->assert(defined($1)); |
|---|
| 981 | $nText =~ s/($Foswiki::regex{setRegex}WEBSUMMARY\s*=).something here$/$1 /m; |
|---|
| 982 | $this->assert(defined($1)); |
|---|
| 983 | $nText =~ s/($Foswiki::regex{setRegex}NOSEARCHALL\s*=).on$/$1 /m; |
|---|
| 984 | $this->assert(defined($1)); |
|---|
| 985 | |
|---|
| 986 | $this->assert_html_equals($eText, $nText); #.($Foswiki::RELEASE =~ /1\.1\.0/?"\n":'')); |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | } |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | #TODO: add tests for all the failure conditions - ie, creating a web that exists. |
|---|
| 993 | |
|---|
| 994 | 1; |
|---|