|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Text; |
3 | 4 | using System.Text.Json; |
4 | 5 | using FluentAssertions; |
5 | 6 | using Microsoft.OneFuzz.Service; |
@@ -32,6 +33,11 @@ public class TemplateTests { |
32 | 33 | // * Change "{% ... %}" in python to "{{ ... }}" |
33 | 34 | private static readonly string _testString3 = "The fuzzing target ({{ job.project }} {{ job.name }} {{ job.build }}) reported a crash. <br> {{ if report.asan_log }} AddressSanitizer reported the following details: <br> <pre> {{ report.asan_log }} </pre> {{ else }} Faulting call stack: <ul> {{ for item in report.call_stack }} <li> {{ item }} </li> {{ end }} </ul> <br> {{ end }} You can reproduce the issue remotely in OneFuzz by running the following command: <pre> {{ repro_cmd }} </pre>"; |
34 | 35 |
|
| 36 | + // Ensure that extension data gets picked up. |
| 37 | + private static readonly string _testString4 = "Artifacts: <ul>{{ for item in report.extension_data.artifacts }}<li><a href=\"{{ item.url }}\">{{ item.name }}</a>({{ item.desc}})</li>{{ end }}</ul>\nInitially found in: <ul><li>Input: <a href='{{ input_url }}'>{{ report.input_sha256 }}</a></ul>\n"; |
| 38 | + |
| 39 | + private static readonly string _testString4Artifacts = """[{"desc": "Super duper sekrit artifacts","name": "Abc","url": "https://onefuzz.microsoft.com/api/download?container=abc123&filename=le_crash.zip"}]"""; |
| 40 | + |
35 | 41 | private static readonly string _jinjaIfStatement = "{% if report.asan_log %} AddressSanitizer reported the following details: <br> <pre> {{ report.asan_log }} </pre> {% else %} Faulting call stack: <ul> {% endif %}"; |
36 | 42 |
|
37 | 43 | [Fact] |
@@ -69,6 +75,23 @@ public void CanFormatTemplateWithForLoop() { |
69 | 75 | output.Should().ContainAll(report.CallStack); |
70 | 76 | } |
71 | 77 |
|
| 78 | + [Fact] |
| 79 | + public void CanFormatTemplateWithExtensionData() { |
| 80 | + var template = Template.Parse(_testString4); |
| 81 | + template.Should().NotBeNull(); |
| 82 | + |
| 83 | + var report = GetReport(); |
| 84 | + |
| 85 | + // Add extension data field to the report. |
| 86 | + report.ExtensionData?.Add("artifacts", JsonSerializer.Deserialize<ExpandoObject>(_testString4Artifacts)!); |
| 87 | + |
| 88 | + var output = template.Render(new { |
| 89 | + Report = report |
| 90 | + }); |
| 91 | + |
| 92 | + output.Should().Contain("Super duper sekrit artifacts"); |
| 93 | + } |
| 94 | + |
72 | 95 | [Fact] |
73 | 96 | public void CanFormatWithMultipleComplexObjects() { |
74 | 97 | var template = Template.Parse(_testString2); |
|
0 commit comments