From 9b78125ffd84fdad21c8d19f1a496331d3fd20be Mon Sep 17 00:00:00 2001 From: ddl-rliu <140021987+ddl-rliu@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:20:17 -0700 Subject: [PATCH] fix: Modify the callback URL string in auth flow, to support custom base URLs in deployments (#5192) * x Signed-off-by: ddl-rliu x Signed-off-by: ddl-rliu x Signed-off-by: ddl-rliu * x Signed-off-by: ddl-rliu --------- Signed-off-by: ddl-rliu Signed-off-by: Eduardo Apolinario Co-authored-by: Eduardo Apolinario --- flyteadmin/auth/auth_context.go | 2 +- flyteadmin/auth/auth_context_test.go | 51 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 flyteadmin/auth/auth_context_test.go diff --git a/flyteadmin/auth/auth_context.go b/flyteadmin/auth/auth_context.go index b6fd3dd4da..0e21efacde 100644 --- a/flyteadmin/auth/auth_context.go +++ b/flyteadmin/auth/auth_context.go @@ -29,7 +29,7 @@ const ( ) var ( - callbackRelativeURL = config.MustParseURL("/callback") + callbackRelativeURL = config.MustParseURL("callback") rootRelativeURL = config.MustParseURL("/") ) diff --git a/flyteadmin/auth/auth_context_test.go b/flyteadmin/auth/auth_context_test.go new file mode 100644 index 0000000000..ed34d92026 --- /dev/null +++ b/flyteadmin/auth/auth_context_test.go @@ -0,0 +1,51 @@ +package auth + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "golang.org/x/oauth2" + + "github.com/flyteorg/flyte/flyteadmin/auth/config" +) + +func TestOAuth2ClientConfig(t *testing.T) { + authCtx := Context{ + oauth2Client: &oauth2.Config{}, + } + + type test struct { + name string + url string + expectedRedirectURL string + } + tests := []test{ + { + name: "simple publicUrl", + url: "https://flyte.com", + expectedRedirectURL: "https://flyte.com/callback", + }, + { + name: "custom subpath", + url: "https://flyte.com/custom-subpath/console", + expectedRedirectURL: "https://flyte.com/custom-subpath/callback", + }, + { + name: "complex publicUrl", + url: "https://flyte.com/login?redirect_url=https://flyte.com/console/select-project", + expectedRedirectURL: "https://flyte.com/callback", + }, + { + name: "complex publicUrl with custom subpath", + url: "https://flyte.com/custom-subpath/login?redirect_url=https://flyte.com/custom-subpath/console/select-project", + expectedRedirectURL: "https://flyte.com/custom-subpath/callback", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := authCtx.OAuth2ClientConfig(config.MustParseURL(tt.url)) + assert.Equal(t, tt.expectedRedirectURL, cfg.RedirectURL) + }) + } +}