-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daryl Newsholme
committed
May 7, 2019
1 parent
9b066ad
commit e2cbbb6
Showing
34 changed files
with
696 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# | ||
} | ||
} | ||
|
Oops, something went wrong.