add admin controller tests, improve controller classes

This commit is contained in:
Daniel Seifert 2022-11-23 00:18:09 +01:00
parent 3bbfde7794
commit f74d6985fb
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
10 changed files with 391 additions and 303 deletions

View File

@ -42,7 +42,7 @@ class d3user_webauthn extends AdminDetailsController
*/
public function render(): string
{
$this->addTplParam('readonly', !$this->getWebauthnObject()->isAvailable());
$this->addTplParam('readonly', !$this->d3GetWebauthnObject()->isAvailable());
$this->d3CallMockableParent('render');
@ -50,7 +50,7 @@ class d3user_webauthn extends AdminDetailsController
if (isset($soxId) && $soxId != "-1") {
/** @var d3_User_Webauthn $oUser */
$oUser = $this->getUserObject();
$oUser = $this->d3GetUserObject();
if ($oUser->load($soxId)) {
$this->addTplParam("oxid", $oUser->getId());
} else {
@ -75,10 +75,10 @@ class d3user_webauthn extends AdminDetailsController
$this->setPageType( 'requestnew' );
$this->setAuthnRegister();
} catch (Exception|ContainerExceptionInterface|NotFoundExceptionInterface|DoctrineDriverException $e) {
$this->getUtilsViewObject()->addErrorToDisplay($e);
$this->getLoggerObject()->error($e->getMessage(), ['UserId' => $this->getEditObjectId()]);
$this->getLoggerObject()->debug($e->getTraceAsString());
$this->getUtilsObject()->redirect('index.php?cl=d3user_webauthn');
$this->d3GetUtilsViewObject()->addErrorToDisplay($e);
$this->d3GetLoggerObject()->error($e->getMessage(), ['UserId' => $this->getEditObjectId()]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
$this->d3GetUtilsObject()->redirect('index.php?cl=d3user_webauthn');
}
}
@ -97,13 +97,13 @@ class d3user_webauthn extends AdminDetailsController
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
if ( strlen((string) $credential) ) {
$webauthn = $this->getWebauthnObject();
$webauthn = $this->d3GetWebauthnObject();
$webauthn->saveAuthn($credential, Registry::getRequest()->getRequestEscapedParameter( 'keyname' ) );
}
} catch (WebauthnException|Exception|NotFoundExceptionInterface|ContainerExceptionInterface|DoctrineDriverException $e) {
$this->getLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $this->getEditObjectId()]);
$this->getLoggerObject()->debug($e->getTraceAsString());
$this->getUtilsViewObject()->addErrorToDisplay($e);
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $this->getEditObjectId()]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
$this->d3GetUtilsViewObject()->addErrorToDisplay($e);
}
}
@ -122,9 +122,9 @@ class d3user_webauthn extends AdminDetailsController
*/
public function setAuthnRegister(): void
{
$authn = $this->getWebauthnObject();
$authn = $this->d3GetWebauthnObject();
$user = $this->getUserObject();
$user = $this->d3GetUserObject();
$user->load($this->getEditObjectId());
$publicKeyCredentialCreationOptions = $authn->getCreationOptions($user);
@ -148,10 +148,10 @@ class d3user_webauthn extends AdminDetailsController
*/
public function getCredentialList($userId): array
{
$oUser = $this->getUserObject();
$oUser = $this->d3GetUserObject();
$oUser->load($userId);
$publicKeyCredentials = $this->getPublicKeyCredentialListObject();
$publicKeyCredentials = $this->d3GetPublicKeyCredentialListObject();
return $publicKeyCredentials->getAllFromUser($oUser)->getArray();
}
@ -160,7 +160,7 @@ class d3user_webauthn extends AdminDetailsController
*/
public function deleteKey(): void
{
$credential = $this->getPublicKeyCredentialObject();
$credential = $this->d3GetPublicKeyCredentialObject();
$credential->delete(Registry::getRequest()->getRequestEscapedParameter('deleteoxid'));
}
}

View File

@ -15,6 +15,8 @@ declare(strict_types=1);
namespace D3\Webauthn\Application\Controller\Admin;
use D3\TestingTools\Production\IsMockable;
use D3\Webauthn\Application\Controller\Traits\helpersTrait;
use D3\Webauthn\Application\Model\Exceptions\WebauthnGetException;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\WebauthnConf;
@ -28,12 +30,16 @@ use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Routing\ControllerClassNameResolver;
use OxidEsales\Eshop\Core\Utils;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class d3webauthnadminlogin extends AdminController
{
use helpersTrait;
use IsMockable;
protected $_sThisTemplate = 'd3webauthnadminlogin.tpl';
/**
@ -53,8 +59,8 @@ class d3webauthnadminlogin extends AdminController
*/
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=admin_start');
if (!defined('OXID_PHP_UNIT')) {
@ -66,7 +72,9 @@ class d3webauthnadminlogin extends AdminController
$this->generateCredentialRequest();
return parent::render();
$this->addTplParam('navFormParams', $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS));
return $this->d3CallMockableParent('render');
}
/**
@ -78,19 +86,19 @@ class d3webauthnadminlogin extends AdminController
*/
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);
Registry::getSession()->setVariable(WebauthnConf::WEBAUTHN_LOGIN_OBJECT, $publicKeyCredentialRequestOptions);
$this->d3GetSession()->setVariable(WebauthnConf::WEBAUTHN_LOGIN_OBJECT, $publicKeyCredentialRequestOptions);
$this->addTplParam('webauthn_publickey_login', $publicKeyCredentialRequestOptions);
$this->addTplParam('isAdmin', isAdmin());
} catch (WebauthnException $e) {
Registry::getSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
$this->d3GetSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
Registry::getUtilsView()->addErrorToDisplay($e);
Registry::getLogger()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
Registry::getLogger()->debug($e->getTraceAsString());
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
$this->getUtils()->redirect('index.php?cl=login');
}
}
@ -101,8 +109,8 @@ class d3webauthnadminlogin extends AdminController
public function d3AssertAuthn(): ?string
{
/** @var d3_User_Webauthn $user */
$user = oxNew(User::class);
$userId = Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
$user = $this->d3GetUserObject();
$userId = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
try {
$error = Registry::getRequest()->getRequestEscapedParameter('error');
@ -114,19 +122,19 @@ class d3webauthnadminlogin extends AdminController
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
if (strlen((string) $credential)) {
$webAuthn = oxNew( Webauthn::class );
$webAuthn->assertAuthn( $credential );
$webAuthn = $this->d3GetWebauthnObject();
$webAuthn->assertAuthn($credential);
$user->load($userId);
Registry::getSession()->setVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH, true);
$this->d3GetSession()->setVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH, true);
/** @var d3_webauthn_UserComponent $userCmp */
$loginController = oxNew(LoginController::class);
return $loginController->checklogin();
}
} catch (WebauthnException $e) {
Registry::getUtilsView()->addErrorToDisplay($e);
Registry::getLogger()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
Registry::getLogger()->debug($e->getTraceAsString());
$this->d3GetUtilsViewObject()->addErrorToDisplay($e);
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
$user->logout();
}
@ -146,7 +154,7 @@ class d3webauthnadminlogin extends AdminController
*/
public function getPreviousClass(): ?string
{
return Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
return $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
}
/**
@ -154,8 +162,8 @@ class d3webauthnadminlogin extends AdminController
*/
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->d3GetControllerClassNameResolver()->getClassNameById($sClassKey);
$resolvedClass = $resolvedClass ?: 'start';
/** @var FrontendController $oController */
@ -170,22 +178,4 @@ class d3webauthnadminlogin extends AdminController
{
return $this->previousClassIsOrderStep();
}
/**
* Returns Bread Crumb - you are here page1/page2/page3...
*
* @return array
*/
public function getBreadCrumb(): array
{
$aPaths = [];
$aPath = [];
$iBaseLanguage = Registry::getLang()->getBaseLanguage();
$aPath['title'] = Registry::getLang()->translateString('D3_WEBAUTHN_BREADCRUMB', $iBaseLanguage, false);
$aPath['link'] = $this->getLink();
$aPaths[] = $aPath;
return $aPaths;
}
}

View File

@ -7,6 +7,8 @@ use D3\Webauthn\Application\Model\Credential\PublicKeyCredentialList;
use D3\Webauthn\Application\Model\Webauthn;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Routing\ControllerClassNameResolver;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\Utils;
use OxidEsales\Eshop\Core\UtilsView;
use Psr\Log\LoggerInterface;
@ -16,7 +18,7 @@ trait helpersTrait
/**
* @return User
*/
public function getUserObject(): User
public function d3GetUserObject(): User
{
return oxNew(User::class);
}
@ -24,7 +26,7 @@ trait helpersTrait
/**
* @return Webauthn
*/
public function getWebauthnObject(): Webauthn
public function d3GetWebauthnObject(): Webauthn
{
return oxNew(Webauthn::class);
}
@ -32,7 +34,7 @@ trait helpersTrait
/**
* @return LoggerInterface
*/
public function getLoggerObject(): LoggerInterface
public function d3GetLoggerObject(): LoggerInterface
{
return Registry::getLogger();
}
@ -40,7 +42,7 @@ trait helpersTrait
/**
* @return Utils
*/
public function getUtilsObject(): Utils
public function d3GetUtilsObject(): Utils
{
return Registry::getUtils();
}
@ -48,7 +50,7 @@ trait helpersTrait
/**
* @return UtilsView
*/
public function getUtilsViewObject(): UtilsView
public function d3GetUtilsViewObject(): UtilsView
{
return Registry::getUtilsView();
}
@ -56,7 +58,7 @@ trait helpersTrait
/**
* @return PublicKeyCredentialList
*/
public function getPublicKeyCredentialListObject(): PublicKeyCredentialList
public function d3GetPublicKeyCredentialListObject(): PublicKeyCredentialList
{
return oxNew(PublicKeyCredentialList::class);
}
@ -64,8 +66,24 @@ trait helpersTrait
/**
* @return PublicKeyCredential
*/
public function getPublicKeyCredentialObject(): PublicKeyCredential
public function d3GetPublicKeyCredentialObject(): PublicKeyCredential
{
return oxNew(PublicKeyCredential::class);
}
/**
* @return Session
*/
public function d3GetSession(): Session
{
return Registry::getSession();
}
/**
* @return ControllerClassNameResolver
*/
public function d3GetControllerClassNameResolver(): ControllerClassNameResolver
{
return Registry::getControllerClassNameResolver();
}
}

View File

@ -43,7 +43,7 @@ class d3_account_webauthn extends AccountController
$sRet = parent::render();
$this->addTplParam('user', $this->getUser());
$this->addTplParam('readonly', !($this->getWebauthnObject()->isAvailable()));
$this->addTplParam('readonly', !($this->d3GetWebauthnObject()->isAvailable()));
return $sRet;
}
@ -58,7 +58,7 @@ class d3_account_webauthn extends AccountController
public function getCredentialList(): PublicKeyCredentialList
{
$oUser = $this->getUser();
$credentialList = $this->getPublicKeyCredentialListObject();
$credentialList = $this->d3GetPublicKeyCredentialListObject();
return $credentialList->getAllFromUser($oUser);
}
@ -75,9 +75,9 @@ class d3_account_webauthn extends AccountController
$this->setAuthnRegister();
$this->setPageType('requestnew');
} catch (WebauthnException $e) {
$this->getLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId: ' => $this->getUser()->getId()]);
$this->getLoggerObject()->debug($e->getTraceAsString());
$this->getUtilsViewObject()->addErrorToDisplay($e);
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId: ' => $this->getUser()->getId()]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
$this->d3GetUtilsViewObject()->addErrorToDisplay($e);
}
}
@ -100,7 +100,7 @@ class d3_account_webauthn extends AccountController
*/
public function setAuthnRegister(): void
{
$publicKeyCredentialCreationOptions = $this->getWebauthnObject()->getCreationOptions($this->getUser());
$publicKeyCredentialCreationOptions = $this->d3GetWebauthnObject()->getCreationOptions($this->getUser());
$this->addTplParam('webauthn_publickey_create', $publicKeyCredentialCreationOptions);
$this->addTplParam('isAdmin', isAdmin());
@ -126,11 +126,11 @@ class d3_account_webauthn extends AccountController
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
if (strlen((string) $credential)) {
$webauthn = $this->getWebauthnObject();
$webauthn = $this->d3GetWebauthnObject();
$webauthn->saveAuthn($credential, Registry::getRequest()->getRequestEscapedParameter('keyname'));
}
} catch (WebauthnException $e) {
$this->getUtilsViewObject()->addErrorToDisplay( $e );
$this->d3GetUtilsViewObject()->addErrorToDisplay( $e );
}
}
@ -141,7 +141,7 @@ class d3_account_webauthn extends AccountController
{
$deleteId = Registry::getRequest()->getRequestEscapedParameter('deleteoxid');
if ($deleteId) {
$credential = $this->getPublicKeyCredentialObject();
$credential = $this->d3GetPublicKeyCredentialObject();
$credential->delete($deleteId);
}
}

View File

@ -16,23 +16,24 @@ declare(strict_types=1);
namespace D3\Webauthn\Application\Controller;
use D3\TestingTools\Production\IsMockable;
use D3\Webauthn\Application\Controller\Traits\helpersTrait;
use D3\Webauthn\Application\Model\Exceptions\WebauthnGetException;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\WebauthnConf;
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
use D3\Webauthn\Modules\Application\Model\d3_User_Webauthn;
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;
use helpersTrait;
protected $_sThisTemplate = 'd3webauthnlogin.tpl';
@ -76,7 +77,7 @@ class d3webauthnlogin extends FrontendController
$this->addTplParam('navFormParams', $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_NAVFORMPARAMS));
return parent::render();
return $this->d3CallMockableParent('render');
}
/**
@ -98,8 +99,8 @@ class d3webauthnlogin extends FrontendController
$this->addTplParam('isAdmin', isAdmin());
} catch (WebauthnException $e) {
$this->d3GetSession()->setVariable(WebauthnConf::GLOBAL_SWITCH, true);
$this->d3GetLogger()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
$this->d3GetLogger()->debug($e->getTraceAsString());
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
Registry::getUtilsView()->addErrorToDisplay($e);
$this->getUtils()->redirect('index.php?cl=start');
}
@ -127,7 +128,7 @@ class d3webauthnlogin extends FrontendController
public function previousClassIsOrderStep(): bool
{
$sClassKey = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTCLASS);
$resolvedClass = $this->getControllerClassNameResolver()->getClassNameById($sClassKey);
$resolvedClass = $this->d3GetControllerClassNameResolver()->getClassNameById($sClassKey);
$resolvedClass = $resolvedClass ?: 'start';
/** @var FrontendController $oController */
@ -144,6 +145,55 @@ class d3webauthnlogin extends FrontendController
return $this->previousClassIsOrderStep();
}
/**
* @return void
*/
public function d3AssertAuthn(): void
{
/** @var d3_User_Webauthn $user */
$user = $this->d3GetUserObject();
$userId = $this->d3GetSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER);
try {
$error = Registry::getRequest()->getRequestEscapedParameter('error');
if (strlen((string) $error)) {
/** @var WebauthnGetException $e */
$e = oxNew(WebauthnGetException::class, $error);
throw $e;
}
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
if (strlen((string) $credential)) {
$webAuthn = $this->d3GetWebauthnObject();
$webAuthn->assertAuthn($credential);
$user->load($userId);
// relogin, don't extract from this try block
$setSessionCookie = Registry::getRequest()->getRequestParameter('lgn_cook');
$this->d3GetSession()->setVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH, $credential);
$this->d3GetSession()->setVariable('usr', $user->getId());
$this->setUser(null);
$this->setLoginStatus(USER_LOGIN_SUCCESS);
// cookie must be set ?
if ($setSessionCookie && Registry::getConfig()->getConfigParam('blShowRememberMe')) {
Registry::getUtilsServer()->setUserCookie(
$user->oxuser__oxusername->value,
$user->oxuser__oxpassword->value,
Registry::getConfig()->getShopId()
);
}
$this->_afterLogin($user);
}
} catch (WebauthnException $e) {
$this->d3GetUtilsViewObject()->addErrorToDisplay($e);
$this->d3GetLoggerObject()->error($e->getDetailedErrorMessage(), ['UserId' => $userId]);
$this->d3GetLoggerObject()->debug($e->getTraceAsString());
$user->logout();
}
}
/**
* @return array
*/
@ -159,36 +209,4 @@ 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();
}
}

View File

@ -15,18 +15,14 @@ declare(strict_types=1);
namespace D3\Webauthn\Modules\Application\Component;
use Assert\AssertionFailedException;
use D3\Webauthn\Application\Model\Exceptions\WebauthnGetException;
use D3\Webauthn\Application\Model\WebauthnConf;
use D3\Webauthn\Application\Model\Webauthn;
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
use D3\Webauthn\Modules\Application\Model\d3_User_Webauthn;
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
use Doctrine\DBAL\Exception;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Session;
use OxidEsales\Eshop\Core\UtilsView;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -109,55 +105,4 @@ class d3_webauthn_UserComponent extends d3_webauthn_UserComponent_parent
{
return Registry::getSession();
}
/**
* @return void
*/
public function d3AssertAuthn(): void
{
/** @var d3_User_Webauthn $user */
$user = oxNew(User::class);
try {
$error = Registry::getRequest()->getRequestEscapedParameter('error');
if (strlen((string) $error)) {
/** @var WebauthnGetException $e */
$e = oxNew(WebauthnGetException::class, $error);
throw $e;
}
$credential = Registry::getRequest()->getRequestEscapedParameter('credential');
if (strlen((string) $credential)) {
$webAuthn = oxNew( Webauthn::class );
$webAuthn->assertAuthn($credential);
$user->load(Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER));
// relogin, don't extract from this try block
$setSessionCookie = Registry::getRequest()->getRequestParameter('lgn_cook');
$this->d3WebauthnGetSession()->setVariable(WebauthnConf::WEBAUTHN_SESSION_AUTH, $credential);
$this->d3WebauthnGetSession()->setVariable('usr', $user->getId());
$this->setUser(null);
$this->setLoginStatus(USER_LOGIN_SUCCESS);
// cookie must be set ?
if ($setSessionCookie && Registry::getConfig()->getConfigParam('blShowRememberMe')) {
Registry::getUtilsServer()->setUserCookie(
$user->oxuser__oxusername->value,
$user->oxuser__oxpassword->value,
Registry::getConfig()->getShopId()
);
}
$this->_afterLogin($user);
}
} catch (WebauthnException $e) {
Registry::getUtilsView()->addErrorToDisplay($e);
Registry::getLogger()->error(
$e->getDetailedErrorMessage(),
['UserId' => Registry::getSession()->getVariable(WebauthnConf::WEBAUTHN_SESSION_CURRENTUSER)]
);
Registry::getLogger()->debug($e->getTraceAsString());
$user->logout();
}
}
}

View File

@ -11,7 +11,7 @@
* @link https://www.oxidmodule.com
*/
namespace D3\Totp\tests\unit\Application\Controller;
namespace D3\Webauthn\tests\unit\Application\Controller\Admin;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Controller\Admin\d3user_webauthn;
@ -65,16 +65,16 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $sutMock */
$sutMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods([
'getWebauthnObject',
'd3GetWebauthnObject',
'd3CallMockableParent',
'getEditObjectId',
'getUserObject'
'd3GetUserObject'
])
->getMock();
$sutMock->method('getWebauthnObject')->willReturn($webauthnMock);
$sutMock->method('d3GetWebauthnObject')->willReturn($webauthnMock);
$sutMock->method('d3CallMockableParent')->willReturn(true);
$sutMock->method('getEditObjectId')->willReturn('editObjectId');
$sutMock->method('getUserObject')->willReturn($userMock);
$sutMock->method('d3GetUserObject')->willReturn($userMock);
$this->setValue(
$sutMock,
@ -130,14 +130,14 @@ class d3user_webauthnTest extends TestCase
->onlyMethods([
'setPageType',
'setAuthnRegister',
'getLoggerObject',
'getUtilsObject'
'd3GetLoggerObject',
'd3GetUtilsObject'
])
->getMock();
$sutMock->expects($this->atLeastOnce())->method('setPageType');
$sutMock->expects($this->atLeastOnce())->method('setAuthnRegister');
$sutMock->expects($this->never())->method('getLoggerObject')->willReturn($loggerMock);
$sutMock->expects($this->never())->method('getUtilsObject')->willReturn($utilsMock);
$sutMock->expects($this->never())->method('d3GetLoggerObject')->willReturn($loggerMock);
$sutMock->expects($this->never())->method('d3GetUtilsObject')->willReturn($utilsMock);
$this->callMethod(
$sutMock,
@ -169,14 +169,14 @@ class d3user_webauthnTest extends TestCase
->onlyMethods([
'setPageType',
'setAuthnRegister',
'getLoggerObject',
'getUtilsObject'
'd3GetLoggerObject',
'd3GetUtilsObject'
])
->getMock();
$sutMock->expects($this->atLeastOnce())->method('setPageType');
$sutMock->expects($this->atLeastOnce())->method('setAuthnRegister')->willThrowException(oxNew(WebauthnException::class));
$sutMock->expects($this->atLeastOnce())->method('getLoggerObject')->willReturn($loggerMock);
$sutMock->expects($this->atLeastOnce())->method('getUtilsObject')->willReturn($utilsMock);
$sutMock->expects($this->atLeastOnce())->method('d3GetLoggerObject')->willReturn($loggerMock);
$sutMock->expects($this->atLeastOnce())->method('d3GetUtilsObject')->willReturn($utilsMock);
$this->callMethod(
$sutMock,
@ -207,10 +207,10 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods(['getUtilsViewObject', 'getLoggerObject'])
->onlyMethods(['d3GetUtilsViewObject', 'd3GetLoggerObject'])
->getMock();
$oControllerMock->method('getUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->expects($this->atLeastOnce())->method('getLoggerObject')->willReturn($loggerMock);
$oControllerMock->method('d3GetUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->expects($this->atLeastOnce())->method('d3GetLoggerObject')->willReturn($loggerMock);
$this->callMethod(
$oControllerMock,
@ -243,10 +243,10 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods(['getWebauthnObject', 'getUtilsViewObject'])
->onlyMethods(['d3GetWebauthnObject', 'd3GetUtilsViewObject'])
->getMock();
$oControllerMock->method('getWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('getUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('d3GetUtilsViewObject')->willReturn($utilsViewMock);
$this->callMethod(
$oControllerMock,
@ -285,11 +285,11 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods(['getWebauthnObject', 'getUtilsViewObject', 'getLoggerObject'])
->onlyMethods(['d3GetWebauthnObject', 'd3GetUtilsViewObject', 'd3GetLoggerObject'])
->getMock();
$oControllerMock->method('getWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('getUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('getLoggerObject')->willReturn($loggerMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('d3GetUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('d3GetLoggerObject')->willReturn($loggerMock);
$this->callMethod(
$oControllerMock,
@ -339,9 +339,9 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods(['getWebauthnObject', 'addTplParam', 'getUser'])
->onlyMethods(['d3GetWebauthnObject', 'addTplParam', 'getUser'])
->getMock();
$oControllerMock->method('getWebauthnObject')->willReturn($webAuthnMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webAuthnMock);
$oControllerMock->expects($throwExc ? $this->never() : $this->atLeast(3))
->method('addTplParam');
$oControllerMock->method('getUser')->willReturn(oxNew(User::class));
@ -391,10 +391,10 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods(['getUserObject', 'getPublicKeyCredentialListObject'])
->onlyMethods(['d3GetUserObject', 'd3GetPublicKeyCredentialListObject'])
->getMock();
$oControllerMock->method('getUserObject')->willReturn($oUser);
$oControllerMock->method('getPublicKeyCredentialListObject')->willReturn($publicKeyCredentialListMock);
$oControllerMock->method('d3GetUserObject')->willReturn($oUser);
$oControllerMock->method('d3GetPublicKeyCredentialListObject')->willReturn($publicKeyCredentialListMock);
$this->assertIsArray(
$this->callMethod(
@ -409,9 +409,9 @@ class d3user_webauthnTest extends TestCase
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3user_webauthn::getUserObject
* @covers \D3\Webauthn\Application\Controller\Admin\d3user_webauthn::d3GetUserObject
*/
public function getUserObjectReturnsRightInstance()
public function d3GetUserObjectReturnsRightInstance()
{
/** @var d3user_webauthn $sut */
$sut = oxNew(d3user_webauthn::class);
@ -420,7 +420,7 @@ class d3user_webauthnTest extends TestCase
User::class,
$this->callMethod(
$sut,
'getUserObject'
'd3GetUserObject'
)
);
}
@ -445,9 +445,9 @@ class d3user_webauthnTest extends TestCase
/** @var d3user_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3user_webauthn::class)
->onlyMethods(['getPublicKeyCredentialObject'])
->onlyMethods(['d3GetPublicKeyCredentialObject'])
->getMock();
$oControllerMock->method('getPublicKeyCredentialObject')->willReturn($publicKeyCredentialMock);
$oControllerMock->method('d3GetPublicKeyCredentialObject')->willReturn($publicKeyCredentialMock);
$this->callMethod($oControllerMock, 'deleteKey');
}
@ -466,7 +466,7 @@ class d3user_webauthnTest extends TestCase
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3user_webauthn::getUtilsObject
* @covers \D3\Webauthn\Application\Controller\Admin\d3user_webauthn::d3GetUtilsObject
*/
public function getUtilsObjectReturnsRightInstance()
{
@ -476,7 +476,7 @@ class d3user_webauthnTest extends TestCase
Utils::class,
$this->callMethod(
$sut,
'getUtilsObject'
'd3GetUtilsObject'
)
);
}

View File

@ -0,0 +1,138 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Application\Controller\Admin;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin;
use D3\Webauthn\tests\unit\Application\Controller\d3webauthnloginTest;
use ReflectionException;
class d3webauthnadminloginTest extends d3webauthnloginTest
{
use CanAccessRestricted;
protected $sutClassName = d3webauthnadminlogin::class;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::_authorize
*/
public function canAuthorize()
{
$sut = oxNew(d3webauthnadminlogin::class);
$this->assertTrue(
$this->callMethod(
$sut,
'_authorize'
)
);
}
/**
* @return void
*/
public function canGetNavigationParams()
{}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::render
* @dataProvider canRenderDataProvider
*/
public function canRender($auth, $userFromLogin, $startRedirect, $redirectController = 'admin_start')
{
parent::canRender($auth, $userFromLogin, $startRedirect, 'admin_start');
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::generateCredentialRequest
*/
public function canGenerateCredentialRequest()
{
parent::canGenerateCredentialRequest();
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::generateCredentialRequest
*/
public function generateCredentialRequestFailed($redirectClass = 'login')
{
parent::generateCredentialRequestFailed($redirectClass);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::getUtils
*/
public function getUtilsReturnsRightInstance()
{
parent::getUtilsReturnsRightInstance();
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::getPreviousClass
*/
public function canGetPreviousClass()
{
parent::canGetPreviousClass();
}
/**
* @test
* @param $currClass
* @param $isOrderStep
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::previousClassIsOrderStep
* @dataProvider canPreviousClassIsOrderStepDataProvider
*/
public function canPreviousClassIsOrderStep($currClass, $isOrderStep)
{
parent::canPreviousClassIsOrderStep($currClass, $isOrderStep);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\Admin\d3webauthnadminlogin::getIsOrderStep
* @dataProvider canGetIsOrderStepDataProvider
*/
public function canGetIsOrderStep($boolean)
{
parent::canGetIsOrderStep($boolean);
}
public function canGetBreadCrumb()
{
}
}

View File

@ -11,7 +11,7 @@
* @link https://www.oxidmodule.com
*/
namespace D3\Totp\tests\unit\Application\Controller;
namespace D3\Webauthn\tests\unit\Application\Controller;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Controller\d3_account_webauthn;
@ -77,10 +77,10 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getUser', 'getWebauthnObject'])
->onlyMethods(['getUser', 'd3GetWebauthnObject'])
->getMock();
$oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getWebauthnObject')->willReturn($webAuthnMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webAuthnMock);
$this->_oController = $oControllerMock;
@ -109,10 +109,10 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getUser', 'getWebauthnObject'])
->onlyMethods(['getUser', 'd3GetWebauthnObject'])
->getMock();
$oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getWebauthnObject')->willReturn($webAuthnMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webAuthnMock);
$this->_oController = $oControllerMock;
@ -147,10 +147,10 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getUser', 'getPublicKeyCredentialListObject'])
->onlyMethods(['getUser', 'd3GetPublicKeyCredentialListObject'])
->getMock();
$oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getPublicKeyCredentialListObject')->willReturn($publicKeyCredentialListMock);
$oControllerMock->method('d3GetPublicKeyCredentialListObject')->willReturn($publicKeyCredentialListMock);
$this->_oController = $oControllerMock;
@ -186,12 +186,12 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['setAuthnRegister', 'setPageType', 'getUser', 'getLoggerObject'])
->onlyMethods(['setAuthnRegister', 'setPageType', 'getUser', 'd3GetLoggerObject'])
->getMock();
$oControllerMock->expects($this->atLeastOnce())->method('setAuthnRegister');
$oControllerMock->expects($this->atLeastOnce())->method('setPageType');
$oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getLoggerObject')->willReturn($loggerMock);
$oControllerMock->method('d3GetLoggerObject')->willReturn($loggerMock);
$this->_oController = $oControllerMock;
@ -224,13 +224,13 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['setAuthnRegister', 'setPageType', 'getUser', 'getLoggerObject'])
->onlyMethods(['setAuthnRegister', 'setPageType', 'getUser', 'd3GetLoggerObject'])
->getMock();
$oControllerMock->expects($this->atLeastOnce())->method('setAuthnRegister')
->willThrowException(oxNew(WebauthnException::class));
$oControllerMock->expects($this->never())->method('setPageType');
$oControllerMock->method('getUser')->willReturn($oUser);
$oControllerMock->method('getLoggerObject')->willReturn($loggerMock);
$oControllerMock->method('d3GetLoggerObject')->willReturn($loggerMock);
$this->_oController = $oControllerMock;
@ -262,9 +262,9 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getWebauthnObject', 'addTplParam', 'getUser'])
->onlyMethods(['d3GetWebauthnObject', 'addTplParam', 'getUser'])
->getMock();
$oControllerMock->method('getWebauthnObject')->willReturn($webAuthnMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webAuthnMock);
$oControllerMock->expects($throwExc ? $this->never() : $this->atLeast(3))
->method('addTplParam');
$oControllerMock->method('getUser')->willReturn(oxNew(User::class));
@ -341,10 +341,10 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getUtilsViewObject', 'getLoggerObject'])
->onlyMethods(['d3GetUtilsViewObject', 'd3GetLoggerObject'])
->getMock();
$oControllerMock->method('getUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('getLoggerObject')->willReturn($loggerMock);
$oControllerMock->method('d3GetUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('d3GetLoggerObject')->willReturn($loggerMock);
$this->_oController = $oControllerMock;
@ -379,10 +379,10 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getWebauthnObject', 'getUtilsViewObject'])
->onlyMethods(['d3GetWebauthnObject', 'd3GetUtilsViewObject'])
->getMock();
$oControllerMock->method('getWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('getUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('d3GetUtilsViewObject')->willReturn($utilsViewMock);
$this->_oController = $oControllerMock;
@ -418,10 +418,10 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getWebauthnObject', 'getUtilsViewObject'])
->onlyMethods(['d3GetWebauthnObject', 'd3GetUtilsViewObject'])
->getMock();
$oControllerMock->method('getWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('getUtilsViewObject')->willReturn($utilsViewMock);
$oControllerMock->method('d3GetWebauthnObject')->willReturn($webauthnMock);
$oControllerMock->method('d3GetUtilsViewObject')->willReturn($utilsViewMock);
$this->_oController = $oControllerMock;
@ -451,9 +451,9 @@ class d3_account_webauthnTest extends UnitTestCase
/** @var d3_account_webauthn|MockObject $oControllerMock */
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
->onlyMethods(['getPublicKeyCredentialObject'])
->onlyMethods(['d3GetPublicKeyCredentialObject'])
->getMock();
$oControllerMock->method('getPublicKeyCredentialObject')->willReturn($publicKeyCredentialMock);
$oControllerMock->method('d3GetPublicKeyCredentialObject')->willReturn($publicKeyCredentialMock);
$this->_oController = $oControllerMock;
@ -490,23 +490,7 @@ class d3_account_webauthnTest extends UnitTestCase
/**
* @test
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getWebauthnObject
*/
public function getWebauthnObjectReturnsRightObject()
{
$this->assertInstanceOf(
Webauthn::class,
$this->callMethod(
$this->_oController,
'getWebauthnObject'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getPublicKeyCredentialObject
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::d3GetPublicKeyCredentialObject
*/
public function getPublicKeyCredentialObjectReturnsRightObject()
{
@ -514,7 +498,7 @@ class d3_account_webauthnTest extends UnitTestCase
PublicKeyCredential::class,
$this->callMethod(
$this->_oController,
'getPublicKeyCredentialObject'
'd3GetPublicKeyCredentialObject'
)
);
}
@ -522,7 +506,7 @@ class d3_account_webauthnTest extends UnitTestCase
/**
* @test
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getPublicKeyCredentialListObject
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::d3GetPublicKeyCredentialListObject
*/
public function getPublicKeyCredentialListObjectReturnsRightObject()
{
@ -530,7 +514,7 @@ class d3_account_webauthnTest extends UnitTestCase
PublicKeyCredentialList::class,
$this->callMethod(
$this->_oController,
'getPublicKeyCredentialListObject'
'd3GetPublicKeyCredentialListObject'
)
);
}
@ -538,23 +522,7 @@ class d3_account_webauthnTest extends UnitTestCase
/**
* @test
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getLoggerObject
*/
public function getLoggerObjectReturnsRightObject()
{
$this->assertInstanceOf(
LoggerInterface::class,
$this->callMethod(
$this->_oController,
'getLoggerObject'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getUtilsViewObject
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::d3GetUtilsViewObject
*/
public function getUtilsViewObjectReturnsRightObject()
{
@ -562,7 +530,7 @@ class d3_account_webauthnTest extends UnitTestCase
UtilsView::class,
$this->callMethod(
$this->_oController,
'getUtilsViewObject'
'd3GetUtilsViewObject'
)
);
}

View File

@ -1,6 +1,19 @@
<?php
namespace D3\Totp\tests\unit\Application\Controller;
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\Webauthn\tests\unit\Application\Controller;
use D3\TestingTools\Development\CanAccessRestricted;
use D3\Webauthn\Application\Controller\d3webauthnlogin;
@ -19,21 +32,7 @@ class d3webauthnloginTest extends TestCase
{
use CanAccessRestricted;
/** @var d3webauthnlogin */
protected $subjectUnderTest;
public function setUp(): void
{
parent::setUp();
$this->subjectUnderTest = oxNew(d3webauthnlogin::class);
}
public function tearDown(): void
{
parent::tearDown();
unset($this->subjectUnderTest);
}
protected $sutClassName = d3webauthnlogin::class;
/**
* @test
@ -52,7 +51,7 @@ class d3webauthnloginTest extends TestCase
]);
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['d3GetSession', 'd3CallMockableParent'])
->getMock();
$sut->method('d3GetSession')->willReturn($sessionMock);
@ -81,7 +80,7 @@ class d3webauthnloginTest extends TestCase
* @covers \D3\Webauthn\Application\Controller\d3webauthnlogin::render
* @dataProvider canRenderDataProvider
*/
public function canRender($auth, $userFromLogin, $startRedirect)
public function canRender($auth, $userFromLogin, $startRedirect, $redirectController = 'start')
{
/** @var Session|MockObject $sessionMock */
$sessionMock = $this->getMockBuilder(Session::class)
@ -97,23 +96,23 @@ class d3webauthnloginTest extends TestCase
->onlyMethods(['redirect'])
->getMock();
$utilsMock->expects($startRedirect ? $this->once() : $this->never())
->method('redirect')->with('index.php?cl=start')->willReturn(true);
->method('redirect')->with('index.php?cl='.$redirectController)->willReturn(true);
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['d3GetSession', 'getUtils', 'd3CallMockableParent',
'generateCredentialRequest', 'addTplParam'])
->getMock();
$sut->method('d3GetSession')->willReturn($sessionMock);
$sut->method('getUtils')->willReturn($utilsMock);
$sut->method('d3CallMockableParent')->willReturn(['defKey1' => 'devValues1']);
$sut->method('d3CallMockableParent')->willReturn('myTemplate.tpl');
$sut->expects($startRedirect ? $this->any() : $this->atLeastOnce())
->method('generateCredentialRequest');
$sut->expects($startRedirect ? $this->any() : $this->atLeastOnce())
->method('addTplParam')->with('navFormParams')->willReturn(true);
$this->assertSame(
'd3webauthnlogin.tpl',
'myTemplate.tpl',
$this->callMethod(
$sut,
'render'
@ -164,14 +163,14 @@ class d3webauthnloginTest extends TestCase
->willReturn('success');
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
->onlyMethods(['d3GetSession', 'd3GetWebauthnObject', 'addTplParam', 'd3GetLogger'])
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['d3GetSession', 'd3GetWebauthnObject', 'addTplParam', 'd3GetLoggerObject'])
->getMock();
$sut->method('d3GetSession')->willReturn($sessionMock);
$sut->method('d3GetWebauthnObject')->willReturn($webAuthnMock);
$sut->expects($this->atLeast(2))
->method('addTplParam')->willReturn(true);
$sut->method('d3GetLogger')->willReturn($loggerMock);
$sut->method('d3GetLoggerObject')->willReturn($loggerMock);
$this->callMethod(
$sut,
@ -185,7 +184,7 @@ class d3webauthnloginTest extends TestCase
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3webauthnlogin::generateCredentialRequest
*/
public function generateCredentialRequestFailed()
public function generateCredentialRequestFailed($redirectClass = 'start')
{
$currUserFixture = 'currentUserFixture';
@ -216,18 +215,18 @@ class d3webauthnloginTest extends TestCase
->onlyMethods(['redirect'])
->getMock();
$utilsMock->expects($this->once())->method('redirect')
->with('index.php?cl=start')->willReturn(true);
->with('index.php?cl='.$redirectClass)->willReturn(true);
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['d3GetSession', 'd3GetWebauthnObject', 'addTplParam',
'd3GetLogger', 'getUtils'])
'd3GetLoggerObject', 'getUtils'])
->getMock();
$sut->method('d3GetSession')->willReturn($sessionMock);
$sut->method('d3GetWebauthnObject')->willReturn($webAuthnMock);
$sut->expects($this->never())
->method('addTplParam')->willReturn(true);
$sut->expects($this->atLeast(2))->method('d3GetLogger')->willReturn($loggerMock);
$sut->expects($this->atLeast(2))->method('d3GetLoggerObject')->willReturn($loggerMock);
$sut->method('getUtils')->willReturn($utilsMock);
$this->callMethod(
@ -244,10 +243,12 @@ class d3webauthnloginTest extends TestCase
*/
public function getUtilsReturnsRightInstance()
{
$sut = oxNew($this->sutClassName);
$this->assertInstanceOf(
Utils::class,
$this->callMethod(
$this->subjectUnderTest,
$sut,
'getUtils'
)
);
@ -272,7 +273,7 @@ class d3webauthnloginTest extends TestCase
]);
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['d3GetSession'])
->getMock();
$sut->method('d3GetSession')->willReturn($sessionMock);
@ -306,7 +307,7 @@ class d3webauthnloginTest extends TestCase
]);
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['d3GetSession'])
->getMock();
$sut->method('d3GetSession')->willReturn($sessionMock);
@ -342,7 +343,7 @@ class d3webauthnloginTest extends TestCase
public function canGetIsOrderStep($boolean)
{
/** @var d3webauthnlogin|MockObject $sut */
$sut = $this->getMockBuilder(d3webauthnlogin::class)
$sut = $this->getMockBuilder($this->sutClassName)
->onlyMethods(['previousClassIsOrderStep'])
->getMock();
$sut->expects($this->atLeastOnce())->method('previousClassIsOrderStep')->willReturn($boolean);
@ -375,9 +376,11 @@ class d3webauthnloginTest extends TestCase
*/
public function canGetBreadCrumb()
{
$sut = oxNew($this->sutClassName);
$this->assertIsArray(
$this->callMethod(
$this->subjectUnderTest,
$sut,
'getBreadCrumb'
)
);
@ -391,10 +394,12 @@ class d3webauthnloginTest extends TestCase
*/
public function canGetSession()
{
$sut = oxNew($this->sutClassName);
$this->assertInstanceOf(
Session::class,
$this->callMethod(
$this->subjectUnderTest,
$sut,
'd3GetSession'
)
);
@ -408,10 +413,12 @@ class d3webauthnloginTest extends TestCase
*/
public function canGetWebauthnObject()
{
$sut = oxNew($this->sutClassName);
$this->assertInstanceOf(
Webauthn::class,
$this->callMethod(
$this->subjectUnderTest,
$sut,
'd3GetWebauthnObject'
)
);
@ -421,15 +428,17 @@ class d3webauthnloginTest extends TestCase
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3webauthnlogin::d3GetLogger
* @covers \D3\Webauthn\Application\Controller\d3webauthnlogin::d3GetLoggerObject
*/
public function canGetLogger()
{
$sut = oxNew($this->sutClassName);
$this->assertInstanceOf(
LoggerInterface::class,
$this->callMethod(
$this->subjectUnderTest,
'd3GetLogger'
$sut,
'd3GetLoggerObject'
)
);
}
@ -438,15 +447,17 @@ class d3webauthnloginTest extends TestCase
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Webauthn\Application\Controller\d3webauthnlogin::getControllerClassNameResolver
* @covers \D3\Webauthn\Application\Controller\d3webauthnlogin::d3GetControllerClassNameResolver
*/
public function canGetClassNameResolver()
{
$sut = oxNew($this->sutClassName);
$this->assertInstanceOf(
ControllerClassNameResolver::class,
$this->callMethod(
$this->subjectUnderTest,
'getControllerClassNameResolver'
$sut,
'd3GetControllerClassNameResolver'
)
);
}