Skip to content

Commit

Permalink
Merge pull request #2787 from brave/test-security-linux
Browse files Browse the repository at this point in the history
Issue 2786: JSON parsing error while running test security
  • Loading branch information
diracdeltas authored Jan 8, 2019
2 parents 3a1feff + d379ca9 commit 8975c64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 16 additions & 2 deletions build/lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
fs.unlinkSync(networkLogFile)
}
if (fs.existsSync('network-audit-results.json')) {
fs.unlinkSync('network-audit-results.json')
}
}
}

let cmdOptions = {
stdio: 'inherit',
timeout: options.network_log ? 120000 : undefined,
continueOnFail: options.network_log ? true : false,
shell: true
shell: process.platform === 'darwin' ? true : false
}

if (options.network_log) {
Expand All @@ -114,8 +120,16 @@ const start = (passthroughArgs, buildConfig = config.defaultBuildConfig, options

if (options.network_log) {
let exitCode = 0
let jsonOutput = {}
// Read the network log
const jsonOutput = fs.readJsonSync(networkLogFile)
let jsonContent = fs.readFileSync(networkLogFile, 'utf8').trim()
// On windows netlog ends abruptly causing JSON parsing errors
if (!jsonContent.endsWith('}]}')) {
const n = jsonContent.lastIndexOf('},')
jsonContent = jsonContent.substring(0, n) + "}]}"
}
jsonOutput = JSON.parse(jsonContent)

const URL_REQUEST_TYPE = jsonOutput.constants.logSourceType.URL_REQUEST
const URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED = jsonOutput.constants.logEventTypes.URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED
const urlRequests = jsonOutput.events.filter((event) => {
Expand Down
6 changes: 5 additions & 1 deletion build/scripts/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ function npmAudit (pathname) {
if (fs.existsSync(path.join(pathname, 'package.json')) &&
fs.existsSync(path.join(pathname, 'package-lock.json'))) {
console.log('Auditing', pathname)
util.run('npm', ['audit'], { cwd: pathname })
let cmdOptions = {
cwd: pathname,
shell: process.platform === 'win32' ? true : false
}
util.run('npm', ['audit'], cmdOptions)
} else {
console.log('Skipping audit of', pathname)
}
Expand Down

0 comments on commit 8975c64

Please sign in to comment.