From 8eef5eace55a55c4095a719926156ec2d5166a53 Mon Sep 17 00:00:00 2001 From: Corentin Mors Date: Mon, 20 Mar 2023 11:32:41 +0100 Subject: [PATCH] chore: make corruption test pass on macos (#1890) --- test/test-50-corrupt-executable/main.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/test-50-corrupt-executable/main.js b/test/test-50-corrupt-executable/main.js index a9bfca474..9e32eef4c 100644 --- a/test/test-50-corrupt-executable/main.js +++ b/test/test-50-corrupt-executable/main.js @@ -10,11 +10,6 @@ const utils = require('../utils.js'); assert(!module.parent); assert(__dirname === process.cwd()); -// TODO : understand why the damage is not impacting macos build -if (process.platform === 'darwin') { - return; -} - const host = 'node' + process.version.match(/^v(\d+)/)[1]; const target = process.argv[2] || host; const input = './test-x-index.js'; @@ -22,7 +17,15 @@ const output = './test-output.exe'; let right; -utils.pkg.sync(['--target', target, '--output', output, input]); +// on macos damaging the binary should happen prior to the signature +utils.pkg.sync([ + '--no-signature', + '--target', + target, + '--output', + output, + input, +]); const damage = fs.readFileSync(output); const boundary = 4096; @@ -34,6 +37,16 @@ damage[damage.length - 3 * boundary + 10] = 0x2; damage[damage.length - 4 * boundary + 10] = 0x2; fs.writeFileSync(output, damage); +if (process.platform === 'darwin') { + utils.spawn.sync( + 'codesign', + ['--no-strict', '-fs', '-', './' + path.basename(output)], + { + cwd: path.dirname(output), + } + ); +} + right = utils.spawn.sync('./' + path.basename(output), [], { cwd: path.dirname(output), stdio: 'pipe',