From e206a69d4a03717588c601075a309e0db53cfabe Mon Sep 17 00:00:00 2001 From: RenCurs <34103666+RenCurs@users.noreply.github.com> Date: Fri, 18 Mar 2022 10:47:19 +0300 Subject: [PATCH] Add models for simple connection callbacks * Add models for simple connection callbacks * Add verifier request and refactor models --- .../SimpleConnection/RequestVerifier.php | 15 +++++++++ .../SimpleConnection/TokenCreator.php | 13 ++++++++ .../RequestConnectionRegister.php | 32 +++++++++++++++++++ .../ConnectionConfigResponse.php | 32 +++++++++++++++++++ .../ConnectionRegisterResponse.php | 24 ++++++++++++++ .../SimpleConnection/RequestVerifierTest.php | 26 +++++++++++++++ .../SimpleConnection/TokenCreatorTest.php | 19 +++++++++++ .../RequestConnectionRegisterTest.php | 26 +++++++++++++++ 8 files changed, 187 insertions(+) create mode 100644 src/Component/SimpleConnection/RequestVerifier.php create mode 100644 src/Component/SimpleConnection/TokenCreator.php create mode 100644 src/Model/Callback/Entity/SimpleConnection/RequestProperty/RequestConnectionRegister.php create mode 100644 src/Model/Callback/Response/SimpleConnection/ConnectionConfigResponse.php create mode 100644 src/Model/Callback/Response/SimpleConnection/ConnectionRegisterResponse.php create mode 100644 tests/src/Component/SimpleConnection/RequestVerifierTest.php create mode 100644 tests/src/Component/SimpleConnection/TokenCreatorTest.php create mode 100644 tests/src/Model/Callback/Entity/SimpleConnection/RequestProperty/RequestConnectionRegisterTest.php diff --git a/src/Component/SimpleConnection/RequestVerifier.php b/src/Component/SimpleConnection/RequestVerifier.php new file mode 100644 index 0000000..81a5819 --- /dev/null +++ b/src/Component/SimpleConnection/RequestVerifier.php @@ -0,0 +1,15 @@ +apiKey, $secret); + + return hash_equals($hash, $registerRequest->token); + } +} diff --git a/src/Component/SimpleConnection/TokenCreator.php b/src/Component/SimpleConnection/TokenCreator.php new file mode 100644 index 0000000..2545c34 --- /dev/null +++ b/src/Component/SimpleConnection/TokenCreator.php @@ -0,0 +1,13 @@ +systemUrl = 'url'; + $request->apiKey = $apiKey; + $request->token = $token; + + static::assertTrue($verifier->verify($secret, $request)); + } +} diff --git a/tests/src/Component/SimpleConnection/TokenCreatorTest.php b/tests/src/Component/SimpleConnection/TokenCreatorTest.php new file mode 100644 index 0000000..d9f2e1a --- /dev/null +++ b/tests/src/Component/SimpleConnection/TokenCreatorTest.php @@ -0,0 +1,19 @@ + 'test_url', + 'apiKey' => 'test_key', + 'token' => 'token' + ]; + + /** @var RequestConnectionRegister $request */ + $request = SerializerFactory::create()->fromArray($requestData, RequestConnectionRegister::class); + + static::assertEquals($requestData['systemUrl'], $request->systemUrl); + static::assertEquals($requestData['apiKey'], $request->apiKey); + static::assertEquals($requestData['token'], $request->token); + } +}