|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +use t::APISIX 'no_plan'; |
| 19 | + |
| 20 | +repeat_each(1); |
| 21 | +no_long_string(); |
| 22 | +no_root_location(); |
| 23 | + |
| 24 | +add_block_preprocessor(sub { |
| 25 | + my ($block) = @_; |
| 26 | + |
| 27 | + if (!defined $block->yaml_config) { |
| 28 | + $block->set_value("yaml_config", <<'_EOC_'); |
| 29 | +apisix: |
| 30 | + admin_key: |
| 31 | + - name: admin |
| 32 | + key: edd1c9f034335f136f87ad84b625c8f1 |
| 33 | + role: admin |
| 34 | +deployment: |
| 35 | + role: data_plane |
| 36 | + role_data_plane: |
| 37 | + config_provider: yaml |
| 38 | +_EOC_ |
| 39 | + } |
| 40 | + |
| 41 | + $block->set_value("stream_enable", 1); |
| 42 | +}); |
| 43 | + |
| 44 | +run_tests(); |
| 45 | + |
| 46 | +__DATA__ |
| 47 | +
|
| 48 | +=== TEST 1: missing plugin on route blocks route matching |
| 49 | +--- extra_yaml_config |
| 50 | +plugins: |
| 51 | + - redirect |
| 52 | +--- apisix_yaml |
| 53 | +routes: |
| 54 | + - id: 1 |
| 55 | + uri: /hello |
| 56 | + plugins: |
| 57 | + openid-connect: |
| 58 | + client_id: x |
| 59 | + client_secret: x |
| 60 | + discovery: x |
| 61 | + scope: openid email |
| 62 | + bearer_only: false |
| 63 | + realm: x |
| 64 | + upstream: |
| 65 | + type: roundrobin |
| 66 | + nodes: |
| 67 | + "127.0.0.1:1980": 1 |
| 68 | +#END |
| 69 | +--- request |
| 70 | +GET /hello |
| 71 | +--- error_code: 404 |
| 72 | +--- error_log |
| 73 | +unknown plugin [openid-connect] |
| 74 | +
|
| 75 | +
|
| 76 | +
|
| 77 | +=== TEST 2: missing plugin on stream route blocks stream matching |
| 78 | +--- extra_yaml_config |
| 79 | +stream_plugins: |
| 80 | + - ip-restriction |
| 81 | +--- apisix_yaml |
| 82 | +stream_routes: |
| 83 | + - id: 1 |
| 84 | + server_port: 1985 |
| 85 | + plugins: |
| 86 | + syslog: |
| 87 | + host: 127.0.0.1 |
| 88 | + port: 514 |
| 89 | + upstream: |
| 90 | + type: roundrobin |
| 91 | + nodes: |
| 92 | + "127.0.0.1:1995": 1 |
| 93 | +#END |
| 94 | +--- config |
| 95 | +location /stream_request { |
| 96 | + content_by_lua_block { |
| 97 | + ngx.sleep(1) -- wait for the stream route to take effect |
| 98 | +
|
| 99 | + local tcp_request = function(host, port) |
| 100 | + local sock, err = ngx.socket.tcp() |
| 101 | + assert(sock, err) |
| 102 | +
|
| 103 | + local ok, err = sock:connect(host, port) |
| 104 | + if not ok then |
| 105 | + ngx.say("connect to stream server error: ", err) |
| 106 | + return |
| 107 | + end |
| 108 | + local bytes, err = sock:send("mmm") |
| 109 | + if not bytes then |
| 110 | + ngx.say("send stream request error: ", err) |
| 111 | + return |
| 112 | + end |
| 113 | +
|
| 114 | + local data, err = sock:receive("*a") |
| 115 | + if not data then |
| 116 | + sock:close() |
| 117 | + ngx.say("receive stream response error: ", err) |
| 118 | + return |
| 119 | + end |
| 120 | + sock:close() |
| 121 | + ngx.print(data) |
| 122 | + end |
| 123 | +
|
| 124 | + tcp_request("127.0.0.1", 1985) |
| 125 | + } |
| 126 | +} |
| 127 | +--- request |
| 128 | +GET /stream_request |
| 129 | +--- response_body |
| 130 | +receive stream response error: connection reset by peer |
| 131 | +--- error_log |
| 132 | +unknown plugin [syslog] |
| 133 | +
|
| 134 | +
|
| 135 | +
|
| 136 | +=== TEST 3: missing plugin on route blocks route matching (json) |
| 137 | +--- yaml_config |
| 138 | +apisix: |
| 139 | + admin_key: |
| 140 | + - name: admin |
| 141 | + key: edd1c9f034335f136f87ad84b625c8f1 |
| 142 | + role: admin |
| 143 | +deployment: |
| 144 | + role: data_plane |
| 145 | + role_data_plane: |
| 146 | + config_provider: json |
| 147 | +--- extra_yaml_config |
| 148 | +plugins: |
| 149 | + - redirect |
| 150 | +--- apisix_json |
| 151 | +{ |
| 152 | + "routes": [ |
| 153 | + { |
| 154 | + "id": "1", |
| 155 | + "uri": "/hello", |
| 156 | + "plugins": { |
| 157 | + "openid-connect": { |
| 158 | + "client_id": "x", |
| 159 | + "client_secret": "x", |
| 160 | + "discovery": "x", |
| 161 | + "scope": "openid email", |
| 162 | + "bearer_only": false, |
| 163 | + "realm": "x" |
| 164 | + } |
| 165 | + }, |
| 166 | + "upstream": { |
| 167 | + "type": "roundrobin", |
| 168 | + "nodes": { |
| 169 | + "127.0.0.1:1980": 1 |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + ] |
| 174 | +} |
| 175 | +--- request |
| 176 | +GET /hello |
| 177 | +--- error_code: 404 |
| 178 | +--- error_log |
| 179 | +unknown plugin [openid-connect] |
| 180 | +
|
| 181 | +
|
| 182 | +
|
| 183 | +=== TEST 4: missing plugin on stream route blocks stream matching (json) |
| 184 | +--- yaml_config |
| 185 | +apisix: |
| 186 | + admin_key: |
| 187 | + - name: admin |
| 188 | + key: edd1c9f034335f136f87ad84b625c8f1 |
| 189 | + role: admin |
| 190 | +deployment: |
| 191 | + role: data_plane |
| 192 | + role_data_plane: |
| 193 | + config_provider: json |
| 194 | +--- extra_yaml_config |
| 195 | +stream_plugins: |
| 196 | + - ip-restriction |
| 197 | +--- apisix_json |
| 198 | +{ |
| 199 | + "stream_routes": [ |
| 200 | + { |
| 201 | + "id": "1", |
| 202 | + "server_port": 1985, |
| 203 | + "plugins": { |
| 204 | + "syslog": { |
| 205 | + "host": "127.0.0.1", |
| 206 | + "port": 514 |
| 207 | + } |
| 208 | + }, |
| 209 | + "upstream": { |
| 210 | + "type": "roundrobin", |
| 211 | + "nodes": { |
| 212 | + "127.0.0.1:1995": 1 |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + ] |
| 217 | +} |
| 218 | +--- config |
| 219 | +location /stream_request { |
| 220 | + content_by_lua_block { |
| 221 | + ngx.sleep(1) -- wait for the stream route to take effect |
| 222 | +
|
| 223 | + local tcp_request = function(host, port) |
| 224 | + local sock, err = ngx.socket.tcp() |
| 225 | + assert(sock, err) |
| 226 | +
|
| 227 | + local ok, err = sock:connect(host, port) |
| 228 | + if not ok then |
| 229 | + ngx.say("connect to stream server error: ", err) |
| 230 | + return |
| 231 | + end |
| 232 | + local bytes, err = sock:send("mmm") |
| 233 | + if not bytes then |
| 234 | + ngx.say("send stream request error: ", err) |
| 235 | + return |
| 236 | + end |
| 237 | +
|
| 238 | + local data, err = sock:receive("*a") |
| 239 | + if not data then |
| 240 | + sock:close() |
| 241 | + ngx.say("receive stream response error: ", err) |
| 242 | + return |
| 243 | + end |
| 244 | + sock:close() |
| 245 | + ngx.print(data) |
| 246 | + end |
| 247 | +
|
| 248 | + tcp_request("127.0.0.1", 1985) |
| 249 | + } |
| 250 | +} |
| 251 | +--- request |
| 252 | +GET /stream_request |
| 253 | +--- response_body |
| 254 | +receive stream response error: connection reset by peer |
| 255 | +--- error_log |
| 256 | +unknown plugin [syslog] |
0 commit comments