Skip to content

Commit a3bd376

Browse files
fixup! Make 2FA providers stateful
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 70e87fb commit a3bd376

1 file changed

Lines changed: 42 additions & 17 deletions

File tree

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Created by PhpStorm.
45
* User: christoph
@@ -8,33 +9,57 @@
89

910
namespace lib\Authentication\TwoFactorAuth;
1011

12+
use Exception;
1113
use OC\Authentication\TwoFactorAuth\ProviderLoader;
14+
use OCP\App\IAppManager;
15+
use PHPUnit_Framework_MockObject_MockObject;
16+
use Test\TestCase;
17+
18+
class ProviderLoaderTest extends TestCase {
19+
20+
/** @var IAppManager|PHPUnit_Framework_MockObject_MockObject */
21+
private $appManager;
22+
23+
/** @var IUser|PHPUnit_Framework_MockObject_MockObject */
24+
private $user;
25+
26+
/** @var ProviderLoader */
27+
private $loader;
28+
29+
protected function setUp() {
30+
parent::setUp();
1231

13-
class ProviderLoaderTest extends \Test\TestCase {
32+
$this->appManager = $this->createMock(IAppManager::class);
33+
$this->user = $this->createMock(\OCP\IUser::class);
34+
35+
$this->loader = new ProviderLoader($this->appManager);
36+
}
1437

1538
/**
1639
* @expectedException Exception
1740
* @expectedExceptionMessage Could not load two-factor auth provider \OCA\MyFaulty2faApp\DoesNotExist
1841
*/
1942
public function testFailHardIfProviderCanNotBeLoaded() {
20-
$this->providerLoader->expects($this->once())
21-
->method('getProviders')
43+
$this->appManager->expects($this->once())
44+
->method('getEnabledAppsForUser')
2245
->with($this->user)
23-
->will($this->returnValue(['faulty2faapp']));
24-
$this->manager->expects($this->once())
25-
->method('loadTwoFactorApp')
26-
->with('faulty2faapp');
27-
28-
$this->providerLoader->expects($this->once())
46+
->willReturn(['mail', 'twofactor_totp']);
47+
$this->appManager
2948
->method('getAppInfo')
30-
->with('faulty2faapp')
31-
->will($this->returnValue([
32-
'two-factor-providers' => [
33-
'\OCA\MyFaulty2faApp\DoesNotExist',
34-
],
35-
]));
36-
37-
$this->manager->getProviderSet($this->user);
49+
->will($this->returnValueMap([
50+
['mail', []],
51+
['twofactor_totp'], [
52+
'two-factor-providers' => [
53+
'\\OCA\\MyFaulty2faApp\\DoesNotExist',
54+
],
55+
],
56+
]));
57+
58+
$this->loader->getProviders($this->user);
59+
}
60+
61+
public function testGetProviders() {
62+
3863
}
3964

4065
}

0 commit comments

Comments
 (0)