0
0
mirror of https://github.com/nextcloud/server.git synced 2024-12-29 00:18:42 +00:00
nextcloud_server/tests/lib/Security/CredentialsManagerTest.php
Christoph Wurst 49dd79eabb
refactor: Add void return type to PHPUnit test methods
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
2024-09-15 22:32:31 +02:00

66 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Security;
use OCP\Security\ICredentialsManager;
use OCP\Server;
/**
* @group DB
*/
class CredentialsManagerTest extends \Test\TestCase {
/**
* @dataProvider credentialsProvider
*/
public function testWithDB($userId, $identifier): void {
$credentialsManager = Server::get(ICredentialsManager::class);
$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);
}
/**
* @dataProvider credentialsProvider
*/
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);
}
public function credentialsProvider(): array {
return [
[
'alice',
'privateCredentials'
],
[
'',
'systemCredentials',
],
];
}
}