blob: d06095b12e1eb5b1b15a2f8c6a1c4eaebe0ec6ea (
plain)
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
60
61
62
63
64
|
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AdminAudit\Tests\Actions;
use OCA\AdminAudit\Actions\Security;
use OCA\AdminAudit\AuditLogger;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class SecurityTest extends TestCase {
private AuditLogger|MockObject $logger;
private Security $security;
private MockObject|IUser $user;
protected function setUp(): void {
parent::setUp();
$this->logger = $this->createMock(AuditLogger::class);
$this->security = new Security($this->logger);
$this->user = $this->createMock(IUser::class);
$this->user->method('getUID')->willReturn('myuid');
$this->user->method('getDisplayName')->willReturn('mydisplayname');
}
public function testTwofactorFailed() {
$this->logger->expects($this->once())
->method('info')
->with(
$this->equalTo('Failed two factor attempt by user mydisplayname (myuid) with provider myprovider'),
['app' => 'admin_audit']
);
$provider = $this->createMock(IProvider::class);
$provider->method('getDisplayName')
->willReturn('myprovider');
$this->security->twofactorFailed($this->user, $provider);
}
public function testTwofactorSuccess() {
$this->logger->expects($this->once())
->method('info')
->with(
$this->equalTo('Successful two factor attempt by user mydisplayname (myuid) with provider myprovider'),
['app' => 'admin_audit']
);
$provider = $this->createMock(IProvider::class);
$provider->method('getDisplayName')
->willReturn('myprovider');
$this->security->twofactorSuccess($this->user, $provider);
}
}
|