Skip to content

Commit 66f1169

Browse files
committed
test: fix, waiting new parse sdk release to handle 500 errors
1 parent 1fb6101 commit 66f1169

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

spec/Adapters/Auth/wechat.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('WeChatAdapter', function () {
2323
const user = await adapter.getUserFromAccessToken('validToken', { id: 'validOpenId' });
2424

2525
expect(global.fetch).toHaveBeenCalledWith(
26-
'https://api.weixin.qq.com/sns/auth?access_token=validToken&openid=validOpenId'
26+
'https://api.weixin.qq.com/sns/auth?access_token=validToken&openid=validOpenId',
27+
jasmine.any(Object)
2728
);
2829
expect(user).toEqual({ errcode: 0, id: 'validUserId' });
2930
});
@@ -64,7 +65,8 @@ describe('WeChatAdapter', function () {
6465
const token = await adapter.getAccessTokenFromCode(authData);
6566

6667
expect(global.fetch).toHaveBeenCalledWith(
67-
'https://api.weixin.qq.com/sns/oauth2/access_token?appid=validAppId&secret=validAppSecret&code=validCode&grant_type=authorization_code'
68+
'https://api.weixin.qq.com/sns/oauth2/access_token?appid=validAppId&secret=validAppSecret&code=validCode&grant_type=authorization_code',
69+
jasmine.any(Object)
6870
);
6971
expect(token).toEqual('validToken');
7072
});

spec/ParseObject.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,10 @@ describe('Parse.Object testing', () => {
13951395
.save()
13961396
.then(function () {
13971397
const query = new Parse.Query(TestObject);
1398-
return query.find(object.id);
1398+
return query.get(object.id);
13991399
})
1400-
.then(function (results) {
1401-
updatedObject = results[0];
1400+
.then(function (result) {
1401+
updatedObject = result;
14021402
updatedObject.set('x', 11);
14031403
return updatedObject.save();
14041404
})
@@ -1409,7 +1409,8 @@ describe('Parse.Object testing', () => {
14091409
equal(object.createdAt.getTime(), updatedObject.createdAt.getTime());
14101410
equal(object.updatedAt.getTime(), updatedObject.updatedAt.getTime());
14111411
done();
1412-
});
1412+
})
1413+
.catch(done.fail);
14131414
});
14141415

14151416
xit('fetchAll backbone-style callbacks', function (done) {

spec/ParseRelation.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ describe('Parse.Relation testing', () => {
517517

518518
// Parent object is un-fetched, so this will call /1/classes/Car instead
519519
// of /1/classes/Wheel and pass { "redirectClassNameForKey":"wheels" }.
520-
return query.find(origWheel.id);
520+
return query.find();
521521
})
522522
.then(function (results) {
523523
// Make sure this is Wheel and not Car.

spec/helper.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ afterEach(global.afterEachFn);
252252

253253
afterAll(() => {
254254
global.displayTestStats();
255+
// restore fetch
256+
global.restoreFetch();
255257
});
256258

257259
const TestObject = Parse.Object.extend({
@@ -387,10 +389,28 @@ function mockShortLivedAuth() {
387389
return auth;
388390
}
389391

392+
const originalFetch = global.fetch;
393+
394+
global.restoreFetch = () => {
395+
global.fetch = originalFetch;
396+
}
397+
390398
function mockFetch(mockResponses) {
391-
global.fetch = jasmine.createSpy('fetch').and.callFake((url, options = { }) => {
399+
const spy = jasmine.createSpy('fetch');
400+
401+
global.fetch = (url, options = {}) => {
402+
// Allow requests to the Parse Server to pass through WITHOUT recording in spy
403+
// This prevents tests from failing when they check that fetch wasn't called
404+
// but the Parse SDK makes internal requests to the Parse Server
405+
if (typeof url === 'string' && url.includes(serverURL)) {
406+
return originalFetch(url, options);
407+
}
408+
409+
// Record non-Parse-Server calls in the spy
410+
spy(url, options);
411+
392412
options.method ||= 'GET';
393-
const mockResponse = mockResponses.find(
413+
const mockResponse = mockResponses?.find(
394414
(mock) => mock.url === url && mock.method === options.method
395415
);
396416

@@ -402,7 +422,11 @@ function mockFetch(mockResponses) {
402422
ok: false,
403423
statusText: 'Unknown URL or method',
404424
});
405-
});
425+
};
426+
427+
// Expose spy methods for test assertions
428+
global.fetch.calls = spy.calls;
429+
global.fetch.and = spy.and;
406430
}
407431

408432

spec/vulnerabilities.spec.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,10 @@ describe('Vulnerabilities', () => {
175175
},
176176
});
177177
});
178-
await expectAsync(new Parse.Object('TestObject').save()).toBeRejectedWith(
179-
new Parse.Error(
180-
Parse.Error.INVALID_KEY_NAME,
181-
'Prohibited keyword in request data: {"key":"constructor"}.'
182-
)
183-
);
178+
// The new Parse SDK handles prototype pollution prevention in .set()
179+
// so no error is thrown, but the object prototype should not be polluted
180+
await new Parse.Object('TestObject').save();
181+
expect(Object.prototype.dummy).toBeUndefined();
184182
});
185183

186184
it('denies creating global config with polluted data', async () => {
@@ -270,12 +268,10 @@ describe('Vulnerabilities', () => {
270268
res.json({ success: object });
271269
});
272270
await Parse.Hooks.createTrigger('TestObject', 'beforeSave', hookServerURL + '/BeforeSave');
273-
await expectAsync(new Parse.Object('TestObject').save()).toBeRejectedWith(
274-
new Parse.Error(
275-
Parse.Error.INVALID_KEY_NAME,
276-
'Prohibited keyword in request data: {"key":"constructor"}.'
277-
)
278-
);
271+
// The new Parse SDK handles prototype pollution prevention in .set()
272+
// so no error is thrown, but the object prototype should not be polluted
273+
await new Parse.Object('TestObject').save();
274+
expect(Object.prototype.dummy).toBeUndefined();
279275
await new Promise(resolve => server.close(resolve));
280276
});
281277

0 commit comments

Comments
 (0)