2
0

remote_addrs.t 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. repeat_each(1);
  19. log_level('info');
  20. worker_connections(256);
  21. no_root_location();
  22. no_shuffle();
  23. run_tests();
  24. __DATA__
  25. === TEST 1: set route(id: 1)
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local t = require("lib.test_admin").test
  30. local code, body = t('/apisix/admin/routes/1',
  31. ngx.HTTP_PUT,
  32. [[{
  33. "uri": "/hello",
  34. "remote_addrs": ["192.0.0.0/8", "127.0.0.3"],
  35. "upstream": {
  36. "nodes": {
  37. "127.0.0.1:1980": 1
  38. },
  39. "type": "roundrobin"
  40. }
  41. }]]
  42. )
  43. if code >= 300 then
  44. ngx.status = code
  45. end
  46. ngx.say(body)
  47. }
  48. }
  49. --- request
  50. GET /t
  51. --- response_body
  52. passed
  53. === TEST 2: /not_found
  54. --- http_config
  55. real_ip_header X-Real-IP;
  56. set_real_ip_from 127.0.0.1;
  57. set_real_ip_from unix:;
  58. --- request
  59. GET /not_found
  60. --- error_code: 404
  61. --- response_body
  62. {"error_msg":"404 Route Not Found"}
  63. === TEST 3: /not_found
  64. --- http_config
  65. real_ip_header X-Real-IP;
  66. set_real_ip_from 127.0.0.1;
  67. set_real_ip_from unix:;
  68. --- request
  69. GET /hello
  70. --- more_headers
  71. Host: not_found.com
  72. --- error_code: 404
  73. === TEST 4: hit routes
  74. --- http_config
  75. real_ip_header X-Real-IP;
  76. set_real_ip_from 127.0.0.1;
  77. set_real_ip_from unix:;
  78. --- request
  79. GET /hello
  80. --- more_headers
  81. X-Real-IP: 192.168.1.100
  82. --- response_body
  83. hello world
  84. === TEST 5: hit routes
  85. --- http_config
  86. real_ip_header X-Real-IP;
  87. set_real_ip_from 127.0.0.1;
  88. set_real_ip_from unix:;
  89. --- request
  90. GET /hello
  91. --- more_headers
  92. X-Real-IP: 127.0.0.3
  93. --- response_body
  94. hello world