mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Related #3238 1. Add autoload for test modules 2. Move TestHostCS.psm1 to 'test\tools\Modules\' folder 3. Remove explicit load TestHostCS.psm1 from test files
103 lines
5.0 KiB
PowerShell
Executable File
103 lines
5.0 KiB
PowerShell
Executable File
Describe "Get-Credential Test" -tag "CI" {
|
|
BeforeAll {
|
|
$th = New-TestHost
|
|
$th.UI.StringForSecureString = "This is a test"
|
|
$th.UI.UserNameForCredential = "John"
|
|
$rs = [runspacefactory]::Createrunspace($th)
|
|
$rs.open()
|
|
$ps = [powershell]::Create()
|
|
$ps.Runspace = $rs
|
|
$ps.Commands.Clear()
|
|
}
|
|
AfterAll {
|
|
$rs.Close()
|
|
$rs.Dispose()
|
|
$ps.Dispose()
|
|
}
|
|
AfterEach {
|
|
$ps.Commands.Clear()
|
|
}
|
|
It "Get-Credential with message, produces a credential object" {
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe -Message Foo").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "Joe"
|
|
$netcred.Password | Should be "this is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:Foo"
|
|
}
|
|
It "Get-Credential with title, produces a credential object" {
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe -Title CustomTitle").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "Joe"
|
|
$netcred.Password | Should be "this is a test"
|
|
$th.ui.Streams.Prompt[-1] | should Match "Credential:CustomTitle:[^:]+"
|
|
}
|
|
It "Get-Credential with only username, produces a credential object" {
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "Joe"
|
|
$netcred.Password | Should be "this is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
|
}
|
|
It "Get-Credential with title and message, produces a credential object" {
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe -Message Foo -Title CustomTitle").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "Joe"
|
|
$netcred.Password | Should be "this is a test"
|
|
$th.ui.Streams.Prompt[-1] | should be "Credential:CustomTitle:Foo"
|
|
}
|
|
It "Get-Credential without parameters" {
|
|
$cred = $ps.AddScript("Get-Credential").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "John"
|
|
$netcred.Password | Should be "This is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
|
}
|
|
It "Get-Credential `$null" {
|
|
$cred = $ps.AddScript("Get-Credential `$null").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "John"
|
|
$netcred.Password | Should be "This is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
|
}
|
|
It "Get-Credential -Credential `$null" {
|
|
$cred = $ps.AddScript("Get-Credential -Credential `$null").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "John"
|
|
$netcred.Password | Should be "This is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
|
}
|
|
it "Get-Credential Joe" {
|
|
$cred = $ps.AddScript("Get-Credential Joe").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "Joe"
|
|
$netcred.Password | Should be "This is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
|
}
|
|
it "Get-Credential -Credential Joe" {
|
|
$cred = $ps.AddScript("Get-Credential Joe").Invoke() | Select-Object -First 1
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "Joe"
|
|
$netcred.Password | Should be "This is a test"
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
|
}
|
|
it "Get-Credential `$credential" {
|
|
$password = ConvertTo-SecureString -String "CredTest" -AsPlainText -Force
|
|
$credential = [pscredential]::new("John", $password)
|
|
|
|
$cred = Get-Credential $credential
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
|
$netcred = $cred.GetNetworkCredential()
|
|
$netcred.UserName | Should be "John"
|
|
$netcred.Password | Should be "CredTest"
|
|
}
|
|
}
|