Skip to content

Commit e643399

Browse files
Reject empty API secrets
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent eb3ec7e commit e643399

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function Test-DomeneshopSecret {
2+
<#
3+
.SYNOPSIS
4+
Validate a Domeneshop API secret.
5+
6+
.DESCRIPTION
7+
Reject empty string and secure string values before credential storage.
8+
9+
.EXAMPLE
10+
Test-DomeneshopSecret -Secret $secret
11+
12+
Confirm that the secret contains a value.
13+
14+
.INPUTS
15+
None
16+
17+
You can't pipe objects to Test-DomeneshopSecret.
18+
19+
.OUTPUTS
20+
System.Boolean
21+
22+
True when the secret is not empty.
23+
24+
.NOTES
25+
Secret type validation remains the responsibility of the calling command.
26+
#>
27+
[OutputType([bool])]
28+
[CmdletBinding()]
29+
param(
30+
# The proposed API secret.
31+
[Parameter(Mandatory)]
32+
[ValidateNotNull()]
33+
[object] $Secret
34+
)
35+
36+
if (
37+
($Secret -is [string] -and [string]::IsNullOrWhiteSpace($Secret)) -or
38+
($Secret -is [securestring] -and $Secret.Length -eq 0)
39+
) {
40+
throw 'Secret cannot be empty or whitespace.'
41+
}
42+
43+
$true
44+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function Connect-DomeneshopAccount {
4545
# The Domeneshop API secret as a string or secure string.
4646
[Parameter(Mandatory)]
4747
[ValidateNotNull()]
48+
[ValidateScript({ Test-DomeneshopSecret -Secret $_ })]
4849
[object] $Secret,
4950

5051
# The name used to store and retrieve this credential context.

tests/Connect-DomeneshopAccount.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ Describe 'Connect-DomeneshopAccount' {
4949
Should -Throw '*Secret must be a SecureString or String value*'
5050
}
5151

52+
It 'rejects empty string and secure string secrets' {
53+
{ Connect-DomeneshopAccount -Token 'token' -Secret ' ' -Context 'demo' } |
54+
Should -Throw '*Secret cannot be empty or whitespace*'
55+
{ Connect-DomeneshopAccount -Token 'token' -Secret ([securestring]::new()) -Context 'demo' } |
56+
Should -Throw '*Secret cannot be empty or whitespace*'
57+
58+
Should -Invoke Set-Context -Times 0 -Exactly
59+
}
60+
5261
It 'rejects the reserved module configuration context name' {
5362
{ Connect-DomeneshopAccount -Token 'token' -Secret 'secret' -Context '__Domeneshop.Config' } |
5463
Should -Throw '*reserved for Domeneshop module configuration*'

0 commit comments

Comments
 (0)