Skip to content
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
9 changes: 6 additions & 3 deletions lib/base/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { CHANNELS, tracePromise, traceCallback, publish } = require('../diagnosti

const NODE_MSSQL_SCHEMA = {
...MSSQL_SCHEMA,
encrypt: { type: 'boolean' },
useutc: { type: 'boolean' },
stream: { type: 'boolean' },
parsejson: { type: 'boolean' },
Expand Down Expand Up @@ -233,9 +234,11 @@ class ConnectionPool extends EventEmitter {
break
}
case 'encrypt':
Object.assign(config.options, {
encrypt: !!value
})
if (typeof value === 'boolean') {
Object.assign(config.options, {
encrypt: value
})
}
break
case 'enlist':
break
Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"license": "MIT",
"dependencies": {
"@tediousjs/connection-string": "^1.0.0",
"@tediousjs/connection-string": "^1.1.2",
"commander": "^11.0.0",
"debug": "^4.3.3",
"tarn": "^3.0.2",
Expand Down
54 changes: 54 additions & 0 deletions test/common/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,60 @@ describe('connection string boolean options', () => {
})
})

describe('connection string encrypt option', () => {
it('does not set encrypt when Encrypt is left out', () => {
const config = BasePool._parseConnectionString('Server=localhost')
assert.strictEqual('encrypt' in config.options, false)
})

it('does not set encrypt when Encrypt is empty', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt=')
assert.strictEqual('encrypt' in config.options, false)
})

it('does not set encrypt when Encrypt is empty and parses the next pair', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt=;Database=db')
assert.strictEqual('encrypt' in config.options, false)
assert.strictEqual(config.database, 'db')
})

it('does not set encrypt when Encrypt is only whitespace', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt={ }')
assert.strictEqual('encrypt' in config.options, false)
})

it('parses Encrypt=true as true', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt=true')
assert.strictEqual(config.options.encrypt, true)
})

it('parses Encrypt=yes as true', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt=yes')
assert.strictEqual(config.options.encrypt, true)
})

it('parses Encrypt=false as false', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt=false')
assert.strictEqual(config.options.encrypt, false)
})

it('parses Encrypt=no as false', () => {
const config = BasePool._parseConnectionString('Server=localhost;Encrypt=no')
assert.strictEqual(config.options.encrypt, false)
})

it('uses the tedious default when Encrypt is empty', () => {
const config = new ConnectionPool('Server=localhost;Encrypt=;Database=db')._config()
assert.strictEqual(config.options.encrypt, true)
assert.strictEqual(config.options.database, 'db')
})

it('uses Encrypt=false in the tedious config', () => {
const config = new ConnectionPool('Server=localhost;Encrypt=false')._config()
assert.strictEqual(config.options.encrypt, false)
})
})

describe('connection string auth - base', () => {
it('parses basic login', () => {
const config = BasePool._parseConnectionString('Server=database.test.com;Database=test;User Id=test;Password=admin')
Expand Down