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

Commit

Permalink
Add a new test for report.extension_data
Browse files Browse the repository at this point in the history
  • Loading branch information
DrChat committed Sep 6, 2023
1 parent 7f7ab37 commit 79db17b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/ApiService/Tests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class TemplateTests {
// * Change "{% ... %}" in python to "{{ ... }}"
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>";

// Ensure that extension data gets picked up.
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";

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"}]""";

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

[Fact]
Expand Down Expand Up @@ -69,6 +74,23 @@ public void CanFormatTemplateWithForLoop() {
output.Should().ContainAll(report.CallStack);
}

[Fact]
public void CanFormatTemplateWithExtensionData() {
var template = Template.Parse(_testString4);
template.Should().NotBeNull();

var report = GetReport();

// Add extension data field to the report.
report.ExtensionData?.Add("artifacts", JsonSerializer.Deserialize<JsonElement>(_testString4Artifacts)!);

var output = template.Render(new {
Report = report
});

output.Should().Contain("Super duper sekrit artifacts");
}

[Fact]
public void CanFormatWithMultipleComplexObjects() {
var template = Template.Parse(_testString2);
Expand Down

0 comments on commit 79db17b

Please sign in to comment.