Skip to content

Commit

Permalink
Add unit test for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Feb 2, 2024
1 parent cb39799 commit e1e84cd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/actions/security-issues/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ runs:
shell: bash
run: |
tbx security cve create --project "${{ inputs.project }}" < issues.jsonl | tee created.jsonl
- name: Define Output Parameter
id: get-created-issues
shell: bash
Expand Down
12 changes: 5 additions & 7 deletions exasol/toolbox/tools/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,15 @@ def create(
Output:
Links to the created issue(s)
"""
def _format_jsonl(issue_url: str, issue: Issue) -> str:
issue = asdict(issue)
issue["url"] = issue_url
return json.dumps(issue)

for issue in _issues(input_file):
std_err, issue_url = create_security_issue(issue, project)
stderr(std_err)
stdout(_format_jsonl(issue_url, issue))

stdout(format_jsonl(issue_url, issue))

def format_jsonl(issue_url: str, issue: Issue) -> str:
issue = asdict(issue)
issue["url"] = issue_url.strip()
return json.dumps(issue)

if __name__ == "__main__":
CLI()
11 changes: 11 additions & 0 deletions test/unit/security_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,14 @@ def test_convert_maven_input(maven_report): # pylint: disable=redefined-outer-n
def test_convert_maven_input_no_vulnerable(): # pylint: disable=redefined-outer-name
actual = set(security.from_maven("{}"))
assert len(actual) == 0

def test_format_jsonl():
issue = security.Issue(coordinates="coordinates", cve="cve", cwe="cwe", description="description", references=())
actual = security.format_jsonl("issue_url", issue)
assert actual == '{"cve": "cve", "cwe": "cwe", "description": "description", "coordinates": "coordinates", "references": [], "url": "issue_url"}'


def test_format_jsonl_removes_newline():
issue = security.Issue(coordinates="coordinates", cve="cve", cwe="cwe", description="description", references=())
actual = security.format_jsonl("issue_url\n", issue)
assert actual == '{"cve": "cve", "cwe": "cwe", "description": "description", "coordinates": "coordinates", "references": [], "url": "issue_url"}'

0 comments on commit e1e84cd

Please sign in to comment.