travis: fix ssl client test
authorMichael Wallner <mike@php.net>
Mon, 23 Jul 2018 09:43:57 +0000 (11:43 +0200)
committerMichael Wallner <mike@php.net>
Mon, 23 Jul 2018 09:43:57 +0000 (11:43 +0200)
src/php_http_client_curl.c
tests/client012.phpt
tests/skipif.inc

index b17d8a6927f30d7cf6c5d15165eba3927584a2e1..1c84e3dde7940d50d62ea544d3016ad66b1129e9 100644 (file)
@@ -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;
index 1e603099f32dd40d2eec48cf8f2097784c730f74..bb599db44c2619b1eac6612f84d7b74f098ac5c1 100644 (file)
@@ -5,6 +5,7 @@ client ssl
 include "skipif.inc";
 skip_online_test();
 skip_client_test();
+skip_curl_test("7.34.0");
 ?>
 --FILE--
 <?php 
@@ -21,17 +22,36 @@ var_dump(
        ) === $client->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
index a9e161ab48722e20c0e57741fb1226effab20101..85dbac2902d2c2ae7915b9fe9dcc18d4d6d053c5 100644 (file)
@@ -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");