Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / oauthserver / __tests__ / PhabricatorOAuthServerTestCase.php
blob2fa1778f510bf9d84a1e9db64acdeaaa0e935130
1 <?php
3 final class PhabricatorOAuthServerTestCase
4 extends PhabricatorTestCase {
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,
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));
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,
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));
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,
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));
68 $primary_uri = new PhutilURI('https://secure.example.com/');
69 $tests = array(
70 'https://secure.example.com/' => true,
71 'http://secure.example.com/' => false,
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));
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,
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));