2010-04-12 23:16:26 +02:00
|
|
|
<?php
|
|
|
|
class SecurityDefaultAdminTest extends SapphireTest {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
2010-04-13 01:08:35 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2014-08-15 08:53:05 +02:00
|
|
|
// TODO Workaround to force database clearing with no fixture present,
|
2010-04-12 23:16:26 +02:00
|
|
|
// and avoid sideeffects from other tests
|
2010-04-13 01:08:35 +02:00
|
|
|
if(!self::using_temp_db()) self::create_temp_db();
|
2010-04-12 23:16:26 +02:00
|
|
|
self::empty_temp_db();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCheckDefaultAdmin() {
|
2012-11-23 14:55:19 +01:00
|
|
|
if(Security::has_default_admin()) {
|
|
|
|
$this->markTestSkipped(
|
|
|
|
'Default admin present. There\'s no way to inspect default admin state, ' .
|
|
|
|
'so we don\'t override existing settings'
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-04-12 23:16:26 +02:00
|
|
|
Security::setDefaultAdmin('admin', 'password');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-04-12 23:16:26 +02:00
|
|
|
$this->assertTrue(Security::has_default_admin());
|
|
|
|
$this->assertTrue(
|
|
|
|
Security::check_default_admin('admin', 'password'),
|
|
|
|
'Succeeds with correct username and password'
|
|
|
|
);
|
|
|
|
$this->assertFalse(
|
|
|
|
Security::check_default_admin('wronguser', 'password'),
|
|
|
|
'Fails with incorrect username'
|
|
|
|
);
|
|
|
|
$this->assertFalse(
|
|
|
|
Security::check_default_admin('admin', 'wrongpassword'),
|
|
|
|
'Fails with incorrect password'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-04-12 23:16:26 +02:00
|
|
|
Security::setDefaultAdmin(null, null);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testFindAnAdministratorCreatesNewUser() {
|
2010-04-12 23:16:26 +02:00
|
|
|
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
2009-11-22 06:16:38 +01:00
|
|
|
$this->assertEquals(0, $adminMembers->count());
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-04-12 23:16:26 +02:00
|
|
|
$admin = Security::findAnAdministrator();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-05-09 12:43:22 +02:00
|
|
|
$this->assertInstanceOf('Member', $admin);
|
2010-04-12 23:16:26 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
|
|
|
|
$this->assertNull($admin->Email);
|
|
|
|
$this->assertNull($admin->Password);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|