-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31932 from owncloud/revert-31927-stable10-fix-sla…
…ses-in-urlparams Revert "[stable10] generated resource routes should allow slashes"
- Loading branch information
Showing
2 changed files
with
3 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<?php | ||
/** | ||
* @author Jörn Friedrich Dreyer <[email protected]> | ||
* @author Thomas Müller <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2018, ownCloud GmbH | ||
|
@@ -25,41 +24,17 @@ | |
|
||
use OC\Route\Router; | ||
use OCP\ILogger; | ||
use Symfony\Component\Routing\Exception\ResourceNotFoundException; | ||
|
||
class LoadableRouter extends Router { | ||
/** | ||
* @param bool $loaded | ||
*/ | ||
public function setLoaded($loaded) { | ||
$this->loaded = $loaded; | ||
} | ||
} | ||
|
||
class RouterTest extends \Test\TestCase { | ||
|
||
/** @var ILogger */ | ||
private $l; | ||
|
||
/** | ||
* RouterTest constructor. | ||
* | ||
* @param string $name | ||
* @param array $data | ||
* @param string $dataName | ||
*/ | ||
public function __construct($name = null, array $data = [], $dataName = '') { | ||
parent::__construct($name, $data, $dataName); | ||
$this->l = $this->createMock(ILogger::class); | ||
} | ||
|
||
/** | ||
* @dataProvider providesWebRoot | ||
* @param $expectedBase | ||
* @param $webRoot | ||
*/ | ||
public function testWebRootSetup($expectedBase, $webRoot) { | ||
$router = new Router($this->l, $webRoot); | ||
$l = $this->createMock(ILogger::class); | ||
$router = new Router($l, $webRoot); | ||
|
||
$this->assertEquals($expectedBase, $router->getGenerator()->getContext()->getBaseUrl()); | ||
} | ||
|
@@ -72,51 +47,4 @@ public function providesWebRoot() { | |
['/oc/index.php', '/oc/'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider urlParamSlashProvider | ||
*/ | ||
public function testMatchURLParamContainingSlash($routeUrl, $slashesAllowed, $matchUrl, $expectedCalled) { | ||
$router = new LoadableRouter($this->l, ''); | ||
|
||
$called = false; | ||
|
||
$router->useCollection('root'); | ||
$route = $router->create('test', $routeUrl) | ||
->action(function () use (&$called) { | ||
$called = true; | ||
}); | ||
if ($slashesAllowed) { | ||
$route->requirements(['id' => '.+']); | ||
} | ||
|
||
// don't load any apps | ||
$router->setLoaded(true); | ||
|
||
try { | ||
$router->match($matchUrl); | ||
} catch (ResourceNotFoundException $e) { | ||
$called = false; | ||
} | ||
|
||
self::assertEquals($expectedCalled, $called); | ||
} | ||
|
||
public function urlParamSlashProvider() { | ||
return [ | ||
// slashed disallowed | ||
['/resource/{id}', false, '/resource/id%2Fwith%2Fslashes', false], | ||
['/resource/{id}/sub', false, '/resource/id%2Fwith%2Fslashes/sub', false], | ||
['/resource/{id}/sub', false, '/resource/id%2Fwith%2Fslashes/subx', false], | ||
['/resource/{id}', false, '/resource/id/with/slashes', false], | ||
['/resource/{id}/sub', false, '/resource/id/with/slashes/sub', false], | ||
|
||
// slashed allowed | ||
['/resource/{id}', true, '/resource/id%2Fwith%2Fslashes', true], | ||
['/resource/{id}/sub', true, '/resource/id%2Fwith%2Fslashes/sub', true], | ||
['/resource/{id}/sub', true, '/resource/id%2Fwith%2Fslashes/subx', false], | ||
['/resource/{id}', true, '/resource/id/with/slashes', true], | ||
['/resource/{id}/sub', true, '/resource/id/with/slashes/sub', true], | ||
]; | ||
} | ||
} |