File tree Expand file tree Collapse file tree 3 files changed +46
-13
lines changed Expand file tree Collapse file tree 3 files changed +46
-13
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import yargs , { Argv } from "yargs" ;
19
19
import { startFuzzing } from "./core" ;
20
- import { ensureFilepath } from "./utils" ;
20
+ import { prepareArgs } from "./utils" ;
21
21
import { defaultOptions , processOptions , fromSnakeCase } from "./options" ;
22
22
23
23
// Use yargs to parse command line arguments and provide a nice CLI experience.
@@ -227,17 +227,7 @@ yargs(process.argv.slice(2))
227
227
} ,
228
228
// eslint-disable-next-line @typescript-eslint/no-explicit-any
229
229
( args : any ) => {
230
- // Transform arguments to common format, add compound properties and
231
- // remove framework specific ones.
232
- const options = {
233
- ...args ,
234
- fuzz_target : ensureFilepath ( args . fuzz_target ) ,
235
- fuzzer_options : ( args . corpus ?? [ ] ) . concat ( args . _ ) ,
236
- } ;
237
- delete options . _ ;
238
- delete options . corpus ;
239
- delete options . $0 ;
240
-
230
+ const options = prepareArgs ( args ) ;
241
231
// noinspection JSIgnoredPromiseFromCall
242
232
startFuzzing ( processOptions ( options , fromSnakeCase ) ) ;
243
233
} ,
Original file line number Diff line number Diff line change 14
14
* limitations under the License.
15
15
*/
16
16
17
- import { ensureFilepath } from "./utils" ;
17
+ import { ensureFilepath , prepareArgs } from "./utils" ;
18
18
19
19
import path from "path" ;
20
20
@@ -35,4 +35,24 @@ describe("core", () => {
35
35
expect ( ensureFilepath ( "filename.js" ) ) . toMatch ( expectedPath ) ;
36
36
} ) ;
37
37
} ) ;
38
+ describe ( "prepareArgs" , ( ) => {
39
+ it ( "converts fuzzer args to strings" , ( ) => {
40
+ const args = {
41
+ _ : [ "-some_arg=value" , "-other_arg" , 123 ] ,
42
+ corpus : [ "directory1" , "directory2" ] ,
43
+ fuzz_target : "filename.js" ,
44
+ } ;
45
+ const options = prepareArgs ( args ) ;
46
+ expect ( options ) . toEqual ( {
47
+ fuzz_target : "file://" + path . join ( process . cwd ( ) , "filename.js" ) ,
48
+ fuzzer_options : [
49
+ "directory1" ,
50
+ "directory2" ,
51
+ "-some_arg=value" ,
52
+ "-other_arg" ,
53
+ "123" ,
54
+ ] ,
55
+ } ) ;
56
+ } ) ;
57
+ } ) ;
38
58
} ) ;
Original file line number Diff line number Diff line change @@ -39,3 +39,26 @@ export function ensureFilepath(filePath: string): string {
39
39
? fullPath
40
40
: fullPath + ".js" ;
41
41
}
42
+
43
+ /**
44
+ * Transform arguments to common format, add compound properties and
45
+ * remove framework specific ones, so that the result can be passed on to the
46
+ * regular option handling code.
47
+ *
48
+ * The function is extracted to "utils" as importing "cli" in tests directly
49
+ * tries to parse command line arguments.
50
+ */
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ export function prepareArgs ( args : any ) {
53
+ const options = {
54
+ ...args ,
55
+ fuzz_target : ensureFilepath ( args . fuzz_target ) ,
56
+ fuzzer_options : ( args . corpus ?? [ ] )
57
+ . concat ( args . _ )
58
+ . map ( ( e : unknown ) => e + "" ) ,
59
+ } ;
60
+ delete options . _ ;
61
+ delete options . corpus ;
62
+ delete options . $0 ;
63
+ return options ;
64
+ }
You can’t perform that action at this time.
0 commit comments