Skip to content

Commit

Permalink
Add unittest for chunked body
Browse files Browse the repository at this point in the history
  • Loading branch information
tkan145 committed Jun 26, 2023
1 parent f58329b commit c1cae29
Show file tree
Hide file tree
Showing 2 changed files with 642 additions and 1 deletion.
105 changes: 105 additions & 0 deletions t/apicast-policy-camel.t
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,108 @@ ETag: foobar
<<EOF
using proxy: http://127.0.0.1:$Test::Nginx::Util::PROXY_SSL_PORT,
EOF

=== TEST 5: chunked request using HTTPS proxy for backend.
--- ONLY
--- init eval
$Test::Nginx::Util::PROXY_SSL_PORT = Test::APIcast::get_random_port();
$Test::Nginx::Util::ENDPOINT_SSL_PORT = Test::APIcast::get_random_port();
--- configuration random_port env eval
<<EOF
{
"services": [
{
"backend_version": 1,
"proxy": {
"api_backend": "https://localhost:$Test::Nginx::Util::ENDPOINT_SSL_PORT",
"proxy_rules": [
{ "pattern": "/test", "http_method": "POST", "metric_system_name": "hits", "delta": 2 }
],
"policy_chain": [
{
"name": "apicast.policy.apicast"
},
{
"name": "apicast.policy.camel",
"configuration": {
"https_proxy": "http://127.0.0.1:$Test::Nginx::Util::PROXY_SSL_PORT"
}
}
]
}
}
]
}
EOF
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.exit(ngx.OK)
}
}
--- upstream eval
<<EOF
# Endpoint config
listen $Test::Nginx::Util::ENDPOINT_SSL_PORT ssl;

ssl_certificate $Test::Nginx::Util::ServRoot/html/server.crt;
ssl_certificate_key $Test::Nginx::Util::ServRoot/html/server.key;

server_name _ default_server;

location /test {
access_by_lua_block {
assert = require('luassert')
local content_length = ngx.req.get_headers()["Content-Length"]
local encoding = ngx.req.get_headers()["Transfer-Encoding"]

-- This is due to the proxy_pass
-- Perhaps we should refactor the test
assert.falsy(encoding)
assert.equal('12', content_length)

ngx.req.read_body()
local body = ngx.req.get_body_data()
assert.equal('hello, world', body)

ngx.header["Content-Length"] = 0
ngx.exit(200)
}
}
}
server {
# Proxy config
listen $Test::Nginx::Util::PROXY_SSL_PORT ssl;

ssl_certificate $Test::Nginx::Util::ServRoot/html/server.crt;
ssl_certificate_key $Test::Nginx::Util::ServRoot/html/server.key;


server_name _ default_server;

location ~ /.* {
proxy_http_version 1.1;
proxy_pass https://\$http_host;
}
EOF
--- raw_request eval
"POST /test?user_key=value HTTP/1.1\r
Host: localhost\r
Connection: close\r
User-Agent: Test::APIcast::Blackbox\r
ETag: foobar\r
Transfer-Encoding: chunked\r
\r
7\r
hello, \r
5\r
world\r
0\r
\r
"
--- error_code: 200
--- user_files fixture=tls.pl eval
--- error_log eval
<<EOF
using proxy: http://127.0.0.1:$Test::Nginx::Util::PROXY_SSL_PORT,
EOF
Loading

0 comments on commit c1cae29

Please sign in to comment.