Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Samples/PowerShell/ExecuteSampleSplitMerge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
.EXAMPLES
.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Int32' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'

.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Int64' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'

.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Guid' `
-SplitRangeLow '00000000-0000-0000-0000-000000000000' `
Expand All @@ -43,7 +43,7 @@

.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Binary' `
-SplitRangeLow '0x00' `
Expand All @@ -54,7 +54,7 @@

.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Datetime' `
-SplitRangeLow '2010-3-21 12:00:00' `
Expand Down
2 changes: 1 addition & 1 deletion Samples/PowerShell/GetMappings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.EXAMPLES
.\GetMappings.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardMapManagerDatabaseName 'MyShardMapManagerDB'
-ShardMapName 'CustomerIdShardMap'
Expand Down
2 changes: 1 addition & 1 deletion Samples/PowerShell/GetShards.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.EXAMPLES
.\GetShards.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardMapManagerDatabaseName 'MyShardMapManagerDB'
-ShardMapName 'CustomerIdShardMap'
Expand Down
10 changes: 5 additions & 5 deletions Samples/PowerShell/SetupSampleSplitMergeEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
.EXAMPLES
.\SetupSampleSplitMergeEnvironment.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Int32'

.\SetupSampleSplitMergeEnvironment.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Int64'

.\SetupSampleSplitMergeEnvironment.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Guid' `
-SplitRangeLow '00000000-0000-0000-0000-000000000000' `
Expand All @@ -37,7 +37,7 @@

.\SetupSampleSplitMergeEnvironment.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Binary' `
-SplitRangeLow '0x00' `
Expand All @@ -46,7 +46,7 @@

.\SetupSampleSplitMergeEnvironment.ps1 `
-UserName 'mysqluser' `
-Password 'MySqlPassw0rd' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Datetime' `
-SplitRangeLow '2010-3-21 12:00:00' `
Expand Down
66 changes: 65 additions & 1 deletion Test/ElasticScale.ClientTestCommon/CommonTestUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Microsoft.Azure.SqlDatabase.ElasticScale.Test.Common
Expand All @@ -10,13 +14,73 @@ public static T SerializeDeserialize<T>(T originalException) where T : Exception
{
using (MemoryStream memStream = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
BinaryFormatter formatter = new BinaryFormatter
{
// Restrict deserialization to the exception graph these tests round-trip.
// This satisfies CA2301 and prevents BinaryFormatter from instantiating
// arbitrary (potentially dangerous) types.
Binder = new ExceptionRoundTripBinder(),
};

formatter.Serialize(memStream, originalException);
memStream.Seek(0, SeekOrigin.Begin);

return (T)formatter.Deserialize(memStream);
}
}

/// <summary>
/// A <see cref="SerializationBinder"/> that only permits the types that make up the
/// serialized graph of the Elastic Scale exceptions exercised by the tests: the
/// Elastic Scale types themselves (exceptions, <c>ShardLocation</c>, error-code enums),
/// <see cref="Exception"/>, and lists/collections/arrays of those types. Any other type
/// is rejected before it can be instantiated.
/// </summary>
private sealed class ExceptionRoundTripBinder : SerializationBinder
{
private const string ElasticScaleNamespacePrefix = "Microsoft.Azure.SqlDatabase.ElasticScale";

public override Type BindToType(string assemblyName, string typeName)
{
// Resolving a Type does not instantiate anything; the object is only created
// by the formatter after we return an allowed type. Reject disallowed types up front.
Type type = Type.GetType(string.Format("{0}, {1}", typeName, assemblyName), throwOnError: false);

if (type == null || !IsAllowed(type))
{
throw new SerializationException(
string.Format("Type '{0}' from assembly '{1}' is not allowed to be deserialized.", typeName, assemblyName));
}

return type;
}

private static bool IsAllowed(Type type)
{
if (type.IsArray)
{
return IsAllowed(type.GetElementType());
}

if (type.IsGenericType)
{
Type definition = type.GetGenericTypeDefinition();
if (definition != typeof(List<>) && definition != typeof(ReadOnlyCollection<>))
{
return false;
}

return type.GetGenericArguments().All(IsAllowed);
}

return type.IsPrimitive
|| type == typeof(string)
|| type == typeof(Exception)
|| IsElasticScaleType(type);
}

private static bool IsElasticScaleType(Type type) =>
type.Namespace != null && type.Namespace.StartsWith(ElasticScaleNamespacePrefix, StringComparison.Ordinal);
}
}
}
7 changes: 1 addition & 6 deletions Test/ElasticScale.Query.UnitTests/MultiShardTestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ internal static class MultiShardTestUtils
/// </summary>
private static string s_testUserId = "TestUser";

/// <summary>
/// User password to use when connecting to shards during a fanout query.
/// </summary>
private static string s_testPassword = "J8X2ndQTZ8cvu1r";

/// <summary>
/// Table name for the sharded table we will issue fanout queries against.
/// </summary>
Expand Down Expand Up @@ -326,7 +321,7 @@ private static void AddDropAndReCreateTestUserCommandsToList(List<string> output

// Then re create it.
//
output.Add(string.Format("CREATE LOGIN {0} WITH Password = '{1}';", s_testUserId, s_testPassword));
output.Add(string.Format("CREATE LOGIN {0} WITH Password = '{1}';", s_testUserId, Guid.NewGuid().ToString()));

// Then grant it lots of permissions.
//
Expand Down
5 changes: 3 additions & 2 deletions Test/ElasticScale.ShardManagement.UnitTests/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ internal static class Globals
internal static string SqlLoginTestUser = "ElasticDatabaseToolsTestUser_" + System.Environment.CurrentManagedThreadId;

/// <summary>
/// Password for test user. (with ' and ; replaced with _ to enable test code to work without T/SQL and connection string escaping)
/// Password for test user. Randomly generated per run so no credential is hard-coded in source. A GUID
/// contains no quote/semicolon and satisfies SQL Server password complexity (lowercase, digits, hyphens).
/// </summary>
internal static readonly string SqlLoginTestPassword = "TestPa$$w0rd" + Guid.NewGuid().ToString("N");
internal static readonly string SqlLoginTestPassword = Guid.NewGuid().ToString();

/// <summary>
/// SMM connection string.
Expand Down