From 6199f703c47d9b82bfc4b7712fb5dcd2b202fe28 Mon Sep 17 00:00:00 2001 From: Emma Turetsky Date: Mon, 12 Aug 2024 18:16:26 +0000 Subject: [PATCH] Fixed an issue that occurred with the federation url had not host but also had a path --- utils/client_test.go | 16 ++++++++++++++++ utils/utils.go | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/utils/client_test.go b/utils/client_test.go index 44358f9af..38bef2ca4 100644 --- a/utils/client_test.go +++ b/utils/client_test.go @@ -254,6 +254,14 @@ func TestUrlWithFederation(t *testing.T) { assert.Equal(t, pelUrl, str) }) + t.Run("testFederationNoHost", func(t *testing.T) { + viper.Set(param.Federation_DiscoveryUrl.GetName(), "somefederation.org") + namespaceOnly := "/namespace/test.txt" + str, err := UrlWithFederation(namespaceOnly) + assert.NoError(t, err) + assert.Equal(t, pelUrl, str) + }) + t.Run("testFederationWithFedHost", func(t *testing.T) { viper.Set(param.Federation_DiscoveryUrl.GetName(), "https://somefederation.org") namespaceOnly := "/namespace/test.txt" @@ -269,4 +277,12 @@ func TestUrlWithFederation(t *testing.T) { assert.Error(t, err) assert.EqualError(t, err, fmt.Sprintf("provided federation url %s has a path component", param.Federation_DiscoveryUrl.GetString())) }) + + t.Run("testFederationPathComponentWithHost", func(t *testing.T) { + viper.Set(param.Federation_DiscoveryUrl.GetName(), "https://somefederation.org/path") + namespaceOnly := "/namespace/test.txt" + _, err := UrlWithFederation(namespaceOnly) + assert.Error(t, err) + assert.EqualError(t, err, fmt.Sprintf("provided federation url %s has a path component", param.Federation_DiscoveryUrl.GetString())) + }) } diff --git a/utils/utils.go b/utils/utils.go index d1d3654fd..a2d3464f1 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -149,6 +149,11 @@ func UrlWithFederation(remoteUrl string) (string, error) { newErr := errors.New(fmt.Sprintf("error parsing discovery url: %s", err)) return remoteUrl, newErr } + if parsedDiscUrl.Scheme == "" { + parsedDiscUrl.Scheme = "https" + updatedDiscString := parsedDiscUrl.String() + parsedDiscUrl, _ = url.Parse(updatedDiscString) + } if parsedDiscUrl.Path != "" { newErr := errors.New(fmt.Sprintf("provided federation url %s has a path component", param.Federation_DiscoveryUrl.GetString())) return remoteUrl, newErr