-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathRequestClassificationServiceTest.php
More file actions
57 lines (51 loc) · 1.28 KB
/
RequestClassificationServiceTest.php
File metadata and controls
57 lines (51 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
use OCA\UserOIDC\Service\RequestClassificationService;
use OCP\IRequest;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class RequestClassificationServiceTest extends TestCase {
#[DataProvider('topLevelHtmlNavigationProvider')]
public function testIsTopLevelHtmlNavigation(string $method, array $headers, bool $expected): void {
$request = $this->createMock(IRequest::class);
$request->method('getMethod')
->willReturn($method);
$request->method('getHeader')
->willReturnCallback(static function (string $name) use ($headers): string {
return $headers[$name] ?? '';
});
self::assertSame($expected, RequestClassificationService::isTopLevelHtmlNavigation($request));
}
public static function topLevelHtmlNavigationProvider(): array {
return [
'top level navigation' => [
'GET',
[],
true,
],
'xhr request' => [
'GET',
[
'X-Requested-With' => 'XMLHttpRequest',
],
false,
],
'ocs api request' => [
'GET',
[
'OCS-apirequest' => 'true',
],
false,
],
'non get request' => [
'POST',
[],
false,
],
];
}
}