This commit is contained in:
Jarkko Lehtoranta 2026-06-13 05:00:24 +02:00 committed by GitHub
commit 22ab072faf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 14 deletions

View file

@ -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());
}

View file

@ -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', []],
]);