Skip to content

Commit

Permalink
fix: Modify the callback URL string in auth flow, to support custom b…
Browse files Browse the repository at this point in the history
…ase URLs in deployments (#5192)

* x

Signed-off-by: ddl-rliu <[email protected]>

x

Signed-off-by: ddl-rliu <[email protected]>

x

Signed-off-by: ddl-rliu <[email protected]>

* x

Signed-off-by: ddl-rliu <[email protected]>

---------

Signed-off-by: ddl-rliu <[email protected]>
Signed-off-by: Eduardo Apolinario <[email protected]>
Co-authored-by: Eduardo Apolinario <[email protected]>
  • Loading branch information
ddl-rliu and eapolinario authored Jun 13, 2024
1 parent 653ca85 commit 9b78125
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flyteadmin/auth/auth_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
)

var (
callbackRelativeURL = config.MustParseURL("/callback")
callbackRelativeURL = config.MustParseURL("callback")
rootRelativeURL = config.MustParseURL("/")
)

Expand Down
51 changes: 51 additions & 0 deletions flyteadmin/auth/auth_context_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit 9b78125

Please sign in to comment.