work
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Notifier.Tests.Support;
|
||||
using StellaOps.Notifier.WebService.Setup;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Notifier.Tests;
|
||||
|
||||
public sealed class AttestationTemplateSeederTests
|
||||
{
|
||||
[Fact]
|
||||
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 >= 3, "Expected attestation routing seed to create channels and rules.");
|
||||
|
||||
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 (File.Exists(Path.Combine(directory, "StellaOps.sln")) ||
|
||||
File.Exists(Path.Combine(directory, "StellaOps.Notifier.sln")))
|
||||
{
|
||||
return directory;
|
||||
}
|
||||
|
||||
directory = Directory.GetParent(directory)?.FullName;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Unable to locate repository root.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user