fix unthrown invalid totp exception

This commit is contained in:
Daniel Seifert 2022-11-13 23:40:54 +01:00
parent 42bab2bd25
commit 12bb6355ee
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
5 changed files with 10 additions and 16 deletions

View File

@ -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);
}
/**

View File

@ -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'));
}

View File

@ -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()

View File

@ -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]);
}
/**

View File

@ -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]);
}
/**