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)); }