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