mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 17:15:30 +00:00
jira: hotfix for Cloud to use /rest/api/3/search/jql (#6489)
* jira: hotfix for Cloud to use /rest/api/3/search/jql in FindExistingIssue; add live test verifying v3 endpoint * jira: fix Cloud v3 search response handling (no total); set Self from base * fix lint error * tests(jira): apply De Morgan to satisfy staticcheck QF1001
This commit is contained in:
parent
d2cf69aebb
commit
8ea5061f5e
@ -437,6 +437,49 @@ func (i *Integration) FindExistingIssue(event *output.ResultEvent, useStatus boo
|
|||||||
jql = fmt.Sprintf("%s AND status != \"%s\"", jql, i.options.StatusNot)
|
jql = fmt.Sprintf("%s AND status != \"%s\"", jql, i.options.StatusNot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hotfix for Jira Cloud: use Enhanced Search API (v3) to avoid deprecated v2 path
|
||||||
|
if i.options.Cloud {
|
||||||
|
params := url.Values{}
|
||||||
|
params.Set("jql", jql)
|
||||||
|
params.Set("maxResults", "1")
|
||||||
|
params.Set("fields", "id,key")
|
||||||
|
|
||||||
|
req, err := i.jira.NewRequest("GET", "/rest/api/3/search/jql"+"?"+params.Encode(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return jira.Issue{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var searchResult struct {
|
||||||
|
Issues []struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Key string `json:"key"`
|
||||||
|
} `json:"issues"`
|
||||||
|
IsLast bool `json:"isLast"`
|
||||||
|
NextPageToken string `json:"nextPageToken"`
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := i.jira.Do(req, &searchResult)
|
||||||
|
if err != nil {
|
||||||
|
var data string
|
||||||
|
if resp != nil && resp.Body != nil {
|
||||||
|
d, _ := io.ReadAll(resp.Body)
|
||||||
|
data = string(d)
|
||||||
|
}
|
||||||
|
return jira.Issue{}, fmt.Errorf("%w => %s", err, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(searchResult.Issues) == 0 {
|
||||||
|
return jira.Issue{}, nil
|
||||||
|
}
|
||||||
|
first := searchResult.Issues[0]
|
||||||
|
base := strings.TrimRight(i.options.URL, "/")
|
||||||
|
return jira.Issue{
|
||||||
|
ID: first.ID,
|
||||||
|
Key: first.Key,
|
||||||
|
Self: fmt.Sprintf("%s/rest/api/3/issue/%s", base, first.ID),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
searchOptions := &jira.SearchOptionsV2{
|
searchOptions := &jira.SearchOptionsV2{
|
||||||
MaxResults: 1, // if any issue exists, then we won't create a new one
|
MaxResults: 1, // if any issue exists, then we won't create a new one
|
||||||
Fields: []string{"summary", "description", "issuetype", "status", "priority", "project"},
|
Fields: []string{"summary", "description", "issuetype", "status", "priority", "project"},
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package jira
|
package jira
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -9,9 +11,23 @@ import (
|
|||||||
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/stringslice"
|
"github.com/projectdiscovery/nuclei/v3/pkg/model/types/stringslice"
|
||||||
"github.com/projectdiscovery/nuclei/v3/pkg/output"
|
"github.com/projectdiscovery/nuclei/v3/pkg/output"
|
||||||
"github.com/projectdiscovery/nuclei/v3/pkg/reporting/trackers/filters"
|
"github.com/projectdiscovery/nuclei/v3/pkg/reporting/trackers/filters"
|
||||||
|
"github.com/projectdiscovery/retryablehttp-go"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type recordingTransport struct {
|
||||||
|
inner http.RoundTripper
|
||||||
|
paths []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rt *recordingTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
if rt.inner == nil {
|
||||||
|
rt.inner = http.DefaultTransport
|
||||||
|
}
|
||||||
|
rt.paths = append(rt.paths, req.URL.Path)
|
||||||
|
return rt.inner.RoundTrip(req)
|
||||||
|
}
|
||||||
|
|
||||||
func TestLinkCreation(t *testing.T) {
|
func TestLinkCreation(t *testing.T) {
|
||||||
jiraIntegration := &Integration{}
|
jiraIntegration := &Integration{}
|
||||||
link := jiraIntegration.CreateLink("ProjectDiscovery", "https://projectdiscovery.io")
|
link := jiraIntegration.CreateLink("ProjectDiscovery", "https://projectdiscovery.io")
|
||||||
@ -188,3 +204,67 @@ Priority: {{if eq .Severity "critical"}}{{.Severity | upper}}{{else}}{{.Severity
|
|||||||
require.Contains(t, result, "CRITICAL")
|
require.Contains(t, result, "CRITICAL")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Live test to verify SearchV2JQL hits /rest/api/3/search/jql when creds are provided via env
|
||||||
|
func TestJiraLive_SearchV2UsesJqlEndpoint(t *testing.T) {
|
||||||
|
jiraURL := os.Getenv("JIRA_URL")
|
||||||
|
jiraEmail := os.Getenv("JIRA_EMAIL")
|
||||||
|
jiraAccountID := os.Getenv("JIRA_ACCOUNT_ID")
|
||||||
|
jiraToken := os.Getenv("JIRA_TOKEN")
|
||||||
|
jiraPAT := os.Getenv("JIRA_PAT")
|
||||||
|
jiraProjectName := os.Getenv("JIRA_PROJECT_NAME")
|
||||||
|
jiraProjectID := os.Getenv("JIRA_PROJECT_ID")
|
||||||
|
jiraStatusNot := os.Getenv("JIRA_STATUS_NOT")
|
||||||
|
jiraCloud := os.Getenv("JIRA_CLOUD")
|
||||||
|
|
||||||
|
if jiraURL == "" || (jiraPAT == "" && jiraToken == "") || (jiraEmail == "" && jiraAccountID == "") || (jiraProjectName == "" && jiraProjectID == "") {
|
||||||
|
t.Skip("live Jira test skipped: missing JIRA_* env vars")
|
||||||
|
}
|
||||||
|
|
||||||
|
statusNot := jiraStatusNot
|
||||||
|
if statusNot == "" {
|
||||||
|
statusNot = "Done"
|
||||||
|
}
|
||||||
|
|
||||||
|
isCloud := !strings.EqualFold(jiraCloud, "false") && jiraCloud != "0"
|
||||||
|
|
||||||
|
rec := &recordingTransport{}
|
||||||
|
rc := retryablehttp.NewClient(retryablehttp.DefaultOptionsSingle)
|
||||||
|
rc.HTTPClient.Transport = rec
|
||||||
|
|
||||||
|
opts := &Options{
|
||||||
|
Cloud: isCloud,
|
||||||
|
URL: jiraURL,
|
||||||
|
Email: jiraEmail,
|
||||||
|
AccountID: jiraAccountID,
|
||||||
|
Token: jiraToken,
|
||||||
|
PersonalAccessToken: jiraPAT,
|
||||||
|
ProjectName: jiraProjectName,
|
||||||
|
ProjectID: jiraProjectID,
|
||||||
|
IssueType: "Task",
|
||||||
|
StatusNot: statusNot,
|
||||||
|
HttpClient: rc,
|
||||||
|
}
|
||||||
|
|
||||||
|
integration, err := New(opts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
event := &output.ResultEvent{
|
||||||
|
Host: "example.com",
|
||||||
|
Info: model.Info{
|
||||||
|
Name: "Nuclei Live Verify",
|
||||||
|
SeverityHolder: severity.Holder{Severity: severity.Low},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = integration.FindExistingIssue(event, true)
|
||||||
|
|
||||||
|
var hitSearchV2 bool
|
||||||
|
for _, p := range rec.paths {
|
||||||
|
if strings.HasSuffix(p, "/rest/api/3/search/jql") {
|
||||||
|
hitSearchV2 = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
require.True(t, hitSearchV2, "expected client to call /rest/api/3/search/jql, got paths: %v", rec.paths)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user