Skip to content

Commit

Permalink
[#1669] CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bozho committed Oct 12, 2021
1 parent e6d41d8 commit fec6c6d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- SqlLogin
- `LoginMustChangePassword`, `LoginPasswordExpirationEnabled` and `LoginPasswordPolicyEnforced`
- BREAKING CHANGE: `LoginMustChangePassword`, `LoginPasswordExpirationEnabled` and `LoginPasswordPolicyEnforced`
parameters no longer enforce default values ([issue #1669](https://github.com/dsccommunity/SqlServerDsc/issues/1669)).

## [15.2.0] - 2021-09-01
Expand Down
99 changes: 72 additions & 27 deletions tests/Integration/DSC_SqlLogin.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -514,30 +514,78 @@ try
} | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser4Name
$resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser4Type
$resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeTrue
$resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeFalse
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

It 'Should allow SQL Server, login username and password to connect to SQL Instance (using SqlConnection.Open())' {
$serverName = $ConfigurationData.AllNodes.ServerName
$instanceName = $ConfigurationData.AllNodes.InstanceName
$databaseName = $ConfigurationData.AllNodes.DefaultDbName
$userName = $ConfigurationData.AllNodes.DscUser4Name
$password = $ConfigurationData.AllNodes.DscUser4Pass1 # Original password
Wait-ForIdleLcm -Clear

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName
# Reset LoginPasswordExpirationEnabled and LoginPasswordExpirationEnabled flags
$configurationName = "$($script:dscResourceName)_UpdateLoginDscUser4_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$sqlConnection.Open()
$sqlConnection.Close()
$configurationParameters = @{
OutputPath = $TestDrive
# The variable $ConfigurationData was dot-sourced above.
ConfigurationData = $ConfigurationData
}

& $configurationName @configurationParameters

$startDscConfigurationParameters = @{
Path = $TestDrive
ComputerName = 'localhost'
Wait = $true
Verbose = $true
Force = $true
ErrorAction = 'Stop'
}

Start-DscConfiguration @startDscConfigurationParameters
} | Should -Not -Throw
}

It 'Should be able to call Get-DscConfiguration without throwing' {
{
$script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop
} | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser4Name
$resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser4Type
$resourceCurrentState.Disabled | Should -Be $false
$resourceCurrentState.LoginMustChangePassword | Should -Be $false # Left the same as this cannot be updated
$resourceCurrentState.LoginPasswordExpirationEnabled | Should -Be $false
$resourceCurrentState.LoginPasswordPolicyEnforced | Should -Be $false
}
}

Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_UpdateLoginDscUser4_UpdateLoginDscUser4_Config_LoginPasswordPolicyEnforced"
$configurationName = "$($script:dscResourceName)_UpdateLoginDscUser4_Config_LoginPasswordPolicyEnforced"

Context ('When using configuration {0} (to update back to original password)' -f $configurationName) {
It 'Should re-compile and re-apply the MOF without throwing' {
Expand Down Expand Up @@ -569,24 +617,21 @@ try
} | Should -Not -Throw
}

It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}

It 'Should allow SQL Server, login username and password to connect to SQL Instance (using SqlConnection.Open())' {
$serverName = $ConfigurationData.AllNodes.ServerName
$instanceName = $ConfigurationData.AllNodes.InstanceName
$databaseName = $ConfigurationData.AllNodes.DefaultDbName
$userName = $ConfigurationData.AllNodes.DscUser4Name
$password = $ConfigurationData.AllNodes.DscUser4Pass1 # Original password
It 'Should have set the resource and all the parameters should match' {
$resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq $configurationName `
-and $_.ResourceId -eq $resourceId
}

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName
$resourceCurrentState.Ensure | Should -Be 'Present'
$resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser4Name
$resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser4Type
$resourceCurrentState.LoginPasswordExpirationEnabled | Should -BeFalse
$resourceCurrentState.LoginPasswordPolicyEnforced | Should -BeTrue
}

{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$sqlConnection.Open()
$sqlConnection.Close()
} | Should -Not -Throw
It 'Should return $true when Test-DscConfiguration is run' {
Test-DscConfiguration -Verbose | Should -Be 'True'
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/DSC_SqlLogin.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ Configuration DSC_SqlLogin_UpdateLoginDscUser4_Config_LoginPasswordExpirationEna
{
Ensure = 'Present'
Name = $Node.DscUser4Name
LoginType = $Node.DscUser4Type
LoginPasswordExpirationEnabled = $true

ServerName = $Node.ServerName
Expand All @@ -350,6 +351,7 @@ Configuration DSC_SqlLogin_UpdateLoginDscUser4_Config_LoginPasswordPolicyEnforce
{
Ensure = 'Present'
Name = $Node.DscUser4Name
LoginType = $Node.DscUser4Type
LoginPasswordPolicyEnforced = $true

ServerName = $Node.ServerName
Expand Down

0 comments on commit fec6c6d

Please sign in to comment.