|
1 | 1 | const ResourceMapper = require('../../lib/handlers/resource-mapper') |
2 | | -const { expect } = require('chai') |
| 2 | +const chai = require('chai') |
| 3 | +const { expect } = chai |
| 4 | +chai.use(require('chai-as-promised')) |
3 | 5 |
|
4 | 6 | describe('ResourceMapper', () => { |
5 | 7 | describe('A ResourceMapper instance for a single-user setup', () => { |
@@ -31,12 +33,35 @@ describe('ResourceMapper', () => { |
31 | 33 | createIfNotExists: true |
32 | 34 | }, |
33 | 35 | { path: `${rootPath}space/foo.exe$.html` }) |
| 36 | + |
| 37 | + // Security cases |
| 38 | + |
| 39 | + itMapsUrl(mapper, 'a URL with an unknown content type', |
| 40 | + { |
| 41 | + url: 'http://localhost/space/foo.html', |
| 42 | + contentTypes: ['text/unknown'], |
| 43 | + createIfNotExists: true |
| 44 | + }, |
| 45 | + { path: `${rootPath}space/foo.html$` }) |
| 46 | + |
| 47 | + itMapsUrl(mapper, 'a URL with a /.. path segment', |
| 48 | + { |
| 49 | + url: 'http://localhost/space/../bar' |
| 50 | + }, |
| 51 | + new Error('Disallowed /.. segment in URL')) |
34 | 52 | }) |
35 | 53 | }) |
36 | 54 |
|
37 | 55 | function itMapsUrl (mapper, label, options, expected) { |
38 | | - it(`maps ${label}`, async () => { |
39 | | - const actual = await mapper.mapUrlToFile(options) |
40 | | - expect(actual).to.deep.equal(expected) |
41 | | - }) |
| 56 | + if (!(expected instanceof Error)) { |
| 57 | + it(`maps ${label}`, async () => { |
| 58 | + const actual = await mapper.mapUrlToFile(options) |
| 59 | + expect(actual).to.deep.equal(expected) |
| 60 | + }) |
| 61 | + } else { |
| 62 | + it(`does not map ${label}`, async () => { |
| 63 | + const actual = mapper.mapUrlToFile(options) |
| 64 | + await expect(actual).to.be.rejectedWith(expected.message) |
| 65 | + }) |
| 66 | + } |
42 | 67 | } |
0 commit comments