|
1 | 1 | # vim:set ft= ts=4 sw=4 et fdm=marker: |
2 | 2 |
|
3 | 3 | use Test::Nginx::Socket::Lua; |
| 4 | +use Cwd qw(abs_path realpath); |
| 5 | +use File::Basename; |
4 | 6 |
|
5 | 7 | repeat_each(2); |
6 | 8 |
|
7 | | -plan tests => repeat_each() * 184; |
| 9 | +plan tests => repeat_each() * 198; |
8 | 10 |
|
9 | 11 | #$ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua'; |
| 12 | +$ENV{TEST_NGINX_HTML_DIR} ||= html_dir(); |
| 13 | +$ENV{TEST_NGINX_CERT_DIR} ||= dirname(realpath(abs_path(__FILE__))); |
10 | 14 |
|
11 | 15 | no_long_string(); |
12 | 16 |
|
@@ -1675,3 +1679,201 @@ grep me: b |
1675 | 1679 | "] |
1676 | 1680 | --- no_error_log |
1677 | 1681 | [error] |
| 1682 | +
|
| 1683 | +
|
| 1684 | +
|
| 1685 | +=== TEST 41: same chunk from different directives produces different closures |
| 1686 | +--- http_config |
| 1687 | + ssl_session_fetch_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1688 | +
|
| 1689 | + ssl_session_store_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1690 | +
|
| 1691 | + upstream backend { |
| 1692 | + server 0.0.0.1; |
| 1693 | + balancer_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1694 | + } |
| 1695 | +
|
| 1696 | + server { |
| 1697 | + server_name test.com; |
| 1698 | + listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; |
| 1699 | + ssl_certificate $TEST_NGINX_CERT_DIR/cert/test.crt; |
| 1700 | + ssl_certificate_key $TEST_NGINX_CERT_DIR/cert/test.key; |
| 1701 | + ssl_session_tickets off; |
| 1702 | +
|
| 1703 | + ssl_certificate_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1704 | +
|
| 1705 | + location /lua { |
| 1706 | + set_by_lua_block $res { ngx.log(ngx.INFO, "hello") } |
| 1707 | +
|
| 1708 | + rewrite_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1709 | +
|
| 1710 | + access_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1711 | +
|
| 1712 | + content_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1713 | +
|
| 1714 | + header_filter_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1715 | +
|
| 1716 | + body_filter_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1717 | +
|
| 1718 | + log_by_lua_block { ngx.log(ngx.INFO, "hello") } |
| 1719 | + } |
| 1720 | + } |
| 1721 | +--- config |
| 1722 | + lua_ssl_trusted_certificate $TEST_NGINX_CERT_DIR/cert/test.crt; |
| 1723 | +
|
| 1724 | + location = /proxy { |
| 1725 | + proxy_pass http://backend; |
| 1726 | + } |
| 1727 | +
|
| 1728 | + location = /t { |
| 1729 | + set $html_dir $TEST_NGINX_HTML_DIR; |
| 1730 | +
|
| 1731 | + content_by_lua_block { |
| 1732 | + ngx.location.capture("/proxy") |
| 1733 | +
|
| 1734 | + local sock = ngx.socket.tcp() |
| 1735 | + sock:settimeout(2000) |
| 1736 | +
|
| 1737 | + local ok, err = sock:connect("unix:" .. ngx.var.html_dir .. "/nginx.sock") |
| 1738 | + if not ok then |
| 1739 | + ngx.log(ngx.ERR, "failed to connect: ", err) |
| 1740 | + return |
| 1741 | + end |
| 1742 | +
|
| 1743 | + local sess, err = sock:sslhandshake(nil, "test.com", true) |
| 1744 | + if not sess then |
| 1745 | + ngx.log(ngx.ERR, "failed to do SSL handshake: ", err) |
| 1746 | + return |
| 1747 | + end |
| 1748 | + package.loaded.session = sess |
| 1749 | + sock:close() |
| 1750 | +
|
| 1751 | + local ok, err = sock:connect("unix:" .. ngx.var.html_dir .. "/nginx.sock") |
| 1752 | + if not ok then |
| 1753 | + ngx.log(ngx.ERR, "failed to connect: ", err) |
| 1754 | + return |
| 1755 | + end |
| 1756 | +
|
| 1757 | + local sess, err = sock:sslhandshake(package.loaded.session, "test.com", true) |
| 1758 | + if not sess then |
| 1759 | + ngx.log(ngx.ERR, "failed to do SSL handshake: ", err) |
| 1760 | + return |
| 1761 | + end |
| 1762 | +
|
| 1763 | + local req = "GET /lua HTTP/1.0\r\nHost: test.com\r\nConnection: close\r\n\r\n" |
| 1764 | + local bytes, err = sock:send(req) |
| 1765 | + if not bytes then |
| 1766 | + ngx.log(ngx.ERR, "failed to send http request: ", err) |
| 1767 | + return |
| 1768 | + end |
| 1769 | + } |
| 1770 | + } |
| 1771 | +--- request |
| 1772 | +GET /t |
| 1773 | +--- ignore_response_body |
| 1774 | +--- grep_error_log eval: qr/code cache .*/ |
| 1775 | +--- grep_error_log_out eval |
| 1776 | +[ |
| 1777 | +"code cache lookup (key='=content_by_lua(nginx.conf:120)nhli_56ca4388611109b6ecfdeada050c8024', ref=-1) |
| 1778 | +code cache miss (key='=content_by_lua(nginx.conf:120)nhli_56ca4388611109b6ecfdeada050c8024', ref=-1) |
| 1779 | +code cache lookup (key='balancer_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1780 | +code cache miss (key='balancer_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1781 | +code cache lookup (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1782 | +code cache miss (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1783 | +code cache lookup (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1784 | +code cache miss (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1785 | +code cache lookup (key='ssl_session_fetch_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1786 | +code cache miss (key='ssl_session_fetch_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1787 | +code cache lookup (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1788 | +code cache hit (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1789 | +code cache lookup (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1790 | +code cache hit (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1791 | +code cache lookup (key='set_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1792 | +code cache miss (key='set_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1793 | +code cache lookup (key='=rewrite_by_lua(nginx.conf:46)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1794 | +code cache miss (key='=rewrite_by_lua(nginx.conf:46)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1795 | +code cache lookup (key='=access_by_lua(nginx.conf:48)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1796 | +code cache miss (key='=access_by_lua(nginx.conf:48)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1797 | +code cache lookup (key='=content_by_lua(nginx.conf:50)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1798 | +code cache miss (key='=content_by_lua(nginx.conf:50)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1799 | +code cache lookup (key='header_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1800 | +code cache miss (key='header_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1801 | +code cache lookup (key='body_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1802 | +code cache miss (key='body_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1803 | +code cache lookup (key='=log_by_lua(nginx.conf:56)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1804 | +code cache miss (key='=log_by_lua(nginx.conf:56)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1805 | +", |
| 1806 | +"code cache lookup (key='=content_by_lua(nginx.conf:120)nhli_56ca4388611109b6ecfdeada050c8024', ref=-1) |
| 1807 | +code cache miss (key='=content_by_lua(nginx.conf:120)nhli_56ca4388611109b6ecfdeada050c8024', ref=-1) |
| 1808 | +code cache lookup (key='balancer_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1809 | +code cache miss (key='balancer_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1810 | +code cache lookup (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1811 | +code cache miss (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1812 | +code cache lookup (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1813 | +code cache miss (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1814 | +code cache lookup (key='ssl_session_fetch_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1815 | +code cache miss (key='ssl_session_fetch_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1816 | +code cache lookup (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1817 | +code cache hit (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1818 | +code cache lookup (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1819 | +code cache hit (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1820 | +code cache lookup (key='set_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1821 | +code cache miss (key='set_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1822 | +code cache lookup (key='=rewrite_by_lua(nginx.conf:46)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1823 | +code cache miss (key='=rewrite_by_lua(nginx.conf:46)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1824 | +code cache lookup (key='=access_by_lua(nginx.conf:48)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1825 | +code cache miss (key='=access_by_lua(nginx.conf:48)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1826 | +code cache lookup (key='=content_by_lua(nginx.conf:50)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1827 | +code cache miss (key='=content_by_lua(nginx.conf:50)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1828 | +code cache lookup (key='header_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1829 | +code cache miss (key='header_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1830 | +code cache lookup (key='body_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1831 | +code cache miss (key='body_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1832 | +code cache lookup (key='=log_by_lua(nginx.conf:56)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1833 | +code cache miss (key='=log_by_lua(nginx.conf:56)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=-1) |
| 1834 | +code cache lookup (key='=content_by_lua(nginx.conf:120)nhli_56ca4388611109b6ecfdeada050c8024', ref=1) |
| 1835 | +code cache hit (key='=content_by_lua(nginx.conf:120)nhli_56ca4388611109b6ecfdeada050c8024', ref=1) |
| 1836 | +code cache lookup (key='balancer_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=2) |
| 1837 | +code cache hit (key='balancer_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=2) |
| 1838 | +code cache lookup (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1839 | +code cache hit (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1840 | +code cache lookup (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1841 | +code cache hit (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1842 | +code cache lookup (key='ssl_session_fetch_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=5) |
| 1843 | +code cache hit (key='ssl_session_fetch_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=5) |
| 1844 | +code cache lookup (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1845 | +code cache hit (key='ssl_certificate_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=3) |
| 1846 | +code cache lookup (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1847 | +code cache hit (key='ssl_session_store_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=4) |
| 1848 | +code cache lookup (key='set_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=6) |
| 1849 | +code cache hit (key='set_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=6) |
| 1850 | +code cache lookup (key='=rewrite_by_lua(nginx.conf:46)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=7) |
| 1851 | +code cache hit (key='=rewrite_by_lua(nginx.conf:46)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=7) |
| 1852 | +code cache lookup (key='=access_by_lua(nginx.conf:48)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=8) |
| 1853 | +code cache hit (key='=access_by_lua(nginx.conf:48)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=8) |
| 1854 | +code cache lookup (key='=content_by_lua(nginx.conf:50)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=9) |
| 1855 | +code cache hit (key='=content_by_lua(nginx.conf:50)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=9) |
| 1856 | +code cache lookup (key='header_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=10) |
| 1857 | +code cache hit (key='header_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=10) |
| 1858 | +code cache lookup (key='body_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=11) |
| 1859 | +code cache hit (key='body_filter_by_luanhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=11) |
| 1860 | +code cache lookup (key='=log_by_lua(nginx.conf:56)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=12) |
| 1861 | +code cache hit (key='=log_by_lua(nginx.conf:56)nhli_8a9441d0a30531ba8bb34ab11c55cfc3', ref=12) |
| 1862 | +"] |
| 1863 | +--- error_log eval |
| 1864 | +[ |
| 1865 | +qr/balancer_by_lua:\d+: hello/, |
| 1866 | +qr/ssl_session_fetch_by_lua_block:\d+: hello/, |
| 1867 | +qr/ssl_certificate_by_lua:\d+: hello/, |
| 1868 | +qr/ssl_session_store_by_lua_block:\d+: hello/, |
| 1869 | +qr/set_by_lua:\d+: hello/, |
| 1870 | +qr/rewrite_by_lua\(nginx\.conf:\d+\):\d+: hello/, |
| 1871 | +qr/access_by_lua\(nginx\.conf:\d+\):\d+: hello/, |
| 1872 | +qr/content_by_lua\(nginx\.conf:\d+\):\d+: hello/, |
| 1873 | +qr/header_filter_by_lua:\d+: hello/, |
| 1874 | +qr/body_filter_by_lua:\d+: hello/, |
| 1875 | +qr/log_by_lua\(nginx\.conf:\d+\):\d+: hello/, |
| 1876 | +] |
| 1877 | +--- log_level: debug |
| 1878 | +--- no_error_log |
| 1879 | +[error] |
0 commit comments