Skip to content

Bump OPA version from v1.3.0 to v1.4.2 and v1.5.1 (Do not merge) #1728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions .github/workflows/run_update_opa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
permissions:
contents: write
pull-requests: write
actions: write
defaults:
run:
shell: powershell
Expand Down Expand Up @@ -75,3 +76,22 @@ jobs:
-CurrentOpaVersion $CurrentOpaVersion `
-LatestOpaVersion $LatestOPAVersion `
-OpaVersionBumpBranch $OpaVersionBumpBranch

- name: Trigger smoke test workflow
if: steps.determine-update-required.outputs.updaterequired == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ steps.determine-update-required.outputs.opaversionbumpbranch }}
shell: pwsh
run: |
$headers = @{
Authorization = "Bearer $env:GITHUB_TOKEN"
Accept = "application/vnd.github+json"
}
$body = @{
ref = "$env:BRANCH_NAME"
} | ConvertTo-Json
Invoke-RestMethod -Method Post `
-Uri "https://api.github.com/repos/${{ github.repository }}/actions/workflows/run_smoke_test.yaml/dispatches" `
-Headers $headers `
-Body $body
2 changes: 1 addition & 1 deletion PowerShell/ScubaGear/Modules/ScubaConfig/ScubaConfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScubaConfig {
"Hybrid Identity Administrator",
"Application Administrator",
"Cloud Application Administrator")
DefaultOPAVersion = '1.3.0'
DefaultOPAVersion = '1.5.1'
}

static [object]ScubaDefault ([string]$Name){
Expand Down
3 changes: 2 additions & 1 deletion PowerShell/ScubaGear/Modules/Support/Support.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ function Install-OPAforSCuBA {
)

# Constants
$ACCEPTABLEVERSIONS = '0.69.0', '0.70.0', '1.0.1', '1.1.0', '1.2.0', [ScubaConfig]::ScubaDefault('DefaultOPAVersion') # End Versions
$ACCEPTABLEVERSIONS = '0.69.0', '0.70.0', '1.0.1', '1.1.0', '1.2.0',
'1.3.0', '1.4.2', [ScubaConfig]::ScubaDefault('DefaultOPAVersion') # End Versions
$FILENAME = @{ Windows = "opa_windows_amd64.exe"; MacOS = "opa_darwin_amd64"; Linux = "opa_linux_amd64_static"}

# Set preferences for writing messages
Expand Down
114 changes: 62 additions & 52 deletions Testing/RunUnitTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,50 @@

[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[ValidateSet('AAD','Defender','EXO','PowerPlatform','Sharepoint','Teams', '*')]
[Parameter(Mandatory = $false)]
[ValidateSet('AAD', 'Defender', 'EXO', 'PowerPlatform', 'Sharepoint', 'Teams', '*')]
[Alias('p')]
[string[]]$Products = '*',

[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[Alias('c')]
[string[]]$ControlGroups = '*',

[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[Alias('t')]
[string[]]$Tests = "*",

[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[Alias('v')]
[switch]$Verbosity,

[Parameter(Mandatory=$false)]
[ValidateScript({Test-Path -Path $_ -PathType Container})]
[Parameter(Mandatory = $false)]
[ValidateScript({ Test-Path -Path $_ -PathType Container })]
[string]
$ScubaParentDirectory = $env:USERPROFILE,

[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[switch]
$RunAsInstalled
$RunAsInstalled,

[Parameter(Mandatory = $false)]
[string]
$OPAPath
)

$ScubaHiddenHome = Join-Path -Path $ScubaParentDirectory -ChildPath '.scubagear'
$ScubaTools = Join-Path -Path $ScubaHiddenHome -ChildPath 'Tools'
$OPAExe = Join-Path -Path $ScubaTools -ChildPath 'opa_windows_amd64.exe'
if ($OPAPath) {
$OPAExe = Join-Path -Path $OPAPath -ChildPath 'opa_windows_amd64.exe'
}
$ScriptName = $MyInvocation.MyCommand
$RootPath = Join-Path -Path $PSScriptRoot -ChildPath '../PowerShell/ScubaGear'

if ($RunAsInstalled){
if ($null -ne (Get-Module -Name ScubaGear)){
if ($RunAsInstalled) {
if ($null -ne (Get-Module -Name ScubaGear)) {
$RootPath = Split-Path (Get-Module -Name ScubaGear).Path -Parent
}
else {
Expand All @@ -75,16 +82,16 @@ if ($RunAsInstalled){
}

$RegoUnitTestPath = Join-Path -Path $RootPath -ChildPath "Testing\Unit\Rego"
$UtilFilename = (Get-ChildItem $(Join-Path -Path $RootPath -ChildPath "Rego\Utils") | Where-Object {$_.Name -like "TestAssertions*" }).FullName
$UtilFilename = (Get-ChildItem $(Join-Path -Path $RootPath -ChildPath "Rego\Utils") | Where-Object { $_.Name -like "TestAssertions*" }).FullName
$RegoPolicyPath = Join-Path -Path $RootPath -ChildPath "Rego"

function Get-ErrorMsg {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string]$ErrorCode,

[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[string[]]$Arguments
)

Expand Down Expand Up @@ -124,23 +131,24 @@ function Get-ErrorMsg {
function Invoke-Products {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Flag,

[Parameter(Mandatory=$true)]
[ValidateSet('AAD','Defender','EXO','PowerPlatform','Sharepoint','Teams')]
[Parameter(Mandatory = $true)]
[ValidateSet('AAD', 'Defender', 'EXO', 'PowerPlatform', 'Sharepoint', 'Teams')]
[string[]]$Products
)

foreach($Product in $Products) {
foreach ($Product in $Products) {
Write-Output "`n======== Testing $Product ========"
$Directory = Join-Path -Path $RegoUnitTestPath -ChildPath $Product
$ConfigFilename = Get-ChildItem $(Join-Path -Path $RegoUnitTestPath -ChildPath $Product) |
Where-Object {$_.Name -like "*BaseConfig*" }
Where-Object { $_.Name -like "*BaseConfig*" }
if ($ConfigFilename.length -eq 0) {
& $OPAExe test $RegoPolicyPath $Directory .\$UtilFilename $Flag
} else {
}
else {
& $OPAExe test $RegoPolicyPath $Directory .\$($ConfigFilename.FullName) .\$UtilFilename $Flag
}
}
Expand All @@ -150,14 +158,14 @@ function Invoke-Products {
function Get-ControlGroup {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string] $ControlGroup
)

$Tens = @('01','02','03','04','05','06','07','08','09')
if(($ControlGroup -match "^\d+$") -or ($ControlGroup -in $Tens)) {
$Tens = @('01', '02', '03', '04', '05', '06', '07', '08', '09')
if (($ControlGroup -match "^\d+$") -or ($ControlGroup -in $Tens)) {
if ([int]$ControlGroup -lt 10) {
$ControlGroup = $Tens[[int]$ControlGroup-1]
$ControlGroup = $Tens[[int]$ControlGroup - 1]
}
return $true, $ControlGroup
}
Expand All @@ -167,35 +175,36 @@ function Get-ControlGroup {
function Invoke-ControlGroups {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Flag,

[Parameter(Mandatory=$true)]
[ValidateSet('AAD','Defender','EXO','PowerPlatform','Sharepoint','Teams')]
[Parameter(Mandatory = $true)]
[ValidateSet('AAD', 'Defender', 'EXO', 'PowerPlatform', 'Sharepoint', 'Teams')]
[string]$Product,

[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string[]]$ControlGroups
)

Write-Output "`n======== Testing $Product ========"
$ConfigFilename = Get-ChildItem $(Join-Path -Path $RegoUnitTestPath -ChildPath $Product) |
Where-Object {$_.Name -like "*BaseConfig*" }
foreach($ControlGroup in $ControlGroups) {
Where-Object { $_.Name -like "*BaseConfig*" }
foreach ($ControlGroup in $ControlGroups) {
$GroupNum = Get-ControlGroup $ControlGroup
if ($GroupNum[0]) {
$UnitTestFile = Get-ChildItem $(Join-Path -Path $RegoUnitTestPath -ChildPath $Product) |
Where-Object {$_.Name -like "*$($GroupNum[1])*" }
if ($UnitTestFile.length -eq 0){
Where-Object { $_.Name -like "*$($GroupNum[1])*" }
if ($UnitTestFile.length -eq 0) {
Write-Warning "`nNOT FOUND: Control Group $ControlGroup does not exist in the $Product directory"
}

elseif(Test-Path -Path $UnitTestFile.Fullname -PathType Leaf) {
elseif (Test-Path -Path $UnitTestFile.Fullname -PathType Leaf) {
Write-Output "# Testing Control Group $($GroupNum[1])"
if ($ConfigFilename.length -eq 0) {
& $OPAExe test $RegoPolicyPath .\$($UnitTestFile.Fullname) .\$UtilFilename $Flag
} else {
}
else {
& $OPAExe test $RegoPolicyPath .\$($UnitTestFile.Fullname) .\$($ConfigFilename.FullName) .\$UtilFilename $Flag
}
Write-Output "" | Out-Host
Expand All @@ -214,39 +223,40 @@ function Invoke-ControlGroups {
function Invoke-SpecificTests {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Flag,

[Parameter(Mandatory=$true)]
[ValidateSet('AAD','Defender','EXO','PowerPlatform','Sharepoint','Teams')]
[Parameter(Mandatory = $true)]
[ValidateSet('AAD', 'Defender', 'EXO', 'PowerPlatform', 'Sharepoint', 'Teams')]
[string]$Product,

[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string]$ControlGroup,

[Parameter(Mandatory=$true)]
[Parameter(Mandatory = $true)]
[string[]]$IndividualTests
)

Write-Output "`n======== Testing $Product ========"
$ConfigFilename = Get-ChildItem $(Join-Path -Path $RegoUnitTestPath -ChildPath $Product) |
Where-Object {$_.Name -like "*BaseConfig*" }
Where-Object { $_.Name -like "*BaseConfig*" }
$GroupNum = Get-ControlGroup $ControlGroup
if ($GroupNum[0]) {
$UnitTestFile = Get-ChildItem $(Join-Path -Path $RegoUnitTestPath -ChildPath $Product) |
Where-Object {$_.Name -like "*$($GroupNum[1])*" }
if ($UnitTestFile.length -eq 0){
Where-Object { $_.Name -like "*$($GroupNum[1])*" }
if ($UnitTestFile.length -eq 0) {
Write-Warning "`nNOT FOUND: Control Group $ControlGroup does not exist in the $Product directory"
}

elseif(Test-Path -Path $UnitTestFile.Fullname -PathType Leaf) {
elseif (Test-Path -Path $UnitTestFile.Fullname -PathType Leaf) {
Write-Output "# Testing Control Group $($GroupNum[1])"
foreach($Test in $IndividualTests) {
foreach ($Test in $IndividualTests) {
Write-Output "## Testing $Test"
if ($ConfigFilename.length -eq 0) {
& $OPAExe test $RegoPolicyPath .\$($UnitTestFile.Fullname) .\$UtilFilename -r $Test $Flag
} else {
}
else {
& $OPAExe test $RegoPolicyPath .\$($UnitTestFile.Fullname) .\$($ConfigFilename.FullName) .\$UtilFilename -r $Test $Flag
}
Write-Output "" | Out-Host
Expand All @@ -270,28 +280,28 @@ $Flag = ""
if ($Verbosity.IsPresent) {
$Flag = "-v"
}
if($pEmpty) {
Invoke-Products -Flag $Flag -Products @('AAD','Defender','EXO','PowerPlatform','Sharepoint','Teams')
if ($pEmpty) {
Invoke-Products -Flag $Flag -Products @('AAD', 'Defender', 'EXO', 'PowerPlatform', 'Sharepoint', 'Teams')
}
elseif((-not $pEmpty) -and (-not $cEmpty) -and (-not $tEmpty)) {
elseif ((-not $pEmpty) -and (-not $cEmpty) -and (-not $tEmpty)) {
if (($Products.Count -gt 1) -or ($ControlGroups.Count -gt 1)) {
Write-Output "**WARNING** can only take 1 argument for each: Products & Control Groups item`n...Running test for $($Products[0]) and $($ControlGroups[0]) only"
}

Invoke-SpecificTests -Flag $Flag -Product $Products[0] -ControlGroup $ControlGroups[0] -IndividualTests $Tests
}
elseif((-not $pEmpty) -and (-not $cEmpty) -and $tEmpty) {
elseif ((-not $pEmpty) -and (-not $cEmpty) -and $tEmpty) {
if ($Products.Count -gt 1) {
Write-Output "**WARNING** can only take 1 argument for Products`n...Running test for $($Products[0]) only"
}
Invoke-ControlGroups -Flag $Flag -Product $Products[0] -ControlGroup $ControlGroups
}
elseif((-not $pEmpty) -and $cEmpty -and $tEmpty) {
elseif ((-not $pEmpty) -and $cEmpty -and $tEmpty) {
Invoke-Products -Flag $Flag -Product $Products
}
elseif($pEmpty -or $cEmpty -and (-not $tEmpty)) {
elseif ($pEmpty -or $cEmpty -and (-not $tEmpty)) {
Get-ErrorMsg TestNameFlagMissingInfo
}
elseif($pEmpty -and (-not $cEmpty) -and $tEmpty) {
elseif ($pEmpty -and (-not $cEmpty) -and $tEmpty) {
Get-ErrorMsg ControlGroupFlagMissingInfo
}
Loading
Loading