Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 79db17b

Browse files
committed
Add a new test for report.extension_data
1 parent 7f7ab37 commit 79db17b

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/ApiService/Tests/TemplateTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class TemplateTests {
3232
// * Change "{% ... %}" in python to "{{ ... }}"
3333
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>";
3434

35+
// Ensure that extension data gets picked up.
36+
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";
37+
38+
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"}]""";
39+
3540
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 %}";
3641

3742
[Fact]
@@ -69,6 +74,23 @@ public void CanFormatTemplateWithForLoop() {
6974
output.Should().ContainAll(report.CallStack);
7075
}
7176

77+
[Fact]
78+
public void CanFormatTemplateWithExtensionData() {
79+
var template = Template.Parse(_testString4);
80+
template.Should().NotBeNull();
81+
82+
var report = GetReport();
83+
84+
// Add extension data field to the report.
85+
report.ExtensionData?.Add("artifacts", JsonSerializer.Deserialize<JsonElement>(_testString4Artifacts)!);
86+
87+
var output = template.Render(new {
88+
Report = report
89+
});
90+
91+
output.Should().Contain("Super duper sekrit artifacts");
92+
}
93+
7294
[Fact]
7395
public void CanFormatWithMultipleComplexObjects() {
7496
var template = Template.Parse(_testString2);

0 commit comments

Comments
 (0)