Skip to content

Introduce Driver.isEncrypted() method to the API #868

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/core/src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ class Driver {
return connectionProvider.supportsUserImpersonation()
}

/**
* Returns boolean to indicate if driver has been configured with encryption enabled.
*
* @returns {boolean}
*/
isEncrypted(): boolean {
return this._isEncrypted()
}

/**
* @protected
* @returns {boolean}
Expand All @@ -220,7 +229,7 @@ class Driver {
* @returns {boolean}
*/
_isEncrypted() {
return this._config.encrypted === ENCRYPTION_ON
return this._config.encrypted === ENCRYPTION_ON || this._config.encrypted === true
}

/**
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/driver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ describe('Driver', () => {
promise.catch(_ => 'Do nothing').finally(() => {})
})

it.each([
[{ encrypted: true }, true],
[{ encrypted: false }, false],
[{}, false],
[{ encrypted: 'ENCRYPTION_ON' }, true],
[{ encrypted: 'ENCRYPTION_OFF' }, false],
])('.isEncrypted()', (config, expectedValue) => {
const connectionProvider = new ConnectionProvider()
connectionProvider.close = jest.fn(() => Promise.resolve())
// @ts-ignore
const driver = new Driver(META_INFO, config, mockCreateConnectonProvider(connectionProvider))

expect(driver.isEncrypted()).toEqual(expectedValue)
})

function mockCreateConnectonProvider(connectionProvider: ConnectionProvider) {
return (
id: number,
Expand Down
6 changes: 6 additions & 0 deletions packages/neo4j-driver/test/driver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('#unit driver', () => {
sharedNeo4j.authToken
)
expect(driver._isEncrypted()).toBeFalsy()
expect(driver.isEncrypted()).toBeFalsy()
expect(driver._supportsRouting()).toBeFalsy()
})

Expand All @@ -57,6 +58,7 @@ describe('#unit driver', () => {
sharedNeo4j.authToken
)
expect(driver._isEncrypted()).toBeTruthy()
expect(driver.isEncrypted()).toBeTruthy()
expect(driver._getTrust()).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES')
expect(driver._supportsRouting()).toBeFalsy()
})
Expand All @@ -67,6 +69,7 @@ describe('#unit driver', () => {
sharedNeo4j.authToken
)
expect(driver._isEncrypted()).toBeTruthy()
expect(driver.isEncrypted()).toBeTruthy()
expect(driver._getTrust()).toEqual('TRUST_ALL_CERTIFICATES')
expect(driver._supportsRouting()).toBeFalsy()
})
Expand All @@ -77,6 +80,7 @@ describe('#unit driver', () => {
sharedNeo4j.authToken
)
expect(driver._isEncrypted()).toBeFalsy()
expect(driver.isEncrypted()).toBeFalsy()
expect(driver._supportsRouting()).toBeTruthy()
})

Expand All @@ -86,6 +90,7 @@ describe('#unit driver', () => {
sharedNeo4j.authToken
)
expect(driver._isEncrypted()).toBeTruthy()
expect(driver.isEncrypted()).toBeTruthy()
expect(driver._getTrust()).toEqual('TRUST_SYSTEM_CA_SIGNED_CERTIFICATES')
expect(driver._supportsRouting()).toBeTruthy()
})
Expand All @@ -96,6 +101,7 @@ describe('#unit driver', () => {
sharedNeo4j.authToken
)
expect(driver._isEncrypted()).toBeTruthy()
expect(driver.isEncrypted()).toBeTruthy()
expect(driver._getTrust()).toEqual('TRUST_ALL_CERTIFICATES')
expect(driver._supportsRouting()).toBeTruthy()
})
Expand Down