2015-12-10 10:57:46 -05:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
declare(strict_types=1);
|
2015-12-10 10:57:46 -05:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-12-10 10:57:46 -05:00
|
|
|
*/
|
2016-05-25 10:04:15 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\DAV;
|
2015-12-10 10:57:46 -05:00
|
|
|
|
|
|
|
|
use OCA\DAV\DAV\SystemPrincipalBackend;
|
2025-05-27 17:36:08 -04:00
|
|
|
use Sabre\DAV\Exception;
|
2015-12-10 10:57:46 -05:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class SystemPrincipalBackendTest extends TestCase {
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providesPrefix')]
|
2025-05-27 17:36:08 -04:00
|
|
|
public function testGetPrincipalsByPrefix(array $expected, string $prefix): void {
|
2015-12-10 10:57:46 -05:00
|
|
|
$backend = new SystemPrincipalBackend();
|
|
|
|
|
$result = $backend->getPrincipalsByPrefix($prefix);
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
public static function providesPrefix(): array {
|
2015-12-10 10:57:46 -05:00
|
|
|
return [
|
|
|
|
|
[[], ''],
|
|
|
|
|
[[[
|
|
|
|
|
'uri' => 'principals/system/system',
|
|
|
|
|
'{DAV:}displayname' => 'system',
|
2016-07-12 10:35:27 -04:00
|
|
|
],
|
2020-04-09 03:22:29 -04:00
|
|
|
[
|
|
|
|
|
'uri' => 'principals/system/public',
|
|
|
|
|
'{DAV:}displayname' => 'public',
|
|
|
|
|
]
|
2016-07-12 10:35:27 -04:00
|
|
|
], 'principals/system'],
|
2015-12-10 10:57:46 -05:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providesPath')]
|
2025-05-27 17:36:08 -04:00
|
|
|
public function testGetPrincipalByPath(?array $expected, string $path): void {
|
2015-12-10 10:57:46 -05:00
|
|
|
$backend = new SystemPrincipalBackend();
|
|
|
|
|
$result = $backend->getPrincipalByPath($path);
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
public static function providesPath(): array {
|
2015-12-10 10:57:46 -05:00
|
|
|
return [
|
|
|
|
|
[null, ''],
|
|
|
|
|
[null, 'principals'],
|
|
|
|
|
[null, 'principals/system'],
|
|
|
|
|
[[
|
|
|
|
|
'uri' => 'principals/system/system',
|
|
|
|
|
'{DAV:}displayname' => 'system',
|
|
|
|
|
], 'principals/system/system'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providesPrincipalForGetGroupMemberSet')]
|
2025-05-27 17:36:08 -04:00
|
|
|
public function testGetGroupMemberSetExceptional(?string $principal): void {
|
|
|
|
|
$this->expectException(Exception::class);
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectExceptionMessage('Principal not found');
|
|
|
|
|
|
2015-12-10 10:57:46 -05:00
|
|
|
$backend = new SystemPrincipalBackend();
|
|
|
|
|
$backend->getGroupMemberSet($principal);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
public static function providesPrincipalForGetGroupMemberSet(): array {
|
2015-12-10 10:57:46 -05:00
|
|
|
return [
|
|
|
|
|
[null],
|
|
|
|
|
['principals/system'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetGroupMemberSet(): void {
|
2015-12-10 10:57:46 -05:00
|
|
|
$backend = new SystemPrincipalBackend();
|
|
|
|
|
$result = $backend->getGroupMemberSet('principals/system/system');
|
|
|
|
|
$this->assertEquals(['principals/system/system'], $result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-30 10:56:59 -04:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providesPrincipalForGetGroupMembership')]
|
2025-05-27 17:36:08 -04:00
|
|
|
public function testGetGroupMembershipExceptional(string $principal): void {
|
|
|
|
|
$this->expectException(Exception::class);
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectExceptionMessage('Principal not found');
|
|
|
|
|
|
2015-12-10 10:57:46 -05:00
|
|
|
$backend = new SystemPrincipalBackend();
|
|
|
|
|
$backend->getGroupMembership($principal);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-27 17:36:08 -04:00
|
|
|
public static function providesPrincipalForGetGroupMembership(): array {
|
2015-12-10 10:57:46 -05:00
|
|
|
return [
|
2020-04-09 03:22:29 -04:00
|
|
|
['principals/system/a'],
|
2015-12-10 10:57:46 -05:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testGetGroupMembership(): void {
|
2015-12-10 10:57:46 -05:00
|
|
|
$backend = new SystemPrincipalBackend();
|
|
|
|
|
$result = $backend->getGroupMembership('principals/system/system');
|
|
|
|
|
$this->assertEquals([], $result);
|
|
|
|
|
}
|
|
|
|
|
}
|