2022-11-17 00:27:43 +01:00
|
|
|
<?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
|
|
|
|
*/
|
|
|
|
|
2022-11-30 01:27:05 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-11-23 00:18:09 +01:00
|
|
|
namespace D3\Webauthn\tests\unit\Application\Controller;
|
2022-11-17 00:27:43 +01:00
|
|
|
|
2023-01-27 08:49:09 +01:00
|
|
|
use Assert\InvalidArgumentException;
|
2022-11-17 00:27:43 +01:00
|
|
|
use D3\TestingTools\Development\CanAccessRestricted;
|
|
|
|
use D3\Webauthn\Application\Controller\d3_account_webauthn;
|
|
|
|
use D3\Webauthn\Application\Model\Credential\PublicKeyCredential;
|
|
|
|
use D3\Webauthn\Application\Model\Credential\PublicKeyCredentialList;
|
|
|
|
use D3\Webauthn\Application\Model\Exceptions\WebauthnException;
|
|
|
|
use D3\Webauthn\Application\Model\Webauthn;
|
2023-01-21 13:50:18 +01:00
|
|
|
use D3\Webauthn\tests\unit\WAUnitTestCase;
|
2023-01-27 08:49:09 +01:00
|
|
|
use Generator;
|
2022-11-17 00:27:43 +01:00
|
|
|
use OxidEsales\Eshop\Application\Model\User;
|
2023-01-21 13:50:18 +01:00
|
|
|
use OxidEsales\Eshop\Core\Request;
|
2022-11-17 00:27:43 +01:00
|
|
|
use OxidEsales\Eshop\Core\UtilsView;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
use ReflectionException;
|
|
|
|
|
2023-01-21 13:50:18 +01:00
|
|
|
class d3_account_webauthnTest extends WAUnitTestCase
|
2022-11-17 00:27:43 +01:00
|
|
|
{
|
|
|
|
use CanAccessRestricted;
|
|
|
|
|
|
|
|
/** @var d3_account_webauthn */
|
|
|
|
protected $_oController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setup basic requirements
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
2022-11-22 00:26:04 +01:00
|
|
|
unset($_POST['error']);
|
|
|
|
unset($_POST['credential']);
|
|
|
|
|
2022-11-17 00:27:43 +01:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->_oController = oxNew(d3_account_webauthn::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown(): void
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
unset($this->_oController);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::render
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getViewDataElement
|
|
|
|
*/
|
|
|
|
public function renderReturnsDefaultTemplate()
|
|
|
|
{
|
|
|
|
$oUser = oxNew(User::class);
|
|
|
|
$oUser->setId('foo');
|
|
|
|
$oUser->assign(
|
|
|
|
[
|
|
|
|
'oxpassword' => 'foo',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
/** @var Webauthn|MockObject $webAuthnMock */
|
|
|
|
$webAuthnMock = $this->getMockBuilder(Webauthn::class)
|
|
|
|
->onlyMethods(['isAvailable'])
|
|
|
|
->getMock();
|
|
|
|
$webAuthnMock->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(Webauthn::class, $webAuthnMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
2023-01-21 13:50:18 +01:00
|
|
|
->onlyMethods(['getUser'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
|
|
|
$oControllerMock->method('getUser')->willReturn($oUser);
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$sTpl = $this->callMethod($this->_oController, 'render');
|
|
|
|
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['user']);
|
|
|
|
|
|
|
|
$this->assertSame('d3_account_webauthn.tpl', $sTpl);
|
|
|
|
$this->assertSame($tplUser, $oUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::render
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getViewDataElement
|
|
|
|
*/
|
|
|
|
public function renderReturnsLoginTemplateIfNotLoggedIn()
|
|
|
|
{
|
|
|
|
$oUser = null;
|
|
|
|
|
|
|
|
/** @var Webauthn|MockObject $webAuthnMock */
|
|
|
|
$webAuthnMock = $this->getMockBuilder(Webauthn::class)
|
|
|
|
->onlyMethods(['isAvailable'])
|
|
|
|
->getMock();
|
|
|
|
$webAuthnMock->expects($this->atLeastOnce())->method('isAvailable')->willReturn(true);
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(Webauthn::class, $webAuthnMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
2023-01-21 13:50:18 +01:00
|
|
|
->onlyMethods(['getUser'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
|
|
|
$oControllerMock->method('getUser')->willReturn($oUser);
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$sTpl = $this->callMethod($this->_oController, 'render');
|
|
|
|
$tplUser = $this->callMethod($this->_oController, 'getViewDataElement', ['user']);
|
|
|
|
|
|
|
|
$this->assertNotSame('d3_account_webauthn.tpl', $sTpl);
|
|
|
|
$this->assertNull($tplUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getCredentialList()
|
|
|
|
*/
|
|
|
|
public function canGetCredentialList()
|
|
|
|
{
|
|
|
|
$oUser = oxNew(User::class);
|
|
|
|
$oUser->setId('foo');
|
|
|
|
$oUser->assign(
|
|
|
|
[
|
|
|
|
'oxpassword' => 'foo',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
/** @var PublicKeyCredentialList|MockObject $publicKeyCredentialListMock */
|
|
|
|
$publicKeyCredentialListMock = $this->getMockBuilder(PublicKeyCredentialList::class)
|
|
|
|
->onlyMethods(['getAllFromUser'])
|
|
|
|
->getMock();
|
|
|
|
$publicKeyCredentialListMock->method('getAllFromUser')->with($oUser)->willReturnSelf();
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(PublicKeyCredentialList::class, $publicKeyCredentialListMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
2023-01-21 13:50:18 +01:00
|
|
|
->onlyMethods(['getUser'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
|
|
|
$oControllerMock->method('getUser')->willReturn($oUser);
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$publicKeyCredentialListMock,
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'getCredentialList'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::requestNewCredential()
|
|
|
|
*/
|
|
|
|
public function canRequestNewCredentialCanGetCreationOptions()
|
|
|
|
{
|
|
|
|
$oUser = oxNew(User::class);
|
|
|
|
$oUser->setId('foo');
|
|
|
|
$oUser->assign(
|
|
|
|
[
|
|
|
|
'oxpassword' => 'foo',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
/** @var LoggerInterface|MockObject $loggerMock */
|
|
|
|
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class, [], '', true, true, true, ['error', 'debug']);
|
|
|
|
$loggerMock->expects($this->never())->method('error')->willReturn(true);
|
|
|
|
$loggerMock->expects($this->never())->method('debug')->willReturn(true);
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.LoggerInterface::class, $loggerMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
2023-01-21 13:50:18 +01:00
|
|
|
->onlyMethods(['setAuthnRegister', 'setPageType', 'getUser'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
|
|
|
$oControllerMock->expects($this->atLeastOnce())->method('setAuthnRegister');
|
|
|
|
$oControllerMock->expects($this->atLeastOnce())->method('setPageType');
|
|
|
|
$oControllerMock->method('getUser')->willReturn($oUser);
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'requestNewCredential'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::requestNewCredential()
|
|
|
|
*/
|
|
|
|
public function canRequestNewCredentialCantGetCreationOptions()
|
|
|
|
{
|
|
|
|
$oUser = oxNew(User::class);
|
|
|
|
$oUser->setId('foo');
|
|
|
|
$oUser->assign(
|
|
|
|
[
|
|
|
|
'oxpassword' => 'foo',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
/** @var LoggerInterface|MockObject $loggerMock */
|
|
|
|
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class, [], '', true, true, true, ['error', 'debug']);
|
|
|
|
$loggerMock->expects($this->atLeastOnce())->method('error')->willReturn(true);
|
|
|
|
$loggerMock->expects($this->atLeastOnce())->method('debug')->willReturn(true);
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.LoggerInterface::class, $loggerMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
2023-01-21 13:50:18 +01:00
|
|
|
->onlyMethods(['setAuthnRegister', 'setPageType', 'getUser'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
|
|
|
$oControllerMock->expects($this->atLeastOnce())->method('setAuthnRegister')
|
|
|
|
->willThrowException(oxNew(WebauthnException::class));
|
|
|
|
$oControllerMock->expects($this->never())->method('setPageType');
|
|
|
|
$oControllerMock->method('getUser')->willReturn($oUser);
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'requestNewCredential'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @param $throwExc
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @dataProvider canSetAuthnRegisterDataProvider
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::setAuthnRegister()
|
|
|
|
*/
|
|
|
|
public function canSetAuthnRegister($throwExc)
|
|
|
|
{
|
|
|
|
/** @var Webauthn|MockObject $webAuthnMock */
|
|
|
|
$webAuthnMock = $this->getMockBuilder(Webauthn::class)
|
|
|
|
->onlyMethods(['getCreationOptions'])
|
|
|
|
->getMock();
|
|
|
|
if ($throwExc) {
|
|
|
|
$webAuthnMock->method('getCreationOptions')->willThrowException(oxNew(WebauthnException::class));
|
|
|
|
} else {
|
|
|
|
$webAuthnMock->method('getCreationOptions')->willReturn('options');
|
|
|
|
}
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(Webauthn::class, $webAuthnMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
2023-01-21 13:50:18 +01:00
|
|
|
->onlyMethods(['addTplParam', 'getUser'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
|
|
|
$oControllerMock->expects($throwExc ? $this->never() : $this->atLeast(3))
|
|
|
|
->method('addTplParam');
|
|
|
|
$oControllerMock->method('getUser')->willReturn(oxNew(User::class));
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
if ($throwExc) {
|
|
|
|
$this->expectException(WebauthnException::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'setAuthnRegister'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-01-27 08:49:09 +01:00
|
|
|
* @return Generator
|
2022-11-17 00:27:43 +01:00
|
|
|
*/
|
2023-01-27 08:49:09 +01:00
|
|
|
public function canSetAuthnRegisterDataProvider(): Generator
|
2022-11-17 00:27:43 +01:00
|
|
|
{
|
2023-01-27 08:49:09 +01:00
|
|
|
yield 'dont throw exception' => [false];
|
|
|
|
yield 'throw exception' => [true];
|
2022-11-17 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::setPageType()
|
|
|
|
*/
|
|
|
|
public function canSetPageType()
|
|
|
|
{
|
|
|
|
$fixture = 'argFixture';
|
|
|
|
|
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
|
|
|
->onlyMethods(['addTplParam'])
|
|
|
|
->getMock();
|
|
|
|
$oControllerMock->expects($this->atLeastOnce())->method('addTplParam')
|
|
|
|
->with($this->anything(), $this->identicalTo($fixture));
|
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'setPageType',
|
|
|
|
[$fixture]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::saveAuthn
|
|
|
|
*/
|
|
|
|
public function canSaveAuthnHasError()
|
|
|
|
{
|
|
|
|
$_POST['error'] = 'msg';
|
|
|
|
|
2023-01-27 08:49:09 +01:00
|
|
|
/** @var LoggerInterface|MockObject $loggerMock */
|
|
|
|
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class, [], '', true, true, true, ['error', 'debug']);
|
|
|
|
$loggerMock->expects($this->once())->method('error')->willReturn(true);
|
|
|
|
$loggerMock->expects($this->once())->method('debug')->willReturn(true);
|
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.LoggerInterface::class, $loggerMock);
|
|
|
|
|
|
|
|
/** @var User|MockObject $userMock */
|
|
|
|
$userMock = $this->getMockBuilder(User::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->onlyMethods(['getId'])
|
|
|
|
->getMock();
|
|
|
|
$userMock->method('getId')->willReturn('userId');
|
|
|
|
|
2022-11-17 00:27:43 +01:00
|
|
|
/** @var UtilsView|MockObject $utilsViewMock */
|
|
|
|
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
|
|
|
|
->onlyMethods(['addErrorToDisplay'])
|
|
|
|
->getMock();
|
|
|
|
$utilsViewMock->expects($this->atLeastOnce())->method('addErrorToDisplay');
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.UtilsView::class, $utilsViewMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
2023-01-21 13:50:18 +01:00
|
|
|
/** @var Request|MockObject $requestMock */
|
|
|
|
$requestMock = $this->getMockBuilder(Request::class)
|
|
|
|
->onlyMethods(['getRequestEscapedParameter'])
|
2022-11-17 00:27:43 +01:00
|
|
|
->getMock();
|
2023-01-21 13:50:18 +01:00
|
|
|
$requestMock->method('getRequestEscapedParameter')->with(
|
|
|
|
$this->identicalTo('error')
|
|
|
|
)->willReturn('errorMsg');
|
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.Request::class, $requestMock);
|
|
|
|
|
2023-01-27 08:49:09 +01:00
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
|
|
|
->onlyMethods(['getUser'])
|
|
|
|
->getMock();
|
|
|
|
$oControllerMock->method('getUser')->willReturn($userMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'saveAuthn'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::saveAuthn
|
|
|
|
*/
|
|
|
|
public function canSaveAuthnSuccess()
|
|
|
|
{
|
|
|
|
$_POST['credential'] = 'msg';
|
|
|
|
$_POST['keyname'] = 'key_name';
|
|
|
|
|
|
|
|
/** @var Webauthn|MockObject $webauthnMock */
|
|
|
|
$webauthnMock = $this->getMockBuilder(Webauthn::class)
|
|
|
|
->onlyMethods(['saveAuthn'])
|
|
|
|
->getMock();
|
|
|
|
$webauthnMock->expects($this->once())->method('saveAuthn');
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(Webauthn::class, $webauthnMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var UtilsView|MockObject $utilsViewMock */
|
|
|
|
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
|
|
|
|
->onlyMethods(['addErrorToDisplay'])
|
|
|
|
->getMock();
|
|
|
|
$utilsViewMock->expects($this->never())->method('addErrorToDisplay');
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.UtilsView::class, $utilsViewMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
2023-01-21 13:50:18 +01:00
|
|
|
/** @var d3_account_webauthn $oControllerMock */
|
|
|
|
$oControllerMock = oxNew(d3_account_webauthn::class);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'saveAuthn'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
2023-01-27 08:49:09 +01:00
|
|
|
* @dataProvider canSaveAuthnFailedDataProvider
|
2022-11-17 00:27:43 +01:00
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::saveAuthn
|
|
|
|
*/
|
2023-01-27 08:49:09 +01:00
|
|
|
public function canSaveAuthnFailed($exception)
|
2022-11-17 00:27:43 +01:00
|
|
|
{
|
|
|
|
$_POST['credential'] = 'msg';
|
|
|
|
$_POST['keyname'] = 'key_name';
|
|
|
|
|
2023-01-27 08:49:09 +01:00
|
|
|
/** @var LoggerInterface|MockObject $loggerMock */
|
|
|
|
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class, [], '', true, true, true, ['error', 'debug']);
|
|
|
|
$loggerMock->expects($this->once())->method('error')->willReturn(true);
|
|
|
|
$loggerMock->expects($this->once())->method('debug')->willReturn(true);
|
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.LoggerInterface::class, $loggerMock);
|
|
|
|
|
|
|
|
/** @var User|MockObject $userMock */
|
|
|
|
$userMock = $this->getMockBuilder(User::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->onlyMethods(['getId'])
|
|
|
|
->getMock();
|
|
|
|
$userMock->method('getId')->willReturn('userId');
|
|
|
|
|
2022-11-17 00:27:43 +01:00
|
|
|
/** @var Webauthn|MockObject $webauthnMock */
|
|
|
|
$webauthnMock = $this->getMockBuilder(Webauthn::class)
|
|
|
|
->onlyMethods(['saveAuthn'])
|
|
|
|
->getMock();
|
|
|
|
$webauthnMock->expects($this->once())->method('saveAuthn')
|
2023-01-27 08:49:09 +01:00
|
|
|
->willThrowException($exception);
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(Webauthn::class, $webauthnMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
/** @var UtilsView|MockObject $utilsViewMock */
|
|
|
|
$utilsViewMock = $this->getMockBuilder(UtilsView::class)
|
|
|
|
->onlyMethods(['addErrorToDisplay'])
|
|
|
|
->getMock();
|
|
|
|
$utilsViewMock->expects($this->atLeastOnce())->method('addErrorToDisplay');
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set('d3ox.webauthn.'.UtilsView::class, $utilsViewMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
2023-01-27 08:49:09 +01:00
|
|
|
/** @var d3_account_webauthn|MockObject $oControllerMock */
|
|
|
|
$oControllerMock = $this->getMockBuilder(d3_account_webauthn::class)
|
|
|
|
->onlyMethods(['getUser'])
|
|
|
|
->getMock();
|
|
|
|
$oControllerMock->method('getUser')->willReturn($userMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'saveAuthn'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-27 08:49:09 +01:00
|
|
|
/**
|
|
|
|
* @return Generator
|
|
|
|
*/
|
|
|
|
public function canSaveAuthnFailedDataProvider(): Generator
|
|
|
|
{
|
|
|
|
yield 'WebauthnException' => [oxNew(WebauthnException::class)];
|
|
|
|
yield 'AssertionException' => [oxNew(InvalidArgumentException::class, 'msg', 200)];
|
|
|
|
}
|
|
|
|
|
2022-11-17 00:27:43 +01:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::deleteKey
|
|
|
|
* @dataProvider canDeleteDataProvider
|
|
|
|
*/
|
|
|
|
public function canDelete($deleteId, $expected)
|
|
|
|
{
|
|
|
|
$_GET['deleteoxid'] = $deleteId;
|
|
|
|
|
|
|
|
/** @var PublicKeyCredential|MockObject $publicKeyCredentialMock */
|
|
|
|
$publicKeyCredentialMock = $this->getMockBuilder(PublicKeyCredential::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->onlyMethods(['delete'])
|
|
|
|
->getMock();
|
|
|
|
$publicKeyCredentialMock->expects($expected)->method('delete')->with($this->identicalTo($deleteId))
|
|
|
|
->willReturn(true);
|
2023-01-21 13:50:18 +01:00
|
|
|
d3GetOxidDIC()->set(PublicKeyCredential::class, $publicKeyCredentialMock);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
2023-01-21 13:50:18 +01:00
|
|
|
/** @var d3_account_webauthn $oControllerMock */
|
|
|
|
$oControllerMock = oxNew(d3_account_webauthn::class);
|
2022-11-17 00:27:43 +01:00
|
|
|
|
|
|
|
$this->_oController = $oControllerMock;
|
|
|
|
|
|
|
|
$this->callMethod($this->_oController, 'deleteKey');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-01-27 08:49:09 +01:00
|
|
|
* @return Generator
|
2022-11-17 00:27:43 +01:00
|
|
|
*/
|
2023-01-27 08:49:09 +01:00
|
|
|
public function canDeleteDataProvider(): Generator
|
2022-11-17 00:27:43 +01:00
|
|
|
{
|
2023-01-27 08:49:09 +01:00
|
|
|
yield 'has delete id' => ['deleteId', $this->once()];
|
|
|
|
yield 'has no delete id' => [null, $this->never()];
|
2022-11-17 00:27:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @covers \D3\Webauthn\Application\Controller\d3_account_webauthn::getBreadCrumb
|
|
|
|
*/
|
|
|
|
public function canGetBreadCrumb()
|
|
|
|
{
|
|
|
|
$this->assertIsArray(
|
|
|
|
$this->callMethod(
|
|
|
|
$this->_oController,
|
|
|
|
'getBreadCrumb'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|