66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
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);
|
|
}
|
|
}
|