Repository navigation
Add WebSocket transport for the dotnettestcli protocol (browser-wasm support) #10118
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
Amaury Levé (Evangelink)
merged 22 commits into
main
from
dev/amauryleve/mtp-transport-neutral-dotnettestcli
Jul 22, 2026
Merged
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6472e52
Add WebSocket transport for the dotnettestcli protocol (browser-wasm …
Evangelink f49d7e6
Address code review findings in WebSocket transport
Evangelink 554fb6b
Fix independent review findings: secret leak in diagnostics, browser …
Evangelink d677f4c
Add regression test for zero-length WebSocket message before reply
Evangelink b848bee
Address WebSocket transport review feedback
Evangelink df9cf13
Address follow-up WebSocket review feedback
Evangelink 53e8877
Address WebSocket zero-read and redaction feedback
Evangelink 7f28661
Tighten WebSocket endpoint validation and diagnostics
Evangelink 16b5994
Enable WebSocket API for browser-wasm tests on Node 20
Evangelink ba5a006
Merge origin/main into WebSocket transport branch
Evangelink 0aa68b4
Document WebSocket endpoint user-info restriction
Evangelink 9fe82da
Complete protocol version docs and endpoint redaction
Evangelink b2b0390
Reject ignored dotnettestcli transport options
Evangelink 120e429
Redact extra inline secret option values
Evangelink f70247b
Merge origin/main into WebSocket transport branch
Evangelink 1f46c69
Reject WebSocket endpoints without a host
Evangelink 4bbf43c
Cancel pending browser WebSocket opens
Evangelink 81bb8a2
Redact secrets from command-line validation errors
Evangelink a5c1ea1
Redact response-file secrets from validation errors
Evangelink 74020a0
Preserve whitespace validation diagnostics
Evangelink 9fad339
Redact normalized token values in parser errors
Evangelink a74e7ff
Constrain validation error redaction to argument tokens
Evangelink 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
187 changes: 178 additions & 9 deletions
187
docs/mstest-runner-protocol/004-protocol-dotnet-test-pipe.md
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
125 changes: 125 additions & 0 deletions
125
src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineArgumentsRedactor.cs
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,125 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Microsoft.Testing.Platform.CommandLine; | ||
|
|
||
| /// <summary> | ||
| /// Formats raw command-line arguments for diagnostics (e.g. the "Command line arguments" line written to the | ||
| /// <c>--diagnostic</c> log) while masking the value(s) of options that carry secrets, so enabling verbose | ||
| /// diagnostics never writes a secret to disk. See | ||
| /// <c>docs/mstest-runner-protocol/004-protocol-dotnet-test-pipe.md</c> §15.4: the | ||
| /// <c>--dotnet-test-websocket-token</c> value is a per-run authentication secret and must never be logged. | ||
| /// </summary> | ||
| internal static class CommandLineArgumentsRedactor | ||
| { | ||
| private const string RedactedPlaceholder = "***REDACTED***"; | ||
|
|
||
| // Option names (without leading dashes) whose argument value(s) must never appear in diagnostics output. | ||
| // Extend this set - not the call site - whenever a new option is introduced that carries a secret. | ||
| private static readonly string[] SensitiveOptionNames = | ||
| [ | ||
| PlatformCommandLineProvider.DotNetTestWebSocketTokenOptionKey, | ||
| ]; | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
|
|
||
| /// <summary> | ||
| /// Formats <paramref name="args"/> as a single space-separated string suitable for diagnostics, replacing | ||
| /// the value(s) of any option in <see cref="SensitiveOptionNames"/> with a fixed placeholder. Every other | ||
| /// argument - including the sensitive option's own name/prefix/delimiter - is preserved exactly, so the | ||
| /// output otherwise remains as useful for troubleshooting as the raw command line. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Mirrors <see cref="CommandLineParser"/>'s own option-detection rule (a token starting with a single '-' | ||
| /// followed by a non-'-' character, or '--' followed by a non-'-' character, optionally with an inline | ||
| /// '='/':' delimited value) so this stays in sync with how the real parser identifies option boundaries. | ||
| /// Handles a missing value (the sensitive option is the last argument - nothing follows to redact, no | ||
| /// out-of-range access) and a repeated option (each occurrence's value(s) are independently redacted). | ||
| /// </remarks> | ||
| public static string Redact(string[] args) | ||
| { | ||
| if (args.Length == 0) | ||
| { | ||
| return string.Empty; | ||
| } | ||
|
|
||
| string[] redacted = new string[args.Length]; | ||
| bool redactingValuesForCurrentOption = false; | ||
| bool redactedValueForCurrentOption = false; | ||
|
|
||
| for (int i = 0; i < args.Length; i++) | ||
| { | ||
| string arg = args[i]; | ||
|
|
||
| if (TryParseOption(arg, out string? prefix, out string? optionName, out string? delimiter, out string? inlineValue)) | ||
| { | ||
| bool isSensitive = IsSensitiveOptionName(optionName); | ||
|
Evangelink marked this conversation as resolved.
Resolved
|
||
| if (redactingValuesForCurrentOption && !redactedValueForCurrentOption && !isSensitive) | ||
| { | ||
| // An opaque secret may itself look like an option (for example "-secret"). Diagnostic | ||
| // logging happens before arity validation, so mask this token rather than leaking it. | ||
| redacted[i] = RedactedPlaceholder; | ||
| redactingValuesForCurrentOption = false; | ||
| redactedValueForCurrentOption = true; | ||
| continue; | ||
| } | ||
|
|
||
| if (isSensitive && inlineValue is not null) | ||
| { | ||
| // Inline form, e.g. '--dotnet-test-websocket-token=<secret>': redact just the value, | ||
| // preserving the original prefix/name/delimiter exactly. | ||
| redacted[i] = $"{prefix}{optionName}{delimiter}{RedactedPlaceholder}"; | ||
| redactingValuesForCurrentOption = false; | ||
| redactedValueForCurrentOption = true; | ||
| } | ||
| else | ||
| { | ||
| // Bare option name (no inline value): keep it as-is. If it is sensitive, its value(s) are | ||
| // one or more separate following tokens - redact those below until the next option. | ||
| redacted[i] = arg; | ||
| redactingValuesForCurrentOption = isSensitive; | ||
| redactedValueForCurrentOption = false; | ||
| } | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| // Not an option-looking token: it's an argument value for whichever option preceded it. | ||
| redacted[i] = redactingValuesForCurrentOption ? RedactedPlaceholder : arg; | ||
| redactedValueForCurrentOption |= redactingValuesForCurrentOption; | ||
| } | ||
|
|
||
| return string.Join(" ", redacted); | ||
| } | ||
|
|
||
| private static bool TryParseOption(string arg, [NotNullWhen(true)] out string? prefix, [NotNullWhen(true)] out string? optionName, out string? delimiter, out string? inlineValue) | ||
| { | ||
| prefix = null; | ||
| optionName = null; | ||
| delimiter = null; | ||
| inlineValue = null; | ||
|
|
||
| bool isDoubleDash = arg.Length > 2 && arg[0] == '-' && arg[1] == '-' && arg[2] != '-'; | ||
| bool isSingleDash = !isDoubleDash && arg.Length > 1 && arg[0] == '-' && arg[1] != '-'; | ||
| if (!isDoubleDash && !isSingleDash) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| prefix = isDoubleDash ? "--" : "-"; | ||
| string withoutPrefix = arg[prefix.Length..]; | ||
|
|
||
| int delimiterIndex = withoutPrefix.IndexOfAny(['=', ':']); | ||
| if (delimiterIndex == -1) | ||
| { | ||
| optionName = withoutPrefix; | ||
| return true; | ||
| } | ||
|
|
||
| optionName = withoutPrefix[..delimiterIndex]; | ||
| delimiter = withoutPrefix[delimiterIndex].ToString(); | ||
| inlineValue = withoutPrefix[(delimiterIndex + 1)..]; | ||
| return true; | ||
| } | ||
|
|
||
| private static bool IsSensitiveOptionName(string optionName) | ||
| => SensitiveOptionNames.Any(sensitive => sensitive.Equals(optionName, StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
Oops, something went wrong.
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.