From bb7606652c9fca6012170602e3ff7cc6d6db502e Mon Sep 17 00:00:00 2001 From: ddl-rliu Date: Fri, 5 Apr 2024 15:49:14 -0700 Subject: [PATCH] x Signed-off-by: ddl-rliu x Signed-off-by: ddl-rliu x --- flyteadmin/auth/auth_context.go | 2 +- flyteadmin/auth/auth_context_test.go | 41 ++++++++++++++++++++++++++++ 2 files changed, 42 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..4a3105ad4b --- /dev/null +++ b/flyteadmin/auth/auth_context_test.go @@ -0,0 +1,41 @@ +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", + }, + } + + 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) + }) + } +}