ProviderSetTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace Test\Authentication\TwoFactorAuth;
  25. use OC\Authentication\TwoFactorAuth\ProviderSet;
  26. use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider;
  27. use OCP\Authentication\TwoFactorAuth\IProvider;
  28. use Test\TestCase;
  29. class ProviderSetTest extends TestCase {
  30. /** @var ProviderSet */
  31. private $providerSet;
  32. public function testIndexesProviders() {
  33. $p1 = $this->createMock(IProvider::class);
  34. $p1->method('getId')->willReturn('p1');
  35. $p2 = $this->createMock(IProvider::class);
  36. $p2->method('getId')->willReturn('p2');
  37. $expected = [
  38. 'p1' => $p1,
  39. 'p2' => $p2,
  40. ];
  41. $set = new ProviderSet([$p2, $p1], false);
  42. $this->assertEquals($expected, $set->getProviders());
  43. }
  44. public function testGet3rdPartyProviders() {
  45. $p1 = $this->createMock(IProvider::class);
  46. $p1->method('getId')->willReturn('p1');
  47. $p2 = $this->createMock(IProvider::class);
  48. $p2->method('getId')->willReturn('p2');
  49. $p3 = $this->createMock(BackupCodesProvider::class);
  50. $p3->method('getId')->willReturn('p3');
  51. $expected = [
  52. 'p1' => $p1,
  53. 'p2' => $p2,
  54. ];
  55. $set = new ProviderSet([$p2, $p1], false);
  56. $this->assertEquals($expected, $set->getPrimaryProviders());
  57. }
  58. public function testGetProvider() {
  59. $p1 = $this->createMock(IProvider::class);
  60. $p1->method('getId')->willReturn('p1');
  61. $set = new ProviderSet([$p1], false);
  62. $provider = $set->getProvider('p1');
  63. $this->assertEquals($p1, $provider);
  64. }
  65. public function testGetProviderNotFound() {
  66. $set = new ProviderSet([], false);
  67. $provider = $set->getProvider('p1');
  68. $this->assertNull($provider);
  69. }
  70. public function testIsProviderMissing() {
  71. $set = new ProviderSet([], true);
  72. $this->assertTrue($set->isProviderMissing());
  73. }
  74. }