mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Checking for presence of all columns in Security::database_is_ready(). This was necessitated by an earlier change to the sapphire ORM which now selects all columns explicitly in a SQL query (instead of SELECT *) (see #4027) (from r97480)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102494 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
426190bc9e
commit
6450810b4c
@ -832,6 +832,8 @@ class Security extends Controller {
|
||||
|
||||
/**
|
||||
* Checks the database is in a state to perform security checks.
|
||||
* See {@link DatabaseAdmin->init()} for more information.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function database_is_ready() {
|
||||
@ -839,10 +841,21 @@ class Security extends Controller {
|
||||
$requiredTables[] = 'Group';
|
||||
$requiredTables[] = 'Permission';
|
||||
|
||||
foreach($requiredTables as $table) if(!ClassInfo::hasTable($table)) return false;
|
||||
foreach($requiredTables as $table) {
|
||||
// if any of the tables aren't created in the database
|
||||
if(!ClassInfo::hasTable($table)) return false;
|
||||
|
||||
return (($permissionFields = DB::fieldList('Permission')) && isset($permissionFields['Type'])) &&
|
||||
(($memberFields = DB::fieldList('Member')) && isset($memberFields['RememberLoginToken']));
|
||||
// if any of the tables don't have all fields mapped as table columns
|
||||
$dbFields = DB::fieldList($table);
|
||||
if(!$dbFields) return false;
|
||||
|
||||
$objFields = DataObject::database_fields($table);
|
||||
$missingFields = array_diff_key($objFields, $dbFields);
|
||||
|
||||
if($missingFields) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -261,6 +261,19 @@ class SecurityTest extends FunctionalTest {
|
||||
$this->assertEquals($attempt->Email, 'sam@silverstripe.com');
|
||||
$this->assertEquals($attempt->Member(), $member);
|
||||
}
|
||||
|
||||
function testDatabaseIsReadyWithInsufficientMemberColumns() {
|
||||
// Assumption: The database has been built correctly by the test runner,
|
||||
// and has all columns present in the ORM
|
||||
DB::getConn()->renameField('Member', 'Email', 'Email_renamed');
|
||||
|
||||
// Email column is now missing, which means we're not ready to do permission checks
|
||||
$this->assertFalse(Security::database_is_ready());
|
||||
|
||||
// Rebuild the database (which re-adds the Email column), and try again
|
||||
$this->resetDBSchema(true);
|
||||
$this->assertTrue(Security::database_is_ready());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a log-in form using Director::test().
|
||||
|
Loading…
x
Reference in New Issue
Block a user