From eb8121f5678adabb2c6f1a27e20ba2b627163f47 Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Wed, 28 Aug 2024 12:30:08 -0300 Subject: [PATCH 1/3] fix: oauth path building --- cli/config/config.go | 3 +-- cli/pkg/oauth/oauth.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/config/config.go b/cli/config/config.go index d6ad567bdb..a8475ce71d 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -43,8 +43,7 @@ type Config struct { } func (c Config) OAuthEndpoint() string { - return fmt.Sprintf("%s%s", c.URL(), c.Path()) - + return path.Join(c.URL(), c.Path()) } func (c Config) URL() string { diff --git a/cli/pkg/oauth/oauth.go b/cli/pkg/oauth/oauth.go index afb148a82f..449a0b1a71 100644 --- a/cli/pkg/oauth/oauth.go +++ b/cli/pkg/oauth/oauth.go @@ -6,6 +6,7 @@ import ( "io" "net" "net/http" + "path" "sync" "github.com/kubeshop/tracetest/cli/ui" @@ -58,7 +59,7 @@ func (s *OAuthServer) GetAuthJWT() error { return fmt.Errorf("failed to start oauth server: %w", err) } - loginUrl := fmt.Sprintf("%soauth?callback=%s", s.frontendEndpoint, url) + loginUrl := path.Join(s.frontendEndpoint, fmt.Sprintf("oauth?callback=%s", url)) ui := ui.DefaultUI err = ui.OpenBrowser(loginUrl) From cbe91b0ea8ddca8ae4fb4284846858b31d885034 Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Wed, 28 Aug 2024 12:51:11 -0300 Subject: [PATCH 2/3] fix paths --- cli/config/config.go | 2 +- cli/config/configurator.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/config/config.go b/cli/config/config.go index a8475ce71d..941b0bd8e7 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -43,7 +43,7 @@ type Config struct { } func (c Config) OAuthEndpoint() string { - return path.Join(c.URL(), c.Path()) + return fmt.Sprintf("%s%s", c.URL(), c.Path()) } func (c Config) URL() string { diff --git a/cli/config/configurator.go b/cli/config/configurator.go index 0ed8fd644f..999e4286cc 100644 --- a/cli/config/configurator.go +++ b/cli/config/configurator.go @@ -156,6 +156,7 @@ func (c Configurator) getServerURL(prev *Config) (string, error) { } func (c Configurator) createConfig(serverURL string) (Config, error) { + serverURL = strings.TrimSuffix(serverURL, "/") scheme, endpoint, path, err := ParseServerURL(serverURL) if err != nil { return Config{}, err From 920f0e8beaf1c3a8f5db82f2875ded05fdce3d8f Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Wed, 28 Aug 2024 13:02:08 -0300 Subject: [PATCH 3/3] replace path.Join with url.JoinPath --- cli/pkg/oauth/oauth.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/pkg/oauth/oauth.go b/cli/pkg/oauth/oauth.go index 449a0b1a71..4e5fb7f5a3 100644 --- a/cli/pkg/oauth/oauth.go +++ b/cli/pkg/oauth/oauth.go @@ -6,7 +6,7 @@ import ( "io" "net" "net/http" - "path" + neturl "net/url" "sync" "github.com/kubeshop/tracetest/cli/ui" @@ -59,7 +59,10 @@ func (s *OAuthServer) GetAuthJWT() error { return fmt.Errorf("failed to start oauth server: %w", err) } - loginUrl := path.Join(s.frontendEndpoint, fmt.Sprintf("oauth?callback=%s", url)) + loginUrl, err := neturl.JoinPath(s.frontendEndpoint, fmt.Sprintf("oauth?callback=%s", url)) + if err != nil { + return fmt.Errorf("could not build path: %w", err) + } ui := ui.DefaultUI err = ui.OpenBrowser(loginUrl)