|
| 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 | +use t::APISIX 'no_plan'; |
| 18 | + |
| 19 | +repeat_each(1); |
| 20 | +no_long_string(); |
| 21 | +no_root_location(); |
| 22 | + |
| 23 | +add_block_preprocessor(sub { |
| 24 | + my ($block) = @_; |
| 25 | + |
| 26 | + if (!defined $block->request) { |
| 27 | + $block->set_value("request", "GET /t"); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +run_tests(); |
| 32 | + |
| 33 | +__DATA__ |
| 34 | +
|
| 35 | +=== TEST 1: setup routes |
| 36 | +--- config |
| 37 | + location /t { |
| 38 | + content_by_lua_block { |
| 39 | + local data = { |
| 40 | + { |
| 41 | + url = "/apisix/admin/upstreams/u1", |
| 42 | + data = [[{ |
| 43 | + "nodes": { |
| 44 | + "127.0.0.1:1984": 1 |
| 45 | + }, |
| 46 | + "type": "roundrobin" |
| 47 | + }]], |
| 48 | + }, |
| 49 | + { |
| 50 | + url = "/apisix/admin/routes/auth", |
| 51 | + data = { |
| 52 | + plugins = { |
| 53 | + ["serverless-pre-function"] = { |
| 54 | + phase = "rewrite", |
| 55 | + functions = { |
| 56 | + [[return function(conf, ctx) |
| 57 | + local core = require("apisix.core") |
| 58 | + -- auth succeeds without setting X-User-ID |
| 59 | + core.response.exit(200) |
| 60 | + end]] |
| 61 | + } |
| 62 | + } |
| 63 | + }, |
| 64 | + uri = "/auth" |
| 65 | + }, |
| 66 | + }, |
| 67 | + { |
| 68 | + url = "/apisix/admin/routes/1", |
| 69 | + data = [[{ |
| 70 | + "plugins": { |
| 71 | + "forward-auth": { |
| 72 | + "uri": "http://127.0.0.1:1984/auth", |
| 73 | + "upstream_headers": ["X-User-ID"] |
| 74 | + }, |
| 75 | + "serverless-post-function": { |
| 76 | + "phase": "access", |
| 77 | + "functions": [ |
| 78 | + "return function(conf, ctx) local core = require(\"apisix.core\"); core.response.exit(200, core.request.headers(ctx)); end" |
| 79 | + ] |
| 80 | + } |
| 81 | + }, |
| 82 | + "upstream_id": "u1", |
| 83 | + "uri": "/hello" |
| 84 | + }]], |
| 85 | + } |
| 86 | + } |
| 87 | +
|
| 88 | + local t = require("lib.test_admin").test |
| 89 | +
|
| 90 | + for _, data in ipairs(data) do |
| 91 | + local code, body = t(data.url, ngx.HTTP_PUT, data.data) |
| 92 | + ngx.say(body) |
| 93 | + end |
| 94 | + } |
| 95 | + } |
| 96 | +--- response_body eval |
| 97 | +"passed\n" x 3 |
| 98 | +
|
| 99 | +
|
| 100 | +
|
| 101 | +=== TEST 2: client-supplied upstream_headers are cleared when auth response omits them |
| 102 | +--- request |
| 103 | +GET /hello |
| 104 | +--- more_headers |
| 105 | +X-User-ID: injected-value |
| 106 | +--- response_body_unlike eval |
| 107 | +qr/x-user-id/ |
0 commit comments