Skip to content

Commit

Permalink
SqlDatabasePermission: Fix Credential property
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Dec 6, 2023
1 parent 22b25f6 commit 9d65897
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix sort to get the latest version
- `Assert-Feature`
- Fixed unit tests.
- SqlDatabasePermission
- Now correctly return the username in the property `Credential`.

### Changed

Expand Down
20 changes: 16 additions & 4 deletions source/Classes/020.SqlDatabasePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,22 @@ class SqlDatabasePermission : SqlResourceBase
return an empty PSCredential-object. Kept it here so it at least
return a Credential object.
#>
$currentStateCredential = [PSCredential]::new(
$this.Credential.UserName,
[SecureString]::new()
)
# $currentStateCredential = [PSCredential]::new(
# $this.Credential.UserName,
# [SecureString]::new()
# )

$newCimInstanceParameters = @{
ClassName = 'MSFT_Credential'
ClientOnly = $true
Namespace = 'root/microsoft/windows/desiredstateconfiguration'
Property = @{
UserName = [System.String] $this.Credential.UserName
Password = ''#$null
}
}

$currentStateCredential = New-CimInstance @newCimInstanceParameters
}

$currentState = @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016',
$grantState.Permission | Should -Contain 'Connect'
$grantState.Permission | Should -Contain 'Select'
$grantState.Permission | Should -Contain 'CreateTable'

$resourceCurrentState.Credential | Should -BeOfType [PSCredential]
$resourceCurrentState.Credential.Username | Should -Be 'SqlAdmin'
$resourceCurrentState.Credential.Password | Should -BeNullOrEmpty
}

It 'Should return $true when Test-DscConfiguration is run' {
Expand Down Expand Up @@ -725,6 +729,10 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016',
$resourceCurrentState.Reasons | Should -HaveCount 1
$resourceCurrentState.Reasons[0].Code | Should -Be 'SqlDatabasePermission:SqlDatabasePermission:Permission'
$resourceCurrentState.Reasons[0].Phrase | Should -Be 'The property Permission should be [{"State":"Grant","Permission":["connect","update","alter"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}], but was [{"State":"Grant","Permission":["Connect"]},{"State":"GrantWithGrant","Permission":[]},{"State":"Deny","Permission":[]}]'

$resourceCurrentState.Credential | Should -BeOfType [PSCredential]
$resourceCurrentState.Credential.Username | Should -Be 'SqlAdmin'
$resourceCurrentState.Credential.Password | Should -BeNullOrEmpty
}

It 'Should run method Test() and return the state as $false' {
Expand Down

0 comments on commit 9d65897

Please sign in to comment.