@@ -952,7 +952,7 @@ Y_UNIT_TEST_SUITE(Mvp) {
952
952
const TString hostProxy = " oidcproxy.net" ;
953
953
const TString protectedPage = " /counters" ;
954
954
955
- auto checkAllowedHostList = [&] (const TString& requestedHost, const TString& expectedStatus) {
955
+ auto checkAllowedHostList = [&] (const TString& requestedHost, const TString& expectedStatus, const TString& expectedBodyContent = " " ) {
956
956
const TString url = " /" + requestedHost + protectedPage;
957
957
TStringBuilder httpRequest;
958
958
httpRequest << " GET " + url + " HTTP/1.1\r\n "
@@ -968,14 +968,54 @@ Y_UNIT_TEST_SUITE(Mvp) {
968
968
TAutoPtr<IEventHandle> handle;
969
969
NHttp::TEvHttpProxy::TEvHttpOutgoingResponse* outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
970
970
UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , expectedStatus);
971
+ if (!expectedBodyContent.empty ()) {
972
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Body , expectedBodyContent);
973
+ }
971
974
};
972
975
973
976
for (const TString& allowedHost : allowedProxyHosts) {
974
977
checkAllowedHostList (allowedHost, " 302" );
975
978
}
976
979
977
980
for (const TString& forbiddenHost : forbiddenProxyHosts) {
978
- checkAllowedHostList (forbiddenHost, " 404 " );
981
+ checkAllowedHostList (forbiddenHost, " 403 " , " 403 Forbidden host: " + forbiddenHost );
979
982
}
980
983
}
984
+
985
+ Y_UNIT_TEST (OpenIdConnectHandleNullResponseFromProtectedResource) {
986
+ TPortManager tp;
987
+ ui16 sessionServicePort = tp.GetPort (8655 );
988
+ TMvpTestRuntime runtime;
989
+ runtime.Initialize ();
990
+
991
+ const TString allowedProxyHost {" ydb.viewer.page" };
992
+
993
+ TOpenIdConnectSettings settings {
994
+ .SessionServiceEndpoint = " localhost:" + ToString (sessionServicePort),
995
+ .AllowedProxyHosts = {allowedProxyHost},
996
+ };
997
+
998
+ const NActors::TActorId edge = runtime.AllocateEdgeActor ();
999
+ const NActors::TActorId target = runtime.Register (new NMVP::TProtectedPageHandler (edge, settings));
1000
+
1001
+ const TString iamToken {" protected_page_iam_token" };
1002
+ NHttp::THttpIncomingRequestPtr incomingRequest = new NHttp::THttpIncomingRequest ();
1003
+ EatWholeString (incomingRequest, " GET /" + allowedProxyHost + " /counters HTTP/1.1\r\n "
1004
+ " Host: oidcproxy.net\r\n "
1005
+ " Authorization: Bearer " + iamToken + " \r\n " );
1006
+ runtime.Send (new IEventHandle (target, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingRequest (incomingRequest)));
1007
+ TAutoPtr<IEventHandle> handle;
1008
+
1009
+ auto outgoingRequestEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingRequest>(handle);
1010
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingRequestEv->Request ->Host , allowedProxyHost);
1011
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingRequestEv->Request ->URL , " /counters" );
1012
+ UNIT_ASSERT_STRING_CONTAINS (outgoingRequestEv->Request ->Headers , " Authorization: Bearer " + iamToken);
1013
+
1014
+ const TString expectedError = " Response is NULL for some reason" ;
1015
+ runtime.Send (new IEventHandle (handle->Sender , edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse (outgoingRequestEv->Request , nullptr , expectedError)));
1016
+
1017
+ auto outgoingResponseEv = runtime.GrabEdgeEvent <NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
1018
+ UNIT_ASSERT_STRINGS_EQUAL (outgoingResponseEv->Response ->Status , " 400" );
1019
+ UNIT_ASSERT_STRING_CONTAINS (outgoingResponseEv->Response ->Body , expectedError);
1020
+ }
981
1021
}
0 commit comments