Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[t] test that path routing works with HTTPS #965

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 70 additions & 17 deletions t/listen-https.t
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ VZ5Wr10wCgYIKoZIzj0EAwIDSAAwRQIhAPRkfbxowt0H7p5xZYpwoMKanUXz9eKQ
0sGkOw+TqqGXAiAMKJRqtjnCF2LIjGygHG6BlgjM4NgIMDHteZPEr4qEmw==
-----END CERTIFICATE-----



=== TEST 3: Listen on HTTPS with path-based routing enabled
Regression test. APIcast was crashing because path-based routing needs the http
method and the path. However, those are not available when trying to find the
Expand All @@ -138,36 +140,87 @@ This test checks that APIcast falls back to finding the service by host.
'APICAST_HTTPS_CERTIFICATE_KEY' => "$Test::Nginx::Util::ServRoot/html/server.key",
'APICAST_PATH_ROUTING' => "true",
)
--- configuration fixture=echo.json
--- configuration
{
"services": [
{
"id": 1,
"proxy": {
"policy_chain": [
{ "name": "apicast.policy.echo", "configuration": {"status": 202 } }
],
"proxy_rules": [
{
"http_method": "GET",
"pattern": "/two",
"metric_system_name": "hits",
"delta": 1
}
]
}
},
{
"id": 1234,
"proxy": {
"policy_chain": [
{ "name": "apicast.policy.echo", "configuration": {"status": 201 } }
],
"proxy_rules": [
{
"http_method": "GET",
"pattern": "/one",
"metric_system_name": "hits",
"delta": 1
}
]
}
}
]
}

--- test env
lua_ssl_trusted_certificate $TEST_NGINX_HTML_DIR/server.crt;
content_by_lua_block {
local sock = ngx.socket.tcp()
sock:settimeout(2000)

local ok, err = sock:connect(ngx.var.server_addr, ngx.var.apicast_port)
if not ok then
ngx.say("failed to connect: ", err)
return
end

ngx.say("connected: ", ok)

local sess, err = sock:sslhandshake(nil, "localhost", true)
if not sess then
ngx.say("failed to do SSL handshake: ", err)
return
local function request(path)
local sock = ngx.socket.tcp()
sock:settimeout(2000)

local ok, err = sock:connect(ngx.var.server_addr, ngx.var.apicast_port)
if not ok then
ngx.say("failed to connect: ", err)
return
end

ngx.say("connected: ", ok)

local sess, err = sock:sslhandshake(nil, "localhost", true)
if not sess then
ngx.say("failed to do SSL handshake: ", err)
return
end

ngx.say("ssl handshake: ", type(sess))
sock:send("GET " .. path .. " HTTP/1.1\r\nHost: localhost\r\n\r\n")
ngx.say(sock:receive())
end

ngx.say("ssl handshake: ", type(sess))
request('/one')
ngx.say()
request('/two')
}
--- response_body
connected: 1
ssl handshake: userdata
HTTP/1.1 201 Created

connected: 1
ssl handshake: userdata
HTTP/1.1 202 Accepted
--- error_code: 200
--- grep_error_log eval: qr/Falling back to routing by host/
--- grep_error_log_out
Falling back to routing by host
Falling back to routing by host
--- no_error_log
[error]
--- user_files
Expand Down