Skip to content

Make testSubprocessPlatfomOptionsPreSpawnProcessConfigurator more robust #75

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
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
23 changes: 20 additions & 3 deletions Tests/SubprocessTests/SubprocessTests+Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,34 @@ import Testing
// MARK: PlatformOption Tests
@Suite(.serialized)
struct SubprocessLinuxTests {
@Test func testSubprocessPlatformOptionsPreSpawnProcessConfigurator() async throws {
@Test(
.enabled(
if: getgid() == 0,
"This test requires root privileges"
)
)
func testSubprocessPlatformOptionsPreSpawnProcessConfigurator() async throws {
var platformOptions = PlatformOptions()
platformOptions.preSpawnProcessConfigurator = {
setgid(4321)
guard setgid(4321) == 0 else {
// Returns EPERM when:
// The calling process is not privileged (does not have the
// CAP_SETGID capability in its user namespace), and gid does
// not match the real group ID or saved set-group-ID of the
// calling process.
perror("setgid")
abort()
}
}
let idResult = try await Subprocess.run(
.path("/usr/bin/id"),
arguments: ["-g"],
platformOptions: platformOptions,
output: .string
output: .string,
error: .string
)
let error = try #require(idResult.standardError)
try #require(error == "")
#expect(idResult.terminationStatus.isSuccess)
let id = try #require(idResult.standardOutput)
#expect(
Expand Down
Loading