Skip to content

Commit 9a9cd0e

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#8196 from maddieclayton/sqlcommon
Add common storage SDK to Sql
2 parents a000f25 + 5f7454a commit 9a9cd0e

File tree

49 files changed

+45633
-54370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+45633
-54370
lines changed

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.Netcore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<PropertyGroup>
44
<PsModuleName>Sql</PsModuleName>
5-
<IncludeManagementStorage>false</IncludeManagementStorage>
65
</PropertyGroup>
76

87
<Import Project="$(MSBuildThisFileDirectory)..\..\..\Az.Test.props" />

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/AdvancedThreatProtectionTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public class AdvancedThreatProtectionTests : SqlTestsBase
2525
protected override void SetupManagementClients(RestTestFramework.MockContext context)
2626
{
2727
var sqlClient = GetSqlClient(context);
28-
var storageV2Client = GetStorageV2Client(context);
29-
var resourcesClient = GetResourcesClient(context);
30-
Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, resourcesClient);
28+
var publicstorageV2Client = GetPublicStorageManagementClient(context);
29+
var storageV2Client = GetStorageManagementClient(context);
30+
var newResourcesClient = GetResourcesClient(context);
31+
Helper.SetupSomeOfManagementClients(sqlClient, publicstorageV2Client, storageV2Client, newResourcesClient);
3132
}
3233

3334
public AdvancedThreatProtectionTests(ITestOutputHelper output) : base(output)

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/AuditingClassicStorageTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public class AuditingClassicStorageTests : SqlTestsBase
2525
protected override void SetupManagementClients(RestTestFramework.MockContext context)
2626
{
2727
var sqlClient = GetSqlClient(context);
28-
var storageV2Client = GetStorageV2Client(context);
28+
var publicstorageV2Client = GetPublicStorageManagementClient(context);
29+
var storageV2Client = GetStorageManagementClient(context);
2930
var newResourcesClient = GetResourcesClient(context);
30-
Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, newResourcesClient);
31+
Helper.SetupSomeOfManagementClients(sqlClient, publicstorageV2Client, storageV2Client, newResourcesClient);
3132
}
3233

3334
public AuditingClassicStorageTests(ITestOutputHelper output) : base(output)

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/BlobAuditingClassicStorageTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public class BlobAuditingClassicStorageTests : SqlTestsBase
2525
protected override void SetupManagementClients(RestTestFramework.MockContext context)
2626
{
2727
var sqlClient = GetSqlClient(context);
28-
var storageV2Client = GetStorageV2Client(context);
28+
var publicstorageV2Client = GetPublicStorageManagementClient(context);
29+
var storageV2Client = GetStorageManagementClient(context);
2930
var newResourcesClient = GetResourcesClient(context);
30-
Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, newResourcesClient);
31+
Helper.SetupSomeOfManagementClients(sqlClient, publicstorageV2Client, storageV2Client, newResourcesClient);
3132
}
3233

3334
public BlobAuditingClassicStorageTests(ITestOutputHelper output) : base(output)

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/BlobAuditingTests.cs

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -25,57 +25,38 @@ public class BlobAuditingTests : SqlTestsBase
2525
protected override void SetupManagementClients(RestTestFramework.MockContext context)
2626
{
2727
var sqlClient = GetSqlClient(context);
28-
var storageV2Client = GetStorageV2Client(context);
28+
var publicstorageV2Client = GetPublicStorageManagementClient(context);
29+
var storageV2Client = GetStorageManagementClient(context);
2930
var newResourcesClient = GetResourcesClient(context);
30-
Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, newResourcesClient);
31+
Helper.SetupSomeOfManagementClients(sqlClient, publicstorageV2Client, storageV2Client, newResourcesClient);
3132
}
3233

3334
public BlobAuditingTests(ITestOutputHelper output) : base(output)
3435
{
3536
}
3637

37-
#if NETSTANDARD
38-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
39-
[Trait(Category.RunType, Category.DesktopOnly)]
40-
#else
4138
[Fact]
42-
#endif
4339
[Trait(Category.AcceptanceType, Category.CheckIn)]
4440
public void TestBlobAuditingDatabaseUpdatePolicyWithStorage()
4541
{
4642
RunPowerShellTest("Test-BlobAuditingDatabaseUpdatePolicyWithStorage");
4743
}
4844

49-
#if NETSTANDARD
50-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
51-
[Trait(Category.RunType, Category.DesktopOnly)]
52-
#else
5345
[Fact]
54-
#endif
5546
[Trait(Category.AcceptanceType, Category.CheckIn)]
5647
public void TestBlobAuditingServerUpdatePolicyWithStorage()
5748
{
5849
RunPowerShellTest("Test-BlobAuditingServerUpdatePolicyWithStorage");
5950
}
6051

61-
#if NETSTANDARD
62-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
63-
[Trait(Category.RunType, Category.DesktopOnly)]
64-
#else
6552
[Fact]
66-
#endif
6753
[Trait(Category.AcceptanceType, Category.CheckIn)]
6854
public void TestBlobAuditingDisableDatabaseAuditing()
6955
{
7056
RunPowerShellTest("Test-BlobAuditingDisableDatabaseAuditing");
7157
}
7258

73-
#if NETSTANDARD
74-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
75-
[Trait(Category.RunType, Category.DesktopOnly)]
76-
#else
7759
[Fact]
78-
#endif
7960
[Trait(Category.AcceptanceType, Category.CheckIn)]
8061
public void TestBlobAuditingDisableServerAuditing()
8162
{
@@ -96,24 +77,14 @@ public void TestBlobAuditingFailedServerUpdatePolicyWithNoStorage()
9677
RunPowerShellTest("Test-BlobAuditingFailedServerUpdatePolicyWithNoStorage");
9778
}
9879

99-
#if NETSTANDARD
100-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
101-
[Trait(Category.RunType, Category.DesktopOnly)]
102-
#else
10380
[Fact]
104-
#endif
10581
[Trait(Category.AcceptanceType, Category.CheckIn)]
10682
public void TestBlobAuditingDatabaseUpdatePolicyKeepPreviousStorage()
10783
{
10884
RunPowerShellTest("Test-BlobAuditingDatabaseUpdatePolicyKeepPreviousStorage");
10985
}
11086

111-
#if NETSTANDARD
112-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
113-
[Trait(Category.RunType, Category.DesktopOnly)]
114-
#else
11587
[Fact]
116-
#endif
11788
[Trait(Category.AcceptanceType, Category.CheckIn)]
11889
public void TestBlobAuditingServerUpdatePolicyKeepPreviousStorage()
11990
{
@@ -134,120 +105,70 @@ public void TestBlobAuditingFailWithBadServerIndentity()
134105
RunPowerShellTest("Test-BlobAuditingFailWithBadServerIndentity");
135106
}
136107

137-
#if NETSTANDARD
138-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
139-
[Trait(Category.RunType, Category.DesktopOnly)]
140-
#else
141108
[Fact]
142-
#endif
143109
[Trait(Category.AcceptanceType, Category.CheckIn)]
144110
public void TestBlobAuditingDatabaseStorageKeyRotation()
145111
{
146112
RunPowerShellTest("Test-BlobAuditingDatabaseStorageKeyRotation");
147113
}
148114

149-
#if NETSTANDARD
150-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
151-
[Trait(Category.RunType, Category.DesktopOnly)]
152-
#else
153115
[Fact]
154-
#endif
155116
[Trait(Category.AcceptanceType, Category.CheckIn)]
156117
public void TestBlobAuditingServerStorageKeyRotation()
157118
{
158119
RunPowerShellTest("Test-BlobAuditingServerStorageKeyRotation");
159120
}
160121

161-
#if NETSTANDARD
162-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
163-
[Trait(Category.RunType, Category.DesktopOnly)]
164-
#else
165122
[Fact]
166-
#endif
167123
[Trait(Category.AcceptanceType, Category.CheckIn)]
168124
public void TestBlobAuditingServerRetentionKeepProperties()
169125
{
170126
RunPowerShellTest("Test-BlobAuditingServerRetentionKeepProperties");
171127
}
172128

173-
#if NETSTANDARD
174-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
175-
[Trait(Category.RunType, Category.DesktopOnly)]
176-
#else
177129
[Fact]
178-
#endif
179130
[Trait(Category.AcceptanceType, Category.CheckIn)]
180131
public void TestBlobAuditingDatabaseRetentionKeepProperties()
181132
{
182133
RunPowerShellTest("Test-BlobAuditingDatabaseRetentionKeepProperties");
183134
}
184135

185-
#if NETSTANDARD
186-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
187-
[Trait(Category.RunType, Category.DesktopOnly)]
188-
#else
189136
[Fact]
190-
#endif
191137
[Trait(Category.AcceptanceType, Category.CheckIn)]
192138
public void TestBlobAuditingOnDatabase()
193139
{
194140
RunPowerShellTest("Test-BlobAuditingOnDatabase");
195141
}
196142

197-
#if NETSTANDARD
198-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
199-
[Trait(Category.RunType, Category.DesktopOnly)]
200-
#else
201143
[Fact]
202-
#endif
203144
[Trait(Category.AcceptanceType, Category.CheckIn)]
204145
public void TestBlobAuditingOnServer()
205146
{
206147
RunPowerShellTest("Test-BlobAuditingOnServer");
207148
}
208149

209-
#if NETSTANDARD
210-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
211-
[Trait(Category.RunType, Category.DesktopOnly)]
212-
#else
213150
[Fact]
214-
#endif
215151
[Trait(Category.AcceptanceType, Category.CheckIn)]
216152
public void TestBlobAuditingDatabaseUpdatePolicyWithSameNameStorageOnDifferentRegion()
217153
{
218154
RunPowerShellTest("Test-BlobAuditingDatabaseUpdatePolicyWithSameNameStorageOnDifferentRegion");
219155
}
220156

221-
#if NETSTANDARD
222-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
223-
[Trait(Category.RunType, Category.DesktopOnly)]
224-
#else
225157
[Fact]
226-
#endif
227158
[Trait(Category.AcceptanceType, Category.CheckIn)]
228159
public void TestBlobAuditingWithAuditActionGroups()
229160
{
230161
RunPowerShellTest("Test-BlobAuditingWithAuditActionGroups");
231162
}
232163

233-
#if NETSTANDARD
234-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
235-
[Trait(Category.RunType, Category.DesktopOnly)]
236-
#else
237164
[Fact]
238-
#endif
239165
[Trait(Category.AcceptanceType, Category.CheckIn)]
240166
public void TestExtendedAuditingOnDatabase()
241167
{
242168
RunPowerShellTest("Test-ExtendedAuditingOnDatabase");
243169
}
244170

245-
#if NETSTANDARD
246-
[Fact(Skip = "Storage version difference: Awaiting Storage.Common usage in Sql")]
247-
[Trait(Category.RunType, Category.DesktopOnly)]
248-
#else
249171
[Fact]
250-
#endif
251172
[Trait(Category.AcceptanceType, Category.CheckIn)]
252173
public void TestExtendedAuditingOnServer()
253174
{

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/BlobAuditingTests.ps1

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ function Test-BlobAuditingOnDatabase
501501
$params = Get-SqlBlobAuditingTestEnvironmentParameters $testSuffix
502502
$dbName = $params.databaseName
503503

504+
# NEEDS TO BE FILLED OUT WITH A PRECREATED STORAGE ACCOUNT IN A DIFFERENT SUBSCRIPTION
505+
$subscriptionId = "c9cbd920-c00c-427c-852b-8aaf38badaeb"
506+
$storageAccountName = "sqltestsa"
507+
504508
try
505509
{
506510
# Test - Tests that when setting blob auditing policy on database without StorageKeyType parameter, it gets the default value - "Primary".
@@ -517,7 +521,7 @@ function Test-BlobAuditingOnDatabase
517521
Assert-True { $policy.StorageKeyType -eq "Primary"}
518522

519523
# Test - Tests setting blob auditing policy on a database with a storage account in a subscription which is different than the database's subscription
520-
Set-AzureRmSqlDatabaseAuditing -State Enabled -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -StorageAccountName datasecpstests -AuditActionGroup "SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP", "FAILED_DATABASE_AUTHENTICATION_GROUP" -RetentionInDays 8 -StorageAccountSubscriptionId b403f7d6-87fb-4a39-8b34-b2172f985b78
524+
Set-AzureRmSqlDatabaseAuditing -State Enabled -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -StorageAccountName $storageAccountName -AuditActionGroup "SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP", "FAILED_DATABASE_AUTHENTICATION_GROUP" -RetentionInDays 8 -StorageAccountSubscriptionId $subscriptionId
521525
$policy = Get-AzureRmSqlDatabaseAuditing -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
522526

523527
# Assert
@@ -528,7 +532,7 @@ function Test-BlobAuditingOnDatabase
528532
Assert-AreEqual $policy.AuditAction.Length 0
529533
Assert-AreEqual $policy.RetentionInDays 8
530534
Assert-True { $policy.StorageKeyType -eq "Primary"}
531-
Assert-AreEqual $policy.StorageAccountSubscriptionId "b403f7d6-87fb-4a39-8b34-b2172f985b78"
535+
Assert-AreEqual $policy.StorageAccountSubscriptionId $subscriptionId
532536

533537
# Test
534538
Set-AzureRmSqlDatabaseAuditing -State Enabled -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -StorageAccountName $params.storageAccount -StorageKeyType "Secondary" -AuditActionGroup "SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP", "FAILED_DATABASE_AUTHENTICATION_GROUP" -RetentionInDays 8 -AuditAction "UPDATE ON database::[$($params.databaseName)] BY [public]"
@@ -579,6 +583,10 @@ function Test-BlobAuditingOnServer
579583
Create-BlobAuditingTestEnvironment $testSuffix
580584
$params = Get-SqlBlobAuditingTestEnvironmentParameters $testSuffix
581585

586+
# NEEDS TO BE FILLED OUT WITH A PRECREATED STORAGE ACCOUNT IN A DIFFERENT SUBSCRIPTION
587+
$subscriptionId = "c9cbd920-c00c-427c-852b-8aaf38badaeb"
588+
$storageAccountName = "sqltestsa"
589+
582590
try
583591
{
584592
# Test - Tests that when setting blob auditing policy on server without StorageKeyType parameter, it gets the default value - "Primary".
@@ -594,7 +602,7 @@ function Test-BlobAuditingOnServer
594602
Assert-AreEqual $policy.StorageKeyType "Primary"
595603

596604
# Test - Tests setting blob auditing policy on a server with a storage account in a subscription which is different than the server's subscription
597-
Set-AzureRmSqlServerAuditing -State Enabled -ResourceGroupName $params.rgname -ServerName $params.serverName -StorageAccountName datasecpstests -AuditActionGroup "SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP", "FAILED_DATABASE_AUTHENTICATION_GROUP" -RetentionInDays 8 -StorageAccountSubscriptionId b403f7d6-87fb-4a39-8b34-b2172f985b78
605+
Set-AzureRmSqlServerAuditing -State Enabled -ResourceGroupName $params.rgname -ServerName $params.serverName -StorageAccountName $storageAccountName -AuditActionGroup "SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP", "FAILED_DATABASE_AUTHENTICATION_GROUP" -RetentionInDays 8 -StorageAccountSubscriptionId $subscriptionId
598606
$policy = Get-AzureRmSqlServerAuditing -ResourceGroupName $params.rgname -ServerName $params.serverName
599607

600608
# Assert
@@ -604,7 +612,7 @@ function Test-BlobAuditingOnServer
604612
Assert-True {$policy.AuditActionGroup.Contains([Microsoft.Azure.Commands.Sql.Auditing.Model.AuditActionGroups]::FAILED_DATABASE_AUTHENTICATION_GROUP)}
605613
Assert-AreEqual $policy.RetentionInDays 8
606614
Assert-AreEqual $policy.StorageKeyType "Primary"
607-
Assert-AreEqual $policy.StorageAccountSubscriptionId "b403f7d6-87fb-4a39-8b34-b2172f985b78"
615+
Assert-AreEqual $policy.StorageAccountSubscriptionId $subscriptionId
608616

609617
# Test
610618
Set-AzureRmSqlServerAuditing -State Enabled -ResourceGroupName $params.rgname -ServerName $params.serverName -StorageAccountName $params.storageAccount -StorageKeyType "Secondary" -AuditActionGroup "SUCCESSFUL_DATABASE_AUTHENTICATION_GROUP", "FAILED_DATABASE_AUTHENTICATION_GROUP" -RetentionInDays 8

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function Create-TestEnvironmentWithParams ($params, $location, $serverVersion)
141141
{
142142
Create-BasicTestEnvironmentWithParams $params $location $serverVersion
143143
New-AzureRmStorageAccount -StorageAccountName $params.storageAccount -ResourceGroupName $params.rgname -Location $location -Type Standard_GRS
144+
Wait-Seconds 10
144145
}
145146

146147
<#

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/SqlTestsBase.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
using System.Diagnostics;
2424
using Microsoft.Azure.Management.Internal.Resources;
2525
using Microsoft.Azure.Management.Sql;
26-
using Microsoft.Azure.Management.Storage;
26+
using CommonStorage = Microsoft.Azure.Management.Storage.Version2017_10_01;
27+
using PublicStorage = Microsoft.Azure.Management.Storage;
2728
using Microsoft.Azure.ServiceManagement.Common.Models;
2829
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2930
using Xunit.Abstractions;
@@ -104,9 +105,15 @@ protected NetworkManagementClient GetNetworkClient(MockContext context)
104105
return context.GetServiceClient<NetworkManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
105106
}
106107

107-
protected StorageManagementClient GetStorageV2Client(MockContext context)
108+
protected static CommonStorage.StorageManagementClient GetStorageManagementClient(MockContext context)
108109
{
109-
return context.GetServiceClient<StorageManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
110+
return context.GetServiceClient<CommonStorage.StorageManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
110111
}
112+
113+
protected static PublicStorage.StorageManagementClient GetPublicStorageManagementClient(MockContext context)
114+
{
115+
return context.GetServiceClient<PublicStorage.StorageManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
116+
}
117+
111118
}
112119
}

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/ThreatDetectionClassicStorageTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public class ThreatDetectionClassicStorageTests : SqlTestsBase
2525
protected override void SetupManagementClients(RestTestFramework.MockContext context)
2626
{
2727
var sqlClient = GetSqlClient(context);
28-
var storageV2Client = GetStorageV2Client(context);
28+
var publicstorageV2Client = GetPublicStorageManagementClient(context);
29+
var storageV2Client = GetStorageManagementClient(context);
2930
var newResourcesClient = GetResourcesClient(context);
30-
Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, newResourcesClient);
31+
Helper.SetupSomeOfManagementClients(sqlClient, publicstorageV2Client, storageV2Client, newResourcesClient);
3132
}
3233

3334
public ThreatDetectionClassicStorageTests(ITestOutputHelper output) : base(output)

0 commit comments

Comments
 (0)