Skip to content
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

test: add initial pull delay and prototype pollution prevention tests for ReadableStream #54061

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions test/parallel/test-whatwg-readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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