Debian Codegraph @

test/acceptance/downloads.js

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1
2 var app = require('../../examples/downloads')
•3 , request = require('supertest')
4 , http = require('node:http')
5 , assert = require('node:assert');
6
7 describe('downloads', function(){
8 describe('GET /', function(){
9 it('should have a link to amazing.txt', function(done){
10 request(app)
11 .get('/')
12 .expect(/href="\/files\/amazing.txt"/, done)
13 })
14 })
15
16 describe('GET /files/notes/groceries.txt', function () {
17 it('should have a download header', function (done) {
18 request(app)
19 .get('/files/notes/groceries.txt')
20 .expect('Content-Disposition', 'attachment; filename="groceries.txt"')
21 .expect(200, done)
22 })
23 })
24
25 describe('GET /files/amazing.txt', function(){
26 it('should have a download header', function(done){
27 request(app)
28 .get('/files/amazing.txt')
29 .expect('Content-Disposition', 'attachment; filename="amazing.txt"')
30 .expect(200, done)
31 })
32 })
33
34 describe('GET /files/missing.txt', function(){
35 it('should respond with 404', function(done){
36 request(app)
37 .get('/files/missing.txt')
38 .expect(404, done)
39 })
40 })
41
42 describe('GET /files/../index.js', function () {
43 it('should respond with 403', function (done) {
•44 var server = app.listen(function () {
45 var port = server.address().port
46 // Use http.request to avoid URL normalization by superagent
47 var req = http.request({
48 hostname: 'localhost',
49 port: port,
50 path: '/files/../index.js',
51 method: 'GET'
52 }, function (res) {
53 assert.strictEqual(res.statusCode, 403)
54 server.close(done)
55 })
56 req.on('error', done)
57 req.end()
58 })
59 })
60 })
61 })