Skip to content

Commit 44b4c5d

Browse files
committed
Sync Deno and adapt testkit-backend
1 parent f3446fa commit 44b4c5d

File tree

9 files changed

+59
-36
lines changed

9 files changed

+59
-36
lines changed

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-direct.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {
5050
async acquireConnection ({ accessMode, database, bookmarks, auth, forceReAuth } = {}) {
5151
const databaseSpecificErrorHandler = ConnectionErrorHandler.create({
5252
errorCode: SERVICE_UNAVAILABLE,
53-
handleAuthorizationExpired: (error, address, conn) =>
54-
this._handleAuthorizationExpired(error, address, conn, database)
53+
handleSecurityError: (error, address, conn) =>
54+
this._handleSecurityError(error, address, conn, database)
5555
})
5656

5757
const connection = await this._connectionPool.acquire({ auth, forceReAuth }, this._address)
@@ -68,12 +68,12 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {
6868
return new DelegateConnection(connection, databaseSpecificErrorHandler)
6969
}
7070

71-
_handleAuthorizationExpired (error, address, connection, database) {
71+
_handleSecurityError (error, address, connection, database) {
7272
this._log.warn(
7373
`Direct driver ${this._id} will close connection to ${address} for database '${database}' because of an error ${error.code} '${error.message}'`
7474
)
7575

76-
return super._handleAuthorizationExpired(error, address, connection)
76+
return super._handleSecurityError(error, address, connection)
7777
}
7878

7979
async _hasProtocolVersion (versionPredicate) {

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-pooled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export default class PooledConnectionProvider extends ConnectionProvider {
223223
conn._updateCurrentObserver()
224224
}
225225

226-
_handleAuthorizationExpired (error, address, connection) {
226+
_handleSecurityError (error, address, connection) {
227227
const handled = this._authenticationProvider.handleError({ connection, code: error.code })
228228

229229
if (handled) {

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-routing.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
116116
return error
117117
}
118118

119-
_handleAuthorizationExpired (error, address, connection, database) {
119+
_handleSecurityError (error, address, connection, database) {
120120
this._log.warn(
121121
`Routing driver ${this._id} will close connections to ${address} for database '${database}' because of an error ${error.code} '${error.message}'`
122122
)
123123

124-
return super._handleAuthorizationExpired(error, address, connection, database)
124+
return super._handleSecurityError(error, address, connection, database)
125125
}
126126

127127
_handleWriteFailure (error, address, database) {
@@ -150,7 +150,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
150150
(error, address) => this._handleUnavailability(error, address, context.database),
151151
(error, address) => this._handleWriteFailure(error, address, context.database),
152152
(error, address, conn) =>
153-
this._handleAuthorizationExpired(error, address, conn, context.database)
153+
this._handleSecurityError(error, address, conn, context.database)
154154
)
155155

156156
const routingTable = await this._freshRoutingTable({
@@ -584,7 +584,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
584584

585585
const databaseSpecificErrorHandler = ConnectionErrorHandler.create({
586586
errorCode: SESSION_EXPIRED,
587-
handleAuthorizationExpired: (error, address, conn) => this._handleAuthorizationExpired(error, address, conn)
587+
handleSecurityError: (error, address, conn) => this._handleSecurityError(error, address, conn)
588588
})
589589

590590
const delegateConnection = !connection._sticky

packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-error-handler.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ export default class ConnectionErrorHandler {
2626
errorCode,
2727
handleUnavailability,
2828
handleWriteFailure,
29-
handleAuthorizationExpired
29+
handleSecurityError
3030
) {
3131
this._errorCode = errorCode
3232
this._handleUnavailability = handleUnavailability || noOpHandler
3333
this._handleWriteFailure = handleWriteFailure || noOpHandler
34-
this._handleAuthorizationExpired = handleAuthorizationExpired || noOpHandler
34+
this._handleSecurityError = handleSecurityError || noOpHandler
3535
}
3636

3737
static create ({
3838
errorCode,
3939
handleUnavailability,
4040
handleWriteFailure,
41-
handleAuthorizationExpired
41+
handleSecurityError
4242
}) {
4343
return new ConnectionErrorHandler(
4444
errorCode,
4545
handleUnavailability,
4646
handleWriteFailure,
47-
handleAuthorizationExpired
47+
handleSecurityError
4848
)
4949
}
5050

@@ -63,8 +63,8 @@ export default class ConnectionErrorHandler {
6363
* @return {Neo4jError} new error that should be propagated to the user.
6464
*/
6565
handleAndTransformError (error, address, connection) {
66-
if (isAutorizationExpiredError(error)) {
67-
return this._handleAuthorizationExpired(error, address, connection)
66+
if (isSecurityError(error)) {
67+
return this._handleSecurityError(error, address, connection)
6868
}
6969
if (isAvailabilityError(error)) {
7070
return this._handleUnavailability(error, address, connection)
@@ -76,11 +76,10 @@ export default class ConnectionErrorHandler {
7676
}
7777
}
7878

79-
function isAutorizationExpiredError (error) {
80-
return error && (
81-
error.code === 'Neo.ClientError.Security.AuthorizationExpired' ||
82-
error.code === 'Neo.ClientError.Security.TokenExpired'
83-
)
79+
function isSecurityError (error) {
80+
return error != null &&
81+
error.code != null &&
82+
error.code.startsWith('Neo.ClientError.Security.')
8483
}
8584

8685
function isAvailabilityError (error) {

packages/neo4j-driver-deno/lib/core/auth-token-manager.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class AuthTokenManagers {
120120
* **Warning**: `tokenProvider` must only ever return auth information belonging to the same identity.
121121
* Switching identities using the `AuthTokenManager` is undefined behavior.
122122
*
123-
* @param param0 - The params
123+
* @param {object} param0 - The params
124124
* @param {function(): Promise<AuthToken>} param0.tokenProvider - Retrieves a new valid auth token.
125125
* Must only ever return auth information belonging to the same identity.
126126
* @returns {AuthTokenManager} The basic auth data manager.
@@ -139,8 +139,16 @@ class AuthTokenManagers {
139139

140140
/**
141141
* Holds the common {@link AuthTokenManagers} used in the Driver
142+
*
143+
* @experimental Exposed as preview feature.
142144
*/
143-
export const authTokenManagers: AuthTokenManagers = Object.freeze(new AuthTokenManagers())
145+
const authTokenManagers: AuthTokenManagers = new AuthTokenManagers()
146+
147+
Object.freeze(authTokenManagers)
148+
149+
export {
150+
authTokenManagers
151+
}
144152

145153
export type {
146154
AuthTokenManagers

packages/testkit-backend/src/request-handlers-rx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export {
2828
NewAuthTokenManager,
2929
AuthTokenManagerClose,
3030
AuthTokenManagerGetAuthCompleted,
31-
AuthTokenManagerOnAuthExpiredCompleted,
31+
AuthTokenManagerHandleSecurityExceptionCompleted,
3232
NewBearerAuthTokenManager,
3333
BearerAuthTokenProviderCompleted,
3434
NewBasicAuthTokenManager,

packages/testkit-backend/src/request-handlers.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,16 @@ export function NewAuthTokenManager (_, context, _data, wire) {
529529
wire.writeResponse(responses.AuthTokenManagerGetAuthRequest({ id, authTokenManagerId }))
530530
}),
531531
handleSecurityException: (auth, code) => {
532-
if ([
533-
'Neo.ClientError.Security.Unauthorized',
534-
'Neo.ClientError.Security.TokenExpired'
535-
].includes(code)) {
536-
const id = context.addAuthTokenManagerOnAuthExpiredRequest()
537-
wire.writeResponse(responses.AuthTokenManagerOnAuthExpiredRequest({ id, authTokenManagerId, auth }))
538-
return true
539-
}
540-
return false
532+
// The handle security exception should wait for the response
533+
// to return the error as handle.
534+
// However, testkit doesn't enable sync communication and
535+
// the `handleSecurityException` must be sync since the
536+
// part of the code which get called depends on it be sync.
537+
// Send the message and return true is a naive implementation
538+
// for making some of the tests valid.
539+
const id = context.addAuthTokenManagerOnAuthExpiredRequest()
540+
wire.writeResponse(responses.AuthTokenManagerHandleSecurityExceptionRequest({ id, authTokenManagerId, auth, code }))
541+
return true
541542
}
542543
}
543544
})
@@ -556,7 +557,8 @@ export function AuthTokenManagerGetAuthCompleted (_, context, { requestId, auth
556557
context.removeAuthTokenManagerGetAuthRequest(requestId)
557558
}
558559

559-
export function AuthTokenManagerOnAuthExpiredCompleted (_, context, { requestId }) {
560+
export function AuthTokenManagerHandleSecurityExceptionCompleted (_, context, { requestId }) {
561+
// See NewAuthTokenManager
560562
context.removeAuthTokenManagerOnAuthExpiredRequest(requestId)
561563
}
562564

packages/testkit-backend/src/responses.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export function AuthorizationToken (data) {
115115
return response('AuthorizationToken', data)
116116
}
117117

118-
export function AuthTokenManagerOnAuthExpiredRequest ({ id, authTokenManagerId, auth }) {
119-
return response('AuthTokenManagerOnAuthExpiredRequest', { id, authTokenManagerId, auth: AuthorizationToken(auth) })
118+
export function AuthTokenManagerHandleSecurityExceptionRequest ({ id, authTokenManagerId, auth, code }) {
119+
return response('AuthTokenManagerHandleSecurityExceptionRequest', { id, authTokenManagerId, auth: AuthorizationToken(auth), error_code: code })
120120
}
121121

122122
export function BearerAuthTokenManager ({ id }) {

packages/testkit-backend/src/skipped-tests/common.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import skip, { ifEquals, ifEndsWith, endsWith, ifStartsWith, startsWith, not } from './skip.js'
1+
import skip, { ifEquals, ifEndsWith, endsWith, ifStartsWith, startsWith, not, or } from './skip.js'
22

33
const skippedTests = [
44
skip(
@@ -184,6 +184,20 @@ const skippedTests = [
184184
ifEquals(
185185
'stub.driver_parameters.test_connection_acquisition_timeout_ms.TestConnectionAcquisitionTimeoutMs.test_does_not_encompass_router_handshake'
186186
)
187+
),
188+
skip(
189+
'Backend does not support async AuthTokenManager.handleSecurityException',
190+
ifStartsWith('stub.authorization.test_auth_token_manager.TestAuthTokenManager')
191+
.and(
192+
or(
193+
endsWith('test_error_on_pull_using_session_run'),
194+
endsWith('test_error_on_begin_using_tx_run'),
195+
endsWith('test_error_on_run_using_tx_run'),
196+
endsWith('test_error_on_pull_using_tx_run'),
197+
endsWith('test_error_on_commit_using_tx_run'),
198+
endsWith('test_error_on_rollback_using_tx_run')
199+
)
200+
)
187201
)
188202
]
189203

0 commit comments

Comments
 (0)