Skip to content

Commit

Permalink
fix(#159): allow domain prefix in username
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaydon committed Aug 24, 2021
1 parent 83c5dc4 commit 3124528
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions resources/dataconnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function New-QlikDataConnection {
Write-Warning "Use of username/password parameters is deprecated, please use Credential instead."
}
if ($Credential) {
$username = $Credential.GetNetworkCredential().Username
$username = $Credential.Username
$password = $Credential.GetNetworkCredential().Password
}
if ($password.Trim().Length -gt 0) {
Expand Down Expand Up @@ -136,7 +136,7 @@ function Update-QlikDataConnection {
$qdc.connectionstring = $ConnectionString
}
if ( $Credential ) {
$qdc.username = $Credential.GetNetworkCredential().Username
$qdc.username = $Credential.Username
if ($qdc.psobject.Properties.name -contains "password") {
$qdc.password = $Credential.GetNetworkCredential().Password
}
Expand Down
30 changes: 30 additions & 0 deletions tests/dataconnection.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ Describe "New-QlikDataConnection" {
}
}

Context 'Username' {
It 'should include the domain prefix if provided' {
$password = ConvertTo-SecureString -String 'password' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("domain\username", $password)
$dc = New-QlikDataConnection `
-name 'My Connection' `
-type Folder `
-connectionstring 'C:\Data' `
-Credential $credential

$dc.username | Should Be 'domain\username'

Assert-VerifiableMock
}
}

Context 'tags' {
Mock Get-QlikTag {
return @(@{
Expand Down Expand Up @@ -118,6 +134,20 @@ Describe "Update-QlikDataConnection" {
}
}

Context 'Username' {
It 'should include the domain prefix if provided' {
$password = ConvertTo-SecureString -String 'password' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential("domain\username", $password)
$dc = Update-QlikDataConnection `
-id '158e743b-c59f-490e-900c-b57e66cf8185' `
-Credential $credential

$dc.username | Should Be 'domain\username'

Assert-VerifiableMock
}
}

Context 'ConnectionString' {
It 'should be updated when provided' {
$dc = Update-QlikDataConnection `
Expand Down

0 comments on commit 3124528

Please sign in to comment.