Skip to content

Commit

Permalink
Laravel 6.0 compatibility (#29)
Browse files Browse the repository at this point in the history
* EmailVerification Updated to Hash
* Bump required Laravel version
* Use POST requests for verification resend route
* Pass entire user object into validVerificationVerifyRoute and invalidVerificationVerifyRoute method
* Change make:auth command to laravel/ui
* Fix missing --auth flag in ui preset setup
* Force version 6.0 of Laravel
* Update readme with new frontend preset
  • Loading branch information
DCzajkowski authored Sep 7, 2019
1 parent bb75abf commit 2df9b1f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
7 changes: 4 additions & 3 deletions .github/actions/common/setup
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ commit="tmp-$(git rev-parse --verify HEAD)"
git checkout -b $commit

# Create Laravel project
composer create-project --prefer-dist laravel/laravel test-app
composer create-project --prefer-dist laravel/laravel test-app 6.0
cd test-app

# Scaffold Authentication
php artisan make:auth
# Require Laravel auth preset and setup views
composer require laravel/ui
php artisan ui vue --auth

# Require the package
composer config repositories.dczajkowski/auth-tests vcs $GITHUB_WORKSPACE
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ The version of this package reflects current major version of the Laravel framew
If Laravel framework has version 5.6, version of this package compatible will be `5.6.*`.

## Installation
> Before installation please make sure you have scaffolded
> frontend views with a `--auth` flag e.g.
> ```bash
> composer require laravel/ui && php artisan ui vue --auth
> ```
```bash
composer require dczajkowski/auth-tests --dev
php artisan make:auth # if not ran previously
php artisan make:auth-tests --without-email-verification
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"laravel/framework": "~5.8"
"laravel/framework": "^6.0"
},
"extra": {
"laravel": {
Expand Down
34 changes: 20 additions & 14 deletions src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ protected function verificationNoticeRoute()
return route('verification.notice');
}

protected function validVerificationVerifyRoute($id)
protected function validVerificationVerifyRoute($user)
{
return URL::signedRoute($this->verificationVerifyRouteName, ['id' => $id]);
return URL::signedRoute($this->verificationVerifyRouteName, [
'id' => $user->id,
'hash' => sha1($user->getEmailForVerification()),
]);
}

protected function invalidVerificationVerifyRoute($id)
protected function invalidVerificationVerifyRoute($user)
{
return route($this->verificationVerifyRouteName, ['id' => $id]) . '?signature=invalid-signature';
return route($this->verificationVerifyRouteName, [
'id' => $user->id,
'hash' => 'invalid-hash',
]);
}

protected function verificationResendRoute()
Expand Down Expand Up @@ -77,12 +83,12 @@ public function testVerifiedUserIsRedirectedHomeWhenVisitingVerificationNoticeRo

public function testGuestCannotSeeTheVerificationVerifyRoute()
{
factory(User::class)->create([
$user = factory(User::class)->create([
'id' => 1,
'email_verified_at' => null,
]);

$response = $this->get($this->validVerificationVerifyRoute(1));
$response = $this->get($this->validVerificationVerifyRoute($user));

$response->assertRedirect($this->loginRoute());
}
Expand All @@ -96,7 +102,7 @@ public function testUserCannotVerifyOthers()

$user2 = factory(User::class)->create(['id' => 2, 'email_verified_at' => null]);

$response = $this->actingAs($user)->get($this->validVerificationVerifyRoute(2));
$response = $this->actingAs($user)->get($this->validVerificationVerifyRoute($user2));

$response->assertForbidden();
$this->assertFalse($user2->fresh()->hasVerifiedEmail());
Expand All @@ -108,18 +114,18 @@ public function testUserIsRedirectedToCorrectRouteWhenAlreadyVerified()
'email_verified_at' => now(),
]);

$response = $this->actingAs($user)->get($this->validVerificationVerifyRoute($user->id));
$response = $this->actingAs($user)->get($this->validVerificationVerifyRoute($user));

$response->assertRedirect($this->successfulVerificationRoute());
}

public function testForbiddenIsReturnedWhenSignatureIsInvalidInVerificationVerfyRoute()
public function testForbiddenIsReturnedWhenSignatureIsInvalidInVerificationVerifyRoute()
{
$user = factory(User::class)->create([
'email_verified_at' => now(),
]);

$response = $this->actingAs($user)->get($this->invalidVerificationVerifyRoute($user->id));
$response = $this->actingAs($user)->get($this->invalidVerificationVerifyRoute($user));

$response->assertStatus(403);
}
Expand All @@ -130,15 +136,15 @@ public function testUserCanVerifyThemselves()
'email_verified_at' => null,
]);

$response = $this->actingAs($user)->get($this->validVerificationVerifyRoute($user->id));
$response = $this->actingAs($user)->get($this->validVerificationVerifyRoute($user));

$response->assertRedirect($this->successfulVerificationRoute());
$this->assertNotNull($user->fresh()->email_verified_at);
}

public function testGuestCannotResendAVerificationEmail()
{
$response = $this->get($this->verificationResendRoute());
$response = $this->post($this->verificationResendRoute());

$response->assertRedirect($this->loginRoute());
}
Expand All @@ -149,7 +155,7 @@ public function testUserIsRedirectedToCorrectRouteIfAlreadyVerified()
'email_verified_at' => now(),
]);

$response = $this->actingAs($user)->get($this->verificationResendRoute());
$response = $this->actingAs($user)->post($this->verificationResendRoute());

$response->assertRedirect($this->successfulVerificationRoute());
}
Expand All @@ -163,7 +169,7 @@ public function testUserCanResendAVerificationEmail()

$response = $this->actingAs($user)
->from($this->verificationNoticeRoute())
->get($this->verificationResendRoute());
->post($this->verificationResendRoute());

Notification::assertSentTo($user, VerifyEmail::class);
$response->assertRedirect($this->verificationNoticeRoute());
Expand Down

0 comments on commit 2df9b1f

Please sign in to comment.