Skip to content

Commit

Permalink
[YetiCommon] Rename test binaries
Browse files Browse the repository at this point in the history
Adds .dat to test binary names, which should prevent accidental
execution. Note that the tests don't actually execute the binaries,
but rather just parse the header info.

GitOrigin-RevId: dc3dbbafa9c619b8c062a2444951cff8c3f5a2cb
  • Loading branch information
ljusten authored and copybara-github committed Dec 19, 2022
1 parent 1413459 commit 13c79be
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 33 deletions.
48 changes: 27 additions & 21 deletions YetiCommon.Tests/ModuleParserTests.ParseBuildIdInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ namespace YetiCommon.Tests
{
public partial class ModuleParserTests
{
[TestCase("hello_cpp.exe", ModuleFormat.Pe, "DD2CC932-5E32-4D66-8B03-875CC0965322-00000001")]
[TestCase("hello_cpp.pdb", ModuleFormat.Pdb, "DD2CC932-5E32-4D66-8B03-875CC0965322-00000001")]
[TestCase("hello", ModuleFormat.Elf, "7119D4F0-85EB-2938-0EAF-23B40BA54FC1-73BF3747")]
[TestCase("hello_dotnet.exe", ModuleFormat.Pe, "445A5B1C-1EF1-4B03-8193-7A4B770873AB-00000001")]
[TestCase("hello_dotnet.pdb", ModuleFormat.Pdb, "FDF485D6-E134-4825-885F-03517602265D-00000001")]
[TestCase("hello_dotnet.dll", ModuleFormat.Pe, "FDF485D6-E134-4825-885F-03517602265D-00000001")]
[TestCase("hello_cpp_exe.dat", ModuleFormat.Pe,
"DD2CC932-5E32-4D66-8B03-875CC0965322-00000001")]
[TestCase("hello_cpp_pdb.dat", ModuleFormat.Pdb,
"DD2CC932-5E32-4D66-8B03-875CC0965322-00000001")]
[TestCase("hello_elf.dat", ModuleFormat.Elf,
"7119D4F0-85EB-2938-0EAF-23B40BA54FC1-73BF3747")]
[TestCase("hello_dotnet_exe.dat", ModuleFormat.Pe,
"445A5B1C-1EF1-4B03-8193-7A4B770873AB-00000001")]
[TestCase("hello_dotnet_pdb.dat", ModuleFormat.Pdb,
"FDF485D6-E134-4825-885F-03517602265D-00000001")]
[TestCase("hello_dotnet_dll.dat", ModuleFormat.Pe,
"FDF485D6-E134-4825-885F-03517602265D-00000001")]
public void ParseBuildId_Succeeds(string filename, ModuleFormat format, string buildId)
{
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "binaries",
filename);
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData",
"ModuleParserTests", filename);
var moduleParser = new ModuleParser();
BuildIdInfo output = moduleParser.ParseBuildIdInfo(path, format);

Expand All @@ -25,31 +31,31 @@ public void ParseBuildId_Succeeds(string filename, ModuleFormat format, string b
[Test]
public void ParseBuildId_FileNotFound([Values] ModuleFormat format)
{
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "binaries",
"unknown_file");
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData",
"ModuleParserTests", "unknown_file");
var moduleParser = new ModuleParser();
BuildIdInfo output = moduleParser.ParseBuildIdInfo(path, format);

Assert.That(output.Error.EndsWith("unknown_file not found"));
}

[TestCase("hello_cpp.exe", ModuleFormat.Elf)]
[TestCase("hello_cpp.exe", ModuleFormat.Pdb)]
[TestCase("hello_cpp.pdb", ModuleFormat.Elf)]
[TestCase("hello_cpp.pdb", ModuleFormat.Pe)]
[TestCase("hello", ModuleFormat.Pe)]
[TestCase("hello", ModuleFormat.Pdb)]
[TestCase("hello_dotnet.dll", ModuleFormat.Elf)]
[TestCase("hello_dotnet.dll", ModuleFormat.Pdb)]
[TestCase("hello_cpp_exe.dat", ModuleFormat.Elf)]
[TestCase("hello_cpp_exe.dat", ModuleFormat.Pdb)]
[TestCase("hello_cpp_pdb.dat", ModuleFormat.Elf)]
[TestCase("hello_cpp_pdb.dat", ModuleFormat.Pe)]
[TestCase("hello_elf.dat", ModuleFormat.Pe)]
[TestCase("hello_elf.dat", ModuleFormat.Pdb)]
[TestCase("hello_dotnet_dll.dat", ModuleFormat.Elf)]
[TestCase("hello_dotnet_dll.dat", ModuleFormat.Pdb)]
public void ParseBuildId_IncorrectFormat(string filename, ModuleFormat format)
{
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "binaries",
filename);
string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData",
"ModuleParserTests", filename);
var moduleParser = new ModuleParser();
BuildIdInfo output = moduleParser.ParseBuildIdInfo(path, format);

Assert.IsTrue(output.HasError);
Assert.That(output.Error.Equals(ErrorStrings.InvalidSymbolFileFormat(path, format)));
}
}
}
}
5 changes: 5 additions & 0 deletions YetiCommon.Tests/TestData/ModuleParserTests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ModuleParserTests binaries

The ModuleParserTests parse different binary test files. To prevent detection
of binaries in the code base, and accidental execution, the files have been
named `.dat`.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 17 additions & 12 deletions YetiCommon.Tests/YetiCommon.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<None Remove="binaries\hello" />
<None Remove="binaries\hello_cpp.exe" />
<None Remove="binaries\hello_cpp.pdb" />
<None Remove="binaries\hello_dotnet.dll" />
<None Remove="binaries\hello_dotnet.exe" />
<None Remove="binaries\hello_dotnet.pdb" />
<Compile Remove="binaries\**" />
<EmbeddedResource Remove="binaries\**" />
<None Remove="binaries\**" />
</ItemGroup>
<ItemGroup>
<None Remove="TestData\ModuleParserTests\hello_cpp_exe.dat" />
<None Remove="TestData\ModuleParserTests\hello_cpp_pdb.dat" />
<None Remove="TestData\ModuleParserTests\hello_dotnet_dll.dat" />
<None Remove="TestData\ModuleParserTests\hello_dotnet_exe.dat" />
<None Remove="TestData\ModuleParserTests\hello_dotnet_pdb.dat" />
<None Remove="TestData\ModuleParserTests\hello_elf.dat" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Web" />
Expand Down Expand Up @@ -75,22 +80,22 @@
</None>
</ItemGroup>
<ItemGroup>
<Content Include="binaries\hello_cpp.exe">
<Content Include="TestData\ModuleParserTests\hello_cpp_exe.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="binaries\hello_cpp.pdb">
<Content Include="TestData\ModuleParserTests\hello_cpp_pdb.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="binaries\hello">
<Content Include="TestData\ModuleParserTests\hello_dotnet_dll.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="binaries\hello_dotnet.dll">
<Content Include="TestData\ModuleParserTests\hello_dotnet_exe.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="binaries\hello_dotnet.exe">
<Content Include="TestData\ModuleParserTests\hello_dotnet_pdb.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="binaries\hello_dotnet.pdb">
<Content Include="TestData\ModuleParserTests\hello_elf.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down

0 comments on commit 13c79be

Please sign in to comment.