summaryrefslogtreecommitdiffhomepage
path: root/src/test (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-06-24test/clone: Constify some local static variablesAndrew Clayton1-3/+3
These somehow got missed in my previous constification patches... Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2024-04-17Fixes: 64934e59f ("HTTP: Introduce quoted target marker in HTTP parsing")Zhidao HONG1-2/+2
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
2024-02-20Updated copyright notice.Andrei Zeliankou2-2/+2
2023-05-25Tests: fixed incorrect pointer assignment.Alejandro Colomar1-2/+2
If we don't update the pointer before copying the request body, then we get the behavior shown below. After this patch, "foo\n" is rightly appended at the end of the response body. Request: "GET / HTTP/1.1\r\nHost: _\nContent-Length: 4\n\nfoo\n" Response body: """ Hello world! foo est data: Method: GET Protocol: HTTP/1.1 Remote addr: 127.0.0.1 Local addr: 127.0.0.1 Target: / Path: / Fields: Host: _ Content-Length: 4 Body: """ Fixes: 1bb22d1e922c ("Unit application library.") Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
2022-11-04Removed the unsafe nxt_memcmp() wrapper for memcmp(3).Alejandro Colomar4-4/+4
The casts are unnecessary, since memcmp(3)'s arguments are 'void *'. It might have been necessary in the times of K&R, where 'void *' didn't exist. Nowadays, it's unnecessary, and _very_ unsafe, since casts can hide all classes of bugs by silencing most compiler warnings. The changes from nxt_memcmp() to memcmp(3) were scripted: $ find src/ -type f \ | grep '\.[ch]$' \ | xargs sed -i 's/nxt_memcmp/memcmp/' Reviewed-by: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
2022-10-28Fixed some function definitions.Andrew Clayton2-2/+2
Future releases of GCC will render function definitions like func() invalid by default. See the previous commit 09f88c9 ("Fixed main() prototypes in auto tests.") for details. Such functions should be defined like func(void) This is a good thing to do regardless of the upcoming GCC changes. Reviewed-by: Alejandro Colomar <alx@nginx.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2022-10-03Renamed a couple of members of nxt_unit_request_t.Andrew Clayton1-1/+1
This is a preparatory patch that renames the 'local' and 'local_length' members of the nxt_unit_request_t structure to 'local_addr' and 'local_addr_length' in preparation for the adding of 'local_port' and 'local_port_length' members. Suggested-by: Zhidao HONG <z.hong@f5.com> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2022-05-03Fixed #define style.Alejandro Colomar1-4/+2
We had a mix of styles for declaring function-like macros: Style A: #define \ foo() \ do { \ ... \ } while (0) Style B: #define foo() \ do { \ ... \ } while (0) We had a similar number of occurences of each style: $ grep -rnI '^\w*(.*\\' | wc -l 244 $ grep -rn 'define.*(.*)' | wc -l 239 (Those regexes aren't perfect, but a very decent approximation.) Real examples: $ find src -type f | xargs sed -n '/^nxt_double_is_zero/,/^$/p' nxt_double_is_zero(f) \ (fabs(f) <= FLT_EPSILON) $ find src -type f | xargs sed -n '/define nxt_http_field_set/,/^$/p' #define nxt_http_field_set(_field, _name, _value) \ do { \ (_field)->name_length = nxt_length(_name); \ (_field)->value_length = nxt_length(_value); \ (_field)->name = (u_char *) _name; \ (_field)->value = (u_char *) _value; \ } while (0) I'd like to standardize on a single style for them, and IMO, having the identifier in the same line as #define is a better option for the following reasons: - Programmers are used to `#define foo() ...` (readability). - One less line of code. - The program for finding them is really simple (see below). function grep_ngx_func() { if (($# != 1)); then >&2 echo "Usage: ${FUNCNAME[0]} <func>"; return 1; fi; find src -type f \ | grep '\.[ch]$' \ | xargs grep -l "$1" \ | sort \ | xargs pcregrep -Mn "(?s)^\$[\w\s*]+?^$1\(.*?^}"; find src -type f \ | grep '\.[ch]$' \ | xargs grep -l "$1" \ | sort \ | xargs pcregrep -Mn "(?s)define $1\(.*?^$" \ | sed -E '1s/^[^:]+:[0-9]+:/&\n\n/'; } $ grep_ngx_func Usage: grep_ngx_func <func> $ grep_ngx_func nxt_http_field_set src/nxt_http.h:98: #define nxt_http_field_set(_field, _name, _value) \ do { \ (_field)->name_length = nxt_length(_name); \ (_field)->value_length = nxt_length(_value); \ (_field)->name = (u_char *) _name; \ (_field)->value = (u_char *) _value; \ } while (0) $ grep_ngx_func nxt_sprintf src/nxt_sprintf.c:56: u_char * nxt_cdecl nxt_sprintf(u_char *buf, u_char *end, const char *fmt, ...) { u_char *p; va_list args; va_start(args, fmt); p = nxt_vsprintf(buf, end, fmt, args); va_end(args); return p; } ................ Scripted change: ................ $ find src -type f \ | grep '\.[ch]$' \ | xargs sed -i '/define *\\$/{N;s/ *\\\n/ /;s/ //}'
2021-10-28Moving request limit control to libunit.Max Romanov1-1/+1
Introducting application graceful stop. For now only used when application process reach request limit value. This closes #585 issue on GitHub.
2021-10-26Custom implementation of Base64 decoding function.Valentin Bartenev3-0/+103
Compared to the previous implementation based on OpenSSL, the new implementation has these advantages: 1. Strict and reliable detection of invalid strings, including strings with less than 4 bytes of garbage at the end; 2. Allows to use Base64 strings without '=' padding.
2020-11-18Libunit: improving logging consistency.Max Romanov2-6/+4
Debug logging depends on macros defined in nxt_auto_config.h.
2020-11-17HTTP parser: allowed more characters in header field names.Valentin Bartenev1-7/+31
Previously, all requests that contained in header field names characters other than alphanumeric, or "-", or "_" were rejected with a 400 "Bad Request" error response. Now, the parser allows the same set of characters as specified in RFC 7230, including: "!", "#", "$", "%", "&", "'", "*", "+", ".", "^", "`", "|", and "~". Header field names that contain only these characters are considered valid. Also, there's a new option introduced: "discard_unsafe_fields". It accepts boolean value and it is set to "true" by default. When this option is "true", all header field names that contain characters in valid range, but other than alphanumeric or "-" are skipped during parsing. When the option is "false", these header fields aren't skipped. Requests with non-valid characters in header field names according to RFC 7230 are rejected regardless of "discard_unsafe_fields" setting. This closes #422 issue on GitHub.
2020-11-01Fixed building test app without debug.Valentin Bartenev1-2/+8
Compilers complained about unused variables after 37e2a3ea1bf1.
2020-10-28Added threading to the libunit test app.Max Romanov1-22/+108
2020-08-13Basic variables support.Valentin Bartenev1-16/+2
2020-08-11Circular queues implementations and a test.Max Romanov1-0/+578
- naive circular queue, described in the article "A Scalable, Portable, and Memory-Efficient Lock-Free FIFO Queue" by Ruslan Nikolaev: https://drops.dagstuhl.de/opus/volltexte/2019/11335/pdf/LIPIcs-DISC-2019-28.pdf - circular queue, proposed by Valentin Bartenev in the "Unit router application IPC" design draft
2020-04-16Using malloc/free for the http fields hash.Max Romanov1-12/+5
This is required due to lack of a graceful shutdown: there is a small gap between the runtime's memory pool release and router process's exit. Thus, a worker thread may start processing a request between these two operations, which may result in an http fields hash access and subsequent crash. To simplify issue reproduction, it makes sense to add a 2 sec sleep before exit() in nxt_runtime_exit().
2020-03-30Configuration: support for rational numbers.Valentin Bartenev1-3/+3
2019-12-06Isolation: allowed the use of credentials with unpriv userns.Tiago Natel3-0/+608
The setuid/setgid syscalls requires root capabilities but if the kernel supports unprivileged user namespace then the child process has the full set of capabilities in the new namespace, then we can allow setting "user" and "group" in such cases (this is a common security use case). Tests were added to ensure user gets meaningful error messages for uid/gid mapping misconfigurations.
2019-11-11Fixing libunit 'off by 2' issue in library.Max Romanov1-4/+4
Name and value in each header are 0-terminated, so additional 2 bytes should be allocated for them. There were several attempts to add these 2 bytes to headers in language modules, but some modules weren't updated. Also, adding these 2 bytes is specific to the implementation which may be changed later, so extending this mechanics to modules may cause errors.
2019-09-30HTTP parser: removed unused "exten" field.Valentin Bartenev1-22/+0
This field was intended for MIME type lookup by file extension when serving static files, but this use case is too narrow; only a fraction of requests targets static content, and the URI presumably isn't rewritten. Moreover, current implementation uses the entire filename for MIME type lookup if the file has no extension. Instead of extracting filenames and extensions when parsing requests, it's easier to obtain them right before serving static content; this behavior is already implemented. Thus, we can drop excessive logic from parser.
2019-09-17HTTP parser: fixed parsing of target after literal space character.Valentin Bartenev1-1/+14
In theory, all space characters in request target must be encoded; however, some clients may violate the specification. For the sake of interoperability, Unit supports unencoded space characters. Previously, if there was a space character before the extension or arguments parts, those parts weren't recognized. Also, quoted symbols and complex target weren't detected after a space character.
2019-09-16HTTP parser: removed unused "plus_in_target" flag.Valentin Bartenev1-20/+10
2019-09-16HTTP parser: removed unused "exten_start" and "args_start" fields.Valentin Bartenev1-16/+8
2019-08-20Introducing websocket support in router and libunit.Max Romanov2-0/+453
2018-11-15Fixed lvlhsh test on 64-bit big-endian systems.Valentin Bartenev1-1/+1
The nxt_murmur_hash2() generated 4-byte hash that was stored in uintptr_t, which was 8 bytes long on 64-bit systems. At each iteration, it took the previous key and hashed it again. The problem was that it took only the first 4 bytes of the key, and these 4 bytes were always zero on 64-bit big-endian system. That resulted in equal keys at each iteration. The bug was discovered on IBM/S390x.
2018-08-06Unit application library.Max Romanov1-0/+191
Library now used in all language modules. Old 'nxt_app_*' code removed. See src/test/nxt_unit_app_test.c for usage sample.
2018-07-03HTTP parser: relaxed checking of fields values.Valentin Bartenev1-1/+1
Allowing characters up to 0xFF doesn't conflict with RFC 7230. Particularly, this make it possible to pass unencoded UTF-8 data through HTTP headers, which can be useful.
2018-06-25Introduced nxt_length() macro.Valentin Bartenev1-2/+2
2018-04-05Style.Valentin Bartenev1-1/+1
2018-04-04Style: capitalized letters in hexadecimal literals.Valentin Bartenev3-25/+25
2018-03-29nxt_lvlhsh_each() refactoring and nxt_lvlhsh_each_init().Igor Sysoev1-2/+1
2018-03-29nxt_lvlhsh_retrieve().Igor Sysoev1-0/+37
2018-03-29nxt_lvlhsh_peek().Igor Sysoev1-2/+14
2018-03-15HTTP parser: allowing tabs in field values as per RFC 7230.Valentin Bartenev1-0/+24
2018-03-15HTTP parser: restricting allowed characters in fields values.Valentin Bartenev1-0/+18
According to RFC 7230 only printable 7-bit ASCII characters are allowed in field values.
2018-03-15HTTP parser: fixed parsing of field values ending with space.Valentin Bartenev1-0/+6
This closes #82 issue on GitHub.
2018-01-24Fixed formatting in nxt_sprintf() and logging.Sergey Kandaurov1-1/+1
2018-01-24Using size_t for the field width type of the "%*s" specifier.Sergey Kandaurov1-2/+3
2018-01-15Checking for major HTTP version.Valentin Bartenev1-0/+5
2018-01-15HTTP parser: improved error reporting.Valentin Bartenev1-11/+11
2018-01-09HTTP parser: allowing underscore in header field names.Valentin Bartenev1-1/+1
2017-12-25HTTP parser: reworked header fields handling.Valentin Bartenev1-28/+89
2017-11-21Tests: move existing tests to "src" folder.Andrey Zelenkov18-0/+3236