From ab5be44238f81ad436aa01f8242a8582f802b184 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 5 Jun 2022 20:05:41 +1000 Subject: [PATCH 01/21] fix: prevent LiveQuery override with query.select --- src/LiveQueryClient.js | 5 +++- src/__tests__/LiveQueryClient-test.js | 37 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 3066ac1c6..2210dee4d 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -419,7 +419,10 @@ class LiveQueryClient extends EventEmitter { data.original = ParseObject.fromJSON(data.original, false); } delete data.object.__type; - const parseObject = ParseObject.fromJSON(data.object, override); + const parseObject = ParseObject.fromJSON( + data.object, + !(subscription.query && subscription.query._select) ? override : false + ); if (data.original) { subscription.emit(data.op, parseObject, data.original, response); diff --git a/src/__tests__/LiveQueryClient-test.js b/src/__tests__/LiveQueryClient-test.js index 812ebb978..4329bcd01 100644 --- a/src/__tests__/LiveQueryClient-test.js +++ b/src/__tests__/LiveQueryClient-test.js @@ -522,6 +522,43 @@ describe('LiveQueryClient', () => { spy.mockRestore(); }); + it('can handle select in websocket payload', () => { + const liveQueryClient = new LiveQueryClient({ + applicationId: 'applicationId', + serverURL: 'ws://test', + javascriptKey: 'javascriptKey', + masterKey: 'masterKey', + sessionToken: 'sessionToken', + }); + // Add mock subscription + const subscription = new events.EventEmitter(); + subscription.query = new ParseQuery('Test').select('foo'); + liveQueryClient.subscriptions.set(1, subscription); + const object = new ParseObject('Test'); + const original = new ParseObject('Test'); + object.set('key', 'value'); + original.set('key', 'old'); + const data = { + op: 'update', + clientId: 1, + requestId: 1, + object: object._toFullJSON(), + original: original._toFullJSON(), + }; + const event = { + data: JSON.stringify(data), + }; + + const spy = jest + .spyOn(ParseObject, 'fromJSON') + .mockImplementationOnce(() => original) + .mockImplementationOnce(() => object); + + liveQueryClient._handleWebSocketMessage(event); + expect(ParseObject.fromJSON.mock.calls[1][1]).toEqual(false); + spy.mockRestore(); + }); + it('can handle WebSocket response unset field', async () => { const liveQueryClient = new LiveQueryClient({ applicationId: 'applicationId', From 3073b777396441e36ef69b113fa0f82854bffe3e Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 5 Jun 2022 21:31:10 +1000 Subject: [PATCH 02/21] fix: allow `Parse.Cloud.beforeSubscribe` rejections to be caught by query.subscribe --- integration/test/ParseLiveQueryTest.js | 27 ++++++++++++++++++++++++ integration/test/cloud/before_connect.js | 3 +++ integration/test/cloud/main.js | 4 ++++ src/LiveQueryClient.js | 16 ++++++++++++-- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 integration/test/cloud/before_connect.js diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index d3089f691..56d78a735 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -256,4 +256,31 @@ describe('Parse LiveQuery', () => { object.set({ foo: 'bar' }); await object.save(); }); + + it('live query can handle beforeConnect and beforeSubscribe errors', async () => { + const client = new Parse.LiveQueryClient({ + applicationId: 'integration', + serverURL: 'ws://localhost:1337', + javascriptKey: null, + masterKey: null, + sessionToken: null, + installationId: null, + }); + client.open(); + const query = new Parse.Query('TestError'); + let subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'not allowed to subscribe') + ); + client.close(); + await reconfigureServer({ + cloud: `${__dirname}/cloud/before_connect.js`, + }); + client.open(); + subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'not allowed to connect') + ); + client.close(); + }); }); diff --git a/integration/test/cloud/before_connect.js b/integration/test/cloud/before_connect.js new file mode 100644 index 000000000..e334bdc53 --- /dev/null +++ b/integration/test/cloud/before_connect.js @@ -0,0 +1,3 @@ +Parse.Cloud.beforeConnect(() => { + throw 'not allowed to connect'; +}); diff --git a/integration/test/cloud/main.js b/integration/test/cloud/main.js index 920948d83..063986120 100644 --- a/integration/test/cloud/main.js +++ b/integration/test/cloud/main.js @@ -48,3 +48,7 @@ Parse.Cloud.job('CloudJob2', function () { Parse.Cloud.job('CloudJobFailing', function () { throw 'cloud job failed'; }); + +Parse.Cloud.beforeSubscribe('TestError', () => { + throw 'not allowed to subscribe'; +}); diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 2210dee4d..198c2d3b0 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -14,6 +14,7 @@ import EventEmitter from './EventEmitter'; import ParseObject from './ParseObject'; import LiveQuerySubscription from './LiveQuerySubscription'; import { resolvingPromise } from './promiseUtils'; +import ParseError from './ParseError'; // The LiveQuery client inner state const CLIENT_STATE = { @@ -218,6 +219,10 @@ class LiveQueryClient extends EventEmitter { this.subscriptions.set(this.requestId, subscription); this.requestId += 1; this.connectPromise.then(() => { + if (this.connectError) { + subscription.subscribePromise.reject(this.connectError); + return; + } this.socket.send(JSON.stringify(subscribeRequest)); }); @@ -382,10 +387,16 @@ class LiveQueryClient extends EventEmitter { setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200); } break; - case OP_EVENTS.ERROR: + case OP_EVENTS.ERROR: { + const parseError = new ParseError(data.code, data.error); + if (!this.id) { + this.connectError = parseError; + this.connectPromise.resolve(); + this.state = CLIENT_STATE.DISCONNECTED; + } if (data.requestId) { if (subscription) { - subscription.subscribePromise.resolve(); + subscription.subscribePromise.reject(parseError); setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error), 200); } } else { @@ -398,6 +409,7 @@ class LiveQueryClient extends EventEmitter { this._handleReconnect(); } break; + } case OP_EVENTS.UNSUBSCRIBED: // We have already deleted subscription in unsubscribe(), do nothing here break; From bc0a5769016662ab020dc805f5660b313edda511 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 5 Jun 2022 21:36:30 +1000 Subject: [PATCH 03/21] Revert "fix: allow `Parse.Cloud.beforeSubscribe` rejections to be caught by query.subscribe" This reverts commit 3073b777396441e36ef69b113fa0f82854bffe3e. --- integration/test/ParseLiveQueryTest.js | 27 ------------------------ integration/test/cloud/before_connect.js | 3 --- integration/test/cloud/main.js | 4 ---- src/LiveQueryClient.js | 16 ++------------ 4 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 integration/test/cloud/before_connect.js diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 56d78a735..d3089f691 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -256,31 +256,4 @@ describe('Parse LiveQuery', () => { object.set({ foo: 'bar' }); await object.save(); }); - - it('live query can handle beforeConnect and beforeSubscribe errors', async () => { - const client = new Parse.LiveQueryClient({ - applicationId: 'integration', - serverURL: 'ws://localhost:1337', - javascriptKey: null, - masterKey: null, - sessionToken: null, - installationId: null, - }); - client.open(); - const query = new Parse.Query('TestError'); - let subscription = client.subscribe(query); - await expectAsync(subscription.subscribePromise).toBeRejectedWith( - new Parse.Error(141, 'not allowed to subscribe') - ); - client.close(); - await reconfigureServer({ - cloud: `${__dirname}/cloud/before_connect.js`, - }); - client.open(); - subscription = client.subscribe(query); - await expectAsync(subscription.subscribePromise).toBeRejectedWith( - new Parse.Error(141, 'not allowed to connect') - ); - client.close(); - }); }); diff --git a/integration/test/cloud/before_connect.js b/integration/test/cloud/before_connect.js deleted file mode 100644 index e334bdc53..000000000 --- a/integration/test/cloud/before_connect.js +++ /dev/null @@ -1,3 +0,0 @@ -Parse.Cloud.beforeConnect(() => { - throw 'not allowed to connect'; -}); diff --git a/integration/test/cloud/main.js b/integration/test/cloud/main.js index 063986120..920948d83 100644 --- a/integration/test/cloud/main.js +++ b/integration/test/cloud/main.js @@ -48,7 +48,3 @@ Parse.Cloud.job('CloudJob2', function () { Parse.Cloud.job('CloudJobFailing', function () { throw 'cloud job failed'; }); - -Parse.Cloud.beforeSubscribe('TestError', () => { - throw 'not allowed to subscribe'; -}); diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 198c2d3b0..2210dee4d 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -14,7 +14,6 @@ import EventEmitter from './EventEmitter'; import ParseObject from './ParseObject'; import LiveQuerySubscription from './LiveQuerySubscription'; import { resolvingPromise } from './promiseUtils'; -import ParseError from './ParseError'; // The LiveQuery client inner state const CLIENT_STATE = { @@ -219,10 +218,6 @@ class LiveQueryClient extends EventEmitter { this.subscriptions.set(this.requestId, subscription); this.requestId += 1; this.connectPromise.then(() => { - if (this.connectError) { - subscription.subscribePromise.reject(this.connectError); - return; - } this.socket.send(JSON.stringify(subscribeRequest)); }); @@ -387,16 +382,10 @@ class LiveQueryClient extends EventEmitter { setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200); } break; - case OP_EVENTS.ERROR: { - const parseError = new ParseError(data.code, data.error); - if (!this.id) { - this.connectError = parseError; - this.connectPromise.resolve(); - this.state = CLIENT_STATE.DISCONNECTED; - } + case OP_EVENTS.ERROR: if (data.requestId) { if (subscription) { - subscription.subscribePromise.reject(parseError); + subscription.subscribePromise.resolve(); setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error), 200); } } else { @@ -409,7 +398,6 @@ class LiveQueryClient extends EventEmitter { this._handleReconnect(); } break; - } case OP_EVENTS.UNSUBSCRIBED: // We have already deleted subscription in unsubscribe(), do nothing here break; From 5f5f3639d4fa679a3c2f678031e9ad39f6476e53 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 5 Jun 2022 21:36:57 +1000 Subject: [PATCH 04/21] Revert "Revert "fix: allow `Parse.Cloud.beforeSubscribe` rejections to be caught by query.subscribe"" This reverts commit bc0a5769016662ab020dc805f5660b313edda511. --- integration/test/ParseLiveQueryTest.js | 27 ++++++++++++++++++++++++ integration/test/cloud/before_connect.js | 3 +++ integration/test/cloud/main.js | 4 ++++ src/LiveQueryClient.js | 16 ++++++++++++-- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 integration/test/cloud/before_connect.js diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index d3089f691..56d78a735 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -256,4 +256,31 @@ describe('Parse LiveQuery', () => { object.set({ foo: 'bar' }); await object.save(); }); + + it('live query can handle beforeConnect and beforeSubscribe errors', async () => { + const client = new Parse.LiveQueryClient({ + applicationId: 'integration', + serverURL: 'ws://localhost:1337', + javascriptKey: null, + masterKey: null, + sessionToken: null, + installationId: null, + }); + client.open(); + const query = new Parse.Query('TestError'); + let subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'not allowed to subscribe') + ); + client.close(); + await reconfigureServer({ + cloud: `${__dirname}/cloud/before_connect.js`, + }); + client.open(); + subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'not allowed to connect') + ); + client.close(); + }); }); diff --git a/integration/test/cloud/before_connect.js b/integration/test/cloud/before_connect.js new file mode 100644 index 000000000..e334bdc53 --- /dev/null +++ b/integration/test/cloud/before_connect.js @@ -0,0 +1,3 @@ +Parse.Cloud.beforeConnect(() => { + throw 'not allowed to connect'; +}); diff --git a/integration/test/cloud/main.js b/integration/test/cloud/main.js index 920948d83..063986120 100644 --- a/integration/test/cloud/main.js +++ b/integration/test/cloud/main.js @@ -48,3 +48,7 @@ Parse.Cloud.job('CloudJob2', function () { Parse.Cloud.job('CloudJobFailing', function () { throw 'cloud job failed'; }); + +Parse.Cloud.beforeSubscribe('TestError', () => { + throw 'not allowed to subscribe'; +}); diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 2210dee4d..198c2d3b0 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -14,6 +14,7 @@ import EventEmitter from './EventEmitter'; import ParseObject from './ParseObject'; import LiveQuerySubscription from './LiveQuerySubscription'; import { resolvingPromise } from './promiseUtils'; +import ParseError from './ParseError'; // The LiveQuery client inner state const CLIENT_STATE = { @@ -218,6 +219,10 @@ class LiveQueryClient extends EventEmitter { this.subscriptions.set(this.requestId, subscription); this.requestId += 1; this.connectPromise.then(() => { + if (this.connectError) { + subscription.subscribePromise.reject(this.connectError); + return; + } this.socket.send(JSON.stringify(subscribeRequest)); }); @@ -382,10 +387,16 @@ class LiveQueryClient extends EventEmitter { setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200); } break; - case OP_EVENTS.ERROR: + case OP_EVENTS.ERROR: { + const parseError = new ParseError(data.code, data.error); + if (!this.id) { + this.connectError = parseError; + this.connectPromise.resolve(); + this.state = CLIENT_STATE.DISCONNECTED; + } if (data.requestId) { if (subscription) { - subscription.subscribePromise.resolve(); + subscription.subscribePromise.reject(parseError); setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error), 200); } } else { @@ -398,6 +409,7 @@ class LiveQueryClient extends EventEmitter { this._handleReconnect(); } break; + } case OP_EVENTS.UNSUBSCRIBED: // We have already deleted subscription in unsubscribe(), do nothing here break; From d84b72eb59ecc2ec13d86dd710ee4da318fc2d80 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 5 Jun 2022 21:39:33 +1000 Subject: [PATCH 05/21] revert --- src/LiveQueryClient.js | 5 +--- src/__tests__/LiveQueryClient-test.js | 37 --------------------------- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 198c2d3b0..229fe88fb 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -431,10 +431,7 @@ class LiveQueryClient extends EventEmitter { data.original = ParseObject.fromJSON(data.original, false); } delete data.object.__type; - const parseObject = ParseObject.fromJSON( - data.object, - !(subscription.query && subscription.query._select) ? override : false - ); + const parseObject = ParseObject.fromJSON(data.object, override); if (data.original) { subscription.emit(data.op, parseObject, data.original, response); diff --git a/src/__tests__/LiveQueryClient-test.js b/src/__tests__/LiveQueryClient-test.js index 4329bcd01..812ebb978 100644 --- a/src/__tests__/LiveQueryClient-test.js +++ b/src/__tests__/LiveQueryClient-test.js @@ -522,43 +522,6 @@ describe('LiveQueryClient', () => { spy.mockRestore(); }); - it('can handle select in websocket payload', () => { - const liveQueryClient = new LiveQueryClient({ - applicationId: 'applicationId', - serverURL: 'ws://test', - javascriptKey: 'javascriptKey', - masterKey: 'masterKey', - sessionToken: 'sessionToken', - }); - // Add mock subscription - const subscription = new events.EventEmitter(); - subscription.query = new ParseQuery('Test').select('foo'); - liveQueryClient.subscriptions.set(1, subscription); - const object = new ParseObject('Test'); - const original = new ParseObject('Test'); - object.set('key', 'value'); - original.set('key', 'old'); - const data = { - op: 'update', - clientId: 1, - requestId: 1, - object: object._toFullJSON(), - original: original._toFullJSON(), - }; - const event = { - data: JSON.stringify(data), - }; - - const spy = jest - .spyOn(ParseObject, 'fromJSON') - .mockImplementationOnce(() => original) - .mockImplementationOnce(() => object); - - liveQueryClient._handleWebSocketMessage(event); - expect(ParseObject.fromJSON.mock.calls[1][1]).toEqual(false); - spy.mockRestore(); - }); - it('can handle WebSocket response unset field', async () => { const liveQueryClient = new LiveQueryClient({ applicationId: 'applicationId', From 540be872816b3ebb00fd194aa2ab2ddf77fdac62 Mon Sep 17 00:00:00 2001 From: dblythy Date: Sun, 5 Jun 2022 21:41:24 +1000 Subject: [PATCH 06/21] add catch block --- src/LiveQueryClient.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/LiveQueryClient.js b/src/LiveQueryClient.js index 229fe88fb..87b81a8e8 100644 --- a/src/LiveQueryClient.js +++ b/src/LiveQueryClient.js @@ -218,13 +218,13 @@ class LiveQueryClient extends EventEmitter { const subscription = new LiveQuerySubscription(this.requestId, query, sessionToken); this.subscriptions.set(this.requestId, subscription); this.requestId += 1; - this.connectPromise.then(() => { - if (this.connectError) { - subscription.subscribePromise.reject(this.connectError); - return; - } - this.socket.send(JSON.stringify(subscribeRequest)); - }); + this.connectPromise + .then(() => { + this.socket.send(JSON.stringify(subscribeRequest)); + }) + .catch(error => { + subscription.subscribePromise.reject(error); + }); return subscription; } @@ -390,8 +390,7 @@ class LiveQueryClient extends EventEmitter { case OP_EVENTS.ERROR: { const parseError = new ParseError(data.code, data.error); if (!this.id) { - this.connectError = parseError; - this.connectPromise.resolve(); + this.connectPromise.reject(parseError); this.state = CLIENT_STATE.DISCONNECTED; } if (data.requestId) { From bfde100cf1839ebce6a60129b25ef1874f34f308 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 11:40:10 +1100 Subject: [PATCH 07/21] fix tests --- integration/test/ParseLiveQueryTest.js | 16 +++++++++++++++- integration/test/cloud/before_connect.js | 3 --- integration/test/cloud/main.js | 4 ---- 3 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 integration/test/cloud/before_connect.js diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 56d78a735..0e2c42498 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -258,6 +258,14 @@ describe('Parse LiveQuery', () => { }); it('live query can handle beforeConnect and beforeSubscribe errors', async () => { + let cloud = null; + await reconfigureServer({ + cloud({ Cloud }) { + Cloud.beforeSubscribe('TestError', () => { + throw 'not allowed to subscribe'; + }); + }, + }); const client = new Parse.LiveQueryClient({ applicationId: 'integration', serverURL: 'ws://localhost:1337', @@ -274,7 +282,12 @@ describe('Parse LiveQuery', () => { ); client.close(); await reconfigureServer({ - cloud: `${__dirname}/cloud/before_connect.js`, + cloud({ Cloud }) { + Cloud.beforeConnect(() => { + throw 'not allowed to connect'; + }); + cloud = Cloud; + }, }); client.open(); subscription = client.subscribe(query); @@ -282,5 +295,6 @@ describe('Parse LiveQuery', () => { new Parse.Error(141, 'not allowed to connect') ); client.close(); + cloud._removeAllHooks(); }); }); diff --git a/integration/test/cloud/before_connect.js b/integration/test/cloud/before_connect.js deleted file mode 100644 index e334bdc53..000000000 --- a/integration/test/cloud/before_connect.js +++ /dev/null @@ -1,3 +0,0 @@ -Parse.Cloud.beforeConnect(() => { - throw 'not allowed to connect'; -}); diff --git a/integration/test/cloud/main.js b/integration/test/cloud/main.js index 063986120..920948d83 100644 --- a/integration/test/cloud/main.js +++ b/integration/test/cloud/main.js @@ -48,7 +48,3 @@ Parse.Cloud.job('CloudJob2', function () { Parse.Cloud.job('CloudJobFailing', function () { throw 'cloud job failed'; }); - -Parse.Cloud.beforeSubscribe('TestError', () => { - throw 'not allowed to subscribe'; -}); From d6808ad833249e66c24d857f21c5f90dce7246bd Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 12:13:26 +1100 Subject: [PATCH 08/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 0e2c42498..9f3696099 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -294,6 +294,9 @@ describe('Parse LiveQuery', () => { await expectAsync(subscription.subscribePromise).toBeRejectedWith( new Parse.Error(141, 'not allowed to connect') ); + await expectAsync(query.subscribe()).toBeRejectedWith( + new Parse.Error(141, 'not allowed to connect') + ); client.close(); cloud._removeAllHooks(); }); From 871f9a4951db643ae7dea97b99c5712f4d773d36 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 12:57:27 +1100 Subject: [PATCH 09/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 9f3696099..3a5c28d1e 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -294,10 +294,11 @@ describe('Parse LiveQuery', () => { await expectAsync(subscription.subscribePromise).toBeRejectedWith( new Parse.Error(141, 'not allowed to connect') ); + const defaultClient = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient(); + defaultClient.close(); await expectAsync(query.subscribe()).toBeRejectedWith( new Parse.Error(141, 'not allowed to connect') ); - client.close(); cloud._removeAllHooks(); }); }); From eea0f9209f582f42de1a4d2c6d75b846201401b9 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 13:15:14 +1100 Subject: [PATCH 10/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 3a5c28d1e..26bf98f34 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -299,6 +299,8 @@ describe('Parse LiveQuery', () => { await expectAsync(query.subscribe()).toBeRejectedWith( new Parse.Error(141, 'not allowed to connect') ); + defaultClient.close(); + defaultClient._handleReset(); cloud._removeAllHooks(); }); }); From b61b5e1f5736f6f92784100c905111bc01a8b52d Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 13:35:46 +1100 Subject: [PATCH 11/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 26bf98f34..ee3574ab5 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -301,6 +301,6 @@ describe('Parse LiveQuery', () => { ); defaultClient.close(); defaultClient._handleReset(); - cloud._removeAllHooks(); + cloud.beforeConnect = () => {}; }); }); From a8b14f015cbc70d1a1f4d356d265ce75c44936b0 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 14:24:53 +1100 Subject: [PATCH 12/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index ee3574ab5..d1760e135 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -301,6 +301,7 @@ describe('Parse LiveQuery', () => { ); defaultClient.close(); defaultClient._handleReset(); - cloud.beforeConnect = () => {}; + cloud._removeAllHooks(); + await reconfigureServer(); }); }); From fde2bb755ebc313987351347ed70e9ffa223fc36 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 15:10:23 +1100 Subject: [PATCH 13/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index d1760e135..8695e33a5 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -258,7 +258,6 @@ describe('Parse LiveQuery', () => { }); it('live query can handle beforeConnect and beforeSubscribe errors', async () => { - let cloud = null; await reconfigureServer({ cloud({ Cloud }) { Cloud.beforeSubscribe('TestError', () => { @@ -281,12 +280,12 @@ describe('Parse LiveQuery', () => { new Parse.Error(141, 'not allowed to subscribe') ); client.close(); + let beforeConnect = () => { + throw 'not allowed to connect'; + }; await reconfigureServer({ cloud({ Cloud }) { - Cloud.beforeConnect(() => { - throw 'not allowed to connect'; - }); - cloud = Cloud; + Cloud.beforeConnect(() => beforeConnect()); }, }); client.open(); @@ -301,7 +300,6 @@ describe('Parse LiveQuery', () => { ); defaultClient.close(); defaultClient._handleReset(); - cloud._removeAllHooks(); - await reconfigureServer(); + beforeConnect = () => {}; }); }); From 7bd826428dd51e404ef2cb558a8d0e5bb3241265 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 15:31:44 +1100 Subject: [PATCH 14/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 8695e33a5..c1a22dc11 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -288,18 +288,12 @@ describe('Parse LiveQuery', () => { Cloud.beforeConnect(() => beforeConnect()); }, }); + client._handleReset(); client.open(); subscription = client.subscribe(query); await expectAsync(subscription.subscribePromise).toBeRejectedWith( new Parse.Error(141, 'not allowed to connect') ); - const defaultClient = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient(); - defaultClient.close(); - await expectAsync(query.subscribe()).toBeRejectedWith( - new Parse.Error(141, 'not allowed to connect') - ); - defaultClient.close(); - defaultClient._handleReset(); beforeConnect = () => {}; }); }); From a99309bbf956b7d42c84bb1942ccbfd0f5c88c94 Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 16:32:19 +1100 Subject: [PATCH 15/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index c1a22dc11..91896fa41 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -265,7 +265,7 @@ describe('Parse LiveQuery', () => { }); }, }); - const client = new Parse.LiveQueryClient({ + let client = new Parse.LiveQueryClient({ applicationId: 'integration', serverURL: 'ws://localhost:1337', javascriptKey: null, @@ -288,7 +288,14 @@ describe('Parse LiveQuery', () => { Cloud.beforeConnect(() => beforeConnect()); }, }); - client._handleReset(); + client = new Parse.LiveQueryClient({ + applicationId: 'integration', + serverURL: 'ws://localhost:1337', + javascriptKey: null, + masterKey: null, + sessionToken: null, + installationId: null, + }); client.open(); subscription = client.subscribe(query); await expectAsync(subscription.subscribePromise).toBeRejectedWith( From e60c5266d4e79ae8ea8832f78a3576f14a48c76a Mon Sep 17 00:00:00 2001 From: dblythy Date: Fri, 11 Nov 2022 16:44:45 +1100 Subject: [PATCH 16/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 91896fa41..b500c51b1 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -303,4 +303,23 @@ describe('Parse LiveQuery', () => { ); beforeConnect = () => {}; }); + + it('connectPromise does throw', async () => { + const client = new Parse.LiveQueryClient({ + applicationId: 'integration', + serverURL: 'ws://localhost:1337', + javascriptKey: null, + masterKey: null, + sessionToken: null, + installationId: null, + }); + client.connectPromise = Promise.reject(new Parse.Error(141, 'connect error')); + client.open(); + const query = new Parse.Query('TestError'); + const subscription = client.subscribe(query); + await expectAsync(subscription.subscribePromise).toBeRejectedWith( + new Parse.Error(141, 'connect error') + ); + client.close(); + }); }); From 1dc35cd5b44b9b7e8c6ff0d4082748a42193f7be Mon Sep 17 00:00:00 2001 From: dblythy Date: Mon, 14 Nov 2022 22:02:50 +1100 Subject: [PATCH 17/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index b500c51b1..dc0aaaff3 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -305,20 +305,28 @@ describe('Parse LiveQuery', () => { }); it('connectPromise does throw', async () => { + await reconfigureServer({ + cloud({ Cloud }) { + Cloud.beforeConnect((params) => { + if (params.sessionToken === 'testToken') { + throw 'not allowed to connect'; + } + }); + }, + }); const client = new Parse.LiveQueryClient({ applicationId: 'integration', serverURL: 'ws://localhost:1337', javascriptKey: null, masterKey: null, - sessionToken: null, + sessionToken: 'testToken', installationId: null, }); - client.connectPromise = Promise.reject(new Parse.Error(141, 'connect error')); client.open(); const query = new Parse.Query('TestError'); const subscription = client.subscribe(query); await expectAsync(subscription.subscribePromise).toBeRejectedWith( - new Parse.Error(141, 'connect error') + new Parse.Error(141, 'not allowed to connect') ); client.close(); }); From 1d805b7d6f1d91543a2ded778eb5ab02636269de Mon Sep 17 00:00:00 2001 From: dblythy Date: Mon, 14 Nov 2022 22:08:32 +1100 Subject: [PATCH 18/21] Update helper.js --- integration/test/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/helper.js b/integration/test/helper.js index 10ceb92ee..713ce7c26 100644 --- a/integration/test/helper.js +++ b/integration/test/helper.js @@ -57,7 +57,7 @@ const defaultConfiguration = { }, }, verbose: false, - silent: true, + silent: false, push: { android: { senderId: 'yolo', From de2335e05192ce8d4126cca80da66d44a71e17b8 Mon Sep 17 00:00:00 2001 From: dblythy Date: Mon, 14 Nov 2022 22:13:19 +1100 Subject: [PATCH 19/21] Update helper.js --- integration/test/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/helper.js b/integration/test/helper.js index 713ce7c26..10ceb92ee 100644 --- a/integration/test/helper.js +++ b/integration/test/helper.js @@ -57,7 +57,7 @@ const defaultConfiguration = { }, }, verbose: false, - silent: false, + silent: true, push: { android: { senderId: 'yolo', From 336239708db93c475ce61709fe28c4d520ca97a3 Mon Sep 17 00:00:00 2001 From: dblythy Date: Mon, 14 Nov 2022 22:16:35 +1100 Subject: [PATCH 20/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index dc0aaaff3..59fb39d3e 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -280,28 +280,6 @@ describe('Parse LiveQuery', () => { new Parse.Error(141, 'not allowed to subscribe') ); client.close(); - let beforeConnect = () => { - throw 'not allowed to connect'; - }; - await reconfigureServer({ - cloud({ Cloud }) { - Cloud.beforeConnect(() => beforeConnect()); - }, - }); - client = new Parse.LiveQueryClient({ - applicationId: 'integration', - serverURL: 'ws://localhost:1337', - javascriptKey: null, - masterKey: null, - sessionToken: null, - installationId: null, - }); - client.open(); - subscription = client.subscribe(query); - await expectAsync(subscription.subscribePromise).toBeRejectedWith( - new Parse.Error(141, 'not allowed to connect') - ); - beforeConnect = () => {}; }); it('connectPromise does throw', async () => { From e062596c79a4b2fed7b132464acfe45d768a71f3 Mon Sep 17 00:00:00 2001 From: dblythy Date: Mon, 14 Nov 2022 22:19:37 +1100 Subject: [PATCH 21/21] Update ParseLiveQueryTest.js --- integration/test/ParseLiveQueryTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/test/ParseLiveQueryTest.js b/integration/test/ParseLiveQueryTest.js index 59fb39d3e..ab779b186 100644 --- a/integration/test/ParseLiveQueryTest.js +++ b/integration/test/ParseLiveQueryTest.js @@ -265,7 +265,7 @@ describe('Parse LiveQuery', () => { }); }, }); - let client = new Parse.LiveQueryClient({ + const client = new Parse.LiveQueryClient({ applicationId: 'integration', serverURL: 'ws://localhost:1337', javascriptKey: null, @@ -275,7 +275,7 @@ describe('Parse LiveQuery', () => { }); client.open(); const query = new Parse.Query('TestError'); - let subscription = client.subscribe(query); + const subscription = client.subscribe(query); await expectAsync(subscription.subscribePromise).toBeRejectedWith( new Parse.Error(141, 'not allowed to subscribe') );