2026-04-20 10:08:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Http\Middleware\CheckForcePasswordReset;
|
|
|
|
|
use App\Http\Middleware\DecideWhatToDoWithUser;
|
|
|
|
|
use App\Models\InstanceSettings;
|
|
|
|
|
use App\Models\Team;
|
2026-06-02 10:22:27 +00:00
|
|
|
use App\Models\TeamInvitation;
|
2026-04-20 10:08:46 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
2026-06-02 10:22:27 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2026-04-20 10:08:46 +00:00
|
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
use Illuminate\Support\Once;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->withoutMiddleware([DecideWhatToDoWithUser::class, CheckForcePasswordReset::class]);
|
|
|
|
|
Once::flush();
|
2026-06-02 10:22:27 +00:00
|
|
|
Config::set('app.maintenance.driver', 'file');
|
|
|
|
|
Config::set('cache.default', 'array');
|
|
|
|
|
Config::set('session.driver', 'array');
|
|
|
|
|
|
2026-04-20 10:08:46 +00:00
|
|
|
if (! InstanceSettings::find(0)) {
|
|
|
|
|
$settings = new InstanceSettings;
|
|
|
|
|
$settings->id = 0;
|
|
|
|
|
$settings->saveQuietly();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('invitation link login', function () {
|
|
|
|
|
test('does not auto-verify the email address', function () {
|
|
|
|
|
$team = Team::factory()->create();
|
|
|
|
|
$password = 'test-password-123';
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee@example.com',
|
|
|
|
|
'password' => Hash::make($password),
|
|
|
|
|
'email_verified_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
$user->teams()->attach($team->id, ['role' => 'member']);
|
|
|
|
|
|
|
|
|
|
$token = Crypt::encryptString("{$user->email}@@@{$password}");
|
2026-06-02 10:22:27 +00:00
|
|
|
TeamInvitation::create([
|
|
|
|
|
'team_id' => $team->id,
|
|
|
|
|
'uuid' => 'email-verification-test-invitation',
|
|
|
|
|
'email' => $user->email,
|
|
|
|
|
'role' => 'member',
|
|
|
|
|
'link' => route('auth.link', ['token' => $token]),
|
|
|
|
|
'via' => 'link',
|
|
|
|
|
]);
|
2026-04-20 10:08:46 +00:00
|
|
|
|
|
|
|
|
$this->get(route('auth.link', ['token' => $token]));
|
|
|
|
|
|
|
|
|
|
$user->refresh();
|
|
|
|
|
expect($user->email_verified_at)->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('still logs the user in', function () {
|
|
|
|
|
$team = Team::factory()->create();
|
|
|
|
|
$password = 'test-password-123';
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee2@example.com',
|
|
|
|
|
'password' => Hash::make($password),
|
|
|
|
|
'email_verified_at' => null,
|
|
|
|
|
]);
|
|
|
|
|
$user->teams()->attach($team->id, ['role' => 'member']);
|
|
|
|
|
|
|
|
|
|
$token = Crypt::encryptString("{$user->email}@@@{$password}");
|
2026-06-02 10:22:27 +00:00
|
|
|
TeamInvitation::create([
|
|
|
|
|
'team_id' => $team->id,
|
|
|
|
|
'uuid' => 'email-verification-login-test-invitation',
|
|
|
|
|
'email' => $user->email,
|
|
|
|
|
'role' => 'member',
|
|
|
|
|
'link' => route('auth.link', ['token' => $token]),
|
|
|
|
|
'via' => 'link',
|
|
|
|
|
]);
|
2026-04-20 10:08:46 +00:00
|
|
|
|
2026-06-02 10:22:27 +00:00
|
|
|
$this->get(route('auth.link', ['token' => $token]))
|
|
|
|
|
->assertRedirect(route('dashboard'));
|
2026-04-20 10:08:46 +00:00
|
|
|
|
|
|
|
|
expect(auth()->id())->toBe($user->id);
|
|
|
|
|
});
|
|
|
|
|
});
|