-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add rate limit * add none to disable rate limit * add env MAGICLINK_RATE_LIMIT * add docs
- Loading branch information
Showing
7 changed files
with
146 additions
and
37 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
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,38 @@ | ||
<?php | ||
|
||
namespace MagicLink\Test\Http; | ||
|
||
use MagicLink\Actions\ResponseAction; | ||
use MagicLink\MagicLink; | ||
use MagicLink\Test\TestCase; | ||
|
||
class HttpHeadTest extends TestCase | ||
{ | ||
public function test_http_head_request_has_not_effects() | ||
{ | ||
$magiclink = MagicLink::create(new ResponseAction(function () { | ||
return 'private content'; | ||
})); | ||
|
||
$magiclink->num_visits = 4; | ||
$magiclink->save(); | ||
|
||
$this->head($magiclink->url) | ||
->assertStatus(200) | ||
->assertDontSeeText('private content'); | ||
|
||
$magiclink->refresh(); | ||
|
||
$this->assertEquals(4, $magiclink->num_visits); | ||
} | ||
|
||
public function test_http_head_request_without_valid_magiclink() | ||
{ | ||
$magiclink = MagicLink::create(new ResponseAction(function () { | ||
return 'private content'; | ||
})); | ||
|
||
$this->head($magiclink->url . '-bad') | ||
->assertStatus(404); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace MagicLink\Test\Http; | ||
|
||
use MagicLink\Actions\ResponseAction; | ||
use MagicLink\MagicLink; | ||
use MagicLink\MagicLinkServiceProvider; | ||
use MagicLink\Test\TestCase; | ||
|
||
class HttpThrottleTest extends TestCase | ||
{ | ||
public function test_http_failed_when_rate_limit_is_exceeded() | ||
{ | ||
config(['magiclink.rate_limit' => 1]); | ||
(new MagicLinkServiceProvider($this->app))->boot(); | ||
|
||
$magiclink = MagicLink::create(new ResponseAction(function () { | ||
return 'private content'; | ||
})); | ||
|
||
$this->get($magiclink->url) | ||
->assertStatus(200); | ||
|
||
$this->get($magiclink->url) | ||
|
||
->assertStatus(429); | ||
} | ||
public function test_http_when_rate_limit_is_none() | ||
{ | ||
config(['magiclink.rate_limit' => 'none']); | ||
(new MagicLinkServiceProvider($this->app))->boot(); | ||
|
||
$magiclink = MagicLink::create(new ResponseAction(function () { | ||
return 'private content'; | ||
})); | ||
|
||
$this->get($magiclink->url) | ||
->assertStatus(200); | ||
|
||
$this->get($magiclink->url) | ||
->assertStatus(200); | ||
} | ||
|
||
} |