From 57cd8dd73f478f2c84c95a7c7d263dce3688d3c0 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Fri, 27 May 2022 19:43:41 +0100 Subject: [PATCH] add autoclose test #884 --- checks/Databasev5.Tests.ps1 | 9 ++++++++- internal/configurations/configuration.ps1 | 2 ++ internal/functions/Get-AllDatabaseInfo.ps1 | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index 86823824..ed49012f 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -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!" + } + } +} \ No newline at end of file diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index da2e42a3..3ce612d2 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -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" @@ -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" diff --git a/internal/functions/Get-AllDatabaseInfo.ps1 b/internal/functions/Get-AllDatabaseInfo.ps1 index a8e90296..7508da48 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -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) @@ -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} } } }