Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -2,11 +2,14 @@ using System.Text;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Scanner.Analyzers.Native.Tests;
|
||||
|
||||
public class HeuristicScannerTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsElfSonamePattern()
|
||||
{
|
||||
// Arrange - binary containing soname strings
|
||||
@@ -26,7 +29,8 @@ public class HeuristicScannerTests
|
||||
result.Edges.Should().OnlyContain(e => e.ReasonCode == HeuristicReasonCodes.StringDlopen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsWindowsDllPattern()
|
||||
{
|
||||
// Arrange
|
||||
@@ -46,7 +50,8 @@ public class HeuristicScannerTests
|
||||
result.Edges.Should().OnlyContain(e => e.ReasonCode == HeuristicReasonCodes.StringLoadLibrary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsMachODylibPattern()
|
||||
{
|
||||
// Arrange
|
||||
@@ -66,7 +71,8 @@ public class HeuristicScannerTests
|
||||
result.Edges.Should().Contain(e => e.LibraryName == "@loader_path/libbaz.dylib");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_AssignsHighConfidenceToPathLikeStrings()
|
||||
{
|
||||
// Arrange
|
||||
@@ -86,7 +92,8 @@ public class HeuristicScannerTests
|
||||
simpleSoname.Confidence.Should().Be(HeuristicConfidence.Medium);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsPluginConfigReferences()
|
||||
{
|
||||
// Arrange
|
||||
@@ -106,7 +113,8 @@ public class HeuristicScannerTests
|
||||
result.PluginConfigs.Should().Contain("modules.conf");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsGoCgoImportDirective()
|
||||
{
|
||||
// Arrange - simulate Go binary with cgo import
|
||||
@@ -126,7 +134,8 @@ public class HeuristicScannerTests
|
||||
e.Confidence == HeuristicConfidence.High);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsGoCgoStaticImport()
|
||||
{
|
||||
// Arrange
|
||||
@@ -145,7 +154,8 @@ public class HeuristicScannerTests
|
||||
e.ReasonCode == HeuristicReasonCodes.GoCgoImport);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DeduplicatesEdgesByLibraryName()
|
||||
{
|
||||
// Arrange - same library mentioned multiple times
|
||||
@@ -164,7 +174,8 @@ public class HeuristicScannerTests
|
||||
result.Edges.Should().ContainSingle(e => e.LibraryName == "libfoo.so");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_IncludesFileOffsetInEdge()
|
||||
{
|
||||
// Arrange
|
||||
@@ -182,7 +193,8 @@ public class HeuristicScannerTests
|
||||
edge.FileOffset.Should().Be(100);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ScanForDynamicLoading_ReturnsOnlyLibraryEdges()
|
||||
{
|
||||
// Arrange
|
||||
@@ -200,7 +212,8 @@ public class HeuristicScannerTests
|
||||
e.ReasonCode == HeuristicReasonCodes.StringDlopen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ScanForPluginConfigs_ReturnsOnlyConfigReferences()
|
||||
{
|
||||
// Arrange
|
||||
@@ -219,7 +232,8 @@ public class HeuristicScannerTests
|
||||
configs.Should().Contain("plugin.json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_EmptyStream_ReturnsEmptyResult()
|
||||
{
|
||||
// Arrange
|
||||
@@ -233,7 +247,8 @@ public class HeuristicScannerTests
|
||||
result.PluginConfigs.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_NoValidStrings_ReturnsEmptyResult()
|
||||
{
|
||||
// Arrange - binary data with no printable strings
|
||||
@@ -247,7 +262,8 @@ public class HeuristicScannerTests
|
||||
result.Edges.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("libfoo.so.1", true)]
|
||||
[InlineData("libbar.so", true)]
|
||||
[InlineData("lib-baz_qux.so.2.3", true)]
|
||||
|
||||
Reference in New Issue
Block a user