|
16 | 16 | use App\libs\Auth\Models\TwoFactorAuditLog; |
17 | 17 | use App\libs\Auth\Models\UserRecoveryCode; |
18 | 18 | use App\libs\Auth\Models\UserTrustedDevice; |
| 19 | +use App\Mail\OAuth2PasswordlessOTPMail; |
19 | 20 | use App\Services\Auth\IDeviceTrustService; |
20 | 21 | use App\Services\Auth\ITwoFactorAuditService; |
21 | 22 | use Auth\AuthHelper; |
|
25 | 26 | use Illuminate\Support\Facades\Cache; |
26 | 27 | use Illuminate\Support\Facades\Config; |
27 | 28 | use Illuminate\Support\Facades\Hash; |
| 29 | +use Illuminate\Support\Facades\Mail; |
28 | 30 | use Illuminate\Support\Facades\Session; |
29 | 31 | use App\libs\OAuth2\Repositories\IOAuth2OTPRepository; |
30 | 32 | use LaravelDoctrine\ORM\Facades\EntityManager; |
@@ -90,6 +92,33 @@ public function testNonAdminWithoutMFALogsInNormally(): void |
90 | 92 | $this->assertTrue(Auth::check(), 'a non-MFA user must get an authenticated session'); |
91 | 93 | } |
92 | 94 |
|
| 95 | + // ------------------------------------------------------------------------- |
| 96 | + // email delivery |
| 97 | + // ------------------------------------------------------------------------- |
| 98 | + |
| 99 | + public function testMFAChallengeQueuesEmailWithCorrectOTPCode(): void |
| 100 | + { |
| 101 | + $this->postLogin(self::ADMIN_EMAIL, self::SEED_PASSWORD); |
| 102 | + |
| 103 | + $dbCode = $this->latestOtpCode(self::ADMIN_EMAIL); |
| 104 | + |
| 105 | + Mail::assertQueued( |
| 106 | + OAuth2PasswordlessOTPMail::class, |
| 107 | + function (OAuth2PasswordlessOTPMail $mail) use ($dbCode): bool { |
| 108 | + return $mail->email === self::ADMIN_EMAIL |
| 109 | + && $mail->otp === $dbCode; |
| 110 | + } |
| 111 | + ); |
| 112 | + } |
| 113 | + |
| 114 | + public function testResendMFAChallengeQueuesAdditionalEmail(): void |
| 115 | + { |
| 116 | + $this->postLogin(self::ADMIN_EMAIL, self::SEED_PASSWORD); |
| 117 | + $this->resend(); |
| 118 | + |
| 119 | + Mail::assertQueued(OAuth2PasswordlessOTPMail::class, 2); |
| 120 | + } |
| 121 | + |
93 | 122 | // ------------------------------------------------------------------------- |
94 | 123 | // verify2FA |
95 | 124 | // ------------------------------------------------------------------------- |
|
0 commit comments