invalid-route.t 3.9 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. no_long_string();
  21. no_root_location();
  22. no_shuffle();
  23. run_tests();
  24. __DATA__
  25. === TEST 1: set invalid route(id: 1)
  26. --- config
  27. location /t {
  28. content_by_lua_block {
  29. local core = require("apisix.core")
  30. local res, err = core.etcd.set("/routes/1", [[mexxxxxxxxxxxxxxx]])
  31. if res.status >= 300 then
  32. res.status = code
  33. end
  34. ngx.print(require("toolkit.json").encode(res.body))
  35. ngx.sleep(1)
  36. }
  37. }
  38. --- request
  39. GET /t
  40. --- wait: 1
  41. --- grep_error_log eval
  42. qr/\[error\].*/
  43. --- grep_error_log_out eval
  44. qr{invalid item data of \[/apisix/routes/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  45. --- response_body_like eval
  46. qr/"value":"mexxxxxxxxxxxxxxx"/
  47. === TEST 2: /not_found
  48. --- request
  49. GET /not_found
  50. --- error_code: 404
  51. --- response_body
  52. {"error_msg":"404 Route Not Found"}
  53. --- wait: 1
  54. --- grep_error_log eval
  55. qr/\[error\].*/
  56. --- grep_error_log_out eval
  57. qr{invalid item data of \[/apisix/routes/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  58. === TEST 3: set valid route(id: 1)
  59. --- config
  60. location /t {
  61. content_by_lua_block {
  62. local t = require("lib.test_admin").test
  63. local code, body = t('/apisix/admin/routes/1',
  64. ngx.HTTP_PUT,
  65. [[{
  66. "methods": ["GET"],
  67. "upstream": {
  68. "nodes": {
  69. "127.0.0.1:1980": 1
  70. },
  71. "type": "roundrobin"
  72. },
  73. "uri": "/hello"
  74. }]]
  75. )
  76. if code >= 300 then
  77. ngx.status = code
  78. end
  79. ngx.say(body)
  80. }
  81. }
  82. --- request
  83. GET /t
  84. --- response_body
  85. passed
  86. --- wait: 1
  87. --- grep_error_log eval
  88. qr/\[error\].*/
  89. --- grep_error_log_out eval
  90. qr{invalid item data of \[/apisix/routes/1\], val: mexxxxxxxxxxxxxxx, it should be an object}
  91. === TEST 4: no error log
  92. --- config
  93. location /t {
  94. content_by_lua_block {
  95. ngx.sleep(1)
  96. ngx.say("done")
  97. }
  98. }
  99. --- request
  100. GET /t
  101. --- response_body
  102. done
  103. === TEST 5: set route(with invalid host)
  104. --- config
  105. location /t {
  106. content_by_lua_block {
  107. local t = require("lib.test_admin").test
  108. local code, body = t('/apisix/admin/routes/1',
  109. ngx.HTTP_PUT,
  110. [[{
  111. "uri": "/server_port",
  112. "upstream": {
  113. "key": "remote_addr",
  114. "type": "chash",
  115. "nodes": {
  116. "xxxx.invalid:1980": 1
  117. }
  118. }
  119. }]]
  120. )
  121. if code >= 300 then
  122. ngx.status = code
  123. end
  124. ngx.say(body)
  125. }
  126. }
  127. --- request
  128. GET /t
  129. --- response_body
  130. passed
  131. === TEST 6: hit route
  132. --- request
  133. GET /server_port
  134. --- error_code: 503
  135. --- error_log
  136. failed to parse domain: xxxx.invalid
  137. --- timeout: 10