Skip to content

Add all existing finding notes to the JIRA when created #6449

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

Merged
merged 2 commits into from
Aug 15, 2022
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
20 changes: 20 additions & 0 deletions dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ def get_jira_status(finding):
return issue.fields.status


# Used for unit testing so geting all the connections is manadatory
def get_jira_comments(finding):
if finding.has_jira_issue:
j_issue = finding.jira_issue.jira_id
elif finding.finding_group and finding.finding_group.has_jira_issue:
j_issue = finding.finding_group.jira_issue.jira_id

if j_issue:
project = get_jira_project(finding)
issue = jira_get_issue(project, j_issue)
return issue.fields.comment.comments


# Logs the error to the alerts table, which appears in the notification toolbar
def log_jira_generic_alert(title, description):
create_notification(
Expand Down Expand Up @@ -719,6 +732,13 @@ def add_jira_issue(obj, *args, **kwargs):
issue = jira.issue(new_issue.id)

logger.info('Created the following jira issue for %d:%s', obj.id, to_str_typed(obj))

# Add any notes that already exist in the finding to the JIRA
for find in findings:
if find.notes.all():
for note in find.notes.all().reverse():
add_comment(obj, note)

return True
except TemplateDoesNotExist as e:
logger.exception(e)
Expand Down
5 changes: 5 additions & 0 deletions unittests/dojo_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ def get_jira_issue_updated(self, finding_id):
updated = jira_helper.get_jira_updated(finding)
return updated

def get_jira_comments(self, finding_id):
finding = Finding.objects.get(id=finding_id)
comments = jira_helper.get_jira_comments(finding)
return comments

def get_jira_issue_updated_map(self, test_id):
findings = Test.objects.get(id=test_id).finding_set.all()
updated_map = {}
Expand Down
21 changes: 21 additions & 0 deletions unittests/test_jira_import_and_pushing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,28 @@ def test_import_with_push_to_jira_add_comment(self):

response = self.post_finding_notes_api(finding_id, 'testing note. creating it and pushing it to JIRA')
self.patch_finding_api(finding_id, {"push_to_jira": True})
# Make sure the number of comments match
self.assertEqual(len(self.get_jira_comments(finding_id)), 1)
# by asserting full cassette is played we know all calls to JIRA have been made as expected
self.assert_cassette_played()
return test_id

def test_import_add_comments_then_push_to_jira(self):
import0 = self.import_scan_with_params(self.zap_sample5_filename, push_to_jira=False)
test_id = import0['test']

findings = self.get_test_findings_api(test_id)

finding_id = findings['results'][0]['id']

response = self.post_finding_notes_api(finding_id, 'testing note. creating it and pushing it to JIRA')
response = self.post_finding_notes_api(finding_id, 'testing second note. creating it and pushing it to JIRA')
self.patch_finding_api(finding_id, {"push_to_jira": True})

self.assert_jira_issue_count_in_test(test_id, 1)
self.assert_jira_group_issue_count_in_test(test_id, 0)
# Make sure the number of comments match
self.assertEqual(len(self.get_jira_comments(finding_id)), 2)
# by asserting full cassette is played we know all calls to JIRA have been made as expected
self.assert_cassette_played()
return test_id
Expand Down
Loading