From: Michael Wallner Date: Mon, 23 Jul 2018 09:43:57 +0000 (+0200) Subject: travis: fix ssl client test X-Git-Tag: RELEASE_3_2_1~39 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e61393c76eb220de660f2b95111f9bf9e072fe1d;p=m6w6%2Fext-http travis: fix ssl client test --- diff --git a/src/php_http_client_curl.c b/src/php_http_client_curl.c index b17d8a6..1c84e3d 100644 --- a/src/php_http_client_curl.c +++ b/src/php_http_client_curl.c @@ -516,7 +516,11 @@ static ZEND_RESULT_CODE php_http_curle_get_info(CURL *ch, HashTable *info) zval ti_array, subarray; struct curl_tlssessioninfo *ti; +#if PHP_HTTP_CURL_VERSION(7,48,0) + if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_TLS_SSL_PTR, &ti)) { +#else if (CURLE_OK == curl_easy_getinfo(ch, CURLINFO_TLS_SESSION, &ti)) { +#endif char *backend; ZVAL_NULL(&subarray); @@ -530,15 +534,22 @@ static ZEND_RESULT_CODE php_http_curle_get_info(CURL *ch, HashTable *info) backend = "openssl"; #if PHP_HTTP_HAVE_LIBCURL_OPENSSL { +#if PHP_HTTP_CURL_VERSION(7,48,0) + SSL *ssl = ti->internals; + SSL_CTX *ctx = ssl ? SSL_get_SSL_CTX(ssl) : NULL; +#else SSL_CTX *ctx = ti->internals; +#endif array_init(&subarray); - add_assoc_long_ex(&subarray, ZEND_STRL("number"), SSL_CTX_sess_number(ctx)); - add_assoc_long_ex(&subarray, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx)); - add_assoc_long_ex(&subarray, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx)); - add_assoc_long_ex(&subarray, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx)); - add_assoc_long_ex(&subarray, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx)); - add_assoc_long_ex(&subarray, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx)); + if (ctx) { + add_assoc_long_ex(&subarray, ZEND_STRL("number"), SSL_CTX_sess_number(ctx)); + add_assoc_long_ex(&subarray, ZEND_STRL("connect"), SSL_CTX_sess_connect(ctx)); + add_assoc_long_ex(&subarray, ZEND_STRL("connect_good"), SSL_CTX_sess_connect_good(ctx)); + add_assoc_long_ex(&subarray, ZEND_STRL("connect_renegotiate"), SSL_CTX_sess_connect_renegotiate(ctx)); + add_assoc_long_ex(&subarray, ZEND_STRL("hits"), SSL_CTX_sess_hits(ctx)); + add_assoc_long_ex(&subarray, ZEND_STRL("cache_full"), SSL_CTX_sess_cache_full(ctx)); + } } #endif break; @@ -550,11 +561,13 @@ static ZEND_RESULT_CODE php_http_curle_get_info(CURL *ch, HashTable *info) char *desc; array_init(&subarray); - if ((desc = gnutls_session_get_desc(sess))) { - add_assoc_string_ex(&subarray, ZEND_STRL("desc"), desc); - gnutls_free(desc); + if (sess) { + if ((desc = gnutls_session_get_desc(sess))) { + add_assoc_string_ex(&subarray, ZEND_STRL("desc"), desc); + gnutls_free(desc); + } + add_assoc_bool_ex(&subarray, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess)); } - add_assoc_bool_ex(&subarray, ZEND_STRL("resumed"), gnutls_session_is_resumed(sess)); } #endif break; diff --git a/tests/client012.phpt b/tests/client012.phpt index 1e60309..bb599db 100644 --- a/tests/client012.phpt +++ b/tests/client012.phpt @@ -5,6 +5,7 @@ client ssl include "skipif.inc"; skip_online_test(); skip_client_test(); +skip_curl_test("7.34.0"); ?> --FILE-- getSslOptions() ); +$client->attach($observer = new class implements SplObserver { + public $data = []; + function update(SplSubject $client, $req = null, $progress = null) { + $ti = $client->getTransferInfo($req); + if (isset($ti->tls_session["internals"])) { + foreach ((array) $ti->tls_session["internals"] as $key => $val) { + if (!isset($this->data[$key]) || $this->data[$key] < $val) { + $this->data[$key] = $val; + } + } + } + } +}); + $client->enqueue($req = new http\Client\Request("GET", "https://twitter.com/")); $client->send(); -$ti = (array) $client->getTransferInfo($req); -var_dump(array_key_exists("ssl_engines", $ti)); -var_dump(0 < count($ti["ssl_engines"]) || $ti["tls_session"]["backend"] != "openssl"); +switch ($client->getTransferInfo($req)->tls_session["backend"]) { + case "openssl": + case "gnutls": + if (count($observer->data) < 1) { + die("failed count(ssl.internals) >= 1\n"); + } + break; + default: + break; +} ?> Done --EXPECTF-- Test bool(true) -bool(true) -bool(true) Done diff --git a/tests/skipif.inc b/tests/skipif.inc index a9e161a..85dbac2 100644 --- a/tests/skipif.inc +++ b/tests/skipif.inc @@ -36,6 +36,12 @@ function skip_client_test($message = "skip need a client driver\n") { } } +function skip_curl_test($version) { + if (!version_compare(http\Client\Curl\Versions\CURL, $version, "<=")) { + die("need at least libcurl version $version\n"); + } +} + function skip_http2_test($message = "skip need http2 support") { if (!defined("http\\Client\\Curl\\HTTP_VERSION_2_0")) { die("$message (HTTP_VERSION_2_0)\n");