32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { loadRuntimeGrants } from './runtime-read.module';
|
|
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
describe('reviewed runtime grants file', () => {
|
|
it('loads an exact reviewed file and fails closed for malformed grants', async () => {
|
|
const dir = await mkdtemp(join(tmpdir(), 'runtime-grants-'));
|
|
const file = join(dir, 'grants.json');
|
|
try {
|
|
await writeFile(file, JSON.stringify({ 'subject-1': ['default'] }));
|
|
expect(await loadRuntimeGrants(file, dir)).toEqual({
|
|
'subject-1': ['default'],
|
|
});
|
|
for (const invalid of [
|
|
null,
|
|
[],
|
|
{ 'subject-1': [] },
|
|
{ 'subject-1': ['default', 'default'] },
|
|
{ 'subject-1': ['../x'] },
|
|
{ 'subject-1': [3] },
|
|
{ 'subject-1': ['default'], extra: true },
|
|
]) {
|
|
await writeFile(file, JSON.stringify(invalid));
|
|
await expect(loadRuntimeGrants(file, dir)).rejects.toThrow();
|
|
}
|
|
await expect(loadRuntimeGrants('/etc/passwd')).rejects.toThrow();
|
|
} finally {
|
|
await rm(dir, { recursive: true });
|
|
}
|
|
});
|
|
});
|