Skip to content

Commit d349b89

Browse files
committed
Ajust the re-auth flow and support FakeTime in tk
1 parent 2be38f2 commit d349b89

File tree

11 files changed

+293
-20
lines changed

11 files changed

+293
-20
lines changed

packages/bolt-connection/src/connection-provider/authentication-provider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export default class AuthenticationProvider {
2929
}
3030

3131
async authenticate ({ connection }) {
32-
if (!this._authToken) {
32+
if (!this._authToken || this._isTokenExpired) {
3333
await this._getFreshAuthToken()
3434
}
3535

36-
if (this._renewableAuthToken.authToken !== connection.authToken || this._isTokenExpired) {
36+
if (this._renewableAuthToken.authToken !== connection.authToken) {
3737
return await connection.connect(this._userAgent, this._authToken)
3838
}
3939

packages/bolt-connection/src/connection/connection-channel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ export default class ChannelConnection extends Connection {
198198
})
199199

200200
const loginPromise = new Promise((resolve, reject) => {
201-
this._protocol.login({ onComplete: resolve, onError: reject, flush: true })
201+
this._protocol.login({ onComplete: resolve, onError: reject, authToken, flush: true })
202202
})
203203

204-
return await Promise.all(logoffPromise, loginPromise)
204+
return await Promise.all([logoffPromise, loginPromise])
205205
.then(() => this)
206206
}
207207

packages/bolt-connection/src/pool/pool.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ class Pool {
203203
while (pool.length) {
204204
const resource = pool.pop()
205205

206-
if (await this._validate(resource)) {
207-
if (this._removeIdleObserver) {
208-
this._removeIdleObserver(resource)
209-
}
206+
if (this._removeIdleObserver) {
207+
this._removeIdleObserver(resource)
208+
}
210209

210+
if (await this._validate(resource)) {
211211
// idle resource is valid and can be acquired
212212
resourceAcquired(key, this._activeResourceCounts)
213213
if (this._log.isDebugEnabled()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export default class AuthenticationProvider {
2929
}
3030

3131
async authenticate ({ connection }) {
32-
if (!this._authToken) {
32+
if (!this._authToken || this._isTokenExpired) {
3333
await this._getFreshAuthToken()
3434
}
3535

36-
if (this._renewableAuthToken.authToken !== connection.authToken || this._isTokenExpired) {
36+
if (this._renewableAuthToken.authToken !== connection.authToken) {
3737
return await connection.connect(this._userAgent, this._authToken)
3838
}
3939

packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-channel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ export default class ChannelConnection extends Connection {
198198
})
199199

200200
const loginPromise = new Promise((resolve, reject) => {
201-
this._protocol.login({ onComplete: resolve, onError: reject, flush: true })
201+
this._protocol.login({ onComplete: resolve, onError: reject, authToken, flush: true })
202202
})
203203

204-
return await Promise.all(logoffPromise, loginPromise)
204+
return await Promise.all([logoffPromise, loginPromise])
205205
.then(() => this)
206206
}
207207

packages/neo4j-driver-deno/lib/bolt-connection/pool/pool.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ class Pool {
203203
while (pool.length) {
204204
const resource = pool.pop()
205205

206-
if (await this._validate(resource)) {
207-
if (this._removeIdleObserver) {
208-
this._removeIdleObserver(resource)
209-
}
206+
if (this._removeIdleObserver) {
207+
this._removeIdleObserver(resource)
208+
}
210209

210+
if (await this._validate(resource)) {
211211
// idle resource is valid and can be acquired
212212
resourceAcquired(key, this._activeResourceCounts)
213213
if (this._log.isDebugEnabled()) {

0 commit comments

Comments
 (0)