|
| 1 | +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: |
| 2 | + |
| 3 | +use strict; |
| 4 | +use lib '.'; |
| 5 | +use t::TestWasm; |
| 6 | + |
| 7 | +skip_valgrind(); |
| 8 | + |
| 9 | +plan tests => repeat_each() * (4 * 4 + 6 * 5); |
| 10 | + |
| 11 | +run_tests(); |
| 12 | + |
| 13 | +__DATA__ |
| 14 | +
|
| 15 | +=== TEST 1: proxy_wasm - get_property() gets Nginx $hostname variable |
| 16 | +--- wasm_modules: hostcalls |
| 17 | +--- load_nginx_modules: ngx_http_echo_module |
| 18 | +--- config |
| 19 | + location /t { |
| 20 | + proxy_wasm hostcalls 'test=/t/log/property name=ngx.hostname'; |
| 21 | + echo ok; |
| 22 | + } |
| 23 | +--- response_body |
| 24 | +ok |
| 25 | +--- error_log eval |
| 26 | +[ |
| 27 | + qr/\[info\] .*? ngx.hostname: [a-z0-9]+/, |
| 28 | +] |
| 29 | +--- no_error_log |
| 30 | +[error] |
| 31 | +
|
| 32 | +
|
| 33 | +
|
| 34 | +=== TEST 2: proxy_wasm - get_property() gets an Nginx $pid variable |
| 35 | +All get_property calls for Nginx variables return strings, so this |
| 36 | +should print the $pid as ASCII numbers. |
| 37 | +--- wasm_modules: hostcalls |
| 38 | +--- load_nginx_modules: ngx_http_echo_module |
| 39 | +--- config |
| 40 | + location /t { |
| 41 | + proxy_wasm hostcalls 'test=/t/log/property name=ngx.pid'; |
| 42 | + echo ok; |
| 43 | + } |
| 44 | +--- response_body |
| 45 | +ok |
| 46 | +--- error_log eval |
| 47 | +[ |
| 48 | + qr/\[info\] .*? ngx.pid: [0-9]+/, |
| 49 | +] |
| 50 | +--- no_error_log |
| 51 | +[error] |
| 52 | +
|
| 53 | +
|
| 54 | +
|
| 55 | +=== TEST 3: proxy_wasm - get_property() reports if an ngx.* property is not found |
| 56 | +--- wasm_modules: hostcalls |
| 57 | +--- load_nginx_modules: ngx_http_echo_module |
| 58 | +--- config |
| 59 | + location /t { |
| 60 | + proxy_wasm hostcalls 'test=/t/log/property name=ngx.nonexistent_property'; |
| 61 | + echo ok; |
| 62 | + } |
| 63 | +--- response_body |
| 64 | +ok |
| 65 | +--- error_log eval |
| 66 | +[ |
| 67 | + qr/\[info\] .*? property not found: ngx.nonexistent_property/, |
| 68 | +] |
| 69 | +--- no_error_log |
| 70 | +[error] |
| 71 | +
|
| 72 | +
|
| 73 | +
|
| 74 | +=== TEST 4: proxy_wasm - get_property() reports if a generic property is not found |
| 75 | +--- wasm_modules: hostcalls |
| 76 | +--- load_nginx_modules: ngx_http_echo_module |
| 77 | +--- config |
| 78 | + location /t { |
| 79 | + proxy_wasm hostcalls 'test=/t/log/property name=nonexistent_property'; |
| 80 | + echo ok; |
| 81 | + } |
| 82 | +--- response_body |
| 83 | +ok |
| 84 | +--- error_log eval |
| 85 | +[ |
| 86 | + qr/\[info\] .*? property not found: nonexistent_property/, |
| 87 | +] |
| 88 | +--- no_error_log |
| 89 | +[error] |
| 90 | +
|
| 91 | +
|
| 92 | +
|
| 93 | +=== TEST 5: proxy_wasm - get_property() works on on_request_headers |
| 94 | +--- wasm_modules: hostcalls |
| 95 | +--- load_nginx_modules: ngx_http_echo_module |
| 96 | +--- config |
| 97 | + location /t { |
| 98 | + proxy_wasm hostcalls 'on=request_headers test=/t/log/property name=ngx.hostname'; |
| 99 | + echo ok; |
| 100 | + } |
| 101 | +--- response_body |
| 102 | +ok |
| 103 | +--- error_log eval |
| 104 | +[ |
| 105 | + qr/\[info\] .*? \[hostcalls\] on_request_headers/, |
| 106 | + qr/\[info\] .*? ngx.hostname: [a-z0-9]+/, |
| 107 | +] |
| 108 | +--- no_error_log |
| 109 | +[error] |
| 110 | +
|
| 111 | +
|
| 112 | +
|
| 113 | +=== TEST 6: proxy_wasm - get_property() works on on_request_body |
| 114 | +--- wasm_modules: hostcalls |
| 115 | +--- load_nginx_modules: ngx_http_echo_module |
| 116 | +--- config |
| 117 | + location /t { |
| 118 | + proxy_wasm hostcalls 'on=request_body test=/t/log/property name=ngx.hostname'; |
| 119 | + echo ok; |
| 120 | + } |
| 121 | +--- request |
| 122 | +POST /t/echo/body |
| 123 | +ok |
| 124 | +--- response_body |
| 125 | +ok |
| 126 | +--- error_log eval |
| 127 | +[ |
| 128 | + qr/\[info\] .*? \[hostcalls\] on_request_body/, |
| 129 | + qr/\[info\] .*? ngx.hostname: [a-z0-9]+/, |
| 130 | +] |
| 131 | +--- no_error_log |
| 132 | +[error] |
| 133 | +
|
| 134 | +
|
| 135 | +
|
| 136 | +=== TEST 7: proxy_wasm - get_property() works on on_response_headers |
| 137 | +--- wasm_modules: hostcalls |
| 138 | +--- load_nginx_modules: ngx_http_echo_module |
| 139 | +--- config |
| 140 | + location /t { |
| 141 | + proxy_wasm hostcalls 'on=response_headers test=/t/log/property name=ngx.hostname'; |
| 142 | + echo ok; |
| 143 | + } |
| 144 | +--- response_body |
| 145 | +ok |
| 146 | +--- error_log eval |
| 147 | +[ |
| 148 | + qr/\[info\] .*? \[hostcalls\] on_response_headers/, |
| 149 | + qr/\[info\] .*? ngx.hostname: [a-z0-9]+/, |
| 150 | +] |
| 151 | +--- no_error_log |
| 152 | +[error] |
| 153 | +
|
| 154 | +
|
| 155 | +
|
| 156 | +=== TEST 8: proxy_wasm - get_property() works on on_response_body |
| 157 | +--- wasm_modules: hostcalls |
| 158 | +--- load_nginx_modules: ngx_http_echo_module |
| 159 | +--- config |
| 160 | + location /t { |
| 161 | + proxy_wasm hostcalls 'on=response_body test=/t/log/property name=ngx.hostname'; |
| 162 | + echo ok; |
| 163 | + } |
| 164 | +--- response_body |
| 165 | +ok |
| 166 | +--- error_log eval |
| 167 | +[ |
| 168 | + qr/\[info\] .*? \[hostcalls\] on_response_body/, |
| 169 | + qr/\[info\] .*? ngx.hostname: [a-z0-9]+/, |
| 170 | +] |
| 171 | +--- no_error_log |
| 172 | +[error] |
| 173 | +
|
| 174 | +
|
| 175 | +
|
| 176 | +=== TEST 9: proxy_wasm - get_property() works on on_log |
| 177 | +--- wasm_modules: hostcalls |
| 178 | +--- load_nginx_modules: ngx_http_echo_module |
| 179 | +--- config |
| 180 | + location /t { |
| 181 | + proxy_wasm hostcalls 'on=log test=/t/log/property name=ngx.hostname'; |
| 182 | + echo ok; |
| 183 | + } |
| 184 | +--- response_body |
| 185 | +ok |
| 186 | +--- error_log eval |
| 187 | +[ |
| 188 | + qr/\[info\] .*? \[hostcalls\] on_log/, |
| 189 | + qr/\[info\] .*? ngx.hostname: [a-z0-9]+/, |
| 190 | +] |
| 191 | +--- no_error_log |
| 192 | +[error] |
| 193 | +
|
| 194 | +
|
| 195 | +
|
| 196 | +=== TEST 10: proxy_wasm - get_property() for ngx.* does not work on on_tick |
| 197 | +on_tick runs on the root context, so it does not have access to ngx_http_* calls. |
| 198 | +--- wasm_modules: hostcalls |
| 199 | +--- load_nginx_modules: ngx_http_echo_module |
| 200 | +--- config |
| 201 | + location /t { |
| 202 | + proxy_wasm hostcalls 'tick_period=10 test=/t/log/property name=ngx.hostname'; |
| 203 | + echo_sleep 0.150; |
| 204 | + echo ok; |
| 205 | + } |
| 206 | +--- response_body |
| 207 | +ok |
| 208 | +--- error_log eval |
| 209 | +[ |
| 210 | + qr/\[info\] .*? \[hostcalls\] on_tick/, |
| 211 | + qr/\[info\] .*? property not found: ngx.hostname/, |
| 212 | +] |
| 213 | +--- no_error_log |
| 214 | +[error] |
0 commit comments