mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 10:40:40 -04:00
Merge 754a976194 into d02155784b
This commit is contained in:
commit
22ab072faf
2 changed files with 53 additions and 14 deletions
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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', []],
|
||||
]);
|
||||
|
|
|
|||
Loading…
Reference in a new issue