up
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using FluentAssertions;
|
||||
using StellaOps.Scanner.Analyzers.Native.Observations;
|
||||
using StellaOps.Scanner.Analyzers.Native.Reachability;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Scanner.Analyzers.Native.Tests.Reachability;
|
||||
|
||||
public class NativeReachabilityGraphBuilderTests
|
||||
{
|
||||
[Fact]
|
||||
public void Build_ConstructsDeterministicGraphWithSyntheticRoots()
|
||||
{
|
||||
// Arrange
|
||||
var document = new NativeObservationDocument
|
||||
{
|
||||
Binary = new NativeObservationBinary
|
||||
{
|
||||
Path = "/usr/bin/test",
|
||||
Format = "elf",
|
||||
BuildId = "abcd1234",
|
||||
Architecture = "x86_64",
|
||||
Is64Bit = true,
|
||||
},
|
||||
Entrypoints =
|
||||
[
|
||||
new NativeObservationEntrypoint
|
||||
{
|
||||
Type = "main",
|
||||
Symbol = "_start",
|
||||
}
|
||||
],
|
||||
DeclaredEdges =
|
||||
[
|
||||
new NativeObservationDeclaredEdge
|
||||
{
|
||||
Target = "libc.so.6",
|
||||
Reason = "elf-dtneeded",
|
||||
}
|
||||
],
|
||||
HeuristicEdges =
|
||||
[
|
||||
new NativeObservationHeuristicEdge
|
||||
{
|
||||
Target = "libplugin.so",
|
||||
Reason = "string-dlopen",
|
||||
Confidence = "medium",
|
||||
}
|
||||
],
|
||||
Environment = new NativeObservationEnvironment()
|
||||
};
|
||||
|
||||
// Act
|
||||
var graph = NativeReachabilityGraphBuilder.Build(document, layerDigest: "sha256:layer1");
|
||||
|
||||
// Assert
|
||||
graph.LayerDigest.Should().Be("sha256:layer1");
|
||||
graph.BuildId.Should().Be("abcd1234");
|
||||
graph.Nodes.Should().ContainSingle(n => n.Kind == "root");
|
||||
graph.Nodes.Should().ContainSingle(n => n.Kind == "binary");
|
||||
graph.Nodes.Should().Contain(n => n.Name == "libc.so.6");
|
||||
graph.Edges.Should().Contain(e => e.Reason == "entrypoint");
|
||||
graph.Edges.Should().Contain(e => e.Reason == "elf-dtneeded");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToBundle_WrapsGraphWithPayloadType()
|
||||
{
|
||||
// Arrange
|
||||
var document = new NativeObservationDocument
|
||||
{
|
||||
Binary = new NativeObservationBinary
|
||||
{
|
||||
Path = "/usr/bin/test",
|
||||
Format = "elf",
|
||||
Sha256 = "aa",
|
||||
Is64Bit = true,
|
||||
},
|
||||
Environment = new NativeObservationEnvironment()
|
||||
};
|
||||
|
||||
// Act
|
||||
var bundle = NativeReachabilityGraphBuilder.ToBundle(document);
|
||||
|
||||
// Assert
|
||||
bundle.PayloadType.Should().Be("stellaops.native.graph@1");
|
||||
bundle.Graph.Nodes.Should().NotBeEmpty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user