tests: add express.urlencoded test suite
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 955f2a5 · Browse files · 3 files·+740 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+740 added−1 removed
- tests:+740 added−1 removed
Provenance
- Commit
8b71f39- Tree
eb227e9- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
955f2a5
3 files changed+740 added−1 removed
modified:test/support/env.js+1 added-1 removed
1233
process.env.NODE_ENV = 'test';process.env.NO_DEPRECATION = 'express';process.env.NO_DEPRECATION = 'body-parser,express';modified:test/exports.js+5 added
12 unmodified lines1314151617181920212223242547 unmodified lines12 unmodified lines assert.equal(typeof express.json, 'function') assert.equal(express.json.length, 1) })
it('should expose urlencoded middleware', function () { assert.equal(typeof express.urlencoded, 'function') assert.equal(express.urlencoded.length, 1) })
it('should expose the application prototype', function(){ express.application.set.should.be.a.Function() })
47 unmodified linesadded:test/express.urlencoded.js+734 added
1+2+var assert = require('assert')3+var Buffer = require('safe-buffer').Buffer4+var express = require('..')5+var request = require('supertest')6+7+describe('express.urlencoded()', function () {8+ before(function () {9+ this.app = createApp()10+ })11+12+ it('should parse x-www-form-urlencoded', function (done) {13+ request(this.app)14+ .post('/')15+ .set('Content-Type', 'application/x-www-form-urlencoded')16+ .send('user=tobi')17+ .expect(200, '{"user":"tobi"}', done)18+ })19+20+ it('should 400 when invalid content-length', function (done) {21+ var app = express()22+23+ app.use(function (req, res, next) {24+ req.headers['content-length'] = '20' // bad length25+ next()26+ })27+28+ app.use(express.urlencoded())29+30+ app.post('/', function (req, res) {31+ res.json(req.body)32+ })33+34+ request(app)35+ .post('/')36+ .set('Content-Type', 'application/x-www-form-urlencoded')37+ .send('str=')38+ .expect(400, /content length/, done)39+ })40+41+ it('should handle Content-Length: 0', function (done) {42+ request(this.app)43+ .post('/')44+ .set('Content-Type', 'application/x-www-form-urlencoded')45+ .set('Content-Length', '0')46+ .send('')47+ .expect(200, '{}', done)48+ })49+50+ it('should handle empty message-body', function (done) {51+ request(createApp({ limit: '1kb' }))52+ .post('/')53+ .set('Content-Type', 'application/x-www-form-urlencoded')54+ .set('Transfer-Encoding', 'chunked')55+ .send('')56+ .expect(200, '{}', done)57+ })58+59+ it('should handle duplicated middleware', function (done) {60+ var app = express()61+62+ app.use(express.urlencoded())63+ app.use(express.urlencoded())64+65+ app.post('/', function (req, res) {66+ res.json(req.body)67+ })68+69+ request(app)70+ .post('/')71+ .set('Content-Type', 'application/x-www-form-urlencoded')72+ .send('user=tobi')73+ .expect(200, '{"user":"tobi"}', done)74+ })75+76+ it('should parse extended syntax', function (done) {77+ request(this.app)78+ .post('/')79+ .set('Content-Type', 'application/x-www-form-urlencoded')80+ .send('user[name][first]=Tobi')81+ .expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)82+ })83+84+ describe('with extended option', function () {85+ describe('when false', function () {86+ before(function () {87+ this.app = createApp({ extended: false })88+ })89+90+ it('should not parse extended syntax', function (done) {91+ request(this.app)92+ .post('/')93+ .set('Content-Type', 'application/x-www-form-urlencoded')94+ .send('user[name][first]=Tobi')95+ .expect(200, '{"user[name][first]":"Tobi"}', done)96+ })97+98+ it('should parse multiple key instances', function (done) {99+ request(this.app)100+ .post('/')101+ .set('Content-Type', 'application/x-www-form-urlencoded')102+ .send('user=Tobi&user=Loki')103+ .expect(200, '{"user":["Tobi","Loki"]}', done)104+ })105+ })106+107+ describe('when true', function () {108+ before(function () {109+ this.app = createApp({ extended: true })110+ })111+112+ it('should parse multiple key instances', function (done) {113+ request(this.app)114+ .post('/')115+ .set('Content-Type', 'application/x-www-form-urlencoded')116+ .send('user=Tobi&user=Loki')117+ .expect(200, '{"user":["Tobi","Loki"]}', done)118+ })119+120+ it('should parse extended syntax', function (done) {121+ request(this.app)122+ .post('/')123+ .set('Content-Type', 'application/x-www-form-urlencoded')124+ .send('user[name][first]=Tobi')125+ .expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)126+ })127+128+ it('should parse parameters with dots', function (done) {129+ request(this.app)130+ .post('/')131+ .set('Content-Type', 'application/x-www-form-urlencoded')132+ .send('user.name=Tobi')133+ .expect(200, '{"user.name":"Tobi"}', done)134+ })135+136+ it('should parse fully-encoded extended syntax', function (done) {137+ request(this.app)138+ .post('/')139+ .set('Content-Type', 'application/x-www-form-urlencoded')140+ .send('user%5Bname%5D%5Bfirst%5D=Tobi')141+ .expect(200, '{"user":{"name":{"first":"Tobi"}}}', done)142+ })143+144+ it('should parse array index notation', function (done) {145+ request(this.app)146+ .post('/')147+ .set('Content-Type', 'application/x-www-form-urlencoded')148+ .send('foo[0]=bar&foo[1]=baz')149+ .expect(200, '{"foo":["bar","baz"]}', done)150+ })151+152+ it('should parse array index notation with large array', function (done) {153+ var str = 'f[0]=0'154+155+ for (var i = 1; i < 500; i++) {156+ str += '&f[' + i + ']=' + i.toString(16)157+ }158+159+ request(this.app)160+ .post('/')161+ .set('Content-Type', 'application/x-www-form-urlencoded')162+ .send(str)163+ .expect(function (res) {164+ var obj = JSON.parse(res.text)165+ assert.strictEqual(Object.keys(obj).length, 1)166+ assert.strictEqual(Array.isArray(obj.f), true)167+ assert.strictEqual(obj.f.length, 500)168+ })169+ .expect(200, done)170+ })171+172+ it('should parse array of objects syntax', function (done) {173+ request(this.app)174+ .post('/')175+ .set('Content-Type', 'application/x-www-form-urlencoded')176+ .send('foo[0][bar]=baz&foo[0][fizz]=buzz&foo[]=done!')177+ .expect(200, '{"foo":[{"bar":"baz","fizz":"buzz"},"done!"]}', done)178+ })179+180+ it('should parse deep object', function (done) {181+ var str = 'foo'182+183+ for (var i = 0; i < 500; i++) {184+ str += '[p]'185+ }186+187+ str += '=bar'188+189+ request(this.app)190+ .post('/')191+ .set('Content-Type', 'application/x-www-form-urlencoded')192+ .send(str)193+ .expect(function (res) {194+ var obj = JSON.parse(res.text)195+ assert.strictEqual(Object.keys(obj).length, 1)196+ assert.strictEqual(typeof obj.foo, 'object')197+198+ var depth = 0199+ var ref = obj.foo200+ while ((ref = ref.p)) { depth++ }201+ assert.strictEqual(depth, 500)202+ })203+ .expect(200, done)204+ })205+ })206+ })207+208+ describe('with inflate option', function () {209+ describe('when false', function () {210+ before(function () {211+ this.app = createApp({ inflate: false })212+ })213+214+ it('should not accept content-encoding', function (done) {215+ var test = request(this.app).post('/')216+ test.set('Content-Encoding', 'gzip')217+ test.set('Content-Type', 'application/x-www-form-urlencoded')218+ test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))219+ test.expect(415, 'content encoding unsupported', done)220+ })221+ })222+223+ describe('when true', function () {224+ before(function () {225+ this.app = createApp({ inflate: true })226+ })227+228+ it('should accept content-encoding', function (done) {229+ var test = request(this.app).post('/')230+ test.set('Content-Encoding', 'gzip')231+ test.set('Content-Type', 'application/x-www-form-urlencoded')232+ test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))233+ test.expect(200, '{"name":"论"}', done)234+ })235+ })236+ })237+238+ describe('with limit option', function () {239+ it('should 413 when over limit with Content-Length', function (done) {240+ var buf = Buffer.alloc(1024, '.')241+ request(createApp({ limit: '1kb' }))242+ .post('/')243+ .set('Content-Type', 'application/x-www-form-urlencoded')244+ .set('Content-Length', '1028')245+ .send('str=' + buf.toString())246+ .expect(413, done)247+ })248+249+ it('should 413 when over limit with chunked encoding', function (done) {250+ var buf = Buffer.alloc(1024, '.')251+ var app = createApp({ limit: '1kb' })252+ var test = request(app).post('/')253+ test.set('Content-Type', 'application/x-www-form-urlencoded')254+ test.set('Transfer-Encoding', 'chunked')255+ test.write('str=')256+ test.write(buf.toString())257+ test.expect(413, done)258+ })259+260+ it('should accept number of bytes', function (done) {261+ var buf = Buffer.alloc(1024, '.')262+ request(createApp({ limit: 1024 }))263+ .post('/')264+ .set('Content-Type', 'application/x-www-form-urlencoded')265+ .send('str=' + buf.toString())266+ .expect(413, done)267+ })268+269+ it('should not change when options altered', function (done) {270+ var buf = Buffer.alloc(1024, '.')271+ var options = { limit: '1kb' }272+ var app = createApp(options)273+274+ options.limit = '100kb'275+276+ request(app)277+ .post('/')278+ .set('Content-Type', 'application/x-www-form-urlencoded')279+ .send('str=' + buf.toString())280+ .expect(413, done)281+ })282+283+ it('should not hang response', function (done) {284+ var buf = Buffer.alloc(10240, '.')285+ var app = createApp({ limit: '8kb' })286+ var test = request(app).post('/')287+ test.set('Content-Type', 'application/x-www-form-urlencoded')288+ test.write(buf)289+ test.write(buf)290+ test.write(buf)291+ test.expect(413, done)292+ })293+ })294+295+ describe('with parameterLimit option', function () {296+ describe('with extended: false', function () {297+ it('should reject 0', function () {298+ assert.throws(createApp.bind(null, { extended: false, parameterLimit: 0 }),299+ /TypeError: option parameterLimit must be a positive number/)300+ })301+302+ it('should reject string', function () {303+ assert.throws(createApp.bind(null, { extended: false, parameterLimit: 'beep' }),304+ /TypeError: option parameterLimit must be a positive number/)305+ })306+307+ it('should 413 if over limit', function (done) {308+ request(createApp({ extended: false, parameterLimit: 10 }))309+ .post('/')310+ .set('Content-Type', 'application/x-www-form-urlencoded')311+ .send(createManyParams(11))312+ .expect(413, /too many parameters/, done)313+ })314+315+ it('should error with type = "parameters.too.many"', function (done) {316+ request(createApp({ extended: false, parameterLimit: 10 }))317+ .post('/')318+ .set('Content-Type', 'application/x-www-form-urlencoded')319+ .set('X-Error-Property', 'type')320+ .send(createManyParams(11))321+ .expect(413, 'parameters.too.many', done)322+ })323+324+ it('should work when at the limit', function (done) {325+ request(createApp({ extended: false, parameterLimit: 10 }))326+ .post('/')327+ .set('Content-Type', 'application/x-www-form-urlencoded')328+ .send(createManyParams(10))329+ .expect(expectKeyCount(10))330+ .expect(200, done)331+ })332+333+ it('should work if number is floating point', function (done) {334+ request(createApp({ extended: false, parameterLimit: 10.1 }))335+ .post('/')336+ .set('Content-Type', 'application/x-www-form-urlencoded')337+ .send(createManyParams(11))338+ .expect(413, /too many parameters/, done)339+ })340+341+ it('should work with large limit', function (done) {342+ request(createApp({ extended: false, parameterLimit: 5000 }))343+ .post('/')344+ .set('Content-Type', 'application/x-www-form-urlencoded')345+ .send(createManyParams(5000))346+ .expect(expectKeyCount(5000))347+ .expect(200, done)348+ })349+350+ it('should work with Infinity limit', function (done) {351+ request(createApp({ extended: false, parameterLimit: Infinity }))352+ .post('/')353+ .set('Content-Type', 'application/x-www-form-urlencoded')354+ .send(createManyParams(10000))355+ .expect(expectKeyCount(10000))356+ .expect(200, done)357+ })358+ })359+360+ describe('with extended: true', function () {361+ it('should reject 0', function () {362+ assert.throws(createApp.bind(null, { extended: true, parameterLimit: 0 }),363+ /TypeError: option parameterLimit must be a positive number/)364+ })365+366+ it('should reject string', function () {367+ assert.throws(createApp.bind(null, { extended: true, parameterLimit: 'beep' }),368+ /TypeError: option parameterLimit must be a positive number/)369+ })370+371+ it('should 413 if over limit', function (done) {372+ request(createApp({ extended: true, parameterLimit: 10 }))373+ .post('/')374+ .set('Content-Type', 'application/x-www-form-urlencoded')375+ .send(createManyParams(11))376+ .expect(413, /too many parameters/, done)377+ })378+379+ it('should error with type = "parameters.too.many"', function (done) {380+ request(createApp({ extended: true, parameterLimit: 10 }))381+ .post('/')382+ .set('Content-Type', 'application/x-www-form-urlencoded')383+ .set('X-Error-Property', 'type')384+ .send(createManyParams(11))385+ .expect(413, 'parameters.too.many', done)386+ })387+388+ it('should work when at the limit', function (done) {389+ request(createApp({ extended: true, parameterLimit: 10 }))390+ .post('/')391+ .set('Content-Type', 'application/x-www-form-urlencoded')392+ .send(createManyParams(10))393+ .expect(expectKeyCount(10))394+ .expect(200, done)395+ })396+397+ it('should work if number is floating point', function (done) {398+ request(createApp({ extended: true, parameterLimit: 10.1 }))399+ .post('/')400+ .set('Content-Type', 'application/x-www-form-urlencoded')401+ .send(createManyParams(11))402+ .expect(413, /too many parameters/, done)403+ })404+405+ it('should work with large limit', function (done) {406+ request(createApp({ extended: true, parameterLimit: 5000 }))407+ .post('/')408+ .set('Content-Type', 'application/x-www-form-urlencoded')409+ .send(createManyParams(5000))410+ .expect(expectKeyCount(5000))411+ .expect(200, done)412+ })413+414+ it('should work with Infinity limit', function (done) {415+ request(createApp({ extended: true, parameterLimit: Infinity }))416+ .post('/')417+ .set('Content-Type', 'application/x-www-form-urlencoded')418+ .send(createManyParams(10000))419+ .expect(expectKeyCount(10000))420+ .expect(200, done)421+ })422+ })423+ })424+425+ describe('with type option', function () {426+ describe('when "application/vnd.x-www-form-urlencoded"', function () {427+ before(function () {428+ this.app = createApp({ type: 'application/vnd.x-www-form-urlencoded' })429+ })430+431+ it('should parse for custom type', function (done) {432+ request(this.app)433+ .post('/')434+ .set('Content-Type', 'application/vnd.x-www-form-urlencoded')435+ .send('user=tobi')436+ .expect(200, '{"user":"tobi"}', done)437+ })438+439+ it('should ignore standard type', function (done) {440+ request(this.app)441+ .post('/')442+ .set('Content-Type', 'application/x-www-form-urlencoded')443+ .send('user=tobi')444+ .expect(200, '{}', done)445+ })446+ })447+448+ describe('when ["urlencoded", "application/x-pairs"]', function () {449+ before(function () {450+ this.app = createApp({451+ type: ['urlencoded', 'application/x-pairs']452+ })453+ })454+455+ it('should parse "application/x-www-form-urlencoded"', function (done) {456+ request(this.app)457+ .post('/')458+ .set('Content-Type', 'application/x-www-form-urlencoded')459+ .send('user=tobi')460+ .expect(200, '{"user":"tobi"}', done)461+ })462+463+ it('should parse "application/x-pairs"', function (done) {464+ request(this.app)465+ .post('/')466+ .set('Content-Type', 'application/x-pairs')467+ .send('user=tobi')468+ .expect(200, '{"user":"tobi"}', done)469+ })470+471+ it('should ignore application/x-foo', function (done) {472+ request(this.app)473+ .post('/')474+ .set('Content-Type', 'application/x-foo')475+ .send('user=tobi')476+ .expect(200, '{}', done)477+ })478+ })479+480+ describe('when a function', function () {481+ it('should parse when truthy value returned', function (done) {482+ var app = createApp({ type: accept })483+484+ function accept (req) {485+ return req.headers['content-type'] === 'application/vnd.something'486+ }487+488+ request(app)489+ .post('/')490+ .set('Content-Type', 'application/vnd.something')491+ .send('user=tobi')492+ .expect(200, '{"user":"tobi"}', done)493+ })494+495+ it('should work without content-type', function (done) {496+ var app = createApp({ type: accept })497+498+ function accept (req) {499+ return true500+ }501+502+ var test = request(app).post('/')503+ test.write('user=tobi')504+ test.expect(200, '{"user":"tobi"}', done)505+ })506+507+ it('should not invoke without a body', function (done) {508+ var app = createApp({ type: accept })509+510+ function accept (req) {511+ throw new Error('oops!')512+ }513+514+ request(app)515+ .get('/')516+ .expect(404, done)517+ })518+ })519+ })520+521+ describe('with verify option', function () {522+ it('should assert value if function', function () {523+ assert.throws(createApp.bind(null, { verify: 'lol' }),524+ /TypeError: option verify must be function/)525+ })526+527+ it('should error from verify', function (done) {528+ var app = createApp({ verify: function (req, res, buf) {529+ if (buf[0] === 0x20) throw new Error('no leading space')530+ } })531+532+ request(app)533+ .post('/')534+ .set('Content-Type', 'application/x-www-form-urlencoded')535+ .send(' user=tobi')536+ .expect(403, 'no leading space', done)537+ })538+539+ it('should error with type = "entity.verify.failed"', function (done) {540+ var app = createApp({ verify: function (req, res, buf) {541+ if (buf[0] === 0x20) throw new Error('no leading space')542+ } })543+544+ request(app)545+ .post('/')546+ .set('Content-Type', 'application/x-www-form-urlencoded')547+ .set('X-Error-Property', 'type')548+ .send(' user=tobi')549+ .expect(403, 'entity.verify.failed', done)550+ })551+552+ it('should allow custom codes', function (done) {553+ var app = createApp({ verify: function (req, res, buf) {554+ if (buf[0] !== 0x20) return555+ var err = new Error('no leading space')556+ err.status = 400557+ throw err558+ } })559+560+ request(app)561+ .post('/')562+ .set('Content-Type', 'application/x-www-form-urlencoded')563+ .send(' user=tobi')564+ .expect(400, 'no leading space', done)565+ })566+567+ it('should allow custom type', function (done) {568+ var app = createApp({ verify: function (req, res, buf) {569+ if (buf[0] !== 0x20) return570+ var err = new Error('no leading space')571+ err.type = 'foo.bar'572+ throw err573+ } })574+575+ request(app)576+ .post('/')577+ .set('Content-Type', 'application/x-www-form-urlencoded')578+ .set('X-Error-Property', 'type')579+ .send(' user=tobi')580+ .expect(403, 'foo.bar', done)581+ })582+583+ it('should allow pass-through', function (done) {584+ var app = createApp({ verify: function (req, res, buf) {585+ if (buf[0] === 0x5b) throw new Error('no arrays')586+ } })587+588+ request(app)589+ .post('/')590+ .set('Content-Type', 'application/x-www-form-urlencoded')591+ .send('user=tobi')592+ .expect(200, '{"user":"tobi"}', done)593+ })594+595+ it('should 415 on unknown charset prior to verify', function (done) {596+ var app = createApp({ verify: function (req, res, buf) {597+ throw new Error('unexpected verify call')598+ } })599+600+ var test = request(app).post('/')601+ test.set('Content-Type', 'application/x-www-form-urlencoded; charset=x-bogus')602+ test.write(Buffer.from('00000000', 'hex'))603+ test.expect(415, 'unsupported charset "X-BOGUS"', done)604+ })605+ })606+607+ describe('charset', function () {608+ before(function () {609+ this.app = createApp()610+ })611+612+ it('should parse utf-8', function (done) {613+ var test = request(this.app).post('/')614+ test.set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')615+ test.write(Buffer.from('6e616d653de8aeba', 'hex'))616+ test.expect(200, '{"name":"论"}', done)617+ })618+619+ it('should parse when content-length != char length', function (done) {620+ var test = request(this.app).post('/')621+ test.set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')622+ test.set('Content-Length', '7')623+ test.write(Buffer.from('746573743dc3a5', 'hex'))624+ test.expect(200, '{"test":"å"}', done)625+ })626+627+ it('should default to utf-8', function (done) {628+ var test = request(this.app).post('/')629+ test.set('Content-Type', 'application/x-www-form-urlencoded')630+ test.write(Buffer.from('6e616d653de8aeba', 'hex'))631+ test.expect(200, '{"name":"论"}', done)632+ })633+634+ it('should fail on unknown charset', function (done) {635+ var test = request(this.app).post('/')636+ test.set('Content-Type', 'application/x-www-form-urlencoded; charset=koi8-r')637+ test.write(Buffer.from('6e616d653dcec5d4', 'hex'))638+ test.expect(415, 'unsupported charset "KOI8-R"', done)639+ })640+ })641+642+ describe('encoding', function () {643+ before(function () {644+ this.app = createApp({ limit: '10kb' })645+ })646+647+ it('should parse without encoding', function (done) {648+ var test = request(this.app).post('/')649+ test.set('Content-Type', 'application/x-www-form-urlencoded')650+ test.write(Buffer.from('6e616d653de8aeba', 'hex'))651+ test.expect(200, '{"name":"论"}', done)652+ })653+654+ it('should support identity encoding', function (done) {655+ var test = request(this.app).post('/')656+ test.set('Content-Encoding', 'identity')657+ test.set('Content-Type', 'application/x-www-form-urlencoded')658+ test.write(Buffer.from('6e616d653de8aeba', 'hex'))659+ test.expect(200, '{"name":"论"}', done)660+ })661+662+ it('should support gzip encoding', function (done) {663+ var test = request(this.app).post('/')664+ test.set('Content-Encoding', 'gzip')665+ test.set('Content-Type', 'application/x-www-form-urlencoded')666+ test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))667+ test.expect(200, '{"name":"论"}', done)668+ })669+670+ it('should support deflate encoding', function (done) {671+ var test = request(this.app).post('/')672+ test.set('Content-Encoding', 'deflate')673+ test.set('Content-Type', 'application/x-www-form-urlencoded')674+ test.write(Buffer.from('789ccb4bcc4db57db16e17001068042f', 'hex'))675+ test.expect(200, '{"name":"论"}', done)676+ })677+678+ it('should be case-insensitive', function (done) {679+ var test = request(this.app).post('/')680+ test.set('Content-Encoding', 'GZIP')681+ test.set('Content-Type', 'application/x-www-form-urlencoded')682+ test.write(Buffer.from('1f8b080000000000000bcb4bcc4db57db16e170099a4bad608000000', 'hex'))683+ test.expect(200, '{"name":"论"}', done)684+ })685+686+ it('should fail on unknown encoding', function (done) {687+ var test = request(this.app).post('/')688+ test.set('Content-Encoding', 'nulls')689+ test.set('Content-Type', 'application/x-www-form-urlencoded')690+ test.write(Buffer.from('000000000000', 'hex'))691+ test.expect(415, 'unsupported content encoding "nulls"', done)692+ })693+ })694+})695+696+function createManyParams (count) {697+ var str = ''698+699+ if (count === 0) {700+ return str701+ }702+703+ str += '0=0'704+705+ for (var i = 1; i < count; i++) {706+ var n = i.toString(36)707+ str += '&' + n + '=' + n708+ }709+710+ return str711+}712+713+function createApp (options) {714+ var app = express()715+716+ app.use(express.urlencoded(options))717+718+ app.use(function (err, req, res, next) {719+ res.status(err.status || 500)720+ res.send(String(err[req.headers['x-error-property'] || 'message']))721+ })722+723+ app.post('/', function (req, res) {724+ res.json(req.body)725+ })726+727+ return app728+}729+730+function expectKeyCount (count) {731+ return function (res) {732+ assert.strictEqual(Object.keys(JSON.parse(res.text)).length, count)733+ }734+}