Skip to content

Commit

Permalink
Fix RestSetAcls compatibility with PowerShell 5 (#248)
Browse files Browse the repository at this point in the history
* Add PowerShell 5 to test matrix

* Change test run names

* Fix compatibility issues with PowerShell 5

* Fix build dependency on Az.Storage

* Fix local publish script for Az.Storage 8.0.0

* Improve name of PSScriptAnalyzer test stage
  • Loading branch information
MaximeKjaer authored Jan 22, 2025
1 parent bd8f56f commit de069a2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/RestSetAcls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
pester-test:
name: Pester test
name: Pester test on PowerShell 7
runs-on: windows-latest
defaults:
run:
Expand All @@ -20,13 +20,32 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Print PowerShell version
run: $PSVersionTable
- name: Run all Pester tests
run: |
.\init.ps1
Test
pester-test-powershell-5:
name: Pester test on PowerShell 5.1
runs-on: windows-latest
defaults:
run:
working-directory: .\RestSetAcls
shell: powershell
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Print PowerShell version
run: $PSVersionTable
- name: Run all Pester tests
run: |
.\init.ps1
Test
test-format:
name: Test PowerShell formatting
name: Check PowerShell formatting
runs-on: windows-latest
defaults:
run:
Expand Down Expand Up @@ -55,7 +74,7 @@ jobs:
Test-Manifest
lint-with-PSScriptAnalyzer:
name: Install and run PSScriptAnalyzer
name: Lint with PSScriptAnalyzer
runs-on: windows-latest
defaults:
run:
Expand Down
8 changes: 4 additions & 4 deletions RestSetAcls/RestSetAcls/SddlUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function Get-AllAceFlagsMatch {
)

foreach ($ace in $SecurityDescriptor.DiscretionaryAcl) {
$hasAllBitsFromEnabledFlags = ($ace.AceFlags -band $EnabledFlags) -eq $EnabledFlags
$hasNoBitsFromDisabledFlags = ($ace.AceFlags -band $DisabledFlags) -eq 0
$hasAllBitsFromEnabledFlags = ([int]$ace.AceFlags -band [int]$EnabledFlags) -eq [int]$EnabledFlags
$hasNoBitsFromDisabledFlags = ([int]$ace.AceFlags -band [int]$DisabledFlags) -eq 0
if (-not ($hasAllBitsFromEnabledFlags -and $hasNoBitsFromDisabledFlags)) {
return $false
}
Expand All @@ -61,13 +61,13 @@ function Set-AceFlags {
[System.Security.AccessControl.AceFlags]$DisableFlags
)

if ($EnableFlags -band $DisableFlags) {
if ([int]$EnableFlags -band [int]$DisableFlags) {
throw "Enable and disable flags cannot overlap"
}

# Create new ACEs with updated flags
$newAces = $SecurityDescriptor.DiscretionaryAcl | ForEach-Object {
$aceFlags = ($_.AceFlags -bor $EnableFlags) -band (-bnot $DisableFlags)
$aceFlags = ([int]$_.AceFlags -bor [int]$EnableFlags) -band (-bnot [int]$DisableFlags)

if ($_.GetType().Name -eq "CommonAce") {
[System.Security.AccessControl.CommonAce]::new(
Expand Down
2 changes: 1 addition & 1 deletion RestSetAcls/build.depend.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

Pester = 'latest'
PSScriptAnalyzer = 'latest'
'Az.Storage' = '6.0.0'
'Az.Storage' = '8.1.0'
}
2 changes: 1 addition & 1 deletion RestSetAcls/publish-tools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Publish-Local {
Write-Host "Done" -ForegroundColor Gray

Write-Host "`nInstalling $moduleName from $repoName" -ForegroundColor White
Install-Module -Name $moduleName -Repository $repoName -Force
Install-Module -Name $moduleName -Repository $repoName -AllowClobber -Force
Write-Host "Done" -ForegroundColor Gray
}

Expand Down

0 comments on commit de069a2

Please sign in to comment.