Skip to content

Commit

Permalink
fixup! Make 2FA providers stateful
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Jun 18, 2018
1 parent 70e87fb commit a3bd376
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Created by PhpStorm.
* User: christoph
Expand All @@ -8,33 +9,57 @@

namespace lib\Authentication\TwoFactorAuth;

use Exception;
use OC\Authentication\TwoFactorAuth\ProviderLoader;
use OCP\App\IAppManager;
use PHPUnit_Framework_MockObject_MockObject;
use Test\TestCase;

class ProviderLoaderTest extends TestCase {

/** @var IAppManager|PHPUnit_Framework_MockObject_MockObject */
private $appManager;

/** @var IUser|PHPUnit_Framework_MockObject_MockObject */
private $user;

/** @var ProviderLoader */
private $loader;

protected function setUp() {
parent::setUp();

class ProviderLoaderTest extends \Test\TestCase {
$this->appManager = $this->createMock(IAppManager::class);
$this->user = $this->createMock(\OCP\IUser::class);

$this->loader = new ProviderLoader($this->appManager);
}

/**
* @expectedException Exception
* @expectedExceptionMessage Could not load two-factor auth provider \OCA\MyFaulty2faApp\DoesNotExist
*/
public function testFailHardIfProviderCanNotBeLoaded() {
$this->providerLoader->expects($this->once())
->method('getProviders')
$this->appManager->expects($this->once())
->method('getEnabledAppsForUser')
->with($this->user)
->will($this->returnValue(['faulty2faapp']));
$this->manager->expects($this->once())
->method('loadTwoFactorApp')
->with('faulty2faapp');

$this->providerLoader->expects($this->once())
->willReturn(['mail', 'twofactor_totp']);
$this->appManager
->method('getAppInfo')
->with('faulty2faapp')
->will($this->returnValue([
'two-factor-providers' => [
'\OCA\MyFaulty2faApp\DoesNotExist',
],
]));

$this->manager->getProviderSet($this->user);
->will($this->returnValueMap([
['mail', []],
['twofactor_totp'], [
'two-factor-providers' => [
'\\OCA\\MyFaulty2faApp\\DoesNotExist',
],
],
]));

$this->loader->getProviders($this->user);
}

public function testGetProviders() {

}

}

0 comments on commit a3bd376

Please sign in to comment.