diff --git a/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php b/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php index 3bfbd77941b57..32e8d1d84bd67 100644 --- a/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php +++ b/lib/private/Authentication/TwoFactorAuth/MandatoryTwoFactor.php @@ -46,7 +46,7 @@ public function __construct(IConfig $config, IGroupManager $groupManager) { */ 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', []) ); @@ -56,7 +56,7 @@ public function getState(): EnforcementState { * 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 0119c97769639..6455dfd3b3f47 100644 --- a/tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php @@ -54,10 +54,14 @@ protected function setUp(): void { } public function testIsNotEnforced() { + $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', [], []], ]); @@ -68,10 +72,14 @@ public function testIsNotEnforced() { } public function testIsEnforced() { + $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', [], []], ]); @@ -84,10 +92,14 @@ public function testIsEnforced() { public function testIsNotEnforcedForAnybody() { $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', [], []], ]); @@ -100,10 +112,14 @@ public function testIsNotEnforcedForAnybody() { public function testIsEnforcedForAGroupMember() { $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', [], []], ]); @@ -120,10 +136,14 @@ public function testIsEnforcedForAGroupMember() { public function testIsEnforcedForOtherGroups() { $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', [], []], ]); @@ -138,10 +158,14 @@ public function testIsEnforcedForOtherGroups() { public function testIsEnforcedButMemberOfExcludedGroup() { $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']], ]); @@ -157,10 +181,15 @@ public function testIsEnforcedButMemberOfExcludedGroup() { public function testSetEnforced() { $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', []], ]); @@ -170,10 +199,15 @@ public function testSetEnforced() { public function testSetEnforcedForGroups() { $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']], ]); @@ -183,10 +217,15 @@ public function testSetEnforcedForGroups() { public function testSetNotEnforced() { $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', []], ]);