From f63a65277baacf957e7d099c333b7e048dc34acf Mon Sep 17 00:00:00 2001 From: Scott Sutherland Date: Fri, 30 Oct 2020 15:47:34 +1300 Subject: [PATCH] Additional Unit tests. Test expected result of isUserInMFAEnabledGroup() --- tests/php/Service/EnforcementManagerTest.php | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/php/Service/EnforcementManagerTest.php b/tests/php/Service/EnforcementManagerTest.php index 56c7f1d0..fa7cd5e7 100644 --- a/tests/php/Service/EnforcementManagerTest.php +++ b/tests/php/Service/EnforcementManagerTest.php @@ -9,6 +9,7 @@ use SilverStripe\MFA\Service\MethodRegistry; use SilverStripe\MFA\Tests\Stub\BasicMath\Method as BasicMathMethod; use SilverStripe\ORM\FieldType\DBDatetime; +use SilverStripe\Security\Group; use SilverStripe\Security\Member; use SilverStripe\SiteConfig\SiteConfig; @@ -253,6 +254,34 @@ public function testUserHasCompletedRegistrationWhenBackupMethodIsDisabled() $this->assertTrue(EnforcementManager::create()->hasCompletedRegistration($member)); } + public function testShouldRedirectToMFAWhenUserIsInMFARestrictedGroup() + { + $this->setSiteConfig(['MFARequired' => true]); + $config = SiteConfig::current_site_config(); + $group = $this->objFromFixture(Group::class, 'admingroup'); + $config->MFAGroupRestrictions()->add($group); + + /** @var Member $member */ + $member = $this->objFromFixture(Member::class, 'sally_smith'); + $this->logInAs($member); + + $this->assertTrue(EnforcementManager::create()->shouldRedirectToMFA($member)); + } + + public function testShouldNotRedirectToMFAWhenUserIsNotInMFARestrictedGroup() + { + $this->setSiteConfig(['MFARequired' => true]); + $config = SiteConfig::current_site_config(); + $group = $this->objFromFixture(Group::class, 'admingroup'); + $config->MFAGroupRestrictions()->add($group); + + /** @var Member $member */ + $member = $this->objFromFixture(Member::class, 'sully_smith'); + $this->logInAs($member); + + $this->assertFalse(EnforcementManager::create()->shouldRedirectToMFA($member)); + } + /** * Helper method for changing the current SiteConfig values *