Source of file tlsSuiteTest.php

Size: 2,400 Bytes - Last Modified: 2020-08-11T22:00:03+00:00

/root/gitwork/work/tornelib-php-netcurl-6.1/tests/tlsSuiteTest.php

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
<?php
/** @noinspection PhpComposerExtensionStubsInspection */

require_once(__DIR__ . '/../vendor/autoload.php');

use PHPUnit\Framework\TestCase;
use TorneLIB\Helpers\Version;
use TorneLIB\Module\Config\WrapperConfig;
use TorneLIB\Module\Network\Wrappers\CurlWrapper;

try {
    Version::getRequiredVersion();
} catch (Exception $e) {
    die($e->getMessage());
}

/**
 * Class curlWrapperTest
 */
class tlsSuiteTest extends TestCase
{
    /**
     * @test
     * Make a TLS 1.3 request (if available).
     * @noinspection NotOptimalIfConditionsInspection
     */
    public function basicGetTLS13()
    {
        // version_compare(PHP_VERSION, '5.6', '>=')
        if (defined('CURL_SSLVERSION_TLSv1_3') && PHP_VERSION_ID >= 50600) {
            try {
                /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
                $tlsResponse = (new CurlWrapper())->
                setConfig(
                    (new WrapperConfig())
                        ->setOption(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_3)
                        ->setUserAgent(sprintf('netcurl-%s', NETCURL_VERSION))
                )
                    ->request(
                        sprintf(
                            'https://ipv4.netcurl.org/?func=%s',
                            __FUNCTION__
                        )
                    )->getParsed();

                if (isset($tlsResponse->ip)) {
                    static::assertTrue(
                        filter_var($tlsResponse->ip, FILTER_VALIDATE_IP) &&
                        $tlsResponse->SSL->SSL_PROTOCOL === 'TLSv1.3'
                    );
                }
            } catch (Exception $e) {
                // Getting connect errors here may indicate that the netcurl server is missing TLS 1.3 support.
                // TLS 1.3 is supported from Apache 2.4.37
                // Also be aware of the fact that not all PHP releases support it.
                if ($e->getCode() === CURLE_SSL_CONNECT_ERROR) {
                    // 14094410
                    static::markTestSkipped($e->getMessage());
                }
            }
        } elseif (PHP_VERSION_ID >= 50600) {
            static::markTestSkipped('TLSv1.3 problems: Your platform is too old to even bother.');
        } else {
            static::markTestSkipped('TLSv1.3 is not available on this platform.');
        }
    }
}