Skip to content

Commit

Permalink
tests/ error output in blanket catch statement (#495)
Browse files Browse the repository at this point in the history
* tests/ error output in blanket catch statement

* Updating PowerShell Module;[skip ci]

* changelog + patch version

* Updating PowerShell Module;[skip ci]

---------

Co-authored-by: TheJumpCloud <TheJumpCloud>
  • Loading branch information
jworkmanjc authored May 31, 2023
1 parent f13cfcb commit 90c979a
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

Expand Down
2 changes: 0 additions & 2 deletions PowerShell/JumpCloud Module/Docs/Remove-JCPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## NOTES
## RELATED LINKS
## RELATED LINKS
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/Set-JCSettingsFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Updates the JumpCloud Module Settings File
## SYNTAX

```
Set-JCSettingsFile [-parallelOverride <PSObject>] [-moduleBannerMessageCount <PSObject>] [<CommonParameters>]
Set-JCSettingsFile [-moduleBannerMessageCount <PSObject>] [-parallelOverride <PSObject>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/JumpCloud.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>JumpCloud</id>
<version>2.5.0</version>
<version>2.6.0.8602-202305261756</version>
<description>PowerShell functions to manage a JumpCloud Directory-as-a-Service</description>
<authors>JumpCloud Solutions Architect Team</authors>
<owners>JumpCloud</owners>
Expand Down
4 changes: 2 additions & 2 deletions 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: 5/11/2023
# Generated on: 5/30/2023
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'JumpCloud.psm1'

# Version number of this module.
ModuleVersion = '2.5.0'
ModuleVersion = '2.5.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]@{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
AfterAll {
Get-JCUser | Where-Object Email -like *pleasedelete* | Remove-JCUser -force
}
14 changes: 14 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 90c979a

Please sign in to comment.