Exemple #1
0
        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);
        }
Exemple #2
0
        public void MissingCertificateNameButExtensionIsIgnored(string extension)
        {
            var needContent = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { ".dll", "EmptyPKT.dll" },
                { ".vsix", "Simple.vsix" },
                { ".nupkg", "Simple.nupkg" },
                { ".exe", "Simple.exe" }
            };

            var task = new SignToolTask {
                BuildEngine = new FakeBuildEngine()
            };

            var inputFilePath = needContent.TryGetValue(extension, out var resourcePath) ?
                                GetResourcePath(resourcePath) :
                                CreateTestResource("test" + extension);

            new Configuration(_tmpDir,
                              new string[] { inputFilePath },
                              new Dictionary <string, SignInfo>(),
                              new Dictionary <ExplicitCertificateKey, string>(),
                              new Dictionary <string, SignInfo>()
            {
                { extension, SignInfo.Ignore }
            },
                              new string[0],
                              task.Log)
            .GenerateListOfFiles();

            Assert.False(task.Log.HasLoggedErrors);
        }
Exemple #3
0
        public SignToolTests()
        {
            _microbuildPath = string.Empty;
            _publishURL     = null;
            _testSign       = true;

            // As of now we don't have "mscoree.dll" on Linux. This DLL is used when checking
            // if the file is strong name signed: SignTool/ContentUtil.NativeMethods
            // Therefore, test cases won't execute in fully on non-Windows machines.
            _isWindows = System.Environment.OSVersion.VersionString.Contains("Windows");

            var testBasePath = Guid.NewGuid().ToString();
            var tempPath     = $@"{testBasePath}/TestTempDir/";
            var logDir       = $@"{testBasePath}/TestLogDir/";

            // 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.
            _signToolArgs = new SignToolArgs(tempPath, _microbuildPath, _testSign, null, logDir);

            _signTool = new ValidationOnlySignTool(_signToolArgs);

            _task = new SignToolTask
            {
                BuildEngine = new FakeBuildEngine()
            };
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string           dropFolder         = "{dropFolder}";
            List <ITaskItem> strongNameSignInfo = new List <ITaskItem>()
            {
                new TaskItem("MsSharedLib72",
                             new Dictionary <string, string> {
                    { "PublicKeyToken", "31bf3856ad364e35" },
                    { "CertificateName", "Microsoft400" }
                })
            };
            List <ITaskItem> fileExtensionSignInfo = new List <ITaskItem>()
            {
                new TaskItem(".exe", new Dictionary <string, string> {
                    { "CertificateName", "Microsoft400" }
                }),
                new TaskItem(".dll", new Dictionary <string, string> {
                    { "CertificateName", "Microsoft400" }
                }),
                new TaskItem(".msi", new Dictionary <string, string> {
                    { "CertificateName", "Microsoft400" }
                }),
                new TaskItem(".zip", new Dictionary <string, string> {
                    { "CertificateName", "None" }
                }),
                new TaskItem(".nupkg", new Dictionary <string, string> {
                    { "CertificateName", "NuGet" }
                })
            };

            var task = new SignToolTask {
                BuildEngine        = new MsBuildEngine(/* pass release logger */),
                MicroBuildCorePath = "E:\\gh\\chcosta\\arcade\\.packages\\microbuild.core\\0.2.0",
                MSBuildPath        = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\MSBuild\\Current\\Bin\\MSBuild.exe",
                SNBinaryPath       = "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.8 Tools\\sn.exe",
                AllowEmptySignList = true,
                TestSign           = true,
                DryRun             = false,
                DoStrongNameCheck  = true,
                TempDir            = "e:\\chcosta\\sometempdir",
                WixToolsPath       = "E:\\gh\\chcosta\\arcade\\.packages\\wix\\3.11.1\\tools",
                LogDir             = "e:\\chcosta\\temp",
                ItemsToSign        = new string[] { $"{dropFolder}windowsdesktop-runtime-5.0.0-rc.2.20464.2-win-x64.exe",
                                                    $"{dropFolder}windowsdesktop-runtime-5.0.0-rc.2.20464.2-win-x64.exe.wixpack.zip",
                                                    $"{dropFolder}windowsdesktop-runtime-5.0.0-rc.2.20464.2-win-x64.msi",
                                                    $"{dropFolder}windowsdesktop-runtime-5.0.0-rc.2.20464.2-win-x64.msi.wixpack.zip",
                                                    $"{dropFolder}VS.Redist.Common.WindowsDesktop.SharedFramework.x64.5.0.5.0.0-rc.2.20464.2.nupkg" },
                StrongNameSignInfo    = strongNameSignInfo.ToArray(),
                FileExtensionSignInfo = fileExtensionSignInfo.ToArray()
            };

            task.Execute();
        }
Exemple #5
0
        private BatchSignInput Load(string json)
        {
            var task = new SignToolTask();

            using (var reader = new StringReader(json))
                using (var writer = new StringWriter())
                {
                    var data = Configuration.TryReadConfigFile(task.Log, reader, @"q:\outputPath");

                    Assert.True(string.IsNullOrEmpty(writer.ToString()));
                    return(data);
                }
        }
Exemple #6
0
        public void EmptySigningListForTask()
        {
            var task = new SignToolTask {
                BuildEngine  = new FakeBuildEngine(),
                ItemsToSign  = new string[0],
                LogDir       = "LogDir",
                TempDir      = "TempDir",
                DryRun       = false,
                TestSign     = true,
                MSBuildPath  = CreateTestResource("msbuild.fake"),
                SNBinaryPath = CreateTestResource("fake.sn.exe")
            };

            Assert.True(task.Execute());
        }
Exemple #7
0
        public void EmptySigningList()
        {
            var itemsToSign = new string[0];

            var strongNameSignInfo = new Dictionary <string, SignInfo>();

            var fileSignInfo = new Dictionary <ExplicitCertificateKey, string>();

            var task = new SignToolTask {
                BuildEngine = new FakeBuildEngine()
            };
            var signingInput = new Configuration(_tmpDir, itemsToSign, strongNameSignInfo, fileSignInfo, s_fileExtensionSignInfo, null, task.Log).GenerateListOfFiles();

            Assert.Empty(signingInput.FilesToSign);
            Assert.Empty(signingInput.ZipDataMap);
            Assert.False(task.Log.HasLoggedErrors);
        }
Exemple #8
0
        private void ValidateFileSignInfos(
            string[] itemsToSign,
            Dictionary <string, SignInfo> strongNameSignInfo,
            Dictionary <ExplicitCertificateKey, string> signingOverridingInfos,
            Dictionary <string, SignInfo> extensionsSignInfo,
            string[] expected,
            string[] expectedCopyFiles = null)
        {
            var task = new SignToolTask {
                BuildEngine = new FakeBuildEngine()
            };
            var signingInput = new Configuration(_tmpDir, itemsToSign, strongNameSignInfo, signingOverridingInfos, extensionsSignInfo, task.Log).GenerateListOfFiles();

            AssertEx.Equal(expected, signingInput.FilesToSign.Select(f => f.ToString()));
            AssertEx.Equal(expectedCopyFiles ?? Array.Empty <string>(), signingInput.FilesToCopy.Select(f => $"{f.Key} -> {f.Value}"));
            Assert.False(task.Log.HasLoggedErrors);
        }
Exemple #9
0
        private void ValidateFileSignInfos(
            string[] itemsToSign,
            Dictionary <string, SignInfo> strongNameSignInfo,
            Dictionary <ExplicitCertificateKey, string> fileSignInfo,
            Dictionary <string, SignInfo> extensionsSignInfo,
            string[] expected,
            string[] expectedCopyFiles = null,
            string[] dualCertificates  = null,
            string[] expectedErrors    = null,
            string[] expectedWarnings  = null)
        {
            var engine = new FakeBuildEngine();
            var task   = new SignToolTask {
                BuildEngine = engine
            };
            var signingInput = new Configuration(_tmpDir, itemsToSign, strongNameSignInfo, fileSignInfo, extensionsSignInfo, dualCertificates, task.Log).GenerateListOfFiles();

            AssertEx.Equal(expected, signingInput.FilesToSign.Select(f => f.ToString()));
            AssertEx.Equal(expectedCopyFiles ?? Array.Empty <string>(), signingInput.FilesToCopy.Select(f => $"{f.Key} -> {f.Value}"));

            AssertEx.Equal(expectedErrors ?? Array.Empty <string>(), engine.LogErrorEvents.Select(w => w.Message));
            AssertEx.Equal(expectedWarnings ?? Array.Empty <string>(), engine.LogWarningEvents.Select(w => $"{w.Code}: {w.Message}"));
        }