Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions test/PSCredentialInfo.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,84 +42,3 @@ Describe "Create PSCredentialInfo with VaultName, SecretName, and Credential" -t
$credentialInfo.SecretName | Should -Be $randomSecret
}
}

Describe "Create PSCredentialInfo from a PSObject" -tags 'CI' {

It "Throws if VaultName is null" {
$customObject = New-Object PSObject
{ New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo $customObject } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand"
}

It "Throws if SecretName is null" {
$customObject = New-Object PSObject
$customObject | Add-Member -Name "VaultName" -Value "testvault" -MemberType NoteProperty
{ New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo $customObject } | Should -Throw -ErrorId "ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand"
}

It "Creates PSCredentialInfo successfully from PSObject with VaultName and SecretName" {
$randomSecret = [System.IO.Path]::GetRandomFileName()
$properties = [PSCustomObject]@{
VaultName = "testvault"
SecretName = $randomSecret
}

$credentialInfo = [Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo] $properties

$credentialInfo.VaultName | Should -Be "testvault"
$credentialInfo.SecretName | Should -Be $randomSecret
}

It "Creates PSCredentialInfo successfully from PSObject with VaultName, SecretName and PSCredential Credential" {
$randomSecret = [System.IO.Path]::GetRandomFileName()
$randomPassword = [System.IO.Path]::GetRandomFileName()

$credential = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $randomPassword -AsPlainText -Force))
$properties = [PSCustomObject]@{
VaultName = "testvault"
SecretName = $randomSecret
Credential = [PSCredential] $credential
}

$credentialInfo = [Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo] $properties

$credentialInfo.VaultName | Should -Be "testvault"
$credentialInfo.SecretName | Should -Be $randomSecret
$credentialInfo.Credential.UserName | Should -Be "username"
$credentialInfo.Credential.GetNetworkCredential().Password | Should -Be $randomPassword
}

It "Creates PSCredentialInfo successfully from PSObject with VaultName, SecretName and string Credential" {
$randomSecret = [System.IO.Path]::GetRandomFileName()
$randomPassword = [System.IO.Path]::GetRandomFileName()

$properties = [PSCustomObject]@{
VaultName = "testvault"
SecretName = $randomSecret
Credential = $randomPassword
}

$credentialInfo = [Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo] $properties

$credentialInfo.VaultName | Should -Be "testvault"
$credentialInfo.SecretName | Should -Be $randomSecret
$credentialInfo.Credential.GetNetworkCredential().Password | Should -Be $randomPassword
}

It "Creates PSCredentialInfo successfully from PSObject with VaultName, SecretName and SecureString Credential" {
$randomSecret = [System.IO.Path]::GetRandomFileName()
$randomPassword = [System.IO.Path]::GetRandomFileName()

$secureString = ConvertTo-SecureString $randomPassword -AsPlainText -Force
$properties = [PSCustomObject]@{
VaultName = "testvault"
SecretName = $randomSecret
Credential = $secureString
}

$credentialInfo = [Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo] $properties

$credentialInfo.VaultName | Should -Be "testvault"
$credentialInfo.SecretName | Should -Be $randomSecret
$credentialInfo.Credential.GetNetworkCredential().Password | Should -Be $randomPassword
}
}