hosts.t 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. "hosts": ["foo.com", "*.bar.com"],
  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. --- request
  55. GET /not_found
  56. --- error_code: 404
  57. --- response_body
  58. {"error_msg":"404 Route Not Found"}
  59. === TEST 3: /not_found
  60. --- request
  61. GET /hello
  62. --- more_headers
  63. Host: not_found.com
  64. --- error_code: 404
  65. --- response_body
  66. {"error_msg":"404 Route Not Found"}
  67. === TEST 4: hit routes
  68. --- request
  69. GET /hello
  70. --- more_headers
  71. Host: foo.com
  72. --- response_body
  73. hello world
  74. === TEST 5: hit routes
  75. --- request
  76. GET /hello
  77. --- more_headers
  78. Host: www.bar.com
  79. --- response_body
  80. hello world