Skip to content
Merged
Show file tree
Hide file tree
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 Jul 21, 2026
f49d7e6
Address code review findings in WebSocket transport
Evangelink Jul 21, 2026
554fb6b
Fix independent review findings: secret leak in diagnostics, browser …
Evangelink Jul 21, 2026
d677f4c
Add regression test for zero-length WebSocket message before reply
Evangelink Jul 21, 2026
b848bee
Address WebSocket transport review feedback
Evangelink Jul 22, 2026
df9cf13
Address follow-up WebSocket review feedback
Evangelink Jul 22, 2026
53e8877
Address WebSocket zero-read and redaction feedback
Evangelink Jul 22, 2026
7f28661
Tighten WebSocket endpoint validation and diagnostics
Evangelink Jul 22, 2026
16b5994
Enable WebSocket API for browser-wasm tests on Node 20
Evangelink Jul 22, 2026
ba5a006
Merge origin/main into WebSocket transport branch
Evangelink Jul 22, 2026
0aa68b4
Document WebSocket endpoint user-info restriction
Evangelink Jul 22, 2026
9fe82da
Complete protocol version docs and endpoint redaction
Evangelink Jul 22, 2026
b2b0390
Reject ignored dotnettestcli transport options
Evangelink Jul 22, 2026
120e429
Redact extra inline secret option values
Evangelink Jul 22, 2026
f70247b
Merge origin/main into WebSocket transport branch
Evangelink Jul 22, 2026
1f46c69
Reject WebSocket endpoints without a host
Evangelink Jul 22, 2026
4bbf43c
Cancel pending browser WebSocket opens
Evangelink Jul 22, 2026
81bb8a2
Redact secrets from command-line validation errors
Evangelink Jul 22, 2026
a5c1ea1
Redact response-file secrets from validation errors
Evangelink Jul 22, 2026
74020a0
Preserve whitespace validation diagnostics
Evangelink Jul 22, 2026
9fad339
Redact normalized token values in parser errors
Evangelink Jul 22, 2026
a74e7ff
Constrain validation error redaction to argument tokens
Evangelink Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 178 additions & 9 deletions docs/mstest-runner-protocol/004-protocol-dotnet-test-pipe.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteExecutionS
static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteListPayload<T>(System.IO.Stream! stream, ushort fieldId, T[]? list, System.Action<System.IO.Stream!, T>! writeItem) -> void
const Microsoft.Testing.Platform.IPC.FailedTestResultMessageFieldsId.Expected = 10 -> ushort
const Microsoft.Testing.Platform.IPC.FailedTestResultMessageFieldsId.Actual = 11 -> ushort
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Stream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Stream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Comment thread
Evangelink marked this conversation as resolved.
Resolved
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Pipes.PipeStream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Pipes.PipeStream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteExecutionS
static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteListPayload<T>(System.IO.Stream! stream, ushort fieldId, T[]? list, System.Action<System.IO.Stream!, T>! writeItem) -> void
const Microsoft.Testing.Platform.IPC.FailedTestResultMessageFieldsId.Expected = 10 -> ushort
const Microsoft.Testing.Platform.IPC.FailedTestResultMessageFieldsId.Actual = 11 -> ushort
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Stream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Stream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Comment thread
Evangelink marked this conversation as resolved.
Resolved
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Pipes.PipeStream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Pipes.PipeStream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteExecutionS
static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteListPayload<T>(System.IO.Stream! stream, ushort fieldId, T[]? list, System.Action<System.IO.Stream!, T>! writeItem) -> void
const Microsoft.Testing.Platform.IPC.FailedTestResultMessageFieldsId.Expected = 10 -> ushort
const Microsoft.Testing.Platform.IPC.FailedTestResultMessageFieldsId.Actual = 11 -> ushort
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Stream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Stream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Comment thread
Evangelink marked this conversation as resolved.
Resolved
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Pipes.PipeStream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Pipes.PipeStream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ Microsoft.Testing.Extensions.MergeOutputFileHelper
static Microsoft.Testing.Extensions.MergeOutputFileHelper.BuildCaseFoldedProbePath(string! directory, string! probeFileName) -> string!
static Microsoft.Testing.Extensions.MergeOutputFileHelper.EnsureOutputDoesNotAliasInput(System.Collections.Generic.IReadOnlyList<string!>! inputPaths, string! outputPath) -> void
static Microsoft.Testing.Extensions.MergeOutputFileHelper.WriteViaTemporarySiblingAsync(string! outputPath, System.Func<string!, System.Threading.Tasks.Task!>! writeToTempAsync) -> System.Threading.Tasks.Task!
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Stream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Stream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Comment thread
Evangelink marked this conversation as resolved.
Resolved
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.ReadNextMessageAsync(System.IO.Pipes.PipeStream! stream, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<object?>!
*REMOVED*Microsoft.Testing.Platform.IPC.NamedPipeConnectionBase.WriteMessageAsync(System.IO.Pipes.PipeStream! stream, Microsoft.Testing.Platform.IPC.INamedPipeSerializer! serializer, object! message, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static async Task LogInformationAsync(

string moduleName = testApplicationModuleInfo.GetDisplayName();
await logger.LogInformationAsync($"Test module: {moduleName}").ConfigureAwait(false);
await logger.LogInformationAsync($"Command line arguments: '{(args.Length == 0 ? string.Empty : args.Aggregate((a, b) => $"{a} {b}"))}'").ConfigureAwait(false);
await logger.LogInformationAsync($"Command line arguments: '{CommandLineArgumentsRedactor.Redact(args)}'").ConfigureAwait(false);
Comment thread
Evangelink marked this conversation as resolved.
Resolved

StringBuilder machineInfo = new();
#pragma warning disable RS0030 // Do not use banned APIs
Expand Down
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,
];
Comment thread
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);
Comment thread
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));
}
Loading
Loading