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

Commit

Permalink
Fix notification validation (#2914)
Browse files Browse the repository at this point in the history
* Add new command

* Update remaining jinja templates and references to use scriban

* Add missing properties to render context when validating notification config
  • Loading branch information
tevoinea authored Mar 7, 2023
1 parent e5dc787 commit f00248f
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,48 +74,126 @@ public static async Async.Task<TemplateValidationResponse> ValidateScribanTempla
var project = "some project";
var jobName = "job name";
var buildName = "build name";
var account = "some account";
var container = Container.Parse("container");
var asanLog = "asan log";
var scarinessScore = 5;
var scarinessDescription = "super scary";
var minimizedStack = new List<string> { "minimized stack frame 0", "minimized stack frame 1" };
var minimizedStackSha = "abc123";
var minimizedStackFunctionNames = new List<string> { "minimized stack function 0", "minimized stack function 1" };
var minimizedStackFunctionNamesSha = "abc123";
var minimizedStackFunctionLines = new List<string> { "minimized stack function line 0", "minimized stack function line 1" };
var minimizedStackFunctionLinesSha = "abc123";
var reportContainer = templateRenderContext?.ReportContainer ?? Container.Parse("example-container-name");
var reportFileName = templateRenderContext?.ReportFilename ?? "example file name";
var reproCmd = templateRenderContext?.ReproCmd ?? "onefuzz command to create a repro";
var toolName = "tool name";
var toolVersion = "tool version";
var onefuzzVersion = "onefuzz version";
var report = templateRenderContext?.Report ?? new Report(
inputUrl.ToString(),
null,
new BlobRef(account, container, reportFileName),
executable,
crashType,
crashSite,
callStack,
callStackSha,
inputSha,
null,
asanLog,
taskId,
jobId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
scarinessScore,
scarinessDescription,
minimizedStack,
minimizedStackSha,
minimizedStackFunctionNames,
minimizedStackFunctionNamesSha,
minimizedStackFunctionLines,
minimizedStackFunctionLinesSha,
toolName,
toolVersion,
onefuzzVersion,
reportUrl
);

var preReqTasks = new List<Guid> { Guid.NewGuid(), Guid.NewGuid() };
var targetExe = "target exe";
var targetEnv = new Dictionary<string, string> { { "key", "value" } };
var targetOptions = new List<string> { "option 1", "option 2" };
var supervisorExe = "supervisor exe";
var task = new Task(
jobId,
taskId,
taskState,
os,
templateRenderContext?.Task ?? new TaskConfig(
jobId,
null,
preReqTasks,
new TaskDetails(
taskType,
duration
)
)
duration,
targetExe,
targetEnv,
targetOptions,
1,
true,
true,
true,
1,
true,
true,
true,
supervisorExe,
targetEnv,
targetOptions,
"supervisor input market",
"generator exe",
targetEnv,
targetOptions,
"analyzer exe",
targetEnv,
targetOptions,
ContainerType.Analysis,
"stats file",
StatsFormat.AFL,
true,
1,
1,
true,
targetOptions,
1,
"coverage filter",
"module allow list",
"source allow list",
"target assembly",
"target class",
"target method"
),
new TaskVm(
Region.Parse("westus3"),
"some sku",
"some image",
true,
1,
true
),
new TaskPool(
1,
PoolName.Parse("poolname")
),
new List<TaskContainers> {
new TaskContainers(ContainerType.Inputs, Container.Parse("inputs")),
},
targetEnv,
new List<TaskDebugFlag> { TaskDebugFlag.KeepNodeOnCompletion },
true
),
new Error(ErrorCode.UNABLE_TO_FIND, new string[] { "some error message" }),
new Authentication("password", "public key", "private key"),
DateTimeOffset.UtcNow,
DateTimeOffset.UtcNow,
new UserInfo(Guid.NewGuid(), Guid.NewGuid(), "upn")
);

var job = new Job(
Expand All @@ -126,8 +204,10 @@ public static async Async.Task<TemplateValidationResponse> ValidateScribanTempla
jobName,
buildName,
duration,
null
)
"logs"
),
"some error",
DateTimeOffset.UtcNow
);

var renderer = await NotificationsBase.Renderer.ConstructRenderer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public static async Async.Task<Renderer> ConstructRenderer(
inputUrl = new Uri(context.Containers.AuthDownloadUrl(report.InputBlob.Container, report.InputBlob.Name));
}

await context.ConfigurationRefresher.TryRefreshAsync().IgnoreResult();
var scribanOnlyFeatureFlag = await context.FeatureManagerSnapshot.IsEnabledAsync(FeatureFlagConstants.EnableScribanOnly);
log.Info($"ScribanOnlyFeatureFlag: {scribanOnlyFeatureFlag}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public TestServiceConfiguration(string tablePrefix) {
public string? OneFuzzInstanceName => "UnitTestInstance";

public string? OneFuzzKeyvault => "TestOneFuzzKeyVault";
public string? OneFuzzInstance => "https://onefuzz-integration-test.example.com";

// -- Remainder not implemented --

Expand All @@ -57,7 +58,6 @@ public TestServiceConfiguration(string tablePrefix) {

public string? DiagnosticsAzureBlobRetentionDays => throw new System.NotImplementedException();

public string? OneFuzzInstance => throw new System.NotImplementedException();

public string? OneFuzzMonitor => throw new System.NotImplementedException();

Expand Down
27 changes: 27 additions & 0 deletions src/ApiService/IntegrationTests/JinjaToScribanMigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,33 @@ public async Async.Task Migration_Happens_When_Not_Dry_run() {
template.Project.Should().BeEquivalentTo(JinjaTemplateAdapter.AdaptForScriban(MigratableAdoTemplate().Project));
}

[Fact]
public async Async.Task OptionalFieldsAreSupported() {
await ConfigureAuth();

var adoTemplate = new AdoTemplate(
new Uri("http://example.com"),
new SecretData<string>(new SecretValue<string>("some secret")),
"{{ report.input_blob.container }}",
"{{ if org }} blah {{ end }}",
Array.Empty<string>().ToList(),
new Dictionary<string, string> {
{ "abc", "{{ if org }} blah {{ end }}"}
},
new ADODuplicateTemplate(
Array.Empty<string>().ToList(),
new Dictionary<string, string>(),
new Dictionary<string, string> {
{ "onDuplicateComment", "{{ if org }} blah {{ end }}" }
},
"{{ if org }} blah {{ end }}"
),
"{{ if org }} blah {{ end }}"
);

(await JinjaTemplateAdapter.IsValidScribanNotificationTemplate(Context, Logger, adoTemplate)).Should().BeTrue();
}

[Fact]
public async Async.Task All_ADO_Fields_Are_Migrated() {
await ConfigureAuth();
Expand Down

0 comments on commit f00248f

Please sign in to comment.