Publish preview version (#42)
* adds certificate store location * add additional certificate store tests * add cert store tests for New-CredentialStoreItem * fix test * add error handling for credential store path * add Import-CSCertificate helper function * Import new certificate if param is given * fix extension filter * add linux error message * fix pester test for linux * update cert helper functions * export helper functions * fix cs cert import * simplify cs cret lookup * remove obsolete functions * fix pester test for linux * fix error type for linux * fix var name * fix pester test * disable travis artifact upload * update cert lookup for item functions * debug build error * use cert instance constructor for linux * disable debug output * remove obsolete exports
This commit is contained in:
@ -4,7 +4,7 @@ Describe "New-CredentialStoreItem" {
|
||||
# Creat a fresh CredentialStore first
|
||||
New-CredentialStore -Force
|
||||
|
||||
[String]$tmp = (65..90) + (97..122) | Get-Random -Count 5 | % {[char]$_}
|
||||
[String]$tmp = (65..90) + (97..122) | Get-Random -Count 5 | ForEach-Object { [char]$_ }
|
||||
$tmp = $tmp.Replace(' ', '')
|
||||
$tmpUser = "MyUser"
|
||||
$tmpPwd = "fooobarysdfsfs" | ConvertTo-SecureString -AsPlainText -Force
|
||||
@ -65,7 +65,7 @@ Describe "New-CredentialStoreItem" {
|
||||
|
||||
}
|
||||
Context "General Exception handling" {
|
||||
Mock Test-CredentialStore {return $false}
|
||||
Mock Test-CredentialStore { return $false }
|
||||
It "Missing CredentialStore should throw" {
|
||||
{ New-CredentialStoreItem -Shared -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' } | Should -Throw "Could not add anything"
|
||||
}
|
||||
@ -81,5 +81,29 @@ Describe "New-CredentialStoreItem" {
|
||||
(Get-CredentialStoreItem -RemoteHost 'PipeHost').UserName | Should -Be 'pipeUser'
|
||||
}
|
||||
}
|
||||
Context "Testing items with certficiate store" {
|
||||
It "Create item in new store with cert store link" {
|
||||
New-CredentialStore -UseCertStore -Force
|
||||
|
||||
$Path = Get-DefaultCredentialStorePath
|
||||
$StoreHome = Split-Path -Path $Path -Parent
|
||||
$CertFile = Join-Path -Path $StoreHome -ChildPath 'PSCredentialStore.pfx'
|
||||
$Cert = Get-PfxCertificate -FilePath $CertFile
|
||||
|
||||
$myStore = [System.Security.Cryptography.X509Certificates.X509Store]::new('My')
|
||||
$myStore.Open("ReadWrite")
|
||||
$myStore.Add($Cert)
|
||||
$MyStore.Close()
|
||||
|
||||
$UserName = 'testuser'
|
||||
$Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force
|
||||
|
||||
[PSCredential]::new($UserName, $Password) | New-CredentialStoreItem -RemoteHost 'foobarcerts'
|
||||
|
||||
$writtenItem = Get-CredentialStoreItem -RemoteHost 'foobarcerts'
|
||||
$writtenItem.UserName | Should -Be "testuser"
|
||||
$writtenItem.GetNetworkCredential().Password | Should -Be 'mypasswd'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ Describe "New-CredentialStore" {
|
||||
Test-Path -Path $sCS | Should -Be $true
|
||||
}
|
||||
It "Test2: Try to override existing shared CS" {
|
||||
{New-CredentialStore -Shared -Confirm:$false} | Should -Throw
|
||||
{ New-CredentialStore -Shared -Confirm:$false } | Should -Throw
|
||||
}
|
||||
It "Test3: Reset shared CredentialStore" {
|
||||
$now = Get-Date
|
||||
@ -59,19 +59,40 @@ Describe "New-CredentialStore" {
|
||||
Context "Custom Shared CS tests" {
|
||||
$cCS = Join-Path -Path (Get-TempDir) -ChildPath "CredentialStore.json"
|
||||
It "Test1: Create new custom shared" {
|
||||
{New-CredentialStore -Path $cCS -Shared -Confirm:$false} | Should -Not -Throw
|
||||
{ New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Not -Throw
|
||||
}
|
||||
It "Test2: Try to override exiting one" {
|
||||
{New-CredentialStore -Path $cCS -Shared -Confirm:$false} | Should -Throw
|
||||
{ New-CredentialStore -Path $cCS -Shared -Confirm:$false } | Should -Throw
|
||||
}
|
||||
It "Test3: Reset existing custom CredentialStore" {
|
||||
{New-CredentialStore -Path $cCS -Shared -Force -Confirm:$false} | Should -Not -Throw
|
||||
{ New-CredentialStore -Path $cCS -Shared -Force -Confirm:$false } | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
Context "Test exception handling" {
|
||||
Mock Out-File {throw "foobar exception"}
|
||||
Mock Out-File { throw "foobar exception" }
|
||||
It "JSON Conversion should fail and throw" {
|
||||
{ New-CredentialStore -Path (Join-Path -Path (Get-TempDir) -ChildPath '/dummy.json') -Shared -Confirm:$false} | Should -Throw
|
||||
{ New-CredentialStore -Path (Join-Path -Path (Get-TempDir) -ChildPath '/dummy.json') -Shared -Confirm:$false } | Should -Throw
|
||||
}
|
||||
}
|
||||
Context "Tests for Windows certificate store" {
|
||||
It "Create new private store and skip certificate linking" {
|
||||
{ New-CredentialStore -UseCertStore -Force } | Should -Not -Throw
|
||||
$CS = Get-CredentialStore
|
||||
$CS.PfxCertificate | Should -Be $null
|
||||
$CS.Thumbprint | Should -Not -Be $null
|
||||
$res = Test-CSCertificate -Thumbprint $CS.Thumbprint -StoreName My -StoreLocation CurrentUser
|
||||
#Write-Verbose -Message ('res: {0}' -f $res) -Verbose
|
||||
$res | Should -Be $true
|
||||
|
||||
}
|
||||
It "Create new shared store and skipt certificate linking" {
|
||||
{ New-CredentialStore -Shared -UseCertStore -Force } | Should -Not -Throw
|
||||
$CS = Get-CredentialStore -Shared
|
||||
$CS.PfxCertificate | Should -Be $null
|
||||
$CS.Thumbprint | Should -Not -Be $null
|
||||
$res = Test-CSCertificate -Thumbprint $CS.Thumbprint -StoreName My -StoreLocation CurrentUser
|
||||
#Write-Verbose -Message ('res: {0}' -f $res) -Verbose
|
||||
$res | Should -Be $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user