Compare commits
82 Commits
rel_1.x
...
dev_3.x_OX
Author | SHA1 | Date | |
---|---|---|---|
be4990f7f7 | |||
1251095eb3
|
|||
fedd03a66e | |||
a0090ab3bb | |||
be1f482aba | |||
30e13cb0dc
|
|||
ceaa9daf90
|
|||
e509aa7eff
|
|||
12d47d14f0
|
|||
f8f488f7a2
|
|||
bef6651a3f
|
|||
f43eb2584a
|
|||
faf08ed786
|
|||
b2ba738b05 | |||
5d4f29988e | |||
0b0f15605f
|
|||
f23bd1339c
|
|||
90013b3832
|
|||
49e54d6866
|
|||
95aa47fa09
|
|||
048057e40b
|
|||
e6cb61e023
|
|||
209b05e347
|
|||
55ed6a1568
|
|||
cfde971a0e
|
|||
79fb841b37 | |||
d93e1517aa | |||
5ee8e18e89 | |||
bedb60928d | |||
43e8291bf9
|
|||
ed06705c40
|
|||
9f6b689a56
|
|||
0adcec6df2
|
|||
c85b944e00
|
|||
6dc3c82fa3
|
|||
ec4e86c5f8
|
|||
957d1cfc7c
|
|||
24d1cd6688
|
|||
5a69d23db2
|
|||
52d4b48849
|
|||
b9db9e601d
|
|||
b18196613e
|
|||
0dc6c49e0b
|
|||
c13b1e04a0
|
|||
f14ce58d6e
|
|||
a9a279a753
|
|||
7a2648fe7b
|
|||
a3c75df635
|
|||
a809c04b5b
|
|||
77eca02079
|
|||
331a05b080
|
|||
c5d9fea2fe
|
|||
c86984df5f
|
|||
749c654b4e
|
|||
46ae7efa32
|
|||
d8be836ed7
|
|||
d7912f6371
|
|||
4edfa2d3c3
|
|||
12bb6355ee
|
|||
42bab2bd25
|
|||
e65c2e7acb
|
|||
be69ed889e
|
|||
222b7b345a
|
|||
3327fc9242
|
|||
02f2f6a843
|
|||
e3d2156d44
|
|||
c80b5f626f
|
|||
f110142474
|
|||
e8a069a63b
|
|||
4691b7d0c0
|
|||
4e8bae08e7
|
|||
ecb8b61923
|
|||
8e0480898a
|
|||
f0275c1bc9
|
|||
de75b77562
|
|||
9c4e7cfcc3
|
|||
7be2c32cf5
|
|||
337107fe52
|
|||
3f77b212b4
|
|||
3095d8d39b
|
|||
47c1f30d7c
|
|||
8b63d67a78
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
Tests/.phpunit.result.cache
|
||||
Tests/reports/
|
||||
.php_cs.cache
|
42
.php-cs-fixer.php
Normal file
42
.php-cs-fixer.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?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);
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()
|
||||
->in(__DIR__)
|
||||
;
|
||||
|
||||
$fileHeaderComment = <<<EOF
|
||||
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
|
||||
EOF;
|
||||
|
||||
$config = new PhpCsFixer\Config();
|
||||
return $config->setRules([
|
||||
'header_comment' => [
|
||||
'header' => $fileHeaderComment,
|
||||
'comment_type' => 'PHPDoc',
|
||||
'location' => 'after_open'
|
||||
],
|
||||
'@PHP80Migration' => true,
|
||||
'@PSR12' => true
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
80
Application/Controller/Admin/d3force_2fa.php
Normal file
80
Application/Controller/Admin/d3force_2fa.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?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\Totp\Application\Controller\Admin;
|
||||
|
||||
use D3\Totp\Application\Model\Constants;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleSettingNotFountException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3force_2fa extends d3user_totp
|
||||
{
|
||||
public function render(): string
|
||||
{
|
||||
$this->addTplParam('force2FA', true);
|
||||
|
||||
$userID = $this->d3TotpGetSessionObject()->getVariable(d3totp_conf::OXID_ADMIN_AUTH);
|
||||
$this->_sEditObjectId = $userID;
|
||||
|
||||
return parent::render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ModuleSettingNotFountException
|
||||
*/
|
||||
protected function authorize(): bool
|
||||
{
|
||||
$userID = $this->d3TotpGetSessionObject()->getVariable(d3totp_conf::OXID_ADMIN_AUTH);
|
||||
|
||||
return ($this->d3IsAdminForce2FA() && !empty($userID));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
private function d3TotpGetSessionObject(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ModuleSettingNotFountException
|
||||
*/
|
||||
private function d3IsAdminForce2FA(): bool
|
||||
{
|
||||
if (!$this->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->getModuleConfiguration()->getModuleSetting('D3_TOTP_ADMIN_FORCE_2FA')->getValue();
|
||||
}
|
||||
|
||||
protected function getModuleConfiguration(): ModuleConfiguration
|
||||
{
|
||||
$container = ContainerFactory::getInstance()->getContainer();
|
||||
$moduleConfigurationBridge = $container->get(ModuleConfigurationDaoBridgeInterface::class);
|
||||
/** @var ModuleConfiguration $moduleConfiguration */
|
||||
return $moduleConfigurationBridge->get(Constants::OXID_MODULE_ID);
|
||||
}
|
||||
}
|
255
Application/Controller/Admin/d3totpadminlogin.php
Normal file
255
Application/Controller/Admin/d3totpadminlogin.php
Normal file
@ -0,0 +1,255 @@
|
||||
<?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\Totp\Application\Controller\Admin;
|
||||
|
||||
use D3\Totp\Application\Model\Constants;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class d3totpadminlogin extends AdminController
|
||||
{
|
||||
protected $_sThisTemplate = '@'.Constants::OXID_MODULE_ID.'/admin/d3totplogin';
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3TotpGetTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
* @throws DBALException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function isTotpIsNotRequired(): bool
|
||||
{
|
||||
/** @var d3_totp_user $user */
|
||||
$user = $this->d3TotpGetUserObject();
|
||||
$userId = $user->d3TotpGetCurrentUser();
|
||||
|
||||
$totp = $this->d3TotpGetTotpObject();
|
||||
$totp->loadByUserId($userId);
|
||||
|
||||
return $this->d3TotpGetSession()->hasVariable(d3totp_conf::SESSION_ADMIN_AUTH) ||
|
||||
!$totp->isActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isTotpLoginNotPossible(): bool
|
||||
{
|
||||
$user = $this->d3TotpGetUserObject();
|
||||
return !$user->d3TotpGetCurrentUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
if ($this->isTotpLoginNotPossible()) {
|
||||
$this->d3TotpGetUtils()->redirect('index.php?cl=login', false);
|
||||
} elseif ($this->isTotpIsNotRequired()) {
|
||||
$this->d3TotpGetUtils()->redirect('index.php?cl=admin_start', false);
|
||||
}
|
||||
|
||||
$this->addTplParam('selectedProfile', Registry::getRequest()->getRequestEscapedParameter('profile'));
|
||||
$this->addTplParam('selectedChLanguage', Registry::getRequest()->getRequestEscapedParameter('chlanguage'));
|
||||
|
||||
/** @var d3_totp_LoginController $loginController */
|
||||
$loginController = $this->d3GetLoginController();
|
||||
$loginController->d3totpAfterLoginSetLanguage();
|
||||
|
||||
return parent::render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcodelist
|
||||
*/
|
||||
public function d3GetBackupCodeListObject(): d3backupcodelist
|
||||
{
|
||||
return oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function getBackupCodeCountMessage()
|
||||
{
|
||||
/** @var d3_totp_user $user */
|
||||
$user = $this->d3TotpGetUserObject();
|
||||
$userId = $user->d3TotpGetCurrentUser();
|
||||
|
||||
$oBackupCodeList = $this->d3GetBackupCodeListObject();
|
||||
$iCount = $oBackupCodeList->getAvailableCodeCount($userId);
|
||||
|
||||
if ($iCount < 4) {
|
||||
return sprintf(
|
||||
Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT'),
|
||||
$iCount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function d3CancelLogin(): string
|
||||
{
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = $this->d3TotpGetUserObject();
|
||||
$oUser->logout();
|
||||
return "login";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3_totp_user
|
||||
*/
|
||||
public function d3TotpGetUserObject(): User
|
||||
{
|
||||
/** @var d3_totp_user $user */
|
||||
$user = oxNew(User::class);
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function checklogin()
|
||||
{
|
||||
$session = $this->d3TotpGetSession();
|
||||
/** @var d3_totp_user $user */
|
||||
$user = $this->d3TotpGetUserObject();
|
||||
$userId = $user->d3TotpGetCurrentUser();
|
||||
|
||||
try {
|
||||
$sTotp = implode('', Registry::getRequest()->getRequestEscapedParameter('d3totp') ?: []);
|
||||
|
||||
$totp = $this->d3TotpGetTotpObject();
|
||||
$totp->loadByUserId($userId);
|
||||
|
||||
$this->d3TotpHasValidTotp($sTotp, $totp);
|
||||
|
||||
$selectedProfile = Registry::getRequest()->getRequestEscapedParameter('profile');
|
||||
$selectedLanguage = Registry::getRequest()->getRequestEscapedParameter('chlanguage');
|
||||
|
||||
$session->initNewSession();
|
||||
$session->setVariable(d3totp_conf::SESSION_ADMIN_PROFILE, $selectedProfile);
|
||||
$session->setVariable(d3totp_conf::SESSION_ADMIN_CHLANGUAGE, $selectedLanguage);
|
||||
$session->setVariable(d3totp_conf::OXID_ADMIN_AUTH, $userId);
|
||||
$session->setVariable(d3totp_conf::SESSION_ADMIN_AUTH, $userId);
|
||||
$session->deleteVariable(d3totp_conf::SESSION_ADMIN_CURRENTUSER);
|
||||
|
||||
/** @var d3_totp_LoginController $loginController */
|
||||
$loginController = $this->d3GetLoginController();
|
||||
$loginController->d3totpAfterLogin();
|
||||
|
||||
return "admin_start";
|
||||
} catch (d3totp_wrongOtpException $e) {
|
||||
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||
$this->getLogger()->error($e->getMessage(), ['UserId' => $userId]);
|
||||
$this->getLogger()->debug($e->getTraceAsString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTotp
|
||||
* @param d3totp $totp
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws d3totp_wrongOtpException
|
||||
*/
|
||||
public function d3TotpHasValidTotp(string $sTotp, d3totp $totp): bool
|
||||
{
|
||||
return $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_AUTH)
|
||||
|| $totp->verify($sTotp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Utils
|
||||
*/
|
||||
public function d3TotpGetUtils(): Utils
|
||||
{
|
||||
return Registry::getUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSession(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger(): LoggerInterface
|
||||
{
|
||||
return Registry::getLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoginController
|
||||
*/
|
||||
public function d3GetLoginController(): LoginController
|
||||
{
|
||||
return oxNew(LoginController::class);
|
||||
}
|
||||
}
|
@ -1,49 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
* 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 <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Controller\Admin;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\Totp\Application\Controller\OtpManagementControllerTrait;
|
||||
use D3\Totp\Application\Model\Constants;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3user_totp extends AdminDetailsController
|
||||
{
|
||||
protected $_sSaveError = null;
|
||||
use OtpManagementControllerTrait;
|
||||
|
||||
protected $_sThisTemplate = 'd3user_totp.tpl';
|
||||
protected null|string $_sSaveError = null;
|
||||
|
||||
public $aBackupCodes = [];
|
||||
protected $_sThisTemplate = '@'.Constants::OXID_MODULE_ID.'/admin/d3user_totp';
|
||||
|
||||
public array $aBackupCodes = [];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
parent::render();
|
||||
|
||||
$soxId = $this->getEditObjectId();
|
||||
|
||||
if (isset($soxId) && $soxId != "-1") {
|
||||
if ($soxId && $soxId != "-1") {
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = $this->getUserObject();
|
||||
if ($oUser->load($soxId)) {
|
||||
@ -64,52 +70,43 @@ class d3user_totp extends AdminDetailsController
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUserObject()
|
||||
public function getUserObject(): User
|
||||
{
|
||||
return oxNew(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
* @throws DBALDriverException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getTotpObject()
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcodelist
|
||||
*/
|
||||
public function getBackupcodeListObject()
|
||||
{
|
||||
return oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
parent::save();
|
||||
|
||||
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
|
||||
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval") ?? [];
|
||||
|
||||
try {
|
||||
/** @var d3totp $oTotp */
|
||||
$oTotp = $this->getTotpObject();
|
||||
if ($oTotp->checkIfAlreadyExist($this->getEditObjectId())) {
|
||||
$oException = oxNew(StandardException::class, 'D3_TOTP_ALREADY_EXIST');
|
||||
throw $oException;
|
||||
};
|
||||
|
||||
Assert::that($oTotp->checkIfAlreadyExist($this->getCurrentUserId()))->false('D3_TOTP_ALREADY_EXIST');
|
||||
|
||||
$oTotpBackupCodes = $this->getBackupcodeListObject();
|
||||
if ($aParams['d3totp__oxid']) {
|
||||
if (isset($aParams['d3totp__oxid'])) {
|
||||
$oTotp->load($aParams['d3totp__oxid']);
|
||||
} else {
|
||||
$aParams['d3totp__usetotp'] = 1;
|
||||
$seed = Registry::getRequest()->getRequestEscapedParameter("secret");
|
||||
/** @var d3totp $init */
|
||||
$init = Registry::getSession()->getVariable(d3totp_conf::OTP_SESSION_VARNAME);
|
||||
Assert::that($init)->isInstanceOf(d3totp::class, 'D3_TOTP_INITOBJECT_MISSING');
|
||||
$seed = $init->getSecret();
|
||||
$otp = Registry::getRequest()->getRequestEscapedParameter("otp");
|
||||
|
||||
Assert::that($seed)->notBlank('D3_TOTP_EMPTY_SEED');
|
||||
Assert::that($otp)
|
||||
->integerish('D3_TOTP_MISSING_VALIDATION')
|
||||
->length(6, 'D3_TOTP_MISSING_VALIDATION');
|
||||
|
||||
$oTotp->saveSecret($seed);
|
||||
$oTotp->assign($aParams);
|
||||
$oTotp->verify($otp, $seed);
|
||||
@ -118,19 +115,19 @@ class d3user_totp extends AdminDetailsController
|
||||
}
|
||||
$oTotp->save();
|
||||
$oTotpBackupCodes->save();
|
||||
} catch (Exception $oExcp) {
|
||||
$this->_sSaveError = $oExcp->getMessage();
|
||||
} catch (Exception $exception) {
|
||||
$this->_sSaveError = $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DatabaseConnectionException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
$aParams = Registry::getRequest()->getRequestEscapedParameter("editval");
|
||||
|
||||
/** @var d3totp $oTotp */
|
||||
$oTotp = $this->getTotpObject();
|
||||
if ($aParams['d3totp__oxid']) {
|
||||
$oTotp->load($aParams['d3totp__oxid']);
|
||||
@ -139,29 +136,8 @@ class d3user_totp extends AdminDetailsController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $aCodes
|
||||
*/
|
||||
public function setBackupCodes($aCodes)
|
||||
public function getCurrentUserId(): string
|
||||
{
|
||||
$this->aBackupCodes = $aCodes;
|
||||
return $this->getEditObjectId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBackupCodes()
|
||||
{
|
||||
return implode(PHP_EOL, $this->aBackupCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws DatabaseConnectionException
|
||||
*/
|
||||
public function getAvailableBackupCodeCount()
|
||||
{
|
||||
$oBackupCodeList = $this->getBackupcodeListObject();
|
||||
return $oBackupCodeList->getAvailableCodeCount($this->getEditObjectId());
|
||||
}
|
||||
}
|
||||
}
|
70
Application/Controller/OtpManagementControllerTrait.php
Normal file
70
Application/Controller/OtpManagementControllerTrait.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?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\Totp\Application\Controller;
|
||||
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait OtpManagementControllerTrait
|
||||
{
|
||||
/**
|
||||
* @param array $aCodes
|
||||
*/
|
||||
public function setBackupCodes(array $aCodes): void
|
||||
{
|
||||
$this->aBackupCodes = $aCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBackupCodes(): string
|
||||
{
|
||||
return implode(PHP_EOL, $this->aBackupCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcodelist
|
||||
*/
|
||||
public function getBackupCodeListObject(): d3backupcodelist
|
||||
{
|
||||
return oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws Exception
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getAvailableBackupCodeCount(): int
|
||||
{
|
||||
$oBackupCodeList = $this->getBackupCodeListObject();
|
||||
return $oBackupCodeList->getAvailableCodeCount($this->getCurrentUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function getTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
}
|
116
Application/Controller/d3_account_totp.php
Normal file
116
Application/Controller/d3_account_totp.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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\Totp\Application\Controller;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\Totp\Application\Model\Constants;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Controller\AccountController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3_account_totp extends AccountController
|
||||
{
|
||||
use OtpManagementControllerTrait;
|
||||
|
||||
protected $_sThisTemplate = '@'.Constants::OXID_MODULE_ID.'/tpl/d3_account_totp';
|
||||
|
||||
public array $aBackupCodes = [];
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
$sRet = parent::render();
|
||||
|
||||
$this->addTplParam('user', $this->getUser());
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
|
||||
public function getCurrentUserId(): string
|
||||
{
|
||||
return $this->getUser()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Doctrine\DBAL\Driver\Exception
|
||||
*/
|
||||
public function create(): void
|
||||
{
|
||||
if (Registry::getRequest()->getRequestEscapedParameter('totp_use') === '1') {
|
||||
try {
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = $this->getUser();
|
||||
$oTotp = $this->getTotpObject();
|
||||
|
||||
Assert::that($oTotp->checkIfAlreadyExist($this->getCurrentUserId()))->false('D3_TOTP_ALREADY_EXIST');
|
||||
|
||||
$oTotpBackupCodes = $this->getBackupCodeListObject();
|
||||
|
||||
$aParams = [
|
||||
'd3totp__usetotp' => 1,
|
||||
'd3totp__oxuserid' => $oUser->getId(),
|
||||
];
|
||||
/** @var d3totp $init */
|
||||
$init = Registry::getSession()->getVariable(d3totp_conf::OTP_SESSION_VARNAME);
|
||||
$seed = $init->getSecret();
|
||||
$otp = Registry::getRequest()->getRequestEscapedParameter("otp");
|
||||
|
||||
Assert::that($seed)->notBlank('D3_TOTP_EMPTY_SEED');
|
||||
Assert::that($otp)
|
||||
->integerish('D3_TOTP_MISSING_VALIDATION')
|
||||
->length(6, 'D3_TOTP_MISSING_VALIDATION');
|
||||
|
||||
$oTotp->saveSecret($seed);
|
||||
$oTotp->assign($aParams);
|
||||
$oTotp->verify($otp, $seed);
|
||||
$oTotpBackupCodes->generateBackupCodes($oUser->getId());
|
||||
$oTotp->setId();
|
||||
|
||||
$oTotp->save();
|
||||
$oTotpBackupCodes->save();
|
||||
} catch (Exception $oExcp) {
|
||||
Registry::get(UtilsView::class)->addErrorToDisplay($oExcp->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Doctrine\DBAL\Driver\Exception
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function delete(): void
|
||||
{
|
||||
if (Registry::getRequest()->getRequestEscapedParameter('totp_use') !== '1') {
|
||||
$oUser = $this->getUser();
|
||||
$oTotp = $this->getTotpObject();
|
||||
if ($oUser instanceof User && $oUser->getId()) {
|
||||
$oTotp->loadByUserId($oUser->getId());
|
||||
$oTotp->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
121
Application/Controller/d3totplogin.php
Normal file
121
Application/Controller/d3totplogin.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?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\Totp\Application\Controller;
|
||||
|
||||
use D3\Totp\Application\Model\Constants;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3totplogin extends FrontendController
|
||||
{
|
||||
protected $_sThisTemplate = '@'.Constants::OXID_MODULE_ID.'/tpl/d3totplogin';
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
if (!Registry::getSession()->hasVariable(d3totp_conf::SESSION_CURRENTUSER)) {
|
||||
$this->getUtils()->redirect('index.php?cl=start', false);
|
||||
}
|
||||
|
||||
$this->addTplParam('navFormParams', Registry::getSession()->getVariable(d3totp_conf::SESSION_NAVFORMPARAMS));
|
||||
|
||||
return parent::render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Utils
|
||||
*/
|
||||
public function getUtils(): Utils
|
||||
{
|
||||
return Registry::getUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|void
|
||||
* @throws Exception
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getBackupCodeCountMessage()
|
||||
{
|
||||
$oBackupCodeList = $this->getBackupCodeListObject();
|
||||
$userId = Registry::getSession()->getVariable(d3totp_conf::SESSION_CURRENTUSER);
|
||||
$iCount = $oBackupCodeList->getAvailableCodeCount($userId);
|
||||
|
||||
if ($iCount < 4) {
|
||||
return sprintf(
|
||||
Registry::getLang()->translateString('D3_TOTP_AVAILBACKUPCODECOUNT', null, true),
|
||||
$iCount
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcodelist
|
||||
*/
|
||||
public function getBackupCodeListObject(): d3backupcodelist
|
||||
{
|
||||
return oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
public function getPreviousClass(): string
|
||||
{
|
||||
return Registry::getSession()->getVariable(d3totp_conf::SESSION_CURRENTCLASS);
|
||||
}
|
||||
|
||||
public function previousClassIsOrderStep(): bool
|
||||
{
|
||||
$sClassKey = Registry::getSession()->getVariable(d3totp_conf::SESSION_CURRENTCLASS);
|
||||
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
|
||||
$resolvedClass = $resolvedClass ?: 'start';
|
||||
|
||||
/** @var FrontendController $oController */
|
||||
$oController = oxNew($resolvedClass);
|
||||
return $oController->getIsOrderStep();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsOrderStep(): bool
|
||||
{
|
||||
return $this->previousClassIsOrderStep();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Bread Crumb - you are here page1/page2/page3...
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBreadCrumb(): array
|
||||
{
|
||||
$aPaths = [];
|
||||
$aPath = [];
|
||||
$iBaseLanguage = (int) Registry::getLang()->getBaseLanguage();
|
||||
$aPath['title'] = Registry::getLang()->translateString('D3_TOTP_BREADCRUMB', $iBaseLanguage, false);
|
||||
$aPath['link'] = $this->getLink();
|
||||
|
||||
$aPaths[] = $aPath;
|
||||
|
||||
return $aPaths;
|
||||
}
|
||||
}
|
@ -1,47 +1,42 @@
|
||||
<?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\Totp\Application\Factory;
|
||||
|
||||
use BaconQrCode\Renderer\RendererInterface;
|
||||
use BaconQrCode\Renderer\Image\Svg; // v1.0.3
|
||||
use BaconQrCode\Renderer\ImageRenderer; // v2.0.0
|
||||
use BaconQrCode\Renderer\Image\SvgImageBackEnd; // v2.0.0
|
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle; // v2.0.0
|
||||
|
||||
|
||||
class BaconQrCodeFactory
|
||||
{
|
||||
/**
|
||||
* @param int $size
|
||||
* @return RendererInterface
|
||||
*/
|
||||
public static function renderer($size)
|
||||
public static function renderer(int $size): RendererInterface
|
||||
{
|
||||
if (class_exists(Svg::class)) {
|
||||
return self::v100($size);
|
||||
}
|
||||
|
||||
return self::v200($size);
|
||||
}
|
||||
|
||||
private static function v200($size)
|
||||
private static function v200(int $size): RendererInterface
|
||||
{
|
||||
$renderer = oxNew(
|
||||
return oxNew(
|
||||
ImageRenderer::class,
|
||||
oxNew(RendererStyle::class, $size),
|
||||
oxNew(SvgImageBackEnd::class),
|
||||
);
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
private static function v100($size)
|
||||
{
|
||||
$renderer = oxNew(Svg::class);
|
||||
$renderer->setHeight($size);
|
||||
$renderer->setWidth($size);
|
||||
|
||||
return $renderer;
|
||||
}
|
||||
}
|
21
Application/Model/Constants.php
Normal file
21
Application/Model/Constants.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?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\Totp\Application\Model;
|
||||
|
||||
class Constants
|
||||
{
|
||||
public const OXID_MODULE_ID = 'd3totp';
|
||||
}
|
@ -1,20 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Application\Model\Exceptions;
|
||||
|
||||
use Exception;
|
31
Application/Model/d3RandomGenerator.php
Normal file
31
Application/Model/d3RandomGenerator.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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\Totp\Application\Model;
|
||||
|
||||
use Laminas\Math\Rand;
|
||||
|
||||
class d3RandomGenerator extends Rand
|
||||
{
|
||||
public const CHAR_DIGITS = '0123456789';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public static function getRandomTotpBackupCode(): string
|
||||
{
|
||||
return self::getString(6, self::CHAR_DIGITS);
|
||||
}
|
||||
}
|
110
Application/Model/d3backupcode.php
Normal file
110
Application/Model/d3backupcode.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?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\Totp\Application\Model;
|
||||
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Model\BaseModel;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3backupcode extends BaseModel
|
||||
{
|
||||
protected $_sCoreTable = 'd3totp_backupcodes';
|
||||
|
||||
/**
|
||||
* @param string $sUserId
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function generateCode(string $sUserId): string
|
||||
{
|
||||
$sCode = $this->getRandomTotpBackupCode();
|
||||
$this->assign([
|
||||
'oxuserid' => $sUserId,
|
||||
'backupcode' => $this->d3EncodeBC($sCode, $sUserId),
|
||||
]);
|
||||
|
||||
return $sCode;
|
||||
}
|
||||
|
||||
public function getRandomTotpBackupCode(): string
|
||||
{
|
||||
return d3RandomGenerator::getRandomTotpBackupCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $sUserId
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function d3EncodeBC(string $code, string $sUserId): string
|
||||
{
|
||||
$oUser = $this->d3TotpGetUserObject();
|
||||
$oUser->load($sUserId);
|
||||
$salt = $oUser->getFieldData('oxpasssalt');
|
||||
|
||||
$qb = $this->getQueryBuilder();
|
||||
$qb->select('BINARY MD5( CONCAT('.$qb->createNamedParameter($code).', UNHEX('.$qb->createNamedParameter($salt).')))');
|
||||
|
||||
return $qb->execute()->fetchOne();
|
||||
}
|
||||
|
||||
public function d3GetUser(): User
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
if ($user instanceof User) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = $this->d3TotpGetUserObject();
|
||||
$sUserId = $oUser->d3TotpGetCurrentUser();
|
||||
$oUser->load($sUserId);
|
||||
return $oUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function d3TotpGetUserObject(): User
|
||||
{
|
||||
return oxNew(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryBuilder
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getQueryBuilder(): QueryBuilder
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
||||
}
|
||||
}
|
198
Application/Model/d3backupcodelist.php
Normal file
198
Application/Model/d3backupcodelist.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?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\Totp\Application\Model;
|
||||
|
||||
use D3\Totp\Application\Controller\Admin\d3user_totp;
|
||||
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Model\ListModel;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3backupcodelist extends ListModel
|
||||
{
|
||||
protected $_sObjectsInListName = d3backupcode::class;
|
||||
|
||||
/** @var string */
|
||||
protected $_sCoreTable = 'd3totp_backupcodes';
|
||||
|
||||
protected array $_backupCodes = [];
|
||||
|
||||
/**
|
||||
* @param string $sUserId
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws DBALDriverException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function generateBackupCodes(string $sUserId): void
|
||||
{
|
||||
$this->deleteAllFromUser($sUserId);
|
||||
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$oBackupCode = $this->getD3BackupCodeObject();
|
||||
$this->_backupCodes[] = $oBackupCode->generateCode($sUserId);
|
||||
$this->offsetSet(md5((string) rand()), $oBackupCode);
|
||||
}
|
||||
|
||||
/** @var d3user_totp $oActView */
|
||||
$oActView = $this->d3GetConfig()->getActiveView();
|
||||
$oActView->setBackupCodes($this->_backupCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcode
|
||||
*/
|
||||
public function getD3BackupCodeObject(): d3backupcode
|
||||
{
|
||||
return oxNew(d3backupcode::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function d3GetConfig(): Config
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save(): void
|
||||
{
|
||||
/** @var d3backupcode $oBackupCode */
|
||||
foreach ($this->getArray() as $oBackupCode) {
|
||||
$oBackupCode->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcode
|
||||
*/
|
||||
public function getBaseObject(): d3backupcode
|
||||
{
|
||||
/** @var d3backupcode $object */
|
||||
$object = parent::getBaseObject();
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $totp
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws DBALDriverException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function verify(string $totp): bool
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
$qb->select('oxid')
|
||||
->from($this->getBaseObject()->getViewName())
|
||||
->where(
|
||||
$qb->expr()->and(
|
||||
$qb->expr()->eq(
|
||||
'backupcode',
|
||||
$qb->createNamedParameter($this->getBaseObject()->d3EncodeBC($totp, $this->d3GetUser()->getId()))
|
||||
),
|
||||
$qb->expr()->eq(
|
||||
'oxuserid',
|
||||
$qb->createNamedParameter($this->d3GetUser()->getId())
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$sVerify = $qb->execute()->fetchOne();
|
||||
|
||||
if ($sVerify) {
|
||||
$this->getBaseObject()->delete($sVerify);
|
||||
}
|
||||
|
||||
return (bool) $sVerify;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUserId
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function deleteAllFromUser(string $sUserId): void
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
$qb->select('oxid')
|
||||
->from($this->getBaseObject()->getCoreTableName())
|
||||
->where(
|
||||
$qb->expr()->eq(
|
||||
'oxuserid',
|
||||
$qb->createNamedParameter($sUserId)
|
||||
)
|
||||
);
|
||||
|
||||
$this->selectString($qb->getSQL(), $qb->getParameters());
|
||||
|
||||
/** @var d3backupcode $oBackupCode */
|
||||
foreach ($this->getArray() as $oBackupCode) {
|
||||
$oBackupCode->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUserId
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws DBALDriverException
|
||||
* @throws DBALException
|
||||
*/
|
||||
public function getAvailableCodeCount(string $sUserId): int
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
$qb->select('count(*)')
|
||||
->from($this->getBaseObject()->getViewName())
|
||||
->where(
|
||||
$qb->expr()->eq(
|
||||
'oxuserid',
|
||||
$qb->createNamedParameter($sUserId)
|
||||
)
|
||||
);
|
||||
|
||||
return (int) $qb->execute()->fetchOne();
|
||||
}
|
||||
|
||||
public function d3GetUser(): User
|
||||
{
|
||||
return $this->getBaseObject()->d3GetUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryBuilder
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getQueryBuilder(): QueryBuilder
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
||||
}
|
||||
}
|
330
Application/Model/d3totp.php
Normal file
330
Application/Model/d3totp.php
Normal file
@ -0,0 +1,330 @@
|
||||
<?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\Totp\Application\Model;
|
||||
|
||||
use BaconQrCode\Renderer\RendererInterface;
|
||||
use BaconQrCode\Writer;
|
||||
use D3\Totp\Application\Factory\BaconQrCodeFactory;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OTPHP\TOTP;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Model\BaseModel;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3totp extends BaseModel
|
||||
{
|
||||
protected const ENC_KEY = 'fq45QS09_fqyx09239QQ';
|
||||
|
||||
protected $_sCoreTable = 'd3totp';
|
||||
public null|string $userId = null;
|
||||
public null|TOTP $totp = null;
|
||||
protected int $timeWindow = 2;
|
||||
|
||||
/**
|
||||
* d3totp constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->init($this->getCoreTableName());
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function loadByUserId(string $userId): void
|
||||
{
|
||||
$this->userId = $userId;
|
||||
|
||||
if ($this->getDbConnection()
|
||||
->prepare("SHOW TABLES LIKE ".$this->getDbConnection()->quote($this->getCoreTableName()))
|
||||
->executeQuery()
|
||||
->fetchOne()
|
||||
) {
|
||||
$qb = $this->getQueryBuilder();
|
||||
$qb->select('oxid')
|
||||
->from($this->getViewName())
|
||||
->where(
|
||||
$qb->expr()->eq('oxuserid', $qb->createNamedParameter($userId))
|
||||
)
|
||||
->setMaxResults(1);
|
||||
|
||||
if ($oxid = $qb->execute()->fetchOne()) {
|
||||
$this->load($oxid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function checkIfAlreadyExist(string $userId): bool
|
||||
{
|
||||
$qb = $this->getQueryBuilder();
|
||||
$qb->select('1')
|
||||
->from($this->getViewName())
|
||||
->where(
|
||||
$qb->expr()->eq('oxuserid', $qb->createNamedParameter($userId))
|
||||
)
|
||||
->setMaxResults(1);
|
||||
|
||||
return (bool) $qb->execute()->fetchOne();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Connection
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getDbConnection(): Connection
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryBuilder
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getQueryBuilder(): QueryBuilder
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()->get(QueryBuilderFactoryInterface::class)->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
$userId = $this->userId ?? $this->getFieldData('oxuserid');
|
||||
|
||||
$user = $this->d3GetUser();
|
||||
$user->load($userId);
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function d3GetUser(): User
|
||||
{
|
||||
return oxNew(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return false == Registry::getConfig()->getConfigParam('blDisableTotpGlobally')
|
||||
&& $this->UserUseTotp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function UserUseTotp(): bool
|
||||
{
|
||||
return $this->getFieldData('usetotp')
|
||||
&& $this->getFieldData('seed');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSavedSecret(): ?string
|
||||
{
|
||||
$seed_enc = $this->getFieldData('seed');
|
||||
|
||||
if ($seed_enc) {
|
||||
$seed = $this->decrypt($seed_enc);
|
||||
if ($seed) {
|
||||
return $seed;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $seed
|
||||
* @return TOTP
|
||||
*/
|
||||
public function getTotp(string $seed = null): TOTP
|
||||
{
|
||||
if (null == $this->totp) {
|
||||
$this->totp = TOTP::create($seed ?: $this->getSavedSecret());
|
||||
$this->totp->setLabel($this->getUser()->getFieldData('oxusername') ?: '');
|
||||
$this->totp->setIssuer(Registry::getConfig()->getActiveShop()->getFieldData('oxname'));
|
||||
}
|
||||
|
||||
return $this->totp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQrCodeElement(): string
|
||||
{
|
||||
$renderer = BaconQrCodeFactory::renderer(200);
|
||||
$writer = $this->d3GetWriter($renderer);
|
||||
|
||||
return $writer->writeString($this->getTotp()->getProvisioningUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RendererInterface $renderer
|
||||
* @return Writer
|
||||
*/
|
||||
public function d3GetWriter(RendererInterface $renderer): Writer
|
||||
{
|
||||
return oxNew(Writer::class, $renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret(): string
|
||||
{
|
||||
return trim($this->getTotp()->getSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $seed
|
||||
*/
|
||||
public function saveSecret(string $seed): void
|
||||
{
|
||||
$this->assign([
|
||||
'seed' => $this->encrypt($seed),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $totp
|
||||
* @param string|null $seed
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws d3totp_wrongOtpException
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function verify(string $totp, string $seed = null): bool
|
||||
{
|
||||
$blNotVerified = $this->getTotp($seed)->verify($totp, null, $this->timeWindow) == false;
|
||||
|
||||
if ($blNotVerified && null == $seed) {
|
||||
$oBC = $this->d3GetBackupCodeListObject();
|
||||
$blNotVerified = $oBC->verify($totp) == false;
|
||||
|
||||
if ($blNotVerified) {
|
||||
/** @var d3totp_wrongOtpException $exception */
|
||||
$exception = oxNew(d3totp_wrongOtpException::class);
|
||||
throw $exception;
|
||||
}
|
||||
} elseif ($blNotVerified && $seed !== null) {
|
||||
/** @var d3totp_wrongOtpException $exception */
|
||||
$exception = oxNew(d3totp_wrongOtpException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return !$blNotVerified;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3backupcodelist
|
||||
*/
|
||||
public function d3GetBackupCodeListObject(): d3backupcodelist
|
||||
{
|
||||
return oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $plaintext
|
||||
* @return string
|
||||
*/
|
||||
public function encrypt(string $plaintext): string
|
||||
{
|
||||
$ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
|
||||
$iv = openssl_random_pseudo_bytes($ivlen);
|
||||
$ciphertext_raw = openssl_encrypt($plaintext, $cipher, self::ENC_KEY, OPENSSL_RAW_DATA, $iv);
|
||||
$hmac = hash_hmac('sha256', $ciphertext_raw, self::ENC_KEY, true);
|
||||
return base64_encode($iv.$hmac.$ciphertext_raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ciphertext
|
||||
* @return false|string
|
||||
*/
|
||||
public function decrypt(string $ciphertext): false|string
|
||||
{
|
||||
$c = $this->d3Base64_decode($ciphertext);
|
||||
$ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
|
||||
$iv = substr($c, 0, $ivlen);
|
||||
$hmac = substr($c, $ivlen, $sha2len = 32);
|
||||
$ciphertext_raw = substr($c, $ivlen + $sha2len);
|
||||
$original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, self::ENC_KEY, OPENSSL_RAW_DATA, $iv);
|
||||
$calcmac = hash_hmac('sha256', $ciphertext_raw, self::ENC_KEY, true);
|
||||
if (hash_equals($hmac, $calcmac)) { // PHP 5.6+ compute attack-safe comparison
|
||||
return $original_plaintext;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* required for unit tests
|
||||
* @param string $source
|
||||
* @return string
|
||||
*/
|
||||
public function d3Base64_decode(string $source): string
|
||||
{
|
||||
return base64_decode($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $oxid
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function delete($oxid = null): bool
|
||||
{
|
||||
$oBackupCodeList = $this->d3GetBackupCodeListObject();
|
||||
$oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid'));
|
||||
|
||||
return parent::delete($oxid);
|
||||
}
|
||||
}
|
31
Application/Model/d3totp_conf.php
Normal file
31
Application/Model/d3totp_conf.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?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\Totp\Application\Model;
|
||||
|
||||
class d3totp_conf
|
||||
{
|
||||
public const OXID_ADMIN_AUTH = 'auth';
|
||||
public const OXID_FRONTEND_AUTH = 'usr';
|
||||
public const SESSION_AUTH = 'd3Totp_auth'; // has valid totp, user is logged in completly
|
||||
public const SESSION_CURRENTUSER = 'd3Totp_currentUser'; // oxid assigned to user from entered username
|
||||
public const SESSION_CURRENTCLASS = 'd3Totp_currentClass'; // oxid assigned to user from entered username
|
||||
public const SESSION_NAVFORMPARAMS = 'd3Totp_navFormParams';
|
||||
public const SESSION_ADMIN_AUTH = 'd3Totp_auth'; // has valid totp, user is logged in completly
|
||||
public const SESSION_ADMIN_CURRENTUSER = 'd3Totp_currentUser'; // oxid assigned to user from entered username
|
||||
public const SESSION_ADMIN_PROFILE = 'd3Totp_currentProfile'; // selected profile
|
||||
public const SESSION_ADMIN_CHLANGUAGE = 'd3Totp_currentChLanguage'; // selected language
|
||||
public const OTP_SESSION_VARNAME = 'd3totpinstance'; // saved OTP initialisation
|
||||
}
|
22
Application/translations/de/d3totp_lang.php
Normal file
22
Application/translations/de/d3totp_lang.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
$sLangName = 'Deutsch';
|
||||
|
||||
$aLang = include __DIR__."/translations.php";
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
@ -1,23 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
$sLangName = "Deutsch";
|
||||
declare(strict_types=1);
|
||||
|
||||
$aLang = [
|
||||
return [
|
||||
'charset' => 'UTF-8',
|
||||
|
||||
'D3_TOTP_INPUT' => 'Authentisierungscode',
|
||||
@ -27,8 +23,7 @@ $aLang = [
|
||||
'D3_TOTP_BREADCRUMB' => 'Einmalpasswort-Anmeldung',
|
||||
'D3_TOTP_ERROR_UNVALID' => 'Das Einmalpasswort ist ungültig.',
|
||||
'D3_TOTP_ACCOUNT' => '2-Faktor-Authentisierung',
|
||||
|
||||
'D3_TOTP_ACCOUNT_USE' => '2-Faktor-Authentisierung verwenden',
|
||||
'D3_TOTP_ACCOUNT_DESC' => 'Sichern Sie Ihre Kontoanmeldung mit einem zweiten Faktor.',
|
||||
|
||||
'D3_TOTP_REGISTERNEW' => 'neue Registrierung erstellen',
|
||||
'D3_TOTP_QRCODE' => 'QR-Code',
|
||||
@ -38,6 +33,9 @@ $aLang = [
|
||||
'D3_TOTP_CURROTP' => 'Bestätigung mit Einmalpasswort',
|
||||
'D3_TOTP_CURROTP_HELP' => 'Haben Sie dieses Kundenkonto in Ihrer Authentisierungs-App registriert, generieren Sie damit ein Einmalpasswort, tragen Sie es hier ein und senden das Formular direkt darauf hin ab.',
|
||||
|
||||
'D3_TOTP_STATUS' => 'Status',
|
||||
'D3_TOTP_ACCOUNT_USE' => '2-Faktor-Authentisierung verwenden',
|
||||
|
||||
'D3_TOTP_REGISTEREXIST' => 'vorhandene Registrierung',
|
||||
'D3_TOTP_REGISTERDELETE_DESC' => 'Um die Registrierung zu ändern, löschen Sie diese bitte vorerst. Sie können sofort im Anschluss eine neue Registrierung anlegen.<br>Wenn Sie die Registrierung löschen, ist das Konto nicht mehr durch die Zwei-Faktor-Authentisierung geschützt.',
|
||||
'D3_TOTP_REGISTERDELETE_CONFIRM' => 'Soll die bestehende 2-Faktor-Authentisierung gelöscht werden?',
|
||||
@ -47,6 +45,13 @@ $aLang = [
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT' => 'noch %1$s Backupcode(s) verfügbar',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT_DESC' => 'Um neue Backupcodes zu erstellen, löschen Sie die bestehende Registrierung und legen diese bitte neu an.',
|
||||
|
||||
'D3_TOTP_INPUT_FIRST' => 'erste TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_SECOND' => 'zweite TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_THIRD' => 'dritte TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_FOURTH' => 'vierte TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_FIFTH' => 'fünfte TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_SIXTH' => 'sechste TOTP-Ziffer',
|
||||
|
||||
'D3_TOTP_ACCOUNT_SAVE' => 'Einstellungen übernehmen',
|
||||
|
||||
];
|
22
Application/translations/en/d3totp_lang.php
Normal file
22
Application/translations/en/d3totp_lang.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
$sLangName = 'English';
|
||||
|
||||
$aLang = include __DIR__."/translations.php";
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
@ -1,23 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
$sLangName = "English";
|
||||
declare(strict_types=1);
|
||||
|
||||
$aLang = [
|
||||
return [
|
||||
'charset' => 'UTF-8',
|
||||
|
||||
'D3_TOTP_INPUT' => 'authentication code',
|
||||
@ -27,8 +23,7 @@ $aLang = [
|
||||
'D3_TOTP_BREADCRUMB' => 'one-time password login',
|
||||
'D3_TOTP_ERROR_UNVALID' => 'The one-time password is invalid.',
|
||||
'D3_TOTP_ACCOUNT' => '2-factor authentication',
|
||||
|
||||
'D3_TOTP_ACCOUNT_USE' => 'Use 2-factor authentication',
|
||||
'D3_TOTP_ACCOUNT_DESC' => 'Secure your account login with a second factor.',
|
||||
|
||||
'D3_TOTP_REGISTERNEW' => 'create a new registration',
|
||||
'D3_TOTP_QRCODE' => 'QR code',
|
||||
@ -38,15 +33,25 @@ $aLang = [
|
||||
'D3_TOTP_CURROTP' => 'Confirmation with one-time password',
|
||||
'D3_TOTP_CURROTP_HELP' => 'If you have registered this customer account in your authentication app, use it to generate a one-time password, enter it here and send the form directly afterwards.',
|
||||
|
||||
'D3_TOTP_REGISTEREXIST' => 'existing registration',
|
||||
'D3_TOTP_STATUS' => 'Status',
|
||||
'D3_TOTP_ACCOUNT_USE' => 'use 2-factor authentication',
|
||||
|
||||
'D3_TOTP_REGISTEREXIST' => 'Existing registration',
|
||||
'D3_TOTP_REGISTERDELETE_DESC' => 'To change the registration, please delete it first. You can then create a new registration immediately. <br>If you delete the registration, the account is no longer protected by two-factor authentication.',
|
||||
'D3_TOTP_REGISTERDELETE_CONFIRM' => 'Should the existing 2-factor authentication be deleted?',
|
||||
|
||||
'D3_TOTP_BACKUPCODES' => 'backup codes',
|
||||
'D3_TOTP_BACKUPCODES' => 'Backup codes',
|
||||
'D3_TOTP_BACKUPCODES_DESC' => 'You can use these backup codes to log on if it is not possible to generate the one-time password (e.g. device lost or newly installed). You can then change the settings to use 2-factor authentication or create a new account. Please save these codes securely at this moment. After leaving this page, these codes cannot be displayed again.',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT' => 'still %1$s backup code(s) available',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT_DESC' => 'To create new backup codes, delete the existing registry and create a new one.',
|
||||
|
||||
'D3_TOTP_INPUT_FIRST' => 'first TOTP digit',
|
||||
'D3_TOTP_INPUT_SECOND' => 'second TOTP digit',
|
||||
'D3_TOTP_INPUT_THIRD' => 'third TOTP digit',
|
||||
'D3_TOTP_INPUT_FOURTH' => 'fourth TOTP digit',
|
||||
'D3_TOTP_INPUT_FIFTH' => 'fifth TOTP digit',
|
||||
'D3_TOTP_INPUT_SIXTH' => 'sixth TOTP digit',
|
||||
|
||||
'D3_TOTP_ACCOUNT_SAVE' => 'Confirm settings',
|
||||
|
||||
];
|
22
Application/views/admin_smarty/de/d3totp_lang.php
Normal file
22
Application/views/admin_smarty/de/d3totp_lang.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
$sLangName = 'Deutsch';
|
||||
|
||||
$aLang = include __DIR__."/../../de/translations.php";
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
22
Application/views/admin_smarty/en/d3totp_lang.php
Normal file
22
Application/views/admin_smarty/en/d3totp_lang.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
$sLangName = 'English';
|
||||
|
||||
$aLang = include __DIR__."/../../en/translations.php";
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
22
Application/views/admin_twig/de/d3totp_lang.php
Normal file
22
Application/views/admin_twig/de/d3totp_lang.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
$sLangName = 'Deutsch';
|
||||
|
||||
$aLang = include __DIR__."/../../de/translations.php";
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
22
Application/views/admin_twig/en/d3totp_lang.php
Normal file
22
Application/views/admin_twig/en/d3totp_lang.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
$sLangName = 'English';
|
||||
|
||||
$aLang = include __DIR__."/../../en/translations.php";
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
@ -1,23 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
$sLangName = "Deutsch";
|
||||
declare(strict_types=1);
|
||||
|
||||
$aLang = [
|
||||
return [
|
||||
'charset' => 'UTF-8',
|
||||
|
||||
'TOTP_INPUT' => 'Authentisierungscode',
|
||||
@ -34,6 +30,7 @@ $aLang = [
|
||||
'D3_TOTP_CURROTP' => 'Bestätigung mit Einmalpasswort',
|
||||
'D3_TOTP_CURROTP_HELP' => 'Haben Sie dieses Kundenkonto in Ihrer Authentisierungs-App registriert, generieren Sie damit ein Einmalpasswort, tragen Sie es hier ein und senden das Formular direkt darauf hin ab.',
|
||||
|
||||
'SHOP_MODULE_GROUP_d3totp_main' => 'Grundeinstellungen',
|
||||
'D3_TOTP_FORCE2FATITLE' => 'Verpflichtet Zwei-Faktor-Authentisierung',
|
||||
'D3_TOTP_FORCE2FASUB' => 'Alle Administratoren müssen es aktivieren',
|
||||
'D3_TOTP_ADMINBACKEND' => 'Admin-Oberfläche',
|
||||
@ -44,15 +41,25 @@ $aLang = [
|
||||
'D3_TOTP_REGISTERDELETE_DESC' => 'Um die Registrierung zu ändern, löschen Sie diese bitte vorerst. Sie können sofort im Anschluss eine neue Registrierung anlegen.<br>Wenn Sie die Registrierung löschen, ist das Konto nicht mehr durch die Zwei-Faktor-Authentisierung geschützt.',
|
||||
'D3_TOTP_REGISTERDELETED' => 'Die Registrierung wurde gelöscht.',
|
||||
|
||||
'D3_TOTP_CONFIRMATION' => 'Bestätigung',
|
||||
'D3_TOTP_BACKUPCODES' => 'Backupcodes',
|
||||
'D3_TOTP_BACKUPCODES_DESC' => 'Mit diesen Backupcodes können Sie sich anmelden, wenn die Generierung des Einmalpasswortes nicht möglich ist (z.B. Gerät verloren oder neu installiert). Sie können dann die Einstellungen zur Verwendung der 2-Faktor-Authentisierung ändern oder einen neuen Zugang erstellen. Speichern Sie sich diese Codes bitte in diesem Moment sicher ab. Nach Verlassen dieser Seite können diese Codes nicht erneut angezeigt werden.',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT' => 'noch %1$s Backupcode(s) verfügbar',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT_DESC' => 'Um neue Backupcodes zu erstellen, löschen Sie die bestehende Registrierung und legen diese bitte neu an.',
|
||||
|
||||
'D3_TOTP_INPUT_FIRST' => 'erste TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_SECOND' => 'zweite TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_THIRD' => 'dritte TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_FOURTH' => 'vierte TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_FIFTH' => 'fünfte TOTP-Ziffer',
|
||||
'D3_TOTP_INPUT_SIXTH' => 'sechste TOTP-Ziffer',
|
||||
|
||||
'D3_TOTP_SAVE' => 'Speichern',
|
||||
|
||||
'D3_TOTP_ERROR_UNVALID' => 'Das Einmalpasswort ist ungültig.',
|
||||
'D3_TOTP_ALREADY_EXIST' => 'Die Registrierung wurde schon gespeichert.',
|
||||
'D3_TOTP_MISSING_VALIDATION' => 'Das bestätigende Einmalkennwort muss aus 6 Ziffern bestehen.',
|
||||
'D3_TOTP_EMPTY_SEED' => 'Der verwendete Schlüssel kann nicht ermittelt werden.',
|
||||
|
||||
'SHOP_MODULE_D3_TOTP_ADMIN_FORCE_2FA' => 'Administratoren sind verpflichtet 2FA zu aktivieren'
|
||||
'SHOP_MODULE_D3_TOTP_ADMIN_FORCE_2FA' => 'Administratoren sind verpflichtet 2FA zu aktivieren',
|
||||
];
|
@ -1,39 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
$sLangName = "English";
|
||||
declare(strict_types=1);
|
||||
|
||||
$aLang = [
|
||||
return [
|
||||
'charset' => 'UTF-8',
|
||||
|
||||
'TOTP_INPUT' => 'authentication code',
|
||||
'TOTP_INPUT_HELP' => 'The authentication code is available from the Two-Factor Authentication app on your device.',
|
||||
'TOTP_INPUT_HELP' => 'You get the one-time password from the two-factor authentication app on your device.',
|
||||
'TOTP_CANCEL_LOGIN' => 'Cancel login',
|
||||
|
||||
'd3mxuser_totp' => 'Two-factor authentication',
|
||||
|
||||
'D3_TOTP_REGISTERNEW' => 'create new registration',
|
||||
'D3_TOTP_QRCODE' => 'QR code',
|
||||
'D3_TOTP_QRCODE_HELP' => 'Scan this QR code with your authentication app to deposit this user account.',
|
||||
'D3_TOTP_SECRET' => 'Can not scan QR code?',
|
||||
'D3_TOTP_SECRET_HELP' => 'If you do not use an app that can scan the QR code, you can also copy this string into your authentication tool. Please also set the password length to 6 characters and the time interval to 30 seconds.',
|
||||
'D3_TOTP_QRCODE_HELP' => 'Scan this QR code with your authentication app to store this user account there.',
|
||||
'D3_TOTP_SECRET' => 'QR code cannot be scanned?',
|
||||
'D3_TOTP_SECRET_HELP' => 'If you are not using an app that can scan the QR code, you can also copy this character string into your authentication tool. Please set the password length to 6 characters and the time interval to 30 seconds.',
|
||||
'D3_TOTP_CURROTP' => 'Confirmation with one-time password',
|
||||
'D3_TOTP_CURROTP_HELP' => 'If you have registered this customer account in your authentication app, you generate a one-time password, enter it here and send the form out immediately.',
|
||||
'D3_TOTP_CURROTP_HELP' => 'If you have registered this customer account in your authentication app, use it to generate a one-time password, enter it here and submit the form directly.',
|
||||
|
||||
'SHOP_MODULE_GROUP_d3totp_main' => 'Basic settings',
|
||||
'D3_TOTP_FORCE2FATITLE' => 'Mandates two-factor authentication',
|
||||
'D3_TOTP_FORCE2FASUB' => 'All administrators need to activate it',
|
||||
'D3_TOTP_ADMINBACKEND' => 'Admin-Backend',
|
||||
@ -44,15 +41,25 @@ $aLang = [
|
||||
'D3_TOTP_REGISTERDELETE_DESC' => 'To change the registration, please delete it. You can then immediately create a new registration. <br> If you delete the registration, the account is no longer protected by the two-factor authentication.',
|
||||
'D3_TOTP_REGISTERDELETED' => 'The registration has been deleted.',
|
||||
|
||||
'D3_TOTP_CONFIRMATION' => 'confirmation',
|
||||
'D3_TOTP_BACKUPCODES' => 'backup codes',
|
||||
'D3_TOTP_BACKUPCODES_DESC' => 'You can use these backup codes to log on if it is not possible to generate the one-time password (e.g. device lost or newly installed). You can then change the settings to use 2-factor authentication or create a new 2FA login. Please save these codes safely at this moment. After leaving this page, these codes cannot be displayed again.',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT' => '%1$s backup code(s) still available',
|
||||
'D3_TOTP_AVAILBACKUPCODECOUNT_DESC' => 'To create new backup codes, delete the existing registry and create a new one.',
|
||||
|
||||
'D3_TOTP_INPUT_FIRST' => 'first TOTP digit',
|
||||
'D3_TOTP_INPUT_SECOND' => 'second TOTP digit',
|
||||
'D3_TOTP_INPUT_THIRD' => 'third TOTP digit',
|
||||
'D3_TOTP_INPUT_FOURTH' => 'fourth TOTP digit',
|
||||
'D3_TOTP_INPUT_FIFTH' => 'fifth TOTP digit',
|
||||
'D3_TOTP_INPUT_SIXTH' => 'sixth TOTP digit',
|
||||
|
||||
'D3_TOTP_SAVE' => 'Save',
|
||||
|
||||
'D3_TOTP_ERROR_UNVALID' => 'The one-time password is invalid.',
|
||||
'D3_TOTP_ALREADY_EXIST' => 'The registration has already been saved.',
|
||||
'D3_TOTP_MISSING_VALIDATION' => 'The confirming one-time password must consist of 6 digits',
|
||||
'D3_TOTP_EMPTY_SEED' => 'The key used cannot be determined.',
|
||||
|
||||
'SHOP_MODULE_D3_TOTP_ADMIN_FORCE_2FA' => 'Administrators are required to activate 2FA'
|
||||
'SHOP_MODULE_D3_TOTP_ADMIN_FORCE_2FA' => 'Administrators are required to activate 2FA',
|
||||
];
|
49
CHANGELOG.md
Normal file
49
CHANGELOG.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased](https://git.d3data.de/D3Public/oxtotp/compare/3.0.0.0...rel_3.x)
|
||||
|
||||
## [3.0.0.0](https://git.d3data.de/D3Public/oxtotp/compare/2.1.1.0...3.0.0.0) - 2024-09-23
|
||||
### Added
|
||||
- installable in OXID eShop 7.0 + 7.1
|
||||
### Removed
|
||||
- support for OXID eShop < 7
|
||||
|
||||
## [2.1.1.0](https://git.d3data.de/D3Public/oxtotp/compare/2.1.0.0...2.1.1.0) - 2023-09-07
|
||||
### Added
|
||||
- installable in OXID 6.5.2 + 6.5.3
|
||||
### Changed
|
||||
- product logo
|
||||
|
||||
## [2.1.0.0](https://git.d3data.de/D3Public/oxtotp/compare/2.0.0.1...2.1.0.0) - 2023-02-18
|
||||
### Added
|
||||
- add compatibility to D3 Webauthn plugin
|
||||
- installable in OXID 6.5.1
|
||||
|
||||
## [2.0.0.1](https://git.d3data.de/D3Public/oxtotp/compare/2.0.0.0...2.0.0.1) - 2022-11-09
|
||||
### Fixed
|
||||
- Further protection of the login
|
||||
|
||||
## [2.0.0.0](https://git.d3data.de/D3Public/oxtotp/compare/1.1.0.0...2.0.0.0) - 2022-09-30
|
||||
### Added
|
||||
- installable in OXID 6.3 to 6.5
|
||||
- tests completed
|
||||
### Removed
|
||||
- support for OXID < 6.3
|
||||
|
||||
## [1.1.0.0](https://git.d3data.de/D3Public/oxtotp/compare/1.0.0.0...1.1.0.0) - 2022-09-30
|
||||
### Added
|
||||
- installable in OXID 6.0 to 6.2
|
||||
- mandatory 2FA use for all admin accounts
|
||||
|
||||
## [1.0.0.0](https://git.d3data.de/D3Public/oxtotp/releases/tag/1.0.0.0) - 2019-08-19
|
||||
### Added
|
||||
- 2-factor authentication for logins in front- and backend in addition to username and password
|
||||
- Activation and setup possible in the front and back end
|
||||
- Authentication is shown for user accounts that have this enabled - otherwise the usual default login.
|
||||
- Access can be set up in the Auth app by scannable QR code or copyable character string
|
||||
- Validation of one-time passwords and generation of QR codes are only carried out within the shop - no communication to the outside necessary
|
||||
- static backup codes also allow (limited) login without access to the generation tool
|
@ -1,24 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
* http://www.shopmodule.com
|
||||
* 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 <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Modules\Application\Component
|
||||
{
|
||||
|
||||
use OxidEsales\Eshop\Application\Component\UserComponent;
|
||||
|
||||
class d3_totp_UserComponent_parent extends UserComponent { }
|
||||
class d3_totp_UserComponent_parent extends UserComponent
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller
|
||||
@ -28,11 +30,17 @@ namespace D3\Totp\Modules\Application\Controller
|
||||
use OxidEsales\Eshop\Application\Controller\PaymentController;
|
||||
use OxidEsales\Eshop\Application\Controller\UserController;
|
||||
|
||||
class d3_totp_UserController_parent extends UserController { }
|
||||
class d3_totp_UserController_parent extends UserController
|
||||
{
|
||||
}
|
||||
|
||||
class d3_totp_PaymentController_parent extends PaymentController { }
|
||||
class d3_totp_PaymentController_parent extends PaymentController
|
||||
{
|
||||
}
|
||||
|
||||
class d3_totp_OrderController_parent extends OrderController { }
|
||||
class d3_totp_OrderController_parent extends OrderController
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace D3\Totp\Modules\Application\Controller\Admin
|
||||
@ -40,7 +48,9 @@ namespace D3\Totp\Modules\Application\Controller\Admin
|
||||
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
||||
|
||||
class d3_totp_LoginController_parent extends LoginController { }
|
||||
class d3_totp_LoginController_parent extends LoginController
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace D3\Totp\Modules\Application\Model
|
||||
@ -48,13 +58,22 @@ namespace D3\Totp\Modules\Application\Model
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
|
||||
class d3_totp_user_parent extends User { }
|
||||
class d3_totp_user_parent extends User
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
namespace D3\Totp\Modules\Core
|
||||
{
|
||||
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\EshopCommunity\Core\SystemEventHandler;
|
||||
|
||||
class d3_totp_utils_parent extends Utils { }
|
||||
}
|
||||
class d3_totp_utils_parent extends Utils
|
||||
{
|
||||
}
|
||||
|
||||
class totpSystemEventHandler_parent extends SystemEventHandler
|
||||
{
|
||||
}
|
||||
}
|
674
LICENSE.md
Normal file
674
LICENSE.md
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
189
Modules/Application/Component/d3_totp_UserComponent.php
Normal file
189
Modules/Application/Component/d3_totp_UserComponent.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?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\Totp\Modules\Application\Component;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use InvalidArgumentException;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3_totp_UserComponent extends d3_totp_UserComponent_parent
|
||||
{
|
||||
/**
|
||||
* @param User $oUser
|
||||
*
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function afterLogin($oUser)
|
||||
{
|
||||
Assert::that($oUser)->isInstanceOf(User::class, 'user argument must an instance of User class');
|
||||
|
||||
try {
|
||||
Assert::that($oUser->getId())->notBlank('user must logged in');
|
||||
$totp = $this->d3GetTotpObject();
|
||||
$totp->loadByUserId($oUser->getId());
|
||||
|
||||
if ($totp->isActive()
|
||||
&& !$this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_AUTH)
|
||||
) {
|
||||
$this->d3TotpGetSession()->setVariable(
|
||||
d3totp_conf::SESSION_CURRENTCLASS,
|
||||
$this->getParent()->getClassKey() != 'd3totplogin' ? $this->getParent()->getClassKey() : 'start'
|
||||
);
|
||||
|
||||
$oUser->logout();
|
||||
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, $oUser->getId());
|
||||
$this->d3TotpGetSession()->setVariable(
|
||||
d3totp_conf::SESSION_NAVFORMPARAMS,
|
||||
$this->getParent()->getViewConfig()->getNavFormParams()
|
||||
);
|
||||
|
||||
$sUrl = Registry::getConfig()->getShopHomeUrl() . 'cl=d3totplogin';
|
||||
$this->d3TotpGetUtils()->redirect($sUrl, false);
|
||||
}
|
||||
} catch (InvalidArgumentException) {
|
||||
}
|
||||
|
||||
return parent::afterLogin($oUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3GetTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function d3TotpCheckTotpLogin(): false|string
|
||||
{
|
||||
$sTotp = implode('', Registry::getRequest()->getRequestEscapedParameter('d3totp') ?: []);
|
||||
|
||||
/** @var d3_totp_user $oUser */
|
||||
$oUser = oxNew(User::class);
|
||||
$sUserId = Registry::getSession()->getVariable(d3totp_conf::SESSION_CURRENTUSER);
|
||||
$oUser->load($sUserId);
|
||||
|
||||
$totp = $this->d3GetTotpObject();
|
||||
$totp->loadByUserId($sUserId);
|
||||
|
||||
try {
|
||||
if (!$this->d3TotpIsNoTotpOrNoLogin($totp) && $this->d3TotpHasValidTotp($sTotp, $totp)) {
|
||||
// relogin, don't extract from this try block
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_AUTH, $oUser->getId());
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::OXID_FRONTEND_AUTH, $oUser->getId());
|
||||
$this->setUser($oUser);
|
||||
$this->setLoginStatus(USER_LOGIN_SUCCESS);
|
||||
$this->afterLogin($oUser);
|
||||
|
||||
$this->d3TotpClearSessionVariables();
|
||||
|
||||
return false;
|
||||
}
|
||||
} catch (d3totp_wrongOtpException $oEx) {
|
||||
$this->d3TotpGetUtilsView()->addErrorToDisplay($oEx, false, false, "", 'd3totplogin');
|
||||
}
|
||||
|
||||
return 'd3totplogin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UtilsView
|
||||
*/
|
||||
public function d3TotpGetUtilsView(): UtilsView
|
||||
{
|
||||
return Registry::getUtilsView();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Utils
|
||||
*/
|
||||
public function d3TotpGetUtils(): Utils
|
||||
{
|
||||
return Registry::getUtils();
|
||||
}
|
||||
|
||||
public function d3TotpCancelTotpLogin(): bool
|
||||
{
|
||||
$this->d3TotpClearSessionVariables();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param d3totp $totp
|
||||
* @return bool
|
||||
*/
|
||||
public function d3TotpIsNoTotpOrNoLogin(d3totp $totp): bool
|
||||
{
|
||||
return false == Registry::getSession()->getVariable(d3totp_conf::SESSION_CURRENTUSER)
|
||||
|| false == $totp->isActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sTotp
|
||||
* @param d3totp $totp
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALException
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws d3totp_wrongOtpException
|
||||
*/
|
||||
public function d3TotpHasValidTotp(string $sTotp, d3totp $totp): bool
|
||||
{
|
||||
return Registry::getSession()->getVariable(d3totp_conf::SESSION_AUTH) ||
|
||||
$totp->verify($sTotp);
|
||||
}
|
||||
|
||||
public function d3TotpClearSessionVariables(): void
|
||||
{
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_CURRENTCLASS);
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_CURRENTUSER);
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_NAVFORMPARAMS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSession(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
}
|
131
Modules/Application/Controller/Admin/d3_totp_LoginController.php
Normal file
131
Modules/Application/Controller/Admin/d3_totp_LoginController.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?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\Totp\Modules\Application\Controller\Admin;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use OxidEsales\Eshop\Core\Language;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\UtilsServer;
|
||||
|
||||
class d3_totp_LoginController extends d3_totp_LoginController_parent
|
||||
{
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3GetTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSession(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function checklogin()
|
||||
{
|
||||
$this->d3TotpGetSession()->setVariable(
|
||||
d3totp_conf::SESSION_ADMIN_PROFILE,
|
||||
Registry::getRequest()->getRequestEscapedParameter('profile')
|
||||
);
|
||||
$this->d3TotpGetSession()->setVariable(
|
||||
d3totp_conf::SESSION_ADMIN_CHLANGUAGE,
|
||||
Registry::getRequest()->getRequestEscapedParameter('chlanguage')
|
||||
);
|
||||
|
||||
return $this->parent__checklogin();
|
||||
}
|
||||
|
||||
/**
|
||||
* mockable parent method
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function parent__checklogin()
|
||||
{
|
||||
return parent::checklogin();
|
||||
}
|
||||
|
||||
public function d3totpAfterLogin(): void
|
||||
{
|
||||
$myUtilsServer = $this->d3TotpGetUtilsServer();
|
||||
$sProfile = $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_PROFILE);
|
||||
|
||||
// #533
|
||||
if (isset($sProfile)) {
|
||||
$aProfiles = $this->d3TotpGetSession()->getVariable("aAdminProfiles");
|
||||
if ($aProfiles && isset($aProfiles[$sProfile])) {
|
||||
// setting cookie to store last locally used profile
|
||||
$myUtilsServer->setOxCookie("oxidadminprofile", $sProfile . "@" . implode("@", $aProfiles[$sProfile]), time() + 31536000);
|
||||
$this->d3TotpGetSession()->setVariable("profile", $aProfiles[$sProfile]);
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_PROFILE);
|
||||
}
|
||||
} else {
|
||||
//deleting cookie info, as setting profile to default
|
||||
$myUtilsServer->setOxCookie("oxidadminprofile", "", time() - 3600);
|
||||
}
|
||||
|
||||
$this->d3totpAfterLoginSetLanguage();
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_CHLANGUAGE);
|
||||
}
|
||||
|
||||
public function d3totpAfterLoginSetLanguage(): void
|
||||
{
|
||||
$myUtilsServer = $this->d3TotpGetUtilsServer();
|
||||
$iLang = Registry::getRequest()->getRequestEscapedParameter('chlanguage');
|
||||
|
||||
$aLanguages = $this->d3TotpGetLangObject()->getAdminTplLanguageArray();
|
||||
if (!isset($aLanguages[$iLang])) {
|
||||
$iLang = key($aLanguages);
|
||||
}
|
||||
|
||||
$myUtilsServer->setOxCookie("oxidadminlanguage", $aLanguages[$iLang]->abbr, time() + 31536000);
|
||||
$this->d3TotpGetLangObject()->setTplLanguage($iLang);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param d3totp $totp
|
||||
* @return bool
|
||||
*/
|
||||
public function d3TotpLoginMissing(d3totp $totp): bool
|
||||
{
|
||||
return $totp->isActive()
|
||||
&& false == $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_AUTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UtilsServer
|
||||
*/
|
||||
protected function d3TotpGetUtilsServer(): UtilsServer
|
||||
{
|
||||
return Registry::getUtilsServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Language
|
||||
*/
|
||||
protected function d3TotpGetLangObject(): Language
|
||||
{
|
||||
return Registry::getLang();
|
||||
}
|
||||
}
|
23
Modules/Application/Controller/d3_totp_OrderController.php
Normal file
23
Modules/Application/Controller/d3_totp_OrderController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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\Totp\Modules\Application\Controller;
|
||||
|
||||
class d3_totp_OrderController extends d3_totp_OrderController_parent
|
||||
{
|
||||
use d3_totp_getUserTrait;
|
||||
|
||||
private $parentClass = d3_totp_OrderController_parent::class;
|
||||
}
|
23
Modules/Application/Controller/d3_totp_PaymentController.php
Normal file
23
Modules/Application/Controller/d3_totp_PaymentController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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\Totp\Modules\Application\Controller;
|
||||
|
||||
class d3_totp_PaymentController extends d3_totp_PaymentController_parent
|
||||
{
|
||||
use d3_totp_getUserTrait;
|
||||
|
||||
private $parentClass = d3_totp_PaymentController_parent::class;
|
||||
}
|
23
Modules/Application/Controller/d3_totp_UserController.php
Normal file
23
Modules/Application/Controller/d3_totp_UserController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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\Totp\Modules\Application\Controller;
|
||||
|
||||
class d3_totp_UserController extends d3_totp_UserController_parent
|
||||
{
|
||||
use d3_totp_getUserTrait;
|
||||
|
||||
private $parentClass = d3_totp_UserController_parent::class;
|
||||
}
|
71
Modules/Application/Controller/d3_totp_getUserTrait.php
Normal file
71
Modules/Application/Controller/d3_totp_getUserTrait.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?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\Totp\Modules\Application\Controller;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait d3_totp_getUserTrait
|
||||
{
|
||||
/**
|
||||
* @return false|User
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function getUser(): false|User
|
||||
{
|
||||
$user = parent::getUser();
|
||||
|
||||
if ($user && $user->isLoaded() && $user->getId()) {
|
||||
$totp = $this->d3GetTotpObject();
|
||||
$totp->loadByUserId($user->getId());
|
||||
|
||||
if ($totp->isActive()
|
||||
&& !$this->d3TotpGetSessionObject()->getVariable(
|
||||
isAdmin() ? d3totp_conf::SESSION_ADMIN_AUTH : d3totp_conf::SESSION_AUTH
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3GetTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSessionObject(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
}
|
74
Modules/Application/Model/d3_totp_user.php
Normal file
74
Modules/Application/Model/d3_totp_user.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?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\Totp\Modules\Application\Model;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
|
||||
class d3_totp_user extends d3_totp_user_parent
|
||||
{
|
||||
public function logout()
|
||||
{
|
||||
$return = parent::logout();
|
||||
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_AUTH);
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_CURRENTUSER);
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_AUTH);
|
||||
$this->d3TotpGetSession()->deleteVariable(d3totp_conf::SESSION_ADMIN_CURRENTUSER);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3getTotp(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSession(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
|
||||
public function d3getSessionedTotp(): d3totp
|
||||
{
|
||||
$totp = $this->d3getTotp();
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::OTP_SESSION_VARNAME, $totp);
|
||||
return $totp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function d3TotpGetCurrentUser(): ?string
|
||||
{
|
||||
return $this->isAdmin() ?
|
||||
($this->d3TotpGetSession()->hasVariable(d3totp_conf::SESSION_ADMIN_CURRENTUSER) ?
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_CURRENTUSER) :
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::OXID_ADMIN_AUTH))
|
||||
:
|
||||
($this->d3TotpGetSession()->hasVariable(d3totp_conf::SESSION_CURRENTUSER) ?
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_CURRENTUSER) :
|
||||
$this->d3TotpGetSession()->getVariable(d3totp_conf::OXID_FRONTEND_AUTH));
|
||||
}
|
||||
}
|
123
Modules/Core/d3_totp_utils.php
Normal file
123
Modules/Core/d3_totp_utils.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?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\Totp\Modules\Core;
|
||||
|
||||
use D3\Totp\Application\Model\Constants;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use Doctrine\DBAL\Driver\Exception;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleSettingNotFountException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class d3_totp_utils extends d3_totp_utils_parent
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws ModuleSettingNotFountException
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
*/
|
||||
public function checkAccessRights()
|
||||
{
|
||||
$blAuth = parent::checkAccessRights();
|
||||
$blAuth = $this->d3AuthHook($blAuth);
|
||||
$userID = $this->d3TotpGetSessionObject()->getVariable(d3totp_conf::OXID_ADMIN_AUTH);
|
||||
$totpAuth = (bool) $this->d3TotpGetSessionObject()->getVariable(d3totp_conf::SESSION_ADMIN_AUTH);
|
||||
$totp = $this->d3GetTotpObject();
|
||||
$totp->loadByUserId($userID);
|
||||
|
||||
//check forced 2FA for all admin users
|
||||
if (
|
||||
$this->d3IsAdminForce2FA()
|
||||
&& $blAuth
|
||||
&& $totp->isActive() === false
|
||||
) {
|
||||
$this->redirect('index.php?cl=d3force_2fa');
|
||||
}
|
||||
|
||||
//staten der prüfung vom einmalpasswort
|
||||
if ($blAuth && $totp->isActive() && false === $totpAuth) {
|
||||
$this->redirect('index.php?cl=d3totpadminlogin', false);
|
||||
}
|
||||
|
||||
return $blAuth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSessionObject(): Session
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3GetTotpObject(): d3totp
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
public function d3GetConfig(): Config
|
||||
{
|
||||
return Registry::getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ModuleSettingNotFountException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function d3IsAdminForce2FA(): bool
|
||||
{
|
||||
if (!$this->isAdmin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->getModuleConfiguration()->getModuleSetting('D3_TOTP_ADMIN_FORCE_2FA')->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $blAuth
|
||||
* @return bool
|
||||
*/
|
||||
protected function d3AuthHook(bool $blAuth): bool
|
||||
{
|
||||
return $blAuth;
|
||||
}
|
||||
|
||||
protected function getModuleConfiguration(): ModuleConfiguration
|
||||
{
|
||||
$container = ContainerFactory::getInstance()->getContainer();
|
||||
$moduleConfigurationBridge = $container->get(ModuleConfigurationDaoBridgeInterface::class);
|
||||
/** @var ModuleConfiguration $moduleConfiguration */
|
||||
return $moduleConfigurationBridge->get(Constants::OXID_MODULE_ID);
|
||||
}
|
||||
}
|
117
Modules/Core/totpSystemEventHandler.php
Normal file
117
Modules/Core/totpSystemEventHandler.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?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\Totp\Modules\Core;
|
||||
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use Doctrine\DBAL\Driver\Exception as DBALDriverException;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class totpSystemEventHandler extends totpSystemEventHandler_parent
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DBALDriverException
|
||||
* @throws DBALException
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function onAdminLogin()
|
||||
{
|
||||
$this->d3requestTotp();
|
||||
|
||||
parent::onAdminLogin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws DBALDriverException
|
||||
* @throws DBALException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function d3requestTotp(): void
|
||||
{
|
||||
$totp = $this->d3GetTotpObject();
|
||||
$userId = $this->d3TotpGetSession()->getVariable(d3totp_conf::OXID_ADMIN_AUTH);
|
||||
$totp->loadByUserId($userId);
|
||||
|
||||
if ($this->d3TotpLoginMissing($totp)) {
|
||||
/** @var d3_totp_user $user */
|
||||
$user = $this->d3TotpGetUserObject();
|
||||
$user->logout();
|
||||
|
||||
$this->d3TotpGetSession()->setVariable(d3totp_conf::SESSION_ADMIN_CURRENTUSER, $userId);
|
||||
|
||||
$this->getUtilsObject()->redirect(
|
||||
'index.php?cl=d3totpadminlogin&'.
|
||||
'stoken='.Registry::getRequest()->getRequestEscapedParameter('stoken').'&'.
|
||||
'profile='.Registry::getRequest()->getRequestEscapedParameter('profile').'&'.
|
||||
'chlanguage='.Registry::getRequest()->getRequestEscapedParameter('chlanguage'),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return d3totp
|
||||
*/
|
||||
public function d3GetTotpObject()
|
||||
{
|
||||
return oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Utils
|
||||
*/
|
||||
public function getUtilsObject(): Utils
|
||||
{
|
||||
return Registry::getUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Session
|
||||
*/
|
||||
public function d3TotpGetSession()
|
||||
{
|
||||
return Registry::getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param d3totp $totp
|
||||
* @return bool
|
||||
*/
|
||||
public function d3TotpLoginMissing(d3totp $totp)
|
||||
{
|
||||
return $totp->isActive()
|
||||
&& false == $this->d3TotpGetSession()->getVariable(d3totp_conf::SESSION_ADMIN_AUTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
protected function d3TotpGetUserObject(): User
|
||||
{
|
||||
return oxNew(User::class);
|
||||
}
|
||||
}
|
92
README.en.md
Normal file
92
README.en.md
Normal file
@ -0,0 +1,92 @@
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
# 2-factor authentication (one-time password) for OXID eShop
|
||||
|
||||
This module provides a 2-factor authentication (time-dependent one-time password / TOTP) for login in front- and backend in addition to username and password.
|
||||
|
||||
## Features
|
||||
|
||||
- 2-factor authentication for logins in front- and backend in addition to username and password
|
||||
- Activation and setup possible in the front and back end
|
||||
- Authentication is shown for user accounts that have this enabled - otherwise the usual default login.
|
||||
- Access can be set up in the Auth app by scannable QR code or copyable character string
|
||||
- Validation of one-time passwords and generation of QR codes are only carried out within the shop - no communication to the outside necessary
|
||||
- static backup codes also allow (limited) login without access to the generation tool
|
||||
- The setting up of the second factor can be made obligatory for admin users.
|
||||
|
||||
### Setup
|
||||

|
||||

|
||||
|
||||
### Login
|
||||

|
||||

|
||||
|
||||
## System requirements
|
||||
|
||||
This package requires an OXID eShop installed with Composer in one of the following versions:
|
||||
|
||||
- 7.0.x
|
||||
- 7.1.x
|
||||
|
||||
and its requirements.
|
||||
|
||||
The Apex (Twig based) and Wave (Smarty based) themes are supported by default. Other themes may require customisation.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Open a command line interface and navigate to the shop root directory (parent of source and vendor). Execute the following command. Adapt the paths to your environment.
|
||||
|
||||
```
|
||||
composer require d3/oxid-twofactor-onetimepassword
|
||||
```
|
||||
|
||||
Activate the module in the admin area of the shop in "Extensions -> Modules".
|
||||
|
||||
The necessary configuration can be found in the same area in the "Settings" tab.
|
||||
|
||||
### Additional installation instructions
|
||||
|
||||
- [Customising the database structure](migration/README.en.md)
|
||||
|
||||
## Changelog
|
||||
|
||||
See [CHANGELOG](CHANGELOG.md) for further information.
|
||||
|
||||
## Contributing
|
||||
|
||||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue. Don't forget to give the project a star! Thanks again!
|
||||
|
||||
- Fork the Project
|
||||
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
|
||||
- Commit your Changes (git commit -m 'Add some AmazingFeature')
|
||||
- Push to the Branch (git push origin feature/AmazingFeature)
|
||||
- Open a Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
If you have any questions about the *messaging service* and its *contracts*, please contact the [LINK Mobility Team](https://www.linkmobility.de/kontakt).
|
||||
|
||||
For *technical inquiries* you will find the contact options in the [composer.json](composer.json).
|
||||
|
||||
## License
|
||||
(status: 2018-10-17)
|
||||
|
||||
Distributed under the GPLv3 license.
|
||||
|
||||
```
|
||||
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
|
||||
This software is distributed under the GNU GENERAL PUBLIC LICENSE version 3.
|
||||
```
|
||||
|
||||
For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code.
|
||||
|
||||
## Credits
|
||||
|
||||
Contributors to this module were:
|
||||
|
||||
- Tobias Matthaiou
|
||||
|
||||
Thanks to.
|
86
README.md
86
README.md
@ -1,10 +1,86 @@
|
||||
# oxtotp (2FA)
|
||||
Modul für eine 2-Faktor-Authentisierung (2FA) zum Login in Front- und Backend zusätzlich zu Benutzername und Passwort.
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
- Authentisierung wird nur bei Benutzerkonten gezeigt, die dieses aktiviert haben - sonst nur Standardanmeldung die Basis der Passwortgenerierung wird für jedes Benutzerkonto individuell angelegt</li>
|
||||
# 2-Faktor-Authentisierung (Einmalpasswort) für OXID eShop
|
||||
|
||||
Dieses Modul stellt eine 2-Faktor-Authentisierung (zeitabhängiges Einmalpasswort / TOTP) zum Login in Front- und Backend zusätzlich zu Benutzername und Passwort zur Verfügung.
|
||||
|
||||
## Features
|
||||
|
||||
- 2-Faktor-Authentisierung für Logins in Front- und Backend zusätzlich zu Benutzername und Passwort
|
||||
- Aktivierung und Einrichtung im Front- und Backend möglich
|
||||
- Authentisierung wird bei Benutzerkonten gezeigt, die dieses aktiviert haben - sonst die übliche Standardanmeldung
|
||||
- Einrichtung des Zugangs in der Auth-App kann durch scanbaren QR-Code oder kopierbare Zeichenkette erfolgen
|
||||
|
||||
- Validierung der Einmalpassworte und Generierung der QR-Codes werden ausschließlich innerhalb des Shops durchgeführt - keine Kommunikation nach außen nötig
|
||||
|
||||
- statische Backupcodes ermöglichen auch eine (begrenzte) Anmeldung ohne Zugang zum Generierungstool
|
||||
- für Adminbenutzer kann die Einrichtung des zweiten Faktors verpflichtend eingestellt werden
|
||||
|
||||
### Einrichtung
|
||||

|
||||

|
||||
|
||||
### Login
|
||||

|
||||

|
||||
|
||||
## Systemanforderungen
|
||||
|
||||
Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer der folgenden Versionen:
|
||||
|
||||
- 7.0.x
|
||||
- 7.1.x
|
||||
|
||||
und dessen Anforderungen.
|
||||
|
||||
Im Standard wird das Apex- (Twig) und Wave- (Smarty) Theme unterstützt. Andere Themes können Anpassungen erfordern.
|
||||
|
||||
## Erste Schritte
|
||||
|
||||
Öffnen Sie eine Kommandozeile und navigieren Sie zum Stammverzeichnis des Shops (Elternverzeichnis von source und vendor). Führen Sie den folgenden Befehl aus. Passen Sie die Pfadangaben an Ihre Installationsumgebung an.
|
||||
|
||||
```
|
||||
composer require d3/oxid-twofactor-onetimepassword
|
||||
```
|
||||
|
||||
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
|
||||
|
||||
Die nötige Konfiguration finden Sie im selben Bereich im Tab "Einstell.".
|
||||
|
||||
### ergänzende Installationhinweise
|
||||
|
||||
- [Anpassen der Datenbankstruktur](migration/README.md)
|
||||
|
||||
## Changelog
|
||||
|
||||
Siehe [CHANGELOG](CHANGELOG.md) für weitere Informationen.
|
||||
|
||||
## Beitragen
|
||||
|
||||
Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Respoitories an und erstellen Sie einen Pull Request. Alternativ können Sie einfach ein Issue erstellen. Fügen Sie das Projekt zu Ihren Favoriten hinzu. Vielen Dank.
|
||||
|
||||
- Erstellen Sie einen Fork des Projekts
|
||||
- Erstellen Sie einen Feature Branch (git checkout -b feature/AmazingFeature)
|
||||
- Fügen Sie Ihre Änderungen hinzu (git commit -m 'Add some AmazingFeature')
|
||||
- Übertragen Sie den Branch (git push origin feature/AmazingFeature)
|
||||
- Öffnen Sie einen Pull Request
|
||||
|
||||
## Lizenz
|
||||
(Stand: 17.10.2018)
|
||||
|
||||
Vertrieben unter der GPLv3 Lizenz.
|
||||
|
||||
```
|
||||
Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
|
||||
Diese Software wird unter der GNU GENERAL PUBLIC LICENSE Version 3 vertrieben.
|
||||
```
|
||||
|
||||
Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde.
|
||||
|
||||
## Credits
|
||||
|
||||
Zu diesem Modul haben beigetragen:
|
||||
|
||||
- Tobias Matthaiou
|
||||
|
||||
Vielen Dank.
|
188
Setup/Actions.php
Normal file
188
Setup/Actions.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?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\Totp\Setup;
|
||||
|
||||
use D3\OxidServiceBridges\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceBridge;
|
||||
use D3\OxidServiceBridges\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceBridgeInterface;
|
||||
use Exception;
|
||||
use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder;
|
||||
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
||||
use OxidEsales\Eshop\Core\DbMetaDataHandler;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\SeoEncoder;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Actions
|
||||
{
|
||||
public array $seo_de = [
|
||||
'2-faktor-authentisierung/',
|
||||
];
|
||||
public array $seo_en = [
|
||||
'en/2-factor-authentication/',
|
||||
];
|
||||
public array $stdClassName = [
|
||||
'd3_account_totp',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return MigrationsBuilder
|
||||
*/
|
||||
protected function getMigrationsBuilder(): MigrationsBuilder
|
||||
{
|
||||
return oxNew(MigrationsBuilder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function runModuleMigrations(): void
|
||||
{
|
||||
$migrationsBuilder = $this->getMigrationsBuilder();
|
||||
$migrations = $migrationsBuilder->build();
|
||||
$migrations->execute('migrations:migrate', 'd3totp');
|
||||
}
|
||||
|
||||
protected function getDbMetaDataHandler(): DbMetaDataHandler
|
||||
{
|
||||
return oxNew(DbMetaDataHandler::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate views for changed tables
|
||||
* @throws Exception
|
||||
*/
|
||||
public function regenerateViews(): void
|
||||
{
|
||||
$oDbMetaDataHandler = $this->getDbMetaDataHandler();
|
||||
$oDbMetaDataHandler->updateViews();
|
||||
}
|
||||
|
||||
protected function getUtils(): Utils
|
||||
{
|
||||
return oxNew(Utils::class);
|
||||
}
|
||||
|
||||
protected function getLogger(): LoggerInterface
|
||||
{
|
||||
return Registry::getLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* clear cache
|
||||
* @throws Exception
|
||||
*/
|
||||
public function clearCache(): void
|
||||
{
|
||||
try {
|
||||
/** @var ShopTemplateCacheServiceBridge $templateCacheService */
|
||||
$templateCacheService = $this->getDIContainer()->get(ShopTemplateCacheServiceBridgeInterface::class);
|
||||
$templateCacheService->invalidateCache(Registry::getConfig()->getShopId());
|
||||
$oUtils = $this->getUtils();
|
||||
$oUtils->resetLanguageCache();
|
||||
} catch (ContainerExceptionInterface $e) {
|
||||
Registry::getLogger()->error($e->getMessage(), [$this]);
|
||||
Registry::getUtilsView()->addErrorToDisplay($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function seoUrl(): void
|
||||
{
|
||||
try {
|
||||
$seoEncoder = oxNew(SeoEncoder::class);
|
||||
if (!$this->hasSeoUrls($seoEncoder)) {
|
||||
$this->createSeoUrls($seoEncoder);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->getLogger()->error($e->getMessage(), [$this]);
|
||||
Registry::getUtilsView()->addErrorToDisplay('error wile creating SEO URLs: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SeoEncoder $seoEncoder
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSeoUrls(SeoEncoder $seoEncoder): bool
|
||||
{
|
||||
foreach ($this->stdClassName as $item) {
|
||||
foreach ([0, 1] as $lang) {
|
||||
if (false === $this->hasSeoUrl($seoEncoder, $item, $lang)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function hasSeoUrl(SeoEncoder $seoEncoder, string $item, int $langId): bool
|
||||
{
|
||||
$seoUrl = $seoEncoder->getStaticUrl(
|
||||
oxNew(FrontendController::class)->getViewConfig()->getSelfLink() .
|
||||
"cl=" . $item,
|
||||
$langId
|
||||
);
|
||||
return (bool)strlen($seoUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SeoEncoder $seoEncoder
|
||||
* @return void
|
||||
*/
|
||||
public function createSeoUrls(SeoEncoder $seoEncoder): void
|
||||
{
|
||||
foreach (array_keys($this->stdClassName) as $id) {
|
||||
$objectid = md5(strtolower(Registry::getConfig()->getShopId() . 'index.php?cl=' . $this->stdClassName[$id]));
|
||||
if (!$this->hasSeoUrl($seoEncoder, $this->stdClassName[$id], 0)) {
|
||||
$seoEncoder->addSeoEntry(
|
||||
$objectid,
|
||||
Registry::getConfig()->getShopId(),
|
||||
0,
|
||||
'index.php?cl=' . $this->stdClassName[$id],
|
||||
$this->seo_de[$id],
|
||||
'static',
|
||||
false
|
||||
);
|
||||
}
|
||||
if (!$this->hasSeoUrl($seoEncoder, $this->stdClassName[$id], 1)) {
|
||||
$seoEncoder->addSeoEntry(
|
||||
$objectid,
|
||||
Registry::getConfig()->getShopId(),
|
||||
1,
|
||||
'index.php?cl=' . $this->stdClassName[$id],
|
||||
$this->seo_en[$id],
|
||||
'static',
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ContainerInterface|null
|
||||
*/
|
||||
protected function getDIContainer(): ?ContainerInterface
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer();
|
||||
}
|
||||
}
|
43
Setup/Events.php
Normal file
43
Setup/Events.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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\Totp\Setup;
|
||||
|
||||
use Exception;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
class Events
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function onActivate(): void
|
||||
{
|
||||
$actions = oxNew(Actions::class);
|
||||
$actions->runModuleMigrations();
|
||||
$actions->regenerateViews();
|
||||
$actions->clearCache();
|
||||
$actions->seoUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function onDeactivate(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
147
Tests/Unit/Application/Controller/Admin/d3force_2faTest.php
Normal file
147
Tests/Unit/Application/Controller/Admin/d3force_2faTest.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
namespace D3\Totp\Tests\Unit\Application\Controller\Admin;
|
||||
|
||||
use D3\Totp\Application\Controller\Admin\d3force_2fa;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3force_2faTest extends d3user_totpTest
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3force_2fa::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::render
|
||||
*/
|
||||
public function testRender()
|
||||
{
|
||||
$expected = 'fixture';
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, $expected);
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'render'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->_oController->getViewDataElement('force2FA')
|
||||
);
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->getValue(
|
||||
$this->_oController,
|
||||
'_sEditObjectId'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::authorize
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::d3IsAdminForce2FA
|
||||
* @dataProvider authorizeDataProvider
|
||||
*/
|
||||
public function testAuthorize($expected, $isAdmin, $force2FA, $givenUserId)
|
||||
{
|
||||
$settingMock = $this->d3getMockBuilder(Setting::class)
|
||||
->onlyMethods(['getValue'])
|
||||
->getMock();
|
||||
$settingMock->method('getValue')->willReturn($force2FA);
|
||||
|
||||
$moduleConfigurationMock = $this->d3getMockBuilder(ModuleConfiguration::class)
|
||||
->onlyMethods(['getModuleSetting'])
|
||||
->getMock();
|
||||
$moduleConfigurationMock->method('getModuleSetting')->willReturn($settingMock);
|
||||
|
||||
/** @var d3force_2fa|MockObject $oController */
|
||||
$oController = $this->d3getMockBuilder(d3force_2fa::class)
|
||||
->onlyMethods(['isAdmin', 'getModuleConfiguration'])
|
||||
->getMock();
|
||||
$oController->expects($this->any())->method('isAdmin')->willReturn($isAdmin);
|
||||
$oController->method('getModuleConfiguration')->willReturn($moduleConfigurationMock);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, $givenUserId);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$oController,
|
||||
'authorize'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public static function authorizeDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'noAdmin' => [false, false, true, 'userId'],
|
||||
'dont force' => [false, true, false, 'userId'],
|
||||
'no user id' => [false, true, true, null],
|
||||
'passed' => [true, true, true, 'userId'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::d3TotpGetSessionObject
|
||||
*/
|
||||
public function testD3GetSessionObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3TotpGetSessionObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3force_2fa::getModuleConfiguration
|
||||
*/
|
||||
public function canGetModuleConfiguration()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
ModuleConfiguration::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getModuleConfiguration'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
686
Tests/Unit/Application/Controller/Admin/d3totpadminloginTest.php
Normal file
686
Tests/Unit/Application/Controller/Admin/d3totpadminloginTest.php
Normal file
@ -0,0 +1,686 @@
|
||||
<?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\Totp\Tests\Unit\Application\Controller\Admin;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Controller\Admin\d3totpadminlogin;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Logger\Wrapper\LoggerWrapper;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
|
||||
class d3totpadminloginTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3totpadminlogin */
|
||||
protected $_oController;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3totpadminlogin::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::authorize
|
||||
*/
|
||||
public function testAuthorize()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'authorize'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetTotpObject
|
||||
*/
|
||||
public function d3TotpGetTotpObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3TotpGetTotpObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $hasAuthAlready
|
||||
* @param $totpActive
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::isTotpIsNotRequired
|
||||
* @dataProvider isTotpIsNotRequiredPassedDataProvider
|
||||
*/
|
||||
public function isTotpIsNotRequiredPassed($hasAuthAlready, $totpActive, $expected)
|
||||
{
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser'])
|
||||
->getMock();
|
||||
$oUserMock->method('d3TotpGetCurrentUser')->willReturn('foo');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn($totpActive);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'hasVariable',
|
||||
])
|
||||
->getMock();
|
||||
$hasVariableMap = [
|
||||
[d3totp_conf::SESSION_ADMIN_AUTH, $hasAuthAlready],
|
||||
];
|
||||
$oSessionMock->method('hasVariable')->willReturnMap($hasVariableMap);
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods([
|
||||
'd3TotpGetSession',
|
||||
'd3TotpGetTotpObject',
|
||||
'd3TotpGetUserObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'isTotpIsNotRequired'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function isTotpIsNotRequiredPassedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'auth already finished' => [true, true, true],
|
||||
'auth required' => [false, true, false],
|
||||
'totp inactive' => [false, false, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $userId
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::isTotpLoginNotPossible
|
||||
* @dataProvider isTotpLoginNotPossiblePassedDataProvider
|
||||
*/
|
||||
public function isTotpLoginNotPossiblePassed($userId, $expected)
|
||||
{
|
||||
/** @var d3_totp_user|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser'])
|
||||
->getMock();
|
||||
$oUserMock->method('d3TotpGetCurrentUser')->willReturn($userId);
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods(['d3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'isTotpLoginNotPossible'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function isTotpLoginNotPossiblePassedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'no user' => [null, true],
|
||||
'has user' => ['userId', false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $totpNotRequired
|
||||
* @param $totpNotPossible
|
||||
* @param $redirect
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::render
|
||||
* @dataProvider canRenderDataProvider
|
||||
*/
|
||||
public function canRender($totpNotRequired, $totpNotPossible, $redirect)
|
||||
{
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock
|
||||
->expects(is_null($redirect) ? $this->never() : $this->once())
|
||||
->method('redirect')
|
||||
->with($this->identicalTo('index.php?cl='.$redirect))
|
||||
->willReturn(true);
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $loginControllerMock */
|
||||
$loginControllerMock = $this->d3getMockBuilder(LoginController::class)
|
||||
->onlyMethods(['d3totpAfterLoginSetLanguage'])
|
||||
->getMock();
|
||||
$loginControllerMock->expects($this->once())->method('d3totpAfterLoginSetLanguage');
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods([
|
||||
'isTotpIsNotRequired',
|
||||
'isTotpLoginNotPossible',
|
||||
'd3TotpGetUtils',
|
||||
'd3GetLoginController',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('isTotpIsNotRequired')->willReturn($totpNotRequired);
|
||||
$oControllerMock->method('isTotpLoginNotPossible')->willReturn($totpNotPossible);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
$oControllerMock->method('d3GetLoginController')->willReturn($loginControllerMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'render'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public static function canRenderDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'not required' => [true, false, 'admin_start'],
|
||||
'not possible' => [false, true, 'login'],
|
||||
'do auth' => [false, false, null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3GetBackupCodeListObject
|
||||
*/
|
||||
public function d3GetBackupCodeListObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcodelist::class,
|
||||
$this->callMethod($this->_oController, 'd3GetBackupCodeListObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::getBackupCodeCountMessage
|
||||
*/
|
||||
public function getBackupCodeCountMessageShowMessage()
|
||||
{
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser'])
|
||||
->getMock();
|
||||
$userMock->method('d3TotpGetCurrentUser')->willReturn('foo');
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(2);
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods(['d3GetBackupCodeListObject', 'd3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
strpos(
|
||||
$this->callMethod($this->_oController, 'getBackupCodeCountMessage'),
|
||||
' 2 '
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::getBackupCodeCountMessage
|
||||
*/
|
||||
public function getBackupCodeCountMessageDontShowMessage()
|
||||
{
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser'])
|
||||
->getMock();
|
||||
$userMock->method('d3TotpGetCurrentUser')->willReturn('foo');
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(10);
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods(['d3GetBackupCodeListObject', 'd3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertEmpty(
|
||||
$this->callMethod($this->_oController, 'getBackupCodeCountMessage')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3CancelLogin
|
||||
*/
|
||||
public function canCancelLogin()
|
||||
{
|
||||
/** @var d3_totp_user|MockObject $userMock */
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['logout'])
|
||||
->getMock();
|
||||
$userMock->expects($this->once())->method('logout')->willReturn(true);
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods(['d3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
'login',
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3CancelLogin'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetUserObject
|
||||
*/
|
||||
public function d3GetUserObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetUserObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::checklogin
|
||||
*/
|
||||
public function checkloginUnvalidTotp()
|
||||
{
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser'])
|
||||
->getMock();
|
||||
$userMock->method('d3TotpGetCurrentUser')->willReturn('foo');
|
||||
|
||||
/** @var LoggerWrapper|MockObject $loggerMock */
|
||||
$loggerMock = $this->d3getMockBuilder(LoggerWrapper::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['error', 'debug'])
|
||||
->getMock();
|
||||
$loggerMock->expects($this->atLeastOnce())->method('error')->willReturn(true);
|
||||
$loggerMock->expects($this->atLeastOnce())->method('debug')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'initNewSession',
|
||||
'setVariable',
|
||||
'deleteVariable',
|
||||
])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('initNewSession')->willReturn(false);
|
||||
$oSessionMock->expects($this->never())->method('setVariable')->willReturn(false);
|
||||
$oSessionMock->expects($this->never())->method('deleteVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $loginControllerMock */
|
||||
$loginControllerMock = $this->d3getMockBuilder(LoginController::class)
|
||||
->onlyMethods(['d3totpAfterLogin'])
|
||||
->getMock();
|
||||
$loginControllerMock->expects($this->never())->method('d3totpAfterLogin');
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods([
|
||||
'getLogger',
|
||||
'd3TotpHasValidTotp',
|
||||
'd3TotpGetSession',
|
||||
'd3GetLoginController',
|
||||
'd3TotpGetUserObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpHasValidTotp')
|
||||
->willThrowException(oxNew(d3totp_wrongOtpException::class));
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('getLogger')->willReturn($loggerMock);
|
||||
$oControllerMock->method('d3GetLoginController')->willReturn($loginControllerMock);
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'checklogin'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::checklogin
|
||||
*/
|
||||
public function checkloginValidTotp()
|
||||
{
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser'])
|
||||
->getMock();
|
||||
$userMock->method('d3TotpGetCurrentUser')->willReturn('foo');
|
||||
|
||||
/** @var LoggerWrapper|MockObject $loggerMock */
|
||||
$loggerMock = $this->d3getMockBuilder(LoggerWrapper::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['error', 'debug'])
|
||||
->getMock();
|
||||
$loggerMock->expects($this->never())->method('error')->willReturn(true);
|
||||
$loggerMock->expects($this->never())->method('debug')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods([
|
||||
'initNewSession',
|
||||
'setVariable',
|
||||
'deleteVariable',
|
||||
])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeastOnce())->method('initNewSession')->willReturn(false);
|
||||
$oSessionMock->expects($this->atLeastOnce())->method('setVariable')->willReturn(false);
|
||||
$oSessionMock->expects($this->atLeastOnce())->method('deleteVariable')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $loginControllerMock */
|
||||
$loginControllerMock = $this->d3getMockBuilder(LoginController::class)
|
||||
->onlyMethods(['d3totpAfterLogin'])
|
||||
->getMock();
|
||||
$loginControllerMock->expects($this->once())->method('d3totpAfterLogin');
|
||||
|
||||
/** @var d3totpadminlogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totpadminlogin::class)
|
||||
->onlyMethods([
|
||||
'getLogger',
|
||||
'd3TotpHasValidTotp',
|
||||
'd3TotpGetSession',
|
||||
'd3GetLoginController',
|
||||
'd3TotpGetUserObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpHasValidTotp')->willReturn(true);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('getLogger')->willReturn($loggerMock);
|
||||
$oControllerMock->method('d3GetLoginController')->willReturn($loginControllerMock);
|
||||
$oControllerMock->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'checklogin'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpTrueSessionVarname()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_ADMIN_AUTH, true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpTrueValidTotp()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_ADMIN_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpFalseMissingTotp()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_ADMIN_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willThrowException(oxNew(d3totp_wrongOtpException::class));
|
||||
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpFalseUnverifiedTotp()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_ADMIN_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetUtils
|
||||
*/
|
||||
public function d3TotpGetUtilsReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3TotpGetUtils'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3TotpGetSession
|
||||
*/
|
||||
public function d3GetSessionReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3TotpGetSession'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::getLogger
|
||||
*/
|
||||
public function getLoggerReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getLogger'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3totpadminlogin::d3GetLoginController
|
||||
*/
|
||||
public function d3GetLoginControllerReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
LoginController::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3GetLoginController'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
579
Tests/Unit/Application/Controller/Admin/d3user_totpTest.php
Normal file
579
Tests/Unit/Application/Controller/Admin/d3user_totpTest.php
Normal file
@ -0,0 +1,579 @@
|
||||
<?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\Totp\Tests\Unit\Application\Controller\Admin;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Controller\Admin\d3user_totp;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3user_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3user_totp */
|
||||
protected $_oController;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3user_totp::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::render
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getViewDataElement
|
||||
*/
|
||||
public function canRenderNoSelectedUser()
|
||||
{
|
||||
$userMock = oxNew(User::class);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('-1');
|
||||
$oControllerMock->expects($this->never())->method('getUserObject')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$sTpl = $this->callMethod($this->_oController, 'render');
|
||||
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['edit']);
|
||||
|
||||
$this->assertSame('@d3totp/admin/d3user_totp', $sTpl);
|
||||
$this->assertSame($tplUser, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::render
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getViewDataElement
|
||||
*/
|
||||
public function canRenderSelectedUser()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'getId',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->atLeast(1))->method('getId')->willReturn('foobar');
|
||||
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(true);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$sTpl = $this->callMethod($this->_oController, 'render');
|
||||
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['edit']);
|
||||
$oxid = $this->callMethod($this->_oController, 'getViewDataElement', ['oxid']);
|
||||
|
||||
$this->assertSame('@d3totp/admin/d3user_totp', $sTpl);
|
||||
$this->assertSame($tplUser, $oUserMock);
|
||||
$this->assertSame($oxid, 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::render
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getViewDataElement
|
||||
*/
|
||||
public function canRenderUnloadableUser()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'getId',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->never())->method('getId');
|
||||
$oUserMock->expects($this->atLeast(1))->method('load')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'addTplParam',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->expects($this->once())->method('getUserObject')->willReturn($oUserMock);
|
||||
$oControllerMock->expects($this->exactly(3))->method('addTplParam')->with(
|
||||
$this->logicalOr(
|
||||
$this->stringContains('sSaveError'),
|
||||
$this->stringContains('oxid'),
|
||||
$this->stringContains('edit')
|
||||
)
|
||||
);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->setValue($this->_oController, '_sSaveError', 'foo');
|
||||
|
||||
$sTpl = $this->callMethod($this->_oController, 'render');
|
||||
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['edit']);
|
||||
$oxid = $this->callMethod($this->_oController, 'getViewDataElement', ['oxid']);
|
||||
|
||||
$this->assertSame('@d3totp/admin/d3user_totp', $sTpl);
|
||||
$this->assertNull($tplUser);
|
||||
$this->assertSame($oxid, 'foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getUserObject
|
||||
*/
|
||||
public function getUserObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getUserObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getTotpObject
|
||||
*/
|
||||
public function getTotpObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getTotpObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getBackupcodeListObject
|
||||
*/
|
||||
public function getBackupCodeListObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcodelist::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getBackupCodeListObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::save
|
||||
*/
|
||||
public function cantSaveBecauseOfNotVerifiable()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('save');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->never())->method('save')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('verify')->willThrowException(new Exception());
|
||||
$oTotpMock->method('saveSecret');
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->method('checkIfAlreadyExist')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$_GET['otp'] = '123456';
|
||||
Registry::getSession()->setVariable(d3totp_conf::OTP_SESSION_VARNAME, $oTotpMock);
|
||||
|
||||
$this->callMethod($this->_oController, 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::save
|
||||
*/
|
||||
public function cantSaveBecauseExistingRegistration()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('save');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->never())->method('save')->willReturn(true);
|
||||
$oTotpMock->expects($this->never())->method('verify')->willThrowException(new Exception());
|
||||
$oTotpMock->method('saveSecret');
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->method('checkIfAlreadyExist')->willReturn(true);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::save
|
||||
*/
|
||||
public function canSave()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'save',
|
||||
'generateBackupCodes',
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('save');
|
||||
$oBackupCodeListMock->method('generateBackupCodes');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('verify')->willReturn(true);
|
||||
$oTotpMock->method('saveSecret');
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->method('checkIfAlreadyExist')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$_GET['otp'] = '123456';
|
||||
Registry::getSession()->setVariable(d3totp_conf::OTP_SESSION_VARNAME, $oTotpMock);
|
||||
|
||||
$this->callMethod($this->_oController, 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::save
|
||||
*/
|
||||
public function canSaveWithKnownOXID()
|
||||
{
|
||||
$aEditval = [
|
||||
'd3totp__oxid' => 'foo',
|
||||
];
|
||||
$_GET['editval'] = $aEditval;
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'save',
|
||||
'generateBackupCodes',
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('save');
|
||||
$oBackupCodeListMock->method('generateBackupCodes');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'load',
|
||||
'save',
|
||||
'verify',
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'checkIfAlreadyExist',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('load')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('save')->willReturn(true);
|
||||
$oTotpMock->expects($this->never())->method('verify')->willReturn(true);
|
||||
$oTotpMock->method('saveSecret');
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->method('checkIfAlreadyExist')->willReturn(false);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId',
|
||||
'getUserObject',
|
||||
'getTotpObject',
|
||||
'getBackupcodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foobar');
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getBackupcodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::setBackupCodes
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getBackupCodes
|
||||
*/
|
||||
public function canSetAndGetBackupCodes()
|
||||
{
|
||||
$aBackupList = [
|
||||
'foo1',
|
||||
'bar2',
|
||||
];
|
||||
|
||||
$this->callMethod($this->_oController, 'setBackupCodes', [$aBackupList]);
|
||||
|
||||
$aReturn = $this->callMethod($this->_oController, 'getBackupCodes');
|
||||
|
||||
$this->assertSame('foo1'.PHP_EOL.'bar2', $aReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @te__st
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::delete
|
||||
*/
|
||||
public function cantDeleteIfNotSetOxid()
|
||||
{
|
||||
$editval = [];
|
||||
$_GET['editval'] = $editval;
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('delete');
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::delete
|
||||
*/
|
||||
public function canDelete()
|
||||
{
|
||||
$editval = [
|
||||
'd3totp__oxid' => 'foo',
|
||||
];
|
||||
$_GET['editval'] = $editval;
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'delete',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
$oTotpMock->method('load')->willReturn(true);
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getAvailableBackupCodeCount
|
||||
*/
|
||||
public function canGetAvailableBackupCodeCount()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25);
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getBackupCodeListObject',
|
||||
'getUser',
|
||||
'getEditObjectId'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
$oControllerMock->method('getEditObjectId')->willReturn('foo');
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
25,
|
||||
$this->callMethod($this->_oController, 'getAvailableBackupCodeCount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\Admin\d3user_totp::getCurrentUserId
|
||||
*/
|
||||
public function canGetCurrentUserId(): void
|
||||
{
|
||||
/** @var d3user_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3user_totp::class)
|
||||
->onlyMethods([
|
||||
'getEditObjectId'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('getEditObjectId')->willReturn('foo');
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getCurrentUserId'
|
||||
);
|
||||
}
|
||||
}
|
456
Tests/Unit/Application/Controller/d3_account_totpTest.php
Normal file
456
Tests/Unit/Application/Controller/d3_account_totpTest.php
Normal file
@ -0,0 +1,456 @@
|
||||
<?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\Totp\Tests\Unit\Application\Controller;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Controller\d3_account_totp;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_account_totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3_account_totp */
|
||||
protected $_oController;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3_account_totp::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::render
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getViewDataElement
|
||||
*/
|
||||
public function renderReturnsDefaultTemplate()
|
||||
{
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
$oUser->assign(
|
||||
[
|
||||
'oxpassword' => 'foo',
|
||||
]
|
||||
);
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getUser'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$sTpl = $this->callMethod($this->_oController, 'render');
|
||||
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['user']);
|
||||
|
||||
$this->assertSame('@d3totp/tpl/d3_account_totp', $sTpl);
|
||||
$this->assertSame($tplUser, $oUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::render
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getViewDataElement
|
||||
*/
|
||||
public function renderReturnsLoginTemplateIfNotLoggedIn()
|
||||
{
|
||||
$oUser = null;
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getUser'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$sTpl = $this->callMethod($this->_oController, 'render');
|
||||
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['user']);
|
||||
|
||||
$this->assertSame('page/account/login', $sTpl);
|
||||
$this->assertNull($tplUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getBackupCodes
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::setBackupCodes
|
||||
*/
|
||||
public function canSetAndGetBackupCodes()
|
||||
{
|
||||
$aBackupList = [
|
||||
'foo1',
|
||||
'bar2',
|
||||
];
|
||||
|
||||
$this->callMethod($this->_oController, 'setBackupCodes', [$aBackupList]);
|
||||
|
||||
$aReturn = $this->callMethod($this->_oController, 'getBackupCodes');
|
||||
|
||||
$this->assertSame('foo1'.PHP_EOL.'bar2', $aReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getBackupCodeListObject
|
||||
*/
|
||||
public function canGetBackupCodeListReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcodelist::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getBackupCodeListObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getAvailableBackupCodeCount
|
||||
*/
|
||||
public function canGetAvailableBackupCodeCount()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('getAvailableCodeCount')->willReturn(25);
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getBackupCodeListObject',
|
||||
'getUser',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
25,
|
||||
$this->callMethod($this->_oController, 'getAvailableBackupCodeCount')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::create
|
||||
*/
|
||||
public function cantCreateIfTotpNotActive()
|
||||
{
|
||||
$_GET['totp_use'] = 0;
|
||||
|
||||
$totp = oxNew(d3totp::class);
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn($totp);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'create');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::create
|
||||
*/
|
||||
public function cantCreateIfTotpNotVerfiable()
|
||||
{
|
||||
$_GET['totp_use'] = '1';
|
||||
$_GET['otp'] = '123456';
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'generateBackupCodes',
|
||||
'save',
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('generateBackupCodes');
|
||||
$oBackupCodeListMock->expects($this->never())->method('save');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'verify',
|
||||
'save',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('saveSecret');
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('verify')->willThrowException(new Exception('foo'));
|
||||
$oTotpMock->expects($this->never())->method('save');
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'getBackupCodeListObject',
|
||||
'getTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::OTP_SESSION_VARNAME, $oTotpMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'create');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::create
|
||||
*/
|
||||
public function canCreate()
|
||||
{
|
||||
$_GET['totp_use'] = '1';
|
||||
$_GET['otp'] = '123456';
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'generateBackupCodes',
|
||||
'save',
|
||||
])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->method('generateBackupCodes');
|
||||
$oBackupCodeListMock->expects($this->once())->method('save');
|
||||
$oBackupCodeListMock->method('save');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'saveSecret',
|
||||
'assign',
|
||||
'verify',
|
||||
'save',
|
||||
'setId',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('saveSecret');
|
||||
$oTotpMock->method('assign')->willReturn(true);
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
$oTotpMock->method('setId')->willReturn(true);
|
||||
$oTotpMock->expects($this->once())->method('save')->willReturn(true);
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'getBackupCodeListObject',
|
||||
'getTotpObject'
|
||||
])
|
||||
->getMock();
|
||||
Registry::getSession()->setVariable(d3totp_conf::OTP_SESSION_VARNAME, $oTotpMock);
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getUser')->willReturn($oUser);
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'create');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::delete
|
||||
*/
|
||||
public function cantDeleteIfTotpActive()
|
||||
{
|
||||
$_GET['totp_use'] = '1';
|
||||
|
||||
$totpMock = oxNew(d3totp::class);
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods(['getTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('getTotpObject')->willReturn($totpMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::delete
|
||||
*/
|
||||
public function cantDeleteIfNoUser()
|
||||
{
|
||||
$_GET['totp_use'] = '0';
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('delete');
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getTotpObject',
|
||||
'getUser',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->expects($this->once())->method('getUser')->willReturn(false);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::delete
|
||||
*/
|
||||
public function canDelete()
|
||||
{
|
||||
$_GET['totp_use'] = '0';
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'delete',
|
||||
'loadByUserId',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
$oUser = oxNew(User::class);
|
||||
$oUser->setId('foo');
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getTotpObject',
|
||||
'getUser',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('getTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->expects($this->once())->method('getUser')->willReturn($oUser);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getTotpObject
|
||||
*/
|
||||
public function getTotpObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getTotpObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3_account_totp::getCurrentUserId
|
||||
*/
|
||||
public function canGetCurrentUserId(): void
|
||||
{
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$userMock->expects($this->once())->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var d3_account_totp|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_account_totp::class)
|
||||
->onlyMethods([
|
||||
'getUser'
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('getUser')->willReturn($userMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
'foo',
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getCurrentUserId'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
285
Tests/Unit/Application/Controller/d3totploginTest.php
Normal file
285
Tests/Unit/Application/Controller/d3totploginTest.php
Normal file
@ -0,0 +1,285 @@
|
||||
<?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\Totp\Tests\Unit\Application\Controller;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Controller\d3totplogin;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3totploginTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3totplogin */
|
||||
protected $_oController;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3totplogin::class);
|
||||
|
||||
Registry::getSession()->deleteVariable(d3totp_conf::SESSION_CURRENTUSER);
|
||||
Registry::getSession()->deleteVariable(d3totp_conf::SESSION_CURRENTCLASS);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::render
|
||||
*/
|
||||
public function renderRedirectIfNoTotp()
|
||||
{
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->once())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getUtils'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUtils')->willReturn($oUtilsMock);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTCLASS, 'currentClass');
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->callMethod($this->_oController, 'render');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::render
|
||||
*/
|
||||
public function renderDontRedirect()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, 'foo');
|
||||
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->never())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getUtils'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTCLASS, 'currentClass');
|
||||
|
||||
$this->assertSame(
|
||||
'@d3totp/tpl/d3totplogin',
|
||||
$this->callMethod($this->_oController, 'render')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getUtils
|
||||
*/
|
||||
public function getUtilsReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getUtils'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getBackupCodeCountMessage
|
||||
*/
|
||||
public function getBackupCodeCountMessageReturnMessage()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodesListMock */
|
||||
$oBackupCodesListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1);
|
||||
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, 'userId');
|
||||
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
strpos(
|
||||
$this->callMethod($this->_oController, 'getBackupCodeCountMessage'),
|
||||
' 1 '
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getBackupCodeCountMessage
|
||||
*/
|
||||
public function getBackupCodeCountMessageReturnNoMessage()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodesListMock */
|
||||
$oBackupCodesListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getAvailableCodeCount'])
|
||||
->getMock();
|
||||
$oBackupCodesListMock->method('getAvailableCodeCount')->willReturn(1234);
|
||||
|
||||
/** @var d3totplogin|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oControllerMock->method('getBackupCodeListObject')->willReturn($oBackupCodesListMock);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, 'userId');
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertEmpty(
|
||||
$this->callMethod($this->_oController, 'getBackupCodeCountMessage')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getBackupCodeListObject
|
||||
*/
|
||||
public function getBackupCodeListObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcodelist::class,
|
||||
$this->callMethod($this->_oController, 'getBackupCodeListObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getPreviousClass
|
||||
*/
|
||||
public function canGetPreviousClass()
|
||||
{
|
||||
$className = "testClass";
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTCLASS, $className);
|
||||
|
||||
$this->assertSame(
|
||||
$className,
|
||||
$this->callMethod($this->_oController, 'getPreviousClass')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::previousClassIsOrderStep
|
||||
* @dataProvider classIsOrderStepDataProvider
|
||||
*/
|
||||
public function classIsOrderStep($className, $expected)
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTCLASS, $className);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'previousClassIsOrderStep'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public static function classIsOrderStepDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'order step class' => ['order', true],
|
||||
'no order step class' => ['start', false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getIsOrderStep
|
||||
* @dataProvider classIsOrderStepDataProvider
|
||||
*/
|
||||
public function getIsOrderStepIsSameLikeOrderClass($className, $expected)
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTCLASS, $className);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'getIsOrderStep'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Controller\d3totplogin::getBreadCrumb
|
||||
*/
|
||||
public function canGetBreadCrumb()
|
||||
{
|
||||
$controllerMock = $this->d3getMockBuilder(d3totplogin::class)
|
||||
->onlyMethods(['getLink'])
|
||||
->getMock();
|
||||
$controllerMock->method('getLink')->willReturn('linkFixture');
|
||||
|
||||
$aBreadCrumb = $this->callMethod($controllerMock, 'getBreadCrumb');
|
||||
|
||||
$this->assertIsString($aBreadCrumb[0]['title']);
|
||||
$this->assertTrue(strlen($aBreadCrumb[0]['title']) > 1);
|
||||
$this->assertIsString($aBreadCrumb[0]['link']);
|
||||
$this->assertTrue(strlen($aBreadCrumb[0]['link']) > 1);
|
||||
}
|
||||
}
|
55
Tests/Unit/Application/Factory/BaconQrCodeFactoryTest.php
Normal file
55
Tests/Unit/Application/Factory/BaconQrCodeFactoryTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
namespace D3\Totp\Tests\Unit\Application\Factory;
|
||||
|
||||
use BaconQrCode\Renderer\ImageRenderer;
|
||||
use D3\Totp\Application\Factory\BaconQrCodeFactory;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
|
||||
class BaconQrCodeFactoryTest extends d3TotpUnitTestCase
|
||||
{
|
||||
/** @var BaconQrCodeFactory */
|
||||
protected $factory;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->factory = oxNew(BaconQrCodeFactory::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @covers \D3\Totp\Application\Factory\BaconQrCodeFactory::renderer
|
||||
* @covers \D3\Totp\Application\Factory\BaconQrCodeFactory::v200
|
||||
*/
|
||||
public function testRenderer()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
ImageRenderer::class,
|
||||
BaconQrCodeFactory::renderer(200)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,42 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Totp\tests\unit\Application\Model\Exceptions;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Tests\Unit\Application\Model\Exceptions;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use ReflectionException;
|
||||
|
||||
class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3totp_wrongOtpException */
|
||||
protected $_oModel;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3totp_wrongOtpException::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -46,6 +47,7 @@ class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException::__construct
|
||||
*/
|
||||
public function constructorHasRightDefaultMessage()
|
||||
{
|
||||
@ -55,4 +57,4 @@ class d3totp_wrongOtpExceptionTest extends d3TotpUnitTestCase
|
||||
$this->callMethod($this->_oModel, 'getMessage')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,42 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This Software is the property of Data Development and is protected
|
||||
* by copyright law - it is NOT Freeware.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* Any unauthorized use of this software without a valid license
|
||||
* is a violation of the license agreement and will be prosecuted by
|
||||
* civil and criminal law.
|
||||
*
|
||||
* http://www.shopmodule.com
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||
* @link http://www.oxidmodule.com
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\Totp\tests\unit\Application\Model;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\Totp\Tests\Unit\Application\Model;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3RandomGenerator;
|
||||
use D3\Totp\tests\unit\d3TotpUnitTestCase;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use ReflectionException;
|
||||
|
||||
class d3RandomGeneratorTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3RandomGenerator */
|
||||
protected $_oModel;
|
||||
protected d3RandomGenerator $_oModel;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3RandomGenerator::class);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
@ -46,12 +47,13 @@ class d3RandomGeneratorTest extends d3TotpUnitTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3RandomGenerator::getRandomTotpBackupCode
|
||||
*/
|
||||
public function getRandomTotpBackupCodeReturnsRightCode()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
$this->assertMatchesRegularExpression(
|
||||
'@[0-9]{6}@',
|
||||
$this->callMethod($this->_oModel, 'getRandomTotpBackupCode')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
220
Tests/Unit/Application/Model/d3backupcodeTest.php
Normal file
220
Tests/Unit/Application/Model/d3backupcodeTest.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?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\Totp\Tests\Unit\Application\Model;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3backupcode;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3backupcodeTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3backupcode */
|
||||
protected $_oModel;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3backupcode::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::generateCode
|
||||
*/
|
||||
public function generateCodePass()
|
||||
{
|
||||
$sTestUserId = 'testUserId';
|
||||
$sBackupCode = '123456';
|
||||
|
||||
/** @var d3backupcode|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods([
|
||||
'getRandomTotpBackupCode',
|
||||
'd3EncodeBC',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getRandomTotpBackupCode')->willReturn($sBackupCode);
|
||||
$oModelMock->method('d3EncodeBC')->will(
|
||||
$this->returnCallback(function ($arg) {
|
||||
return $arg;
|
||||
})
|
||||
);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'generateCode', [$sTestUserId]);
|
||||
|
||||
$this->assertSame($sTestUserId, $this->_oModel->getFieldData('oxuserid'));
|
||||
$this->assertSame($sBackupCode, $this->_oModel->getFieldData('backupcode'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::getRandomTotpBackupCode
|
||||
*/
|
||||
public function getRandomTotpBackupCodePass()
|
||||
{
|
||||
$this->assertMatchesRegularExpression(
|
||||
'@[0-9]{6}@',
|
||||
$this->callMethod($this->_oModel, 'getRandomTotpBackupCode')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::d3EncodeBC
|
||||
*/
|
||||
public function d3EncodeBCPass()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$oUserMock->method('load')->willReturn(true);
|
||||
$oUserMock->assign(
|
||||
[
|
||||
'oxpasssalt' => '6162636465666768696A6B',
|
||||
]
|
||||
);
|
||||
|
||||
/** @var d3backupcode|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['d3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
'9f7f502a8148f90732a4aa4d880b8cf5',
|
||||
$this->callMethod($this->_oModel, 'd3EncodeBC', ['123456', 'userId'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::d3GetUser
|
||||
*/
|
||||
public function d3GetUserReturnCachedUser()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oUserMock->assign(
|
||||
[
|
||||
'oxid' => 'foobar',
|
||||
]
|
||||
);
|
||||
|
||||
$this->_oModel->setUser($oUserMock);
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->callMethod($this->_oModel, 'd3GetUser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::d3GetUser
|
||||
*/
|
||||
public function d3GetUserReturnCurrentUser()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetCurrentUser', 'load'])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->once())->method('d3TotpGetCurrentUser')->willReturn('currentUserId');
|
||||
$oUserMock->expects($this->once())->method('load');
|
||||
$oUserMock->assign([
|
||||
'oxid' => 'currentUserId',
|
||||
]);
|
||||
|
||||
/** @var d3backupcode|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['d3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$this->_oModel->setUser(null);
|
||||
|
||||
$oUser = $this->callMethod($oModelMock, 'd3GetUser');
|
||||
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$oUser
|
||||
);
|
||||
$this->assertSame(
|
||||
'currentUserId',
|
||||
$oUser->getId()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::d3TotpGetUserObject
|
||||
*/
|
||||
public function d3getUserObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod($this->_oModel, 'd3TotpGetUserObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcode::getQueryBuilder
|
||||
*/
|
||||
public function canGetQueryBuilder(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
QueryBuilder::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getQueryBuilder'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
413
Tests/Unit/Application/Model/d3backupcodelistTest.php
Normal file
413
Tests/Unit/Application/Model/d3backupcodelistTest.php
Normal file
@ -0,0 +1,413 @@
|
||||
<?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\Totp\Tests\Unit\Application\Model;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3backupcode;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Doctrine\DBAL\ForwardCompatibility\Result;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionException;
|
||||
|
||||
class d3backupcodelistTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3backupcodelist */
|
||||
protected d3backupcodelist $_oModel;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3backupcodelist::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::generateBackupCodes
|
||||
*/
|
||||
public function generateBackupCodes()
|
||||
{
|
||||
/** @var FrontendController|MockObject $oViewMock */
|
||||
$oViewMock = $this->d3getMockBuilder(FrontendController::class)
|
||||
->addMethods(['setBackupCodes'])
|
||||
->getMock();
|
||||
$oViewMock->expects($this->once())->method('setBackupCodes')->willReturn(true);
|
||||
|
||||
/** @var Config|MockObject $oConfigMock */
|
||||
$oConfigMock = $this->d3getMockBuilder(Config::class)
|
||||
->onlyMethods(['getActiveView'])
|
||||
->getMock();
|
||||
$oConfigMock->method('getActiveView')->willReturn($oViewMock);
|
||||
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['generateCode'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->exactly(10))->method('generateCode');
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'deleteAllFromUser',
|
||||
'getD3BackupCodeObject',
|
||||
'd3GetConfig',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('deleteAllFromUser');
|
||||
$oModelMock->method('getD3BackupCodeObject')->willReturn($oBackupCodeMock);
|
||||
$oModelMock->method('d3GetConfig')->willReturn($oConfigMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'generateBackupCodes', ['123456']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::getD3BackupCodeObject
|
||||
*/
|
||||
public function getD3BackupCodeObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcode::class,
|
||||
$this->callMethod($this->_oModel, 'getD3BackupCodeObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::d3GetConfig
|
||||
*/
|
||||
public function d3GetConfigReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Config::class,
|
||||
$this->callMethod($this->_oModel, 'd3GetConfig')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::save
|
||||
*/
|
||||
public function savePass()
|
||||
{
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['save'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->once())->method('save')->willReturn(true);
|
||||
|
||||
$aBackupCodeArray = [
|
||||
$oBackupCodeMock,
|
||||
];
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getArray'])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'save');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::getBaseObject
|
||||
*/
|
||||
public function getBaseObjectReturnsRightObject()
|
||||
{
|
||||
$oBaseObject = $this->callMethod($this->_oModel, 'getBaseObject');
|
||||
|
||||
$this->assertIsObject($oBaseObject);
|
||||
$this->assertInstanceOf(d3backupcode::class, $oBaseObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::verify
|
||||
*/
|
||||
public function verifyFoundTotp()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foobar');
|
||||
$oUserMock->assign(['oxpasssalt' => '6162636465666768696A6B']);
|
||||
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete', 'd3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
$oBackupCodeMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$resultMock = $this->d3getMockBuilder(Result::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['fetchOne'])
|
||||
->getMock();
|
||||
$resultMock->method('fetchOne')->willReturn('1');
|
||||
|
||||
$qbMock = $this->d3getMockBuilder(QueryBuilder::class)
|
||||
->setConstructorArgs([ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get()])
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$qbMock->method('execute')->willReturn($resultMock);
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'getQueryBuilder',
|
||||
'getBaseObject',
|
||||
'd3GetUser',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
$oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock);
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oModel, 'verify', ['123456'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::verify
|
||||
*/
|
||||
public function verifyNotFoundTotp()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['getId'])
|
||||
->getMock();
|
||||
$oUserMock->method('getId')->willReturn('foobar');
|
||||
$oUserMock->assign(['oxpasssalt' => '6162636465666768696A6B']);
|
||||
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete', 'd3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true);
|
||||
$oBackupCodeMock->method('d3TotpGetUserObject')->willReturn($oUserMock);
|
||||
|
||||
$resultMock = $this->d3getMockBuilder(Result::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['fetchOne'])
|
||||
->getMock();
|
||||
$resultMock->method('fetchOne')->willReturn('');
|
||||
|
||||
$qbMock = $this->d3getMockBuilder(QueryBuilder::class)
|
||||
->setConstructorArgs([ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get()])
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$qbMock->method('execute')->willReturn($resultMock);
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'getQueryBuilder',
|
||||
'getBaseObject',
|
||||
'd3GetUser',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
$oModelMock->method('getBaseObject')->willReturn($oBackupCodeMock);
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'verify', ['123456'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::deleteAllFromUser
|
||||
*/
|
||||
public function deleteAllFromUserCodesFound()
|
||||
{
|
||||
$qbMock = new QueryBuilder(ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get());
|
||||
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->once())->method('delete')->willReturn(true);
|
||||
|
||||
$aBackupCodeArray = [
|
||||
$oBackupCodeMock,
|
||||
];
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'getArray',
|
||||
'selectString',
|
||||
'getQueryBuilder',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
|
||||
$oModelMock->expects($this->once())->method('selectString')->willReturn(true);
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'deleteAllFromUser', ['foobar']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::deleteAllFromUser
|
||||
*/
|
||||
public function deleteAllFromUserNoCodesFound()
|
||||
{
|
||||
$qbMock = new QueryBuilder(ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get());
|
||||
|
||||
/** @var d3backupcode|MockObject $oBackupCodeMock */
|
||||
$oBackupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['delete'])
|
||||
->getMock();
|
||||
$oBackupCodeMock->expects($this->never())->method('delete')->willReturn(true);
|
||||
|
||||
$aBackupCodeArray = [];
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods([
|
||||
'getArray',
|
||||
'selectString',
|
||||
'getQueryBuilder',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('getArray')->willReturn($aBackupCodeArray);
|
||||
$oModelMock->expects($this->once())->method('selectString')->willReturn(true);
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'deleteAllFromUser', ['foobar']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::getAvailableCodeCount
|
||||
*/
|
||||
public function getAvailableCodeCountPass()
|
||||
{
|
||||
$resultMock = $this->d3getMockBuilder(Result::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['fetchOne'])
|
||||
->getMock();
|
||||
$resultMock->method('fetchOne')->willReturn(25);
|
||||
|
||||
$qbMock = $this->d3getMockBuilder(QueryBuilder::class)
|
||||
->setConstructorArgs([ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get()])
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$qbMock->method('execute')->willReturn($resultMock);
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['getQueryBuilder'])
|
||||
->getMock();
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
25,
|
||||
$this->callMethod($this->_oModel, 'getAvailableCodeCount', ['foobar'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::d3GetUser
|
||||
*/
|
||||
public function d3GetUserReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod($this->_oModel, 'd3GetUser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3backupcodelist::getQueryBuilder
|
||||
*/
|
||||
public function canGetQueryBuilder(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
QueryBuilder::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getQueryBuilder'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
958
Tests/Unit/Application/Model/d3totpTest.php
Normal file
958
Tests/Unit/Application/Model/d3totpTest.php
Normal file
@ -0,0 +1,958 @@
|
||||
<?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\Totp\Tests\Unit\Application\Model;
|
||||
|
||||
use BaconQrCode\Writer;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Factory\BaconQrCodeFactory;
|
||||
use D3\Totp\Application\Model\d3backupcode;
|
||||
use D3\Totp\Application\Model\d3backupcodelist;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\ForwardCompatibility\Result;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OTPHP\TOTP;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Database\ConnectionProviderInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionException;
|
||||
|
||||
class d3totpTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3totp */
|
||||
protected d3totp $_oModel;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oModel = oxNew(d3totp::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::__construct
|
||||
*/
|
||||
public function constructCallsInit()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['init'])
|
||||
->getMock();
|
||||
$oModelMock->expects($this->once())->method('init');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, '__construct');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @covers \D3\Totp\Application\Model\d3totp::loadByUserId
|
||||
*/
|
||||
public function loadByUserIdTableNotExist()
|
||||
{
|
||||
$resultMock = $this->d3getMockBuilder(Result::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['fetchOne'])
|
||||
->getMock();
|
||||
$resultMock->method('fetchOne')->willReturn('');
|
||||
|
||||
$qbMock = $this->d3getMockBuilder(QueryBuilder::class)
|
||||
->setConstructorArgs([ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get()])
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$qbMock->method('execute')->willReturn($resultMock);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getQueryBuilder',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
$oModelMock->expects($this->never())->method('load')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'loadByUserId', ['foobar']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::loadByUserId
|
||||
*/
|
||||
public function loadByUserIdTableExist()
|
||||
{
|
||||
$resultMock = $this->d3getMockBuilder(Result::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['fetchOne'])
|
||||
->getMock();
|
||||
$resultMock->method('fetchOne')->willReturn('oxid');
|
||||
|
||||
$qbMock = $this->d3getMockBuilder(QueryBuilder::class)
|
||||
->setConstructorArgs([ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get()])
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$qbMock->method('execute')->willReturn($resultMock);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getQueryBuilder',
|
||||
'load',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
$oModelMock->expects($this->once())->method('load')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'loadByUserId', ['foobar']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getUser
|
||||
*/
|
||||
public function getUserFromMember()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$oUserMock->method('load')->with('foobar')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetUser',
|
||||
'getFieldData',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
$oModelMock->expects($this->never())->method('getFieldData')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->setValue($this->_oModel, 'userId', 'foobar');
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->callMethod($this->_oModel, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getUser
|
||||
*/
|
||||
public function getUserFromObject()
|
||||
{
|
||||
$this->setValue($this->_oModel, 'userId', null);
|
||||
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['load'])
|
||||
->getMock();
|
||||
$oUserMock->method('load')->with('barfoo')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetUser',
|
||||
'getFieldData',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetUser')->willReturn($oUserMock);
|
||||
$oModelMock->expects($this->once())->method('getFieldData')->willReturn('barfoo');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
$oUserMock,
|
||||
$this->callMethod($this->_oModel, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::checkIfAlreadyExist
|
||||
*/
|
||||
public function checkIfAlreadyExistPass()
|
||||
{
|
||||
$resultMock = $this->d3getMockBuilder(Result::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['fetchOne'])
|
||||
->getMock();
|
||||
$resultMock->method('fetchOne')->willReturn(2);
|
||||
|
||||
$qbMock = $this->d3getMockBuilder(QueryBuilder::class)
|
||||
->setConstructorArgs([ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get()])
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$qbMock->method('execute')->willReturn($resultMock);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getQueryBuilder'])
|
||||
->getMock();
|
||||
$oModelMock->method('getQueryBuilder')->willReturn($qbMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oModel, 'checkIfAlreadyExist', ['testUserId'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::d3GetUser
|
||||
*/
|
||||
public function d3GetUserReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod($this->_oModel, 'd3GetUser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::isActive
|
||||
*/
|
||||
public function isActivePass()
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oModel, 'isActive')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::isActive
|
||||
*/
|
||||
public function isActiveFailedBecauseNoTotpUse()
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', false);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'isActive')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::isActive
|
||||
*/
|
||||
public function isActiveFailedBecauseConfigParam()
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'isActive')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::isActive
|
||||
*/
|
||||
public function isActiveFailedBecauseNoTotpUseAndConfigParam()
|
||||
{
|
||||
Registry::getConfig()->setConfigParam('blDisableTotpGlobally', true);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['UserUseTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('UserUseTotp')->willReturn(false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'isActive')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::UserUseTotp
|
||||
*/
|
||||
public function UserUseTotpPass()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oModel, 'UserUseTotp')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::UserUseTotp
|
||||
*/
|
||||
public function UserUseTotpNoTotp()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, true);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'UserUseTotp')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::UserUseTotp
|
||||
*/
|
||||
public function UserUseTotpNoSeed()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(true, false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'UserUseTotp')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::UserUseTotp
|
||||
*/
|
||||
public function UserUseTotpNoTotpAndNoSeed()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturnOnConsecutiveCalls(false, false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'UserUseTotp')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getSavedSecret
|
||||
*/
|
||||
public function getSavedSecretExistingSeed()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getFieldData',
|
||||
'decrypt',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturn('seed');
|
||||
$oModelMock->method('decrypt')->willReturn('unencseed');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
'unencseed',
|
||||
$this->callMethod($this->_oModel, 'getSavedSecret')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getSavedSecret
|
||||
*/
|
||||
public function getSavedSecretNoSeed()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getFieldData',
|
||||
'decrypt',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturn(null);
|
||||
$oModelMock->method('decrypt')->willReturn('unencseed');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertNull(
|
||||
$this->callMethod($this->_oModel, 'getSavedSecret')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getSavedSecret
|
||||
*/
|
||||
public function getSavedSecretCantDecrypt()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getFieldData',
|
||||
'decrypt',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getFieldData')->willReturn('seed');
|
||||
$oModelMock->method('decrypt')->willReturn(false);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertNull(
|
||||
$this->callMethod($this->_oModel, 'getSavedSecret')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getTotp
|
||||
*/
|
||||
public function getTotpReturnsCachedObject()
|
||||
{
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
|
||||
$this->setValue($this->_oModel, 'totp', $otpMock);
|
||||
|
||||
$this->assertSame(
|
||||
$otpMock,
|
||||
$this->callMethod($this->_oModel, 'getTotp')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getTotp
|
||||
*/
|
||||
public function getTotpReturnsNewObject()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oUserMock->method('getFieldData')->willReturn('username');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'getSavedSecret',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getUser')->willReturn($oUserMock);
|
||||
$oModelMock->method('getSavedSecret')->willReturn('savedSecret');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
/** @var TOTP $oTotp */
|
||||
$oTotp = $this->callMethod($this->_oModel, 'getTotp');
|
||||
|
||||
$this->assertInstanceOf(TOTP::class, $oTotp);
|
||||
$this->assertSame('username', $oTotp->getLabel());
|
||||
$this->assertSame('SAVEDSECRET', $oTotp->getSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getTotp
|
||||
*/
|
||||
public function getTotpReturnsNewObjectNoUserGivenSeed()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['getFieldData'])
|
||||
->getMock();
|
||||
$oUserMock->method('getFieldData')->willReturnMap(
|
||||
[['oxusername', 'oxusername']]
|
||||
);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getUser',
|
||||
'getSavedSecret',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getUser')->willReturn($oUserMock);
|
||||
$oModelMock->method('getSavedSecret')->willReturn('savedSecret');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
/** @var TOTP $oTotp */
|
||||
$oTotp = $this->callMethod($this->_oModel, 'getTotp', ['givenSeed']);
|
||||
|
||||
$this->assertInstanceOf(TOTP::class, $oTotp);
|
||||
$this->assertSame('oxusername', $oTotp->getLabel());
|
||||
$this->assertSame('GIVENSEED', $oTotp->getSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getQrCodeElement
|
||||
*/
|
||||
public function getQrCodeElement()
|
||||
{
|
||||
BaconQrCodeFactory::renderer(200);
|
||||
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
$otpMock->setLabel('label');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getTotp'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($otpMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertIsString(
|
||||
$this->callMethod($this->_oModel, 'getQrCodeElement')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::d3GetWriter
|
||||
*/
|
||||
public function d3GetWriterReturnsRightInstance()
|
||||
{
|
||||
$renderer = BaconQrCodeFactory::renderer(200);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Writer::class,
|
||||
$this->callMethod($this->_oModel, 'd3GetWriter', [$renderer])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getSecret
|
||||
*/
|
||||
public function getSecretPass()
|
||||
{
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getTotp'])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($otpMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'getSecret');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::saveSecret
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getFieldData
|
||||
*/
|
||||
public function saveSecretPass()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['encrypt'])
|
||||
->getMock();
|
||||
$oModelMock->method('encrypt')->willReturn('enc_secret');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'saveSecret', ['newSecret']);
|
||||
$this->assertSame(
|
||||
'enc_secret',
|
||||
$this->callMethod($this->_oModel, 'getFieldData', ['seed'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::verify
|
||||
*/
|
||||
public function verifyPass()
|
||||
{
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
|
||||
$userMock = oxNew(User::class);
|
||||
$userMock->setId('foo');
|
||||
$userMock->assign(['oxpasssalt' => '6162636465666768696A6B']);
|
||||
|
||||
$backupCodeMock = $this->d3getMockBuilder(d3backupcode::class)
|
||||
->onlyMethods(['d3TotpGetUserObject'])
|
||||
->getMock();
|
||||
$backupCodeMock->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
|
||||
$backupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['d3GetUser', 'getBaseObject', 'verify'])
|
||||
->getMock();
|
||||
$backupCodeListMock->method('d3GetUser')->willReturn($userMock);
|
||||
$backupCodeListMock->method('getBaseObject')->willReturn($backupCodeMock);
|
||||
$backupCodeListMock->method('verify')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['getTotp', 'd3GetBackupCodeListObject'])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($otpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($backupCodeListMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oModel, 'verify', ['012345'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::verify
|
||||
*/
|
||||
public function verifyBackupCodePass()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(true);
|
||||
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($otpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oModel, 'verify', ['012345'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::verify
|
||||
*/
|
||||
public function verifyFailed()
|
||||
{
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('verify')->willReturn(false);
|
||||
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($otpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'verify', ['012345']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::verify
|
||||
*/
|
||||
public function verifyWithSeedFailed()
|
||||
{
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['verify'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->never())->method('verify')->willReturn(false);
|
||||
|
||||
$otpMock = TOTP::createFromSecret('abc');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'getTotp',
|
||||
'd3GetBackupCodeListObject',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('getTotp')->willReturn($otpMock);
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->callMethod($this->_oModel, 'verify', ['012345', 'abcdef']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::d3GetBackupCodeListObject
|
||||
*/
|
||||
public function d3GetBackupCodeListObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3backupcodelist::class,
|
||||
$this->callMethod($this->_oModel, 'd3GetBackupCodeListObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::encrypt
|
||||
*/
|
||||
public function encryptDecryptPass()
|
||||
{
|
||||
$sReturn = $this->callMethod($this->_oModel, 'encrypt', ['foobar']);
|
||||
|
||||
// indirect tests, because string changes on every call
|
||||
$this->assertIsString($sReturn);
|
||||
$this->assertNotSame('foobar', $sReturn);
|
||||
$this->assertStringEndsWith('==', $sReturn);
|
||||
$this->assertTrue(strlen($sReturn) === 88);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::decrypt
|
||||
*/
|
||||
public function decryptPass()
|
||||
{
|
||||
$sReturn = $this->callMethod(
|
||||
$this->_oModel,
|
||||
'decrypt',
|
||||
['L5cSqld/1jpoSHnbxF1/+lGqN8OM7FWt2CagEkqNeRMvkyogrl0msvSuOpLwDwngvSa80bfDnfwWrPe5c6pdww==']
|
||||
);
|
||||
|
||||
$this->assertSame('foobar', $sReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::decrypt
|
||||
*/
|
||||
public function decryptFailed()
|
||||
{
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['d3Base64_decode'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3Base64_decode')->willReturn(
|
||||
str_pad('foobar', 50, '0', STR_PAD_LEFT)
|
||||
);
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$sReturn = $this->callMethod(
|
||||
$this->_oModel,
|
||||
'decrypt',
|
||||
['L5cSqld/1jpoSHnbxF1/+lGqN8OM7FWt2CagEkqNeRMvkyogrl0msvSuOpLwDwngvSa80bfDnfwWrPe5c6pdww==']
|
||||
);
|
||||
|
||||
$this->assertFalse($sReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::d3Base64_decode
|
||||
*/
|
||||
public function d3Base64_decodePass()
|
||||
{
|
||||
$this->assertSame(
|
||||
'foobar',
|
||||
$this->callMethod($this->_oModel, 'd3Base64_decode', [base64_encode('foobar')])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::delete
|
||||
*/
|
||||
public function deletePass()
|
||||
{
|
||||
/** @var d3backupcodelist|MockObject $oBackupCodeListMock */
|
||||
$oBackupCodeListMock = $this->d3getMockBuilder(d3backupcodelist::class)
|
||||
->onlyMethods(['deleteAllFromUser'])
|
||||
->getMock();
|
||||
$oBackupCodeListMock->expects($this->once())->method('deleteAllFromUser');
|
||||
|
||||
/** @var d3totp|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'd3GetBackupCodeListObject',
|
||||
'getFieldData',
|
||||
])
|
||||
->getMock();
|
||||
$oModelMock->method('d3GetBackupCodeListObject')->willReturn($oBackupCodeListMock);
|
||||
$oModelMock->method('getFieldData')->willReturn('newId');
|
||||
|
||||
$this->_oModel = $oModelMock;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oModel, 'delete')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getQueryBuilder
|
||||
*/
|
||||
public function canGetQueryBuilder(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
QueryBuilder::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getQueryBuilder'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Application\Model\d3totp::getDbConnection
|
||||
*/
|
||||
public function canGetDbConnection(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Connection::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'getDbConnection'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
31
Tests/Unit/Application/TranslationTest.php
Normal file
31
Tests/Unit/Application/TranslationTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Unit\Application;
|
||||
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Generator;
|
||||
|
||||
class TranslationTest extends d3TotpUnitTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @dataProvider canGetTranslationDataProvider
|
||||
*/
|
||||
public function canGetTranslation(string $path): void
|
||||
{
|
||||
$list = require __DIR__.'/../../../'.$path;
|
||||
|
||||
$this->assertIsArray($list);
|
||||
$this->assertTrue(count($list) > 1);
|
||||
$this->assertTrue($list['charset'] === 'UTF-8');
|
||||
}
|
||||
|
||||
public static function canGetTranslationDataProvider(): Generator
|
||||
{
|
||||
yield 'frontend DE' => ['Application/translations/de/translations.php'];
|
||||
yield 'frontend EN' => ['Application/translations/en/translations.php'];
|
||||
yield 'backend DE' => ['Application/views/de/translations.php'];
|
||||
yield 'backend EN' => ['Application/views/en/translations.php'];
|
||||
}
|
||||
}
|
@ -0,0 +1,700 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Component;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
|
||||
use D3\Totp\Modules\Application\Component\d3_totp_UserComponent;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use InvalidArgumentException;
|
||||
use OxidEsales\Eshop\Application\Component\UserComponent;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Controller\BaseController;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_UserComponentTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::afterLogin
|
||||
*/
|
||||
public function afterLoginFailsIfNoUserLoggedIn()
|
||||
{
|
||||
$oUser = false;
|
||||
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->never())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('setVariable');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
'd3TotpGetUtils',
|
||||
])
|
||||
->getMock();
|
||||
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$this->callMethod($oControllerMock, 'afterLogin', [$oUser]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::afterLogin
|
||||
* @dataProvider afterLoginFailTotpNotActiveOrAlreadyCheckedDataProvider
|
||||
*/
|
||||
public function afterLoginFailTotpNotActiveOrAlreadyChecked($isActive, $checked)
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'logout',
|
||||
'getId',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->never())->method('logout')->willReturn(false);
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->never())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable', 'getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('setVariable');
|
||||
$oSessionMock->method('getVariable')->willReturn($checked);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn($isActive);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
'd3TotpGetUtils',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->callMethod($oControllerMock, 'afterLogin', [$oUserMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function afterLoginFailTotpNotActiveOrAlreadyCheckedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'TOTP not active, not checked' => [false, null],
|
||||
'TOTP not active, checked' => [false, true],
|
||||
'TOTP active, checked' => [true, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::afterLogin
|
||||
*/
|
||||
public function afterLoginPass()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'logout',
|
||||
'getId',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->once())->method('logout')->willReturn(false);
|
||||
$oUserMock->method('getId')->willReturn('foo');
|
||||
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->once())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable', 'getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeast(3))->method('setVariable');
|
||||
$oSessionMock->method('getVariable')->willReturn(null);
|
||||
|
||||
/** @var BaseController|MockObject $oParentMock */
|
||||
$oParentMock = $this->d3getMockBuilder(BaseController::class)
|
||||
->onlyMethods(['getClassKey'])
|
||||
->getMock();
|
||||
$oParentMock->method('getClassKey')->willReturn('foo');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->once())->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
'd3TotpGetUtils',
|
||||
'getParent',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getParent')->willReturn($oParentMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->callMethod($oControllerMock, 'afterLogin', [$oUserMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::afterLogin
|
||||
*/
|
||||
public function afterFailedNoUserLoaded()
|
||||
{
|
||||
/** @var User|MockObject $oUserMock */
|
||||
$oUserMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods([
|
||||
'logout',
|
||||
'getId',
|
||||
])
|
||||
->getMock();
|
||||
$oUserMock->expects($this->never())->method('logout')->willReturn(false);
|
||||
$oUserMock->method('getId')->willReturn('');
|
||||
|
||||
/** @var Utils|MockObject $oUtilsMock */
|
||||
$oUtilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$oUtilsMock->expects($this->never())->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable', 'getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('setVariable');
|
||||
$oSessionMock->method('getVariable')->willReturn(null);
|
||||
|
||||
/** @var BaseController|MockObject $oParentMock */
|
||||
$oParentMock = $this->d3getMockBuilder(BaseController::class)
|
||||
->onlyMethods(['getClassKey'])
|
||||
->getMock();
|
||||
$oParentMock->method('getClassKey')->willReturn('foo');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->expects($this->never())->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
'd3TotpGetUtils',
|
||||
'getParent',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('getParent')->willReturn($oParentMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->method('d3TotpGetUtils')->willReturn($oUtilsMock);
|
||||
|
||||
$this->callMethod($oControllerMock, 'afterLogin', [$oUserMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3GetTotpObject
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($oController, 'd3GetTotpObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpCheckTotpLogin
|
||||
*/
|
||||
public function checkTotploginNoTotpLogin()
|
||||
{
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('setVariable');
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3TotpIsNoTotpOrNoLogin',
|
||||
'd3TotpHasValidTotp',
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpIsNoTotpOrNoLogin')->willReturn(true);
|
||||
$oControllerMock->expects($this->never())->method('d3TotpHasValidTotp')->willReturn(false);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, 'oxid');
|
||||
|
||||
$this->assertSame(
|
||||
'd3totplogin',
|
||||
$this->callMethod($oControllerMock, 'd3TotpCheckTotpLogin')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpCheckTotpLogin
|
||||
*/
|
||||
public function checkTotploginUnvalidTotp()
|
||||
{
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->never())->method('setVariable');
|
||||
|
||||
/** @var d3totp_wrongOtpException|MockObject $oTotpExceptionMock */
|
||||
$oTotpExceptionMock = $this->d3getMockBuilder(d3totp_wrongOtpException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var UtilsView|MockObject $oUtilsViewMock */
|
||||
$oUtilsViewMock = $this->d3getMockBuilder(UtilsView::class)
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$oUtilsViewMock->expects($this->atLeast(1))->method('addErrorToDisplay')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3TotpIsNoTotpOrNoLogin',
|
||||
'd3TotpHasValidTotp',
|
||||
'd3TotpGetUtilsView',
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpIsNoTotpOrNoLogin')->willReturn(false);
|
||||
$oControllerMock->expects($this->once())->method('d3TotpHasValidTotp')->willThrowException($oTotpExceptionMock);
|
||||
$oControllerMock->method('d3TotpGetUtilsView')->willReturn($oUtilsViewMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, 'oxid');
|
||||
|
||||
$this->assertSame(
|
||||
'd3totplogin',
|
||||
$this->callMethod($oControllerMock, 'd3TotpCheckTotpLogin')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpCheckTotpLogin
|
||||
*/
|
||||
public function checkTotploginValidTotp()
|
||||
{
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['setVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeast(2))->method('setVariable');
|
||||
|
||||
/** @var UtilsView|MockObject $oUtilsViewMock */
|
||||
$oUtilsViewMock = $this->d3getMockBuilder(UtilsView::class)
|
||||
->onlyMethods(['addErrorToDisplay'])
|
||||
->getMock();
|
||||
$oUtilsViewMock->expects($this->never())->method('addErrorToDisplay')->willReturn(true);
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods([
|
||||
'd3TotpIsNoTotpOrNoLogin',
|
||||
'd3TotpHasValidTotp',
|
||||
'd3TotpGetUtilsView',
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSession',
|
||||
'setLoginStatus',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpIsNoTotpOrNoLogin')->willReturn(false);
|
||||
$oControllerMock->expects($this->once())->method('d3TotpHasValidTotp')->willReturn(true);
|
||||
$oControllerMock->method('d3TotpGetUtilsView')->willReturn($oUtilsViewMock);
|
||||
$oControllerMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oControllerMock->expects($this->once())->method('setLoginStatus')->with(
|
||||
$this->identicalTo(USER_LOGIN_SUCCESS)
|
||||
);
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, 'oxid');
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($oControllerMock, 'd3TotpCheckTotpLogin')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpGetUtilsView
|
||||
*/
|
||||
public function d3GetUtilsViewReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
UtilsView::class,
|
||||
$this->callMethod($oController, 'd3TotpGetUtilsView')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpGetUtils
|
||||
*/
|
||||
public function d3GetUtilsReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod($oController, 'd3TotpGetUtils')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpCancelTotpLogin
|
||||
*/
|
||||
public function canCancelTotpLogin()
|
||||
{
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods(['d3TotpClearSessionVariables'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3TotpClearSessionVariables');
|
||||
|
||||
$this->callMethod($oControllerMock, 'd3TotpCancelTotpLogin');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpIsNoTotpOrNoLogin
|
||||
*/
|
||||
public function isNoTotpOrNoLoginTrueNoSessionVariable()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpIsNoTotpOrNoLogin
|
||||
*/
|
||||
public function isNoTotpOrNoLoginTrueTotpNotActive()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpIsNoTotpOrNoLogin
|
||||
*/
|
||||
public function isNoTotpOrNoLoginFalse()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_CURRENTUSER, true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($oController, 'd3TotpIsNoTotpOrNoLogin', [$oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpTrueSessionVarname()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpTrueValidTotp()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpFalseMissingTotp()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willThrowException(oxNew(d3totp_wrongOtpException::class));
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->expectException(d3totp_wrongOtpException::class);
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['', $oTotpMock]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpHasValidTotp
|
||||
*/
|
||||
public function hasValidTotpFalseUnverifiedTotp()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::SESSION_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['verify'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('verify')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($oController, 'd3TotpHasValidTotp', ['123456', $oTotpMock])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpClearSessionVariables
|
||||
*/
|
||||
public function d3TotpClearSessionVariablesPass()
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['deleteVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeast(3))->method('deleteVariable')->willReturn(false);
|
||||
|
||||
/** @var UserComponent|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(UserComponent::class)
|
||||
->onlyMethods(['d3TotpGetSession'])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->callMethod($oControllerMock, 'd3TotpClearSessionVariables');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Component\d3_totp_UserComponent::d3TotpGetSession
|
||||
*/
|
||||
public function d3GetSessionReturnsRightInstance()
|
||||
{
|
||||
/** @var d3_totp_UserComponent $oController */
|
||||
$oController = oxNew(UserComponent::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod($oController, 'd3TotpGetSession')
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,306 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Controller\Admin;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Language;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\UtilsServer;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_LoginControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3_totp_LoginController */
|
||||
protected $_oController;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oController = oxNew(d3_totp_LoginController::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oController);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3GetTotpObject
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oController, 'd3GetTotpObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpGetSession
|
||||
*/
|
||||
public function d3GetSessionReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetSession')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::checklogin
|
||||
*/
|
||||
public function canChecklogin()
|
||||
{
|
||||
$fixture = 'returnString';
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods(['parent__checklogin'])
|
||||
->getMock();
|
||||
$oControllerMock->method('parent__checklogin')->willReturn($fixture);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
$fixture,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'checklogin'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @param $selectedProfile
|
||||
* @param $setCookie
|
||||
* @param $expectedCookie
|
||||
* @param $setSession
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider canRunTotpAfterLoginDataProvider
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3totpAfterLogin
|
||||
*/
|
||||
public function canRunTotpAfterLogin($selectedProfile, $setCookie, $expectedCookie, $setSession)
|
||||
{
|
||||
/** @var Session|MockObject $sessionMock */
|
||||
$sessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable', 'setVariable'])
|
||||
->getMock();
|
||||
$variableMap = [
|
||||
[d3totp_conf::SESSION_ADMIN_PROFILE, $selectedProfile],
|
||||
['aAdminProfiles', [
|
||||
0 => ['abc', 0],
|
||||
1 => ['def', 1],
|
||||
2 => ['geh', 2],
|
||||
]],
|
||||
];
|
||||
$sessionMock->method('getVariable')->willReturnMap($variableMap);
|
||||
$sessionMock->expects($setSession)->method('setVariable')->willReturnMap($variableMap);
|
||||
|
||||
/** @var UtilsServer|MockObject $utilsServerMock */
|
||||
$utilsServerMock = $this->d3getMockBuilder(UtilsServer::class)
|
||||
->onlyMethods(['setOxCookie'])
|
||||
->getMock();
|
||||
$utilsServerMock->expects($setCookie)->method('setOxCookie')->with(
|
||||
$this->anything(),
|
||||
$expectedCookie
|
||||
);
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $sut */
|
||||
$sut = $this->d3getMockBuilder(LoginController::class)
|
||||
->onlyMethods(['d3TotpGetUtilsServer', 'd3TotpGetSession', 'd3totpAfterLoginSetLanguage'])
|
||||
->getMock();
|
||||
$sut->method('d3TotpGetUtilsServer')->willReturn($utilsServerMock);
|
||||
$sut->method('d3TotpGetSession')->willReturn($sessionMock);
|
||||
$sut->expects($this->once())->method('d3totpAfterLoginSetLanguage');
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3totpAfterLogin'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function canRunTotpAfterLoginDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'no profile selected' => [null, $this->once(), '', $this->never()],
|
||||
'valid profile selected' => [2, $this->once(), '2@geh@2', $this->once()],
|
||||
'invalid profile selected' => [5, $this->never(), false, $this->never()],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3totpAfterLoginSetLanguage
|
||||
* @dataProvider canRunTotpAfterLoginSetLanguageDataProvider
|
||||
*/
|
||||
public function canRunTotpAfterLoginSetLanguage($languageId)
|
||||
{
|
||||
/** @var Session|MockObject $sessionMock */
|
||||
$sessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$sessionMock->method('getVariable')->willReturn($languageId);
|
||||
|
||||
/** @var UtilsServer|MockObject $utilsServerMock */
|
||||
$utilsServerMock = $this->d3getMockBuilder(UtilsServer::class)
|
||||
->onlyMethods(['setOxCookie'])
|
||||
->getMock();
|
||||
$utilsServerMock->expects($this->once())->method('setOxCookie');
|
||||
|
||||
/** @var Language|MockObject $langMock */
|
||||
$langMock = $this->d3getMockBuilder(Language::class)
|
||||
->onlyMethods(['setTplLanguage'])
|
||||
->getMock();
|
||||
$langMock->expects($this->once())->method('setTplLanguage');
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $sut */
|
||||
$sut = $this->d3getMockBuilder(LoginController::class)
|
||||
->onlyMethods(['d3TotpGetUtilsServer', 'd3TotpGetSession', 'd3TotpGetLangObject'])
|
||||
->getMock();
|
||||
$sut->method('d3TotpGetUtilsServer')->willReturn($utilsServerMock);
|
||||
$sut->method('d3TotpGetSession')->willReturn($sessionMock);
|
||||
$sut->method('d3TotpGetLangObject')->willReturn($langMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3totpAfterLoginSetlanguage'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function canRunTotpAfterLoginSetLanguageDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'existing language' => [0],
|
||||
'not existing language' => [50],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $totpActive
|
||||
* @param $loggedin
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpLoginMissing
|
||||
* @dataProvider d3TotpLoginMissingTestDataProvider
|
||||
*/
|
||||
public function d3TotpLoginMissingTest($totpActive, $loggedin, $expected)
|
||||
{
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['isActive'])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn($totpActive);
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->with(d3totp_conf::SESSION_ADMIN_AUTH)->willReturn($loggedin);
|
||||
|
||||
/** @var d3_totp_LoginController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder(d3_totp_LoginController::class)
|
||||
->onlyMethods([
|
||||
'd3TotpGetSession',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$this->_oController = $oControllerMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3TotpLoginMissing',
|
||||
[$oTotpMock]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function d3TotpLoginMissingTestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'totp not active, not logged in' => [false, false, false],
|
||||
'totp active, logged in' => [true, true, false],
|
||||
'totp active, not logged in' => [true, false, true],
|
||||
'totp not active, logged in' => [false, true, false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpGetUtilsServer
|
||||
*/
|
||||
public function d3GetUtilsServerObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
UtilsServer::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetUtilsServer')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\Admin\d3_totp_LoginController::d3TotpGetLangObject
|
||||
*/
|
||||
public function d3GetLangObjectReturnsRightObject()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Language::class,
|
||||
$this->callMethod($this->_oController, 'd3TotpGetLangObject')
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Controller;
|
||||
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController_parent;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\OrderController;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class d3_totp_OrderControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
protected $sControllerClass = OrderController::class;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Controller;
|
||||
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_PaymentController;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\PaymentController;
|
||||
|
||||
class d3_totp_PaymentControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
protected $sControllerClass = PaymentController::class;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Controller;
|
||||
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_UserController;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Controller\UserController;
|
||||
|
||||
class d3_totp_UserControllerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use d3_totp_getUserTestTrait;
|
||||
|
||||
protected $sControllerClass = UserController::class;
|
||||
}
|
@ -0,0 +1,248 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Controller;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_OrderController;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_PaymentController;
|
||||
use D3\Totp\Modules\Application\Controller\d3_totp_UserController;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
trait d3_totp_getUserTestTrait
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
protected string $userFixtureId = 'userIdFixture1';
|
||||
|
||||
/** @var User */
|
||||
protected User $userFixture;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->userFixture = oxNew(User::class);
|
||||
$this->userFixture->setId($this->userFixtureId);
|
||||
$this->userFixture->assign(['oxlname' => __METHOD__, 'oxusername' => __METHOD__, 'oxpassword' => __METHOD__]);
|
||||
$this->userFixture->save();
|
||||
$this->userFixture->load($this->userFixtureId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->userFixture->delete($this->userFixtureId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::getUser
|
||||
*/
|
||||
public function getUserHasNoUser(): void
|
||||
{
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods(['d3GetTotpObject'])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->never())->method('d3GetTotpObject');
|
||||
|
||||
$this->setValue($oControllerMock, '_oActUser', false);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::getUser
|
||||
*/
|
||||
public function getUserTotpNotActive(): void
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->setUser($this->userFixture);
|
||||
|
||||
$this->assertSame(
|
||||
$this->userFixture,
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
|
||||
$oControllerMock->setUser(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::getUser
|
||||
*/
|
||||
public function getUserTotpFinished(): void
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->setUser($this->userFixture);
|
||||
|
||||
$this->assertSame(
|
||||
$this->userFixture,
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
|
||||
$oControllerMock->setUser(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::getUser
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::getUser
|
||||
*/
|
||||
public function getUserTotpNotFinished(): void
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->willReturn(false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'isActive',
|
||||
'loadByUserId',
|
||||
])
|
||||
->getMock();
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
$oTotpMock->method('loadByUserId');
|
||||
|
||||
/** @var d3_totp_orderController|d3_totp_UserController|d3_totp_PaymentController|MockObject $oControllerMock */
|
||||
$oControllerMock = $this->d3getMockBuilder($this->sControllerClass)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
])
|
||||
->getMock();
|
||||
$oControllerMock->expects($this->once())->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oControllerMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oControllerMock->setUser($this->userFixture);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($oControllerMock, 'getUser')
|
||||
);
|
||||
|
||||
$oControllerMock->setUser(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::d3GetTotpObject
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::d3GetTotpObject
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::d3GetTotpObject
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightObject(): void
|
||||
{
|
||||
/** @var d3_totp_UserController|d3_totp_PaymentController|d3_totp_OrderController $oController */
|
||||
$oController = oxNew($this->sControllerClass);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($oController, 'd3GetTotpObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_OrderController::d3TotpGetSessionObject
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_PaymentController::d3TotpGetSessionObject
|
||||
* @covers \D3\Totp\Modules\Application\Controller\d3_totp_UserController::d3TotpGetSessionObject
|
||||
*/
|
||||
public function d3GetSessionObjectReturnsRightObject(): void
|
||||
{
|
||||
/** @var d3_totp_UserController|d3_totp_PaymentController|d3_totp_OrderController $oController */
|
||||
$oController = oxNew($this->sControllerClass);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod(
|
||||
$oController,
|
||||
'd3TotpGetSessionObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
180
Tests/Unit/Modules/Application/Model/d3_totp_userTest.php
Normal file
180
Tests/Unit/Modules/Application/Model/d3_totp_userTest.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Application\Model;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_userTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Model\d3_totp_user::logout
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['deleteVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->atLeast(2))->method('deleteVariable')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_user|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetSession'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
|
||||
$sut = $oModelMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'logout'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Model\d3_totp_user::d3getTotp
|
||||
*/
|
||||
public function d3getTotpReturnsRightInstance()
|
||||
{
|
||||
$sut = oxNew(User::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3getTotp'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Model\d3_totp_user::d3TotpGetSession
|
||||
*/
|
||||
public function d3GetSessionReturnsRightInstance()
|
||||
{
|
||||
$sut = oxNew(User::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3TotpGetSession'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Model\d3_totp_user::d3getSessionedTotp
|
||||
*/
|
||||
public function d3getSessionedTotpReturnsRightInstance()
|
||||
{
|
||||
$sut = oxNew(User::class);
|
||||
|
||||
$otp = $this->callMethod(
|
||||
$sut,
|
||||
'd3getSessionedTotp'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$otp
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$otp,
|
||||
Registry::getSession()->getVariable(d3totp_conf::OTP_SESSION_VARNAME)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $currentUser
|
||||
* @param $isAdmin
|
||||
* @param $adminAuth
|
||||
* @param $frontendAuth
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Application\Model\d3_totp_user::d3TotpGetCurrentUser
|
||||
* @dataProvider d3TotpGetCurrentUserTestDataProvider
|
||||
*/
|
||||
public function d3TotpGetCurrentUserTest($currentUser, $isAdmin, $adminAuth, $frontendAuth, $expected)
|
||||
{
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['hasVariable', 'getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->expects($this->once())->method('hasVariable')->willReturn((bool) $currentUser);
|
||||
$getVariableMap = [
|
||||
[d3totp_conf::SESSION_CURRENTUSER, $currentUser],
|
||||
[d3totp_conf::SESSION_ADMIN_CURRENTUSER, $currentUser],
|
||||
[d3totp_conf::OXID_ADMIN_AUTH, $adminAuth],
|
||||
[d3totp_conf::OXID_FRONTEND_AUTH, $frontendAuth],
|
||||
];
|
||||
$oSessionMock->method('getVariable')->willReturnMap($getVariableMap);
|
||||
|
||||
/** @var d3_totp_user|MockObject $oModelMock */
|
||||
$oModelMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['d3TotpGetSession', 'isAdmin'])
|
||||
->getMock();
|
||||
$oModelMock->method('d3TotpGetSession')->willReturn($oSessionMock);
|
||||
$oModelMock->method('isAdmin')->willReturn($isAdmin);
|
||||
|
||||
$sut = $oModelMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3TotpGetCurrentUser'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function d3TotpGetCurrentUserTestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'adm login request' => ['currentFixture', true, 'adminFixture', 'frontendFixture', 'currentFixture'],
|
||||
'frnt login request' => ['currentFixture', false, 'adminFixture', 'frontendFixture', 'currentFixture'],
|
||||
'admin auth' => [null, true, 'adminFixture', 'frontendFixture', 'adminFixture'],
|
||||
'frontend auth' => [null, false, 'adminFixture', 'frontendFixture', 'frontendFixture'],
|
||||
];
|
||||
}
|
||||
}
|
412
Tests/Unit/Modules/Core/d3_totp_utilsTest.php
Normal file
412
Tests/Unit/Modules/Core/d3_totp_utilsTest.php
Normal file
@ -0,0 +1,412 @@
|
||||
<?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\Totp\Tests\Unit\Modules\Core;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Application\Model\d3totp_conf;
|
||||
use D3\Totp\Modules\Core\d3_totp_utils;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3_totp_utilsTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var d3_totp_utils */
|
||||
protected $_oCoreClass;
|
||||
|
||||
/**
|
||||
* setup basic requirements
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_oCoreClass = oxNew(d3_totp_utils::class);
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->_oCoreClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::checkAccessRights
|
||||
*/
|
||||
public function checkAccessRightsNoAuth()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['d3GetTotpObject'])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, 'oxid');
|
||||
|
||||
$this->assertFalse(
|
||||
$this->callMethod($this->_oCoreClass, 'checkAccessRights')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::checkAccessRights
|
||||
*/
|
||||
public function checkAccessRightsForce2FA()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, false);
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['d3GetTotpObject', 'd3AuthHook', 'redirect', 'd3IsAdminForce2FA'])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->method('d3AuthHook')->willReturn(true);
|
||||
$oCoreMock->expects($this->once())->method('redirect')
|
||||
->with($this->stringContains('d3force_2fa'))->willReturn(true);
|
||||
$oCoreMock->method('d3IsAdminForce2FA')->willReturn(true);
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, 'oxid');
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oCoreClass, 'checkAccessRights')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::checkAccessRights
|
||||
*/
|
||||
public function checkAccessRightsTotpNotActive()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, 'foo');
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
$oTotpMock->method('isActive')->willReturn(false);
|
||||
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'fetchRightsForUser',
|
||||
])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oCoreClass, 'checkAccessRights')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::checkAccessRights
|
||||
*/
|
||||
public function checkAccessRightsTotpFinished()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, 'foo');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', true));
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
'fetchRightsForUser',
|
||||
'redirect',
|
||||
])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
|
||||
$oCoreMock->expects($this->never())->method('redirect')->willReturn(true);
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->callMethod($this->_oCoreClass, 'checkAccessRights')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::checkAccessRights
|
||||
*/
|
||||
public function checkAccessRightsTotpUnfinished()
|
||||
{
|
||||
Registry::getSession()->setVariable(d3totp_conf::OXID_ADMIN_AUTH, 'foo');
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false));
|
||||
|
||||
/** @var Session|MockObject $oSessionMock */
|
||||
$oSessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$oSessionMock->method('getVariable')->will($this->onConsecutiveCalls('foo', false));
|
||||
|
||||
/** @var d3totp|MockObject $oTotpMock */
|
||||
$oTotpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods([
|
||||
'loadByUserId',
|
||||
'isActive',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$oTotpMock->method('loadByUserId');
|
||||
$oTotpMock->method('isActive')->willReturn(true);
|
||||
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods([
|
||||
'd3GetTotpObject',
|
||||
'd3TotpGetSessionObject',
|
||||
'fetchRightsForUser',
|
||||
'redirect',
|
||||
])
|
||||
->getMock();
|
||||
$oCoreMock->method('d3GetTotpObject')->willReturn($oTotpMock);
|
||||
$oCoreMock->method('d3TotpGetSessionObject')->willReturn($oSessionMock);
|
||||
$oCoreMock->method('fetchRightsForUser')->willReturn('malladmin');
|
||||
$oCoreMock->expects($this->once())->method('redirect')->willReturn(true);
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
$this->callMethod($this->_oCoreClass, 'checkAccessRights');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::d3TotpGetSessionObject
|
||||
*/
|
||||
public function d3GetSessionObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod($this->_oCoreClass, 'd3TotpGetSessionObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::d3GetTotpObject
|
||||
*/
|
||||
public function d3GetTotpObjectReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod($this->_oCoreClass, 'd3GetTotpObject')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::d3GetConfig
|
||||
*/
|
||||
public function d3GetConfigReturnsRightInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Config::class,
|
||||
$this->callMethod(
|
||||
$this->_oCoreClass,
|
||||
'd3GetConfig'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider d3IsAdminForce2FADataProvider
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::d3IsAdminForce2FA
|
||||
*/
|
||||
public function d3IsAdminForce2FA($isAdmin, $hasConfig, $expected)
|
||||
{
|
||||
/** @var Config|MockObject $configMock */
|
||||
$configMock = $this->d3getMockBuilder(Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getConfigParam'])
|
||||
->getMock();
|
||||
$configMock->method('getConfigParam')->with($this->equalTo('D3_TOTP_ADMIN_FORCE_2FA'))->willReturn($hasConfig);
|
||||
|
||||
$settingMock = $this->d3getMockBuilder(Setting::class)
|
||||
->onlyMethods(['getValue'])
|
||||
->getMock();
|
||||
$settingMock->method('getValue')->willReturn($hasConfig);
|
||||
|
||||
$moduleConfigurationMock = $this->d3getMockBuilder(ModuleConfiguration::class)
|
||||
->onlyMethods(['getModuleSetting'])
|
||||
->getMock();
|
||||
$moduleConfigurationMock->method('getModuleSetting')->willReturn($settingMock);
|
||||
|
||||
/** @var d3_totp_utils|MockObject $oCoreMock */
|
||||
$oCoreMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['isAdmin', 'd3GetConfig', 'getModuleConfiguration'])
|
||||
->getMock();
|
||||
$oCoreMock->method('isAdmin')->willReturn($isAdmin);
|
||||
$oCoreMock->method('d3GetConfig')->willReturn($configMock);
|
||||
$oCoreMock->method('getModuleConfiguration')->willReturn($moduleConfigurationMock);
|
||||
|
||||
$this->_oCoreClass = $oCoreMock;
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_oCoreClass,
|
||||
'd3IsAdminForce2FA'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function d3IsAdminForce2FADataProvider(): array
|
||||
{
|
||||
return [
|
||||
'noAdmin, noConfig' => [false, false, false],
|
||||
'noAdmin' => [false, true, false],
|
||||
'noConfig' => [true, false, false],
|
||||
'passed' => [true, true, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @dataProvider d3AuthHookDataProvider
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::d3AuthHook
|
||||
*/
|
||||
public function d3AuthHook($argument)
|
||||
{
|
||||
$this->assertSame(
|
||||
$argument,
|
||||
$this->callMethod(
|
||||
$this->_oCoreClass,
|
||||
'd3AuthHook',
|
||||
[$argument]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\d3_totp_utils::getModuleConfiguration
|
||||
*/
|
||||
public function canGetModuleConfiguration()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
ModuleConfiguration::class,
|
||||
$this->callMethod(
|
||||
$this->_oCoreClass,
|
||||
'getModuleConfiguration'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function d3AuthHookDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[true],
|
||||
[false],
|
||||
];
|
||||
}
|
||||
}
|
253
Tests/Unit/Modules/Core/totpSystemEventHandlerTest.php
Normal file
253
Tests/Unit/Modules/Core/totpSystemEventHandlerTest.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?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 unit\Modules\Core;
|
||||
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Application\Model\d3totp;
|
||||
use D3\Totp\Modules\Application\Model\d3_totp_user;
|
||||
use D3\Totp\Modules\Core\totpSystemEventHandler;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use OxidEsales\Eshop\Application\Model\User;
|
||||
use OxidEsales\Eshop\Core\Session;
|
||||
use OxidEsales\Eshop\Core\SystemEventHandler;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionException;
|
||||
|
||||
class totpSystemEventHandlerTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::onAdminLogin
|
||||
*/
|
||||
public function runOnAdminLogin()
|
||||
{
|
||||
/** @var totpSystemEventHandler|MockObject $sut */
|
||||
$sut = $this->d3getMockBuilder(SystemEventHandler::class)
|
||||
->onlyMethods(['d3requestTotp'])
|
||||
->getMock();
|
||||
|
||||
$sut->expects($this->once())->method('d3requestTotp');
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'onAdminLogin'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @param $totpMissing
|
||||
* @param $doLogout
|
||||
* @param $doRedirect
|
||||
*
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider canRequestTotpDataProvider
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::d3requestTotp
|
||||
*/
|
||||
public function canRequestTotp($totpMissing, $doLogout, $doRedirect)
|
||||
{
|
||||
/** @var Session|MockObject $sessionMock */
|
||||
$sessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$sessionMock->method('getVariable')->willReturn('myUserId');
|
||||
|
||||
/** @var d3_totp_user|MockObject $userMock */
|
||||
$userMock = $this->d3getMockBuilder(User::class)
|
||||
->onlyMethods(['logout'])
|
||||
->getMock();
|
||||
$userMock->expects($doLogout)->method('logout')->willReturn(true);
|
||||
|
||||
/** @var Utils|MockObject $utilsMock */
|
||||
$utilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['redirect'])
|
||||
->getMock();
|
||||
$utilsMock->expects($doRedirect)->method('redirect')->willReturn(true);
|
||||
|
||||
/** @var d3totp|MockObject $totpMock */
|
||||
$totpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['loadByUserId'])
|
||||
->getMock();
|
||||
$totpMock->expects($this->atLeastOnce())->method('loadByUserId')->with('myUserId');
|
||||
|
||||
/** @var totpSystemEventHandler|MockObject $sut */
|
||||
$sut = $this->d3getMockBuilder(SystemEventHandler::class)
|
||||
->onlyMethods(['d3GetTotpObject', 'd3TotpGetSession', 'd3TotpLoginMissing',
|
||||
'd3TotpGetUserObject', 'getUtilsObject', ])
|
||||
->getMock();
|
||||
$sut->method('d3GetTotpObject')->willReturn($totpMock);
|
||||
$sut->method('d3TotpGetSession')->willReturn($sessionMock);
|
||||
$sut->method('d3TotpLoginMissing')->with($totpMock)->willReturn($totpMissing);
|
||||
$sut->method('d3TotpGetUserObject')->willReturn($userMock);
|
||||
$sut->method('getUtilsObject')->willReturn($utilsMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3requestTotp'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function canRequestTotpDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'no totp missing' => [false, $this->never(), $this->never()],
|
||||
'totp missing' => [true, $this->once(), $this->once()],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::d3GetTotpObject
|
||||
*/
|
||||
public function canGetTotpObject()
|
||||
{
|
||||
/** @var totpSystemEventHandler $sut */
|
||||
$sut = oxNew(SystemEventHandler::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
d3totp::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3GetTotpObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::getUtilsObject
|
||||
*/
|
||||
public function canGetUtilsObject()
|
||||
{
|
||||
/** @var totpSystemEventHandler $sut */
|
||||
$sut = oxNew(SystemEventHandler::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getUtilsObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::d3TotpGetSession
|
||||
*/
|
||||
public function canGetSessionObject()
|
||||
{
|
||||
/** @var totpSystemEventHandler $sut */
|
||||
$sut = oxNew(SystemEventHandler::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Session::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3TotpGetSession'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::d3TotpGetUserObject
|
||||
*/
|
||||
public function canGetUserObject()
|
||||
{
|
||||
/** @var totpSystemEventHandler $sut */
|
||||
$sut = oxNew(SystemEventHandler::class);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
User::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3TotpGetUserObject'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $isActive
|
||||
* @param $hasTotpAuth
|
||||
* @param $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider checkTotpLoginMissingDataProvider
|
||||
* @covers \D3\Totp\Modules\Core\totpSystemEventHandler::d3TotpLoginMissing
|
||||
*/
|
||||
public function checkTotpLoginMissing($isActive, $hasTotpAuth, $expected)
|
||||
{
|
||||
/** @var Session|MockObject $sessionMock */
|
||||
$sessionMock = $this->d3getMockBuilder(Session::class)
|
||||
->onlyMethods(['getVariable'])
|
||||
->getMock();
|
||||
$sessionMock->method('getVariable')->willReturn($hasTotpAuth);
|
||||
|
||||
/** @var d3totp|MockObject $totpMock */
|
||||
$totpMock = $this->d3getMockBuilder(d3totp::class)
|
||||
->onlyMethods(['isActive'])
|
||||
->getMock();
|
||||
$totpMock->method('isActive')->willReturn($isActive);
|
||||
|
||||
/** @var totpSystemEventHandler|MockObject $sut */
|
||||
$sut = $this->d3getMockBuilder(SystemEventHandler::class)
|
||||
->onlyMethods(['d3TotpGetSession'])
|
||||
->getMock();
|
||||
$sut->method('d3TotpGetSession')->willReturn($sessionMock);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'd3TotpLoginMissing',
|
||||
[$totpMock]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function checkTotpLoginMissingDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'totp not active' => [false, false, false],
|
||||
'missing totp' => [true, false, true],
|
||||
'totp exists' => [true, true, false],
|
||||
];
|
||||
}
|
||||
}
|
387
Tests/Unit/Setup/ActionsTest.php
Normal file
387
Tests/Unit/Setup/ActionsTest.php
Normal file
@ -0,0 +1,387 @@
|
||||
<?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\Totp\Tests\Unit\Setup;
|
||||
|
||||
use D3\OxidServiceBridges\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceBridge;
|
||||
use D3\TestingTools\Development\CanAccessRestricted;
|
||||
use D3\Totp\Setup\Actions;
|
||||
use D3\Totp\Tests\Unit\d3TotpUnitTestCase;
|
||||
use Generator;
|
||||
use OxidEsales\DoctrineMigrationWrapper\Migrations;
|
||||
use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder;
|
||||
use OxidEsales\Eshop\Core\DbMetaDataHandler;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\SeoEncoder;
|
||||
use OxidEsales\Eshop\Core\Utils;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Logger\Wrapper\LoggerWrapper;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
|
||||
class ActionsTest extends d3TotpUnitTestCase
|
||||
{
|
||||
use CanAccessRestricted;
|
||||
|
||||
/** @var Actions */
|
||||
protected Actions $_sut;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_sut = oxNew(Actions::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::getMigrationsBuilder
|
||||
*/
|
||||
public function canGetMigrationsBuilder(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
MigrationsBuilder::class,
|
||||
$this->callMethod(
|
||||
$this->_sut,
|
||||
'getMigrationsBuilder'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::runModuleMigrations
|
||||
*/
|
||||
public function canRunModuleMigrations(): void
|
||||
{
|
||||
$migrationsMock = $this->d3getMockBuilder(Migrations::class)
|
||||
->onlyMethods(['execute'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$migrationsMock->expects($this->once())->method('execute');
|
||||
|
||||
$migrationsBuilderMock = $this->d3getMockBuilder(MigrationsBuilder::class)
|
||||
->onlyMethods(['build'])
|
||||
->getMock();
|
||||
$migrationsBuilderMock->method("build")->willReturn($migrationsMock);
|
||||
|
||||
$sutMock = $this->d3getMockBuilder(Actions::class)
|
||||
->onlyMethods(['getMigrationsBuilder'])
|
||||
->getMock();
|
||||
$sutMock->method('getMigrationsBuilder')->willReturn($migrationsBuilderMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sutMock,
|
||||
'runModuleMigrations'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::getDbMetaDataHandler
|
||||
*/
|
||||
public function canGetDbMetaDataHandler(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
DbMetaDataHandler::class,
|
||||
$this->callMethod(
|
||||
$this->_sut,
|
||||
'getDbMetaDataHandler'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::regenerateViews
|
||||
*/
|
||||
public function canRegenerateViews(): void
|
||||
{
|
||||
$dbMetaDataHandlerMock = $this->d3getMockBuilder(DbMetaDataHandler::class)
|
||||
->onlyMethods(['updateViews'])
|
||||
->getMock();
|
||||
$dbMetaDataHandlerMock->expects($this->once())->method("updateViews");
|
||||
|
||||
$sutMock = $this->d3getMockBuilder(Actions::class)
|
||||
->onlyMethods(['getDbMetaDataHandler'])
|
||||
->getMock();
|
||||
$sutMock->method('getDbMetaDataHandler')->willReturn($dbMetaDataHandlerMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sutMock,
|
||||
'regenerateViews'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::getUtils
|
||||
*/
|
||||
public function canGetUtils(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Utils::class,
|
||||
$this->callMethod(
|
||||
$this->_sut,
|
||||
'getUtils'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::getLogger
|
||||
*/
|
||||
public function canGetLogger(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$this->callMethod(
|
||||
$this->_sut,
|
||||
'getLogger'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param string|null $thrownException
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::clearCache
|
||||
* @dataProvider canClearCacheDataProvider
|
||||
*/
|
||||
public function canClearCache(string $thrownException = null): void
|
||||
{
|
||||
$shopTemplateCacheServiceMock = $this->d3getMockBuilder(ShopTemplateCacheServiceBridge::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['invalidateCache'])
|
||||
->getMock();
|
||||
$shopTemplateCacheServiceMock->expects($this->exactly((int) !$thrownException))->method("invalidateCache");
|
||||
|
||||
$DIContainerMock = $this->d3getMockBuilder(Container::class)
|
||||
->onlyMethods(['get', 'has'])
|
||||
->getMock();
|
||||
if ($thrownException === null) {
|
||||
$DIContainerMock->method('get')->willReturn($shopTemplateCacheServiceMock);
|
||||
} else {
|
||||
/** @var ServiceNotFoundException|MockObject $exceptionMock */
|
||||
$exceptionMock = $this->d3getMockBuilder(ServiceNotFoundException::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$DIContainerMock->method('get')->willThrowException($exceptionMock);
|
||||
}
|
||||
|
||||
$utilsMock = $this->d3getMockBuilder(Utils::class)
|
||||
->onlyMethods(['resetLanguageCache'])
|
||||
->getMock();
|
||||
$utilsMock->expects($this->exactly((int) !$thrownException))->method('resetLanguageCache');
|
||||
|
||||
$loggerMock = $this->d3getMockBuilder(LoggerWrapper::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['error'])
|
||||
->getMock();
|
||||
$loggerMock->expects($this->exactly((int) $thrownException))->method('error');
|
||||
|
||||
$sutMock = $this->d3getMockBuilder(Actions::class)
|
||||
->onlyMethods(['getDIContainer', 'getUtils', 'getLogger'])
|
||||
->getMock();
|
||||
$sutMock->method('getDIContainer')->willReturn($DIContainerMock);
|
||||
$sutMock->method('getUtils')->willReturn($utilsMock);
|
||||
$sutMock->method('getLogger')->willReturn($loggerMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sutMock,
|
||||
'clearCache'
|
||||
);
|
||||
}
|
||||
|
||||
public static function canClearCacheDataProvider(): Generator
|
||||
{
|
||||
yield 'passed' => [];
|
||||
yield 'container exception' => [ServiceNotFoundException::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param bool $hasSeoUrls
|
||||
* @param InvokedCount $createCount
|
||||
* @param bool $throwException
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::seoUrl
|
||||
* @dataProvider canHandleSeoUrlsDataProvider
|
||||
*/
|
||||
public function canHandleSeoUrls(bool $hasSeoUrls, InvokedCount $createCount, bool $throwException = false): void
|
||||
{
|
||||
$loggerMock = $this->d3getMockBuilder(LoggerWrapper::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['error'])
|
||||
->getMock();
|
||||
$loggerMock->expects($this->exactly((int) $throwException))->method('error');
|
||||
|
||||
$sutMock = $this->d3getMockBuilder(Actions::class)
|
||||
->onlyMethods(['hasSeoUrls', 'createSeoUrls', 'getLogger'])
|
||||
->getMock();
|
||||
$sutMock->method('hasSeoUrls')->willReturn($hasSeoUrls);
|
||||
$sutMock->method('getLogger')->willReturn($loggerMock);
|
||||
if ($throwException) {
|
||||
$sutMock->expects($createCount)->method('createSeoUrls')->willThrowException(new StandardException());
|
||||
} else {
|
||||
$sutMock->expects($createCount)->method('createSeoUrls');
|
||||
}
|
||||
|
||||
$this->callMethod(
|
||||
$sutMock,
|
||||
'seoUrl'
|
||||
);
|
||||
}
|
||||
|
||||
public static function canHandleSeoUrlsDataProvider(): Generator
|
||||
{
|
||||
yield 'urls exists' => [true, self::never()];
|
||||
yield 'urls not exists' => [false, self::once()];
|
||||
yield 'throw exception' => [false, self::once(), true];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param bool $hasSeoUrl
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::hasSeoUrls
|
||||
* @dataProvider hasSeoUrlsDataProvider
|
||||
*/
|
||||
public function testHasSeoUrls(bool $hasSeoUrl): void
|
||||
{
|
||||
$sutMock = $this->d3getMockBuilder(Actions::class)
|
||||
->onlyMethods(['hasSeoUrl'])
|
||||
->getMock();
|
||||
$sutMock->method('hasSeoUrl')->willReturn($hasSeoUrl);
|
||||
|
||||
$this->assertSame(
|
||||
$hasSeoUrl,
|
||||
$this->callMethod(
|
||||
$sutMock,
|
||||
'hasSeoUrls',
|
||||
[oxNew(SeoEncoder::class)]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function hasSeoUrlsDataProvider(): Generator
|
||||
{
|
||||
yield 'url exists' => [true];
|
||||
yield 'url not exists' => [false];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param string $staticUrl
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::hasSeoUrl
|
||||
* @dataProvider hasSeoUrlDataProvider
|
||||
*/
|
||||
public function testHasSeoUrl(string $staticUrl, bool $expected)
|
||||
{
|
||||
$seoEncoderMock = $this->d3getMockBuilder(SeoEncoder::class)
|
||||
->onlyMethods(['getStaticUrl'])
|
||||
->getMock();
|
||||
$seoEncoderMock->expects($this->once())->method('getStaticUrl')->willReturn($staticUrl);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$this->_sut,
|
||||
'hasSeoUrl',
|
||||
[$seoEncoderMock, 'item', 0]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function hasSeoUrlDataProvider(): Generator
|
||||
{
|
||||
yield 'passed' => ['staticFixture', true];
|
||||
yield 'failed' => ['', false];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param bool $hasSeoUrl
|
||||
* @param InvokedCount $expectedCount
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::createSeoUrls
|
||||
* @dataProvider canCreateSeoUrlsDataProvider
|
||||
*/
|
||||
public function canCreateSeoUrls(bool $hasSeoUrl, invokedCount $expectedCount): void
|
||||
{
|
||||
$seoEncoderMock = $this->d3getMockBuilder(SeoEncoder::class)
|
||||
->onlyMethods(['addSeoEntry'])
|
||||
->getMock();
|
||||
$seoEncoderMock->expects($expectedCount)->method('addSeoEntry')->willReturn('addSeoEntry');
|
||||
|
||||
$sutMock = $this->d3getMockBuilder(Actions::class)
|
||||
->onlyMethods(['hasSeoUrl'])
|
||||
->getMock();
|
||||
$sutMock->method('hasSeoUrl')->willReturn($hasSeoUrl);
|
||||
|
||||
$this->callMethod(
|
||||
$sutMock,
|
||||
'createSeoUrls',
|
||||
[$seoEncoderMock]
|
||||
);
|
||||
}
|
||||
|
||||
public static function canCreateSeoUrlsDataProvider(): Generator
|
||||
{
|
||||
yield 'url not exists' => [false, self::exactly(2)];
|
||||
yield 'url exists' => [true, self::never()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\Totp\Setup\Actions::getDIContainer
|
||||
*/
|
||||
public function canGetDIContainer(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
ContainerInterface::class,
|
||||
$this->callMethod(
|
||||
$this->_sut,
|
||||
'getDIContainer'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
33
Tests/Unit/d3TotpUnitTestCase.php
Normal file
33
Tests/Unit/d3TotpUnitTestCase.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?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\Totp\Tests\Unit;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry as RegistryAlias;
|
||||
use PHPUnit\Framework\MockObject\MockBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class d3TotpUnitTestCase extends TestCase
|
||||
{
|
||||
public function d3getMockBuilder($className): MockBuilder
|
||||
{
|
||||
if (strpos($className, '\\') === false) {
|
||||
$className = strtolower($className);
|
||||
}
|
||||
$editionClassName = RegistryAlias::getUtilsObject()->getClassName($className);
|
||||
|
||||
return parent::getMockBuilder($editionClassName);
|
||||
}
|
||||
}
|
41
Tests/phpunit.xml
Normal file
41
Tests/phpunit.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
backupGlobals="true"
|
||||
bootstrap="../../../../source/bootstrap.php"
|
||||
colors="true"
|
||||
backupStaticAttributes="false"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="false"
|
||||
convertWarningsToExceptions="false"
|
||||
forceCoversAnnotation="false"
|
||||
processIsolation="false"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
beStrictAboutTestsThatDoNotTestAnything="false"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd">
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory>Unit/</directory>
|
||||
</testsuite>
|
||||
<!-- <testsuite name="Integration">-->
|
||||
<!-- <directory>integration/</directory>-->
|
||||
<!-- </testsuite>-->
|
||||
</testsuites>
|
||||
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">../</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<file>../.php-cs-fixer.php</file>
|
||||
<file>../IntelliSenseHelper.php</file>
|
||||
<file>../rector.php</file>
|
||||
<file>../metadata.php</file>
|
||||
<directory>../Tests/</directory>
|
||||
</exclude>
|
||||
</coverage>
|
||||
<php>
|
||||
<const name="OXID_PHP_UNIT" value="true"/>
|
||||
</php>
|
||||
</phpunit>
|
BIN
assets/login_backend.png
Normal file
BIN
assets/login_backend.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
assets/login_frontend.png
Normal file
BIN
assets/login_frontend.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
41
assets/out/admin/src/css/d3totplogin.css
Normal file
41
assets/out/admin/src/css/d3totplogin.css
Normal file
@ -0,0 +1,41 @@
|
||||
#login {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
#login .btn {
|
||||
order: 1;
|
||||
}
|
||||
#login .btn.btn_cancel {
|
||||
order: 2;
|
||||
background: silver;
|
||||
color: black;
|
||||
}
|
||||
#login label {
|
||||
position: absolute;
|
||||
left: -2000px;
|
||||
}
|
||||
|
||||
#login label.show {
|
||||
position: relative;
|
||||
display: block;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#login .container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-bottom: 10px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#login .digit {
|
||||
height: 3em;
|
||||
width: 2em;
|
||||
margin: 0 2px;
|
||||
text-align: center;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
#login .digit:nth-of-type(4) {
|
||||
margin-left: 7px;
|
||||
}
|
48
assets/out/flow/src/css/d3totplogin.css
Normal file
48
assets/out/flow/src/css/d3totplogin.css
Normal file
@ -0,0 +1,48 @@
|
||||
#login {
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
#login .btn.btn_cancel {
|
||||
background: silver;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.cl-d3totplogin .btn {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.cl-d3totplogin .mainforms {
|
||||
margin-top: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
|
||||
#login label {
|
||||
position: absolute;
|
||||
left: -2000px;
|
||||
}
|
||||
|
||||
#login label.show {
|
||||
position: relative;
|
||||
display: block;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#login .container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin: 20px 0;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#login .digit {
|
||||
width: 2em;
|
||||
margin: 0 2px;
|
||||
text-align: center;
|
||||
height: 3em;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
#login .digit:nth-of-type(4) {
|
||||
margin-left: 15px;
|
||||
}
|
7
assets/out/src/css/bootstrap.min.css
vendored
Normal file
7
assets/out/src/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
93
assets/picture.svg
Normal file
93
assets/picture.svg
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="201px" height="124px" viewBox="0 0 201 124" enable-background="new 0 0 201 124" xml:space="preserve">
|
||||
<g>
|
||||
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="47.0591" y1="67.5117" x2="47.0591" y2="54.6143">
|
||||
<stop offset="0.0056" style="stop-color:#3266A9"/>
|
||||
<stop offset="1" style="stop-color:#0099FF"/>
|
||||
</linearGradient>
|
||||
<path fill="url(#SVGID_1_)" d="M50.282,55.502c-0.784-0.592-2.104-0.888-3.961-0.888h-1.376l-2.283,12.898h1.779
|
||||
c3.76,0,6.032-2.245,6.815-6.733c0.134-0.871,0.202-1.642,0.202-2.313C51.457,57.081,51.064,56.093,50.282,55.502z"/>
|
||||
<linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="65.9609" y1="49.104" x2="65.9609" y2="36.9434">
|
||||
<stop offset="0.0056" style="stop-color:#3266A9"/>
|
||||
<stop offset="1" style="stop-color:#0099FF"/>
|
||||
</linearGradient>
|
||||
<path fill="url(#SVGID_2_)" d="M65.72,40.482c1.074,0,1.611,0.381,1.611,1.143c0,0.701-0.321,1.201-0.962,1.5
|
||||
c-0.209,0.119-0.366,0.194-0.471,0.224c-0.065,0.019-0.158,0.037-0.271,0.056c1.98,1.621,3.702,3.544,5.097,5.699
|
||||
c0.117-0.321,0.21-0.658,0.277-1.013l0.09-1.008c0-1.223-0.568-2.081-1.701-2.574c0.776-0.402,1.376-0.94,1.801-1.611
|
||||
c0.425-0.672,0.638-1.418,0.638-2.239c0-0.642-0.198-1.265-0.593-1.868c-0.396-0.605-0.98-1.049-1.757-1.333
|
||||
c-0.433-0.193-0.876-0.328-1.332-0.402c-0.456-0.075-1.003-0.113-1.645-0.113c-0.82,0-1.663,0.124-2.529,0.37
|
||||
c-0.865,0.246-1.6,0.563-2.204,0.952s-1.13,0.907-1.578,1.557c-0.036,0.052-0.066,0.109-0.101,0.163
|
||||
c1.196,0.534,2.341,1.163,3.426,1.874C63.947,40.943,64.68,40.482,65.72,40.482z"/>
|
||||
<linearGradient id="SVGID_3_" gradientUnits="userSpaceOnUse" x1="50.0576" y1="87.0566" x2="50.0576" y2="37.8525">
|
||||
<stop offset="0.0056" style="stop-color:#3266A9"/>
|
||||
<stop offset="1" style="stop-color:#0099FF"/>
|
||||
</linearGradient>
|
||||
<path fill="url(#SVGID_3_)" d="M70.725,49.104c-0.433,1.189-1.208,2.147-2.331,2.871c-1.425,0.918-3.182,1.377-5.271,1.377
|
||||
c-1.179,0-2.175-0.176-2.988-0.525c-0.813-0.35-1.444-0.864-1.891-1.543c-0.448-0.678-0.671-1.481-0.671-2.405l0.022-0.694
|
||||
l0.156-0.693h4.367l-0.028,0.179v0.179v0.246c0,1.164,0.628,1.746,1.884,1.746c0.635,0,1.201-0.217,1.696-0.649
|
||||
c0.495-0.434,0.742-0.94,0.742-1.522c0-0.522-0.194-0.887-0.582-1.097c-0.329-0.208-1.007-0.313-2.036-0.313l0.47-2.754
|
||||
l1.141-0.067c0.083-0.011,0.154-0.022,0.221-0.033c-0.674-0.551-1.378-1.067-2.11-1.546c-0.044,0.096-0.087,0.195-0.125,0.302
|
||||
h-4.185c0.192-0.837,0.49-1.56,0.884-2.175c-3.064-1.372-6.46-2.133-10.034-2.133c-13.588,0-24.603,11.014-24.603,24.601
|
||||
c0,13.59,11.015,24.604,24.603,24.604S74.66,76.043,74.66,62.453C74.66,57.532,73.214,52.949,70.725,49.104z M59.413,59.233
|
||||
l-0.168,1.275c-0.538,2.953-1.511,5.404-2.921,7.35c-1.298,1.835-3.016,3.179-5.153,4.028c-2.138,0.851-4.494,1.274-7.067,1.274
|
||||
H33.731l4.264-24.198h10.441c1.141,0,2.204,0.073,3.189,0.218c0.984,0.146,1.868,0.364,2.651,0.655
|
||||
c1.611,0.537,2.887,1.471,3.827,2.802c0.94,1.332,1.41,2.992,1.41,4.984L59.413,59.233z"/>
|
||||
</g>
|
||||
<linearGradient id="SVGID_4_" gradientUnits="userSpaceOnUse" x1="107.3027" y1="105.8555" x2="93.0727" y2="16.0106">
|
||||
<stop offset="0" style="stop-color:#B2B2B2;stop-opacity:0"/>
|
||||
<stop offset="0.2" style="stop-color:#B2B2B2"/>
|
||||
<stop offset="0.8" style="stop-color:#B2B2B2"/>
|
||||
<stop offset="1" style="stop-color:#B2B2B2;stop-opacity:0"/>
|
||||
</linearGradient>
|
||||
<rect x="99.875" y="14.933" fill="url(#SVGID_4_)" width="0.625" height="92"/>
|
||||
<script xmlns=""></script>
|
||||
<g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)">
|
||||
<path d="M1280.234,4748.803c-7.021-2.446-12.822-6.802-17.158-12.822c-7.041-9.702-6.592,5.796-6.367-238.306l0.332-222.49
|
||||
l2.344-5.117c3.467-7.48,9.697-13.828,16.953-17.393l6.357-3.135h104.258h104.268l6.367,3.135
|
||||
c7.256,3.564,13.486,9.912,16.953,17.393c2.334,5.117,2.334,5.801,2.666,97.344l0.234,92.344h109.502
|
||||
c82.861,0,110.518,0.342,113.965,1.348c6.025,1.777,14.277,10.039,16.064,16.045c1.895,6.592,1.895,159.365,0,165.942
|
||||
c-1.787,6.021-10.039,14.277-16.064,16.06c-3.447,1.006-30.996,1.343-113.965,1.343h-109.395l-0.342,32.109
|
||||
c-0.332,29.888-0.439,32.349-2.666,37.129c-3.467,7.48-9.697,13.838-16.953,17.402l-6.367,3.125l-102.588,0.225
|
||||
C1292.392,4750.698,1285.713,4750.595,1280.234,4748.803z M1417.637,4727.836c3.789-1.782,7.236-7.241,7.236-11.367
|
||||
c0-3.564-4.795-9.585-8.916-11.045c-2.568-0.889-12.49-1.343-29.004-1.343c-28.096,0-31.445,0.679-35.342,6.475
|
||||
c-3.018,4.458-3.242,6.802-0.781,11.821c3.125,6.689,5.684,7.251,35.908,7.251
|
||||
C1409.267,4729.628,1414.609,4729.292,1417.637,4727.836z M1495.127,4671.635v-11.143h-68.242c-46.621,0-69.805-0.449-72.813-1.23
|
||||
c-5.918-1.68-14.395-10.151-16.064-16.06c-1.67-6.25-1.67-159.922,0-166.152c1.67-5.908,10.146-14.395,16.064-16.064
|
||||
c2.666-0.674,14.375-1.23,28.652-1.23h24.189l0.342-22.969l0.342-22.969l3.672-3.242c4.248-3.789,10.264-4.336,14.717-1.23
|
||||
c1.563,1.006,13.604,12.822,26.66,26.094l23.857,24.316h9.375h9.248v-71.357v-71.377h-108.174h-108.174v182.876v182.896h108.174
|
||||
h108.174V4671.635z M1435.576,4608.75l3.799-3.789v-11.27c0-6.25,0.215-11.27,0.557-11.27s4.58,2.236,9.355,5.02
|
||||
c9.043,5.244,13.281,6.025,18.525,3.691c6.25-2.798,8.145-12.837,3.447-18.408c-1.436-1.67-6.23-5.132-10.586-7.578
|
||||
c-4.355-2.461-7.92-4.692-7.92-5.02c0-0.342,4.131-2.788,9.033-5.586c9.473-5.229,12.158-8.354,12.158-14.38
|
||||
c0-4.79-1.895-8.369-5.586-10.488c-5.225-3.11-9.805-2.334-18.945,3.125c-4.58,2.783-8.701,5.02-9.141,5.02
|
||||
c-0.566,0-0.898-5.02-0.898-11.255v-11.27l-3.799-3.789c-3.115-3.125-4.678-3.804-8.467-3.804s-5.361,0.679-8.467,3.804
|
||||
l-3.809,3.789v11.27c0,6.235-0.322,11.255-0.771,11.255c-0.557,0-4.688-2.236-9.268-5.02c-9.131-5.459-13.711-6.235-18.945-3.125
|
||||
c-3.691,2.119-5.586,5.698-5.586,10.488c0,6.025,2.676,9.15,12.158,14.38c4.912,2.798,9.043,5.244,9.043,5.586
|
||||
c0,0.327-3.564,2.559-7.92,5.02c-4.355,2.446-9.15,5.908-10.605,7.578c-4.678,5.571-2.783,15.61,3.467,18.408
|
||||
c5.244,2.334,9.473,1.553,18.506-3.691c4.795-2.783,9.033-5.02,9.375-5.02c0.322,0,0.547,5.02,0.547,11.27v11.27l3.809,3.789
|
||||
c3.105,3.11,4.678,3.789,8.467,3.789S1432.461,4611.86,1435.576,4608.75z M1556.025,4608.75l3.789-3.789v-11.27
|
||||
c0-6.25,0.225-11.27,0.557-11.27s4.57,2.236,9.365,5.02c9.033,5.244,13.271,6.025,18.506,3.691
|
||||
c6.25-2.798,8.145-12.837,3.467-18.408c-1.455-1.67-6.25-5.132-10.596-7.578c-4.355-2.461-7.91-4.692-7.91-5.02
|
||||
c0-0.342,4.111-2.788,9.014-5.586c9.492-5.229,12.158-8.354,12.158-14.38c0-4.79-1.895-8.369-5.566-10.488
|
||||
c-5.244-3.11-9.814-2.334-18.965,3.125c-4.57,2.783-8.691,5.02-9.141,5.02c-0.557,0-0.889-5.02-0.889-11.255v-11.27l-3.789-3.789
|
||||
c-3.125-3.125-4.688-3.804-8.486-3.804c-3.789,0-5.342,0.679-8.467,3.804l-3.789,3.789v11.27c0,6.235-0.342,11.255-0.781,11.255
|
||||
c-0.566,0-4.697-2.236-9.258-5.02c-9.15-5.459-13.721-6.235-18.965-3.125c-3.672,2.119-5.566,5.698-5.566,10.488
|
||||
c0,6.025,2.676,9.15,12.148,14.38c4.902,2.798,9.033,5.244,9.033,5.586c0,0.327-3.564,2.559-7.92,5.02
|
||||
c-4.346,2.446-9.131,5.908-10.586,7.578c-4.688,5.571-2.793,15.61,3.457,18.408c5.234,2.334,9.473,1.553,18.506-3.691
|
||||
c4.795-2.783,9.033-5.02,9.365-5.02c0.342,0,0.566,5.02,0.566,11.27v11.27l3.789,3.789c3.125,3.11,4.678,3.789,8.467,3.789
|
||||
C1551.338,4612.539,1552.9,4611.86,1556.025,4608.75z M1676.455,4608.75l3.799-3.789v-11.27c0-6.25,0.215-11.27,0.557-11.27
|
||||
c0.332,0,4.58,2.236,9.355,5.02c9.033,5.244,13.271,6.025,18.525,3.691c6.24-2.798,8.135-12.837,3.447-18.408
|
||||
c-1.445-1.67-6.24-5.132-10.596-7.578c-4.346-2.461-7.91-4.692-7.91-5.02c0-0.342,4.121-2.788,9.033-5.586
|
||||
c9.473-5.229,12.158-8.354,12.158-14.38c0-4.79-1.895-8.369-5.586-10.488c-5.234-3.11-9.814-2.334-18.945,3.125
|
||||
c-4.58,2.783-8.711,5.02-9.15,5.02c-0.566,0-0.889-5.02-0.889-11.255v-11.27l-3.799-3.789c-3.115-3.125-4.688-3.804-8.477-3.804
|
||||
s-5.352,0.679-8.467,3.804l-3.799,3.789v11.27c0,6.235-0.332,11.255-0.781,11.255c-0.547,0-4.678-2.236-9.258-5.02
|
||||
c-9.131-5.459-13.711-6.235-18.945-3.125c-3.691,2.119-5.586,5.698-5.586,10.488c0,6.025,2.686,9.15,12.158,14.38
|
||||
c4.902,2.798,9.033,5.244,9.033,5.586c0,0.327-3.574,2.559-7.92,5.02c-4.346,2.446-9.141,5.908-10.586,7.578
|
||||
c-4.697,5.571-2.803,15.61,3.447,18.408c5.244,2.334,9.492,1.553,18.516-3.691c4.785-2.783,9.033-5.02,9.365-5.02
|
||||
c0.342,0,0.557,5.02,0.557,11.27v11.27l3.799,3.789c3.115,3.11,4.678,3.789,8.467,3.789S1673.34,4611.86,1676.455,4608.75z
|
||||
M1416.514,4294.257c8.584-3.555,10.479-13.496,3.906-20.176l-3.35-3.33h-30.117h-30.098l-3.35,3.33
|
||||
c-6.465,6.582-4.678,16.514,3.672,20.078C1362.422,4296.494,1411.045,4296.494,1416.514,4294.257z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 8.6 KiB |
BIN
assets/setup_backend.jpg
Normal file
BIN
assets/setup_backend.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
BIN
assets/setup_frontend.jpg
Normal file
BIN
assets/setup_frontend.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "d3/oxtotp",
|
||||
"name": "d3/oxid-twofactor-onetimepassword",
|
||||
"description": "Two-factor authentication via time-based one-time password for OXID eSales shop",
|
||||
"type": "oxideshop-module",
|
||||
"keywords": [
|
||||
@ -7,7 +7,13 @@
|
||||
"modules",
|
||||
"eShop",
|
||||
"d3",
|
||||
"2FA"
|
||||
"2FA",
|
||||
"two factor",
|
||||
"second factor",
|
||||
"TOTP",
|
||||
"OTP",
|
||||
"one-time password",
|
||||
"authenticator"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
@ -30,26 +36,49 @@
|
||||
"license": [
|
||||
"GPL-3.0-only"
|
||||
],
|
||||
"extra": {
|
||||
"oxideshop": {
|
||||
"source-directory": "/src",
|
||||
"target-directory": "d3/totp"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6",
|
||||
"php": ">=8.0",
|
||||
"ext-xmlwriter": "*",
|
||||
"oxid-esales/oxideshop-ce": "6.2.1 - 6.12",
|
||||
"spomky-labs/otphp": "^8.3",
|
||||
"bacon/bacon-qr-code": "^1.0 || ^2.0",
|
||||
"zendframework/zend-math": "^3.2"
|
||||
"ext-openssl": "*",
|
||||
"oxid-esales/oxideshop-ce": "7.0 - 7.1",
|
||||
"spomky-labs/otphp": "^10.0 || ^11.0",
|
||||
"bacon/bacon-qr-code": "^2.0 || ^3.0",
|
||||
"laminas/laminas-math": "^3.2",
|
||||
"d3/oxidservicebridges": "^2.1.0.0",
|
||||
"beberlei/assert": "^v3.3.2"
|
||||
},
|
||||
"suggest": {
|
||||
"d3/modcfg": "Provides automatic installation routines"
|
||||
"require-dev": {
|
||||
"phpunit/phpunit" : "^9.6",
|
||||
"d3/testingtools": "^1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.9",
|
||||
"phpstan/phpstan": "^1.8",
|
||||
"boxblinkracer/phpunuhi": "^1.12"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"D3\\Totp\\": "../../../source/modules/d3/totp"
|
||||
"D3\\Totp\\": ""
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"D3\\Totp\\Tests\\": "Tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/oxid-twofactor-onetimepassword/.php-cs-fixer.php",
|
||||
|
||||
"phpstan": "./vendor/bin/phpstan --configuration=./vendor/d3/oxid-twofactor-onetimepassword/phpstan.neon",
|
||||
|
||||
"phpunit": "XDEBUG_MODE=off vendor/bin/phpunit --config=vendor/d3/oxid-twofactor-onetimepassword/Tests/",
|
||||
"phpunit-line-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --config=vendor/d3/oxid-twofactor-onetimepassword/Tests/ --coverage-html=vendor/d3/oxid-twofactor-onetimepassword/Tests/reports/coverage",
|
||||
"phpunit-path-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --config=vendor/d3/oxid-twofactor-onetimepassword/Tests/ --coverage-html=vendor/d3/oxid-twofactor-onetimepassword/Tests/reports/coverage --path-coverage",
|
||||
|
||||
"phpunuhi": "./vendor/bin/phpunuhi --configuration=vendor/d3/oxid-twofactor-onetimepassword/phpunuhi.xml validate"
|
||||
},
|
||||
"suggest": {
|
||||
"d3/oxid-twofactor-passwordless": "Passwordless login with FIDO2 hardware token."
|
||||
},
|
||||
"replace": {
|
||||
"d3/oxtotp": "*"
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
Die [2-Faktor-Authentisierung](https://de.wikipedia.org/wiki/Zwei-Faktor-Authentisierung) ermöglicht es den Shopbesuchern, neben der üblichen Kombination aus Benutzername und Passwort auch ein [zeitgesteuertes Einmalpasswort](https://de.wikipedia.org/wiki/Time-based_One-time_Password_Algorithmus) zur Anmeldung abfragen zu lassen. Dies erhöht die Sicherheit im Anmeldeprozess deutlich und macht auch Anmeldungen in öffentlichen Netzwerken oder Internet-Cafés sicherer.
|
||||
Das abgefragte Einmalpasswort wird z.B. durch entsprechende Apps auf dem Smartphone erzeugt. Die folgenden Apps sind Empfehlungen und können gegen andere nach dem TOTP-Standard arbeitende Apps getauscht werden.
|
||||
|
||||
[](http://play.google.com/store/search?q=totp%20authenticator&c=apps)
|
||||
|
||||
[](https://apps.apple.com/de/app/totp-authenticator-fast-2fa/id1404230533)
|
||||
|
||||
Die Einrichtung dieses 2. Faktors ist optional und lässt sich für jedes Benutzerkonto separat einrichten. Die Einrichtung erfolgt im "Mein Konto"-Bereich, über das Shopbackend kann die Einrichtung ebenfalls durchgeführt werden.
|
||||
|
||||
Erst dann wird die zusätzliche Sicherheit genutzt. Sofern der Benutzer auch Zugang zum Adminbereich hat, wird das Einmalpasswort dort ebenfalls abgefragt.
|
||||
|
||||
Zur Einrichtung wird ein scanbarer QR-Code angeboten. Bei der Aktivierung werden statische Backup-Codes angelegt, die verwendet werden können, wenn ein Anmelden mit den Einmalpasswörtern nicht möglich ist. Die Einrichtung kann jederzeit wieder gelöscht werden.
|
@ -1,13 +0,0 @@
|
||||
---
|
||||
title: Changelog
|
||||
---
|
||||
|
||||
## 1.0.0.0 (2019-08-19)
|
||||
|
||||
### Added
|
||||
- 2-Faktor-Authentisierung für Logins in Front- und Backend zusätzlich zu Benutzername und Passwort
|
||||
- Authentisierung wird nur bei Benutzerkonten gezeigt, die dieses aktiviert haben - sonst nur Standardanmeldung
|
||||
- die Basis der Passwortgenerierung wird für jedes Benutzerkonto individuell angelegt
|
||||
- Einrichtung des Zugangs in der Auth-App kann durch scanbaren QR-Code oder kopierbare Zeichenkette erfolgen
|
||||
- Validierung der Einmalpassworte und Generierung der QR-Codes werden ausschließlich innerhalb des Shops durchgeführt - keine Kommunikation nach außen nötig
|
||||
- statische Backupcodes ermöglichen auch eine (begrenzte) Anmeldung ohne Zugang zum Generierungstool
|
@ -1,71 +0,0 @@
|
||||
{
|
||||
"title": "<i class='fab fa-d3 d3fa-color-blue'></i> 2-Faktor-Authentisierung",
|
||||
"moduleversion": "1.0.0.0",
|
||||
"titledesc": "für den Oxid eShop",
|
||||
"author": "D³ Data Development",
|
||||
"moduledate": "19.08.2019",
|
||||
"editors": "DS",
|
||||
"tagline": "",
|
||||
"image": "",
|
||||
"ignore": {
|
||||
"files": [],
|
||||
"folders": [".idea"]
|
||||
},
|
||||
"live": {
|
||||
"clean_urls": true
|
||||
},
|
||||
"html": {
|
||||
"theme": "d3",
|
||||
"breadcrumbs": true,
|
||||
"breadcrumb_separator": "Chevrons",
|
||||
"toggle_code": false,
|
||||
"date_modified": true,
|
||||
"date_modified_format": "d.m.Y",
|
||||
"float": false,
|
||||
"inherit_index": true,
|
||||
"auto_landing": true,
|
||||
|
||||
"links": {
|
||||
"Shop": "https://www.oxidmodule.com"
|
||||
},
|
||||
|
||||
"powered_by": ""
|
||||
},
|
||||
"languages": {
|
||||
"installation": "Installation",
|
||||
"changelog": "Changelog",
|
||||
"support": "Support"
|
||||
},
|
||||
"processor": "d3processor",
|
||||
"language": "de",
|
||||
"strings": {
|
||||
"de": {
|
||||
"CodeBlocks_title": "Code-Blöcke",
|
||||
"CodeBlocks_hide": "Aus",
|
||||
"CodeBlocks_below": "Unterhalb",
|
||||
"CodeBlocks_inline": "Linear",
|
||||
"CodeBlocks_show": "Code-Blöcke anzeigen",
|
||||
"Search_placeholder": "Suchen...",
|
||||
"Link_previous": "Zurück",
|
||||
"Link_next": "Weiter",
|
||||
"Edit_on": "Bearbeiten bei :name:",
|
||||
"View_on_github": "Bei GitHub anzeigen",
|
||||
"View_documentation": "Dokumentation anzeigen",
|
||||
"Table_of_contents": "Inhaltsverzeichnis",
|
||||
"author": "Autor",
|
||||
"moduledate": "Stand",
|
||||
"version": "Version",
|
||||
"editors": "Bearbeiter",
|
||||
"selectversion": "Version wechseln"
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"modulename" : "<i class='fab fa-d3 d3fa-color-blue'></i> 2-Faktor-Authentisierung",
|
||||
"menutitle" : "<i class='fab fa-d3 d3fa-color-blue'></i> 2-Faktor-Authentisierung",
|
||||
"modulefolder" : "totp",
|
||||
"modcfgident" : "d3totp",
|
||||
"composerident" : "d3/oxtotp"
|
||||
},
|
||||
"versionselector": false,
|
||||
"versiondirectoryindex": 2
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
---
|
||||
title: Installation / Update / Deinstallation
|
||||
---
|
||||
|
||||
* [Anforderungen](installation/010_Anforderungen/010_Systemanforderungen.md)
|
||||
* [Neuinstallation](installation/020_Neuinstallation/index.md)
|
||||
* [Update](installation/030_Update/005_Updatedefinition.md)
|
||||
* [Deinstallation](installation/060_Deinstallation/010_Modulerweiterungen_deaktivieren_und_entfernen.md)
|
||||
|
||||
Bei Bedarf bieten wir Ihnen auch gern die Installation des Moduls in Ihrem Shop an. Geben Sie uns bitte unter den unter [Hilfe und Support](support/010_Hilfe-und-Support.md) genannten Kontaktdaten Bescheid.
|
@ -1,25 +0,0 @@
|
||||
---
|
||||
title: Systemanforderungen
|
||||
---
|
||||
|
||||
* PHP Version
|
||||
* 5.6.x bis 7.2.x
|
||||
* PHP Decoder
|
||||
* installierter ionCube Loader
|
||||
* Shopversionen / -editionen
|
||||
* OXID eShop Community Edition (CE), Professional Edition (PE) oder Enterprise Edition (EE) in Compilation Version
|
||||
* 6.0.2 und höher
|
||||
* 6.1.x
|
||||
* Installation via [Composer](https://getcomposer.org)
|
||||
* Themes (weitere Themes nach Ergänzung der Templates möglich)
|
||||
* flow
|
||||
* wave
|
||||
|
||||
Beachten Sie, dass die Ihnen vorliegende Modulversion entsprechend für **PHP 5.6**, **PHP 7.0**, **PHP 7.1** oder **PHP 7.2** kompatibel ist. Im Zweifelsfall kontaktieren Sie uns und nennen den für Ihren Shop genutzten Decoder und die PHP-Version.
|
||||
|
||||
Kontrollieren Sie bitte auch, ob diese Modulversion für die von Ihnen eingesetzte Shopedition (Community Edition (CE), Professional Edition (PE) oder Enterprise Edition (EE)) ausgelegt ist.
|
||||
|
||||
### optional:
|
||||
* D3 Modul-Connector ([kostenfrei bei D3 erhältlich](https://www.oxidmodule.com/connector/)) ab Version 5.1.1.4
|
||||
|
||||
Ist der D3 Modul-Connector installiert, können Datenbankänderungen über die automatische Installation eingerichtet und überwacht werden.
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
title: Modul zur Installation hinzufügen
|
||||
---
|
||||
|
||||
Führen Sie in der Konsole im Hauptverzeichnis Ihres Shops (oberhalb des `source`- und `vendor`-Verzeichnisses) diesen Befehl aus, um das Modul **{$modulename}** zur Installation hinzuzufügen:
|
||||
|
||||
```bash
|
||||
php composer require {$composerident} --update-no-dev
|
||||
```
|
||||
|
||||
> [i] Benötigt Ihre Installation einen anderen Aufruf von Composer, ändern Sie den Befehl bitte entsprechend ab. Für weitere Optionen dieses Befehls lesen Sie bitte die [Dokumentation von Composer](https://getcomposer.org/doc/03-cli.md#require).
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
title: Providerspezifische Installation
|
||||
---
|
||||
|
||||
Manche Provider erfordern besondere Einstellungen für installierte Module. Ob Ihr Anbieter spezielle Anforderungen stellt und wie diese aussehen, kontrollieren Sie bitte in unserer [FAQ](http://faq.oxidmodule.com/Modulinstallation/providerspezifische-Installation/).
|
@ -1,7 +0,0 @@
|
||||
---
|
||||
title: Modul im Shop aktivieren
|
||||
---
|
||||
|
||||
Aktivieren Sie das Modul über den Shopadmin unter [ Erweiterungen ] -> [ Module ]. Klicken Sie nach Auswahl von [ {$menutitle} ] auf den Button [ Aktivieren ].
|
||||
|
||||
> [!] **Enterprise Editon**: Achten Sie darauf, dass das Modul in weiteren Shops (Mall) ebenfalls aktiviert werden muss, um dessen Funktion dort auch zu nutzen.
|
@ -1,17 +0,0 @@
|
||||
---
|
||||
title: Shopanpassungen installieren
|
||||
---
|
||||
|
||||
# mit installiertem D3 Modul-Connector
|
||||
|
||||
Wenn der D3 Modul-Connector installiert ist, startet direkt nach der Modulaktivierung der Assistent, der Sie durch die Shopanpassung führt. Darin können Sie verschiedene Optionen der Installation wählen.
|
||||
|
||||
Den Installationsassistenten finden Sie auch unter den Menüpunkten [ Admin ] -> [ (D3) Module ] -> [ Modul-Connector ] -> [ Modulverwaltung ] -> [ Modulinstallation ].
|
||||
|
||||
Bei tiefgreifenden Änderungen an Ihrem Shop (z.B. Hinzufügen weiterer Sprachen oder Mandanten) rufen Sie den Installationsassistenten bitte erneut auf, um dann eventuell notwendige Nacharbeiten für das Modul ausführen zu lassen.
|
||||
|
||||
Möchten Sie die Änderungen manuell installieren, können Sie sich über diesen Assistenten ebenfalls eine Checkliste erstellen.
|
||||
|
||||
# ohne installierten D3 Modul-Connector
|
||||
|
||||
Führen Sie bitte die Anweisungen in der Datei `install.sql` im docs-Ordner in Ihrer Datenbank aus.
|
@ -1,15 +0,0 @@
|
||||
---
|
||||
title: TMP-Ordner leeren
|
||||
---
|
||||
|
||||
# mit installiertem D3 Modul-Connector
|
||||
|
||||
Leeren Sie das Verzeichnis `tmp` über [ Admin ] -> [ (D3) Module ] -> [ Modul-Connector ] -> [ TMP leeren ]. Markieren Sie [ komplett leeren ] und klicken auf [ TMP leeren ].
|
||||
|
||||
Sofern die Views nicht automatisch aktualisiert werden, führen Sie dies noch durch.
|
||||
|
||||
> [i] Erfordert Ihre Installation eine andere Vorgehensweise zum Leeren des Caches oder zum Aktualisieren der Datenbank-Viewtabellen, führen Sie diese bitte aus.
|
||||
|
||||
# ohne installierten D3 Modul-Connector
|
||||
|
||||
Verbinden Sie sich mit Hilfe Ihres FTP-Programms zu Ihrem Server und löschen Sie alle Dateien bis auf `.htaccess` in den Ordnern `source/tmp` und `source/tmp/smarty` innerhalb Ihrer Shopinstallation.
|
@ -1,7 +0,0 @@
|
||||
---
|
||||
title: Updatefähigkeit
|
||||
---
|
||||
|
||||
Bei individuellen Änderungen von Moduldateien empfehlen wir, jeweils die Überladungsmöglichkeiten des Shops dafür zu verwenden. So brauchen Sie die originalen Moduldateien nicht verändern und erhalten sich so die Updatefähigkeit des Shops und des Moduls. Beachten Sie, dass Moduldateien bei Updateinstallationen überschrieben werden.
|
||||
|
||||
Weitere Informationen zu den Überladungsmöglichkeiten verschiedener Dateien finden Sie in unserer [FAQ](http://faq.oxidmodule.com/Modulinstallation/Modulanpassungen/).
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
title: Schnellstart per Composer
|
||||
---
|
||||
|
||||
## Schnellstart per Composer
|
||||
|
||||
```bash
|
||||
php composer require {$composerident} --update-no-dev
|
||||
```
|
||||
|
||||
Detailliertere Angaben zur Installation entnehmen Sie bitte den folgenden Seiten.
|
@ -1,8 +0,0 @@
|
||||
---
|
||||
title: Wann kann ein Update ausgeführt werden?
|
||||
---
|
||||
|
||||
Die Updatenaweisungen können verwendet werden, wenn dieses Modul schon früher mit Hilfe von Composer installiert wurde.
|
||||
|
||||
Wurde die Installation bisher noch nicht durchgeführt oder die Installation wurde **nicht** über Composer
|
||||
durchgeführt (weil das Modul dies z.B. früher nicht unterstützte), verwenden Sie bitte die Beschreibung unter [Neuinstallation](../020_Neuinstallation/_index.md).
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
title: Modul deaktivieren
|
||||
---
|
||||
|
||||
Deaktivieren Sie das Modul über den Shopadmin unter [ Erweiterungen ] -> [ Module ]. Klicken Sie nach Auswahl von [ {$menutitle} ] auf den Button [ Deaktivieren ].
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
title: Dateien erneuern
|
||||
---
|
||||
|
||||
Starten Sie die Konsole Ihres Webservers und wechseln in das Hauptverzeichnis Ihres
|
||||
Shops (oberhalb des `source`- und `vendor`-Verzeichnisses). Führen Sie dort diesen Befehl aus:
|
||||
|
||||
```bash
|
||||
php composer update {$composerident} --no-dev
|
||||
```
|
||||
|
||||
> [!] Achten Sie darauf, dass die Installation über Composer mit derselben PHP-Version erfolgt, in der auch Ihr Shop installiert ist. Sie erhalten sonst unpassende Modulpakete.
|
||||
|
||||
> [i] Benötigt Ihre Installation einen anderen Aufruf von Composer, ändern Sie den Befehl bitte entsprechend ab. Für weitere Optionen dieses Befehls lesen Sie bitte die [Dokumentation von Composer](https://getcomposer.org/doc/03-cli.md#require).
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
title: Providerspezifische Installation
|
||||
---
|
||||
|
||||
Manche Provider erfordern besondere Einstellungen für installierte Module. Ob Ihr Anbieter spezielle Anforderungen stellt und wie diese aussehen, kontrollieren Sie bitte in unserer [FAQ](http://faq.oxidmodule.com/Modulinstallation/providerspezifische-Installation/).
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
title: Modulinformationen aktualisieren
|
||||
---
|
||||
|
||||
Wechseln Sie im Adminbereich zu [ Erweiterungen ] -> [ Module ]. Klicken Sie nach Auswahl von [ {$menutitle} ] auf den Button [ Aktivieren ].
|
@ -1,17 +0,0 @@
|
||||
---
|
||||
title: Shopanpassungen installierren
|
||||
---
|
||||
|
||||
# mit installiertem D3 Modul-Connector
|
||||
|
||||
Ob Shopanpassungen notwendig sind, ist von der Versionsänderung des Moduls abhängig.
|
||||
|
||||
Möglicherweise sehen Sie nach dem Neuaktivieren des Moduls den Installationsassistent, der Sie durch die Änderungen führt. Folgen Sie dann den einzelnen Schritten. Möchten Sie die Änderungen manuell installieren, können Sie sich über diesen Assistenten ebenfalls eine Checkliste erstellen.
|
||||
|
||||
Wird der Assistent nicht gezeigt (Sie sehen wieder die Modulübersicht), waren keine Anpassungen am Shop notwendig.
|
||||
|
||||
Ob erforderliche Updates ausgeführt werden sollen, können Sie jederzeit im Adminbereich unter [ (D3) Module ] -> [ Modul-Connector ] -> [ Modulverwaltung ] -> [ Modulinstallation ] prüfen.
|
||||
|
||||
# ohne installierten D3 Modul-Connector
|
||||
|
||||
Prüfen Sie bitte, ob in der Datei "update.sql" im docs-Ordner Änderungen hinterlegt sind, die in der Datenbank ausgeführt werden sollten.
|
@ -1,15 +0,0 @@
|
||||
---
|
||||
title: TMP-Ordner leeren
|
||||
---
|
||||
|
||||
# mit installiertem D3 Modul-Connector
|
||||
|
||||
Leeren Sie das Verzeichnis `tmp` über [ Admin ] -> [ (D3) Module ] -> [ Modul-Connector ] -> [ TMP leeren ]. Markieren Sie [ komplett leeren ] und klicken auf [ TMP leeren ].
|
||||
|
||||
Sofern die Views nicht automatisch aktualisiert werden, führen Sie dies noch durch.
|
||||
|
||||
> [i] Erfordert Ihre Installation eine andere Vorgehensweise zum Leeren des Caches oder zum Aktualisieren der Datenbank-Viewtabellen, führen Sie diese bitte aus.
|
||||
|
||||
# ohne installierten D3 Modul-Connector
|
||||
|
||||
Verbinden Sie sich mit Hilfe Ihres FTP-Programms zu Ihrem Server und löschen Sie alle Dateien bis auf `.htaccess` in den Ordnern `source/tmp` und `source/tmp/smarty` innerhalb Ihrer Shopinstallation.
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
title: Erweiterungen anpassen
|
||||
---
|
||||
|
||||
Haben Sie für dieses Modul eigene Erweiterung entwickelt, gleichen Sie dies bitte mit der neuen Fassung des Moduls ab.
|
@ -1,26 +0,0 @@
|
||||
---
|
||||
title: Installationsprüfung
|
||||
---
|
||||
|
||||
Um die erfolgreiche Installation zu prüfen, können Sie die folgende(n) Checkliste(n) verwenden:
|
||||
|
||||
## Einstellungsunabhängige Prüfungen
|
||||
|
||||
### Backend
|
||||
|
||||
* Modul ist unter [ Erweiterungen ] -> [ Module ] aktiv geschaltet
|
||||
* Modul zeigt unter [ Benutzer verwalten ] -> [ Benutzer ] -> [ 2-Faktor-Authentisierung ] einen eigenen Bereich für Einstellungen
|
||||
|
||||
### Frontend
|
||||
|
||||
* Modul zeigt in "Mein Konto" einen Bereich zur Einrichtung des 2. Faktors
|
||||
|
||||
## Einstellungsabhängige Prüfungen
|
||||
|
||||
### Backend
|
||||
|
||||
* Nach Aktivierung fragt das Backend neben Benutzername und Passwort auch ein Einmalpasswort ab.
|
||||
|
||||
### Frontend
|
||||
|
||||
* Nach Aktivierung fragt das Frontend neben Benutzername und Passwort auch ein Einmalpasswort ab.
|
@ -1,13 +0,0 @@
|
||||
---
|
||||
title: Schnellstart
|
||||
---
|
||||
|
||||
Aktivieren Sie die 2-Faktor-Authentisierung im Backend unter [ Benutzer verwalten ] -> [ Benutzer ] -> [ 2-Faktor-Authentisierung ] oder im "Mein Konto" des Shopfrontends.
|
||||
|
||||
Ab dann erfordert das Login im Shop (Front- und Backend) für das jeweilige Benutzerkonto neben Benutzername und Passwort auch die Angabe eines Einmalpasswortes.
|
||||
|
||||
Diese zusätzliche Absicherung kann im Adminbereich jederzeit wieder entfernt werden.
|
||||
|
||||
## zusätzliche Konfigurationsparameter in der Datei `config.inc.php` möglich:
|
||||
|
||||
`blDisableTotpGlobally` => true: deaktiviert diese zusätzlichen Sicherung shopweit für alle Benutzer. Diese Option ist für den Fall vorbehalten, wenn der Adminbereich aus einem technischen Grund und von diesem Modul verursacht nicht mehr aufgerufen werden kann.
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
title: Modulerweiterungen deaktivieren und entfernen
|
||||
---
|
||||
|
||||
Deaktivieren Sie alle vorhandenen Erweiterungen, die auf dem Modul **{$modulename}** aufbauen und löschen bitte alle Dateien dieser Erweiterungen. Entfernen Sie ebenfalls alle individuellen Templateanpassungen für dieses Modul.
|
@ -1,6 +0,0 @@
|
||||
---
|
||||
title: Modul deaktivieren
|
||||
---
|
||||
|
||||
Deaktivieren Sie das Modul **{$modulename}** über den Shopadmin [ Erweiterungen ] -> [ Module ]. Klicken Sie nach Auswahl von [ {$menutitle} ] auf den Button [ Deaktivieren ].
|
||||
|
@ -1,13 +0,0 @@
|
||||
---
|
||||
title: Modul aus der Installation entfernen
|
||||
---
|
||||
|
||||
Starten Sie die Konsole Ihres Webservers und wechseln in das Hauptverzeichnis Ihres Shops (oberhalb des `source`- und `vendor`-Verzeichnisses). Führen Sie Sie dort diesen Befehl aus:
|
||||
|
||||
```Bash
|
||||
php composer remove {$composerident} --no-update
|
||||
```
|
||||
|
||||
> [!] Achten Sie darauf, dass die Installation über Composer mit derselben PHP-Version erfolgt, in der auch Ihr Shop installiert ist. Sie erhalten sonst unpassende Modulpakete.
|
||||
|
||||
> [i] Benötigt Ihre Installation einen anderen Aufruf von Composer, ändern Sie den Befehl bitte entsprechend ab. Für weitere Optionen dieses Befehls lesen Sie bitte die [Dokumentation von Composer](https://getcomposer.org/doc/03-cli.md#require).
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user