add frontend controller tests

Cette révision appartient à :
2022-11-17 00:27:43 +01:00
Parent b21d5cf622
révision b995437483
4 fichiers modifiés avec 1120 ajouts et 31 suppressions

Voir le fichier

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\Webauthn\Application\Controller;
use D3\TestingTools\Production\IsMockable;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\WebauthnConf;
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
@ -22,24 +23,30 @@ use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
use Doctrine\DBAL\Exception as DoctrineException;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Routing\ControllerClassNameResolver;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\Utils;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
class d3webauthnlogin extends FrontendController
{
use IsMockable;
protected $_sThisTemplate = 'd3webauthnlogin.tpl';
/**
* @return array
*/
public function getNavigationParams(): array
{
$navparams = Registry::getSession()->getVariable(
{;
$navparams = $this->d3GetSession()->getVariable(
WebauthnConf::WEBAUTHN_SESSION_NAVPARAMS
);
return array_merge(
$this->d3CallMockableParent('getNavigationParams'),
$navparams,
['cl' => $navparams['actcontrol']]
);
@ -54,8 +61,8 @@ class d3webauthnlogin extends FrontendController
*/
public function render(): string
{
if (Registry::getSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH) ||
!Registry::getSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER)
if ($this->d3GetSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH) ||
!$this->d3GetSession()->hasVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER)
) {
$this->getUtils()->redirect('index.php?cl=start');
if (!defined('OXID_PHP_UNIT')) {
@ -67,7 +74,7 @@ class d3webauthnlogin extends FrontendController
$this->generateCredentialRequest();
$this->addTplParam('navFormParams', Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS));
$this->addTplParam('navFormParams', $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS));
return parent::render();
}
@ -81,18 +88,18 @@ class d3webauthnlogin extends FrontendController
*/
public function generateCredentialRequest(): void
{
$userId = Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
$userId = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
try {
/** @var Webauthn $webauthn */
$webauthn = oxNew(Webauthn::class);
$webauthn = $this->d3GetWebauthnObject();
$publicKeyCredentialRequestOptions = $webauthn->getRequestOptions($userId);
$this->addTplParam('webauthn_publickey_login', $publicKeyCredentialRequestOptions);
$this->addTplParam('isAdmin', isAdmin());
} catch (WebauthnException $e) {
Registry::getSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
Registry::getLogger()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
Registry::getLogger()->debug($e->getTraceAsString());
$this->d3GetSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
$this->d3GetLogger()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
$this->d3GetLogger()->debug($e->getTraceAsString());
Registry::getUtilsView()->addErrorToDisplay($e);
$this->getUtils()->redirect('index.php?cl=start');
}
@ -111,7 +118,7 @@ class d3webauthnlogin extends FrontendController
*/
public function getPreviousClass(): ?string
{
return Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
return $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
}
/**
@ -119,12 +126,13 @@ class d3webauthnlogin extends FrontendController
*/
public function previousClassIsOrderStep(): bool
{
$sClassKey = Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
$sClassKey = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
$resolvedClass = $this->getControllerClassNameResolver()->getClassNameById($sClassKey);
$resolvedClass = $resolvedClass ?: 'start';
/** @var FrontendController $oController */
$oController = oxNew($resolvedClass);
return $oController->getIsOrderStep();
}
@ -151,4 +159,36 @@ class d3webauthnlogin extends FrontendController
return $aPaths;
}
/**
* @return Session
*/
public function d3GetSession(): Session
{
return Registry::getSession();
}
/**
* @return Webauthn
*/
public function d3GetWebauthnObject(): Webauthn
{
return oxNew(Webauthn::class);
}
/**
* @return LoggerInterface
*/
public function d3GetLogger(): LoggerInterface
{
return Registry::getLogger();
}
/**
* @return ControllerClassNameResolver
*/
public function getControllerClassNameResolver(): ControllerClassNameResolver
{
return Registry::getControllerClassNameResolver();
}
}