Skip to content

Commit a8e167d

Browse files
Keep credential prompting available without a browser
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 41f39ca commit a8e167d

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/functions/public/Auth/Connect-DomeneshopAccount.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ function Connect-DomeneshopAccount {
7777

7878
if ($PSCmdlet.ShouldProcess("Domeneshop context [$Context]", 'Store API credentials')) {
7979
if (-not $PSBoundParameters.ContainsKey('Secret')) {
80-
Start-Process -FilePath 'https://domene.shop/admin?view=api'
80+
try {
81+
Start-Process -FilePath 'https://domene.shop/admin?view=api'
82+
} catch {
83+
Write-Warning "Unable to open the Domeneshop API settings page: $($_.Exception.Message)"
84+
}
8185
$Secret = Read-Host -Prompt 'Enter the Domeneshop API secret' -AsSecureString
8286
$null = Test-DomeneshopSecret -Secret $Secret
8387
}

tests/Connect-DomeneshopAccount.Tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ Describe 'Connect-DomeneshopAccount' {
6464
}
6565
}
6666

67+
It 'securely prompts and stores credentials when the browser cannot open' {
68+
Mock Start-Process { throw 'No browser is available.' }
69+
Mock Write-Warning {}
70+
71+
Connect-DomeneshopAccount -Token 'token' -Context 'demo'
72+
73+
Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter {
74+
$Message -eq 'Unable to open the Domeneshop API settings page: No browser is available.'
75+
}
76+
Should -Invoke Read-Host -Times 1 -Exactly -ParameterFilter {
77+
$Prompt -eq 'Enter the Domeneshop API secret' -and $AsSecureString
78+
}
79+
Should -Invoke Set-Context -Times 1 -Exactly -ParameterFilter {
80+
[object]::ReferenceEquals($Context.Secret, $script:PromptedSecret)
81+
}
82+
}
83+
6784
It 'does not open API settings or prompt when WhatIf omits Secret' {
6885
Connect-DomeneshopAccount -Token 'token' -Context 'demo' -WhatIf
6986

0 commit comments

Comments
 (0)