Skip to content

Commit ac379be

Browse files
committed
Fix unit/integration tests related with connection.connect and bolt-agent for Deno
The test code related with `connection.connect` were calling the method without the bolt agent causing all kind of errors. Add the bolt agent to the calls and expectations solves the issue. `Deno.osRelease()` and the flag `--allow-sys` are not available in Deno 1.19.2. The missing flag was causing the test don't even start. The method unexistance was causing the code fails because is calling a non existing method. The missing flag is solved by using `--allow-all` instead. This is a more permissive flag, but it is not a big deal in test env. The absence of `Deno.osRelease()` is solved by not setting the release when this method is not available. This might be an issue for old Deno users, but it's not a blocker.
1 parent eb9897a commit ac379be

File tree

8 files changed

+41
-39
lines changed

8 files changed

+41
-39
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import AuthenticationProvider from '../../src/connection-provider/authentication
2121

2222
describe('AuthenticationProvider', () => {
2323
const USER_AGENT = 'javascript-driver/5.5.0'
24+
const BOLT_AGENT = 'javascript-driver/5.5.0 some information about system'
2425

2526
describe('.authenticate()', () => {
2627
describe('when called without an auth', () => {
@@ -69,7 +70,7 @@ describe('AuthenticationProvider', () => {
6970

7071
await authenticationProvider.authenticate({ connection })
7172

72-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, authToken)
73+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, authToken, false)
7374
})
7475

7576
it('should throw errors happened during token refresh', async () => {
@@ -201,7 +202,7 @@ describe('AuthenticationProvider', () => {
201202

202203
await authenticationProvider.authenticate({ connection })
203204

204-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, authToken)
205+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, authToken, false)
205206
})
206207

207208
it('should throw errors happened during token refresh', async () => {
@@ -330,7 +331,7 @@ describe('AuthenticationProvider', () => {
330331

331332
await authenticationProvider.authenticate({ connection })
332333

333-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, authToken)
334+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, authToken, false)
334335
})
335336

336337
it('should throw errors happened during connection.connect', async () => {
@@ -405,7 +406,7 @@ describe('AuthenticationProvider', () => {
405406

406407
await authenticationProvider.authenticate({ connection, auth })
407408

408-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, auth, false)
409+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth, false)
409410
})
410411

411412
it('should return the connection', async () => {
@@ -451,7 +452,7 @@ describe('AuthenticationProvider', () => {
451452

452453
await authenticationProvider.authenticate({ connection, auth })
453454

454-
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, auth)
455+
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth)
455456
})
456457

457458
it('should not call connection connect with the supplied auth and skipReAuth=true', async () => {
@@ -462,7 +463,7 @@ describe('AuthenticationProvider', () => {
462463

463464
await authenticationProvider.authenticate({ connection, auth, skipReAuth: true })
464465

465-
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, auth)
466+
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth)
466467
})
467468

468469
if (supportsReAuth) {
@@ -474,7 +475,7 @@ describe('AuthenticationProvider', () => {
474475

475476
await authenticationProvider.authenticate({ connection, auth, forceReAuth: true })
476477

477-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, auth, false)
478+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth, false)
478479
})
479480
} else {
480481
it('should not call connection connect with the supplied auth if forceReAuth=true', async () => {
@@ -485,7 +486,7 @@ describe('AuthenticationProvider', () => {
485486

486487
await authenticationProvider.authenticate({ connection, auth, forceReAuth: true })
487488

488-
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, auth)
489+
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth)
489490
})
490491
}
491492

@@ -519,7 +520,7 @@ describe('AuthenticationProvider', () => {
519520

520521
await authenticationProvider.authenticate({ connection, auth })
521522

522-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, auth, false)
523+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth, false)
523524
})
524525

525526
it('should return the connection', async () => {
@@ -569,7 +570,7 @@ describe('AuthenticationProvider', () => {
569570

570571
await authenticationProvider.authenticate({ connection, auth, waitReAuth })
571572

572-
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, auth, expectedWaitForReAuth)
573+
expect(connection.connect).toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth, expectedWaitForReAuth)
573574
})
574575

575576
it('should not call connect when skipReAuth=true', async () => {
@@ -593,7 +594,7 @@ describe('AuthenticationProvider', () => {
593594

594595
await authenticationProvider.authenticate({ connection, auth })
595596

596-
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, auth)
597+
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth)
597598
})
598599

599600
it('should not call connection connect with the supplied auth and forceReAuth=true', async () => {
@@ -604,7 +605,7 @@ describe('AuthenticationProvider', () => {
604605

605606
await authenticationProvider.authenticate({ connection, auth, forceReAuth: true })
606607

607-
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, auth)
608+
expect(connection.connect).not.toHaveBeenCalledWith(USER_AGENT, BOLT_AGENT, auth)
608609
})
609610

610611
it('should return the connection', async () => {
@@ -787,7 +788,8 @@ describe('AuthenticationProvider', () => {
787788
const authTokenManager = expirationBasedAuthTokenManager({ tokenProvider: authTokenProvider })
788789
const provider = new AuthenticationProvider({
789790
authTokenManager,
790-
userAgent: USER_AGENT
791+
userAgent: USER_AGENT,
792+
boltAgent: BOLT_AGENT
791793
})
792794

793795
if (mocks) {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('ChannelConnection', () => {
4848
const protocolSupplier = () => protocol
4949
const connection = spyOnConnectionChannel({ channel, protocolSupplier })
5050

51-
await connection.connect('userAgent', {})
51+
await connection.connect('userAgent', 'boltAgent', {})
5252

5353
expect(channel.setupReceiveTimeout).toHaveBeenCalledWith(expected)
5454
}
@@ -79,7 +79,7 @@ describe('ChannelConnection', () => {
7979
const protocolSupplier = () => protocol
8080
const connection = spyOnConnectionChannel({ channel, protocolSupplier })
8181

82-
await connection.connect('userAgent', {})
82+
await connection.connect('userAgent', 'boltAgent', {})
8383

8484
expect(channel.setupReceiveTimeout).not.toHaveBeenCalled()
8585
}
@@ -114,7 +114,7 @@ describe('ChannelConnection', () => {
114114
address
115115
})
116116

117-
await connection.connect('userAgent', {})
117+
await connection.connect('userAgent', 'boltAgent', {})
118118
expect(loggerFunction).toHaveBeenCalledWith(
119119
'info',
120120
`Connection [${
@@ -142,7 +142,7 @@ describe('ChannelConnection', () => {
142142
const protocolSupplier = () => protocol
143143
const connection = spyOnConnectionChannel({ channel, protocolSupplier, notificationFilter })
144144

145-
await connection.connect('userAgent', {})
145+
await connection.connect('userAgent', 'boltAgent', {})
146146

147147
const call = protocol.initialize.mock.calls[0][0]
148148

@@ -159,7 +159,7 @@ describe('ChannelConnection', () => {
159159
const protocolSupplier = () => protocol
160160
const connection = spyOnConnectionChannel({ protocolSupplier })
161161

162-
await connection.connect('userAgent', authToken)
162+
await connection.connect('userAgent', 'boltAgent', authToken)
163163

164164
expect(connection.authToken).toEqual(authToken)
165165
})
@@ -181,7 +181,7 @@ describe('ChannelConnection', () => {
181181
const protocolSupplier = () => protocol
182182
const connection = spyOnConnectionChannel({ protocolSupplier })
183183

184-
await connection.connect('userAgent', authToken)
184+
await connection.connect('userAgent', 'boltAgent', authToken)
185185

186186
expect(protocol.initialize).not.toHaveBeenCalled()
187187
expect(protocol.logoff).toHaveBeenCalledWith()
@@ -207,7 +207,7 @@ describe('ChannelConnection', () => {
207207
const protocolSupplier = () => protocol
208208
const connection = spyOnConnectionChannel({ protocolSupplier })
209209

210-
const connectionPromise = connection.connect('userAgent', authToken, true)
210+
const connectionPromise = connection.connect('userAgent', 'boltAgent', authToken, true)
211211

212212
const isPending = await Promise.race([connectionPromise, Promise.resolve(true)])
213213
expect(isPending).toEqual(true)
@@ -243,7 +243,7 @@ describe('ChannelConnection', () => {
243243
const protocolSupplier = () => protocol
244244
const connection = spyOnConnectionChannel({ protocolSupplier })
245245

246-
const connectionPromise = connection.connect('userAgent', authToken, true)
246+
const connectionPromise = connection.connect('userAgent', 'boltAgent', authToken, true)
247247

248248
const isPending = await Promise.race([connectionPromise, Promise.resolve(true)])
249249
expect(isPending).toEqual(true)
@@ -278,7 +278,7 @@ describe('ChannelConnection', () => {
278278
const protocolSupplier = () => protocol
279279
const connection = spyOnConnectionChannel({ protocolSupplier })
280280

281-
const connectionPromise = connection.connect('userAgent', authToken, true)
281+
const connectionPromise = connection.connect('userAgent', 'boltAgent', authToken, true)
282282

283283
const isPending = await Promise.race([connectionPromise, Promise.resolve(true)])
284284
expect(isPending).toEqual(true)
@@ -314,7 +314,7 @@ describe('ChannelConnection', () => {
314314
const protocolSupplier = () => protocol
315315
const connection = spyOnConnectionChannel({ protocolSupplier })
316316

317-
await expect(connection.connect('userAgent', authToken)).rejects.toThrow(
317+
await expect(connection.connect('userAgent', 'boltAgent', authToken)).rejects.toThrow(
318318
newError('Connection does not support re-auth')
319319
)
320320

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"test": "jest",
1111
"test::watch": "jest --watch",
1212
"test::unit": "npm run test",
13-
"test::deno": "deno test --allow-sys ./test/deno/",
13+
"test::deno": "deno test --allow-all ./test/deno/",
1414
"predocs": "npm run build && npm run build::es6",
1515
"docs": "esdoc -c esdoc.json",
1616
"prepare": "npm run build",

packages/core/src/internal/bolt-agent/deno/bolt-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function fromVersion (version: string): string {
2626
//@ts-ignore
2727
const NODE_V8_VERSION = Deno.version.v8
2828
//@ts-ignore
29-
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease()}`
29+
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease ? Deno.osRelease() : ''}`.trim()
3030

3131
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${DENO_VERSION} (v8 ${NODE_V8_VERSION})`
3232
}

packages/core/test/deno/internal/bolt-agent/deno/bolt-agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Deno.test('Test full bolt agent', () => {
3838
//@ts-ignore
3939
const NODE_V8_VERSION = Deno.version.v8
4040
//@ts-ignore
41-
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease()}`
41+
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease ? Deno.osRelease() : ''}`.trim()
4242

4343
const boltAgentExpected = `neo4j-javascript/5.3 (${OS_NAME_VERSION}; ${HOST_ARCH}) ${DENO_VERSION} (v8 ${NODE_V8_VERSION})`
4444

packages/neo4j-driver-deno/lib/core/internal/bolt-agent/deno/bolt-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function fromVersion (version: string): string {
2626
//@ts-ignore
2727
const NODE_V8_VERSION = Deno.version.v8
2828
//@ts-ignore
29-
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease()}`
29+
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease ? Deno.osRelease() : ''}`.trim()
3030

3131
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${DENO_VERSION} (v8 ${NODE_V8_VERSION})`
3232
}

packages/neo4j-driver/test/internal/connection-channel.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('#integration ChannelConnection', () => {
104104
}
105105

106106
connection
107-
.connect('mydriver/0.0.0', basicAuthToken())
107+
.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken())
108108
.then(() => {
109109
connection
110110
.protocol()
@@ -177,7 +177,7 @@ describe('#integration ChannelConnection', () => {
177177
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
178178

179179
connection
180-
.connect('mydriver/0.0.0', basicAuthToken())
180+
.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken())
181181
.then(initializedConnection => {
182182
expect(initializedConnection).toBe(connection)
183183
done()
@@ -189,7 +189,7 @@ describe('#integration ChannelConnection', () => {
189189
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) // wrong port
190190

191191
connection
192-
.connect('mydriver/0.0.0', basicWrongAuthToken())
192+
.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicWrongAuthToken())
193193
.then(() => done.fail('Should not initialize'))
194194
.catch(error => {
195195
expect(error).toBeDefined()
@@ -200,7 +200,7 @@ describe('#integration ChannelConnection', () => {
200200
it('should have server version after connection initialization completed', async done => {
201201
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
202202
connection
203-
.connect('mydriver/0.0.0', basicAuthToken())
203+
.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken())
204204
.then(initializedConnection => {
205205
expect(initializedConnection).toBe(connection)
206206
const serverVersion = ServerVersion.fromString(connection.version)
@@ -214,7 +214,7 @@ describe('#integration ChannelConnection', () => {
214214
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
215215

216216
connection
217-
.connect('mydriver/0.0.0', basicWrongAuthToken())
217+
.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicWrongAuthToken())
218218
.then(() => done.fail('Should not connect'))
219219
.catch(initialError => {
220220
expect(initialError).toBeDefined()
@@ -274,7 +274,7 @@ describe('#integration ChannelConnection', () => {
274274
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
275275

276276
connection
277-
.connect('my-driver/1.2.3', basicAuthToken())
277+
.connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken())
278278
.then(() => {
279279
connection
280280
.resetAndFlush()
@@ -297,7 +297,7 @@ describe('#integration ChannelConnection', () => {
297297
it('should fail to reset and flush when FAILURE received', async done => {
298298
createConnection(`bolt://${sharedNeo4j.hostname}`)
299299
.then(connection => {
300-
connection.connect('my-driver/1.2.3', basicAuthToken()).then(() => {
300+
connection.connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken()).then(() => {
301301
connection
302302
.resetAndFlush()
303303
.then(() => done.fail('Should fail'))
@@ -325,7 +325,7 @@ describe('#integration ChannelConnection', () => {
325325
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
326326

327327
connection
328-
.connect('my-driver/1.2.3', basicAuthToken())
328+
.connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken())
329329
.then(() => {
330330
connection
331331
.resetAndFlush()
@@ -353,7 +353,7 @@ describe('#integration ChannelConnection', () => {
353353
createConnection(`bolt://${sharedNeo4j.hostname}`)
354354
.then(connection => {
355355
connection
356-
.connect('my-driver/1.2.3', basicAuthToken())
356+
.connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken())
357357
.then(() => {
358358
connection.protocol()._responseHandler._currentFailure = newError(
359359
'Hello'
@@ -419,7 +419,7 @@ describe('#integration ChannelConnection', () => {
419419
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
420420
recordWrittenMessages(connection._protocol, messages)
421421

422-
await connection.connect('mydriver/0.0.0', basicAuthToken())
422+
await connection.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken())
423423

424424
expect(connection.isOpen()).toBeTruthy()
425425
await connection.close()
@@ -436,7 +436,7 @@ describe('#integration ChannelConnection', () => {
436436
it('should not prepare broken connection to close', async () => {
437437
connection = await createConnection(`bolt://${sharedNeo4j.hostname}`)
438438

439-
await connection.connect('my-connection/9.9.9', basicAuthToken())
439+
await connection.connect('my-connection/9.9.9', 'mydriver/0.0.0 some system info', basicAuthToken())
440440
expect(connection._protocol).toBeDefined()
441441
expect(connection._protocol).not.toBeNull()
442442

packages/neo4j-driver/test/internal/connection-delegate.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('#unit DelegateConnection', () => {
128128
const spy = spyOn(delegate, 'connect')
129129
const connection = new DelegateConnection(delegate, null)
130130

131-
connection.connect('neo4j/js-driver', {})
131+
connection.connect('neo4j/js-driver', 'mydriver/0.0.0 some system info', {})
132132

133133
expect(spy).toHaveBeenCalledTimes(1)
134134
})

0 commit comments

Comments
 (0)