- Bump bareOsCtxApiVersion to 1.48.0; sync CHANGELOG, compatibility matrix, syscalls.example.json, ctx d.ts, generated ctx-client helper - POSIX: getconf _SC_NPROCESSORS_ONLN; shell set -o pipefail + BARE_OS_PIPESTATUS; posix_utilities schema v2 + JSON Schema; generated dashboard refresh - Host/subprocess: bare-subprocess then Node child_process spawn; optional backend on ctx.bareOsTrySpawnHostSubprocess; bin-worker WASM wall budget - VFS: BARE_OS_VFS_SYSTEM_IMAGE_WRITE for system image writes + warm-cache eviction path; guest /.bare/account EACCES test; environ TOKEN redaction test - Docs: corestore snapshot non-goal in package-bare-os-booter; PEAR-RUN links → docs/PEAR-RUN.md; POSIX pretest matrix in scripts/README + dev guide; environment appendix (PIPESTATUS, WASM_MS, system image write) - Seeder: keep kernel/ mirror in sync after bundle + coreutils builds Verified: npm test -w bare-os-booter, npm run pretest
103 lines
2.8 KiB
JavaScript
103 lines
2.8 KiB
JavaScript
/**
|
|
* Unit tests for BARE_OS_POSIX_SOCKET_SCM_RIGHTS parsing helpers (no live TCP/UDP bridge).
|
|
*/
|
|
import test from 'brittle'
|
|
import {
|
|
bareOsEnsureSocketSlotAliasKeys,
|
|
bareOsParseSendmsgScmRights,
|
|
bareOsScmRightsMaxFds,
|
|
wantPosixSocketScmRights
|
|
} from './lib/bare-os-socket-scm-rights.js'
|
|
|
|
test('wantPosixSocketScmRights', (t) => {
|
|
t.absent(wantPosixSocketScmRights({}))
|
|
t.ok(wantPosixSocketScmRights({ BARE_OS_POSIX_SOCKET_SCM_RIGHTS: '1' }))
|
|
t.ok(wantPosixSocketScmRights({ BARE_OS_POSIX_SOCKET_SCM_RIGHTS: 'true' }))
|
|
t.absent(wantPosixSocketScmRights({ BARE_OS_POSIX_SOCKET_SCM_RIGHTS: '0' }))
|
|
})
|
|
|
|
test('bareOsScmRightsMaxFds default and cap', (t) => {
|
|
t.is(bareOsScmRightsMaxFds({}), 4)
|
|
t.is(bareOsScmRightsMaxFds({ BARE_OS_POSIX_SOCKET_SCM_RIGHTS_MAX_FDS: '2' }), 2)
|
|
t.is(bareOsScmRightsMaxFds({ BARE_OS_POSIX_SOCKET_SCM_RIGHTS_MAX_FDS: '99' }), 16)
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: empty / no ancillary', (t) => {
|
|
const r = bareOsParseSendmsgScmRights({}, true, 4)
|
|
t.ok(r.ok)
|
|
t.alike(r.fds, [])
|
|
const r2 = bareOsParseSendmsgScmRights({ buf: new Uint8Array(1) }, true, 4)
|
|
t.ok(r2.ok)
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: rejects binary control when scm on', (t) => {
|
|
const r = bareOsParseSendmsgScmRights(
|
|
{ control: new Uint8Array([1]) },
|
|
true,
|
|
4
|
|
)
|
|
t.absent(r.ok)
|
|
t.is(r.reject, 'control')
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: rejects controllen when scm on', (t) => {
|
|
const r = bareOsParseSendmsgScmRights({ controllen: 3 }, true, 4)
|
|
t.absent(r.ok)
|
|
t.is(r.reject, 'controllen')
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: valid cmsgs fds', (t) => {
|
|
const r = bareOsParseSendmsgScmRights(
|
|
{ cmsgs: [{ fds: [3, 4] }] },
|
|
true,
|
|
4
|
|
)
|
|
t.ok(r.ok)
|
|
t.alike(r.fds, [3, 4])
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: msgHdr.cmsgs merged', (t) => {
|
|
const r = bareOsParseSendmsgScmRights(
|
|
{ msgHdr: { cmsgs: [{ fds: [5] }] } },
|
|
true,
|
|
4
|
|
)
|
|
t.ok(r.ok)
|
|
t.alike(r.fds, [5])
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: cap exceeded', (t) => {
|
|
const r = bareOsParseSendmsgScmRights(
|
|
{ cmsgs: [{ fds: [1, 2, 3, 4, 5] }] },
|
|
true,
|
|
4
|
|
)
|
|
t.absent(r.ok)
|
|
t.is(r.reject, 'cmsgs_cap')
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: cmsgs when scm off', (t) => {
|
|
const r = bareOsParseSendmsgScmRights(
|
|
{ cmsgs: [{ fds: [1] }] },
|
|
false,
|
|
4
|
|
)
|
|
t.absent(r.ok)
|
|
t.is(r.reject, 'cmsgs')
|
|
})
|
|
|
|
test('bareOsParseSendmsgScmRights: malformed cmsgs entry', (t) => {
|
|
const r = bareOsParseSendmsgScmRights({ cmsgs: [{ fds: 'nope' }] }, true, 4)
|
|
t.absent(r.ok)
|
|
t.is(r.reject, 'cmsgs')
|
|
})
|
|
|
|
test('bareOsEnsureSocketSlotAliasKeys', (t) => {
|
|
const slot = {}
|
|
bareOsEnsureSocketSlotAliasKeys(slot, '7')
|
|
t.ok(slot.aliasKeys instanceof Set)
|
|
t.ok(slot.aliasKeys.has('7'))
|
|
bareOsEnsureSocketSlotAliasKeys(slot, '8')
|
|
t.ok(slot.aliasKeys.has('8'))
|
|
})
|