Skip to content

Commit f2b078b

Browse files
committed
OXDEV-9078 Add settings class to get verification url from
1 parent fe3c286 commit f2b078b

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings;
11+
12+
use OxidEsales\Eshop\Core\Config;
13+
14+
class TwoFASettings implements TwoFASettingsInterface
15+
{
16+
public function __construct(
17+
private Config $config,
18+
) {
19+
}
20+
21+
public function getVerificationUrl(): string
22+
{
23+
return $this->config->getShopHomeUrl() . 'cl=twofactorauth';
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings;
11+
12+
interface TwoFASettingsInterface
13+
{
14+
public function getVerificationUrl(): string;
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
public: false
5+
6+
OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface:
7+
class: OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettings

tests/Integration/ServiceAvailabilityTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static function serviceAvailabilityDataProvider(): array
4747
[\OxidEsales\SecurityModule\Authentication\TwoFactorAuth\OTP\Infrastructure\Repository\OtpChallengeStateRepositoryInterface::class],
4848
[\OxidEsales\SecurityModule\Authentication\TwoFactorAuth\OTP\Service\OtpCodeGeneratorServiceInterface::class],
4949
[\OxidEsales\SecurityModule\Authentication\TwoFactorAuth\OTP\Service\OtpCodeHasherServiceInterface::class],
50+
[\OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface::class],
5051
[\OxidEsales\SecurityModule\Authentication\TwoFactorAuth\OTP\Notifier\OtpNotifierInterface::class],
5152
[\OxidEsales\SecurityModule\Authentication\TwoFactorAuth\OTP\Notifier\Factory\OtpNotifierFactoryInterface::class],
5253
];
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\SecurityModule\Tests\Unit\Authentication\TwoFactorAuth\Settings;
11+
12+
use OxidEsales\Eshop\Core\Config;
13+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettings;
14+
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Settings\TwoFASettingsInterface;
15+
use PHPUnit\Framework\Attributes\Test;
16+
use PHPUnit\Framework\TestCase;
17+
18+
class TwoFASettingsTest extends TestCase
19+
{
20+
#[Test]
21+
public function getVerificationUrlReturnsVerificationControllerUrl(): void
22+
{
23+
$configStub = $this->createStub(Config::class);
24+
$configStub->method('getShopHomeUrl')->willReturn($homeUrl = uniqid());
25+
26+
$sut = $this->getSut(config: $configStub);
27+
28+
$this->assertSame($homeUrl . 'cl=twofactorauth', $sut->getVerificationUrl());
29+
}
30+
31+
#[Test]
32+
public function implementsInterface(): void
33+
{
34+
$this->assertInstanceOf(TwoFASettingsInterface::class, $this->getSut());
35+
}
36+
37+
private function getSut(Config $config = null): TwoFASettings
38+
{
39+
return new TwoFASettings(
40+
config: $config ?? $this->createStub(Config::class),
41+
);
42+
}
43+
}

0 commit comments

Comments
 (0)