17
17
. SYNOPSIS
18
18
Tests the default values of database's threat detection policy
19
19
#>
20
- function Test-ThreatDetectionDatabaseGetDefualtPolicy
20
+ function Test-ThreatDetectionGetDefualtPolicy
21
21
{
22
22
# Setup
23
- $testSuffix = 4002
23
+ $testSuffix = 4006
24
24
Create- TestEnvironment $testSuffix " Japan East" # Create-ThreatDetectionTestEnvironmentWithStorageV2 $testSuffix
25
25
$params = Get-SqlAuditingTestEnvironmentParameters $testSuffix # Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
26
26
@@ -33,7 +33,16 @@ function Test-ThreatDetectionDatabaseGetDefualtPolicy
33
33
Assert-AreEqual $policy.ThreatDetectionState " New"
34
34
Assert-AreEqual $policy.NotificationRecipientsEmails " "
35
35
Assert-True {$policy.EmailAdmins }
36
- Assert-AreEqual $policy.ExcludedDetectionTypes.Length 0
36
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 1
37
+
38
+ # Test
39
+ $policy = Get-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName
40
+
41
+ # Assert
42
+ Assert-AreEqual $policy.ThreatDetectionState " New"
43
+ Assert-AreEqual $policy.NotificationRecipientsEmails " "
44
+ Assert-True {$policy.EmailAdmins }
45
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 1
37
46
}
38
47
finally
39
48
{
@@ -49,7 +58,7 @@ Tests that when modifying the properties of a databases's threat detection polic
49
58
function Test-ThreatDetectionDatabaseUpdatePolicy
50
59
{
51
60
# Setup
52
- $testSuffix = 6002
61
+ $testSuffix = 6004
53
62
Create- TestEnvironment $testSuffix " Japan East" # Create-ThreatDetectionTestEnvironmentWithStorageV2 $testSuffix
54
63
$params = Get-SqlAuditingTestEnvironmentParameters $testSuffix # Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
55
64
@@ -120,7 +129,7 @@ Tests that when turning off auditing or marking it as "use server default" , thr
120
129
function Test-DisablingThreatDetection
121
130
{
122
131
# Setup
123
- $testSuffix = 7005
132
+ $testSuffix = 7011
124
133
Create- TestEnvironment $testSuffix " Japan East" # Create-ThreatDetectionTestEnvironmentWithStorageV2 $testSuffix
125
134
$params = Get-SqlAuditingTestEnvironmentParameters $testSuffix # Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
126
135
@@ -163,7 +172,7 @@ Tests sending invalid arguments in database's threat detection
163
172
function Test-InvalidArgumentsThreatDetection
164
173
{
165
174
# Setup5
166
- $testSuffix = 8009
175
+ $testSuffix = 8025
167
176
Create- TestEnvironment $testSuffix " Japan East" # Create-ThreatDetectionTestEnvironmentWithStorageV2 $testSuffix
168
177
$params = Get-SqlAuditingTestEnvironmentParameters $testSuffix # Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
169
178
@@ -210,13 +219,89 @@ function Test-ThreatDetectionOnV2Server
210
219
try
211
220
{
212
221
Set-AzureRmSqlDatabaseAuditingPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - StorageAccountName $params.storageAccount
213
- Assert-Throws {Set-AzureRmSqlDatabaseAuditingPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName - StorageAccountName $params.storageAccount - ThreatDetectionState " Enabled" }
214
222
Assert-Throws {Set-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName }
215
223
Assert-Throws {Get-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - DatabaseName $params.databaseName }
224
+
225
+ Set-AzureRmSqlServerAuditingPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - StorageAccountName $params.storageAccount
226
+ Assert-Throws {Set-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName }
227
+ Assert-Throws {Get-AzureRmSqlDatabaseThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName }
228
+
216
229
}
217
230
finally
218
231
{
219
232
# Cleanup
220
233
Remove-ThreatDetectionTestEnvironment $testSuffix
221
234
}
222
- }
235
+ }
236
+
237
+ <#
238
+ . SYNOPSIS
239
+ Tests that when modifying the properties of a server's threat detection policy , they are later fetched properly
240
+ #>
241
+ function Test-ThreatDetectionServerUpdatePolicy
242
+ {
243
+ # Setup
244
+ $testSuffix = 6027
245
+ Create- TestEnvironment $testSuffix " Japan East" # Create-ThreatDetectionTestEnvironmentWithStorageV2 $testSuffix
246
+ $params = Get-SqlAuditingTestEnvironmentParameters $testSuffix # Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
247
+
248
+ try
249
+ {
250
+ # Test
251
+ Set-AzureRmSqlServerAuditingPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - StorageAccountName $params.storageAccount
252
+ Set-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName
$params.rgname - ServerName
$params.serverName - NotificationRecipientsEmails
" [email protected] ;[email protected] " - EmailAdmins
$false - ExcludedDetectionType Sql_Injection_Vulnerability
253
+ $policy = Get-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName
254
+
255
+ # Assert
256
+ Assert-AreEqual $policy.ThreatDetectionState " Enabled"
257
+ Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
258
+ Assert-False {$policy.EmailAdmins }
259
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 1
260
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection_Vulnerability)}
261
+
262
+
263
+ # Test
264
+ Set-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - ExcludedDetectionType Sql_Injection, Sql_Injection_Vulnerability, Access_Anomaly, Usage_Anomaly
265
+ $policy = Get-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName
266
+
267
+ # Assert
268
+ Assert-AreEqual $policy.ThreatDetectionState " Enabled"
269
+ Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
270
+ Assert-False {$policy.EmailAdmins }
271
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 4
272
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection)}
273
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection_Vulnerability)}
274
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Access_Anomaly)}
275
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Usage_Anomaly)}
276
+
277
+ # Test
278
+ Remove-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName
279
+ $policy = Get-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName
280
+
281
+ # Assert
282
+ Assert-AreEqual $policy.ThreatDetectionState " Disabled"
283
+ Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
284
+ Assert-False {$policy.EmailAdmins }
285
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 4
286
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection)}
287
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Sql_Injection_Vulnerability)}
288
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Access_Anomaly)}
289
+ Assert-True {$policy.ExcludedDetectionTypes.Contains ([Microsoft.Azure.Commands.Sql.ThreatDetection.Model.DetectionType ]::Usage_Anomaly)}
290
+
291
+ # Test
292
+ Set-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName - ExcludedDetectionType None
293
+ $policy = Get-AzureRmSqlServerThreatDetectionPolicy - ResourceGroupName $params.rgname - ServerName $params.serverName
294
+
295
+ # Assert
296
+ Assert-AreEqual $policy.ThreatDetectionState " Enabled"
297
+ Assert-AreEqual $policy.NotificationRecipientsEmails " [email protected] ;[email protected] "
298
+ Assert-False {$policy.EmailAdmins }
299
+ Assert-AreEqual $policy.ExcludedDetectionTypes.Length 0
300
+ }
301
+ finally
302
+ {
303
+ # Cleanup
304
+ Remove-ThreatDetectionTestEnvironment $testSuffix
305
+ }
306
+ }
307
+
0 commit comments