mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Introduce connection API (#598)
Including getCurrentConnection, getActiveConnections, and getCredentials
This commit is contained in:
@@ -790,4 +790,14 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
}
|
||||
}, err => done(err));
|
||||
});
|
||||
|
||||
test('getActiveConnectionCredentials returns the credentials dictionary for a connection profile', () => {
|
||||
let profile = Object.assign({}, connectionProfile);
|
||||
profile.options = {password: profile.password};
|
||||
profile.id = 'test_id';
|
||||
connectionStatusManager.addConnection(profile, 'test_uri');
|
||||
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||
let credentials = connectionManagementService.getActiveConnectionCredentials(profile.id);
|
||||
assert.equal(credentials['password'], profile.options['password']);
|
||||
});
|
||||
});
|
||||
@@ -236,4 +236,19 @@ suite('SQL ConnectionStatusManager tests', () => {
|
||||
let connectionStatus = connections.getOriginalOwnerUri(connection2Id);
|
||||
assert.equal(connectionStatus, connection2Id);
|
||||
});
|
||||
|
||||
test('getActiveConnectionProfiles should return a list of all the unique connections that the status manager knows about', () => {
|
||||
// Add duplicate connections
|
||||
let newConnection = Object.assign({}, connectionProfile);
|
||||
newConnection.id = 'test_id';
|
||||
newConnection.serverName = 'new_server_name';
|
||||
newConnection.options['databaseDisplayName'] = newConnection.databaseName;
|
||||
connections.addConnection(newConnection, 'test_uri_1');
|
||||
connections.addConnection(newConnection, 'test_uri_2');
|
||||
|
||||
// Get the connections and verify that the duplicate is only returned once
|
||||
let activeConnections = connections.getActiveConnectionProfiles();
|
||||
assert.equal(activeConnections.length, 4);
|
||||
assert.equal(activeConnections.filter(connection => connection.matches(newConnection)).length, 1, 'Did not find newConnection in active connections');
|
||||
});
|
||||
});
|
||||
@@ -492,4 +492,18 @@ suite('SQL ConnectionStore tests', () => {
|
||||
actualGroup = connectionStore.getGroupFromId(childGroupId);
|
||||
assert.equal(actualGroup.id, childGroupId, 'Did not get the child group when looking it up with its ID');
|
||||
});
|
||||
|
||||
test('getProfileWithoutPassword can return the profile without credentials in the password property or options dictionary', () => {
|
||||
let connectionStore = new ConnectionStore(storageServiceMock.object, context.object, undefined, workspaceConfigurationServiceMock.object,
|
||||
credentialStore.object, capabilitiesService.object, connectionConfig.object);
|
||||
let profile = Object.assign({}, defaultNamedProfile);
|
||||
profile.options['password'] = profile.password;
|
||||
profile.id = 'testId';
|
||||
let expectedProfile = Object.assign({}, profile);
|
||||
expectedProfile.password = '';
|
||||
expectedProfile.options['password'] = '';
|
||||
expectedProfile = ConnectionProfile.convertToConnectionProfile(msSQLCapabilities, expectedProfile).toIConnectionProfile();
|
||||
let profileWithoutCredentials = connectionStore.getProfileWithoutPassword(profile);
|
||||
assert.deepEqual(profileWithoutCredentials.toIConnectionProfile(), expectedProfile);
|
||||
});
|
||||
});
|
||||
@@ -241,4 +241,12 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
||||
getTabColorForUri(uri: string): string {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
removeConnectionProfileCredentials(profile: IConnectionProfile): IConnectionProfile {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getActiveConnectionCredentials(profileId: string): { [name: string]: string } {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user