Skip to content

Commit 3c0bbaa

Browse files
committed
Merge branch 'main' into feat/two-factor-auth
# Conflicts: # tests/Feature/Auth/AuthenticationTest.php # tests/Feature/Auth/PasswordResetTest.php
2 parents 048876e + 98e83b9 commit 3c0bbaa

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

config/database.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@
158158
'password' => env('REDIS_PASSWORD'),
159159
'port' => env('REDIS_PORT', '6379'),
160160
'database' => env('REDIS_DB', '0'),
161+
'max_retries' => env('REDIS_MAX_RETRIES', 3),
162+
'backoff_algorithm' => env('REDIS_BACKOFF_ALGORITHM', 'decorrelated_jitter'),
163+
'backoff_base' => env('REDIS_BACKOFF_BASE', 100),
164+
'backoff_cap' => env('REDIS_BACKOFF_CAP', 1000),
161165
],
162166

163167
'cache' => [
@@ -167,6 +171,10 @@
167171
'password' => env('REDIS_PASSWORD'),
168172
'port' => env('REDIS_PORT', '6379'),
169173
'database' => env('REDIS_CACHE_DB', '1'),
174+
'max_retries' => env('REDIS_MAX_RETRIES', 3),
175+
'backoff_algorithm' => env('REDIS_BACKOFF_ALGORITHM', 'decorrelated_jitter'),
176+
'backoff_base' => env('REDIS_BACKOFF_BASE', 100),
177+
'backoff_cap' => env('REDIS_BACKOFF_CAP', 1000),
170178
],
171179

172180
],

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Illuminate\Support\Facades\RateLimiter;
78
use Laravel\Fortify\Features;
89
use Tests\TestCase;
910

@@ -100,14 +101,7 @@ public function test_users_are_rate_limited()
100101
{
101102
$user = User::factory()->create();
102103

103-
for ($i = 0; $i < 5; $i++) {
104-
$this->post(route('login.store'), [
105-
'email' => $user->email,
106-
'password' => 'wrong-password',
107-
])->assertStatus(302)->assertSessionHasErrors([
108-
'email' => 'These credentials do not match our records.',
109-
]);
110-
}
104+
RateLimiter::increment(implode('|', [$user->email, '127.0.0.1']), amount: 10);
111105

112106
$response = $this->post(route('login.store'), [
113107
'email' => $user->email,

tests/Feature/Auth/EmailVerificationTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function test_email_is_not_verified_with_invalid_hash()
4545
{
4646
$user = User::factory()->unverified()->create();
4747

48+
Event::fake();
49+
4850
$verificationUrl = URL::temporarySignedRoute(
4951
'verification.verify',
5052
now()->addMinutes(60),
@@ -53,14 +55,15 @@ public function test_email_is_not_verified_with_invalid_hash()
5355

5456
$this->actingAs($user)->get($verificationUrl);
5557

58+
Event::assertNotDispatched(Verified::class);
5659
$this->assertFalse($user->fresh()->hasVerifiedEmail());
5760
}
5861

5962
public function test_email_is_not_verified_with_invalid_user_id(): void
6063
{
61-
$user = User::factory()->create([
62-
'email_verified_at' => null,
63-
]);
64+
$user = User::factory()->unverified()->create();
65+
66+
Event::fake();
6467

6568
$verificationUrl = URL::temporarySignedRoute(
6669
'verification.verify',
@@ -70,25 +73,25 @@ public function test_email_is_not_verified_with_invalid_user_id(): void
7073

7174
$this->actingAs($user)->get($verificationUrl);
7275

76+
Event::assertNotDispatched(Verified::class);
7377
$this->assertFalse($user->fresh()->hasVerifiedEmail());
7478
}
7579

7680
public function test_verified_user_is_redirected_to_dashboard_from_verification_prompt(): void
7781
{
78-
$user = User::factory()->create([
79-
'email_verified_at' => now(),
80-
]);
82+
$user = User::factory()->create();
83+
84+
Event::fake();
8185

8286
$response = $this->actingAs($user)->get(route('verification.notice'));
8387

88+
Event::assertNotDispatched(Verified::class);
8489
$response->assertRedirect(route('dashboard', absolute: false));
8590
}
8691

8792
public function test_already_verified_user_visiting_verification_link_is_redirected_without_firing_event_again(): void
8893
{
89-
$user = User::factory()->create([
90-
'email_verified_at' => now(),
91-
]);
94+
$user = User::factory()->create();
9295

9396
Event::fake();
9497

@@ -101,7 +104,7 @@ public function test_already_verified_user_visiting_verification_link_is_redirec
101104
$this->actingAs($user)->get($verificationUrl)
102105
->assertRedirect(route('dashboard', absolute: false).'?verified=1');
103106

104-
$this->assertTrue($user->fresh()->hasVerifiedEmail());
105107
Event::assertNotDispatched(Verified::class);
108+
$this->assertTrue($user->fresh()->hasVerifiedEmail());
106109
}
107110
}

tests/Feature/Auth/PasswordResetTest.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,9 @@ public function test_reset_password_screen_can_be_rendered()
3939
$this->post(route('password.email'), ['email' => $user->email]);
4040

4141
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
42-
$response = $this->get(route('password.reset', $notification->token).'?email='.$user->email);
43-
44-
$response->assertStatus(200)
45-
->assertInertia(fn ($page) => $page
46-
->component('auth/ResetPassword')
47-
->has('email')
48-
->has('token')
49-
->where('email', $user->email)
50-
->where('token', $notification->token)
51-
);
42+
$response = $this->get(route('password.reset', $notification->token));
43+
44+
$response->assertStatus(200);
5245

5346
return true;
5447
});

tests/Feature/Auth/VerificationNotificationTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public function test_sends_verification_notification(): void
1616
{
1717
Notification::fake();
1818

19-
$user = User::factory()->create([
20-
'email_verified_at' => null,
21-
]);
19+
$user = User::factory()->unverified()->create();
2220

2321
$this->actingAs($user)
2422
->post(route('verification.send'))
@@ -31,9 +29,7 @@ public function test_does_not_send_verification_notification_if_email_is_verifie
3129
{
3230
Notification::fake();
3331

34-
$user = User::factory()->create([
35-
'email_verified_at' => now(),
36-
]);
32+
$user = User::factory()->create();
3733

3834
$this->actingAs($user)
3935
->post(route('verification.send'))

0 commit comments

Comments
 (0)