@@ -57,35 +57,31 @@ function Test-ThreatDetectionDatabaseUpdatePolicy
57
57
{
58
58
# Test
59
59
Set-AzureRmSqlDatabaseAuditingPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - StorageAccountName $params.storageAccount
60
- Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName
$params.rgname - ServerName
$params.serverName - DatabaseName
$params.databaseName - NotificationRecipientsEmails
" [email protected] ;[email protected] " - EmailAdmins
$false - ExcludedDetectionType
" Successful_SQLi " , " Attempted_SQLi "
60
+ Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName
$params.rgname - ServerName
$params.serverName - DatabaseName
$params.databaseName - NotificationRecipientsEmails
" [email protected] ;[email protected] " - EmailAdmins
$false - ExcludedDetectionType
" Sql_Injection " , " Sql_Injection_Vulnerability "
61
61
$policy = Get-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName
62
62
63
63
# Assert
64
64
Assert-AreEqual $policy.ThreatDetectionState " Enabled"
65
65
Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
66
66
Assert-False {$policy.EmailAdmins }
67
67
Assert-AreEqual $policy.ExcludedDetectionTypes.Length 2
68
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Successful_SQLi )}
69
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Attempted_SQLi )}
68
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection )}
69
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection_Vulnerability )}
70
70
71
71
72
72
# Test
73
- Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - ExcludedDetectionType " Successful_SQLi " , " Attempted_SQLi " , " Client_GEO_Anomaly " , " Failed_Logins_Anomaly " , " Failed_Queries_Anomaly " , " Data_Extraction_Anomaly " , " Data_Alteration_Anomaly "
73
+ Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - ExcludedDetectionType " Sql_Injection " , " Sql_Injection_Vulnerability " , " Access_Anomaly " , " Usage_Anomaly "
74
74
$policy = Get-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName
75
75
76
76
# Assert
77
77
Assert-AreEqual $policy.ThreatDetectionState " Enabled"
78
78
Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
79
79
Assert-False {$policy.EmailAdmins }
80
80
Assert-AreEqual $policy.ExcludedDetectionTypes.Length 7
81
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Successful_SQLi)}
82
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Attempted_SQLi)}
83
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Client_GEO_Anomaly)}
84
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Failed_Logins_Anomaly)}
85
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Failed_Queries_Anomaly)}
86
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Data_Extraction_Anomaly)}
87
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Data_Alteration_Anomaly)}
88
-
81
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection)}
82
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection_Vulnerability)}
83
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Access_Anomaly)}
84
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Usage_Anomaly)}
89
85
90
86
# Test
91
87
Remove-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName
@@ -96,13 +92,20 @@ function Test-ThreatDetectionDatabaseUpdatePolicy
96
92
Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
97
93
Assert-False {$policy.EmailAdmins }
98
94
Assert-AreEqual $policy.ExcludedDetectionTypes.Length 7
99
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Successful_SQLi)}
100
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Attempted_SQLi)}
101
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Client_GEO_Anomaly)}
102
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Failed_Logins_Anomaly)}
103
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Failed_Queries_Anomaly)}
104
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Data_Extraction_Anomaly)}
105
- Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Data_Alteration_Anomaly)}
95
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection)}
96
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection_Vulnerability)}
97
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Access_Anomaly)}
98
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Usage_Anomaly)}
99
+
100
+ # Test
101
+ Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - ExcludedDetectionType " None"
102
+ $policy = Get-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName
103
+
104
+ # Assert
105
+ Assert-AreEqual $policy.ThreatDetectionState " Enabled"
106
+ Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
107
+ Assert-False {$policy.EmailAdmins }
108
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 0
106
109
}
107
110
finally
108
111
{
@@ -183,6 +186,9 @@ function Test-InvalidArgumentsThreatDetection
183
186
# Check that EmailAdmins is not False and NotificationRecipientsEmails is not empty
184
187
Assert-Throws {Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - EmailAdmins $false }
185
188
Assert-Throws {Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - EmailAdmins $false - NotificationRecipientsEmails " " }
189
+
190
+ # Check that ExcludedDetectionType doesn't hold None and any other type
191
+ Assert-Throws {Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - EmailAdmins $true - ExcludedDetectionType " None" , " Sql_Injection_Vulnerability" }
186
192
}
187
193
finally
188
194
{
0 commit comments