feat: add critical path test suite and fix auth/config issues
Test Infrastructure:
- Modernize phpunit.xml (bootstrap, source block, Laravel 12 env vars)
- Configure tests/Pest.php with pest()->extend(TestCase::class)->in('Feature')
- Add docker-compose.test.yml (Redis for test suite)
- Add composer test/test:quick scripts
- Rename CACHE_DRIVER to CACHE_STORE across config (backwards compatible)
- Update .env.testing for in-memory SQLite + Docker Redis
Test Coverage (190 tests):
- CriticalRoutes: public routes, auth routes, API endpoints, middleware, schedule
- Auth/LoginTest: login, logout, rate limiting, redirect behavior
- Auth/RegisterTest: registration flow, validation, disabled registration
- Auth/PasswordResetTest: reset request, token validation, password update
- Auth/TwoFactorTest: 2FA checkpoint, setup behind password confirmation
- Auth/PasswordConfirmationTest: sudo mode flow via Laravel password.confirm
- Api/ScopeTest: scope enforcement, public endpoints, admin access
Bugs Fixed:
- Fix unauthenticated API returning 500 instead of 401 (AuthenticationException
not handled in custom exception renderer in bootstrap/app.php)
- Replace custom DangerZone middleware with Laravel password.confirm
- Add HasFactory trait to Profile model for test factories
Bugs Documented (known-bugs group):
- Registration crashes with str_ends_with TypeError (RegisterController:82)
- OAuth routes use legacy array syntax causing ReflectionFunction TypeError
4 weeks ago
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
feat: add critical path test suite and fix auth/config issues
Test Infrastructure:
- Modernize phpunit.xml (bootstrap, source block, Laravel 12 env vars)
- Configure tests/Pest.php with pest()->extend(TestCase::class)->in('Feature')
- Add docker-compose.test.yml (Redis for test suite)
- Add composer test/test:quick scripts
- Rename CACHE_DRIVER to CACHE_STORE across config (backwards compatible)
- Update .env.testing for in-memory SQLite + Docker Redis
Test Coverage (190 tests):
- CriticalRoutes: public routes, auth routes, API endpoints, middleware, schedule
- Auth/LoginTest: login, logout, rate limiting, redirect behavior
- Auth/RegisterTest: registration flow, validation, disabled registration
- Auth/PasswordResetTest: reset request, token validation, password update
- Auth/TwoFactorTest: 2FA checkpoint, setup behind password confirmation
- Auth/PasswordConfirmationTest: sudo mode flow via Laravel password.confirm
- Api/ScopeTest: scope enforcement, public endpoints, admin access
Bugs Fixed:
- Fix unauthenticated API returning 500 instead of 401 (AuthenticationException
not handled in custom exception renderer in bootstrap/app.php)
- Replace custom DangerZone middleware with Laravel password.confirm
- Add HasFactory trait to Profile model for test factories
Bugs Documented (known-bugs group):
- Registration crashes with str_ends_with TypeError (RegisterController:82)
- OAuth routes use legacy array syntax causing ReflectionFunction TypeError
4 weeks ago
|
|
|
use Illuminate\Auth\Notifications\ResetPassword;
|
|
|
|
|
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
|
use Illuminate\Support\Facades\Password;
|
|
|
|
|
|
|
|
|
|
uses(LazilyRefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Password Reset
|
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
it('renders the password reset request page', function () {
|
|
|
|
|
$this->get('/password/reset')
|
|
|
|
|
->assertOk();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('sends a password reset link to a valid email', function () {
|
|
|
|
|
Notification::fake();
|
|
|
|
|
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
|
|
|
|
|
$this->post('/password/email', [
|
|
|
|
|
'email' => $user->email,
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
Notification::assertSentTo($user, ResetPassword::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not reveal whether an email exists', function () {
|
|
|
|
|
Notification::fake();
|
|
|
|
|
|
|
|
|
|
$this->post('/password/email', [
|
|
|
|
|
'email' => 'nonexistent@example.com',
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
Notification::assertNothingSent();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders the password reset form with a valid token', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$token = Password::createToken($user);
|
|
|
|
|
|
|
|
|
|
$this->get("/password/reset/{$token}")
|
|
|
|
|
->assertOk();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('resets the password with a valid token', function () {
|
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
$token = Password::createToken($user);
|
|
|
|
|
|
|
|
|
|
$this->post('/password/reset', [
|
|
|
|
|
'token' => $token,
|
|
|
|
|
'email' => $user->email,
|
|
|
|
|
'password' => 'NewSecurePass123!',
|
|
|
|
|
'password_confirmation' => 'NewSecurePass123!',
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$user->refresh();
|
|
|
|
|
expect(Hash::check('NewSecurePass123!', $user->password))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rejects password reset with an invalid token', function () {
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'password' => Hash::make('original-password'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->post('/password/reset', [
|
|
|
|
|
'token' => 'invalid-token',
|
|
|
|
|
'email' => $user->email,
|
|
|
|
|
'password' => 'NewSecurePass123!',
|
|
|
|
|
'password_confirmation' => 'NewSecurePass123!',
|
|
|
|
|
])->assertRedirect();
|
|
|
|
|
|
|
|
|
|
$user->refresh();
|
|
|
|
|
expect(Hash::check('original-password', $user->password))->toBeTrue();
|
|
|
|
|
});
|