| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent daacaa6 commit ee9fe75
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,7 +56,6 @@ internal static class EnvironmentVariableNames | |||
| 56 | 56 | ||
| 57 | 57 | /// <summary> | |
| 58 | 58 | /// Specifies the NuGet feeds to use for fallback NuGet dependency fetching. The value is a space-separated list of feed URLs. | |
| 59 | - /// The default value is `https://api.nuget.org/v3/index.json`. | ||
| 60 | 59 | /// </summary> | |
| 61 | 60 | public const string FallbackNugetFeeds = "CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_FALLBACK"; | |
| 62 | 61 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ internal sealed partial class FeedManager : IDisposable | |||
| 17 | 17 | private readonly IFileProvider fileProvider; | |
| 18 | 18 | private readonly DependencyDirectory emptyPackageDirectory; | |
| 19 | 19 | private readonly ImmutableHashSet<string> privateRegistryFeeds; | |
| 20 | + private readonly ImmutableHashSet<string> defaultFeeds; | ||
| 20 | 21 | private readonly IFeedManagerIO feedManagerIo; | |
| 21 | 22 | ||
| 22 | 23 | /// <summary> | |
@@ -72,6 +73,13 @@ internal sealed partial class FeedManager : IDisposable | |||
| 72 | 73 | /// </summary> | |
| 73 | 74 | public ImmutableHashSet<string> ReachableFallbackFeeds => lazyReachableFallbackFeeds.Value; | |
| 74 | 75 | ||
| 76 | + private readonly Lazy<ImmutableHashSet<string>> lazyReachableDefaultFeeds; | ||
| 77 | + | ||
| 78 | + /// <summary> | ||
| 79 | + /// Gets the list of reachable default NuGet feeds. | ||
| 80 | + /// </summary> | ||
| 81 | + public ImmutableHashSet<string> ReachableDefaultFeeds => lazyReachableDefaultFeeds.Value; | ||
| 82 | + | ||
| 75 | 83 | public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotProxy, IFileProvider fileProvider, IFeedManagerIO feedManagerIo) | |
| 76 | 84 | { | |
| 77 | 85 | this.logger = logger; | |
@@ -80,6 +88,9 @@ public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotP | |||
| 80 | 88 | this.feedManagerIo = feedManagerIo; | |
| 81 | 89 | privateRegistryFeeds = dependabotProxy?.RegistryURLs ?? []; | |
| 82 | 90 | HasPrivateRegistryFeeds = privateRegistryFeeds.Count > 0; | |
| 91 | + defaultFeeds = dependabotProxy?.RegistryBaseURLs.Any() == true | ||
| 92 | + ? dependabotProxy.RegistryBaseURLs | ||
| 93 | + : [PublicNugetOrgFeed]; | ||
| 83 | 94 | emptyPackageDirectory = new DependencyDirectory("empty", "empty package", logger); | |
| 84 | 95 | ||
| 85 | 96 | lazyExplicitFeeds = new Lazy<ImmutableHashSet<string>>(GetExplicitFeeds); | |
@@ -96,6 +107,7 @@ public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotP | |||
| 96 | 107 | var reachableFallbackFeeds = GetReachableFallbackNugetFeeds(); | |
| 97 | 108 | return reachableFallbackFeeds.ToImmutableHashSet(); | |
| 98 | 109 | }); | |
| 110 | + lazyReachableDefaultFeeds = new Lazy<ImmutableHashSet<string>>(() => CheckSpecifiedFeeds(defaultFeeds)); | ||
| 99 | 111 | } | |
| 100 | 112 | ||
| 101 | 113 | public FeedManager(ILogger logger, IDotNet dotnet, IDependabotProxy? dependabotProxy, IFileProvider fileProvider) | |
@@ -266,22 +278,6 @@ private ImmutableHashSet<string> CheckSpecifiedFeeds(ImmutableHashSet<string> fe | |||
| 266 | 278 | return reachable.Union(feeds.Where(feed => excludedFeeds.Contains(feed))).ToImmutableHashSet(); | |
| 267 | 279 | } | |
| 268 | 280 | ||
| 269 | - /// <summary> | ||
| 270 | - /// Return true if the default NuGet feed is reachable, false otherwise. | ||
| 271 | - /// If the reachability check is disabled, this method will always return true. | ||
| 272 | - /// </summary> | ||
| 273 | - /// <returns>True if the default NuGet feed is reachable, false otherwise.</returns> | ||
| 274 | - public bool IsDefaultFeedReachable() | ||
| 275 | - { | ||
| 276 | - if (CheckNugetFeedResponsiveness) | ||
| 277 | - { | ||
| 278 | - var (initialTimeout, tryCount) = GetFeedRequestSettings(isFallback: false); | ||
| 279 | - return feedManagerIo.IsFeedReachable(PublicNugetOrgFeed, initialTimeout, tryCount); | ||
| 280 | - } | ||
| 281 | - | ||
| 282 | - return true; | ||
| 283 | - } | ||
| 284 | - | ||
| 285 | 281 | /// <summary> | |
| 286 | 282 | /// Tests which of the feeds given by <paramref name="feedsToCheck"/> are reachable. | |
| 287 | 283 | /// </summary> | |
@@ -315,8 +311,8 @@ private List<string> GetReachableFallbackNugetFeeds() | |||
| 315 | 311 | var fallbackFeeds = EnvironmentVariables.GetURLs(EnvironmentVariableNames.FallbackNugetFeeds).ToHashSet(); | |
| 316 | 312 | if (fallbackFeeds.Count == 0) | |
| 317 | 313 | { | |
| 318 | - fallbackFeeds.Add(PublicNugetOrgFeed); | ||
| 319 | - logger.LogInfo($"No fallback NuGet feeds specified. Adding default feed: {PublicNugetOrgFeed}"); | ||
| 314 | + fallbackFeeds.UnionWith(defaultFeeds); | ||
| 315 | + logger.LogInfo($"No fallback NuGet feeds specified. Adding default feeds: {string.Join(", ", defaultFeeds.OrderBy(f => f))}"); | ||
| 320 | 316 | ||
| 321 | 317 | var shouldAddNugetConfigFeeds = EnvironmentVariables.GetBooleanOptOut(EnvironmentVariableNames.AddNugetConfigFeedsToFallback); | |
| 322 | 318 | logger.LogInfo($"Adding feeds from nuget.config to fallback restore: {shouldAddNugetConfigFeeds}"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,10 +67,6 @@ private class NugetExeWrapper : IPackagesConfigRestore | |||
| 67 | 67 | ||
| 68 | 68 | private bool IsWindows => SystemBuildActions.Instance.IsWindows(); | |
| 69 | 69 | ||
| 70 | - private bool? isDefaultFeedReachable; | ||
| 71 | - private bool IsDefaultFeedReachable => | ||
| 72 | - isDefaultFeedReachable ??= feedManager.IsDefaultFeedReachable(); | ||
| 73 | - | ||
| 74 | 70 | /// <summary> | |
| 75 | 71 | /// Create the package manager for a specified source tree. | |
| 76 | 72 | /// </summary> | |
@@ -169,15 +165,15 @@ private bool TryRestoreNugetPackage(string packagesConfig) | |||
| 169 | 165 | ||
| 170 | 166 | List<string> sourcesArgument = []; | |
| 171 | 167 | var feedsToUse = feedManager.FeedsToUse(packagesConfig).ToList(); | |
| 172 | - var useDefaultFeed = feedsToUse.Count == 0 && IsDefaultFeedReachable; | ||
| 168 | + var useDefaultFeeds = feedsToUse.Count == 0 && feedManager.ReachableDefaultFeeds.Count > 0; | ||
| 173 | 169 | ||
| 174 | 170 | // Explicitly construct the sources to be used for the restore command when checking feed | |
| 175 | - // responsiveness, using private registries, or falling back to nuget.org. | ||
| 176 | - if (feedManager.CheckNugetFeedResponsiveness || feedManager.HasPrivateRegistryFeeds || useDefaultFeed) | ||
| 171 | + // responsiveness, using private registries, or falling back to default feeds. | ||
| 172 | + if (feedManager.CheckNugetFeedResponsiveness || feedManager.HasPrivateRegistryFeeds || useDefaultFeeds) | ||
| 177 | 173 | { | |
| 178 | - if (useDefaultFeed) | ||
| 174 | + if (useDefaultFeeds) | ||
| 179 | 175 | { | |
| 180 | - feedsToUse.Add(FeedManager.PublicNugetOrgFeed); | ||
| 176 | + feedsToUse.AddRange(feedManager.ReachableDefaultFeeds); | ||
| 181 | 177 | } | |
| 182 | 178 | var restoreFeeds = feedManager.RestoreFeeds(feedsToUse); | |
| 183 | 179 | sourcesArgument = restoreFeeds.SelectMany<string, string>(feed => ["-Source", feed]).ToList(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,11 @@ | |||
| 1 | 1 | using Xunit; | |
| 2 | 2 | using System; | |
| 3 | 3 | using System.Collections.Generic; | |
| 4 | + using System.Collections.Immutable; | ||
| 4 | 5 | using System.IO; | |
| 5 | 6 | using System.Linq; | |
| 7 | + using System.Security.Cryptography.X509Certificates; | ||
| 6 | 8 | using Semmle.Extraction.CSharp.DependencyFetching; | |
| 7 | - using System.Collections.Immutable; | ||
| 8 | 9 | ||
| 9 | 10 | namespace Semmle.Extraction.Tests | |
| 10 | 11 | { | |
@@ -14,7 +15,18 @@ public class DependabotProxyStub : IDependabotProxy | |||
| 14 | 15 | public ImmutableHashSet<string> RegistryURLs { get; } = ["https://example.com/registry1", "https://example.com/registry2"]; | |
| 15 | 16 | public ImmutableHashSet<string> RegistryBaseURLs { get; } = []; | |
| 16 | 17 | public string? CertificatePath { get; } = null; | |
| 17 | - public System.Security.Cryptography.X509Certificates.X509Certificate2? Certificate { get; } = null; | ||
| 18 | + public X509Certificate2? Certificate { get; } = null; | ||
| 19 | + | ||
| 20 | + public void Dispose() { } | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public class DependabotProxyStubWithBaseUrls : IDependabotProxy | ||
| 24 | + { | ||
| 25 | + public string Address { get; } = ""; | ||
| 26 | + public ImmutableHashSet<string> RegistryURLs { get; } = ["https://example.com/registry1", "https://example.com/registry2", "https://example.com/base1", "https://example.com/base2"]; | ||
| 27 | + public ImmutableHashSet<string> RegistryBaseURLs { get; } = ["https://example.com/base1", "https://example.com/base2"]; | ||
| 28 | + public string? CertificatePath { get; } = null; | ||
| 29 | + public X509Certificate2? Certificate { get; } = null; | ||
| 18 | 30 | ||
| 19 | 31 | public void Dispose() { } | |
| 20 | 32 | } | |
@@ -185,5 +197,45 @@ public void TestFeedsToUse() | |||
| 185 | 197 | "https://feed.from/folder1" | |
| 186 | 198 | ], feedsToUse); | |
| 187 | 199 | } | |
| 200 | + | ||
| 201 | + [Fact] | ||
| 202 | + public void TestDefaultFeeds1() | ||
| 203 | + { | ||
| 204 | + // Setup | ||
| 205 | + var feedManager = MakeFeedManager(); | ||
| 206 | + | ||
| 207 | + // Execute | ||
| 208 | + var reachableDefault = feedManager.ReachableDefaultFeeds; | ||
| 209 | + | ||
| 210 | + // Verify | ||
| 211 | + Assert.Equal([ | ||
| 212 | + "https://api.nuget.org/v3/index.json" | ||
| 213 | + ], reachableDefault); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + [Fact] | ||
| 217 | + public void TestDefaultFeeds2() | ||
| 218 | + { | ||
| 219 | + // Setup | ||
| 220 | + var logger = new LoggerStub(); | ||
| 221 | + var dotnet = new DotNetStub([], [], [], []); | ||
| 222 | + var dependabotProxy = new DependabotProxyStubWithBaseUrls(); | ||
| 223 | + var fileProvider = new FileProviderStub(); | ||
| 224 | + var feedManagerIo = new FeedManagerIOStub(["https://example.com/registry2", "https://example.com/base1"]); | ||
| 225 | + var feedManager = new FeedManager(logger, dotnet, dependabotProxy, fileProvider, feedManagerIo); | ||
| 226 | + | ||
| 227 | + // Execute | ||
| 228 | + var reachableDefault = feedManager.ReachableDefaultFeeds; | ||
| 229 | + var reachableFallback = feedManager.ReachableFallbackFeeds; | ||
| 230 | + | ||
| 231 | + // Verify | ||
| 232 | + Assert.Equal([ | ||
| 233 | + "https://example.com/base2" | ||
| 234 | + ], reachableDefault); | ||
| 235 | + Assert.Equal([ | ||
| 236 | + "https://example.com/registry1", | ||
| 237 | + "https://example.com/base2" | ||
| 238 | + ], reachableFallback); | ||
| 239 | + } | ||
| 188 | 240 | } | |
| 189 | 241 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments