prep docs and service updates
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Findings.Ledger.WebService.Contracts;
|
||||
using StellaOps.Findings.Ledger.WebService.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Findings.Ledger.Tests.Exports;
|
||||
|
||||
public class AttestationQueryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void ComputeFiltersHash_IsDeterministic()
|
||||
{
|
||||
var svc = new AttestationQueryService(NullLogger<AttestationQueryService>.Instance);
|
||||
|
||||
var requestA = new AttestationQueryRequest(
|
||||
TenantId: "t1",
|
||||
ArtifactId: "sha256:a",
|
||||
FindingId: null,
|
||||
AttestationId: null,
|
||||
Status: "verified",
|
||||
SinceRecordedAt: DateTimeOffset.Parse("2024-01-01T00:00:00Z"),
|
||||
UntilRecordedAt: DateTimeOffset.Parse("2024-01-02T00:00:00Z"),
|
||||
Limit: 100,
|
||||
FiltersHash: string.Empty,
|
||||
PagingKey: null);
|
||||
|
||||
var requestB = requestA with { FiltersHash = "anything" };
|
||||
|
||||
var hashA = svc.ComputeFiltersHash(requestA);
|
||||
var hashB = svc.ComputeFiltersHash(requestB);
|
||||
|
||||
Assert.Equal(hashA, hashB);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PageToken_RoundTrips()
|
||||
{
|
||||
var svc = new AttestationQueryService(NullLogger<AttestationQueryService>.Instance);
|
||||
|
||||
var request = new AttestationQueryRequest(
|
||||
TenantId: "t1",
|
||||
ArtifactId: "sha256:a",
|
||||
FindingId: "f1",
|
||||
AttestationId: "att-1",
|
||||
Status: "verified",
|
||||
SinceRecordedAt: DateTimeOffset.Parse("2024-01-01T00:00:00Z"),
|
||||
UntilRecordedAt: DateTimeOffset.Parse("2024-01-02T00:00:00Z"),
|
||||
Limit: 50,
|
||||
FiltersHash: string.Empty,
|
||||
PagingKey: null);
|
||||
|
||||
var filtersHash = svc.ComputeFiltersHash(request);
|
||||
var key = new AttestationPagingKey(DateTimeOffset.Parse("2024-01-01T12:00:00Z"), "att-9");
|
||||
|
||||
var token = svc.CreatePageToken(key, filtersHash);
|
||||
|
||||
var ok = svc.TryParsePageToken(token, filtersHash, out var parsed, out var error);
|
||||
|
||||
Assert.True(ok);
|
||||
Assert.Null(error);
|
||||
Assert.NotNull(parsed);
|
||||
Assert.Equal(key.RecordedAt, parsed!.RecordedAt);
|
||||
Assert.Equal(key.AttestationId, parsed.AttestationId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user