Refactor code structure and optimize performance across multiple modules

This commit is contained in:
StellaOps Bot
2025-12-26 20:03:22 +02:00
parent c786faae84
commit f10d83c444
1385 changed files with 69732 additions and 10280 deletions

View File

@@ -7,7 +7,8 @@ namespace StellaOps.Scanner.Analyzers.Native.Tests;
public class ElfDynamicSectionParserTests : NativeTestBase
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ParsesMinimalElfWithNoDynamicSection()
{
// Minimal ELF64 with no dependencies (static binary scenario)
@@ -21,7 +22,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
info.Runpath.Should().BeEmpty();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ParsesElfWithDtNeeded()
{
// Build ELF with DT_NEEDED entries using the builder
@@ -38,7 +40,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
info.Dependencies[2].Soname.Should().Be("libpthread.so.0");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ParsesElfWithRpathAndRunpath()
{
// Build ELF with rpath and runpath using the builder
@@ -53,7 +56,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
info.Runpath.Should().BeEquivalentTo(["$ORIGIN/../lib"]);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ParsesElfWithInterpreterAndBuildId()
{
// Build ELF with interpreter and build ID using the builder
@@ -67,7 +71,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
info.BinaryId.Should().Be("deadbeef0102030405060708090a0b0c");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void DeduplicatesDtNeededEntries()
{
// ElfBuilder deduplicates internally, so add "duplicates" via builder
@@ -85,7 +90,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
info.Dependencies[0].Soname.Should().Be("libc.so.6");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ReturnsFalseForNonElfData()
{
var buffer = new byte[] { 0x00, 0x01, 0x02, 0x03 };
@@ -96,7 +102,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
result.Should().BeFalse();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ReturnsFalseForPeFile()
{
var buffer = new byte[256];
@@ -104,12 +111,14 @@ public class ElfDynamicSectionParserTests : NativeTestBase
buffer[1] = (byte)'Z';
using var stream = new MemoryStream(buffer);
using StellaOps.TestKit;
var result = ElfDynamicSectionParser.TryParse(stream, out var info);
result.Should().BeFalse();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ParsesElfWithVersionNeeds()
{
// Test that version needs (GLIBC_2.17, etc.) are properly extracted
@@ -128,7 +137,8 @@ public class ElfDynamicSectionParserTests : NativeTestBase
info.Dependencies[0].VersionNeeds.Should().Contain(v => v.Version == "GLIBC_2.28");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ParsesElfWithWeakVersionNeeds()
{
// Test that weak version requirements (VER_FLG_WEAK) are properly detected