-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
|
||
use Test::Nginx::Socket::Lua::Stream; | ||
use Test::Nginx::Socket::Lua; | ||
|
||
#worker_connections(1014); | ||
#master_process_enabled(1); | ||
|
||
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir(); | ||
|
||
repeat_each(2); | ||
|
||
plan tests => repeat_each() * (blocks() * 4); | ||
|
||
#no_diff(); | ||
#no_long_string(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 4: sending client certificate using resty.kong.tls.set_upstream_cert_and_key in access phase | ||
--- http_config | ||
lua_package_path "../lua-resty-core/lib/?.lua;lualib/?.lua;;"; | ||
server { | ||
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; | ||
server_name example.com; | ||
ssl_certificate ../../cert/example.com.crt; | ||
ssl_certificate_key ../../cert/example.com.key; | ||
ssl_client_certificate ../../cert/ca.crt; | ||
ssl_verify_client on; | ||
server_tokens off; | ||
location /foo { | ||
default_type 'text/plain'; | ||
more_clear_headers Date; | ||
echo 'it works!'; | ||
} | ||
} | ||
--- stream_server_config | ||
proxy_ssl_trusted_certificate ../../cert/ca.crt; | ||
proxy_ssl_verify on; | ||
proxy_ssl_name example.com; | ||
proxy_ssl on; | ||
preread_by_lua_block { | ||
local tls = require("resty.kong.tls") | ||
local ssl = require("ngx.ssl") | ||
local f = assert(io.open("t/cert/client_example.com.crt")) | ||
local cert_data = f:read("*a") | ||
f:close() | ||
local chain = assert(ssl.parse_pem_cert(cert_data)) | ||
f = assert(io.open("t/cert/client_example.com.key")) | ||
local key_data = f:read("*a") | ||
f:close() | ||
local key = assert(ssl.parse_pem_priv_key(key_data)) | ||
local ok, err = tls.set_upstream_cert_and_key(chain, key) | ||
if not ok then | ||
ngx.say("set_upstream_cert_and_key failed: ", err) | ||
end | ||
} | ||
proxy_pass unix:$TEST_NGINX_HTML_DIR/nginx.sock; | ||
proxy_ssl_session_reuse off; | ||
--- stream_request eval | ||
"GET /foo HTTP/1.0\r\nHost: example.com\r\n\r\n" | ||
--- stream_response_like | ||
it works! | ||
--- error_log | ||
verify:1, error:0, depth:0, subject:"/C=US/ST=California/O=Kong Testing/[email protected]", issuer:"/C=US/ST=California/O=Kong Testing/CN=Kong Testing Intermidiate CA" | ||