silverstripe-framework/tests/security/SecurityDefaultAdminTest.php

53 lines
1.4 KiB
PHP
Raw Normal View History

<?php
class SecurityDefaultAdminTest extends SapphireTest {
2014-08-15 08:53:05 +02:00
public function setUp() {
parent::setUp();
2014-08-15 08:53:05 +02:00
// TODO Workaround to force database clearing with no fixture present,
// and avoid sideeffects from other tests
if(!self::using_temp_db()) self::create_temp_db();
self::empty_temp_db();
}
2014-08-15 08:53:05 +02:00
public function testCheckDefaultAdmin() {
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
Security::setDefaultAdmin('admin', 'password');
2014-08-15 08:53:05 +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
Security::setDefaultAdmin(null, null);
}
2014-08-15 08:53:05 +02:00
public function testFindAnAdministratorCreatesNewUser() {
$adminMembers = Permission::get_members_by_permission('ADMIN');
$this->assertEquals(0, $adminMembers->count());
2014-08-15 08:53:05 +02:00
$admin = Security::findAnAdministrator();
2014-08-15 08:53:05 +02:00
$this->assertInstanceOf('Member', $admin);
$this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
$this->assertNull($admin->Email);
$this->assertNull($admin->Password);
}
2014-08-15 08:53:05 +02:00
}