@@ -10,6 +10,7 @@ plan tests => repeat_each() * (blocks() * 4);
10
10
run_tests();
11
11
12
12
__DATA__
13
+
13
14
=== TEST 1: service.response.error() use accept header
14
15
--- http_config eval: $t::Util::HttpConfig
15
16
--- config
@@ -35,6 +36,8 @@ Content-Type: application/json; charset=utf-8
35
36
--- no_error_log
36
37
[error]
37
38
39
+
40
+
38
41
=== TEST 2: service.response.error() fallbacks to json
39
42
--- http_config eval: $t::Util::HttpConfig
40
43
--- config
@@ -58,6 +61,8 @@ Content-Type: application/json; charset=utf-8
58
61
--- no_error_log
59
62
[error]
60
63
64
+
65
+
61
66
=== TEST 3: service.response.error() may ignore accept header
62
67
--- http_config eval: $t::Util::HttpConfig
63
68
--- config
@@ -88,6 +93,8 @@ Content-Type: application/xml
88
93
--- no_error_log
89
94
[error]
90
95
96
+
97
+
91
98
=== TEST 4: service.response.error() respects accept header priorities
92
99
--- http_config eval: $t::Util::HttpConfig
93
100
--- config
@@ -122,6 +129,7 @@ Content-Type: text/html; charset=utf-8
122
129
[error]
123
130
124
131
132
+
125
133
=== TEST 5: service.response.error() has higher priority than handle_errors
126
134
--- http_config eval: $t::Util::HttpConfig
127
135
--- config
@@ -155,6 +163,8 @@ Content-Type: application/json; charset=utf-8
155
163
--- no_error_log
156
164
[error]
157
165
166
+
167
+
158
168
=== TEST 6: service.response.error() formats default template
159
169
--- http_config eval: $t::Util::HttpConfig
160
170
--- config
@@ -180,6 +190,8 @@ Content-Type: application/json; charset=utf-8
180
190
--- no_error_log
181
191
[error]
182
192
193
+
194
+
183
195
=== TEST 7: service.response.error() overrides default message
184
196
--- http_config eval: $t::Util::HttpConfig
185
197
--- config
@@ -205,6 +217,8 @@ Content-Type: application/json; charset=utf-8
205
217
--- no_error_log
206
218
[error]
207
219
220
+
221
+
208
222
=== TEST 8: service.response.error() use accept header "*" mime sub-type
209
223
--- http_config eval: $t::Util::HttpConfig
210
224
--- config
@@ -227,3 +241,107 @@ Content-Type: text/plain; charset=utf-8
227
241
Gone
228
242
--- no_error_log
229
243
[error]
244
+
245
+
246
+
247
+ === TEST 9: response.error() maps http 400 to grpc InvalidArgument
248
+ --- http_config eval: $t::Util::HttpConfig
249
+ --- config
250
+ location = /t {
251
+ default_type 'text/test';
252
+ access_by_lua_block {
253
+ ngx.req.http_version = function() return 2 end
254
+ local PDK = require "kong.pdk"
255
+ local pdk = PDK.new()
256
+
257
+ pdk.response.error(400)
258
+ }
259
+ }
260
+ --- request
261
+ GET /t
262
+ --- more_headers
263
+ Content-Type: application/grpc
264
+ --- error_code: 400
265
+ --- response_headers_like
266
+ grpc-status: 3
267
+ grpc-message: InvalidArgument
268
+ --- no_error_log
269
+ [error]
270
+
271
+
272
+
273
+ === TEST 10: response.error() maps http 401 to grpc Unauthenticated
274
+ --- http_config eval: $t::Util::HttpConfig
275
+ --- config
276
+ location = /t {
277
+ default_type 'text/test';
278
+ access_by_lua_block {
279
+ ngx.req.http_version = function() return 2 end
280
+ local PDK = require "kong.pdk"
281
+ local pdk = PDK.new()
282
+
283
+ pdk.response.error(401)
284
+ }
285
+ }
286
+ --- request
287
+ GET /t
288
+ --- more_headers
289
+ Content-Type: application/grpc
290
+ --- error_code: 401
291
+ --- response_headers_like
292
+ grpc-status: 16
293
+ grpc-message: Unauthenticated
294
+ --- no_error_log
295
+ [error]
296
+
297
+
298
+
299
+ === TEST 11: response.error() maps http 403 to grpc PermissionDenied
300
+ --- http_config eval: $t::Util::HttpConfig
301
+ --- config
302
+ location = /t {
303
+ default_type 'text/test';
304
+ access_by_lua_block {
305
+ ngx.req.http_version = function() return 2 end
306
+ local PDK = require "kong.pdk"
307
+ local pdk = PDK.new()
308
+
309
+ pdk.response.error(403)
310
+ }
311
+ }
312
+ --- request
313
+ GET /t
314
+ --- more_headers
315
+ Content-Type: application/grpc
316
+ --- error_code: 403
317
+ --- response_headers_like
318
+ grpc-status: 7
319
+ grpc-message: PermissionDenied
320
+ --- no_error_log
321
+ [error]
322
+
323
+
324
+
325
+ === TEST 12: response.error() maps http 429 to grpc ResourceExhausted
326
+ --- http_config eval: $t::Util::HttpConfig
327
+ --- config
328
+ location = /t {
329
+ default_type 'text/test';
330
+ access_by_lua_block {
331
+ ngx.req.http_version = function() return 2 end
332
+ local PDK = require "kong.pdk"
333
+ local pdk = PDK.new()
334
+
335
+ pdk.response.error(429)
336
+ }
337
+ }
338
+ --- request
339
+ GET /t
340
+ --- more_headers
341
+ Content-Type: application/grpc
342
+ --- error_code: 429
343
+ --- response_headers_like
344
+ grpc-status: 8
345
+ grpc-message: ResourceExhausted
346
+ --- no_error_log
347
+ [error]
0 commit comments