32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using StellaOps.AirGap.Time.Models;
|
|
using StellaOps.AirGap.Time.Parsing;
|
|
using StellaOps.AirGap.Time.Services;
|
|
|
|
using StellaOps.TestKit;
|
|
namespace StellaOps.AirGap.Time.Tests;
|
|
|
|
public class TimeVerificationServiceTests
|
|
{
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void FailsWithoutTrustRoots()
|
|
{
|
|
var svc = new TimeVerificationService();
|
|
var result = svc.Verify(new byte[] { 0x01 }, TimeTokenFormat.Roughtime, Array.Empty<TimeTrustRoot>(), out _);
|
|
Assert.False(result.IsValid);
|
|
Assert.Equal("trust-roots-required", result.Reason);
|
|
}
|
|
|
|
[Trait("Category", TestCategories.Unit)]
|
|
[Fact]
|
|
public void SucceedsForRoughtimeWithTrustRoot()
|
|
{
|
|
var svc = new TimeVerificationService();
|
|
var trust = new[] { new TimeTrustRoot("k1", new byte[] { 0x01 }, "rsassa-pss-sha256") };
|
|
var result = svc.Verify(new byte[] { 0x01, 0x02 }, TimeTokenFormat.Roughtime, trust, out var anchor);
|
|
Assert.True(result.IsValid);
|
|
Assert.Equal("Roughtime", anchor.Format);
|
|
Assert.Equal("k1", anchor.SignatureFingerprint);
|
|
}
|
|
}
|