Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server v12 support to sql auth. #38

Merged
merged 7 commits into from
Dec 8, 2014
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.Services.Client" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -132,6 +133,18 @@
<Compile Include="UnitTests\Database\Cmdlet\NewAzureSqlPremiumDatabaseTests.cs" />
<Compile Include="UnitTests\Database\Cmdlet\AzureSqlDatabaseCopyCertAuthTests.cs" />
<Compile Include="UnitTests\Database\Cmdlet\RestoreDatabaseTests.cs" />
<Compile Include="UnitTests\Database\Cmdlet\SqlAuthv12MockTests.cs" />
<Compile Include="UnitTests\TSql\MockQueryResult.cs" />
<Compile Include="UnitTests\TSql\MockSettings.cs" />
<Compile Include="UnitTests\TSql\MockSqlCommand.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UnitTests\TSql\MockSqlConnection.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UnitTests\TSql\MockSqlParameter.cs" />
<Compile Include="UnitTests\TSql\MockSqlParameterCollection.cs" />
<Compile Include="UnitTests\TSql\RecordMockDataResultsAttribute.cs" />
<Compile Include="Utilities\SqlCustomPsHostUserInterface.cs" />
<Compile Include="Utilities\SqlDatabaseSettings.cs" />
<Compile Include="UnitTests\MockServer\AsyncExceptionManager.cs" />
Expand Down Expand Up @@ -221,6 +234,9 @@
<SubType>Designer</SubType>
</Content>
<None Include="TestScripts\Database\DeleteDatabase-ScenarioFunctions.ps1" />
<Content Include="Resources\TSqlMockSessions\SqlAuthv12MockTests.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestScripts\Database\ExpectedFormat.txt" />
<Content Include="TestScripts\Server\ExpectedFormat.txt" />
</ItemGroup>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public static class DatabaseTestHelper
/// </summary>
public static readonly Guid StandardS1SloGuid = new Guid("1b1ebd4d-d903-4baa-97f9-4ea675f5e928");

/// <summary>
/// The unique GUID for identifying the Standard S0 SLO.
/// </summary>
public static readonly Guid StandardS0SloGuid = new Guid("f1173c43-91bd-4aaa-973c-54e79e15235b");

/// <summary>
/// The unique GUID for identifying the Premium P1 SLO.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Microsoft.WindowsAzure.Commands.SqlDatabase.Test.Utilities;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server;

namespace Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.Database.Cmdlet
{
Expand Down Expand Up @@ -112,6 +113,10 @@ public void ImportExportAzureSqlDatabaseTests()
@" -StorageAccountKey $storageAccountKey");
}).FirstOrDefault();

// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
//
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;

//testSession.ServiceBaseUri = new Uri("https://lqtqbo6kkp.database.windows.net");
Collection<PSObject> databaseContext = MockServerHelper.ExecuteWithMock(
testSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public void NewAzureSqlDatabaseServerContextWithSqlAuth()
UnitTestHelper.ImportAzureModule(powershell);
UnitTestHelper.CreateTestCredential(powershell);

// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
//
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
{
Collection<PSObject> serverContext;
Expand Down Expand Up @@ -190,6 +193,10 @@ public void NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases()

using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
{
// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
//
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;

// Test warning when different $metadata is received.
Collection<PSObject> serverContext;
using (new MockHttpServer(
Expand All @@ -212,6 +219,10 @@ public void NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases()
Assert.AreEqual(2, powershell.Streams.Warning.Count, "Should have warning!");
powershell.Streams.ClearStreams();

// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
//
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;

// Test error case
using (new MockHttpServer(
exceptionManager,
Expand Down Expand Up @@ -308,6 +319,10 @@ public static void CreateServerContextSqlAuth(
testSession.SessionProperties["Username"],
testSession.SessionProperties["Password"]);

// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
//
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;

Collection<PSObject> serverContext;
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
{
Expand Down Expand Up @@ -339,5 +354,50 @@ public static void CreateServerContextSqlAuth(
contextPsObject.BaseObject is ServerDataServiceSqlAuth,
"Expecting a ServerDataServiceSqlAuth object");
}

/// <summary>
/// Common helper method for other tests to create a context for ESA server.
/// </summary>
/// <param name="contextVariable">The variable name that will hold the new context.</param>
public static void CreateServerContextSqlAuthV12(
System.Management.Automation.PowerShell powershell,
string manageUrl,
string username,
string password,
string contextVariable)
{
UnitTestHelper.ImportAzureModule(powershell);
UnitTestHelper.CreateTestCredential(
powershell,
username,
password);

// Tell the sql auth factory to create a v22 context (skip checking sql version using select query).
//
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v12;

Collection<PSObject> serverContext;
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
{
serverContext = powershell.InvokeBatchScript(
string.Format(
CultureInfo.InvariantCulture,
@"{1} = New-AzureSqlDatabaseServerContext " +
@"-ManageUrl {0} " +
@"-Credential $credential ",
manageUrl,
contextVariable),
contextVariable);
}

Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
powershell.Streams.ClearStreams();

PSObject contextPsObject = serverContext.Single();
Assert.IsTrue(
contextPsObject.BaseObject is TSqlConnectionContext,
"Expecting a TSqlConnectionContext object");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void CreatePremiumDatabasesWithSqlAuth()
"$context");
HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
"UnitTest.Common.CreatePremiumDatabasesWithSqlAuth");
DatabaseTestHelper.SetDefaultTestSessionSettings(testSession);
DatabaseTestHelper.SetDefaultTestSessionSettings(testSession);
testSession.RequestValidator =
new Action<HttpMessage, HttpMessage.Request>(
(expected, actual) =>
Expand All @@ -57,69 +57,79 @@ public void CreatePremiumDatabasesWithSqlAuth()
Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent);
});

using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
TestCreatePremiumDatabase(powershell, testSession);
}
}

/// <summary>
/// Helper function to create premium database in the powershell environment provided.
/// </summary>
/// <param name="powershell">The powershell environment</param>
/// <param name="testSession">The test session</param>
private static void TestCreatePremiumDatabase(System.Management.Automation.PowerShell powershell, HttpSession testSession)
{
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
{
Collection<PSObject> premiumDB_P1, PremiumDB_P2;
using (new MockHttpServer(
exceptionManager,
MockHttpServer.DefaultServerPrefixUri,
testSession))
{
Collection<PSObject> premiumDB_P1, PremiumDB_P2;
using (new MockHttpServer(
exceptionManager,
MockHttpServer.DefaultServerPrefixUri,
testSession))
{
powershell.InvokeBatchScript(
@"$P1 = Get-AzureSqlDatabaseServiceObjective" +
@" -Context $context" +
@" -ServiceObjectiveName ""P1""");

powershell.InvokeBatchScript(
@"$P2 = Get-AzureSqlDatabaseServiceObjective " +
@"-Context $context" +
@" -ServiceObjectiveName ""P2""");

premiumDB_P1 = powershell.InvokeBatchScript(
@"$premiumDB_P1 = New-AzureSqlDatabase " +
@"-Context $context " +
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " +
@"-Edition Premium " +
@"-ServiceObjective $P1 ");
premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1");

powershell.InvokeBatchScript(
@"$PremiumDB_P2 = New-AzureSqlDatabase " +
@"-Context $context " +
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " +
@"-Collation Japanese_CI_AS " +
@"-Edition Premium " +
@"-ServiceObjective $P2 " +
@"-MaxSizeGB 10 " +
@"-Force");
PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2");
}
powershell.InvokeBatchScript(
@"$P1 = Get-AzureSqlDatabaseServiceObjective" +
@" -Context $context" +
@" -ServiceObjectiveName ""P1""");

Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
powershell.Streams.ClearStreams();

Assert.IsTrue(
premiumDB_P1.Single().BaseObject is Services.Server.Database,
"Expecting a Database object");
Services.Server.Database databaseP1 =
(Services.Server.Database)premiumDB_P1.Single().BaseObject;
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1");

Assert.IsTrue(
PremiumDB_P2.Single().BaseObject is Services.Server.Database,
"Expecting a Database object");
Services.Server.Database databaseP2 =
(Services.Server.Database)PremiumDB_P2.Single().BaseObject;
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2");

Assert.AreEqual(
"Japanese_CI_AS",
databaseP2.CollationName,
"Expected collation to be Japanese_CI_AS");
Assert.AreEqual("Premium", databaseP2.Edition, "Expected edition to be Premium");
Assert.AreEqual(10, databaseP2.MaxSizeGB, "Expected max size to be 10 GB");
powershell.InvokeBatchScript(
@"$P2 = Get-AzureSqlDatabaseServiceObjective " +
@"-Context $context" +
@" -ServiceObjectiveName ""P2""");

premiumDB_P1 = powershell.InvokeBatchScript(
@"$premiumDB_P1 = New-AzureSqlDatabase " +
@"-Context $context " +
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " +
@"-Edition Premium " +
@"-ServiceObjective $P1 ");
premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1");

powershell.InvokeBatchScript(
@"$PremiumDB_P2 = New-AzureSqlDatabase " +
@"-Context $context " +
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " +
@"-Collation Japanese_CI_AS " +
@"-Edition Premium " +
@"-ServiceObjective $P2 " +
@"-MaxSizeGB 10 " +
@"-Force");
PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2");
}

Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
powershell.Streams.ClearStreams();

Assert.IsTrue(
premiumDB_P1.Single().BaseObject is Services.Server.Database,
"Expecting a Database object");
Services.Server.Database databaseP1 =
(Services.Server.Database)premiumDB_P1.Single().BaseObject;
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1");

Assert.IsTrue(
PremiumDB_P2.Single().BaseObject is Services.Server.Database,
"Expecting a Database object");
Services.Server.Database databaseP2 =
(Services.Server.Database)PremiumDB_P2.Single().BaseObject;
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2");

Assert.AreEqual(
"Japanese_CI_AS",
databaseP2.CollationName,
"Expected collation to be Japanese_CI_AS");
Assert.AreEqual("Premium", databaseP2.Edition, "Expected edition to be Premium");
Assert.AreEqual(10, databaseP2.MaxSizeGB, "Expected max size to be 10 GB");
}
}

Expand Down
Loading