CredentialsManagerTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace Test\Security;
  9. use OCP\Security\ICredentialsManager;
  10. use OCP\Server;
  11. /**
  12. * @group DB
  13. */
  14. class CredentialsManagerTest extends \Test\TestCase {
  15. /**
  16. * @dataProvider credentialsProvider
  17. */
  18. public function testWithDB($userId, $identifier) {
  19. $credentialsManager = Server::get(ICredentialsManager::class);
  20. $secrets = 'Open Sesame';
  21. $credentialsManager->store($userId, $identifier, $secrets);
  22. $received = $credentialsManager->retrieve($userId, $identifier);
  23. $this->assertSame($secrets, $received);
  24. $removedRows = $credentialsManager->delete($userId, $identifier);
  25. $this->assertSame(1, $removedRows);
  26. }
  27. /**
  28. * @dataProvider credentialsProvider
  29. */
  30. public function testUpdate($userId, $identifier): void {
  31. $credentialsManager = Server::get(ICredentialsManager::class);
  32. $secrets = 'Open Sesame';
  33. $secretsRev = strrev($secrets);
  34. $credentialsManager->store($userId, $identifier, $secrets);
  35. $credentialsManager->store($userId, $identifier, $secretsRev);
  36. $received = $credentialsManager->retrieve($userId, $identifier);
  37. $this->assertSame($secretsRev, $received);
  38. }
  39. public function credentialsProvider(): array {
  40. return [
  41. [
  42. 'alice',
  43. 'privateCredentials'
  44. ],
  45. [
  46. '',
  47. 'systemCredentials',
  48. ],
  49. ];
  50. }
  51. }