Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure relative paths before resolving #32

Merged
merged 2 commits into from
Jan 15, 2024
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
11 changes: 9 additions & 2 deletions pkg/c8y/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions test/c8y_test/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading