get(route('password.request')); $response->assertOk(); }); test('reset password link can be requested', function () { Notification::fake(); $user = User::factory()->create(); $this->post(route('password.request'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class); }); test('the reset link points at APP_URL, whatever host the request claims', function () { Notification::fake(); config(['app.url' => 'https://share.example.com']); $user = User::factory()->create(); $this->withHeader('X-Forwarded-Host', 'attacker.example') ->post(route('password.request'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class, function (ResetPassword $notification) use ($user) { return str_starts_with($notification->toMail($user)->actionUrl, 'https://share.example.com/reset-password/'); }); }); test('reset password screen can be rendered', function () { Notification::fake(); $user = User::factory()->create(); $this->post(route('password.request'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class, function ($notification) { $response = $this->get(route('password.reset', $notification->token)); $response->assertOk(); return true; }); }); test('password can be reset with valid token', function () { Notification::fake(); $user = User::factory()->create(); $this->post(route('password.request'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { $response = $this->post(route('password.update'), [ 'token' => $notification->token, 'email' => $user->email, 'password' => 'password', 'password_confirmation' => 'password', ]); $response ->assertSessionHasNoErrors() ->assertRedirect(route('login', absolute: false)); return true; }); }); test('reset password mail wears the material theme in the app scheme', function () { $user = User::factory()->create(); $scheme = json_decode(file_get_contents(resource_path('css/material-scheme.json')), true); $html = (string) (new ResetPassword('token'))->toMail($user)->render(); expect($html) ->toContain('background-color: '.$scheme['light']['primary']) ->toContain(route('password.reset', ['token' => 'token', 'email' => $user->email])); });