Skip to content

Commit 1e945ca

Browse files
committed
test: fix
1 parent 26fc40b commit 1e945ca

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

t/plugin/grpc-web.t

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ passed
6969
7070
7171
=== TEST 2: Proxy unary request using APISIX with trailers gRPC-Web plugin
72+
Status should be printed at most once per request, otherwise this would be out of specification.
7273
--- exec
7374
node ./t/plugin/grpc-web/client.js BIN UNARY
7475
node ./t/plugin/grpc-web/client.js TEXT UNARY
7576
--- response_body
7677
Status: { code: 0, details: '', metadata: {} }
77-
Status: { code: 0, details: '', metadata: {} }
7878
{"name":"hello","path":"/hello"}
7979
Status: { code: 0, details: '', metadata: {} }
80-
Status: { code: 0, details: '', metadata: {} }
8180
{"name":"hello","path":"/hello"}
8281
8382
@@ -90,11 +89,9 @@ node ./t/plugin/grpc-web/client.js TEXT STREAM
9089
{"name":"hello","path":"/hello"}
9190
{"name":"world","path":"/world"}
9291
Status: { code: 0, details: '', metadata: {} }
93-
Status: { code: 0, details: '', metadata: {} }
9492
{"name":"hello","path":"/hello"}
9593
{"name":"world","path":"/world"}
9694
Status: { code: 0, details: '', metadata: {} }
97-
Status: { code: 0, details: '', metadata: {} }
9895
9996
10097
@@ -112,7 +109,7 @@ Access-Control-Allow-Origin: *
112109
=== TEST 5: test non-options request
113110
--- request
114111
GET /grpc/web/a6.RouteService/GetRoute
115-
--- error_code: 400
112+
--- error_code: 405
116113
--- response_headers
117114
Access-Control-Allow-Origin: *
118115
--- error_log
@@ -128,7 +125,7 @@ Content-Type: application/json
128125
--- error_code: 400
129126
--- response_headers
130127
Access-Control-Allow-Origin: *
131-
Content-Type: application/json
128+
Content-Type: text/html
132129
--- error_log
133130
request Content-Type: `application/json` invalid
134131
@@ -177,7 +174,7 @@ Content-Type: application/grpc-web
177174
--- error_code: 400
178175
--- response_headers
179176
Access-Control-Allow-Origin: *
180-
Content-Type: application/grpc-web
177+
Content-Type: text/html
181178
--- error_log
182179
routing configuration error, grpc-web plugin only supports `prefix matching` pattern routing
183180
@@ -226,33 +223,35 @@ passed
226223
227224
228225
=== TEST 10: don't override Access-Control-Allow-Origin header in response
229-
--- request
230-
POST /grpc/web/a6.RouteService/GetRoute
231-
{}
232-
--- more_headers
233-
Origin: http://test.com
234-
Content-Type: application/grpc-web
235-
--- response_headers
236-
Access-Control-Allow-Origin: http://test.com
237-
Content-Type: application/grpc-web
226+
--- exec
227+
curl -iv --location 'http://127.0.0.1:1984/grpc/web/a6.RouteService/GetRoute' \
228+
--header 'Origin: http://test.com' \
229+
--header 'Content-Type: application/grpc-web-text' \
230+
--data-raw 'AAAAAAcKBXdvcmxkCgo='
231+
--- response_body eval
232+
qr/HTTP\/1.1 200 OK/ and qr/Access-Control-Allow-Origin: http:\/\/test.com/
238233
239234
240235
241236
=== TEST 11: check for Access-Control-Expose-Headers header in response
242-
--- request
243-
POST /grpc/web/a6.RouteService/GetRoute
244-
{}
245-
--- more_headers
246-
Origin: http://test.com
247-
Content-Type: application/grpc-web
248-
--- response_headers
249-
Access-Control-Allow-Origin: http://test.com
250-
Access-Control-Expose-Headers: grpc-message,grpc-status
251-
Content-Type: application/grpc-web
237+
--- exec
238+
curl -iv --location 'http://127.0.0.1:1984/grpc/web/a6.RouteService/GetRoute' \
239+
--header 'Origin: http://test.com' \
240+
--header 'Content-Type: application/grpc-web-text' \
241+
--data-raw 'AAAAAAcKBXdvcmxkCgo='
242+
--- response_body eval
243+
qr/Access-Control-Expose-Headers: grpc-message,grpc-status/ and qr/Access-Control-Allow-Origin: http:\/\/test.com/
252244
253245
254246
255247
=== TEST 12: verify trailers in response
248+
According to the gRPC documentation, the grpc-web proxy should not retain trailers received from upstream when
249+
forwarding them, as the reference implementation envoy does, so the current test case is status quo rather
250+
than "correct", which is not expected to have an impact since browsers ignore trailers.
251+
Currently there is no API or hook point available in nginx/lua-nginx-module to remove specified trailers
252+
on demand (grpc_hide_header can do it but it affects the grpc proxy), and some nginx patches may be needed
253+
to allow for code-controlled removal of the trailer at runtime.
254+
When we implement that, this use case will be removed.
256255
--- exec
257256
curl -iv --location 'http://127.0.0.1:1984/grpc/web/a6.RouteService/GetRoute' \
258257
--header 'Content-Type: application/grpc-web+proto' \

0 commit comments

Comments
 (0)