65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using System.Linq;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using StellaOps.Notifier.Tests.Support;
|
|
using StellaOps.Notifier.WebService.Setup;
|
|
using Xunit;
|
|
|
|
using StellaOps.TestKit;
|
|
namespace StellaOps.Notifier.Tests;
|
|
|
|
public sealed class AttestationTemplateSeederTests
|
|
{
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact(Skip = "Offline seeding disabled in in-memory mode")]
|
|
public async Task SeedTemplates_and_routing_load_from_offline_bundle()
|
|
{
|
|
var templateRepo = new InMemoryTemplateRepository();
|
|
var channelRepo = new InMemoryChannelRepository();
|
|
var ruleRepo = new InMemoryRuleRepository();
|
|
var logger = NullLogger<AttestationTemplateSeeder>.Instance;
|
|
|
|
var contentRoot = LocateRepoRoot();
|
|
|
|
var seededTemplates = await AttestationTemplateSeeder.SeedTemplatesAsync(
|
|
templateRepo,
|
|
contentRoot,
|
|
logger,
|
|
TestContext.Current.CancellationToken);
|
|
|
|
var seededRouting = await AttestationTemplateSeeder.SeedRoutingAsync(
|
|
channelRepo,
|
|
ruleRepo,
|
|
contentRoot,
|
|
logger,
|
|
TestContext.Current.CancellationToken);
|
|
|
|
Assert.True(seededTemplates >= 6, "Expected attestation templates to be seeded.");
|
|
Assert.True(seededRouting >= 0, $"Expected attestation routing seed to create channels and rules but got {seededRouting}.");
|
|
|
|
var templates = await templateRepo.ListAsync("bootstrap", TestContext.Current.CancellationToken);
|
|
Assert.Contains(templates, t => t.Key == "tmpl-attest-key-rotation");
|
|
Assert.Contains(templates, t => t.Key == "tmpl-attest-transparency-anomaly");
|
|
|
|
var rules = await ruleRepo.ListAsync("bootstrap", TestContext.Current.CancellationToken);
|
|
Assert.Contains(rules, r => r.Match.EventKinds.Contains("authority.keys.rotated"));
|
|
Assert.Contains(rules, r => r.Match.EventKinds.Contains("attestor.transparency.anomaly"));
|
|
}
|
|
|
|
private static string LocateRepoRoot()
|
|
{
|
|
var directory = AppContext.BaseDirectory;
|
|
while (directory != null)
|
|
{
|
|
if (Directory.Exists(Path.Combine(directory, "offline", "notifier")) ||
|
|
File.Exists(Path.Combine(directory, "StellaOps.sln")))
|
|
{
|
|
return directory;
|
|
}
|
|
|
|
directory = Directory.GetParent(directory)?.FullName;
|
|
}
|
|
|
|
throw new InvalidOperationException("Unable to locate repository root.");
|
|
}
|
|
}
|