Refactor code structure for improved readability and maintainability; optimize performance in key functions.

This commit is contained in:
master
2025-12-22 19:06:31 +02:00
parent dfaa2079aa
commit 4602ccc3a3
1444 changed files with 109919 additions and 8058 deletions

View File

@@ -0,0 +1,94 @@
using System.Collections.Immutable;
using FluentAssertions;
using StellaOps.AirGap.Bundle.Models;
using StellaOps.AirGap.Bundle.Serialization;
using StellaOps.AirGap.Bundle.Services;
using StellaOps.AirGap.Bundle.Validation;
using Xunit;
namespace StellaOps.AirGap.Bundle.Tests;
public class BundleManifestTests
{
[Fact]
public void Serializer_RoundTrip_PreservesFields()
{
var manifest = CreateManifest();
var json = BundleManifestSerializer.Serialize(manifest);
var deserialized = BundleManifestSerializer.Deserialize(json);
deserialized.Should().BeEquivalentTo(manifest);
}
[Fact]
public async Task Validator_FlagsMissingFeedFile()
{
var manifest = CreateManifest();
var validator = new BundleValidator();
var result = await validator.ValidateAsync(manifest, Path.GetTempPath());
result.IsValid.Should().BeFalse();
result.Errors.Should().NotBeEmpty();
}
[Fact]
public async Task Builder_CopiesComponentsAndComputesDigest()
{
var tempRoot = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var sourceFile = Path.Combine(tempRoot, "feed.json");
Directory.CreateDirectory(tempRoot);
await File.WriteAllTextAsync(sourceFile, "feed");
var builder = new BundleBuilder();
var request = new BundleBuildRequest(
"offline-test",
"1.0.0",
null,
new[] { new FeedBuildConfig("feed-1", "nvd", "v1", sourceFile, "feeds/nvd.json", DateTimeOffset.UtcNow, FeedFormat.StellaOpsNative) },
Array.Empty<PolicyBuildConfig>(),
Array.Empty<CryptoBuildConfig>());
var outputPath = Path.Combine(tempRoot, "bundle");
var manifest = await builder.BuildAsync(request, outputPath);
manifest.BundleDigest.Should().NotBeNullOrEmpty();
File.Exists(Path.Combine(outputPath, "feeds", "nvd.json")).Should().BeTrue();
}
private static BundleManifest CreateManifest()
{
return new BundleManifest
{
BundleId = Guid.NewGuid().ToString(),
SchemaVersion = "1.0.0",
Name = "offline-test",
Version = "1.0.0",
CreatedAt = DateTimeOffset.UtcNow,
Feeds = ImmutableArray.Create(new FeedComponent(
"feed-1",
"nvd",
"v1",
"feeds/nvd.json",
new string('a', 64),
10,
DateTimeOffset.UtcNow,
FeedFormat.StellaOpsNative)),
Policies = ImmutableArray.Create(new PolicyComponent(
"policy-1",
"default",
"1.0",
"policies/default.rego",
new string('b', 64),
10,
PolicyType.OpaRego)),
CryptoMaterials = ImmutableArray.Create(new CryptoComponent(
"crypto-1",
"trust-root",
"certs/root.pem",
new string('c', 64),
10,
CryptoComponentType.TrustRoot,
null)),
TotalSizeBytes = 30
};
}
}

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StellaOps.AirGap.Bundle\StellaOps.AirGap.Bundle.csproj" />
</ItemGroup>
</Project>