Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

chore: make corruption test pass on macos #1890

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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