1# curl test suite file format 2 3The curl test suite's file format is very simple and extensible, closely 4resembling XML. All data for a single test case resides in a single ASCII 5file. Labels mark the beginning and the end of all sections, and each label 6must be written in its own line. Comments are either XML-style (enclosed with 7`<!--` and `-->`) or shell script style (beginning with `#`) and must appear 8on their own lines and not alongside actual test data. Most test data files 9are syntactically valid XML, although a few files are not (lack of support for 10character entities and the preservation of CR/LF characters at the end of 11lines are the biggest differences). 12 13Each test case source exists as a file matching the format 14`tests/data/testNUM`, where NUM is the unique test number, and must begin with 15a 'testcase' tag, which encompasses the remainder of the file. 16 17# Preprocessing 18 19When a test is to be executed, the source file is first preprocessed and 20variables are substituted by the their respective contents and the output 21version of the test file is stored as `log/testNUM`. That version is what will 22be read and used by the test servers. 23 24## Base64 Encoding 25 26In the preprocess stage, a special instruction can be used to have runtests.pl 27base64 encode a certain section and insert in the generated output file. This 28is in particular good for test cases where the test tool is expected to pass 29in base64 encoded content that might use dynamic information that is unique 30for this particular test invocation, like the server port number. 31 32To insert a base64 encoded string into the output, use this syntax: 33 34 %b64[ data to encode ]b64% 35 36The data to encode can then use any of the existing variables mentioned below, 37or even percent-encoded individual bytes. As an example, insert the HTTP 38server's port number (in ASCII) followed by a space and the hexadecimal byte 399a: 40 41 %b64[%HTTPPORT %9a]b64% 42 43## Hexadecimal decoding 44 45In the preprocess stage, a special instruction can be used to have runtests.pl 46generate a sequence of binary bytes. 47 48To insert a sequence of bytes from a hex encoded string, use this syntax: 49 50 %hex[ %XX-encoded data to decode ]hex% 51 52For example, to insert the binary octets 0, 1 and 255 into the test file: 53 54 %hex[ %00%01%FF ]hex% 55 56## Repeat content 57 58In the preprocess stage, a special instruction can be used to have runtests.pl 59generate a repetetive sequence of bytes. 60 61To insert a sequence of repeat bytes, use this syntax to make the `<string>` 62get repeated `<number>` of times. The number has to be 1 or large and the 63string may contain `%HH` hexadecimal codes: 64 65 %repeat[<number> x <string>]% 66 67For example, to insert the word hello a 100 times: 68 69 %repeat[100 x hello]% 70 71## Conditional lines 72 73Lines in the test file can be made to appear conditionally on a specific 74feature (see the "features" section below) being set or not set. If the 75specific feature is present, the following lines will be output, otherwise it 76outputs nothing, until a following else or endif clause. Like this: 77 78 %if brotli 79 Accept-Encoding 80 %endif 81 82It can also check for the inversed condition, so if the feature us *not* set by 83the use of an exclamation mark: 84 85 %if !brotli 86 Accept-Encoding: not-brotli 87 %endif 88 89You can also make an "else" clause to get output for the opposite condition, 90like: 91 92 %if brotli 93 Accept-Encoding: brotli 94 %else 95 Accept-Encoding: nothing 96 %endif 97 98**Note** that there can be no nested conditions. You can only do one 99conditional at a time and you can only check for a single feature in it. 100 101# Variables 102 103When the test is preprocessed, a range of "variables" in the test file will be 104replaced by their content at that time. 105 106Available substitute variables include: 107 108- `%CLIENT6IP` - IPv6 address of the client running curl 109- `%CLIENTIP` - IPv4 address of the client running curl 110- `%CURL` - Path to the curl executable 111- `%FILE_PWD` - Current directory, on windows prefixed with a slash 112- `%FTP6PORT` - IPv6 port number of the FTP server 113- `%FTPPORT` - Port number of the FTP server 114- `%FTPSPORT` - Port number of the FTPS server 115- `%FTPTIME2` - Timeout in seconds that should be just sufficient to receive a 116 response from the test FTP server 117- `%FTPTIME3` - Even longer than %FTPTIME2 118- `%GOPHER6PORT` - IPv6 port number of the Gopher server 119- `%GOPHERPORT` - Port number of the Gopher server 120- `%GOPHERSPORT` - Port number of the Gophers server 121- `%HOST6IP` - IPv6 address of the host running this test 122- `%HOSTIP` - IPv4 address of the host running this test 123- `%HTTP6PORT` - IPv6 port number of the HTTP server 124- `%HTTPPORT` - Port number of the HTTP server 125- `%HTTP2PORT` - Port number of the HTTP/2 server 126- `%HTTPSPORT` - Port number of the HTTPS server 127- `%HTTPSPROXYPORT` - Port number of the HTTPS-proxy 128- `%HTTPTLS6PORT` - IPv6 port number of the HTTP TLS server 129- `%HTTPTLSPORT` - Port number of the HTTP TLS server 130- `%HTTPUNIXPATH` - Path to the Unix socket of the HTTP server 131- `%IMAP6PORT` - IPv6 port number of the IMAP server 132- `%IMAPPORT` - Port number of the IMAP server 133- `%MQTTPORT` - Port number of the MQTT server 134- `%TELNETPORT` - Port number of the telnet server 135- `%NOLISTENPORT` - Port number where no service is listening 136- `%POP36PORT` - IPv6 port number of the POP3 server 137- `%POP3PORT` - Port number of the POP3 server 138- `%POSIX_PWD` - Current directory somewhat mingw friendly 139- `%PROXYPORT` - Port number of the HTTP proxy 140- `%PWD` - Current directory 141- `%RTSP6PORT` - IPv6 port number of the RTSP server 142- `%RTSPPORT` - Port number of the RTSP server 143- `%SMBPORT` - Port number of the SMB server 144- `%SMBSPORT` - Port number of the SMBS server 145- `%SMTP6PORT` - IPv6 port number of the SMTP server 146- `%SMTPPORT` - Port number of the SMTP server 147- `%SOCKSPORT` - Port number of the SOCKS4/5 server 148- `%SRCDIR` - Full path to the source dir 149- `%SSHPORT` - Port number of the SCP/SFTP server 150- `%SSHSRVMD5` - MD5 of SSH server's public key 151- `%SSH_PWD` - Current directory friendly for the SSH server 152- `%TESTNUMBER` - Number of the test case 153- `%TFTP6PORT` - IPv6 port number of the TFTP server 154- `%TFTPPORT` - Port number of the TFTP server 155- `%USER` - Login ID of the user running the test 156- `%VERSION` - the full version number of the tested curl 157 158# `<testcase>` 159 160Each test is always specified entirely within the testcase tag. Each test case 161is split up in four main sections: `info`, `reply`, `client` and `verify`. 162 163- **info** provides information about the test case 164 165- **reply** is used for the server to know what to send as a reply for the 166requests curl sends 167 168- **client** defines how the client should behave 169 170- **verify** defines how to verify that the data stored after a command has 171been run ended up correctly 172 173Each main section has a number of available subsections that can be specified, 174that will be checked/used if specified. 175 176## `<info>` 177 178### `<keywords>` 179A newline-separated list of keywords describing what this test case uses and 180tests. Try to use already used keywords. These keywords will be used for 181statistical/informational purposes and for choosing or skipping classes of 182tests. "Keywords" must begin with an alphabetic character, "-", "[" or "{" 183and may actually consist of multiple words separated by spaces which are 184treated together as a single identifier. 185 186When using curl built with Hyper, the keywords must include HTTP or HTTPS for 187'hyper mode' to kick in and make line ending checks work for tests. 188## `<reply>` 189 190### `<data [nocheck="yes"] [sendzero="yes"] [base64="yes"] [hex="yes"]>` 191 192data to be sent to the client on its request and later verified that it 193arrived safely. Set `nocheck="yes"` to prevent the test script from verifying 194the arrival of this data. 195 196If the data contains `swsclose` anywhere within the start and end tag, and 197this is a HTTP test, then the connection will be closed by the server after 198this response is sent. If not, the connection will be kept persistent. 199 200If the data contains `swsbounce` anywhere within the start and end tag, the 201HTTP server will detect if this is a second request using the same test and 202part number and will then increase the part number with one. This is useful 203for auth tests and similar. 204 205`sendzero=yes` means that the (FTP) server will "send" the data even if the 206size is zero bytes. Used to verify curl's behavior on zero bytes transfers. 207 208`base64=yes` means that the data provided in the test-file is a chunk of data 209encoded with base64. It is the only way a test case can contain binary 210data. (This attribute can in fact be used on any section, but it doesn't make 211much sense for other sections than "data"). 212 213`hex=yes` means that the data is a sequence of hex pairs. It will get decoded 214and used as "raw" data. 215 216For FTP file listings, the `<data>` section will be used *only* if you make 217sure that there has been a CWD done first to a directory named `test-[num]` 218where [num] is the test case number. Otherwise the ftp server can't know from 219which test file to load the list content. 220 221### `<dataNUM>` 222 223Send back this contents instead of the <data> one. The num is set by: 224 225 - The test number in the request line is >10000 and this is the remainder 226 of [test case number]%10000. 227 - The request was HTTP and included digest details, which adds 1000 to NUM 228 - If a HTTP request is NTLM type-1, it adds 1001 to num 229 - If a HTTP request is NTLM type-3, it adds 1002 to num 230 - If a HTTP request is Basic and num is already >=1000, it adds 1 to num 231 - If a HTTP request is Negotiate, num gets incremented by one for each 232 request with Negotiate authorization header on the same test case. 233 234Dynamically changing num in this way allows the test harness to be used to 235test authentication negotiation where several different requests must be sent 236to complete a transfer. The response to each request is found in its own data 237section. Validating the entire negotiation sequence can be done by specifying 238a datacheck section. 239 240### `<connect>` 241The connect section is used instead of the 'data' for all CONNECT 242requests. The remainder of the rules for the data section then apply but with 243a connect prefix. 244 245### `<datacheck [mode="text"] [nonewline="yes"]>` 246if the data is sent but this is what should be checked afterwards. If 247`nonewline=yes` is set, runtests will cut off the trailing newline from the 248data before comparing with the one actually received by the client. 249 250Use the `mode="text"` attribute if the output is in text mode on platforms 251that have a text/binary difference. 252 253### `<datacheckNUM [nonewline="yes"] [mode="text"]>` 254The contents of numbered datacheck sections are appended to the non-numbered 255one. 256 257### `<size>` 258number to return on a ftp SIZE command (set to -1 to make this command fail) 259 260### `<mdtm>` 261what to send back if the client sends a (FTP) MDTM command, set to -1 to 262have it return that the file doesn't exist 263 264### `<postcmd>` 265special purpose server-command to control its behavior *after* the 266reply is sent 267For HTTP/HTTPS, these are supported: 268 269`wait [secs]` - Pause for the given time 270 271### `<servercmd>` 272Special-commands for the server. 273 274The first line of this file will always be set to `Testnum [number]` by the 275test script, to allow servers to read that to know what test the client is 276about to issue. 277 278#### For FTP/SMTP/POP/IMAP 279 280- `REPLY [command] [return value] [response string]` - Changes how the server 281 responds to the [command]. [response string] is evaluated as a perl string, 282 so it can contain embedded \r\n, for example. There's a special [command] 283 named "welcome" (without quotes) which is the string sent immediately on 284 connect as a welcome. 285- `REPLYLF` (like above but sends the response terminated with LF-only and not 286 CRLF) 287- `COUNT [command] [num]` - Do the `REPLY` change for `[command]` only `[num]` 288 times and then go back to the built-in approach 289- `DELAY [command] [secs]` - Delay responding to this command for the given 290 time 291- `RETRWEIRDO` - Enable the "weirdo" RETR case when multiple response lines 292 appear at once when a file is transferred 293- `RETRNOSIZE` - Make sure the RETR response doesn't contain the size of the 294 file 295- `NOSAVE` - Don't actually save what is received 296- `SLOWDOWN` - Send FTP responses with 0.01 sec delay between each byte 297- `PASVBADIP` - makes PASV send back an illegal IP in its 227 response 298- `CAPA [capabilities]` - Enables support for and specifies a list of space 299 separated capabilities to return to the client for the IMAP `CAPABILITY`, 300 POP3 `CAPA` and SMTP `EHLO` commands 301- `AUTH [mechanisms]` - Enables support for SASL authentication and specifies 302 a list of space separated mechanisms for IMAP, POP3 and SMTP 303- `STOR [msg]` respond with this instead of default after `STOR` 304 305#### For HTTP/HTTPS 306 307- `auth_required` if this is set and a POST/PUT is made without auth, the 308 server will NOT wait for the full request body to get sent 309- `idle` - do nothing after receiving the request, just "sit idle" 310- `stream` - continuously send data to the client, never-ending 311- `writedelay: [secs]` delay this amount between reply packets 312- `skip: [num]` - instructs the server to ignore reading this many bytes from 313 a PUT or POST request 314- `rtp: part [num] channel [num] size [num]` - stream a fake RTP packet for 315 the given part on a chosen channel with the given payload size 316- `connection-monitor` - When used, this will log `[DISCONNECT]` to the 317 `server.input` log when the connection is disconnected. 318- `upgrade` - when an HTTP upgrade header is found, the server will upgrade to 319 http2 320- `swsclose` - instruct server to close connection after response 321- `no-expect` - don't read the request body if Expect: is present 322 323#### For TFTP 324`writedelay: [secs]` delay this amount between reply packets (each packet 325 being 512 bytes payload) 326 327## `<client>` 328 329### `<server>` 330What server(s) this test case requires/uses. Available servers: 331 332- `file` 333- `ftp-ipv6` 334- `ftp` 335- `ftps` 336- `gopher` 337- `gophers` 338- `http-ipv6` 339- `http-proxy` 340- `http-unix` 341- `http/2` 342- `http` 343- `https` 344- `httptls+srp-ipv6` 345- `httptls+srp` 346- `imap` 347- `mqtt` 348- `none` 349- `pop3` 350- `rtsp-ipv6` 351- `rtsp` 352- `scp` 353- `sftp` 354- `smtp` 355- `socks4` 356- `socks5` 357 358Give only one per line. This subsection is mandatory. 359 360### `<features>` 361A list of features that MUST be present in the client/library for this test to 362be able to run. If a required feature is not present then the test will be 363SKIPPED. 364 365Alternatively a feature can be prefixed with an exclamation mark to indicate a 366feature is NOT required. If the feature is present then the test will be 367SKIPPED. 368 369Features testable here are: 370 371- `alt-svc` 372- `c-ares` 373- `cookies` 374- `crypto` 375- `debug` 376- `DoH` 377- `getrlimit` 378- `GnuTLS` 379- `GSS-API` 380- `HSTS` 381- `HTTP-auth` 382- `http/2` 383- `hyper` 384- `idn` 385- `ipv6` 386- `Kerberos` 387- `large_file` 388- `ld_preload` 389- `libz` 390- `manual` 391- `Mime` 392- `netrc` 393- `NSS` 394- `NTLM` 395- `OpenSSL` 396- `parsedate` 397- `proxy` 398- `PSL` 399- `Schannel` 400- `sectransp` 401- `shuffle-dns` 402- `socks` 403- `SPNEGO` 404- `SSL` 405- `SSLpinning` 406- `SSPI` 407- `threaded-resolver` 408- `TLS-SRP` 409- `TrackMemory` 410- `typecheck` 411- `Unicode` 412- `unittest` 413- `unix-sockets` 414- `verbose-strings` 415- `wakeup` 416- `win32` 417 418as well as each protocol that curl supports. A protocol only needs to be 419specified if it is different from the server (useful when the server 420is `none`). 421 422### `<killserver>` 423Using the same syntax as in `<server>` but when mentioned here these servers 424are explicitly KILLED when this test case is completed. Only use this if there 425is no other alternatives. Using this of course requires subsequent tests to 426restart servers. 427 428### `<precheck>` 429A command line that if set gets run by the test script before the test. If an 430output is displayed by the command or if the return code is non-zero, the test 431will be skipped and the (single-line) output will be displayed as reason for 432not running the test. 433 434### `<postcheck>` 435A command line that if set gets run by the test script after the test. If 436the command exists with a non-zero status code, the test will be considered 437to have failed. 438 439### `<tool>` 440Name of tool to invoke instead of "curl". This tool must be built and exist 441either in the libtest/ directory (if the tool name starts with 'lib') or in 442the unit/ directory (if the tool name starts with 'unit'). 443 444### `<name>` 445Brief test case description, shown when the test runs. 446 447### `<setenv>` 448 variable1=contents1 449 variable2=contents2 450 451Set the given environment variables to the specified value before the actual 452command is run. They are cleared again after the command has been run. 453 454### `<command [option="no-output/no-include/force-output/binary-trace"] [timeout="secs"][delay="secs"][type="perl/shell"]>` 455Command line to run. 456 457Note that the URL that gets passed to the server actually controls what data 458that is returned. The last slash in the URL must be followed by a number. That 459number (N) will be used by the test-server to load test case N and return the 460data that is defined within the `<reply><data></data></reply>` section. 461 462If there's no test number found above, the HTTP test server will use the 463number following the last dot in the given hostname (made so that a CONNECT 464can still pass on test number) so that "foo.bar.123" gets treated as test case 465123. Alternatively, if an IPv6 address is provided to CONNECT, the last 466hexadecimal group in the address will be used as the test number! For example 467the address "[1234::ff]" would be treated as test case 255. 468 469Set `type="perl"` to write the test case as a perl script. It implies that 470there's no memory debugging and valgrind gets shut off for this test. 471 472Set `type="shell"` to write the test case as a shell script. It implies that 473there's no memory debugging and valgrind gets shut off for this test. 474 475Set `option="no-output"` to prevent the test script to slap on the `--output` 476argument that directs the output to a file. The `--output` is also not added 477if the verify/stdout section is used. 478 479Set `option="force-output"` to make use of `--output` even when the test is 480otherwise written to verify stdout. 481 482Set `option="no-include"` to prevent the test script to slap on the 483`--include` argument. 484 485Set `option="binary-trace"` to use `--trace` instead of `--trace-ascii` for 486tracing. Suitable for binary-oriented protocols such as MQTT. 487 488Set `timeout="secs"` to override default server logs advisor read lock 489timeout. This timeout is used by the test harness, once that the command has 490completed execution, to wait for the test server to write out server side log 491files and remove the lock that advised not to read them. The "secs" parameter 492is the not negative integer number of seconds for the timeout. This `timeout` 493attribute is documented for completeness sake, but is deep test harness stuff 494and only needed for very singular and specific test cases. Avoid using it. 495 496Set `delay="secs"` to introduce a time delay once that the command has 497completed execution and before the `<postcheck>` section runs. The "secs" 498parameter is the not negative integer number of seconds for the delay. This 499'delay' attribute is intended for very specific test cases, and normally not 500needed. 501 502### `<file name="log/filename" [nonewline="yes"]>` 503This creates the named file with this content before the test case is run, 504which is useful if the test case needs a file to act on. 505 506If 'nonewline="yes"` is used, the created file will have the final newline 507stripped off. 508 509### `<stdin [nonewline="yes"]>` 510Pass this given data on stdin to the tool. 511 512If 'nonewline' is set, we will cut off the trailing newline of this given data 513before comparing with the one actually received by the client 514 515## `<verify>` 516### `<errorcode>` 517numerical error code curl is supposed to return. Specify a list of accepted 518error codes by separating multiple numbers with comma. See test 237 for an 519example. 520 521### `<strip>` 522One regex per line that is removed from the protocol dumps before the 523comparison is made. This is very useful to remove dependencies on dynamically 524changing protocol data such as port numbers or user-agent strings. 525 526### `<strippart>` 527One perl op per line that operates on the protocol dump. This is pretty 528advanced. Example: `s/^EPRT .*/EPRT stripped/`. 529 530### `<protocol [nonewline="yes"][crlf="yes"]>` 531 532the protocol dump curl should transmit, if 'nonewline' is set, we will cut off 533the trailing newline of this given data before comparing with the one actually 534sent by the client The `<strip>` and `<strippart>` rules are applied before 535comparisons are made. 536 537### `<proxy [nonewline="yes"][crlf="yes"]>` 538 539The protocol dump curl should transmit to a HTTP proxy (when the http-proxy 540server is used), if 'nonewline' is set, we will cut off the trailing newline 541of this given data before comparing with the one actually sent by the client 542The `<strip>` and `<strippart>` rules are applied before comparisons are made. 543 544### `<stderr [mode="text"] [nonewline="yes"]>` 545This verifies that this data was passed to stderr. 546 547Use the mode="text" attribute if the output is in text mode on platforms that 548have a text/binary difference. 549 550If 'nonewline' is set, we will cut off the trailing newline of this given data 551before comparing with the one actually received by the client 552 553### `<stdout [mode="text"] [nonewline="yes"]>` 554This verifies that this data was passed to stdout. 555 556Use the mode="text" attribute if the output is in text mode on platforms that 557have a text/binary difference. 558 559If 'nonewline' is set, we will cut off the trailing newline of this given data 560before comparing with the one actually received by the client 561 562### `<file name="log/filename" [mode="text"]>` 563The file's contents must be identical to this after the test is complete. Use 564the mode="text" attribute if the output is in text mode on platforms that have 565a text/binary difference. 566 567### `<file1>` 5681 to 4 can be appended to 'file' to compare more files. 569 570### `<file2>` 571 572### `<file3>` 573 574### `<file4>` 575 576### `<stripfile>` 577One perl op per line that operates on the output file or stdout before being 578compared with what is stored in the test file. This is pretty 579advanced. Example: "s/^EPRT .*/EPRT stripped/" 580 581### `<stripfile1>` 5821 to 4 can be appended to 'stripfile' to strip the corresponding <fileN> 583content 584 585### `<stripfile2>` 586 587### `<stripfile3>` 588 589### `<stripfile4>` 590 591### `<upload>` 592the contents of the upload data curl should have sent 593 594### `<valgrind>` 595disable - disables the valgrind log check for this test 596