From ddb6f20d95502d3614505c79fcde62b27a66182d Mon Sep 17 00:00:00 2001 From: Hadrien De Laforce Date: Tue, 11 Feb 2025 11:37:25 +0100 Subject: [PATCH] PRE-2727 feat: Get client secret data from jwt one shot the create jwt --- lib/Payplug/Authentication.php | 97 ++++++------------ lib/Payplug/Core/APIRoutes.php | 107 ++++++++------------ lib/Payplug/Core/HttpClient.php | 121 +++++++++++++---------- lib/Payplug/PluginTelemetry.php | 56 +++-------- tests/unit_tests/AuthenticationTest.php | 63 +----------- tests/unit_tests/PluginTelemetryTest.php | 18 +--- 6 files changed, 155 insertions(+), 307 deletions(-) diff --git a/lib/Payplug/Authentication.php b/lib/Payplug/Authentication.php index 1a9e705..6f11c29 100644 --- a/lib/Payplug/Authentication.php +++ b/lib/Payplug/Authentication.php @@ -114,7 +114,7 @@ public static function getPermissionsByLogin($email, $password) * @param Payplug $payplug the client configuration * * @return array|false - * + *createClientIdAndSecret * @throws Exception */ public static function getPublishableKeys(Payplug $payplug = null) @@ -140,22 +140,30 @@ public static function getPublishableKeys(Payplug $payplug = null) * * @throws Exception */ - public static function generateJWT($client_id = '', Payplug $payplug = null) + public static function generateJWT($client_id = '', $client_secret = '') { if ($client_id == '') { return array(); } - - if ($payplug === null) { - $payplug = Payplug::getDefaultConfiguration(); + if ($client_secret == '') { + return array(); } - $httpClient = new Core\HttpClient($payplug); + + $httpClient = new Core\HttpClient(null); try { + $route = Core\APIRoutes::getRoute(Core\APIRoutes::OAUTH2_RESOURCE, null, array(), array(), false); + return $httpClient->post( - Core\APIRoutes::getRoute(Core\APIRoutes::$HYDRA_RESOURCE), - array('client_id' => $client_id, 'grant_type' => 'client_credentials') - ); + $route, + array( + 'grant_type' => 'client_credentials', + 'audience' => 'https://www.payplug.com', + ), false, null, array( + 'Content-Type: application/x-www-form-urlencoded', + 'Authorization: Basic ' . base64_encode($client_id . ':' . $client_secret) + ), + 'x-www-form-urlencoded'); } catch (Exception $e) { return array(); } @@ -176,39 +184,6 @@ private static function validateToken(Payplug $payplug) } } - /** - * Retrieve client datas from the user manager resource. - * - * @param Payplug $payplug the client configuration - * - * @return array the client id and client_secret_mask - * - * @throws Exception - */ - public static function getClientData($session = null, Payplug $payplug = null) - { - if ($payplug === null) { - $payplug = Payplug::getDefaultConfiguration(); - } - $kratosSession = self::setKratosSession($session); - - $httpClient = new Core\HttpClient($payplug); - $response = $httpClient->get(Core\APIRoutes::$USER_MANAGER_RESOURCE, null, $kratosSession); - $result = array(); - foreach ($response['httpResponse'] as $client) { - $result[] = array( - 'client_id' => $client['client_id'], - 'client_secret_mask' => $client['client_secret_mask'], - 'client_name' => $client['client_name'], - 'client_type' => $client['client_type'], - 'mode' => $client['mode'], - - ); - } - - return $result; - } - /** * Create a client ID and secret for a given mode * @@ -217,6 +192,7 @@ public static function getClientData($session = null, Payplug $payplug = null) * @param $mode * @param $session * @param Payplug|null $payplug + * * @return array * @throws ConfigurationException * @throws Exception\ConfigurationNotSetException @@ -226,21 +202,23 @@ public static function getClientData($session = null, Payplug $payplug = null) */ public static function createClientIdAndSecret($company_id = '', $client_name = '', $mode = '', $session = null, Payplug $payplug = null) { - if ($payplug === null) { $payplug = Payplug::getDefaultConfiguration(); } - $kratosSession = self::setKratosSession($session); $httpClient = new Core\HttpClient($payplug); $result = array(); - $response = $httpClient->post(Core\APIRoutes::$USER_MANAGER_RESOURCE, array( - 'company_id' => $company_id, - 'client_name' => $client_name, - 'client_type' => 'oauth2', - 'mode' => $mode, - ), $kratosSession); + + $response = $httpClient->post( + Core\APIRoutes::getServiceRoute(Core\APIRoutes::USER_SERVICE), + array( + 'company_id' => $company_id, + 'client_name' => $client_name, + 'client_type' => 'client_credentials_flow', + 'mode' => $mode, + )); + foreach ($response['httpResponse'] as $client) { $result[] = array( 'client_id' => $client['client_id'], @@ -251,22 +229,6 @@ public static function createClientIdAndSecret($company_id = '', $client_name = return $result; } - /** - * Set the Kratos session cookie. - * - * @param string $session The session value to be set in the cookie. - * - * @return string The formatted Kratos session cookie string. - * @throws ConfigurationException - */ - public static function setKratosSession($session) - { - if (empty($session)) { - throw new ConfigurationException('The session value must be set.'); - } - return 'ory_kratos_session=' . $session; - } - /** * Get the return url to register user through the portal * @@ -292,10 +254,9 @@ public static function getRegisterUrl($setup_redirection_uri = '', $oauth_callba 'setup_redirection_uri' => $setup_redirection_uri, 'oauth_callback_uri' => $oauth_callback_uri, ); - $register_uri = Core\APIRoutes::$PLUGIN_SETUP_URL . '?' . http_build_query($url_datas); return $httpClient->get( - $register_uri, + Core\APIRoutes::getServiceRoute(Core\APIRoutes::PLUGIN_SETUP_SERVICE, $url_datas), null, false ); diff --git a/lib/Payplug/Core/APIRoutes.php b/lib/Payplug/Core/APIRoutes.php index 1838467..b4e44a4 100644 --- a/lib/Payplug/Core/APIRoutes.php +++ b/lib/Payplug/Core/APIRoutes.php @@ -1,4 +1,5 @@ $value) { $route = str_replace('{' . $parameter . '}', $value, $route); @@ -71,52 +58,39 @@ public static function getRoute($route, $resourceId = null, array $parameters = if (!empty($pagination)) $query_pagination = '?' . http_build_query($pagination); - return self::$API_BASE_URL . '/v' . self::API_VERSION . $route . $resourceIdUrl . $query_pagination; - } - - /** - * @description set $API_BASE_URL from plugin - * @param $apiBaseUrl - */ - public static function setApiBaseUrl($apiBaseUrl) - { - self::$API_BASE_URL = $apiBaseUrl; - } - - /** - * @description set $MERCHANT_PLUGINS_DATA_COLLECTOR_RESOURCE from plugin - * @param $microServiceBaseUrl - */ - public static function setMerchantPluginsDataCollectorService($microServiceBaseUrl) - { - self::$MERCHANT_PLUGINS_DATA_COLLECTOR_RESOURCE = $microServiceBaseUrl; + return self::$API_BASE_URL . ($with_version ? '/v' . self::API_VERSION : '') . $route . $resourceIdUrl . $query_pagination; } /** - * @description set $PLUGIN_SETUP_URL from plugin - * @param $pluginSetupUrl + * Get the route to a specified resource. + * + * @param string $route One of the routes defined above + * @param array $parameters The parameters required by the route. + * + * @return string the full URL to the resource + * */ - public static function setPluginSetupUrl($pluginSetupUrl) + public static function getServiceRoute($route, array $parameters = array()) { - self::$PLUGIN_SETUP_URL = $pluginSetupUrl; + return self::$SERVICE_BASE_URL . $route . ($parameters ? '?' . http_build_query($parameters) : ''); } /** - * @description set $HYDRA_RESOURCE from plugin - * @param $microServiceBaseUrl + * @description set $API_BASE_URL from plugin + * @param $apiBaseUrl */ - public static function setHydraResource($microServiceBaseUrl) + public static function setApiBaseUrl($apiBaseUrl) { - self::$HYDRA_RESOURCE = $microServiceBaseUrl; + self::$API_BASE_URL = $apiBaseUrl; } /** - * @description set $USER_MANAGER_RESOURCE from plugin - * @param $microServiceBaseUrl + * @description set $SERVICE_BASE_URL from plugin + * @param $serviceBaseUrl */ - public static function setUserManagerResource($microServiceBaseUrl) + public static function setServiceBaseUrl($serviceBaseUrl) { - self::$USER_MANAGER_RESOURCE = $microServiceBaseUrl; + self::$SERVICE_BASE_URL = $serviceBaseUrl; } /** @@ -131,7 +105,4 @@ public static function getTestRoute() } APIRoutes::$API_BASE_URL = 'https://api.payplug.com'; -APIRoutes::$MERCHANT_PLUGINS_DATA_COLLECTOR_RESOURCE = 'https://retail.service.payplug.com/merchant-plugin-data-collectors/api/v1/plugin_telemetry'; -APIRoutes::$PLUGIN_SETUP_URL = "https://retail.service.payplug.com/users/api/v1/plugin_setup"; -APIRoutes::$USER_MANAGER_RESOURCE ='User manager resource'; -APIRoutes::$HYDRA_RESOURCE = 'Microservice Url'; +APIRoutes::$SERVICE_BASE_URL = 'https://retail.service.payplug.com'; diff --git a/lib/Payplug/Core/HttpClient.php b/lib/Payplug/Core/HttpClient.php index 695e64d..f7f6704 100644 --- a/lib/Payplug/Core/HttpClient.php +++ b/lib/Payplug/Core/HttpClient.php @@ -1,5 +1,7 @@ @@ -59,16 +61,16 @@ public function __construct(Payplug\Payplug $authentication = null) * @throws Payplug\Exception\HttpException When status code is not 2xx. * @throws Payplug\Exception\ConnectionException When an error was encountered while connecting to the resource. */ - public function post($resource, $data = null, $authenticated = true) + public function post($resource, $data = null, $authenticated = true, $cookie = null, $headers = null, $data_type = 'json') { - return $this->request('POST', $resource, $data, $authenticated); + return $this->request('POST', $resource, $data, $authenticated, $cookie, $headers, $data_type); } /** * Sends a PATCH request to the API. * - * @param string $resource the path to the remote resource - * @param array $data Request data + * @param string $resource the path to the remote resource + * @param array $data Request data * * @return array the response in a dictionary with following keys: *
@@ -88,8 +90,8 @@ public function patch($resource, $data = null)
     /**
      * Sends a DELETE request to the API.
      *
-     * @param   string  $resource   the path to the remote resource
-     * @param   array   $data       Request data
+     * @param string $resource the path to the remote resource
+     * @param array $data Request data
      *
      * @return  array   the response in a dictionary with following keys:
      * 
@@ -109,10 +111,8 @@ public function delete($resource, $data = null)
     /**
      * Sends a GET request to the API.
      *
-     * @param   string  $resource       the path to the remote resource
-     * @param   array   $data           Request data
-     * @param   bool   $authenticated
-     * @param   bool   $cookie
+     * @param string $resource the path to the remote resource
+     * @param array $data Request data
      *
      * @return  array   the response in a dictionary with following keys:
      * 
@@ -124,7 +124,7 @@ public function delete($resource, $data = null)
      * @throws  Payplug\Exception\HttpException                   When status code is not 2xx.
      * @throws  Payplug\Exception\ConnectionException             When an error was encountered while connecting to the resource.
      */
-    public function get($resource, $data = null, $authenticated = true, $cookie=null)
+    public function get($resource, $data = null, $authenticated = true, $cookie = null)
     {
         return $this->request('GET', $resource, $data, $authenticated, $cookie);
     }
@@ -142,7 +142,8 @@ public function get($resource, $data = null, $authenticated = true, $cookie=null
      * @throws  Payplug\Exception\HttpException                   When status code is not 2xx.
      * @throws  Payplug\Exception\ConnectionException             When an error was encountered while connecting to the resource.
      */
-    public function testRemote() {
+    public function testRemote()
+    {
         return $this->request('GET', APIRoutes::getTestRoute(), null, false);
     }
 
@@ -150,9 +151,9 @@ public function testRemote() {
      * Legacy : Adds a default product for the User-Agent HTTP header sent for each HTTP request.
      * Replaced by setDefaultUserAgentProduct()
      *
-     * @param   string  $product   the product's name
-     * @param   string  $version   the product's version
-     * @param   string  $comment   a comment about the product
+     * @param string $product the product's name
+     * @param string $version the product's version
+     * @param string $comment a comment about the product
      *
      */
     public static function addDefaultUserAgentProduct($product, $version = null, $comment = null)
@@ -163,9 +164,9 @@ public static function addDefaultUserAgentProduct($product, $version = null, $co
     /**
      * Set a default product for the User-Agent HTTP header sent for each HTTP request.
      *
-     * @param   string  $product   the product's name
-     * @param   string  $version   the product's version
-     * @param   string  $comment   a comment about the product
+     * @param string $product the product's name
+     * @param string $version the product's version
+     * @param string $comment a comment about the product
      *
      */
     public static function setDefaultUserAgentProduct($product, $version = null, $comment = null)
@@ -176,9 +177,9 @@ public static function setDefaultUserAgentProduct($product, $version = null, $co
     /**
      * Formats a product for a User-Agent HTTP header.
      *
-     * @param   string  $product   the product name
-     * @param   string  $version   (optional) product version
-     * @param   string  $comment   (optional) comment about the product.
+     * @param string $product the product name
+     * @param string $version (optional) product version
+     * @param string $comment (optional) comment about the product.
      *
      * @return  string  a formatted User-Agent string (`PRODUCT/VERSION (COMMENT)`)
      */
@@ -200,10 +201,10 @@ private static function formatUserAgentProduct($product, $version = null, $comme
     public static function getUserAgent()
     {
         $curlVersion = curl_version(); // Do not move this inside $headers even if it is used only there.
-                                       // PHP < 5.4 doesn't support call()['value'] directly.
+        // PHP < 5.4 doesn't support call()['value'] directly.
         $userAgent = self::formatUserAgentProduct('PayPlug-PHP',
-                                                  Payplug\Core\Config::LIBRARY_VERSION,
-                                                  sprintf('PHP/%s; curl/%s', phpversion(), $curlVersion['version']));
+            Payplug\Core\Config::LIBRARY_VERSION,
+            sprintf('PHP/%s; curl/%s', phpversion(), $curlVersion['version']));
         foreach (self::$defaultUserAgentProducts as $product) {
             $userAgent .= ' ' . self::formatUserAgentProduct($product[0], $product[1], $product[2]);
         }
@@ -213,10 +214,10 @@ public static function getUserAgent()
     /**
      * Performs a request.
      *
-     * @param   string  $httpVerb       the HTTP verb (PUT, POST, GET, …)
-     * @param   string  $resource       the path to the resource queried
-     * @param   array   $data           the request content
-     * @param   bool    $authenticated  the request should be authenticated
+     * @param string $httpVerb the HTTP verb (PUT, POST, GET, …)
+     * @param string $resource the path to the resource queried
+     * @param array $data the request content
+     * @param bool $authenticated the request should be authenticated
      *
      * @return array the response in a dictionary with following keys:
      * 
@@ -228,21 +229,37 @@ public static function getUserAgent()
      * @throws  Payplug\Exception\HttpException                   When status code is not 2xx.
      * @throws  Payplug\Exception\ConnectionException             When an error was encountered while connecting to the resource.
      */
-    private function request($httpVerb, $resource, array $data = null, $authenticated = true, $cookie = null)
+    private function request(
+        $httpVerb,
+        $resource,
+        array $data = null,
+        $authenticated = true,
+        $cookie = null,
+        array $headersParams = null,
+        $data_type = 'json'
+    )
     {
+
         if (self::$REQUEST_HANDLER === null) {
             $request = new CurlRequest();
-        }
-        else {
+        } else {
             $request = self::$REQUEST_HANDLER;
         }
 
         $userAgent = self::getUserAgent();
-        $headers = array(
-            'Accept: application/json',
-            'Content-Type: application/json',
-            'User-Agent: ' . $userAgent
-        );
+
+        $headers = array();
+
+        if ($headersParams) {
+            foreach ($headersParams as $header) {
+                $headers[] = $header;
+            }
+        } else {
+            $headers[] = 'Accept: application/json';
+            $headers[] = 'Content-Type: application/json';
+        }
+
+        $headers[] = 'User-Agent: ' . $userAgent;
         if ($authenticated) {
             $headers[] = 'Authorization: Bearer ' . $this->_configuration->getToken();
             $headers[] = 'PayPlug-Version: ' . $this->_configuration->getApiVersion();
@@ -262,12 +279,16 @@ private function request($httpVerb, $resource, array $data = null, $authenticate
         $request->setopt(CURLOPT_CAINFO, self::$CACERT_PATH);
         $request->setopt(CURLOPT_FOLLOWLOCATION, true);
         if (!empty($data)) {
-            $request->setopt(CURLOPT_POSTFIELDS, json_encode($data));
+            if ('json' == $data_type) {
+                $request->setopt(CURLOPT_POSTFIELDS, json_encode($data));
+            } else {
+                $request->setopt(CURLOPT_POSTFIELDS, http_build_query($data));
+            }
         }
 
         $result = array(
-            'httpResponse'  => $request->exec(),
-            'httpStatus'    => $request->getInfo(CURLINFO_HTTP_CODE)
+            'httpResponse' => $request->exec(),
+            'httpStatus' => $request->getInfo(CURLINFO_HTTP_CODE)
         );
 
         // We must do this before closing curl
@@ -285,11 +306,11 @@ private function request($httpVerb, $resource, array $data = null, $authenticate
         // If there was an HTTP error
         if (in_array($errorCode, $curlStatusNotManage) && substr($result['httpStatus'], 0, 1) !== '2') {
             $this->throwRequestException($result['httpResponse'], $result['httpStatus']);
-        // Unreachable bracket marked as executable by old versions of XDebug
+            // Unreachable bracket marked as executable by old versions of XDebug
         } // If there was an error with curl
         elseif ($result['httpResponse'] === false || $errorCode) {
             $this->throwConnectionException($result['httpStatus'], $errorMessage);
-        // Unreachable bracket marked as executable by old versions of XDebug
+            // Unreachable bracket marked as executable by old versions of XDebug
         }
 
         $result['httpResponse'] = json_decode($result['httpResponse'], true);
@@ -304,8 +325,8 @@ private function request($httpVerb, $resource, array $data = null, $authenticate
     /**
      * Throws an exception from a given curl error.
      *
-     * @param   int     $errorCode      the curl error code
-     * @param   string  $errorMessage   the error message
+     * @param int $errorCode the curl error code
+     * @param string $errorMessage the error message
      *
      * @throws  Payplug\Exception\ConnectionException
      */
@@ -319,8 +340,8 @@ private function throwConnectionException($errorCode, $errorMessage)
     /**
      * Throws an exception from a given HTTP response and status.
      *
-     * @param   string  $httpResponse   the HTTP response
-     * @param   int     $httpStatus     the HTTP status
+     * @param string $httpResponse the HTTP response
+     * @param int $httpStatus the HTTP status
      *
      * @throws  Payplug\Exception\HttpException   the generated exception from the request
      */
@@ -357,7 +378,7 @@ private function throwRequestException($httpResponse, $httpStatus)
                 break;
             case 422:
                 throw new Payplug\Exception\UnprocessableEntityException('The server encountered an error while processing the request. The submitted data could not be processed.',
-                     $httpResponse, $httpStatus);
+                    $httpResponse, $httpStatus);
                 break;
         }
 
diff --git a/lib/Payplug/PluginTelemetry.php b/lib/Payplug/PluginTelemetry.php
index 387a8cf..be53466 100644
--- a/lib/Payplug/PluginTelemetry.php
+++ b/lib/Payplug/PluginTelemetry.php
@@ -1,8 +1,6 @@
 post(
-            Payplug\Core\APIRoutes::$MERCHANT_PLUGINS_DATA_COLLECTOR_RESOURCE,
+            Core\APIRoutes::getServiceRoute(Core\APIRoutes::TELEMETRY_SERVICE),
             $data
         );
-
-    }
-    /**
-     * this is a mock for send function
-     *
-     * @param string $data
-     * @param \Payplug\Payplug|null $payplug
-     * @return array
-     * @throws Exception\UnprocessableEntityException
-     */
-    public static function mockSend(string $data, Payplug\Payplug $payplug = null)
-    {
-        // Simulate API response
-        $data = json_decode($data, true);
-
-        self::validateData($data);
-
-        $responseData = array(
-            'id' => '64de13f259a577c644d0fb61',
-            'data' => $data
-        );
-        return array(
-            'httpStatus' => 201,
-            'httpResponse' => json_encode(
-                $responseData
-            )
-        );
-
     }
 
     /**
@@ -79,7 +48,7 @@ public static function validateData(array $data)
 
         foreach ($requiredFields as $field) {
             if (!isset($data[$field])) {
-                throw new Payplug\Exception\UnprocessableEntityException(
+                throw new Exception\UnprocessableEntityException(
                     'The server encountered an error while processing the request. The submitted data could not be processed.',
                     '{"detail":[{"loc":["body","' . $field . '"],"msg":"field required","type":"value_error.missing"}]}',
                     422
@@ -87,7 +56,7 @@ public static function validateData(array $data)
             }
         }
         if (!is_array($data['domains']) || empty($data['domains']) || !isset($data['domains'][0]['url']) || !isset($data['domains'][0]['default'])) {
-            throw new Payplug\Exception\UnprocessableEntityException(
+            throw new Exception\UnprocessableEntityException(
                 'The server encountered an error while processing the request. The submitted data could not be processed.',
                 '{"detail":[{"loc":["body","domains"],"msg":"invalid structure","type":"value_error.invalid_structure"}]}',
                 422
@@ -95,7 +64,7 @@ public static function validateData(array $data)
         }
 
         if (!is_array($data['configurations']) || empty($data['configurations']) || !isset($data['configurations']['name'])) {
-            throw new Payplug\Exception\UnprocessableEntityException(
+            throw new Exception\UnprocessableEntityException(
                 'The server encountered an error while processing the request. The submitted data could not be processed.',
                 '{"detail":[{"loc":["body","configurations"],"msg":"invalid structure","type":"value_error.invalid_structure"}]}',
                 422
@@ -103,14 +72,11 @@ public static function validateData(array $data)
         }
 
         if (!is_array($data['modules']) || empty($data['modules']) || !isset($data['modules'][0]['name']) || !isset($data['modules'][0]['version'])) {
-            throw new Payplug\Exception\UnprocessableEntityException(
+            throw new Exception\UnprocessableEntityException(
                 'The server encountered an error while processing the request. The submitted data could not be processed.',
                 '{"detail":[{"loc":["body","modules"],"msg":"invalid structure","type":"value_error.invalid_structure"}]}',
                 422
             );
         }
-
-
-
     }
 }
\ No newline at end of file
diff --git a/tests/unit_tests/AuthenticationTest.php b/tests/unit_tests/AuthenticationTest.php
index bdf34e2..8f9ecf7 100644
--- a/tests/unit_tests/AuthenticationTest.php
+++ b/tests/unit_tests/AuthenticationTest.php
@@ -214,53 +214,6 @@ public function testPublishableKeys()
         $this->assertEquals('pk_test_everythingIsUnderControl', $publishable_keys['httpResponse']['publishable_key']);
     }
 
-    /**
-     * Test the getClientIdAndSecretMask method.
-     *
-     * This test verifies that the getClientData method correctly retrieves
-     * the client_id, client_secret_mask , client_name client_type and mode from the user manager resource.
-     *
-     * @throws \Exception
-     */
-    public function testGetClientData()
-    {
-        $response = array(
-            array(
-                'client_id' => 'test_client_id',
-                'client_secret_mask' => 'test_secret_mask',
-                'client_name' => 'test_client_name',
-                'client_type' => 'test_client_type',
-                'mode' => 'test_mode',
-            ),
-        );
-
-        $this->_requestMock
-            ->expects($this->once())
-            ->method('exec')
-            ->will($this->returnValue(json_encode($response)));
-
-        $this->_requestMock
-            ->expects($this->any())
-            ->method('getinfo')
-            ->will($this->returnCallback(function ($option) {
-                switch ($option) {
-                    case CURLINFO_HTTP_CODE:
-                        return 200;
-                }
-                return null;
-            }));
-
-        $session = 'test_session_value';
-        $result = Authentication::getClientData($session, $this->_configuration);
-        $this->assertCount(1, $result);
-        $this->assertEquals('test_client_id', $result[0]['client_id']);
-        $this->assertEquals('test_secret_mask', $result[0]['client_secret_mask']);
-        $this->assertEquals('test_client_name', $result[0]['client_name']);
-        $this->assertEquals('test_client_type', $result[0]['client_type']);
-        $this->assertEquals('test_mode', $result[0]['mode']);
-
-    }
-
     /**
      * Test the createClientIdAndSecret correctly creates
      *  a client ID and client secret.
@@ -301,19 +254,9 @@ public function testCreateClientIdAndSecret()
         $this->assertEquals('test_client_secret', $result[0]['client_secret']);
     }
 
-    /**
-     * Test the setKratosSession method with a null session.
-     */
-    public function testSetKratosSessionNull()
-    {
-        $this->expectException('\PayPlug\Exception\ConfigurationException');
-        $this->expectExceptionMessage('The session value must be set.');
-        Authentication::setKratosSession(null);
-    }
-
     public function testGenerateJWTWithEmptyClientId()
     {
-        $jwt = Authentication::generateJWT($this->_configuration);
+        $jwt = Authentication::generateJWT('', 'client_secret');
         $this->assertEquals(array(), $jwt);
     }
 
@@ -342,7 +285,7 @@ public function testGenerateJWTWhenErrorResponse()
                 return null;
             }));
 
-        $jwt = Authentication::generateJWT('some_client_id', $this->_configuration);
+        $jwt = Authentication::generateJWT('client_id', 'client_secret');
 
         $this->assertEquals(array(), $jwt);
     }
@@ -372,7 +315,7 @@ public function testGenerateJWTWhenSuccessResponse()
                 return null;
             }));
 
-        $jwt = Authentication::generateJWT('some_client_id', $this->_configuration);
+        $jwt = Authentication::generateJWT('client_id', 'client_secret');
 
         $this->assertEquals(200, $jwt['httpStatus']);
         $this->assertEquals($response, $jwt['httpResponse']);
diff --git a/tests/unit_tests/PluginTelemetryTest.php b/tests/unit_tests/PluginTelemetryTest.php
index 44badbe..1dfc7ae 100644
--- a/tests/unit_tests/PluginTelemetryTest.php
+++ b/tests/unit_tests/PluginTelemetryTest.php
@@ -3,13 +3,11 @@
 
 namespace Payplug;
 use Payplug;
-use \Payplug\Core\HttpClient;
-use Payplug\Core\APIRoutes;
+
 use PHPUnit\Framework\TestCase;
 
 class PluginTelemetryTest extends TestCase
 {
-
     private $_requestMock;
     private $_httpClient;
 
@@ -19,7 +17,7 @@ class PluginTelemetryTest extends TestCase
     protected function setUpTest()
     {
         $this->_configuration = new Payplug\Payplug('abc');
-        $this->_httpClient = new HttpClient(new \Payplug\Payplug('abc'));
+        $this->_httpClient = new Payplug\Core\HttpClient(new \Payplug\Payplug('abc'));
         Payplug\Payplug::setDefaultConfiguration($this->_configuration);
 
         $this->_requestMock = $this->createMock('Payplug\Core\IHttpRequest');
@@ -37,17 +35,6 @@ protected function setUpTest()
     public function testSendWithBadMockedURL()
     {
         $this->expectException('Payplug\Exception\HttpException');
-        // Set a mocked MPDC API URL that will raise an exception
-        APIRoutes::setMerchantPluginsDataCollectorService('bad_mocked_mpdc_api_url');
-
-
-        // Mock the post method of the HTTP client
-        $this->_requestMock->expects($this->once())
-            ->method('exec')
-            ->will($this->returnValue('{"status":"not ok"}'));
-
-        $result = $this->_httpClient->post(APIRoutes::$MERCHANT_PLUGINS_DATA_COLLECTOR_RESOURCE);
-
 
         // Data to send to the MPDC microservice
         $data = array(
@@ -75,6 +62,5 @@ public function testSendWithBadMockedURL()
 
         // call send and assert
         PluginTelemetry::send($data);
-
     }
 }
\ No newline at end of file