2022-11-07 16:00:53 +01:00
|
|
|
<?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
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\Webauthn\tests\integration;
|
|
|
|
|
2022-11-23 08:46:25 +01:00
|
|
|
use D3\Webauthn\Application\Model\WebauthnConf;
|
2022-11-07 16:00:53 +01:00
|
|
|
use OxidEsales\Eshop\Application\Controller\Admin\LoginController;
|
|
|
|
use OxidEsales\Eshop\Core\DatabaseProvider;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class passwordAdminAuthTest extends integrationTestCase
|
|
|
|
{
|
|
|
|
protected $userList = [
|
2022-11-08 10:19:43 +01:00
|
|
|
1 => 'userId1',
|
|
|
|
2 => 'userId2',
|
|
|
|
3 => 'userId3',
|
|
|
|
4 => 'userId4',
|
2022-11-07 16:00:53 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
public function createTestData()
|
|
|
|
{
|
|
|
|
$admin = DatabaseProvider::getDb()->getOne('SELECT oxid FROM oxuser WHERE oxrights = "malladmin"');
|
2022-11-23 08:46:25 +01:00
|
|
|
Registry::getSession()->setVariable(WebauthnConf::OXID_ADMIN_AUTH, $admin);
|
2022-11-07 16:00:53 +01:00
|
|
|
$this->createUser(
|
2022-11-08 10:19:43 +01:00
|
|
|
$this->userList[1],
|
2022-11-07 16:00:53 +01:00
|
|
|
[
|
|
|
|
'oxactive' => 1,
|
|
|
|
'oxrights' => 'user',
|
|
|
|
'oxshopid' => 1,
|
|
|
|
'oxusername' => 'noadmin@user.localhost',
|
|
|
|
'oxpassword' => '$2y$10$QErMJNHQCoN03tfCUQDRfOvbwvqfzwWw1iI/7bC49fKQrPKoDdnaK', // 123456
|
|
|
|
'oxstreet' => __CLASS__
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->createUser(
|
2022-11-08 10:19:43 +01:00
|
|
|
$this->userList[2],
|
2022-11-07 16:00:53 +01:00
|
|
|
[
|
|
|
|
'oxactive' => 1,
|
|
|
|
'oxrights' => 'malladmin',
|
|
|
|
'oxshopid' => 1,
|
|
|
|
'oxusername' => 'admin@user.localhost',
|
|
|
|
'oxpassword' => '$2y$10$QErMJNHQCoN03tfCUQDRfOvbwvqfzwWw1iI/7bC49fKQrPKoDdnaK', // 123456
|
|
|
|
'oxstreet' => __CLASS__
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->createUser(
|
2022-11-08 10:19:43 +01:00
|
|
|
$this->userList[3],
|
2022-11-07 16:00:53 +01:00
|
|
|
[
|
|
|
|
'oxactive' => 1,
|
|
|
|
'oxrights' => 'malladmin',
|
|
|
|
'oxshopid' => 2,
|
|
|
|
'oxusername' => 'wrongshop@user.localhost',
|
|
|
|
'oxpassword' => '$2y$10$QErMJNHQCoN03tfCUQDRfOvbwvqfzwWw1iI/7bC49fKQrPKoDdnaK', // 123456
|
|
|
|
'oxstreet' => __CLASS__
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->createUser(
|
2022-11-08 10:19:43 +01:00
|
|
|
$this->userList[4],
|
2022-11-07 16:00:53 +01:00
|
|
|
[
|
|
|
|
'oxactive' => 0,
|
|
|
|
'oxrights' => 'malladmin',
|
|
|
|
'oxshopid' => 1,
|
|
|
|
'oxusername' => 'inactive@user.localhost',
|
|
|
|
'oxpassword' => '$2y$10$QErMJNHQCoN03tfCUQDRfOvbwvqfzwWw1iI/7bC49fKQrPKoDdnaK', // 123456
|
|
|
|
'oxstreet' => __CLASS__
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function cleanTestData()
|
|
|
|
{
|
|
|
|
$this->deleteUser($this->userList[1]);
|
|
|
|
$this->deleteUser($this->userList[2]);
|
|
|
|
$this->deleteUser($this->userList[3]);
|
|
|
|
$this->deleteUser($this->userList[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2022-11-08 10:19:43 +01:00
|
|
|
* @dataProvider loginDataProvider
|
2022-11-07 16:00:53 +01:00
|
|
|
*/
|
2022-11-08 10:19:43 +01:00
|
|
|
public function testCheckLoginReturn($username, $password, $expected)
|
2022-11-07 16:00:53 +01:00
|
|
|
{
|
|
|
|
$_POST['user'] = $username;
|
|
|
|
$_POST['pwd'] = $password;
|
|
|
|
|
|
|
|
/** @var LoginController $login */
|
|
|
|
$login = oxNew(LoginController::class);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$expected,
|
|
|
|
$login->checklogin()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
2022-11-08 10:19:43 +01:00
|
|
|
public function loginDataProvider(): array
|
2022-11-07 16:00:53 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'not existing account' => ['unknown@user.localhost', '123456', null],
|
2022-11-08 10:19:43 +01:00
|
|
|
'missing password' => ['admin@user.localhost', null, null],
|
2022-11-07 16:00:53 +01:00
|
|
|
'inactive account' => ['inactive@user.localhost', '123456', null],
|
|
|
|
'no backend account' => ['noadmin@user.localhost', '123456', null],
|
|
|
|
'wrong shop account' => ['wrongshop@user.localhost', '123456', 'admin_start'],
|
|
|
|
'account ok' => ['admin@user.localhost', '123456', 'admin_start'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|