2016-08-19 22:01:04 +02:00
|
|
|
Describe "Get-Credential Test" -tag "CI" {
|
|
|
|
BeforeAll {
|
|
|
|
$th = New-TestHost
|
|
|
|
$th.UI.StringForSecureString = "This is a test"
|
2016-09-22 00:16:03 +02:00
|
|
|
$th.UI.UserNameForCredential = "John"
|
2016-08-19 22:01:04 +02:00
|
|
|
$rs = [runspacefactory]::Createrunspace($th)
|
|
|
|
$rs.open()
|
|
|
|
$ps = [powershell]::Create()
|
|
|
|
$ps.Runspace = $rs
|
|
|
|
$ps.Commands.Clear()
|
|
|
|
}
|
|
|
|
AfterAll {
|
|
|
|
$rs.Close()
|
|
|
|
$rs.Dispose()
|
|
|
|
$ps.Dispose()
|
|
|
|
}
|
2016-09-22 00:16:03 +02:00
|
|
|
AfterEach {
|
|
|
|
$ps.Commands.Clear()
|
|
|
|
}
|
2016-09-16 23:53:55 +02:00
|
|
|
It "Get-Credential with message, produces a credential object" {
|
|
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe -Message Foo").Invoke() | Select-Object -First 1
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-08-19 22:01:04 +02:00
|
|
|
$netcred = $cred.GetNetworkCredential()
|
|
|
|
$netcred.UserName | Should be "Joe"
|
|
|
|
$netcred.Password | Should be "this is a test"
|
2017-01-16 22:31:14 +01:00
|
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:Foo"
|
2016-09-16 23:53:55 +02:00
|
|
|
}
|
|
|
|
It "Get-Credential with title, produces a credential object" {
|
|
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe -Title CustomTitle").Invoke() | Select-Object -First 1
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-16 23:53:55 +02:00
|
|
|
$netcred = $cred.GetNetworkCredential()
|
|
|
|
$netcred.UserName | Should be "Joe"
|
|
|
|
$netcred.Password | Should be "this is a test"
|
2016-09-22 00:16:03 +02:00
|
|
|
$th.ui.Streams.Prompt[-1] | should Match "Credential:CustomTitle:[^:]+"
|
2016-09-16 23:53:55 +02:00
|
|
|
}
|
|
|
|
It "Get-Credential with only username, produces a credential object" {
|
|
|
|
$cred = $ps.AddScript("Get-Credential -UserName Joe").Invoke() | Select-Object -First 1
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-16 23:53:55 +02:00
|
|
|
$netcred = $cred.GetNetworkCredential()
|
|
|
|
$netcred.UserName | Should be "Joe"
|
|
|
|
$netcred.Password | Should be "this is a test"
|
2016-09-22 00:16:03 +02:00
|
|
|
$th.ui.Streams.Prompt[-1] | Should Match "Credential:[^:]+:[^:]+"
|
2016-09-16 23:53:55 +02:00
|
|
|
}
|
|
|
|
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
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-16 23:53:55 +02:00
|
|
|
$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"
|
2016-08-19 22:01:04 +02:00
|
|
|
}
|
2016-09-22 00:16:03 +02:00
|
|
|
It "Get-Credential without parameters" {
|
|
|
|
$cred = $ps.AddScript("Get-Credential").Invoke() | Select-Object -First 1
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-22 00:16:03 +02:00
|
|
|
$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
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-22 00:16:03 +02:00
|
|
|
$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
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-22 00:16:03 +02:00
|
|
|
$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
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-22 00:16:03 +02:00
|
|
|
$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
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-22 00:16:03 +02:00
|
|
|
$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" {
|
2017-09-27 20:54:22 +02:00
|
|
|
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
|
2016-09-22 00:16:03 +02:00
|
|
|
$password = ConvertTo-SecureString -String "CredTest" -AsPlainText -Force
|
|
|
|
$credential = [pscredential]::new("John", $password)
|
|
|
|
|
|
|
|
$cred = Get-Credential $credential
|
2017-02-16 01:40:51 +01:00
|
|
|
$cred | Should BeOfType System.Management.Automation.PSCredential
|
2016-09-22 00:16:03 +02:00
|
|
|
$netcred = $cred.GetNetworkCredential()
|
|
|
|
$netcred.UserName | Should be "John"
|
|
|
|
$netcred.Password | Should be "CredTest"
|
|
|
|
}
|
2016-08-19 22:01:04 +02:00
|
|
|
}
|