From adfa1e2dea123c36fff4b45e0ec2c25368262036 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Mon, 21 Oct 2019 09:51:40 +0200 Subject: [PATCH 1/3] Assert that the clientId starts with the expected token --- src/Provider/Mollie.php | 16 ++++++++++++++++ tests/src/Provider/MollieTest.php | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Provider/Mollie.php b/src/Provider/Mollie.php index b7e53c1..5c5ecb7 100644 --- a/src/Provider/Mollie.php +++ b/src/Provider/Mollie.php @@ -25,6 +25,13 @@ class Mollie extends AbstractProvider */ const MOLLIE_WEB_URL = 'https://www.mollie.com'; + /** + * The prefix for the Client ID + * + * @const string + */ + const CLIENT_ID_PREFIX = 'app_'; + /** * Shortcuts to the available Mollie scopes. * @@ -56,6 +63,15 @@ class Mollie extends AbstractProvider const SCOPE_ONBOARDING_READ = 'onboarding.read'; const SCOPE_ONBOARDING_WRITE = 'onboarding.write'; + public function __construct(array $options = [], array $collaborators = []) + { + parent::__construct($options, $collaborators); + + if (!isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) === 0) { + throw new \DomainException("Mollie needs the client ID to be prefixed with " . self::CLIENT_ID_PREFIX . "."); + } + } + /** * Returns the base URL for authorizing a client. * diff --git a/tests/src/Provider/MollieTest.php b/tests/src/Provider/MollieTest.php index 6458c29..5436430 100644 --- a/tests/src/Provider/MollieTest.php +++ b/tests/src/Provider/MollieTest.php @@ -1,6 +1,7 @@ provider = new \Mollie\OAuth2\Client\Provider\Mollie([ - 'clientId' => 'mock_client_id', + $this->provider = new Mollie([ + 'clientId' => 'app_mock_client_id', 'clientSecret' => 'mock_secret', 'redirectUri' => 'none', ]); @@ -21,6 +22,18 @@ public function tearDown() parent::tearDown(); } + public function testClientIdShouldThrowExceptionWhenNotPrefixed() + { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage("Mollie needs the client ID to be prefixed with " . Mollie::CLIENT_ID_PREFIX . "."); + + $provider = new \Mollie\OAuth2\Client\Provider\Mollie([ + 'clientId' => 'not_pefixed_client_id', + 'clientSecret' => 'mock_secret', + 'redirectUri' => 'none', + ]); + } + public function testGetBaseAccessTokenUrl() { $params = []; From b3dd5e3316d703a6cde90dd9d32388bb18a8770b Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Mon, 21 Oct 2019 09:58:44 +0200 Subject: [PATCH 2/3] Fix the if statement to check if it's present and it does not start with prefix --- src/Provider/Mollie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Mollie.php b/src/Provider/Mollie.php index 5c5ecb7..2d444eb 100644 --- a/src/Provider/Mollie.php +++ b/src/Provider/Mollie.php @@ -67,7 +67,7 @@ public function __construct(array $options = [], array $collaborators = []) { parent::__construct($options, $collaborators); - if (!isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) === 0) { + if (isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) === 0) { throw new \DomainException("Mollie needs the client ID to be prefixed with " . self::CLIENT_ID_PREFIX . "."); } } From c71358dc93cdc397e6052ed91961d98f99e402f6 Mon Sep 17 00:00:00 2001 From: Martijn Smit Date: Mon, 21 Oct 2019 10:04:20 +0200 Subject: [PATCH 3/3] Fix the if statement --- src/Provider/Mollie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Provider/Mollie.php b/src/Provider/Mollie.php index 2d444eb..ff7de14 100644 --- a/src/Provider/Mollie.php +++ b/src/Provider/Mollie.php @@ -67,7 +67,7 @@ public function __construct(array $options = [], array $collaborators = []) { parent::__construct($options, $collaborators); - if (isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) === 0) { + if (isset($options["clientId"]) && strpos($options["clientId"], self::CLIENT_ID_PREFIX) !== 0) { throw new \DomainException("Mollie needs the client ID to be prefixed with " . self::CLIENT_ID_PREFIX . "."); } }