Skip to content

Commit

Permalink
Merge pull request #634 from TheJumpCloud/CUT-4546_PolicyResultTests
Browse files Browse the repository at this point in the history
Update Policy Results Tests to run without SetupOrg
  • Loading branch information
jworkmanjc authored Jan 3, 2025
2 parents 9ab8c31 + 2e17c41 commit 63309ac
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/JumpCloud.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: JumpCloud Solutions Architect Team
#
# Generated on: 1/2/2025
# Generated on: 1/3/2025
#

@{
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions PowerShell/JumpCloud Module/Tests/SetupOrg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"
}
}
}
Expand Down Expand Up @@ -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
11 changes: 6 additions & 5 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 2.17.0

Release Date: January 2, 2025
Release Date: January 3, 2025

#### RELEASE NOTES

Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 63309ac

Please sign in to comment.