@@ -30,6 +30,8 @@ for _, strategy in helpers.each_strategy() do
30
30
reload_router (flavor )
31
31
32
32
lazy_setup (function ()
33
+ assert (helpers .start_grpc_target ())
34
+
33
35
local bp = helpers .get_db_utils (strategy , {
34
36
" routes" ,
35
37
" services" ,
@@ -47,12 +49,16 @@ for _, strategy in helpers.each_strategy() do
47
49
48
50
local mock_grpc_service = assert (bp .services :insert {
49
51
name = " mock_grpc_service" ,
50
- url = " grpc://localhost:8765" ,
52
+ protocol = " grpc" ,
53
+ host = " 127.0.0.1" ,
54
+ port = helpers .get_grpc_target_port (),
51
55
})
52
56
53
57
local mock_grpc_service_retry = assert (bp .services :insert {
54
58
name = " mock_grpc_service_retry" ,
55
- url = " grpc://grpc_retry" ,
59
+ protocol = " grpc" ,
60
+ host = " 127.0.0.1" ,
61
+ port = helpers .get_grpc_target_port (),
56
62
})
57
63
58
64
local upstream_retry = assert (bp .upstreams :insert {
@@ -111,30 +117,10 @@ for _, strategy in helpers.each_strategy() do
111
117
},
112
118
})
113
119
114
- local fixtures = {
115
- http_mock = {}
116
- }
117
-
118
- fixtures .http_mock .my_server_block = [[
119
- server {
120
- server_name myserver;
121
- listen 8765;
122
- http2 on;
123
-
124
- location ~ / {
125
- content_by_lua_block {
126
- ngx.header.content_type = "application/grpc"
127
- ngx.header.received_host = ngx.req.get_headers()["Host"]
128
- }
129
- }
130
- }
131
- ]]
132
-
133
120
assert (helpers .start_kong ({
134
121
router_flavor = flavor ,
135
122
database = strategy ,
136
- nginx_conf = " spec/fixtures/custom_nginx.template" ,
137
- }, nil , nil , fixtures ))
123
+ }))
138
124
139
125
proxy_client_grpc = helpers .proxy_client_grpc ()
140
126
proxy_client_grpcs = helpers .proxy_client_grpcs ()
@@ -150,6 +136,7 @@ for _, strategy in helpers.each_strategy() do
150
136
151
137
lazy_teardown (function ()
152
138
helpers .stop_kong ()
139
+ helpers .stop_grpc_target ()
153
140
end )
154
141
155
142
it (" proxies grpc" , function ()
@@ -228,32 +215,33 @@ for _, strategy in helpers.each_strategy() do
228
215
229
216
it (" proxies :authority header if `preserve_host` is set" , function ()
230
217
local _ , resp = proxy_client_grpc ({
231
- service = " hello.HelloService.SayHello " ,
218
+ service = " targetservice.Bouncer.EchoHeaders " ,
232
219
body = {
233
- greeting = " world!"
234
220
},
235
221
opts = {
222
+ [" -proto" ] = " ./spec/fixtures/grpc/proto/targetservice.proto" ,
223
+ [" -import-path" ] = " ./spec/fixtures/grpc/proto" ,
236
224
[" -authority" ] = " grpc_authority_1.example" ,
237
- [" -v" ] = true ,
238
225
}
239
226
})
240
-
241
- assert .matches (" received%-host: grpc_authority_1.example" , resp )
227
+ local headers = cjson . decode ( resp ). headers
228
+ assert .matches (" grpc_authority_1.example" , headers [ " :authority " ] )
242
229
end )
243
230
244
231
it (" sets default :authority header if `preserve_host` isn't set" , function ()
245
232
local _ , resp = proxy_client_grpc ({
246
- service = " hello.HelloService.SayHello " ,
233
+ service = " targetservice.Bouncer.EchoHeaders " ,
247
234
body = {
248
- greeting = " world!"
249
235
},
250
236
opts = {
237
+ [" -proto" ] = " ./spec/fixtures/grpc/proto/targetservice.proto" ,
238
+ [" -import-path" ] = " ./spec/fixtures/grpc/proto" ,
251
239
[" -authority" ] = " grpc_authority_2.example" ,
252
- [" -v" ] = true ,
253
240
}
254
241
})
255
242
256
- assert .matches (" received%-host: localhost:8765" , resp )
243
+ local headers = cjson .decode (resp ).headers
244
+ assert .matches (" 127.0.0.1:15010" , headers [" :authority" ])
257
245
end )
258
246
259
247
it (" proxies :authority header on balancer retry" , function ()
0 commit comments