22import fs from "node:fs" ;
33import os from "node:os" ;
44import path from "node:path" ;
5- import { beforeEach , describe , expect , it , vi } from "vitest" ;
5+ import { describe , expect , it } from "vitest" ;
66import type { ConfigFileSnapshot } from "../config/types.openclaw.js" ;
7-
8- const inspectPathPermissionsMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
9-
10- vi . mock ( "./audit-fs.js" , ( ) => ( {
11- inspectPathPermissions : inspectPathPermissionsMock ,
12- formatPermissionDetail : ( targetPath : string ) => `${ targetPath } mocked-perms` ,
13- formatPermissionRemediation : ( { targetPath } : { targetPath : string } ) =>
14- `chmod 600 ${ targetPath } ` ,
15- } ) ) ;
7+ import { collectIncludeFilePermFindings } from "./audit-extra.async.js" ;
168
179describe ( "security audit config include permissions" , ( ) => {
18- beforeEach ( ( ) => {
19- vi . resetModules ( ) ;
20- inspectPathPermissionsMock . mockReset ( ) ;
21- } ) ;
22-
2310 it ( "flags group/world-readable config include files" , async ( ) => {
24- const { collectIncludeFilePermFindings } = await import ( "./audit-extra.async.js" ) ;
2511 const tmp = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "openclaw-include-perms-" ) ) ;
2612 const stateDir = path . join ( tmp , "state" ) ;
2713 fs . mkdirSync ( stateDir , { recursive : true , mode : 0o700 } ) ;
2814
2915 const includePath = path . join ( stateDir , "extra.json5" ) ;
3016 fs . writeFileSync ( includePath , "{ logging: { redactSensitive: 'off' } }\n" , "utf-8" ) ;
31- inspectPathPermissionsMock . mockResolvedValue ( {
32- ok : true ,
33- isSymlink : false ,
34- isDir : false ,
35- mode : 0o644 ,
36- bits : 0o644 ,
37- source : "posix" ,
38- worldWritable : false ,
39- groupWritable : false ,
40- worldReadable : true ,
41- groupReadable : true ,
42- } ) ;
17+ fs . chmodSync ( includePath , 0o644 ) ;
4318
4419 const configSnapshot : ConfigFileSnapshot = {
4520 path : path . join ( stateDir , "openclaw.json" ) ,
@@ -58,13 +33,9 @@ describe("security audit config include permissions", () => {
5833
5934 const findings = await collectIncludeFilePermFindings ( {
6035 configSnapshot,
36+ platform : "linux" ,
6137 } ) ;
6238
63- expect ( inspectPathPermissionsMock ) . toHaveBeenCalledWith ( includePath , {
64- env : undefined ,
65- exec : undefined ,
66- platform : undefined ,
67- } ) ;
6839 const finding = findings . find (
6940 ( entry ) => entry . checkId === "fs.config_include.perms_world_readable" ,
7041 ) ;
0 commit comments