Skip to content

Commit

Permalink
minor: release changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mathild3r committed Oct 12, 2021
1 parent 10b3447 commit 0d4e906
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Use the binaries from [the release page](https://github.com/snyk-tech-services/j
-severity=<critical|high|medium|low> // Optional. Severity threshold to open tickets for. Defaults to low.
-maturityFilter=[mature,proof-of-concept,no-known-exploit,no-data] // Optional. include only maturity level(s). Separated by commas
-type=<all|vuln|license> // Optional. Issue type to open tickets for. Defaults to all.
-assigneeId=<123abc456def789> // Optional. Jira ID of user to assign tickets to.
-assigneeId=<123abc456def789> // Optional. Jira ID of user to assign tickets to. Note: Do not use assigneeName and assigneeId at the same time
-assigneeName=<AccountName> // Optional. Jira Name of user to assign tickets to. Note: Do not use assigneeName and assigneeId at the same time
-priorityIsSeverity // Optional. Set the ticket priority to be based on severity (defaults: Low|Medium|High|Critical=>Low|Medium|High|Highest)
-labels=<IssueLabel1>,IssueLabel2 // Optional. Set JIRA ticket labels
-priorityScoreThreshold=[0-1000] // Optional. Your min priority score threshold
Expand Down
2 changes: 1 addition & 1 deletion fixtures/results/jiraTicketWithCustomPriorityMapping.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{},"priority":{"name":"not too bad"}}}
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"priority":{"name":"not too bad"}}}
2 changes: 1 addition & 1 deletion fixtures/results/jiraTicketWithLabels.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{},"labels":["Label1","Label2"]}}
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"labels":["Label1","Label2"]}}
2 changes: 1 addition & 1 deletion fixtures/results/jiraTicketWithPriorityMapping.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{},"priority":{"name":"Medium"}}}
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"priority":{"name":"Medium"}}}
2 changes: 1 addition & 1 deletion fixtures/results/jiraTicketWithoutLabels.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{}}}
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{"accountId":"12345"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{"name":"admin"}}}
26 changes: 19 additions & 7 deletions jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type JiraIssue struct {
Fields Field `json:"fields"`
}

// Some info on ommit : https://www.sohamkamani.com/golang/omitempty/#values-that-cannot-be-omitted
type PriorityType struct {
Name string `json:"name,omitempty"`
}
Expand All @@ -27,14 +28,15 @@ type Field struct {
Summary string `json:"summary"`
Description string `json:"description"`
IssueTypes IssueType `json:"issuetype"`
Assignees Assignee `json:"assignee,omitempty"`
Assignees *Assignee `json:"assignee,omitempty"`
Priority *PriorityType `json:"priority,omitempty"`
Labels []string `json:"labels,omitempty"`
}

// Assignee is the account ID of the JIRA user to assign tickets to
type Assignee struct {
ID string `json:"accountId,omitempty"`
Name string `json:"name,omitempty"`
AccountId string `json:"accountId,omitempty"`
}

// Project is the JIRA project ID
Expand Down Expand Up @@ -68,7 +70,7 @@ func getJiraTickets(endpointAPI string, orgID string, projectID string, token st
return tickRefs
}

func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeID string, labels string, projectInfo jsn.Json, vulnForJira interface{}, priorityIsSeverity bool) ([]byte, error) {
func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeName string, assigneeID string, labels string, projectInfo jsn.Json, vulnForJira interface{}, priorityIsSeverity bool) ([]byte, error) {

jsonVuln, _ := jsn.NewJson(vulnForJira)
vulnID := jsonVuln.K("id").String().Value
Expand All @@ -77,7 +79,6 @@ func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectI

jiraTicket.Fields.Projects.ID = jiraProjectID
jiraTicket.Fields.IssueTypes.Name = jiraTicketType
jiraTicket.Fields.Assignees.ID = assigneeID

projectInfoId := projectInfo.K("id").String().Value

Expand All @@ -88,6 +89,17 @@ func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectI
if labels != "" {
jiraTicket.Fields.Labels = strings.Split(labels, ",")
}

if assigneeName != "" {
var assignee Assignee
assignee.Name = assigneeName
jiraTicket.Fields.Assignees = &assignee
} else if assigneeID != "" {
var assignee Assignee
assignee.AccountId = assigneeID
jiraTicket.Fields.Assignees = &assignee
}

if priorityIsSeverity {
var priority PriorityType
jiraMappingEnvVarName := fmt.Sprintf("SNYK_JIRA_PRIORITY_FOR_%s_VULN", strings.ToUpper(jsonVuln.K("issueData").K("severity").String().Value))
Expand Down Expand Up @@ -139,7 +151,7 @@ func displayErrorForIssue(vulnForJira interface{}, endpointAPI string) string {
return vulnID + "\n"
}

func openJiraTickets(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeID string, labels string, projectInfo jsn.Json, vulnsForJira map[string]interface{}, priorityIsSeverity bool) (int, string, string) {
func openJiraTickets(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeName string, assigneeID string, labels string, projectInfo jsn.Json, vulnsForJira map[string]interface{}, priorityIsSeverity bool) (int, string, string) {
fullResponseDataAggregated := ""
fullListNotCreatedIssue := ""
RequestFailed := false
Expand All @@ -148,7 +160,7 @@ func openJiraTickets(endpointAPI string, orgID string, token string, jiraProject

for _, vulnForJira := range vulnsForJira {
RequestFailed = false
responseDataAggregatedByte, err := openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity)
responseDataAggregatedByte, err := openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeName, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity)

if err != nil {
fmt.Printf("Request to %s failed\n", endpointAPI)
Expand All @@ -159,7 +171,7 @@ func openJiraTickets(endpointAPI string, orgID string, token string, jiraProject
for numberOfRetries := 0; numberOfRetries < MaxNumberOfRetry; numberOfRetries++ {
fmt.Println("Retrying with priorityIsSeverity set to false, max retry ", MaxNumberOfRetry)
priorityIsSeverity = false
responseDataAggregatedByte, err = openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity)
responseDataAggregatedByte, err = openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeName, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity)
if err != nil {
fullListNotCreatedIssue += displayErrorForIssue(vulnForJira, endpointAPI)
} else {
Expand Down
4 changes: 2 additions & 2 deletions jira_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestOpenJiraTicketWithLabelsFunc(t *testing.T) {
if err != nil {
panic(err)
}
numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "Label1,Label2", projectInfo, vulnsForJira, false)
numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "Label1,Label2", projectInfo, vulnsForJira, false)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
Expand All @@ -67,7 +67,7 @@ func TestOpenJiraTicketWithoutLabelsFunc(t *testing.T) {
if err != nil {
panic(err)
}
numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, false)
numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, false)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions jira_prioritymapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestOpenJiraTicketWithPriorityMappingFunc(t *testing.T) {
if err != nil {
panic(err)
}
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
Expand All @@ -49,7 +49,7 @@ func TestOpenJiraTicketWithoutPriorityMappingFunc(t *testing.T) {
if err != nil {
panic(err)
}
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, false)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, false)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
Expand All @@ -75,7 +75,7 @@ func TestOpenJiraTicketWithCustomPriorityMappingFunc(t *testing.T) {
panic(err)
}
os.Setenv("SNYK_JIRA_PRIORITY_FOR_MEDIUM_VULN", "not too bad")
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
Expand Down
60 changes: 55 additions & 5 deletions jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestOpenJiraTicketFunc(t *testing.T) {
if err != nil {
panic(err)
}
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, false)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, false)

assert.Equal("", NotCreatedIssueId)
assert.Equal(string(readFixture("./fixtures/results/jiraTicketsOpeningResults")), jiraResponse)
Expand All @@ -46,7 +46,7 @@ func TestOpenJiraTicketErrorAndRetryFunc(t *testing.T) {
if err != nil {
panic(err)
}
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true)

assert.Equal("", NotCreatedIssueId)
assert.Equal(string(readFixture("./fixtures/results/jiraTicketsOpeningResults")), jiraResponse)
Expand All @@ -68,7 +68,7 @@ func TestOpenJiraMultipleTicketsErrorAndRetryFunc(t *testing.T) {
panic(err)
}

NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true)

assert.Equal("", NotCreatedIssueId)
fmt.Println(NumberIssueCreated)
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestOpenJiraMultipleTicketsErrorAndRetryAndFailFunc(t *testing.T) {
panic(err)
}

NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true)

assert.Equal(string(readFixture("./fixtures/results/NotCreatedIssueIdSingle")), NotCreatedIssueId)
fmt.Println(NumberIssueCreated)
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestOpenJiraMultipleTicketsFailureFunc(t *testing.T) {
panic(err)
}

NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true)
NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true)

fmt.Println(NumberIssueCreated)

Expand All @@ -170,3 +170,53 @@ func TestOpenJiraMultipleTicketsFailureFunc(t *testing.T) {

return
}

func TestOpenJiraTicketWithAssigneeNameFunc(t *testing.T) {
assert := assert.New(t)
server := HTTPResponseStubAndMirrorRequest("/v1/org/123/project/12345678-1234-1234-1234-123456789012/issue/SNYK-JS-MINIMIST-559764/jira-issue", "", "")

defer server.Close()

projectInfo, _ := jsn.NewJson(readFixture("./fixtures/project.json"))
vulnsForJira := make(map[string]interface{})
err := json.Unmarshal(readFixture("./fixtures/vulnForJiraAggregatedWithPath.json"), &vulnsForJira)
if err != nil {
panic(err)
}
numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "admin", "", "", projectInfo, vulnsForJira, false)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
panic(err)
}
assert.Equal(NotCreatedIssueId, "")
assert.Equal(string(readFixture("./fixtures/results/jiraTicketWithoutLabelsWithAssigneeName.json")), string(mirroredResponse.Body))
fmt.Println("NumberIssueCreated :", numberIssueCreated)

return
}

func TestOpenJiraTicketWithAssigneeIDFunc(t *testing.T) {
assert := assert.New(t)
server := HTTPResponseStubAndMirrorRequest("/v1/org/123/project/12345678-1234-1234-1234-123456789012/issue/SNYK-JS-MINIMIST-559764/jira-issue", "", "")

defer server.Close()

projectInfo, _ := jsn.NewJson(readFixture("./fixtures/project.json"))
vulnsForJira := make(map[string]interface{})
err := json.Unmarshal(readFixture("./fixtures/vulnForJiraAggregatedWithPath.json"), &vulnsForJira)
if err != nil {
panic(err)
}
numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "12345", "", projectInfo, vulnsForJira, false)

var mirroredResponse mirroredResponse
if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil {
panic(err)
}
assert.Equal(NotCreatedIssueId, "")
assert.Equal(string(readFixture("./fixtures/results/jiraTicketWithoutLabelsWithAssigneeID.json")), string(mirroredResponse.Body))
fmt.Println("NumberIssueCreated :", numberIssueCreated)

return
}
Loading

0 comments on commit 0d4e906

Please sign in to comment.