/
security.api.tests.js
56 lines (48 loc) 路 1.76 KB
/
security.api.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* global describe, it, before */
const { promisify } = require('util');
const assert = require('assert');
const { ADMIN_USER, cleanup, URL_PREFIX } = require('../fixtures.js');
const apiClient = require('../api-client.js');
const postRaw = promisify(apiClient.postRaw);
const loginAs = promisify(apiClient.loginAs);
before(cleanup);
describe('security', () => {
describe('Open Redirect', () => {
it('should allow redirect to /stream', async () => {
const target = `/stream`;
const { jar } = await loginAs(ADMIN_USER);
const { response } = await postRaw(jar, `/consent`, {
lang: 'en',
redirect: target,
});
assert.equal(response.statusCode, 302);
assert.equal(response.headers.location, target);
});
it(`should allow redirect to ${URL_PREFIX}/stream`, async () => {
const target = `${URL_PREFIX}/stream`;
const { jar } = await loginAs(ADMIN_USER);
const { response } = await postRaw(jar, `/consent`, {
lang: 'en',
redirect: target,
});
assert.equal(response.statusCode, 302);
assert.equal(response.headers.location, target);
});
it('should NOT allow redirect to other domain', async () => {
const { jar } = await loginAs(ADMIN_USER);
const { response } = await postRaw(jar, `/consent`, {
lang: 'en',
redirect: `http://google.com`,
});
assert.equal(response.statusCode, 403); // forbidden
});
it('should NOT allow redirect to a disguised domain', async () => {
const { jar } = await loginAs(ADMIN_USER);
const { response } = await postRaw(jar, `/consent`, {
lang: 'en',
redirect: `${URL_PREFIX}@google.com`,
});
assert.equal(response.statusCode, 403); // forbidden
});
});
});