ListCommandTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Tests\Command;
  8. use OCA\Files_External\Command\ListCommand;
  9. use OCA\Files_External\Lib\Auth\NullMechanism;
  10. use OCA\Files_External\Lib\Auth\Password\Password;
  11. use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
  12. use OCA\Files_External\Lib\Backend\Local;
  13. use OCA\Files_External\Lib\StorageConfig;
  14. use OCA\Files_External\Service\GlobalStoragesService;
  15. use OCA\Files_External\Service\UserStoragesService;
  16. use OCP\Authentication\LoginCredentials\IStore;
  17. use OCP\IL10N;
  18. use OCP\ISession;
  19. use OCP\IUserManager;
  20. use OCP\IUserSession;
  21. use OCP\Security\ICrypto;
  22. use Symfony\Component\Console\Output\BufferedOutput;
  23. class ListCommandTest extends CommandTest {
  24. /**
  25. * @return ListCommand|\PHPUnit\Framework\MockObject\MockObject
  26. */
  27. private function getInstance() {
  28. /** @var GlobalStoragesService|\PHPUnit\Framework\MockObject\MockObject $globalService */
  29. $globalService = $this->createMock(GlobalStoragesService::class);
  30. /** @var UserStoragesService|\PHPUnit\Framework\MockObject\MockObject $userService */
  31. $userService = $this->createMock(UserStoragesService::class);
  32. /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
  33. $userManager = $this->createMock(IUserManager::class);
  34. /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
  35. $userSession = $this->createMock(IUserSession::class);
  36. return new ListCommand($globalService, $userService, $userSession, $userManager);
  37. }
  38. public function testListAuthIdentifier(): void {
  39. $l10n = $this->createMock(IL10N::class);
  40. $session = $this->createMock(ISession::class);
  41. $crypto = $this->createMock(ICrypto::class);
  42. $instance = $this->getInstance();
  43. $mount1 = new StorageConfig();
  44. $mount1->setAuthMechanism(new Password($l10n));
  45. $mount1->setBackend(new Local($l10n, new NullMechanism($l10n)));
  46. $mount2 = new StorageConfig();
  47. $credentialStore = $this->createMock(IStore::class);
  48. $mount2->setAuthMechanism(new SessionCredentials($l10n, $credentialStore));
  49. $mount2->setBackend(new Local($l10n, new NullMechanism($l10n)));
  50. $input = $this->getInput($instance, [], [
  51. 'output' => 'json'
  52. ]);
  53. $output = new BufferedOutput();
  54. $instance->listMounts('', [$mount1, $mount2], $input, $output);
  55. $output = json_decode($output->fetch(), true);
  56. $this->assertNotEquals($output[0]['authentication_type'], $output[1]['authentication_type']);
  57. }
  58. }