diff --git a/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php b/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php index b829666f3c0..4e0bb63242a 100644 --- a/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php +++ b/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php @@ -25,7 +25,7 @@ class MandatoryTwoFactor { */ public function getState(): EnforcementState { return new EnforcementState( - $this->config->getSystemValue('twofactor_enforced', 'false') === 'true', + $this->config->getSystemValueBool('twofactor_enforced', false), $this->config->getSystemValue('twofactor_enforced_groups', []), $this->config->getSystemValue('twofactor_enforced_excluded_groups', []) ); @@ -35,7 +35,7 @@ class MandatoryTwoFactor { * Set the state of enforced two-factor auth */ public function setState(EnforcementState $state) { - $this->config->setSystemValue('twofactor_enforced', $state->isEnforced() ? 'true' : 'false'); + $this->config->setSystemValueBool('twofactor_enforced', $state->isEnforced()); $this->config->setSystemValue('twofactor_enforced_groups', $state->getEnforcedGroups()); $this->config->setSystemValue('twofactor_enforced_excluded_groups', $state->getExcludedGroups()); } diff --git a/tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php b/tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php index cfbb701414c..590b5a7851e 100644 --- a/tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php @@ -38,10 +38,14 @@ class MandatoryTwoFactorTest extends TestCase { } public function testIsNotEnforced(): void { + $this->config + ->method('getSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false, false], + ]); $this->config ->method('getSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false', 'false'], ['twofactor_enforced_groups', [], []], ['twofactor_enforced_excluded_groups', [], []], ]); @@ -52,10 +56,14 @@ class MandatoryTwoFactorTest extends TestCase { } public function testIsEnforced(): void { + $this->config + ->method('getSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false, true], + ]); $this->config ->method('getSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false', 'true'], ['twofactor_enforced_groups', [], []], ['twofactor_enforced_excluded_groups', [], []], ]); @@ -68,10 +76,14 @@ class MandatoryTwoFactorTest extends TestCase { public function testIsNotEnforcedForAnybody(): void { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user123'); + $this->config + ->method('getSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false, false], + ]); $this->config ->method('getSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false', 'false'], ['twofactor_enforced_groups', [], []], ['twofactor_enforced_excluded_groups', [], []], ]); @@ -84,10 +96,14 @@ class MandatoryTwoFactorTest extends TestCase { public function testIsEnforcedForAGroupMember(): void { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user123'); + $this->config + ->method('getSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false, true], + ]); $this->config ->method('getSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false', 'true'], ['twofactor_enforced_groups', [], ['twofactorers']], ['twofactor_enforced_excluded_groups', [], []], ]); @@ -104,10 +120,14 @@ class MandatoryTwoFactorTest extends TestCase { public function testIsEnforcedForOtherGroups(): void { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user123'); + $this->config + ->method('getSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false, true], + ]); $this->config ->method('getSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false', 'true'], ['twofactor_enforced_groups', [], ['twofactorers']], ['twofactor_enforced_excluded_groups', [], []], ]); @@ -122,10 +142,14 @@ class MandatoryTwoFactorTest extends TestCase { public function testIsEnforcedButMemberOfExcludedGroup(): void { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user123'); + $this->config + ->method('getSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false, true], + ]); $this->config ->method('getSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false', 'true'], ['twofactor_enforced_groups', [], []], ['twofactor_enforced_excluded_groups', [], ['yoloers']], ]); @@ -141,10 +165,15 @@ class MandatoryTwoFactorTest extends TestCase { public function testSetEnforced(): void { $this->config - ->expects($this->exactly(3)) + ->expects($this->exactly(1)) + ->method('setSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', true], + ]); + $this->config + ->expects($this->exactly(2)) ->method('setSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'true'], ['twofactor_enforced_groups', []], ['twofactor_enforced_excluded_groups', []], ]); @@ -154,10 +183,15 @@ class MandatoryTwoFactorTest extends TestCase { public function testSetEnforcedForGroups(): void { $this->config - ->expects($this->exactly(3)) + ->expects($this->exactly(1)) + ->method('setSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', true], + ]); + $this->config + ->expects($this->exactly(2)) ->method('setSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'true'], ['twofactor_enforced_groups', ['twofactorers']], ['twofactor_enforced_excluded_groups', ['yoloers']], ]); @@ -167,10 +201,15 @@ class MandatoryTwoFactorTest extends TestCase { public function testSetNotEnforced(): void { $this->config - ->expects($this->exactly(3)) + ->expects($this->exactly(1)) + ->method('setSystemValueBool') + ->willReturnMap([ + ['twofactor_enforced', false], + ]); + $this->config + ->expects($this->exactly(2)) ->method('setSystemValue') ->willReturnMap([ - ['twofactor_enforced', 'false'], ['twofactor_enforced_groups', []], ['twofactor_enforced_excluded_groups', []], ]);