Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2786: JSON parsing error while running test security #2787

Merged
merged 2 commits into from Jan 8, 2019

Conversation

@jumde
Copy link
Contributor

jumde commented Jan 2, 2019

fix #2786
fix #2834

On linux, with shell set to true spawnSync timeout fails to kill the running browser window causing JSON parsing error since network_log is being written.

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Verified that these changes build without errors on
    • Windows
    • macOS
    • Linux
  • Verified that these changes pass automated tests (npm test brave_unit_tests && npm test brave_browser_tests) on
    • Windows
    • macOS
    • Linux
  • Ran git rebase master (if needed).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Requested a security/privacy review as needed.

Test Plan:

Verify npm run test-security runs without parsing errors.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions.
@jumde jumde requested a review from diracdeltas Jan 2, 2019
@@ -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.

Copy link
@diracdeltas

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)

@jumde jumde force-pushed the test-security-linux branch from 3468c8a to ece8fec Jan 3, 2019
// 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.

Copy link
@jumde

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.

Copy link
@diracdeltas

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.

Copy link
@jumde

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.

Copy link
@diracdeltas

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.

Copy link
@diracdeltas

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.

Copy link
@diracdeltas

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

@diracdeltas diracdeltas requested a review from mihaiplesa Jan 3, 2019
@diracdeltas
Copy link
Member

diracdeltas commented Jan 3, 2019

adding @mihaiplesa as a reviewer to see whether this fixes the security test running on linux/win build machines

@jumde jumde force-pushed the test-security-linux branch 2 times, most recently from 9791376 to 353580d Jan 3, 2019
@@ -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.

Copy link
@jumde

jumde Jan 3, 2019

Author Contributor

Deleting the files before starting the audit helps avoid stale results if the new file is not created.

@jumde jumde force-pushed the test-security-linux branch from 353580d to ab7169b Jan 4, 2019
Copy link
Member

diracdeltas left a comment

lgtm

@jumde jumde self-assigned this Jan 4, 2019
@jumde jumde force-pushed the test-security-linux branch from ab7169b to 79f1631 Jan 7, 2019
@mihaiplesa
Copy link
Collaborator

mihaiplesa commented Jan 7, 2019

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).

@jumde
Copy link
Contributor Author

jumde commented Jan 7, 2019

Test Results:

  1. MacOS:
  • npm start
  • npm test brave_unit_tests && npm test brave_browser_tests
  • npm run test-security
  1. Linux:
  • npm start
  • npm test brave_unit_tests && npm test brave_browser_tests
  • npm run test-security
  1. Windows:
  • npm start
  • npm test brave_unit_tests && npm test brave_browser_tests
  • npm run test-security

On Windows:

  1. Terminating npm start fails with this backtrace - this happens on master as well
Backtrace:
  CrashOnProcessDetach [0x00007FFD739E1120+0] (c:\b\src\base\win\dllmain.cc:89)
        DllMain [0x00007FFD739E1056+54] (c:\b\src\base\win\dllmain.cc:98)
        dllmain_dispatch [0x00007FFD7C4D2A18+152] (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\dll_dllmain.cpp:200)
        _DllMainCRTStartup [0x00007FFD7C4D2AF1+49] (d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\dll_dllmain.cpp:254)
        RtlAnsiStringToUnicodeString [0x00007FFDB95E8F07+663]
        LdrShutdownProcess [0x00007FFDB95E35BC+300]
        RtlExitUserProcess [0x00007FFDB9606DAD+173]
        CtrlRoutine [0x00007FFDB57927C0+288]
        CtrlRoutine [0x00007FFDB5792763+195]
        BaseThreadInitThunk [0x00007FFDB86B7E94+20]
        RtlUserThreadStart [0x00007FFDB960A251+33]
  1. brave-unit-tests are failing with this error on master as well
CXX obj/brave/test/brave_unit_tests/brave_common_static_redirect_network_delegate_helper_unittest.obj
FAILED: obj/brave/test/brave_unit_tests/brave_common_static_redirect_network_delegate_helper_unittest.obj
Copy link
Collaborator

mihaiplesa left a comment

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.

Copy link
@diracdeltas

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.

Copy link
@jumde

jumde Jan 8, 2019

Author Contributor

Updated! and yes, this is needed for windows.

@jumde jumde force-pushed the test-security-linux branch from 79f1631 to d164fb8 Jan 8, 2019
Copy link
Collaborator

mihaiplesa left a comment

looking good

@diracdeltas diracdeltas merged commit 65b3f17 into master Jan 8, 2019
@mihaiplesa
Copy link
Collaborator

mihaiplesa commented Jan 8, 2019

We might need to uplift this to all other channel branches as it will be part of the build process.

@diracdeltas diracdeltas added the 0.61.x label Jan 8, 2019
@diracdeltas
Copy link
Member

diracdeltas commented Jan 8, 2019

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

@bbondy bbondy added this to the 0.61.x - Nightly milestone Jan 14, 2019
@bbondy bbondy removed the 0.61.x label Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.