-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: refactor and harden ProcessEmitWarning()
#17420
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2bb2ed1
src: refactor and harden `ProcessEmitWarning()`
addaleax 657555d
[squash] indentation
addaleax bb5ba30
[squash] bnoordhuis & AndreasMadsen nits
addaleax 1c72f29
[squash] bnoordhuis comment
addaleax 35d3c42
[squash] skip test in FIPS mode
addaleax a9613ac
[squash] skip environment variable encoding test on windows
addaleax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
if (common.hasFipsCrypto) | ||
common.skip('crypto.createCipher() is not supported in FIPS mode'); | ||
|
||
const crypto = require('crypto'); | ||
const key = '0123456789'; | ||
|
||
{ | ||
common.expectWarning('Warning', | ||
'Use Cipheriv for counter mode of aes-256-gcm'); | ||
|
||
// Emits regular warning expected by expectWarning() | ||
crypto.createCipher('aes-256-gcm', key); | ||
} | ||
|
||
const realEmitWarning = process.emitWarning; | ||
|
||
{ | ||
// It's a good idea to make this overridable from userland. | ||
process.emitWarning = () => { throw new Error('foo'); }; | ||
assert.throws(() => { | ||
crypto.createCipher('aes-256-gcm', key); | ||
}, /^Error: foo$/); | ||
} | ||
|
||
{ | ||
Object.defineProperty(process, 'emitWarning', { | ||
get() { throw new Error('bar'); }, | ||
configurable: true | ||
}); | ||
assert.throws(() => { | ||
crypto.createCipher('aes-256-gcm', key); | ||
}, /^Error: bar$/); | ||
} | ||
|
||
// Reset back to default after the test. | ||
Object.defineProperty(process, 'emitWarning', { | ||
value: realEmitWarning, | ||
configurable: true, | ||
writable: true | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ if (process.env.CHILD) { | |
|
||
const env = Object.assign({}, process.env, { | ||
CHILD: 'yes', | ||
NODE_EXTRA_CA_CERTS: `${fixtures.fixturesDir}/no-such-file-exists`, | ||
NODE_EXTRA_CA_CERTS: `${fixtures.fixturesDir}/no-such-file-exists-🐢`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha :-) |
||
}); | ||
|
||
const opts = { | ||
|
@@ -32,8 +32,12 @@ fork(__filename, opts) | |
assert.strictEqual(status, 0, 'client did not succeed in connecting'); | ||
})) | ||
.on('close', common.mustCall(function() { | ||
const re = /Warning: Ignoring extra certs from.*no-such-file-exists.* load failed:.*No such file or directory/; | ||
assert(re.test(stderr), stderr); | ||
// TODO(addaleax): Make `SafeGetenv` work like `process.env` | ||
// encoding-wise | ||
if (!common.isWindows) { | ||
const re = /Warning: Ignoring extra certs from.*no-such-file-exists-🐢.* load failed:.*No such file or directory/; | ||
assert(re.test(stderr), stderr); | ||
} | ||
})) | ||
.stderr.setEncoding('utf8').on('data', function(str) { | ||
stderr += str; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
process.emitWarning
is supposed to be overwritable, as your test says. Then we should useMakeCallback
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh … I am not sure. There is usually always a JS call stack below, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that won't be true for the
domain
MakeCallback
deprecation. Anything could callMakeCallback
in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. True. But that would put us in a pretty difficult position if
process.domain
happens to be set in that case (by accident), sinceprocess
would be the resource object?So, I am okay with changing this but I’m not sure where we’d get the async context to use for
MakeCallback
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is a general problem. We have
process.on('beforeExit')
,process.on('exit')
without context as well. In this case I think there are two options:async_context
for theprocess
, and use that.async_context
withasync_context_.async_id
as thetriggerAsyncId
.The latter option is better for this case but I don't see it working in general for all
ProcessEmitWarningGeneric
use cases.