From 3c7e17fca8b6f044dfbfc492a27fd66facce1ff3 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 26 Mar 2024 09:15:45 +0100 Subject: [PATCH] Handle 'SecondFactorRequiredException' in four relevant cases in tests --- tests/index.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/index.php b/tests/index.php index 3b2f799..5d48bbe 100644 --- a/tests/index.php +++ b/tests/index.php @@ -88,6 +88,21 @@ function processRequestData(\Delight\Auth\Auth $auth) { catch (\Delight\Auth\EmailNotVerifiedException $e) { return 'email address not verified'; } + catch (\Delight\Auth\SecondFactorRequiredException $e) { + $secondFactorOptions = []; + + if ($e->hasTotpOption()) { + $secondFactorOptions[] = 'TOTP'; + } + if ($e->hasSmsOption()) { + $secondFactorOptions[] = 'SMS (' . $e->getSmsRecipient() . ') with ' . $e->getSmsOtpValue(); + } + if ($e->hasEmailOption()) { + $secondFactorOptions[] = 'email (' . $e->getEmailRecipient() . ') with ' . $e->getEmailOtpValue(); + } + + return 'second factor required: ' . \implode(' / ', $secondFactorOptions); + } catch (\Delight\Auth\TooManyRequestsException $e) { return 'too many requests'; } @@ -167,6 +182,21 @@ function processRequestData(\Delight\Auth\Auth $auth) { catch (\Delight\Auth\UserAlreadyExistsException $e) { return 'email address already exists'; } + catch (\Delight\Auth\SecondFactorRequiredException $e) { + $secondFactorOptions = []; + + if ($e->hasTotpOption()) { + $secondFactorOptions[] = 'TOTP'; + } + if ($e->hasSmsOption()) { + $secondFactorOptions[] = 'SMS (' . $e->getSmsRecipient() . ') with ' . $e->getSmsOtpValue(); + } + if ($e->hasEmailOption()) { + $secondFactorOptions[] = 'email (' . $e->getEmailRecipient() . ') with ' . $e->getEmailOtpValue(); + } + + return 'second factor required: ' . \implode(' / ', $secondFactorOptions); + } catch (\Delight\Auth\TooManyRequestsException $e) { return 'too many requests'; } @@ -282,6 +312,21 @@ function processRequestData(\Delight\Auth\Auth $auth) { catch (\Delight\Auth\InvalidPasswordException $e) { return 'invalid password'; } + catch (\Delight\Auth\SecondFactorRequiredException $e) { + $secondFactorOptions = []; + + if ($e->hasTotpOption()) { + $secondFactorOptions[] = 'TOTP'; + } + if ($e->hasSmsOption()) { + $secondFactorOptions[] = 'SMS (' . $e->getSmsRecipient() . ') with ' . $e->getSmsOtpValue(); + } + if ($e->hasEmailOption()) { + $secondFactorOptions[] = 'email (' . $e->getEmailRecipient() . ') with ' . $e->getEmailOtpValue(); + } + + return 'second factor required: ' . \implode(' / ', $secondFactorOptions); + } catch (\Delight\Auth\TooManyRequestsException $e) { return 'too many requests'; }