Skip to content

Commit

Permalink
Add method for testing cURL to DebugController
Browse files Browse the repository at this point in the history
CS-2981
  • Loading branch information
MarijaIv committed Mar 17, 2022
1 parent d4d7e0d commit 191eb24
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/classes/Utility/SystemInfoUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ protected static function getPrestaShopInfo()
$result['Plugin version'] = $packlink->version;
$result['Async process URL'] = $configService->getAsyncProcessUrl('test');
$result['Auto-test URL'] = \Context::getContext()->link->getAdminLink('PacklinkAutoTest');
$result['Test cURL URL'] = \Context::getContext()->link->getAdminLink('Debug') . '&' .
http_build_query(
array(
'ajax' => true,
'action' => 'testCurl',
)
);

return json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
Expand Down
50 changes: 50 additions & 0 deletions src/controllers/admin/DebugController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Logeecom\Infrastructure\ServiceRegister;
use Packlink\PrestaShop\Classes\Utility\PacklinkPrestaShopUtility;
use Packlink\PrestaShop\Classes\Utility\SystemInfoUtility;
use Packlink\BusinessLogic\Controllers\DebugController as BaseDebugController;
Expand Down Expand Up @@ -60,4 +61,53 @@ public function displayAjaxGetSystemInfo()

PacklinkPrestaShopUtility::dieFile($file, self::SYSTEM_INFO_FILE_NAME);
}

/**
* Tests cURL request to the async process controller.
*
* @return void
*/
public function displayAjaxTestCurl()
{
/** @var \Logeecom\Infrastructure\Configuration\Configuration $config */
$config = ServiceRegister::getService( \Logeecom\Infrastructure\Configuration\Configuration::CLASS_NAME );
$url = $config->getAsyncProcessUrl( 'test' );

$curl = curl_init();
$verbose = fopen( 'php://temp', 'wb+' );
/** @noinspection CurlSslServerSpoofingInspection */
curl_setopt_array(
$curl,
array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
// CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_0,
// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 2,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_VERBOSE => true,
CURLOPT_STDERR => $verbose,
// CURLOPT_SSL_CIPHER_LIST => 'TLSv1.2',
CURLOPT_HTTPHEADER => array(
'Cache-Control: no-cache',
),
)
);

$response = curl_exec( $curl );

rewind( $verbose );
echo '<pre>', stream_get_contents( $verbose );

curl_close( $curl );

echo $response;

echo '</pre>';
exit;
}
}

0 comments on commit 191eb24

Please sign in to comment.