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