-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathDiscoveryServiceTest.php
More file actions
124 lines (114 loc) · 3.95 KB
/
DiscoveryServiceTest.php
File metadata and controls
124 lines (114 loc) · 3.95 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
use OCA\UserOIDC\Service\DiscoveryService;
use OCA\UserOIDC\Service\NetworkService;
use OCA\UserOIDC\Service\ProviderService;
use OCP\ICacheFactory;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class DiscoveryServiceTest extends TestCase {
/**
* @var MockObject|LoggerInterface
*/
private $logger;
/**
* @var NetworkService|MockObject
*/
private $networkService;
/**
* @var ProviderService|MockObject
*/
private $providerService;
/**
* @var ICacheFactory|MockObject
*/
private $cacheFactory;
/**
* @var DiscoveryService
*/
private $discoveryService;
public function setUp(): void {
parent::setUp();
$this->logger = $this->createMock(LoggerInterface::class);
$this->networkService = $this->createMock(NetworkService::class);
$this->providerService = $this->createMock(ProviderService::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->discoveryService = new DiscoveryService($this->logger, $this->networkService, $this->providerService, $this->cacheFactory);
}
public function testBuildAuthorizationUrl() {
$xss1 = '\'"http-equiv=><svg/onload=alert(1)>';
$cleanedXss1 = ''"http-equiv=><svg/onload=alert(1)>';
$cleanAuthorizationEndpoint = 'https://test.org:9999/path1/path2';
$stringQueryParams = 'param1=value1¶m2=value2';
$extraParams = [
'extraParam1' => 'extraValue1',
'extraParam2' => 'extraValue2',
];
$stringExtraParams = 'extraParam1=extraValue1&extraParam2=extraValue2';
$extraParamsWithXssValue = [
'extraParam1' => $xss1,
];
$extraParamsWithXssKey = [
$xss1 => 'extraValue1',
];
$testValues = [
[
'authorization_endpoint' => $cleanAuthorizationEndpoint,
'extra_params' => [],
'expected_result' => $cleanAuthorizationEndpoint,
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint . $xss1,
'extra_params' => [],
'expected_result' => $cleanAuthorizationEndpoint . $cleanedXss1,
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint . '?' . $stringQueryParams,
'extra_params' => [],
'expected_result' => $cleanAuthorizationEndpoint . '?' . $stringQueryParams,
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint,
'extra_params' => $extraParams,
'expected_result' => $cleanAuthorizationEndpoint . '?' . $stringExtraParams,
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint . '?' . $stringQueryParams,
'extra_params' => $extraParams,
'expected_result' => $cleanAuthorizationEndpoint . '?' . $stringExtraParams . '&' . $stringQueryParams,
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint,
'extra_params' => $extraParamsWithXssKey,
'expected_result' => $cleanAuthorizationEndpoint . '?' . urlencode($xss1) . '=extraValue1',
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint,
'extra_params' => $extraParamsWithXssValue,
'expected_result' => $cleanAuthorizationEndpoint . '?extraParam1=' . urlencode($xss1),
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint . '?' . $stringQueryParams,
'extra_params' => $extraParamsWithXssKey,
'expected_result' => $cleanAuthorizationEndpoint . '?' . urlencode($xss1) . '=extraValue1' . '&' . $stringQueryParams,
],
[
'authorization_endpoint' => $cleanAuthorizationEndpoint . '?' . $stringQueryParams,
'extra_params' => $extraParamsWithXssValue,
'expected_result' => $cleanAuthorizationEndpoint . '?' . 'extraParam1=' . urlencode($xss1) . '&' . $stringQueryParams,
],
];
foreach ($testValues as $test) {
Assert::assertEquals(
$test['expected_result'],
$this->discoveryService->buildAuthorizationUrl($test['authorization_endpoint'], $test['extra_params'])
);
}
}
}