feat(telemetry): add telemetry client and services for tracking events
- Implemented TelemetryClient to handle event queuing and flushing to the telemetry endpoint. - Created TtfsTelemetryService for emitting specific telemetry events related to TTFS. - Added tests for TelemetryClient to ensure event queuing and flushing functionality. - Introduced models for reachability drift detection, including DriftResult and DriftedSink. - Developed DriftApiService for interacting with the drift detection API. - Updated FirstSignalCardComponent to emit telemetry events on signal appearance. - Enhanced localization support for first signal component with i18n strings.
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// InternalCallGraphTests.cs
|
||||
// Sprint: SPRINT_3700_0003_0001_trigger_extraction
|
||||
// Description: Unit tests for InternalCallGraph.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
using StellaOps.Scanner.VulnSurfaces.CallGraph;
|
||||
using StellaOps.Scanner.VulnSurfaces.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Scanner.VulnSurfaces.Tests;
|
||||
|
||||
public class InternalCallGraphTests
|
||||
{
|
||||
[Fact]
|
||||
public void AddMethod_StoresMethod()
|
||||
{
|
||||
// Arrange
|
||||
var graph = new InternalCallGraph
|
||||
{
|
||||
PackageId = "TestPackage",
|
||||
Version = "1.0.0"
|
||||
};
|
||||
|
||||
var method = new InternalMethodRef
|
||||
{
|
||||
MethodKey = "Namespace.Class::Method()",
|
||||
Name = "Method",
|
||||
DeclaringType = "Namespace.Class",
|
||||
IsPublic = true
|
||||
};
|
||||
|
||||
// Act
|
||||
graph.AddMethod(method);
|
||||
|
||||
// Assert
|
||||
Assert.True(graph.ContainsMethod("Namespace.Class::Method()"));
|
||||
Assert.Equal(1, graph.MethodCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddEdge_CreatesForwardAndReverseMapping()
|
||||
{
|
||||
// Arrange
|
||||
var graph = new InternalCallGraph
|
||||
{
|
||||
PackageId = "TestPackage",
|
||||
Version = "1.0.0"
|
||||
};
|
||||
|
||||
var edge = new InternalCallEdge
|
||||
{
|
||||
Caller = "A::M1()",
|
||||
Callee = "A::M2()"
|
||||
};
|
||||
|
||||
// Act
|
||||
graph.AddEdge(edge);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("A::M2()", graph.GetCallees("A::M1()"));
|
||||
Assert.Contains("A::M1()", graph.GetCallers("A::M2()"));
|
||||
Assert.Equal(1, graph.EdgeCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPublicMethods_ReturnsOnlyPublic()
|
||||
{
|
||||
// Arrange
|
||||
var graph = new InternalCallGraph
|
||||
{
|
||||
PackageId = "TestPackage",
|
||||
Version = "1.0.0"
|
||||
};
|
||||
|
||||
graph.AddMethod(new InternalMethodRef
|
||||
{
|
||||
MethodKey = "A::Public()",
|
||||
Name = "Public",
|
||||
DeclaringType = "A",
|
||||
IsPublic = true
|
||||
});
|
||||
|
||||
graph.AddMethod(new InternalMethodRef
|
||||
{
|
||||
MethodKey = "A::Private()",
|
||||
Name = "Private",
|
||||
DeclaringType = "A",
|
||||
IsPublic = false
|
||||
});
|
||||
|
||||
// Act
|
||||
var publicMethods = graph.GetPublicMethods().ToList();
|
||||
|
||||
// Assert
|
||||
Assert.Single(publicMethods);
|
||||
Assert.Equal("A::Public()", publicMethods[0].MethodKey);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCallees_EmptyForUnknownMethod()
|
||||
{
|
||||
// Arrange
|
||||
var graph = new InternalCallGraph
|
||||
{
|
||||
PackageId = "TestPackage",
|
||||
Version = "1.0.0"
|
||||
};
|
||||
|
||||
// Act
|
||||
var callees = graph.GetCallees("Unknown::Method()");
|
||||
|
||||
// Assert
|
||||
Assert.Empty(callees);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetMethod_ReturnsNullForUnknown()
|
||||
{
|
||||
// Arrange
|
||||
var graph = new InternalCallGraph
|
||||
{
|
||||
PackageId = "TestPackage",
|
||||
Version = "1.0.0"
|
||||
};
|
||||
|
||||
// Act
|
||||
var method = graph.GetMethod("Unknown::Method()");
|
||||
|
||||
// Assert
|
||||
Assert.Null(method);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user