Skip to content

Commit b434b4e

Browse files
committed
feat: add testing infrastructure for login MFA flow and E2E suite
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 3b111f5 commit b434b4e

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

.github/workflows/pull_request_unit_tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
PHP_VERSION: 8.3
3838
OTEL_SDK_DISABLED: true
3939
OTEL_SERVICE_ENABLED: false
40+
TURNSTILE_SITE_KEY: '1x00000000000000000000AA'
41+
TURNSTILE_SECRET_KEY: '1x0000000000000000000000000000000AA'
4042
services:
4143
mysql:
4244
image: mysql:8.0

tests/TwoFactorLoginFlowTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\libs\Auth\Models\TwoFactorAuditLog;
1717
use App\libs\Auth\Models\UserRecoveryCode;
1818
use App\libs\Auth\Models\UserTrustedDevice;
19+
use App\Mail\OAuth2PasswordlessOTPMail;
1920
use App\Services\Auth\IDeviceTrustService;
2021
use App\Services\Auth\ITwoFactorAuditService;
2122
use Auth\AuthHelper;
@@ -25,6 +26,7 @@
2526
use Illuminate\Support\Facades\Cache;
2627
use Illuminate\Support\Facades\Config;
2728
use Illuminate\Support\Facades\Hash;
29+
use Illuminate\Support\Facades\Mail;
2830
use Illuminate\Support\Facades\Session;
2931
use App\libs\OAuth2\Repositories\IOAuth2OTPRepository;
3032
use LaravelDoctrine\ORM\Facades\EntityManager;
@@ -90,6 +92,33 @@ public function testNonAdminWithoutMFALogsInNormally(): void
9092
$this->assertTrue(Auth::check(), 'a non-MFA user must get an authenticated session');
9193
}
9294

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+
93122
// -------------------------------------------------------------------------
94123
// verify2FA
95124
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)