Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using FluentAssertions;
|
|
using Mongo2Go;
|
|
using MongoDB.Driver;
|
|
using StellaOps.Concelier.Core.Linksets;
|
|
using StellaOps.Concelier.Storage.Mongo.Linksets;
|
|
|
|
namespace StellaOps.Concelier.Storage.Mongo.Tests;
|
|
|
|
public sealed class AdvisoryLinksetStoreTests : IAsyncLifetime
|
|
{
|
|
private MongoDbRunner _runner = null!;
|
|
private IMongoDatabase _database = null!;
|
|
|
|
public Task InitializeAsync()
|
|
{
|
|
_runner = MongoDbRunner.Start(singleNodeReplSet: true);
|
|
var client = new MongoClient(_runner.ConnectionString);
|
|
_database = client.GetDatabase("lnm-store-tests");
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
_runner.Dispose();
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpsertAndFetch_RetainsCpesInNormalizedShape()
|
|
{
|
|
var collection = _database.GetCollection<AdvisoryLinksetDocument>(MongoStorageDefaults.Collections.AdvisoryLinksets);
|
|
var store = new ConcelierMongoLinksetStore(collection);
|
|
|
|
var linkset = new AdvisoryLinkset(
|
|
TenantId: "TenantA",
|
|
Source: "source-A",
|
|
AdvisoryId: "ADV-1234",
|
|
ObservationIds: ImmutableArray.Create("obs-1"),
|
|
Normalized: new AdvisoryLinksetNormalized(
|
|
Purls: new List<string> { "pkg:npm/lodash@4.17.21" },
|
|
Cpes: new List<string> { "cpe:2.3:a:lodash:lodash:4.17.21:*:*:*:*:*:*:*" },
|
|
Versions: new List<string> { "4.17.21" },
|
|
Ranges: new List<Dictionary<string, object?>>(),
|
|
Severities: null),
|
|
Provenance: null,
|
|
Confidence: null,
|
|
Conflicts: null,
|
|
CreatedAt: DateTimeOffset.Parse("2025-11-24T00:00:00Z"),
|
|
BuiltByJobId: "job-001");
|
|
|
|
await store.UpsertAsync(linkset, CancellationToken.None);
|
|
|
|
var result = await store.FindByTenantAsync(
|
|
tenantId: "TenantA",
|
|
advisoryIds: new[] { "ADV-1234" },
|
|
sources: new[] { "source-A" },
|
|
cursor: null,
|
|
limit: 10,
|
|
cancellationToken: CancellationToken.None);
|
|
|
|
result.Should().ContainSingle();
|
|
var returned = result.Single();
|
|
returned.Normalized.Should().NotBeNull();
|
|
returned.Normalized!.Cpes.Should().ContainSingle()
|
|
.Which.Should().Be("cpe:2.3:a:lodash:lodash:4.17.21:*:*:*:*:*:*:*");
|
|
}
|
|
}
|