Skip to content

Commit 57cd8dd

Browse files
committed
add autoclose test #884
1 parent b5f6e66 commit 57cd8dd

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

checks/Databasev5.Tests.ps1

+8-1
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,11 @@ Describe "AsymmetricKeySize" -Tag AsymmetricKeySize, CIS, Database -ForEach $Ins
103103
}
104104
}
105105

106-
106+
Describe "Auto Close" -Tag AutoClose, High, Database -ForEach $InstancesToTest {
107+
$skip = Get-DbcConfigValue skip.database.autoclose
108+
Context "Testing Auto Close on <_.Name>" {
109+
It "Database <_.Name> should have Auto Close set to <_.ConfigValues.autoclose> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.autocloseexclude -notcontains $PsItem.Name } } {
110+
$psitem.AutoClose | Should -Be $psitem.ConfigValues.autoclose -Because "Because!"
111+
}
112+
}
113+
}

internal/configurations/configuration.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ Set-PSFConfig -Module dbachecks -Name policy.build.behind -Value $null -Initiali
230230

231231
# exclude databases
232232
Set-PSFConfig -Module dbachecks -Name policy.asymmetrickeysize.excludedb -Value @('master', 'msdb', 'tempdb') -Initialize -Description "Databases to exclude from asymmetric key size checks"
233+
Set-PSFConfig -Module dbachecks -Name policy.autoclose.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks"
233234

234235

235236

@@ -255,6 +256,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.validdatabaseowner -Validati
255256
Set-PSFConfig -Module dbachecks -Name skip.database.invaliddatabaseowner -Validation bool -Value $false -Initialize -Description "Skip the invalid database owner test"
256257
Set-PSFConfig -Module dbachecks -Name skip.database.databasecollation -Validation bool -Value $false -Initialize -Description "Skip the database collation test"
257258
Set-PSFConfig -Module dbachecks -Name skip.database.suspectpage -Validation bool -Value $false -Initialize -Description "Skip the suspect pages test"
259+
Set-PSFConfig -Module dbachecks -Name skip.database.autoclose -Validation bool -Value $false -Initialize -Description "Skip the autoclose test"
258260

259261

260262
Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"

internal/functions/Get-AllDatabaseInfo.ps1

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ function Get-AllDatabaseInfo {
5454
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'asymmetrickeysizeexclude' -Value (Get-DbcConfigValue policy.asymmetrickeysize.excludedb)
5555
}
5656

57+
'AutoClose' {
58+
$autoclose = $true
59+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoclose' -Value (Get-DbcConfigValue policy.database.autoclose)
60+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocloseexclude' -Value (Get-DbcConfigValue policy.autoclose.excludedb)
61+
}
62+
5763
'ValidDatabaseOwner' {
5864
$owner = $true
5965
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownername' -Value (Get-DbcConfigValue policy.validdbowner.name)
@@ -96,6 +102,7 @@ function Get-AllDatabaseInfo {
96102
ConfigValues = $ConfigValues # can we move this out?
97103
AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count }
98104
#AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key
105+
AutoClose = if ($autoclose) { $psitem.AutoClose}
99106
}
100107
}
101108
}

0 commit comments

Comments
 (0)