refactor(ses): refactor console init and test cleanup #1941
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.
closes: #XXXX
refs: #1345 #1942
Description
A flaw in tame-console.js made it hard to use throws-and-logs.js to test the console output that happens during lockdown. The flaw is that tame-console.js read the value of the global
console
variable at initialization, rather than whentameConsole()
is called. This PR moves that initialization code intotameConsole
, which is highly unlikely to break any working code.Using that fix, this PR also tests the current behavior that #1345 complains about. A later PR #1942 will fix that problem, building on this PR so that the difference is itself tested.
Security Considerations
Prior to this PR, tame-console.js used
console
andprint
as ambient globals without a/* global ... */
annotation. Forconsole
this is not surprising, as we generally assume this is ambiently available. But forprint
it is surprising. Do we have a bug in our lint diagnostic framework? Attn @kriskowalIn any case, this PR changes those specifically to
globalThis.console
andglobalThis.print
, where thatglobalThis
is itself obtained fromcommons.js
.Moving the sampling of these globals into
tameConsole()
enables them to be changed beforetameConsole()
samples them, as we now intend. This should have zero security implications as these will still be sampled beforelockdown()
returns.Scaling Considerations
none
Documentation Considerations
none
Testing Considerations
Moving the sampling of
console
this way should enable other uses ofthrows-and-logs.js
for testing console output that would not work before this PR.Upgrade Considerations
none.