wildcard-host.t 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: host: *.foo.com
  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. "host": "*.foo.com",
  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: /not_found
  50. --- request
  51. GET /not_found
  52. --- error_code: 404
  53. --- response_body
  54. {"error_msg":"404 Route Not Found"}
  55. === TEST 3: not found, missing host
  56. --- request
  57. GET /hello
  58. --- error_code: 404
  59. --- response_body
  60. {"error_msg":"404 Route Not Found"}
  61. === TEST 4: host: a.foo.com
  62. --- request
  63. GET /hello
  64. --- more_headers
  65. Host: a.foo.com
  66. --- response_body
  67. hello world
  68. === TEST 5: host: a.b.foo.com
  69. --- request
  70. GET /hello
  71. --- more_headers
  72. Host: a.b.foo.com
  73. --- response_body
  74. hello world
  75. === TEST 6: host: .foo.com
  76. --- request
  77. GET /hello
  78. --- more_headers
  79. Host: .foo.com
  80. --- response_body
  81. hello world