Skip to content

Commit

Permalink
Fixed an issue that occurred with the federation url had not host but…
Browse files Browse the repository at this point in the history
… also had a path
  • Loading branch information
turetske committed Aug 12, 2024
1 parent 9bcb8e8 commit 6199f70
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions utils/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()))
})
}
5 changes: 5 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6199f70

Please sign in to comment.