Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Apr 16, 2024
1 parent 64d891c commit a000d73
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions lualib/resty/kong/tls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if subsystem == "http" then
kong_lua_kong_ffi_set_upstream_ssl_verify = C.ngx_http_lua_kong_ffi_set_upstream_ssl_verify
kong_lua_kong_ffi_set_upstream_ssl_verify_depth = C.ngx_http_lua_kong_ffi_set_upstream_ssl_verify_depth
kong_lua_kong_ffi_get_socket_ssl = C.ngx_http_lua_kong_ffi_get_socket_ssl
ngx.log(ngx.ERR, "111!!!!!!!!!!!!!!!!!!!!!! " .. require('inspect')(kong_lua_kong_ffi_get_socket_ssl))--@@@@@@@@@@@@@@

elseif subsystem == 'stream' then
ffi.cdef([[
Expand Down
5 changes: 5 additions & 0 deletions src/ngx_http_lua_kong_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,27 @@ int
ngx_http_lua_kong_ffi_get_socket_ssl(ngx_http_lua_socket_tcp_upstream_t *u, void **ssl_conn)
{
#if (NGX_SSL)
ngx_log_error(NGX_LOG_EMERG, u->peer.connection->log, 0, "1@@@@@@@@@@@@@@@@@@");//@@@@@@@@@
ngx_connection_t *uc = u->peer.connection;

if (ssl_conn == NULL) {
return NGX_ABORT;
}
ngx_log_error(NGX_LOG_EMERG, u->peer.connection->log, 0, "2@@@@@@@@@@@@@@@@@@");//@@@@@@@@@

if (uc && (uc->ssl) &&
(uc->ssl->connection)) {

ngx_log_error(NGX_LOG_EMERG, u->peer.connection->log, 0, "3@@@@@@@@@@@@@@@@@@");//@@@@@@@@@
*ssl_conn = uc->ssl->connection;
return NGX_OK;
}

ngx_log_error(NGX_LOG_EMERG, u->peer.connection->log, 0, "4@@@@@@@@@@@@@@@@@@");//@@@@@@@@@
return NGX_ERROR;

#else
ngx_log_error(NGX_LOG_EMERG, u->peer.connection->log, 0, "5@@@@@@@@@@@@@@@@@@");//@@@@@@@@@
return NGX_ABORT;
#endif
}
Expand Down
33 changes: 33 additions & 0 deletions t/001-tls.t
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,36 @@ nil, connection is not TLS or TLS support for Nginx not enabled
[alert]
[warn]
[crit]
=== TEST 7: ssl.get_ssl_pointer
--- http_config
server {
listen unix:/tmp/nginx-c1.sock ssl;
server_name test.com;
ssl_certificate ../../cert/example.com.crt;
ssl_certificate_key ../../cert/example.com.key;
}
--- config
location /t {
content_by_lua_block {
local sock = ngx.socket.tcp()
assert(sock:connect("unix:/tmp/nginx-c1.sock"))
assert(sock:sslhandshake(nil, "test.com"))
local ssl = require "resty.kong.tls"
if ssl.get_ssl_pointer(sock) == nil then
print("cannot get socket")
else
print("ok")
end
}
}
--- request
GET /t
--- response_body
ok
--- no_error_log
[error]
[emerg]

0 comments on commit a000d73

Please sign in to comment.