-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathLogsRouter.spec.js
173 lines (160 loc) · 5.17 KB
/
LogsRouter.spec.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
const request = require('../lib/request');
const LogsRouter = require('../lib/Routers/LogsRouter').LogsRouter;
const LoggerController = require('../lib/Controllers/LoggerController').LoggerController;
const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapter')
.WinstonLoggerAdapter;
const loggerController = new LoggerController(new WinstonLoggerAdapter());
describe_only(() => {
return process.env.PARSE_SERVER_LOG_LEVEL !== 'debug';
})('LogsRouter', () => {
it('can check valid master key of request', done => {
// Make mock request
const request = {
auth: {
isMaster: true,
},
query: {},
config: {
loggerController: loggerController,
},
};
const router = new LogsRouter();
expect(() => {
router.validateRequest(request);
}).not.toThrow();
done();
});
it('can check invalid construction of controller', done => {
// Make mock request
const request = {
auth: {
isMaster: true,
},
query: {},
config: {
loggerController: undefined, // missing controller
},
};
const router = new LogsRouter();
expect(() => {
router.validateRequest(request);
}).toThrow();
done();
});
it('can check invalid master key of request', done => {
request({
url: 'http://localhost:8378/1/scriptlog',
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
},
}).then(fail, response => {
const body = response.data;
expect(response.status).toEqual(403);
expect(body.error).toEqual('unauthorized: master key is required');
done();
});
});
const headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
'X-Parse-Master-Key': 'test',
};
/**
* Verifies simple passwords in GET login requests with special characters are scrubbed from the verbose log
*/
it_id('e36d6141-2a20-41d0-85fc-d1534c3e4bae')(it)('does scrub simple passwords on GET login', done => {
reconfigureServer({
verbose: true,
}).then(function () {
request({
headers: headers,
url: 'http://localhost:8378/1/login?username=test&password=simplepass.com',
})
.catch(() => {})
.then(() => {
request({
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
headers: headers,
}).then(response => {
const body = response.data;
expect(response.status).toEqual(200);
// 4th entry is our actual GET request
expect(body[2].url).toEqual('/1/login?username=test&password=********');
expect(body[2].message).toEqual(
'REQUEST for [GET] /1/login?username=test&password=********: {}'
);
done();
});
});
});
});
/**
* Verifies complex passwords in GET login requests with special characters are scrubbed from the verbose log
*/
it_id('24b277c5-250f-4a35-a449-2c8c519d4c03')(it)('does scrub complex passwords on GET login', done => {
reconfigureServer({
verbose: true,
})
.then(function () {
return request({
headers: headers,
// using urlencoded password, 'simple @,/?:&=+$#pass.com'
url:
'http://localhost:8378/1/login?username=test&password=simple%20%40%2C%2F%3F%3A%26%3D%2B%24%23pass.com',
})
.catch(() => {})
.then(() => {
return request({
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
headers: headers,
}).then(response => {
const body = response.data;
expect(response.status).toEqual(200);
// 4th entry is our actual GET request
expect(body[2].url).toEqual('/1/login?username=test&password=********');
expect(body[2].message).toEqual(
'REQUEST for [GET] /1/login?username=test&password=********: {}'
);
done();
});
});
})
.catch(done.fail);
});
/**
* Verifies fields in POST login requests are NOT present in the verbose log
*/
it_id('33143ec9-b32d-467c-ba65-ff2bbefdaadd')(it)('does not have password field in POST login', done => {
reconfigureServer({
verbose: true,
}).then(function () {
request({
method: 'POST',
headers: headers,
url: 'http://localhost:8378/1/login',
body: {
username: 'test',
password: 'simplepass.com',
},
})
.catch(() => {})
.then(() => {
request({
url: 'http://localhost:8378/1/scriptlog?size=4&level=verbose',
headers: headers,
}).then(response => {
const body = response.data;
expect(response.status).toEqual(200);
// 4th entry is our actual GET request
expect(body[2].url).toEqual('/1/login');
expect(body[2].message).toEqual(
'REQUEST for [POST] /1/login: {\n "username": "test",\n "password": "********"\n}'
);
done();
});
});
});
});
});