silverstripe-framework/tests/security/SecurityDefaultAdminTest.php
Ingo Schommer 51c14227b2 API CHANGE Security::setDefaultAdmin() no longer writes credentials to any Member database records (created through Security::findAnAdministrator(). This prevents outdated credentials when setDefaultAdmin() code changes after creating the database record (see #4271)
API CHANGE Security::findAnAdministrator() no longer sets 'Email' and 'Password' properties on newly created members. Removed the $username and $password argments from the method.
ENHANCEMENT Member->requireDefaultRecords() no longer creates a default administrator based on $_REQUEST data. Moved functionality into Installer->install()
MINOR Security::findAnAdministrator() names any default administrators 'Default Admin' instead of 'Admin'

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97478 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:18:13 +13:00

48 lines
1.3 KiB
PHP

<?php
class SecurityDefaultAdminTest extends SapphireTest {
function setUp() {
// TODO Workaround to force database clearing with no fixture present,
// and avoid sideeffects from other tests
self::empty_temp_db();
parent::setUp();
}
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');
$this->assertFalse($adminMembers);
$admin = Security::findAnAdministrator();
$this->assertType('Member', $admin);
$this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
$this->assertNull($admin->Email);
$this->assertNull($admin->Password);
}
}