diff --git a/tests/post-limiting-test.js b/tests/post-limiting-test.js index b2e5ca2f70df5b3dac5155f52064fda95d7475cf..9ea67608a9c651050486768ab89caa7b926f9bb0 100755 --- a/tests/post-limiting-test.js +++ b/tests/post-limiting-test.js @@ -22,61 +22,68 @@ suite.options.error = false; start_stop.addStartupBatches(suite); -// test posting more than 10kb -suite.addBatch({ - "posting more than 10kb": { - topic: function(assertion) { - var cb = this.callback; - var req = http.request({ - host: '127.0.0.1', - port: 10002, - path: '/wsapi/authenticate_user', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - method: "POST" - }, function (res) { - cb(null, res); - }).on('error', function (e) { - cb(e); - }); - req.write(secrets.weakGenerate(1024 * 10 + 1)); - req.end(); - }, - "fails": function (err, r) { - assert.ok(/socket hang up/.test(err.toString())); +function addTests(port, path) { + // test posting more than 10kb + suite.addBatch({ + "posting more than 10kb": { + topic: function(assertion) { + var cb = this.callback; + var req = http.request({ + host: '127.0.0.1', + port: port, + path: path, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + method: "POST" + }, function (res) { + cb(null, res); + }).on('error', function (e) { + cb(e); + }); + req.write(secrets.weakGenerate(1024 * 10 + 1)); + req.end(); + }, + "fails": function (err, r) { + assert.ok(/socket hang up/.test(err.toString())); + } } - } -}); + }); -// test posting more than 10kb with content-length header -suite.addBatch({ - "posting more than 10kb with content-length": { - topic: function(assertion) { - var cb = this.callback; - var req = http.request({ - host: '127.0.0.1', - port: 10002, - path: '/wsapi/authenticate_user', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Content-Length': 1024 * 10 + 1 - }, - method: "POST" - }, function (res) { - cb(null, res); - }).on('error', function (e) { - cb(e); - }); - req.write(secrets.weakGenerate(1024 * 10 + 1)); - req.end(); - }, - "fails": function (err, r) { - assert.strictEqual(413, r.statusCode); + // test posting more than 10kb with content-length header + suite.addBatch({ + "posting more than 10kb with content-length": { + topic: function(assertion) { + var cb = this.callback; + var req = http.request({ + host: '127.0.0.1', + port: port, + path: path, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': 1024 * 10 + 1 + }, + method: "POST" + }, function (res) { + cb(null, res); + }).on('error', function (e) { + cb(e); + }); + req.write(secrets.weakGenerate(1024 * 10 + 1)); + req.end(); + }, + "fails": function (err, r) { + assert.strictEqual(413, r.statusCode); + } } - } -}); + }); +}; +// test the browserid process +addTests(10002, '/wsapi/authenticate_user'); + +// test the verifier +addTests(10000, '/verify'); start_stop.addShutdownBatches(suite);