Skip to content

Commit bbb007f

Browse files
committed
fix: feedbacks
1 parent 16cf793 commit bbb007f

19 files changed

+223
-223
lines changed

spec/AudienceRouter.spec.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const auth = require('../lib/Auth');
22
const Config = require('../lib/Config');
33
const rest = require('../lib/rest');
44
const request = require('../lib/request');
5-
const { getSanitizedErrorCall } = require('../lib/TestUtils');
65
const AudiencesRouter = require('../lib/Routers/AudiencesRouter').AudiencesRouter;
76

87
describe('AudiencesRouter', () => {
@@ -264,75 +263,75 @@ describe('AudiencesRouter', () => {
264263
});
265264

266265
it('should only create with master key', done => {
267-
const sanitizedErrorCall = getSanitizedErrorCall();
268-
269-
const callCountBefore = sanitizedErrorCall.callCountBefore();
266+
const logger = require('../lib/logger').default;
267+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
268+
loggerErrorSpy.calls.reset();
270269
Parse._request('POST', 'push_audiences', {
271270
name: 'My Audience',
272271
query: JSON.stringify({ deviceType: 'ios' }),
273272
}).then(
274273
() => {},
275274
error => {
276275
expect(error.message).toEqual('Permission denied');
277-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
276+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
278277
done();
279278
}
280279
);
281280
});
282281

283282
it('should only find with master key', done => {
284-
const sanitizedErrorCall = getSanitizedErrorCall();
285-
286-
const callCountBefore = sanitizedErrorCall.callCountBefore();
283+
const logger = require('../lib/logger').default;
284+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
285+
loggerErrorSpy.calls.reset();
287286
Parse._request('GET', 'push_audiences', {}).then(
288287
() => {},
289288
error => {
290289
expect(error.message).toEqual('Permission denied');
291-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
290+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
292291
done();
293292
}
294293
);
295294
});
296295

297296
it('should only get with master key', done => {
298-
const sanitizedErrorCall = getSanitizedErrorCall();
299-
300-
const callCountBefore = sanitizedErrorCall.callCountBefore();
297+
const logger = require('../lib/logger').default;
298+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
299+
loggerErrorSpy.calls.reset();
301300
Parse._request('GET', `push_audiences/someId`, {}).then(
302301
() => {},
303302
error => {
304303
expect(error.message).toEqual('Permission denied');
305-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
304+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
306305
done();
307306
}
308307
);
309308
});
310309

311310
it('should only update with master key', done => {
312-
const sanitizedErrorCall = getSanitizedErrorCall();
313-
314-
const callCountBefore = sanitizedErrorCall.callCountBefore();
311+
const logger = require('../lib/logger').default;
312+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
313+
loggerErrorSpy.calls.reset();
315314
Parse._request('PUT', `push_audiences/someId`, {
316315
name: 'My Audience 2',
317316
}).then(
318317
() => {},
319318
error => {
320319
expect(error.message).toEqual('Permission denied');
321-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
320+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
322321
done();
323322
}
324323
);
325324
});
326325

327326
it('should only delete with master key', done => {
328-
const sanitizedErrorCall = getSanitizedErrorCall();
329-
330-
const callCountBefore = sanitizedErrorCall.callCountBefore();
327+
const logger = require('../lib/logger').default;
328+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
329+
loggerErrorSpy.calls.reset();
331330
Parse._request('DELETE', `push_audiences/someId`, {}).then(
332331
() => {},
333332
error => {
334333
expect(error.message).toEqual('Permission denied');
335-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
334+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
336335
done();
337336
}
338337
);

spec/LogsRouter.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const request = require('../lib/request');
4-
const { getSanitizedErrorCall } = require('../lib/TestUtils');
54
const LogsRouter = require('../lib/Routers/LogsRouter').LogsRouter;
65
const LoggerController = require('../lib/Controllers/LoggerController').LoggerController;
76
const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapter')
@@ -53,9 +52,9 @@ describe_only(() => {
5352
});
5453

5554
it('can check invalid master key of request', done => {
56-
const sanitizedErrorCall = getSanitizedErrorCall();
57-
58-
const callCountBefore = sanitizedErrorCall.callCountBefore();
55+
const logger = require('../lib/logger').default;
56+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
57+
loggerErrorSpy.calls.reset();
5958
request({
6059
url: 'http://localhost:8378/1/scriptlog',
6160
headers: {
@@ -66,7 +65,7 @@ describe_only(() => {
6665
const body = response.data;
6766
expect(response.status).toEqual(403);
6867
expect(body.error).toEqual('Permission denied');
69-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
68+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
7069
done();
7170
});
7271
});

spec/ParseAPI.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const request = require('../lib/request');
66
const Parse = require('parse/node');
77
const Config = require('../lib/Config');
88
const SchemaController = require('../lib/Controllers/SchemaController');
9-
const { getSanitizedErrorCall, destroyAllDataPermanently } = require('../lib/TestUtils');
9+
const { destroyAllDataPermanently } = require('../lib/TestUtils');
1010

1111
const userSchema = SchemaController.convertSchemaToAdapterSchema({
1212
className: '_User',
@@ -1710,14 +1710,15 @@ describe('miscellaneous', () => {
17101710
});
17111711

17121712
it('fail on purge all objects in class without master key', done => {
1713-
const sanitizedErrorCall = getSanitizedErrorCall();
1713+
const logger = require('../lib/logger').default;
1714+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
17141715

17151716
const headers = {
17161717
'Content-Type': 'application/json',
17171718
'X-Parse-Application-Id': 'test',
17181719
'X-Parse-REST-API-Key': 'rest',
17191720
};
1720-
const callCountBefore = sanitizedErrorCall.callCountBefore();
1721+
loggerErrorSpy.calls.reset();
17211722
request({
17221723
method: 'DELETE',
17231724
headers: headers,
@@ -1728,7 +1729,7 @@ describe('miscellaneous', () => {
17281729
})
17291730
.catch(response => {
17301731
expect(response.data.error).toEqual('Permission denied');
1731-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
1732+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
17321733
done();
17331734
});
17341735
});

spec/ParseFile.spec.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
const { FilesController } = require('../lib/Controllers/FilesController');
77
const request = require('../lib/request');
8-
const { getSanitizedErrorCall } = require('../lib/TestUtils');
98

109
const str = 'Hello World!';
1110
const data = [];
@@ -133,7 +132,8 @@ describe('Parse.File testing', () => {
133132
});
134133

135134
it('blocks file deletions with missing or incorrect master-key header', done => {
136-
const sanitizedErrorCall = getSanitizedErrorCall();
135+
const logger = require('../lib/logger').default;
136+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
137137

138138
const headers = {
139139
'Content-Type': 'image/jpeg',
@@ -149,7 +149,7 @@ describe('Parse.File testing', () => {
149149
const b = response.data;
150150
expect(b.url).toMatch(/^http:\/\/localhost:8378\/1\/files\/test\/.*thefile.jpg$/);
151151
// missing X-Parse-Master-Key header
152-
const callCountBefore = sanitizedErrorCall.callCountBefore();
152+
loggerErrorSpy.calls.reset();
153153
request({
154154
method: 'DELETE',
155155
headers: {
@@ -161,9 +161,9 @@ describe('Parse.File testing', () => {
161161
const del_b = response.data;
162162
expect(response.status).toEqual(403);
163163
expect(del_b.error).toBe('Permission denied');
164-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
164+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
165165
// incorrect X-Parse-Master-Key header
166-
const callCountBefore2 = sanitizedErrorCall.callCountBefore();
166+
loggerErrorSpy.calls.reset();
167167
request({
168168
method: 'DELETE',
169169
headers: {
@@ -176,7 +176,7 @@ describe('Parse.File testing', () => {
176176
const del_b2 = response.data;
177177
expect(response.status).toEqual(403);
178178
expect(del_b2.error).toBe('Permission denied');
179-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore2);
179+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
180180
done();
181181
});
182182
});
@@ -763,16 +763,15 @@ describe('Parse.File testing', () => {
763763

764764
describe('getting files', () => {
765765
it('does not crash on file request with invalid app ID', async () => {
766-
const { getSanitizedErrorCall } = require('../lib/TestUtils');
767-
const sanitizedErrorCall = getSanitizedErrorCall();
768-
769-
const callCountBefore = sanitizedErrorCall.callCountBefore();
766+
const logger = require('../lib/logger').default;
767+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
768+
loggerErrorSpy.calls.reset();
770769
const res1 = await request({
771770
url: 'http://localhost:8378/1/files/invalid-id/invalid-file.txt',
772771
}).catch(e => e);
773772
expect(res1.status).toBe(403);
774773
expect(res1.data).toEqual({ code: 119, error: 'Permission denied' });
775-
sanitizedErrorCall.checkMessage('Invalid application ID.', callCountBefore);
774+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('Invalid application ID.'));
776775
// Ensure server did not crash
777776
const res2 = await request({ url: 'http://localhost:8378/1/health' });
778777
expect(res2.status).toEqual(200);

spec/ParseGlobalConfig.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const request = require('../lib/request');
44
const Config = require('../lib/Config');
5-
const { getSanitizedErrorCall } = require('../lib/TestUtils');
65

76
describe('a GlobalConfig', () => {
87
beforeEach(async () => {
@@ -221,9 +220,9 @@ describe('a GlobalConfig', () => {
221220
});
222221

223222
it('fail to update if master key is missing', done => {
224-
const sanitizedErrorCall = getSanitizedErrorCall();
225-
226-
const callCountBefore = sanitizedErrorCall.callCountBefore();
223+
const logger = require('../lib/logger').default;
224+
const loggerErrorSpy = spyOn(logger, 'error').and.callThrough();
225+
loggerErrorSpy.calls.reset();
227226
request({
228227
method: 'PUT',
229228
url: 'http://localhost:8378/1/config',
@@ -238,7 +237,7 @@ describe('a GlobalConfig', () => {
238237
const body = response.data;
239238
expect(response.status).toEqual(403);
240239
expect(body.error).toEqual('Permission denied');
241-
sanitizedErrorCall.checkMessage('unauthorized: master key is required', callCountBefore);
240+
expect(loggerErrorSpy).toHaveBeenCalledWith('Sanitized error:', jasmine.stringContaining('unauthorized: master key is required'));
242241
done();
243242
});
244243
});

0 commit comments

Comments
 (0)