Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function Set-TargetResource
throw "Unable to get ACL for '$Path' as it does not exist"
}

$acl = Get-Acl -Path $Path
$acl = Get-ACLAccess -Path $Path
$accessRules = $acl.Access

if ($Ensure -eq "Present")
Expand Down Expand Up @@ -230,5 +230,9 @@ function Test-TargetResource

return $true
}
Function Get-ACLAccess($Path)
{
return (Get-Item -Path $Path).GetAccessControl('Access')
}

Export-ModuleMember -Function *-TargetResource
31 changes: 31 additions & 0 deletions Tests/Unit/MSFT_xFileSystemAccessRule.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ try
| Add-Member -MemberType ScriptMethod -Name "RemoveAccessRule" -Value {} -PassThru
}

Mock Get-ACLAccess {
return @{
Access = @()
} | Add-Member -MemberType ScriptMethod -Name "SetAccessRule" -Value {} -PassThru `
| Add-Member -MemberType ScriptMethod -Name "RemoveAccessRule" -Value {} -PassThru
}

It "should return absent from the get method" {
(Get-TargetResource @testParams).Ensure | Should Be "Absent"
}
Expand Down Expand Up @@ -70,6 +77,18 @@ try
| Add-Member -MemberType ScriptMethod -Name "RemoveAccessRule" -Value {} -PassThru
}

Mock Get-ACLAccess {
return @{
Access = @(
@{
IdentityReference = $testParams.Identity
FileSystemRights = [System.Security.AccessControl.FileSystemRights]::FullControl
}
)
} | Add-Member -MemberType ScriptMethod -Name "SetAccessRule" -Value {} -PassThru `
| Add-Member -MemberType ScriptMethod -Name "RemoveAccessRule" -Value {} -PassThru
}

It "should return present from the get method" {
(Get-TargetResource @testParams).Ensure | Should Be "Present"
}
Expand Down Expand Up @@ -129,6 +148,18 @@ try
| Add-Member -MemberType ScriptMethod -Name "RemoveAccessRule" -Value {} -PassThru
}

Mock Get-ACLAccess {
return @{
Access = @(
@{
IdentityReference = $testParams.Identity
FileSystemRights = [System.Security.AccessControl.FileSystemRights]::FullControl
}
)
} | Add-Member -MemberType ScriptMethod -Name "SetAccessRule" -Value {} -PassThru `
| Add-Member -MemberType ScriptMethod -Name "RemoveAccessRule" -Value {} -PassThru
}

It "should return present from the get method" {
(Get-TargetResource @testParams).Ensure | Should Be "Present"
}
Expand Down