-
Notifications
You must be signed in to change notification settings - Fork 8.1k
More curl tests #23333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sjord
wants to merge
19
commits into
php:master
Choose a base branch
from
Sjord:more-curl-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
More curl tests #23333
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
97b325b
ext/curl: test curl option CURLOPT_WRITEHEADER
Sjord 70feecf
ext/curl: add test for CURLOPT_MAXFILESIZE_LARGE
Sjord cd1390d
Add test for CURLOPT_POSTREDIR
Sjord 7501662
ext/curl: test CURLOPT_SSH_HOSTKEYFUNCTION
Sjord 91def8b
ext/curl: test CURLOPT_FNMATCH_FUNCTION
Sjord 0095114
ext/curl: test CURLINFO_HEADER_OUT
Sjord cbb4b73
ext/curl: test read_cb by sending a CURLFile twice
Sjord d0a6edf
ext/curl: add test for CURLINFO_CERTINFO
Sjord 6b16a26
Minor fixes
Sjord dc8b553
ext/curl: test CURLE_ error constants
Sjord 85a93c4
Improve tests after review comments
Sjord 9d608c8
ext/curl: Skip CURLOPT_MAXFILESIZE_LARGE test on curl < 8.4.0
Sjord 98067c0
Remove duplicate CURLE_OUT_OF_MEMORY
Sjord 2bf48ac
Test error code instead of error message
Sjord 1205971
Run CURLOPT_FNMATCH_FUNCTION test on local test FTP server
Sjord 88e1bba
Remove descriptions
Sjord 29d877e
Fix undefined variable warning
Sjord daa486c
Use valid line terminator in LIST
Sjord e65ad7d
ext/ftp/tests/server.inc requires pcntl_fork
Sjord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| curl seek within uploaded file | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
| include 'server.inc'; | ||
| $host = curl_cli_server_start(); | ||
|
|
||
| $url = "{$host}/get.inc?test=redirect&target=file"; | ||
|
|
||
| $ch = curl_init(); | ||
| curl_setopt($ch, CURLOPT_URL, $url); | ||
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | ||
| curl_setopt($ch, CURLOPT_POSTFIELDS, [ | ||
| 'file' => new CURLFile(__DIR__ . '/curl_testdata1.txt') | ||
| ]); | ||
| curl_exec($ch); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| curl_testdata1.txt|application/octet-stream|6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| --TEST-- | ||
| curl error constants | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $errors = [ | ||
| "CURLE_OK", | ||
| "CURLE_UNSUPPORTED_PROTOCOL", | ||
| "CURLE_FAILED_INIT", | ||
| "CURLE_URL_MALFORMAT", | ||
| "CURLE_COULDNT_RESOLVE_PROXY", | ||
| "CURLE_COULDNT_RESOLVE_HOST", | ||
| "CURLE_COULDNT_CONNECT", | ||
| "CURLE_WEIRD_SERVER_REPLY", | ||
| "CURLE_FTP_WEIRD_PASS_REPLY", | ||
| "CURLE_FTP_WEIRD_PASV_REPLY", | ||
| "CURLE_FTP_WEIRD_227_FORMAT", | ||
| "CURLE_FTP_CANT_GET_HOST", | ||
| "CURLE_PARTIAL_FILE", | ||
| "CURLE_FTP_COULDNT_RETR_FILE", | ||
| "CURLE_HTTP_RETURNED_ERROR", | ||
| "CURLE_WRITE_ERROR", | ||
| "CURLE_READ_ERROR", | ||
| "CURLE_OUT_OF_MEMORY", | ||
| "CURLE_OPERATION_TIMEDOUT", | ||
| "CURLE_FTP_PORT_FAILED", | ||
| "CURLE_FTP_COULDNT_USE_REST", | ||
| "CURLE_HTTP_POST_ERROR", | ||
| "CURLE_SSL_CONNECT_ERROR", | ||
| "CURLE_BAD_DOWNLOAD_RESUME", | ||
| "CURLE_FILE_COULDNT_READ_FILE", | ||
| "CURLE_LDAP_CANNOT_BIND", | ||
| "CURLE_LDAP_SEARCH_FAILED", | ||
| "CURLE_FUNCTION_NOT_FOUND", | ||
| "CURLE_ABORTED_BY_CALLBACK", | ||
| "CURLE_BAD_FUNCTION_ARGUMENT", | ||
| "CURLE_TOO_MANY_REDIRECTS", | ||
| "CURLE_TELNET_OPTION_SYNTAX", | ||
| "CURLE_GOT_NOTHING", | ||
| "CURLE_SSL_ENGINE_NOTFOUND", | ||
| "CURLE_SSL_ENGINE_SETFAILED", | ||
| "CURLE_SEND_ERROR", | ||
| "CURLE_RECV_ERROR", | ||
| "CURLE_SSL_CERTPROBLEM", | ||
| "CURLE_SSL_CIPHER", | ||
| "CURLE_SSL_CACERT", | ||
| "CURLE_BAD_CONTENT_ENCODING", | ||
| "CURLE_LDAP_INVALID_URL", | ||
| "CURLE_FILESIZE_EXCEEDED", | ||
| "CURLE_SSL_CACERT_BADFILE", | ||
| "CURLE_SSH", | ||
| "CURLE_SSL_PINNEDPUBKEYNOTMATCH", | ||
| ]; | ||
|
|
||
| foreach ($errors as $error) { | ||
| $value = defined($error) ? constant($error) : 'undefined'; | ||
| echo $error, '=', $value, "\n"; | ||
| } | ||
|
|
||
| --EXPECT-- | ||
| CURLE_OK=0 | ||
| CURLE_UNSUPPORTED_PROTOCOL=1 | ||
| CURLE_FAILED_INIT=2 | ||
| CURLE_URL_MALFORMAT=3 | ||
| CURLE_COULDNT_RESOLVE_PROXY=5 | ||
| CURLE_COULDNT_RESOLVE_HOST=6 | ||
| CURLE_COULDNT_CONNECT=7 | ||
| CURLE_WEIRD_SERVER_REPLY=8 | ||
| CURLE_FTP_WEIRD_PASS_REPLY=11 | ||
| CURLE_FTP_WEIRD_PASV_REPLY=13 | ||
| CURLE_FTP_WEIRD_227_FORMAT=14 | ||
| CURLE_FTP_CANT_GET_HOST=15 | ||
| CURLE_PARTIAL_FILE=18 | ||
| CURLE_FTP_COULDNT_RETR_FILE=19 | ||
| CURLE_HTTP_RETURNED_ERROR=22 | ||
| CURLE_WRITE_ERROR=23 | ||
| CURLE_READ_ERROR=26 | ||
| CURLE_OUT_OF_MEMORY=27 | ||
| CURLE_OPERATION_TIMEDOUT=28 | ||
| CURLE_FTP_PORT_FAILED=30 | ||
| CURLE_FTP_COULDNT_USE_REST=31 | ||
| CURLE_HTTP_POST_ERROR=34 | ||
| CURLE_SSL_CONNECT_ERROR=35 | ||
| CURLE_BAD_DOWNLOAD_RESUME=36 | ||
| CURLE_FILE_COULDNT_READ_FILE=37 | ||
| CURLE_LDAP_CANNOT_BIND=38 | ||
| CURLE_LDAP_SEARCH_FAILED=39 | ||
| CURLE_FUNCTION_NOT_FOUND=41 | ||
| CURLE_ABORTED_BY_CALLBACK=42 | ||
| CURLE_BAD_FUNCTION_ARGUMENT=43 | ||
| CURLE_TOO_MANY_REDIRECTS=47 | ||
| CURLE_TELNET_OPTION_SYNTAX=49 | ||
| CURLE_GOT_NOTHING=52 | ||
| CURLE_SSL_ENGINE_NOTFOUND=53 | ||
| CURLE_SSL_ENGINE_SETFAILED=54 | ||
| CURLE_SEND_ERROR=55 | ||
| CURLE_RECV_ERROR=56 | ||
| CURLE_SSL_CERTPROBLEM=58 | ||
| CURLE_SSL_CIPHER=59 | ||
| CURLE_SSL_CACERT=60 | ||
| CURLE_BAD_CONTENT_ENCODING=61 | ||
| CURLE_LDAP_INVALID_URL=62 | ||
| CURLE_FILESIZE_EXCEEDED=63 | ||
| CURLE_SSL_CACERT_BADFILE=77 | ||
| CURLE_SSH=79 | ||
| CURLE_SSL_PINNEDPUBKEYNOTMATCH=90 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --TEST-- | ||
| curl_getinfo - CURLINFO_CERTINFO | ||
| --EXTENSIONS-- | ||
| curl | ||
| --SKIPIF-- | ||
| <?php | ||
| include 'skipif-nocaddy.inc'; | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $ch = curl_init("https://localhost/ping"); | ||
| curl_setopt($ch, CURLOPT_CERTINFO, 1); | ||
| curl_exec($ch); | ||
| echo "\n"; | ||
|
|
||
| $certinfo = curl_getinfo($ch, CURLINFO_CERTINFO); | ||
|
|
||
| var_dump(empty($certinfo)); | ||
| var_dump(str_starts_with($certinfo[0]['Cert'], '-----BEGIN CERTIFICATE-----')); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| pong | ||
| bool(false) | ||
| bool(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --TEST-- | ||
| curl_getinfo CURLINFO_HEADER_OUT | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
| include 'server.inc'; | ||
| $host = curl_cli_server_start(); | ||
|
|
||
| $ch = curl_init("{$host}/get.inc?test=method"); | ||
| curl_setopt($ch, CURLINFO_HEADER_OUT, 1); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| curl_setopt($ch, CURLOPT_HTTPHEADER, ['Request-num: 1']); | ||
| curl_exec($ch); | ||
|
|
||
| // The header string contains the full request header line(s). | ||
| $headers = rtrim(curl_getinfo($ch, CURLINFO_HEADER_OUT)); | ||
| echo "With CURLINFO_HEADER_OUT=1:\n"; | ||
| echo $headers, "\n---\n"; | ||
|
|
||
| // Toggling back to 0 should clear the buffer; next getinfo returns false. | ||
| curl_setopt($ch, CURLOPT_HTTPHEADER, ['Request-num: 2']); | ||
| curl_setopt($ch, CURLINFO_HEADER_OUT, 0); | ||
| curl_exec($ch); | ||
|
|
||
| $headers = curl_getinfo($ch, CURLINFO_HEADER_OUT); | ||
| echo "With CURLINFO_HEADER_OUT=0:\n"; | ||
| var_dump($headers); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| With CURLINFO_HEADER_OUT=1: | ||
| GET /get.inc?test=method HTTP/1.1 | ||
| Host: localhost:%d | ||
| %s | ||
| Request-num: 1 | ||
| --- | ||
| With CURLINFO_HEADER_OUT=0: | ||
| bool(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --TEST-- | ||
| Curl option CURLOPT_FNMATCH_FUNCTION | ||
| --EXTENSIONS-- | ||
| curl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (!function_exists('pcntl_fork')) die("skip pcntl_fork() not available."); | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| require(__DIR__ . '/../../ftp/tests/server.inc'); | ||
|
|
||
| $seen_patterns = []; | ||
| $seen_fnames = []; | ||
|
|
||
| function fnmatch_function($ch, string $pattern, string $fname) { | ||
| global $seen_patterns, $seen_fnames; | ||
|
|
||
| $seen_patterns[] = $pattern; | ||
| $seen_fnames[] = $fname; | ||
|
|
||
| if ($fname === 'a story') { | ||
| return CURL_FNMATCHFUNC_MATCH; | ||
| } else { | ||
| return CURL_FNMATCHFUNC_NOMATCH; | ||
| } | ||
| } | ||
|
|
||
| $ch = curl_init("ftp://$socket_name/f*"); | ||
| curl_setopt($ch, CURLOPT_FNMATCH_FUNCTION, 'fnmatch_function'); | ||
| curl_setopt($ch, CURLOPT_WILDCARDMATCH, 1); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| echo curl_exec($ch); | ||
|
|
||
| var_dump(in_array('f*', $seen_patterns)); | ||
| var_dump(in_array('mediumfile', $seen_fnames)); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| For sale: baby shoes, never worn. | ||
| bool(true) | ||
| bool(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --TEST-- | ||
| Curl option CURLOPT_MAXFILESIZE_LARGE | ||
| --SKIPIF-- | ||
| <?php | ||
| $curl_version = curl_version(); | ||
| if ($curl_version['version_number'] < 0x080400) { | ||
| // Earlier curl has this option, but it only works | ||
| // when the response has a Content-Length header. | ||
| exit("skip: test works only with curl >= 8.4.0"); | ||
| } | ||
| ?> | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
| include 'server.inc'; | ||
| $host = curl_cli_server_start(); | ||
|
|
||
| echo "Body larger than CURLOPT_MAXFILESIZE_LARGE\n"; | ||
| $ch = curl_init(); | ||
| curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc"); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| curl_setopt($ch, CURLOPT_MAXFILESIZE_LARGE, 10); | ||
| $r = curl_exec($ch); | ||
| var_dump($r); | ||
| var_dump(curl_errno($ch) === CURLE_FILESIZE_EXCEEDED); | ||
|
|
||
| echo "Body smaller than CURLOPT_MAXFILESIZE_LARGE\n"; | ||
| curl_setopt($ch, CURLOPT_MAXFILESIZE_LARGE, 30); | ||
| $r = curl_exec($ch); | ||
| var_dump(strlen($r)); | ||
|
|
||
| echo "Limit disabled by setting CURLOPT_MAXFILESIZE_LARGE to 0\n"; | ||
| curl_setopt($ch, CURLOPT_MAXFILESIZE_LARGE, 0); | ||
| $r = curl_exec($ch); | ||
| var_dump(strlen($r)); | ||
|
|
||
| echo "Negative value for CURLOPT_MAXFILESIZE_LARGE\n"; | ||
| $ok = curl_setopt($ch, CURLOPT_MAXFILESIZE_LARGE, -1); | ||
| var_dump($ok); | ||
| var_dump(curl_errno($ch) === CURLE_BAD_FUNCTION_ARGUMENT); | ||
|
|
||
| echo "Negative value not set, CURLOPT_MAXFILESIZE_LARGE is still 0\n"; | ||
| $r = curl_exec($ch); | ||
| var_dump(strlen($r)); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Body larger than CURLOPT_MAXFILESIZE_LARGE | ||
| bool(false) | ||
| bool(true) | ||
| Body smaller than CURLOPT_MAXFILESIZE_LARGE | ||
| int(25) | ||
| Limit disabled by setting CURLOPT_MAXFILESIZE_LARGE to 0 | ||
| int(25) | ||
| Negative value for CURLOPT_MAXFILESIZE_LARGE | ||
| bool(false) | ||
| bool(true) | ||
| Negative value not set, CURLOPT_MAXFILESIZE_LARGE is still 0 | ||
| int(25) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --TEST-- | ||
| Curl option CURLOPT_POSTREDIR | ||
| --EXTENSIONS-- | ||
| curl | ||
| --FILE-- | ||
| <?php | ||
| include 'server.inc'; | ||
| $host = curl_cli_server_start(); | ||
|
|
||
| function do_redirect($code, $postredir_value = null) { | ||
| global $host; | ||
|
|
||
| $ch = curl_init(); | ||
| curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=redirect&code={$code}"); | ||
| curl_setopt($ch, CURLOPT_POST, true); | ||
| curl_setopt($ch, CURLOPT_POSTFIELDS, 'postdata was kept in redirect'); | ||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | ||
| if ($postredir_value !== null) { | ||
| curl_setopt($ch, CURLOPT_POSTREDIR, $postredir_value); | ||
| } | ||
| return trim(curl_exec($ch)); | ||
| } | ||
|
|
||
| $options = [null, CURL_REDIR_POST_301, CURL_REDIR_POST_302, CURL_REDIR_POST_303, CURL_REDIR_POST_ALL, 0]; | ||
| $codes = [301, 302, 303]; | ||
|
|
||
| foreach ($options as $option) { | ||
| foreach ($codes as $code) { | ||
| echo "code: $code; option ", var_export($option, true), ': '; | ||
| echo do_redirect($code, $option), "\n"; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| code: 301; option NULL: string(0) "" | ||
| code: 302; option NULL: string(0) "" | ||
| code: 303; option NULL: string(0) "" | ||
| code: 301; option 1: string(29) "postdata was kept in redirect" | ||
| code: 302; option 1: string(0) "" | ||
| code: 303; option 1: string(0) "" | ||
| code: 301; option 2: string(0) "" | ||
| code: 302; option 2: string(29) "postdata was kept in redirect" | ||
| code: 303; option 2: string(0) "" | ||
| code: 301; option 4: string(0) "" | ||
| code: 302; option 4: string(0) "" | ||
| code: 303; option 4: string(29) "postdata was kept in redirect" | ||
| code: 301; option 7: string(29) "postdata was kept in redirect" | ||
| code: 302; option 7: string(29) "postdata was kept in redirect" | ||
| code: 303; option 7: string(29) "postdata was kept in redirect" | ||
| code: 301; option 0: string(0) "" | ||
| code: 302; option 0: string(0) "" | ||
| code: 303; option 0: string(0) "" |
30 changes: 30 additions & 0 deletions
30
ext/curl/tests/curl_setopt_CURLOPT_SSH_HOSTKEYFUNCTION.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --TEST-- | ||
| Curl option CURLOPT_SSH_HOSTKEYFUNCTION | ||
| --EXTENSIONS-- | ||
| curl | ||
| --SKIPIF-- | ||
| <?php | ||
| if (getenv('SKIP_ONLINE_TESTS')) die('skip Online test'); | ||
| $curl_version = curl_version(); | ||
| if ($curl_version['version_number'] < 0x075400) { | ||
| exit("skip: test works only with curl >= 7.84.0"); | ||
| } | ||
| ?> | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| function hostkeyfunction($ch, int $keyType, string $key, int $keyLength) { | ||
| return CURLKHMATCH_MISMATCH; | ||
| } | ||
|
|
||
| // GitHub doesn't actually support SFTP, it does get far enough that the host key callback is called. | ||
| $ch = curl_init('sftp://php@github.com/file.txt'); | ||
| curl_setopt($ch, CURLOPT_SSH_HOSTKEYFUNCTION, 'hostkeyfunction'); | ||
|
Sjord marked this conversation as resolved.
|
||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| var_dump(curl_exec($ch)); | ||
| var_dump(curl_errno($ch) == CURLE_SSL_CACERT); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(false) | ||
| bool(true) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.