diff --git a/src/Application/Controller/Admin/d3totpadminlogin.php b/src/Application/Controller/Admin/d3totpadminlogin.php index f29970d..0550a8f 100644 --- a/src/Application/Controller/Admin/d3totpadminlogin.php +++ b/src/Application/Controller/Admin/d3totpadminlogin.php @@ -179,10 +179,8 @@ class d3totpadminlogin extends AdminController */ public function d3TotpHasValidTotp(string $sTotp = null, d3totp $totp): bool { - return $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH) || - ( - $sTotp && $totp->verify($sTotp) - ); + return $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH) + || $totp->verify($sTotp); } /** diff --git a/src/Application/Model/d3totp.php b/src/Application/Model/d3totp.php index 5ac72be..4046e3d 100644 --- a/src/Application/Model/d3totp.php +++ b/src/Application/Model/d3totp.php @@ -143,7 +143,7 @@ class d3totp extends BaseModel { if (false == $this->totp) { $this->totp = TOTP::create($seed ?: $this->getSavedSecret()); - $this->totp->setLabel($this->getUser()->getFieldData('oxusername')); + $this->totp->setLabel($this->getUser()->getFieldData('oxusername')?: ''); $this->totp->setIssuer(Registry::getConfig()->getActiveShop()->getFieldData('oxname')); } diff --git a/src/Modules/Application/Component/d3_totp_UserComponent.php b/src/Modules/Application/Component/d3_totp_UserComponent.php index 1e9bfdf..697368c 100644 --- a/src/Modules/Application/Component/d3_totp_UserComponent.php +++ b/src/Modules/Application/Component/d3_totp_UserComponent.php @@ -157,9 +157,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent public function d3TotpHasValidTotp($sTotp, $totp) { return Registry::getSession()->getVariable(d3totp_conf::SESSION_AUTH) || - ( - $sTotp && $totp->verify($sTotp) - ); + $totp->verify($sTotp); } public function d3TotpClearSessionVariables() diff --git a/src/tests/unit/Application/Controller/Admin/d3totpadminloginTest.php b/src/tests/unit/Application/Controller/Admin/d3totpadminloginTest.php index dcd9b07..5e84e3c 100644 --- a/src/tests/unit/Application/Controller/Admin/d3totpadminloginTest.php +++ b/src/tests/unit/Application/Controller/Admin/d3totpadminloginTest.php @@ -537,11 +537,10 @@ class d3totpadminloginTest extends d3TotpUnitTestCase ->onlyMethods(['verify']) ->disableOriginalConstructor() ->getMock(); - $oTotpMock->method('verify')->willReturn(true); + $oTotpMock->method('verify')->willThrowException(oxNew(d3totp_wrongOtpException::class)); - $this->assertFalse( - $this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock]) - ); + $this->expectException(d3totp_wrongOtpException::class); + $this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock]); } /** diff --git a/src/tests/unit/Modules/Application/Component/d3_totp_UserComponentTest.php b/src/tests/unit/Modules/Application/Component/d3_totp_UserComponentTest.php index 1a53cba..24141cd 100644 --- a/src/tests/unit/Modules/Application/Component/d3_totp_UserComponentTest.php +++ b/src/tests/unit/Modules/Application/Component/d3_totp_UserComponentTest.php @@ -566,11 +566,10 @@ class d3_totp_UserComponentTest extends d3TotpUnitTestCase ->onlyMethods(['verify']) ->disableOriginalConstructor() ->getMock(); - $oTotpMock->method('verify')->willReturn(true); + $oTotpMock->method('verify')->willThrowException(oxNew(d3totp_wrongOtpException::class)); - $this->assertFalse( - $this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock]) - ); + $this->expectException(d3totp_wrongOtpException::class); + $this->callMethod($this->_oController, 'd3TotpHasValidTotp', [null, $oTotpMock]); } /**