diff --git a/src/tests/integration/integrationTestCase.php b/src/tests/integration/integrationTestCase.php index f8901ca..a6ba5bb 100644 --- a/src/tests/integration/integrationTestCase.php +++ b/src/tests/integration/integrationTestCase.php @@ -17,15 +17,15 @@ namespace D3\Webauthn\tests\integration; -use D3\ModCfg\Application\Model\DependencyInjectionContainer\d3DicHandler; -use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; +use D3\DIContainerHandler\d3DicHandler; use Exception; use OxidEsales\Eshop\Application\Model\Article; use OxidEsales\Eshop\Application\Model\Rights; use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Model\BaseModel; +use OxidEsales\TestingLibrary\UnitTestCase; -abstract class integrationTestCase extends d3ModCfgUnitTestCase +abstract class integrationTestCase extends UnitTestCase { /** * Set up fixture. diff --git a/src/tests/integration/passwordFrontendAuthTest.php b/src/tests/integration/passwordFrontendAuthTest.php index 917a115..0b0c85a 100644 --- a/src/tests/integration/passwordFrontendAuthTest.php +++ b/src/tests/integration/passwordFrontendAuthTest.php @@ -76,7 +76,7 @@ class passwordFrontendAuthTest extends integrationTestCase * @test * @dataProvider loginDataProvider */ - public function testCheckLoginReturn($username, $password, $expected) + public function testCheckLoginReturn($username, $password, $expected, $redirect = null) { $_POST['lgn_usr'] = $username; $_POST['lgn_pwd'] = $password; diff --git a/src/tests/integration/webauthnFrontendAuthTest.php b/src/tests/integration/webauthnFrontendAuthTest.php new file mode 100644 index 0000000..0315d3f --- /dev/null +++ b/src/tests/integration/webauthnFrontendAuthTest.php @@ -0,0 +1,167 @@ + + * @link http://www.oxidmodule.com + */ + +namespace D3\Webauthn\tests\integration; + +use D3\DIContainerHandler\d3DicHandler; +use D3\Webauthn\Application\Model\Credential\PublicKeyCredential; +use OxidEsales\Eshop\Core\Utils; + +class webauthnFrontendAuthTest extends passwordFrontendAuthTest +{ + protected $userList = [ + 1 => 'userId1', + 2 => 'userId2', + 3 => 'userId3', + 4 => 'userId4', + 5 => 'userId5', + ]; + + protected $credentialList = [ + 1 => 'credId1', + 2 => 'credId2', + 3 => 'credId3', + 4 => 'credId4', + 5 => 'credId5', + ]; + + public function createTestData() + { + parent::createTestData(); + + $this->createUser( + $this->userList[5], + [ + 'oxactive' => 1, + 'oxrights' => 'malladmin', + 'oxshopid' => 1, + 'oxusername' => 'wawrongshopid@user.localhost', + 'oxpassword' => '$2y$10$QErMJNHQCoN03tfCUQDRfOvbwvqfzwWw1iI/7bC49fKQrPKoDdnaK', // 123456 + 'oxstreet' => __CLASS__, + ], + true + ); + + $this->createObject( + PublicKeyCredential::class, + $this->credentialList[1], + [ + 'oxuserid' => $this->userList[1], + 'oxshopid' => 1, + 'name' => __CLASS__, + 'credentialid' => 'ITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAAA==', + 'credential'=> 'TzozNDoiV2ViYXV0aG5cUHVibGljS2V5Q3JlZGVudGlhbFNvdXJjZSI6MTA6e3M6MjQ6IgAqAHB1YmxpY0tleUNyZWRlbnRpYWxJZCI7czo3MDoiITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAACI7czo3OiIAKgB0eXBlIjtzOjEwOiJwdWJsaWMta2V5IjtzOjEzOiIAKgB0cmFuc3BvcnRzIjthOjA6e31zOjE4OiIAKgBhdHRlc3RhdGlvblR5cGUiO3M6NDoibm9uZSI7czoxMjoiACoAdHJ1c3RQYXRoIjtPOjMzOiJXZWJhdXRoblxUcnVzdFBhdGhcRW1wdHlUcnVzdFBhdGgiOjA6e31zOjk6IgAqAGFhZ3VpZCI7TzozNToiUmFtc2V5XFV1aWRcTGF6eVxMYXp5VXVpZEZyb21TdHJpbmciOjE6e3M6Njoic3RyaW5nIjtzOjM2OiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiO31zOjIyOiIAKgBjcmVkZW50aWFsUHVibGljS2V5IjtzOjc3OiKlAQIDJiABIVggHucXfQh0acwpsffVRM02F7P57mVm6hPX/l8Pjbh0jOwiWCBRT5MMqa909tcXHqG/EKfjXXDd9UEisk+ZF7QSTfwv0CI7czoxMzoiACoAdXNlckhhbmRsZSI7czoxNDoib3hkZWZhdWx0YWRtaW4iO3M6MTA6IgAqAGNvdW50ZXIiO2k6NDI3MTtzOjEwOiIAKgBvdGhlclVJIjtOO30=', + ] + ); + + $this->createObject( + PublicKeyCredential::class, + $this->credentialList[2], + [ + 'oxuserid' => $this->userList[2], + 'oxshopid' => 1, + 'name' => __CLASS__, + 'credentialid' => 'ITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAAA==', + 'credential'=> 'TzozNDoiV2ViYXV0aG5cUHVibGljS2V5Q3JlZGVudGlhbFNvdXJjZSI6MTA6e3M6MjQ6IgAqAHB1YmxpY0tleUNyZWRlbnRpYWxJZCI7czo3MDoiITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAACI7czo3OiIAKgB0eXBlIjtzOjEwOiJwdWJsaWMta2V5IjtzOjEzOiIAKgB0cmFuc3BvcnRzIjthOjA6e31zOjE4OiIAKgBhdHRlc3RhdGlvblR5cGUiO3M6NDoibm9uZSI7czoxMjoiACoAdHJ1c3RQYXRoIjtPOjMzOiJXZWJhdXRoblxUcnVzdFBhdGhcRW1wdHlUcnVzdFBhdGgiOjA6e31zOjk6IgAqAGFhZ3VpZCI7TzozNToiUmFtc2V5XFV1aWRcTGF6eVxMYXp5VXVpZEZyb21TdHJpbmciOjE6e3M6Njoic3RyaW5nIjtzOjM2OiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiO31zOjIyOiIAKgBjcmVkZW50aWFsUHVibGljS2V5IjtzOjc3OiKlAQIDJiABIVggHucXfQh0acwpsffVRM02F7P57mVm6hPX/l8Pjbh0jOwiWCBRT5MMqa909tcXHqG/EKfjXXDd9UEisk+ZF7QSTfwv0CI7czoxMzoiACoAdXNlckhhbmRsZSI7czoxNDoib3hkZWZhdWx0YWRtaW4iO3M6MTA6IgAqAGNvdW50ZXIiO2k6NDI3MTtzOjEwOiIAKgBvdGhlclVJIjtOO30=', + ] + ); + + $this->createObject( + PublicKeyCredential::class, + $this->credentialList[3], + [ + 'oxuserid' => $this->userList[3], + 'oxshopid' => 1, + 'name' => __CLASS__, + 'credentialid' => 'ITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAAA==', + 'credential'=> 'TzozNDoiV2ViYXV0aG5cUHVibGljS2V5Q3JlZGVudGlhbFNvdXJjZSI6MTA6e3M6MjQ6IgAqAHB1YmxpY0tleUNyZWRlbnRpYWxJZCI7czo3MDoiITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAACI7czo3OiIAKgB0eXBlIjtzOjEwOiJwdWJsaWMta2V5IjtzOjEzOiIAKgB0cmFuc3BvcnRzIjthOjA6e31zOjE4OiIAKgBhdHRlc3RhdGlvblR5cGUiO3M6NDoibm9uZSI7czoxMjoiACoAdHJ1c3RQYXRoIjtPOjMzOiJXZWJhdXRoblxUcnVzdFBhdGhcRW1wdHlUcnVzdFBhdGgiOjA6e31zOjk6IgAqAGFhZ3VpZCI7TzozNToiUmFtc2V5XFV1aWRcTGF6eVxMYXp5VXVpZEZyb21TdHJpbmciOjE6e3M6Njoic3RyaW5nIjtzOjM2OiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiO31zOjIyOiIAKgBjcmVkZW50aWFsUHVibGljS2V5IjtzOjc3OiKlAQIDJiABIVggHucXfQh0acwpsffVRM02F7P57mVm6hPX/l8Pjbh0jOwiWCBRT5MMqa909tcXHqG/EKfjXXDd9UEisk+ZF7QSTfwv0CI7czoxMzoiACoAdXNlckhhbmRsZSI7czoxNDoib3hkZWZhdWx0YWRtaW4iO3M6MTA6IgAqAGNvdW50ZXIiO2k6NDI3MTtzOjEwOiIAKgBvdGhlclVJIjtOO30=', + ] + ); + + $this->createObject( + PublicKeyCredential::class, + $this->credentialList[4], + [ + 'oxuserid' => $this->userList[4], + 'oxshopid' => 1, + 'name' => __CLASS__, + 'credentialid' => 'ITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAAA==', + 'credential'=> 'TzozNDoiV2ViYXV0aG5cUHVibGljS2V5Q3JlZGVudGlhbFNvdXJjZSI6MTA6e3M6MjQ6IgAqAHB1YmxpY0tleUNyZWRlbnRpYWxJZCI7czo3MDoiITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAACI7czo3OiIAKgB0eXBlIjtzOjEwOiJwdWJsaWMta2V5IjtzOjEzOiIAKgB0cmFuc3BvcnRzIjthOjA6e31zOjE4OiIAKgBhdHRlc3RhdGlvblR5cGUiO3M6NDoibm9uZSI7czoxMjoiACoAdHJ1c3RQYXRoIjtPOjMzOiJXZWJhdXRoblxUcnVzdFBhdGhcRW1wdHlUcnVzdFBhdGgiOjA6e31zOjk6IgAqAGFhZ3VpZCI7TzozNToiUmFtc2V5XFV1aWRcTGF6eVxMYXp5VXVpZEZyb21TdHJpbmciOjE6e3M6Njoic3RyaW5nIjtzOjM2OiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiO31zOjIyOiIAKgBjcmVkZW50aWFsUHVibGljS2V5IjtzOjc3OiKlAQIDJiABIVggHucXfQh0acwpsffVRM02F7P57mVm6hPX/l8Pjbh0jOwiWCBRT5MMqa909tcXHqG/EKfjXXDd9UEisk+ZF7QSTfwv0CI7czoxMzoiACoAdXNlckhhbmRsZSI7czoxNDoib3hkZWZhdWx0YWRtaW4iO3M6MTA6IgAqAGNvdW50ZXIiO2k6NDI3MTtzOjEwOiIAKgBvdGhlclVJIjtOO30=', + ] + ); + + $this->createObject( + PublicKeyCredential::class, + $this->credentialList[5], + [ + 'oxuserid' => $this->userList[5], + 'oxshopid' => 2, + 'name' => __CLASS__, + 'credentialid' => 'ITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAAA==', + 'credential'=> 'TzozNDoiV2ViYXV0aG5cUHVibGljS2V5Q3JlZGVudGlhbFNvdXJjZSI6MTA6e3M6MjQ6IgAqAHB1YmxpY0tleUNyZWRlbnRpYWxJZCI7czo3MDoiITSNkDRdN1bfRrb9MDCNOfBNay7YqT3ZxWxxqIQWVvwN0tFOG7SN2JiCfcUfPMBhE9bTLU1Gbb/8+5eHyFR2d5DCrxAAACI7czo3OiIAKgB0eXBlIjtzOjEwOiJwdWJsaWMta2V5IjtzOjEzOiIAKgB0cmFuc3BvcnRzIjthOjA6e31zOjE4OiIAKgBhdHRlc3RhdGlvblR5cGUiO3M6NDoibm9uZSI7czoxMjoiACoAdHJ1c3RQYXRoIjtPOjMzOiJXZWJhdXRoblxUcnVzdFBhdGhcRW1wdHlUcnVzdFBhdGgiOjA6e31zOjk6IgAqAGFhZ3VpZCI7TzozNToiUmFtc2V5XFV1aWRcTGF6eVxMYXp5VXVpZEZyb21TdHJpbmciOjE6e3M6Njoic3RyaW5nIjtzOjM2OiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiO31zOjIyOiIAKgBjcmVkZW50aWFsUHVibGljS2V5IjtzOjc3OiKlAQIDJiABIVggHucXfQh0acwpsffVRM02F7P57mVm6hPX/l8Pjbh0jOwiWCBRT5MMqa909tcXHqG/EKfjXXDd9UEisk+ZF7QSTfwv0CI7czoxMzoiACoAdXNlckhhbmRsZSI7czoxNDoib3hkZWZhdWx0YWRtaW4iO3M6MTA6IgAqAGNvdW50ZXIiO2k6NDI3MTtzOjEwOiIAKgBvdGhlclVJIjtOO30=', + ] + ); + } + + public function cleanTestData() + { + parent::cleanTestData(); + + $this->deleteUser($this->userList[5]); + + $this->deleteObject(PublicKeyCredential::class, $this->credentialList[1]); + $this->deleteObject(PublicKeyCredential::class, $this->credentialList[2]); + $this->deleteObject(PublicKeyCredential::class, $this->credentialList[3]); + $this->deleteObject(PublicKeyCredential::class, $this->credentialList[4]); + $this->deleteObject(PublicKeyCredential::class, $this->credentialList[5]); + } + + /** + * @test + * @param $username + * @param $password + * @param $expected + * @param $redirect + * @return void + * @dataProvider loginDataProvider + */ + public function testCheckLoginReturn($username, $password, $expected, $redirect = null) + { + $utilsMock = $this->getMockBuilder(Utils::class) + ->onlyMethods(['redirect']) + ->getMock(); + $utilsMock->expects($redirect ?: $this->never())->method('redirect')->willReturn(true); + d3DicHandler::getInstance()->set('d3ox.webauthn.'.Utils::class, $utilsMock); + + parent::testCheckLoginReturn($username, $password, $expected); + } + + + /** + * @return array[] + */ + public function loginDataProvider(): array + { + return [ + 'not existing account' => ['unknown@user.localhost', '123456', 'user'], + 'missing password' => ['noadmin@user.localhost', null, 'user', $this->once()], + 'inactive account' => ['inactive@user.localhost', '123456', 'user'], + 'wrong shop account' => ['wrongshop@user.localhost', '123456', 'user'], + 'account ok' => ['admin@user.localhost', '123456', 'user'], + 'cred. wrong shopid' => ['wawrongshopid@user.localhost', null, 'user'], + 'credpass. wrong shopid'=> ['wawrongshopid@user.localhost', '123456', 'payment'], + ]; + } +} diff --git a/src/tests/unit/Application/Model/Credential/PublicKeyCredentialTest.php b/src/tests/unit/Application/Model/Credential/PublicKeyCredentialTest.php index b0fd0e0..716c895 100644 --- a/src/tests/unit/Application/Model/Credential/PublicKeyCredentialTest.php +++ b/src/tests/unit/Application/Model/Credential/PublicKeyCredentialTest.php @@ -141,8 +141,8 @@ class PublicKeyCredentialTest extends WAUnitTestCase $this->canGetField( 'credentialid', 'getCredentialId', - 'credentialFixture', - base64_decode('credentialFixture') + base64_encode('credentialFixture'), + 'credentialFixture' ); }