diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2021-04-16 14:52:59 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2021-04-20 21:01:16 +0200 |
commit | 5ee9e1f78467d1004177012978160731606f204e (patch) | |
tree | 19d94834311518bb7cad1e2669f7bb64d5225d39 /tests | |
parent | 46872e392183215a2bcac2e7e80937ae58e4b4ab (diff) | |
download | nextcloud-server-5ee9e1f78467d1004177012978160731606f204e.tar.gz nextcloud-server-5ee9e1f78467d1004177012978160731606f204e.zip |
Move 2FA registration to IBootstrap
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php b/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php index 378376a41f9..1b813b5f36b 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php @@ -26,9 +26,13 @@ declare(strict_types=1); namespace lib\Authentication\TwoFactorAuth; +use OC\AppFramework\Bootstrap\Coordinator; +use OC\AppFramework\Bootstrap\RegistrationContext; +use OC\AppFramework\Bootstrap\ServiceRegistration; use OC\Authentication\TwoFactorAuth\ProviderLoader; use OCP\App\IAppManager; use OCP\Authentication\TwoFactorAuth\IProvider; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class ProviderLoaderTest extends TestCase { @@ -39,6 +43,9 @@ class ProviderLoaderTest extends TestCase { /** @var \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject */ private $user; + /** @var RegistrationContext|MockObject */ + private $registrationContext; + /** @var ProviderLoader */ private $loader; @@ -48,7 +55,12 @@ class ProviderLoaderTest extends TestCase { $this->appManager = $this->createMock(IAppManager::class); $this->user = $this->createMock(\OCP\IUser::class); - $this->loader = new ProviderLoader($this->appManager); + $this->registrationContext = $this->createMock(RegistrationContext::class); + $coordinator = $this->createMock(Coordinator::class); + $coordinator->method('getRegistrationContext') + ->willReturn($this->registrationContext); + + $this->loader = new ProviderLoader($this->appManager, $coordinator); } @@ -97,4 +109,29 @@ class ProviderLoaderTest extends TestCase { $this->assertArrayHasKey('test', $providers); $this->assertSame($provider, $providers['test']); } + + public function testGetProvidersBootstrap() { + $provider = $this->createMock(IProvider::class); + $provider->method('getId')->willReturn('test'); + + \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) { + return $provider; + }); + + $this->appManager->expects($this->once()) + ->method('getEnabledAppsForUser') + ->with($this->user) + ->willReturn([]); + + $this->registrationContext->method('getTwoFactorProvider') + ->willReturn([ + new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider') + ]); + + $providers = $this->loader->getProviders($this->user); + + $this->assertCount(1, $providers); + $this->assertArrayHasKey('test', $providers); + $this->assertSame($provider, $providers['test']); + } } |