Skip to content

Commit bc11b99

Browse files
committed
Fix typosquat test fail
1 parent 9157db5 commit bc11b99

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

test/socket-npm.test.cjs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,33 @@ for (const npmDir of ['npm8', 'npm10']) {
2929
const entryPath = path.join(constants.rootBinPath, 'cli.js')
3030

3131
it('should bail on new typosquat', async () => {
32-
await assert.rejects(
32+
await assert.doesNotReject(
3333
() =>
34-
spawn(
35-
// Lazily access constants.execPath.
36-
constants.execPath,
37-
[entryPath, NPM, 'install', 'bowserify'],
38-
{
39-
cwd: path.join(npmFixturesPath, 'lacking-typosquat'),
40-
encoding: 'utf8',
41-
env: {
42-
// Make sure we don't borrow TTY from parent.
43-
SOCKET_SECURITY_TTY_IPC: undefined,
44-
PATH: `${npmBinPath}:${process.env.PATH}`
45-
},
46-
signal: abortSignal
47-
}
48-
),
49-
e => e?.stderr.includes('Unable to prompt')
34+
new Promise((resolve, reject) => {
35+
const promise = spawn(
36+
// Lazily access constants.execPath.
37+
constants.execPath,
38+
[entryPath, NPM, 'install', 'bowserify'],
39+
{
40+
cwd: path.join(npmFixturesPath, 'lacking-typosquat'),
41+
encoding: 'utf8',
42+
env: {
43+
PATH: `${npmBinPath}:${process.env.PATH}`
44+
},
45+
signal: abortSignal
46+
}
47+
)
48+
promise.process.stderr.on('data', buffer => {
49+
if (buffer.toString().includes('Possible typosquat attack')) {
50+
promise.process.kill('SIGINT')
51+
resolve()
52+
}
53+
})
54+
promise.catch(() => {
55+
promise.process.kill('SIGINT')
56+
reject()
57+
})
58+
})
5059
)
5160
})
5261
})

0 commit comments

Comments
 (0)