From baa9daccabb2cd78c7f05aec1a4d805d512be209 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Mon, 15 Jan 2024 13:26:35 +0100 Subject: [PATCH 1/2] fix: ensure relative paths before resolving Avoid problems where the user provides a fixed path (e.g. a leading slash), however it should always be resolved as a relative path as the host could be set to localhost:8001/c8y which uses a common path prefix. --- pkg/c8y/client.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/c8y/client.go b/pkg/c8y/client.go index 4f982226..c99ef824 100644 --- a/pkg/c8y/client.go +++ b/pkg/c8y/client.go @@ -764,7 +764,7 @@ func (c *Client) NewRequest(method, path string, query string, body interface{}) return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL) } - rel := &url.URL{Path: path} + rel := &url.URL{Path: ensureRelativePath(path)} if query != "" { rel.RawQuery = query } @@ -820,13 +820,20 @@ func (c *Client) SetDomain(v string) { } } +// ensureRelativePath returns a relative path variant of the input path. +// e.g. /test/path => test/path +func ensureRelativePath(u string) string { + return strings.TrimPrefix(u, "/") +} + // NewRequestWithoutAuth returns a request with the required additional base url, accept and user-agent.NewRequest func (c *Client) NewRequestWithoutAuth(method, path string, query string, body interface{}) (*http.Request, error) { if !strings.HasSuffix(c.BaseURL.Path, "/") { return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL) } - rel := &url.URL{Path: path} + // Note: Ensure path is a relative address + rel := &url.URL{Path: ensureRelativePath(path)} if query != "" { rel.RawQuery = query } From 6dd90cb535a8f939c4350c481a5fc55c65b81e21 Mon Sep 17 00:00:00 2001 From: Reuben Miller Date: Mon, 15 Jan 2024 17:00:08 +0100 Subject: [PATCH 2/2] test: skip test due to server error --- test/c8y_test/event_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/c8y_test/event_test.go b/test/c8y_test/event_test.go index ba05b33a..805f0f54 100644 --- a/test/c8y_test/event_test.go +++ b/test/c8y_test/event_test.go @@ -105,6 +105,7 @@ func TestEventService_Update(t *testing.T) { } func TestEventService_Delete(t *testing.T) { + t.Skip("Skipping due to ci issue on 1020.40.0 on staging latest. https://cumulocity.atlassian.net/browse/MTM-57310") client := createTestClient() testDevice, err := createRandomTestDevice()