Skip to content

Commit 80bec5a

Browse files
committed
Anonymize diagnostics information
1 parent 1840339 commit 80bec5a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/nugraph/GraphCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ protected override async Task<int> ExecuteAsync(CommandContext commandContext, G
7575

7676
private static async Task<int> DiagnoseAsync(TextWriter stdOut, DirectoryInfo? sdk, CancellationToken cancellationToken)
7777
{
78+
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
79+
var userProfileReplacement = OperatingSystem.IsWindows() ? "%UserProfile%" : "~";
80+
7881
await stdOut.WriteLineAsync("nugraph:");
7982
await stdOut.WriteLineAsync($" Version: {typeof(Program).Assembly.GetVersion()}");
8083
await stdOut.WriteLineAsync($" Runtime: {Environment.Version}");
81-
await stdOut.WriteLineAsync($" SDK: {DotnetSdk.Register(sdk)}");
84+
await stdOut.WriteLineAsync($" SDK: {DotnetSdk.Register(sdk)?.Replace(userProfile, userProfileReplacement)}");
8285
await stdOut.WriteLineAsync();
8386

8487
await stdOut.WriteLineAsync("attributes:");
@@ -91,11 +94,11 @@ private static async Task<int> DiagnoseAsync(TextWriter stdOut, DirectoryInfo? s
9194
await stdOut.WriteLineAsync("assemblies:");
9295
foreach (var assembly in typeof(Program).Assembly.LoadReferencedAssemblies().OrderBy(a => a.GetName().Name))
9396
{
94-
await stdOut.WriteLineAsync($" {assembly}: {assembly.Location}");
97+
await stdOut.WriteLineAsync($" {assembly}: {assembly.Location.Replace(userProfile, userProfileReplacement)}");
9598
}
9699
await stdOut.WriteLineAsync();
97100

98-
var dotnetInfo = Cli.Wrap("dotnet").WithArguments("--info").WithStandardOutputPipe(PipeTarget.ToDelegate(stdOut.WriteLine));
101+
var dotnetInfo = Cli.Wrap("dotnet").WithArguments("--info").WithStandardOutputPipe(PipeTarget.ToDelegate(line => stdOut.WriteLine(line.Replace(userProfile, userProfileReplacement))));
99102
var result = await dotnetInfo.ExecuteAsync(cancellationToken);
100103
return result.ExitCode;
101104
}

tests/nugraph.Tests/NugraphTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System;
12
using System.IO;
23
using System.Threading.Tasks;
4+
using AwesomeAssertions;
5+
using AwesomeAssertions.Execution;
36
using NuGet.Common;
47

58
namespace nugraph.Tests;
@@ -19,7 +22,11 @@ public async Task Diagnose()
1922

2023
await File.WriteAllTextAsync($"{nugraph.GetType().Name}.diagnostics.txt", result.StdOut);
2124

22-
result.Should().Match(stdOutPattern: "nugraph:*");
25+
using (new AssertionScope())
26+
{
27+
result.Should().Match(stdOutPattern: "nugraph:*");
28+
result.StdOut.Should().NotContain(Path.DirectorySeparatorChar + Environment.UserName + Path.DirectorySeparatorChar);
29+
}
2330
}
2431

2532
[Test]

0 commit comments

Comments
 (0)