Skip to content

Commit 2c091be

Browse files
committed
add show io
1 parent 0821917 commit 2c091be

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ function outputToStream(stream, data) {
3030
}
3131
````
3232

33+
## Default environment variable control
34+
35+
`fuzz-me-maybe` turns **off** the fuzzer by default. This is such that it will allow tests and other systems to run unless there are explicit flags turning on the fuzzer, and lets you leave fuzzing infrastructure in place. To enable your fuzzer, you will need to set `$ENVPREFIX_ENABLED=1` on your command line (by default, this environment prefix is `FUZZER_`, so you would set `FUZZER_ENABLED=1` to turn on the fuzzer.)
36+
37+
If you want to show your I/O (for example, to save testcases or a log of fuzz output), you can show it by setting `$ENVPREFIX_SHOW_IO=1` on your command line to print to stdout, and `$ENVPREFIX_SHOW_IO=1 $ENVPREFIX_SHOW_IO_STDERR=1`, where `$ENVPREFIX` is either `FUZZER` (the default) or what you set with the `registerEnvironmentPrefix` method.
38+
39+
3340
## Custom environment flags
3441

3542
`fuzz-me-maybe` allows for boolean, counted, and string matching flags. To get more functionality, tag your fuzzer calls for enable/disable:

fuzzer.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const Sinkdweller = require('sinkdweller');
4+
const chalk = require('chalk');
45

56
const ENV_TYPE = {
67
BOOLEAN: 1,
@@ -17,7 +18,8 @@ const FLAG_TYPE = {
1718
const DEFAULT_OPTIONS = {
1819
environmentPrefix: 'FUZZER_',
1920
enableFlag: 'ENABLED',
20-
enableByDefault: false
21+
enableByDefault: false,
22+
showIOByDefault: false
2123
};
2224

2325

@@ -48,9 +50,11 @@ class Fuzzer {
4850
strDataKey = strDataKey.toUpperCase();
4951
}
5052

53+
this._showIOMaybe('in', strbufData);
5154
if (this._shouldFuzz(strDataKey, strbufData)) {
52-
return this._fuzzer.fuzzSync(strbufData);
55+
strbufData = this._fuzzer.fuzzSync(strbufData);
5356
}
57+
this._showIOMaybe('out', strbufData);
5458
return strbufData;
5559
}
5660

@@ -131,7 +135,30 @@ class Fuzzer {
131135
}
132136

133137

138+
/**
139+
* Show IO to a stdout/stderr if enabled.
140+
*
141+
* @param {String} type Caption string (e.g.' 'in', 'out')
142+
* @param {String|Buffer} strbufData Data for IO
143+
*/
144+
_showIOMaybe(type, strbufData) {
145+
let showIO = this._getEnvironmentVariable('SHOW_IO', VAR_TYPE.BOOLEAN);
146+
if (showIO === null) {
147+
showIO = this.options.showIOByDefault;
148+
}
149+
if (showIO) {
150+
let showAsStdErr = this._getEnvironmentVariable('SHOW_IO_STDERR', VAR_TYPE.BOOLEAN);
151+
if (showAsStdErr === null) {
152+
showAsStdErr = false;
153+
}
154+
let output = showAsStdErr ? console.error : console.info;
155+
output(chalk.gray(type) + "\n");
156+
output(strbufData);
157+
output(chalk.gray('-------------'));
158+
}
159+
}
134160

161+
135162
/**
136163
* Whether or not data with the key `strDataKey` should be fuzzed.
137164
*

package-lock.json

+3-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"homepage": "https://github.com/rarecoil/fuzz-me-maybe#readme",
2424
"dependencies": {
25+
"chalk": "^2.4.2",
2526
"sinkdweller": "^1.0.3"
2627
},
2728
"devDependencies": {

0 commit comments

Comments
 (0)