From e919eec2a9589816a35e812969f05e24b4ba5776 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 1 Apr 2024 14:15:11 +0200 Subject: [PATCH] Add tests for 'Auth#enableTwoFactorViaTotp' --- tests/index.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/index.php b/tests/index.php index 7ee41de..08e3222 100644 --- a/tests/index.php +++ b/tests/index.php @@ -366,6 +366,28 @@ function processRequestData(\Delight\Auth\Auth $auth) { return 'too many requests'; } } + else if ($_POST['action'] === 'enableTwoFactorViaTotp') { + try { + $recoveryCodes = $auth->enableTwoFactorViaTotp($_POST['otpValue']); + + return \implode(' | ', $recoveryCodes); + } + catch (\Delight\Auth\InvalidOneTimePasswordException $e) { + return 'invalid OTP'; + } + catch (\Delight\Auth\TwoFactorMechanismNotInitializedException $e) { + return 'not initialized'; + } + catch (\Delight\Auth\TwoFactorMechanismAlreadyEnabledException $e) { + return 'already enabled'; + } + catch (\Delight\Auth\NotLoggedInException $e) { + return 'not logged in'; + } + catch (\Delight\Auth\TooManyRequestsException $e) { + return 'too many requests'; + } + } else if ($_POST['action'] === 'reconfirmPassword') { try { return $auth->reconfirmPassword($_POST['password']) ? 'correct' : 'wrong'; @@ -900,6 +922,12 @@ function showAuthenticatedUserForm(\Delight\Auth\Auth $auth) { echo ''; echo ''; + echo '
'; + echo ''; + echo ' '; + echo ''; + echo '
'; + echo '
'; echo ''; echo '';