Skip to content

Commit 0c22ba7

Browse files
committed
Fixing bug where connection string with integrated auth crashes connection dialog
1 parent d98030e commit 0c22ba7

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/connectionconfig/connectionDialogWebViewController.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
8282

8383
private async loadRecentConnections() {
8484
const recentConnections = this._mainController.connectionManager.connectionStore.loadAllConnections(true).map(c => c.connectionCreds);
85-
const dialogConnections = [];
85+
const dialogConnections: IConnectionDialogProfile[] = [];
8686
for (let i = 0; i < recentConnections.length; i++) {
8787
dialogConnections.push(await this.initializeConnectionForDialog(recentConnections[i]));
8888
}
@@ -106,25 +106,38 @@ export class ConnectionDialogWebViewController extends ReactWebViewPanelControll
106106
this.state.connectionProfile = emptyConnection;
107107
}
108108

109-
private async initializeConnectionForDialog(connection: IConnectionInfo) {
109+
private async initializeConnectionForDialog(connection: IConnectionInfo): Promise<IConnectionDialogProfile> {
110110
// Load the password if it's saved
111111
const isConnectionStringConnection = connection.connectionString !== undefined && connection.connectionString !== '';
112-
const password = await this._mainController.connectionManager.connectionStore.lookupPassword(connection, isConnectionStringConnection);
113112
if (!isConnectionStringConnection) {
113+
const password = await this._mainController.connectionManager.connectionStore.lookupPassword(connection, isConnectionStringConnection);
114114
connection.password = password;
115115
} else {
116-
connection.connectionString = '';
117-
// extract password from connection string it starts after 'Password=' and ends before ';'
118-
const passwordIndex = password.indexOf('Password=') === -1 ? password.indexOf('password=') : password.indexOf('Password=');
119-
if (passwordIndex !== -1) {
120-
const passwordStart = passwordIndex + 'Password='.length;
121-
const passwordEnd = password.indexOf(';', passwordStart);
122-
if (passwordEnd !== -1) {
123-
connection.password = password.substring(passwordStart, passwordEnd);
116+
// If the connection is a connection string connection with SQL Auth:
117+
// * the full connection string is stored as the "password" in the credential store
118+
// * we need to extract the password from the connection string
119+
// If the connection is a connection string connection with a different auth type, then there's nothing in the credential store.
120+
121+
const connectionString = await this._mainController.connectionManager.connectionStore.lookupPassword(connection, isConnectionStringConnection);
122+
123+
if (connectionString) {
124+
const passwordIndex = connectionString.indexOf('Password=') === -1 ? connectionString.indexOf('password=') : connectionString.indexOf('Password=');
125+
126+
if (passwordIndex !== -1) {
127+
// extract password from connection string; found between 'Password=' and the next ';'
128+
const passwordStart = passwordIndex + 'Password='.length;
129+
const passwordEnd = connectionString.indexOf(';', passwordStart);
130+
if (passwordEnd !== -1) {
131+
connection.password = connectionString.substring(passwordStart, passwordEnd);
132+
}
133+
134+
// clear the connection string from the IConnectionDialogProfile so that the ugly connection string key
135+
// that's used to look up the actual connection string (with password) isn't displayed
136+
connection.connectionString = '';
124137
}
125138
}
126-
127139
}
140+
128141
const dialogConnection = connection as IConnectionDialogProfile;
129142
// Set the profile name
130143
dialogConnection.profileName = dialogConnection.profileName ?? getConnectionDisplayName(connection);

0 commit comments

Comments
 (0)