Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP PHP Support in CMS5 #476

Merged
merged 3 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/framework": "^4.10",
"silverstripe/admin": "^1.1",
"silverstripe/siteconfig": "^4.1",
"defuse/php-encryption": "^2.2",
"silverstripe/login-forms": "^4.0",
"silverstripe/security-extensions": "^4.0"
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/admin": "^2",
"silverstripe/siteconfig": "^5",
"defuse/php-encryption": "^2.3",
"silverstripe/login-forms": "^5",
"silverstripe/security-extensions": "^5"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
"squizlabs/php_codesniffer": "^3"
},
"conflict": {
"silverstripe/subsites": "<2.2.2 || 2.3.0",
Expand Down
9 changes: 7 additions & 2 deletions src/Extension/AccountReset/SecurityAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class SecurityAdminExtension extends Extension
'reset',
];

private static $url_handlers = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We change the SecurityAdmin to be a plain ModelAdmin. A side affect of that seems to be that we can create REST endpoints directly on this controller anymore.

MFA has a "reset" endpoint on Security used to trigger a force reset of a Member MFA settings.

I change that endpoint to be users/reset/$ID instead of reset/$ID.

'users/reset/$ID' => 'reset',
];

/**
* @var string[]
*/
Expand Down Expand Up @@ -135,12 +139,13 @@ protected function sendResetEmail($member)
->addData('AccountResetLink', $this->getAccountResetLink($member, $token))
->addData('Member', $member)
->setTo($member->Email);

return $email->send();
$email->send();
} catch (Exception $e) {
$this->logger->info('WARNING: Account Reset Email failed to send: ' . $e->getMessage());
return false;
}

return true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Email::send() now return void. We'll consider the Email sending a success if no exceptions are thrown.


/**
Expand Down
2 changes: 1 addition & 1 deletion src/FormField/RegisteredMFAMethodListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getSchemaDataDefaults()
'backupCreationDate' => $this->getBackupMethod()
? $this->getBackupMethod()->Created
: null,
'resetEndpoint' => SecurityAdmin::singleton()->Link("reset/{$this->value}"),
'resetEndpoint' => SecurityAdmin::singleton()->Link("users/reset/{$this->value}"),
'isMFARequired' => EnforcementManager::create()->isMFARequired(),
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testEndpointRequiresCSRF()
/** @var Member $member */
$member = $this->objFromFixture(Member::class, 'squib');

$response = $this->post(SecurityAdmin::singleton()->Link("reset/{$member->ID}"), [true]);
$response = $this->post(SecurityAdmin::singleton()->Link("users/reset/{$member->ID}"), [true]);

$this->assertEquals(400, $response->getStatusCode(), $response->getBody());
$this->assertStringContainsString('Invalid or missing CSRF', $response->getBody());
Expand All @@ -52,7 +52,7 @@ public function testResetCanBeInitiatedByAdmin()
$member = $this->objFromFixture(Member::class, 'squib');

$response = $this->post(
SecurityAdmin::singleton()->Link("reset/{$member->ID}"),
SecurityAdmin::singleton()->Link("users/reset/{$member->ID}"),
[true],
null,
null,
Expand All @@ -71,7 +71,7 @@ public function testResetCannotBeInitiatedByStandardUser()
$member = $this->objFromFixture(Member::class, 'admin');

$response = $this->post(
SecurityAdmin::singleton()->Link("reset/{$member->ID}"),
SecurityAdmin::singleton()->Link("users/reset/{$member->ID}"),
[true],
null,
null,
Expand Down
6 changes: 3 additions & 3 deletions tests/php/Service/RegisteredMethodManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testRegisterForMemberWritesToExistingRegisteredMethod()
public function testRegisterForMemberCreatesNewMethod()
{
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Mike']);
$member = Member::create(['FirstName' => 'Mike', 'Email' => '[email protected]']);
$member->write();
$method = new BackupCodeMethod();

Expand All @@ -72,7 +72,7 @@ public function testRegisterForMemberCreatesNewMethod()
public function testRegisterForMemberAssignsDefaultRegisteredMethod()
{
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Mike']);
$member = Member::create(['FirstName' => 'Mike', 'Email' => '[email protected]']);
$member->write();
$method = new BackupCodeMethod();

Expand Down Expand Up @@ -127,7 +127,7 @@ public function testRegisterBackupMethodDoesNotSendEmail()
public function testRegisterForMemberDoesNothingWithNoData()
{
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Michelle']);
$member = Member::create(['FirstName' => 'Michelle', 'Email' => '[email protected]']);
$member->write();
$method = new BackupCodeMethod();

Expand Down