Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -6,7 +6,8 @@ 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 +27,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 +48,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 +69,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 +90,8 @@ public class HeuristicScannerTests
|
||||
simpleSoname.Confidence.Should().Be(HeuristicConfidence.Medium);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsPluginConfigReferences()
|
||||
{
|
||||
// Arrange
|
||||
@@ -106,7 +111,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 +132,8 @@ public class HeuristicScannerTests
|
||||
e.Confidence == HeuristicConfidence.High);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_DetectsGoCgoStaticImport()
|
||||
{
|
||||
// Arrange
|
||||
@@ -145,7 +152,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 +172,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 +191,8 @@ public class HeuristicScannerTests
|
||||
edge.FileOffset.Should().Be(100);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ScanForDynamicLoading_ReturnsOnlyLibraryEdges()
|
||||
{
|
||||
// Arrange
|
||||
@@ -200,7 +210,8 @@ public class HeuristicScannerTests
|
||||
e.ReasonCode == HeuristicReasonCodes.StringDlopen);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ScanForPluginConfigs_ReturnsOnlyConfigReferences()
|
||||
{
|
||||
// Arrange
|
||||
@@ -219,7 +230,8 @@ public class HeuristicScannerTests
|
||||
configs.Should().Contain("plugin.json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Scan_EmptyStream_ReturnsEmptyResult()
|
||||
{
|
||||
// Arrange
|
||||
@@ -233,7 +245,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 +260,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)]
|
||||
@@ -261,6 +275,7 @@ public class HeuristicScannerTests
|
||||
|
||||
// Act
|
||||
using var stream = new MemoryStream(data);
|
||||
using StellaOps.TestKit;
|
||||
var result = HeuristicScanner.Scan(stream, NativeFormat.Elf);
|
||||
|
||||
// Assert
|
||||
|
||||
Reference in New Issue
Block a user