|
55 | 55 | Context 'When the node does not belong to a cluster' { |
56 | 56 | BeforeAll { |
57 | 57 | Mock -CommandName Write-Warning |
58 | | - Mock -CommandName Get-Acl |
| 58 | + Mock -CommandName Get-ACLAccess |
59 | 59 |
|
60 | 60 | Mock -CommandName Test-Path -MockWith { |
61 | 61 | return $false |
|
67 | 67 | It 'Should not throw and output the correct warning message' { |
68 | 68 | { $script:result = Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw |
69 | 69 |
|
70 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 0 -Scope It |
| 70 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 0 -Scope It |
71 | 71 | Assert-MockCalled -CommandName Test-Path -Times 1 -Exactly -Scope It |
72 | 72 |
|
73 | 73 | Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { |
|
93 | 93 | Context 'When no cluster disk partition is found that uses the path' { |
94 | 94 | BeforeAll { |
95 | 95 | Mock -CommandName Write-Warning |
96 | | - Mock -CommandName Get-Acl |
| 96 | + Mock -CommandName Get-ACLAccess |
97 | 97 | Mock -CommandName Get-CimAssociatedInstance |
98 | 98 | Mock -CommandName Test-Path -MockWith { |
99 | 99 | return $false |
|
121 | 121 | It 'Should not throw and output the correct warning message' { |
122 | 122 | { $script:result = Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw |
123 | 123 |
|
124 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 0 -Scope It |
| 124 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 0 -Scope It |
125 | 125 | Assert-MockCalled -CommandName Test-Path -Times 1 -Exactly -Scope It |
126 | 126 |
|
127 | 127 | Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { |
|
158 | 158 | Context 'When the current node is not a possible cluster resource owner' { |
159 | 159 | BeforeAll { |
160 | 160 | Mock -CommandName Write-Warning |
161 | | - Mock -CommandName Get-Acl |
| 161 | + Mock -CommandName Get-ACLAccess |
162 | 162 | Mock -CommandName Test-Path -MockWith { |
163 | 163 | return $false |
164 | 164 | } |
|
208 | 208 | It 'Should not throw and output the correct warning message' { |
209 | 209 | { $script:result = Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw |
210 | 210 |
|
211 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 0 -Scope It |
| 211 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 0 -Scope It |
212 | 212 | Assert-MockCalled -CommandName Test-Path -Times 1 -Exactly -Scope It |
213 | 213 |
|
214 | 214 | Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { |
|
250 | 250 | Context 'When the configuration is present' { |
251 | 251 | Context 'When the path exists' { |
252 | 252 | BeforeAll { |
253 | | - Mock -CommandName Get-Acl -MockWith { |
| 253 | + Mock -CommandName Get-ACLAccess -MockWith { |
254 | 254 | return New-Object -TypeName PSObject | |
255 | 255 | Add-Member -MemberType 'NoteProperty' -Name 'Access' -Value @( |
256 | 256 | New-Object -TypeName PSObject | |
|
269 | 269 | It 'Should get the access rules without throwing' { |
270 | 270 | { $script:result = Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw |
271 | 271 |
|
272 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 1 -Scope It |
| 272 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 1 -Scope It |
273 | 273 | } |
274 | 274 |
|
275 | 275 | It 'Should return the state as present' { |
|
292 | 292 | Context 'When path is not found on the node, but the path is found in a cluster disk partition and the current node is a possible cluster resource owner' { |
293 | 293 | BeforeAll { |
294 | 294 | Mock -CommandName Write-Warning |
295 | | - Mock -CommandName Get-Acl |
| 295 | + Mock -CommandName Get-ACLAccess |
296 | 296 | Mock -CommandName Test-Path -MockWith { |
297 | 297 | return $false |
298 | 298 | } |
|
347 | 347 | It 'Should not throw and should not output a warning message' { |
348 | 348 | { $script:result = Get-TargetResource @mockGetTargetResourceParameters } | Should -Not -Throw |
349 | 349 |
|
350 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 0 -Scope It |
| 350 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 0 -Scope It |
351 | 351 | Assert-MockCalled -CommandName Test-Path -Times 1 -Exactly -Scope It |
352 | 352 |
|
353 | 353 | Assert-MockCalled -CommandName Get-CimInstance -ParameterFilter { |
|
659 | 659 | } -PassThru -Force |
660 | 660 | } |
661 | 661 |
|
662 | | - Mock -CommandName Get-Acl -MockWith $mockGetAcl |
| 662 | + Mock -CommandName Get-ACLAccess -MockWith $mockGetAcl |
663 | 663 | Mock -CommandName Set-Acl |
664 | 664 | } |
665 | 665 |
|
|
710 | 710 | It 'Should call the correct methods and mocks to remove the permissions' { |
711 | 711 | { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw |
712 | 712 |
|
713 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 1 -Scope It |
| 713 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 1 -Scope It |
714 | 714 |
|
715 | 715 | $script:SetAccessRuleMethodCallCount | Should -Be 0 |
716 | 716 | $script:PurgeAccessRulesMethodCallCount | Should -Be 0 |
|
731 | 731 | It 'Should call the correct methods and mocks to remove the permissions' { |
732 | 732 | { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw |
733 | 733 |
|
734 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 1 -Scope It |
| 734 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 1 -Scope It |
735 | 735 |
|
736 | 736 | $script:SetAccessRuleMethodCallCount | Should -Be 0 |
737 | 737 | $script:PurgeAccessRulesMethodCallCount | Should -Be 1 |
|
750 | 750 | It 'Should call the correct methods and mocks to remove the permissions' { |
751 | 751 | { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw |
752 | 752 |
|
753 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 1 -Scope It |
| 753 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 1 -Scope It |
754 | 754 |
|
755 | 755 | $script:SetAccessRuleMethodCallCount | Should -Be 0 |
756 | 756 | $script:PurgeAccessRulesMethodCallCount | Should -Be 1 |
|
771 | 771 | It 'Should call the correct methods and mocks to set the permissions' { |
772 | 772 | { Set-TargetResource @mockSetTargetResourceParameters } | Should -Not -Throw |
773 | 773 |
|
774 | | - Assert-MockCalled -CommandName Get-Acl -Exactly -Times 1 -Scope It |
| 774 | + Assert-MockCalled -CommandName Get-ACLAccess -Exactly -Times 1 -Scope It |
775 | 775 |
|
776 | 776 | $script:SetAccessRuleMethodCallCount | Should -Be 1 |
777 | 777 | $script:PurgeAccessRulesMethodCallCount | Should -Be 0 |
|
799 | 799 | } |
800 | 800 | } |
801 | 801 | } |
| 802 | + |
| 803 | + Describe 'DSC_FileSystemAccessRule\Get-ACLAccess' -Tag 'Helper' { |
| 804 | + BeforeAll { |
| 805 | + Mock -CommandName Get-Item -MockWith { |
| 806 | + return New-Object -TypeName PSObject | |
| 807 | + Add-Member -MemberType 'ScriptMethod' -Name 'GetAccessControl' -Value { |
| 808 | + return New-Object -TypeName PSObject | |
| 809 | + # Regression test for issue #3 |
| 810 | + Add-Member -MemberType 'NoteProperty' -Name 'Owner' -Value $null -PassThru | |
| 811 | + Add-Member -MemberType 'NoteProperty' -Name 'Access' -Value @( |
| 812 | + New-Object -TypeName PSObject | |
| 813 | + Add-Member -MemberType 'NoteProperty' -Name 'IdentityReference' -Value $mockIdentity -PassThru | |
| 814 | + Add-Member -MemberType 'NoteProperty' -Name 'FileSystemRights' -Value $mockFileSystemRights -PassThru -Force |
| 815 | + ) -PassThru -Force |
| 816 | + } -PassThru -Force |
| 817 | + } |
| 818 | + } |
| 819 | + |
| 820 | + It 'Should return the correct access control list (ACL)' { |
| 821 | + $result = Get-ACLAccess -Path 'AnyPath' |
| 822 | + |
| 823 | + $result.Access[0].IdentityReference | Should -Be $mockIdentity |
| 824 | + $result.Access[0].FileSystemRights | Should -Be $mockFileSystemRights |
| 825 | + |
| 826 | + # Regression test for issue #3 |
| 827 | + $result.Owner | Should -BeNullOrEmpty |
| 828 | + } |
| 829 | + } |
802 | 830 | } |
803 | 831 | } |
804 | 832 | finally |
|
0 commit comments