-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
450d0ba
commit 09edac0
Showing
2 changed files
with
112 additions
and
0 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
111 changes: 111 additions & 0 deletions
111
SecurityFever/Tests/Unit/SecurityFever.CredentialManager.Tests.ps1
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
|
||
$modulePath = Resolve-Path -Path "$PSScriptRoot\..\..\.." | Select-Object -ExpandProperty Path | ||
$moduleName = Resolve-Path -Path "$PSScriptRoot\..\.." | Get-Item | Select-Object -ExpandProperty BaseName | ||
|
||
Remove-Module -Name $moduleName -Force -ErrorAction SilentlyContinue | ||
Import-Module -Name "$modulePath\$moduleName" -Force | ||
|
||
Describe 'SecurityFever.CredentialManager' { | ||
|
||
It 'Should create credential' { | ||
|
||
# Arrange | ||
$expectedNamespace = 'LegacyGeneric' | ||
$expectedAttribute = 'target' | ||
$expectedTargetAlias = '' | ||
$expectedTargetName = 'Unit Test Demo' | ||
$expectedType = [SecurityFever.CredentialManager.CredentialType]::Generic | ||
$expectedPersist = [SecurityFever.CredentialManager.CredentialPersist]::LocalMachine | ||
$expectedUsername = 'DEMO\\user' | ||
$expectedPassword = 'MySecurePassword' | ||
$expectedCredential = [System.Management.Automation.PSCredential]::new($expectedUsername, [SecurityFever.CredentialManager.CredentialHelper]::StringToSecureString($expectedPassword)) | ||
|
||
# Act | ||
$actual = [SecurityFever.CredentialManager.CredentialStore]::CreateCredential($expectedTargetName, $expectedType, $expectedPersist, $expectedCredential) | ||
|
||
# Assert | ||
$actual.Namespace | Should -Be $expectedNamespace | ||
$actual.Attribute | Should -Be $expectedAttribute | ||
$actual.TargetAlias | Should -Be $expectedTargetAlias | ||
$actual.TargetName | Should -Be $expectedTargetName | ||
$actual.Type | Should -Be $expectedType | ||
$actual.Persist | Should -Be $expectedPersist | ||
$actual.Credential.Username | Should -Be $expectedUsername | ||
$actual.Credential.GetNetworkCredential().Password | Should -Be $expectedPassword | ||
} | ||
|
||
It 'Should return true if credential exists' { | ||
|
||
# Arrange | ||
$targetName = 'Unit Test Demo' | ||
$type = [SecurityFever.CredentialManager.CredentialType]::Generic | ||
|
||
# Act | ||
$actual = [SecurityFever.CredentialManager.CredentialStore]::ExistCredential($targetName, $type) | ||
|
||
# Assert | ||
$actual | Should -BeTrue | ||
} | ||
|
||
It 'Should return false if credential does not exists' { | ||
|
||
# Arrange | ||
$targetName = [System.Guid]::NewGuid().Guid | ||
$type = [SecurityFever.CredentialManager.CredentialType]::MaximumEx | ||
|
||
# Act | ||
$actual = [SecurityFever.CredentialManager.CredentialStore]::ExistCredential($targetName, $type) | ||
|
||
# Assert | ||
$actual | Should -BeFalse | ||
} | ||
|
||
It 'Should get credential' { | ||
|
||
# Arrange | ||
$expectedNamespace = 'LegacyGeneric' | ||
$expectedAttribute = 'target' | ||
$expectedTargetAlias = '' | ||
$expectedTargetName = 'Unit Test Demo' | ||
$expectedType = [SecurityFever.CredentialManager.CredentialType]::Generic | ||
$expectedPersist = [SecurityFever.CredentialManager.CredentialPersist]::LocalMachine | ||
$expectedUsername = 'DEMO\\user' | ||
$expectedPassword = 'MySecurePassword' | ||
|
||
# Act | ||
$actual = [SecurityFever.CredentialManager.CredentialStore]::GetCredential($expectedTargetName, $expectedType) | ||
|
||
# Assert | ||
$actual.Namespace | Should -Be $expectedNamespace | ||
$actual.Attribute | Should -Be $expectedAttribute | ||
$actual.TargetAlias | Should -Be $expectedTargetAlias | ||
$actual.TargetName | Should -Be $expectedTargetName | ||
$actual.Type | Should -Be $expectedType | ||
$actual.Persist | Should -Be $expectedPersist | ||
$actual.Credential.Username | Should -Be $expectedUsername | ||
$actual.Credential.GetNetworkCredential().Password | Should -Be $expectedPassword | ||
} | ||
|
||
It 'Should get credentials' { | ||
|
||
# Act | ||
$actual = @([SecurityFever.CredentialManager.CredentialStore]::GetCredentials()) | ||
|
||
# Assert | ||
$actual.Count | Should -BeGreaterThan 0 | ||
} | ||
|
||
It 'Should remove credential' { | ||
|
||
# Arrange | ||
$targetName = 'Unit Test Demo' | ||
$type = [SecurityFever.CredentialManager.CredentialType]::Generic | ||
|
||
# Act | ||
[SecurityFever.CredentialManager.CredentialStore]::RemoveCredential($targetName, $type) | ||
$actual = [SecurityFever.CredentialManager.CredentialStore]::ExistCredential($targetName, $type) | ||
|
||
# Assert | ||
$actual | Should -BeFalse | ||
} | ||
} |