From ca2723904c937f7af233102992e958bff3bac38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9Frul=20Topuz?= Date: Sun, 4 Apr 2021 17:18:14 +0300 Subject: [PATCH 1/2] expose false route option test --- .../Extractor/ExposedRoutesExtractorTest.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/Extractor/ExposedRoutesExtractorTest.php b/Tests/Extractor/ExposedRoutesExtractorTest.php index 7078bcb0..06b270d8 100644 --- a/Tests/Extractor/ExposedRoutesExtractorTest.php +++ b/Tests/Extractor/ExposedRoutesExtractorTest.php @@ -140,6 +140,33 @@ public function testGetHostOverHttps($host, $httpsPort, $expected) $this->assertEquals($expected, $extractor->getHost()); } + public function testExposeFalse() + { + $expected = new RouteCollection(); + $expected->add('user_public_1', new Route('/user/public/1')); + $expected->add('user_public_2', new Route('/user/public/2', [], [], ['expose' => true])); + $expected->add('user_public_3', new Route('/user/public/3', [], [], ['expose' => 'true'])); + $expected->add('user_public_4', new Route('/user/public/4', [], [], ['expose' => 'default'])); + $expected->add('user_public_5', new Route('/user/public/5', [], [], ['expose' => 'group_name'])); + $expected->add('user_secret_1', new Route('/user/secret/1', [], [], ['expose' => false])); + $expected->add('user_secret_2', new Route('/user/secret/2', [], [], ['expose' => 'false'])); + + $router = $this->getRouter($expected); + $extractor = new ExposedRoutesExtractor($router, array('user_.+'), $this->cacheDir, []); + + $this->assertCount(5, $extractor->getRoutes()); + + foreach ($expected->all() as $name => $route) { + + if (in_array($name, ['user_secret_1', 'user_secret_2'])) { + $this->assertFalse($extractor->isRouteExposed($route, $name)); + } else { + $this->assertTrue($extractor->isRouteExposed($route, $name)); + } + + } + } + /** * @return array */ From 6b29b97f96c7453cd2ffcb5f32e34df208e7097a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9Frul=20Topuz?= Date: Sun, 4 Apr 2021 18:39:47 +0300 Subject: [PATCH 2/2] route expose false option --- Extractor/ExposedRoutesExtractor.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Extractor/ExposedRoutesExtractor.php b/Extractor/ExposedRoutesExtractor.php index b6dfeaa6..90faf8c9 100644 --- a/Extractor/ExposedRoutesExtractor.php +++ b/Extractor/ExposedRoutesExtractor.php @@ -83,7 +83,12 @@ public function getRoutes() foreach ($collection->all() as $name => $route) { if ($route->hasOption('expose')) { - $routes->add($name, $route); + + $expose = $route->getOption('expose'); + + if ($expose !== false && $expose !== 'false') { + $routes->add($name, $route); + } continue; } @@ -196,8 +201,12 @@ public function getResources() */ public function isRouteExposed(Route $route, $name) { - return true === $route->hasOption('expose') || - ('' !== $this->pattern && preg_match('#^' . $this->pattern . '$#', $name)); + if (false === $route->hasOption('expose')) { + return ('' !== $this->pattern && preg_match('#^' . $this->pattern . '$#', $name)); + } + + $status = $route->getOption('expose'); + return ($status !== false && $status !== 'false'); } protected function getDomainByRouteMatches($matches, $name)