diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 8f97ecc25..73d684267 100755 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -45,7 +45,7 @@ parameters: PublishToPSGallery: description: 'When `true` and when run against Master branch, this workflow will publish the latest code to PSGallery' type: boolean - default: false + default: true ManualModuleVersion: description: 'When `true` the pipeline will use the Module Version specified in JumpCloud Module JumpCloud.psd1 file' type: boolean @@ -85,7 +85,6 @@ workflows: requires: - Initial Setup - Build Modules - - Build Help and Test Files context: aws-credentials - Module Validation Tests: requires: @@ -104,7 +103,6 @@ workflows: - Initial Setup - Build Help and Test Files - Build Nuspec - - Module Validation Tests - Invoke Git Commit context: aws-credentials - Pester Tests Mac: @@ -112,7 +110,6 @@ workflows: - Initial Setup - Build Help and Test Files - Build Nuspec - - Module Validation Tests - Invoke Git Commit context: aws-credentials - Pester Tests Linux: @@ -120,7 +117,6 @@ workflows: - Initial Setup - Build Help and Test Files - Build Nuspec - - Module Validation Tests - Invoke Git Commit context: aws-credentials - Publish Module Validation: @@ -128,7 +124,6 @@ workflows: - Initial Setup - Build Help and Test Files - Build Nuspec - - Module Validation Tests - Invoke Git Commit release: when: diff --git a/PowerShell/Deploy/Setup-Dependencies.ps1 b/PowerShell/Deploy/Setup-Dependencies.ps1 index 2938414c5..6845030ef 100644 --- a/PowerShell/Deploy/Setup-Dependencies.ps1 +++ b/PowerShell/Deploy/Setup-Dependencies.ps1 @@ -1,6 +1,5 @@ Param( - [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 0)][System.String[]]$DependentModules = ('PowerShellGet', 'PackageManagement', 'PSScriptAnalyzer', 'PlatyPS', 'Pester', 'AWS.Tools.Common', 'AWS.Tools.CodeArtifact') - , [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 1)][System.String]$RequiredModulesRepo = 'PSGallery' + [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 0)][System.String]$RequiredModulesRepo = 'PSGallery' ) # Install NuGet If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue'))) @@ -8,28 +7,28 @@ If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('Silently Write-Host ('[status]Installing package provider NuGet'); Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force } -# Install dependent modules -ForEach ($DependentModule In $DependentModules) + +$PSDependencies = @{ + 'PowerShellGet' = @{Repository = 'PSGallery'; RequiredVersion = '3.0.12-beta' } + 'PackageManagement' = @{Repository = 'PSGallery'; RequiredVersion = '1.4.8.1' } + 'PSScriptAnalyzer' = @{Repository = 'PSGallery'; RequiredVersion = '1.19.1' } + 'PlatyPS' = @{Repository = 'PSGallery'; RequiredVersion = '0.14.2' } + 'Pester' = @{Repository = 'PSGallery'; RequiredVersion = '5.3.3' } + 'AWS.Tools.Common' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.122' } + 'AWS.Tools.CodeArtifact' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.122' } +} + +foreach ($RequiredModule in $PSDependencies.Keys) { - # Check to see if the module is installed - If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $DependentModule }))) - { - Write-Host("[status]Installing module: '$DependentModule' from 'PSGallery'") - if ($DependentModule -eq 'PowerShellGet'){ - Install-Module -Name $DependentModule -Repository:('PSGallery') -RequiredVersion '3.0.12-beta' -AllowPrerelease -Force - } - elseif ($DependentModule -eq 'PSScriptAnalyzer') { - Install-Module -Name $DependentModule -Repository:('PSGallery') -RequiredVersion '1.19.1' -Force - } - else{ - Install-Module -Repository:('PSGallery') -Force -Name:($DependentModule) -Scope:('CurrentUser') -AllowClobber + If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $RequiredModule }))) + { + Write-Host("[status]Installing module: '$RequiredModule'; version: $($PSDependencies[$RequiredModule].RequiredVersion) from $($PSDependencies[$RequiredModule].Repository)") + Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -RequiredVersion:($($PSDependencies[$RequiredModule].RequiredVersion)) -AllowPrerelease -Force } - } - # Get-Module -Refresh -ListAvailable - If ([System.String]::IsNullOrEmpty((Get-Module | Where-Object { $_.Name -eq $DependentModule }))) + If ([System.String]::IsNullOrEmpty((Get-Module | Where-Object { $_.Name -eq $RequiredModule }))) { - Write-Host("[status]Importing module: '$DependentModule'") - Import-Module -Name:($DependentModule) -Force -Global + Write-Host("[status]Importing module: '$RequiredModule'") + Import-Module -Name:($RequiredModule) -Force -Global } } ### TODO: Switch to CodeArtifact @@ -86,7 +85,7 @@ If (-not [System.String]::IsNullOrEmpty($Psd1)) } elseif ($PowerShellModulesPaths -match 'documents') { - # Windows Ststems + # Windows Systems $LocalPSModulePath = $env:PSModulePath.split(';') | Where-Object { $_ -like '*documents*' } Write-Host "Module Installation Path: $LocalPSModulePath" } diff --git a/PowerShell/JumpCloud Module/Docs/JumpCloud.md b/PowerShell/JumpCloud Module/Docs/JumpCloud.md index 379097009..83bc31624 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: 1.23.1 +Help Version: 1.23.2 Locale: en-US --- diff --git a/PowerShell/JumpCloud Module/JumpCloud.psd1 b/PowerShell/JumpCloud Module/JumpCloud.psd1 index 5d5e9e5a7..23910c241 100755 --- a/PowerShell/JumpCloud Module/JumpCloud.psd1 +++ b/PowerShell/JumpCloud Module/JumpCloud.psd1 @@ -3,7 +3,7 @@ # # Generated by: JumpCloud Solutions Architect Team # -# Generated on: 7/7/2022 +# Generated on: 7/11/2022 # @{ @@ -12,7 +12,7 @@ RootModule = 'JumpCloud.psm1' # Version number of this module. -ModuleVersion = '1.23.1' +ModuleVersion = '1.23.2' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 b/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 index 24bbcca62..205682b7f 100644 --- a/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 +++ b/PowerShell/JumpCloud Module/Public/Users/Get-JCUser.ps1 @@ -315,10 +315,12 @@ Function Get-JCUser () if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){ # if we have a 24 characterid, try to match the id using the search endpoint $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('id') + filter = @{ + 'and' = @( + @{'id' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'id' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue; this is a validated user id @@ -326,10 +328,12 @@ Function Get-JCUser () # if no value was returned, then assume the case this is actually a username and search if (!$managerValue){ $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -341,20 +345,24 @@ Function Get-JCUser () $null = [mailaddress]$EmailAddress # Search manager using email $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('email') + filter = @{ + 'and' = @( + @{'email' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'email' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue; this is a validated user id $managerValue = $managerResults.id if (!$managerValue){ $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -364,10 +372,12 @@ Function Get-JCUser () catch { # search the username in the search endpoint $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -385,7 +395,7 @@ Function Get-JCUser () } } - # case insensitve state param + # case insensitive state param if ("state" -eq $param.Key) { if ($param.Value -cin @('ACTIVATED', 'SUSPENDED', 'STAGED')) diff --git a/PowerShell/JumpCloud Module/Public/Users/New-JCUser.ps1 b/PowerShell/JumpCloud Module/Public/Users/New-JCUser.ps1 index 90e717290..430f926c0 100755 --- a/PowerShell/JumpCloud Module/Public/Users/New-JCUser.ps1 +++ b/PowerShell/JumpCloud Module/Public/Users/New-JCUser.ps1 @@ -326,21 +326,25 @@ Function New-JCUser () if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){ # if we have a 24 characterid, try to match the id using the search endpoint $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('id') + filter = @{ + 'and' = @( + @{'id' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'id' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue; this is a validated user id $managerValue = $managerResults.id - # if no value was returned, then assume the case this is actuallty a username and search + # if no value was returned, then assume the case this is actually a username and search if (!$managerValue){ $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -351,21 +355,25 @@ Function New-JCUser () try { $null = [mailaddress]$EmailAddress $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('email') + filter = @{ + 'and' = @( + @{'email' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'email' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue; this is a validated user id $managerValue = $managerResults.id - # if no value was returned, then assume the case this is actuallty a username and search + # if no value was returned, then assume the case this is actually a username and search if (!$managerValue){ $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -375,10 +383,12 @@ Function New-JCUser () catch { # search the username in the search endpoint $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username diff --git a/PowerShell/JumpCloud Module/Public/Users/Set-JCUser.ps1 b/PowerShell/JumpCloud Module/Public/Users/Set-JCUser.ps1 index c47cb0cb0..dd8ae56e2 100644 --- a/PowerShell/JumpCloud Module/Public/Users/Set-JCUser.ps1 +++ b/PowerShell/JumpCloud Module/Public/Users/Set-JCUser.ps1 @@ -606,10 +606,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline if (((Select-String -InputObject $param.Value -Pattern $regexPattern).Matches.value)::IsNullOrEmpty){ # if we have a 24 characterid, try to match the id using the search endpoint $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('id') + filter = @{ + 'and' = @( + @{'id' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'id' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue; this is a validated user id @@ -617,10 +619,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline # if no value was returned, then assume the case this is actually a username and search if (!$managerValue){ $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -632,10 +636,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline $null = [mailaddress]$EmailAddress # Search for manager using email $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('email') + filter = @{ + 'and' = @( + @{'email' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'email' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue; this is a validated user id @@ -643,10 +649,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline # if no value was returned, then assume the case this is actually a username and search if (!$managerValue){ $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -656,10 +664,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline catch { # search the username in the search endpoint $managerSearch = @{ - searchFilter = @{ - searchTerm = @($param.Value) - fields = @('username') + filter = @{ + 'and' = @( + @{'username' = @{'$regex' = "(?i)(`^$($param.Value)`$)" } } + ) } + fields = 'username' } $managerResults = Search-JcSdkUser -Body:($managerSearch) # Set managerValue from the matched username @@ -1148,12 +1158,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline $body['state'] = 'SUSPENDED' } else { - switch ($state) + switch ($state) { - SUSPENDED { - $body['suspended'] = $true + SUSPENDED { + $body['suspended'] = $true } - ACTIVATED { + ACTIVATED { $body['suspended'] = $false } } @@ -1311,12 +1321,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline $body['state'] = 'SUSPENDED' } else { - switch ($state) + switch ($state) { - SUSPENDED { - $body['suspended'] = $true + SUSPENDED { + $body['suspended'] = $true } - ACTIVATED { + ACTIVATED { $body['suspended'] = $false } } @@ -1467,12 +1477,12 @@ UserID has an Alias of _id. This means you can leverage the PowerShell pipeline $body['state'] = 'SUSPENDED' } else { - switch ($state) + switch ($state) { - SUSPENDED { - $body['suspended'] = $true + SUSPENDED { + $body['suspended'] = $true } - ACTIVATED { + ACTIVATED { $body['suspended'] = $false } } diff --git a/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 b/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 index d49ea29bc..6d0ed4fc7 100755 --- a/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 +++ b/PowerShell/JumpCloud Module/Tests/Public/Users/Get-JCUser.tests.ps1 @@ -94,6 +94,28 @@ Describe -Tag:('JCUser') 'Get-JCUser 1.1' { $NewUser.manager | Should -Be $managerId Remove-JCUser -UserID $NewUser._id -force } + It "Searches a JumpCloud user by managerUsername & Email and should not return user with similar username" { + # Define two users who's username is contained by another user + $newUser1 = New-JCUser -username "jemartin" -firstname "je" -lastname "martin" -email "jemartin@deleteme.com" + $newUser2 = New-JCUser -username "emartin" -firstname "e" -lastname "martin" -email "emartin@deleteme.come" + $NewUser = New-RandomUser -Domain DeleteMe | New-JCUser -manager $newUser2.username + $NewUser = Get-JCUser -manager $newUser2.username + $NewUser = Get-JCUser -manager $newUser2.email + $NewUser.manager | Should -Be $newUser2.Id + $NewUser.manager | Should -Not -Be $newUser1.Id + # Remove all users from the test + Remove-JCUser -UserID $NewUser._id -force + Remove-JCUser -UserID $NewUser1._id -force + Remove-JCUser -UserID $NewUser2._id -force + } + It "Searches a JumpCloud user by managerUsername (Case Insensitive)" { + $managerUsername = $PesterParams_User1.username + $managerId = $PesterParams_User1.id + $NewUser = New-RandomUser -Domain DeleteMe | New-JCUser -manager $managerUsername + $NewUser = Get-JCUser -manager $($managerUsername.ToUpper()) + $NewUser.manager | Should -Be $managerId + Remove-JCUser -UserID $NewUser._id -force + } It "Searches a JumpCloud user by managerEmail" { $managerEmail = $PesterParams_User1.email $managerId = $PesterParams_User1.id @@ -102,6 +124,14 @@ Describe -Tag:('JCUser') 'Get-JCUser 1.1' { $NewUser.manager | Should -Be $managerId Remove-JCUser -UserID $NewUser._id -force } + It "Searches a JumpCloud user by managerEmail (Case Insensitive)" { + $managerEmail = $PesterParams_User1.email + $managerId = $PesterParams_User1.id + $NewUser = New-RandomUser -Domain DeleteMe | New-JCUser -manager $managerEmail + $NewUser = Get-JCUser -manager $($managerEmail.ToUpper()) + $NewUser.manager | Should -Be $managerId + Remove-JCUser -UserID $NewUser._id -force + } It "Searches a JumpCloud user by state SUSPENDED" { $NewUser = New-RandomUser -Domain DeleteMe | New-JcUser -state "SUSPENDED" $SearchUser = Get-JCUser -state "SUSPENDED" | Select-Object -First 1 diff --git a/PowerShell/ModuleBanner.md b/PowerShell/ModuleBanner.md index 9de6a5fc1..d2541cf92 100755 --- a/PowerShell/ModuleBanner.md +++ b/PowerShell/ModuleBanner.md @@ -1,14 +1,13 @@ #### Latest Version ``` -1.23.1 +1.23.2 ``` #### Banner Current ``` -* Get-JCUser -State should accept case insensitive values such as "suspended" "activated" "staged" and validate input -``` +* Get-JCUser -State should accept case insensitive values such as "suspended" "activated" "staged" and validate input``` #### Banner Old diff --git a/PowerShell/ModuleChangelog.md b/PowerShell/ModuleChangelog.md index 3122e5a63..c91a92cf8 100644 --- a/PowerShell/ModuleChangelog.md +++ b/PowerShell/ModuleChangelog.md @@ -1,6 +1,18 @@ +## 1.23.2 + +Release Date: July 11, 2022 + +#### RELEASE NOTES + +This release modifies how the Manager Username Lookup works with Get-JCUser. Only usernames/ emails that match the full string of the search are now returned + +#### BUG FIXES: + +* Get-JCUser -Manager "someUser" could return multiple values if another user username: "User" exists in the Organization + ## 1.23.1 -Release Date: June 21, 2022 +Release Date: July 7, 2022 #### RELEASE NOTES