Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
feat: Implement BsonJsonConverter for converting BsonDocument and BsonArray to JSON fix: Update project file to include MongoDB.Bson package test: Add GraphOverlayExporterTests to validate NDJSON export functionality refactor: Refactor Program.cs in Attestation Tool for improved argument parsing and error handling docs: Update README for stella-forensic-verify with usage instructions and exit codes feat: Enhance HmacVerifier with clock skew and not-after checks feat: Add MerkleRootVerifier and ChainOfCustodyVerifier for additional verification methods fix: Update DenoRuntimeShim to correctly handle file paths feat: Introduce ComposerAutoloadData and related parsing in ComposerLockReader test: Add tests for Deno runtime execution and verification test: Enhance PHP package tests to include autoload data verification test: Add unit tests for HmacVerifier and verification logic
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Text;
|
|
using StellaOps.Provenance.Attestation;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Provenance.Attestation.Tests;
|
|
|
|
public sealed class ToolEntrypointTests
|
|
{
|
|
[Fact]
|
|
public async Task RunAsync_ReturnsInvalidOnMissingArgs()
|
|
{
|
|
var code = await ToolEntrypoint.RunAsync(Array.Empty<string>(), TextWriter.Null, new StringWriter(), new TestTimeProvider(DateTimeOffset.UtcNow));
|
|
Assert.Equal(1, code);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RunAsync_VerifiesValidSignature()
|
|
{
|
|
var payload = Encoding.UTF8.GetBytes("payload");
|
|
var key = Convert.ToHexString(Encoding.UTF8.GetBytes("secret"));
|
|
using var hmac = new System.Security.Cryptography.HMACSHA256(Encoding.UTF8.GetBytes("secret"));
|
|
var sig = Convert.ToHexString(hmac.ComputeHash(payload));
|
|
|
|
var tmp = Path.GetTempFileName();
|
|
await File.WriteAllBytesAsync(tmp, payload);
|
|
|
|
var stdout = new StringWriter();
|
|
var code = await ToolEntrypoint.RunAsync(new[]
|
|
{
|
|
"--payload", tmp,
|
|
"--signature-hex", sig,
|
|
"--key-hex", key,
|
|
"--signed-at", "2025-11-22T00:00:00Z"
|
|
}, stdout, new StringWriter(), new TestTimeProvider(new DateTimeOffset(2025,11,22,0,0,0,TimeSpan.Zero)));
|
|
|
|
Assert.Equal(0, code);
|
|
Assert.Contains("\"valid\":true", stdout.ToString());
|
|
}
|
|
}
|