-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathUserManagementMfaTest.php
More file actions
59 lines (44 loc) · 2.09 KB
/
Copy pathUserManagementMfaTest.php
File metadata and controls
59 lines (44 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Tests\User;
use BookStack\Access\Mfa\MfaValue;
use BookStack\Activity\ActivityType;
use BookStack\Permissions\Permission;
use Tests\TestCase;
class UserManagementMfaTest extends TestCase
{
public function test_configured_mfa_options_visible_on_user_edit()
{
$editor = $this->users->editor();
$resp = $this->asAdmin()->get($editor->getEditUrl());
$resp->assertSeeText('0 methods configured');
MfaValue::factory()->create(['user_id' => $editor->id, 'method' => MfaValue::METHOD_BACKUP_CODES]);
$resp = $this->get($editor->getEditUrl());
$resp->assertSeeText('1 method configured');
$resp->assertDontSeeText('0 methods configured');
}
public function test_reset_mfa_flow()
{
$editor = $this->users->editor();
MfaValue::factory()->create(['user_id' => $editor->id, 'method' => MfaValue::METHOD_BACKUP_CODES]);
MfaValue::factory()->create(['user_id' => $editor->id, 'method' => MfaValue::METHOD_TOTP]);
$this->assertEquals(2, $editor->mfaValues()->count());
$resp = $this->asAdmin()->get($editor->getEditUrl());
$this->withHtml($resp)->assertElementContains('form[action$="/mfa"] button[type="submit"]', 'Reset');
$resp = $this->delete($editor->getEditUrl('/mfa'));
$resp->assertRedirect($editor->getEditUrl());
$this->assertActivityExists(ActivityType::USER_MFA_RESET);
$resp = $this->followRedirects($resp);
$resp->assertSee('Multi-factor authentication methods reset');
$this->assertEquals(0, $editor->mfaValues()->count());
}
public function test_users_manage_permission_required_for_mfa_reset()
{
$editor = $this->users->editor();
$resp = $this->actingAs($editor)->delete($editor->getEditUrl('/mfa'));
$this->assertPermissionError($resp);
$this->permissions->grantUserRolePermissions($editor, [Permission::UsersManage]);
$resp = $this->delete($editor->getEditUrl('/mfa'));
$this->assertNotPermissionError($resp);
$resp->assertRedirect($editor->getEditUrl());
}
}