mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
Connection management service updates to support multiple providers (#9698)
* Connection management service work * Fix tests * Change how accounts are deleted * Be consistent with names * feedback * Fix based on feedback * Change sqltoolsservice version
This commit is contained in:
@@ -780,9 +780,9 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
||||
return true;
|
||||
}
|
||||
let azureResource = this.getAzureResourceForConnection(connection);
|
||||
let accounts = await this._accountManagementService.getAccountsForProvider('azurePublicCloud');
|
||||
let accounts = (await this._accountManagementService.getAccounts()).filter(a => a.key.providerId.startsWith('azure'));
|
||||
if (accounts && accounts.length > 0) {
|
||||
let accountName = (connection.authenticationType !== Constants.azureMFA) ? connection.azureAccount : connection.userName;
|
||||
let accountName = (connection.authenticationType === Constants.azureMFA) ? connection.azureAccount : connection.userName;
|
||||
let account = find(accounts, account => account.key.accountId === accountName);
|
||||
if (account) {
|
||||
if (account.isStale) {
|
||||
|
||||
@@ -56,7 +56,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
||||
private _azureTenantDropdown: SelectBox;
|
||||
private _refreshCredentialsLink: HTMLLinkElement;
|
||||
private _addAzureAccountMessage: string = localize('connectionWidget.AddAzureAccount', "Add an account...");
|
||||
private readonly _azureProviderId = 'azurePublicCloud';
|
||||
private readonly _azureProviderId = 'azure_publicCloud';
|
||||
private _azureTenantId: string;
|
||||
private _azureAccountList: azdata.Account[];
|
||||
private _callbacks: IConnectionComponentCallbacks;
|
||||
@@ -518,7 +518,8 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
||||
|
||||
private async fillInAzureAccountOptions(): Promise<void> {
|
||||
let oldSelection = this._azureAccountDropdown.value;
|
||||
this._azureAccountList = await this._accountManagementService.getAccountsForProvider(this._azureProviderId);
|
||||
const accounts = await this._accountManagementService.getAccounts();
|
||||
this._azureAccountList = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
||||
let accountDropdownOptions = this._azureAccountList.map(account => account.key.accountId);
|
||||
if (accountDropdownOptions.length === 0) {
|
||||
// If there are no accounts add a blank option so that add account isn't automatically selected
|
||||
@@ -821,7 +822,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
||||
}
|
||||
|
||||
public get azureAccount(): string {
|
||||
return this.authenticationType === AuthenticationType.AzureMFAAndUser ? this._azureAccountDropdown.value : undefined;
|
||||
return this.authenticationType === AuthenticationType.AzureMFAAndUser || this.authenticationType === AuthenticationType.AzureMFA ? this._azureAccountDropdown.value : undefined;
|
||||
}
|
||||
|
||||
private validateAzureAccountSelection(showMessage: boolean = true): boolean {
|
||||
|
||||
@@ -796,9 +796,10 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
let azureConnectionProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, connectionProfile);
|
||||
azureConnectionProfile.authenticationType = 'AzureMFA';
|
||||
let username = 'testuser@microsoft.com';
|
||||
azureConnectionProfile.userName = username;
|
||||
azureConnectionProfile.azureAccount = username;
|
||||
let servername = 'test-database.database.windows.net';
|
||||
azureConnectionProfile.serverName = servername;
|
||||
let providerId = 'azure_PublicCloud';
|
||||
|
||||
// Set up the account management service to return a token for the given user
|
||||
accountManagementService.setup(x => x.getAccountsForProvider(TypeMoq.It.isAny())).returns(providerId => Promise.resolve<azdata.Account[]>([
|
||||
@@ -812,9 +813,23 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
properties: undefined
|
||||
}
|
||||
]));
|
||||
|
||||
accountManagementService.setup(x => x.getAccounts()).returns(() => {
|
||||
return Promise.resolve<azdata.Account[]>([
|
||||
{
|
||||
key: {
|
||||
accountId: username,
|
||||
providerId: providerId
|
||||
},
|
||||
displayInfo: undefined,
|
||||
isStale: false,
|
||||
properties: undefined
|
||||
}
|
||||
]);
|
||||
});
|
||||
let testToken = 'testToken';
|
||||
accountManagementService.setup(x => x.getSecurityToken(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({
|
||||
azurePublicCloud: {
|
||||
azure_publicCloud: {
|
||||
token: testToken
|
||||
}
|
||||
}));
|
||||
@@ -827,7 +842,7 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
let profileWithCredentials = await connectionManagementService.addSavedPassword(azureConnectionProfile);
|
||||
|
||||
// Then the returned profile has the account token set
|
||||
assert.equal(profileWithCredentials.userName, username);
|
||||
assert.equal(profileWithCredentials.userName, azureConnectionProfile.userName);
|
||||
assert.equal(profileWithCredentials.options['azureAccountToken'], testToken);
|
||||
});
|
||||
|
||||
@@ -836,11 +851,12 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
let azureConnectionProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, connectionProfile);
|
||||
azureConnectionProfile.authenticationType = 'AzureMFA';
|
||||
let username = 'testuser@microsoft.com';
|
||||
azureConnectionProfile.userName = username;
|
||||
azureConnectionProfile.azureAccount = username;
|
||||
let servername = 'test-database.database.windows.net';
|
||||
azureConnectionProfile.serverName = servername;
|
||||
let azureTenantId = 'testTenant';
|
||||
azureConnectionProfile.azureTenantId = azureTenantId;
|
||||
let providerId = 'azure_PublicCloud';
|
||||
|
||||
// Set up the account management service to return a token for the given user
|
||||
accountManagementService.setup(x => x.getAccountsForProvider(TypeMoq.It.isAny())).returns(providerId => Promise.resolve<azdata.Account[]>([
|
||||
@@ -854,9 +870,24 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
properties: undefined
|
||||
}
|
||||
]));
|
||||
|
||||
accountManagementService.setup(x => x.getAccounts()).returns(() => {
|
||||
return Promise.resolve<azdata.Account[]>([
|
||||
{
|
||||
key: {
|
||||
accountId: username,
|
||||
providerId,
|
||||
},
|
||||
displayInfo: undefined,
|
||||
isStale: false,
|
||||
properties: undefined
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
let testToken = 'testToken';
|
||||
let returnedTokens = {};
|
||||
returnedTokens['azurePublicCloud'] = { token: 'badToken' };
|
||||
returnedTokens['azure_publicCloud'] = { token: 'badToken' };
|
||||
returnedTokens[azureTenantId] = { token: testToken };
|
||||
accountManagementService.setup(x => x.getSecurityToken(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(returnedTokens));
|
||||
connectionStore.setup(x => x.addSavedPassword(TypeMoq.It.is(profile => profile.authenticationType === 'AzureMFA'))).returns(profile => Promise.resolve({
|
||||
@@ -868,7 +899,7 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
let profileWithCredentials = await connectionManagementService.addSavedPassword(azureConnectionProfile);
|
||||
|
||||
// Then the returned profile has the account token set corresponding to the requested tenant
|
||||
assert.equal(profileWithCredentials.userName, username);
|
||||
assert.equal(profileWithCredentials.userName, azureConnectionProfile.userName);
|
||||
assert.equal(profileWithCredentials.options['azureAccountToken'], testToken);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user