Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/twofactor_gateway.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2018-08-24 10:36:14 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2018-08-24 10:36:14 +0300
commitc8cc0455b5900e4b9bbef5ae3319bad12ba3e4c3 (patch)
tree6fc4bc892186bca8cfa358ceafdd5144352b8238
parent743c69e9a9dad819445020c96c1b8fc0102a3d6e (diff)
Fix tests
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--lib/Provider/Factory.php62
-rw-r--r--lib/Service/SetupService.php20
-rw-r--r--lib/Service/StateStorage.php2
-rw-r--r--package-lock.json28
-rw-r--r--tests/Unit/Provider/SignalProviderTest.php35
-rw-r--r--tests/Unit/Provider/SmsProviderTest.php7
-rw-r--r--tests/Unit/Provider/TelegramProviderTest.php106
-rw-r--r--tests/Unit/Service/SetupServiceTest.php64
-rw-r--r--tests/Unit/Service/StateStorageTest.php37
9 files changed, 301 insertions, 60 deletions
diff --git a/lib/Provider/Factory.php b/lib/Provider/Factory.php
new file mode 100644
index 0000000..466effc
--- /dev/null
+++ b/lib/Provider/Factory.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\TwoFactorGateway\Provider;
+
+use OCA\TwoFactorGateway\Exception\InvalidSmsProviderException;
+
+class Factory {
+
+ /** @var SignalProvider */
+ private $signalProvider;
+
+ /** @var SmsProvider */
+ private $smsProvider;
+
+ /** @var TelegramProvider */
+ private $telegramProvider;
+
+ public function __construct(SignalProvider $signalProvider,
+ SmsProvider $smsProvider,
+ TelegramProvider $telegramProvider) {
+ $this->signalProvider = $signalProvider;
+ $this->smsProvider = $smsProvider;
+ $this->telegramProvider = $telegramProvider;
+ }
+
+
+ public function getProvider(string $name): AProvider {
+ switch ($name) {
+ case 'signal':
+ return $this->signalProvider;
+ case 'sms':
+ return $this->smsProvider;
+ case 'telegram':
+ return $this->telegramProvider;
+ default:
+ throw new InvalidSmsProviderException();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/lib/Service/SetupService.php b/lib/Service/SetupService.php
index a5c7d51..f5be2d1 100644
--- a/lib/Service/SetupService.php
+++ b/lib/Service/SetupService.php
@@ -29,8 +29,8 @@ use OCA\TwoFactorGateway\Exception\IdentifierMissingException;
use OCA\TwoFactorGateway\Exception\SmsTransmissionException;
use OCA\TwoFactorGateway\Exception\VerificationException;
use OCA\TwoFactorGateway\Exception\VerificationTransmissionException;
+use OCA\TwoFactorGateway\Provider\Factory;
use OCA\TwoFactorGateway\Service\Gateway\Factory as GatewayFactory;
-use OCA\TwoFactorGateway\Provider\SmsProvider;
use OCA\TwoFactorGateway\Provider\State;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\IUser;
@@ -44,24 +44,24 @@ class SetupService {
/** @var GatewayFactory */
private $gatewayFactory;
+ /** @var Factory */
+ private $providerFactory;
+
/** @var ISecureRandom */
private $random;
- /** @var SmsProvider */
- private $provider;
-
/** @var IRegistry */
private $providerRegistry;
public function __construct(StateStorage $stateStorage,
GatewayFactory $gatewayFactory,
+ Factory $providerFactory,
ISecureRandom $random,
- SmsProvider $provider,
IRegistry $providerRegistry) {
$this->stateStorage = $stateStorage;
$this->gatewayFactory = $gatewayFactory;
+ $this->providerFactory = $providerFactory;
$this->random = $random;
- $this->provider = $provider;
$this->providerRegistry = $providerRegistry;
}
@@ -109,7 +109,8 @@ class SetupService {
throw new VerificationException('verification token mismatch');
}
- $this->providerRegistry->enableProviderFor($this->provider, $user);
+ $provider = $this->providerFactory->getProvider($gatewayName);
+ $this->providerRegistry->enableProviderFor($provider, $user);
return $this->stateStorage->persist(
$state->verify()
@@ -117,7 +118,10 @@ class SetupService {
}
public function disable(IUser $user, string $gatewayName): State {
- $this->providerRegistry->disableProviderFor($this->provider, $user);
+ $provider = $this->providerFactory->getProvider($gatewayName);
+ $this->providerRegistry->enableProviderFor($provider, $user);
+ $this->providerRegistry->disableProviderFor($provider, $user);
+
return $this->stateStorage->persist(
State::disabled($user, $gatewayName)
diff --git a/lib/Service/StateStorage.php b/lib/Service/StateStorage.php
index 10307d5..c3eb806 100644
--- a/lib/Service/StateStorage.php
+++ b/lib/Service/StateStorage.php
@@ -41,7 +41,7 @@ class StateStorage {
}
private function buildConfigKey(string $gatewayName, string $key) {
- return "twofactor_gateway_$gatewayName" . "_$key";
+ return "$gatewayName" . "_$key";
}
private function getUserValue(IUser $user, string $gatewayName, string $key, $default = '') {
diff --git a/package-lock.json b/package-lock.json
index 915f923..f54be74 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1699,12 +1699,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -1719,17 +1721,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -1846,7 +1851,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"ini": {
"version": "1.3.5",
@@ -1858,6 +1864,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -1872,6 +1879,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -1879,12 +1887,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@@ -1903,6 +1913,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -1983,7 +1994,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -1995,6 +2007,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"wrappy": "1"
}
@@ -2116,6 +2129,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
diff --git a/tests/Unit/Provider/SignalProviderTest.php b/tests/Unit/Provider/SignalProviderTest.php
new file mode 100644
index 0000000..28e7bf8
--- /dev/null
+++ b/tests/Unit/Provider/SignalProviderTest.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\TwoFactorGateway\Tests\Unit\Provider;
+
+use ChristophWurst\Nextcloud\Testing\TestCase;
+use OCA\TwoFactorGateway\Provider\SignalProvider;
+
+class SignalProviderTest extends TestCase {
+
+ public function test__construct() {
+
+ }
+}
diff --git a/tests/Unit/Provider/SmsProviderTest.php b/tests/Unit/Provider/SmsProviderTest.php
index c1637a4..8df16c0 100644
--- a/tests/Unit/Provider/SmsProviderTest.php
+++ b/tests/Unit/Provider/SmsProviderTest.php
@@ -26,6 +26,7 @@ use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\TwoFactorGateway\Provider\SmsProvider;
use OCA\TwoFactorGateway\Provider\State;
use OCA\TwoFactorGateway\Service\Gateway\IGateway;
+use OCA\TwoFactorGateway\Service\Gateway\SMS\Gateway;
use OCA\TwoFactorGateway\Service\StateStorage;
use OCP\IL10N;
use OCP\ISession;
@@ -36,7 +37,7 @@ use PHPUnit_Framework_MockObject_MockObject;
class SmsProviderTest extends TestCase {
/** @var IGateway|PHPUnit_Framework_MockObject_MockObject */
- private $smsService;
+ private $smsGateway;
/** @var StateStorage|PHPUnit_Framework_MockObject_MockObject */
private $stateStorage;
@@ -56,14 +57,14 @@ class SmsProviderTest extends TestCase {
protected function setUp() {
parent::setUp();
- $this->smsService = $this->createMock(IGateway::class);
+ $this->smsGateway = $this->createMock(Gateway::class);
$this->stateStorage = $this->createMock(StateStorage::class);
$this->session = $this->createMock(ISession::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->l10n = $this->createMock(IL10N::class);
$this->provider = new SmsProvider(
- $this->smsService,
+ $this->smsGateway,
$this->stateStorage,
$this->session,
$this->random,
diff --git a/tests/Unit/Provider/TelegramProviderTest.php b/tests/Unit/Provider/TelegramProviderTest.php
new file mode 100644
index 0000000..738ae0b
--- /dev/null
+++ b/tests/Unit/Provider/TelegramProviderTest.php
@@ -0,0 +1,106 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\TwoFactorGateway\Tests\Unit\Provider;
+
+use ChristophWurst\Nextcloud\Testing\TestCase;
+use OCA\TwoFactorGateway\Provider\TelegramProvider;
+use OCA\TwoFactorGateway\Service\Gateway\Telegram\Gateway;
+use OCA\TwoFactorGateway\Service\StateStorage;
+use OCP\IL10N;
+use OCP\ISession;
+use OCP\Security\ISecureRandom;
+use PHPUnit_Framework_MockObject_MockObject;
+
+class TelegramProviderTest extends TestCase {
+
+ /** @var Gateway|PHPUnit_Framework_MockObject_MockObject */
+ private $gateway;
+
+ /** @var StateStorage|PHPUnit_Framework_MockObject_MockObject */
+ private $stateStorage;
+
+ /** @var ISession|PHPUnit_Framework_MockObject_MockObject */
+ private $session;
+
+ /** @var ISecureRandom|PHPUnit_Framework_MockObject_MockObject */
+ private $random;
+
+ /** @var IL10N|PHPUnit_Framework_MockObject_MockObject */
+ private $l10n;
+
+ /** @var TelegramProvider */
+ private $provider;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->gateway = $this->createMock(Gateway::class);
+ $this->stateStorage = $this->createMock(StateStorage::class);
+ $this->session = $this->createMock(ISession::class);
+ $this->random = $this->createMock(ISecureRandom::class);
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $this->provider = new TelegramProvider(
+ $this->gateway,
+ $this->stateStorage,
+ $this->session,
+ $this->random,
+ $this->l10n
+ );
+ }
+
+
+ public function testGetDescription() {
+ $translated = 'trans';
+ $this->l10n->expects($this->once())
+ ->method('t')
+ ->with('Authenticate via Telegram')
+ ->willReturn($translated);
+
+ $actual = $this->provider->getDescription();
+
+ $this->assertSame($translated, $actual);
+ }
+
+ public function testGetId() {
+ $expected = 'gateway_telegram';
+
+ $actual = $this->provider->getId();
+
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testGetDisplayName() {
+ $translated = 'trans';
+ $this->l10n->expects($this->once())
+ ->method('t')
+ ->with('Telegram verification')
+ ->willReturn($translated);
+
+ $actual = $this->provider->getDisplayName();
+
+ $this->assertSame($translated, $actual);
+ }
+}
diff --git a/tests/Unit/Service/SetupServiceTest.php b/tests/Unit/Service/SetupServiceTest.php
index b7e5555..0dcc21a 100644
--- a/tests/Unit/Service/SetupServiceTest.php
+++ b/tests/Unit/Service/SetupServiceTest.php
@@ -23,11 +23,13 @@
namespace OCA\TwoFactorGateway\Tests\Unit\Service;
use ChristophWurst\Nextcloud\Testing\TestCase;
-use OCA\TwoFactorGateway\Exception\IdentifierMissingException;
+use Exception;
use OCA\TwoFactorGateway\Exception\VerificationException;
use OCA\TwoFactorGateway\Exception\VerificationTransmissionException;
-use OCA\TwoFactorGateway\Provider\SmsProvider;
+use OCA\TwoFactorGateway\Provider\AProvider;
+use OCA\TwoFactorGateway\Provider\Factory as ProviderFactory;
use OCA\TwoFactorGateway\Provider\State;
+use OCA\TwoFactorGateway\Service\Gateway\Factory as GatewayFactory;
use OCA\TwoFactorGateway\Service\Gateway\IGateway;
use OCA\TwoFactorGateway\Service\SetupService;
use OCA\TwoFactorGateway\Service\StateStorage;
@@ -41,14 +43,14 @@ class SetupServiceTest extends TestCase {
/** @var StateStorage|PHPUnit_Framework_MockObject_MockObject */
private $stateStorage;
- /** @var IGateway|PHPUnit_Framework_MockObject_MockObject */
- private $gateway;
+ /** @var GatewayFactory|PHPUnit_Framework_MockObject_MockObject */
+ private $gatewayFactory;
/** @var ISecureRandom|PHPUnit_Framework_MockObject_MockObject */
private $random;
- /** @var SmsProvider|PHPUnit_Framework_MockObject_MockObject */
- private $provider;
+ /** @var ProviderFactory|PHPUnit_Framework_MockObject_MockObject */
+ private $providerFactory;
/** @var IRegistry|PHPUnit_Framework_MockObject_MockObject */
private $registry;
@@ -60,16 +62,16 @@ class SetupServiceTest extends TestCase {
parent::setUp();
$this->stateStorage = $this->createMock(StateStorage::class);
- $this->gateway = $this->createMock(IGateway::class);
+ $this->gatewayFactory = $this->createMock(GatewayFactory::class);
+ $this->providerFactory = $this->createMock(ProviderFactory::class);
$this->random = $this->createMock(ISecureRandom::class);
- $this->provider = $this->createMock(SmsProvider::class);
$this->registry = $this->createMock(IRegistry::class);
$this->setupService = new SetupService(
$this->stateStorage,
- $this->gateway,
+ $this->gatewayFactory,
+ $this->providerFactory,
$this->random,
- $this->provider,
$this->registry
);
}
@@ -77,20 +79,29 @@ class SetupServiceTest extends TestCase {
public function testStartSetupTransmissionError() {
$identifier = '1234';
$user = $this->createMock(IUser::class);
- $this->gateway->expects($this->once())
+ $gateway = $this->createMock(IGateway::class);
+ $this->gatewayFactory->expects($this->once())
+ ->method('getGateway')
+ ->with('sms')
+ ->willReturn($gateway);
+ $gateway->expects($this->once())
->method('send')
->willThrowException(new VerificationTransmissionException());
$this->expectException(VerificationTransmissionException::class);
- $this->setupService->startSetup($user, $identifier);
+ $this->setupService->startSetup($user, 'sms', $identifier);
}
public function testStartSetup() {
$identifier = '0123456789';
- $gatewayName = 'websms';
- $this->gateway->method('getShortName')->willReturn($gatewayName);
+ $gatewayName = 'signal';
+ $gateway = $this->createMock(IGateway::class);
+ $this->gatewayFactory->expects($this->once())
+ ->method('getGateway')
+ ->with($gatewayName)
+ ->willReturn($gateway);
$user = $this->createMock(IUser::class);
- $this->gateway->expects($this->once())
+ $gateway->expects($this->once())
->method('send');
$this->random->expects($this->once())
->method('generate')
@@ -101,14 +112,14 @@ class SetupServiceTest extends TestCase {
->with($this->equalTo($state))
->willReturnArgument(0);
- $actualState = $this->setupService->startSetup($user, $identifier);
+ $actualState = $this->setupService->startSetup($user, $gatewayName, $identifier);
$this->assertEquals($state, $actualState);
}
public function testFinishSetupNoVerificationNumberSet() {
$user = $this->createMock(IUser::class);
- $state = State::disabled($user);
+ $state = State::disabled($user, 'sms');
$this->stateStorage->expects($this->once())
->method('get')
->willReturn($state);
@@ -116,15 +127,15 @@ class SetupServiceTest extends TestCase {
->method('persist');
$this->registry->expects($this->never())
->method('enableProviderFor');
- $this->expectException(\Exception::class);
+ $this->expectException(Exception::class);
- $this->setupService->finishSetup($user, '123456');
+ $this->setupService->finishSetup($user, 'telegram','123456');
}
public function testFinishSetupWithWrongVerificationNumber() {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user123');
- $state = State::verifying($user, 'websms', '0123456789', '654321');
+ $state = State::verifying($user, 'telegram', '0123456789', '654321');
$this->stateStorage->expects($this->once())
->method('get')
->willReturn($state);
@@ -134,20 +145,25 @@ class SetupServiceTest extends TestCase {
->method('enableProviderFor');
$this->expectException(VerificationException::class);
- $this->setupService->finishSetup($user, '123456');
+ $this->setupService->finishSetup($user, 'telegram', '123456');
}
public function testFinishSetup() {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user123');
- $state = State::verifying($user, 'websms', '0123456789', '123456');
+ $state = State::verifying($user, 'signal', '0123456789', '123456');
$this->stateStorage->expects($this->once())
->method('get')
->willReturn($state);
+ $provider = $this->createMock(AProvider::class);
+ $this->providerFactory->expects($this->once())
+ ->method('getProvider')
+ ->with('signal')
+ ->willReturn($provider);
$this->registry->expects($this->once())
->method('enableProviderFor')
->with(
- $this->provider,
+ $provider,
$user
);
$verfied = $state->verify();
@@ -156,7 +172,7 @@ class SetupServiceTest extends TestCase {
->with($this->equalTo($verfied))
->willReturnArgument(0);
- $actualState = $this->setupService->finishSetup($user, '123456');
+ $actualState = $this->setupService->finishSetup($user, 'signal', '123456');
$this->assertEquals($verfied, $actualState);
}
diff --git a/tests/Unit/Service/StateStorageTest.php b/tests/Unit/Service/StateStorageTest.php
index b4359eb..fceef09 100644
--- a/tests/Unit/Service/StateStorageTest.php
+++ b/tests/Unit/Service/StateStorageTest.php
@@ -60,7 +60,7 @@ class StateStorageTest extends TestCase {
[$uid, 'twofactor_gateway', 'verified', 'false', 'false'],
]);
- $state = $this->storage->get($user);
+ $state = $this->storage->get($user, 'sms');
$this->assertSame(SmsProvider::STATE_DISABLED, $state->getState());
}
@@ -71,16 +71,17 @@ class StateStorageTest extends TestCase {
$user->method('getUID')->willReturn($uid);
$this->config->method('getUserValue')
->willReturnMap([
- [$uid, 'twofactor_gateway', 'verified', 'false', 'false'],
- [$uid, 'twofactor_gateway', 'identifier', null, '0123456789'],
- [$uid, 'twofactor_gateway', 'verification_code', null, '123456'],
+ [$uid, 'twofactor_gateway', 'signal_verified', 'false', 'false'],
+ [$uid, 'twofactor_gateway', 'signal_identifier', null, '0123456789'],
+ [$uid, 'twofactor_gateway', 'signal_verification_code', null, '123456'],
]);
- $state = $this->storage->get($user);
+ $state = $this->storage->get($user, 'signal');
$this->assertSame(SmsProvider::STATE_VERIFYING, $state->getState());
$this->assertSame('0123456789', $state->getIdentifier());
$this->assertSame('123456', $state->getVerificationCode());
+ $this->assertSame('signal', $state->getGatewayName());
}
public function testGetEnabledState() {
@@ -89,14 +90,15 @@ class StateStorageTest extends TestCase {
$user->method('getUID')->willReturn($uid);
$this->config->method('getUserValue')
->willReturnMap([
- [$uid, 'twofactor_gateway', 'verified', 'false', 'true'],
- [$uid, 'twofactor_gateway', 'identifier', null, '0123456789'],
+ [$uid, 'twofactor_gateway', 'telegram_verified', 'false', 'true'],
+ [$uid, 'twofactor_gateway', 'telegram_identifier', null, '0123456789'],
]);
- $state = $this->storage->get($user);
+ $state = $this->storage->get($user, 'telegram');
$this->assertSame(SmsProvider::STATE_ENABLED, $state->getState());
$this->assertSame('0123456789', $state->getIdentifier());
+ $this->assertSame('telegram', $state->getGatewayName());
}
public function testDisabledState() {
@@ -105,14 +107,15 @@ class StateStorageTest extends TestCase {
$user->method('getUID')->willReturn($uid);
$this->config->method('getUserValue')
->willReturnMap([
- [$uid, 'twofactor_gateway', 'verified', 'false', 'false'],
- [$uid, 'twofactor_gateway', 'identifier', null, '0123456789'],
+ [$uid, 'twofactor_gateway', 'sms_verified', 'false', 'false'],
+ [$uid, 'twofactor_gateway', 'sms_identifier', null, '0123456789'],
]);
- $state = $this->storage->get($user);
+ $state = $this->storage->get($user, 'sms');
$this->assertSame(SmsProvider::STATE_DISABLED, $state->getState());
$this->assertSame('0123456789', $state->getIdentifier());
+ $this->assertSame('sms', $state->getGatewayName());
}
public function testPersistVerifyingState() {
@@ -129,9 +132,9 @@ class StateStorageTest extends TestCase {
->expects($this->exactly(3))
->method('setUserValue')
->withConsecutive(
- [$uid, 'twofactor_gateway', 'identifier', '0123456789'],
- [$uid, 'twofactor_gateway', 'verification_code', '1234'],
- [$uid, 'twofactor_gateway', 'verified', 'false']
+ [$uid, 'twofactor_gateway', 'telegram_identifier', '0123456789'],
+ [$uid, 'twofactor_gateway', 'telegram_verification_code', '1234'],
+ [$uid, 'twofactor_gateway', 'telegram_verified', 'false']
);
$persisted = $this->storage->persist($state);
@@ -154,9 +157,9 @@ class StateStorageTest extends TestCase {
->expects($this->exactly(3))
->method('setUserValue')
->withConsecutive(
- [$uid, 'twofactor_gateway', 'identifier', '0123456789'],
- [$uid, 'twofactor_gateway', 'verification_code', '1234'],
- [$uid, 'twofactor_gateway', 'verified', 'true']
+ [$uid, 'twofactor_gateway', 'telegram_identifier', '0123456789'],
+ [$uid, 'twofactor_gateway', 'telegram_verification_code', '1234'],
+ [$uid, 'twofactor_gateway', 'telegram_verified', 'true']
);
$persisted = $this->storage->persist($state);