|
| 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 | +log_level('info'); |
| 21 | +no_root_location(); |
| 22 | +no_shuffle(); |
| 23 | + |
| 24 | +add_block_preprocessor(sub { |
| 25 | + my ($block) = @_; |
| 26 | + |
| 27 | + my $yaml_config = $block->yaml_config // <<_EOC_; |
| 28 | +apisix: |
| 29 | + node_listen: 1984 |
| 30 | +deployment: |
| 31 | + role: data_plane |
| 32 | + role_data_plane: |
| 33 | + config_provider: yaml |
| 34 | +_EOC_ |
| 35 | + |
| 36 | + $block->set_value("yaml_config", $yaml_config); |
| 37 | +}); |
| 38 | + |
| 39 | +run_tests(); |
| 40 | + |
| 41 | +__DATA__ |
| 42 | +
|
| 43 | +=== TEST 1: test with username in id field - invalid key |
| 44 | +--- apisix_yaml |
| 45 | +routes: |
| 46 | + - |
| 47 | + uri: /hello |
| 48 | + plugins: |
| 49 | + key-auth: |
| 50 | + upstream: |
| 51 | + nodes: |
| 52 | + "127.0.0.1:1980": 1 |
| 53 | + type: roundrobin |
| 54 | +consumers: |
| 55 | + - id: rose/credentials/542f7414-87f6-4793-a68e-99983dde9913 |
| 56 | + name: rose |
| 57 | + plugins: |
| 58 | + key-auth: |
| 59 | + key: csdt8UPw76/SG+WlHBoFeg== |
| 60 | +
|
| 61 | + - id: rose |
| 62 | + username: rose |
| 63 | + plugins: |
| 64 | + limit-count: |
| 65 | + time_window: 3 |
| 66 | + count: 100000000 |
| 67 | + key_type: var |
| 68 | + allow_degradation: false |
| 69 | + key: remote_addr |
| 70 | + rejected_code: 429 |
| 71 | + show_limit_quota_header: true |
| 72 | + policy: local |
| 73 | +#END |
| 74 | +--- more_headers |
| 75 | +apikey: user-key |
| 76 | +--- error_code: 401 |
| 77 | +--- request |
| 78 | +POST /hello |
| 79 | +
|
| 80 | +
|
| 81 | +
|
| 82 | +=== TEST 2: test with username in id field - valid key |
| 83 | +--- apisix_yaml |
| 84 | +routes: |
| 85 | + - |
| 86 | + uri: /hello |
| 87 | + plugins: |
| 88 | + key-auth: |
| 89 | + upstream: |
| 90 | + nodes: |
| 91 | + "127.0.0.1:1980": 1 |
| 92 | + type: roundrobin |
| 93 | +consumers: |
| 94 | + - id: rose/credentials/542f7414-87f6-4793-a68e-99983dde9913 |
| 95 | + name: rose |
| 96 | + plugins: |
| 97 | + key-auth: |
| 98 | + key: csdt8UPw76/SG+WlHBoFeg== |
| 99 | +
|
| 100 | + - id: rose |
| 101 | + username: rose |
| 102 | + plugins: |
| 103 | + limit-count: |
| 104 | + time_window: 3 |
| 105 | + count: 100000000 |
| 106 | + key_type: var |
| 107 | + allow_degradation: false |
| 108 | + key: remote_addr |
| 109 | + rejected_code: 429 |
| 110 | + show_limit_quota_header: true |
| 111 | + policy: local |
| 112 | +#END |
| 113 | +--- more_headers |
| 114 | +apikey: csdt8UPw76/SG+WlHBoFeg== |
| 115 | +--- error_code: 200 |
| 116 | +--- request |
| 117 | +POST /hello |
0 commit comments