2
0

debug-mode.t 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. no_long_string();
  20. no_root_location();
  21. our $debug_config = t::APISIX::read_file("conf/debug.yaml");
  22. $debug_config =~ s/basic:\n enable: false/basic:\n enable: true/;
  23. run_tests;
  24. __DATA__
  25. === TEST 1: loaded plugin
  26. --- debug_config eval: $::debug_config
  27. --- config
  28. location /t {
  29. content_by_lua_block {
  30. ngx.sleep(0.3)
  31. ngx.say("done")
  32. }
  33. }
  34. --- request
  35. GET /t
  36. --- response_body
  37. done
  38. --- error_log
  39. loaded plugin and sort by priority: 23000 name: real-ip
  40. loaded plugin and sort by priority: 22000 name: client-control
  41. loaded plugin and sort by priority: 12015 name: request-id
  42. loaded plugin and sort by priority: 12011 name: zipkin
  43. loaded plugin and sort by priority: 12000 name: ext-plugin-pre-req
  44. loaded plugin and sort by priority: 11000 name: fault-injection
  45. loaded plugin and sort by priority: 10000 name: serverless-pre-function
  46. loaded plugin and sort by priority: 4000 name: cors
  47. loaded plugin and sort by priority: 3000 name: ip-restriction
  48. loaded plugin and sort by priority: 2990 name: referer-restriction
  49. loaded plugin and sort by priority: 2900 name: uri-blocker
  50. loaded plugin and sort by priority: 2800 name: request-validation
  51. loaded plugin and sort by priority: 2600 name: multi-auth
  52. loaded plugin and sort by priority: 2599 name: openid-connect
  53. loaded plugin and sort by priority: 2555 name: wolf-rbac
  54. loaded plugin and sort by priority: 2530 name: hmac-auth
  55. loaded plugin and sort by priority: 2520 name: basic-auth
  56. loaded plugin and sort by priority: 2510 name: jwt-auth
  57. loaded plugin and sort by priority: 2500 name: key-auth
  58. loaded plugin and sort by priority: 2400 name: consumer-restriction
  59. loaded plugin and sort by priority: 2000 name: authz-keycloak
  60. loaded plugin and sort by priority: 1085 name: proxy-cache
  61. loaded plugin and sort by priority: 1010 name: proxy-mirror
  62. loaded plugin and sort by priority: 1008 name: proxy-rewrite
  63. loaded plugin and sort by priority: 1005 name: api-breaker
  64. loaded plugin and sort by priority: 1003 name: limit-conn
  65. loaded plugin and sort by priority: 1002 name: limit-count
  66. loaded plugin and sort by priority: 1001 name: limit-req
  67. loaded plugin and sort by priority: 995 name: gzip
  68. loaded plugin and sort by priority: 990 name: server-info
  69. loaded plugin and sort by priority: 966 name: traffic-split
  70. loaded plugin and sort by priority: 900 name: redirect
  71. loaded plugin and sort by priority: 899 name: response-rewrite
  72. loaded plugin and sort by priority: 506 name: grpc-transcode
  73. loaded plugin and sort by priority: 500 name: prometheus
  74. loaded plugin and sort by priority: 412 name: echo
  75. loaded plugin and sort by priority: 410 name: http-logger
  76. loaded plugin and sort by priority: 406 name: sls-logger
  77. loaded plugin and sort by priority: 405 name: tcp-logger
  78. loaded plugin and sort by priority: 403 name: kafka-logger
  79. loaded plugin and sort by priority: 402 name: rocketmq-logger
  80. loaded plugin and sort by priority: 401 name: syslog
  81. loaded plugin and sort by priority: 400 name: udp-logger
  82. loaded plugin and sort by priority: 398 name: clickhouse-logger
  83. loaded plugin and sort by priority: 0 name: example-plugin
  84. loaded plugin and sort by priority: -2000 name: serverless-post-function
  85. loaded plugin and sort by priority: -3000 name: ext-plugin-post-req
  86. === TEST 2: set route(no plugin)
  87. --- config
  88. location /t {
  89. content_by_lua_block {
  90. local t = require("lib.test_admin").test
  91. local code, body = t('/apisix/admin/routes/1',
  92. ngx.HTTP_PUT,
  93. [[{
  94. "methods": ["GET"],
  95. "uri": "/hello",
  96. "upstream": {
  97. "nodes": {
  98. "127.0.0.1:1980": 1
  99. },
  100. "type": "roundrobin"
  101. }
  102. }]]
  103. )
  104. if code >= 300 then
  105. ngx.status = code
  106. end
  107. ngx.say(body)
  108. }
  109. }
  110. --- request
  111. GET /t
  112. --- response_body
  113. passed
  114. === TEST 3: hit routes
  115. --- debug_config eval: $::debug_config
  116. --- request
  117. GET /hello
  118. --- response_body
  119. hello world
  120. --- response_headers
  121. Apisix-Plugins: no plugin
  122. === TEST 4: set route(one plugin)
  123. --- config
  124. location /t {
  125. content_by_lua_block {
  126. local t = require("lib.test_admin").test
  127. local code, body = t('/apisix/admin/routes/1',
  128. ngx.HTTP_PUT,
  129. [[{
  130. "methods": ["GET"],
  131. "plugins": {
  132. "limit-count": {
  133. "count": 2,
  134. "time_window": 60,
  135. "rejected_code": 503,
  136. "key": "remote_addr"
  137. },
  138. "limit-conn": {
  139. "conn": 100,
  140. "burst": 50,
  141. "default_conn_delay": 0.1,
  142. "rejected_code": 503,
  143. "key": "remote_addr"
  144. }
  145. },
  146. "upstream": {
  147. "nodes": {
  148. "127.0.0.1:1980": 1
  149. },
  150. "type": "roundrobin"
  151. },
  152. "uri": "/hello"
  153. }]]
  154. )
  155. if code >= 300 then
  156. ngx.status = code
  157. end
  158. ngx.say(body)
  159. }
  160. }
  161. --- request
  162. GET /t
  163. --- response_body
  164. passed
  165. === TEST 5: hit routes
  166. --- debug_config eval: $::debug_config
  167. --- config
  168. location /t {
  169. content_by_lua_block {
  170. local json = require("toolkit.json")
  171. local ngx_re = require("ngx.re")
  172. local http = require "resty.http"
  173. local httpc = http.new()
  174. local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
  175. local res, err = httpc:request_uri(uri, {
  176. method = "GET",
  177. })
  178. local debug_header = res.headers["Apisix-Plugins"]
  179. local arr = ngx_re.split(debug_header, ", ")
  180. local hash = {}
  181. for i, v in ipairs(arr) do
  182. hash[v] = true
  183. end
  184. ngx.status = res.status
  185. ngx.say(json.encode(hash))
  186. }
  187. }
  188. --- request
  189. GET /t
  190. --- response_body
  191. {"limit-conn":true,"limit-count":true}
  192. === TEST 6: global rule, header sent
  193. --- config
  194. location /t {
  195. content_by_lua_block {
  196. local t = require("lib.test_admin").test
  197. local code, body = t('/apisix/admin/global_rules/1',
  198. ngx.HTTP_PUT,
  199. [[{
  200. "plugins": {
  201. "response-rewrite": {
  202. "status_code": 200,
  203. "body": "yes\n"
  204. }
  205. }
  206. }]]
  207. )
  208. if code >= 300 then
  209. ngx.status = code
  210. end
  211. ngx.say(body)
  212. }
  213. }
  214. --- request
  215. GET /t
  216. --- response_body
  217. passed
  218. === TEST 7: hit routes
  219. --- debug_config eval: $::debug_config
  220. --- config
  221. location /t {
  222. content_by_lua_block {
  223. local json = require("toolkit.json")
  224. local ngx_re = require("ngx.re")
  225. local http = require "resty.http"
  226. local httpc = http.new()
  227. local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
  228. local res, err = httpc:request_uri(uri, {
  229. method = "GET",
  230. })
  231. local debug_header = res.headers["Apisix-Plugins"]
  232. local arr = ngx_re.split(debug_header, ", ")
  233. local hash = {}
  234. for i, v in ipairs(arr) do
  235. hash[v] = true
  236. end
  237. ngx.status = res.status
  238. ngx.say(json.encode(hash))
  239. }
  240. }
  241. --- request
  242. GET /t
  243. --- response_body
  244. {"limit-conn":true,"limit-count":true,"response-rewrite":true}
  245. --- error_log
  246. Apisix-Plugins: response-rewrite
  247. === TEST 8: clear global routes
  248. --- config
  249. location /t {
  250. content_by_lua_block {
  251. local t = require("lib.test_admin").test
  252. local code, body = t('/apisix/admin/global_rules/1',
  253. ngx.HTTP_DELETE
  254. )
  255. if code >= 300 then
  256. ngx.status = code
  257. end
  258. ngx.say(body)
  259. }
  260. }
  261. --- request
  262. GET /t
  263. --- response_body
  264. passed
  265. === TEST 9: set stream route
  266. --- config
  267. location /t {
  268. content_by_lua_block {
  269. local t = require("lib.test_admin").test
  270. local code, body = t('/apisix/admin/stream_routes/1',
  271. ngx.HTTP_PUT,
  272. [[{
  273. "remote_addr": "127.0.0.1",
  274. "server_port": 1985,
  275. "plugins": {
  276. "mqtt-proxy": {
  277. "protocol_name": "MQTT",
  278. "protocol_level": 4
  279. }
  280. },
  281. "upstream": {
  282. "type": "chash",
  283. "key": "mqtt_client_id",
  284. "nodes": [
  285. {
  286. "host": "127.0.0.1",
  287. "port": 1995,
  288. "weight": 1
  289. }
  290. ]
  291. }
  292. }]]
  293. )
  294. if code >= 300 then
  295. ngx.status = code
  296. end
  297. ngx.say(body)
  298. }
  299. }
  300. --- request
  301. GET /t
  302. --- response_body
  303. passed
  304. === TEST 10: hit route
  305. --- debug_config eval: $::debug_config
  306. --- stream_request eval
  307. "\x10\x0f\x00\x04\x4d\x51\x54\x54\x04\x02\x00\x3c\x00\x03\x66\x6f\x6f"
  308. --- stream_response
  309. hello world
  310. --- error_log
  311. mqtt client id: foo while prereading client data