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