mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Fix invalid dacpac version crashing sqltoolsservice (#789)
* fix invalid dacpac version crashing sqltoolsservice
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the version of the DAC application
|
/// Gets or sets the version of the DAC application
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Version ApplicationVersion { get; set; }
|
public string ApplicationVersion { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Microsoft.SqlTools.Utility;
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||||
{
|
{
|
||||||
@@ -28,7 +29,19 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
|||||||
|
|
||||||
public override void Execute()
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2869,6 +2869,14 @@ namespace Microsoft.SqlTools.ServiceLayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ExtractInvalidVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Keys.GetString(Keys.ExtractInvalidVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string ConnectionServiceListDbErrorNotConnected(string uri)
|
public static string ConnectionServiceListDbErrorNotConnected(string uri)
|
||||||
{
|
{
|
||||||
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, 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 Error_ExistingDirectoryName = "Error_ExistingDirectoryName";
|
||||||
|
|
||||||
|
|
||||||
|
public const string ExtractInvalidVersion = "ExtractInvalidVersion";
|
||||||
|
|
||||||
|
|
||||||
private Keys()
|
private Keys()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -1687,4 +1687,8 @@
|
|||||||
<value>For directory {0} a file with name {1} already exist</value>
|
<value>For directory {0} a file with name {1} already exist</value>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
</data>
|
</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>
|
</root>
|
||||||
|
|||||||
@@ -783,3 +783,7 @@ JobServerIsNotAvailable = Job server is not available
|
|||||||
NeverBackedUp = Never
|
NeverBackedUp = Never
|
||||||
Error_InvalidDirectoryName = Path {0} is not a valid directory
|
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.
|
||||||
@@ -1956,6 +1956,11 @@
|
|||||||
<target state="new">Batch parser wrapper execution: {0} found... at line {1}: {2} Description: {3}</target>
|
<target state="new">Batch parser wrapper execution: {0} found... at line {1}: {2} Description: {3}</target>
|
||||||
<note></note>
|
<note></note>
|
||||||
</trans-unit>
|
</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>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
@@ -132,7 +132,7 @@ CREATE TABLE [dbo].[table3]
|
|||||||
DatabaseName = testdb.DatabaseName,
|
DatabaseName = testdb.DatabaseName,
|
||||||
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", testdb.DatabaseName)),
|
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", testdb.DatabaseName)),
|
||||||
ApplicationName = "test",
|
ApplicationName = "test",
|
||||||
ApplicationVersion = new Version(1, 0)
|
ApplicationVersion = "1.0.0.0"
|
||||||
};
|
};
|
||||||
|
|
||||||
DacFxService service = new DacFxService();
|
DacFxService service = new DacFxService();
|
||||||
@@ -162,7 +162,7 @@ CREATE TABLE [dbo].[table3]
|
|||||||
DatabaseName = sourceDb.DatabaseName,
|
DatabaseName = sourceDb.DatabaseName,
|
||||||
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
|
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
|
||||||
ApplicationName = "test",
|
ApplicationName = "test",
|
||||||
ApplicationVersion = new Version(1, 0)
|
ApplicationVersion = "1.0.0.0"
|
||||||
};
|
};
|
||||||
|
|
||||||
DacFxService service = new DacFxService();
|
DacFxService service = new DacFxService();
|
||||||
@@ -233,6 +233,8 @@ CREATE TABLE [dbo].[table3]
|
|||||||
return requestContext;
|
return requestContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async Task<Mock<RequestContext<DacFxResult>>> SendAndValidateGenerateDeployScriptRequest()
|
private async Task<Mock<RequestContext<DacFxResult>>> SendAndValidateGenerateDeployScriptRequest()
|
||||||
{
|
{
|
||||||
// first extract a dacpac
|
// first extract a dacpac
|
||||||
@@ -249,7 +251,7 @@ CREATE TABLE [dbo].[table3]
|
|||||||
DatabaseName = sourceDb.DatabaseName,
|
DatabaseName = sourceDb.DatabaseName,
|
||||||
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
|
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
|
||||||
ApplicationName = "test",
|
ApplicationName = "test",
|
||||||
ApplicationVersion = new Version(1, 0)
|
ApplicationVersion = "1.0.0.0"
|
||||||
};
|
};
|
||||||
|
|
||||||
DacFxService service = new DacFxService();
|
DacFxService service = new DacFxService();
|
||||||
@@ -295,7 +297,7 @@ CREATE TABLE [dbo].[table3]
|
|||||||
DatabaseName = sourceDb.DatabaseName,
|
DatabaseName = sourceDb.DatabaseName,
|
||||||
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
|
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", sourceDb.DatabaseName)),
|
||||||
ApplicationName = "test",
|
ApplicationName = "test",
|
||||||
ApplicationVersion = new Version(1, 0)
|
ApplicationVersion = "1.0.0.0"
|
||||||
};
|
};
|
||||||
|
|
||||||
ExtractOperation extractOperation = new ExtractOperation(extractParams, result.ConnectionInfo);
|
ExtractOperation extractOperation = new ExtractOperation(extractParams, result.ConnectionInfo);
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ CREATE TABLE [dbo].[table3]
|
|||||||
DatabaseName = testdb.DatabaseName,
|
DatabaseName = testdb.DatabaseName,
|
||||||
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", testdb.DatabaseName)),
|
PackageFilePath = Path.Combine(folderPath, string.Format("{0}.dacpac", testdb.DatabaseName)),
|
||||||
ApplicationName = "test",
|
ApplicationName = "test",
|
||||||
ApplicationVersion = new Version(1, 0)
|
ApplicationVersion = "1.0.0.0"
|
||||||
};
|
};
|
||||||
|
|
||||||
DacFxService service = new DacFxService();
|
DacFxService service = new DacFxService();
|
||||||
|
|||||||
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user