"Fossies" - the Fresh Open Source Software Archive

Member "PowerShell-7.2.6/test/powershell/Modules/Microsoft.PowerShell.Security/AclCmdlets.Tests.ps1" (11 Aug 2022, 3402 Bytes) of package /linux/misc/PowerShell-7.2.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Microsoft PowerShell source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 # Copyright (c) Microsoft Corporation.
    2 # Licensed under the MIT License.
    3 Describe "Acl cmdlets are available and operate properly" -Tag CI {
    4     Context "Windows ACL test" {
    5         BeforeAll {
    6             $PSDefaultParameterValues["It:Skip"] = -not $IsWindows
    7         }
    8 
    9         It "Get-Acl returns an ACL DirectorySecurity object"  {
   10             $ACL = Get-Acl $TESTDRIVE
   11             $ACL | Should -BeOfType System.Security.AccessControl.DirectorySecurity
   12         }
   13 
   14         It "Get-Acl -LiteralPath HKLM:Software\Classes\*"  {
   15             $ACL = Get-Acl -LiteralPath HKLM:Software\Classes\*
   16             $ACL | Should -BeOfType System.Security.AccessControl.RegistrySecurity
   17         }
   18 
   19         It "Get-Acl -LiteralPath .\Software\Classes\*"  {
   20             $currentPath = Get-Location
   21             Set-Location -LiteralPath HKLM:\
   22             $ACL = Get-Acl -LiteralPath .\Software\Classes\*
   23             $ACL | Should -BeOfType System.Security.AccessControl.RegistrySecurity
   24             $currentPath | Set-Location
   25         }
   26 
   27         It "Get-Acl -LiteralPath ."  {
   28             $currentPath = Get-Location
   29             Set-Location -LiteralPath $TESTDRIVE
   30             $ACL = Get-Acl -LiteralPath .
   31             $ACL | Should -BeOfType System.Security.AccessControl.DirectorySecurity
   32             $currentPath | Set-Location
   33         }
   34 
   35         It "Get-Acl -LiteralPath .."  {
   36             $currentPath = Get-Location
   37             Set-Location -LiteralPath $TESTDRIVE
   38             $ACL = Get-Acl -LiteralPath ..
   39             $ACL | Should -BeOfType System.Security.AccessControl.DirectorySecurity
   40             $currentPath | Set-Location
   41         }
   42 
   43         It "Get-Acl -Path .\Software\Classes\"  {
   44             $currentPath = Get-Location
   45             Set-Location -LiteralPath HKLM:\
   46             $ACL = Get-Acl -Path .\Software\Classes\
   47             $ACL | Should -BeOfType System.Security.AccessControl.RegistrySecurity
   48             $currentPath | Set-Location
   49         }
   50 
   51         It "Get-Acl -Path ."  {
   52             $currentPath = Get-Location
   53             Set-Location -LiteralPath $TESTDRIVE
   54             $ACL = Get-Acl -Path .
   55             $ACL | Should -BeOfType System.Security.AccessControl.DirectorySecurity
   56             $currentPath | Set-Location
   57         }
   58 
   59         It "Get-Acl -Path .."  {
   60             $currentPath = Get-Location
   61             Set-Location -LiteralPath $TESTDRIVE
   62             $ACL = Get-Acl -Path ..
   63             $ACL | Should -BeOfType System.Security.AccessControl.DirectorySecurity
   64             $currentPath | Set-Location
   65         }
   66 
   67         It "Set-Acl can set the ACL of a directory" {
   68             Setup -d testdir
   69             $directory = "$TESTDRIVE/testdir"
   70             $acl = Get-Acl $directory
   71             $accessRule = [System.Security.AccessControl.FileSystemAccessRule]::New("Everyone","FullControl","ContainerInherit,ObjectInherit","None","Allow")
   72             $acl.AddAccessRule($accessRule)
   73             { $acl | Set-Acl $directory } | Should -Not -Throw
   74 
   75             $newacl = Get-Acl $directory
   76             $newrule = $newacl.Access | Where-Object { $accessrule.FileSystemRights -eq $_.FileSystemRights -and $accessrule.AccessControlType -eq $_.AccessControlType -and $accessrule.IdentityReference -eq $_.IdentityReference }
   77             $newrule | Should -Not -BeNullOrEmpty
   78         }
   79 
   80         AfterAll {
   81             $PSDefaultParameterValues.Remove("It:Skip")
   82         }
   83     }
   84 }