Skip to content

Commit

Permalink
chore: make corruption test pass on macos (vercel#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikescops committed Mar 20, 2023
1 parent e388983 commit 8eef5ea
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions test/test-50-corrupt-executable/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ 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';
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;
Expand All @@ -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',
Expand Down

0 comments on commit 8eef5ea

Please sign in to comment.