Skip to content

Commit 17b7ec4

Browse files
sonsurimtargos
authored andcommitted
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: #54061 Reviewed-By: James M Snell <[email protected]>
1 parent afbf2c0 commit 17b7ec4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/parallel/test-whatwg-readablestream.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,3 +1701,50 @@ class Source {
17011701
assert.deepStrictEqual(value, new Uint8Array([1, 1, 1]));
17021702
}));
17031703
}
1704+
1705+
// Initial Pull Delay
1706+
{
1707+
const stream = new ReadableStream({
1708+
start(controller) {
1709+
controller.enqueue('data');
1710+
controller.close();
1711+
}
1712+
});
1713+
1714+
const iterator = stream.values();
1715+
1716+
let microtaskCompleted = false;
1717+
Promise.resolve().then(() => { microtaskCompleted = true; });
1718+
1719+
iterator.next().then(common.mustCall(({ done, value }) => {
1720+
assert.strictEqual(done, false);
1721+
assert.strictEqual(value, 'data');
1722+
assert.strictEqual(microtaskCompleted, true);
1723+
}));
1724+
}
1725+
1726+
// Avoiding Prototype Pollution
1727+
{
1728+
const stream = new ReadableStream({
1729+
start(controller) {
1730+
controller.enqueue('data');
1731+
controller.close();
1732+
}
1733+
});
1734+
1735+
const iterator = stream.values();
1736+
1737+
// Modify Promise.prototype.then to simulate prototype pollution
1738+
const originalThen = Promise.prototype.then;
1739+
Promise.prototype.then = function(onFulfilled, onRejected) {
1740+
return originalThen.call(this, onFulfilled, onRejected);
1741+
};
1742+
1743+
iterator.next().then(common.mustCall(({ done, value }) => {
1744+
assert.strictEqual(done, false);
1745+
assert.strictEqual(value, 'data');
1746+
1747+
// Restore original then method
1748+
Promise.prototype.then = originalThen;
1749+
}));
1750+
}

0 commit comments

Comments
 (0)