Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions src/windows/wslaservice/exe/WSLAVirtualMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,9 @@ Microsoft::WRL::ComPtr<WSLAProcess> WSLAVirtualMachine::CreateLinuxProcessImpl(
// std::thread::joinable() is const, so this can be called without acquiring the lock.
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !m_processExitThread.joinable());

THROW_WIN32_IF_MSG(
ERROR_NOT_SUPPORTED, Options.User != nullptr, "Custom users are not supported for root namespace processes");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add support later if there's a usecase for it. For now let's fail with a proper error code


auto setErrno = [Errno](int Error) {
if (Errno != nullptr)
{
Expand Down
31 changes: 31 additions & 0 deletions test/windows/WSLATests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,15 @@ class WSLATests
auto process = launcher.Launch(*m_defaultSession);
ValidateProcessOutput(process, {{1, "foo bar\n"}}); // expect two spaces for the empty argument.
}

// Validate error paths
{
WSLAProcessLauncher launcher("/bin/bash", {"/bin/bash"});
launcher.SetUser("nobody"); // Custom users are not supported for root namespace processes.

auto [hresult, error, process] = launcher.LaunchNoThrow(*m_defaultSession);
VERIFY_ARE_EQUAL(hresult, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED));
}
}

TEST_METHOD(CrashDumpCollection)
Expand Down Expand Up @@ -1534,6 +1543,19 @@ class WSLATests
ValidateProcessOutput(process, {{1, "nobody\n"}});
}

// Validate that the group is correctly wired.
{
WSLAContainerLauncher launcher("debian:latest", "test-group", {"groups"});

launcher.SetUser("nobody:www-data");

auto container = launcher.Launch(*m_defaultSession);
auto process = container.GetInitProcess();
ValidateProcessOutput(process, {{1, "www-data\n"}});
}

// TODO: Add test coverage for error message when the user / group doesn't exist.

// Validate that empty arguments are correctly handled.
{
WSLAContainerLauncher launcher("debian:latest", "test-empty-args", {"echo", "foo", "", "bar"});
Expand Down Expand Up @@ -2017,6 +2039,15 @@ class WSLATests
ValidateProcessOutput(process, {{1, "nobody\n"}});
}

// Validate that the group is correctly wired.
{
WSLAProcessLauncher launcher({}, {"groups"});
launcher.SetUser("nobody:www-data");

auto process = launcher.Launch(container.Get());
ValidateProcessOutput(process, {{1, "www-data\n"}});
}

// Validate that stdin is correctly wired.
{
auto process = WSLAProcessLauncher({}, {"/bin/cat"}, {}, WSLAProcessFlagsStdin).Launch(container.Get());
Expand Down