Skip to content

Commit

Permalink
Additional Unit tests. Test expected result of isUserInMFAEnabledGroup()
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-nz authored and GuySartorelli committed Oct 1, 2023
1 parent 955701a commit f63a652
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/php/Service/EnforcementManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit f63a652

Please sign in to comment.