blob: 13b9480921e888695c861a1fd46e969646d7e709 (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
<?php
/**
* Nextcloud - U2F 2FA
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright Christoph Wurst 2016
*/
namespace OCA\TwoFactorU2F\Tests\Unit\Provider;
use OCA\TwoFactorU2F\Provider\U2FProvider;
use OCA\TwoFactorU2F\Service\U2FManager;
use OCP\IL10N;
use OCP\IUser;
use OCP\Template;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class U2FProviderTest extends TestCase {
/** @var IL10N|MockObject */
private $l10n;
/** @var U2FManager|MockObject */
private $manager;
/** @var U2FProvider */
private $provider;
protected function setUp() {
parent::setUp();
$this->l10n = $this->createMock(IL10N::class);
$this->manager = $this->createMock(U2FManager::class);
$this->provider = new U2FProvider($this->l10n, $this->manager);
}
public function testGetId() {
$this->assertSame('u2f', $this->provider->getId());
}
public function testGetDisplayName() {
$this->assertSame('U2F device', $this->provider->getDisplayName());
}
public function testGetDescription() {
$this->l10n->expects($this->once())
->method('t')
->with('Authenticate with an U2F device')
->willReturn('translated');
$this->assertSame('translated', $this->provider->getDescription());
}
public function testGetTemplate() {
$user = $this->createMock(IUser::class);
$this->manager->expects($this->once())
->method('startAuthenticate')
->willReturn([]);
$tmpl = new Template('twofactor_u2f', 'challenge');
$tmpl->assign('reqs', []);
$actual = $this->provider->getTemplate($user);
$this->assertEquals($tmpl, $actual);
$actual->fetchPage();
}
public function testVerifyChallenge() {
$user = $this->createMock(IUser::class);
$val = '123';
$this->manager->expects($this->once())
->method('finishAuthenticate')
->willReturn(false);
$this->assertFalse($this->provider->verifyChallenge($user, $val));
}
public function testIsTwoFactorAuthEnabledForUser() {
$user = $this->createMock(IUser::class);
$devices = [
'dev1',
];
$this->manager->expects($this->once())
->method('getDevices')
->willReturn($devices);
$this->assertTrue($this->provider->isTwoFactorAuthEnabledForUser($user));
}
public function testIsTwoFactorAuthDisabledForUser() {
$user = $this->createMock(IUser::class);
$devices = [];
$this->manager->expects($this->once())
->method('getDevices')
->willReturn($devices);
$this->assertFalse($this->provider->isTwoFactorAuthEnabledForUser($user));
}
}
|