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

Commit e007b3d

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

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/ApiService/Tests/TemplateTests.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
3+
using System.Text;
34
using System.Text.Json;
45
using FluentAssertions;
56
using Microsoft.OneFuzz.Service;
@@ -32,6 +33,11 @@ public class TemplateTests {
3233
// * Change "{% ... %}" in python to "{{ ... }}"
3334
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>";
3435

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+
3541
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 %}";
3642

3743
[Fact]
@@ -69,6 +75,23 @@ public void CanFormatTemplateWithForLoop() {
6975
output.Should().ContainAll(report.CallStack);
7076
}
7177

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+
7295
[Fact]
7396
public void CanFormatWithMultipleComplexObjects() {
7497
var template = Template.Parse(_testString2);

0 commit comments

Comments
 (0)