Tests: client_body_early_read directive. - #103
Conversation
062294f to
b6bb50b
Compare
b6bb50b to
4d25224
Compare
| plan(skip_all => 'no client_body_early_read support') | ||
| unless $t->has_version('1.31.4'); |
There was a problem hiding this comment.
spaces to tabs
or remove "support" to unwrap into a single line, or use $t->try_run()
also, let's drop a trailing dot in log summary
4daf606 to
18f9433
Compare
18f9433 to
33c136d
Compare
| server_name localhost; | ||
|
|
||
| client_max_body_size 256; | ||
| client_body_buffer_size 4k; |
There was a problem hiding this comment.
It seems that none of the checks depend on this directive value, the only checks regarding the buffer/file go to server 8083, which has its own client_body_buffer_size 16. If I remove it, tests are passed.
There was a problem hiding this comment.
Yes, this line is not needed. Good catch.
| listen 127.0.0.1:8081; | ||
| server_name localhost; | ||
|
|
||
| client_body_early_read $arg_on; |
There was a problem hiding this comment.
Here we check the complex val only, which is good, however, the directive itself employs a more extensive logic:
0if we want to disable it (falsy literal)- multiple arguments are possible => the rule acts as OR
There was a problem hiding this comment.
Added explicit tests for 0 and non-0 cases
| 'body at exact limit'); | ||
| like(http_post_body('/', '0123456789' x 2, 8082), qr/ 413 /, | ||
| 'server limit applies not location'); | ||
| like(http_post_body('/', '0123456789' x 100, 8083), qr/ 204 /, |
There was a problem hiding this comment.
what exactly are we trying to test here? If we remove client_max_body_size 0;, then this test will pass...
There was a problem hiding this comment.
Yes, the test name is misleading. Renamed. The goal of this test is to confirm that intensive memory allocation does not impact system functionality or stability.
| } | ||
| } | ||
|
|
||
| server { |
There was a problem hiding this comment.
I don't think this server is needed at all, since 8002 is perfectly sufficient. The only difference is the client_max_body_size 100 setting within the location block, but that gets ignored in early read mode anyway. In other words, the chunked body exceeds limit and chunked body within limit cases can be moved to 8002
|
|
||
| like(http_post_body('/', '0123456789', 8080), qr/body:0123456789/, | ||
| 'body via return'); | ||
| unlike(http_post_body('/', '0123456789', 8081), qr/body:0123456789/, |
There was a problem hiding this comment.
I'd try to avoid unlike tests, since they succeed on just about anything. I would do:
like(http_post_body('/', '0123456789', 8081), qr/body:$/, 'predicate false');| unlike(http_post_body('/', '0123456789', 8081), qr/body:0123456789/, | ||
| 'no early read - body not available'); | ||
| like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/, | ||
| 'ealy read - body available'); |
| 'no early read - body not available'); | ||
| like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/, | ||
| 'ealy read - body available'); | ||
| like(http_post_body('/proxy', '0123456789', 8080), |
There was a problem hiding this comment.
during feature discussion, we mentioned this directive isn't needed for proxy_pass, meaning you'll get the body in the content phase anyway. So, even if you remove the directive, this test (and friends) will still pass...
There was a problem hiding this comment.
This test is intended to ensure that no regressions have been introduced.
| qr/X-Body: 0123456789\x0d?$/ms, 'body via proxy'); | ||
| like(http_get('/'), qr/ 200 /, 'no body'); | ||
| like(http_post_body('/', '', 8080), qr/body:$/, 'empty body'); | ||
| like(http_post_body('/', '0123456789', 8080), qr/ 200 /, |
There was a problem hiding this comment.
This is the same test as body via return, but the regex is different, but body via return is only possible with 200 ok => can be removed
| like(http_post_body('/', '', 8080), qr/body:$/, 'empty body'); | ||
| like(http_post_body('/', '0123456789', 8080), qr/ 200 /, | ||
| 'body within limit'); | ||
| like(http_post_body('/', 'x' x 300, 8080), qr/ 413 /, |
There was a problem hiding this comment.
Duplicate of server limit applies not location. The location block L:51 does not have its own limit => the location value matches the server value.
There was a problem hiding this comment.
Updated tests to show directive inheritance.
| 'body within limit'); | ||
| like(http_post_body('/', 'x' x 300, 8080), qr/ 413 /, | ||
| 'body exceeds limit'); | ||
| like(http_post_body('/', 'x' x 256, 8080), qr/ 200 /, |
There was a problem hiding this comment.
I'd replace qr/ 200 / to qr/body:x{256}/.
| 'early read body reaches location'); | ||
| like(http_post_body('/rewrite', 'HELLO', 8080), qr/loc1:HELLO/, | ||
| 'early read body survives rewrite'); | ||
| like(http_post_body('/echo', 'TESTBODY', 8080), qr/echo:TESTBODY/, |
There was a problem hiding this comment.
looks like it is also redundant, since server 8085 inherits client_body_early_read 1 from http block and proxy_pass passes the body upstream in any case.
There was a problem hiding this comment.
Agree. No, this test isn't needed.
| like($r, qr/ 413 /, 'expect continue too large'); | ||
| unlike($r, qr/100 Continue/, 'expect continue too large - no 100'); |
There was a problem hiding this comment.
the same remark as for body exceeds limit, It looks like you need to send the request to a location with a limit higher than the server limit.
There was a problem hiding this comment.
No, it's intended to verify that no 100 status in the 413 response.
| like($r, qr/ 413 /, 'expect continue too large'); | ||
| unlike($r, qr/100 Continue/, 'expect continue too large - no 100'); | ||
|
|
||
| like(http_post_body('/loc1', 'HELLO', 8080), qr/loc1:HELLO/, |
There was a problem hiding this comment.
I don't quite see the fundamental difference compared to body via return tc
There was a problem hiding this comment.
Yes, me too. Removed.
f250d85 to
b6c8564
Compare
| server_name localhost; | ||
|
|
||
| client_max_body_size 256; | ||
| client_body_buffer_size 4k; |
There was a problem hiding this comment.
Yes, this line is not needed. Good catch.
| listen 127.0.0.1:8081; | ||
| server_name localhost; | ||
|
|
||
| client_body_early_read $arg_on; |
There was a problem hiding this comment.
Added explicit tests for 0 and non-0 cases
| } | ||
| } | ||
|
|
||
| server { |
| unlike(http_post_body('/', '0123456789', 8081), qr/body:0123456789/, | ||
| 'no early read - body not available'); | ||
| like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/, | ||
| 'ealy read - body available'); |
| 'no early read - body not available'); | ||
| like(http_post_body('/?on=1', '0123456789', 8081), qr/body:0123456789/, | ||
| 'ealy read - body available'); | ||
| like(http_post_body('/proxy', '0123456789', 8080), |
There was a problem hiding this comment.
This test is intended to ensure that no regressions have been introduced.
| 'body within limit'); | ||
| like(http_post_body('/', 'x' x 300, 8080), qr/ 413 /, | ||
| 'body exceeds limit'); | ||
| like(http_post_body('/', 'x' x 256, 8080), qr/ 200 /, |
| like($r, qr/ 413 /, 'expect continue too large'); | ||
| unlike($r, qr/100 Continue/, 'expect continue too large - no 100'); | ||
|
|
||
| like(http_post_body('/loc1', 'HELLO', 8080), qr/loc1:HELLO/, |
There was a problem hiding this comment.
Yes, me too. Removed.
| 'early read body reaches location'); | ||
| like(http_post_body('/rewrite', 'HELLO', 8080), qr/loc1:HELLO/, | ||
| 'early read body survives rewrite'); | ||
| like(http_post_body('/echo', 'TESTBODY', 8080), qr/echo:TESTBODY/, |
There was a problem hiding this comment.
Agree. No, this test isn't needed.
| 'body at exact limit'); | ||
| like(http_post_body('/', '0123456789' x 2, 8082), qr/ 413 /, | ||
| 'server limit applies not location'); | ||
| like(http_post_body('/', '0123456789' x 100, 8083), qr/ 204 /, |
There was a problem hiding this comment.
Yes, the test name is misleading. Renamed. The goal of this test is to confirm that intensive memory allocation does not impact system functionality or stability.
| like($r, qr/ 413 /, 'expect continue too large'); | ||
| unlike($r, qr/100 Continue/, 'expect continue too large - no 100'); |
There was a problem hiding this comment.
No, it's intended to verify that no 100 status in the 413 response.
Proposed changes
Added tests for the client_body_early_read directive introduced in PR: nginx/nginx#1641
Checklist
Before creating a PR, run through this checklist and mark each as complete:
README.mdand/orCHANGELOG.md).