@@ -9,7 +9,7 @@ use Cwd qw(cwd);
99
1010# repeat_each(2);
1111
12- plan tests => repeat_each() * (blocks() * 6 - 6 );
12+ plan tests => repeat_each() * (blocks() * 6 - 13 );
1313
1414my $ pwd = cwd();
1515
@@ -1685,3 +1685,206 @@ Upstream foo.com
16851685
16861686-- - no_error_log
16871687SSL reused session
1688+
1689+
1690+
1691+ === TEST 20 : SSL health check with certificate created with a different server name should work when ssl_verify is false
1692+ -- - http_config eval
1693+ " $::HttpConfig"
1694+ . q {
1695+ lua_ssl_trusted_certificate ../../ssl/foo_bar.crt;
1696+
1697+ upstream foo.com {
1698+ server 127.0.0.1:12355;
1699+ }
1700+
1701+ server {
1702+ listen 12355;
1703+ ssl on;
1704+ ssl_certificate ../../ssl/foo_bar.crt;
1705+ ssl_certificate_key ../../ssl/foo_bar.key;
1706+ location = /status {
1707+ return 200;
1708+ }
1709+ }
1710+
1711+ lua_shared_dict healthcheck 1m;
1712+ init_worker_by_lua_block {
1713+ ngx.shared.healthcheck:flush_all()
1714+ local hc = require "resty.upstream.healthcheck"
1715+ local ok, err = hc.spawn_checker{
1716+ shm = "healthcheck",
1717+ upstream = "foo.com",
1718+ type = "https",
1719+ ssl_verify = false,
1720+ ssl_reuse_session = true,
1721+ http_req = "GET /status HTTP/1.0\r\nHost: localhost\r\n\r\n",
1722+ interval = 100, -- 100ms
1723+ fall = 2,
1724+ valid_statuses = {200},
1725+ }
1726+ if not ok then
1727+ ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
1728+ return
1729+ end
1730+ }
1731+ }
1732+ -- - config
1733+ location = /t {
1734+ access_log off;
1735+ content_by_lua_block {
1736+ ngx. sleep (0.52 )
1737+
1738+ local hc = require " resty.upstream.healthcheck"
1739+ ngx. print (hc. status_page())
1740+ }
1741+ }
1742+ --- request
1743+ GET /t
1744+
1745+ -- - response_body
1746+ Upstream foo. com
1747+ Primary Peers
1748+ 127.0 . 0. 1: 12355 up
1749+ Backup Peers
1750+
1751+ -- - error_log
1752+ SSL reused session
1753+
1754+ -- - no_error_log
1755+ certificate host mismatch
1756+
1757+
1758+
1759+ === TEST 21 : SSL health check with certificate created with a different server name should fail when ssl_verify is true
1760+ -- - http_config eval
1761+ " $::HttpConfig"
1762+ . q {
1763+ lua_ssl_trusted_certificate ../../ssl/foo_bar.crt;
1764+
1765+ upstream foo.com {
1766+ server 127.0.0.1:12355;
1767+ }
1768+
1769+ server {
1770+ listen 12355;
1771+ ssl on;
1772+ ssl_certificate ../../ssl/foo_bar.crt;
1773+ ssl_certificate_key ../../ssl/foo_bar.key;
1774+ location = /status {
1775+ return 200;
1776+ }
1777+ }
1778+
1779+ lua_shared_dict healthcheck 1m;
1780+ init_worker_by_lua_block {
1781+ ngx.shared.healthcheck:flush_all()
1782+ local hc = require "resty.upstream.healthcheck"
1783+ local ok, err = hc.spawn_checker{
1784+ shm = "healthcheck",
1785+ upstream = "foo.com",
1786+ type = "https",
1787+ ssl_verify = true,
1788+ ssl_reuse_session = true,
1789+ http_req = "GET /status HTTP/1.0\r\nHost: localhost\r\n\r\n",
1790+ interval = 100, -- 100ms
1791+ fall = 2,
1792+ valid_statuses = {200},
1793+ }
1794+ if not ok then
1795+ ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
1796+ return
1797+ end
1798+ }
1799+ }
1800+ -- - config
1801+ location = /t {
1802+ access_log off;
1803+ content_by_lua_block {
1804+ ngx. sleep (0.52 )
1805+
1806+ local hc = require " resty.upstream.healthcheck"
1807+ ngx. print (hc. status_page())
1808+ }
1809+ }
1810+ --- request
1811+ GET /t
1812+
1813+ -- - response_body
1814+ Upstream foo. com
1815+ Primary Peers
1816+ 127.0 . 0. 1: 12355 DOWN
1817+ Backup Peers
1818+
1819+ -- - error_log
1820+ certificate host mismatch
1821+
1822+
1823+
1824+
1825+ === TEST 22 : SSL health check with certificate created with a different server name should work when ssl_verify is true and correct server name is given
1826+ -- - http_config eval
1827+ " $::HttpConfig"
1828+ . q {
1829+ lua_ssl_trusted_certificate ../../ssl/foo_bar.crt;
1830+
1831+ upstream foo.com {
1832+ server 127.0.0.1:12355;
1833+ }
1834+
1835+ server {
1836+ listen 12355;
1837+ ssl on;
1838+ ssl_certificate ../../ssl/foo_bar.crt;
1839+ ssl_certificate_key ../../ssl/foo_bar.key;
1840+ location = /status {
1841+ return 200;
1842+ }
1843+ }
1844+
1845+ lua_shared_dict healthcheck 1m;
1846+ init_worker_by_lua_block {
1847+ ngx.shared.healthcheck:flush_all()
1848+ local hc = require "resty.upstream.healthcheck"
1849+ local ok, err = hc.spawn_checker{
1850+ shm = "healthcheck",
1851+ upstream = "foo.com",
1852+ type = "https",
1853+ ssl_verify = true,
1854+ ssl_reuse_session = true,
1855+ ssl_server_name = "foo.bar",
1856+ http_req = "GET /status HTTP/1.0\r\nHost: localhost\r\n\r\n",
1857+ interval = 100, -- 100ms
1858+ fall = 2,
1859+ valid_statuses = {200},
1860+ }
1861+ if not ok then
1862+ ngx.log(ngx.ERR, "failed to spawn health checker: ", err)
1863+ return
1864+ end
1865+ }
1866+ }
1867+ -- - config
1868+ location = /t {
1869+ access_log off;
1870+ content_by_lua_block {
1871+ ngx. sleep (0.52 )
1872+
1873+ local hc = require " resty.upstream.healthcheck"
1874+ ngx. print (hc. status_page())
1875+ }
1876+ }
1877+ --- request
1878+ GET /t
1879+
1880+ -- - response_body
1881+ Upstream foo. com
1882+ Primary Peers
1883+ 127.0 . 0. 1: 12355 up
1884+ Backup Peers
1885+
1886+ -- - error_log
1887+ SSL reused session
1888+
1889+ -- - no_error_log
1890+ certificate host mismatch
0 commit comments