Skip to content

Validate query type in the ResultSummary #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/bolt-connection/src/bolt/stream-observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,22 @@ class ResultStreamObserver extends StreamObserver {
}

_handlePullSuccess (meta) {
this._setState(_states.SUCCEEDED)
const completionMetadata = Object.assign(
this._server ? { server: this._server } : {},
this._meta,
meta
)

if (![undefined, null, 'r', 'w', 'rw', 's'].includes(completionMetadata.type)) {
this.onError(
newError(
`Server returned invalid query type. Expected one of [undefined, null, "r", "w", "rw", "s"] but got '${completionMetadata.type}'`,
PROTOCOL_ERROR))
return
}

this._setState(_states.SUCCEEDED)

let beforeHandlerResult = null
if (this._beforeComplete) {
beforeHandlerResult = this._beforeComplete(completionMetadata)
Expand Down
51 changes: 51 additions & 0 deletions packages/bolt-connection/test/bolt/stream-observer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,57 @@ describe('#unit ResultStreamObserver', () => {
})
})
})

describe('metadata validation', () => {
it.each([
['wr'],
['read'],
['read/write'],
['write/read'],
['write'],
['undefined'],
['null'],
['banana']
])(`should trigger onError when the type is '%s'`, (type) => {
const streamObserver = newStreamObserver()
const expectedError = newError(
`Server returned invalid query type. Expected one of [undefined, null, "r", "w", "rw", "s"] but got '${type}'`,
PROTOCOL_ERROR)

streamObserver.onCompleted({ fields: ['A', 'B', 'C'] })
streamObserver.onCompleted({ type })

streamObserver.subscribe(
newObserver(NO_OP, receivedError => {
expect(receivedError).toEqual(expectedError)
}, () => {
fail('Should not succeed')
})
)
})

it.each([
['r'],
['w'],
['rw'],
['s'],
[null],
[undefined]
])(`should trigger onComplete when the type is '%s'`, (type) => {
const streamObserver = newStreamObserver()

streamObserver.onCompleted({ fields: ['A', 'B', 'C'] })
streamObserver.onCompleted({ type })

streamObserver.subscribe(
newObserver(NO_OP, () => {
fail('should not fail')
}, meta => {
expect(meta.type).toBe(type)
})
)
})
})
})

describe('#unit RouteObserver', () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/testkit-backend/src/skipped-tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const skippedTests = [
'Flaky in TeamCity',
ifEndsWith('test_should_fail_when_writing_to_unexpectedly_interrupting_writers_on_run_using_tx_function'),
),
skip(
'Driver does not validate query type values in result summaries',
ifEquals('stub.summary.test_summary.TestSummary.test_invalid_query_type')
),
skip(
'ResultSummary.notifications defaults to empty array instead of return null/undefined',
ifEquals('stub.summary.test_summary.TestSummary.test_no_notifications'),
Expand Down