Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiospizzi committed Nov 6, 2019
1 parent 450d0ba commit 09edac0
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

* Added: Alias cred to the Use-VaultCredential
* Changed: .NET Library structure and unit tests
* Fixed: Prevent user interaction if not in interactive mode

## 2.6.2 - 2019-09-05
Expand Down
111 changes: 111 additions & 0 deletions SecurityFever/Tests/Unit/SecurityFever.CredentialManager.Tests.ps1
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
}
}

0 comments on commit 09edac0

Please sign in to comment.