Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/oauthserver/__tests__/PhabricatorOAuthServerTestCase.php
12241 views
1
<?php
2
3
final class PhabricatorOAuthServerTestCase
4
extends PhabricatorTestCase {
5
6
public function testValidateRedirectURI() {
7
static $map = array(
8
'http://www.google.com' => true,
9
'http://www.google.com/' => true,
10
'http://www.google.com/auth' => true,
11
'www.google.com' => false,
12
'http://www.google.com/auth#invalid' => false,
13
);
14
$server = new PhabricatorOAuthServer();
15
foreach ($map as $input => $expected) {
16
$uri = new PhutilURI($input);
17
$result = $server->validateRedirectURI($uri);
18
$this->assertEqual(
19
$expected,
20
$result,
21
pht("Validation of redirect URI '%s'", $input));
22
}
23
}
24
25
public function testValidateSecondaryRedirectURI() {
26
$server = new PhabricatorOAuthServer();
27
$primary_uri = new PhutilURI('http://www.google.com/');
28
static $test_domain_map = array(
29
'http://www.google.com' => false,
30
'http://www.google.com/' => true,
31
'http://www.google.com/auth' => false,
32
'http://www.google.com/?auth' => true,
33
'www.google.com' => false,
34
'http://www.google.com/auth#invalid' => false,
35
'http://www.example.com' => false,
36
);
37
foreach ($test_domain_map as $input => $expected) {
38
$uri = new PhutilURI($input);
39
$this->assertEqual(
40
$expected,
41
$server->validateSecondaryRedirectURI($uri, $primary_uri),
42
pht(
43
"Validation of redirect URI '%s' relative to '%s'",
44
$input,
45
$primary_uri));
46
}
47
48
$primary_uri = new PhutilURI('http://www.google.com/?auth');
49
static $test_query_map = array(
50
'http://www.google.com' => false,
51
'http://www.google.com/' => false,
52
'http://www.google.com/auth' => false,
53
'http://www.google.com/?auth' => true,
54
'http://www.google.com/?auth&stuff' => true,
55
'http://www.google.com/?stuff' => false,
56
);
57
foreach ($test_query_map as $input => $expected) {
58
$uri = new PhutilURI($input);
59
$this->assertEqual(
60
$expected,
61
$server->validateSecondaryRedirectURI($uri, $primary_uri),
62
pht(
63
"Validation of secondary redirect URI '%s' relative to '%s'",
64
$input,
65
$primary_uri));
66
}
67
68
$primary_uri = new PhutilURI('https://secure.example.com/');
69
$tests = array(
70
'https://secure.example.com/' => true,
71
'http://secure.example.com/' => false,
72
);
73
foreach ($tests as $input => $expected) {
74
$uri = new PhutilURI($input);
75
$this->assertEqual(
76
$expected,
77
$server->validateSecondaryRedirectURI($uri, $primary_uri),
78
pht('Validation (https): %s', $input));
79
}
80
81
$primary_uri = new PhutilURI('http://example.com/?z=2&y=3');
82
$tests = array(
83
'http://example.com/?z=2&y=3' => true,
84
'http://example.com/?y=3&z=2' => true,
85
'http://example.com/?y=3&z=2&x=1' => true,
86
'http://example.com/?y=2&z=3' => false,
87
'http://example.com/?y&x' => false,
88
'http://example.com/?z=2&x=3' => false,
89
);
90
foreach ($tests as $input => $expected) {
91
$uri = new PhutilURI($input);
92
$this->assertEqual(
93
$expected,
94
$server->validateSecondaryRedirectURI($uri, $primary_uri),
95
pht('Validation (params): %s', $input));
96
}
97
98
}
99
100
}
101
102