@@ -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,205 @@ 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+ ===  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 
1825+ -- - http_config eval
1826+ " $::HttpConfig" 
1827+ .  q { 
1828+ lua_ssl_trusted_certificate ../../ssl/foo_bar.crt; 
1829+ 
1830+ upstream foo.com { 
1831+     server 127.0.0.1:12355; 
1832+ } 
1833+ 
1834+ server { 
1835+     listen 12355; 
1836+     ssl on; 
1837+     ssl_certificate ../../ssl/foo_bar.crt; 
1838+     ssl_certificate_key ../../ssl/foo_bar.key; 
1839+     location = /status { 
1840+         return 200; 
1841+     } 
1842+ } 
1843+ 
1844+ lua_shared_dict healthcheck 1m; 
1845+ init_worker_by_lua_block { 
1846+     ngx.shared.healthcheck:flush_all() 
1847+     local hc = require "resty.upstream.healthcheck" 
1848+     local ok, err = hc.spawn_checker{ 
1849+         shm = "healthcheck", 
1850+         upstream = "foo.com", 
1851+         type = "https", 
1852+         ssl_verify = true, 
1853+         ssl_reuse_session = true, 
1854+         ssl_server_name = "foo.bar", 
1855+         http_req = "GET /status HTTP/1.0\r\nHost: localhost\r\n\r\n", 
1856+         interval = 100,  -- 100ms 
1857+         fall = 2, 
1858+         valid_statuses = {200}, 
1859+     } 
1860+     if not ok then 
1861+         ngx.log(ngx.ERR, "failed to spawn health checker: ", err) 
1862+         return 
1863+     end 
1864+ } 
1865+ } 
1866+ -- - config
1867+     location =  /t {   
1868+         access_log off; 
1869+         content_by_lua_block { 
1870+             ngx. sleep (0.52 ) 
1871+ 
1872+             local hc =  require  " resty.upstream.healthcheck"  
1873+             ngx. print (hc. status_page()) 
1874+         } 
1875+     }  
1876+ --- request 
1877+ GET  /t
1878+ 
1879+ -- - response_body
1880+ Upstream foo. com 
1881+     Primary Peers 
1882+         127.0 . 0. 1: 12355  up 
1883+     Backup Peers 
1884+ 
1885+ -- - error_log
1886+ SSL reused session 
1887+ 
1888+ -- - no_error_log
1889+ certificate host mismatch 
0 commit comments