Skip to content

Commit b99d313

Browse files
authored
Introduce Driver.isEncrypted() method to the API (#868)
1 parent 47ea9df commit b99d313

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

packages/core/src/driver.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ class Driver {
205205
return connectionProvider.supportsUserImpersonation()
206206
}
207207

208+
/**
209+
* Returns boolean to indicate if driver has been configured with encryption enabled.
210+
*
211+
* @returns {boolean}
212+
*/
213+
isEncrypted(): boolean {
214+
return this._isEncrypted()
215+
}
216+
208217
/**
209218
* @protected
210219
* @returns {boolean}
@@ -220,7 +229,7 @@ class Driver {
220229
* @returns {boolean}
221230
*/
222231
_isEncrypted() {
223-
return this._config.encrypted === ENCRYPTION_ON
232+
return this._config.encrypted === ENCRYPTION_ON || this._config.encrypted === true
224233
}
225234

226235
/**

packages/core/test/driver.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ describe('Driver', () => {
140140
promise.catch(_ => 'Do nothing').finally(() => {})
141141
})
142142

143+
it.each([
144+
[{ encrypted: true }, true],
145+
[{ encrypted: false }, false],
146+
[{}, false],
147+
[{ encrypted: 'ENCRYPTION_ON' }, true],
148+
[{ encrypted: 'ENCRYPTION_OFF' }, false],
149+
])('.isEncrypted()', (config, expectedValue) => {
150+
const connectionProvider = new ConnectionProvider()
151+
connectionProvider.close = jest.fn(() => Promise.resolve())
152+
// @ts-ignore
153+
const driver = new Driver(META_INFO, config, mockCreateConnectonProvider(connectionProvider))
154+
155+
expect(driver.isEncrypted()).toEqual(expectedValue)
156+
})
157+
143158
function mockCreateConnectonProvider(connectionProvider: ConnectionProvider) {
144159
return (
145160
id: number,

packages/neo4j-driver/test/driver.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('#unit driver', () => {
4848
sharedNeo4j.authToken
4949
)
5050
expect(driver._isEncrypted()).toBeFalsy()
51+
expect(driver.isEncrypted()).toBeFalsy()
5152
expect(driver._supportsRouting()).toBeFalsy()
5253
})
5354

@@ -57,6 +58,7 @@ describe('#unit driver', () => {
5758
sharedNeo4j.authToken
5859
)
5960
expect(driver._isEncrypted()).toBeTruthy()
61+
expect(driver.isEncrypted()).toBeTruthy()
6062
expect(driver._getTrust()).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES')
6163
expect(driver._supportsRouting()).toBeFalsy()
6264
})
@@ -67,6 +69,7 @@ describe('#unit driver', () => {
6769
sharedNeo4j.authToken
6870
)
6971
expect(driver._isEncrypted()).toBeTruthy()
72+
expect(driver.isEncrypted()).toBeTruthy()
7073
expect(driver._getTrust()).toEqual('TRUST_ALL_CERTIFICATES')
7174
expect(driver._supportsRouting()).toBeFalsy()
7275
})
@@ -77,6 +80,7 @@ describe('#unit driver', () => {
7780
sharedNeo4j.authToken
7881
)
7982
expect(driver._isEncrypted()).toBeFalsy()
83+
expect(driver.isEncrypted()).toBeFalsy()
8084
expect(driver._supportsRouting()).toBeTruthy()
8185
})
8286

@@ -86,6 +90,7 @@ describe('#unit driver', () => {
8690
sharedNeo4j.authToken
8791
)
8892
expect(driver._isEncrypted()).toBeTruthy()
93+
expect(driver.isEncrypted()).toBeTruthy()
8994
expect(driver._getTrust()).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES')
9095
expect(driver._supportsRouting()).toBeTruthy()
9196
})
@@ -96,6 +101,7 @@ describe('#unit driver', () => {
96101
sharedNeo4j.authToken
97102
)
98103
expect(driver._isEncrypted()).toBeTruthy()
104+
expect(driver.isEncrypted()).toBeTruthy()
99105
expect(driver._getTrust()).toEqual('TRUST_ALL_CERTIFICATES')
100106
expect(driver._supportsRouting()).toBeTruthy()
101107
})

0 commit comments

Comments
 (0)