Skip to content

Commit f6dd8db

Browse files
committed
Fix tests
1 parent 2341a2a commit f6dd8db

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
@@ -667,15 +667,9 @@ Y_UNIT_TEST_SUITE(Mvp) {
667667

668668
TAutoPtr<IEventHandle> handle;
669669
NHttp::TEvHttpProxy::TEvHttpOutgoingResponse* outgoingResponseEv = runtime.GrabEdgeEvent<NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
670-
UNIT_ASSERT_STRINGS_EQUAL(outgoingResponseEv->Response->Status, "302");
671-
const NHttp::THeaders headers(outgoingResponseEv->Response->Headers);
672-
UNIT_ASSERT(headers.Has("Location"));
673-
TString location = TString(headers.Get("Location"));
674-
UNIT_ASSERT_STRING_CONTAINS(location, "https://auth.test.net/oauth/authorize");
675-
UNIT_ASSERT_STRING_CONTAINS(location, "response_type=code");
676-
UNIT_ASSERT_STRING_CONTAINS(location, "scope=openid");
677-
UNIT_ASSERT_STRING_CONTAINS(location, "client_id=" + settings.ClientId);
678-
UNIT_ASSERT_STRING_CONTAINS(location, "redirect_uri=https://" + hostProxy + "/auth/callback");
670+
UNIT_ASSERT_STRINGS_EQUAL(outgoingResponseEv->Response->Status, "400");
671+
UNIT_ASSERT_STRING_CONTAINS(outgoingResponseEv->Response->Body, "Unknown error has occurred. Please open the page again");
672+
679673
}
680674

681675
Y_UNIT_TEST(OpenIdConnectotWrongStateAuthorizationFlow) {
@@ -784,22 +778,11 @@ Y_UNIT_TEST_SUITE(Mvp) {
784778
"Content-Length: " + ToString(authorizationServerResponse.length()) + "\r\n\r\n" + authorizationServerResponse);
785779
runtime.Send(new IEventHandle(handle->Sender, edge, new NHttp::TEvHttpProxy::TEvHttpIncomingResponse(outgoingRequestEv->Request, incomingResponse)));
786780
auto outgoingResponseEv = runtime.GrabEdgeEvent<NHttp::TEvHttpProxy::TEvHttpOutgoingResponse>(handle);
787-
redirectStrategy.CheckRedirectStatus(outgoingResponseEv);
788-
TString location = redirectStrategy.GetRedirectUrl(outgoingResponseEv);
789-
UNIT_ASSERT_STRING_CONTAINS(location, "https://auth.test.net/oauth/authorize");
790-
UNIT_ASSERT_STRING_CONTAINS(location, "response_type=code");
791-
UNIT_ASSERT_STRING_CONTAINS(location, "scope=openid");
792-
UNIT_ASSERT_STRING_CONTAINS(location, "client_id=" + settings.ClientId);
793-
UNIT_ASSERT_STRING_CONTAINS(location, "redirect_uri=https://oidcproxy.net/auth/callback");
794-
795-
NHttp::TUrlParameters urlParameters(location);
796-
const TString newState = urlParameters["state"];
797-
798-
NHttp::THeaders headers(outgoingResponseEv->Response->Headers);
799-
UNIT_ASSERT(headers.Has("Set-Cookie"));
800-
const TStringBuf setCookie = headers.Get("Set-Cookie");
801-
UNIT_ASSERT_STRING_CONTAINS(setCookie, CreateNameYdbOidcCookie(settings.ClientSecret, newState));
802-
redirectStrategy.CheckSpecificHeaders(headers);
781+
UNIT_ASSERT_STRINGS_EQUAL(outgoingResponseEv->Response->Status, "302");
782+
const NHttp::THeaders headers(outgoingResponseEv->Response->Headers);
783+
UNIT_ASSERT(headers.Has("Location"));
784+
TStringBuf location = headers.Get("Location");
785+
UNIT_ASSERT_STRING_CONTAINS(location, "/requested/page");
803786
}
804787

805788
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)