コード例 #1
0
        public void WellKnownArgumentTokensReplaced()
        {
            string logDirectory        = "mock:\\test_log_directory";
            string noTokenSourceString = "/arg no_token log_directory installation_id";

            NuGetUpgrader.ReplaceArgTokens(noTokenSourceString, "unique_id", logDirectory).ShouldEqual(noTokenSourceString, "String with no tokens should not be modifed");

            string sourceStringWithTokens  = "/arg /log {log_directory}_{installation_id}";
            string expectedProcessedString = "/arg /log " + logDirectory + "_" + "unique_id";

            NuGetUpgrader.ReplaceArgTokens(sourceStringWithTokens, "unique_id", logDirectory).ShouldEqual(expectedProcessedString, "expected tokens have not been replaced");
        }
コード例 #2
0
        public void TestUpgradeAllowed()
        {
            // Properly Configured NuGet config
            NuGetUpgrader.NuGetUpgraderConfig nuGetUpgraderConfig =
                new NuGetUpgrader.NuGetUpgraderConfig(this.tracer, null, NuGetFeedUrl, NuGetFeedName);

            NuGetUpgrader nuGetUpgrader = new NuGetUpgrader(
                CurrentVersion,
                this.tracer,
                false,
                false,
                this.mockFileSystem,
                nuGetUpgraderConfig,
                this.mockNuGetFeed.Object,
                this.mockCredentialManager.Object);

            nuGetUpgrader.UpgradeAllowed(out _).ShouldBeTrue("NuGetUpgrader config is complete: upgrade should be allowed.");

            // Empty FeedURL
            nuGetUpgraderConfig =
                new NuGetUpgrader.NuGetUpgraderConfig(this.tracer, null, string.Empty, NuGetFeedName);

            nuGetUpgrader = new NuGetUpgrader(
                CurrentVersion,
                this.tracer,
                false,
                false,
                this.mockFileSystem,
                nuGetUpgraderConfig,
                this.mockNuGetFeed.Object,
                this.mockCredentialManager.Object);

            nuGetUpgrader.UpgradeAllowed(out string _).ShouldBeFalse("Upgrade without FeedURL configured should not be allowed.");

            // Empty packageFeedName
            nuGetUpgraderConfig =
                new NuGetUpgrader.NuGetUpgraderConfig(this.tracer, null, NuGetFeedUrl, string.Empty);

            // Empty packageFeedName
            nuGetUpgrader = new NuGetUpgrader(
                CurrentVersion,
                this.tracer,
                false,
                false,
                this.mockFileSystem,
                nuGetUpgraderConfig,
                this.mockNuGetFeed.Object,
                this.mockCredentialManager.Object);

            nuGetUpgrader.UpgradeAllowed(out string _).ShouldBeFalse("Upgrade without FeedName configured should not be allowed.");
        }
コード例 #3
0
 public static bool TryCreateUpgrader(
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     bool dryRun,
     bool noVerify,
     out ProductUpgrader newUpgrader,
     out string error)
 {
     // Prefer to use the NuGet upgrader if it is configured. If the NuGet upgrader is not configured,
     // then try to use the GitHubUpgrader.
     if (NuGetUpgrader.TryCreate(tracer, fileSystem, dryRun, noVerify, out NuGetUpgrader nuGetUpgrader, out bool isConfigured, out error))
     {
         // We were successfully able to load a NuGetUpgrader - use that.
         newUpgrader = nuGetUpgrader;
         return(true);
     }
コード例 #4
0
        public void DoNotVerifyNuGetPackageWhenNoVerifyIsSpecified()
        {
            NuGetUpgrader.NuGetUpgraderConfig nuGetUpgraderConfig =
                new NuGetUpgrader.NuGetUpgraderConfig(this.tracer, null, NuGetFeedUrl, NuGetFeedName);

            NuGetUpgrader nuGetUpgrader = new NuGetUpgrader(
                CurrentVersion,
                this.tracer,
                false,
                true,
                this.mockFileSystem,
                nuGetUpgraderConfig,
                this.mockNuGetFeed.Object,
                this.mockCredentialManager.Object,
                this.productUpgraderPlatformStrategy);

            Version actualNewestVersion;
            string  message;
            List <IPackageSearchMetadata> availablePackages = new List <IPackageSearchMetadata>()
            {
                this.GeneratePackageSeachMetadata(new Version(CurrentVersion)),
                this.GeneratePackageSeachMetadata(new Version(NewerVersion)),
            };

            IPackageSearchMetadata newestAvailableVersion = availablePackages.Last();

            string testDownloadPath = Path.Combine(this.downloadDirectoryPath, "testNuget.zip");

            this.mockNuGetFeed.Setup(foo => foo.QueryFeedAsync(NuGetFeedName)).ReturnsAsync(availablePackages);
            this.mockNuGetFeed.Setup(foo => foo.DownloadPackageAsync(It.Is <PackageIdentity>(packageIdentity => packageIdentity == newestAvailableVersion.Identity))).ReturnsAsync(testDownloadPath);
            this.mockNuGetFeed.Setup(foo => foo.VerifyPackage(It.IsAny <string>())).Returns(false);

            bool success = nuGetUpgrader.TryQueryNewestVersion(out actualNewestVersion, out message);

            success.ShouldBeTrue($"Expecting TryQueryNewestVersion to have completed sucessfully. Error: {message}");
            actualNewestVersion.ShouldEqual(newestAvailableVersion.Identity.Version.Version, "Actual new version does not match expected new version.");

            bool downloadSuccessful = nuGetUpgrader.TryDownloadNewestVersion(out message);

            this.mockNuGetFeed.Verify(nuGetFeed => nuGetFeed.VerifyPackage(It.IsAny <string>()), Times.Never());
            downloadSuccessful.ShouldBeTrue("Should be able to download package with verification issues when noVerify is specified");
        }
コード例 #5
0
        public void CanConstructAzureDevOpsUrlFromPackageFeedUrl(string packageFeedUrl, string expectedAzureDevOpsUrl)
        {
            bool success = NuGetUpgrader.TryCreateAzDevOrgUrlFromPackageFeedUrl(
                packageFeedUrl,
                out string azureDevOpsUrl,
                out string error);

            if (expectedAzureDevOpsUrl != null)
            {
                success.ShouldBeTrue();
                azureDevOpsUrl.ShouldEqual(expectedAzureDevOpsUrl);
                error.ShouldBeNull();
            }
            else
            {
                success.ShouldBeFalse();
                azureDevOpsUrl.ShouldBeNull();
                error.ShouldNotBeNull();
            }
        }
コード例 #6
0
        public void SetUp()
        {
            this.upgraderConfig = new NuGetUpgrader.NuGetUpgraderConfig(this.tracer, null, NuGetFeedUrl, NuGetFeedName);

            this.tracer = new MockTracer();

            this.mockFileSystem = new MockFileSystem(
                new MockDirectory(
                    Path.GetDirectoryName(this.downloadDirectoryPath),
                    new[] { new MockDirectory(this.downloadDirectoryPath, null, null) },
                    null));

            this.mockNuGetFeed = new Mock <NuGetFeed>(
                NuGetFeedUrl,
                NuGetFeedName,
                this.downloadDirectoryPath,
                null,
                ScalarPlatform.Instance.UnderConstruction.SupportsNuGetEncryption,
                this.tracer,
                this.mockFileSystem);
            this.mockNuGetFeed.Setup(feed => feed.SetCredentials(It.IsAny <string>()));

            this.mockCredentialManager = new Mock <ICredentialStore>();
            string credentialManagerString = "value";
            string emptyString             = string.Empty;

            this.mockCredentialManager.Setup(foo => foo.TryGetCredential(It.IsAny <ITracer>(), It.IsAny <string>(), out credentialManagerString, out credentialManagerString, out credentialManagerString)).Returns(true);

            this.productUpgraderPlatformStrategy = this.CreateProductUpgraderPlatformStrategy();

            this.upgrader = new NuGetUpgrader(
                CurrentVersion,
                this.tracer,
                false,
                false,
                this.mockFileSystem,
                this.upgraderConfig,
                this.mockNuGetFeed.Object,
                this.mockCredentialManager.Object,
                this.productUpgraderPlatformStrategy);
        }
コード例 #7
0
        public static bool TryCreateUpgrader(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            LocalGSDConfig gvfsConfig,
            ICredentialStore credentialStore,
            bool dryRun,
            bool noVerify,
            out ProductUpgrader newUpgrader,
            out string error)
        {
            Dictionary <string, string> entries;

            if (!gvfsConfig.TryGetAllConfig(out entries, out error))
            {
                newUpgrader = null;
                return(false);
            }

            bool containsUpgradeFeedUrl     = entries.ContainsKey(GSDConstants.LocalGSDConfig.UpgradeFeedUrl);
            bool containsUpgradePackageName = entries.ContainsKey(GSDConstants.LocalGSDConfig.UpgradeFeedPackageName);
            bool containsOrgInfoServerUrl   = entries.ContainsKey(GSDConstants.LocalGSDConfig.OrgInfoServerUrl);

            if (containsUpgradeFeedUrl || containsUpgradePackageName)
            {
                // We are configured for NuGet - determine if we are using OrgNuGetUpgrader or not
                if (containsOrgInfoServerUrl)
                {
                    if (OrgNuGetUpgrader.TryCreate(
                            tracer,
                            fileSystem,
                            gvfsConfig,
                            new HttpClient(),
                            credentialStore,
                            dryRun,
                            noVerify,
                            out OrgNuGetUpgrader orgNuGetUpgrader,
                            out error))
                    {
                        // We were successfully able to load a NuGetUpgrader - use that.
                        newUpgrader = orgNuGetUpgrader;
                        return(true);
                    }
                    else
                    {
                        tracer.RelatedError($"{nameof(TryCreateUpgrader)}: Could not create organization based upgrader. {error}");
                        newUpgrader = null;
                        return(false);
                    }
                }
                else
                {
                    if (NuGetUpgrader.TryCreate(
                            tracer,
                            fileSystem,
                            gvfsConfig,
                            credentialStore,
                            dryRun,
                            noVerify,
                            out NuGetUpgrader nuGetUpgrader,
                            out bool isConfigured,
                            out error))
                    {
                        // We were successfully able to load a NuGetUpgrader - use that.
                        newUpgrader = nuGetUpgrader;
                        return(true);
                    }