private void ValidateGeneratedProject( string[] itemsToSign, Dictionary <string, SignInfo> strongNameSignInfo, Dictionary <ExplicitCertificateKey, string> fileSignInfo, Dictionary <string, SignInfo> extensionsSignInfo, string[] expectedXmlElementsPerSingingRound, string[] dualCertificates = null) { var buildEngine = new FakeBuildEngine(); var task = new SignToolTask { BuildEngine = buildEngine }; // The path to MSBuild will always be null in these tests, this will force // the signing logic to call our FakeBuildEngine.BuildProjectFile with a path // to the XML that store the content of the would be Microbuild sign request. var signToolArgs = new SignToolArgs(_tmpDir, microBuildCorePath: "MicroBuildCorePath", testSign: true, msBuildPath: null, _tmpDir, enclosingDir: "", ""); var signTool = new FakeSignTool(signToolArgs, task.Log); var signingInput = new Configuration(signToolArgs.TempDir, itemsToSign, strongNameSignInfo, fileSignInfo, extensionsSignInfo, dualCertificates, task.Log).GenerateListOfFiles(); var util = new BatchSignUtil(task.BuildEngine, task.Log, signTool, signingInput, new string[] { }); util.Go(false); Assert.Same(ByteSequenceComparer.Instance, signingInput.ZipDataMap.KeyComparer); // The list of files that would be signed was captured inside the FakeBuildEngine, // here we check if that matches what we expected var actualXmlElementsPerSingingRound = buildEngine.FilesToSign.Select(round => string.Join(Environment.NewLine, round)); AssertEx.Equal(expectedXmlElementsPerSingingRound, actualXmlElementsPerSingingRound, comparer: AssertEx.EqualIgnoringWhitespace, itemInspector: s => s.Replace("\"", "\"\"")); Assert.False(task.Log.HasLoggedErrors); }
private void TestCaseEpilogue(string[] itemsToSign, Dictionary <string, SignInfo> strongNameSignInfo, Dictionary <ExplicitCertificateKey, string> signingOverridingInfos, List <FileName> expectedToBeSigned) { if (!_isWindows) { return; } var signingInput = new Configuration(_signToolArgs.TempDir, itemsToSign, strongNameSignInfo, signingOverridingInfos, _publishURL, _task.Log).GenerateListOfFiles(); Assert.Equal(expectedToBeSigned.Count, signingInput.FilesToSign.Count()); // Check that all files that were expected to be discovered were actually found and the // signing information for them are correct. var signInfoCheck = signingInput.FilesToSign.All <FileName>(candidate => { return(expectedToBeSigned.Exists(expected => candidate.FullPath.EndsWith(expected.FullPath) && candidate.SignInfo.Certificate == expected.SignInfo.Certificate && candidate.SignInfo.StrongName == expected.SignInfo.StrongName)); }); Assert.True(signInfoCheck); var util = new BatchSignUtil(_task.BuildEngine, _task.Log, _signTool, signingInput, null); util.Go(); // The list of files that would be signed was captured inside the FakeBuildEngine, // here we check if that matches what we expected var fakeEngine = (FakeBuildEngine)_task.BuildEngine; foreach (var expected in expectedToBeSigned) { var signedInfoCheck = fakeEngine.filesSigned.Exists(candidate => candidate.FullPath.EndsWith(expected.FullPath) && candidate.SignInfo.Certificate == expected.SignInfo.Certificate && candidate.SignInfo.StrongName == expected.SignInfo.StrongName); Assert.True(signedInfoCheck, $"Expected this file ({expected.FullPath}) to be signed with this " + $"certificate ({expected.SignInfo.Certificate}) and this strong name ({expected.SignInfo.StrongName})"); } Assert.False(_task.Log.HasLoggedErrors); }