dependabot-nuget 0.241.0 → 0.242.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +4 -5
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +18 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +17 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +3 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +25 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +19 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +2 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +18 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +204 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +63 -0
- data/lib/dependabot/nuget/file_fetcher.rb +3 -23
- data/lib/dependabot/nuget/file_parser/project_file_parser.rb +2 -41
- data/lib/dependabot/nuget/file_parser.rb +4 -4
- data/lib/dependabot/nuget/nuget_client.rb +74 -11
- data/lib/dependabot/nuget/update_checker/version_finder.rb +1 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a49c3bda283658e65f9a37cf33e5b4855048bf2673bcfdcde4bb2e39d00d68e
|
4
|
+
data.tar.gz: 340fb04884786613bcbf75e25f7b51be9e662d26211418804965162df2c95c2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55e5a6b6949b5d30cfd95fb8ac185e9ccad548e0f8cc073237181c8a99e76252602920f6ff4cce68afb8310b4e358a7191ff4c9fe1ef27e92147529eb6c0012a
|
7
|
+
data.tar.gz: ea153c1649add8848551c6a54577beb7fa554f557275d1ed09928d741bc5ded5a1bfe7ed39561592bda152d8ded72f4081d30da3fcd748500f5d887825c27eb9
|
@@ -1,3 +1,3 @@
|
|
1
1
|
namespace NuGetUpdater.Core;
|
2
2
|
|
3
|
-
public sealed record Dependency(string Name, string? Version, DependencyType Type, bool IsDevDependency = false, bool IsOverride = false);
|
3
|
+
public sealed record Dependency(string Name, string? Version, DependencyType Type, bool IsDevDependency = false, bool IsOverride = false, bool IsUpdate = false);
|
@@ -1,4 +1,3 @@
|
|
1
|
-
using System;
|
2
1
|
using System.Collections.Generic;
|
3
2
|
using System.IO;
|
4
3
|
using System.Linq;
|
@@ -8,11 +7,11 @@ namespace NuGetUpdater.Core;
|
|
8
7
|
|
9
8
|
internal sealed class DotNetToolsJsonBuildFile : JsonBuildFile
|
10
9
|
{
|
11
|
-
public static DotNetToolsJsonBuildFile Open(string repoRootPath, string path)
|
12
|
-
=> new(repoRootPath, path, File.ReadAllText(path));
|
10
|
+
public static DotNetToolsJsonBuildFile Open(string repoRootPath, string path, Logger logger)
|
11
|
+
=> new(repoRootPath, path, File.ReadAllText(path), logger);
|
13
12
|
|
14
|
-
public DotNetToolsJsonBuildFile(string repoRootPath, string path, string contents)
|
15
|
-
: base(repoRootPath, path, contents)
|
13
|
+
public DotNetToolsJsonBuildFile(string repoRootPath, string path, string contents, Logger logger)
|
14
|
+
: base(repoRootPath, path, contents, logger)
|
16
15
|
{
|
17
16
|
}
|
18
17
|
|
@@ -7,18 +7,29 @@ namespace NuGetUpdater.Core;
|
|
7
7
|
|
8
8
|
internal sealed class GlobalJsonBuildFile : JsonBuildFile
|
9
9
|
{
|
10
|
-
public static GlobalJsonBuildFile Open(string repoRootPath, string path)
|
11
|
-
=> new(repoRootPath, path, File.ReadAllText(path));
|
10
|
+
public static GlobalJsonBuildFile Open(string repoRootPath, string path, Logger logger)
|
11
|
+
=> new(repoRootPath, path, File.ReadAllText(path), logger);
|
12
12
|
|
13
|
-
public GlobalJsonBuildFile(string repoRootPath, string path, string contents)
|
14
|
-
: base(repoRootPath, path, contents)
|
13
|
+
public GlobalJsonBuildFile(string repoRootPath, string path, string contents, Logger logger)
|
14
|
+
: base(repoRootPath, path, contents, logger)
|
15
15
|
{
|
16
16
|
}
|
17
17
|
|
18
|
-
public JsonObject? Sdk
|
18
|
+
public JsonObject? Sdk
|
19
|
+
{
|
20
|
+
get
|
21
|
+
{
|
22
|
+
return Node.Value is JsonObject root ? root["sdk"]?.AsObject() : null;
|
23
|
+
}
|
24
|
+
}
|
19
25
|
|
20
|
-
public JsonObject? MSBuildSdks
|
21
|
-
|
26
|
+
public JsonObject? MSBuildSdks
|
27
|
+
{
|
28
|
+
get
|
29
|
+
{
|
30
|
+
return Node.Value is JsonObject root ? root["msbuild-sdks"]?.AsObject() : null;
|
31
|
+
}
|
32
|
+
}
|
22
33
|
|
23
34
|
public IEnumerable<Dependency> GetDependencies() => MSBuildSdks?.AsObject().Select(
|
24
35
|
t => new Dependency(t.Key, t.Value?.GetValue<string>() ?? string.Empty, DependencyType.MSBuildSdk)) ?? Enumerable.Empty<Dependency>();
|
@@ -8,11 +8,13 @@ namespace NuGetUpdater.Core;
|
|
8
8
|
internal abstract class JsonBuildFile : BuildFile<string>
|
9
9
|
{
|
10
10
|
protected Lazy<JsonNode?> Node;
|
11
|
+
private readonly Logger logger;
|
11
12
|
|
12
|
-
public JsonBuildFile(string repoRootPath, string path, string contents)
|
13
|
+
public JsonBuildFile(string repoRootPath, string path, string contents, Logger logger)
|
13
14
|
: base(repoRootPath, path, contents)
|
14
15
|
{
|
15
16
|
Node = new Lazy<JsonNode?>(() => null);
|
17
|
+
this.logger = logger;
|
16
18
|
ResetNode();
|
17
19
|
}
|
18
20
|
|
@@ -27,6 +29,19 @@ internal abstract class JsonBuildFile : BuildFile<string>
|
|
27
29
|
|
28
30
|
private void ResetNode()
|
29
31
|
{
|
30
|
-
Node = new Lazy<JsonNode?>(() =>
|
32
|
+
Node = new Lazy<JsonNode?>(() =>
|
33
|
+
{
|
34
|
+
try
|
35
|
+
{
|
36
|
+
return JsonHelper.ParseNode(Contents);
|
37
|
+
}
|
38
|
+
catch (System.Text.Json.JsonException ex)
|
39
|
+
{
|
40
|
+
// We can't police that people have legal JSON files.
|
41
|
+
// If they don't, we just return null.
|
42
|
+
logger.Log($"Failed to parse JSON file: {RepoRelativePath}, got {ex}");
|
43
|
+
return null;
|
44
|
+
}
|
45
|
+
});
|
31
46
|
}
|
32
47
|
}
|
@@ -10,7 +10,7 @@ internal static partial class DotNetToolsJsonUpdater
|
|
10
10
|
{
|
11
11
|
public static async Task UpdateDependencyAsync(string repoRootPath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, Logger logger)
|
12
12
|
{
|
13
|
-
var buildFiles = LoadBuildFiles(repoRootPath);
|
13
|
+
var buildFiles = LoadBuildFiles(repoRootPath, logger);
|
14
14
|
if (buildFiles.Length == 0)
|
15
15
|
{
|
16
16
|
logger.Log($" No dotnet-tools.json files found.");
|
@@ -49,7 +49,7 @@ internal static partial class DotNetToolsJsonUpdater
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
-
private static ImmutableArray<DotNetToolsJsonBuildFile> LoadBuildFiles(string repoRootPath)
|
52
|
+
private static ImmutableArray<DotNetToolsJsonBuildFile> LoadBuildFiles(string repoRootPath, Logger logger)
|
53
53
|
{
|
54
54
|
var options = new EnumerationOptions()
|
55
55
|
{
|
@@ -60,7 +60,7 @@ internal static partial class DotNetToolsJsonUpdater
|
|
60
60
|
MatchCasing = MatchCasing.CaseInsensitive,
|
61
61
|
};
|
62
62
|
return Directory.EnumerateFiles(repoRootPath, "dotnet-tools.json", options)
|
63
|
-
.Select(path => DotNetToolsJsonBuildFile.Open(repoRootPath, path))
|
63
|
+
.Select(path => DotNetToolsJsonBuildFile.Open(repoRootPath, path, logger))
|
64
64
|
.ToImmutableArray();
|
65
65
|
}
|
66
66
|
}
|
@@ -15,7 +15,7 @@ internal static partial class GlobalJsonUpdater
|
|
15
15
|
return;
|
16
16
|
}
|
17
17
|
|
18
|
-
var globalJsonFile = GlobalJsonBuildFile.Open(repoRootPath, globalJsonPath);
|
18
|
+
var globalJsonFile = GlobalJsonBuildFile.Open(repoRootPath, globalJsonPath, logger);
|
19
19
|
|
20
20
|
logger.Log($" Updating [{globalJsonFile.RepoRelativePath}] file.");
|
21
21
|
|
@@ -34,7 +34,7 @@ internal static partial class SdkPackageUpdater
|
|
34
34
|
foreach (var tfm in tfms)
|
35
35
|
{
|
36
36
|
var dependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(repoRootPath, projectPath, tfm, topLevelDependencies, logger);
|
37
|
-
foreach (var (packageName, packageVersion, _, _, _) in dependencies)
|
37
|
+
foreach (var (packageName, packageVersion, _, _, _, _) in dependencies)
|
38
38
|
{
|
39
39
|
if (packageName.Equals(dependencyName, StringComparison.OrdinalIgnoreCase))
|
40
40
|
{
|
@@ -76,7 +76,7 @@ internal static partial class SdkPackageUpdater
|
|
76
76
|
var packagesAndVersions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
77
77
|
foreach (var (tfm, dependencies) in tfmsAndDependencies)
|
78
78
|
{
|
79
|
-
foreach (var (packageName, packageVersion, _, _, _) in dependencies)
|
79
|
+
foreach (var (packageName, packageVersion, _, _, _, _) in dependencies)
|
80
80
|
{
|
81
81
|
if (packagesAndVersions.TryGetValue(packageName, out var existingVersion) &&
|
82
82
|
existingVersion != packageVersion)
|
@@ -136,7 +136,7 @@ internal static partial class MSBuildHelper
|
|
136
136
|
|
137
137
|
public static IEnumerable<Dependency> GetTopLevelPackageDependenyInfos(ImmutableArray<ProjectBuildFile> buildFiles)
|
138
138
|
{
|
139
|
-
Dictionary<string, string> packageInfo = new(StringComparer.OrdinalIgnoreCase);
|
139
|
+
Dictionary<string, (string, bool)> packageInfo = new(StringComparer.OrdinalIgnoreCase);
|
140
140
|
Dictionary<string, string> packageVersionInfo = new(StringComparer.OrdinalIgnoreCase);
|
141
141
|
Dictionary<string, string> propertyInfo = new(StringComparer.OrdinalIgnoreCase);
|
142
142
|
|
@@ -154,7 +154,22 @@ internal static partial class MSBuildHelper
|
|
154
154
|
{
|
155
155
|
if (!string.IsNullOrWhiteSpace(attributeValue))
|
156
156
|
{
|
157
|
-
packageInfo
|
157
|
+
if (packageInfo.TryGetValue(attributeValue, out var existingInfo))
|
158
|
+
{
|
159
|
+
var existingVersion = existingInfo.Item1;
|
160
|
+
var existingUpdate = existingInfo.Item2;
|
161
|
+
// Retain the version from the Update reference since the intention
|
162
|
+
// would be to override the version of the Include reference.
|
163
|
+
var vSpec = string.IsNullOrEmpty(versionSpecification) || existingUpdate ? existingVersion : versionSpecification;
|
164
|
+
|
165
|
+
var isUpdate = existingUpdate && string.IsNullOrEmpty(packageItem.Include);
|
166
|
+
packageInfo[attributeValue] = (vSpec, isUpdate);
|
167
|
+
}
|
168
|
+
else
|
169
|
+
{
|
170
|
+
var isUpdate = !string.IsNullOrEmpty(packageItem.Update);
|
171
|
+
packageInfo[attributeValue] = (versionSpecification, isUpdate);
|
172
|
+
}
|
158
173
|
}
|
159
174
|
}
|
160
175
|
}
|
@@ -180,8 +195,9 @@ internal static partial class MSBuildHelper
|
|
180
195
|
}
|
181
196
|
}
|
182
197
|
|
183
|
-
foreach (var (name,
|
198
|
+
foreach (var (name, info) in packageInfo)
|
184
199
|
{
|
200
|
+
var (version, isUpdate) = info;
|
185
201
|
if (version.Length != 0 || !packageVersionInfo.TryGetValue(name, out var packageVersion))
|
186
202
|
{
|
187
203
|
packageVersion = version;
|
@@ -195,8 +211,8 @@ internal static partial class MSBuildHelper
|
|
195
211
|
// We don't know the version for range requirements or wildcard
|
196
212
|
// requirements, so return "" for these.
|
197
213
|
yield return packageVersion.Contains(',') || packageVersion.Contains('*')
|
198
|
-
? new Dependency(name, string.Empty, DependencyType.Unknown)
|
199
|
-
: new Dependency(name, packageVersion, DependencyType.Unknown);
|
214
|
+
? new Dependency(name, string.Empty, DependencyType.Unknown, IsUpdate: isUpdate)
|
215
|
+
: new Dependency(name, packageVersion, DependencyType.Unknown, IsUpdate: isUpdate);
|
200
216
|
}
|
201
217
|
}
|
202
218
|
|
@@ -247,7 +263,7 @@ internal static partial class MSBuildHelper
|
|
247
263
|
try
|
248
264
|
{
|
249
265
|
var tempProjectPath = await CreateTempProjectAsync(tempDirectory, repoRoot, projectPath, targetFramework, packages);
|
250
|
-
var (exitCode, stdOut, stdErr) = await ProcessEx.RunAsync("dotnet", $"
|
266
|
+
var (exitCode, stdOut, stdErr) = await ProcessEx.RunAsync("dotnet", $"restore \"{tempProjectPath}\"");
|
251
267
|
|
252
268
|
// NU1608: Detected package version outside of dependency constraint
|
253
269
|
|
@@ -284,13 +300,15 @@ internal static partial class MSBuildHelper
|
|
284
300
|
Environment.NewLine,
|
285
301
|
packages
|
286
302
|
.Where(p => !string.IsNullOrWhiteSpace(p.Version)) // empty `Version` attributes will cause the temporary project to not build
|
287
|
-
|
303
|
+
// If all PackageReferences for a package are update-only mark it as such, otherwise it can cause package incoherence errors which do not exist in the repo.
|
304
|
+
.Select(static p => $"<PackageReference {(p.IsUpdate ? "Update" : "Include")}=\"{p.Name}\" Version=\"[{p.Version}]\" />"));
|
288
305
|
|
289
306
|
var projectContents = $"""
|
290
307
|
<Project Sdk="Microsoft.NET.Sdk">
|
291
308
|
<PropertyGroup>
|
292
309
|
<TargetFramework>{targetFramework}</TargetFramework>
|
293
310
|
<GenerateDependencyFile>true</GenerateDependencyFile>
|
311
|
+
<RunAnalyzers>false</RunAnalyzers>
|
294
312
|
</PropertyGroup>
|
295
313
|
<ItemGroup>
|
296
314
|
{packageReferences}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
using System;
|
2
2
|
using System.Diagnostics;
|
3
3
|
using System.Text;
|
4
|
+
using System.Threading;
|
4
5
|
using System.Threading.Tasks;
|
5
6
|
|
6
7
|
namespace NuGetUpdater.Core;
|
@@ -11,6 +12,7 @@ public static class ProcessEx
|
|
11
12
|
{
|
12
13
|
var tcs = new TaskCompletionSource<(int, string, string)>();
|
13
14
|
|
15
|
+
var redirectInitiated = new ManualResetEventSlim();
|
14
16
|
var process = new Process
|
15
17
|
{
|
16
18
|
StartInfo =
|
@@ -37,8 +39,21 @@ public static class ProcessEx
|
|
37
39
|
|
38
40
|
process.Exited += (sender, args) =>
|
39
41
|
{
|
40
|
-
|
41
|
-
|
42
|
+
// It is necessary to wait until we have invoked 'BeginXReadLine' for our redirected IO. Then,
|
43
|
+
// we must call WaitForExit to make sure we've received all OutputDataReceived/ErrorDataReceived calls
|
44
|
+
// or else we'll be returning a list we're still modifying. For paranoia, we'll start a task here rather
|
45
|
+
// than enter right back into the Process type and start a wait which isn't guaranteed to be safe.
|
46
|
+
Task.Run(() =>
|
47
|
+
{
|
48
|
+
redirectInitiated.Wait();
|
49
|
+
redirectInitiated.Dispose();
|
50
|
+
redirectInitiated = null;
|
51
|
+
|
52
|
+
process.WaitForExit();
|
53
|
+
|
54
|
+
tcs.TrySetResult((process.ExitCode, stdout.ToString(), stderr.ToString()));
|
55
|
+
process.Dispose();
|
56
|
+
});
|
42
57
|
};
|
43
58
|
|
44
59
|
#if DEBUG
|
@@ -61,6 +76,8 @@ public static class ProcessEx
|
|
61
76
|
process.BeginOutputReadLine();
|
62
77
|
process.BeginErrorReadLine();
|
63
78
|
|
79
|
+
redirectInitiated.Set();
|
80
|
+
|
64
81
|
return tcs.Task;
|
65
82
|
}
|
66
83
|
}
|
@@ -32,7 +32,8 @@ public class DotnetToolsJsonBuildFileTests
|
|
32
32
|
private static DotNetToolsJsonBuildFile GetBuildFile() => new(
|
33
33
|
repoRootPath: "/",
|
34
34
|
path: "/.config/dotnet-tools.json",
|
35
|
-
contents: DotnetToolsJson
|
35
|
+
contents: DotnetToolsJson,
|
36
|
+
logger: new Logger(verbose: true));
|
36
37
|
|
37
38
|
[Fact]
|
38
39
|
public void GetDependencies_ReturnsDependencies()
|
@@ -31,7 +31,24 @@ public class GlobalJsonBuildFileTests
|
|
31
31
|
private static GlobalJsonBuildFile GetBuildFile(string contents) => new(
|
32
32
|
repoRootPath: "/",
|
33
33
|
path: "/global.json",
|
34
|
-
contents: contents
|
34
|
+
contents: contents,
|
35
|
+
logger: new Logger(verbose: true));
|
36
|
+
|
37
|
+
[Fact]
|
38
|
+
public void GlobalJson_Malformed_DoesNotThrow()
|
39
|
+
{
|
40
|
+
var buildFile = GetBuildFile("""[{ "Random": "stuff"}]""");
|
41
|
+
|
42
|
+
Assert.Null(buildFile.MSBuildSdks);
|
43
|
+
}
|
44
|
+
|
45
|
+
[Fact]
|
46
|
+
public void GlobalJson_NotJson_DoesNotThrow()
|
47
|
+
{
|
48
|
+
var buildFile = GetBuildFile("not json");
|
49
|
+
|
50
|
+
Assert.Null(buildFile.MSBuildSdks);
|
51
|
+
}
|
35
52
|
|
36
53
|
[Fact]
|
37
54
|
public void GlobalJson_GetDependencies_ReturnsDependencies()
|
@@ -171,6 +171,144 @@ public class MSBuildHelperTests
|
|
171
171
|
Assert.Equal(expectedDependencies, actualDependencies);
|
172
172
|
}
|
173
173
|
|
174
|
+
[Fact]
|
175
|
+
public async Task AllPackageDependencies_DoNotTruncateLongDependencyLists()
|
176
|
+
{
|
177
|
+
using var temp = new TemporaryDirectory();
|
178
|
+
var expectedDependencies = new Dependency[]
|
179
|
+
{
|
180
|
+
new("Castle.Core", "4.4.1", DependencyType.Unknown),
|
181
|
+
new("Microsoft.ApplicationInsights", "2.10.0", DependencyType.Unknown),
|
182
|
+
new("Microsoft.ApplicationInsights.Agent.Intercept", "2.4.0", DependencyType.Unknown),
|
183
|
+
new("Microsoft.ApplicationInsights.DependencyCollector", "2.10.0", DependencyType.Unknown),
|
184
|
+
new("Microsoft.ApplicationInsights.PerfCounterCollector", "2.10.0", DependencyType.Unknown),
|
185
|
+
new("Microsoft.ApplicationInsights.WindowsServer", "2.10.0", DependencyType.Unknown),
|
186
|
+
new("Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel", "2.10.0", DependencyType.Unknown),
|
187
|
+
new("Microsoft.AspNet.TelemetryCorrelation", "1.0.5", DependencyType.Unknown),
|
188
|
+
new("Microsoft.Bcl.AsyncInterfaces", "7.0.0", DependencyType.Unknown),
|
189
|
+
new("Microsoft.Extensions.Caching.Abstractions", "1.0.0", DependencyType.Unknown),
|
190
|
+
new("Microsoft.Extensions.Caching.Memory", "1.0.0", DependencyType.Unknown),
|
191
|
+
new("Microsoft.Extensions.DependencyInjection", "7.0.0", DependencyType.Unknown),
|
192
|
+
new("Microsoft.Extensions.DependencyInjection.Abstractions", "7.0.0", DependencyType.Unknown),
|
193
|
+
new("Microsoft.Extensions.DiagnosticAdapter", "1.1.0", DependencyType.Unknown),
|
194
|
+
new("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
|
195
|
+
new("Microsoft.Extensions.Logging", "7.0.0", DependencyType.Unknown),
|
196
|
+
new("Microsoft.Extensions.Logging.Abstractions", "7.0.0", DependencyType.Unknown),
|
197
|
+
new("Microsoft.Extensions.Options", "7.0.0", DependencyType.Unknown),
|
198
|
+
new("Microsoft.Extensions.PlatformAbstractions", "1.1.0", DependencyType.Unknown),
|
199
|
+
new("Microsoft.Extensions.Primitives", "7.0.0", DependencyType.Unknown),
|
200
|
+
new("Moq", "4.16.1", DependencyType.Unknown),
|
201
|
+
new("MSTest.TestFramework", "2.1.0", DependencyType.Unknown),
|
202
|
+
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown),
|
203
|
+
new("System", "4.1.311.2", DependencyType.Unknown),
|
204
|
+
new("System.Buffers", "4.5.1", DependencyType.Unknown),
|
205
|
+
new("System.Collections.Concurrent", "4.3.0", DependencyType.Unknown),
|
206
|
+
new("System.Collections.Immutable", "1.3.0", DependencyType.Unknown),
|
207
|
+
new("System.Collections.NonGeneric", "4.3.0", DependencyType.Unknown),
|
208
|
+
new("System.Collections.Specialized", "4.3.0", DependencyType.Unknown),
|
209
|
+
new("System.ComponentModel", "4.3.0", DependencyType.Unknown),
|
210
|
+
new("System.ComponentModel.Annotations", "5.0.0", DependencyType.Unknown),
|
211
|
+
new("System.ComponentModel.Primitives", "4.3.0", DependencyType.Unknown),
|
212
|
+
new("System.ComponentModel.TypeConverter", "4.3.0", DependencyType.Unknown),
|
213
|
+
new("System.Core", "3.5.21022.801", DependencyType.Unknown),
|
214
|
+
new("System.Data.Common", "4.3.0", DependencyType.Unknown),
|
215
|
+
new("System.Diagnostics.DiagnosticSource", "7.0.0", DependencyType.Unknown),
|
216
|
+
new("System.Diagnostics.PerformanceCounter", "4.5.0", DependencyType.Unknown),
|
217
|
+
new("System.Diagnostics.StackTrace", "4.3.0", DependencyType.Unknown),
|
218
|
+
new("System.Dynamic.Runtime", "4.3.0", DependencyType.Unknown),
|
219
|
+
new("System.IO.FileSystem.Primitives", "4.3.0", DependencyType.Unknown),
|
220
|
+
new("System.Linq", "4.3.0", DependencyType.Unknown),
|
221
|
+
new("System.Linq.Expressions", "4.3.0", DependencyType.Unknown),
|
222
|
+
new("System.Memory", "4.5.5", DependencyType.Unknown),
|
223
|
+
new("System.Net.WebHeaderCollection", "4.3.0", DependencyType.Unknown),
|
224
|
+
new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
|
225
|
+
new("System.ObjectModel", "4.3.0", DependencyType.Unknown),
|
226
|
+
new("System.Private.DataContractSerialization", "4.3.0", DependencyType.Unknown),
|
227
|
+
new("System.Reflection.Emit", "4.3.0", DependencyType.Unknown),
|
228
|
+
new("System.Reflection.Emit.ILGeneration", "4.3.0", DependencyType.Unknown),
|
229
|
+
new("System.Reflection.Emit.Lightweight", "4.3.0", DependencyType.Unknown),
|
230
|
+
new("System.Reflection.Metadata", "1.4.1", DependencyType.Unknown),
|
231
|
+
new("System.Reflection.TypeExtensions", "4.3.0", DependencyType.Unknown),
|
232
|
+
new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
|
233
|
+
new("System.Runtime.InteropServices.RuntimeInformation", "4.3.0", DependencyType.Unknown),
|
234
|
+
new("System.Runtime.Numerics", "4.3.0", DependencyType.Unknown),
|
235
|
+
new("System.Runtime.Serialization.Json", "4.3.0", DependencyType.Unknown),
|
236
|
+
new("System.Runtime.Serialization.Primitives", "4.3.0", DependencyType.Unknown),
|
237
|
+
new("System.Security.Claims", "4.3.0", DependencyType.Unknown),
|
238
|
+
new("System.Security.Cryptography.OpenSsl", "4.3.0", DependencyType.Unknown),
|
239
|
+
new("System.Security.Cryptography.Primitives", "4.3.0", DependencyType.Unknown),
|
240
|
+
new("System.Security.Principal", "4.3.0", DependencyType.Unknown),
|
241
|
+
new("System.Text.RegularExpressions", "4.3.0", DependencyType.Unknown),
|
242
|
+
new("System.Threading", "4.3.0", DependencyType.Unknown),
|
243
|
+
new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
|
244
|
+
new("System.Threading.Thread", "4.3.0", DependencyType.Unknown),
|
245
|
+
new("System.Threading.ThreadPool", "4.3.0", DependencyType.Unknown),
|
246
|
+
new("System.Xml.ReaderWriter", "4.3.0", DependencyType.Unknown),
|
247
|
+
new("System.Xml.XDocument", "4.3.0", DependencyType.Unknown),
|
248
|
+
new("System.Xml.XmlDocument", "4.3.0", DependencyType.Unknown),
|
249
|
+
new("System.Xml.XmlSerializer", "4.3.0", DependencyType.Unknown),
|
250
|
+
new("Microsoft.ApplicationInsights.Web", "2.10.0", DependencyType.Unknown),
|
251
|
+
new("MSTest.TestAdapter", "2.1.0", DependencyType.Unknown),
|
252
|
+
new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
|
253
|
+
};
|
254
|
+
var packages = new[] {
|
255
|
+
new Dependency("System", "4.1.311.2", DependencyType.Unknown),
|
256
|
+
new Dependency("System.Core", "3.5.21022.801", DependencyType.Unknown),
|
257
|
+
new Dependency("Moq", "4.16.1", DependencyType.Unknown),
|
258
|
+
new Dependency("Castle.Core", "4.4.1", DependencyType.Unknown),
|
259
|
+
new Dependency("MSTest.TestAdapter", "2.1.0", DependencyType.Unknown),
|
260
|
+
new Dependency("MSTest.TestFramework", "2.1.0", DependencyType.Unknown),
|
261
|
+
new Dependency("Microsoft.ApplicationInsights", "2.10.0", DependencyType.Unknown),
|
262
|
+
new Dependency("Microsoft.ApplicationInsights.Agent.Intercept", "2.4.0", DependencyType.Unknown),
|
263
|
+
new Dependency("Microsoft.ApplicationInsights.DependencyCollector", "2.10.0", DependencyType.Unknown),
|
264
|
+
new Dependency("Microsoft.ApplicationInsights.PerfCounterCollector", "2.10.0", DependencyType.Unknown),
|
265
|
+
new Dependency("Microsoft.ApplicationInsights.Web", "2.10.0", DependencyType.Unknown),
|
266
|
+
new Dependency("Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel", "2.10.0", DependencyType.Unknown),
|
267
|
+
new Dependency("Microsoft.ApplicationInsights.WindowsServer", "2.10.0", DependencyType.Unknown),
|
268
|
+
new Dependency("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
|
269
|
+
new Dependency("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
270
|
+
};
|
271
|
+
var actualDependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", packages);
|
272
|
+
for(int i = 0; i < actualDependencies.Length; i++)
|
273
|
+
{
|
274
|
+
var ad = actualDependencies[i];
|
275
|
+
var ed = expectedDependencies[i];
|
276
|
+
Assert.Equal(ed, ad);
|
277
|
+
}
|
278
|
+
Assert.Equal(expectedDependencies, actualDependencies);
|
279
|
+
}
|
280
|
+
|
281
|
+
[Fact]
|
282
|
+
public async Task AllPackageDependencies_DoNotIncludeUpdateOnlyPackages()
|
283
|
+
{
|
284
|
+
using var temp = new TemporaryDirectory();
|
285
|
+
var expectedDependencies = new Dependency[]
|
286
|
+
{
|
287
|
+
new("Microsoft.Bcl.AsyncInterfaces", "7.0.0", DependencyType.Unknown),
|
288
|
+
new("Microsoft.Extensions.DependencyInjection", "7.0.0", DependencyType.Unknown),
|
289
|
+
new("Microsoft.Extensions.DependencyInjection.Abstractions", "7.0.0", DependencyType.Unknown),
|
290
|
+
new("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
|
291
|
+
new("Microsoft.Extensions.Logging", "7.0.0", DependencyType.Unknown),
|
292
|
+
new("Microsoft.Extensions.Logging.Abstractions", "7.0.0", DependencyType.Unknown),
|
293
|
+
new("Microsoft.Extensions.Options", "7.0.0", DependencyType.Unknown),
|
294
|
+
new("Microsoft.Extensions.Primitives", "7.0.0", DependencyType.Unknown),
|
295
|
+
new("System.Buffers", "4.5.1", DependencyType.Unknown),
|
296
|
+
new("System.ComponentModel.Annotations", "5.0.0", DependencyType.Unknown),
|
297
|
+
new("System.Diagnostics.DiagnosticSource", "7.0.0", DependencyType.Unknown),
|
298
|
+
new("System.Memory", "4.5.5", DependencyType.Unknown),
|
299
|
+
new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
|
300
|
+
new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
|
301
|
+
new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
|
302
|
+
new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
|
303
|
+
};
|
304
|
+
var packages = new[] {
|
305
|
+
new Dependency("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
|
306
|
+
new Dependency("Newtonsoft.Json", "12.0.1", DependencyType.Unknown, IsUpdate: true)
|
307
|
+
};
|
308
|
+
var actualDependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", packages);
|
309
|
+
Assert.Equal(expectedDependencies, actualDependencies);
|
310
|
+
}
|
311
|
+
|
174
312
|
[Fact]
|
175
313
|
public async Task AllPackageDependenciesCanBeFoundWithNuGetConfig()
|
176
314
|
{
|
@@ -349,6 +487,72 @@ public class MSBuildHelperTests
|
|
349
487
|
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
350
488
|
}
|
351
489
|
};
|
490
|
+
|
491
|
+
// version is set in one file, used in another
|
492
|
+
yield return new object[]
|
493
|
+
{
|
494
|
+
// build file contents
|
495
|
+
new[]
|
496
|
+
{
|
497
|
+
("Packages.props", """
|
498
|
+
<Project>
|
499
|
+
<ItemGroup>
|
500
|
+
<PackageReference Update="Azure.Identity" Version="1.6.0" />
|
501
|
+
<PackageReference Update="Microsoft.Data.SqlClient" Version="5.1.4" />
|
502
|
+
</ItemGroup>
|
503
|
+
</Project>
|
504
|
+
"""),
|
505
|
+
("project.csproj", """
|
506
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
507
|
+
<PropertyGroup>
|
508
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
509
|
+
</PropertyGroup>
|
510
|
+
<ItemGroup>
|
511
|
+
<PackageReference Include="Azure.Identity" Version="1.6.1" />
|
512
|
+
</ItemGroup>
|
513
|
+
</Project>
|
514
|
+
""")
|
515
|
+
},
|
516
|
+
// expected dependencies
|
517
|
+
new Dependency[]
|
518
|
+
{
|
519
|
+
new("Azure.Identity", "1.6.0", DependencyType.Unknown),
|
520
|
+
new("Microsoft.Data.SqlClient", "5.1.4", DependencyType.Unknown, IsUpdate: true)
|
521
|
+
}
|
522
|
+
};
|
523
|
+
|
524
|
+
// version is set in one file, used in another
|
525
|
+
yield return new object[]
|
526
|
+
{
|
527
|
+
// build file contents
|
528
|
+
new[]
|
529
|
+
{
|
530
|
+
("project.csproj", """
|
531
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
532
|
+
<PropertyGroup>
|
533
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
534
|
+
</PropertyGroup>
|
535
|
+
<ItemGroup>
|
536
|
+
<PackageReference Include="Azure.Identity" />
|
537
|
+
</ItemGroup>
|
538
|
+
</Project>
|
539
|
+
"""),
|
540
|
+
("Packages.props", """
|
541
|
+
<Project>
|
542
|
+
<ItemGroup>
|
543
|
+
<PackageReference Update="Azure.Identity" Version="1.6.0" />
|
544
|
+
<PackageReference Update="Microsoft.Data.SqlClient" Version="5.1.4" />
|
545
|
+
</ItemGroup>
|
546
|
+
</Project>
|
547
|
+
""")
|
548
|
+
},
|
549
|
+
// expected dependencies
|
550
|
+
new Dependency[]
|
551
|
+
{
|
552
|
+
new("Azure.Identity", "1.6.0", DependencyType.Unknown),
|
553
|
+
new("Microsoft.Data.SqlClient", "5.1.4", DependencyType.Unknown, IsUpdate: true)
|
554
|
+
}
|
555
|
+
};
|
352
556
|
}
|
353
557
|
|
354
558
|
public static IEnumerable<object[]> SolutionProjectPathTestData()
|
@@ -187,6 +187,69 @@ public class SdkPackageUpdaterTests
|
|
187
187
|
"Newtonsoft.Json", "12.0.1", "13.0.1", false // isTransitive
|
188
188
|
};
|
189
189
|
|
190
|
+
// Make sure we don't update if there are incoherent versions
|
191
|
+
yield return new object[] {
|
192
|
+
new []
|
193
|
+
{
|
194
|
+
(Path: "src/Project.csproj", Content: """
|
195
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
196
|
+
<PropertyGroup>
|
197
|
+
<TargetFramework>netcoreapp2.1</TargetFramework>
|
198
|
+
</PropertyGroup>
|
199
|
+
<ItemGroup>
|
200
|
+
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.2.0" />
|
201
|
+
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
|
202
|
+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
|
203
|
+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
|
204
|
+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
|
205
|
+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
|
206
|
+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.0" />
|
207
|
+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
|
208
|
+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
209
|
+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
|
210
|
+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" />
|
211
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.0" />
|
212
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="2.2.0" />
|
213
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.2.0" />
|
214
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
|
215
|
+
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
|
216
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
|
217
|
+
</ItemGroup>
|
218
|
+
</Project>
|
219
|
+
""")
|
220
|
+
}, // starting contents
|
221
|
+
new []
|
222
|
+
{
|
223
|
+
(Path: "src/Project.csproj", Content: """
|
224
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
225
|
+
<PropertyGroup>
|
226
|
+
<TargetFramework>netcoreapp2.1</TargetFramework>
|
227
|
+
</PropertyGroup>
|
228
|
+
<ItemGroup>
|
229
|
+
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.2.0" />
|
230
|
+
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
|
231
|
+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
|
232
|
+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
|
233
|
+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
|
234
|
+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
|
235
|
+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.0" />
|
236
|
+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
|
237
|
+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
238
|
+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
|
239
|
+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" />
|
240
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.0" />
|
241
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="2.2.0" />
|
242
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.2.0" />
|
243
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
|
244
|
+
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0" />
|
245
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
|
246
|
+
</ItemGroup>
|
247
|
+
</Project>
|
248
|
+
""")
|
249
|
+
}, // expected contents
|
250
|
+
"Microsoft.EntityFrameworkCore.SqlServer", "2.1.0", "2.2.0", false // isTransitive
|
251
|
+
};
|
252
|
+
|
190
253
|
// PackageReference with Version as child element
|
191
254
|
yield return new object[]
|
192
255
|
{
|
@@ -72,7 +72,9 @@ module Dependabot
|
|
72
72
|
project_files += fsproj_file
|
73
73
|
project_files += sln_project_files
|
74
74
|
project_files += proj_files
|
75
|
-
project_files += project_files.filter_map
|
75
|
+
project_files += project_files.filter_map do |f|
|
76
|
+
named_file_up_tree_from_project_file(f, "Directory.Packages.props")
|
77
|
+
end
|
76
78
|
project_files
|
77
79
|
end
|
78
80
|
rescue Octokit::NotFound, Gitlab::Error::NotFound
|
@@ -191,28 +193,6 @@ module Dependabot
|
|
191
193
|
@proj_files ||= find_and_fetch_with_suffix(".proj")
|
192
194
|
end
|
193
195
|
|
194
|
-
def directory_packages_props_file_from_project_file(project_file)
|
195
|
-
# walk up the tree from each project file stopping at the first `Directory.Packages.props` file found
|
196
|
-
# https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management#central-package-management-rules
|
197
|
-
|
198
|
-
found_directory_packages_props_file = nil
|
199
|
-
directory_path = Pathname.new(directory)
|
200
|
-
full_project_dir = Pathname.new(project_file.directory).join(project_file.name).dirname
|
201
|
-
full_project_dir.ascend.each do |base|
|
202
|
-
break if found_directory_packages_props_file
|
203
|
-
|
204
|
-
candidate_file_path = Pathname.new(base).join("Directory.Packages.props").cleanpath.to_path
|
205
|
-
candidate_directory = Pathname.new(File.dirname(candidate_file_path))
|
206
|
-
relative_candidate_directory = candidate_directory.relative_path_from(directory_path)
|
207
|
-
candidate_file = repo_contents(dir: relative_candidate_directory).find do |f|
|
208
|
-
f.name.casecmp?("Directory.Packages.props")
|
209
|
-
end
|
210
|
-
found_directory_packages_props_file = fetch_file_from_host(candidate_file.name) if candidate_file
|
211
|
-
end
|
212
|
-
|
213
|
-
found_directory_packages_props_file
|
214
|
-
end
|
215
|
-
|
216
196
|
def find_and_fetch_with_suffix(suffix)
|
217
197
|
repo_contents.select { |f| f.name.end_with?(suffix) }.map { |f| fetch_file_from_host(f.name) }
|
218
198
|
end
|
@@ -293,47 +293,8 @@ module Dependabot
|
|
293
293
|
end
|
294
294
|
|
295
295
|
def dependency_url_has_matching_result?(dependency_name, dependency_url)
|
296
|
-
|
297
|
-
|
298
|
-
dependency_url_has_matching_result_v3?(dependency_name, dependency_url)
|
299
|
-
elsif repository_type == "v2"
|
300
|
-
dependency_url_has_matching_result_v2?(dependency_name, dependency_url)
|
301
|
-
else
|
302
|
-
raise "Unknown repository type: #{repository_type}"
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
def dependency_url_has_matching_result_v3?(dependency_name, dependency_url)
|
307
|
-
versions = NugetClient.get_package_versions_v3(dependency_name, dependency_url)
|
308
|
-
|
309
|
-
versions != nil
|
310
|
-
end
|
311
|
-
|
312
|
-
def dependency_url_has_matching_result_v2?(dependency_name, dependency_url)
|
313
|
-
url = dependency_url.fetch(:versions_url)
|
314
|
-
auth_header = dependency_url.fetch(:auth_header)
|
315
|
-
response = execute_search_for_dependency_url(url, auth_header)
|
316
|
-
return false unless response.status == 200
|
317
|
-
|
318
|
-
doc = Nokogiri::XML(response.body)
|
319
|
-
doc.remove_namespaces!
|
320
|
-
id_nodes = doc.xpath("/feed/entry/properties/Id")
|
321
|
-
found_matching_result = id_nodes.any? do |id_node|
|
322
|
-
return false unless id_node.text
|
323
|
-
|
324
|
-
id_node.text.casecmp?(dependency_name)
|
325
|
-
end
|
326
|
-
found_matching_result
|
327
|
-
end
|
328
|
-
|
329
|
-
def execute_search_for_dependency_url(url, auth_header)
|
330
|
-
cache = ProjectFileParser.dependency_url_search_cache
|
331
|
-
cache[url] ||= Dependabot::RegistryClient.get(
|
332
|
-
url: url,
|
333
|
-
headers: auth_header
|
334
|
-
)
|
335
|
-
|
336
|
-
cache[url]
|
296
|
+
versions = NugetClient.get_package_versions(dependency_name, dependency_url)
|
297
|
+
versions&.any?
|
337
298
|
end
|
338
299
|
|
339
300
|
def dependency_name(dependency_node, project_file)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "nokogiri"
|
@@ -85,7 +85,7 @@ module Dependabot
|
|
85
85
|
|
86
86
|
def packages_config_files
|
87
87
|
dependency_files.select do |f|
|
88
|
-
f.name.split("/").last
|
88
|
+
f.name.split("/").last&.casecmp("packages.config")&.zero?
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -103,11 +103,11 @@ module Dependabot
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def global_json
|
106
|
-
dependency_files.find { |f| f.name.casecmp("global.json")
|
106
|
+
dependency_files.find { |f| f.name.casecmp("global.json")&.zero? }
|
107
107
|
end
|
108
108
|
|
109
109
|
def dotnet_tools_json
|
110
|
-
dependency_files.find { |f| f.name.casecmp(".config/dotnet-tools.json")
|
110
|
+
dependency_files.find { |f| f.name.casecmp(".config/dotnet-tools.json")&.zero? }
|
111
111
|
end
|
112
112
|
|
113
113
|
def check_required_files
|
@@ -7,7 +7,18 @@ require "dependabot/nuget/update_checker/repository_finder"
|
|
7
7
|
module Dependabot
|
8
8
|
module Nuget
|
9
9
|
class NugetClient
|
10
|
-
def self.
|
10
|
+
def self.get_package_versions(dependency_name, repository_details)
|
11
|
+
repository_type = repository_details.fetch(:repository_type)
|
12
|
+
if repository_type == "v3"
|
13
|
+
get_package_versions_v3(dependency_name, repository_details)
|
14
|
+
elsif repository_type == "v2"
|
15
|
+
get_package_versions_v2(dependency_name, repository_details)
|
16
|
+
else
|
17
|
+
raise "Unknown repository type: #{repository_type}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private_class_method def self.get_package_versions_v3(dependency_name, repository_details)
|
11
22
|
# Use the registration URL if possible because it is fast and correct
|
12
23
|
if repository_details[:registration_url]
|
13
24
|
get_versions_from_registration_v3(repository_details)
|
@@ -20,14 +31,32 @@ module Dependabot
|
|
20
31
|
end
|
21
32
|
end
|
22
33
|
|
34
|
+
private_class_method def self.get_package_versions_v2(dependency_name, repository_details)
|
35
|
+
doc = execute_xml_nuget_request(repository_details.fetch(:versions_url), repository_details)
|
36
|
+
return unless doc
|
37
|
+
|
38
|
+
id_nodes = doc.xpath("/feed/entry/properties/Id")
|
39
|
+
matching_versions = Set.new
|
40
|
+
id_nodes.each do |id_node|
|
41
|
+
return nil unless id_node.text
|
42
|
+
|
43
|
+
next unless id_node.text.casecmp?(dependency_name)
|
44
|
+
|
45
|
+
version_node = id_node.parent.xpath("Version")
|
46
|
+
matching_versions << version_node.text if version_node && version_node.text
|
47
|
+
end
|
48
|
+
|
49
|
+
matching_versions
|
50
|
+
end
|
51
|
+
|
23
52
|
private_class_method def self.get_versions_from_versions_url_v3(repository_details)
|
24
|
-
body =
|
53
|
+
body = execute_json_nuget_request(repository_details[:versions_url], repository_details)
|
25
54
|
body&.fetch("versions")
|
26
55
|
end
|
27
56
|
|
28
57
|
private_class_method def self.get_versions_from_registration_v3(repository_details)
|
29
58
|
url = repository_details[:registration_url]
|
30
|
-
body =
|
59
|
+
body = execute_json_nuget_request(url, repository_details)
|
31
60
|
|
32
61
|
return unless body
|
33
62
|
|
@@ -47,7 +76,7 @@ module Dependabot
|
|
47
76
|
else
|
48
77
|
# paged entries
|
49
78
|
page_url = page["@id"]
|
50
|
-
page_body =
|
79
|
+
page_body = execute_json_nuget_request(page_url, repository_details)
|
51
80
|
items = page_body.fetch("items")
|
52
81
|
items.each do |item|
|
53
82
|
catalog_entry = item.fetch("catalogEntry")
|
@@ -61,7 +90,7 @@ module Dependabot
|
|
61
90
|
|
62
91
|
private_class_method def self.get_versions_from_search_url_v3(repository_details, dependency_name)
|
63
92
|
search_url = repository_details[:search_url]
|
64
|
-
body =
|
93
|
+
body = execute_json_nuget_request(search_url, repository_details)
|
65
94
|
|
66
95
|
body&.fetch("data")
|
67
96
|
&.find { |d| d.fetch("id").casecmp(dependency_name.downcase).zero? }
|
@@ -69,21 +98,55 @@ module Dependabot
|
|
69
98
|
&.map { |d| d.fetch("version") }
|
70
99
|
end
|
71
100
|
|
72
|
-
private_class_method def self.
|
73
|
-
|
74
|
-
cache[url] ||= Dependabot::RegistryClient.get(
|
101
|
+
private_class_method def self.execute_xml_nuget_request(url, repository_details)
|
102
|
+
response = execute_nuget_request_internal(
|
75
103
|
url: url,
|
76
|
-
|
104
|
+
auth_header: repository_details[:auth_header],
|
105
|
+
repository_url: repository_details[:repository_url]
|
77
106
|
)
|
107
|
+
return unless response.status == 200
|
78
108
|
|
79
|
-
|
109
|
+
doc = Nokogiri::XML(response.body)
|
110
|
+
doc.remove_namespaces!
|
111
|
+
doc
|
112
|
+
end
|
80
113
|
|
114
|
+
private_class_method def self.execute_json_nuget_request(url, repository_details)
|
115
|
+
response = execute_nuget_request_internal(
|
116
|
+
url: url,
|
117
|
+
auth_header: repository_details[:auth_header],
|
118
|
+
repository_url: repository_details[:repository_url]
|
119
|
+
)
|
81
120
|
return unless response.status == 200
|
82
121
|
|
83
122
|
body = remove_wrapping_zero_width_chars(response.body)
|
84
123
|
JSON.parse(body)
|
124
|
+
end
|
125
|
+
|
126
|
+
private_class_method def self.execute_nuget_request_internal(
|
127
|
+
url: String,
|
128
|
+
auth_header: String,
|
129
|
+
repository_url: String
|
130
|
+
)
|
131
|
+
cache = CacheManager.cache("dependency_url_search_cache")
|
132
|
+
if cache[url].nil?
|
133
|
+
response = Dependabot::RegistryClient.get(
|
134
|
+
url: url,
|
135
|
+
headers: auth_header
|
136
|
+
)
|
137
|
+
|
138
|
+
if [401, 402, 403].include?(response.status)
|
139
|
+
raise Dependabot::PrivateSourceAuthenticationFailure, repository_url
|
140
|
+
end
|
141
|
+
|
142
|
+
cache[url] = response if !CacheManager.caching_disabled? && response.status == 200
|
143
|
+
else
|
144
|
+
response = cache[url]
|
145
|
+
end
|
146
|
+
|
147
|
+
response
|
85
148
|
rescue Excon::Error::Timeout, Excon::Error::Socket
|
86
|
-
repo_url =
|
149
|
+
repo_url = repository_url
|
87
150
|
raise if repo_url == Dependabot::Nuget::UpdateChecker::RepositoryFinder::DEFAULT_REPOSITORY_URL
|
88
151
|
|
89
152
|
raise PrivateSourceTimedOut, repo_url
|
@@ -235,7 +235,7 @@ module Dependabot
|
|
235
235
|
dependency_urls
|
236
236
|
.select { |details| details.fetch(:repository_type) == "v3" }
|
237
237
|
.filter_map do |url_details|
|
238
|
-
versions =
|
238
|
+
versions = NugetClient.get_package_versions(dependency.name, url_details)
|
239
239
|
next unless versions
|
240
240
|
|
241
241
|
{ "versions" => versions, "listing_details" => url_details }
|
@@ -294,10 +294,6 @@ module Dependabot
|
|
294
294
|
nil
|
295
295
|
end
|
296
296
|
|
297
|
-
def versions_for_v3_repository(repository_details)
|
298
|
-
NugetClient.get_package_versions_v3(dependency.name, repository_details)
|
299
|
-
end
|
300
|
-
|
301
297
|
def dependency_urls
|
302
298
|
@dependency_urls ||=
|
303
299
|
RepositoryFinder.new(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependabot-nuget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.242.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dependabot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dependabot-common
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.242.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.242.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubyzip
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -369,7 +369,7 @@ licenses:
|
|
369
369
|
- Nonstandard
|
370
370
|
metadata:
|
371
371
|
bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
|
372
|
-
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.
|
372
|
+
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.242.1
|
373
373
|
post_install_message:
|
374
374
|
rdoc_options: []
|
375
375
|
require_paths:
|