diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/dts/lib.deno.ns.d.ts | 6 | ||||
-rw-r--r-- | cli/dts/lib.deno.unstable.d.ts | 4 | ||||
-rw-r--r-- | cli/tests/unit/process_test.ts | 56 |
3 files changed, 66 insertions, 0 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 5b6849bfd..05e600ed7 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -2034,6 +2034,12 @@ declare namespace Deno { * Environmental variables for subprocess can be specified using `opt.env` * mapping. * + * `opt.uid` sets the child process’s user ID. This translates to a setuid call + * in the child process. Failure in the setuid call will cause the spawn to fail. + * + * `opt.gid` is similar to `opt.uid`, but sets the group ID of the child process. + * This has the same semantics as the uid field. + * * By default subprocess inherits stdio of parent process. To change that * `opt.stdout`, `opt.stderr` and `opt.stdin` can be specified independently - * they can be set to either an rid of open file or set to "inherit" "piped" diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index 5854a5181..1a27f2b38 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -713,8 +713,12 @@ declare namespace Deno { export function run< T extends RunOptions & { clearEnv?: boolean; + gid?: number; + uid?: number; } = RunOptions & { clearEnv?: boolean; + gid?: number; + uid?: number; }, >(opt: T): Process<T>; diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index 371521e33..9f8e9cd9f 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -537,3 +537,59 @@ unitTest( p.close(); }, ); + +unitTest( + { perms: { run: true, read: true }, ignore: Deno.build.os === "windows" }, + async function uid(): Promise<void> { + const p = Deno.run({ + cmd: [ + "id", + "-u", + ], + stdout: "piped", + }); + + const currentUid = new TextDecoder().decode(await p.output()); + p.close(); + + if (currentUid !== "0") { + assertThrows(() => { + Deno.run({ + cmd: [ + "echo", + "fhqwhgads", + ], + uid: 0, + }); + }, Deno.errors.PermissionDenied); + } + }, +); + +unitTest( + { perms: { run: true, read: true }, ignore: Deno.build.os === "windows" }, + async function gid(): Promise<void> { + const p = Deno.run({ + cmd: [ + "id", + "-g", + ], + stdout: "piped", + }); + + const currentGid = new TextDecoder().decode(await p.output()); + p.close(); + + if (currentGid !== "0") { + assertThrows(() => { + Deno.run({ + cmd: [ + "echo", + "fhqwhgads", + ], + gid: 0, + }); + }, Deno.errors.PermissionDenied); + } + }, +); |