Skip to content

Commit

Permalink
Merge branch 'thomaslevesque-sign-all-files-at-once' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Mar 7, 2017
2 parents b0858c5 + 9b883fd commit 0632cae
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
Expand Up @@ -14,10 +14,9 @@ namespace Cake.Common.Tests.Fixtures.Tools
internal sealed class SignToolSignRunnerFixture : ToolFixture<SignToolSignSettings>
{
public ISignToolResolver Resolver { get; set; }
public IFile AssemblyFile { get; set; }
public IFile CertificateFile { get; set; }

public FilePath AssemblyPath { get; set; }
public FilePath[] AssemblyPaths { get; set; }

public SignToolSignRunnerFixture()
: base("signtool.exe")
Expand All @@ -26,7 +25,7 @@ public SignToolSignRunnerFixture()
Settings.Password = "secret";
Settings.TimeStampUri = new Uri("https://t.com");

AssemblyPath = new FilePath("./a.dll");
AssemblyPaths = new[] { new FilePath("./a.dll") };
FileSystem.CreateFile("/Working/a.dll");
FileSystem.CreateFile("/Working/cert.pfx");

Expand All @@ -36,7 +35,7 @@ public SignToolSignRunnerFixture()
protected override void RunTool()
{
var tool = new SignToolSignRunner(FileSystem, Environment, ProcessRunner, Tools, null, Resolver);
tool.Run(AssemblyPath, Settings);
tool.Run(AssemblyPaths, Settings);
}
}
}
Expand Up @@ -6,6 +6,7 @@
using Cake.Common.Tests.Fixtures.Tools;
using Cake.Common.Tools.SignTool;
using Cake.Core;
using Cake.Core.IO;
using Cake.Testing;
using Xunit;

Expand Down Expand Up @@ -61,17 +62,17 @@ public void Should_Throw_If_Process_Runner_Is_Null()
public sealed class TheRunMethod
{
[Fact]
public void Should_Throw_If_Assembly_Path_Is_Null()
public void Should_Throw_If_Assembly_Paths_Is_Null()
{
// Given
var fixture = new SignToolSignRunnerFixture();
fixture.AssemblyPath = null;
fixture.AssemblyPaths = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
Assert.IsArgumentNullException(result, "assemblyPath");
Assert.IsArgumentNullException(result, "assemblyPaths");
}

[Fact]
Expand Down Expand Up @@ -371,6 +372,28 @@ public void Should_Call_Sign_Tool_With_Correct_Parameters_With_Append_Signature(
// Then
Assert.Equal("SIGN /t \"https://t.com/\" /f \"/Working/cert.pfx\" /p secret /as \"/Working/a.dll\"", result.Args);
}

[Fact]
public void Should_Call_Sign_Tool_With_Correct_Parameters_With_Thumbprint_And_Multiple_Assemblies()
{
// Given
var fixture = new SignToolSignRunnerFixture();
fixture.Settings.CertPath = null;
fixture.Settings.Password = null;
fixture.Settings.CertThumbprint = "ThumbprintTest";
fixture.AssemblyPaths = new[]
{
new FilePath("./a.dll"),
new FilePath("./foo/b.dll")
};
fixture.FileSystem.CreateFile("/Working/foo/b.dll");

// When
var result = fixture.Run();

// Then
Assert.Equal("SIGN /t \"https://t.com/\" /sha1 \"ThumbprintTest\" \"/Working/a.dll\" \"/Working/foo/b.dll\"", result.Args);
}
}
}
}
5 changes: 1 addition & 4 deletions src/Cake.Common/Tools/SignTool/SignToolSignAliases.cs
Expand Up @@ -162,10 +162,7 @@ public static void Sign(this ICakeContext context, IEnumerable<FilePath> assembl
}

var runner = new SignToolSignRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools, context.Registry);
foreach (var assembly in assemblies)
{
runner.Run(assembly, settings);
}
runner.Run(assemblies, settings);
}
}
}
37 changes: 20 additions & 17 deletions src/Cake.Common/Tools/SignTool/SignToolSignRunner.cs
Expand Up @@ -60,36 +60,36 @@ public sealed class SignToolSignRunner : Tool<SignToolSignSettings>
}

/// <summary>
/// Signs the specified assembly.
/// Signs the specified assemblies.
/// </summary>
/// <param name="assemblyPath">The assembly path.</param>
/// <param name="assemblyPaths">The assembly paths.</param>
/// <param name="settings">The settings.</param>
public void Run(FilePath assemblyPath, SignToolSignSettings settings)
public void Run(IEnumerable<FilePath> assemblyPaths, SignToolSignSettings settings)
{
if (assemblyPath == null)
if (assemblyPaths == null)
{
throw new ArgumentNullException(nameof(assemblyPath));
throw new ArgumentNullException(nameof(assemblyPaths));
}
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}

if (assemblyPath.IsRelative)
{
assemblyPath = assemblyPath.MakeAbsolute(_environment);
}
var absoluteAssemblyPaths = assemblyPaths.Select(p => p.IsRelative ? p.MakeAbsolute(_environment) : p).ToArray();

Run(settings, GetArguments(assemblyPath, settings));
Run(settings, GetArguments(absoluteAssemblyPaths, settings));
}

private ProcessArgumentBuilder GetArguments(FilePath assemblyPath, SignToolSignSettings settings)
private ProcessArgumentBuilder GetArguments(FilePath[] absoluteAssemblyPaths, SignToolSignSettings settings)
{
if (!_fileSystem.Exist(assemblyPath))
foreach (var path in absoluteAssemblyPaths)
{
const string format = "{0}: The assembly '{1}' does not exist.";
var message = string.Format(CultureInfo.InvariantCulture, format, GetToolName(), assemblyPath.FullPath);
throw new CakeException(message);
if (!_fileSystem.Exist(path))
{
const string format = "{0}: The assembly '{1}' does not exist.";
var message = string.Format(CultureInfo.InvariantCulture, format, GetToolName(), path.FullPath);
throw new CakeException(message);
}
}

if (settings.TimeStampUri == null)
Expand Down Expand Up @@ -224,8 +224,11 @@ private ProcessArgumentBuilder GetArguments(FilePath assemblyPath, SignToolSignS
builder.Append("/as");
}

// Target Assembly to sign.
builder.AppendQuoted(assemblyPath.MakeAbsolute(_environment).FullPath);
// Target Assemblies to sign.
foreach (var path in absoluteAssemblyPaths)
{
builder.AppendQuoted(path.FullPath);
}

return builder;
}
Expand Down

0 comments on commit 0632cae

Please sign in to comment.