Repository navigation
Require an execute bit before selecting a Unix apphost #10641
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 78 commits into
microsoft:main
from
nohwnd:nohwnd-restore-unix-execute-bit-guard-mtp-appho
Aug 26, 2026
Merged
Changes from 3 commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
7598bd3
Require an execute bit before selecting a Unix apphost
nohwnd 114e602
Merge remote-tracking branch 'origin/main' into nohwnd-restore-unix-e…
nohwnd 01d27ff
Fence the Unix apphost execute-bit check on NET7_0_OR_GREATER
nohwnd f122241
docs: fix typo refrence -> reference (#10672)
vaibhav8a 57204bd
Add DisposeHelper unit tests (#10649)
Evangelink 8393f40
[main] Bump Microsoft.CodeAnalysis.BannedApiAnalyzers from 5.10.0-1.2…
dependabot[bot] 39bf3c0
Reduce ServerMode notification allocations (#10670)
Evangelink e287fd7
Cache regex assertion patterns safely (#10661)
Evangelink 2538d01
Add StackTraceRegexHelper unit tests (#10655)
Evangelink 808198c
Optimize TRX reparse point confinement checks (#10648)
Evangelink d52effb
[main] Bump github/gh-aw/actions/setup from 0.86.0 to 0.86.2 (#10657)
dependabot[bot] 966e2a2
[main] Bump Azure.Core from 1.61.0 to 1.62.0 (#10663)
dependabot[bot] 396ebe4
Add report file retry helper tests (#10635)
Evangelink 71b22b5
Split AzureDevOpsSummaryReporter into focused modules (#10644)
Evangelink 456af5a
Update bundled Playwright for .NET to 1.62.0 (#10624)
nohwnd-bot 39a9175
[main] Bump DavidAnson/markdownlint-cli2-action from 24.1.0 to 24.2.0…
dependabot[bot] d499b22
[main] Update dependencies from devdiv/DevDiv/vs-code-coverage, dotne…
dotnet-maestro[bot] 77d47b4
Test MSTEST0001 adapter flag parsing (#10631)
Evangelink 6c7846a
Fix broken changelog comparison links (#10676)
Evangelink eb36b1e
Localized file check-in by OneLocBuild Task: Build definition ID 1218…
dotnet-oneloc-localization[bot] 0981e6d
Fix apphost DOTNET_ROOT path assertion (#10626)
nohwnd 2661467
Read acceptance-test binlogs behind a lock (#10658)
nohwnd c59d540
Localized file check-in by OneLocBuild Task: Build definition ID 1218…
dotnet-oneloc-localization[bot] c1279d5
[main] Bump github/codeql-action/upload-sarif from 4.37.6 to 4.37.7 (…
dependabot[bot] 73397da
Remove duplicate XLF target entries (#10680)
Evangelink 9c6cc0e
Pin expert review threat detector model (#10684)
Evangelink e77b6cb
Fix TRX lifetime handshake race (#10682)
Evangelink 9516a1c
Fix server-mode protocol capability documentation (#10688)
Evangelink 1d2d090
Upgrade agentic workflows to gh-aw 0.86.2 (#10678)
Evangelink 95901a7
Enforce AwesomeAssertions in source generation tests (#10677)
Evangelink 85b1aaf
Fix agentic workflow activation failures (#10686)
Evangelink 100b3d9
Normalize punctuation in MTP help descriptions (#10683)
Evangelink 6fb5373
Deduplicate report identity key encoding (#10687)
Evangelink 034514c
Avoid false threat detection in review workflows (#10692)
Evangelink df20227
Fix MSTEST0082 follow-up gaps (#10637)
Evangelink 25010a3
Fix ambiguous localization lock markers (#10690)
Evangelink 31e1cbf
Cache MSTest MTP node properties (#10694)
Evangelink 348da37
Localized file check-in by OneLocBuild Task: Build definition ID 1218…
dotnet-oneloc-localization[bot] a0177c7
Avoid expert review detection false positives (#10705)
Evangelink 14f0b0a
Report code coverage in CI summaries (#10693)
Evangelink 6c06604
Label Azure DevOps retry attempt results (#10704)
Evangelink 0b3d85c
Add hierarchical configuration sections (#10699)
Evangelink a7f3466
Document and test custom retry extensibility (#10703)
Evangelink f8992c1
[main] Update dependencies from microsoft/testfx (#10713)
dotnet-maestro[bot] 99c5496
[main] Update dependencies from dotnet/arcade (#10712)
dotnet-maestro[bot] 5115024
[main] Update dependencies from devdiv/DevDiv/vs-code-coverage (#10714)
dotnet-maestro[bot] f0bcffa
Localized file check-in by OneLocBuild Task: Build definition ID 1218…
dotnet-oneloc-localization[bot] c6b529b
Preserve generated attributes for async tests (#10700)
Evangelink 9bbfc32
Fix Azure DevOps published test identity (#10706)
Evangelink 111e68f
Add GitHub Actions summary section selection (#10697)
Evangelink b525be9
Deduplicate report post-processing helpers (#10717)
Evangelink 66ec411
Add failure-only GitHub step summaries (#10695)
Evangelink af78e8b
Fix agentic workflow incident handling (#10722)
Evangelink 85b7f8f
Split CI run summary aggregation into focused modules (#10719)
Evangelink 88063ea
Localized file check-in by OneLocBuild Task: Build definition ID 1218…
dotnet-oneloc-localization[bot] 359e1d9
Update Aspire.Hosting.Testing to 13.5.2 (#10724)
Evangelink 5ac412c
Add tests for artifact reparse point detection (#10721)
Evangelink 52b767e
Attach retry artifacts to Azure DevOps sub-results (#10723)
Evangelink c005c21
Declare PlatformServices as non-packable (#10728)
Evangelink 491b236
Pin the threat-detection model on every agentic workflow (#10729)
nohwnd 4f64688
Test that the HTML post-processor refuses to merge through a symlink …
nohwnd a6f1a7d
Run the Markdown Linter on markdownlint-cli2 instead of Super Linter …
nohwnd 3986221
Complete MSTest 4.4 and Platform 2.4 changelogs (#10742)
Evangelink 57ea162
Add nightly performance regression detection (#10720)
Evangelink 432ae5e
Handle report merge directory creation failures (#10734)
Evangelink 4c5f67e
Deduplicate published-results parsing in Azure DevOps client (#10735)
Evangelink 86e88e3
Document IDataConsumer UID filtering (#10740)
Evangelink bdc92c4
[main] Update dependencies from dotnet/arcade (#10747)
dotnet-maestro[bot] dfd5b7c
[main] Update dependencies from devdiv/DevDiv/vs-code-coverage (#10749)
dotnet-maestro[bot] a89f97b
Localized file check-in by OneLocBuild Task: Build definition ID 1218…
dotnet-oneloc-localization[bot] 0708690
[main] Update dependencies from microsoft/testfx (#10748)
dotnet-maestro[bot] cd572ae
[main] Bump Microsoft.TestPlatform.Filter.Source from 18.8.0-preview-…
dependabot[bot] 366d968
[main] Bump Microsoft.TestPlatform.ObjectModel from 18.8.0 to 18.9.0 …
dependabot[bot] 16b27e3
[main] Bump Microsoft.CodeAnalysis.VisualBasic.Analyzer.Testing from …
dependabot[bot] 190ac31
Require an execute bit before selecting a Unix apphost
nohwnd 3ef8a35
Fence the Unix apphost execute-bit check on NET7_0_OR_GREATER
nohwnd a43021a
Retry Unix apphost launches through dotnet
Evangelink fffb558
Merge PR branch before review fixes
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
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
203 changes: 203 additions & 0 deletions
203
...s/Microsoft.Testing.Platform.ServerMode.Client.Sources.UnitTests/MtpServerProcessTests.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,203 @@ | ||
| // 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.ServerMode.Client.Sources.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Tests for how <see cref="MtpServerProcess"/> chooses between a sibling apphost and <c>dotnet <dll></c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The scenario these guard is a test payload built on a Windows agent and executed on a Linux machine. Two | ||
| /// things go wrong there: a Windows PE <c>App.exe</c> travels next to <c>App.dll</c> and is not a Linux | ||
| /// executable, and a zip round trip does not carry POSIX permission bits, so the real extensionless apphost | ||
| /// can arrive without its execute bit. Launching either one aborts the run with <c>Permission denied</c>, so | ||
| /// the launcher has to reject both and fall back to <c>dotnet <dll></c>. | ||
| /// </remarks> | ||
| [TestClass] | ||
| public sealed class MtpServerProcessTests | ||
| { | ||
| // Any value works: BuildLaunch only formats the port into the argument string, it never binds it. | ||
| private const int Port = 12345; | ||
|
|
||
| [TestMethod] | ||
| public void BuildLaunchWhenSourceIsExeLaunchesItDirectly() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string exe = temp.CreateFile("App.exe"); | ||
|
|
||
| MtpServerProcess.LaunchCommand launch = MtpServerProcess.BuildLaunch(exe, Port); | ||
|
|
||
| Assert.AreEqual(exe, launch.FileName, "A native executable source must be launched directly."); | ||
| Assert.AreEqual(temp.Path, launch.WorkingDirectory); | ||
| Assert.Contains("--server", launch.Arguments); | ||
| Assert.Contains($"--client-port {Port}", launch.Arguments); | ||
| Assert.Contains("--no-banner", launch.Arguments); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void BuildLaunchWhenDllHasNoApphostFallsBackToDotnet() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string dll = temp.CreateFile("App.dll"); | ||
|
|
||
| MtpServerProcess.LaunchCommand launch = MtpServerProcess.BuildLaunch(dll, Port); | ||
|
|
||
| Assert.AreEqual("dotnet", launch.FileName, "Without an apphost the assembly must be launched by the muxer."); | ||
| Assert.Contains($"\"{dll}\"", launch.Arguments, "The muxer needs the quoted assembly path as its first argument."); | ||
| Assert.AreEqual(temp.Path, launch.WorkingDirectory); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Include, OperatingSystems.Windows, IgnoreMessage = "A '.exe' apphost is only launchable on Windows.")] | ||
| public void BuildLaunchOnWindowsSelectsSiblingExeApphost() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string dll = temp.CreateFile("App.dll"); | ||
| string exe = temp.CreateFile("App.exe"); | ||
|
|
||
| MtpServerProcess.LaunchCommand launch = MtpServerProcess.BuildLaunch(dll, Port); | ||
|
|
||
| Assert.AreEqual(exe, launch.FileName, "On Windows the sibling '.exe' apphost is the preferred launch target."); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Asserts that a Windows PE sibling is rejected, which only matters off Windows.")] | ||
| public void BuildLaunchOnUnixIgnoresSiblingWindowsExeAndFallsBackToDotnet() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string dll = temp.CreateFile("App.dll"); | ||
|
|
||
| // The Windows apphost that rode along in the payload. It exists, but it is a Windows PE binary. | ||
| _ = temp.CreateFile("App.exe"); | ||
|
|
||
| MtpServerProcess.LaunchCommand launch = MtpServerProcess.BuildLaunch(dll, Port); | ||
|
|
||
| Assert.AreEqual("dotnet", launch.FileName, "A Windows '.exe' must never be selected as the apphost on Unix."); | ||
| } | ||
|
|
||
| #if NET | ||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Unix file modes are a Unix concept.")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public void BuildLaunchOnUnixSelectsExecutableExtensionlessApphost() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string dll = temp.CreateFile("App.dll"); | ||
| string apphost = temp.CreateFile("App"); | ||
| MakeExecutable(apphost); | ||
|
|
||
| MtpServerProcess.LaunchCommand launch = MtpServerProcess.BuildLaunch(dll, Port); | ||
|
|
||
| Assert.AreEqual(apphost, launch.FileName, "An executable extensionless apphost is the preferred launch target on Unix."); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Unix file modes are a Unix concept.")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public void BuildLaunchOnUnixIgnoresNonExecutableApphostAndFallsBackToDotnet() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string dll = temp.CreateFile("App.dll"); | ||
|
|
||
| // The apphost survived the trip but the archive dropped its permission bits. | ||
| string apphost = temp.CreateFile("App"); | ||
| File.SetUnixFileMode(apphost, UnixFileMode.UserRead | UnixFileMode.UserWrite); | ||
|
|
||
| MtpServerProcess.LaunchCommand launch = MtpServerProcess.BuildLaunch(dll, Port); | ||
|
|
||
| Assert.AreEqual( | ||
| "dotnet", | ||
| launch.FileName, | ||
| "Starting a file with no execute bit throws 'Permission denied', so the launch must fall back to the muxer."); | ||
| } | ||
| #endif | ||
|
|
||
| [TestMethod] | ||
| public void IsUsableApphostReturnsFalseWhenFileMissing() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
|
|
||
| Assert.IsFalse(MtpServerProcess.IsUsableApphost(Path.Combine(temp.Path, "Missing"))); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Include, OperatingSystems.Windows, IgnoreMessage = "Windows has no execute bit, so this asserts the Windows-only branch.")] | ||
| public void IsUsableApphostOnWindowsReturnsTrueForExistingFile() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string apphost = temp.CreateFile("App.exe"); | ||
|
|
||
| Assert.IsTrue(MtpServerProcess.IsUsableApphost(apphost), "Windows has no execute bit, so existence is the whole check there."); | ||
| } | ||
|
|
||
| #if NET | ||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Unix file modes are a Unix concept.")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public void IsUsableApphostOnUnixReturnsFalseForNonExecutableFile() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string apphost = temp.CreateFile("App"); | ||
| File.SetUnixFileMode(apphost, UnixFileMode.UserRead | UnixFileMode.UserWrite); | ||
|
|
||
| Assert.IsFalse(MtpServerProcess.IsUsableApphost(apphost)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [OSCondition(ConditionMode.Exclude, OperatingSystems.Windows, IgnoreMessage = "Unix file modes are a Unix concept.")] | ||
| [UnsupportedOSPlatform("windows")] | ||
| public void IsUsableApphostOnUnixReturnsTrueForExecutableFile() | ||
| { | ||
| using var temp = TempDirectory.Create(); | ||
| string apphost = temp.CreateFile("App"); | ||
| MakeExecutable(apphost); | ||
|
|
||
| Assert.IsTrue(MtpServerProcess.IsUsableApphost(apphost)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Grants the owner execute permission only, so the test also proves the check does not require all three | ||
| /// execute bits. | ||
| /// </summary> | ||
| [UnsupportedOSPlatform("windows")] | ||
| private static void MakeExecutable(string path) | ||
| => File.SetUnixFileMode(path, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); | ||
| #endif | ||
|
|
||
| private sealed class TempDirectory : IDisposable | ||
| { | ||
| private TempDirectory(string path) => Path = path; | ||
|
|
||
| public string Path { get; } | ||
|
|
||
| public static TempDirectory Create() | ||
| { | ||
| string path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"mtp-apphost-{Guid.NewGuid():N}"); | ||
| _ = Directory.CreateDirectory(path); | ||
| return new TempDirectory(path); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates an empty file in the directory and returns its full path. The content is irrelevant: the | ||
| /// launcher only looks at the path, its existence, and its permissions. | ||
| /// </summary> | ||
| public string CreateFile(string fileName) | ||
| { | ||
| string fullPath = System.IO.Path.Combine(Path, fileName); | ||
| File.WriteAllText(fullPath, string.Empty); | ||
| return fullPath; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| try | ||
| { | ||
| Directory.Delete(Path, recursive: true); | ||
| } | ||
| catch (IOException) | ||
| { | ||
| // Best-effort cleanup: a temp directory left behind must never fail a test. | ||
| } | ||
| } | ||
| } | ||
| } |
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.