-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLA-1700] Add API generic rate limit (#144)
- Loading branch information
1 parent
cf0b5e7
commit cf8c231
Showing
4 changed files
with
77 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Enjin\Platform\Tests\Feature\GraphQL\Mutations; | ||
|
||
use Enjin\Platform\Models\Collection; | ||
use Enjin\Platform\Tests\Feature\GraphQL\TestCaseGraphQL; | ||
use Enjin\Platform\Tests\Feature\GraphQL\Traits\HasHttp; | ||
use Illuminate\Support\Arr; | ||
|
||
class RateLimit extends TestCaseGraphQL | ||
{ | ||
use HasHttp; | ||
|
||
public function test_it_can_rate_limit(): void | ||
{ | ||
config()->set('enjin-platform.rate_limit.attempts', 1); | ||
Collection::factory()->create(); | ||
$this->json( | ||
'POST', | ||
'/graphql', | ||
['query' => static::$queries['GetCollections']], | ||
); | ||
$response = $this->json( | ||
'POST', | ||
'/graphql', | ||
['query' => static::$queries['GetCollections']], | ||
); | ||
$result = $response->getData(true); | ||
$this->assertStringContainsString('Too Many Attempts.', Arr::get($result, 'message')); | ||
} | ||
|
||
public function test_it_will_not_rate_limit(): void | ||
{ | ||
config()->set('enjin-platform.rate_limit.attempts', 1); | ||
config()->set('enjin-platform.rate_limit.enabled', false); | ||
Collection::factory()->create(); | ||
$response = $this->json( | ||
'POST', | ||
'/graphql', | ||
['query' => static::$queries['GetCollections']], | ||
); | ||
$result = $response->getData(true); | ||
$this->assertNotEmpty(Arr::get($result, 'data.GetCollections.edges')); | ||
$response = $this->json( | ||
'POST', | ||
'/graphql', | ||
['query' => static::$queries['GetCollections']], | ||
); | ||
$result = $response->getData(true); | ||
$this->assertNotEmpty(Arr::get($result, 'data.GetCollections.edges')); | ||
} | ||
} |