Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/kiali/kiali.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,23 @@ func (k *Kiali) validateAndGetURL(endpoint string) (string, error) {
if endpoint == "" {
return baseURL.String(), nil
}
ref, err := url.Parse(endpoint)
// Parse the endpoint to extract path, query, and fragment
endpoint = strings.TrimSpace(endpoint)
endpointURL, err := url.Parse(endpoint)

if err != nil {
return "", fmt.Errorf("invalid endpoint path: %w", err)
}
return baseURL.ResolveReference(ref).String(), nil
resultURL, err := url.JoinPath(baseURL.String(), endpointURL.Path)
if err != nil {
return "", fmt.Errorf("failed to join kiali base URL with endpoint path: %w", err)
}

u, _ := url.Parse(resultURL)
u.RawQuery = endpointURL.RawQuery
u.Fragment = endpointURL.Fragment

return u.String(), nil
}

func (k *Kiali) createHTTPClient() *http.Client {
Expand Down
30 changes: 30 additions & 0 deletions pkg/kiali/kiali_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@ func (s *KialiSuite) TestValidateAndGetURL() {
s.Equal("2", u.Query().Get("y"), "Unexpected query parameter y")
})
})

s.Run("With base URL containing path", func() {
s.Config = test.Must(config.ReadToml([]byte(`
[toolset_configs.kiali]
url = "http://kiali-istio-system.apps-crc.testing/kiali"
insecure = true
`)))
k := NewKiali(s.Config, s.MockServer.Config())

s.Run("concatenates base path with endpoint", func() {
full, err := k.validateAndGetURL("/api/namespaces")
s.Require().NoError(err, "Expected no error validating URL")
s.Equal("http://kiali-istio-system.apps-crc.testing/kiali/api/namespaces", full, "Unexpected full URL")
})

s.Run("handles endpoint without leading slash", func() {
full, err := k.validateAndGetURL("api/namespaces")
s.Require().NoError(err, "Expected no error validating URL")
s.Equal("http://kiali-istio-system.apps-crc.testing/kiali/api/namespaces", full, "Unexpected full URL")
})

s.Run("preserves query parameters with base path", func() {
full, err := k.validateAndGetURL("/api/namespaces?health=true")
s.Require().NoError(err, "Expected no error validating URL")
u, err := url.Parse(full)
s.Require().NoError(err, "Expected to parse full URL")
s.Equal("/kiali/api/namespaces", u.Path, "Unexpected path in parsed URL")
s.Equal("true", u.Query().Get("health"), "Unexpected query parameter health")
})
})
}

// CurrentAuthorizationHeader behavior is now implicit via executeRequest using Manager.BearerToken
Expand Down