Skip to content

Commit

Permalink
FIX Email correct content via translation key correction
Browse files Browse the repository at this point in the history
Upon registering a user is being sent an email to notify them that they have successfully added a multiple factor of authentication to their account on the site.
However due to a mix up with translation keys, the default text was being replaced with that for removing an authentication factor.
This commit fixes the translation key, and extends the tests to cover the body as well as the subject.
  • Loading branch information
Dylan Wagstaff committed Jul 24, 2019
1 parent f2b1bda commit 254864f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ en:
CODESLEFT: 'You now have {count} codes remaining.'
HELLO: Hi
NOTYOU: 'If you did not take this action, please contact your system administrator immediately.'
REGISTERED: 'You have removed the {method} authentication method from your account at {site}.'
REGISTERED: 'You have successfully registered {method} as an extra layer of protection for your account at {site}.'
REMOVED: 'You have removed the {method} authentication method from your account at {site}.'
USEDBACKUPCODE: 'A recovery code was used to gain access to your account at {site}.'
SilverStripe\MFA\Extension\AccountReset\SecurityAdminExtension:
ACCOUNT_RESET_EMAIL_SUBJECT: 'Reset your account'
Expand Down
2 changes: 1 addition & 1 deletion templates/SilverStripe/MFA/Email/Notification_removed.ss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p><%t SilverStripe\\MFA\\Email\\Notification.HELLO 'Hi' %> $Member.Name,</p>

<p>
<%t SilverStripe\\MFA\\Email\\Notification.REGISTERED 'You have removed the {method} authentication method from your account at {site}.' method=$MethodName site=$AbsoluteBaseURL %>
<%t SilverStripe\\MFA\\Email\\Notification.REMOVED 'You have removed the {method} authentication method from your account at {site}.' method=$MethodName site=$AbsoluteBaseURL %>
</p>

<p>
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Context/LoginContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SilverStripe\MFA\Extension\SiteConfigExtension;
use SilverStripe\SiteConfig\SiteConfig;

if (!class_exists(CMSLoginContext::class) || !class_exists(BehatLoginContext::class)) {
if (!class_exists(BehatLoginContext::class) || !class_exists(CMSLoginContext::class)) {
return;
}

Expand Down
12 changes: 10 additions & 2 deletions tests/php/Service/RegisteredMethodManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SilverStripe\MFA\Tests\Stub\BasicMath\Method as BasicMathMethod;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use SilverStripe\View\SSViewer;

class RegisteredMethodManagerTest extends SapphireTest
{
Expand Down Expand Up @@ -92,6 +93,7 @@ public function testRegisterForMemberAssignsDefaultRegisteredMethod()

public function testRegisterForMemberSendsNotification()
{
SSViewer::set_themes(['$public', '$default']);
/** @var Member&MemberExtension $member */
$member = Member::create(['FirstName' => 'Mike', 'Email' => '[email protected]']);
$member->write();
Expand All @@ -100,7 +102,12 @@ public function testRegisterForMemberSendsNotification()
$manager = RegisteredMethodManager::singleton();
RegisteredMethodManager::singleton()->registerForMember($member, $method, ['foo', 'bar']);

$this->assertEmailSent($member->Email, null, '/method was added to your account/');
$this->assertEmailSent(
$member->Email,
null,
'/method was added to your account/',
'/You have successfully registered/'
);
}

public function testRegisterBackupMethodDoesNotSendEmail()
Expand Down Expand Up @@ -146,13 +153,14 @@ public function testDeleteFromMember()

public function testDeleteFromMemberSendsNotification()
{
SSViewer::set_themes(['$public', '$default']);
/** @var Member&MemberExtension $member */
$member = $this->objFromFixture(Member::class, 'bob_jones');

$manager = RegisteredMethodManager::singleton();
$manager->deleteFromMember($member, new BasicMathMethod());

$this->assertEmailSent($member->Email, null, '/method was removed from your account/');
$this->assertEmailSent($member->Email, null, '/method was removed from your account/', '/You have removed/');
}

public function testDeletingLastMethodRemovesBackupCodes()
Expand Down

0 comments on commit 254864f

Please sign in to comment.