From 90fccfda34a4aed6bee24a454f5b92f29884cdb6 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Tue, 11 Jul 2023 19:13:26 -0700 Subject: [PATCH] [Release/1.45] Fix connection URI default value comparisons (#23775) * Fix connection URI default value comparisons (#23705) * Bump STS --- extensions/mssql/config.json | 2 +- .../connection/common/connectionConfig.ts | 12 +++-- .../connection/common/connectionProfile.ts | 8 ++- .../common/providerConnectionInfo.ts | 5 +- .../test/common/connectionConfig.test.ts | 49 ++++++++++--------- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/extensions/mssql/config.json b/extensions/mssql/config.json index cbcc7d86f9..2d61fd3777 100644 --- a/extensions/mssql/config.json +++ b/extensions/mssql/config.json @@ -1,6 +1,6 @@ { "downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}", - "version": "4.8.0.39", + "version": "4.8.1.1", "downloadFileNames": { "Windows_86": "win-x86-net7.0.zip", "Windows_64": "win-x64-net7.0.zip", diff --git a/src/sql/platform/connection/common/connectionConfig.ts b/src/sql/platform/connection/common/connectionConfig.ts index ea8e96f233..59d9020cbf 100644 --- a/src/sql/platform/connection/common/connectionConfig.ts +++ b/src/sql/platform/connection/common/connectionConfig.ts @@ -359,10 +359,10 @@ export class ConnectionConfig { let profiles = this.getIConnectionProfileStores(true); let existingProfile = profiles.find(p => p.providerName === profile.providerName && - p.options.authenticationType === profile.options.authenticationType && - p.options.database === profile.options.database && - p.options.server === profile.options.server && - p.options.user === profile.options.user && + this.checkIfAuthenticationOptionsMatch(p, profile) && + p.options.databaseName === profile.options.databaseName && + p.options.serverName === profile.options.serverName && + p.options.userName === profile.options.userName && p.options.connectionName === profile.options.connectionName && p.groupId === newGroupID && this.checkIfNonDefaultOptionsMatch(p, profile)); @@ -375,6 +375,10 @@ export class ConnectionConfig { return result; } + private checkIfAuthenticationOptionsMatch(profileStore: IConnectionProfileStore, profile: ConnectionProfile): boolean { + return ((profileStore.options.authenticationType === undefined || profileStore.options.authenticationType === '') && (profile.options.authenticationType === undefined || profile.options.authenticationType === '')) || profileStore.options.authenticationType === profile.options.authenticationType; + } + /** * Moves the connection under the target group with the new ID. */ diff --git a/src/sql/platform/connection/common/connectionProfile.ts b/src/sql/platform/connection/common/connectionProfile.ts index 25fe36f2c0..a8836d0142 100644 --- a/src/sql/platform/connection/common/connectionProfile.ts +++ b/src/sql/platform/connection/common/connectionProfile.ts @@ -81,7 +81,7 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa // Set values for advanced options received in model. Object.keys(model.options).forEach(a => { let option = options.find(opt => opt.name === a); - if (option !== undefined) { + if (option !== undefined && option.defaultValue?.toString().toLocaleLowerCase() !== model.options[a]?.toString().toLocaleLowerCase()) { this.options[option.name] = model.options[a]; } }); @@ -358,7 +358,11 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa id: connectionInfo.id }; - profile.options = connectionInfo.options; + Object.keys(connectionInfo.options).forEach(element => { + if (connectionInfo.options[element] && connectionInfo.options[element] !== null && connectionInfo.options[element] !== '') { + profile.options[element] = connectionInfo.options[element]; + } + }); return profile; } diff --git a/src/sql/platform/connection/common/providerConnectionInfo.ts b/src/sql/platform/connection/common/providerConnectionInfo.ts index 0e16d69591..1a9386cf7a 100644 --- a/src/sql/platform/connection/common/providerConnectionInfo.ts +++ b/src/sql/platform/connection/common/providerConnectionInfo.ts @@ -231,7 +231,8 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo { let finalValue = undefined; let options = this.serverCapabilities.connectionOptions.filter(value => value.name === idNames[index]!); if (options.length > 0 && value) { - finalValue = value !== options[0].defaultValue ? value : undefined; + let defaultValue = options[0].defaultValue ?? ''; + finalValue = value && value.toString().toLocaleLowerCase() !== defaultValue.toString().toLocaleLowerCase() ? value : undefined; if (options[0].specialValueType === 'appName' && this.providerName === Constants.mssqlProviderName) { finalValue = (value as string).startsWith('azdata') ? undefined : finalValue } @@ -390,7 +391,7 @@ export class ProviderConnectionInfo implements azdata.ConnectionInfo { element.specialValueType !== ConnectionOptionSpecialType.password) { if (getNonDefault) { let value = this.getOptionValue(element.name); - if (value && value !== element.defaultValue) { + if (value && value.toString().toLocaleLowerCase() !== element.defaultValue?.toLocaleLowerCase()) { connectionOptions.push(element); } } diff --git a/src/sql/platform/connection/test/common/connectionConfig.test.ts b/src/sql/platform/connection/test/common/connectionConfig.test.ts index aac1ca793f..283ba00777 100644 --- a/src/sql/platform/connection/test/common/connectionConfig.test.ts +++ b/src/sql/platform/connection/test/common/connectionConfig.test.ts @@ -82,7 +82,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '' + authenticationType: 'SqlLogin' }, providerName: 'MSSQL', groupId: 'test', @@ -95,7 +95,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '' + authenticationType: 'SqlLogin' }, providerName: 'MSSQL', groupId: 'test', @@ -108,7 +108,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '' + authenticationType: 'SqlLogin' }, providerName: 'MSSQL', groupId: 'g3', @@ -296,7 +296,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: undefined, groupId: undefined, @@ -364,7 +364,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g2/g2-2', groupId: undefined, @@ -509,7 +509,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -541,7 +541,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -580,7 +580,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'newid', @@ -662,7 +662,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -681,7 +681,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -723,7 +723,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -745,7 +745,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -785,7 +785,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -807,7 +807,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -816,7 +816,10 @@ suite('ConnectionConfig', () => { getOptionKeyIdNames: undefined!, matches: undefined!, providerName: 'MSSQL', - options: { 'testProperty1': 'nonDefault' }, + options: { + 'testProperty1': 'nonDefault', + 'testProperty2': '10' + }, saveProfile: true, id: 'server3', connectionName: undefined! @@ -850,7 +853,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -872,7 +875,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -912,7 +915,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -1016,7 +1019,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'g3', groupId: 'g3', @@ -1035,7 +1038,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -1054,7 +1057,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -1090,7 +1093,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test', @@ -1128,7 +1131,7 @@ suite('ConnectionConfig', () => { databaseName: 'database', userName: 'user', password: 'password', - authenticationType: '', + authenticationType: 'SqlLogin', savePassword: true, groupFullName: 'test', groupId: 'test',