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 : refactored test-http-response-splitting to use countdown #17348

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions test/parallel/test-http-response-splitting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const http = require('http');
const net = require('net');
const url = require('url');
const assert = require('assert');
const Countdown = require('../common/countdown');

// Response splitting example, credit: Amit Klein, Safebreach
const str = '/welcome?lang=bar%c4%8d%c4%8aContent­Length:%200%c4%8d%c4%8a%c' +
Expand All @@ -18,6 +19,7 @@ const x = 'fooഊSet-Cookie: foo=barഊഊ<script>alert("Hi!")</script>';
const y = 'foo⠊Set-Cookie: foo=bar';

let count = 0;
const countdown = new Countdown(3, () => server.close());

function test(res, code, key, value) {
const header = { [key]: value };
Expand Down Expand Up @@ -46,8 +48,7 @@ const server = http.createServer((req, res) => {
default:
assert.fail('should not get to here.');
}
if (count === 3)
server.close();
countdown.dec();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the count variable itself, if we can return the current value from Countdown.dec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye : For what you've suggested.. the dec() returns the remaining count and not current count right... return this[kLimit]
So I guess we would need the count variable being used in switch else I'll have to do limit - countdown.remaining() or something to get the current count..Correct me if I'm wrong... we're counting down right...!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's okay. That can be done in a separate PR though. I think that would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye : I'll have it done over another PR !

res.end('ok');
});
server.listen(0, () => {
Expand Down