diff options
author | Matt Ward <matt.ward@microsoft.com> | 2020-01-17 18:21:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-17 18:21:47 +0300 |
commit | 30ff79c2f58be039e7d3b9c430c1be50f6c30253 (patch) | |
tree | 8e56128797f99a973f49c1cab4d133053a8705d0 /main/src/addins/MonoDevelop.PackageManagement | |
parent | 8fb03b1e3c970d0429cb12ef30cf4d09867f4b6d (diff) | |
parent | a8800cba80d380877b1b6215307e1289f0839d77 (diff) |
Merge pull request #8844 from mono/nuget-5.4-preview
[NuGet] Fix requests bypassing the native HTTP handler
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj | 1 | ||||
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopNuGetResourceProviderFactoryTests.cs | 70 | ||||
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj | 2 | ||||
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetResourceProviderFactory.cs (renamed from main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/RepositoryProviderFactoryExtensions.cs) | 49 | ||||
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SourceRepositoryProvider.cs | 2 |
5 files changed, 112 insertions, 12 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj index ff695562c1..b96a78138b 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj @@ -159,6 +159,7 @@ <Compile Include="MonoDevelop.PackageManagement.Tests\UpdateStrictPackageDependenciesTests.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests\UpdateMultipleNuGetPackagesActionTests.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableUpdateMultipleNuGetPackagesAction.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests\MonoDevelopNuGetResourceProviderFactoryTests.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj"> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopNuGetResourceProviderFactoryTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopNuGetResourceProviderFactoryTests.cs new file mode 100644 index 0000000000..522b851f30 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopNuGetResourceProviderFactoryTests.cs @@ -0,0 +1,70 @@ +// +// MonoDevelopNuGetResourceProviderFactoryTests.cs +// +// Author: +// Matt Ward <matt.ward@microsoft.com> +// +// Copyright (c) 2019 Microsoft Corporation +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; +using NuGet.Protocol; +using NuGet.Protocol.Core.Types; +using NUnit.Framework; + +namespace MonoDevelop.PackageManagement.Tests +{ + [TestFixture] + public class MonoDevelopNuGetResourceProviderFactoryTests + { + [Test] + public void CustomProviderFactory_HasSameProvidersAsDefault_ExceptHttpHandlerResourceProvider () + { + bool customHttpHandlerResourceV3Provider = false; + var customProviderItems = new List<string> (); + var defaultProviderItems = new List<string> (); + + // Touch the MonoDevelopNuGetResourceProviderFactory so it initializes the NuGet Respository.Provider. + // The NuGet addin uses MonoDevelopNuGetResourceProviderFactory directly some parts of NuGet create + // new SourceRepository instances using Repository.Provider directory. + var _ = MonoDevelopNuGetResourceProviderFactory.GetProviders (); + + foreach (Lazy<INuGetResourceProvider> item in Repository.Provider.GetCoreV3 ()) { + Type type = item.Value.GetType (); + if (type == typeof (MonoDevelopHttpHandlerResourceV3Provider)) { + type = typeof (HttpHandlerResourceV3Provider); + customHttpHandlerResourceV3Provider = true; + } + customProviderItems.Add (type.Name); + } + + var defaultProviderFactory = new Repository.ProviderFactory (); + + foreach (Lazy<INuGetResourceProvider> item in defaultProviderFactory.GetCoreV3 ()) { + Type type = item.Value.GetType (); + defaultProviderItems.Add (type.Name); + } + + Assert.AreEqual (defaultProviderItems, customProviderItems); + Assert.IsTrue (customHttpHandlerResourceV3Provider, "Custom MonoDevelopHttpHandlerResourceV3Provider not used"); + } + } +} diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj index 6a83e95e4e..ba2765a202 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj @@ -314,7 +314,6 @@ <Compile Include="MonoDevelop.PackageManagement\ItemTemplateNuGetPackageInstaller.cs" /> <Compile Include="Gui\MonoDevelop.PackageManagement.PackageManagementOptionsWidget.cs" /> <Compile Include="Gui\MonoDevelop.PackageManagement.PackageSourcesWidget.cs" /> - <Compile Include="MonoDevelop.PackageManagement\RepositoryProviderFactoryExtensions.cs" /> <Compile Include="MonoDevelop.PackageManagement\MonoDevelopHttpHandlerResourceV3Provider.cs" /> <Compile Include="MonoDevelop.PackageManagement\MonoDevelopServerWarningLogHandler.cs" /> <Compile Include="MonoDevelop.PackageManagement\NuGetHttpSourceAuthenticationHandler.cs" /> @@ -369,6 +368,7 @@ <Compile Include="MonoDevelop.PackageManagement\UpdateMultipleNuGetPackagesAction.cs" /> <Compile Include="MonoDevelop.PackageManagement\ProjectReferenceMaintainerCollection.cs" /> <Compile Include="MonoDevelop.PackageManagement\MonoDevelopPluginFactory.cs" /> + <Compile Include="MonoDevelop.PackageManagement\MonoDevelopNuGetResourceProviderFactory.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.PackageManagement.addin.xml" /> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/RepositoryProviderFactoryExtensions.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetResourceProviderFactory.cs index 4f9569a233..43d08989e1 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/RepositoryProviderFactoryExtensions.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/MonoDevelopNuGetResourceProviderFactory.cs @@ -1,8 +1,28 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // -// Based on FactoryExtensionsV3 and FactoryExtensionsVS -// From: https://github.com/NuGet/NuGet.Client/ +// MonoDevelopNuGetResourceProviderFactory.cs +// +// Author: +// Matt Ward <matt.ward@microsoft.com> +// +// Copyright (c) 2019 Microsoft Corporation +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. using System; using System.Collections.Generic; @@ -12,19 +32,25 @@ using NuGet.Protocol.LocalRepositories; namespace MonoDevelop.PackageManagement { - static class RepositoryProviderFactoryExtensions + class MonoDevelopNuGetResourceProviderFactory : Repository.ProviderFactory { - public static IEnumerable<Lazy<INuGetResourceProvider>> GetMonoDevelop (this Repository.ProviderFactory factory) + static MonoDevelopNuGetResourceProviderFactory () + { + // Some parts of NuGet create new SourceRepository instances which bypasses the custom + // MonoDevelopHttpHandlerResourceV3Provider used when SourceRepository instances are created by the NuGet + // addin itself. To prevent this the default provider factory is replaced with a custom provider factory. + Repository.Provider = new MonoDevelopNuGetResourceProviderFactory (); + } + + public static IEnumerable<Lazy<INuGetResourceProvider>> GetProviders () { - foreach (Lazy<INuGetResourceProvider> item in Repository.Provider.GetMonoDevelopCoreV3 ()) { - yield return item; - } + return Repository.Provider.GetCoreV3 (); } /// <summary> /// Includes a custom HttpHandlerResourceV3Provider which can use native HttpMessageHandlers defined by MonoDevelop. /// </summary> - public static IEnumerable<Lazy<INuGetResourceProvider>> GetMonoDevelopCoreV3 (this Repository.ProviderFactory factory) + public override IEnumerable<Lazy<INuGetResourceProvider>> GetCoreV3 () { yield return new Lazy<INuGetResourceProvider> (() => new FeedTypeResourceProvider ()); yield return new Lazy<INuGetResourceProvider> (() => new DependencyInfoResourceV3Provider ()); @@ -33,7 +59,9 @@ namespace MonoDevelop.PackageManagement yield return new Lazy<INuGetResourceProvider> (() => new MetadataResourceV3Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new RawSearchResourceV3Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new RegistrationResourceV3Provider ()); + yield return new Lazy<INuGetResourceProvider> (() => new SymbolPackageUpdateResourceV3Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new ReportAbuseResourceV3Provider ()); + yield return new Lazy<INuGetResourceProvider> (() => new PackageDetailsUriResourceV3Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new ServiceIndexResourceV3Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new ODataServiceDocumentResourceV2Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new MonoDevelopHttpHandlerResourceV3Provider ()); @@ -59,6 +87,7 @@ namespace MonoDevelop.PackageManagement yield return new Lazy<INuGetResourceProvider> (() => new AutoCompleteResourceV2FeedProvider ()); yield return new Lazy<INuGetResourceProvider> (() => new AutoCompleteResourceV3Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new PluginResourceProvider (PackageManagementServices.PluginManager)); + yield return new Lazy<INuGetResourceProvider> (() => new RepositorySignatureResourceProvider ()); yield return new Lazy<INuGetResourceProvider> (() => new FindLocalPackagesResourceUnzippedProvider ()); yield return new Lazy<INuGetResourceProvider> (() => new FindLocalPackagesResourceV2Provider ()); yield return new Lazy<INuGetResourceProvider> (() => new FindLocalPackagesResourceV3Provider ()); diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SourceRepositoryProvider.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SourceRepositoryProvider.cs index 3bc25eef1a..887f7286ac 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SourceRepositoryProvider.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SourceRepositoryProvider.cs @@ -40,7 +40,7 @@ namespace MonoDevelop.PackageManagement public static ISourceRepositoryProvider CreateSourceRepositoryProvider (ISettings settings)
{
var packageSourceProvider = new MonoDevelopPackageSourceProvider (settings);
- return new SourceRepositoryProvider (packageSourceProvider, Repository.Provider.GetMonoDevelop ());
+ return new SourceRepositoryProvider (packageSourceProvider, MonoDevelopNuGetResourceProviderFactory.GetProviders ());
}
}
}
|