Skip to content

Commit

Permalink
Merge pull request #15 from pspete/issue-14
Browse files Browse the repository at this point in the history
Get-AIMCredential
  • Loading branch information
pspete authored Apr 9, 2020
2 parents d357d71 + 124f116 commit 417effd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CredentialRetriever Changelog

## 3.5.22 (April 10th 2020)

- Fix `Get-AIMCredential`
- Resolves error when returning passwords containing a comma character.

## 3.4.19 (March 27th 2020)

- Changed minimum required PowerShell version to 5.1
Expand Down
15 changes: 8 additions & 7 deletions CredentialRetriever/Functions/Get-AIMCredential.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ Function Get-AIMCredential {
[array]$ReturnProps = @()
#Hashtable to hold the Results to Output
[hashtable]$Output = @{ }
#Delimiter for separating the output fields
$Separator = "#_-_#"
#Set StringSplitOption
$RemoveEmptyEntries = [System.StringSplitOptions]::RemoveEmptyEntries

}

Expand All @@ -203,8 +207,6 @@ Function Get-AIMCredential {
#Initial Command String
$Command = "/p AppDescs.AppID=`"$AppID`""

Write-Debug $Command

#Build array of query string properties
$PSBoundParameters.Add("Query", @())
$QueryParameters | ForEach-Object {
Expand Down Expand Up @@ -265,8 +267,7 @@ Function Get-AIMCredential {
$ReturnProps = $ReturnProps -join ","

#Build Command String
$Command = "$Command /o $ReturnProps"
Write-Debug $Command
$Command = "$Command /o $ReturnProps /d $Separator"

#Add Required CommandParameters to $PSBoundParameters for Splat against Invoke-AIMClient
$PSBoundParameters.Add("CommandParameters", "$Command")
Expand All @@ -278,13 +279,13 @@ Function Get-AIMCredential {
#Output on StdOut
If ($Result.StdOut) {

#split returned results
$Results = ($Result.StdOut).Split(",")
#split returned results at Separator
$Results = ($Result.StdOut).Split($Separator, $RemoveEmptyEntries)

#use $returnProps to determine propertynames
$ReturnProps = $ReturnProps.Split(",")

For ($i = 0 ; $i -lt $Results.length ; $i++) {
For ($i = 0 ; $i -lt $ReturnProps.length ; $i++) {

#PropertyName=PropertyValue
$Output[$(($ReturnProps[$i]) -replace "PassProps.", "")] = ($Results[$i]).trim()
Expand Down
3 changes: 0 additions & 3 deletions CredentialRetriever/Private/Invoke-AIMClient.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@

Begin {

$CallStack = $((Get-PSCallStack).Command)[1]
Write-Debug "Origin: $CallStack"

Try {

Get-Variable -Name AIM -ErrorAction Stop
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# version format
version: 3.4.{build}
version: 3.5.{build}

environment:
#GIT_TRACE: 1
Expand Down
14 changes: 13 additions & 1 deletion tests/Get-AIMCredential.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ InModuleScope $ModuleName {
Mock Invoke-AIMClient -MockWith {
[pscustomobject]@{
"ExitCode" = 0
"StdOut" = "SomeUser,value2,value3,value4,SomePassword,true"
"StdOut" = "SomeUser#_-_#value2#_-_#value3#_-_#value4#_-_#SomePassword#_-_#true"
"StdErr" = $null
}
}
Expand Down Expand Up @@ -82,6 +82,18 @@ InModuleScope $ModuleName {
($result.ToCredential()).GetNetworkCredential().Password | Should Be "SomePassword"
}

It "outputs expected password containing comma" {
Mock Invoke-AIMClient -MockWith {
[pscustomobject]@{
"ExitCode" = 0
"StdOut" = "SomeUser#_-_#value2#_-_#value3#_-_#value4#_-_#Some,Password#_-_#true"
"StdErr" = $null
}
}
$result = $InputObj | Get-AIMCredential
$result.Password | Should Be "Some,Password"
}

}

}

0 comments on commit 417effd

Please sign in to comment.