2015-08-24 11:13:16 -04:00
|
|
|
<?php
|
2021-04-19 09:50:30 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2015-08-24 11:13:16 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-08-24 11:13:16 -04:00
|
|
|
*/
|
|
|
|
|
|
2016-05-19 03:02:58 -04:00
|
|
|
namespace Test\Security;
|
|
|
|
|
|
2023-03-31 09:29:26 -04:00
|
|
|
use OCP\Security\ICredentialsManager;
|
|
|
|
|
use OCP\Server;
|
|
|
|
|
|
2025-10-20 19:52:40 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\Group('DB')]
|
2015-08-24 11:13:16 -04:00
|
|
|
class CredentialsManagerTest extends \Test\TestCase {
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('credentialsProvider')]
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testWithDB($userId, $identifier): void {
|
2023-03-31 09:29:26 -04:00
|
|
|
$credentialsManager = Server::get(ICredentialsManager::class);
|
2020-04-15 10:44:28 -04:00
|
|
|
|
|
|
|
|
$secrets = 'Open Sesame';
|
|
|
|
|
|
|
|
|
|
$credentialsManager->store($userId, $identifier, $secrets);
|
|
|
|
|
$received = $credentialsManager->retrieve($userId, $identifier);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($secrets, $received);
|
|
|
|
|
|
|
|
|
|
$removedRows = $credentialsManager->delete($userId, $identifier);
|
|
|
|
|
$this->assertSame(1, $removedRows);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('credentialsProvider')]
|
2023-03-31 09:29:26 -04:00
|
|
|
public function testUpdate($userId, $identifier): void {
|
|
|
|
|
$credentialsManager = Server::get(ICredentialsManager::class);
|
|
|
|
|
|
|
|
|
|
$secrets = 'Open Sesame';
|
|
|
|
|
$secretsRev = strrev($secrets);
|
|
|
|
|
|
|
|
|
|
$credentialsManager->store($userId, $identifier, $secrets);
|
|
|
|
|
$credentialsManager->store($userId, $identifier, $secretsRev);
|
|
|
|
|
$received = $credentialsManager->retrieve($userId, $identifier);
|
|
|
|
|
|
|
|
|
|
$this->assertSame($secretsRev, $received);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-13 02:49:30 -04:00
|
|
|
public static function credentialsProvider(): array {
|
2020-04-15 10:44:28 -04:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'alice',
|
|
|
|
|
'privateCredentials'
|
|
|
|
|
],
|
|
|
|
|
[
|
2020-04-15 13:34:23 -04:00
|
|
|
'',
|
|
|
|
|
'systemCredentials',
|
|
|
|
|
],
|
2020-04-15 10:44:28 -04:00
|
|
|
];
|
|
|
|
|
}
|
2015-08-24 11:13:16 -04:00
|
|
|
}
|