2010-04-12 23:16:26 +02:00
|
|
|
<?php
|
|
|
|
class SecurityDefaultAdminTest extends SapphireTest {
|
|
|
|
|
|
|
|
function setUp() {
|
2010-04-13 01:08:35 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2010-04-12 23:16:26 +02:00
|
|
|
// TODO Workaround to force database clearing with no fixture present,
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCheckDefaultAdmin() {
|
|
|
|
// TODO There's currently no way to inspect default admin state,
|
|
|
|
// hence we don't override existing settings
|
|
|
|
if(Security::has_default_admin()) return;
|
|
|
|
|
|
|
|
Security::setDefaultAdmin('admin', 'password');
|
|
|
|
|
|
|
|
$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'
|
|
|
|
);
|
|
|
|
|
|
|
|
Security::setDefaultAdmin(null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFindAnAdministratorCreatesNewUser() {
|
|
|
|
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
2009-11-22 06:16:38 +01:00
|
|
|
$this->assertEquals(0, $adminMembers->count());
|
2010-04-12 23:16:26 +02:00
|
|
|
|
|
|
|
$admin = Security::findAnAdministrator();
|
|
|
|
|
2011-03-11 03:06:09 +01:00
|
|
|
$this->assertType('Member', $admin);
|
2010-04-12 23:16:26 +02:00
|
|
|
$this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
|
|
|
|
$this->assertNull($admin->Email);
|
|
|
|
$this->assertNull($admin->Password);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|