summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-response-statuscode.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2016-04-19 20:49:45 -0400
committerJames M Snell <jasnell@gmail.com>2016-04-20 16:34:58 -0700
commit7e9b0dd6949aaa6afda4da9f41e1d60d9b3d6225 (patch)
tree32935d28db90e13caa917e7ddb62d40aca710971 /test/parallel/test-http-response-statuscode.js
parent0800c0aa7275bf389b157e1568fa61b59285ad86 (diff)
downloadandroid-node-v8-7e9b0dd6949aaa6afda4da9f41e1d60d9b3d6225.tar.gz
android-node-v8-7e9b0dd6949aaa6afda4da9f41e1d60d9b3d6225.tar.bz2
android-node-v8-7e9b0dd6949aaa6afda4da9f41e1d60d9b3d6225.zip
http: disallow sending obviously invalid status codes
PR-URL: https://github.com/nodejs/node/pull/6291 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-http-response-statuscode.js')
-rw-r--r--test/parallel/test-http-response-statuscode.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/parallel/test-http-response-statuscode.js b/test/parallel/test-http-response-statuscode.js
new file mode 100644
index 0000000000..43bf3aebff
--- /dev/null
+++ b/test/parallel/test-http-response-statuscode.js
@@ -0,0 +1,92 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const http = require('http');
+
+const MAX_REQUESTS = 12;
+var reqNum = 0;
+
+const server = http.Server(common.mustCall(function(req, res) {
+ switch (reqNum) {
+ case 0:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(-1);
+ }, /invalid status code/i));
+ break;
+ case 1:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(Infinity);
+ }, /invalid status code/i));
+ break;
+ case 2:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(NaN);
+ }, /invalid status code/i));
+ break;
+ case 3:
+ assert.throws(common.mustCall(() => {
+ res.writeHead({});
+ }, /invalid status code/i));
+ break;
+ case 4:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(99);
+ }, /invalid status code/i));
+ break;
+ case 5:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(1000);
+ }, /invalid status code/i));
+ break;
+ case 6:
+ assert.throws(common.mustCall(() => {
+ res.writeHead('1000');
+ }, /invalid status code/i));
+ break;
+ case 7:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(null);
+ }, /invalid status code/i));
+ break;
+ case 8:
+ assert.throws(common.mustCall(() => {
+ res.writeHead(true);
+ }, /invalid status code/i));
+ break;
+ case 9:
+ assert.throws(common.mustCall(() => {
+ res.writeHead([]);
+ }, /invalid status code/i));
+ break;
+ case 10:
+ assert.throws(common.mustCall(() => {
+ res.writeHead('this is not valid');
+ }, /invalid status code/i));
+ break;
+ case 11:
+ assert.throws(common.mustCall(() => {
+ res.writeHead('404 this is not valid either');
+ }, /invalid status code/i));
+ this.close();
+ break;
+ default:
+ throw new Error('Unexpected request');
+ }
+ res.statusCode = 200;
+ res.end();
+}, MAX_REQUESTS));
+server.listen();
+
+server.on('listening', function makeRequest() {
+ http.get({
+ port: this.address().port
+ }, (res) => {
+ assert.strictEqual(res.statusCode, 200);
+ res.on('end', () => {
+ if (++reqNum < MAX_REQUESTS)
+ makeRequest.call(this);
+ });
+ res.resume();
+ });
+});
+