-
Notifications
You must be signed in to change notification settings - Fork 9
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 #65 from dennis-koster/feature/extract-url-transfo…
…rmation-to-separate-methods Extracted the transformation of URL's for email verification and password resets to a separate method
- Loading branch information
Showing
6 changed files
with
91 additions
and
16 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 |
---|---|---|
|
@@ -26,6 +26,49 @@ protected function setUp(): void | |
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_transforms_a_verification_url(): void | ||
{ | ||
/** @var UserMustVerifyEmail $user */ | ||
$user = UserMustVerifyEmail::factory()->create([ | ||
'id' => 12345, | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$url = $this->service->transformUrl( | ||
$user, | ||
'https://mysite.com/verify-email/__ID__/__HASH__' | ||
); | ||
|
||
static::assertSame('https://mysite.com/verify-email/12345/' . sha1('[email protected]'), $url); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_transforms_a_signed_verification_url(): void | ||
{ | ||
Carbon::setTestNow(Carbon::createFromTimestamp(1609477200)); | ||
|
||
/** @var UserMustVerifyEmail $user */ | ||
$user = UserMustVerifyEmail::factory()->create([ | ||
'id' => 12345, | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$url = $this->service->transformUrl($user, 'https://mysite.com/verify-email/__ID__/__HASH__/__EXPIRES__/__SIGNATURE__'); | ||
|
||
$signature = hash_hmac('sha256', serialize([ | ||
'id' => 12345, | ||
'hash' => sha1('[email protected]'), | ||
'expires' => 1609480800, | ||
]), $this->app['config']->get('app.key')); | ||
|
||
static::assertSame('https://mysite.com/verify-email/12345/' . sha1('[email protected]') . '/1609480800/' . $signature, $url); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -30,6 +30,23 @@ protected function setUp(): void | |
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_transforms_a_reset_password_url(): void | ||
{ | ||
/** @var UserMustVerifyEmail $user */ | ||
$user = UserMustVerifyEmail::factory()->create([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$token = 'token123'; | ||
|
||
$url = $this->service->transformUrl($user, $token, 'https://mysite.com/reset-password/__EMAIL__/__TOKEN__'); | ||
|
||
static::assertSame('https://mysite.com/reset-password/[email protected]/token123', $url); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|