diff --git a/.github/actions/common/setup b/.github/actions/common/setup index aa1c67b..dbbbafe 100644 --- a/.github/actions/common/setup +++ b/.github/actions/common/setup @@ -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 diff --git a/README.md b/README.md index 23446f7..d7a7e88 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/composer.json b/composer.json index 9f83ce5..5dc1375 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "laravel/framework": "~5.8" + "laravel/framework": "^6.0" }, "extra": { "laravel": { diff --git a/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php b/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php index 581285d..a266c31 100644 --- a/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php +++ b/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php @@ -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() @@ -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()); } @@ -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()); @@ -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); } @@ -130,7 +136,7 @@ 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); @@ -138,7 +144,7 @@ public function testUserCanVerifyThemselves() public function testGuestCannotResendAVerificationEmail() { - $response = $this->get($this->verificationResendRoute()); + $response = $this->post($this->verificationResendRoute()); $response->assertRedirect($this->loginRoute()); } @@ -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()); } @@ -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());