Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlLogin: Added and amended integration tests for logins of 'SqlLogin' type (Fixes #361, #792, #1032, #1050, #1634) #1652

Merged
merged 71 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
1918a9c
Added 'FailedToObtainServerInstance' string
SphenicPaul Dec 13, 2020
557c9e7
Added condition in 'Get-ServerProtocolObject' to throw exception if $…
SphenicPaul Dec 13, 2020
fbcaf5b
Updated changelog to add issue #1628 fix comments (and correct typo)
SphenicPaul Dec 13, 2020
a3dd55f
Updated 'FailedToObtainServerInstance' error message
SphenicPaul Dec 13, 2020
8a06161
Updated 'Get-ServerProtocolObject' to pass $ServerName into 'FailedTo…
SphenicPaul Dec 13, 2020
a7c62d3
Merge branch 'master' of https://github.com/dsccommunity/SqlServerDsc
SphenicPaul Dec 13, 2020
cdd1197
Merge branch 'master' of https://github.com/dsccommunity/SqlServerDsc
SphenicPaul Dec 14, 2020
e66174b
Updated 'DSC_SqlLogin_AddLoginDscUser4_Config' to create login as 'Ds…
SphenicPaul Dec 14, 2020
9dd2d99
Added 'DSC_SqlLogin_UpdateLoginDscUser4_Config', integration test con…
SphenicPaul Dec 14, 2020
34691d4
Removed 'Admin_Password2' configuration property and made use of 'Dsc…
SphenicPaul Dec 14, 2020
3d7d15c
Added 'SqlDatabaseUser' resource into 'DSC_SqlLogin_AddLoginDscUser4_…
SphenicPaul Dec 14, 2020
092554b
Added 'DefaultDatabase' property assignment to 'DSC_SqlLogin_AddLogin…
SphenicPaul Dec 14, 2020
bfe3a4a
Added integration tests for 'SqlLogin_AddLoginDscUser4_Config' to ens…
SphenicPaul Dec 14, 2020
c73b168
Added 'SqlLogin_UpdateLoginDscUser4_Config', integration tests (simil…
SphenicPaul Dec 14, 2020
768999d
Added 'LoginMustChangePassword', 'LoginPasswordExpirationEnabled' and…
SphenicPaul Dec 14, 2020
9845c11
Added incorrectly merged changes to 'SqlServerDsc.Common.Tests.ps1'
SphenicPaul Dec 14, 2020
e79b349
Added incorrectly merged 'FailedToObtainServerInstance' value to 'sv-…
SphenicPaul Dec 14, 2020
c3f3841
Updated 'Test-TargetResource' for 'SqlLogin' resource to return $fals…
SphenicPaul Dec 14, 2020
8320a6b
Added 'DSC_SqlLogin\Test-TargetResource' unit test for when 'Get-Targ…
SphenicPaul Dec 14, 2020
30ed056
Updated changelog to include 'SqlLogin` fixes for #792
SphenicPaul Dec 14, 2020
0e43b48
Updated 'SqlLogin', 'Test-TargetResource' to cater for an existing, '…
SphenicPaul Dec 14, 2020
d159c78
Updated $Disabled in 'SqlLogin' back to original, 'Test-TargetResourc…
SphenicPaul Dec 14, 2020
97fc2c5
Added/Used 'DscUser4DbRole' property and 'Integration_Test_SqlRole', …
SphenicPaul Dec 15, 2020
b19cb50
Updated 'SqlLogin' tests to use 'ServerName' (not 'NodeName') and inc…
SphenicPaul Dec 15, 2020
44858e5
Updated 'SqlLogin' connection strings in 'SqlLogin', integration tests.
SphenicPaul Dec 15, 2020
996b8be
Added $sqlConnection.Close() to the 'SqlLogin' integration tests to c…
SphenicPaul Dec 15, 2020
4693871
Removed 'SqlLogin' tests using 'Connect-SQL'
SphenicPaul Dec 15, 2020
1534d32
Updated 'SqlLogin', integration test, 'DSC_SqlLogin_UpdateLoginDscUse…
SphenicPaul Dec 15, 2020
a88ee76
Added 'MustChangePasswordCannotBeChanged' string to 'SqlLogin', resou…
SphenicPaul Dec 15, 2020
9e89942
Added condition to 'SqlLogin' resource to throw exception if 'MustCha…
SphenicPaul Dec 15, 2020
c323da5
Added unit test for 'SqlLogin' when 'MustChangePassword' is to be upd…
SphenicPaul Dec 15, 2020
5b98d96
Corrected formatting of 'SqlLogin' integration test assertion.
SphenicPaul Dec 15, 2020
61ec7c4
Corrected 'SqlLogin', 'LoginMustChangePassword' test assertion within…
SphenicPaul Dec 15, 2020
bed3fcb
Updated 'SqlLogin', unit tests to ensure that 'LoginMustChangePasswor…
SphenicPaul Dec 15, 2020
c3e950e
Updated 'CHANGELOG.md' to include 'LoginMustChangePassword' change/up…
SphenicPaul Dec 15, 2020
38c8c4a
Updated 'DSC_SqlLogin.schema.mof' to include note around inability to…
SphenicPaul Dec 15, 2020
9b6a6bb
Updated 'SqlLogin', 'README.md' to include description around 'LoginM…
SphenicPaul Dec 15, 2020
3d15820
Updated 'LoginMustChangePassword' parameter description on 'SqlLogin'…
SphenicPaul Dec 15, 2020
a6112af
Added 'Clear' switch into 'Wait-ForIdleLcm', test helper method.
SphenicPaul Dec 15, 2020
e892b0d
Added '-Clear' switch to 'Wait-ForIdleLcm' function calls within 'Sql…
SphenicPaul Dec 15, 2020
f12845e
Added cleanup functionality prior to dropping database within 'SqlLog…
SphenicPaul Dec 15, 2020
6ba3bf4
Updated 'SqlLogin', integration test, database pre-tidy up to set 'Se…
SphenicPaul Dec 16, 2020
e776cf0
Added import of 'SqlServer' module into 'SqlLogin' integration tests.
SphenicPaul Dec 16, 2020
0aa342e
Updated 'SqlLogin', integration tests to take default database offlin…
SphenicPaul Dec 16, 2020
ee691e9
Updated 'SqlLogin' integration tests to move database tidy up into 'C…
SphenicPaul Dec 16, 2020
6c4c3ca
Updated 'DscUser4DbRole' to 'DscUser4Role' in 'SqlAdmin', integration…
SphenicPaul Dec 16, 2020
61ab3fb
Updated username and password for 'CleanupDependencies' configuration…
SphenicPaul Dec 16, 2020
44296ef
Added line to 'SqlLogin' to trigger integration tests
SphenicPaul Dec 17, 2020
0db46c0
Updated 'SqlLogin' to add missing 'Context' curly bracket
SphenicPaul Dec 17, 2020
1f3d7c3
Updated 'DscUser4Pass1' and 'DscUser4Pass2' properties in 'SqlLogin',…
SphenicPaul Jan 10, 2021
c544ad2
Added addition 'SqlLogin', integration tests to update the 'DscUser4'…
SphenicPaul Jan 10, 2021
4f63fe2
Added additional note around 'DscUser4' password change into integrat…
SphenicPaul Jan 10, 2021
392df9c
Updated names of 2 'SqlLogin', integration tests to update 'to correc…
SphenicPaul Jan 10, 2021
7b9090b
Updated 'SqlLogin' documentation to attempt to clarify functionality …
SphenicPaul Jan 10, 2021
c2ef2e1
Updated 'CHANGELOG' to reflect newer releases and additional 'SqlLogi…
SphenicPaul Jan 10, 2021
326d424
Merge pull request #1 from dsccommunity/main
SphenicPaul Jan 10, 2021
8ee45cd
Merge branch 'main' into pjw-issue361-sqlLoginUpdateTests
SphenicPaul Jan 10, 2021
794c07d
Updated 'CleanupDependencies', 'SqlLogin' integration test to use ori…
SphenicPaul Jan 10, 2021
8d1426c
Removed '$null -eq $loginInfo' condition/check from 'SqlLogin' resource.
SphenicPaul Jan 10, 2021
2c54fa2
Removed 'DSC_SqlLogin\Test-TargetResource', unit test that asserts ar…
SphenicPaul Jan 10, 2021
855ffca
Updated $sqlStatement variable assignment to use single quotes.
SphenicPaul Jan 11, 2021
d39ee7a
Removed incorrect '15.0.1' heading from 'CHANGELOG.md'
SphenicPaul Jan 11, 2021
c8e1123
Moved 3, $sqlConnection = New-Object assignments into 'Should -Not -T…
SphenicPaul Jan 11, 2021
25c275b
Updated '...to connect to correct, SQL instance, default database', '…
SphenicPaul Jan 11, 2021
31303e8
Updated second, 'AddLoginDscUser4_Config' comment to use comment bloc…
SphenicPaul Jan 11, 2021
9a3ddcb
Added 'When preparing database, dependencies cleanup' context to 'Sql…
SphenicPaul Jan 11, 2021
b279b52
Removed, non-required brackets from 'When preparing database, depende…
SphenicPaul Jan 11, 2021
b6e8159
Reversed update order of 'PasswordExpirationEnabled' and 'PasswordPol…
SphenicPaul Jan 11, 2021
2b5434b
Updated 'CHANGELOG' to include reversing of 'PasswordExpirationEnable…
SphenicPaul Jan 11, 2021
d2db2e0
Added comments around the ordering of updates to 'PasswordExpirationE…
SphenicPaul Jan 11, 2021
d0d0120
Updated 'Set-TargetResource' in 'SqlLogin' to update 'PasswordPolicyE…
SphenicPaul Jan 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- SqlLogin
- Added functionality to throw exception if an update to the `LoginMustChangePassword`
value on an existing SQL Login is attempted. This functionality is not supported
by referenced, SQL Server Management Object (SMO), libraries and cannot be
supported directly by this module.
- Added integration tests to ensure that an added (or updated) `SqlLogin` can
connect into a SQL instance once added (or updated).
- Added integration tests to ensure that the default database connected to by
a `SqlLogin` is the same as specified in the resource's `DefaultDatabase`
property/parameter.

### Fixed

- SqlLogin
- Added integration tests to assert `LoginPasswordExpirationEnabled`,
`LoginPasswordPolicyEnforced` and `LoginMustChangePassword` properties/parameters
are applied and updated correctly. Similar integration tests also added to ensure
the password of the `SqlLogin` is updated if the password within the `SqlCredential`
value/object is changed ([issue #361](https://github.com/dsccommunity/SqlServerDsc/issues/361),
[issue #1032](https://github.com/dsccommunity/SqlServerDsc/issues/1032) and
[issue #1050](https://github.com/dsccommunity/SqlServerDsc/issues/1050)).
- Updated `SqlLogin`, integration tests to make use of amended `Wait-ForIdleLcm`,
helper function, `-Clear` switch usage to remove intermittent, integration
test failures ([issue #1634](https://github.com/dsccommunity/SqlServerDsc/issues/1634)).

## [15.0.1] - 2021-01-09

### Changed

- SqlServerDsc
- Renamed `master` branch to `main` ([issue #1660](https://github.com/dsccommunity/SqlServerDsc/issues/1660)).
- The module manifest property `DscResourcesToExport` now updates automatically
Expand Down
9 changes: 8 additions & 1 deletion source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function Get-TargetResource
The credential containing the password for a SQL Login. Only applies if the login type is SqlLogin.

.PARAMETER LoginMustChangePassword
Specifies if the login is required to have its password change on the next login. Only applies to SQL Logins. Default is $true.
Specifies if the login is required to have its password change on the next login. Only applies to SQL Logins. Does not update pre-existing SQL Logins. Default is $true.

.PARAMETER LoginPasswordExpirationEnabled
Specifies if the login password is required to expire in accordance to the operating system security policy. Only applies to SQL Logins. Default is $true.
Expand Down Expand Up @@ -194,6 +194,13 @@ function Set-TargetResource

if ( $login.LoginType -eq 'SqlLogin' )
{
# There is no way to update 'MustChangePassword' on existing login so must explicitly throw exception to avoid this functionality being assumed
if ( $login.MustChangePassword -ne $LoginMustChangePassword )
{
$errorMessage = $script:localizedData.MustChangePasswordCannotBeChanged
New-InvalidOperationException -Message $errorMessage
}

if ( $login.PasswordExpirationEnabled -ne $LoginPasswordExpirationEnabled )
{
Write-Verbose -Message (
Expand Down
2 changes: 1 addition & 1 deletion source/DSCResources/DSC_SqlLogin/DSC_SqlLogin.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DSC_SqlLogin : OMI_BaseResource
Values{"WindowsUser","WindowsGroup","SqlLogin","Certificate","AsymmetricKey","ExternalUser","ExternalGroup"}] String LoginType;
[Write, Description("The hostname of the _SQL Server_ to be configured. Default value is the current computer name.")] String ServerName;
[Write, EmbeddedInstance("MSFT_Credential"), Description("Specifies the password as a `[PSCredential]` object. Only applies to _SQL Logins_.")] String LoginCredential;
[Write, Description("Specifies if the login is required to have its password change on the next login. Only applies to _SQL Logins_. Default value is `$true`.")] Boolean LoginMustChangePassword;
[Write, Description("Specifies if the login is required to have its password change on the next login. Only applies to _SQL Logins_. Default value is `$true`. This cannot be updated on a pre-existing _SQL Login_ and any attempt to do this will throw an exception.")] Boolean LoginMustChangePassword;
[Write, Description("Specifies if the login password is required to expire in accordance to the operating system security policy. Only applies to _SQL Logins_. Default value is `$true`.")] Boolean LoginPasswordExpirationEnabled;
[Write, Description("Specifies if the login password is required to conform to the password policy specified in the system security policy. Only applies to _SQL Logins_. Default value is `$true`.")] Boolean LoginPasswordPolicyEnforced;
[Write, Description("Specifies if the login is disabled. Default value is `$false`.")] Boolean Disabled;
Expand Down
10 changes: 9 additions & 1 deletion source/DSCResources/DSC_SqlLogin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ for a SQL Server instance.

* Target machine must be running Windows Server 2012 or later.
* Target machine must be running SQL Server Database Engine 2012 or later.
* When the `LoginType` `'SqlLogin'` is used, then the login authentication
* When the `LoginType` of `'SqlLogin'` is used, then the login authentication
mode must have been set to `Mixed` or `Normal`. If set to `Integrated`
and error will be thrown.
* The `LoginMustChangePassword` property/parameter is only valid on a `SqlLogin`
where the `LoginType` property/parameter is set to `'SqlLogin'`.
* The `LoginMustChangePassword` property/parameter can **not** be used to change
this setting on a pre-existing `SqlLogin` - This property/parameter can only
be used when creating a new `SqlLogin` and where subsequent updates will
not be applied or, alternatively, when the desired state will not change (for example,
where `LoginMustChangePassword` is initially set to `$false` and will always
be set to `$false`).

## Known issues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ ConvertFrom-StringData @'
DropLoginFailed = Removal of the login '{0}' failed.
SetPasswordValidationFailed = Setting the password failed for the login '{0}' because of password validation error.
SetPasswordFailed = Setting the password failed for the login '{0}'.
MustChangePasswordCannotBeChanged = The '(Login)MustChangePassword' parameter cannot be updated on a login that is already present.
'@
217 changes: 210 additions & 7 deletions tests/Integration/DSC_SqlLogin.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ try
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_AddLoginDscUser1_Config"

Expand Down Expand Up @@ -117,7 +117,7 @@ try
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_AddLoginDscUser2_Config"

Expand Down Expand Up @@ -169,7 +169,7 @@ try
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_AddLoginDscUser3_Disabled_Config"

Expand Down Expand Up @@ -220,7 +220,7 @@ try
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_AddLoginDscUser4_Config"

Expand Down Expand Up @@ -264,14 +264,199 @@ try
$resourceCurrentState.Name | Should -Be $ConfigurationData.AllNodes.DscUser4Name
$resourceCurrentState.LoginType | Should -Be $ConfigurationData.AllNodes.DscUser4Type
$resourceCurrentState.Disabled | Should -Be $false
$resourceCurrentState.LoginMustChangePassword | Should -Be $false
$resourceCurrentState.LoginPasswordExpirationEnabled | Should -Be $true
$resourceCurrentState.LoginPasswordPolicyEnforced | Should -Be $true
}

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

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

{
$sqlConnection.Open()
$sqlConnection.Close()
} | Should -Not -Throw
}

It 'Should allow SQL Server, login username and password to connect to correct, SQL instance, default database' {
$serverName = $ConfigurationData.AllNodes.ServerName
$instanceName = $ConfigurationData.AllNodes.InstanceName
$userName = $ConfigurationData.AllNodes.DscUser4Name
$password = $ConfigurationData.AllNodes.DscUser4Pass1 # Original password

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;' -f $serverName, $instanceName, $userName, $password # Note: Not providing a database name
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection)

$sqlConnection.Open()
$sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $sqlCommand
$sqlDataSet = New-Object System.Data.DataSet
$sqlDataAdapter.Fill($sqlDataSet) | Out-Null
$sqlConnection.Close()

$sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_UpdateLoginDscUser4_Config"

Context ('When using configuration {0}' -f $configurationName) {
It 'Should compile and apply the MOF without throwing' {
{
$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
}

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

It 'Should allow SQL Server, login username and (changed) 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.DscUser4Pass2 # Changed password

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

{
$sqlConnection.Open()
$sqlConnection.Close()
} | Should -Not -Throw
}

It 'Should allow SQL Server, login username and (changed) password to connect to correct, SQL instance, default database' {
$serverName = $ConfigurationData.AllNodes.ServerName
$instanceName = $ConfigurationData.AllNodes.InstanceName
$userName = $ConfigurationData.AllNodes.DscUser4Name
$password = $ConfigurationData.AllNodes.DscUser4Pass2 # Changed password

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;' -f $serverName, $instanceName, $userName, $password # Note: Not providing a database name
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand('SELECT DB_NAME() as CurrentDatabaseName', $sqlConnection)

$sqlConnection.Open()
$sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $sqlCommand
$sqlDataSet = New-Object System.Data.DataSet
$sqlDataAdapter.Fill($sqlDataSet) | Out-Null
$sqlConnection.Close()

$sqlDataSet.Tables[0].Rows[0].CurrentDatabaseName | Should -Be $ConfigurationData.AllNodes.DefaultDbName
}
}


Wait-ForIdleLcm -Clear

# Note that this configuration has already been run within these Integration tests but is
# executed once more to reset the password back to the original one provided.
$configurationName = "$($script:dscResourceName)_AddLoginDscUser4_Config"

Context ('When using configuration {0} (to update back to original password)' -f $configurationName) {
It 'Should re-compile and re-apply the MOF without throwing' {
{
$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 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

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database={4};' -f $serverName, $instanceName, $userName, $password, $databaseName
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString

{
$sqlConnection.Open()
$sqlConnection.Close()
} | Should -Not -Throw
}
}

Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_AddLoginDscSqlUsers1_Config"

Expand Down Expand Up @@ -322,7 +507,7 @@ try
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_RemoveLoginDscUser3_Config"

Expand Down Expand Up @@ -372,11 +557,29 @@ try
}
}

Wait-ForIdleLcm
Wait-ForIdleLcm -Clear

$configurationName = "$($script:dscResourceName)_CleanupDependencies_Config"

Context ('When using configuration {0}' -f $configurationName) {


# Close any existing connections into the database before it is dropped
$serverName = $ConfigurationData.AllNodes.ServerName
$instanceName = $ConfigurationData.AllNodes.InstanceName
$userName = $ConfigurationData.AllNodes.DscUser4Name
$password = $ConfigurationData.AllNodes.DscUser4Pass1 # Using original password
$defaultDbName = $ConfigurationData.AllNodes.DefaultDbName

$sqlConnectionString = 'Data Source={0}\{1};User ID={2};Password={3};Connect Timeout=5;Database=master;' -f $serverName, $instanceName, $userName, $password
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $sqlConnectionString
$sqlStatement = "ALTER DATABASE [{0}] SET OFFLINE WITH ROLLBACK IMMEDIATE" -f $defaultDbName
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand($sqlStatement, $sqlConnection)
$sqlConnection.Open()
$sqlCommand.ExecuteNonQuery()
$sqlConnection.Close()


It 'Should compile and apply the MOF without throwing' {
{
$configurationParameters = @{
Expand Down
Loading