Load connection from publish profile (#11263)

* initial changes for reading connection from profile

* connection string can now be read from publish.xml

* fix build errors and update test

* move publish profile tests to their own file

* cleanup

* update message

* fix string

* remove apiWrapper
This commit is contained in:
Kim Santiago
2020-07-15 17:03:25 -07:00
committed by GitHub
parent aae013d498
commit 0a1c2583cc
13 changed files with 247 additions and 69 deletions

View File

@@ -16,7 +16,8 @@ export let SSDTUpdatedProjectBaseline: string;
export let SSDTUpdatedProjectAfterSystemDbUpdateBaseline: string;
export let SSDTProjectBaselineWithCleanTarget: string;
export let SSDTProjectBaselineWithCleanTargetAfterUpdate: string;
export let publishProfileBaseline: string;
export let publishProfileIntegratedSecurityBaseline: string;
export let publishProfileSqlLoginBaseline: string;
const baselineFolderPath = __dirname;
@@ -30,7 +31,8 @@ export async function loadBaselines() {
SSDTUpdatedProjectAfterSystemDbUpdateBaseline = await loadBaseline(baselineFolderPath, 'SSDTUpdatedProjectAfterSystemDbUpdateBaseline.xml');
SSDTProjectBaselineWithCleanTarget = await loadBaseline(baselineFolderPath, 'SSDTProjectBaselineWithCleanTarget.xml');
SSDTProjectBaselineWithCleanTargetAfterUpdate = await loadBaseline(baselineFolderPath, 'SSDTProjectBaselineWithCleanTargetAfterUpdate.xml');
publishProfileBaseline = await loadBaseline(baselineFolderPath, 'publishProfileBaseline.publish.xml');
publishProfileIntegratedSecurityBaseline = await loadBaseline(baselineFolderPath, 'publishProfileIntegratedSecurityBaseline.publish.xml');
publishProfileSqlLoginBaseline = await loadBaseline(baselineFolderPath, 'publishProfileSqlLoginBaseline.publish.xml');
}
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {

View File

@@ -4,6 +4,7 @@
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>targetDb</TargetDatabaseName>
<DeployScriptFileName>DatabaseProject1.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=testserver;Integrated Security=true;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
<ItemGroup>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>targetDb</TargetDatabaseName>
<DeployScriptFileName>DatabaseProject1.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=testserver;User Id=testUser;Password=abcd123;Integrated Security=false;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
<ItemGroup>
<SqlCmdVariable Include="ProdDatabaseName">
<DefaultValue>MyProdDatabase</DefaultValue>
<Value>$(SqlCmdVar__1)</Value>
</SqlCmdVariable>
</ItemGroup>
</Project>

View File

@@ -267,10 +267,12 @@ describe ('ProjectsController', function(): void {
holler = publishHoller;
return Promise.resolve(undefined);
});
projController.setup(x => x.readPublishProfile(TypeMoq.It.isAny())).returns(() => {
projController.setup(x => x.readPublishProfileCallback(TypeMoq.It.isAny())).returns(() => {
holler = profileHoller;
return Promise.resolve({
databaseName: '',
connectionId: '',
connectionString: '',
sqlCmdVariables: {}
});
});
@@ -291,21 +293,11 @@ describe ('ProjectsController', function(): void {
should(holler).equal(generateHoller, 'executionCallback() is supposed to have been setup and called for GenerateScript scenario');
dialog = await projController.object.publishProject(proj);
await projController.object.readPublishProfile(vscode.Uri.parse('test'));
await projController.object.readPublishProfileCallback(vscode.Uri.parse('test'));
should(holler).equal(profileHoller, 'executionCallback() is supposed to have been setup and called for ReadPublishProfile scenario');
});
it('Should read database name and SQLCMD variables from publish profile', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileBaseline, 'publishProfile.publish.xml');
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
let result = await projController.readPublishProfile(vscode.Uri.file(profilePath));
should(result.databaseName).equal('targetDb');
should(Object.keys(result.sqlCmdVariables).length).equal(1);
should(result.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
});
it('Should copy dacpac to temp folder before publishing', async function (): Promise<void> {
const fakeDacpacContents = 'SwiftFlewHiawathasArrow';

View File

@@ -0,0 +1,80 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as should from 'should';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import * as sinon from 'sinon';
import * as baselines from './baselines/baselines';
import * as testUtils from './testUtils';
import * as constants from '../common/constants';
import { ProjectsController } from '../controllers/projectController';
import { SqlDatabaseProjectTreeViewProvider } from '../controllers/databaseProjectTreeViewProvider';
describe('Publish profile tests', function (): void {
before(async function (): Promise<void> {
await baselines.loadBaselines();
});
afterEach(function (): void {
sinon.restore();
});
it('Should read database name, integrated security connection string, and SQLCMD variables from publish profile', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
const connectionResult = {
connected: true,
connectionId: 'connId',
errorMessage: '',
errorCode: 0
};
const connectionString = 'Data Source=testserver;Integrated Security=true;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True';
sinon.stub(azdata.connection, 'connect').resolves(connectionResult);
sinon.stub(azdata.connection, 'getConnectionString').resolves(connectionString);
let result = await projController.readPublishProfileCallback(vscode.Uri.file(profilePath));
should(result.databaseName).equal('targetDb');
should(Object.keys(result.sqlCmdVariables).length).equal(1);
should(result.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
should(result.connectionId).equal('connId');
should(result.connectionString).equal('Data Source=testserver;Integrated Security=true;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True');
});
it('Should read database name, SQL login connection string, and SQLCMD variables from publish profile', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileSqlLoginBaseline, 'publishProfile.publish.xml');
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
const connectionResult = {
providerName: 'MSSQL',
connectionId: 'connId',
options: {}
};
const connectionString = 'Data Source=testserver;User Id=testUser;Password=******;Integrated Security=false;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True';
sinon.stub(azdata.connection, 'openConnectionDialog').resolves(connectionResult);
sinon.stub(azdata.connection, 'getConnectionString').resolves(connectionString);
let result = await projController.readPublishProfileCallback(vscode.Uri.file(profilePath));
should(result.databaseName).equal('targetDb');
should(Object.keys(result.sqlCmdVariables).length).equal(1);
should(result.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
should(result.connectionId).equal('connId');
should(result.connectionString).equal('Data Source=testserver;User Id=testUser;Password=******;Integrated Security=false;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True');
});
it('Should throw error when connecting does not work', async function (): Promise<void> {
await baselines.loadBaselines();
let profilePath = await testUtils.createTestFile(baselines.publishProfileIntegratedSecurityBaseline, 'publishProfile.publish.xml');
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
const connectionString = 'Data Source=testserver;Integrated Security=true;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True';
sinon.stub(azdata.connection, 'connect').throws(new Error('Could not connect'));
sinon.stub(azdata.connection, 'getConnectionString').resolves(connectionString);
await testUtils.shouldThrowSpecificError(async () => await projController.readPublishProfileCallback(vscode.Uri.file(profilePath)), constants.unableToCreatePublishConnection('Could not connect'));
});
});