Fix invalid dacpac version crashing sqltoolsservice (#789)

* fix invalid dacpac version crashing sqltoolsservice
This commit is contained in:
kisantia
2019-04-03 17:30:10 -07:00
committed by GitHub
parent 49cecaf72a
commit dc5ab60df5
9 changed files with 68 additions and 8 deletions

View File

@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
/// <summary>
/// Gets or sets the version of the DAC application
/// </summary>
public Version ApplicationVersion { get; set; }
public string ApplicationVersion { get; set; }
}
/// <summary>

View File

@@ -10,6 +10,7 @@ using Microsoft.SqlTools.Utility;
using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
namespace Microsoft.SqlTools.ServiceLayer.DacFx
{
@@ -28,7 +29,19 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
public override void Execute()
{
this.DacServices.Extract(this.Parameters.PackageFilePath, this.Parameters.DatabaseName, this.Parameters.ApplicationName, this.Parameters.ApplicationVersion, null, null, null, this.CancellationToken);
Version version = ParseVersion(this.Parameters.ApplicationVersion);
this.DacServices.Extract(this.Parameters.PackageFilePath, this.Parameters.DatabaseName, this.Parameters.ApplicationName, version, null, null, null, this.CancellationToken);
}
public static Version ParseVersion(string incomingVersion)
{
Version parsedVersion;
if (!Version.TryParse(incomingVersion, out parsedVersion))
{
throw new ArgumentException(string.Format(SR.ExtractInvalidVersion, incomingVersion));
}
return parsedVersion;
}
}
}

View File

@@ -2869,6 +2869,14 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
public static string ExtractInvalidVersion
{
get
{
return Keys.GetString(Keys.ExtractInvalidVersion);
}
}
public static string ConnectionServiceListDbErrorNotConnected(string uri)
{
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri);
@@ -4182,6 +4190,9 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string Error_ExistingDirectoryName = "Error_ExistingDirectoryName";
public const string ExtractInvalidVersion = "ExtractInvalidVersion";
private Keys()
{ }

View File

@@ -1687,4 +1687,8 @@
<value>For directory {0} a file with name {1} already exist</value>
<comment></comment>
</data>
<data name="ExtractInvalidVersion" xml:space="preserve">
<value>Invalid version '{0}' passed. Version must be in the format x.x.x.x where x is a number.</value>
<comment></comment>
</data>
</root>

View File

@@ -782,4 +782,8 @@ JobServerIsNotAvailable = Job server is not available
NeverBackedUp = Never
Error_InvalidDirectoryName = Path {0} is not a valid directory
Error_ExistingDirectoryName = For directory {0} a file with name {1} already exist
Error_ExistingDirectoryName = For directory {0} a file with name {1} already exist
############################################################################
# DacFx
ExtractInvalidVersion = Invalid version '{0}' passed. Version must be in the format x.x.x.x where x is a number.

View File

@@ -1956,6 +1956,11 @@
<target state="new">Batch parser wrapper execution: {0} found... at line {1}: {2} Description: {3}</target>
<note></note>
</trans-unit>
<trans-unit id="ExtractInvalidVersion">
<source>Invalid version '{0}' passed. Version must be in the format x.x.x.x where x is a number.</source>
<target state="new">Invalid version '{0}' passed. Version must be in the format x.x.x.x where x is a number.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>

View File

@@ -132,7 +132,7 @@ CREATE TABLE [dbo].[table3]
DatabaseName = testdb.DatabaseName,
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", testdb.DatabaseName)),
ApplicationName = "test",
ApplicationVersion = new Version(1, 0)
ApplicationVersion = "1.0.0.0"
};
DacFxService service = new DacFxService();
@@ -162,7 +162,7 @@ CREATE TABLE [dbo].[table3]
DatabaseName = sourceDb.DatabaseName,
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
ApplicationName = "test",
ApplicationVersion = new Version(1, 0)
ApplicationVersion = "1.0.0.0"
};
DacFxService service = new DacFxService();
@@ -233,6 +233,8 @@ CREATE TABLE [dbo].[table3]
return requestContext;
}
private async Task<Mock<RequestContext<DacFxResult>>> SendAndValidateGenerateDeployScriptRequest()
{
// first extract a dacpac
@@ -249,7 +251,7 @@ CREATE TABLE [dbo].[table3]
DatabaseName = sourceDb.DatabaseName,
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
ApplicationName = "test",
ApplicationVersion = new Version(1, 0)
ApplicationVersion = "1.0.0.0"
};
DacFxService service = new DacFxService();
@@ -295,7 +297,7 @@ CREATE TABLE [dbo].[table3]
DatabaseName = sourceDb.DatabaseName,
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
ApplicationName = "test",
ApplicationVersion = new Version(1, 0)
ApplicationVersion = "1.0.0.0"
};
ExtractOperation extractOperation = new ExtractOperation(extractParams, result.ConnectionInfo);

View File

@@ -369,7 +369,7 @@ CREATE TABLE [dbo].[table3]
DatabaseName = testdb.DatabaseName,
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", testdb.DatabaseName)),
ApplicationName = "test",
ApplicationVersion = new Version(1, 0)
ApplicationVersion = "1.0.0.0"
};
DacFxService service = new DacFxService();

View File

@@ -0,0 +1,21 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.ServiceLayer.DacFx;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.DacFx
{
public class DacFxTests
{
[Fact]
public void ExtractParseVersionShouldThrowExceptionGivenInvalidVersion()
{
string invalidVersion = "invalidVerison";
Assert.Throws<ArgumentException>(() => ExtractOperation.ParseVersion(invalidVersion));
}
}
}