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

[jira test connection api]fix: invalid url detection not working correctly #7016

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
26 changes: 13 additions & 13 deletions backend/plugins/jira/api/connection_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ func testConnection(ctx context.Context, connection models.JiraConn) (*JiraTestC
// serverInfo checking
res, err := apiClient.Get("api/2/serverInfo", nil, nil)
if err != nil {
// check if `/rest/` was missing
if strings.Contains(err.Error(), "status code 404") && !strings.HasSuffix(connection.Endpoint, "/rest/") {
endpointUrl, err := url.Parse(connection.Endpoint)
if err != nil {
return nil, errors.Convert(err)
}
refUrl, err := url.Parse("/rest/")
if err != nil {
return nil, errors.Convert(err)
}
restUrl := endpointUrl.ResolveReference(refUrl)
return nil, errors.NotFound.New(fmt.Sprintf("Seems like an invalid Endpoint URL, please try %s", restUrl.String()))
}
return nil, err
}
serverInfoFail := "Failed testing the serverInfo: [ " + res.Request.URL.String() + " ]"
// check if `/rest/` was missing
if res.StatusCode == http.StatusNotFound && !strings.HasSuffix(connection.Endpoint, "/rest/") {
endpointUrl, err := url.Parse(connection.Endpoint)
if err != nil {
return nil, errors.Convert(err)
}
refUrl, err := url.Parse("/rest/")
if err != nil {
return nil, errors.Convert(err)
}
restUrl := endpointUrl.ResolveReference(refUrl)
return nil, errors.NotFound.New(fmt.Sprintf("Seems like an invalid Endpoint URL, please try %s", restUrl.String()))
}
if res.StatusCode == http.StatusUnauthorized {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix didn't solve the problem, the problem is apiClient.Get overwritten response status code > 400 to 400, so all the error handling code in testConnection of different plugins won't work as they used to be.
This "Error username/password" check will not work, as the res.StatusCode will always be 400 when upstream returned 401 error.

return nil, errors.HttpStatus(http.StatusBadRequest).New("Error username/password")
}
Expand Down
Loading