Skip to content

Commit

Permalink
support for secure strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Daryl Newsholme committed May 7, 2019
1 parent 9b066ad commit e2cbbb6
Show file tree
Hide file tree
Showing 34 changed files with 696 additions and 517 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.0.94

+ Feature
+ Passwords now returned as secure string. Use .GetPassword() method to retrieve plaintext
+ Global variable for returning plain text passwords $global:PasswordStateShowPasswordsPlainText = $true
+ Fixes
+ Added support for APIKey auth to generate passwords as this was broken.
+ Various bugfixes when using apikeys.

## 0.0.91

+ Fix
Expand Down
4 changes: 2 additions & 2 deletions docs/Get-PasswordStatePasswords.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use Get-PasswordStateList to search for a name and return the ID
## SYNTAX

```
Get-PasswordStatePasswords [-PasswordlistID <Int32[]>] [<CommonParameters>]
Get-PasswordStatePasswords [[-PasswordlistID] <Int32[]>] [<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -41,7 +41,7 @@ Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Position: 1
Default value: 0
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
Expand Down
4 changes: 2 additions & 2 deletions docs/New-PasswordStateList.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Creates a passwordstate List.
## SYNTAX

```
New-PasswordStateList [-Name] <String> [-description] <String> [[-CopySettingsFromPasswordListID] <Int32>]
New-PasswordStateList [-Name] <String> [-description] <String> [-CopySettingsFromPasswordListID] <Int32>
[-FolderID] <Int32> [-WhatIf] [-Confirm] [<CommonParameters>]
```

Expand Down Expand Up @@ -67,7 +67,7 @@ Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Required: True
Position: 3
Default value: None
Accept pipeline input: True (ByPropertyName)
Expand Down
83 changes: 48 additions & 35 deletions functions/Find-PasswordStatePassword.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,41 +1,54 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
(import-module "$psscriptroot\..\passwordstate-management.psm1" -force)
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Import-Module "$here\..\passwordstate-management.psm1"
Describe "Find-PasswordStatePassword" {
It "Finds a Password From Password State" {
Mock -CommandName Get-PasswordStateResource -MockWith {return [PSCustomObject]@{
"Title" = "testuser"
"Username" = "test"
"Domain" = ""
"Description" = ""
"PasswordId" = 3
"AccountType" = ""
"URL" = ""
"Password" = "testpassword"
}
} -ParameterFilter {$uri -eq "/api/passwords/3"}

Mock -CommandName Get-PasswordStateResource -MockWith {return [PSCustomObject]@{
"Title" = "testuser"
"Username" = "test"
"Domain" = ""
"Description" = ""
"PasswordId" = 3
"AccountType" = ""
"URL" = ""
"Password" = ""
}
} -ParameterFilter {$uri -eq "/api/searchpasswords/?title=testuser&ExcludePassword=true"}

Mock -CommandName Get-PasswordStateEnvironment -MockWith {return [PSCustomObject]@{
"Baseuri" = "https://passwordstateserver.co.uk"
"APIKey" = "WindowsAuth"

}
It "Finds a Password by generic search" {
(Find-PasswordStatePassword "test").Title | Should -BeExactly "test"
}
It "Finds a Password by ID" {
(Find-PasswordStatePassword -PasswordID "1").PasswordID | Should -BeExactly 1
}
It "Finds a Password with a reason" {
(Find-PasswordStatePassword -PasswordID "1" -Reason "Unit Test").PasswordID | Should -BeExactly 1
}
It "Finds a Password by Username Search" {
(Find-PasswordStatePassword -UserName "test").Username | Should -BeExactly "test"
}
It "Checks Password is returned as type [System.Security.SecureString]" {
(Find-PasswordStatePassword -PasswordID "1").Password.Password | Should -BeOfType [System.Security.SecureString]
}
It "Checks Password is decrypted by method .GetPassword()" {
(Find-PasswordStatePassword -PasswordID "1").GetPassword() | Should -BeOfType [String]
}
It "Checks Password is decrypted by method .DecryptPassword()" {
$result = (Find-PasswordStatePassword -PasswordID "1")
$result.DecryptPassword()
$result.Password | Should -BeOfType [String]
}
It "Checks `$global:PasswordStateShowPasswordsPlainText is honoured" {
$global:PasswordStateShowPasswordsPlainText = $true
(Find-PasswordStatePassword -PasswordID "1").Password | Should -BeOfType [String]
}

BeforeEach {
# Create Test Environment
try {
$globalsetting = Get-Variable PasswordStateShowPasswordsPlainText -ErrorAction stop -Verbose -ValueOnly
$global:PasswordStateShowPasswordsPlainText = $false
}

(Find-PasswordStatePassword -Title "testuser").PasswordId | Should -BeExactly 3
(Find-PasswordStatePassword -Title "testuser").Password | Should -not -BeNullOrEmpty
Catch {
New-Variable -Name PasswordStateShowPasswordsPlainText -Value $false -Scope Global
}
Move-Item "$($env:USERPROFILE)\passwordstate.json" "$($env:USERPROFILE)\passwordstate.json.bak" -force
Set-PasswordStateEnvironment -Apikey "$env:pwsapikey" -Baseuri "$env:pwsuri"
}

AfterEach {
# Remove Test Environment
Move-Item "$($env:USERPROFILE)\passwordstate.json.bak" "$($env:USERPROFILE)\passwordstate.json" -force
$global:PasswordStateShowPasswordsPlainText = $globalsetting
#
}
}

Loading

0 comments on commit e2cbbb6

Please sign in to comment.