Skip to content

Commit

Permalink
Refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-omarov committed Dec 27, 2023
1 parent d9c413d commit 1be2e5e
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 236 deletions.
6 changes: 3 additions & 3 deletions builtin-functions/_functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ define('CURLOPT_SUPPRESS_CONNECT_HEADERS', 200148);
define('CURLOPT_TCP_FASTOPEN', 200149);
define('CURLOPT_TFTP_NO_OPTIONS', 200150);
define('CURLOPT_SSH_COMPRESSION', 200151); // don't work (kphp failed)
define('CURLOPT_SSL_FALSESTART', 200152); // work only on IOS with TLS backend (will be removed)
define('CURLOPT_SSL_FALSESTART', 200152); // work only on IOS with TLS backend (will be removed)
define('CURLOPT_HTTP09_ALLOWED', 200153);
define('CURLOPT_MAIL_RCPT_ALLLOWFAILS', 200154);
define('CURLOPT_MAXAGE_CONN', 200155);
Expand All @@ -1311,13 +1311,13 @@ define('CURLOPT_SSL_OPTIONS', 200159);
define('CURLOPT_PROXY_SSL_OPTIONS', 200160);
define('CURLOPT_PROXY_SSL_VERIFYHOST', 200161);
define('CURLOPT_PROXY_SSLVERSION', 200162); // without CURL_SSLVERSION_MAX_* options
define('CURLOPT_STREAM_WEIGHT', 200163); // don't work (kphp failed)
define('CURLOPT_STREAM_WEIGHT', 200163); // don't work (kphp failed)
define('CURLOPT_TIMEVALUE', 200164);
define('CURLOPT_TIMECONDITION', 200165);
define('CURLOPT_TIMEVALUE_LARGE', 200166);
define('CURLOPT_UPKEEP_INTERVAL_MS', 200167);
define('CURLOPT_UPLOAD_BUFFERSIZE', 200168);
define('CURLOPT_SSH_AUTH_TYPES', 200169); // kphp-curl doesn't support this option
define('CURLOPT_SSH_AUTH_TYPES', 200169); // kphp-curl doesn't support this option
// new slist options
define('CURLOPT_CONNECT_TO', 200170);
define('CURLOPT_PROXYHEADER', 200171);
Expand Down
6 changes: 5 additions & 1 deletion runtime/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ void long_option_setter(EasyContext *easy_context, CURLoption option, const mixe
easy_context->set_option_safe(option, static_cast<long>(value.to_int()));
}

void test_stream_weight(EasyContext *easy_context, CURLoption option, const mixed &value) {
fprintf(stderr, "I can't support %d option, sorry. Got these args: %d, %d\n", (int)option, (int)value.to_int(),(int)easy_context->uniq_id);
}

void string_option_setter(EasyContext *easy_context, CURLoption option, const mixed &value) {
easy_context->set_option_safe(option, value.to_string().c_str());
}
Expand Down Expand Up @@ -887,7 +891,7 @@ bool curl_setopt(EasyContext *easy_context, int64_t option, const mixed &value)
{CURLOPT_PROXY_SSL_OPTIONS, long_option_setter},
{CURLOPT_PROXY_SSL_VERIFYHOST, long_option_setter},
{CURLOPT_PROXY_SSLVERSION, proxy_ssl_version_option_setter},
{CURLOPT_STREAM_WEIGHT, long_option_setter},
{CURLOPT_STREAM_WEIGHT, test_stream_weight},
{CURLOPT_TIMEVALUE, long_option_setter},
{CURLOPT_TIMECONDITION, timecond_option_setter},
{CURLOPT_TIMEVALUE_LARGE, off_option_setter},
Expand Down
26 changes: 15 additions & 11 deletions tests/phpt/curl/13_curl_setopt_new.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

function test_new_options() {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "https://example.com/");

var_dump(curl_setopt($c, CURLOPT_SSL_VERIFYSTATUS, 1));
var_dump(curl_setopt($c, CURLOPT_DISALLOW_USERNAME_IN_URL, 1));
Expand Down Expand Up @@ -34,17 +33,11 @@ function test_new_options() {

var_dump(curl_setopt($c, CURLOPT_HTTP09_ALLOWED, false));
var_dump(curl_setopt($c, CURLOPT_SOCKS5_AUTH, CURLAUTH_GSSAPI));
var_dump(curl_setopt($c, CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST | CURLSSLOPT_NO_PARTIALCHAIN));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST | CURLSSLOPT_NO_PARTIALCHAIN));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSL_VERIFYHOST, 2));

test_proxy_ssl_version_option(); // testing CURLOPT_PROXY_SSLVERSION option

var_dump(curl_setopt($c, CURLOPT_TIMEVALUE, 300));
var_dump(curl_setopt($c, CURLOPT_TIMEVALUE_LARGE, 1<<12));
var_dump(curl_setopt($c, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFUNMODSINCE));
var_dump(curl_setopt($c, CURLOPT_UPKEEP_INTERVAL_MS, 10000));
var_dump(curl_setopt($c, CURLOPT_UPLOAD_BUFFERSIZE, 100000));
var_dump(curl_setopt($c, CURLOPT_CONNECT_TO, ['example.com: server1.example.com']));
var_dump(curl_setopt($c, CURLOPT_PROXYHEADER, ["http://proxy.example.com:80"]));
var_dump(curl_setopt($c, CURLOPT_ENCODING, "gzip"));
Expand All @@ -71,12 +64,23 @@ function test_new_options() {
var_dump(curl_setopt($c, CURLOPT_PROXY_SSLKEY, "$filename.pem"));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSLKEYTYPE, "PEM"));
var_dump(curl_setopt($c, CURLOPT_SERVICE_NAME, "custom"));
var_dump(curl_setopt($c, CURLOPT_SSL_EC_CURVES, "smth"));
var_dump(curl_setopt($c, CURLOPT_UNIX_SOCKET_PATH, "smth"));
var_dump(curl_setopt($c, CURLOPT_XOAUTH2_BEARER, "smth"));

var_dump(curl_exec($c) == true);
curl_close($c);
exec("rm ./$filename.pem");
echo "deleting $filename.pem file\n";
}
}

function test_proxy_ssl_version_option() {
$c = curl_init();

var_dump(curl_setopt($c, CURLOPT_PROXY_SSLVERSION, CURL_SSLVERSION_DEFAULT));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSLVERSION, CURL_SSLVERSION_TLSv1));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSLVERSION, CURL_SSLVERSION_TLSv1_0));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSLVERSION, CURL_SSLVERSION_TLSv1_1));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSLVERSION, CURL_SSLVERSION_TLSv1_2));
curl_close($c);
}

test_new_options();
test_proxy_ssl_version_option();
18 changes: 6 additions & 12 deletions tests/phpt/curl/14_curl_setopt_problems.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@ function test_new_options() {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, "https://example.com/");

var_dump(curl_setopt($c, CURLOPT_SSH_COMPRESSION, true)); // got 48 error
var_dump(curl_setopt($c, CURLOPT_SSL_FALSESTART, false)); // got 4 error
var_dump(curl_setopt($c, CURLOPT_SSH_COMPRESSION, true)); // got 48 error

var_dump(curl_setopt($c, CURLOPT_HTTP09_ALLOWED, false));
var_dump(@curl_setopt($c, CURLOPT_MAIL_RCPT_ALLLOWFAILS, true)); // got warning and NULL from php
var_dump(@curl_setopt($c, CURLOPT_MAXAGE_CONN, 30)); // got warning and NULL from php
var_dump(curl_setopt($c, CURLOPT_MAXFILESIZE_LARGE, 1<<58)); // got NULL from php
var_dump(curl_setopt($c, CURLOPT_MAXLIFETIME_CONN, 30)); // got NULL from php

var_dump(curl_setopt($c, CURLOPT_STREAM_WEIGHT, 20)); // dont work (very bad)

var_dump(curl_setopt($c, CURLOPT_SSH_AUTH_TYPES, CURLSSH_AUTH_NONE)); // got 48 error


var_dump(curl_setopt($c, CURLOPT_DNS_INTERFACE, "eth0")); // got 48 error

var_dump(curl_setopt($c, CURLOPT_PROXY_TLS13_CIPHERS, "kDHE")); // got 4 error
var_dump(curl_setopt($c, CURLOPT_PROXY_TLSAUTH_PASSWORD, "smth")); // got 48 error
var_dump(curl_setopt($c, CURLOPT_PROXY_TLSAUTH_TYPE, "SRP")); // got 48 error, needs OpenSSL with TLS-SRP
var_dump(curl_setopt($c, CURLOPT_SASL_AUTHZID, "Ursel")); // got NULL from PHP
var_dump(curl_setopt($c, CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256, "smth")); // got 48 error, needs libssh2
var_dump(curl_setopt($c, CURLOPT_TLS13_CIPHERS, "smth")); // got 4 error (doesn't supported)

var_dump(curl_exec($c) == true);
var_dump(curl_exec($c));
curl_close($c);
}
}

// only for testing kphp with new libcurl version and all dependencies
//test_new_options();
39 changes: 39 additions & 0 deletions tests/phpt/curl/14_curl_setopt_streams.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@ok
<?php

require_once 'kphp_tester_include.php';

$length = 0;

function test_stream_options() {
$c = curl_init("http://localhost:8080");
$page_info = 'phpinfo();';
$filename = "simple_page.php";
$cmd = "nohup php -S localhost:8080 ./$filename > /dev/null 2>&1 & echo $!";
$fh = fopen("file.txt", "w+");

$callback = function ($ch, $str) {
global $length;
$length += strlen($str);
if ($length >= 100) return -1;
return $length;
};

// var_dump(curl_setopt($c, CURLOPT_WRITEHEADER, $fh));
// var_dump(curl_setopt($c, CURLOPT_HEADERFUNCTION, $callback));
var_dump(curl_setopt($c, CURLOPT_WRITEFUNCTION, $callback));
var_dump(curl_setopt($c, CURLOPT_FILE, $fh));

exec("touch $filename && echo \"<?php\" > .$filename");
exec("echo \"$page_info\" >> .$filename");
exec($cmd, $op);
var_dump(curl_exec($c));

var_dump($fh);
exec("kill $op[0]");
fwrite(fopen("./test.txt", "w+"), $fh);
curl_close($c);
exec("rm ./$filename");
}

test_stream_options();
62 changes: 62 additions & 0 deletions tests/phpt/curl/15_curl_setopt_callables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@ok
<?php

require_once 'kphp_tester_include.php';

// this test is not ready yet

function test_write_function_option() {
$fhandle = "hello world\n";
$ch = curl_init();
$callback = function ($ch, $str) use ($fhandle) {
$rval = fwrite($fhandle, $str);
return $rval ?: 0;
};

var_dump(curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback));
curl_close($ch);
}

function test_write_header_function_option() {
$fhandle = "hello world\n";
$ch = curl_init();
$callback = function ($ch, $str) use ($fhandle) {
$rval = fwrite($fhandle, $str);
return $rval ?: 0;
};

var_dump(curl_setopt($ch, CURLOPT_WRITEHEADER, $fhandle));
var_dump(curl_setopt($ch, CURLOPT_HEADERFUNCTION, $callback));
curl_close($ch);
}

function test_progress_function_option() {
$ch = curl_init();

$callback = function ($resource,$download_size, $downloaded, $upload_size, $uploaded)
{
if($download_size > 0)
echo $downloaded / $download_size * 100;
return 0;
};

var_dump(curl_setopt($ch, CURLOPT_NOPROGRESS, false));
var_dump(curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, $callback));
curl_close($ch);
}

function test_read_function_option() {
$ch = curl_init();

$stream = fopen("php://stdin", "r"); // wont work in kphp

$callback = function ($ch, $stream, $length) {
$data = fread($stream, $length);
var_dump($data);
return ($data !== false) ? $data : "";
};

var_dump(curl_setopt($ch, CURLOPT_READFUNCTION, $callback));
var_dump(curl_setopt($ch, CURLOPT_INFILE, $stream));
curl_close($ch);
}
23 changes: 23 additions & 0 deletions tests/phpt/curl/16_curl_setopt_only_new_curl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@ok
<?php

require_once 'kphp_tester_include.php';

function test_new_options() {
$c = curl_init();
var_dump(curl_setopt($c, CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST | CURLSSLOPT_NO_PARTIALCHAIN));
var_dump(curl_setopt($c, CURLOPT_PROXY_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST | CURLSSLOPT_NO_PARTIALCHAIN));
var_dump(curl_setopt($c, CURLOPT_UPKEEP_INTERVAL_MS, 10000));
var_dump(curl_setopt($c, CURLOPT_UPLOAD_BUFFERSIZE, 100000));
var_dump(curl_setopt($c, CURLOPT_SSL_EC_CURVES, "smth"));

var_dump(curl_setopt($c, CURLOPT_MAIL_RCPT_ALLLOWFAILS, true));
var_dump(curl_setopt($c, CURLOPT_MAXAGE_CONN, 30));
var_dump(curl_setopt($c, CURLOPT_MAXFILESIZE_LARGE, 1 << 48));
var_dump(curl_setopt($c, CURLOPT_MAXLIFETIME_CONN, 30));
var_dump(curl_setopt($c, CURLOPT_SASL_AUTHZID, "Ursel"));
curl_close($c);
}

// only for testing kphp with new libcurl version
//test_new_options();
Loading

0 comments on commit 1be2e5e

Please sign in to comment.