This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
234 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"base_url": "https://dev.azure.com/contoso", | ||
"auth_token": "DO NOT PUT YOUR PAT HERE", | ||
"type": "Bug", | ||
"project": "Contoso", | ||
"unique_fields": [ | ||
"Microsoft.VSTS.Build.FoundIn" | ||
], | ||
"comment": "my comment", | ||
"ado_fields": { | ||
"System.AssignedTo": "example@contoso.com", | ||
"System.Tags": "OneFuzz; OneFuzz-Pipeline; example@example.com", | ||
"System.AreaPath": "MY\\AREA Path\\Here", | ||
"System.IterationPath": "MY\\ITERATION", | ||
"Microsoft.VSTS.Scheduling.StoryPoints": "1", | ||
"Microsoft.VSTS.Build.FoundIn": "{{ report.input_sha256 }}", | ||
"System.Title": "[OneFuzz] - {{ report.crash_site }}", | ||
"Microsoft.VSTS.TCM.ReproSteps": "This is the call stack. You may wish to confirm: <ul> {% for item in report.call_stack %} <li> {{ item }} </li> {% endfor %} </ul>" | ||
}, | ||
"on_duplicate": { | ||
"comment": "DEDUPED!", | ||
"set_state": { | ||
"Resolved": "Active" | ||
}, | ||
"ado_fields": { | ||
"System.IterationPath": "MY\\ITERATION" | ||
}, | ||
"increment": [ | ||
"Microsoft.VSTS.Scheduling.StoryPoints" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"op": "Add", | ||
"path": "/fields/System.AssignedTo", | ||
"value": "example@contoso.com" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/System.Tags", | ||
"value": "OneFuzz; OneFuzz-Pipeline; example@example.com;Onefuzz" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/System.AreaPath", | ||
"value": "MY\\AREA Path\\Here" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/System.IterationPath", | ||
"value": "MY\\ITERATION" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/Microsoft.VSTS.Scheduling.StoryPoints", | ||
"value": "1" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/Microsoft.VSTS.Build.FoundIn", | ||
"value": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/System.Title", | ||
"value": "[OneFuzz] - callfunc" | ||
}, | ||
{ | ||
"op": "Add", | ||
"path": "/fields/Microsoft.VSTS.TCM.ReproSteps", | ||
"value": "This is the call stack. You may wish to confirm: <ul> <li> test.exe.exe+0x2 </li> <li> test.exe.exe+0x9 </li> <li> test.exe.exe+0x3 </li> <li> test.exe.exe+0xd </li> <li> test.exe.exe+0x8 </li> <li> test.exe.exe+0x8 </li> <li> test.exe.exe+0x2 </li> </ul>" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"call_stack": [ | ||
"test.exe.exe+0x2", | ||
"test.exe.exe+0x9", | ||
"test.exe.exe+0x3", | ||
"test.exe.exe+0xd", | ||
"test.exe.exe+0x8", | ||
"test.exe.exe+0x8", | ||
"test.exe.exe+0x2" | ||
], | ||
"call_stack_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"crash_site": "callfunc", | ||
"crash_type": "customtype", | ||
"executable": "test2.exe", | ||
"input_blob": { | ||
"account": "storageaccount1", | ||
"container": "storagecontainer1", | ||
"name": "%23A_B.exe.exe%2B0x0_a_b_c_0x5b1e7_a_515c01e.tar" | ||
}, | ||
"input_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"job_id": "581e0ba6-9757-47e5-a077-dba21e604961", | ||
"task_id": "4a949007-b59f-4a47-8418-8a2c94b4aef1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
|
||
import json | ||
import unittest | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
from onefuzztypes.enums import OS, TaskType | ||
from onefuzztypes.models import ADOTemplate, JobConfig, Report, TaskConfig, TaskDetails | ||
from onefuzztypes.primitives import Container | ||
|
||
from __app__.onefuzzlib.jobs import Job | ||
from __app__.onefuzzlib.notifications.ado import ADO | ||
from __app__.onefuzzlib.notifications.common import Render | ||
from __app__.onefuzzlib.tasks.main import Task | ||
|
||
|
||
class TestReportParse(unittest.TestCase): | ||
def setUp(self) -> None: | ||
self.env_patch = patch.dict( | ||
"os.environ", {"ONEFUZZ_INSTANCE_NAME": "contoso-test"} | ||
) | ||
self.env_patch.start() | ||
|
||
def tearDown(self) -> None: | ||
self.env_patch.stop() | ||
|
||
def test_sample(self) -> None: | ||
expected_path = Path(__file__).parent / "data" / "ado-rendered.json" | ||
with open(expected_path, "r") as handle: | ||
expected_document = json.load(handle) | ||
|
||
report_path = Path(__file__).parent / "data" / "crash-report-with-html.json" | ||
with open(report_path, "r") as handle: | ||
report_raw = json.load(handle) | ||
|
||
ado_path = Path(__file__).parent / "data" / "ado-config.json" | ||
with open(ado_path, "r") as handle: | ||
ado_raw = json.load(handle) | ||
|
||
report = Report.parse_obj(report_raw) | ||
config = ADOTemplate.parse_obj(ado_raw) | ||
|
||
container = Container("containername") | ||
filename = "test.json" | ||
|
||
job = Job( | ||
config=JobConfig(project="project", name="name", build="build", duration=1) | ||
) | ||
task = Task( | ||
config=TaskConfig( | ||
job_id=job.job_id, | ||
tags={}, | ||
containers=[], | ||
task=TaskDetails(type=TaskType.libfuzzer_fuzz, duration=1), | ||
), | ||
job_id=job.job_id, | ||
os=OS.linux, | ||
) | ||
|
||
renderer = Render( | ||
container, | ||
filename, | ||
report, | ||
task=task, | ||
job=job, | ||
target_url="https://contoso.com/1", | ||
input_url="https://contoso.com/2", | ||
report_url="https://contoso.com/3", | ||
) | ||
|
||
ado = ADO(container, filename, config, report, renderer=renderer) | ||
work_item_type, document = ado.render_new() | ||
self.assertEqual(work_item_type, "Bug") | ||
|
||
as_obj = [x.as_dict() for x in document] | ||
|
||
self.assertEqual(as_obj, expected_document) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |