From dc5ab60df5cdcc30a6a3cd1941fdf8fd686d6d25 Mon Sep 17 00:00:00 2001
From: kisantia <31145923+kisantia@users.noreply.github.com>
Date: Wed, 3 Apr 2019 17:30:10 -0700
Subject: [PATCH] Fix invalid dacpac version crashing sqltoolsservice (#789)
* fix invalid dacpac version crashing sqltoolsservice
---
.../DacFx/Contracts/ExtractRequest.cs | 2 +-
.../DacFx/ExtractOperation.cs | 15 ++++++++++++-
.../Localization/sr.cs | 11 ++++++++++
.../Localization/sr.resx | 4 ++++
.../Localization/sr.strings | 6 +++++-
.../Localization/sr.xlf | 5 +++++
.../DacFx/DacFxserviceTests.cs | 10 +++++----
.../SchemaCompareServiceTests.cs | 2 +-
.../DacFx/DacFxTests.cs | 21 +++++++++++++++++++
9 files changed, 68 insertions(+), 8 deletions(-)
create mode 100644 test/Microsoft.SqlTools.ServiceLayer.UnitTests/DacFx/DacFxTests.cs
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ExtractRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ExtractRequest.cs
index 6f904d17..5eb3ef13 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ExtractRequest.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ExtractRequest.cs
@@ -22,7 +22,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
///
/// Gets or sets the version of the DAC application
///
- public Version ApplicationVersion { get; set; }
+ public string ApplicationVersion { get; set; }
}
///
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/ExtractOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/ExtractOperation.cs
index 4e4b6180..958bb5c9 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DacFx/ExtractOperation.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/ExtractOperation.cs
@@ -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;
}
}
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
index a7adb947..1c8b3006 100755
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
@@ -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()
{ }
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
index 2d48d7b1..7a9fe996 100755
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
@@ -1687,4 +1687,8 @@
For directory {0} a file with name {1} already exist
+
+ Invalid version '{0}' passed. Version must be in the format x.x.x.x where x is a number.
+
+
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
index 7931948a..5bf96de0 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
@@ -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
\ No newline at end of file
+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.
\ No newline at end of file
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
index 1076e99a..08ae2fed 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
+++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf
@@ -1956,6 +1956,11 @@
Batch parser wrapper execution: {0} found... at line {1}: {2} Description: {3}
+