ProviderSetTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Authentication\TwoFactorAuth;
  8. use OC\Authentication\TwoFactorAuth\ProviderSet;
  9. use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
  10. use OCP\Authentication\TwoFactorAuth\IProvider;
  11. use Test\TestCase;
  12. class ProviderSetTest extends TestCase {
  13. /** @var ProviderSet */
  14. private $providerSet;
  15. public function testIndexesProviders(): void {
  16. $p1 = $this->createMock(IProvider::class);
  17. $p1->method('getId')->willReturn('p1');
  18. $p2 = $this->createMock(IProvider::class);
  19. $p2->method('getId')->willReturn('p2');
  20. $expected = [
  21. 'p1' => $p1,
  22. 'p2' => $p2,
  23. ];
  24. $set = new ProviderSet([$p2, $p1], false);
  25. $this->assertEquals($expected, $set->getProviders());
  26. }
  27. public function testGet3rdPartyProviders(): void {
  28. $p1 = $this->createMock(IProvider::class);
  29. $p1->method('getId')->willReturn('p1');
  30. $p2 = $this->createMock(IProvider::class);
  31. $p2->method('getId')->willReturn('p2');
  32. $p3 = $this->createMock(BackupCodesProvider::class);
  33. $p3->method('getId')->willReturn('p3');
  34. $expected = [
  35. 'p1' => $p1,
  36. 'p2' => $p2,
  37. ];
  38. $set = new ProviderSet([$p2, $p1], false);
  39. $this->assertEquals($expected, $set->getPrimaryProviders());
  40. }
  41. public function testGetProvider(): void {
  42. $p1 = $this->createMock(IProvider::class);
  43. $p1->method('getId')->willReturn('p1');
  44. $set = new ProviderSet([$p1], false);
  45. $provider = $set->getProvider('p1');
  46. $this->assertEquals($p1, $provider);
  47. }
  48. public function testGetProviderNotFound(): void {
  49. $set = new ProviderSet([], false);
  50. $provider = $set->getProvider('p1');
  51. $this->assertNull($provider);
  52. }
  53. public function testIsProviderMissing(): void {
  54. $set = new ProviderSet([], true);
  55. $this->assertTrue($set->isProviderMissing());
  56. }
  57. }