-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.test.js
68 lines (52 loc) · 2 KB
/
sample.test.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
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @jest-environment jsdom
*/
const request = require('supertest');
const path = require('path');
const fs = require('fs');
const app = require('./server.js');
jest.dontMock('fs');
const html = fs.readFileSync(path.resolve(__dirname, './App/index.html'), 'utf8');
describe('Sanitize index page', () => {
beforeAll(async() => {
global.document.documentElement.innerHTML = html.toString();
});
it('should have valid cdn link', () => {
expect(document.getElementById("load-msal").getAttribute("src")).toContain("https://alcdn.msauth.net/browser");
});
});
describe('Sanitize configuration object', () => {
beforeAll(() => {
global.msalConfig = require('./App/authConfig.js').msalConfig;
});
it('should define the config object', () => {
expect(msalConfig).toBeDefined();
});
it('should not contain credentials', () => {
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
expect(regexGuid.test(msalConfig.auth.clientId)).toBe(false);
});
it('should contain authority URI', () => {
const regexUri = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi;
expect(regexUri.test(msalConfig.auth.authority)).toBe(true);
});
});
describe('Ensure pages served', () => {
beforeAll(() => {
process.env.NODE_ENV = 'test';
});
it('should get index page', async () => {
const res = await request(app)
.get('/');
const data = await fs.promises.readFile(path.join(__dirname, './App/index.html'), 'utf8');
expect(res.statusCode).toEqual(200);
expect(res.text).toEqual(data);
});
it('should get signout page', async () => {
const res = await request(app)
.get('/signout');
const data = await fs.promises.readFile(path.join(__dirname, './App/signout.html'), 'utf8');
expect(res.statusCode).toEqual(200);
expect(res.text).toEqual(data);
});
});