[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/oauthserver/__tests__/ -> PhabricatorOAuthServerTestCase.php (source)

   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          "Validation of redirect URI '{$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'               => true,
  30        'http://www.google.com/'              => true,
  31        'http://www.google.com/auth'          => true,
  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          "Validation of redirect URI '{$input}' ".
  43          "relative to '{$primary_uri}'");
  44      }
  45  
  46      $primary_uri = new PhutilURI('http://www.google.com/?auth');
  47      static $test_query_map = array(
  48        'http://www.google.com'               => false,
  49        'http://www.google.com/'              => false,
  50        'http://www.google.com/auth'          => false,
  51        'http://www.google.com/?auth'         => true,
  52        'http://www.google.com/?auth&stuff'   => true,
  53        'http://www.google.com/?stuff'        => false,
  54      );
  55      foreach ($test_query_map as $input => $expected) {
  56        $uri = new PhutilURI($input);
  57        $this->assertEqual(
  58          $expected,
  59          $server->validateSecondaryRedirectURI($uri, $primary_uri),
  60          "Validation of secondary redirect URI '{$input}' ".
  61          "relative to '{$primary_uri}'");
  62      }
  63  
  64      $primary_uri = new PhutilURI('https://secure.example.com/');
  65      $tests = array(
  66        'https://secure.example.com/' => true,
  67        'http://secure.example.com/'  => false,
  68      );
  69      foreach ($tests as $input => $expected) {
  70        $uri = new PhutilURI($input);
  71        $this->assertEqual(
  72          $expected,
  73          $server->validateSecondaryRedirectURI($uri, $primary_uri),
  74          "Validation (https): {$input}");
  75      }
  76  
  77      $primary_uri = new PhutilURI('http://example.com/?z=2&y=3');
  78      $tests = array(
  79        'http://example.com?z=2&y=3'      => true,
  80        'http://example.com?y=3&z=2'      => true,
  81        'http://example.com?y=3&z=2&x=1'  => true,
  82        'http://example.com?y=2&z=3'      => false,
  83        'http://example.com?y&x'          => false,
  84        'http://example.com?z=2&x=3'      => false,
  85      );
  86      foreach ($tests as $input => $expected) {
  87        $uri = new PhutilURI($input);
  88        $this->assertEqual(
  89          $expected,
  90          $server->validateSecondaryRedirectURI($uri, $primary_uri),
  91          "Validation (params): {$input}");
  92      }
  93  
  94    }
  95  
  96  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1