audit notes work completed, test fixes work (95% done), new sprints, new data sources setup and configuration

This commit is contained in:
master
2026-01-14 10:48:00 +02:00
parent d7be6ba34b
commit 95d5898650
379 changed files with 40695 additions and 19041 deletions

View File

@@ -231,7 +231,7 @@ internal sealed class AttestorWebApplicationFactory : WebApplicationFactory<Prog
displayName: null,
configureOptions: options => { options.TimeProvider ??= TimeProvider.System; });
#pragma warning disable CS0618
services.TryAddSingleton<ISystemClock, SystemClock>();
services.TryAddSingleton<TimeProvider, SystemClock>();
#pragma warning restore CS0618
});
}
@@ -246,7 +246,7 @@ internal sealed class TestAuthHandler : AuthenticationHandler<AuthenticationSche
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock)
TimeProvider clock)
: base(options, logger, encoder, clock)
{
}
@@ -272,3 +272,4 @@ internal sealed class TestAuthHandler : AuthenticationHandler<AuthenticationSche
return Task.FromResult(AuthenticateResult.Success(ticket));
}
}

View File

@@ -0,0 +1,295 @@
using StellaOps.Attestor.GraphRoot;
using StellaOps.Attestor.GraphRoot.Models;
using Xunit;
namespace StellaOps.Attestor.GraphRoot.Tests;
/// <summary>
/// Tests for GraphType enum.
/// </summary>
public sealed class GraphTypeTests
{
[Theory]
[InlineData(GraphType.Unknown)]
[InlineData(GraphType.CallGraph)]
[InlineData(GraphType.DependencyGraph)]
[InlineData(GraphType.SbomGraph)]
[InlineData(GraphType.EvidenceGraph)]
[InlineData(GraphType.PolicyGraph)]
[InlineData(GraphType.ProofSpine)]
[InlineData(GraphType.ReachabilityGraph)]
[InlineData(GraphType.VexLinkageGraph)]
public void GraphType_AllValues_AreDefined(GraphType graphType)
{
Assert.True(Enum.IsDefined(graphType));
}
[Theory]
[InlineData(GraphType.Unknown, 0)]
[InlineData(GraphType.CallGraph, 1)]
[InlineData(GraphType.DependencyGraph, 2)]
[InlineData(GraphType.SbomGraph, 3)]
[InlineData(GraphType.EvidenceGraph, 4)]
[InlineData(GraphType.PolicyGraph, 5)]
[InlineData(GraphType.ProofSpine, 6)]
[InlineData(GraphType.ReachabilityGraph, 7)]
[InlineData(GraphType.VexLinkageGraph, 8)]
public void GraphType_Values_HaveCorrectNumericValue(GraphType graphType, int expected)
{
Assert.Equal(expected, (int)graphType);
}
}
/// <summary>
/// Tests for GraphRootPredicateTypes constants.
/// </summary>
public sealed class GraphRootPredicateTypesTests
{
[Fact]
public void GraphRootV1_HasCorrectUri()
{
Assert.Equal("https://stella-ops.org/attestation/graph-root/v1", GraphRootPredicateTypes.GraphRootV1);
}
}
/// <summary>
/// Tests for GraphRootAttestation record.
/// </summary>
public sealed class GraphRootAttestationTests
{
[Fact]
public void GraphRootAttestation_Type_DefaultsToInTotoStatement()
{
var subject = new GraphRootSubject
{
Name = "root-hash",
Digest = new Dictionary<string, string> { ["sha256"] = "abc123" }
};
var predicate = CreateTestPredicate();
var attestation = new GraphRootAttestation
{
Subject = [subject],
Predicate = predicate
};
Assert.Equal("https://in-toto.io/Statement/v1", attestation.Type);
}
[Fact]
public void GraphRootAttestation_PredicateType_DefaultsToGraphRootV1()
{
var subject = new GraphRootSubject
{
Name = "artifact",
Digest = new Dictionary<string, string> { ["sha256"] = "xyz789" }
};
var attestation = new GraphRootAttestation
{
Subject = [subject],
Predicate = CreateTestPredicate()
};
Assert.Equal(GraphRootPredicateTypes.GraphRootV1, attestation.PredicateType);
}
[Fact]
public void GraphRootAttestation_RequiredProperties_MustBeSet()
{
var subjects = new List<GraphRootSubject>
{
new GraphRootSubject
{
Name = "sha256:deadbeef",
Digest = new Dictionary<string, string> { ["sha256"] = "deadbeef" }
}
};
var predicate = CreateTestPredicate();
var attestation = new GraphRootAttestation
{
Subject = subjects,
Predicate = predicate
};
Assert.Single(attestation.Subject);
Assert.NotNull(attestation.Predicate);
}
private static GraphRootPredicate CreateTestPredicate()
{
return new GraphRootPredicate
{
GraphType = "call-graph",
RootHash = "sha256:abc123def456",
NodeCount = 10,
EdgeCount = 15,
NodeIds = ["node-1", "node-2"],
EdgeIds = ["edge-1", "edge-2"],
Inputs = new GraphInputDigests
{
PolicyDigest = "sha256:policy-hash",
FeedsDigest = "sha256:feeds-hash",
ToolchainDigest = "sha256:toolchain-hash",
ParamsDigest = "sha256:params-hash"
},
CanonVersion = "1.0.0",
ComputedAt = DateTimeOffset.UtcNow,
ComputedBy = "test-tool",
ComputedByVersion = "1.0.0"
};
}
}
/// <summary>
/// Tests for GraphRootSubject record.
/// </summary>
public sealed class GraphRootSubjectTests
{
[Fact]
public void GraphRootSubject_RequiredProperties_MustBeSet()
{
var subject = new GraphRootSubject
{
Name = "artifact-name",
Digest = new Dictionary<string, string>
{
["sha256"] = "abcdef123456"
}
};
Assert.Equal("artifact-name", subject.Name);
Assert.Single(subject.Digest);
Assert.Equal("abcdef123456", subject.Digest["sha256"]);
}
[Fact]
public void GraphRootSubject_MultipleDigests_Supported()
{
var subject = new GraphRootSubject
{
Name = "multi-digest-artifact",
Digest = new Dictionary<string, string>
{
["sha256"] = "sha256hash",
["sha512"] = "sha512hash"
}
};
Assert.Equal(2, subject.Digest.Count);
}
}
/// <summary>
/// Tests for GraphRootPredicate record.
/// </summary>
public sealed class GraphRootPredicateTests
{
[Fact]
public void GraphRootPredicate_RootAlgorithm_DefaultsToSha256()
{
var predicate = new GraphRootPredicate
{
GraphType = "dependency-graph",
RootHash = "sha256:hash",
NodeCount = 5,
EdgeCount = 8,
NodeIds = [],
EdgeIds = [],
Inputs = new GraphInputDigests
{
PolicyDigest = "sha256:p",
FeedsDigest = "sha256:f",
ToolchainDigest = "sha256:t",
ParamsDigest = "sha256:params"
},
CanonVersion = "1.0.0",
ComputedAt = DateTimeOffset.UtcNow,
ComputedBy = "test-tool",
ComputedByVersion = "1.0.0"
};
Assert.Equal("sha256", predicate.RootAlgorithm);
}
[Fact]
public void GraphRootPredicate_EvidenceIds_DefaultsToEmpty()
{
var predicate = new GraphRootPredicate
{
GraphType = "sbom-graph",
RootHash = "sha256:xyz",
NodeCount = 100,
EdgeCount = 200,
NodeIds = ["a", "b", "c"],
EdgeIds = ["e1", "e2"],
Inputs = new GraphInputDigests
{
PolicyDigest = "sha256:p",
FeedsDigest = "sha256:f",
ToolchainDigest = "sha256:t",
ParamsDigest = "sha256:params"
},
CanonVersion = "1.0.0",
ComputedAt = DateTimeOffset.UtcNow,
ComputedBy = "test-tool",
ComputedByVersion = "1.0.0"
};
Assert.Empty(predicate.EvidenceIds);
}
[Fact]
public void GraphRootPredicate_WithEvidenceIds_ContainsValues()
{
var predicate = new GraphRootPredicate
{
GraphType = "evidence-graph",
RootHash = "sha256:root",
NodeCount = 20,
EdgeCount = 30,
NodeIds = [],
EdgeIds = [],
Inputs = new GraphInputDigests
{
PolicyDigest = "sha256:p",
FeedsDigest = "sha256:f",
ToolchainDigest = "sha256:t",
ParamsDigest = "sha256:params"
},
EvidenceIds = ["ev-001", "ev-002", "ev-003"],
CanonVersion = "1.0.0",
ComputedAt = DateTimeOffset.UtcNow,
ComputedBy = "test-tool",
ComputedByVersion = "1.0.0"
};
Assert.Equal(3, predicate.EvidenceIds.Count);
}
}
/// <summary>
/// Tests for GraphInputDigests record.
/// </summary>
public sealed class GraphInputDigestsTests
{
[Fact]
public void GraphInputDigests_RequiredProperties_MustBeSet()
{
var inputs = new GraphInputDigests
{
PolicyDigest = "sha256:policy-digest",
FeedsDigest = "sha256:feeds-digest",
ToolchainDigest = "sha256:toolchain-digest",
ParamsDigest = "sha256:params-digest"
};
Assert.Equal("sha256:policy-digest", inputs.PolicyDigest);
Assert.Equal("sha256:feeds-digest", inputs.FeedsDigest);
Assert.Equal("sha256:toolchain-digest", inputs.ToolchainDigest);
Assert.Equal("sha256:params-digest", inputs.ParamsDigest);
}
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<UseXunitV3>true</UseXunitV3>
</PropertyGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Moq" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\__Libraries\StellaOps.Attestor.GraphRoot\StellaOps.Attestor.GraphRoot.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"diagnosticMessages": true,
"parallelizeAssembly": true,
"parallelizeTestCollections": true,
"maxParallelThreads": -1
}