Skip to content

Commit

Permalink
add autoclose test #884
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret committed May 27, 2022
1 parent b5f6e66 commit 57cd8dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ Describe "AsymmetricKeySize" -Tag AsymmetricKeySize, CIS, Database -ForEach $Ins
}
}


Describe "Auto Close" -Tag AutoClose, High, Database -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.database.autoclose
Context "Testing Auto Close on <_.Name>" {
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 } } {
$psitem.AutoClose | Should -Be $psitem.ConfigValues.autoclose -Because "Because!"
}
}
}
2 changes: 2 additions & 0 deletions internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Set-PSFConfig -Module dbachecks -Name policy.build.behind -Value $null -Initiali

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



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


Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"
Expand Down
7 changes: 7 additions & 0 deletions internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ function Get-AllDatabaseInfo {
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'asymmetrickeysizeexclude' -Value (Get-DbcConfigValue policy.asymmetrickeysize.excludedb)
}

'AutoClose' {
$autoclose = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoclose' -Value (Get-DbcConfigValue policy.database.autoclose)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocloseexclude' -Value (Get-DbcConfigValue policy.autoclose.excludedb)
}

'ValidDatabaseOwner' {
$owner = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownername' -Value (Get-DbcConfigValue policy.validdbowner.name)
Expand Down Expand Up @@ -96,6 +102,7 @@ function Get-AllDatabaseInfo {
ConfigValues = $ConfigValues # can we move this out?
AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count }
#AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key
AutoClose = if ($autoclose) { $psitem.AutoClose}
}
}
}
Expand Down

0 comments on commit 57cd8dd

Please sign in to comment.