From c221b8596e5ff783bbedadb2d7696f90817b0c85 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 27 Jan 2022 19:02:58 -0500 Subject: [PATCH 01/30] build: mocha@9.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5db814094..ebb7425d9a 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "istanbul": "0.4.5", "marked": "0.7.0", "method-override": "3.0.0", - "mocha": "9.1.3", + "mocha": "9.2.0", "morgan": "1.10.0", "multiparty": "4.2.2", "pbkdf2-password": "1.2.1", From 69997cbdbef83c5cf1a419d6e86519af432d68a8 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 00:44:28 -0500 Subject: [PATCH 02/30] examples: fix error handling in auth example --- examples/auth/index.js | 7 ++++--- test/acceptance/auth.js | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/auth/index.js b/examples/auth/index.js index b8e854300c..70110891ad 100644 --- a/examples/auth/index.js +++ b/examples/auth/index.js @@ -59,14 +59,14 @@ function authenticate(name, pass, fn) { if (!module.parent) console.log('authenticating %s:%s', name, pass); var user = users[name]; // query the db for the given username - if (!user) return fn(new Error('cannot find user')); + if (!user) return fn(null, null) // apply the same algorithm to the POSTed password, applying // the hash against the pass / salt, if there is a match we // found the user hash({ password: pass, salt: user.salt }, function (err, pass, salt, hash) { if (err) return fn(err); if (hash === user.hash) return fn(null, user) - fn(new Error('invalid password')); + fn(null, null) }); } @@ -99,8 +99,9 @@ app.get('/login', function(req, res){ res.render('login'); }); -app.post('/login', function(req, res){ +app.post('/login', function (req, res, next) { authenticate(req.body.username, req.body.password, function(err, user){ + if (err) return next(err) if (user) { // Regenerate session when signing in // to prevent fixation diff --git a/test/acceptance/auth.js b/test/acceptance/auth.js index 9a36ea45fe..d7838755a0 100644 --- a/test/acceptance/auth.js +++ b/test/acceptance/auth.js @@ -22,7 +22,7 @@ describe('auth', function(){ .expect(200, /
Date: Wed, 2 Feb 2022 01:23:40 -0500 Subject: [PATCH 03/30] tests: add test for hello-world example --- examples/hello-world/index.js | 2 +- test/acceptance/hello-world.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/hello-world.js diff --git a/examples/hello-world/index.js b/examples/hello-world/index.js index 04382ac3d0..d82452f331 100644 --- a/examples/hello-world/index.js +++ b/examples/hello-world/index.js @@ -1,6 +1,6 @@ var express = require('../../'); -var app = express(); +var app = module.exports = express() app.get('/', function(req, res){ res.send('Hello World'); diff --git a/test/acceptance/hello-world.js b/test/acceptance/hello-world.js new file mode 100644 index 0000000000..db90349c49 --- /dev/null +++ b/test/acceptance/hello-world.js @@ -0,0 +1,21 @@ + +var app = require('../../examples/hello-world') +var request = require('supertest') + +describe('hello-world', function () { + describe('GET /', function () { + it('should respond with hello world', function (done) { + request(app) + .get('/') + .expect(200, 'Hello World', done) + }) + }) + + describe('GET /missing', function () { + it('should respond with 404', function (done) { + request(app) + .get('/missing') + .expect(404, done) + }) + }) +}) From 8b9757e8b80d5fd1a5105f9caed8ce5f9aea6c46 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:25:55 -0500 Subject: [PATCH 04/30] build: fix running linter in CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80248fab69..e2a4945645 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,6 +133,7 @@ jobs: echo "node@$(node -v)" echo "npm@$(npm -v)" npm -s ls ||: + (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' - name: Run tests shell: bash From 20047bb6e40e76aa855632fb423905c4d0b038c3 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:30:51 -0500 Subject: [PATCH 05/30] examples: use strict mode --- examples/auth/index.js | 2 ++ examples/content-negotiation/db.js | 2 ++ examples/content-negotiation/index.js | 2 ++ examples/content-negotiation/users.js | 1 + examples/cookie-sessions/index.js | 2 ++ examples/cookies/index.js | 2 ++ examples/downloads/index.js | 2 ++ examples/ejs/index.js | 2 ++ examples/error-pages/index.js | 2 ++ examples/error/index.js | 2 ++ examples/hello-world/index.js | 2 ++ examples/markdown/index.js | 2 ++ examples/multi-router/controllers/api_v1.js | 2 ++ examples/multi-router/controllers/api_v2.js | 2 ++ examples/multi-router/index.js | 2 ++ examples/multipart/index.js | 2 ++ examples/mvc/controllers/main/index.js | 2 ++ examples/mvc/controllers/pet/index.js | 2 ++ examples/mvc/controllers/user-pet/index.js | 2 ++ examples/mvc/controllers/user/index.js | 2 ++ examples/mvc/db.js | 2 ++ examples/mvc/index.js | 2 ++ examples/mvc/lib/boot.js | 2 ++ examples/online/index.js | 1 + examples/params/index.js | 2 ++ examples/resource/index.js | 2 ++ examples/route-map/index.js | 2 ++ examples/route-middleware/index.js | 2 ++ examples/route-separation/index.js | 2 ++ examples/route-separation/post.js | 2 ++ examples/route-separation/site.js | 2 ++ examples/route-separation/user.js | 2 ++ examples/search/index.js | 1 + examples/search/public/client.js | 2 ++ examples/session/index.js | 1 + examples/session/redis.js | 2 ++ examples/static-files/index.js | 2 ++ examples/vhost/index.js | 2 ++ examples/view-constructor/github-view.js | 2 ++ examples/view-constructor/index.js | 2 ++ examples/view-locals/index.js | 2 ++ examples/view-locals/user.js | 2 ++ examples/web-service/index.js | 2 ++ 43 files changed, 82 insertions(+) diff --git a/examples/auth/index.js b/examples/auth/index.js index 70110891ad..36205d0f99 100644 --- a/examples/auth/index.js +++ b/examples/auth/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/content-negotiation/db.js b/examples/content-negotiation/db.js index 43fb04baa1..f59b23bf18 100644 --- a/examples/content-negotiation/db.js +++ b/examples/content-negotiation/db.js @@ -1,3 +1,5 @@ +'use strict' + var users = []; users.push({ name: 'Tobi' }); diff --git a/examples/content-negotiation/index.js b/examples/content-negotiation/index.js index 348929e852..280a4e2299 100644 --- a/examples/content-negotiation/index.js +++ b/examples/content-negotiation/index.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../'); var app = module.exports = express(); var users = require('./db'); diff --git a/examples/content-negotiation/users.js b/examples/content-negotiation/users.js index fe511072ec..fe703e73a9 100644 --- a/examples/content-negotiation/users.js +++ b/examples/content-negotiation/users.js @@ -1,3 +1,4 @@ +'use strict' var users = require('./db'); diff --git a/examples/cookie-sessions/index.js b/examples/cookie-sessions/index.js index 1dda15de61..01c731c1c8 100644 --- a/examples/cookie-sessions/index.js +++ b/examples/cookie-sessions/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/cookies/index.js b/examples/cookies/index.js index 93515e5961..04093591f7 100644 --- a/examples/cookies/index.js +++ b/examples/cookies/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/downloads/index.js b/examples/downloads/index.js index 9321f3bf95..91c52bb87c 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/ejs/index.js b/examples/ejs/index.js index 7278091293..a39d805a16 100644 --- a/examples/ejs/index.js +++ b/examples/ejs/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/error-pages/index.js b/examples/error-pages/index.js index 44333cb08f..efa815c474 100644 --- a/examples/error-pages/index.js +++ b/examples/error-pages/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/error/index.js b/examples/error/index.js index 07814d8520..d922de06cc 100644 --- a/examples/error/index.js +++ b/examples/error/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/hello-world/index.js b/examples/hello-world/index.js index d82452f331..8c1855c2eb 100644 --- a/examples/hello-world/index.js +++ b/examples/hello-world/index.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../'); var app = module.exports = express() diff --git a/examples/markdown/index.js b/examples/markdown/index.js index df8c195fb4..74ac05e77f 100644 --- a/examples/markdown/index.js +++ b/examples/markdown/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/multi-router/controllers/api_v1.js b/examples/multi-router/controllers/api_v1.js index 08b7b5e6fd..a301e3ee72 100644 --- a/examples/multi-router/controllers/api_v1.js +++ b/examples/multi-router/controllers/api_v1.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../..'); var apiv1 = express.Router(); diff --git a/examples/multi-router/controllers/api_v2.js b/examples/multi-router/controllers/api_v2.js index 4dd708281c..e997fb1f88 100644 --- a/examples/multi-router/controllers/api_v2.js +++ b/examples/multi-router/controllers/api_v2.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../../..'); var apiv2 = express.Router(); diff --git a/examples/multi-router/index.js b/examples/multi-router/index.js index 78bae9d6e3..dbfd284126 100644 --- a/examples/multi-router/index.js +++ b/examples/multi-router/index.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../..'); var app = module.exports = express(); diff --git a/examples/multipart/index.js b/examples/multipart/index.js index 42c2af23f7..ea7b86e0c9 100644 --- a/examples/multipart/index.js +++ b/examples/multipart/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/controllers/main/index.js b/examples/mvc/controllers/main/index.js index 031862d345..74cde191cd 100644 --- a/examples/mvc/controllers/main/index.js +++ b/examples/mvc/controllers/main/index.js @@ -1,3 +1,5 @@ +'use strict' + exports.index = function(req, res){ res.redirect('/users'); }; diff --git a/examples/mvc/controllers/pet/index.js b/examples/mvc/controllers/pet/index.js index 157a98e84e..214160f9a4 100644 --- a/examples/mvc/controllers/pet/index.js +++ b/examples/mvc/controllers/pet/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/controllers/user-pet/index.js b/examples/mvc/controllers/user-pet/index.js index 416b00741a..42a29adebe 100644 --- a/examples/mvc/controllers/user-pet/index.js +++ b/examples/mvc/controllers/user-pet/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/controllers/user/index.js b/examples/mvc/controllers/user/index.js index a7b0208c8e..ec3ae4c811 100644 --- a/examples/mvc/controllers/user/index.js +++ b/examples/mvc/controllers/user/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/db.js b/examples/mvc/db.js index c992afcfd7..94d1480f9b 100644 --- a/examples/mvc/db.js +++ b/examples/mvc/db.js @@ -1,3 +1,5 @@ +'use strict' + // faux database var pets = exports.pets = []; diff --git a/examples/mvc/index.js b/examples/mvc/index.js index 77885a60ca..da4727b282 100644 --- a/examples/mvc/index.js +++ b/examples/mvc/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/mvc/lib/boot.js b/examples/mvc/lib/boot.js index 422330dc06..0216e5d76d 100644 --- a/examples/mvc/lib/boot.js +++ b/examples/mvc/lib/boot.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/online/index.js b/examples/online/index.js index f14474c08d..0b5fdffc86 100644 --- a/examples/online/index.js +++ b/examples/online/index.js @@ -1,3 +1,4 @@ +'use strict' // install redis first: // https://redis.io/ diff --git a/examples/params/index.js b/examples/params/index.js index 5b57573d1e..b153b93b98 100644 --- a/examples/params/index.js +++ b/examples/params/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/resource/index.js b/examples/resource/index.js index b79ad923d2..ff1f6fe11f 100644 --- a/examples/resource/index.js +++ b/examples/resource/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-map/index.js b/examples/route-map/index.js index e7adf5fcb4..2bc28bd4b2 100644 --- a/examples/route-map/index.js +++ b/examples/route-map/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-middleware/index.js b/examples/route-middleware/index.js index e7a0901fa8..44ec13a95b 100644 --- a/examples/route-middleware/index.js +++ b/examples/route-middleware/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-separation/index.js b/examples/route-separation/index.js index 6512109134..5d48381111 100644 --- a/examples/route-separation/index.js +++ b/examples/route-separation/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/route-separation/post.js b/examples/route-separation/post.js index e3f12e7884..3a8e3a2d22 100644 --- a/examples/route-separation/post.js +++ b/examples/route-separation/post.js @@ -1,3 +1,5 @@ +'use strict' + // Fake posts database var posts = [ diff --git a/examples/route-separation/site.js b/examples/route-separation/site.js index a3d20bc8a1..aee36d1bd7 100644 --- a/examples/route-separation/site.js +++ b/examples/route-separation/site.js @@ -1,3 +1,5 @@ +'use strict' + exports.index = function(req, res){ res.render('index', { title: 'Route Separation Example' }); }; diff --git a/examples/route-separation/user.js b/examples/route-separation/user.js index ef79b343a2..1c2aec7cd2 100644 --- a/examples/route-separation/user.js +++ b/examples/route-separation/user.js @@ -1,3 +1,5 @@ +'use strict' + // Fake user database var users = [ diff --git a/examples/search/index.js b/examples/search/index.js index 246993caa5..0d19444e52 100644 --- a/examples/search/index.js +++ b/examples/search/index.js @@ -1,3 +1,4 @@ +'use strict' // install redis first: // https://redis.io/ diff --git a/examples/search/public/client.js b/examples/search/public/client.js index 75c37d8e00..cd43faf71e 100644 --- a/examples/search/public/client.js +++ b/examples/search/public/client.js @@ -1,3 +1,5 @@ +'use strict' + var search = document.querySelector('[type=search]'); var code = document.querySelector('pre'); diff --git a/examples/session/index.js b/examples/session/index.js index 9bae48b8d3..2bb2b109c8 100644 --- a/examples/session/index.js +++ b/examples/session/index.js @@ -1,3 +1,4 @@ +'use strict' // install redis first: // https://redis.io/ diff --git a/examples/session/redis.js b/examples/session/redis.js index 1338d6e95e..bbbdc7fd3e 100644 --- a/examples/session/redis.js +++ b/examples/session/redis.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/static-files/index.js b/examples/static-files/index.js index 0e44313d15..609c546b47 100644 --- a/examples/static-files/index.js +++ b/examples/static-files/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/vhost/index.js b/examples/vhost/index.js index 4a0c17b850..a9499356b4 100644 --- a/examples/vhost/index.js +++ b/examples/vhost/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-constructor/github-view.js b/examples/view-constructor/github-view.js index 0a98a90843..43d29336ca 100644 --- a/examples/view-constructor/github-view.js +++ b/examples/view-constructor/github-view.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-constructor/index.js b/examples/view-constructor/index.js index 175a254e4e..3d673670e3 100644 --- a/examples/view-constructor/index.js +++ b/examples/view-constructor/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-locals/index.js b/examples/view-locals/index.js index cb41509606..bf52d2a85a 100644 --- a/examples/view-locals/index.js +++ b/examples/view-locals/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ diff --git a/examples/view-locals/user.js b/examples/view-locals/user.js index 90ab1f389d..aaa6f85ff0 100644 --- a/examples/view-locals/user.js +++ b/examples/view-locals/user.js @@ -1,3 +1,5 @@ +'use strict' + module.exports = User; // faux model diff --git a/examples/web-service/index.js b/examples/web-service/index.js index 3685619d10..c22fea4032 100644 --- a/examples/web-service/index.js +++ b/examples/web-service/index.js @@ -1,3 +1,5 @@ +'use strict' + /** * Module dependencies. */ From 215f484fb4d8b71ae079f3d8a9d43e3470dacc5c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:42:35 -0500 Subject: [PATCH 06/30] tests: fix wording of req.accepts* test cases --- test/req.acceptsEncoding.js | 34 ++++++++++++----------- test/req.acceptsEncodings.js | 34 ++++++++++++----------- test/req.acceptsLanguage.js | 53 +++++++++++++++++++----------------- test/req.acceptsLanguages.js | 53 +++++++++++++++++++----------------- 4 files changed, 92 insertions(+), 82 deletions(-) diff --git a/test/req.acceptsEncoding.js b/test/req.acceptsEncoding.js index 9ed9197829..f2af68da22 100644 --- a/test/req.acceptsEncoding.js +++ b/test/req.acceptsEncoding.js @@ -4,33 +4,35 @@ var express = require('../') describe('req', function(){ describe('.acceptsEncoding', function(){ - it('should be true if encoding accepted', function(done){ + it('should return encoding if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsEncoding('gzip').should.be.ok() - req.acceptsEncoding('deflate').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + gzip: req.acceptsEncoding('gzip'), + deflate: req.acceptsEncoding('deflate') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { gzip: 'gzip', deflate: 'deflate' }, done) }) it('should be false if encoding not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsEncoding('bogus').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + bogus: req.acceptsEncoding('bogus') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { bogus: false }, done) }) }) }) diff --git a/test/req.acceptsEncodings.js b/test/req.acceptsEncodings.js index a5cf747d41..dc21c4edda 100644 --- a/test/req.acceptsEncodings.js +++ b/test/req.acceptsEncodings.js @@ -4,33 +4,35 @@ var express = require('../') describe('req', function(){ describe('.acceptsEncodings', function () { - it('should be true if encoding accepted', function(done){ + it('should return encoding if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsEncodings('gzip').should.be.ok() - req.acceptsEncodings('deflate').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + gzip: req.acceptsEncoding('gzip'), + deflate: req.acceptsEncoding('deflate') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { gzip: 'gzip', deflate: 'deflate' }, done) }) it('should be false if encoding not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsEncodings('bogus').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + bogus: req.acceptsEncoding('bogus') + }) + }) request(app) - .get('/') - .set('Accept-Encoding', ' gzip, deflate') - .expect(200, done); + .get('/') + .set('Accept-Encoding', ' gzip, deflate') + .expect(200, { bogus: false }, done) }) }) }) diff --git a/test/req.acceptsLanguage.js b/test/req.acceptsLanguage.js index 1c7c5fd86f..616e723946 100644 --- a/test/req.acceptsLanguage.js +++ b/test/req.acceptsLanguage.js @@ -4,49 +4,52 @@ var express = require('../') describe('req', function(){ describe('.acceptsLanguage', function(){ - it('should be true if language accepted', function(done){ + it('should return language if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguage('en-us').should.be.ok() - req.acceptsLanguage('en').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + 'en-us': req.acceptsLanguages('en-us'), + en: req.acceptsLanguages('en') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { 'en-us': 'en-us', en: 'en' }, done) }) it('should be false if language not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsLanguage('es').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + es: req.acceptsLanguages('es') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { es: false }, done) }) describe('when Accept-Language is not present', function(){ - it('should always return true', function(done){ + it('should always return language', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguage('en').should.be.ok() - req.acceptsLanguage('es').should.be.ok() - req.acceptsLanguage('jp').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + en: req.acceptsLanguages('en'), + es: req.acceptsLanguages('es'), + jp: req.acceptsLanguages('jp') + }) + }) request(app) - .get('/') - .expect(200, done); + .get('/') + .expect(200, { en: 'en', es: 'es', jp: 'jp' }, done) }) }) }) diff --git a/test/req.acceptsLanguages.js b/test/req.acceptsLanguages.js index 1d92f44b2b..87bf7b25df 100644 --- a/test/req.acceptsLanguages.js +++ b/test/req.acceptsLanguages.js @@ -4,49 +4,52 @@ var express = require('../') describe('req', function(){ describe('.acceptsLanguages', function(){ - it('should be true if language accepted', function(done){ + it('should return language if accepted', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguages('en-us').should.be.ok() - req.acceptsLanguages('en').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + 'en-us': req.acceptsLanguages('en-us'), + en: req.acceptsLanguages('en') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { 'en-us': 'en-us', en: 'en' }, done) }) it('should be false if language not accepted', function(done){ var app = express(); - app.use(function(req, res){ - req.acceptsLanguages('es').should.not.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + es: req.acceptsLanguages('es') + }) + }) request(app) - .get('/') - .set('Accept-Language', 'en;q=.5, en-us') - .expect(200, done); + .get('/') + .set('Accept-Language', 'en;q=.5, en-us') + .expect(200, { es: false }, done) }) describe('when Accept-Language is not present', function(){ - it('should always return true', function(done){ + it('should always return language', function (done) { var app = express(); - app.use(function(req, res){ - req.acceptsLanguages('en').should.be.ok() - req.acceptsLanguages('es').should.be.ok() - req.acceptsLanguages('jp').should.be.ok() - res.end(); - }); + app.get('/', function (req, res) { + res.send({ + en: req.acceptsLanguages('en'), + es: req.acceptsLanguages('es'), + jp: req.acceptsLanguages('jp') + }) + }) request(app) - .get('/') - .expect(200, done); + .get('/') + .expect(200, { en: 'en', es: 'es', jp: 'jp' }, done) }) }) }) From bd4fdfe5f771d07ef544c4a91bd6bfc4cc711f9b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 01:55:16 -0500 Subject: [PATCH 07/30] tests: remove global dependency on should fixes #4797 --- test/app.engine.js | 13 ++++---- test/app.js | 24 +++++++-------- test/app.locals.js | 14 +++++---- test/app.param.js | 30 +++++++++---------- test/app.render.js | 54 ++++++++++++++++----------------- test/app.router.js | 4 +-- test/app.routes.error.js | 14 +++++---- test/app.use.js | 8 ++--- test/req.query.js | 4 ++- test/req.route.js | 10 ++++--- test/req.xhr.js | 65 ++++++++++++++-------------------------- test/res.cookie.js | 28 ++++++----------- test/res.send.js | 2 +- test/utils.js | 37 ++++++++++++----------- 14 files changed, 142 insertions(+), 165 deletions(-) diff --git a/test/app.engine.js b/test/app.engine.js index b198292fa0..0d54c90d56 100644 --- a/test/app.engine.js +++ b/test/app.engine.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , fs = require('fs'); var path = require('path') @@ -22,16 +23,16 @@ describe('app', function(){ app.render('user.html', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) it('should throw when the callback is missing', function(){ var app = express(); - (function(){ + assert.throws(function () { app.engine('.html', null); - }).should.throw('callback function required'); + }, /callback function required/) }) it('should work without leading "."', function(done){ @@ -43,7 +44,7 @@ describe('app', function(){ app.render('user.html', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -58,7 +59,7 @@ describe('app', function(){ app.render('user', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -73,7 +74,7 @@ describe('app', function(){ app.render('user', function(err, str){ if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) diff --git a/test/app.js b/test/app.js index e52365c36b..d0756795d3 100644 --- a/test/app.js +++ b/test/app.js @@ -32,8 +32,8 @@ describe('app.parent', function(){ blog.use('/admin', blogAdmin); assert(!app.parent, 'app.parent'); - blog.parent.should.equal(app); - blogAdmin.parent.should.equal(blog); + assert.strictEqual(blog.parent, app) + assert.strictEqual(blogAdmin.parent, blog) }) }) @@ -48,10 +48,10 @@ describe('app.mountpath', function(){ app.use(fallback); blog.use('/admin', admin); - admin.mountpath.should.equal('/admin'); - app.mountpath.should.equal('/'); - blog.mountpath.should.equal('/blog'); - fallback.mountpath.should.equal('/'); + assert.strictEqual(admin.mountpath, '/admin') + assert.strictEqual(app.mountpath, '/') + assert.strictEqual(blog.mountpath, '/blog') + assert.strictEqual(fallback.mountpath, '/') }) }) @@ -76,9 +76,9 @@ describe('app.path()', function(){ app.use('/blog', blog); blog.use('/admin', blogAdmin); - app.path().should.equal(''); - blog.path().should.equal('/blog'); - blogAdmin.path().should.equal('/blog/admin'); + assert.strictEqual(app.path(), '') + assert.strictEqual(blog.path(), '/blog') + assert.strictEqual(blogAdmin.path(), '/blog/admin') }) }) @@ -86,7 +86,7 @@ describe('in development', function(){ it('should disable "view cache"', function(){ process.env.NODE_ENV = 'development'; var app = express(); - app.enabled('view cache').should.be.false() + assert.ok(!app.enabled('view cache')) process.env.NODE_ENV = 'test'; }) }) @@ -95,7 +95,7 @@ describe('in production', function(){ it('should enable "view cache"', function(){ process.env.NODE_ENV = 'production'; var app = express(); - app.enabled('view cache').should.be.true() + assert.ok(app.enabled('view cache')) process.env.NODE_ENV = 'test'; }) }) @@ -104,7 +104,7 @@ describe('without NODE_ENV', function(){ it('should default to development', function(){ process.env.NODE_ENV = ''; var app = express(); - app.get('env').should.equal('development'); + assert.strictEqual(app.get('env'), 'development') process.env.NODE_ENV = 'test'; }) }) diff --git a/test/app.locals.js b/test/app.locals.js index d8bfb5a987..0b14ac9070 100644 --- a/test/app.locals.js +++ b/test/app.locals.js @@ -1,16 +1,18 @@ +var assert = require('assert') var express = require('../') +var should = require('should') describe('app', function(){ describe('.locals(obj)', function(){ it('should merge locals', function(){ var app = express(); - Object.keys(app.locals).should.eql(['settings']); + should(Object.keys(app.locals)).eql(['settings']) app.locals.user = 'tobi'; app.locals.age = 2; - Object.keys(app.locals).should.eql(['settings', 'user', 'age']); - app.locals.user.should.equal('tobi'); - app.locals.age.should.equal(2); + should(Object.keys(app.locals)).eql(['settings', 'user', 'age']) + assert.strictEqual(app.locals.user, 'tobi') + assert.strictEqual(app.locals.age, 2) }) }) @@ -19,8 +21,8 @@ describe('app', function(){ var app = express(); app.set('title', 'House of Manny'); var obj = app.locals.settings; - obj.should.have.property('env', 'test'); - obj.should.have.property('title', 'House of Manny'); + should(obj).have.property('env', 'test') + should(obj).have.property('title', 'House of Manny') }) }) }) diff --git a/test/app.param.js b/test/app.param.js index 577b00710b..7dbe3ffb61 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -40,7 +41,7 @@ describe('app', function(){ it('should fail if not given fn', function(){ var app = express(); - app.param.bind(app, ':name', 'bob').should.throw(); + assert.throws(app.param.bind(app, ':name', 'bob')) }) }) @@ -57,24 +58,22 @@ describe('app', function(){ app.get('/post/:id', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); app.get('/user/:uid', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); request(app) - .get('/user/123') - .expect(200, '123', function (err) { - if (err) return done(err) - request(app) - .get('/post/123') - .expect('123', done); - }) + .get('/user/123') + .expect(200, 'number:123', function (err) { + if (err) return done(err) + request(app) + .get('/post/123') + .expect('number:123', done) + }) }) }) @@ -91,13 +90,12 @@ describe('app', function(){ app.get('/user/:id', function(req, res){ var id = req.params.id; - id.should.be.a.Number() - res.send('' + id); + res.send((typeof id) + ':' + id) }); request(app) - .get('/user/123') - .expect('123', done); + .get('/user/123') + .expect(200, 'number:123', done) }) it('should only call once per request', function(done) { diff --git a/test/app.render.js b/test/app.render.js index 54f6c2ca82..d0b367189b 100644 --- a/test/app.render.js +++ b/test/app.render.js @@ -13,7 +13,7 @@ describe('app', function(){ app.render(path.join(__dirname, 'fixtures', 'user.tmpl'), function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -26,7 +26,7 @@ describe('app', function(){ app.render(path.join(__dirname, 'fixtures', 'user'), function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -39,7 +39,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -52,7 +52,7 @@ describe('app', function(){ app.render('blog/post', function (err, str) { if (err) return done(err); - str.should.equal('

blog post

'); + assert.strictEqual(str, '

blog post

') done(); }) }) @@ -72,8 +72,8 @@ describe('app', function(){ app.set('view', View); app.render('something', function(err, str){ - err.should.be.ok() - err.message.should.equal('err!'); + assert.ok(err) + assert.strictEqual(err.message, 'err!') done(); }) }) @@ -113,7 +113,7 @@ describe('app', function(){ app.render('email.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

This is an email

'); + assert.strictEqual(str, '

This is an email

') done(); }) }) @@ -128,7 +128,7 @@ describe('app', function(){ app.render('email', function(err, str){ if (err) return done(err); - str.should.equal('

This is an email

'); + assert.strictEqual(str, '

This is an email

') done(); }) }) @@ -143,7 +143,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -161,7 +161,7 @@ describe('app', function(){ app.render('user.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('tobi'); + assert.strictEqual(str, 'tobi') done(); }) }) @@ -178,7 +178,7 @@ describe('app', function(){ app.render('name.tmpl', function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -219,7 +219,7 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - str.should.equal('abstract engine'); + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -245,12 +245,12 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(2); - str.should.equal('abstract engine'); + assert.strictEqual(count, 2) + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -275,12 +275,12 @@ describe('app', function(){ app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') done(); }) }) @@ -298,7 +298,7 @@ describe('app', function(){ app.render('user.tmpl', { user: user }, function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -311,7 +311,7 @@ describe('app', function(){ app.render('user.tmpl', {}, function (err, str) { if (err) return done(err); - str.should.equal('

tobi

'); + assert.strictEqual(str, '

tobi

') done(); }) }) @@ -325,7 +325,7 @@ describe('app', function(){ app.render('user.tmpl', { user: jane }, function (err, str) { if (err) return done(err); - str.should.equal('

jane

'); + assert.strictEqual(str, '

jane

') done(); }) }) @@ -350,12 +350,12 @@ describe('app', function(){ app.render('something', {cache: true}, function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') app.render('something', {cache: true}, function(err, str){ if (err) return done(err); - count.should.equal(1); - str.should.equal('abstract engine'); + assert.strictEqual(count, 1) + assert.strictEqual(str, 'abstract engine') done(); }) }) diff --git a/test/app.router.js b/test/app.router.js index a4fe57cc2b..6edb93d6ea 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -51,7 +51,7 @@ describe('app.router', function(){ it('should reject numbers for app.' + method, function(){ var app = express(); - app[method].bind(app, '/', 3).should.throw(/Number/); + assert.throws(app[method].bind(app, '/', 3), /Number/) }) }); @@ -1102,6 +1102,6 @@ describe('app.router', function(){ it('should be chainable', function(){ var app = express(); - app.get('/', function(){}).should.equal(app); + assert.strictEqual(app.get('/', function () {}), app) }) }) diff --git a/test/app.routes.error.js b/test/app.routes.error.js index cbbc23ef57..b1f95d0d6e 100644 --- a/test/app.routes.error.js +++ b/test/app.routes.error.js @@ -1,3 +1,5 @@ + +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -34,20 +36,20 @@ describe('app', function(){ next(); }, function(err, req, res, next){ b = true; - err.message.should.equal('fabricated error'); + assert.strictEqual(err.message, 'fabricated error') next(err); }, function(err, req, res, next){ c = true; - err.message.should.equal('fabricated error'); + assert.strictEqual(err.message, 'fabricated error') next(); }, function(err, req, res, next){ d = true; next(); }, function(req, res){ - a.should.be.false() - b.should.be.true() - c.should.be.true() - d.should.be.false() + assert.ok(!a) + assert.ok(b) + assert.ok(c) + assert.ok(!d) res.send(204); }); diff --git a/test/app.use.js b/test/app.use.js index 347937fbb3..7987405a8b 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -10,7 +10,7 @@ describe('app', function(){ , app = express(); blog.on('mount', function(arg){ - arg.should.equal(app); + assert.strictEqual(arg, app) done(); }); @@ -63,7 +63,7 @@ describe('app', function(){ , app = express(); app.use('/blog', blog); - blog.parent.should.equal(app); + assert.strictEqual(blog.parent, app) }) it('should support dynamic routes', function(done){ @@ -102,11 +102,11 @@ describe('app', function(){ }); blog.once('mount', function (parent) { - parent.should.equal(app); + assert.strictEqual(parent, app) cb(); }); other.once('mount', function (parent) { - parent.should.equal(app); + assert.strictEqual(parent, app) cb(); }); diff --git a/test/req.query.js b/test/req.query.js index 0e810b8ef9..f3e8df8a18 100644 --- a/test/req.query.js +++ b/test/req.query.js @@ -1,4 +1,5 @@ +var assert = require('assert') var express = require('../') , request = require('supertest'); @@ -99,7 +100,8 @@ describe('req', function(){ describe('when "query parser" an unknown value', function () { it('should throw', function () { - createApp.bind(null, 'bogus').should.throw(/unknown value.*query parser/); + assert.throws(createApp.bind(null, 'bogus'), + /unknown value.*query parser/) }); }); }) diff --git a/test/req.route.js b/test/req.route.js index 2947b7c3d0..b32d470bd6 100644 --- a/test/req.route.js +++ b/test/req.route.js @@ -8,18 +8,20 @@ describe('req', function(){ var app = express(); app.get('/user/:id/:op?', function(req, res, next){ - req.route.path.should.equal('/user/:id/:op?'); + res.header('path-1', req.route.path) next(); }); app.get('/user/:id/edit', function(req, res){ - req.route.path.should.equal('/user/:id/edit'); + res.header('path-2', req.route.path) res.end(); }); request(app) - .get('/user/12/edit') - .expect(200, done); + .get('/user/12/edit') + .expect('path-1', '/user/:id/:op?') + .expect('path-2', '/user/:id/edit') + .expect(200, done) }) }) }) diff --git a/test/req.xhr.js b/test/req.xhr.js index 94af9170cb..3ad1c6fb72 100644 --- a/test/req.xhr.js +++ b/test/req.xhr.js @@ -4,59 +4,38 @@ var express = require('../') describe('req', function(){ describe('.xhr', function(){ - it('should return true when X-Requested-With is xmlhttprequest', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.true() - res.end(); - }); + before(function () { + this.app = express() + this.app.get('/', function (req, res) { + res.send(req.xhr) + }) + }) - request(app) - .get('/') - .set('X-Requested-With', 'xmlhttprequest') - .expect(200, done) + it('should return true when X-Requested-With is xmlhttprequest', function(done){ + request(this.app) + .get('/') + .set('X-Requested-With', 'xmlhttprequest') + .expect(200, 'true', done) }) it('should case-insensitive', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.true() - res.end(); - }); - - request(app) - .get('/') - .set('X-Requested-With', 'XMLHttpRequest') - .expect(200, done) + request(this.app) + .get('/') + .set('X-Requested-With', 'XMLHttpRequest') + .expect(200, 'true', done) }) it('should return false otherwise', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.false() - res.end(); - }); - - request(app) - .get('/') - .set('X-Requested-With', 'blahblah') - .expect(200, done) + request(this.app) + .get('/') + .set('X-Requested-With', 'blahblah') + .expect(200, 'false', done) }) it('should return false when not present', function(done){ - var app = express(); - - app.use(function(req, res){ - req.xhr.should.be.false() - res.end(); - }); - - request(app) - .get('/') - .expect(200, done) + request(this.app) + .get('/') + .expect(200, 'false', done) }) }) }) diff --git a/test/res.cookie.js b/test/res.cookie.js index d8e6b7ca85..8f8662c217 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -1,7 +1,6 @@ var express = require('../') , request = require('supertest') - , cookie = require('cookie') , cookieParser = require('cookie-parser') var merge = require('utils-merge'); @@ -46,12 +45,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - var val = ['name=tobi; Path=/', 'age=1; Path=/', 'gender=%3F; Path=/']; - res.headers['set-cookie'].should.eql(val); - done(); - }) + .get('/') + .expect('Set-Cookie', 'name=tobi; Path=/,age=1; Path=/,gender=%3F; Path=/') + .expect(200, done) }) }) @@ -80,11 +76,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - res.headers['set-cookie'][0].should.not.containEql('Thu, 01 Jan 1970 00:00:01 GMT'); - done(); - }) + .get('/') + .expect('Set-Cookie', /name=tobi; Max-Age=1; Path=\/; Expires=/) + .expect(200, done) }) it('should set max-age', function(done){ @@ -141,13 +135,9 @@ describe('res', function(){ }); request(app) - .get('/') - .end(function(err, res){ - var val = res.headers['set-cookie'][0]; - val = cookie.parse(val.split('.')[0]); - val.user.should.equal('s:j:{"name":"tobi"}'); - done(); - }) + .get('/') + .expect('Set-Cookie', 'user=s%3Aj%3A%7B%22name%22%3A%22tobi%22%7D.K20xcwmDS%2BPb1rsD95o5Jm5SqWs1KteqdnynnB7jkTE; Path=/') + .expect(200, done) }) }) diff --git a/test/res.send.js b/test/res.send.js index b836b5e4dc..e62caf95dc 100644 --- a/test/res.send.js +++ b/test/res.send.js @@ -544,7 +544,7 @@ describe('res', function(){ var chunk = !Buffer.isBuffer(body) ? Buffer.from(body, encoding) : body; - chunk.toString().should.equal('hello, world!'); + assert.strictEqual(chunk.toString(), 'hello, world!') return '"custom"'; }); diff --git a/test/utils.js b/test/utils.js index b51d223af9..a0fac7a722 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,27 +1,28 @@ var assert = require('assert'); var Buffer = require('safe-buffer').Buffer +var should = require('should') var utils = require('../lib/utils'); describe('utils.etag(body, encoding)', function(){ it('should support strings', function(){ - utils.etag('express!') - .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.etag('express!'), + '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support utf8 strings', function(){ - utils.etag('express❤', 'utf8') - .should.eql('"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') + assert.strictEqual(utils.etag('express❤', 'utf8'), + '"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') }) it('should support buffer', function(){ - utils.etag(Buffer.from('express!')) - .should.eql('"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.etag(Buffer.from('express!')), + '"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support empty string', function(){ - utils.etag('') - .should.eql('"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') + assert.strictEqual(utils.etag(''), + '"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) @@ -49,23 +50,23 @@ describe('utils.setCharset(type, charset)', function () { describe('utils.wetag(body, encoding)', function(){ it('should support strings', function(){ - utils.wetag('express!') - .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.wetag('express!'), + 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support utf8 strings', function(){ - utils.wetag('express❤', 'utf8') - .should.eql('W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') + assert.strictEqual(utils.wetag('express❤', 'utf8'), + 'W/"a-JBiXf7GyzxwcrxY4hVXUwa7tmks"') }) it('should support buffer', function(){ - utils.wetag(Buffer.from('express!')) - .should.eql('W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') + assert.strictEqual(utils.wetag(Buffer.from('express!')), + 'W/"8-O2uVAFaQ1rZvlKLT14RnuvjPIdg"') }) it('should support empty string', function(){ - utils.wetag('') - .should.eql('W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') + assert.strictEqual(utils.wetag(''), + 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"') }) }) @@ -89,7 +90,7 @@ describe('utils.isAbsolute()', function(){ describe('utils.flatten(arr)', function(){ it('should flatten an array', function(){ var arr = ['one', ['two', ['three', 'four'], 'five']]; - utils.flatten(arr) - .should.eql(['one', 'two', 'three', 'four', 'five']); + should(utils.flatten(arr)) + .eql(['one', 'two', 'three', 'four', 'five']) }) }) From 141914e8172f5d1a08825fc60a54d944121b1ec0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 14:16:20 -0500 Subject: [PATCH 08/30] tests: fix tests that did not bubble errors --- test/app.all.js | 12 +++++++----- test/app.head.js | 15 ++++++--------- test/app.router.js | 33 ++++++++++++++++++--------------- test/app.use.js | 11 ++++++----- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/test/app.all.js b/test/app.all.js index e9ef08831d..45c3ddb93b 100644 --- a/test/app.all.js +++ b/test/app.all.js @@ -1,22 +1,24 @@ +var after = require('after') var express = require('../') , request = require('supertest'); describe('app.all()', function(){ it('should add a router per method', function(done){ var app = express(); + var cb = after(2, done) app.all('/tobi', function(req, res){ res.end(req.method); }); request(app) - .put('/tobi') - .expect('PUT', function(){ - request(app) + .put('/tobi') + .expect(200, 'PUT', cb) + + request(app) .get('/tobi') - .expect('GET', done); - }); + .expect(200, 'GET', cb) }) it('should run the callback for a method just once', function(done){ diff --git a/test/app.head.js b/test/app.head.js index b417ca0c92..6aa1bb8003 100644 --- a/test/app.head.js +++ b/test/app.head.js @@ -46,23 +46,20 @@ describe('HEAD', function(){ describe('app.head()', function(){ it('should override', function(done){ var app = express() - , called; app.head('/tobi', function(req, res){ - called = true; - res.end(''); + res.header('x-method', 'head') + res.end() }); app.get('/tobi', function(req, res){ - assert(0, 'should not call GET'); + res.header('x-method', 'get') res.send('tobi'); }); request(app) - .head('/tobi') - .expect(200, function(){ - assert(called); - done(); - }); + .head('/tobi') + .expect('x-method', 'head') + .expect(200, done) }) }) diff --git a/test/app.router.js b/test/app.router.js index 6edb93d6ea..8c98aa869b 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -636,18 +636,19 @@ describe('app.router', function(){ it('should work cross-segment', function(done){ var app = express(); + var cb = after(2, done) app.get('/api*', function(req, res){ res.send(req.params[0]); }); request(app) - .get('/api') - .expect('', function(){ - request(app) + .get('/api') + .expect(200, '', cb) + + request(app) .get('/api/hey') - .expect('/hey', done); - }); + .expect(200, '/hey', cb) }) it('should allow naming', function(done){ @@ -863,36 +864,38 @@ describe('app.router', function(){ describe('.:name', function(){ it('should denote a format', function(done){ var app = express(); + var cb = after(2, done) app.get('/:name.:format', function(req, res){ res.end(req.params.name + ' as ' + req.params.format); }); request(app) - .get('/foo.json') - .expect('foo as json', function(){ - request(app) + .get('/foo.json') + .expect(200, 'foo as json', cb) + + request(app) .get('/foo') - .expect(404, done); - }); + .expect(404, cb) }) }) describe('.:name?', function(){ it('should denote an optional format', function(done){ var app = express(); + var cb = after(2, done) app.get('/:name.:format?', function(req, res){ res.end(req.params.name + ' as ' + (req.params.format || 'html')); }); request(app) - .get('/foo') - .expect('foo as html', function(){ - request(app) + .get('/foo') + .expect(200, 'foo as html', cb) + + request(app) .get('/foo.json') - .expect('foo as json', done); - }); + .expect(200, 'foo as json', done) }) }) diff --git a/test/app.use.js b/test/app.use.js index 7987405a8b..55ba0689c8 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -37,6 +37,7 @@ describe('app', function(){ var blog = express() , forum = express() , app = express(); + var cb = after(2, done) blog.get('/', function(req, res){ res.end('blog'); @@ -50,12 +51,12 @@ describe('app', function(){ app.use('/forum', forum); request(app) - .get('/blog') - .expect('blog', function(){ - request(app) + .get('/blog') + .expect(200, 'blog', cb) + + request(app) .get('/forum') - .expect('forum', done); - }); + .expect(200, 'forum', done) }) it('should set the child\'s .parent', function(){ From 00ad5bee96bade1b776be62c7f1912eefc41793d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 15:02:46 -0500 Subject: [PATCH 09/30] tests: add more tests for app.request & app.response --- test/app.request.js | 119 ++++++++++++++++++++++++++++++++++++++++ test/app.response.js | 128 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 232 insertions(+), 15 deletions(-) diff --git a/test/app.request.js b/test/app.request.js index 728043a5a3..0288f80b09 100644 --- a/test/app.request.js +++ b/test/app.request.js @@ -1,4 +1,5 @@ +var after = require('after') var express = require('../') , request = require('supertest'); @@ -19,5 +20,123 @@ describe('app', function(){ .get('/foo?name=tobi') .expect('name=tobi', done); }) + + it('should only extend for the referenced app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app1.get('/', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/') + .expect(200, 'tobi', cb) + + request(app2) + .get('/') + .expect(500, /(?:not a function|has no method)/, cb) + }) + + it('should inherit to sub apps', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/') + .expect(200, 'tobi', cb) + + request(app1) + .get('/sub') + .expect(200, 'tobi', cb) + }) + + it('should allow sub app to override', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app2.request.foobar = function () { + return 'loki' + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/') + .expect(200, 'tobi', cb) + + request(app1) + .get('/sub') + .expect(200, 'loki', cb) + }) + + it('should not pollute parent app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.request.foobar = function () { + return 'tobi' + } + + app2.request.foobar = function () { + return 'loki' + } + + app1.use('/sub', app2) + + app1.get('/sub/foo', function (req, res) { + res.send(req.foobar()) + }) + + app2.get('/', function (req, res) { + res.send(req.foobar()) + }) + + request(app1) + .get('/sub') + .expect(200, 'loki', cb) + + request(app1) + .get('/sub/foo') + .expect(200, 'tobi', cb) + }) }) }) diff --git a/test/app.response.js b/test/app.response.js index c6ea77c820..ea696b566f 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -1,4 +1,5 @@ +var after = require('after') var express = require('../') , request = require('supertest'); @@ -20,25 +21,122 @@ describe('app', function(){ .expect('HEY', done); }) - it('should not be influenced by other app protos', function(done){ - var app = express() - , app2 = express(); + it('should only extend for the referenced app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) - app.response.shout = function(str){ - this.send(str.toUpperCase()); - }; + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } - app2.response.shout = function(str){ - this.send(str); - }; + app1.get('/', function (req, res) { + res.shout('foo') + }) - app.use(function(req, res){ - res.shout('hey'); - }); + app2.get('/', function (req, res) { + res.shout('foo') + }) - request(app) - .get('/') - .expect('HEY', done); + request(app1) + .get('/') + .expect(200, 'FOO', cb) + + request(app2) + .get('/') + .expect(500, /(?:not a function|has no method)/, cb) + }) + + it('should inherit to sub apps', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.shout('foo') + }) + + app2.get('/', function (req, res) { + res.shout('foo') + }) + + request(app1) + .get('/') + .expect(200, 'FOO', cb) + + request(app1) + .get('/sub') + .expect(200, 'FOO', cb) + }) + + it('should allow sub app to override', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } + + app2.response.shout = function (str) { + this.send(str + '!') + } + + app1.use('/sub', app2) + + app1.get('/', function (req, res) { + res.shout('foo') + }) + + app2.get('/', function (req, res) { + res.shout('foo') + }) + + request(app1) + .get('/') + .expect(200, 'FOO', cb) + + request(app1) + .get('/sub') + .expect(200, 'foo!', cb) + }) + + it('should not pollute parent app', function (done) { + var app1 = express() + var app2 = express() + var cb = after(2, done) + + app1.response.shout = function (str) { + this.send(str.toUpperCase()) + } + + app2.response.shout = function (str) { + this.send(str + '!') + } + + app1.use('/sub', app2) + + app1.get('/sub/foo', function (req, res) { + res.shout('foo') + }) + + app2.get('/', function (req, res) { + res.shout('foo') + }) + + request(app1) + .get('/sub') + .expect(200, 'foo!', cb) + + request(app1) + .get('/sub/foo') + .expect(200, 'FOO', cb) }) }) }) From da6cb0ed8a4c9a5048cf391a32f9fab1960d9284 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 15:15:41 -0500 Subject: [PATCH 10/30] tests: add range tests to res.download --- test/res.download.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/res.download.js b/test/res.download.js index cf3b3ca53e..658d80af4f 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -20,6 +20,33 @@ describe('res', function(){ .expect('Content-Disposition', 'attachment; filename="user.html"') .expect(200, '

{{user.name}}

', done) }) + + it('should accept range requests', function (done) { + var app = express() + + app.get('/', function (req, res) { + res.download('test/fixtures/user.html') + }) + + request(app) + .get('/') + .expect('Accept-Ranges', 'bytes') + .expect(200, '

{{user.name}}

', done) + }) + + it('should respond with requested byte range', function (done) { + var app = express() + + app.get('/', function (req, res) { + res.download('test/fixtures/user.html') + }) + + request(app) + .get('/') + .set('Range', 'bytes=0-2') + .expect('Content-Range', 'bytes 0-2/20') + .expect(206, '

', done) + }) }) describe('.download(path, filename)', function(){ From 744564fcf806311fdc88fb1d8b4097560d514ad7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Feb 2022 16:19:01 -0500 Subject: [PATCH 11/30] tests: add test for multiple ips in "trust proxy" --- test/req.ip.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/req.ip.js b/test/req.ip.js index 1cd255216b..23623cfce6 100644 --- a/test/req.ip.js +++ b/test/req.ip.js @@ -21,7 +21,7 @@ describe('req', function(){ .expect('client', done); }) - it('should return the addr after trusted proxy', function(done){ + it('should return the addr after trusted proxy based on count', function (done) { var app = express(); app.set('trust proxy', 2); @@ -36,6 +36,21 @@ describe('req', function(){ .expect('p1', done); }) + it('should return the addr after trusted proxy based on list', function (done) { + var app = express() + + app.set('trust proxy', '10.0.0.1, 10.0.0.2, 127.0.0.1, ::1') + + app.get('/', function (req, res) { + res.send(req.ip) + }) + + request(app) + .get('/') + .set('X-Forwarded-For', '10.0.0.2, 10.0.0.3, 10.0.0.1', '10.0.0.4') + .expect('10.0.0.3', done) + }) + it('should return the addr after trusted proxy, from sub app', function (done) { var app = express(); var sub = express(); From 89bb531b311e2670a12dc020d69adb91327aa7e0 Mon Sep 17 00:00:00 2001 From: caioagiani Date: Thu, 3 Feb 2022 23:54:57 -0300 Subject: [PATCH 12/30] docs: fix typo in res.download jsdoc closes #4805 --- lib/response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index 48239a475a..ba02008522 100644 --- a/lib/response.js +++ b/lib/response.js @@ -524,7 +524,7 @@ res.sendfile = deprecate.function(res.sendfile, * Optionally providing an alternate attachment `filename`, * and optional callback `callback(err)`. The callback is invoked * when the data transfer is complete, or when an error has - * ocurred. Be sure to check `res.headersSent` if you plan to respond. + * occurred. Be sure to check `res.headersSent` if you plan to respond. * * Optionally providing an `options` object to use with `res.sendFile()`. * This function will set the `Content-Disposition` header, overriding From 2bc734aa3f76db2984368134736e1ddf2d325e6a Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:21:11 -0500 Subject: [PATCH 13/30] deps: accepts@~1.3.8 --- History.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 41cacce786..57df902afe 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,10 @@ +unreleased +========== + + * deps: accepts@~1.3.8 + - deps: mime-types@~2.1.34 + - deps: negotiator@0.6.3 + 4.17.2 / 2021-12-16 =================== diff --git a/package.json b/package.json index ebb7425d9a..dc86d680cc 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "api" ], "dependencies": { - "accepts": "~1.3.7", + "accepts": "~1.3.8", "array-flatten": "1.1.1", "body-parser": "1.19.1", "content-disposition": "0.5.4", From 6fbc269563c53297d29b69b89fd71b74c1dbd6ce Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:34:56 -0500 Subject: [PATCH 14/30] pref: remove unnecessary regexp for trust proxy --- History.md | 1 + lib/utils.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 57df902afe..493ea189ff 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ unreleased * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 - deps: negotiator@0.6.3 + * pref: remove unnecessary regexp for trust proxy 4.17.2 / 2021-12-16 =================== diff --git a/lib/utils.js b/lib/utils.js index a9ef259ff1..7797b06853 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -228,7 +228,8 @@ exports.compileTrust = function(val) { if (typeof val === 'string') { // Support comma-separated values - val = val.split(/ *, */); + val = val.split(',') + .map(function (v) { return v.trim() }) } return proxyaddr.compile(val || []); From 9cbbc8ae74c63ec79b04971923493533066bf4d2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:35:50 -0500 Subject: [PATCH 15/30] deps: cookie@0.4.2 --- History.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 493ea189ff..140756cd03 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ unreleased * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 - deps: negotiator@0.6.3 + * deps: cookie@0.4.2 * pref: remove unnecessary regexp for trust proxy 4.17.2 / 2021-12-16 diff --git a/package.json b/package.json index dc86d680cc..bc24d1a4f4 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "body-parser": "1.19.1", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.4.1", + "cookie": "0.4.2", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "~1.1.2", From 1c7bbcc143296576e12ffe0fb9a35d43ede43ae7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:36:47 -0500 Subject: [PATCH 16/30] build: Node.js@14.19 --- .github/workflows/ci.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2a4945645..98314e57f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,7 +88,7 @@ jobs: node-version: "13.14" - name: Node.js 14.x - node-version: "14.18" + node-version: "14.19" steps: - uses: actions/checkout@v2 diff --git a/appveyor.yml b/appveyor.yml index 785c799e8f..01e357f104 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,7 +15,7 @@ environment: - nodejs_version: "11.15" - nodejs_version: "12.22" - nodejs_version: "13.14" - - nodejs_version: "14.18" + - nodejs_version: "14.19" cache: - node_modules install: From 43cc56eb9e529774535a992422ee90b5c9e15ff9 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 16:48:33 -0500 Subject: [PATCH 17/30] build: clean up gitignore --- .gitignore | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 5fee6a2dc9..a1e980205f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,14 @@ -# OS X -.DS_Store* -Icon? -._* - -# Windows -Thumbs.db -ehthumbs.db -Desktop.ini - -# Linux -.directory -*~ - - # npm node_modules package-lock.json *.log *.gz - # Coveralls coverage # Benchmarking benchmarks/graphs + +# ignore additional files using core.excludesFile +# https://git-scm.com/docs/gitignore From 9d0976229d48c22e8f47dee6349bc4531035657f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 21:14:41 -0500 Subject: [PATCH 18/30] build: supertest@6.2.2 --- .github/workflows/ci.yml | 4 +-- appveyor.yml | 3 ++ package.json | 2 +- test/res.sendFile.js | 76 ++++++++++++++++++++++++---------------- 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98314e57f8..c6eba737f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,11 +59,11 @@ jobs: - name: Node.js 6.x node-version: "6.17" - npm-i: mocha@6.2.2 + npm-i: mocha@6.2.2 supertest@6.1.6 - name: Node.js 7.x node-version: "7.10" - npm-i: mocha@6.2.2 + npm-i: mocha@6.2.2 supertest@6.1.6 - name: Node.js 8.x node-version: "8.17" diff --git a/appveyor.yml b/appveyor.yml index 01e357f104..ca108e24fb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -58,10 +58,13 @@ install: # supertest for http calls # - use 2.0.0 for Node.js < 4 # - use 3.4.2 for Node.js < 6 + # - use 6.1.6 for Node.js < 8 if ([int]$env:nodejs_version.split(".")[0] -lt 4) { npm install --silent --save-dev supertest@2.0.0 } elseif ([int]$env:nodejs_version.split(".")[0] -lt 6) { npm install --silent --save-dev supertest@3.4.2 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 8) { + npm install --silent --save-dev supertest@6.1.6 } # Update Node.js modules - ps: | diff --git a/package.json b/package.json index bc24d1a4f4..b3eedce29c 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "multiparty": "4.2.2", "pbkdf2-password": "1.2.1", "should": "13.2.3", - "supertest": "6.1.6", + "supertest": "6.2.2", "vhost": "~3.0.2" }, "engines": { diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 5f494f1e0b..183faceb1d 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -112,12 +112,11 @@ describe('res', function(){ app.use(function (req, res) { setImmediate(function () { res.sendFile(path.resolve(fixtures, 'name.txt')); - server.close(cb) setTimeout(function () { cb(error) }, 10) }) - test.abort(); + test.req.abort() }); app.use(function (err, req, res, next) { @@ -127,7 +126,10 @@ describe('res', function(){ var server = app.listen() var test = request(server).get('/') - test.end() + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) describe('with "cacheControl" option', function () { @@ -272,43 +274,49 @@ describe('res', function(){ }) it('should invoke the callback when client aborts', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { setImmediate(function () { res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback when client already aborted', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { onFinished(res, function () { res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback without error when HEAD', function (done) { @@ -398,43 +406,49 @@ describe('res', function(){ }) it('should invoke the callback when client aborts', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { setImmediate(function () { res.sendfile('test/fixtures/name.txt', function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback when client already aborted', function (done) { - var cb = after(1, done); + var cb = after(2, done) var app = express(); app.use(function (req, res) { onFinished(res, function () { res.sendfile('test/fixtures/name.txt', function (err) { - should(err).be.ok() - err.code.should.equal('ECONNABORTED'); - server.close(cb) + assert.ok(err) + assert.strictEqual(err.code, 'ECONNABORTED') + cb() }); }); - test.abort(); + test.req.abort() }); var server = app.listen() var test = request(server).get('/') - test.expect(200, cb); + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) it('should invoke the callback without error when HEAD', function (done) { @@ -652,12 +666,11 @@ describe('res', function(){ app.use(function (req, res) { setImmediate(function () { res.sendfile(path.resolve(fixtures, 'name.txt')); - server.close(cb) setTimeout(function () { cb(error) }, 10) }); - test.abort(); + test.req.abort() }); app.use(function (err, req, res, next) { @@ -667,7 +680,10 @@ describe('res', function(){ var server = app.listen() var test = request(server).get('/') - test.end() + test.end(function (err) { + assert.ok(err) + server.close(cb) + }) }) describe('with an absolute path', function(){ From 2585f209f98f91da68739bdb33b599df45b3a6e6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 4 Feb 2022 21:18:47 -0500 Subject: [PATCH 19/30] tests: fix test missing assertion --- test/res.download.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/res.download.js b/test/res.download.js index 658d80af4f..579f8c67a9 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -88,7 +88,7 @@ describe('res', function(){ var cb = after(2, done); app.use(function(req, res){ - res.download('test/fixtures/user.html', 'document', done); + res.download('test/fixtures/user.html', 'document', cb) }); request(app) From 7511d083283529f865ade6fedac08716f0efde05 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 7 Feb 2022 17:46:47 -0500 Subject: [PATCH 20/30] build: use minimatch@3.0.4 for Node.js < 4 --- .github/workflows/ci.yml | 10 +++++----- appveyor.yml | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6eba737f9..416ece0959 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,23 +31,23 @@ jobs: include: - name: Node.js 0.10 node-version: "0.10" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: io.js 1.x node-version: "1.8" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: io.js 2.x node-version: "2.5" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: io.js 3.x node-version: "3.3" - npm-i: mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 - name: Node.js 4.x node-version: "4.9" diff --git a/appveyor.yml b/appveyor.yml index ca108e24fb..c1b51ca7cd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,11 @@ install: sls "^eslint(-|$)" | ` %{ npm rm --silent --save-dev $_ } # Setup Node.js version-specific dependencies + - ps: | + # minimatch for Node.js < 4 + if ([int]$env:nodejs_version.split(".")[0] -lt 4) { + npm install --silent --save-dev minimatch@3.0.4 + } - ps: | # mocha for testing # - use 3.x for Node.js < 4 From 884657d54665f323c236055d6e3d3e85d96e5f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Strau=C3=9F?= <49093997+thst71@users.noreply.github.com> Date: Sun, 6 Feb 2022 16:59:17 +0100 Subject: [PATCH 21/30] examples: remove bitwise syntax for includes check closes #4814 --- examples/web-service/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/web-service/index.js b/examples/web-service/index.js index c22fea4032..a2cd2cb7f9 100644 --- a/examples/web-service/index.js +++ b/examples/web-service/index.js @@ -34,7 +34,7 @@ app.use('/api', function(req, res, next){ if (!key) return next(error(400, 'api key required')); // key is invalid - if (!~apiKeys.indexOf(key)) return next(error(401, 'invalid api key')); + if (apiKeys.indexOf(key) === -1) return next(error(401, 'invalid api key')) // all good, store req.key for route access req.key = key; From 12310c52947ee159f7ecd63d125243cdca891135 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 7 Feb 2022 23:08:12 -0500 Subject: [PATCH 22/30] build: use nyc for test coverage --- .github/workflows/ci.yml | 18 +++++++++--------- .gitignore | 1 + appveyor.yml | 12 ++++++++++++ package.json | 6 +++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 416ece0959..30da0e25c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,39 +31,39 @@ jobs: include: - name: Node.js 0.10 node-version: "0.10" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 1.x node-version: "1.8" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 2.x node-version: "2.5" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 3.x node-version: "3.3" - npm-i: minimatch@3.0.4 mocha@3.5.3 supertest@2.0.0 + npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 4.x node-version: "4.9" - npm-i: mocha@5.2.0 supertest@3.4.2 + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - name: Node.js 5.x node-version: "5.12" - npm-i: mocha@5.2.0 supertest@3.4.2 + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - name: Node.js 6.x node-version: "6.17" - npm-i: mocha@6.2.2 supertest@6.1.6 + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 7.x node-version: "7.10" - npm-i: mocha@6.2.2 supertest@6.1.6 + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 8.x node-version: "8.17" diff --git a/.gitignore b/.gitignore index a1e980205f..3a673d9cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ package-lock.json *.gz # Coveralls +.nyc_output coverage # Benchmarking diff --git a/appveyor.yml b/appveyor.yml index c1b51ca7cd..1052be0097 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -59,6 +59,18 @@ install: } elseif ([int]$env:nodejs_version.split(".")[0] -lt 12) { npm install --silent --save-dev mocha@8.4.0 } + - ps: | + # nyc for test coverage + # - use 10.3.2 for Node.js < 4 + # - use 11.9.0 for Node.js < 6 + # - use 14.1.1 for Node.js < 8 + if ([int]$env:nodejs_version.split(".")[0] -lt 4) { + npm install --silent --save-dev nyc@10.3.2 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 6) { + npm install --silent --save-dev nyc@11.9.0 + } elseif ([int]$env:nodejs_version.split(".")[0] -lt 8) { + npm install --silent --save-dev nyc@14.1.1 + } - ps: | # supertest for http calls # - use 2.0.0 for Node.js < 4 diff --git a/package.json b/package.json index b3eedce29c..daa2f0d3a1 100644 --- a/package.json +++ b/package.json @@ -68,12 +68,12 @@ "eslint": "7.32.0", "express-session": "1.17.2", "hbs": "4.2.0", - "istanbul": "0.4.5", "marked": "0.7.0", "method-override": "3.0.0", "mocha": "9.2.0", "morgan": "1.10.0", "multiparty": "4.2.2", + "nyc": "15.1.0", "pbkdf2-password": "1.2.1", "should": "13.2.3", "supertest": "6.2.2", @@ -92,8 +92,8 @@ "scripts": { "lint": "eslint .", "test": "mocha --require test/support/env --reporter spec --bail --check-leaks test/ test/acceptance/", - "test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --require test/support/env --reporter spec --check-leaks test/ test/acceptance/", - "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --require test/support/env --reporter dot --check-leaks test/ test/acceptance/", + "test-ci": "nyc --reporter=lcovonly --reporter=text npm test", + "test-cov": "nyc --reporter=html --reporter=text npm test", "test-tap": "mocha --require test/support/env --reporter tap --check-leaks test/ test/acceptance/" } } From 82de4de5ab92e8237d713285104e4b8452927352 Mon Sep 17 00:00:00 2001 From: KoyamaSohei Date: Fri, 13 Dec 2019 14:38:56 +0900 Subject: [PATCH 23/30] examples: fix path traversal in downloads example closes #4120 --- examples/downloads/index.js | 7 ++++++- package.json | 1 + test/acceptance/downloads.js | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/downloads/index.js b/examples/downloads/index.js index 91c52bb87c..62e7fa6e3e 100644 --- a/examples/downloads/index.js +++ b/examples/downloads/index.js @@ -6,8 +6,13 @@ var express = require('../../'); var path = require('path'); +var resolvePath = require('resolve-path') + var app = module.exports = express(); +// path to where the files are stored on disk +var FILES_DIR = path.join(__dirname, 'files') + app.get('/', function(req, res){ res.send('

    ' + '
  • Download notes/groceries.txt.
  • ' + @@ -20,7 +25,7 @@ app.get('/', function(req, res){ // /files/* is accessed via req.params[0] // but here we name it :file app.get('/files/:file(*)', function(req, res, next){ - var filePath = path.join(__dirname, 'files', req.params.file); + var filePath = resolvePath(FILES_DIR, req.params.file) res.download(filePath, function (err) { if (!err) return; // file sent diff --git a/package.json b/package.json index daa2f0d3a1..fe5d07553f 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "multiparty": "4.2.2", "nyc": "15.1.0", "pbkdf2-password": "1.2.1", + "resolve-path": "1.4.0", "should": "13.2.3", "supertest": "6.2.2", "vhost": "~3.0.2" diff --git a/test/acceptance/downloads.js b/test/acceptance/downloads.js index ae44388354..6db43b351e 100644 --- a/test/acceptance/downloads.js +++ b/test/acceptance/downloads.js @@ -36,4 +36,12 @@ describe('downloads', function(){ .expect(404, done) }) }) + + describe('GET /files/../index.js', function () { + it('should respond with 403', function (done) { + request(app) + .get('/files/../index.js') + .expect(403, done) + }) + }) }) From a39e409cf3739ef9c9b597a9680813a34c3931c2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 8 Feb 2022 18:40:07 -0500 Subject: [PATCH 24/30] tests: prevent leaking changes to NODE_ENV --- test/app.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/app.js b/test/app.js index d0756795d3..70f72de7c7 100644 --- a/test/app.js +++ b/test/app.js @@ -83,28 +83,49 @@ describe('app.path()', function(){ }) describe('in development', function(){ + before(function () { + this.env = process.env.NODE_ENV + process.env.NODE_ENV = 'development' + }) + + after(function () { + process.env.NODE_ENV = this.env + }) + it('should disable "view cache"', function(){ - process.env.NODE_ENV = 'development'; var app = express(); assert.ok(!app.enabled('view cache')) - process.env.NODE_ENV = 'test'; }) }) describe('in production', function(){ + before(function () { + this.env = process.env.NODE_ENV + process.env.NODE_ENV = 'production' + }) + + after(function () { + process.env.NODE_ENV = this.env + }) + it('should enable "view cache"', function(){ - process.env.NODE_ENV = 'production'; var app = express(); assert.ok(app.enabled('view cache')) - process.env.NODE_ENV = 'test'; }) }) describe('without NODE_ENV', function(){ + before(function () { + this.env = process.env.NODE_ENV + process.env.NODE_ENV = '' + }) + + after(function () { + process.env.NODE_ENV = this.env + }) + it('should default to development', function(){ - process.env.NODE_ENV = ''; var app = express(); assert.strictEqual(app.get('env'), 'development') - process.env.NODE_ENV = 'test'; }) }) From a65913776d0b16837364ee66caa1a7f38a9997c0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 9 Feb 2022 01:07:08 -0500 Subject: [PATCH 25/30] tests: use strict mode --- test/Route.js | 1 + test/Router.js | 1 + test/app.all.js | 1 + test/app.del.js | 1 + test/app.engine.js | 1 + test/app.head.js | 1 + test/app.js | 1 + test/app.listen.js | 1 + test/app.locals.js | 1 + test/app.options.js | 1 + test/app.param.js | 1 + test/app.render.js | 1 + test/app.request.js | 1 + test/app.response.js | 1 + test/app.route.js | 2 ++ test/app.router.js | 1 + test/app.routes.error.js | 1 + test/app.use.js | 1 + test/config.js | 1 + test/exports.js | 1 + test/express.json.js | 1 + test/express.raw.js | 1 + test/express.static.js | 1 + test/express.text.js | 1 + test/express.urlencoded.js | 1 + test/middleware.basic.js | 1 + test/regression.js | 1 + test/req.accepts.js | 1 + test/req.acceptsCharset.js | 1 + test/req.acceptsCharsets.js | 1 + test/req.acceptsEncoding.js | 1 + test/req.acceptsEncodings.js | 1 + test/req.acceptsLanguage.js | 1 + test/req.acceptsLanguages.js | 1 + test/req.baseUrl.js | 1 + test/req.fresh.js | 1 + test/req.get.js | 1 + test/req.host.js | 1 + test/req.hostname.js | 1 + test/req.ip.js | 1 + test/req.ips.js | 1 + test/req.is.js | 1 + test/req.param.js | 1 + test/req.path.js | 1 + test/req.protocol.js | 1 + test/req.query.js | 1 + test/req.range.js | 1 + test/req.route.js | 1 + test/req.secure.js | 1 + test/req.signedCookies.js | 1 + test/req.stale.js | 1 + test/req.subdomains.js | 1 + test/req.xhr.js | 1 + test/res.append.js | 1 + test/res.attachment.js | 1 + test/res.clearCookie.js | 1 + test/res.cookie.js | 1 + test/res.download.js | 1 + test/res.format.js | 1 + test/res.get.js | 1 + test/res.json.js | 1 + test/res.jsonp.js | 1 + test/res.links.js | 1 + test/res.locals.js | 1 + test/res.location.js | 1 + test/res.redirect.js | 1 + test/res.render.js | 1 + test/res.send.js | 1 + test/res.sendFile.js | 1 + test/res.sendStatus.js | 1 + test/res.set.js | 1 + test/res.status.js | 1 + test/res.type.js | 1 + test/res.vary.js | 1 + test/utils.js | 1 + 75 files changed, 76 insertions(+) diff --git a/test/Route.js b/test/Route.js index 8f90152d8c..005b4634e9 100644 --- a/test/Route.js +++ b/test/Route.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var should = require('should'); diff --git a/test/Router.js b/test/Router.js index 16522f6aa8..907b972636 100644 --- a/test/Router.js +++ b/test/Router.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var express = require('../') diff --git a/test/app.all.js b/test/app.all.js index 45c3ddb93b..185a8332fe 100644 --- a/test/app.all.js +++ b/test/app.all.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/app.del.js b/test/app.del.js index d419fbb158..e9e5769d65 100644 --- a/test/app.del.js +++ b/test/app.del.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/app.engine.js b/test/app.engine.js index 0d54c90d56..214510a94c 100644 --- a/test/app.engine.js +++ b/test/app.engine.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.head.js b/test/app.head.js index 6aa1bb8003..fabb98795a 100644 --- a/test/app.head.js +++ b/test/app.head.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../'); var request = require('supertest'); diff --git a/test/app.js b/test/app.js index 70f72de7c7..6134717c33 100644 --- a/test/app.js +++ b/test/app.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('..') diff --git a/test/app.listen.js b/test/app.listen.js index 9d54ca5244..08eeaaa63c 100644 --- a/test/app.listen.js +++ b/test/app.listen.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') diff --git a/test/app.locals.js b/test/app.locals.js index 0b14ac9070..88f83c9483 100644 --- a/test/app.locals.js +++ b/test/app.locals.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.options.js b/test/app.options.js index 9c88abafe5..fdfd38c8a2 100644 --- a/test/app.options.js +++ b/test/app.options.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/app.param.js b/test/app.param.js index 7dbe3ffb61..8893851f9d 100644 --- a/test/app.param.js +++ b/test/app.param.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.render.js b/test/app.render.js index d0b367189b..9d202acfdd 100644 --- a/test/app.render.js +++ b/test/app.render.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('..'); diff --git a/test/app.request.js b/test/app.request.js index 0288f80b09..4930af84c2 100644 --- a/test/app.request.js +++ b/test/app.request.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/app.response.js b/test/app.response.js index ea696b566f..5fb69f6275 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/app.route.js b/test/app.route.js index 75e5e0b842..eaf8a12051 100644 --- a/test/app.route.js +++ b/test/app.route.js @@ -1,3 +1,5 @@ +'use strict' + var express = require('../'); var request = require('supertest'); diff --git a/test/app.router.js b/test/app.router.js index 8c98aa869b..3069a22c77 100644 --- a/test/app.router.js +++ b/test/app.router.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var express = require('../') diff --git a/test/app.routes.error.js b/test/app.routes.error.js index b1f95d0d6e..56081b3112 100644 --- a/test/app.routes.error.js +++ b/test/app.routes.error.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/app.use.js b/test/app.use.js index 55ba0689c8..fd9b1751a3 100644 --- a/test/app.use.js +++ b/test/app.use.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var assert = require('assert') diff --git a/test/config.js b/test/config.js index 17a02b7eba..8386a4471c 100644 --- a/test/config.js +++ b/test/config.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert'); var express = require('..'); diff --git a/test/exports.js b/test/exports.js index 7624a8c864..98d7936594 100644 --- a/test/exports.js +++ b/test/exports.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../'); diff --git a/test/express.json.js b/test/express.json.js index 907fa0cfeb..53a39565a9 100644 --- a/test/express.json.js +++ b/test/express.json.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.raw.js b/test/express.raw.js index 571c29ca9b..cbd0736e7c 100644 --- a/test/express.raw.js +++ b/test/express.raw.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.static.js b/test/express.static.js index 56d3657bff..245fd5929c 100644 --- a/test/express.static.js +++ b/test/express.static.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.text.js b/test/express.text.js index 7c92f90e5a..ebc12cd109 100644 --- a/test/express.text.js +++ b/test/express.text.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/express.urlencoded.js b/test/express.urlencoded.js index 6011de05f7..340eb74316 100644 --- a/test/express.urlencoded.js +++ b/test/express.urlencoded.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/middleware.basic.js b/test/middleware.basic.js index 4616842ed6..19f00d9a29 100644 --- a/test/middleware.basic.js +++ b/test/middleware.basic.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../'); diff --git a/test/regression.js b/test/regression.js index 5d4509ed6f..4e99b30694 100644 --- a/test/regression.js +++ b/test/regression.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.accepts.js b/test/req.accepts.js index 0df4780e22..2066fb5185 100644 --- a/test/req.accepts.js +++ b/test/req.accepts.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsCharset.js b/test/req.acceptsCharset.js index f7d0cc0e30..6dbab439b7 100644 --- a/test/req.acceptsCharset.js +++ b/test/req.acceptsCharset.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsCharsets.js b/test/req.acceptsCharsets.js index d1c459174a..360a9878a7 100644 --- a/test/req.acceptsCharsets.js +++ b/test/req.acceptsCharsets.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsEncoding.js b/test/req.acceptsEncoding.js index f2af68da22..bcec2280e6 100644 --- a/test/req.acceptsEncoding.js +++ b/test/req.acceptsEncoding.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsEncodings.js b/test/req.acceptsEncodings.js index dc21c4edda..c36934290a 100644 --- a/test/req.acceptsEncodings.js +++ b/test/req.acceptsEncodings.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsLanguage.js b/test/req.acceptsLanguage.js index 616e723946..816be244eb 100644 --- a/test/req.acceptsLanguage.js +++ b/test/req.acceptsLanguage.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.acceptsLanguages.js b/test/req.acceptsLanguages.js index 87bf7b25df..e5629fbc32 100644 --- a/test/req.acceptsLanguages.js +++ b/test/req.acceptsLanguages.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.baseUrl.js b/test/req.baseUrl.js index 9ac9d88029..b70803ea8b 100644 --- a/test/req.baseUrl.js +++ b/test/req.baseUrl.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/req.fresh.js b/test/req.fresh.js index 1aa8fa5b21..9160e2caaf 100644 --- a/test/req.fresh.js +++ b/test/req.fresh.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.get.js b/test/req.get.js index 109a2d90ce..16589b3f05 100644 --- a/test/req.get.js +++ b/test/req.get.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.host.js b/test/req.host.js index 7bb0b27acf..2c051fb979 100644 --- a/test/req.host.js +++ b/test/req.host.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.hostname.js b/test/req.hostname.js index 09bfb89989..b3716b566a 100644 --- a/test/req.hostname.js +++ b/test/req.hostname.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.ip.js b/test/req.ip.js index 23623cfce6..6bb3c5ac52 100644 --- a/test/req.ip.js +++ b/test/req.ip.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.ips.js b/test/req.ips.js index a7d464b846..2f9a0736ea 100644 --- a/test/req.ips.js +++ b/test/req.ips.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.is.js b/test/req.is.js index a2fce17867..c5904dd600 100644 --- a/test/req.is.js +++ b/test/req.is.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/req.param.js b/test/req.param.js index 89f0295cd9..b3748c02bc 100644 --- a/test/req.param.js +++ b/test/req.param.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.path.js b/test/req.path.js index 6ad4009c7d..3ff6177c74 100644 --- a/test/req.path.js +++ b/test/req.path.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.protocol.js b/test/req.protocol.js index 453ad11ca4..61f76356b4 100644 --- a/test/req.protocol.js +++ b/test/req.protocol.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.query.js b/test/req.query.js index f3e8df8a18..6fae592dcc 100644 --- a/test/req.query.js +++ b/test/req.query.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('../') diff --git a/test/req.range.js b/test/req.range.js index 5443c0658d..111441736e 100644 --- a/test/req.range.js +++ b/test/req.range.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest') diff --git a/test/req.route.js b/test/req.route.js index b32d470bd6..6c17fbb1c8 100644 --- a/test/req.route.js +++ b/test/req.route.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.secure.js b/test/req.secure.js index 2025c8786b..0097ed6136 100644 --- a/test/req.secure.js +++ b/test/req.secure.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.signedCookies.js b/test/req.signedCookies.js index a55f81b22c..db56195166 100644 --- a/test/req.signedCookies.js +++ b/test/req.signedCookies.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/req.stale.js b/test/req.stale.js index 30c9d05d51..cda77fa403 100644 --- a/test/req.stale.js +++ b/test/req.stale.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.subdomains.js b/test/req.subdomains.js index 18e4d80ad3..e5600f2eb5 100644 --- a/test/req.subdomains.js +++ b/test/req.subdomains.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/req.xhr.js b/test/req.xhr.js index 3ad1c6fb72..99cf7f1917 100644 --- a/test/req.xhr.js +++ b/test/req.xhr.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.append.js b/test/res.append.js index f7f1d55b3c..5b12e35b69 100644 --- a/test/res.append.js +++ b/test/res.append.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/res.attachment.js b/test/res.attachment.js index 4c3d4aa2f1..6283ded0d6 100644 --- a/test/res.attachment.js +++ b/test/res.attachment.js @@ -1,3 +1,4 @@ +'use strict' var Buffer = require('safe-buffer').Buffer var express = require('../') diff --git a/test/res.clearCookie.js b/test/res.clearCookie.js index 4822057e92..fc0cfb99a3 100644 --- a/test/res.clearCookie.js +++ b/test/res.clearCookie.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.cookie.js b/test/res.cookie.js index 8f8662c217..d10e48646b 100644 --- a/test/res.cookie.js +++ b/test/res.cookie.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/res.download.js b/test/res.download.js index 579f8c67a9..ce0ee088ba 100644 --- a/test/res.download.js +++ b/test/res.download.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var assert = require('assert'); diff --git a/test/res.format.js b/test/res.format.js index 076b78d738..24e18d9552 100644 --- a/test/res.format.js +++ b/test/res.format.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after') var express = require('../') diff --git a/test/res.get.js b/test/res.get.js index a53bdc3380..a5f12e2e53 100644 --- a/test/res.get.js +++ b/test/res.get.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/res.json.js b/test/res.json.js index 59227a830b..dcaceae5ca 100644 --- a/test/res.json.js +++ b/test/res.json.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/res.jsonp.js b/test/res.jsonp.js index 3444d5138b..0735d43bd5 100644 --- a/test/res.jsonp.js +++ b/test/res.jsonp.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest') diff --git a/test/res.links.js b/test/res.links.js index 36630c9ccc..240b7fcfda 100644 --- a/test/res.links.js +++ b/test/res.links.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/res.locals.js b/test/res.locals.js index a1c819667a..c4365b36f3 100644 --- a/test/res.locals.js +++ b/test/res.locals.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.location.js b/test/res.location.js index c0bfbe8c8e..158afac01e 100644 --- a/test/res.location.js +++ b/test/res.location.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.redirect.js b/test/res.redirect.js index c07df5dd2c..be7c773bee 100644 --- a/test/res.redirect.js +++ b/test/res.redirect.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var express = require('..'); diff --git a/test/res.render.js b/test/res.render.js index 643a57002a..50f0b0a742 100644 --- a/test/res.render.js +++ b/test/res.render.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var path = require('path') diff --git a/test/res.send.js b/test/res.send.js index e62caf95dc..8f849f8069 100644 --- a/test/res.send.js +++ b/test/res.send.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert') var Buffer = require('safe-buffer').Buffer diff --git a/test/res.sendFile.js b/test/res.sendFile.js index 183faceb1d..c7fc93a76d 100644 --- a/test/res.sendFile.js +++ b/test/res.sendFile.js @@ -1,3 +1,4 @@ +'use strict' var after = require('after'); var Buffer = require('safe-buffer').Buffer diff --git a/test/res.sendStatus.js b/test/res.sendStatus.js index c355bc408f..9b1de8385c 100644 --- a/test/res.sendStatus.js +++ b/test/res.sendStatus.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..') var request = require('supertest') diff --git a/test/res.set.js b/test/res.set.js index e46d123947..04511c1c95 100644 --- a/test/res.set.js +++ b/test/res.set.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/res.status.js b/test/res.status.js index 8c173a645c..e0abc73c4c 100644 --- a/test/res.status.js +++ b/test/res.status.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.type.js b/test/res.type.js index cc1dd08d41..980717a6e3 100644 --- a/test/res.type.js +++ b/test/res.type.js @@ -1,3 +1,4 @@ +'use strict' var express = require('../') , request = require('supertest'); diff --git a/test/res.vary.js b/test/res.vary.js index 9d39a341c0..1efc20b445 100644 --- a/test/res.vary.js +++ b/test/res.vary.js @@ -1,3 +1,4 @@ +'use strict' var express = require('..'); var request = require('supertest'); diff --git a/test/utils.js b/test/utils.js index a0fac7a722..f0cb3c3761 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,3 +1,4 @@ +'use strict' var assert = require('assert'); var Buffer = require('safe-buffer').Buffer From e98f5848a0a496c0977a2d1734067b77f69de360 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 14 Feb 2022 18:42:47 -0500 Subject: [PATCH 26/30] Revert "build: use minimatch@3.0.4 for Node.js < 4" --- .github/workflows/ci.yml | 10 +++++----- appveyor.yml | 5 ----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30da0e25c3..d6e1b168ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,23 +31,23 @@ jobs: include: - name: Node.js 0.10 node-version: "0.10" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 0.12 node-version: "0.12" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 1.x node-version: "1.8" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 2.x node-version: "2.5" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: io.js 3.x node-version: "3.3" - npm-i: minimatch@3.0.4 mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - name: Node.js 4.x node-version: "4.9" diff --git a/appveyor.yml b/appveyor.yml index 1052be0097..db54a3fdb0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,11 +36,6 @@ install: sls "^eslint(-|$)" | ` %{ npm rm --silent --save-dev $_ } # Setup Node.js version-specific dependencies - - ps: | - # minimatch for Node.js < 4 - if ([int]$env:nodejs_version.split(".")[0] -lt 4) { - npm install --silent --save-dev minimatch@3.0.4 - } - ps: | # mocha for testing # - use 3.x for Node.js < 4 From a00786309641731661edb4d826a6919330887ca7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 15 Feb 2022 23:43:41 -0500 Subject: [PATCH 27/30] deps: body-parser@1.19.2 --- History.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 140756cd03..2550cba59b 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,10 @@ unreleased * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 - deps: negotiator@0.6.3 + * deps: body-parser@1.19.2 + - deps: bytes@3.1.2 + - deps: qs@6.9.7 + - deps: raw-body@2.4.3 * deps: cookie@0.4.2 * pref: remove unnecessary regexp for trust proxy diff --git a/package.json b/package.json index fe5d07553f..a028b3896c 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.19.1", + "body-parser": "1.19.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", "cookie": "0.4.2", From 6381bc6317ec8ffbf830e2d16677e4b5af37cc08 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 00:03:16 -0500 Subject: [PATCH 28/30] deps: qs@6.9.7 --- History.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 2550cba59b..e57f098a9f 100644 --- a/History.md +++ b/History.md @@ -9,6 +9,8 @@ unreleased - deps: qs@6.9.7 - deps: raw-body@2.4.3 * deps: cookie@0.4.2 + * deps: qs@6.9.7 + * Fix handling of `__proto__` keys * pref: remove unnecessary regexp for trust proxy 4.17.2 / 2021-12-16 diff --git a/package.json b/package.json index a028b3896c..4816ae1b4a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", "proxy-addr": "~2.0.7", - "qs": "6.9.6", + "qs": "6.9.7", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", "send": "0.17.2", From f9063712e01979588818b0756851053b5ee43d09 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 00:11:24 -0500 Subject: [PATCH 29/30] build: update example dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4816ae1b4a..2ff077f833 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "method-override": "3.0.0", "mocha": "9.2.0", "morgan": "1.10.0", - "multiparty": "4.2.2", + "multiparty": "4.2.3", "nyc": "15.1.0", "pbkdf2-password": "1.2.1", "resolve-path": "1.4.0", From 3d7fce56a35f4f73fa437866cd1401587a212334 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 16 Feb 2022 21:03:42 -0500 Subject: [PATCH 30/30] 4.17.3 --- History.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index e57f098a9f..9f3f876512 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,5 @@ -unreleased -========== +4.17.3 / 2022-02-16 +=================== * deps: accepts@~1.3.8 - deps: mime-types@~2.1.34 diff --git a/package.json b/package.json index 2ff077f833..2fb6ebaab0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "express", "description": "Fast, unopinionated, minimalist web framework", - "version": "4.17.2", + "version": "4.17.3", "author": "TJ Holowaychuk ", "contributors": [ "Aaron Heckmann ",