@@ -253,6 +253,54 @@ Y_UNIT_TEST_SUITE(Mvp) {
253
253
}
254
254
255
255
256
+ Y_UNIT_TEST (OpenIdConnectFixLocationHeader) {
257
+ TPortManager tp;
258
+ ui16 sessionServicePort = tp.GetPort (8655 );
259
+ TMvpTestRuntime runtime;
260
+ runtime.Initialize ();
261
+
262
+ const TString allowedProxyHost {" ydb.viewer.page:1234" };
263
+
264
+ TOpenIdConnectSettings settings {
265
+ .SessionServiceEndpoint = " localhost:" + ToString (sessionServicePort),
266
+ .AllowedProxyHosts = {allowedProxyHost},
267
+ .AccessServiceType = NMvp::yandex_v2
268
+ };
269
+
270
+ const NActors::TActorId edge = runtime.AllocateEdgeActor ();
271
+ const NActors::TActorId target = runtime.Register (new NMVP::TProtectedPageHandler (edge, settings));
272
+
273
+ TSessionServiceMock sessionServiceMock;
274
+ sessionServiceMock.AllowedCookies .second = " allowed_session_cookie" ;
275
+ grpc::ServerBuilder builder;
276
+ builder.AddListeningPort (settings.SessionServiceEndpoint , grpc::InsecureServerCredentials ()).RegisterService (&sessionServiceMock);
277
+ std::unique_ptr<grpc::Server> sessionServer (builder.BuildAndStart ());
278
+
279
+ NHttp::THttpIncomingRequestPtr incomingRequest = new NHttp::THttpIncomingRequest ();
280
+ EatWholeString (incomingRequest, " GET /" + allowedProxyHost + " /counters HTTP/1.1\r\n "
281
+ " Host: oidcproxy.net\r\n "
282
+ " Cookie: yc_session=allowed_session_cookie\r\n\r\n " );
283
+ runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
284
+ TAutoPtr<IEventHandle> handle;
285
+
286
+ auto outgoingRequestEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingRequest>(handle);
287
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingRequestEv->Request ->Host , allowedProxyHost);
288
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingRequestEv->Request ->URL , " /counters" );
289
+ UNIT_ASSERT_STRING_CONTAINS (outgoingRequestEv->Request ->Headers , " Authorization: Bearer protected_page_iam_token" );
290
+ UNIT_ASSERT_EQUAL (outgoingRequestEv->Request ->Secure , false );
291
+ NHttp::THttpIncomingResponsePtr incomingResponse = new NHttp::THttpIncomingResponse (outgoingRequestEv->Request );
292
+ EatWholeString (incomingResponse, " HTTP/1.1 307 Temporary Redirect\r\n "
293
+ " Connection: close\r\n "
294
+ " Location: /node/12345/counters\r\n "
295
+ " Content-Length:0\r\n\r\n " );
296
+ runtime.Send (new IEventHandle (handle->Sender , edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse (outgoingRequestEv->Request , incomingResponse)));
297
+
298
+ auto outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
299
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 307" );
300
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Headers , " Location: /" + allowedProxyHost + " /node/12345/counters" );
301
+ }
302
+
303
+
256
304
Y_UNIT_TEST (OpenIdConnectExchangeNebius) {
257
305
TPortManager tp;
258
306
ui16 sessionServicePort = tp.GetPort (8655 );
0 commit comments