public async Task TestBuildNugetSources_Source_Uri_Is_Null(NuGetProtocolVersion protocolVersion) { await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem); var snapNugetFeed = new SnapNugetFeed { Name = "nuget.org", ProtocolVersion = protocolVersion, Source = null }; var snapChannel = new SnapChannel { Name = "test", PushFeed = snapNugetFeed, UpdateFeed = snapNugetFeed }; var snapApp = new SnapApp { Channels = new List <SnapChannel> { snapChannel } }; var nugetPackageSources = snapApp.BuildNugetSources(nugetTempDirectory); Assert.Empty(nugetPackageSources); }
public void TestBuildNugetSources_SnapApp() { var nugetOrgFeed = new SnapNugetFeed { Name = "nuget.org", Source = new Uri(NuGetConstants.V3FeedUrl) }; var snapApp = new SnapApp { Channels = new List <SnapChannel> { new SnapChannel { UpdateFeed = nugetOrgFeed, PushFeed = nugetOrgFeed, Name = "test" }, new SnapChannel { UpdateFeed = nugetOrgFeed, PushFeed = nugetOrgFeed, Name = "staging" } } }; var nugetPackageSources = snapApp.BuildNugetSources(_baseFixture.NugetTempDirectory); Assert.Single(nugetPackageSources.Items); var packageSource = nugetPackageSources.Items.First(); Assert.Equal(packageSource.Name, nugetOrgFeed.Name); }
public async Task TestBuildSnapApp_Ignore_Non_Existant_Feeds() { await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem); var testChannel = new SnapChannel { Name = "test", PushFeed = new SnapNugetFeed { Name = Guid.NewGuid().ToString("N") }, UpdateFeed = new SnapNugetFeed { Name = Guid.NewGuid().ToString("N") }, Current = true }; var snapAppBefore = new SnapApp { Id = "demoapp", SuperVisorId = Guid.NewGuid().ToString(), Version = new SemanticVersion(1, 0, 0), Channels = new List <SnapChannel> { testChannel }, Target = new SnapTarget { Os = OSPlatform.Windows, Framework = "netcoreapp2.1", Rid = "win-x64", PersistentAssets = new List <string> { "subdirectory", "myjsonfile.json" } } }; var snapApps = new SnapApps(snapAppBefore); var snapAppAfter = snapApps.BuildSnapApp(snapAppBefore.Id, snapAppBefore.Target.Rid, snapAppBefore.BuildNugetSources(nugetTempDirectory), _fileSystem, false, false); Assert.NotNull(snapAppAfter); Assert.Single(snapAppAfter.Channels.Select(x => x.UpdateFeed is {}));
static async Task PushPackagesAsync([NotNull] PackOptions packOptions, [NotNull] ILog logger, [NotNull] ISnapFilesystem filesystem, [NotNull] INugetService nugetService, [NotNull] ISnapPackageManager snapPackageManager, [NotNull] IDistributedMutex distributedMutex, [NotNull] SnapAppsReleases snapAppsReleases, [NotNull] SnapApp snapApp, [NotNull] SnapChannel snapChannel, [NotNull] List <string> packages, CancellationToken cancellationToken) { if (packOptions == null) { throw new ArgumentNullException(nameof(packOptions)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (filesystem == null) { throw new ArgumentNullException(nameof(filesystem)); } if (nugetService == null) { throw new ArgumentNullException(nameof(nugetService)); } if (snapPackageManager == null) { throw new ArgumentNullException(nameof(snapPackageManager)); } if (distributedMutex == null) { throw new ArgumentNullException(nameof(distributedMutex)); } if (snapAppsReleases == null) { throw new ArgumentNullException(nameof(snapAppsReleases)); } if (snapApp == null) { throw new ArgumentNullException(nameof(snapApp)); } if (snapChannel == null) { throw new ArgumentNullException(nameof(snapChannel)); } if (packages == null) { throw new ArgumentNullException(nameof(packages)); } if (packages.Count == 0) { throw new ArgumentException("Value cannot be an empty collection.", nameof(packages)); } logger.Info('-'.Repeat(TerminalBufferWidth)); var pushDegreeOfParallelism = Math.Min(Environment.ProcessorCount, packages.Count); var nugetSources = snapApp.BuildNugetSources(filesystem.PathGetTempPath()); var pushFeedPackageSource = nugetSources.Items.Single(x => x.Name == snapChannel.PushFeed.Name); if (pushFeedPackageSource.IsLocalOrUncPath()) { filesystem.DirectoryCreateIfNotExists(pushFeedPackageSource.SourceUri.AbsolutePath); } if (snapChannel.UpdateFeed.HasCredentials()) { if (!logger.Prompt("y|yes", "Update feed contains credentials. Do you want to continue? [y|n]", infoOnly: packOptions.YesToAllPrompts)) { logger.Error("Publish aborted."); return; } } logger.Info("Ready to publish application!"); logger.Info($"Id: {snapApp.Id}"); logger.Info($"Rid: {snapApp.Target.Rid}"); logger.Info($"Channel: {snapChannel.Name}"); logger.Info($"Version: {snapApp.Version}"); logger.Info($"Feed name: {snapChannel.PushFeed.Name}"); if (!logger.Prompt("y|yes", "Are you ready to push release upstream? [y|n]", infoOnly: packOptions.YesToAllPrompts)) { logger.Error("Publish aborted."); return; } var stopwatch = new Stopwatch(); stopwatch.Restart(); logger.Info($"Pushing packages to default channel: {snapChannel.Name}. Feed: {snapChannel.PushFeed.Name}."); await packages.ForEachAsync(async packageAbsolutePath => await PushPackageAsync(nugetService, filesystem, distributedMutex, nugetSources, pushFeedPackageSource, snapChannel, packageAbsolutePath, logger, cancellationToken), pushDegreeOfParallelism); logger.Info($"Successfully pushed {packages.Count} packages in {stopwatch.Elapsed.TotalSeconds:F1}s."); var skipInitialBlock = pushFeedPackageSource.IsLocalOrUncPath(); await BlockUntilSnapUpdatedReleasesNupkgAsync(logger, snapPackageManager, snapAppsReleases, snapApp, snapChannel, TimeSpan.FromSeconds(15), cancellationToken, skipInitialBlock, packOptions.SkipAwaitUpdate); }
static async Task <int> CommandDemoteAsync([NotNull] DemoteOptions options, [NotNull] ISnapFilesystem filesystem, [NotNull] ISnapAppReader snapAppReader, [NotNull] ISnapAppWriter snapAppWriter, [NotNull] INuGetPackageSources nuGetPackageSources, [NotNull] INugetService nugetService, [NotNull] IDistributedMutexClient distributedMutexClient, [NotNull] ISnapPackageManager snapPackageManager, [NotNull] ISnapPack snapPack, [NotNull] ISnapNetworkTimeProvider snapNetworkTimeProvider, [NotNull] ISnapExtractor snapExtractor, [NotNull] ISnapOs snapOs, [NotNull] ISnapxEmbeddedResources snapxEmbeddedResources, [NotNull] ICoreRunLib coreRunLib, [NotNull] ILog logger, [NotNull] string workingDirectory, CancellationToken cancellationToken) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (filesystem == null) { throw new ArgumentNullException(nameof(filesystem)); } if (snapAppReader == null) { throw new ArgumentNullException(nameof(snapAppReader)); } if (snapAppWriter == null) { throw new ArgumentNullException(nameof(snapAppWriter)); } if (nuGetPackageSources == null) { throw new ArgumentNullException(nameof(nuGetPackageSources)); } if (nugetService == null) { throw new ArgumentNullException(nameof(nugetService)); } if (distributedMutexClient == null) { throw new ArgumentNullException(nameof(distributedMutexClient)); } if (snapPackageManager == null) { throw new ArgumentNullException(nameof(snapPackageManager)); } if (snapPack == null) { throw new ArgumentNullException(nameof(snapPack)); } if (snapNetworkTimeProvider == null) { throw new ArgumentNullException(nameof(snapNetworkTimeProvider)); } if (snapExtractor == null) { throw new ArgumentNullException(nameof(snapExtractor)); } if (snapOs == null) { throw new ArgumentNullException(nameof(snapOs)); } if (snapxEmbeddedResources == null) { throw new ArgumentNullException(nameof(snapxEmbeddedResources)); } if (coreRunLib == null) { throw new ArgumentNullException(nameof(coreRunLib)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (workingDirectory == null) { throw new ArgumentNullException(nameof(workingDirectory)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (nugetService == null) { throw new ArgumentNullException(nameof(nugetService)); } var stopwatch = new Stopwatch(); stopwatch.Restart(); var anyRid = options.Rid == null; var anyVersion = options.FromVersion == null; SnapApp anyRidSnapApp = null; SemanticVersion fromVersion = null; var runtimeIdentifiers = new List <string>(); if (!anyVersion) { if (!SemanticVersion.TryParse(options.FromVersion, out fromVersion)) { Console.WriteLine($"Unable to parse from version: {options.FromVersion}"); return(1); } if (!options.RemoveAll) { Console.WriteLine("You must specify --remove-all if you want to demote releases newer than --from-version."); return(1); } } var snapApps = BuildSnapAppsFromDirectory(filesystem, snapAppReader, workingDirectory); if (!snapApps.Apps.Any()) { return(1); } foreach (var snapsApp in snapApps.Apps) { foreach (var target in snapsApp.Targets.Where(target => anyRid || string.Equals(options.Rid, target.Rid, StringComparison.OrdinalIgnoreCase))) { anyRidSnapApp = snapApps.BuildSnapApp(snapsApp.Id, target.Rid, nuGetPackageSources, filesystem); runtimeIdentifiers.AddRange(snapApps.GetRids(anyRidSnapApp)); break; } } if (anyRidSnapApp == null) { if (anyRid) { logger.Error($"Unable to find application with id: {options.Id}."); return(1); } logger.Error($"Unable to find application with id: {options.Id}. Rid: {options.Rid}"); return(1); } logger.Info('-'.Repeat(TerminalBufferWidth)); Console.WriteLine($"Demoting application with id: {anyRidSnapApp.Id}."); Console.WriteLine($"Runtime identifiers (RID): {string.Join(", ", runtimeIdentifiers)}"); if (anyRid) { if (!logger.Prompt("y|yes", "You have not specified a rid, all releases in listed runtime identifiers will be removed. " + "Do you want to continue? [y|n]") ) { return(1); } } MaybeOverrideLockToken(snapApps, logger, options.Id, options.LockToken); if (string.IsNullOrWhiteSpace(snapApps.Generic.Token)) { logger.Error("Please specify a token in your snapx.yml file. A random UUID is sufficient."); return(1); } logger.Info('-'.Repeat(TerminalBufferWidth)); var packagesDirectory = BuildPackagesDirectory(filesystem, workingDirectory); filesystem.DirectoryCreateIfNotExists(packagesDirectory); await using var distributedMutex = WithDistributedMutex(distributedMutexClient, logger, snapApps.BuildLockKey(anyRidSnapApp), cancellationToken); var tryAcquireRetries = options.LockRetries == -1 ? int.MaxValue : options.LockRetries; if (!await distributedMutex.TryAquireAsync(TimeSpan.FromSeconds(15), tryAcquireRetries)) { logger.Info('-'.Repeat(TerminalBufferWidth)); return(1); } logger.Info('-'.Repeat(TerminalBufferWidth)); logger.Info("Downloading releases nupkg."); var(snapAppsReleases, _, currentReleasesMemoryStream) = await snapPackageManager .GetSnapsReleasesAsync(anyRidSnapApp, logger, cancellationToken); if (currentReleasesMemoryStream != null) { await currentReleasesMemoryStream.DisposeAsync(); } if (snapAppsReleases == null) { return(1); } if (!snapAppsReleases.Any()) { logger.Error($"Releases nupkg does not contain application id: {anyRidSnapApp.Id}"); return(1); } logger.Info($"Downloaded releases nupkg. Current version: {snapAppsReleases.Version}."); var snapAppReleases = options.RemoveAll ? snapAppsReleases.GetReleases(anyRidSnapApp, x => { bool VersionFilter() { return(anyVersion || x.Version > fromVersion); } bool RidFilter() { return(anyRid || x.Target.Rid == anyRidSnapApp.Target.Rid); } return(RidFilter() && VersionFilter()); }) : snapAppsReleases.GetMostRecentReleases(anyRidSnapApp, x => anyRid || x.Target.Rid == anyRidSnapApp.Target.Rid); if (!snapAppReleases.Any()) { logger.Error("Unable to find any releases that matches demotion criterias."); return(1); } logger.Info('-'.Repeat(TerminalBufferWidth)); var consoleTable = new ConsoleTable("Rid", "Channels", "Version", "Count") { Header = $"Demote summary overview. Total releases: {snapAppReleases.Count()}." }; foreach (var(rid, releases) in snapAppReleases.ToDictionaryByKey(x => x.Target.Rid)) { var channels = releases.SelectMany(x => x.Channels).Distinct().ToList(); var releaseVersion = options.RemoveAll ? "All versions" : releases.First().Version.ToString(); consoleTable.AddRow(new object[] { rid, string.Join(", ", channels), releaseVersion, releases.Count.ToString() }); } consoleTable.Write(logger); if (!logger.Prompt("y|yes", "Ready to demote releases. Do you want to continue? [y|n]")) { return(1); } logger.Info('-'.Repeat(TerminalBufferWidth)); logger.Info($"Retrieving network time from: {snapNetworkTimeProvider}."); var nowUtc = await SnapUtility.RetryAsync(async() => await snapNetworkTimeProvider.NowUtcAsync(), 3); if (!nowUtc.HasValue) { logger.Error($"Unknown error retrieving network time from: {snapNetworkTimeProvider}"); return(1); } var localTimeStr = TimeZoneInfo .ConvertTimeFromUtc(nowUtc.Value, TimeZoneInfo.Local) .ToString("F", CultureInfo.CurrentCulture); logger.Info($"Successfully retrieved network time. Time is now: {localTimeStr}"); logger.Info('-'.Repeat(TerminalBufferWidth)); var snapAppsReleasesDemotedCount = snapAppsReleases.Demote(snapAppReleases); if (snapAppsReleasesDemotedCount != snapAppReleases.Count()) { logger.Error("Unknown error when removing demoted releases. " + $"Expected to remove {snapAppReleases.Count()} but only {snapAppsReleasesDemotedCount} was removed."); return(1); } logger.Info("Building releases nupkg. " + $"Current database version: {snapAppsReleases.Version}. " + $"Releases count: {snapAppsReleases.Count()}."); var releasesMemoryStream = !snapAppsReleases.Any() ? snapPack.BuildEmptyReleasesPackage(anyRidSnapApp, snapAppsReleases) : snapPack.BuildReleasesPackage(anyRidSnapApp, snapAppsReleases); var releasesNupkgAbsolutePath = snapOs.Filesystem.PathCombine(packagesDirectory, anyRidSnapApp.BuildNugetReleasesFilename()); var releasesNupkgFilename = filesystem.PathGetFileName(releasesNupkgAbsolutePath); await snapOs.Filesystem.FileWriteAsync(releasesMemoryStream, releasesNupkgAbsolutePath, cancellationToken); logger.Info("Finished building releases nupkg.\n" + $"Filename: {releasesNupkgFilename}.\n" + $"Size: {releasesMemoryStream.Length.BytesAsHumanReadable()}.\n" + $"New database version: {snapAppsReleases.Version}.\n" + $"Pack id: {snapAppsReleases.PackId:N}."); logger.Info('-'.Repeat(TerminalBufferWidth)); var anySnapTargetDefaultChannel = anyRidSnapApp.Channels.First(); var nugetSources = anyRidSnapApp.BuildNugetSources(filesystem.PathGetTempPath()); var packageSource = nugetSources.Items.Single(x => x.Name == anySnapTargetDefaultChannel.PushFeed.Name); await PushPackageAsync(nugetService, filesystem, distributedMutex, nuGetPackageSources, packageSource, anySnapTargetDefaultChannel, releasesNupkgAbsolutePath, cancellationToken, logger); await BlockUntilSnapUpdatedReleasesNupkgAsync(logger, snapPackageManager, snapAppsReleases, anyRidSnapApp, anySnapTargetDefaultChannel, TimeSpan.FromSeconds(15), cancellationToken); logger.Info('-'.Repeat(TerminalBufferWidth)); await CommandRestoreAsync(new RestoreOptions { Id = anyRidSnapApp.Id, Rid = anyRid ? null : anyRidSnapApp.Target.Rid, BuildInstallers = true }, filesystem, snapAppReader, snapAppWriter, nuGetPackageSources, snapPackageManager, snapOs, snapxEmbeddedResources, coreRunLib, snapPack, logger, workingDirectory, cancellationToken); logger.Info('-'.Repeat(TerminalBufferWidth)); logger.Info($"Fetching releases overview from feed: {anySnapTargetDefaultChannel.PushFeed.Name}"); await CommandListAsync(new ListOptions { Id = anyRidSnapApp.Id }, filesystem, snapAppReader, nuGetPackageSources, nugetService, snapExtractor, logger, workingDirectory, cancellationToken); logger.Info('-'.Repeat(TerminalBufferWidth)); logger.Info($"Demote completed in {stopwatch.Elapsed.TotalSeconds:F1}s."); return(0); }
public async Task TestBuildSnapApp_Throws_If_Multiple_Nuget_Push_Feed_Names() { await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem); var nugetOrgFeed = new SnapNugetFeed { Name = "nuget.org", Source = new Uri(NuGetConstants.V3FeedUrl), ProtocolVersion = NuGetProtocolVersion.V3, Username = "******", Password = "******", ApiKey = "myapikey" }; var nugetOrgFeed2 = new SnapNugetFeed { Name = "nuget2.org", Source = new Uri(NuGetConstants.V3FeedUrl), ProtocolVersion = NuGetProtocolVersion.V3, Username = "******", Password = "******", ApiKey = "myapikey" }; var testChannel = new SnapChannel { Name = "test", PushFeed = nugetOrgFeed, UpdateFeed = nugetOrgFeed, Current = true }; var stagingChannel = new SnapChannel { Name = "staging", PushFeed = nugetOrgFeed2, UpdateFeed = nugetOrgFeed2 }; var productionChannel = new SnapChannel { Name = "production", PushFeed = nugetOrgFeed, UpdateFeed = nugetOrgFeed }; var snapAppBefore = new SnapApp { Id = "demoapp", SuperVisorId = Guid.NewGuid().ToString(), Version = new SemanticVersion(1, 0, 0), Channels = new List <SnapChannel> { testChannel, stagingChannel, productionChannel }, Target = new SnapTarget { Os = OSPlatform.Windows, Framework = "netcoreapp2.1", Rid = "win-x64", Shortcuts = new List <SnapShortcutLocation> { SnapShortcutLocation.Desktop, SnapShortcutLocation.Startup }, PersistentAssets = new List <string> { "subdirectory", "myjsonfile.json" } } }; var snapApps = new SnapApps(snapAppBefore); var ex = Assert.Throws <Exception>(() => snapApps.BuildSnapApp(snapAppBefore.Id, snapAppBefore.Target.Rid, snapAppBefore.BuildNugetSources(nugetTempDirectory), _fileSystem)); Assert.Equal($"Multiple nuget push feeds is not supported: nuget.org,nuget2.org. Application id: {snapAppBefore.Id}", ex.Message); }
public async Task TestBuildSnapApp() { await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem); var nugetOrgFeed = new SnapNugetFeed { Name = "nuget.org", Source = new Uri(NuGetConstants.V3FeedUrl), ProtocolVersion = NuGetProtocolVersion.V3, Username = "******", Password = "******", ApiKey = "myapikey" }; var updateFeedHttp = new SnapHttpFeed { Source = new Uri("https://mydynamicupdatefeed.com") }; var testChannel = new SnapChannel { Name = "test", PushFeed = nugetOrgFeed, UpdateFeed = nugetOrgFeed, Current = true }; var stagingChannel = new SnapChannel { Name = "staging", PushFeed = nugetOrgFeed, UpdateFeed = updateFeedHttp }; var productionChannel = new SnapChannel { Name = "production", PushFeed = nugetOrgFeed, UpdateFeed = nugetOrgFeed }; var snapAppBefore = new SnapApp { Id = "demoapp", MainExe = "demoapp", InstallDirectoryName = "demoapp", SuperVisorId = Guid.NewGuid().ToString(), Version = new SemanticVersion(1, 0, 0), Channels = new List <SnapChannel> { testChannel, stagingChannel, productionChannel }, Target = new SnapTarget { Os = OSPlatform.Windows, Framework = "netcoreapp2.1", Rid = "win-x64", Shortcuts = new List <SnapShortcutLocation> { SnapShortcutLocation.Desktop, SnapShortcutLocation.Startup }, PersistentAssets = new List <string> { "subdirectory", "myjsonfile.json" } } }; var snapApps = new SnapApps(snapAppBefore); var snapAppAfter = snapApps.BuildSnapApp(snapAppBefore.Id, snapAppBefore.Target.Rid, snapAppBefore.BuildNugetSources(nugetTempDirectory), _fileSystem); snapAppAfter.Version = snapAppBefore.Version.BumpMajor(); // Generic Assert.Equal(snapAppBefore.Id, snapAppAfter.Id); Assert.Equal(snapAppBefore.InstallDirectoryName, snapAppAfter.InstallDirectoryName); Assert.Equal(snapAppBefore.MainExe, snapAppAfter.MainExe); Assert.NotNull(snapAppAfter.MainExe); Assert.Equal(snapAppBefore.SuperVisorId, snapAppAfter.SuperVisorId); Assert.True(snapAppBefore.Version < snapAppAfter.Version); // Target Assert.NotNull(snapAppBefore.Target); Assert.NotNull(snapAppAfter.Target); Assert.Equal(snapAppBefore.Target.Os, snapAppAfter.Target.Os); Assert.Equal(snapAppBefore.Target.Rid, snapAppAfter.Target.Rid); Assert.NotNull(snapAppBefore.Target.Framework); Assert.NotNull(snapAppAfter.Target.Framework); Assert.Equal(snapAppBefore.Target.Framework, snapAppAfter.Target.Framework); Assert.Equal(snapAppBefore.Target.Rid, snapAppAfter.Target.Rid); Assert.Equal(snapAppBefore.Target.Shortcuts, snapAppAfter.Target.Shortcuts); Assert.Equal(snapAppBefore.Target.PersistentAssets, snapAppAfter.Target.PersistentAssets); // Channels Assert.Equal(snapAppBefore.Channels.Count, snapAppAfter.Channels.Count); for (var index = 0; index < snapAppAfter.Channels.Count; index++) { var lhsChannel = snapAppBefore.Channels[index]; var rhsChannel = snapAppAfter.Channels[index]; Assert.Equal(lhsChannel.Name, rhsChannel.Name); Assert.NotNull(lhsChannel.PushFeed); Assert.NotNull(rhsChannel.PushFeed); Assert.NotNull(lhsChannel.UpdateFeed); Assert.NotNull(rhsChannel.UpdateFeed); if (index == 0) { Assert.True(lhsChannel.Current); Assert.True(rhsChannel.Current); } else { Assert.False(lhsChannel.Current); Assert.False(rhsChannel.Current); } var lhsNugetPushFeed = lhsChannel.PushFeed; var rhsNugetPushFeed = rhsChannel.PushFeed; Assert.Equal(lhsNugetPushFeed.Name, rhsNugetPushFeed.Name); Assert.Equal(lhsNugetPushFeed.Source, rhsNugetPushFeed.Source); Assert.Equal(lhsNugetPushFeed.ProtocolVersion, rhsNugetPushFeed.ProtocolVersion); Assert.Equal(lhsNugetPushFeed.ApiKey, rhsNugetPushFeed.ApiKey); Assert.Equal(lhsNugetPushFeed.Username, rhsNugetPushFeed.Username); // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (lhsNugetPushFeed.IsPasswordEncryptionSupported()) { Assert.Equal(EncryptionUtility.DecryptString(lhsNugetPushFeed.Password), rhsNugetPushFeed.Password); } else { Assert.Equal(lhsNugetPushFeed.Password, rhsNugetPushFeed.Password); } var lhsUpdateFeed = lhsChannel.UpdateFeed; var rhsUpdateFeed = rhsChannel.UpdateFeed; switch (rhsUpdateFeed) { case SnapNugetFeed rhsNugetUpdateFeed: var lhsNugetUpdateFeed = (SnapNugetFeed)lhsUpdateFeed; Assert.Equal(lhsNugetUpdateFeed.Name, rhsNugetUpdateFeed.Name); Assert.Equal(lhsNugetUpdateFeed.Source, rhsNugetUpdateFeed.Source); Assert.Equal(lhsNugetUpdateFeed.ProtocolVersion, rhsNugetUpdateFeed.ProtocolVersion); Assert.Equal(lhsNugetUpdateFeed.ApiKey, rhsNugetUpdateFeed.ApiKey); Assert.Equal(lhsNugetUpdateFeed.Username, rhsNugetUpdateFeed.Username); Assert.Equal( lhsNugetUpdateFeed.IsPasswordEncryptionSupported() ? EncryptionUtility.DecryptString(lhsNugetUpdateFeed.Password) : lhsNugetUpdateFeed.Password, rhsNugetUpdateFeed.Password); break; case SnapHttpFeed rhsHttpUpdateFeed: var lhsHttpUpdateFeed = (SnapHttpFeed)lhsUpdateFeed; Assert.NotNull(lhsHttpUpdateFeed.Source); Assert.NotNull(rhsHttpUpdateFeed.Source); Assert.Equal(lhsHttpUpdateFeed.Source, rhsHttpUpdateFeed.Source); break; default: throw new NotSupportedException(rhsUpdateFeed.GetType().ToString()); } } }
public async Task TestBuildSnapFeedsFromNugetPackageSources(NuGetProtocolVersion protocolVersion) { await using var nugetTempDirectory = new DisposableDirectory(_baseFixture.WorkingDirectory, _fileSystem); var feedUrl = protocolVersion switch { NuGetProtocolVersion.V2 => NuGetConstants.V2FeedUrl, NuGetProtocolVersion.V3 => NuGetConstants.V3FeedUrl, _ => throw new NotSupportedException(protocolVersion.ToString()) }; var snapNugetFeed = new SnapNugetFeed { Name = "nuget.org", ProtocolVersion = protocolVersion, Source = new Uri(feedUrl), Username = "******", Password = "******", ApiKey = "myapikey" }; var snapChannel = new SnapChannel { Name = "test", PushFeed = snapNugetFeed, UpdateFeed = snapNugetFeed }; var snapApp = new SnapApp { Channels = new List <SnapChannel> { snapChannel } }; var nugetPackageSources = snapApp.BuildNugetSources(nugetTempDirectory); Assert.NotNull(nugetPackageSources.Settings); Assert.Single(nugetPackageSources.Items); var snapFeeds = snapApp.BuildNugetSources(nugetTempDirectory); Assert.NotNull(snapFeeds.Settings); Assert.Single(snapFeeds.Items); var snapNugetFeedAfter = snapFeeds.Items.Single(); Assert.Equal(snapNugetFeed.Name, snapNugetFeedAfter.Name); Assert.Equal((int)snapNugetFeed.ProtocolVersion, snapNugetFeedAfter.ProtocolVersion); Assert.Equal(snapNugetFeed.Source, snapNugetFeedAfter.SourceUri); Assert.Equal(snapNugetFeed.Username, snapNugetFeedAfter.Credentials.Username); var credential = snapNugetFeedAfter.Credentials; if (nugetPackageSources.IsPasswordEncryptionSupported()) { Assert.False(credential.IsPasswordClearText); Assert.Equal(EncryptionUtility.DecryptString(snapNugetFeed.Password), credential.Password); Assert.Equal(snapNugetFeed.Password, credential.PasswordText); } else { Assert.True(credential.IsPasswordClearText); Assert.Equal(snapNugetFeed.Password, credential.Password); } Assert.Equal(snapNugetFeed.ApiKey, snapNugetFeedAfter.GetDecryptedValue(nugetPackageSources, ConfigurationConstants.ApiKeys)); }
public void TestBuildNugetSourcesFromSnapApp(NuGetProtocolVersion protocolVersion) { string feedUrl; switch (protocolVersion) { case NuGetProtocolVersion.V2: feedUrl = NuGetConstants.V2FeedUrl; break; case NuGetProtocolVersion.V3: feedUrl = NuGetConstants.V3FeedUrl; break; default: throw new NotSupportedException(protocolVersion.ToString()); } var snapNugetFeed = new SnapNugetFeed { Name = "nuget.org", ProtocolVersion = protocolVersion, Source = new Uri(feedUrl), Username = "******", Password = "******", ApiKey = "myapikey" }; var snapChannel = new SnapChannel { Name = "test", PushFeed = snapNugetFeed, UpdateFeed = snapNugetFeed }; var snapApp = new SnapApp { Channels = new List <SnapChannel> { snapChannel } }; var nuGetPackageSources = snapApp.BuildNugetSources(_baseFixture.NugetTempDirectory); Assert.Single(nuGetPackageSources.Items); var packageSource = nuGetPackageSources.Items.Single(); Assert.True(packageSource.IsEnabled); Assert.True(packageSource.IsOfficial); Assert.False(packageSource.IsPersistable); Assert.False(packageSource.IsMachineWide); Assert.Equal(snapNugetFeed.Name, packageSource.Name); Assert.Equal(snapNugetFeed.Source.ToString(), packageSource.TrySourceAsUri.ToString()); Assert.Equal((int)snapNugetFeed.ProtocolVersion, packageSource.ProtocolVersion); Assert.NotNull(packageSource.Credentials); var credential = packageSource.Credentials; Assert.Equal(snapNugetFeed.Username, credential.Username); if (nuGetPackageSources.IsPasswordEncryptionSupported()) { Assert.False(credential.IsPasswordClearText); Assert.Equal(EncryptionUtility.DecryptString(snapNugetFeed.Password), credential.Password); Assert.Equal(snapNugetFeed.Password, credential.PasswordText); } else { Assert.True(credential.IsPasswordClearText); Assert.Equal(snapNugetFeed.Password, credential.Password); } Assert.Equal(snapNugetFeed.Name, credential.Source); Assert.Equal(snapNugetFeed.ApiKey, packageSource.GetDecryptedValue(nuGetPackageSources, ConfigurationConstants.ApiKeys)); }