Skip to content

Commit 27df20f

Browse files
committed
Implement notification filters validation from v1 to v5.0
1 parent 38c2d17 commit 27df20f

17 files changed

+538
-2
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v1.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export default class BoltProtocol {
182182
* @param {string} param.database the target database name.
183183
* @param {string} param.mode the access mode.
184184
* @param {string} param.impersonatedUser the impersonated user
185+
* @param {?string[]} param.notificationFilters the filtering for notifications.
185186
* @param {function(err: Error)} param.beforeError the callback to invoke before handling the error.
186187
* @param {function(err: Error)} param.afterError the callback to invoke after handling the error.
187188
* @param {function()} param.beforeComplete the callback to invoke before handling the completion.
@@ -194,6 +195,7 @@ export default class BoltProtocol {
194195
database,
195196
mode,
196197
impersonatedUser,
198+
notificationFilters,
197199
beforeError,
198200
afterError,
199201
beforeComplete,
@@ -208,6 +210,7 @@ export default class BoltProtocol {
208210
database,
209211
mode,
210212
impersonatedUser,
213+
notificationFilters,
211214
beforeError,
212215
afterError,
213216
beforeComplete,
@@ -290,6 +293,7 @@ export default class BoltProtocol {
290293
* @param {TxConfig} param.txConfig the transaction configuration.
291294
* @param {string} param.database the target database name.
292295
* @param {string} param.impersonatedUser the impersonated user
296+
* @param {?string[]} param.notificationFilters the filtering for notifications.
293297
* @param {string} param.mode the access mode.
294298
* @param {function(keys: string[])} param.beforeKeys the callback to invoke before handling the keys.
295299
* @param {function(keys: string[])} param.afterKeys the callback to invoke after handling the keys.
@@ -309,6 +313,7 @@ export default class BoltProtocol {
309313
database,
310314
mode,
311315
impersonatedUser,
316+
notificationFilters,
312317
beforeKeys,
313318
afterKeys,
314319
beforeError,
@@ -332,6 +337,8 @@ export default class BoltProtocol {
332337
lowRecordWatermark
333338
})
334339

340+
// passing notification filters user on this protocol version throws an error
341+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
335342
// bookmarks and mode are ignored in this version of the protocol
336343
assertTxConfigIsEmpty(txConfig, this._onProtocolError, observer)
337344
// passing in a database name on this protocol version throws an error

packages/bolt-connection/src/bolt/bolt-protocol-v3.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
9292
txConfig,
9393
database,
9494
impersonatedUser,
95+
notificationFilters,
9596
mode,
9697
beforeError,
9798
afterError,
@@ -107,6 +108,8 @@ export default class BoltProtocol extends BoltProtocolV2 {
107108
})
108109
observer.prepareToHandleSingleResponse()
109110

111+
// passing notification filters user on this protocol version throws an error
112+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
110113
// passing in a database name on this protocol version throws an error
111114
assertDatabaseIsEmpty(database, this._onProtocolError, observer)
112115
// passing impersonated user on this protocol version throws an error
@@ -169,6 +172,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
169172
txConfig,
170173
database,
171174
impersonatedUser,
175+
notificationFilters,
172176
mode,
173177
beforeKeys,
174178
afterKeys,
@@ -193,6 +197,8 @@ export default class BoltProtocol extends BoltProtocolV2 {
193197
lowRecordWatermark
194198
})
195199

200+
// passing notification filters user on this protocol version throws an error
201+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
196202
// passing in a database name on this protocol version throws an error
197203
assertDatabaseIsEmpty(database, this._onProtocolError, observer)
198204
// passing impersonated user on this protocol version throws an error

packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
import BoltProtocolV3 from './bolt-protocol-v3'
2020
import RequestMessage from './request-message'
21-
import { assertImpersonatedUserIsEmpty } from './bolt-protocol-util'
21+
import { assertImpersonatedUserIsEmpty, assertNotificationFiltersIsEmpty } from './bolt-protocol-util'
2222
import {
2323
ResultStreamObserver,
2424
ProcedureRouteObserver
@@ -56,6 +56,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
5656
txConfig,
5757
database,
5858
impersonatedUser,
59+
notificationFilters,
5960
mode,
6061
beforeError,
6162
afterError,
@@ -71,6 +72,8 @@ export default class BoltProtocol extends BoltProtocolV3 {
7172
})
7273
observer.prepareToHandleSingleResponse()
7374

75+
// passing notification filters user on this protocol version throws an error
76+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
7477
// passing impersonated user on this protocol version throws an error
7578
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
7679

@@ -91,6 +94,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
9194
txConfig,
9295
database,
9396
impersonatedUser,
97+
notificationFilters,
9498
mode,
9599
beforeKeys,
96100
afterKeys,
@@ -121,6 +125,8 @@ export default class BoltProtocol extends BoltProtocolV3 {
121125
lowRecordWatermark
122126
})
123127

128+
// passing notification filters user on this protocol version throws an error
129+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
124130
// passing impersonated user on this protocol version throws an error
125131
assertImpersonatedUserIsEmpty(impersonatedUser, this._onProtocolError, observer)
126132

packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import transformersFactories from './bolt-protocol-v4x4.transformer'
2626
import utcTransformersFactories from './bolt-protocol-v5x0.utc.transformer'
2727
import Transformer from './transformer'
2828

29+
import { assertNotificationFiltersIsEmpty } from './bolt-protocol-util'
30+
2931
const {
3032
constants: { BOLT_PROTOCOL_V4_4, FETCH_ALL },
3133
bookmarks: { Bookmarks }
@@ -87,6 +89,7 @@ export default class BoltProtocol extends BoltProtocolV43 {
8789
database,
8890
mode,
8991
impersonatedUser,
92+
notificationFilters,
9093
beforeKeys,
9194
afterKeys,
9295
beforeError,
@@ -116,6 +119,9 @@ export default class BoltProtocol extends BoltProtocolV43 {
116119
lowRecordWatermark
117120
})
118121

122+
// passing notification filters user on this protocol version throws an error
123+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
124+
119125
const flushRun = reactive
120126
this.write(
121127
RequestMessage.runWithMetadata(query, parameters, {
@@ -142,6 +148,7 @@ export default class BoltProtocol extends BoltProtocolV43 {
142148
database,
143149
mode,
144150
impersonatedUser,
151+
notificationFilters,
145152
beforeError,
146153
afterError,
147154
beforeComplete,
@@ -156,6 +163,9 @@ export default class BoltProtocol extends BoltProtocolV43 {
156163
})
157164
observer.prepareToHandleSingleResponse()
158165

166+
// passing notification filters user on this protocol version throws an error
167+
assertNotificationFiltersIsEmpty(notificationFilters, this._onProtocolError, observer)
168+
159169
this.write(
160170
RequestMessage.begin({ bookmarks, txConfig, database, mode, impersonatedUser }),
161171
observer,

packages/bolt-connection/test/bolt/bolt-protocol-v1.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,59 @@ describe('#unit BoltProtocolV1', () => {
334334
})
335335
})
336336

337+
describe('Bolt v5.1', () => {
338+
/**
339+
* @param {string[]} notificationFilters The impersonated user.
340+
* @param {function(protocol: BoltProtocolV1)} fn
341+
*/
342+
function verifyNotificationFiltersNotSupportedError (notificationFilters, fn) {
343+
const recorder = new utils.MessageRecordingConnection()
344+
const protocol = new BoltProtocolV1(recorder, null, false, undefined, undefined, () => {})
345+
346+
expect(() => fn(protocol)).toThrowError(
347+
'Driver is connected to the database that does not support user notification filters. ' +
348+
'Please upgrade to neo4j 5.3.0 or later in order to use this functionality. ' +
349+
`Trying to set notifications to ${JSON.stringify(notificationFilters)}.`
350+
)
351+
}
352+
353+
describe('initialize', () => {
354+
function verifyInitialize (notificationFilters) {
355+
verifyNotificationFiltersNotSupportedError(
356+
notificationFilters,
357+
protocol => protocol.initialize({ notificationFilters }))
358+
}
359+
360+
it('should throw error when notificationFilters is set', () => {
361+
verifyInitialize('test')
362+
})
363+
})
364+
365+
describe('beginTransaction', () => {
366+
function verifyBeginTransaction (notificationFilters) {
367+
verifyNotificationFiltersNotSupportedError(
368+
notificationFilters,
369+
protocol => protocol.beginTransaction({ notificationFilters }))
370+
}
371+
372+
it('should throw error when notificationFilters is set', () => {
373+
verifyBeginTransaction('test')
374+
})
375+
})
376+
377+
describe('run', () => {
378+
function verifyRun (notificationFilters) {
379+
verifyNotificationFiltersNotSupportedError(
380+
notificationFilters,
381+
protocol => protocol.run('query', {}, { notificationFilters }))
382+
}
383+
384+
it('should throw error when notificationFilters is set', () => {
385+
verifyRun('test')
386+
})
387+
})
388+
})
389+
337390
describe('unpacker configuration', () => {
338391
test.each([
339392
[false, false],

packages/bolt-connection/test/bolt/bolt-protocol-v2.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,59 @@ describe('#unit BoltProtocolV2', () => {
111111
})
112112
})
113113

114+
describe('Bolt v5.1', () => {
115+
/**
116+
* @param {string[]} notificationFilters The impersonated user.
117+
* @param {function(protocol: BoltProtocolV2)} fn
118+
*/
119+
function verifyNotificationFiltersNotSupportedError (notificationFilters, fn) {
120+
const recorder = new utils.MessageRecordingConnection()
121+
const protocol = new BoltProtocolV2(recorder, null, false, undefined, undefined, () => {})
122+
123+
expect(() => fn(protocol)).toThrowError(
124+
'Driver is connected to the database that does not support user notification filters. ' +
125+
'Please upgrade to neo4j 5.3.0 or later in order to use this functionality. ' +
126+
`Trying to set notifications to ${JSON.stringify(notificationFilters)}.`
127+
)
128+
}
129+
130+
describe('initialize', () => {
131+
function verifyInitialize (notificationFilters) {
132+
verifyNotificationFiltersNotSupportedError(
133+
notificationFilters,
134+
protocol => protocol.initialize({ notificationFilters }))
135+
}
136+
137+
it('should throw error when notificationFilters is set', () => {
138+
verifyInitialize('test')
139+
})
140+
})
141+
142+
describe('beginTransaction', () => {
143+
function verifyBeginTransaction (notificationFilters) {
144+
verifyNotificationFiltersNotSupportedError(
145+
notificationFilters,
146+
protocol => protocol.beginTransaction({ notificationFilters }))
147+
}
148+
149+
it('should throw error when notificationFilters is set', () => {
150+
verifyBeginTransaction('test')
151+
})
152+
})
153+
154+
describe('run', () => {
155+
function verifyRun (notificationFilters) {
156+
verifyNotificationFiltersNotSupportedError(
157+
notificationFilters,
158+
protocol => protocol.run('query', {}, { notificationFilters }))
159+
}
160+
161+
it('should throw error when notificationFilters is set', () => {
162+
verifyRun('test')
163+
})
164+
})
165+
})
166+
114167
describe('watermarks', () => {
115168
it('.run() should configure watermarks', () => {
116169
const recorder = new utils.MessageRecordingConnection()

packages/bolt-connection/test/bolt/bolt-protocol-v3.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,59 @@ describe('#unit BoltProtocolV3', () => {
293293
})
294294
})
295295

296+
describe('Bolt v5.1', () => {
297+
/**
298+
* @param {string[]} notificationFilters The impersonated user.
299+
* @param {function(protocol: BoltProtocolV3)} fn
300+
*/
301+
function verifyNotificationFiltersNotSupportedError (notificationFilters, fn) {
302+
const recorder = new utils.MessageRecordingConnection()
303+
const protocol = new BoltProtocolV3(recorder, null, false, undefined, undefined, () => {})
304+
305+
expect(() => fn(protocol)).toThrowError(
306+
'Driver is connected to the database that does not support user notification filters. ' +
307+
'Please upgrade to neo4j 5.3.0 or later in order to use this functionality. ' +
308+
`Trying to set notifications to ${JSON.stringify(notificationFilters)}.`
309+
)
310+
}
311+
312+
describe('initialize', () => {
313+
function verifyInitialize (notificationFilters) {
314+
verifyNotificationFiltersNotSupportedError(
315+
notificationFilters,
316+
protocol => protocol.initialize({ notificationFilters }))
317+
}
318+
319+
it('should throw error when notificationFilters is set', () => {
320+
verifyInitialize('test')
321+
})
322+
})
323+
324+
describe('beginTransaction', () => {
325+
function verifyBeginTransaction (notificationFilters) {
326+
verifyNotificationFiltersNotSupportedError(
327+
notificationFilters,
328+
protocol => protocol.beginTransaction({ notificationFilters }))
329+
}
330+
331+
it('should throw error when notificationFilters is set', () => {
332+
verifyBeginTransaction('test')
333+
})
334+
})
335+
336+
describe('run', () => {
337+
function verifyRun (notificationFilters) {
338+
verifyNotificationFiltersNotSupportedError(
339+
notificationFilters,
340+
protocol => protocol.run('query', {}, { notificationFilters }))
341+
}
342+
343+
it('should throw error when notificationFilters is set', () => {
344+
verifyRun('test')
345+
})
346+
})
347+
})
348+
296349
describe('unpacker configuration', () => {
297350
test.each([
298351
[false, false],

0 commit comments

Comments
 (0)