From c77f6fa9e2c42dd8d5df0031076d8c7caa6835fd Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 11 Aug 2019 00:33:59 +0200 Subject: [PATCH] change and add tests --- .../Controller/Admin/d3user_totp.php | 2 +- src/Application/Model/d3totp.php | 5 +- .../views/admin/tpl/d3user_totp.tpl | 2 + src/Application/views/tpl/d3_account_totp.tpl | 2 + .../Application/Model/d3_totp_user.php | 5 +- .../Controller/Admin/d3user_totpTest.php | 119 ++++++++++++++++-- .../Controller/d3_account_totpTest.php | 24 +++- .../d3totp_wrongOtpExceptionTest.php | 58 +++++++++ .../Model/d3RandomGeneratorTest.php | 57 +++++++++ .../Component/d3_totp_UserComponentTest.php | 61 ++++++--- .../Admin/d3_totp_LoginControllerTest.php | 33 ++--- .../Controller/d3_totp_getUserTestTrait.php | 6 +- .../unit/Modules/Core/d3_totp_utilsTest.php | 8 +- 13 files changed, 323 insertions(+), 59 deletions(-) create mode 100644 src/tests/unit/Application/Model/Exceptions/d3totp_wrongOtpExceptionTest.php create mode 100644 src/tests/unit/Application/Model/d3RandomGeneratorTest.php diff --git a/src/Application/Controller/Admin/d3user_totp.php b/src/Application/Controller/Admin/d3user_totp.php index 04b7b81..37bd028 100644 --- a/src/Application/Controller/Admin/d3user_totp.php +++ b/src/Application/Controller/Admin/d3user_totp.php @@ -166,6 +166,6 @@ class d3user_totp extends AdminDetailsController public function getAvailableBackupCodeCount() { $oBackupCodeList = $this->getBackupcodeListObject(); - return $oBackupCodeList->getAvailableCodeCount($this->getUser()->getId()); + return $oBackupCodeList->getAvailableCodeCount($this->getEditObjectId()); } } \ No newline at end of file diff --git a/src/Application/Model/d3totp.php b/src/Application/Model/d3totp.php index bab1ad5..e798da8 100644 --- a/src/Application/Model/d3totp.php +++ b/src/Application/Model/d3totp.php @@ -51,7 +51,6 @@ class d3totp extends BaseModel /** * @param $userId - * @return bool * @throws DBALException * @throws DatabaseConnectionException */ @@ -66,10 +65,8 @@ class d3totp extends BaseModel ->where("oxuserid = " . $oQB->createNamedParameter($userId)) ->setMaxResults(1); - return $this->load(DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC)->getOne($oQB->getSQL(), $oQB->getParameters())); + $this->load(DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC)->getOne($oQB->getSQL(), $oQB->getParameters())); } - - return false; } /** diff --git a/src/Application/views/admin/tpl/d3user_totp.tpl b/src/Application/views/admin/tpl/d3user_totp.tpl index a610382..8d73e9c 100644 --- a/src/Application/views/admin/tpl/d3user_totp.tpl +++ b/src/Application/views/admin/tpl/d3user_totp.tpl @@ -1,6 +1,8 @@ [{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}] [{assign var="totp" value=$edit->d3GetTotp()}] +[{assign var="userid" value=$edit->getId()}] +[{$totp->loadByUserId($userid)}] [{if $readonly}] [{assign var="readonly" value="readonly disabled"}] diff --git a/src/Application/views/tpl/d3_account_totp.tpl b/src/Application/views/tpl/d3_account_totp.tpl index 614e3ce..f30039e 100644 --- a/src/Application/views/tpl/d3_account_totp.tpl +++ b/src/Application/views/tpl/d3_account_totp.tpl @@ -3,6 +3,8 @@

[{oxmultilang ident="D3_TOTP_ACCOUNT"}]

[{assign var="totp" value=$user->d3GetTotp()}] + [{assign var="userid" value=$user->getId()}] + [{$totp->loadByUserId($userid)}]