@@ -1067,6 +1067,46 @@ func TestExecParse(t *testing.T) {
10671067 assert .Equal (t , string (cwd ), decCwd )
10681068 })
10691069
1070+ t .Run ("Filename, args, cwd and envs" , func (t * testing.T ) {
1071+ observer .DataPurge ()
1072+
1073+ // - filename (string)
1074+ // - args (string)
1075+ // - cwd (string)
1076+ // - envs (string)
1077+
1078+ var args []byte
1079+ args = append (args , 'a' , 'r' , 'g' , '1' , 0 , 'a' , 'r' , 'g' , '2' )
1080+
1081+ var envs []byte
1082+ envs = append (envs , 'A' , '=' , '1' , 0 , 'B' , '=' , '2' )
1083+
1084+ exec .Flags = api .EventErrorFilename
1085+ exec .Size = uint32 (processapi .MSG_SIZEOF_EXECVE + len (filename ) + len (args ) + len (cwd ) + len (envs ))
1086+ exec .SizePath = uint16 (len (filename ))
1087+ exec .SizeArgs = uint16 (len (args ))
1088+ exec .SizeCwd = uint16 (len (cwd ))
1089+ exec .SizeEnvs = uint16 (len (envs ))
1090+
1091+ var buf bytes.Buffer
1092+ binary .Write (& buf , binary .LittleEndian , exec )
1093+ binary .Write (& buf , binary .LittleEndian , filename )
1094+ binary .Write (& buf , binary .LittleEndian , args )
1095+ binary .Write (& buf , binary .LittleEndian , cwd )
1096+ binary .Write (& buf , binary .LittleEndian , envs )
1097+
1098+ reader := bytes .NewReader (buf .Bytes ())
1099+
1100+ process , err := execParse (reader )
1101+ require .NoError (t , err )
1102+
1103+ assert .Equal (t , string (filename ), process .Filename )
1104+ assert .Equal (t , "A=1 B=2" , process .Envs )
1105+
1106+ decArgs , decCwd := proc .ArgsDecoder (process .Args , process .Flags )
1107+ assert .Equal (t , "arg1 arg2" , decArgs )
1108+ assert .Equal (t , string (cwd ), decCwd )
1109+ })
10701110 observer .DataPurge ()
10711111}
10721112
0 commit comments