Skip to content

Commit

Permalink
Merge pull request #121 from asilelik/master
Browse files Browse the repository at this point in the history
Allow wildcard in path
  • Loading branch information
jaytaph authored Apr 7, 2021
2 parents 3ddfa80 + 032a73a commit 15e5a87
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Tests/Util/PathLimitProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,37 @@ function itMatchesAstrixAsAnyMethod()
$this->assertEquals(array('*'), $result->getMethods());
}

/** @test */
function itMatchesAstrixAsAnyPath()
{
$plp = new PathLimitProcessor(array(
'api' => array(
'path' => '*',
'methods' => array('GET'),
'limit' => 100,
'period' => 60
)
));

$result = $plp->getRateLimit(Request::create('/api'));

$this->assertEquals(100, $result->getLimit());
$this->assertEquals(60, $result->getPeriod());
$this->assertEquals(array('GET'), $result->getMethods());

$result = $plp->getRateLimit(Request::create('/api/users'));

$this->assertEquals(100, $result->getLimit());
$this->assertEquals(60, $result->getPeriod());
$this->assertEquals(array('GET'), $result->getMethods());

$result = $plp->getRateLimit(Request::create('/api/users/emails'));

$this->assertEquals(100, $result->getLimit());
$this->assertEquals(60, $result->getPeriod());
$this->assertEquals(array('GET'), $result->getMethods());
}

/** @test */
function itMatchesWhenAccessSubPaths()
{
Expand Down
4 changes: 4 additions & 0 deletions Util/PathLimitProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ private function methodMatched(array $expectedMethods, $method)

private function pathMatched($expectedPath, $path)
{
if ($expectedPath === '*') {
return true;
}

$expectedParts = explode('/', $expectedPath);
$actualParts = explode('/', $path);

Expand Down

0 comments on commit 15e5a87

Please sign in to comment.