Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize .tar.gz file extension sign info parsing #15265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Microsoft.DotNet.SignTool.Tests/SignToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,19 @@ public void ValidateParseFileExtensionEntriesForDifferentCollisionPriorityIdSucc
runTask(fileExtensionSignInfo: fileExtensionSignInfo.ToArray()).Should().BeTrue();
}

[Fact]
public void ValidateParseFileExtensionEntriesForTarGzExtensionPasses()
{
var fileExtensionSignInfo = new List<ITaskItem>();

fileExtensionSignInfo.Add(new TaskItem(".tar.gz", new Dictionary<string, string>
{
{ "CertificateName", "None" }
}));

runTask(fileExtensionSignInfo: fileExtensionSignInfo.ToArray()).Should().BeTrue();
}

// Given:
// - "SameFiles1.zip" contains "Simple1.exe" and "Simple2.exe"
// - "SameFiles2.zip" contains "Simple1.exe"
Expand Down
10 changes: 7 additions & 3 deletions src/Microsoft.DotNet.SignTool/src/SignToolTask.cs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ int getCommonPrefixLength(string[] dir1, string[] dir2)
}
}

private readonly HashSet<string> specialExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".tar.gz"
};

private Dictionary<string, List<SignInfo>> ParseFileExtensionSignInfo()
{
var map = new Dictionary<string, List<SignInfo>>(StringComparer.OrdinalIgnoreCase);
Expand All @@ -375,9 +380,8 @@ private Dictionary<string, List<SignInfo>> ParseFileExtensionSignInfo()
var certificate = item.GetMetadata("CertificateName");
var collisionPriorityId = item.GetMetadata(SignToolConstants.CollisionPriorityId);

// Path.GetExtension will return .gz for .tar.gz files, so we need to handle that case separately
var actualExtension = extension.Equals(".tar.gz", StringComparison.OrdinalIgnoreCase) ? ".tar.gz" : Path.GetExtension(extension);
if (!extension.Equals(actualExtension))
// Some supported extensions have multiple dots. Special case these so that we don't throw an error below.
if (!extension.Equals(Path.GetExtension(extension)) && !specialExtensions.Contains(extension))
{
Log.LogError($"Value of {nameof(FileExtensionSignInfo)} is invalid: '{extension}'");
continue;
Expand Down
Loading