|
| 1 | +# vim:set ft= ts=4 sw=4 et fdm=marker: |
| 2 | +use lib 'lib'; |
| 3 | +use Test::Nginx::Socket; |
| 4 | + |
| 5 | +#worker_connections(1014); |
| 6 | +#master_on(); |
| 7 | +#workers(2); |
| 8 | +#log_level('warn'); |
| 9 | + |
| 10 | +repeat_each(2); |
| 11 | +#repeat_each(1); |
| 12 | + |
| 13 | +plan tests => repeat_each() * (blocks() * 3 + 2); |
| 14 | + |
| 15 | +#no_diff(); |
| 16 | +#no_long_string(); |
| 17 | +run_tests(); |
| 18 | + |
| 19 | +__DATA__ |
| 20 | +
|
| 21 | +=== TEST 1: set_by_lua (if fails) |
| 22 | +--- config |
| 23 | + location /t { |
| 24 | + set $true $arg_a; |
| 25 | + if ($true) { |
| 26 | + set_by_lua $true 'return tonumber(ngx.var["true"]) + 1'; |
| 27 | + break; |
| 28 | + } |
| 29 | + set $true "empty"; |
| 30 | +
|
| 31 | + echo "[$true]"; |
| 32 | + } |
| 33 | +--- request |
| 34 | +GET /t |
| 35 | +--- response_body |
| 36 | +[empty] |
| 37 | +--- no_error_log |
| 38 | +[error] |
| 39 | +
|
| 40 | +
|
| 41 | +
|
| 42 | +=== TEST 2: set_by_lua (if true) |
| 43 | +--- config |
| 44 | + location /t { |
| 45 | + set $true $arg_a; |
| 46 | + if ($true) { |
| 47 | + set_by_lua $true 'return tonumber(ngx.var["true"]) + 1'; |
| 48 | + break; |
| 49 | + } |
| 50 | + set $true "blah"; |
| 51 | +
|
| 52 | + echo "[$true]"; |
| 53 | + } |
| 54 | +--- request |
| 55 | +GET /t?a=2 |
| 56 | +--- response_body |
| 57 | +[3] |
| 58 | +--- no_error_log |
| 59 | +[error] |
| 60 | +
|
| 61 | +
|
| 62 | +
|
| 63 | +=== TEST 3: content_by_lua inherited by location if |
| 64 | +--- config |
| 65 | + location /t { |
| 66 | + set $true 1; |
| 67 | + if ($true) { |
| 68 | + # nothing |
| 69 | + } |
| 70 | +
|
| 71 | + content_by_lua 'ngx.say("hello world")'; |
| 72 | + } |
| 73 | +--- request |
| 74 | +GET /t |
| 75 | +--- response_body |
| 76 | +hello world |
| 77 | +--- no_error_log |
| 78 | +[error] |
| 79 | +
|
| 80 | +
|
| 81 | +
|
| 82 | +=== TEST 4: rewrite_by_lua inherited by location if |
| 83 | +--- config |
| 84 | + location /t { |
| 85 | + set $true 1; |
| 86 | + if ($true) { |
| 87 | + # nothing |
| 88 | + } |
| 89 | +
|
| 90 | + rewrite_by_lua 'ngx.say("hello world") ngx.exit(200)'; |
| 91 | + } |
| 92 | +--- request |
| 93 | +GET /t |
| 94 | +--- response_body |
| 95 | +hello world |
| 96 | +--- no_error_log |
| 97 | +[error] |
| 98 | +
|
| 99 | +
|
| 100 | +
|
| 101 | +=== TEST 5: access_by_lua inherited by location if |
| 102 | +--- config |
| 103 | + location /t { |
| 104 | + set $true 1; |
| 105 | + if ($true) { |
| 106 | + # nothing |
| 107 | + } |
| 108 | +
|
| 109 | + access_by_lua 'ngx.say("hello world") ngx.exit(200)'; |
| 110 | + } |
| 111 | +--- request |
| 112 | +GET /t |
| 113 | +--- response_body |
| 114 | +hello world |
| 115 | +--- no_error_log |
| 116 | +[error] |
| 117 | +
|
| 118 | +
|
| 119 | +
|
| 120 | +=== TEST 6: log_by_lua inherited by location if |
| 121 | +--- config |
| 122 | + location /t { |
| 123 | + set $true 1; |
| 124 | + if ($true) { |
| 125 | + # nothing |
| 126 | + } |
| 127 | +
|
| 128 | + log_by_lua 'ngx.log(ngx.WARN, "from log by lua")'; |
| 129 | + echo hello world; |
| 130 | + } |
| 131 | +--- request |
| 132 | +GET /t |
| 133 | +--- response_body |
| 134 | +hello world |
| 135 | +--- no_error_log |
| 136 | +[error] |
| 137 | +--- error_log |
| 138 | +from log by lua |
| 139 | +
|
| 140 | +
|
| 141 | +
|
| 142 | +=== TEST 7: header_filter_by_lua inherited by location if |
| 143 | +--- config |
| 144 | + location /t { |
| 145 | + set $true 1; |
| 146 | + if ($true) { |
| 147 | + # nothing |
| 148 | + } |
| 149 | +
|
| 150 | + header_filter_by_lua 'ngx.header.Foo = "bah"'; |
| 151 | + echo hello world; |
| 152 | + } |
| 153 | +--- request |
| 154 | +GET /t |
| 155 | +--- response_body |
| 156 | +hello world |
| 157 | +--- response_headers |
| 158 | +Foo: bah |
| 159 | +--- no_error_log |
| 160 | +[error] |
| 161 | +
|
| 162 | +
|
| 163 | +
|
| 164 | +=== TEST 8: body_filter_by_lua inherited by location if |
| 165 | +--- config |
| 166 | + location /t { |
| 167 | + set $true 1; |
| 168 | + if ($true) { |
| 169 | + # nothing |
| 170 | + } |
| 171 | +
|
| 172 | + body_filter_by_lua 'ngx.arg[1] = string.upper(ngx.arg[1])'; |
| 173 | + echo hello world; |
| 174 | + } |
| 175 | +--- request |
| 176 | +GET /t |
| 177 | +--- response_body |
| 178 | +HELLO WORLD |
| 179 | +--- no_error_log |
| 180 | +[error] |
| 181 | +
|
| 182 | +
|
| 183 | +
|
| 184 | +=== TEST 9: if is evil for ngx_proxy |
| 185 | +This test case requires the following patch for the nginx core: |
| 186 | +http://mailman.nginx.org/pipermail/nginx-devel/2012-June/002374.html |
| 187 | +--- config |
| 188 | + location /proxy-pass-uri { |
| 189 | + proxy_pass http://127.0.0.1:1984/; |
| 190 | +
|
| 191 | + set $true 1; |
| 192 | +
|
| 193 | + if ($true) { |
| 194 | + # nothing |
| 195 | + } |
| 196 | + } |
| 197 | +--- request |
| 198 | +GET /proxy-pass-uri |
| 199 | +--- response_body_like: It works! |
| 200 | +--- no_error_log |
| 201 | +[error] |
| 202 | +
|
0 commit comments