Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIssue 2786: JSON parsing error while running test security #2787
Conversation
| @@ -87,7 +87,7 @@ const start = (passthroughArgs, buildConfig = config.defaultBuildConfig, options | |||
| stdio: 'inherit', | |||
| timeout: options.network_log ? 120000 : undefined, | |||
| continueOnFail: options.network_log ? true : false, | |||
| shell: true | |||
| shell: process.platform === 'linux' && options.network_log ? false : true | |||
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 3, 2019
Member
shell false is better for security anyway; can we set it to false on all platforms except mac? (regardless of whether network_log is true)
| // fix the json if there was a parsing error | ||
| const n = jsonContent.lastIndexOf('},') | ||
| const fixedJSONContent = jsonContent.substring(0, n) + "}]}" | ||
| jsonOutput = JSON.parse(fixedJSONContent) |
This comment has been minimized.
This comment has been minimized.
jumde
Jan 3, 2019
Author
Contributor
This also can be within a try | catch block, but haven't seen it fail till now.
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 3, 2019
Member
This doesn't seem to guarantee the JSON file is completely written by the network log process, just that it is parseable. What if instead it tried to re-parse the file some number of times with a time delay to wait until the JSON file is completely rewritten?
This comment has been minimized.
This comment has been minimized.
jumde
Jan 3, 2019
Author
Contributor
I tried reparsing the file 3 times after a wait of 10 secs on Win10, but I always got the file with terminating string },. I'll try increasing the timeout to check if it may be a result of my VM being slow.
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 3, 2019
Member
@jumde i see, so it seems the file is indeed complete but just that it has a weird terminating string on windows?
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 3, 2019
Member
in that case i suggest adding a comment in the code to say that this is a windows chromium issue
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 3, 2019
Member
if i understand this bug correctly, i think this code would be more clear as:
let jsonContent = fs.readFileSync(networkLogFile, 'utf8')
if (jsonContent.endsWith('},')) {
// do the fixing
}
jsonOutput = JSON.parse(jsonContent)
instead of a try-catch, since the JSON parsing might potentially fail for other reasons
|
adding @mihaiplesa as a reviewer to see whether this fixes the security test running on linux/win build machines |
9791376
to
353580d
| @@ -80,14 +80,20 @@ const start = (passthroughArgs, buildConfig = config.defaultBuildConfig, options | |||
| if (user_data_dir) { | |||
| // clear the data directory before doing a network test | |||
| fs.removeSync(user_data_dir.replace('\\', '')) | |||
| if (fs.existsSync(networkLogFile)) { | |||
This comment has been minimized.
This comment has been minimized.
jumde
Jan 3, 2019
Author
Contributor
Deleting the files before starting the audit helps avoid stale results if the new file is not created.
|
lgtm |
auditors: @diracdeltas
|
Looking good, it's passing for Linux and Windows now. Have to find a way to execute browser tests on Windows as they fail when run in Jenkins (which uses powershell in non-interactive mode). |
|
Test Results:
On Windows:
|
|
Let's get this in. |
| util.run('npm', ['audit'], { cwd: pathname }) | ||
| let cmdOptions = { | ||
| cwd: pathname, | ||
| shell: process.platform === 'win32' ? true: false |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 8, 2019
Member
minor: this should be true : instead of true:
i assume this doesn't work on windows without this change?
This comment has been minimized.
This comment has been minimized.
auditor: @diracdeltas
|
looking good |
|
We might need to uplift this to all other channel branches as it will be part of the build process. |
|
i recommending opening an uplift PR for this in dev channel (see https://github.com/brave/brave-browser/wiki/Triage-Guidelines for instructions), make sure it doesn't cause any build issues, and then opening uplift requests for the other channels |
jumde commentedJan 2, 2019
•
edited
fix #2786
fix #2834
On linux, with shell set to true
spawnSync timeoutfails to kill the running browser window causing JSON parsing error since network_log is being written.Submitter Checklist:
npm test brave_unit_tests && npm test brave_browser_tests) ongit rebase master(if needed).git rebase -ito squash commits (if needed).Test Plan:
Verify
npm run test-securityruns without parsing errors.Reviewer Checklist: