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

Commit

Permalink
Loosen scriban validation (#2963)
Browse files Browse the repository at this point in the history
* Add new command

* Update remaining jinja templates and references to use scriban

* Do not enforce that key exists in dictionary when doing strict validation
  • Loading branch information
tevoinea authored Apr 4, 2023
1 parent 34b513e commit 8bd2d40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Async.Task<string> Render(string templateString, Uri instanceUrl, b
true => new TemplateContext {
EnableRelaxedFunctionAccess = false,
EnableRelaxedIndexerAccess = false,
EnableRelaxedMemberAccess = false,
EnableRelaxedMemberAccess = true,
EnableRelaxedTargetAccess = false
},
_ => new TemplateContext()
Expand Down
21 changes: 21 additions & 0 deletions src/ApiService/IntegrationTests/JinjaToScribanMigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ public async Async.Task Access_WithoutAuthorization_IsRejected() {
result.StatusCode.Should().Be(System.Net.HttpStatusCode.BadRequest);
}

[Fact]
public async Async.Task Do_Not_Enforce_Key_Exists_In_Strict_Validation() {
(await JinjaTemplateAdapter.IsValidScribanNotificationTemplate(Context, Logger, ValidScribanAdoTemplate()))
.Should().BeTrue();
}

private async Async.Task ConfigureAuth() {
await Context.InsertAll(
new InstanceConfig(Context.ServiceConfiguration.OneFuzzInstanceName!) { Admins = new[] { _userObjectId } } // needed for admin check
Expand Down Expand Up @@ -412,4 +418,19 @@ private static GithubIssuesTemplate MigratableGithubTemplate() {
private static TeamsTemplate GetTeamsTemplate() {
return new TeamsTemplate(new SecretData<string>(new SecretValue<string>("https://example.com")));
}

private static AdoTemplate ValidScribanAdoTemplate() {
return new AdoTemplate(
new Uri("http://example.com"),
new SecretData<string>(new SecretValue<string>("some secret")),
"{{ if task.tags.project }} blah {{ end }}",
string.Empty,
Array.Empty<string>().ToList(),
new Dictionary<string, string>(),
new ADODuplicateTemplate(
Array.Empty<string>().ToList(),
new Dictionary<string, string>(),
new Dictionary<string, string>()
));
}
}

0 comments on commit 8bd2d40

Please sign in to comment.