@@ -143,8 +143,17 @@ public function testSettingsAction()
143
143
144
144
$ usersFile = $ this ->loadData ('User ' , 'default ' );
145
145
$ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
146
- $ this ->dispatchUrI ("/user/settings " , $ userDao );
146
+ $ user2Dao = $ this ->User ->load ($ usersFile [1 ]->getKey ());
147
+ $ adminDao = $ this ->User ->load ($ usersFile [2 ]->getKey ());
147
148
149
+ // Non admin user should not be able to edit other user's profiles
150
+ $ this ->resetAll ();
151
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ adminDao ->getKey (), $ userDao , true );
152
+ $ this ->resetAll ();
153
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ user2Dao ->getKey (), $ userDao , true );
154
+
155
+ $ this ->resetAll ();
156
+ $ this ->dispatchUrI ("/user/settings " , $ userDao );
148
157
$ this ->assertQuery ("div#tabsSettings " );
149
158
$ this ->assertQuery ("li.settingsCommunityList " );
150
159
@@ -393,4 +402,92 @@ public function testDeleteSelfAction()
393
402
}
394
403
$ this ->assertTrue ($ revisionNotDeleted , 'At least one revision should not have been deleted ' );
395
404
}
405
+
406
+ /** Test setting the admin status of users */
407
+ public function testSetAdminStatus ()
408
+ {
409
+ $ usersFile = $ this ->loadData ('User ' , 'default ' );
410
+ $ user1 = $ this ->User ->load ($ usersFile [0 ]->getKey ());
411
+ $ adminUser = $ this ->User ->load ($ usersFile [2 ]->getKey ());
412
+
413
+ $ this ->assertFalse ($ user1 ->isAdmin ());
414
+ $ this ->assertTrue ($ adminUser ->isAdmin ());
415
+
416
+ // Admin checkbox should be visible for an admin on his own view, it should be checked and disabled
417
+ $ this ->resetAll ();
418
+ $ this ->dispatchUrI ('/user/settings ' , $ adminUser );
419
+ $ this ->assertQuery ('input[type="checkbox"][name="adminStatus"][checked="checked"][disabled="disabled"] ' );
420
+
421
+ // Admin checkbox should be visible for an admin on user 1's view, it should be unchecked and enabled
422
+ $ this ->resetAll ();
423
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ user1 ->getKey (), $ adminUser );
424
+ $ this ->assertQuery ('input[type="checkbox"][name="adminStatus"] ' );
425
+ $ this ->assertNotQuery ('input[type="checkbox"][name="adminStatus"][checked="checked"] ' );
426
+ $ this ->assertNotQuery ('input[type="checkbox"][name="adminStatus"][disabled="disabled"] ' );
427
+
428
+ // Admin checkbox should not be visible on user 1's setting page at all
429
+ $ this ->resetAll ();
430
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ user1 ->getKey (), $ user1 );
431
+ $ this ->assertNotQuery ('input[type="checkbox"][name="adminStatus"] ' );
432
+
433
+ // If non admin user attempts to maliciously become admin, make sure we ignore it.
434
+ $ this ->resetAll ();
435
+ $ this ->params = array ();
436
+ $ this ->params ['firstname ' ] = 'First Name ' ;
437
+ $ this ->params ['lastname ' ] = 'Last Name ' ;
438
+ $ this ->params ['company ' ] = 'Company ' ;
439
+ $ this ->params ['privacy ' ] = MIDAS_USER_PRIVATE ;
440
+ $ this ->params ['adminStatus ' ] = 'on ' ;
441
+ $ this ->params ['modifyAccount ' ] = 'true ' ;
442
+ $ this ->request ->setMethod ('POST ' );
443
+ $ this ->dispatchUrI ('/user/settings ' , $ user1 );
444
+
445
+ $ user1 = $ this ->User ->load ($ user1 ->getKey ());
446
+ $ this ->assertFalse ($ user1 ->isAdmin ());
447
+
448
+ // Admin user should be allowed to set user 1 as admin
449
+ $ this ->resetAll ();
450
+ $ this ->params = array ();
451
+ $ this ->params ['firstname ' ] = 'First Name ' ;
452
+ $ this ->params ['lastname ' ] = 'Last Name ' ;
453
+ $ this ->params ['company ' ] = 'Company ' ;
454
+ $ this ->params ['privacy ' ] = MIDAS_USER_PRIVATE ;
455
+ $ this ->params ['adminStatus ' ] = 'on ' ;
456
+ $ this ->params ['modifyAccount ' ] = 'true ' ;
457
+ $ this ->request ->setMethod ('POST ' );
458
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ user1 ->getKey (), $ adminUser );
459
+
460
+ $ user1 = $ this ->User ->load ($ user1 ->getKey ());
461
+ $ this ->assertTrue ($ user1 ->isAdmin ());
462
+
463
+ // Admin user should be able to unset another admin user's status
464
+ $ this ->resetAll ();
465
+ $ this ->params = array ();
466
+ $ this ->params ['firstname ' ] = 'First Name ' ;
467
+ $ this ->params ['lastname ' ] = 'Last Name ' ;
468
+ $ this ->params ['company ' ] = 'Company ' ;
469
+ $ this ->params ['privacy ' ] = MIDAS_USER_PRIVATE ;
470
+ $ this ->params ['adminStatus ' ] = '' ;
471
+ $ this ->params ['modifyAccount ' ] = 'true ' ;
472
+ $ this ->request ->setMethod ('POST ' );
473
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ user1 ->getKey (), $ adminUser );
474
+
475
+ $ user1 = $ this ->User ->load ($ user1 ->getKey ());
476
+ $ this ->assertFalse ($ user1 ->isAdmin ());
477
+
478
+ // But an admin should not be able to remove their own admin status
479
+ $ this ->resetAll ();
480
+ $ this ->params = array ();
481
+ $ this ->params ['firstname ' ] = 'First Name ' ;
482
+ $ this ->params ['lastname ' ] = 'Last Name ' ;
483
+ $ this ->params ['company ' ] = 'Company ' ;
484
+ $ this ->params ['privacy ' ] = MIDAS_USER_PRIVATE ;
485
+ $ this ->params ['adminStatus ' ] = '' ;
486
+ $ this ->params ['modifyAccount ' ] = 'true ' ;
487
+ $ this ->request ->setMethod ('POST ' );
488
+ $ this ->dispatchUrI ('/user/settings?userId= ' .$ adminUser ->getKey (), $ adminUser );
489
+
490
+ $ adminUser = $ this ->User ->load ($ adminUser ->getKey ());
491
+ $ this ->assertTrue ($ adminUser ->isAdmin ());
492
+ }
396
493
}
0 commit comments