@@ -277,7 +277,7 @@ Y_UNIT_TEST_SUITE(Mvp) {
277
277
std::unique_ptr<grpc::Server> sessionServer (builder.BuildAndStart ());
278
278
279
279
NHttp::THttpIncomingRequestPtr incomingRequest = new NHttp::THttpIncomingRequest ();
280
- EatWholeString (incomingRequest, " GET /" + allowedProxyHost + " /counters HTTP/1.1\r\n "
280
+ EatWholeString (incomingRequest, " GET /http:// " + allowedProxyHost + " /counters HTTP/1.1\r\n "
281
281
" Host: oidcproxy.net\r\n "
282
282
" Cookie: yc_session=allowed_session_cookie\r\n\r\n " );
283
283
runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
@@ -288,6 +288,8 @@ Y_UNIT_TEST_SUITE(Mvp) {
288
288
UNIT_ASSERT_STRINGS_EQUAL (outgoingRequestEv->Request ->URL , " /counters" );
289
289
UNIT_ASSERT_STRING_CONTAINS (outgoingRequestEv->Request ->Headers , " Authorization: Bearer protected_page_iam_token" );
290
290
UNIT_ASSERT_EQUAL (outgoingRequestEv->Request ->Secure , false );
291
+
292
+ // Location start with '/'
291
293
NHttp::THttpIncomingResponsePtr incomingResponse = new NHttp::THttpIncomingResponse (outgoingRequestEv->Request );
292
294
EatWholeString (incomingResponse, " HTTP/1.1 307 Temporary Redirect\r\n "
293
295
" Connection: close\r\n "
@@ -297,7 +299,67 @@ Y_UNIT_TEST_SUITE(Mvp) {
297
299
298
300
auto outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
299
301
UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 307" );
300
- UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: /" + allowedProxyHost + " /node/12345/counters" );
302
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: /http://" + allowedProxyHost + " /node/12345/counters" );
303
+
304
+ // Location start with "//"
305
+ runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
306
+ outgoingRequestEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingRequest>(handle);
307
+
308
+ incomingResponse = new NHttp::THttpIncomingResponse (outgoingRequestEv->Request );
309
+ EatWholeString (incomingResponse, " HTTP/1.1 302 Found\r\n "
310
+ " Connection: close\r\n "
311
+ " Location: //new.oidc.proxy.host:1234/node/12345/counters\r\n "
312
+ " Content-Length:0\r\n\r\n " );
313
+ runtime.Send (new IEventHandle (handle->Sender , edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse (outgoingRequestEv->Request , incomingResponse)));
314
+
315
+ outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
316
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 302" );
317
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: /http://new.oidc.proxy.host:1234/node/12345/counters" );
318
+
319
+ // Location start with ".."
320
+ runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
321
+ outgoingRequestEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingRequest>(handle);
322
+
323
+ incomingResponse = new NHttp::THttpIncomingResponse (outgoingRequestEv->Request );
324
+ EatWholeString (incomingResponse, " HTTP/1.1 302 Found\r\n "
325
+ " Connection: close\r\n "
326
+ " Location: ../node/12345/counters\r\n "
327
+ " Content-Length:0\r\n\r\n " );
328
+ runtime.Send (new IEventHandle (handle->Sender , edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse (outgoingRequestEv->Request , incomingResponse)));
329
+
330
+ outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
331
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 302" );
332
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: ../node/12345/counters" );
333
+
334
+ // Location is absolute URL
335
+ runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
336
+ outgoingRequestEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingRequest>(handle);
337
+
338
+ incomingResponse = new NHttp::THttpIncomingResponse (outgoingRequestEv->Request );
339
+ EatWholeString (incomingResponse, " HTTP/1.1 302 Found\r\n "
340
+ " Connection: close\r\n "
341
+ " Location: https://some.new.oidc.host:9876/counters/v1\r\n "
342
+ " Content-Length:0\r\n\r\n " );
343
+ runtime.Send (new IEventHandle (handle->Sender , edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse (outgoingRequestEv->Request , incomingResponse)));
344
+
345
+ outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
346
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 302" );
347
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: /https://some.new.oidc.host:9876/counters/v1" );
348
+
349
+ // Location is sub-resources URL
350
+ runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
351
+ outgoingRequestEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingRequest>(handle);
352
+
353
+ incomingResponse = new NHttp::THttpIncomingResponse (outgoingRequestEv->Request );
354
+ EatWholeString (incomingResponse, " HTTP/1.1 302 Found\r\n "
355
+ " Connection: close\r\n "
356
+ " Location: v1/\r\n "
357
+ " Content-Length:0\r\n\r\n " );
358
+ runtime.Send (new IEventHandle (handle->Sender , edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse (outgoingRequestEv->Request , incomingResponse)));
359
+
360
+ outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
361
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 302" );
362
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: v1/" );
301
363
}
302
364
303
365
0 commit comments