route-host.t 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. "methods": ["GET"],
  34. "upstream": {
  35. "nodes": {
  36. "127.0.0.1:1980": 1
  37. },
  38. "type": "roundrobin"
  39. },
  40. "host": "foo.com",
  41. "uri": "/hello"
  42. }]]
  43. )
  44. if code >= 300 then
  45. ngx.status = code
  46. end
  47. ngx.say(body)
  48. }
  49. }
  50. --- request
  51. GET /t
  52. --- response_body
  53. passed
  54. === TEST 2: /not_found
  55. --- request
  56. GET /not_found
  57. --- error_code: 404
  58. --- response_body
  59. {"error_msg":"404 Route Not Found"}
  60. === TEST 3: /not_found
  61. --- request
  62. GET /hello
  63. --- error_code: 404
  64. --- response_body
  65. {"error_msg":"404 Route Not Found"}
  66. === TEST 4: /not_found
  67. --- request
  68. GET /hello
  69. --- more_headers
  70. Host: not_found.com
  71. --- error_code: 404
  72. --- response_body
  73. {"error_msg":"404 Route Not Found"}
  74. === TEST 5: hit routes
  75. --- request
  76. GET /hello
  77. --- more_headers
  78. Host: foo.com
  79. --- response_body
  80. hello world
  81. === TEST 6: hit routes, uppercase
  82. --- request
  83. GET /hello
  84. --- more_headers
  85. Host: FOO.com
  86. --- response_body
  87. hello world
  88. === TEST 7: set route(host is uppercase)
  89. --- config
  90. location /t {
  91. content_by_lua_block {
  92. local t = require("lib.test_admin").test
  93. local code, body = t('/apisix/admin/routes/1',
  94. ngx.HTTP_PUT,
  95. [[{
  96. "methods": ["GET"],
  97. "upstream": {
  98. "nodes": {
  99. "127.0.0.1:1980": 1
  100. },
  101. "type": "roundrobin"
  102. },
  103. "host": "FOO.com",
  104. "uri": "/hello"
  105. }]]
  106. )
  107. if code >= 300 then
  108. ngx.status = code
  109. end
  110. ngx.say(body)
  111. }
  112. }
  113. --- request
  114. GET /t
  115. --- response_body
  116. passed
  117. === TEST 8: hit routes
  118. --- request
  119. GET /hello
  120. --- more_headers
  121. Host: foo.com
  122. --- response_body
  123. hello world
  124. === TEST 9: hit routes, uppercase
  125. --- request
  126. GET /hello
  127. --- more_headers
  128. Host: FOO.com
  129. --- response_body
  130. hello world