From 90c979a2c1edf206780dee61214526eadd0fd215 Mon Sep 17 00:00:00 2001 From: Joe Workman <54448601+jworkmanjc@users.noreply.github.com> Date: Wed, 31 May 2023 15:05:46 -0600 Subject: [PATCH] tests/ error output in blanket catch statement (#495) * tests/ error output in blanket catch statement * Updating PowerShell Module;[skip ci] * changelog + patch version * Updating PowerShell Module;[skip ci] --------- Co-authored-by: TheJumpCloud --- .circleci/workflows.yml | 2 +- PowerShell/JumpCloud Module/Docs/JumpCloud.md | 2 +- .../JumpCloud Module/Docs/Remove-JCPolicy.md | 2 - .../Docs/Set-JCSettingsFile.md | 2 +- PowerShell/JumpCloud Module/JumpCloud.nuspec | 2 +- PowerShell/JumpCloud Module/JumpCloud.psd1 | 4 +- .../CSV_Import/Update-JCUsersFromCSV.ps1 | 10 ++++- .../Import-JCUsersFromCSV.tests.ps1 | 42 ++++++++++++++++++- .../Update-JCUsersFromCSV.tests.ps1 | 37 ++++++++++++++-- PowerShell/ModuleChangelog.md | 14 +++++++ 10 files changed, 102 insertions(+), 15 deletions(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 433cb05fb..17d4c4a3a 100755 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -32,7 +32,7 @@ parameters: description: "Release Type. Accepted values [ Major, Minor, Patch ]" type: enum enum: ["Major", "Minor", "Patch"] - default: "Minor" + default: "Patch" RequiredModulesRepo: description: "PowerShell Repository for JumpCloud SDKs" type: enum diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index a52d2a0f4..567121a0f 100644 --- a/PowerShell/JumpCloud Module/Docs/JumpCloud.md +++ b/PowerShell/JumpCloud Module/Docs/JumpCloud.md @@ -2,7 +2,7 @@ Module Name: JumpCloud Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646 Download Help Link: https://github.com/TheJumpCloud/support/wiki -Help Version: 2.5.0 +Help Version: 2.5.1 Locale: en-US --- diff --git a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md index 70f1d4d18..55560965c 100644 --- a/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md +++ b/PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md @@ -101,5 +101,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## NOTES ## RELATED LINKS - -## RELATED LINKS diff --git a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md index f8bf10130..ba6b37a0c 100644 --- a/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md +++ b/PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md @@ -14,7 +14,7 @@ Updates the JumpCloud Module Settings File ## SYNTAX ``` -Set-JCSettingsFile [-parallelOverride ] [-moduleBannerMessageCount ] [] +Set-JCSettingsFile [-moduleBannerMessageCount ] [-parallelOverride ] [] ``` ## DESCRIPTION diff --git a/PowerShell/JumpCloud Module/JumpCloud.nuspec b/PowerShell/JumpCloud Module/JumpCloud.nuspec index a44e0d52b..0d0621c11 100644 --- a/PowerShell/JumpCloud Module/JumpCloud.nuspec +++ b/PowerShell/JumpCloud Module/JumpCloud.nuspec @@ -2,7 +2,7 @@ JumpCloud - 2.5.0 + 2.6.0.8602-202305261756 PowerShell functions to manage a JumpCloud Directory-as-a-Service JumpCloud Solutions Architect Team JumpCloud diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 49d37b426..9da628246 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: 5/11/2023 +# Generated on: 5/30/2023 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '2.5.0' +ModuleVersion = '2.5.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 b/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 index e4b8d4843..7cc8f9bd2 100755 --- a/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 +++ b/PowerShell/JumpCloud Module/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.ps1 @@ -505,8 +505,14 @@ Function Update-JCUsersFromCSV () { } catch { - - $Status = 'User does not exist' + If ($_.ErrorDetails) { + $Status = $_.ErrorDetails + } elseif ($_.Exception) { + $Status = $_.Exception.Message + } + if (-not (Get-JCUser -username $UpdateParams.username -returnProperties username)) { + $Status = 'User does not exist' + } $FormattedResults = [PSCustomObject]@{ diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 index 822c929ea..08d141152 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Import-JCUsersFromCSV.tests.ps1 @@ -661,7 +661,45 @@ Describe -Tag:('JCUsersFromCSV') 'LDAP Import Tests' { $LDAPUser.ldap_binding_user | should -Be $false $importStatus.LdapUserBind | Should -Match "not recognized as a valid Boolean" } - AfterAll { - Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force + +} +Describe -Tag:('JCUsersFromCSV') "Import-JCUsersFromCSV 2.5.1" { + Context "Custom Attribute API error should be returned" { + It "When a custom attribute name has a space in the field, the API should return an error message in the status field" { + $user = New-RandomUser -Domain pleasedelete + $today = Get-Date + $EnrollmentDays = 14 + $CSVDATA = @{ + Username = $user.username + LastName = $user.LastName + FirstName = $user.FirstName + Email = $user.Email + Attribute1_name = "bad value" + Attribute1_value = "string" + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/custom_attribute.csv" -Force + $importResults = Import-JCUsersFromCSV -CSVFilePath "$PesterParams_ImportPath/custom_attribute.csv" -force + $importResults[0].AdditionalInfo | Should -Match "Attribute names may not contain spaces" + } + It "When a custom attribute name has a non-alphanumeric in the field, the API should return an error message in the status field" { + $user = New-RandomUser -Domain pleasedelete + $today = Get-Date + $EnrollmentDays = 14 + $CSVDATA = @{ + Username = $user.username + LastName = $user.LastName + FirstName = $user.FirstName + Email = $user.Email + Attribute1_name = "bad.value" + Attribute1_value = "string" + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_ImportPath/custom_attribute.csv" -Force + $importResults = Import-JCUsersFromCSV -CSVFilePath "$PesterParams_ImportPath/custom_attribute.csv" -force + $importResults[0].AdditionalInfo | Should -Match "Attribute names may only contain letters and numbers" + } } +} + +AfterAll { + Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force } \ No newline at end of file diff --git a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 index f3c6f0f0c..6d9fe2ec4 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Utilities/CSV_Import/Update-JCUsersFromCSV.tests.ps1 @@ -529,7 +529,38 @@ Describe -Tag:('JCUsersFromCSV') 'LDAP Update Tests' { $LDAPUser.ldap_binding_user | should -Be $false $UpdateStatus.LdapUserBind | Should -Match "not recognized as a valid Boolean" } - AfterAll { - Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force +} + +Describe -Tag:('JCUsersFromCSV') "Update-JCUsersFromCSV 2.5.1" { + Context "Custom Attribute API error should be returned" { + It "When a custom attribute name has a space in the field, the API should return an error message in the status field" { + $user = New-RandomUser -Domain pleasedelete | New-JCUser + $CSVDATA = @{ + Username = $user.username + Attribute1_name = "bad value" + Attribute1_value = 'string' + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_UpdatePath/custom_attribute.csv" -Force + $UpdateStatus = Update-JCUsersFromCSV -CSVFilePath "$PesterParams_UpdatePath/custom_attribute.csv" -force + # the error message should show that custom attribute names cannot contain spaces + $UpdateStatus[0].status | Should -Match "Attribute names may not contain spaces" + $UpdateStatus[0].status | Should -Not -Match "User does not exist" + } + It "When a custom attribute name has a non-alphanumeric in the field, the API should return an error message in the status field" { + $user = New-RandomUser -Domain pleasedelete | New-JCUser + $CSVDATA = @{ + Username = $user.username + Attribute1_name = "bad.value" + Attribute1_value = 'string' + } + $CSVFILE = $CSVDATA | Export-Csv "$PesterParams_UpdatePath/custom_attribute.csv" -Force + $UpdateStatus = Update-JCUsersFromCSV -CSVFilePath "$PesterParams_UpdatePath/custom_attribute.csv" -force + # the error message should show that custom attribute names cannot contain spaces + $UpdateStatus[0].status | Should -Match "Attribute names may only contain letters and numbers" + $UpdateStatus[0].status | Should -Not -Match "User does not exist" + } } -} \ No newline at end of file +} +AfterAll { + Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force +} diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index a5eb268d3..cd6a1d660 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,3 +1,17 @@ +## 2.5.1 + +Release Date: May 30, 2023 + +#### RELEASE NOTES + +``` +Bug fix for Update-JCUsersFromCSV function +``` + +#### BUG FIXES: + +Update-JCUsersFromCSV would throw an incorrect status message if updated custom attributes or other API errors would be thrown during script execution. Now the correct error statement from our API should be displayed in the status message object on each updated user. + ## 2.5.0 Release Date: May 11, 2023