Skip to content

Commit f09e745

Browse files
Adding new Az.Sql AdvancedThreatProtectionSetting cmdlets that make use of the new advancedThreatProtectionSettings ARM API (#19548)
* Adding new Az.Sql AdvancedThreatProtectionSetting cmdlets and removing old deprecated ones (that used old APIs) * Fix and adding test session recordings * Temporarily adding private SQL .NET SDK to Localfeed * Fixing tests according to latest used Sql test infra * Correctly push a Preview .NET SDK nuget * Fix AdvancedDataSecurity tests * Fix DataClassification tests * Temporary compilation fix for ManagedDatabaseModel breaking change * Fixing Static Analysis * Adding generated SDK client that contains AdvancedThreatProtection APIs and fixing some tests * Fix StaticAnalysis * Fix some tests with new recordings * Fix ManagedDatabase test * Updated ChangeLog Co-authored-by: Yunchi Wang <[email protected]>
1 parent ef0d61a commit f09e745

File tree

71 files changed

+15298
-29649
lines changed

Some content is hidden

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

71 files changed

+15298
-29649
lines changed

src/Sql/Sql.Test/ScenarioTests/AdvancedDataSecurityTests.ps1

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,17 @@ function Test-AdvancedDataSecurityPolicyTest
5252
Assert-False { $policy.IsEnabled }
5353

5454
# See that ATP cmdlets don't mess up the Threat Detection policy - with enabling VA off
55-
Update-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -NotificationRecipientsEmails "[email protected];[email protected]" -EmailAdmins $false -ExcludedDetectionType Sql_Injection_Vulnerability
56-
5755
Disable-AzSqlServerAdvancedDataSecurity -ResourceGroupName $params.rgname -ServerName $params.serverName
5856

5957
# Assert
60-
$policy = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
61-
Assert-AreEqual $policy.ThreatDetectionState "Disabled"
62-
Assert-AreEqual $policy.NotificationRecipientsEmails "[email protected];[email protected]"
63-
Assert-False {$policy.EmailAdmins}
64-
Assert-AreEqual $policy.ExcludedDetectionTypes.Count 1
65-
Assert-True {$policy.ExcludedDetectionTypes.Contains([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType]::Sql_Injection_Vulnerability)}
58+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
59+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Disabled"
6660

6761
Enable-AzSqlServerAdvancedDataSecurity -ResourceGroupName $params.rgname -ServerName $params.serverName -DoNotConfigureVulnerabilityAssessment
6862

6963
# Assert
70-
$policy = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
71-
Assert-AreEqual $policy.ThreatDetectionState "Enabled"
72-
Assert-AreEqual $policy.NotificationRecipientsEmails "[email protected];[email protected]"
73-
Assert-False {$policy.EmailAdmins}
74-
Assert-AreEqual $policy.ExcludedDetectionTypes.Count 1
75-
Assert-True {$policy.ExcludedDetectionTypes.Contains([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType]::Sql_Injection_Vulnerability)}
64+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
65+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Enabled"
7666

7767
# Check enabling ADS with VA
7868
Disable-AzSqlServerAdvancedDataSecurity -ResourceGroupName $params.rgname -ServerName $params.serverName
@@ -95,27 +85,17 @@ function Test-AdvancedDataSecurityPolicyTest
9585
Assert-AreEqualArray @() $settings.NotificationEmail
9686

9787
# See that ATP cmdlets don't mess up the Threat Detection policy - with enabling VA on
98-
Update-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -NotificationRecipientsEmails "[email protected];[email protected]" -EmailAdmins $false -ExcludedDetectionType Sql_Injection_Vulnerability
99-
10088
Disable-AzSqlServerAdvancedDataSecurity -ResourceGroupName $params.rgname -ServerName $params.serverName
10189

10290
# Assert
103-
$policy = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
104-
Assert-AreEqual $policy.ThreatDetectionState "Disabled"
105-
Assert-AreEqual $policy.NotificationRecipientsEmails "[email protected];[email protected]"
106-
Assert-False {$policy.EmailAdmins}
107-
Assert-AreEqual $policy.ExcludedDetectionTypes.Count 1
108-
Assert-True {$policy.ExcludedDetectionTypes.Contains([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType]::Sql_Injection_Vulnerability)}
91+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
92+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Disabled"
10993

11094
Enable-AzSqlServerAdvancedDataSecurity -ResourceGroupName $params.rgname -ServerName $params.serverName -DeploymentName "EnableVA_sql-ads-cmdlet-test-srv2"
11195

11296
# Assert
113-
$policy = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
114-
Assert-AreEqual $policy.ThreatDetectionState "Enabled"
115-
Assert-AreEqual $policy.NotificationRecipientsEmails "[email protected];[email protected]"
116-
Assert-False {$policy.EmailAdmins}
117-
Assert-AreEqual $policy.ExcludedDetectionTypes.Count 1
118-
Assert-True {$policy.ExcludedDetectionTypes.Contains([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType]::Sql_Injection_Vulnerability)}
97+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
98+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Enabled"
11999
}
120100
finally
121101
{
@@ -128,7 +108,7 @@ function Test-AdvancedDataSecurityPolicyTest
128108
.SYNOPSIS
129109
Creates the test environment needed to perform the tests
130110
#>
131-
function Create-AdvancedDataSecurityTestEnvironment ($testSuffix, $location = "West Central US", $serverVersion = "12.0")
111+
function Create-AdvancedDataSecurityTestEnvironment ($testSuffix, $location = "West Europe", $serverVersion = "12.0")
132112
{
133113
$params = Get-SqlAdvancedDataSecurityTestEnvironmentParameters $testSuffix
134114
Create-BasicTestEnvironmentWithParams $params $location $serverVersion
@@ -140,8 +120,8 @@ Gets the values of the parameters used at the tests
140120
#>
141121
function Get-SqlAdvancedDataSecurityTestEnvironmentParameters ($testSuffix)
142122
{
143-
return @{ rgname = "sql-ads-cmdlet-test-rg" +$testSuffix;
144-
serverName = "sql-ads-cmdlet-server" +$testSuffix;
123+
return @{ rgname = "sql-ads-cmdlet-test-rg" + $testSuffix;
124+
serverName = "sql-ads-cmdlet-server" + $testSuffix;
145125
databaseName = "sql-ads-cmdlet-db" + $testSuffix;
146126
}
147127
}

src/Sql/Sql.Test/ScenarioTests/ThreatDetectionTests.cs renamed to src/Sql/Sql.Test/ScenarioTests/AdvancedThreatProtectionTests.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,35 @@
1616
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1717
using Xunit;
1818
using Xunit.Abstractions;
19-
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2019

2120
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
2221
{
23-
public class ThreatDetectionTests : SqlTestRunner
22+
public class AdvancedThreatProtectionTests : SqlTestRunner
2423
{
25-
public ThreatDetectionTests(ITestOutputHelper output) : base(output)
24+
public AdvancedThreatProtectionTests(ITestOutputHelper output) : base(output)
2625
{
2726

2827
}
2928

3029
[Fact]
3130
[Trait(Category.AcceptanceType, Category.CheckIn)]
32-
public void ThreatDetectionGetDefaultPolicy()
31+
public void AdvancedThreatProtectionGetDefaultSettings()
3332
{
34-
TestRunner.RunTestScript("Test-ThreatDetectionGetDefaultPolicy");
33+
TestRunner.RunTestScript("Test-AdvancedThreatProtectionGetDefaultSettings");
3534
}
3635

3736
[Fact]
3837
[Trait(Category.AcceptanceType, Category.CheckIn)]
39-
public void ThreatDetectionDatabaseUpdatePolicy()
38+
public void AdvancedThreatProtectionDatabaseUpdateSettings()
4039
{
41-
TestRunner.RunTestScript("Test-ThreatDetectionDatabaseUpdatePolicy");
40+
TestRunner.RunTestScript("Test-AdvancedThreatProtectionDatabaseUpdateSettings");
4241
}
4342

4443
[Fact]
4544
[Trait(Category.AcceptanceType, Category.CheckIn)]
46-
public void ThreatDetectionServerUpdatePolicy()
45+
public void AdvancedThreatProtectionServerUpdateSettings()
4746
{
48-
TestRunner.RunTestScript("Test-ThreatDetectionServerUpdatePolicy");
49-
}
50-
51-
[Fact]
52-
[Trait(Category.AcceptanceType, Category.CheckIn)]
53-
public void DisablingThreatDetection()
54-
{
55-
TestRunner.RunTestScript("Test-DisablingThreatDetection");
56-
}
57-
58-
[Fact]
59-
[Trait(Category.AcceptanceType, Category.CheckIn)]
60-
public void InvalidArgumentsThreatDetection()
61-
{
62-
TestRunner.RunTestScript("Test-InvalidArgumentsThreatDetection");
47+
TestRunner.RunTestScript("Test-AdvancedThreatProtectionServerUpdateSettings");
6348
}
6449
}
6550
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests the default values of database's Advanced Threat Protection settings
18+
#>
19+
function Test-AdvancedThreatProtectionGetDefaultSettings
20+
{
21+
# Setup
22+
$testSuffix = getAssetName
23+
Create-AdvancedThreatProtectionTestEnvironment $testSuffix
24+
$params = Get-SqlAdvancedThreatProtectionTestEnvironmentParameters $testSuffix
25+
26+
try
27+
{
28+
# Test
29+
$settings = Get-AzSqlDatabaseAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
30+
31+
# Assert
32+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Disabled"
33+
34+
# Test
35+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
36+
37+
# Assert
38+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Disabled"
39+
}
40+
finally
41+
{
42+
# Cleanup
43+
Remove-AdvancedThreatProtectionTestEnvironment $testSuffix
44+
}
45+
}
46+
47+
<#
48+
.SYNOPSIS
49+
Tests that when modifying the properties of a databases's Advanced Threat Protection Settings, they are later fetched properly
50+
#>
51+
function Test-AdvancedThreatProtectionDatabaseUpdateSettings
52+
{
53+
# Setup
54+
$testSuffix = getAssetName
55+
Create-AdvancedThreatProtectionTestEnvironment $testSuffix
56+
$params = Get-SqlAdvancedThreatProtectionTestEnvironmentParameters $testSuffix
57+
58+
try
59+
{
60+
# Test upsert of ATP settings
61+
Update-AzSqlDatabaseAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -Enable $true
62+
$settings = Get-AzSqlDatabaseAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
63+
64+
# Assert
65+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Enabled"
66+
67+
# Test
68+
Update-AzSqlDatabaseAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -Enable $false
69+
$settings = Get-AzSqlDatabaseAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
70+
71+
# Assert
72+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Disabled"
73+
}
74+
finally
75+
{
76+
# Cleanup
77+
Remove-AdvancedThreatProtectionTestEnvironment $testSuffix
78+
}
79+
}
80+
81+
<#
82+
.SYNOPSIS
83+
Tests that when modifying the properties of a server's Advanced Threat Protection Settings, they are later fetched properly
84+
#>
85+
function Test-AdvancedThreatProtectionServerUpdateSettings
86+
{
87+
# Setup
88+
$testSuffix = getAssetName
89+
Create-AdvancedThreatProtectionTestEnvironment $testSuffix
90+
$params = Get-SqlAdvancedThreatProtectionTestEnvironmentParameters $testSuffix
91+
92+
try
93+
{
94+
# Test upsert of ATP settings
95+
Update-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -Enable $true
96+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
97+
98+
# Assert
99+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Enabled"
100+
101+
# Test
102+
Update-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName -Enable $false
103+
$settings = Get-AzSqlServerAdvancedThreatProtectionSetting -ResourceGroupName $params.rgname -ServerName $params.serverName
104+
105+
# Assert
106+
Assert-AreEqual $settings.AdvancedThreatProtectionState "Disabled"
107+
}
108+
finally
109+
{
110+
# Cleanup
111+
Remove-AdvancedThreatProtectionTestEnvironment $testSuffix
112+
}
113+
}

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ function Get-SqlBlobAuditingTestEnvironmentParameters ($testSuffix)
4545

4646
<#
4747
.SYNOPSIS
48-
Gets the values of the parameters used at the threat detection tests
48+
Gets the values of the parameters used for the Advanced Threat Protection tests
4949
#>
50-
function Get-SqlThreatDetectionTestEnvironmentParameters ($testSuffix)
50+
function Get-SqlAdvancedThreatProtectionTestEnvironmentParameters ($testSuffix)
5151
{
52-
return @{ rgname = "sql-td-cmdlet-test-rg" +$testSuffix;
53-
serverName = "sql-td-cmdlet-server" +$testSuffix;
52+
return @{ rgname = "sql-td-cmdlet-test-rg" + $testSuffix;
53+
serverName = "sql-td-cmdlet-server" + $testSuffix;
5454
databaseName = "sql-td-cmdlet-db" + $testSuffix;
55-
storageAccount = "tdcmdlets" +$testSuffix
5655
}
5756
}
5857

@@ -111,22 +110,12 @@ function Create-BlobAuditingClassicTestEnvironment ($testSuffix, $location = "We
111110

112111
<#
113112
.SYNOPSIS
114-
Creates the test environment needed to perform the Sql threat detecion tests
113+
Creates the test environment needed to perform the Sql Advanced Threat Protection tests
115114
#>
116-
function Create-ThreatDetectionTestEnvironment ($testSuffix, $location = "West Central US", $serverVersion = "12.0")
115+
function Create-AdvancedThreatProtectionTestEnvironment ($testSuffix, $location = "West Europe", $serverVersion = "12.0")
117116
{
118-
$params = Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
119-
Create-TestEnvironmentWithParams $params $location $serverVersion
120-
}
121-
122-
<#
123-
.SYNOPSIS
124-
Creates the test environment needed to perform the Sql threat detecion tests with classic storage
125-
#>
126-
function Create-ThreatDetectionClassicTestEnvironment ($testSuffix, $location = "West Central US", $serverVersion = "12.0")
127-
{
128-
$params = Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
129-
Create-ClassicTestEnvironmentWithParams $params $location $serverVersion
117+
$params = Get-SqlAdvancedThreatProtectionTestEnvironmentParameters $testSuffix
118+
Create-BasicTestEnvironmentWithParams $params $location $serverVersion
130119
}
131120

132121
<#
@@ -790,11 +779,11 @@ function Create-JobStepForTest ($j, $tg, $c, $ct)
790779

791780
<#
792781
.SYNOPSIS
793-
Removes the test environment that was needed to perform the Sql threat detection tests
782+
Removes the test environment that was needed to perform the Sql Advanced Threat Protection tests
794783
#>
795-
function Remove-ThreatDetectionTestEnvironment ($testSuffix)
784+
function Remove-AdvancedThreatProtectionTestEnvironment ($testSuffix)
796785
{
797-
$params = Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
786+
$params = Get-SqlAdvancedThreatProtectionTestEnvironmentParameters $testSuffix
798787
Remove-AzResourceGroup -Name $params.rgname -Force
799788
}
800789

src/Sql/Sql.Test/ScenarioTests/DataClassificationTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ function Remove-DataClassificationTestEnvironment ($testSuffix)
497497
.SYNOPSIS
498498
Creates the test environment needed to perform the tests
499499
#>
500-
function Create-SqlDataClassificationTestEnvironment ($testSuffix, $location = "west central us", $serverVersion = "12.0")
500+
function Create-SqlDataClassificationTestEnvironment ($testSuffix, $location = "North Europe", $serverVersion = "12.0")
501501
{
502502
$params = Get-DataClassificationTestEnvironmentParameters $testSuffix
503503

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)