Files
bun.sh/test/js/node/process/process-initgroups.test.ts
Claude Bot b0b94b1e7a Add integer validation for numeric uid/gid arguments
- Use Bun::V::validateInteger to reject non-integers (NaN, Infinity, floats, negatives)
- Match the validation pattern used in setuid/setgid functions
- Add comprehensive test coverage for numeric edge cases (1.5, -1, NaN, Infinity, 2^31)
- Validate both user and extraGroup parameters when numeric

Addresses CodeRabbit review feedback.
2025-10-21 06:33:54 +00:00

70 lines
1.8 KiB
TypeScript

import { expect, test } from "bun:test";
import { isWindows } from "harness";
if (!isWindows) {
test("process.initgroups validates arguments", () => {
// Missing arguments
expect(() => {
// @ts-expect-error
process.initgroups();
}).toThrow();
expect(() => {
// @ts-expect-error
process.initgroups("user");
}).toThrow();
// Invalid argument types
const invalidValues = [null, true, {}, [], () => {}];
for (const val of invalidValues) {
expect(() => {
// @ts-expect-error
process.initgroups(val, 1000);
}).toThrow();
expect(() => {
// @ts-expect-error
process.initgroups("user", val);
}).toThrow();
}
});
test("process.initgroups validates numeric arguments are integers", () => {
// Non-integer numeric values should be rejected
const invalidNumericValues = [1.5, -1, NaN, Infinity, -Infinity, 2 ** 31];
for (const val of invalidNumericValues) {
expect(() => {
process.initgroups(val, 1000);
}).toThrow();
expect(() => {
process.initgroups("root", val);
}).toThrow();
}
});
test("process.initgroups throws for non-existent user", () => {
expect(() => {
process.initgroups("fhqwhgadshgnsdhjsdbkhsdabkfabkveyb", 1000);
}).toThrow(/User identifier does not exist/);
});
test("process.initgroups throws for non-existent group", () => {
expect(() => {
process.initgroups("root", "fhqwhgadshgnsdhjsdbkhsdabkfabkveyb");
}).toThrow(/Group identifier does not exist/);
});
test("process.initgroups throws for invalid uid", () => {
expect(() => {
process.initgroups(9999999, 1000);
}).toThrow(/User identifier does not exist/);
});
} else {
test("process.initgroups is undefined on Windows", () => {
expect(process.initgroups).toBeUndefined();
});
}