2010-04-12 23:16:26 +02:00
|
|
|
<?php
|
|
|
|
class SecurityDefaultAdminTest extends SapphireTest {
|
2014-10-06 05:01:33 +02:00
|
|
|
|
|
|
|
protected $defaultUsername = null;
|
|
|
|
protected $defaultPassword = null;
|
2010-04-12 23:16:26 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public 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();
|
2014-10-06 05:01:33 +02:00
|
|
|
|
|
|
|
$this->defaultUsername = Security::default_admin_username();
|
|
|
|
$this->defaultPassword = Security::default_admin_password();
|
|
|
|
Security::clear_default_admin();
|
|
|
|
Security::setDefaultAdmin('admin', 'password');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
Security::setDefaultAdmin($this->defaultUsername, $this->defaultPassword);
|
|
|
|
parent::tearDown();
|
2010-04-12 23:16:26 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCheckDefaultAdmin() {
|
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'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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());
|
2010-04-12 23:16:26 +02:00
|
|
|
|
|
|
|
$admin = Security::findAnAdministrator();
|
|
|
|
|
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'));
|
2014-10-06 05:01:33 +02:00
|
|
|
$this->assertEquals($admin->Email, Security::default_admin_username());
|
2010-04-12 23:16:26 +02:00
|
|
|
$this->assertNull($admin->Password);
|
|
|
|
}
|
2014-10-06 05:01:33 +02:00
|
|
|
|
|
|
|
public function testDefaultAdmin() {
|
|
|
|
$adminMembers = Permission::get_members_by_permission('ADMIN');
|
|
|
|
$this->assertEquals(0, $adminMembers->count());
|
|
|
|
|
|
|
|
$admin = Member::default_admin();
|
|
|
|
|
|
|
|
$this->assertInstanceOf('Member', $admin);
|
|
|
|
$this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
|
|
|
|
$this->assertEquals($admin->Email, Security::default_admin_username());
|
|
|
|
$this->assertNull($admin->Password);
|
|
|
|
|
|
|
|
}
|
2010-04-12 23:16:26 +02:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|