Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Implement `SbomIngestServiceCollectionExtensionsTests` to verify the SBOM ingestion pipeline exports snapshots correctly. - Create `SbomIngestTransformerTests` to ensure the transformation produces expected nodes and edges, including deduplication of license nodes and normalization of timestamps. - Add `SbomSnapshotExporterTests` to test the export functionality for manifest, adjacency, nodes, and edges. - Introduce `VexOverlayTransformerTests` to validate the transformation of VEX nodes and edges. - Set up project file for the test project with necessary dependencies and configurations. - Include JSON fixture files for testing purposes.
85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using System.Text;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using StellaOps.EvidenceLocker.Core.Configuration;
|
|
using StellaOps.EvidenceLocker.Core.Domain;
|
|
using StellaOps.EvidenceLocker.Core.Storage;
|
|
using StellaOps.EvidenceLocker.Infrastructure.Storage;
|
|
|
|
namespace StellaOps.EvidenceLocker.Tests;
|
|
|
|
public sealed class FileSystemEvidenceObjectStoreTests : IDisposable
|
|
{
|
|
private readonly string _rootPath;
|
|
|
|
public FileSystemEvidenceObjectStoreTests()
|
|
{
|
|
_rootPath = Path.Combine(Path.GetTempPath(), $"evidence-locker-tests-{Guid.NewGuid():N}");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StoreAsync_EnforcesWriteOnceWhenConfigured()
|
|
{
|
|
var cancellationToken = TestContext.Current.CancellationToken;
|
|
var store = CreateStore(enforceWriteOnce: true);
|
|
var options = CreateWriteOptions();
|
|
|
|
using var first = CreateStream("payload-1");
|
|
await store.StoreAsync(first, options, cancellationToken);
|
|
|
|
using var second = CreateStream("payload-1");
|
|
await Assert.ThrowsAsync<InvalidOperationException>(() => store.StoreAsync(second, options, cancellationToken));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task StoreAsync_AllowsOverwriteWhenWriteOnceDisabled()
|
|
{
|
|
var cancellationToken = TestContext.Current.CancellationToken;
|
|
var store = CreateStore(enforceWriteOnce: false);
|
|
var options = CreateWriteOptions() with { EnforceWriteOnce = false };
|
|
|
|
using var first = CreateStream("payload-1");
|
|
var firstMetadata = await store.StoreAsync(first, options, cancellationToken);
|
|
|
|
using var second = CreateStream("payload-1");
|
|
var secondMetadata = await store.StoreAsync(second, options, cancellationToken);
|
|
|
|
Assert.Equal(firstMetadata.Sha256, secondMetadata.Sha256);
|
|
Assert.True(File.Exists(Path.Combine(_rootPath, secondMetadata.StorageKey.Replace('/', Path.DirectorySeparatorChar))));
|
|
}
|
|
|
|
private FileSystemEvidenceObjectStore CreateStore(bool enforceWriteOnce)
|
|
{
|
|
var fileSystemOptions = new FileSystemStoreOptions
|
|
{
|
|
RootPath = _rootPath
|
|
};
|
|
|
|
return new FileSystemEvidenceObjectStore(
|
|
fileSystemOptions,
|
|
enforceWriteOnce,
|
|
NullLogger<FileSystemEvidenceObjectStore>.Instance);
|
|
}
|
|
|
|
private static EvidenceObjectWriteOptions CreateWriteOptions()
|
|
{
|
|
var tenant = TenantId.FromGuid(Guid.NewGuid());
|
|
var bundle = EvidenceBundleId.FromGuid(Guid.NewGuid());
|
|
return new EvidenceObjectWriteOptions(
|
|
tenant,
|
|
bundle,
|
|
"artifact.txt",
|
|
"text/plain");
|
|
}
|
|
|
|
private static MemoryStream CreateStream(string content)
|
|
=> new(Encoding.UTF8.GetBytes(content));
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Directory.Exists(_rootPath))
|
|
{
|
|
Directory.Delete(_rootPath, recursive: true);
|
|
}
|
|
}
|
|
}
|