-
Notifications
You must be signed in to change notification settings - Fork 471
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
Fixed issues related to previous PR regarding AAD authentication via connection string #1461
Fixed issues related to previous PR regarding AAD authentication via connection string #1461
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - this is looking a lot better. Please can we have some tests for this, to assert the auth credentials are assigned as expected.
I tested this using the following: Basic SQL Login: var sql = require("../../node-mssql/tedious")
var main = async () => {
var server = `${process.env.server}`
var username = `${process.env.username}`
var database = `${process.env.database}`
var password = `${process.env.password}`
var table = `${process.env.table}`
var conn_str = `Server=${server};Database=${database};User Id=${username};Password=${password};`
console.log(conn_str)
await sql.connect(conn_str).then(async(pool) => {
var result = await pool.request().query(`select top 1 * from ${table}`).catch((err) => {
console.warn(err)
throw err
});
console.log(result)
})
}
main() The other one is using azure-active-directory-service-principal-secret. (Have to redact starting here) var sql = require("../../node-mssql/tedious")
var main = async () => {
var server = `${process.env.server}`
var database = `${process.env.database}`
var conn_str = `Server=${server};Database=${database};Authentication=Active Directory Integrated;client id=${process.env.AZURE_CLIENT_ID};client secret=${process.env.AZURE_CLIENT_SECRET};tenant id=${process.env.AZURE_TENANT_ID}`;
var table = `${process.env.table}`
await sql.connect(conn_str).then(async(pool) => {
var result = await pool.request().query(`select top 1 * from ${table}`).catch((err) => {
console.warn(err)
throw err
});
console.log(result)
});
}
main(); And lastly is azure-active-directory-access-token var sql = require("../../node-mssql/tedious")
const { EnvironmentCredential } = require('@azure/identity')
const tokenUrl = 'https://database.windows.net/.default'
var main = async () => {
const credential = new EnvironmentCredential()
const { token } = await credential.getToken(tokenUrl);
var server = `${process.env.server}`
var database = `${process.env.database}`
var table = `${process.env.table}`
var conn_str = `Server=${server};Database=${database};Authentication=Active Directory Integrated;Token=${token};`;
await sql.connect(conn_str).then(async(pool) => {
var result = await pool.request().query(`select top 1 * from ${table}`).catch((err) => {
console.warn(err)
throw err
});
console.log(result)
});
}
main(); On the basic login, I tried both SQL servers hosted elsewhere outside Azure (SQL Server 2017-2019) and Azure. While the AAD one is Azure only. |
Thanks for that. Whilst that manual testing is really helpful, what I was referring to was the automated test suite. We need some tests that the connection string gets correctly parsed and the output shape looks right for our internal config structure. The unit tests is the best place to add this. Something like: describe('connection string auth', () => {
it('parses basic login', () => {
const config = BaseConnection._parseConnectionString('test string here')
assert.equal(config, { expected shape })
})
... more tests here
}) |
Ok cool, I do have some questions though, for example this connection string: 'Server=database.test.com;Database=test;User Id=admin;Password=admin' In the BaseConnectionPool under /lib/base/connection-pool.js, the object becomes: {
options: { instanceName: undefined },
pool: {},
port: 1433,
server: 'database.test.com',
database: 'test',
domain: undefined,
user: 'test',
password: 'admin'
} But if it passes through /lib/tedious/connection-pool.js, the config above becomes: {
server: 'database.test.com',
options: {
encrypt: true,
trustServerCertificate: false,
instanceName: undefined,
database: 'test',
port: 1433,
connectTimeout: 15000,
requestTimeout: 15000,
tdsVersion: '7_4',
rowCollectionOnDone: false,
rowCollectionOnRequestCompletion: false,
useColumnNames: false,
appName: 'node-mssql'
},
authentication: {
type: 'default',
options: {
userName: 'admin',
password: 'admin',
domain: undefined,
clientId: undefined,
clientSecret: undefined,
tenantId: undefined,
token: undefined
}
}
} Which one should we start testing, the base one? tedious or both? and if both or tedious is included, would it be fine if we seperate the config generation away from _poolCreate() so we can reuse them on the unit-test file? |
Hey @dhensby, I made some changes today, I decided to add both unit tests (Base and Tedious) comparison instead of just base or tedious. Seems to be a good idea to test the two in-case some changes are made either in the connection-pool of either base library or tedious, we can check if it gets affected. |
7a418d1
to
7b22303
Compare
1bd8942
to
c772fe6
Compare
Authentication now uses the standard values defined on [.NET Platform Extension 7](https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring?view=dotnet-plat-ext-7.0).
c772fe6
to
59aea21
Compare
🎉 This PR is included in version 9.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This PR is aimed to fix a couple of issues with the previous PR: #1436 in attempt to accomodate issue #1400
Changes include: