Skip to content

Commit 0e12525

Browse files
committed
Fix tests
1 parent fb2ad79 commit 0e12525

File tree

3 files changed

+11
-43
lines changed

3 files changed

+11
-43
lines changed

ydb/mvp/oidc_proxy/oidc_proxy_ut.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -729,15 +729,9 @@ Y_UNIT_TEST_SUITE(Mvp) {
729729

730730
TAutoPtr<IEventHandle> handle;
731731
NHttp::TEvHttpProxy::TEvHttpOutgoingResponse* outgoingResponseEv = runtime.GrabEdgeEvent<NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
732-
UNIT_ASSERT_STRINGS_EQUAL(outgoingResponseEv->Response->Status, "302");
733-
const NHttp::THeaders headers(outgoingResponseEv->Response->Headers);
734-
UNIT_ASSERT(headers.Has("Location"));
735-
TString location = TString(headers.Get("Location"));
736-
UNIT_ASSERT_STRING_CONTAINS(location, "https://auth.test.net/oauth/authorize");
737-
UNIT_ASSERT_STRING_CONTAINS(location, "response_type=code");
738-
UNIT_ASSERT_STRING_CONTAINS(location, "scope=openid");
739-
UNIT_ASSERT_STRING_CONTAINS(location, "client_id=" + settings.ClientId);
740-
UNIT_ASSERT_STRING_CONTAINS(location, "redirect_uri=https://" + hostProxy + "/auth/callback");
732+
UNIT_ASSERT_STRINGS_EQUAL(outgoingResponseEv->Response->Status, "400");
733+
UNIT_ASSERT_STRING_CONTAINS(outgoingResponseEv->Response->Body, "Unknown error has occurred. Please open the page again");
734+
741735
}
742736

743737
Y_UNIT_TEST(OpenIdConnectotWrongStateAuthorizationFlow) {
@@ -846,22 +840,11 @@ Y_UNIT_TEST_SUITE(Mvp) {
846840
"Content-Length: " + ToString(authorizationServerResponse.length()) + "\r\n\r\n" + authorizationServerResponse);
847841
runtime.Send(new IEventHandle(handle->Sender, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse(outgoingRequestEv->Request, incomingResponse)));
848842
auto outgoingResponseEv = runtime.GrabEdgeEvent<NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
849-
redirectStrategy.CheckRedirectStatus(outgoingResponseEv);
850-
TString location = redirectStrategy.GetRedirectUrl(outgoingResponseEv);
851-
UNIT_ASSERT_STRING_CONTAINS(location, "https://auth.test.net/oauth/authorize");
852-
UNIT_ASSERT_STRING_CONTAINS(location, "response_type=code");
853-
UNIT_ASSERT_STRING_CONTAINS(location, "scope=openid");
854-
UNIT_ASSERT_STRING_CONTAINS(location, "client_id=" + settings.ClientId);
855-
UNIT_ASSERT_STRING_CONTAINS(location, "redirect_uri=https://oidcproxy.net/auth/callback");
856-
857-
NHttp::TUrlParameters urlParameters(location);
858-
const TString newState = urlParameters["state"];
859-
860-
NHttp::THeaders headers(outgoingResponseEv->Response->Headers);
861-
UNIT_ASSERT(headers.Has("Set-Cookie"));
862-
const TStringBuf setCookie = headers.Get("Set-Cookie");
863-
UNIT_ASSERT_STRING_CONTAINS(setCookie, CreateNameYdbOidcCookie(settings.ClientSecret, newState));
864-
redirectStrategy.CheckSpecificHeaders(headers);
843+
UNIT_ASSERT_STRINGS_EQUAL(outgoingResponseEv->Response->Status, "302");
844+
const NHttp::THeaders headers(outgoingResponseEv->Response->Headers);
845+
UNIT_ASSERT(headers.Has("Location"));
846+
TStringBuf location = headers.Get("Location");
847+
UNIT_ASSERT_STRING_CONTAINS(location, "/requested/page");
865848
}
866849

867850
Y_UNIT_TEST(OpenIdConnectSessionServiceCreateAccessTokenInvalid) {

ydb/mvp/oidc_proxy/oidc_session_create.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@ THandlerSessionCreate::THandlerSessionCreate(const NActors::TActorId& sender,
2020
{}
2121

2222
void THandlerSessionCreate::Bootstrap(const NActors::TActorContext& ctx) {
23-
// NHttp::TUrlParameters urlParameters(Request->URL);
24-
// TString code = urlParameters["code"];
25-
// TString state = urlParameters["state"];
26-
27-
// NHttp::THeaders headers(Request->Headers);
28-
// NHttp::TCookies cookies(headers.Get("cookie"));
29-
30-
// if (IsStateValid(state, cookies, ctx) && !code.Empty()) {
31-
// RequestSessionToken(code, ctx);
32-
// } else {
33-
// NHttp::THttpOutgoingResponsePtr response = GetHttpOutgoingResponsePtr(Request, Settings, IsAjaxRequest);
34-
// ctx.Send(Sender, new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(response));
35-
// TBase::Die(ctx);
36-
// return;
37-
// }
3823
TryRestoreOidcSessionFromCookie(ctx);
3924
}
4025

@@ -126,7 +111,7 @@ void THandlerSessionCreate::TryRestoreOidcSessionFromCookie(const NActors::TActo
126111
NHttp::THeadersBuilder responseHeaders;
127112
responseHeaders.Set("Content-Type", "text/html");
128113
SetCORS(Request, &responseHeaders);
129-
const static TStringBuf BAD_REQUEST_HTML_PAGE = "<html><head><title>400 Bad Request</title></head><body bgcolor=\"white\"><center><h1>go back to the page</h1></center></body></html>";
114+
const static TStringBuf BAD_REQUEST_HTML_PAGE = "<html><head><title>400 Bad Request</title></head><body bgcolor=\"white\"><center><h1>Unknown error has occurred. Please open the page again</h1></center></body></html>";
130115
ctx.Send(Sender, new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(Request->CreateResponse("400", "Bad Request", responseHeaders, BAD_REQUEST_HTML_PAGE)));
131116
}
132117
Die(ctx);

ydb/mvp/oidc_proxy/openid_connect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ TRestoreOidcContextResult RestoreSessionStoredOnClientSide(const TString& state,
148148
expectedState = jsonState->GetStringRobust();
149149
}
150150
const NJson::TJsonValue* jsonRedirectUrl = nullptr;
151-
if (jsonValue.GetValuePointer("redirect_url", &jsonRedirectUrl)) {
151+
if (jsonValue.GetValuePointer("requested_address", &jsonRedirectUrl)) {
152152
redirectUrl = jsonRedirectUrl->GetStringRobust();
153153
} else {
154154
return TRestoreOidcContextResult({.IsSuccess = false,
155155
.IsErrorRetryable = false,
156-
.ErrorMessage = errorMessage << "Redirect url not found in cookie"});
156+
.ErrorMessage = errorMessage << "Requested address not found in cookie"});
157157
}
158158
const NJson::TJsonValue* jsonExpirationTime = nullptr;
159159
if (jsonValue.GetValuePointer("expiration_time", &jsonExpirationTime)) {

0 commit comments

Comments
 (0)