From 33619da936fc53939e33567c83bdefd6c9c678c9 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Thu, 2 Jan 2025 15:58:00 -0700 Subject: [PATCH 1/4] Update Policy Results Tests to run without SetupOrg --- .../Get-JCPolicyResult.Tests.ps1 | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.Tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.Tests.ps1 index f1af4be84..bd50e05e5 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.Tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Policies/PolicyResults/Get-JCPolicyResult.Tests.ps1 @@ -1,25 +1,52 @@ -# TODO: rewrite these failing tests in CUT-4546 -Describe -Tag:('JCPolicyResult') "Get-JCPolicyResult 1.10" -skip { - BeforeAll { } +Describe -Tag:('JCPolicyResult') "Get-JCPolicyResult 1.10" { + BeforeAll { + $allSystems = Get-JCSystem + # get an active linux system + $activeLinuxSystem = $allSystems | Where-Object { ($_.active -eq $true) -And ($_.osFamily -eq 'linux') } + # create a policy to test the + $policyName = "Pester-$(new-randomString -numberOfChars 6)" + $linuxHardeningPolicy = New-JCPolicy -TemplateName linux_Additional_Process_Hardening -core_dumps_restricted $true -aslr_enabled $false -prelink_disabled $false -XD_NX_support_enabled $false -Name $policyName + Set-JcSdkPolicyAssociation -PolicyId $linuxHardeningPolicy.id -Id $activeLinuxSystem.id -Op "add" -Type 'system' + + # loop with timeout to check for policy result: + $policyResult = Get-JCPolicyResult $policyName + if (-Not $policyResult.Id) { + $wait = 10 + $i = 0 + $timeout = $false + do { + $policyResult = Get-JCPolicyResult $policyName + if ($i -ne 10) { + Write-Output "waiting $wait seconds| i: $i to: $timeout $($policyResult.id)" + Start-Sleep -Seconds $wait + } else { + break + } + $i++ + } until ( + (-Not [System.String]::IsNullOrEmpty($($policyResult.id))) + ) + } + } It "Returns a policy result with the PolicyName" { - $PolicyResult = Get-JCPolicyResult $PesterParams_SinglePolicy.Name + $PolicyResult = Get-JCPolicyResult $linuxHardeningPolicy.Name $PolicyResult.count | Should -BeGreaterThan 0 } It "Returns a policy result with the PolicyId" { - $PolicyResult = Get-JCPolicyResult -PolicyId:($PesterParams_SinglePolicy.id) + $PolicyResult = Get-JCPolicyResult -PolicyId:($linuxHardeningPolicy.id) $PolicyResult.id.count | Should -BeGreaterThan 0 } It "Returns a policy result with the SystemID" { - $PolicyResult = Get-JCPolicyResult -SystemID:($PesterParams_SystemLinux._id) + $PolicyResult = Get-JCPolicyResult -SystemID:($activeLinuxSystem._id) $PolicyResult.id.count | Should -BeGreaterThan 0 } It "Returns a policy result using the -ByPolicyID switch parameter via the pipeline" { - $PolicyResultVar = Get-JCPolicyResult -PolicyId:($PesterParams_SinglePolicy.id) + $PolicyResultVar = Get-JCPolicyResult -PolicyId:($linuxHardeningPolicy.id) $PolicyResult = $PolicyResultVar | Get-JCPolicyResult -ByPolicyID @@ -29,7 +56,7 @@ Describe -Tag:('JCPolicyResult') "Get-JCPolicyResult 1.10" -skip { It "Returns a policy using the -BySystemID switch parameter via the pipeline " { - $PolicyResultVar = Get-JCPolicyResult -PolicyId:($PesterParams_SinglePolicy.id) + $PolicyResultVar = Get-JCPolicyResult -PolicyId:($linuxHardeningPolicy.id) $PolicyResult = $PolicyResultVar | Get-JCPolicyResult -BySystemID From f3180c6383d165ea9a0429fbb336018b78b8a948 Mon Sep 17 00:00:00 2001 From: Geoffrey Wein Date: Fri, 3 Jan 2025 12:35:35 -0700 Subject: [PATCH 2/4] check for emails with 'del' --- PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 b/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 index 63b65aff1..d7f49c2b9 100644 --- a/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 +++ b/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1 @@ -36,7 +36,7 @@ Try { ) # Remove all users from an org If ($Users) { - $NonExternallyManagedUsersToRemove = Get-JCUser | Where-Object { ($_.Email -like '*delete*' -or $_.Email -like '*pester*') -and -not $_.externally_managed } + $NonExternallyManagedUsersToRemove = Get-JCUser | Where-Object { ($_.Email -like '*delete*' -or $_.Email -like '*del*' -or $_.Email -like '*pester*') -and -not $_.externally_managed } $RemoveNonExternallyManagedUsers = $NonExternallyManagedUsersToRemove | Remove-JCUser -force $ExternallyManagedUsersToRemove = Get-JCUser | Where-Object { ($_.Email -like '*delete*' -or $_.Email -like '*pester*') -and $_.externally_managed } $UpdateExternallyManagedUsersToRemove = $ExternallyManagedUsersToRemove | Set-JCUser -externally_managed $false @@ -52,16 +52,16 @@ Try { If ($Groups) { $AllGroupsToRemove = Get-JCGroup foreach ($group in $allGroupsToRemove) { - write-host "Group Name: $($group.Name) $($group.id) $($group.type)" + Write-Host "Group Name: $($group.Name) $($group.id) $($group.type)" switch ($group.type) { 'system_group' { try { - Remove-JcSdkSystemGroup -Id $group.id -ErrorAction Ignore -errorVariable groupError + Remove-JcSdkSystemGroup -Id $group.id -ErrorAction Ignore -ErrorVariable groupError } catch { if ($groupError.ErrorRecord -Match "default macOS ADE device group") { - Set-JCsdkSystemGroup -Id $group.id -Name "MDM-$(Get-Random)" + Set-JcSdkSystemGroup -Id $group.id -Name "MDM-$(Get-Random)" } else { - Set-JCsdkSystemGroup -Id $group.id -Name "unknown-$(Get-Random)" + Set-JcSdkSystemGroup -Id $group.id -Name "unknown-$(Get-Random)" } } } @@ -208,8 +208,8 @@ Try { # Clean up unnecessary Radius Server Attributes to Export: $r1 = $variableArray | Where-Object { $_.name -eq 'PesterParams_RadiusAzureServer' } $r2 = $variableArray | Where-Object { $_.name -eq 'PesterParams_RadiusServer' } -$r1.value | % { $_.psobject.properties.remove('httpMetaData') } -$r2.value | % { $_.psobject.properties.remove('httpMetaData') } +$r1.value | ForEach-Object { $_.psobject.properties.remove('httpMetaData') } +$r2.value | ForEach-Object { $_.psobject.properties.remove('httpMetaData') } -write-Host "[Status] Exporting $($variableArray.count) variables from setupOrg" +Write-Host "[Status] Exporting $($variableArray.count) variables from setupOrg" Return $variableArray From 542e71b98417c2f369e908ecfd273d09a888d76a Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Fri, 3 Jan 2025 13:05:19 -0700 Subject: [PATCH 3/4] changlog + version date --- PowerShell/JumpCloud Module/JumpCloud.psd1 | 2 +- PowerShell/ModuleChangelog.md | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index ef55a8e7a..cd1ebbf1b 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.psd1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psd1 @@ -3,7 +3,7 @@ # # Generated by: JumpCloud Solutions Architect Team # -# Generated on: 1/2/2025 +# Generated on: 1/3/2025 # @{ diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 06bcd345f..9eb97dea3 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,6 +1,6 @@ ## 2.17.0 -Release Date: January 2, 2025 +Release Date: January 03, 2025 #### RELEASE NOTES @@ -11,8 +11,8 @@ This release introduces two new functions `New-JCReport` and `Get-JCReport` #### FEATURES: - Introduces two new functions `New-JCReport` and `Get-JCReport` - - `New-JCReport` - Generates a report using the pre-built report generators available in the console - - `Get-JCReport` - Allows you get get the report metadata and once the report is finished processing, using the reportID and the artifactID, you can output the report content via JSON or CSV + - `New-JCReport` - Generates a report using the pre-built report generators available in the console + - `Get-JCReport` - Allows you get get the report metadata and once the report is finished processing, using the reportID and the artifactID, you can output the report content via JSON or CSV ## 2.16.0 @@ -28,13 +28,14 @@ This release introduces a bug fix for `Import-JCUsersFromCSV` and `Update-JCUser #### FEATURES: - Introduces the `Update-JCDeviceFromCSV` and `New-JCDeviceUpdateTemplate` functions - - `New-JCDeviceUpdateTemplate`: Creates a csv template used for bulk updating devices - - `Update-JCDeviceFromCSV`: Updates a list of devices from a CSV created by the `New-JCDeviceUpdateTemplate` function + - `New-JCDeviceUpdateTemplate`: Creates a csv template used for bulk updating devices + - `Update-JCDeviceFromCSV`: Updates a list of devices from a CSV created by the `New-JCDeviceUpdateTemplate` function - Introduces `Remove-JCUser` - Added -CascadeManager (null, automatic, user) parameter - null - Manager field for managed users by the user being removed will be set to null - automatic - If the user (manager1) being removed is a manager but also managed by another user(manager2). The manager for managed users will cascade to manager2. - User - Manually specify the manager for users managed by the user/manager being removed - -CascadeManagerUser Id/Username + #### BUG FIXES: - Fixed a bug with `Import-JCUsersFromCSV` and `Update-JCUsersFromCSV` throwing error when importing 10 or more Custom Attributes due to a sorting issue From 2e17c4185c715bff82198469dc1c22f5e0056195 Mon Sep 17 00:00:00 2001 From: Joe Workman Date: Fri, 3 Jan 2025 13:09:25 -0700 Subject: [PATCH 4/4] changelog date --- PowerShell/ModuleChangelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 9eb97dea3..6ba8e34d7 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,6 +1,6 @@ ## 2.17.0 -Release Date: January 03, 2025 +Release Date: January 3, 2025 #### RELEASE NOTES