mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: add initial pull delay and prototype pollution prevention tests
Refs : https://github.com/nodejs/node/blob/main/lib/internal/webstreams/readablestream.js#L522-L536 PR-URL: https://github.com/nodejs/node/pull/54061 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
5d6c76adee
commit
d172da8d01
@ -1701,3 +1701,50 @@ class Source {
|
||||
assert.deepStrictEqual(value, new Uint8Array([1, 1, 1]));
|
||||
}));
|
||||
}
|
||||
|
||||
// Initial Pull Delay
|
||||
{
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue('data');
|
||||
controller.close();
|
||||
}
|
||||
});
|
||||
|
||||
const iterator = stream.values();
|
||||
|
||||
let microtaskCompleted = false;
|
||||
Promise.resolve().then(() => { microtaskCompleted = true; });
|
||||
|
||||
iterator.next().then(common.mustCall(({ done, value }) => {
|
||||
assert.strictEqual(done, false);
|
||||
assert.strictEqual(value, 'data');
|
||||
assert.strictEqual(microtaskCompleted, true);
|
||||
}));
|
||||
}
|
||||
|
||||
// Avoiding Prototype Pollution
|
||||
{
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue('data');
|
||||
controller.close();
|
||||
}
|
||||
});
|
||||
|
||||
const iterator = stream.values();
|
||||
|
||||
// Modify Promise.prototype.then to simulate prototype pollution
|
||||
const originalThen = Promise.prototype.then;
|
||||
Promise.prototype.then = function(onFulfilled, onRejected) {
|
||||
return originalThen.call(this, onFulfilled, onRejected);
|
||||
};
|
||||
|
||||
iterator.next().then(common.mustCall(({ done, value }) => {
|
||||
assert.strictEqual(done, false);
|
||||
assert.strictEqual(value, 'data');
|
||||
|
||||
// Restore original then method
|
||||
Promise.prototype.then = originalThen;
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user