diff --git a/CHANGELOG.md b/CHANGELOG.md index 81b31a60f..3afa24932 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Set-SqlDscStartupParameter` - Added class `StartupParameters` which can parse the startup parameters of a manged computer service object. + - Added class `SqlReason` to be used as the type of the DSC property `Reasons` + for class-based resources. - New GitHub issue templates for proposing new public commands, proposing an enhancement to an existing command, or having a problem with an existing command. @@ -143,6 +145,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 output a warning to install any of the dependent modules. - Add empty constructor to classes to be able to use Pester's new code coverage method. See more information can be found in [pester/Pester#2306](https://github.com/pester/Pester/issues/2306). + - The type of the property `Reasons` was changed in the class-based resources. + This resolves a problem when using two DSC resource modules that was + using the same class-type for the property `Reasons`. Resolves the issues + [issue #1831](https://github.com/dsccommunity/SqlServerDsc/issues/1831), + [issue #1832](https://github.com/dsccommunity/SqlServerDsc/issues/1832), + and [issue #1833](https://github.com/dsccommunity/SqlServerDsc/issues/1833). - `Install-SqlServerDsc` - No longer throws an exception when parameter `AgtSvcAccount` is not specified. - SqlAgReplica @@ -230,6 +238,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 current state ([issue #1834](https://github.com/dsccommunity/SqlServerDsc/issues/1834)). - `Set-TargetResource` was updated to correctly include or exclude a single flag ([issue #1834](https://github.com/dsccommunity/SqlServerDsc/issues/1834)). +- SqlAudit + - Return the correct type for parameter `LogType` when calling method `Get()`. ## [16.0.0] - 2022-09-09 diff --git a/source/Classes/001.SqlReason.ps1 b/source/Classes/001.SqlReason.ps1 new file mode 100644 index 000000000..cbe97fbd6 --- /dev/null +++ b/source/Classes/001.SqlReason.ps1 @@ -0,0 +1,21 @@ +<# + .SYNOPSIS + The reason a property of a DSC resource is not in desired state. + + .DESCRIPTION + A DSC resource can have a read-only property `Reasons` that the compliance + part (audit via Azure Policy) of Azure AutoManage Machine Configuration + uses. The property Reasons holds an array of SqlReason. Each SqlReason + explains why a property of a DSC resource is not in desired state. +#> + +class SqlReason +{ + [DscProperty()] + [System.String] + $Code + + [DscProperty()] + [System.String] + $Phrase +} diff --git a/source/Classes/011.SqlResourceBase.ps1 b/source/Classes/011.SqlResourceBase.ps1 index 369757d46..bcd589217 100644 --- a/source/Classes/011.SqlResourceBase.ps1 +++ b/source/Classes/011.SqlResourceBase.ps1 @@ -43,7 +43,7 @@ class SqlResourceBase : ResourceBase $Credential [DscProperty(NotConfigurable)] - [Reason[]] + [SqlReason[]] $Reasons # Passing the module's base directory to the base constructor. diff --git a/source/Classes/020.SqlAudit.ps1 b/source/Classes/020.SqlAudit.ps1 index 48c7790ea..25b5afd4e 100644 --- a/source/Classes/020.SqlAudit.ps1 +++ b/source/Classes/020.SqlAudit.ps1 @@ -269,7 +269,7 @@ class SqlAudit : SqlResourceBase if ($auditObject.DestinationType -in @('ApplicationLog', 'SecurityLog')) { - $currentState.LogType = $auditObject.DestinationType + $currentState.LogType = $auditObject.DestinationType.ToString() } if ($auditObject.FilePath) diff --git a/tests/Unit/Classes/SqlReason.Tests.ps1 b/tests/Unit/Classes/SqlReason.Tests.ps1 new file mode 100644 index 000000000..d0c9ca061 --- /dev/null +++ b/tests/Unit/Classes/SqlReason.Tests.ps1 @@ -0,0 +1,80 @@ +[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] +param () + +BeforeDiscovery { + try + { + if (-not (Get-Module -Name 'DscResource.Test')) + { + # Assumes dependencies has been resolved, so if this module is not available, run 'noop' task. + if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable)) + { + # Redirect all streams to $null, except the error stream (stream 2) + & "$PSScriptRoot/../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null + } + + # If the dependencies has not been resolved, this will throw an error. + Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop' + } + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.' + } +} + +BeforeAll { + $script:dscModuleName = 'SqlServerDsc' + + $env:SqlServerDscCI = $true + + Import-Module -Name $script:dscModuleName + + $PSDefaultParameterValues['InModuleScope:ModuleName'] = $script:dscModuleName + $PSDefaultParameterValues['Mock:ModuleName'] = $script:dscModuleName + $PSDefaultParameterValues['Should:ModuleName'] = $script:dscModuleName +} + +AfterAll { + $PSDefaultParameterValues.Remove('InModuleScope:ModuleName') + $PSDefaultParameterValues.Remove('Mock:ModuleName') + $PSDefaultParameterValues.Remove('Should:ModuleName') + + # Unload the module being tested so that it doesn't impact any other tests. + Get-Module -Name $script:dscModuleName -All | Remove-Module -Force + + Remove-Item -Path 'env:SqlServerDscCI' +} + +Describe 'SqlReason' -Tag 'SqlReason' { + Context 'When instantiating the class' { + It 'Should not throw an error' { + $script:mockSqlReasonInstance = InModuleScope -ScriptBlock { + [SqlReason]::new() + } + } + + It 'Should be of the correct type' { + $mockSqlReasonInstance | Should -Not -BeNullOrEmpty + $mockSqlReasonInstance.GetType().Name | Should -Be 'SqlReason' + } + } + + Context 'When setting an reading values' { + It 'Should be able to set value in instance' { + $script:mockSqlReasonInstance = InModuleScope -ScriptBlock { + $sqlReasonInstance = [SqlReason]::new() + + $sqlReasonInstance.Code = 'SqlAudit:SqlAudit:Ensure' + $sqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' + + return $sqlReasonInstance + } + } + + It 'Should be able read the values from instance' { + $mockSqlReasonInstance.Code | Should -Be 'SqlAudit:SqlAudit:Ensure' + $mockSqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"' + } + } +}