public void TestWhitelist()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults             results;
            string                    assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string                    manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string                    defaultConfigFile = Path.Combine(assetsDirectory, "default.config");
            ImmutableHashSet <string> ignoredPackages   = ImmutableHashSet <string> .Empty;

            IEnumerable <Regex> whitelistedPackages = new Regex[]
            {
                new Regex(@"VS\.Redist\.Common\.NetCore\.AppHostPack\.x86_x64\.3\.1"),
                new Regex(@"^VS\.Redist\.Common\.NetCore\.SharedFramework\.(x86|x64)\.[0-9]+\.[0-9]+$")
            };

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null,
                null);

            Assert.IsFalse(results.UpdatedPackages.Any(n => whitelistedPackages.All(pattern => !pattern.IsMatch(n.PackageId))),
                           "A package was updated even though it wasn't in the whitelist.");
        }
        public void TestIgnorelist()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults       results;
            string              assetsDirectory     = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string              manifestFile        = Path.Combine(assetsDirectory, "manifest.json");
            string              defaultConfigFile   = Path.Combine(assetsDirectory, "default.config");
            IEnumerable <Regex> whitelistedPackages = Enumerable.Empty <Regex>();

            ImmutableHashSet <string> ignoredPackages = ImmutableHashSet.Create(new string[] {
                @"^VS\.Redist\.Common\.NetCore\.AppHostPack\.x86_x64\.3\.1",
                @"^VS\.Redist\.Common\.NetCore\.SharedFramework\.(x86|x64)\.[0-9]+\.[0-9]+$"
            });

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null,
                null);

            // Ignore all modified files except for one
            Assert.IsFalse(results.UpdatedPackages.Any(n => ignoredPackages.Contains(n.PackageId)), "A package that should have been ignored was updated.");
            Assert.IsFalse(results.IgnoredNuGets.Any(n => !ignoredPackages.Contains(n)), "A package was ignored, but it shouldn't have been");
        }
Ejemplo n.º 3
0
        public void TestLoadedIgnoredPackages()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults       results;
            string              assetsDirectory     = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string              manifestFile        = Path.Combine(assetsDirectory, "manifest.json");
            string              defaultConfigFile   = Path.Combine(assetsDirectory, "default.config");
            IEnumerable <Regex> whitelistedPackages = Enumerable.Empty <Regex>();

            ImmutableHashSet <string> ignoredPackages = InputLoading.LoadPackagesToIgnore(Path.Combine(assetsDirectory, "ignored.txt"));

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null,
                null);

            Assert.IsTrue(ignoredPackages.SetEquals(results.IgnoredNuGets), $"Mismatched ignore packages");
            Assert.IsFalse(results.UpdatedPackages.Any(n => ignoredPackages.Contains(n.PackageId)), "Packages that shouldn't have been updated were updated.");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Convenience method to call <see cref="IInsertionApi.UpdateVersions(IEnumerable{string}, string, IEnumerable{Regex}, ImmutableHashSet{string}?, string?, string?)"/>
 /// with a single manifest file instead of a set of manifest files.
 /// See the documentation of the related method for the detailed usage.
 /// </summary>
 public static UpdateResults UpdateVersions(this IInsertionApi api,
                                            string manifestFile,
                                            string defaultConfigFile,
                                            IEnumerable <Regex> whitelistedPackages,
                                            ImmutableHashSet <string>?packagesToIgnore,
                                            string?accessToken,
                                            string?propsFilesRootDirectory)
 {
     return(api.UpdateVersions(
                new[] { manifestFile },
                defaultConfigFile,
                whitelistedPackages,
                packagesToIgnore,
                accessToken,
                propsFilesRootDirectory));
 }
        public void TestLoadFile(IgnoreCase ignoreCase)
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults results;
            string        assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string        manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string        defaultConfigFile = Path.Combine(assetsDirectory, "default.config");

            results = ignoreCase switch
            {
                IgnoreCase.DefaultDevUxTeamPackages => api.UpdateVersions(manifestFile, defaultConfigFile, InsertionConstants.DefaultDevUxTeamPackages, null, null),
                IgnoreCase.SpecifiedFile => api.UpdateVersions(manifestFile, defaultConfigFile, Path.Combine(assetsDirectory, "ignored.txt"), null, null),
                _ => api.UpdateVersions(manifestFile, defaultConfigFile, (HashSet <string>?)null, null, null),
            };

            Assert.IsTrue(ListsAreEquivalent(ignoreCase, results?.IgnoredNuGets), $"Mismatched ignore packages for {ignoreCase}");
        }
        public void TestEmptyWhitelist()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults             results;
            string                    assetsDirectory     = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string                    manifestFile        = Path.Combine(assetsDirectory, "manifest.json");
            string                    defaultConfigFile   = Path.Combine(assetsDirectory, "default.config");
            IEnumerable <Regex>       whitelistedPackages = Enumerable.Empty <Regex>();
            ImmutableHashSet <string> ignoredPackages     = ImmutableHashSet <string> .Empty;

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null);

            Assert.IsTrue(results.UpdatedNuGets.Any(), "Empty whitelist shouldn't prevent package updates, but no packages were updated.");
        }
Ejemplo n.º 7
0
        public void TestLoadedWhitelist()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults             results;
            string                    assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string                    manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string                    defaultConfigFile = Path.Combine(assetsDirectory, "default.config");
            ImmutableHashSet <string> ignoredPackages   = ImmutableHashSet <string> .Empty;

            IEnumerable <Regex> whitelistedPackages = InputLoading.LoadWhitelistedPackages(Path.Combine(assetsDirectory, "whitelist.txt"));

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null);

            Assert.IsFalse(results.UpdatedNuGets.Any(n => whitelistedPackages.All(pattern => !pattern.IsMatch(n.PackageId))), "Packages that shouldn't have been updated were updated.");
        }
Ejemplo n.º 8
0
        public void TestBuildRejections()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults             results;
            string                    assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string                    manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string                    defaultConfigFile = Path.Combine(assetsDirectory, "default.config");
            ImmutableHashSet <string> ignoredPackages   = ImmutableHashSet <string> .Empty;
            IEnumerable <Regex>       allowedPackages   = new List <Regex>();

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                allowedPackages,
                null,
                null,
                null,
                build => false);

            Assert.IsTrue(results.Outcome, "Insertion should have succeeded, but failed with error: " + results.OutcomeDetails);
            Assert.IsTrue(results.UpdatedNuGets == null || !results.UpdatedNuGets.Any(), "No packages should have been updated.");

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                allowedPackages,
                null,
                null,
                null,
                null);

            Assert.IsTrue(results.Outcome, "Insertion should have succeeded, but failed with error: " + results.OutcomeDetails);
            Assert.IsTrue(results.UpdatedNuGets != null && results.UpdatedNuGets.Any(), "Inconclusive test. This manifest didn't update any packages." +
                          " It is not possible to know if build filter worked or not.");
        }
Ejemplo n.º 9
0
        public void TestVersionNumberComparison()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults       results;
            string              assetsDirectory     = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string              manifestFile        = Path.Combine(assetsDirectory, "manifest.json");
            string              defaultConfigFile   = Path.Combine(assetsDirectory, "default.config");
            IEnumerable <Regex> whitelistedPackages = new Regex[]
            {
                new Regex(@"^VS\.Redist\.Common\.NetCore\.SharedFramework\.(x86|x64)\.[0-9]+\.[0-9]+$")
            };
            ImmutableHashSet <string> ignoredPackages = ImmutableHashSet <string> .Empty;

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null,
                null);

            Assert.IsTrue(results.UpdatedPackages.Any(), "Some packages should have been updated.");

            PackageUpdateResult packx64 = results.UpdatedPackages.FirstOrDefault(p => p.PackageId == "VS.Redist.Common.NetCore.SharedFramework.x64.3.1");

            Assert.IsNotNull(packx64);
            Assert.AreEqual(packx64.NewVersion, "4.1.2-servicing.20067.4");

            PackageUpdateResult packx86 = results.UpdatedPackages.FirstOrDefault(p => p.PackageId == "VS.Redist.Common.NetCore.SharedFramework.x86.3.1");

            Assert.IsNotNull(packx86);
            Assert.AreEqual("3.1.3-servicing.20067.4", packx86.NewVersion);
        }