-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Replace Newtonsoft.Json with System.Text.Json in dotnet-user-secrets #65686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MichaelSimons
merged 10 commits into
main
from
copilot/replace-newtonsoft-json-dependency
May 5, 2026
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
79c2b41
Initial plan
Copilot 57bd09a
Replace Newtonsoft.Json with System.Text.Json in dotnet-user-secrets …
Copilot 9811cd9
Extract shared JsonSerializerOptions to SecretsStore.SerializerOption…
Copilot 40f7f91
Merge branch 'main' into copilot/replace-newtonsoft-json-dependency
MichaelSimons 66f8e89
Remove UnsafeRelaxedJsonEscaping, use default STJ escaping for non-AS…
Copilot 59d29fe
Consolidate list command tests from SecretManagerTests into ListComma…
Copilot 8ba1aaa
Add List_Json_OptionIsWired integration test to cover --json CLI opti…
Copilot 084a745
Add List_Flattens_Nested_Objects integration test to cover SecretsSto…
Copilot 4ba58be
Apply suggestion from @Copilot
MichaelSimons 0c389c8
Merge branch 'main' into copilot/replace-newtonsoft-json-dependency
MichaelSimons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.Extensions.SecretManager.Tools.Internal; | ||
| using Microsoft.Extensions.Tools.Internal; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Extensions.SecretManager.Tools.Tests; | ||
|
|
||
| public class ListCommandTest | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public ListCommandTest(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void List_Json_OutputIsProperlyFormatted() | ||
| { | ||
| var secretStore = new TestSecretsStore(_output); | ||
| secretStore.Set("key1", "value1"); | ||
| var testConsole = new TestConsole(_output); | ||
| var reporter = new ConsoleReporter(testConsole); | ||
| var command = new ListCommand(jsonOutput: true); | ||
|
|
||
| command.Execute(new CommandContext(secretStore, reporter, testConsole)); | ||
|
|
||
|
MichaelSimons marked this conversation as resolved.
|
||
| var output = testConsole.GetOutput(); | ||
| var jsonContent = ExtractJsonContent(output); | ||
|
|
||
| Assert.Equal("{\n \"key1\": \"value1\"\n}", jsonContent, ignoreLineEndingDifferences: true); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void List_Json_EscapesNonAsciiCharacters() | ||
| { | ||
| var secretStore = new TestSecretsStore(_output); | ||
| secretStore.Set("AzureAd:ClientSecret", "abcd郩˙î"); | ||
| var testConsole = new TestConsole(_output); | ||
| var reporter = new ConsoleReporter(testConsole); | ||
| var command = new ListCommand(jsonOutput: true); | ||
|
|
||
| command.Execute(new CommandContext(secretStore, reporter, testConsole)); | ||
|
|
||
| var output = testConsole.GetOutput(); | ||
| var jsonContent = ExtractJsonContent(output); | ||
|
|
||
| // Non-ASCII characters are Unicode-escaped using the default System.Text.Json encoding | ||
| Assert.Equal("{\n \"AzureAd:ClientSecret\": \"abcd\\u00E9\\u0192\\u00A9\\u02D9\\u00EE\"\n}", jsonContent, ignoreLineEndingDifferences: true); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void List_Json_HasBeginAndEndMarkers() | ||
| { | ||
| var secretStore = new TestSecretsStore(_output); | ||
| secretStore.Set("key1", "value1"); | ||
| var testConsole = new TestConsole(_output); | ||
| var reporter = new ConsoleReporter(testConsole); | ||
| var command = new ListCommand(jsonOutput: true); | ||
|
|
||
| command.Execute(new CommandContext(secretStore, reporter, testConsole)); | ||
|
|
||
| var output = testConsole.GetOutput(); | ||
|
|
||
| Assert.Contains("//BEGIN", output); | ||
| Assert.Contains("//END", output); | ||
| var beginIndex = output.IndexOf("//BEGIN", StringComparison.Ordinal); | ||
| var endIndex = output.IndexOf("//END", StringComparison.Ordinal); | ||
| Assert.True(beginIndex < endIndex, "//BEGIN should appear before //END"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void List_NonJson_OutputIsProperlyFormatted() | ||
| { | ||
| var secretStore = new TestSecretsStore(_output); | ||
| secretStore.Set("key1", "value1"); | ||
| secretStore.Set("AzureAd:ClientSecret", "someSecret"); | ||
| var testConsole = new TestConsole(_output); | ||
| var reporter = new ConsoleReporter(testConsole); | ||
| var command = new ListCommand(jsonOutput: false); | ||
|
|
||
| command.Execute(new CommandContext(secretStore, reporter, testConsole)); | ||
|
|
||
| var output = testConsole.GetOutput(); | ||
| Assert.Contains("key1 = value1", output); | ||
| Assert.Contains("AzureAd:ClientSecret = someSecret", output); | ||
| } | ||
|
MichaelSimons marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public void List_NonJson_EmptyStore() | ||
| { | ||
| var secretStore = new TestSecretsStore(_output); | ||
| var testConsole = new TestConsole(_output); | ||
| var reporter = new ConsoleReporter(testConsole); | ||
| var command = new ListCommand(jsonOutput: false); | ||
|
|
||
| command.Execute(new CommandContext(secretStore, reporter, testConsole)); | ||
|
|
||
| Assert.Contains(Resources.Error_No_Secrets_Found, testConsole.GetOutput()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void List_Json_EmptyStore() | ||
| { | ||
| var secretStore = new TestSecretsStore(_output); | ||
| var testConsole = new TestConsole(_output); | ||
| var reporter = new ConsoleReporter(testConsole); | ||
| var command = new ListCommand(jsonOutput: true); | ||
|
|
||
| command.Execute(new CommandContext(secretStore, reporter, testConsole)); | ||
|
|
||
| var output = testConsole.GetOutput(); | ||
| var jsonContent = ExtractJsonContent(output); | ||
|
|
||
| Assert.Equal("{}", jsonContent, ignoreLineEndingDifferences: true); | ||
| } | ||
|
|
||
| private static string ExtractJsonContent(string output) | ||
| { | ||
| const string beginMarker = "//BEGIN"; | ||
| const string endMarker = "//END"; | ||
| var beginIndex = output.IndexOf(beginMarker, StringComparison.Ordinal) + beginMarker.Length; | ||
| var endIndex = output.IndexOf(endMarker, StringComparison.Ordinal); | ||
| return output[beginIndex..endIndex].Trim(); | ||
|
MichaelSimons marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| private sealed class TestSecretsStore : SecretsStore | ||
| { | ||
| public TestSecretsStore(ITestOutputHelper output) | ||
| : base("xyz", new TestReporter(output)) | ||
| { | ||
| } | ||
|
|
||
| protected override IDictionary<string, string> Load(string userSecretsId) | ||
| { | ||
| return new Dictionary<string, string>(); | ||
| } | ||
|
|
||
| public override void Save() | ||
| { | ||
| // noop | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.