Merge pull request #10560 from creative-commoners/pulls/4.11/default-admin-encryption

This commit is contained in:
Michal Kleiner 2022-10-27 14:48:52 +13:00 committed by GitHub
commit 27eb390d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -171,7 +171,7 @@ class DefaultAdminService
$admin = Member::create(); $admin = Member::create();
$admin->FirstName = $name ?: $email; $admin->FirstName = $name ?: $email;
$admin->Email = $email; $admin->Email = $email;
$admin->PasswordEncryption = 'none'; $admin->PasswordEncryption = Security::config()->get('password_encryption_algorithm');
$admin->write(); $admin->write();
} }

View File

@ -77,7 +77,7 @@ class SecurityDefaultAdminTest extends SapphireTest
$this->assertTrue(Permission::checkMember($admin, 'ADMIN')); $this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
$this->assertEquals($admin->Email, DefaultAdminService::getDefaultAdminUsername()); $this->assertEquals($admin->Email, DefaultAdminService::getDefaultAdminUsername());
$this->assertTrue(DefaultAdminService::isDefaultAdmin($admin->Email)); $this->assertTrue(DefaultAdminService::isDefaultAdmin($admin->Email));
$this->assertNull($admin->Password); $this->assertStringStartsWith('$2y$10$', $admin->Password);
$this->assertArrayHasKey($admin->PasswordEncryption, PasswordEncryptor::get_encryptors()); $this->assertArrayHasKey($admin->PasswordEncryption, PasswordEncryptor::get_encryptors());
} }
@ -92,7 +92,7 @@ class SecurityDefaultAdminTest extends SapphireTest
$this->assertTrue(Permission::checkMember($admin, 'ADMIN')); $this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
$this->assertEquals('newadmin@example.com', $admin->Email); $this->assertEquals('newadmin@example.com', $admin->Email);
$this->assertEquals('Admin Name', $admin->FirstName); $this->assertEquals('Admin Name', $admin->FirstName);
$this->assertNull($admin->Password); $this->assertStringStartsWith('$2y$10$', $admin->Password);
} }
public function testFindAnAdministratorWithoutDefaultAdmin() public function testFindAnAdministratorWithoutDefaultAdmin()
@ -112,9 +112,8 @@ class SecurityDefaultAdminTest extends SapphireTest
$admin = $service->findOrCreateDefaultAdmin(); $admin = $service->findOrCreateDefaultAdmin();
$this->assertTrue(Permission::checkMember($admin, 'ADMIN')); $this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
// User should have Email but no Password
$this->assertEquals('admin', $admin->Email); $this->assertEquals('admin', $admin->Email);
$this->assertEmpty($admin->Password); $this->assertStringStartsWith('$2y$10$', $admin->Password);
} }
public function testDefaultAdmin() public function testDefaultAdmin()
@ -127,6 +126,6 @@ class SecurityDefaultAdminTest extends SapphireTest
$this->assertTrue(Permission::checkMember($admin, 'ADMIN')); $this->assertTrue(Permission::checkMember($admin, 'ADMIN'));
$this->assertEquals($admin->Email, DefaultAdminService::getDefaultAdminUsername()); $this->assertEquals($admin->Email, DefaultAdminService::getDefaultAdminUsername());
$this->assertTrue(DefaultAdminService::isDefaultAdmin($admin->Email)); $this->assertTrue(DefaultAdminService::isDefaultAdmin($admin->Email));
$this->assertNull($admin->Password); $this->assertStringStartsWith('$2y$10$', $admin->Password);
} }
} }