Skip to content

Commit d6642b7

Browse files
committed
test: wrap inject + code signing part into a helper
Refs: #47588 (comment) Signed-off-by: Darshan Sen <[email protected]>
1 parent 009fe2f commit d6642b7

File tree

5 files changed

+128
-124
lines changed

5 files changed

+128
-124
lines changed

test/common/README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,6 @@ will not be run.
420420

421421
Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`.
422422

423-
### `skipIfSingleExecutableIsNotSupported()`
424-
425-
Skip the rest of the tests if single executable applications are not supported
426-
in the current configuration.
427-
428423
### `skipIfDumbTerminal()`
429424

430425
Skip the rest of the tests if the current terminal is a dumb terminal
@@ -996,6 +991,22 @@ Validates the schema of a diagnostic report file whose path is specified in
996991
Validates the schema of a diagnostic report whose content is specified in
997992
`report`. If the report fails validation, an exception is thrown.
998993

994+
## SEA Module
995+
996+
The `sea` module provides helper functions for testing Single Executable
997+
Application functionality.
998+
999+
### `skipIfSingleExecutableIsNotSupported()`
1000+
1001+
Skip the rest of the tests if single executable applications are not supported
1002+
in the current configuration.
1003+
1004+
### `injectAndCodeSign(targetExecutable, resource)`
1005+
1006+
Uses Postect to inject the contents of the file at the path `resource` into
1007+
the target executable file at the path `targetExecutable` and ultimately code
1008+
sign the final binary.
1009+
9991010
## tick Module
10001011

10011012
The `tick` module provides a helper function that can be used to call a callback

test/common/index.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -822,47 +822,6 @@ function invalidArgTypeHelper(input) {
822822
return ` Received type ${typeof input} (${inspected})`;
823823
}
824824

825-
function skipIfSingleExecutableIsNotSupported() {
826-
if (!process.config.variables.single_executable_application)
827-
skip('Single Executable Application support has been disabled.');
828-
829-
if (!['darwin', 'win32', 'linux'].includes(process.platform))
830-
skip(`Unsupported platform ${process.platform}.`);
831-
832-
if (process.platform === 'linux' && process.config.variables.is_debug === 1)
833-
skip('Running the resultant binary fails with `Couldn\'t read target executable"`.');
834-
835-
if (process.config.variables.node_shared)
836-
skip('Running the resultant binary fails with ' +
837-
'`/home/iojs/node-tmp/.tmp.2366/sea: error while loading shared libraries: ' +
838-
'libnode.so.112: cannot open shared object file: No such file or directory`.');
839-
840-
if (process.config.variables.icu_gyp_path === 'tools/icu/icu-system.gyp')
841-
skip('Running the resultant binary fails with ' +
842-
'`/home/iojs/node-tmp/.tmp.2379/sea: error while loading shared libraries: ' +
843-
'libicui18n.so.71: cannot open shared object file: No such file or directory`.');
844-
845-
if (!process.config.variables.node_use_openssl || process.config.variables.node_shared_openssl)
846-
skip('Running the resultant binary fails with `Node.js is not compiled with OpenSSL crypto support`.');
847-
848-
if (process.config.variables.want_separate_host_toolset !== 0)
849-
skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.');
850-
851-
if (process.platform === 'linux') {
852-
const osReleaseText = fs.readFileSync('/etc/os-release', { encoding: 'utf-8' });
853-
const isAlpine = /^NAME="Alpine Linux"/m.test(osReleaseText);
854-
if (isAlpine) skip('Alpine Linux is not supported.');
855-
856-
if (process.arch === 's390x') {
857-
skip('On s390x, postject fails with `memory access out of bounds`.');
858-
}
859-
860-
if (process.arch === 'ppc64') {
861-
skip('On ppc64, this test times out.');
862-
}
863-
}
864-
}
865-
866825
function skipIfDumbTerminal() {
867826
if (isDumbTerminal) {
868827
skip('skipping - dumb terminal');
@@ -985,7 +944,6 @@ const common = {
985944
runWithInvalidFD,
986945
skip,
987946
skipIf32Bits,
988-
skipIfSingleExecutableIsNotSupported,
989947
skipIfDumbTerminal,
990948
skipIfEslintMissing,
991949
skipIfInspectorDisabled,

test/common/sea.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fixtures = require('../common/fixtures');
5+
6+
const { readFileSync } = require('fs');
7+
const { execFileSync } = require('child_process');
8+
9+
function skipIfSingleExecutableIsNotSupported() {
10+
if (!process.config.variables.single_executable_application)
11+
common.skip('Single Executable Application support has been disabled.');
12+
13+
if (!['darwin', 'win32', 'linux'].includes(process.platform))
14+
common.skip(`Unsupported platform ${process.platform}.`);
15+
16+
if (process.platform === 'linux' && process.config.variables.is_debug === 1)
17+
common.skip('Running the resultant binary fails with `Couldn\'t read target executable"`.');
18+
19+
if (process.config.variables.node_shared)
20+
common.skip('Running the resultant binary fails with ' +
21+
'`/home/iojs/node-tmp/.tmp.2366/sea: error while loading shared libraries: ' +
22+
'libnode.so.112: cannot open shared object file: No such file or directory`.');
23+
24+
if (process.config.variables.icu_gyp_path === 'tools/icu/icu-system.gyp')
25+
common.skip('Running the resultant binary fails with ' +
26+
'`/home/iojs/node-tmp/.tmp.2379/sea: error while loading shared libraries: ' +
27+
'libicui18n.so.71: cannot open shared object file: No such file or directory`.');
28+
29+
if (!process.config.variables.node_use_openssl || process.config.variables.node_shared_openssl)
30+
common.skip('Running the resultant binary fails with `Node.js is not compiled with OpenSSL crypto support`.');
31+
32+
if (process.config.variables.want_separate_host_toolset !== 0)
33+
common.skip('Running the resultant binary fails with `Segmentation fault (core dumped)`.');
34+
35+
if (process.platform === 'linux') {
36+
const osReleaseText = readFileSync('/etc/os-release', { encoding: 'utf-8' });
37+
const isAlpine = /^NAME="Alpine Linux"/m.test(osReleaseText);
38+
if (isAlpine) common.skip('Alpine Linux is not supported.');
39+
40+
if (process.arch === 's390x') {
41+
common.skip('On s390x, postject fails with `memory access out of bounds`.');
42+
}
43+
44+
if (process.arch === 'ppc64') {
45+
common.skip('On ppc64, this test times out.');
46+
}
47+
}
48+
}
49+
50+
function injectAndCodeSign(targetExecutable, resource) {
51+
const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
52+
execFileSync(process.execPath, [
53+
postjectFile,
54+
targetExecutable,
55+
'NODE_SEA_BLOB',
56+
resource,
57+
'--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
58+
...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
59+
]);
60+
61+
if (process.platform === 'darwin') {
62+
execFileSync('codesign', [ '--sign', '-', targetExecutable ]);
63+
execFileSync('codesign', [ '--verify', targetExecutable ]);
64+
} else if (process.platform === 'win32') {
65+
let signtoolFound = false;
66+
try {
67+
execFileSync('where', [ 'signtool' ]);
68+
signtoolFound = true;
69+
} catch (err) {
70+
console.log(err.message);
71+
}
72+
if (signtoolFound) {
73+
let certificatesFound = false;
74+
try {
75+
execFileSync('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ]);
76+
certificatesFound = true;
77+
} catch (err) {
78+
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) {
79+
throw err;
80+
}
81+
}
82+
if (certificatesFound) {
83+
execFileSync('signtool', 'verify', '/pa', 'SHA256', targetExecutable);
84+
}
85+
}
86+
}
87+
}
88+
89+
module.exports = {
90+
skipIfSingleExecutableIsNotSupported,
91+
injectAndCodeSign,
92+
};

test/sequential/test-single-executable-application-disable-experimental-sea-warning.js

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
'use strict';
2-
const common = require('../common');
32

4-
common.skipIfSingleExecutableIsNotSupported();
3+
require('../common');
54

6-
// This tests the creation of a single executable application.
5+
const {
6+
injectAndCodeSign,
7+
skipIfSingleExecutableIsNotSupported,
8+
} = require('../common/sea');
9+
10+
skipIfSingleExecutableIsNotSupported();
11+
12+
// This tests the creation of a single executable application which has the
13+
// experimental SEA warning disabled.
714

815
const fixtures = require('../common/fixtures');
916
const tmpdir = require('../common/tmpdir');
@@ -44,42 +51,7 @@ execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'],
4451
assert(existsSync(seaPrepBlob));
4552

4653
copyFileSync(process.execPath, outputFile);
47-
const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
48-
execFileSync(process.execPath, [
49-
postjectFile,
50-
outputFile,
51-
'NODE_SEA_BLOB',
52-
seaPrepBlob,
53-
'--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
54-
...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
55-
]);
56-
57-
if (process.platform === 'darwin') {
58-
execFileSync('codesign', [ '--sign', '-', outputFile ]);
59-
execFileSync('codesign', [ '--verify', outputFile ]);
60-
} else if (process.platform === 'win32') {
61-
let signtoolFound = false;
62-
try {
63-
execFileSync('where', [ 'signtool' ]);
64-
signtoolFound = true;
65-
} catch (err) {
66-
console.log(err.message);
67-
}
68-
if (signtoolFound) {
69-
let certificatesFound = false;
70-
try {
71-
execFileSync('signtool', [ 'sign', '/fd', 'SHA256', outputFile ]);
72-
certificatesFound = true;
73-
} catch (err) {
74-
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) {
75-
throw err;
76-
}
77-
}
78-
if (certificatesFound) {
79-
execFileSync('signtool', 'verify', '/pa', 'SHA256', outputFile);
80-
}
81-
}
82-
}
54+
injectAndCodeSign(outputFile, seaPrepBlob);
8355

8456
const singleExecutableApplicationOutput = execFileSync(
8557
outputFile,

test/sequential/test-single-executable-application.js

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
'use strict';
2-
const common = require('../common');
32

4-
common.skipIfSingleExecutableIsNotSupported();
3+
require('../common');
4+
5+
const {
6+
injectAndCodeSign,
7+
skipIfSingleExecutableIsNotSupported,
8+
} = require('../common/sea');
9+
10+
skipIfSingleExecutableIsNotSupported();
511

612
// This tests the creation of a single executable application.
713

@@ -44,42 +50,7 @@ execFileSync(process.execPath, ['--experimental-sea-config', 'sea-config.json'],
4450
assert(existsSync(seaPrepBlob));
4551

4652
copyFileSync(process.execPath, outputFile);
47-
const postjectFile = fixtures.path('postject-copy', 'node_modules', 'postject', 'dist', 'cli.js');
48-
execFileSync(process.execPath, [
49-
postjectFile,
50-
outputFile,
51-
'NODE_SEA_BLOB',
52-
seaPrepBlob,
53-
'--sentinel-fuse', 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
54-
...process.platform === 'darwin' ? [ '--macho-segment-name', 'NODE_SEA' ] : [],
55-
]);
56-
57-
if (process.platform === 'darwin') {
58-
execFileSync('codesign', [ '--sign', '-', outputFile ]);
59-
execFileSync('codesign', [ '--verify', outputFile ]);
60-
} else if (process.platform === 'win32') {
61-
let signtoolFound = false;
62-
try {
63-
execFileSync('where', [ 'signtool' ]);
64-
signtoolFound = true;
65-
} catch (err) {
66-
console.log(err.message);
67-
}
68-
if (signtoolFound) {
69-
let certificatesFound = false;
70-
try {
71-
execFileSync('signtool', [ 'sign', '/fd', 'SHA256', outputFile ]);
72-
certificatesFound = true;
73-
} catch (err) {
74-
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(err)) {
75-
throw err;
76-
}
77-
}
78-
if (certificatesFound) {
79-
execFileSync('signtool', 'verify', '/pa', 'SHA256', outputFile);
80-
}
81-
}
82-
}
53+
injectAndCodeSign(outputFile, seaPrepBlob);
8354

8455
const singleExecutableApplicationOutput = execFileSync(
8556
outputFile,

0 commit comments

Comments
 (0)