remote-addr-ipv6.t 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. no_root_location();
  19. run_tests();
  20. __DATA__
  21. === TEST 1: set route: remote addr = ::1
  22. --- config
  23. location /t {
  24. content_by_lua_block {
  25. local t = require("lib.test_admin").test
  26. local code, body = t('/apisix/admin/routes/1',
  27. ngx.HTTP_PUT,
  28. [[{
  29. "remote_addr": "::1",
  30. "upstream": {
  31. "nodes": {
  32. "127.0.0.1:1980": 1
  33. },
  34. "type": "roundrobin"
  35. },
  36. "uri": "/hello"
  37. }]]
  38. )
  39. if code >= 300 then
  40. ngx.status = code
  41. end
  42. ngx.say(body)
  43. }
  44. }
  45. --- request
  46. GET /t
  47. --- response_body
  48. passed
  49. === TEST 2: IPv6 /not_found
  50. --- listen_ipv6
  51. --- config
  52. location /t {
  53. content_by_lua_block {
  54. ngx.sleep(0.2)
  55. local t = require("lib.test_admin").test_ipv6
  56. t('/not_found')
  57. }
  58. }
  59. --- request
  60. GET /t
  61. --- response_body eval
  62. qr/"error_msg":"404 Route Not Found"/
  63. === TEST 3: IPv4 /not_found
  64. --- listen_ipv6
  65. --- request
  66. GET /not_found
  67. --- error_code: 404
  68. --- response_body eval
  69. qr/"error_msg":"404 Route Not Found"/
  70. === TEST 4: IPv6 /hello
  71. --- listen_ipv6
  72. --- config
  73. location /t {
  74. content_by_lua_block {
  75. ngx.sleep(0.2)
  76. local t = require("lib.test_admin").test_ipv6
  77. t('/hello')
  78. }
  79. }
  80. --- request
  81. GET /t
  82. --- response_body eval
  83. qr{connected: 1
  84. request sent: 59
  85. received: HTTP/1.1 200 OK
  86. received: Content-Type: text/plain
  87. received: Content-Length: 12
  88. received: Connection: close
  89. received: Server: APISIX/\d\.\d+(\.\d+)?
  90. received:
  91. received: hello world
  92. failed to receive a line: closed \[\]
  93. close: 1 nil}
  94. === TEST 5: IPv4 /hello
  95. --- listen_ipv6
  96. --- request
  97. GET /hello
  98. --- error_code: 404
  99. --- response_body
  100. {"error_msg":"404 Route Not Found"}