This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 80851803 fix: jira test connection username check (#2404)
80851803 is described below
commit 80851803513c687fa87fdc168e8a87b4f1c125d9
Author: mappjzc <[email protected]>
AuthorDate: Mon Jul 4 11:30:29 2022 +0800
fix: jira test connection username check (#2404)
Add userSearch to check weather the username all right at connction test.
Nddtfjiang <[email protected]>
---
plugins/jira/api/connection.go | 34 ++++++++++++++++++++++++++++++++--
plugins/jira/models/response_type.go | 4 ++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/plugins/jira/api/connection.go b/plugins/jira/api/connection.go
index f11c5a26..881ebfdd 100644
--- a/plugins/jira/api/connection.go
+++ b/plugins/jira/api/connection.go
@@ -59,10 +59,12 @@ func TestConnection(input *core.ApiResourceInput)
(*core.ApiResourceOutput, erro
if err != nil {
return nil, err
}
+ // serverInfo checking
res, err := apiClient.Get("api/2/serverInfo", nil, nil)
if err != nil {
return nil, err
}
+ serverInfoFail := "You are failed on test 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)
@@ -85,12 +87,40 @@ func TestConnection(input *core.ApiResourceInput)
(*core.ApiResourceOutput, erro
if resBody.DeploymentType == models.DeploymentServer {
// only support 8.x.x or higher
if versions := resBody.VersionNumbers; len(versions) == 3 &&
versions[0] < 8 {
- return nil, fmt.Errorf("Support JIRA Server 8+ only")
+ return nil, fmt.Errorf("%s Support JIRA Server 8+
only", serverInfoFail)
}
}
if res.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("unexpected status code: %d",
res.StatusCode)
+ return nil, fmt.Errorf("%s unexpected status code: %d",
serverInfoFail, res.StatusCode)
}
+
+ // usersSearch checking
+ usersSearchFail := "You are suceess on test the serverInfo but failed
to test on userSearch"
+ res, err = apiClient.Get("api/3/users/search", nil, nil)
+ if err != nil {
+ return nil, fmt.Errorf("%s %s", usersSearchFail, err)
+ }
+ usersSearchFail += ": [ " + res.Request.URL.String() + " ]"
+
+ errMsg := ""
+ if res.StatusCode == http.StatusForbidden {
+ resErrBody := &models.JiraErrorInfo{}
+ err = helper.UnmarshalResponse(res, resErrBody)
+ if err != nil {
+ return nil, fmt.Errorf("%s Unexpected status code:
%d,and UnmarshalResponse error %s", usersSearchFail, res.StatusCode, err)
+ }
+ for _, em := range resErrBody.ErrorMessages {
+ if em == "error.no-permission" {
+ return nil, fmt.Errorf("%s We get the error %s
,it might you use the right token(password) but with the wrong username.please
check your password", usersSearchFail, em)
+ }
+ errMsg += em + " \r\n"
+ }
+ }
+
+ if res.StatusCode != http.StatusOK {
+ return nil, fmt.Errorf("%s Unexpected [%s] status code: %d %s",
usersSearchFail, res.Request.URL, res.StatusCode, errMsg)
+ }
+
return nil, nil
}
diff --git a/plugins/jira/models/response_type.go
b/plugins/jira/models/response_type.go
index 0fcd4236..368a4bfd 100644
--- a/plugins/jira/models/response_type.go
+++ b/plugins/jira/models/response_type.go
@@ -36,6 +36,10 @@ type JiraServerInfo struct {
VersionNumbers []int `json:"versionNumbers"`
}
+type JiraErrorInfo struct {
+ ErrorMessages []string `json:"errorMessages"`
+}
+
type ApiMyselfResponse struct {
AccountId string
DisplayName string