Skip to content
Myr

response.test.js

This file

Path

test/response.test.js

306 lines · 10.4 KiB · JavaScript

Last changed by

res.sendfile() responding with 403 on malicious pathTj Holowaychukbefore adoption177a724

History of this file

Take it

The walk stopped after 200 commits: lines older than 5f59303 point at it.

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 1–38why, one step back
1
2/**3 * Module dependencies.4 */56var express = require('express'),7 Buffer = require('buffer').Buffer;89module.exports = {10 'test #send()': function(assert){11 var app = express.createServer();1213 app.get('/html', function(req, res){14 res.send('<p>test</p>', { 'Content-Language': 'en' });15 });16 17 app.get('/json', function(req, res){18 res.header('X-Foo', 'bar');19 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);20 });21 22 app.get('/text', function(req, res){23 res.header('X-Foo', 'bar');24 res.contentType('.txt');25 res.send('wahoo');26 });27 28 app.get('/status', function(req, res){29 res.send(404);30 });31 32 app.get('/error', function(req, res){33 res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);34 });35 36 app.get('/buffer', function(req, res){37 res.send(new Buffer('wahoo!'));38 });

Merge branch 'master' of github.com:visionmedia/expressTj Holowaychukbefore adoption838a51d

lines 39–42why, one step back
39
40 app.get('/noargs', function(req, res, next){41 res.send();42 });

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 43–61why, one step back
43
44 assert.response(app,45 { url: '/html' },46 { body: '<p>test</p>', headers: { 'Content-Language': 'en', 'Content-Type': 'text/html; charset=utf-8' }});47 assert.response(app,48 { url: '/json' },49 { body: '{"foo":"bar"}', status: 201, headers: { 'Content-Type': 'application/json', 'X-Foo': 'baz' }});50 assert.response(app,51 { url: '/text' },52 { body: 'wahoo', headers: { 'Content-Type': 'text/plain; charset=utf-8', 'X-Foo': 'bar' }});53 assert.response(app,54 { url: '/status' },55 { body: 'Not Found', status: 404, headers: { 'Content-Type': 'text/plain; charset=utf-8' }});56 assert.response(app,57 { url: '/error' },58 { body: 'Oh shit!', status: 500, headers: { 'Content-Type': 'text/plain' }});59 assert.response(app,60 { url: '/buffer' },61 { body: 'wahoo!', headers: { 'Content-Type': 'application/octet-stream' }});

Merge branch 'master' of github.com:visionmedia/expressTj Holowaychukbefore adoption838a51d

lines 62–67why, one step back
62 assert.response(app,
63 { url: '/noargs' },64 { status: 204 }, function(res){65 assert.equal(undefined, res.headers['content-type']);66 assert.equal(undefined, res.headers['content-length']);67 });

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 68–69why, one step back
68 },
69

Fixed test labelsTj Holowaychukbefore adoption2844b1a

line 70why, one step back
70 'test #contentType()': function(assert){

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 71–83why, one step back
71 var app = express.createServer();
72 73 app.get('/html', function(req, res){74 res.contentType('index.html');75 res.writeHead(200, res.headers);76 res.end('<p>yay</p>');77 });78 79 assert.response(app,80 { url: '/html' },81 { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html; charset=utf-8' }});82 },83

Fixed test labelsTj Holowaychukbefore adoption2844b1a

line 84why, one step back
84 'test #attachment()': function(assert){

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 85–91why, one step back
85 var app = express.createServer();
86 87 app.get('/style.css', function(req, res){88 res.attachment();89 res.send('some stylezzz');90 });91

Route callback signature changedTj Holowaychukbefore adoption75661a2

lines 92–93why, one step back
92 app.get('/*', function(req, res){
93 res.attachment(req.params[0]);

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 94–112why, one step back
94 res.send('whatever');
95 });96 97 assert.response(app,98 { url: '/javascripts/jquery.js' },99 { body: 'whatever', headers: { 'Content-Disposition': 'attachment; filename="jquery.js"' }});100 assert.response(app,101 { url: '/style.css' },102 { body: 'some stylezzz', headers: { 'Content-Disposition': 'attachment' }});103 },104 105 'test #redirect()': function(assert){106 var app = express.createServer(),107 app2 = express.createServer();108 109 app2.set('home', '/blog');110111 app2.redirect('google', 'http://google.com');112

Route callback signature changedTj Holowaychukbefore adoption75661a2

lines 113–115why, one step back
113 app2.redirect('blog', function(req, res){
114 return req.params.id115 ? '/user/' + req.params.id + '/blog'

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 116–147why, one step back
116 : null;
117 });118 119 app.get('/', function(req, res){120 res.redirect('http://google.com', 301);121 });122 123 app.get('/back', function(req, res){124 res.redirect('back');125 });126 127 app.get('/home', function(req, res){128 res.redirect('home');129 });130 131 app2.get('/', function(req, res){132 res.redirect('http://google.com', 301);133 });134 135 app2.get('/back', function(req, res){136 res.redirect('back');137 });138 139 app2.get('/home', function(req, res){140 res.redirect('home');141 });142 143 app2.get('/google', function(req, res){144 res.redirect('google');145 });146147 app2.get('/user/:id', function(req, res){

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 148why, one step back
148 res.header('X-Foo', 'bar');

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 149–153why, one step back
149 res.redirect('blog');
150 });151 152 assert.response(app,153 { url: '/' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 154why, one step back
154 { body: 'Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 155–156why, one step back
155 assert.response(app,
156 { url: '/back' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 157why, one step back
157 { body: 'Redirecting to /', status: 302, headers: { Location: '/', 'Content-Type': 'text/plain' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 158–159why, one step back
158 assert.response(app,
159 { url: '/back', headers: { Referer: '/foo' }},

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 160why, one step back
160 { body: 'Redirecting to /foo', status: 302, headers: { Location: '/foo' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 161–162why, one step back
161 assert.response(app,
162 { url: '/back', headers: { Referrer: '/foo' }},

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 163why, one step back
163 { body: 'Redirecting to /foo', status: 302, headers: { Location: '/foo' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 164–165why, one step back
164 assert.response(app,
165 { url: '/home' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 166why, one step back
166 { body: 'Redirecting to /', status: 302, headers: { Location: '/' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 167–169why, one step back
167
168 assert.response(app2,169 { url: '/' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 170why, one step back
170 { body: 'Redirecting to http://google.com', status: 301, headers: { Location: 'http://google.com' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 171–172why, one step back
171 assert.response(app2,
172 { url: '/back' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 173why, one step back
173 { body: 'Redirecting to /blog', status: 302, headers: { Location: '/blog' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 174–175why, one step back
174 assert.response(app2,
175 { url: '/home' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 176why, one step back
176 { body: 'Redirecting to /blog', status: 302, headers: { Location: '/blog' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 177–178why, one step back
177 assert.response(app2,
178 { url: '/google' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 179why, one step back
179 { body: 'Redirecting to http://google.com', headers: { Location: 'http://google.com' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 180–181why, one step back
180 assert.response(app2,
181 { url: '/user/12' },

Merge branch 'redirect-bodies'Tj Holowaychukbefore adoption640274e

line 182why, one step back
182 { body: 'Redirecting to /user/12/blog', headers: { Location: '/user/12/blog', 'X-Foo': 'bar' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 183–186why, one step back
183 },
184 185 'test #sendfile()': function(assert){186 var app = express.createServer();

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 187why, one step back
187

Merge branch 'downloads'Tj Holowaychukbefore adoption949803d

lines 188–189why, one step back
188 app.set('stream threshold', 2 * 1024)
189

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 190why, one step back
190 app.get('/*', function(req, res, next){

Added callback support for res.sendfile()Tj Holowaychukbefore adoption25909c0

lines 191–194why, one step back
191 var file = req.params[0],
192 filePath = __dirname + '/fixtures/' + file;193 res.sendfile(filePath, function(err, path){194 assert.equal(path, filePath);

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 195why, one step back
195 if (err) next(err);

Added callback support for res.sendfile()Tj Holowaychukbefore adoption25909c0

line 196why, one step back
196 });

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 197–198why, one step back
197 });
198

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 199why, one step back
199 app.use(express.errorHandler());

res.sendfile() responding with 403 on malicious pathTj Holowaychukbefore adoption177a724

lines 200–203why, one step back
200
201 assert.response(app,202 { url: '/../express.test.js' },203 { body: 'Forbidden', status: 403 });

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 204–211why, one step back
204 assert.response(app,
205 { url: '/user.json' },206 { body: '{"name":"tj"}', status: 200, headers: { 'Content-Type': 'application/json' }});207 assert.response(app,208 { url: '/hello.haml' },209 { body: '%p Hello World', status: 200, headers: { 'Content-Type': 'application/octet-stream' }});210 assert.response(app,211 { url: '/doesNotExist' },

Fixed res.sendfile() error handling, defer via next()Tj Holowaychukbefore adoption8308e50

line 212why, one step back
212 { body: 'Internal Server Error', status: 500 });

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 213–215why, one step back
213 assert.response(app,
214 { url: '/partials' },215 { body: 'Internal Server Error', status: 500 });

Merge branch 'downloads'Tj Holowaychukbefore adoption949803d

lines 216–218why, one step back
216 assert.response(app,
217 { url: '/large.json' },218 { status: 200, headers: { 'Content-Length': 2535, 'Content-Type': 'application/json' }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 219–223why, one step back
219 },
220 221 'test #download()': function(assert){222 var app = express.createServer();223

Route callback signature changedTj Holowaychukbefore adoption75661a2

line 224why, one step back
224 app.get('/json', function(req, res, next){

Added callback support to res.download()Tj Holowaychukbefore adoption6bfa759

lines 225–228why, one step back
225 var filePath = __dirname + '/fixtures/user.json';
226 res.download(filePath, 'account.json', function(err, path){227 assert.equal(filePath, path);228 });

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 229–230why, one step back
229 });
230

Fixed res.download() testTj Holowaychukbefore adoption7af7851

lines 231–232why, one step back
231 app.get('/*', function(req, res, next){
232 res.download(__dirname + '/fixtures/' + req.params[0]);

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 233–234why, one step back
233 });
234

Merge branch 'download-example'Tj Holowaychukbefore adoptionf6ba793

lines 235–238why, one step back
235 app.error(function(err, req, res){
236 res.send(404);237 })238

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 239–249why, one step back
239 assert.response(app,
240 { url: '/user.json' },241 { body: '{"name":"tj"}', status: 200, headers: {242 'Content-Type': 'application/json',243 'Content-Disposition': 'attachment; filename="user.json"'244 }});245246 assert.response(app,247 { url: '/json' },248 { body: '{"name":"tj"}', status: 200, headers: {249 'Content-Type': 'application/json',

Merge branch 'downloads'Tj Holowaychukbefore adoption949803d

line 250why, one step back
250 'Content-Length': '13',

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 251–252why, one step back
251 'Content-Disposition': 'attachment; filename="account.json"'
252 }});

Merge branch 'download-example'Tj Holowaychukbefore adoptionf6ba793

lines 253–258why, one step back
253
254 assert.response(app,255 { url: '/missing' },256 function(res){257 assert.equal(null, res.headers['content-disposition']);258 });

Merge branch 'features/cookie'Tj Holowaychukbefore adoption6521d2b

lines 259–271why, one step back
259 },
260 261 'test #cookie()': function(assert){262 var app = express.createServer();263 264 app.get('/', function(req, res){265 res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });266 res.redirect('/');267 });268 269 assert.response(app,270 { url: '/' },271 function(res){

Fixed res.cookie() testTj Holowaychukbefore adoption6a68950

line 272why, one step back
272 assert.equal(

Merge branch 'features/cookie'Tj Holowaychukbefore adoption6521d2b

line 273why, one step back
273 'rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly',

Fixed tests for node --version 0.2.1Tj Holowaychukbefore adoption87003c8

line 274why, one step back
274 res.headers['set-cookie']);

Merge branch 'features/cookie'Tj Holowaychukbefore adoption6521d2b

line 275why, one step back
275 });

Added test for res.clearCookie()Tj Holowaychukbefore adoptiona13df5b

lines 276–290why, one step back
276 },
277 278 'test #clearCookie()': function(assert){279 var app = express.createServer();280 281 app.get('/', function(req, res){282 res.clearCookie('rememberme');283 res.redirect('/');284 });285 286 assert.response(app,287 { url: '/' },288 function(res){289 assert.equal(290 'rememberme=; expires=Thu, 01 Jan 1970 00:00:00 GMT',

Fixed tests for node --version 0.2.1Tj Holowaychukbefore adoption87003c8

line 291why, one step back
291 res.headers['set-cookie']);

Added test for res.clearCookie()Tj Holowaychukbefore adoptiona13df5b

line 292why, one step back
292 });

res.send() HEAD supportTj Holowaychukbefore adoptiona9819df

lines 293–304why, one step back
293 },
294 295 'test HEAD': function(assert){296 var app = express.createServer();297 298 app.get('/', function(req, res, next){299 res.send('Hello World');300 });301 302 assert.response(app,303 { url: '/', method: 'HEAD' },304 { body: '', headers: { 'Content-Length': 11 }});

Added --growl flag to `make test`Tj Holowaychukbefore adoption5f59303

lines 305–306why, one step back
305 }
306};